From 8529caacca1803d31334d64684de51ab28790848 Mon Sep 17 00:00:00 2001 From: Trek H Date: Tue, 16 Feb 2021 14:57:47 +1030 Subject: [PATCH 1/2] revid: put writeRate into metadata for mts --- container/mts/encoder.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/container/mts/encoder.go b/container/mts/encoder.go index e78bd8b8..fff47dac 100644 --- a/container/mts/encoder.go +++ b/container/mts/encoder.go @@ -164,6 +164,8 @@ func NewEncoder(dst io.WriteCloser, log logger.LoggerIF, options ...func(*Encode } log.Debug("encoder options applied") + Meta.Add("writeRate", 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 e.pmtBytes = e.pmt.Bytes() From bbd779d28ea77f14ee2f69e3f350cc7459867b31 Mon Sep 17 00:00:00 2001 From: Trek H Date: Wed, 17 Feb 2021 10:35:48 +1030 Subject: [PATCH 2/2] revid: update tests to include writeRate metadata --- container/mts/encoder_test.go | 37 +++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/container/mts/encoder_test.go b/container/mts/encoder_test.go index 2752efed..58dd1ca1 100644 --- a/container/mts/encoder_test.go +++ b/container/mts/encoder_test.go @@ -27,6 +27,7 @@ package mts import ( "bytes" + "fmt" "io" "io/ioutil" "reflect" @@ -283,12 +284,17 @@ func TestMetaEncode1(t *testing.T) { got := out[PacketSize+4:] want := []byte{ - 0x00, 0x02, 0xb0, 0x23, 0x00, 0x01, 0xc1, 0x00, 0x00, 0xe1, 0x00, 0xf0, 0x11, - psi.MetadataTag, // Descriptor tag - 0x0f, // Length of bytes to follow - 0x00, 0x10, 0x00, 0x0b, 't', 's', '=', '1', '2', '3', '4', '5', '6', '7', '8', // timestamp - 0x1b, 0xe1, 0x00, 0xf0, 0x00, + 0x00, 0x02, 0xb0, 0x37, 0x00, 0x01, 0xc1, 0x00, 0x00, 0xe1, 0x00, 0xf0, 0x25, + psi.MetadataTag, // Descriptor tag + 0x23, // Length of bytes to follow + 0x00, 0x10, 0x00, 0x1f, } + rate := "writeRate=" + fmt.Sprintf("%f", float64(defaultRate)) + want = append(want, []byte(rate)...) // writeRate + want = append(want, []byte{ + '\t', 't', 's', '=', '1', '2', '3', '4', '5', '6', '7', '8', // timestamp + 0x1b, 0xe1, 0x00, 0xf0, 0x00, + }...) want = psi.AddCRC(want) want = psi.AddPadding(want) if !bytes.Equal(got, want) { @@ -315,13 +321,18 @@ func TestMetaEncode2(t *testing.T) { out := buf.Bytes() got := out[PacketSize+4:] want := []byte{ - 0x00, 0x02, 0xb0, 0x36, 0x00, 0x01, 0xc1, 0x00, 0x00, 0xe1, 0x00, 0xf0, 0x24, - psi.MetadataTag, // Descriptor tag - 0x22, // Length of bytes to follow - 0x00, 0x10, 0x00, 0x1e, 't', 's', '=', '1', '2', '3', '4', '5', '6', '7', '8', '\t', // timestamp + 0x00, 0x02, 0xb0, 0x4a, 0x00, 0x01, 0xc1, 0x00, 0x00, 0xe1, 0x00, 0xf0, 0x38, + psi.MetadataTag, // Descriptor tag + 0x36, // Length of bytes to follow + 0x00, 0x10, 0x00, 0x32, + } + rate := "writeRate=" + fmt.Sprintf("%f", float64(defaultRate)) + want = append(want, []byte(rate)...) // writeRate + want = append(want, []byte{ + '\t', 't', 's', '=', '1', '2', '3', '4', '5', '6', '7', '8', '\t', // timestamp 'l', 'o', 'c', '=', '1', '2', '3', '4', ',', '4', '3', '2', '1', ',', '1', '2', '3', '4', // location 0x1b, 0xe1, 0x00, 0xf0, 0x00, - } + }...) want = psi.AddCRC(want) want = psi.AddPadding(want) if !bytes.Equal(got, want) { @@ -349,9 +360,11 @@ func TestExtractMeta(t *testing.T) { if err != nil { t.Errorf("did not expect error: %v", err.Error()) } + rate := fmt.Sprintf("%f", float64(defaultRate)) want := map[string]string{ - "ts": "12345678", - "loc": "1234,4321,1234", + "ts": "12345678", + "loc": "1234,4321,1234", + "writeRate": rate, } if !reflect.DeepEqual(got, want) { t.Errorf("did not get expected result.\ngot: %v\nwant: %v\n", got, want)