-
Notifications
You must be signed in to change notification settings - Fork 31
/
box_types_av1_test.go
82 lines (76 loc) · 2.22 KB
/
box_types_av1_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package mp4
import (
"bytes"
"io"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestBoxTypesAV1(t *testing.T) {
testCases := []struct {
name string
src IImmutableBox
dst IBox
bin []byte
str string
ctx Context
}{
{
name: "Av1C",
src: &Av1C{
Marker: 1,
Version: 1,
SeqProfile: 2,
SeqLevelIdx0: 1,
SeqTier0: 1,
HighBitdepth: 1,
TwelveBit: 0,
Monochrome: 0,
ChromaSubsamplingX: 1,
ChromaSubsamplingY: 1,
ChromaSamplePosition: 0,
ConfigOBUs: []byte{
0x08, 0x00, 0x00, 0x00, 0x42, 0xa7, 0xbf, 0xe4,
0x60, 0x0d, 0x00, 0x40,
},
},
dst: &Av1C{},
bin: []byte{
0x81, 0x41, 0xcc, 0x00, 0x08, 0x00, 0x00, 0x00,
0x42, 0xa7, 0xbf, 0xe4, 0x60, 0x0d, 0x00, 0x40,
},
str: `SeqProfile=0x2 SeqLevelIdx0=0x1 SeqTier0=0x1 HighBitdepth=0x1 TwelveBit=0x0 Monochrome=0x0 ChromaSubsamplingX=0x1 ChromaSubsamplingY=0x1 ChromaSamplePosition=0x0 InitialPresentationDelayPresent=0x0 InitialPresentationDelayMinusOne=0x0 ConfigOBUs=[0x8, 0x0, 0x0, 0x0, 0x42, 0xa7, 0xbf, 0xe4, 0x60, 0xd, 0x0, 0x40]`,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
// Marshal
buf := bytes.NewBuffer(nil)
n, err := Marshal(buf, tc.src, tc.ctx)
require.NoError(t, err)
assert.Equal(t, uint64(len(tc.bin)), n)
assert.Equal(t, tc.bin, buf.Bytes())
// Unmarshal
r := bytes.NewReader(tc.bin)
n, err = Unmarshal(r, uint64(len(tc.bin)), tc.dst, tc.ctx)
require.NoError(t, err)
assert.Equal(t, uint64(buf.Len()), n)
assert.Equal(t, tc.src, tc.dst)
s, err := r.Seek(0, io.SeekCurrent)
require.NoError(t, err)
assert.Equal(t, int64(buf.Len()), s)
// UnmarshalAny
dst, n, err := UnmarshalAny(bytes.NewReader(tc.bin), tc.src.GetType(), uint64(len(tc.bin)), tc.ctx)
require.NoError(t, err)
assert.Equal(t, uint64(buf.Len()), n)
assert.Equal(t, tc.src, dst)
s, err = r.Seek(0, io.SeekCurrent)
require.NoError(t, err)
assert.Equal(t, int64(buf.Len()), s)
// Stringify
str, err := Stringify(tc.src, tc.ctx)
require.NoError(t, err)
assert.Equal(t, tc.str, str)
})
}
}