mirror of
https://github.com/bluenviron/mediamtx
synced 2024-12-16 11:44:50 +00:00
141 lines
2.5 KiB
Go
141 lines
2.5 KiB
Go
package h264
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
var annexBCases = []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},
|
|
},
|
|
},
|
|
{
|
|
"anti-competition",
|
|
[]byte{
|
|
0x00, 0x00, 0x00, 0x01,
|
|
0x00, 0x00, 0x03, 0x00,
|
|
0x00, 0x00, 0x03, 0x01,
|
|
0x00, 0x00, 0x03, 0x02,
|
|
0x00, 0x00, 0x03, 0x03,
|
|
},
|
|
[]byte{
|
|
0x00, 0x00, 0x00, 0x01,
|
|
0x00, 0x00, 0x03, 0x00,
|
|
0x00, 0x00, 0x03, 0x01,
|
|
0x00, 0x00, 0x03, 0x02,
|
|
0x00, 0x00, 0x03, 0x03,
|
|
},
|
|
[][]byte{
|
|
{
|
|
0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x01,
|
|
0x00, 0x00, 0x02,
|
|
0x00, 0x00, 0x03,
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
func TestAnnexBDecode(t *testing.T) {
|
|
for _, ca := range annexBCases {
|
|
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 annexBCases {
|
|
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)
|
|
})
|
|
}
|
|
}
|