mirror of https://bitbucket.org/ausocean/av.git
revid: modified http sender to look at reply of send and get time and gps data to mts package
This commit is contained in:
parent
2ca393c276
commit
9a7d7a9ab3
|
@ -35,6 +35,7 @@ import (
|
|||
"os/exec"
|
||||
|
||||
"bitbucket.org/ausocean/av/rtmp"
|
||||
"bitbucket.org/ausocean/av/stream/mts"
|
||||
"bitbucket.org/ausocean/av/stream/rtp"
|
||||
"bitbucket.org/ausocean/iot/pi/netsender"
|
||||
"bitbucket.org/ausocean/utils/ring"
|
||||
|
@ -143,9 +144,26 @@ func (s *httpSender) send() error {
|
|||
}
|
||||
}
|
||||
var err error
|
||||
var reply string
|
||||
if send {
|
||||
_, _, err = s.client.Send(netsender.RequestRecv, pins)
|
||||
reply, _, err = s.client.Send(netsender.RequestPoll, pins)
|
||||
}
|
||||
// Extract time from reply
|
||||
t, err := netsender.ExtractJsonInt(reply, "ts")
|
||||
if err != nil {
|
||||
s.log(smartlogger.Warning, pkg+"No timestamp in reply")
|
||||
} else {
|
||||
mts.TimeMeta(uint64(t))
|
||||
}
|
||||
|
||||
// Extract gps from reply
|
||||
g, err := netsender.ExtractJsonString(reply, "ll")
|
||||
if err != nil {
|
||||
s.log(smartlogger.Warning, pkg+"No gps in reply")
|
||||
} else {
|
||||
mts.GpsMeta(g)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -29,10 +29,7 @@ LICENSE
|
|||
package mts
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"hash/crc32"
|
||||
"io"
|
||||
"math/bits"
|
||||
"time"
|
||||
|
||||
"bitbucket.org/ausocean/av/stream/mts/pes"
|
||||
|
@ -49,49 +46,24 @@ const (
|
|||
psiSendCount = 100
|
||||
)
|
||||
|
||||
type MetaData struct {
|
||||
time uint64
|
||||
gps string
|
||||
}
|
||||
|
||||
var metaData = MetaData{time: 0, gps: ""}
|
||||
|
||||
func TimeMeta(t uint64) {
|
||||
metaData.time = t
|
||||
}
|
||||
|
||||
func GpsMeta(g string) {
|
||||
metaData.gps = g
|
||||
}
|
||||
|
||||
func init() {
|
||||
// Generate IEEE polynomial table
|
||||
// for the big-endian algorithm.
|
||||
crcTable := crc32_MakeTable(bits.Reverse32(crc32.IEEE))
|
||||
|
||||
patTable = completePSI(psi.StdPat, crcTable)
|
||||
pmtTable = completePSI(psi.StdPmt, crcTable)
|
||||
}
|
||||
|
||||
func completePSI(psi []byte, tab *crc32.Table) []byte {
|
||||
var buf [4]byte
|
||||
crc := crc32_Update(0xffffffff, tab, psi[1:])
|
||||
binary.BigEndian.PutUint32(buf[:], crc)
|
||||
dst := make([]byte, len(psi), psiPacketSize)
|
||||
copy(dst, psi)
|
||||
dst = append(dst, buf[:]...)
|
||||
for len(dst) < cap(dst) {
|
||||
dst = append(dst, 0xff)
|
||||
}
|
||||
return dst
|
||||
}
|
||||
|
||||
func crc32_MakeTable(poly uint32) *crc32.Table {
|
||||
var t crc32.Table
|
||||
for i := range t {
|
||||
crc := uint32(i) << 24
|
||||
for j := 0; j < 8; j++ {
|
||||
if crc&0x80000000 != 0 {
|
||||
crc = (crc << 1) ^ poly
|
||||
} else {
|
||||
crc <<= 1
|
||||
}
|
||||
}
|
||||
t[i] = crc
|
||||
}
|
||||
return &t
|
||||
}
|
||||
|
||||
func crc32_Update(crc uint32, tab *crc32.Table, p []byte) uint32 {
|
||||
for _, v := range p {
|
||||
crc = tab[byte(crc>>24)^v] ^ (crc << 8)
|
||||
}
|
||||
return crc
|
||||
patTable = psi.StdPat.Bytes()
|
||||
pmtTable = psi.StdPmtTimeGps.Bytes()
|
||||
}
|
||||
|
||||
const (
|
||||
|
@ -215,7 +187,17 @@ func (e *Encoder) writePSI() error {
|
|||
return err
|
||||
}
|
||||
|
||||
// Write PMT.
|
||||
// Update pmt table time and gps
|
||||
err = psi.UpdateTime(pmtTable, metaData.time)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = psi.UpdateGps(pmtTable, metaData.gps)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Create mts packet from pmt table
|
||||
pmtPkt := Packet{
|
||||
PUSI: true,
|
||||
PID: pmtPid,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
NAME
|
||||
op.go
|
||||
op.go
|
||||
DESCRIPTION
|
||||
op.go provides functionality for editing and reading bytes slices
|
||||
directly in order to insert/read timestamp and gps data in psi.
|
||||
|
@ -61,7 +61,7 @@ func ChkGps(p []byte) error {
|
|||
// UpdateTime takes the byte slice representation of a psi-pmt as well as a time
|
||||
// as an integer and attempts to update the time descriptor in the pmt with the
|
||||
// given time if the time descriptor exists, otherwise an error is returned
|
||||
func UpdateTime(d []byte, t int) error {
|
||||
func UpdateTime(d []byte, t uint64) error {
|
||||
err := ChkTime(d)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -105,15 +105,15 @@ var bytesTests = []struct {
|
|||
// Pat test
|
||||
{
|
||||
name: "pat Bytes()",
|
||||
input: stdPat,
|
||||
want: stdPatBytes,
|
||||
input: StdPat,
|
||||
want: StdPatBytes,
|
||||
},
|
||||
|
||||
// Pmt test data no descriptor
|
||||
{
|
||||
name: "pmt to Bytes() without descriptors",
|
||||
input: stdPmt,
|
||||
want: stdPmtBytes,
|
||||
input: StdPmt,
|
||||
want: StdPmtBytes,
|
||||
},
|
||||
|
||||
// Pmt with time descriptor
|
||||
|
|
|
@ -33,7 +33,7 @@ const (
|
|||
// Some common manifestations of PSI
|
||||
var (
|
||||
// PSI struct to represent basic pat
|
||||
stdPat = PSI{
|
||||
StdPat = PSI{
|
||||
Pf: 0x00,
|
||||
Tid: 0x00,
|
||||
Ssi: true,
|
||||
|
@ -53,7 +53,7 @@ var (
|
|||
}
|
||||
|
||||
// PSI struct to represent basic pmt without descriptors for time and gps
|
||||
stdPmt = PSI{
|
||||
StdPmt = PSI{
|
||||
Pf: 0x00,
|
||||
Tid: 0x02,
|
||||
Ssi: true,
|
||||
|
@ -77,7 +77,7 @@ var (
|
|||
}
|
||||
|
||||
// Std pmt with time and gps descriptors, time and gps fields are zerod out
|
||||
stdPmtTimeGps = PSI{
|
||||
StdPmtTimeGps = PSI{
|
||||
Pf: 0x00,
|
||||
Tid: 0x02,
|
||||
Ssi: true,
|
||||
|
@ -115,7 +115,7 @@ var (
|
|||
|
||||
// Std PSI in bytes form
|
||||
var (
|
||||
stdPatBytes = []byte{
|
||||
StdPatBytes = []byte{
|
||||
0x00, // pointer
|
||||
|
||||
// ---- section included in data sent to CRC32 during check
|
||||
|
@ -136,7 +136,7 @@ var (
|
|||
// 0x2a, 0xb1, 0x04, 0xb2, // CRC
|
||||
// ----
|
||||
}
|
||||
stdPmtBytes = []byte{
|
||||
StdPmtBytes = []byte{
|
||||
0x00, // pointer
|
||||
|
||||
// ---- section included in data sent to CRC32 during check
|
||||
|
|
Loading…
Reference in New Issue