mts: change meta const names eg. WriteRateStr to WriteRateKey

This commit is contained in:
Trek H 2021-02-22 16:17:36 +10:30
parent 3ec7201d9c
commit 357cb196b9
4 changed files with 28 additions and 28 deletions

View File

@ -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())

View File

@ -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,7 +289,7 @@ 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
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)
@ -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)

View File

@ -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
}

View File

@ -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