mirror of https://bitbucket.org/ausocean/av.git
revid: cleaned and added commenting
This commit is contained in:
parent
239b52ad84
commit
fbdce669e7
|
@ -156,6 +156,8 @@ func (s *httpSender) send() error {
|
|||
return s.extractMeta(reply)
|
||||
}
|
||||
|
||||
// extractMeta looks at a reply at extracts any time or location data - then used
|
||||
// to update time and location information in the mpegts encoder.
|
||||
func (s *httpSender) extractMeta(r string) error {
|
||||
dec, err := netsender.NewJsonDecoder(r)
|
||||
if err != nil {
|
||||
|
|
|
@ -169,6 +169,8 @@ func (e *Encoder) Encode(nalu []byte) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// writePSI creates mpegts with pat and pmt tables - with pmt table having updated
|
||||
// location and time data.
|
||||
func (e *Encoder) writePSI() error {
|
||||
// Write PAT
|
||||
patPkt := Packet{
|
||||
|
@ -209,6 +211,8 @@ func (e *Encoder) writePSI() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// addPadding adds an appropriate amount of padding to a pat or pmt table for
|
||||
// addition to an mpegts packet
|
||||
func addPadding(d []byte) []byte {
|
||||
for len(d) < psiPacketSize {
|
||||
d = append(d, 0xff)
|
||||
|
|
|
@ -35,7 +35,7 @@ import (
|
|||
"math/bits"
|
||||
)
|
||||
|
||||
// timeBytes takes a timestamp as an uint64 and converts to an 8 byte slice -
|
||||
// TimeBytes takes a timestamp as an uint64 and converts to an 8 byte slice -
|
||||
// allows for updating of timestamp in pmt time descriptor.
|
||||
func TimeBytes(t uint64) []byte {
|
||||
var s [timeDataSize]byte
|
||||
|
@ -43,7 +43,7 @@ func TimeBytes(t uint64) []byte {
|
|||
return s[:]
|
||||
}
|
||||
|
||||
// ChkTime takes a psi as a byte slice and checks to see if it has a time descriptor
|
||||
// HasTime takes a psi as a byte slice and checks to see if it has a time descriptor
|
||||
// - if so return nil, otherwise return error
|
||||
func HasTime(p []byte) error {
|
||||
if p[timeTagIndx] != timeDescTag {
|
||||
|
@ -52,7 +52,7 @@ func HasTime(p []byte) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// ChkLocation takes a psi as a byte slice and checks to see if it has a location descriptor
|
||||
// HasLocation takes a psi as a byte slice and checks to see if it has a location descriptor
|
||||
// - if so return nil, otherwise return error
|
||||
func HasLocation(p []byte) error {
|
||||
if p[locationTagIndx] != locationDescTag {
|
||||
|
@ -77,7 +77,7 @@ func UpdateTime(dst []byte, t uint64) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// TimeOf takes a byte slice representation of a psi-pmt and extracts it's
|
||||
// TimeFrom takes a byte slice representation of a psi-pmt and extracts it's
|
||||
// timestamp, returning as a uint64 if it exists, otherwise returning 0 and nil
|
||||
// if it does not exist
|
||||
func TimeFrom(p []byte) (t uint64, err error) {
|
||||
|
@ -89,7 +89,7 @@ func TimeFrom(p []byte) (t uint64, err error) {
|
|||
return t, nil
|
||||
}
|
||||
|
||||
// TimeOf takes a byte slice representation of a psi-pmt and extracts it's
|
||||
// LocationFrom takes a byte slice representation of a psi-pmt and extracts it's
|
||||
// timestamp, returning as a uint64 if it exists, otherwise returning 0 and nil
|
||||
// if it does not exist
|
||||
func LocationFrom(p []byte) (g string, err error) {
|
||||
|
@ -130,12 +130,14 @@ func UpdateLocation(d []byte, s string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// addCrc appends a crc table to a given psi table in bytes
|
||||
func addCrc(out []byte) []byte {
|
||||
out = append(out, make([]byte, 4)...)
|
||||
out = updateCrc(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// updateCrc updates the crc of psi bytes slice that may have been modified
|
||||
func updateCrc(out []byte) []byte {
|
||||
crc32 := crc32_Update(0xffffffff, crc32_MakeTable(bits.Reverse32(crc32.IEEE)), out[1:len(out)-4])
|
||||
out[len(out)-4] = byte(crc32 >> 24)
|
||||
|
|
|
@ -160,6 +160,7 @@ func readTSS(data []byte, p *PSI) *TSS {
|
|||
return &tss
|
||||
}
|
||||
|
||||
// readPAT creates a pat struct based on a bytes slice representing a pat
|
||||
func readPAT(data []byte, p *TSS) *PAT {
|
||||
pat := PAT{}
|
||||
pos := 0
|
||||
|
@ -169,6 +170,7 @@ func readPAT(data []byte, p *TSS) *PAT {
|
|||
return &pat
|
||||
}
|
||||
|
||||
// readPMT creates a pmt struct based on a bytes slice that represents a pmt
|
||||
func readPMT(data []byte, p *TSS) *PAT {
|
||||
pmt := PMT{}
|
||||
pos := 0
|
||||
|
@ -205,6 +207,7 @@ func readDescs(data []byte, descLen int) (o []Desc) {
|
|||
return
|
||||
}
|
||||
|
||||
// readEESD creates an ESSD struct based on a bytes slice that represents ESSD
|
||||
func readEssd(data []byte) *ESSD {
|
||||
essd := ESSD{}
|
||||
pos := 0
|
||||
|
|
|
@ -38,6 +38,7 @@ const (
|
|||
)
|
||||
|
||||
// GPS string for testing
|
||||
// TODO: make these realistic
|
||||
const (
|
||||
locationTstStr1 = "$GPGGA,123519,4807.038,N,01131.0"
|
||||
locationTstStr2 = "$GPGGA,183710,4902.048,N,02171.0"
|
||||
|
@ -240,6 +241,7 @@ func TestTimeGet(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// TestLocationGet checks that we can correctly get location data from a pmt table
|
||||
func TestLocationGet(t *testing.T) {
|
||||
pb := StdPmtTimeLocation.Bytes()
|
||||
err := UpdateLocation(pb, locationTstStr1)
|
||||
|
|
Loading…
Reference in New Issue