From 357cb196b9b270d906acc2f50be530c6f387710c Mon Sep 17 00:00:00 2001 From: Trek H Date: Mon, 22 Feb 2021 16:17:36 +1030 Subject: [PATCH] mts: change meta const names eg. WriteRateStr to WriteRateKey --- container/mts/encoder.go | 10 +++++----- container/mts/encoder_test.go | 24 ++++++++++++------------ revid/audio_linux.go | 20 ++++++++++---------- revid/senders.go | 2 +- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/container/mts/encoder.go b/container/mts/encoder.go index e7aae26b..c40cc596 100644 --- a/container/mts/encoder.go +++ b/container/mts/encoder.go @@ -103,9 +103,9 @@ const ( // Used to consistently read and write MTS metadata entries. const ( - WriteRateStr = "writeRate" - TSStr = "ts" - LocStr = "loc" + WriteRateKey = "writeRate" + TimestampKey = "ts" + LocationKey = "loc" ) // Meta allows addition of metadata to encoded mts from outside of this pkg. @@ -171,7 +171,7 @@ func NewEncoder(dst io.WriteCloser, log logger.LoggerIF, options ...func(*Encode } log.Debug("encoder options applied") - Meta.Add(WriteRateStr, fmt.Sprintf("%f", 1/float64(e.writePeriod.Seconds()))) + Meta.Add(WriteRateKey, fmt.Sprintf("%f", 1/float64(e.writePeriod.Seconds()))) e.pmt.SyntaxSection.SpecificData.(*psi.PMT).StreamSpecificData.StreamType = e.streamID e.pmt.SyntaxSection.SpecificData.(*psi.PMT).StreamSpecificData.PID = e.mediaPID @@ -339,7 +339,7 @@ func updateMeta(b []byte, log logger.LoggerIF) ([]byte, error) { p := psi.PSIBytes(b) if RealTime.IsSet() { t := strconv.Itoa(int(RealTime.Get().Unix())) - Meta.Add(TSStr, t) + Meta.Add(TimestampKey, t) log.Debug("latest time added to meta", "time", t) } err := p.AddDescriptor(psi.MetadataTag, Meta.Encode()) diff --git a/container/mts/encoder_test.go b/container/mts/encoder_test.go index 1b7a5d01..048894e9 100644 --- a/container/mts/encoder_test.go +++ b/container/mts/encoder_test.go @@ -276,7 +276,7 @@ func TestMetaEncode1(t *testing.T) { t.Fatalf("could not create encoder, failed with error: %v", err) } - Meta.Add(TSStr, "12345678") + Meta.Add(TimestampKey, "12345678") if err := e.writePSI(); err != nil { t.Errorf("unexpected error: %v\n", err.Error()) } @@ -289,8 +289,8 @@ func TestMetaEncode1(t *testing.T) { 0x23, // Length of bytes to follow 0x00, 0x10, 0x00, 0x1f, } - rate := "writeRate=" + fmt.Sprintf("%f", float64(defaultRate)) + "\t" + TSStr + "=12345678" // timestamp - want = append(want, []byte(rate)...) // writeRate + rate := WriteRateKey + "=" + fmt.Sprintf("%f", float64(defaultRate)) + "\t" + TimestampKey + "=12345678" // timestamp + want = append(want, []byte(rate)...) // writeRate want = append(want, []byte{0x1b, 0xe1, 0x00, 0xf0, 0x00}...) want = psi.AddCRC(want) want = psi.AddPadding(want) @@ -310,8 +310,8 @@ func TestMetaEncode2(t *testing.T) { t.Fatalf("could not create MTS encoder, failed with error: %v", err) } - Meta.Add(TSStr, "12345678") - Meta.Add(LocStr, "1234,4321,1234") + Meta.Add(TimestampKey, "12345678") + Meta.Add(LocationKey, "1234,4321,1234") if err := e.writePSI(); err != nil { t.Errorf("did not expect error: %v from writePSI", err.Error()) } @@ -323,8 +323,8 @@ func TestMetaEncode2(t *testing.T) { 0x36, // Length of bytes to follow 0x00, 0x10, 0x00, 0x32, } - s := WriteRateStr + "=" + fmt.Sprintf("%f", float64(defaultRate)) + "\t" + - TSStr + "=12345678\t" + LocStr + "=1234,4321,1234" + s := WriteRateKey + "=" + fmt.Sprintf("%f", float64(defaultRate)) + "\t" + + TimestampKey + "=12345678\t" + LocationKey + "=1234,4321,1234" want = append(want, []byte(s)...) want = append(want, []byte{0x1b, 0xe1, 0x00, 0xf0, 0x00}...) want = psi.AddCRC(want) @@ -344,8 +344,8 @@ func TestExtractMeta(t *testing.T) { t.Fatalf("could not create MTS encoder, failed with error: %v", err) } - Meta.Add(TSStr, "12345678") - Meta.Add(LocStr, "1234,4321,1234") + Meta.Add(TimestampKey, "12345678") + Meta.Add(LocationKey, "1234,4321,1234") if err := e.writePSI(); err != nil { t.Errorf("did not expect error: %v", err.Error()) } @@ -356,9 +356,9 @@ func TestExtractMeta(t *testing.T) { } rate := fmt.Sprintf("%f", float64(defaultRate)) want := map[string]string{ - "ts": "12345678", - "loc": "1234,4321,1234", - "writeRate": rate, + TimestampKey: "12345678", + LocationKey: "1234,4321,1234", + WriteRateKey: rate, } if !reflect.DeepEqual(got, want) { t.Errorf("did not get expected result.\ngot: %v\nwant: %v\n", got, want) diff --git a/revid/audio_linux.go b/revid/audio_linux.go index 3511f367..1553dc47 100644 --- a/revid/audio_linux.go +++ b/revid/audio_linux.go @@ -38,11 +38,11 @@ import ( // Used to reliably read, write, and test audio metadata entry keys. const ( - SampleRateStr = "sampleRate" - ChannelsStr = "channels" - PeriodStr = "period" - BitDepthStr = "bitDepth" - CodecStr = "codec" + SampleRateKey = "sampleRate" + ChannelsKey = "channels" + PeriodKey = "period" + BitDepthKey = "bitDepth" + CodecKey = "codec" ) func (r *Revid) setupAudio() error { @@ -68,11 +68,11 @@ func (r *Revid) setupAudio() error { r.lexTo = l.Lex // Add metadata. - mts.Meta.Add(SampleRateStr, strconv.Itoa(int(r.cfg.SampleRate))) - mts.Meta.Add(ChannelsStr, strconv.Itoa(int(r.cfg.Channels))) - mts.Meta.Add(PeriodStr, fmt.Sprintf("%.6f", r.cfg.RecPeriod)) - mts.Meta.Add(BitDepthStr, strconv.Itoa(int(r.cfg.BitDepth))) - mts.Meta.Add(CodecStr, r.cfg.InputCodec) + mts.Meta.Add(SampleRateKey, strconv.Itoa(int(r.cfg.SampleRate))) + mts.Meta.Add(ChannelsKey, strconv.Itoa(int(r.cfg.Channels))) + mts.Meta.Add(PeriodKey, fmt.Sprintf("%.6f", r.cfg.RecPeriod)) + mts.Meta.Add(BitDepthKey, strconv.Itoa(int(r.cfg.BitDepth))) + mts.Meta.Add(CodecKey, r.cfg.InputCodec) return nil } diff --git a/revid/senders.go b/revid/senders.go index a0172491..36310389 100644 --- a/revid/senders.go +++ b/revid/senders.go @@ -153,7 +153,7 @@ func extractMeta(r string, log func(lvl int8, msg string, args ...interface{})) log(logger.Debug, "No location in reply") } else { log(logger.Debug, fmt.Sprintf("got location: %v", g)) - mts.Meta.Add(mts.LocStr, g) + mts.Meta.Add(mts.LocationKey, g) } return nil