From fbdce669e77d88355d5be946a9dafb6469ee6869 Mon Sep 17 00:00:00 2001 From: saxon Date: Fri, 14 Dec 2018 16:46:36 +1030 Subject: [PATCH] revid: cleaned and added commenting --- revid/senders.go | 2 ++ stream/mts/encoder.go | 4 ++++ stream/mts/psi/op.go | 12 +++++++----- stream/mts/psi/psi.go | 3 +++ stream/mts/psi/psi_test.go | 2 ++ 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/revid/senders.go b/revid/senders.go index 549ce30d..3db3a982 100644 --- a/revid/senders.go +++ b/revid/senders.go @@ -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 { diff --git a/stream/mts/encoder.go b/stream/mts/encoder.go index 719ccd86..3236c95b 100644 --- a/stream/mts/encoder.go +++ b/stream/mts/encoder.go @@ -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) diff --git a/stream/mts/psi/op.go b/stream/mts/psi/op.go index 331019b7..e08d64d5 100644 --- a/stream/mts/psi/op.go +++ b/stream/mts/psi/op.go @@ -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) diff --git a/stream/mts/psi/psi.go b/stream/mts/psi/psi.go index 259fa95c..56abc260 100644 --- a/stream/mts/psi/psi.go +++ b/stream/mts/psi/psi.go @@ -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 diff --git a/stream/mts/psi/psi_test.go b/stream/mts/psi/psi_test.go index eccf057a..86c19f60 100644 --- a/stream/mts/psi/psi_test.go +++ b/stream/mts/psi/psi_test.go @@ -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)