diff --git a/container/flv/flv_test.go b/container/flv/flv_test.go index 42aa499c..847138cb 100644 --- a/container/flv/flv_test.go +++ b/container/flv/flv_test.go @@ -73,5 +73,39 @@ func TestVideoTagBytes(t *testing.T) { } func TestAudioTagBytes(t *testing.T) { + tests := []struct { + tag AudioTag + expected []byte + }{ + { + tag: AudioTag{ + TagType: AudioTagType, + DataSize: 8, + Timestamp: 1234, + TimestampExtended: 56, + SoundFormat: AACAudioFormat, + SoundRate: 3, + SoundSize: true, + SoundType: true, + Data: []byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}, + }, + expected: []byte{ + 0x08, // TagType. + 0x00, 0x00, 0x08, // DataSize. + 0x00, 0x04, 0xd2, // Timestamp. + 0x38, // TimestampExtended. + 0x00, 0x00, 0x00, // StreamID. (always 0) + 0xaf, // SoundFormat=1010,SoundRate=11,SoundSize=1,SoundType=1 + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, // AudioData. + 0x00, 0x00, 0x00, 0x00, // previousTagSize. + }, + }, + } + for testNum, test := range tests { + got := test.tag.Bytes() + if !bytes.Equal(got, test.expected) { + t.Errorf("did not get expected result for test: %v.\n Got: %v\n Want: %v\n", testNum, got, test.expected) + } + } }