Merge branch 'master' into jpeg-rate

This commit is contained in:
Trek H 2021-02-22 12:06:21 +10:30
commit 2d75692e70
2 changed files with 27 additions and 12 deletions

View File

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

View File

@ -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,
0x00, 0x02, 0xb0, 0x37, 0x00, 0x01, 0xc1, 0x00, 0x00, 0xe1, 0x00, 0xf0, 0x25,
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,
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,
0x00, 0x02, 0xb0, 0x4a, 0x00, 0x01, 0xc1, 0x00, 0x00, 0xe1, 0x00, 0xf0, 0x38,
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
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",
"writeRate": rate,
}
if !reflect.DeepEqual(got, want) {
t.Errorf("did not get expected result.\ngot: %v\nwant: %v\n", got, want)