Ready-to-use SRT / WebRTC / RTSP / RTMP / LL-HLS media server and media proxy that allows to read, publish, proxy, record and playback video and audio streams.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

115 lines
2.0 KiB

package h264
import (
"testing"
"github.com/stretchr/testify/require"
)
var casesAnnexB = []struct {
name string
encin []byte
encout []byte
dec [][]byte
}{
{
"2 zeros, single",
[]byte{0x00, 0x00, 0x01, 0xaa, 0xbb},
[]byte{0x00, 0x00, 0x00, 0x01, 0xaa, 0xbb},
[][]byte{
{0xaa, 0xbb},
},
},
{
"2 zeros, multiple",
[]byte{
0x00, 0x00, 0x01, 0xaa, 0xbb, 0x00, 0x00, 0x01,
0xcc, 0xdd, 0x00, 0x00, 0x01, 0xee, 0xff,
},
[]byte{
0x00, 0x00, 0x00, 0x01, 0xaa, 0xbb, 0x00, 0x00,
0x00, 0x01, 0xcc, 0xdd, 0x00, 0x00, 0x00, 0x01,
0xee, 0xff,
},
[][]byte{
{0xaa, 0xbb},
{0xcc, 0xdd},
{0xee, 0xff},
},
},
{
"3 zeros, single",
[]byte{0x00, 0x00, 0x00, 0x01, 0xaa, 0xbb},
[]byte{0x00, 0x00, 0x00, 0x01, 0xaa, 0xbb},
[][]byte{
{0xaa, 0xbb},
},
},
{
"3 zeros, multiple",
[]byte{
0x00, 0x00, 0x00, 0x01, 0xaa, 0xbb, 0x00, 0x00,
0x00, 0x01, 0xcc, 0xdd, 0x00, 0x00, 0x00, 0x01,
0xee, 0xff,
},
[]byte{
0x00, 0x00, 0x00, 0x01, 0xaa, 0xbb, 0x00, 0x00,
0x00, 0x01, 0xcc, 0xdd, 0x00, 0x00, 0x00, 0x01,
0xee, 0xff,
},
[][]byte{
{0xaa, 0xbb},
{0xcc, 0xdd},
{0xee, 0xff},
},
},
}
func TestAnnexBDecode(t *testing.T) {
for _, ca := range casesAnnexB {
t.Run(ca.name, func(t *testing.T) {
dec, err := DecodeAnnexB(ca.encin)
require.NoError(t, err)
require.Equal(t, ca.dec, dec)
})
}
}
func TestAnnexBEncode(t *testing.T) {
for _, ca := range casesAnnexB {
t.Run(ca.name, func(t *testing.T) {
enc, err := EncodeAnnexB(ca.dec)
require.NoError(t, err)
require.Equal(t, ca.encout, enc)
})
}
}
func TestAnnexBDecodeError(t *testing.T) {
for _, ca := range []struct {
name string
enc []byte
}{
{
"empty",
[]byte{},
},
{
"missing initial delimiter",
[]byte{0xaa, 0xbb},
},
{
"empty initial",
[]byte{0x00, 0x00, 0x01},
},
{
"empty 2nd",
[]byte{0x00, 0x00, 0x01, 0xaa, 0x00, 0x00, 0x01},
},
} {
t.Run(ca.name, func(t *testing.T) {
_, err := DecodeAnnexB(ca.enc)
require.Error(t, err)
})
}
}