mirror of
https://github.com/aler9/gortsplib
synced 2025-10-22 14:49:31 +08:00
add h264 utilities
This commit is contained in:
115
pkg/h264/annexb_test.go
Normal file
115
pkg/h264/annexb_test.go
Normal file
@@ -0,0 +1,115 @@
|
||||
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)
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user