2019-05-08 08:44:35 +03:00
|
|
|
/*
|
|
|
|
NAME
|
|
|
|
flv_test.go
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
flv_test.go provides testing for functionality provided in flv.go.
|
|
|
|
|
|
|
|
AUTHORS
|
|
|
|
Saxon A. Nelson-Milton <saxon@ausocean.org>
|
|
|
|
|
|
|
|
LICENSE
|
|
|
|
Copyright (C) 2019 the Australian Ocean Lab (AusOcean)
|
|
|
|
|
|
|
|
It is free software: you can redistribute it and/or modify them
|
|
|
|
under the terms of the GNU General Public License as published by the
|
|
|
|
Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with revid in gpl.txt. If not, see http://www.gnu.org/licenses.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package flv
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2019-05-08 09:11:19 +03:00
|
|
|
// TestVideoTagBytes checks that we can correctly get a []byte representation
|
|
|
|
// of a VideoTag using VideoTag.Bytes().
|
2019-05-08 08:44:35 +03:00
|
|
|
func TestVideoTagBytes(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
tag VideoTag
|
|
|
|
expected []byte
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
tag: VideoTag{
|
|
|
|
TagType: VideoTagType,
|
|
|
|
DataSize: 12,
|
|
|
|
Timestamp: 1234,
|
|
|
|
TimestampExtended: 56,
|
2019-05-08 10:36:23 +03:00
|
|
|
FrameType: KeyFrameType,
|
|
|
|
Codec: H264,
|
|
|
|
PacketType: AVCNALU,
|
2019-05-08 08:44:35 +03:00
|
|
|
CompositionTime: 0,
|
|
|
|
Data: []byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07},
|
|
|
|
},
|
|
|
|
expected: []byte{
|
|
|
|
0x09, // TagType.
|
|
|
|
0x00, 0x00, 0x0c, // DataSize.
|
|
|
|
0x00, 0x04, 0xd2, // Timestamp.
|
|
|
|
0x38, // TimestampExtended.
|
|
|
|
0x00, 0x00, 0x00, // StreamID. (always 0)
|
|
|
|
0x17, // FrameType=0001, Codec=0111
|
|
|
|
0x01, // PacketType.
|
|
|
|
0x00, 0x00, 0x00, // CompositionTime
|
|
|
|
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, // VideoData.
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-08 09:11:19 +03:00
|
|
|
// TestAudioTagBytes checks that we can correctly get a []byte representation of
|
|
|
|
// an AudioTag using AudioTag.Bytes().
|
2019-05-08 08:44:35 +03:00
|
|
|
func TestAudioTagBytes(t *testing.T) {
|
2019-05-08 09:09:12 +03:00
|
|
|
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.
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2019-05-08 08:44:35 +03:00
|
|
|
|
2019-05-08 09:09:12 +03:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
2019-05-08 08:44:35 +03:00
|
|
|
}
|