-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathavc_test.go
163 lines (152 loc) · 3.09 KB
/
avc_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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package avc
import (
"strings"
"testing"
"github.com/go-test/deep"
)
func TestGetNaluTypes(t *testing.T) {
testCases := []struct {
name string
input []byte
wanted []NaluType
}{
{
"IDR",
[]byte{0, 0, 0, 2, 5, 0},
[]NaluType{NALU_IDR},
},
{
"AUD and SPS",
[]byte{0, 0, 0, 2, 9, 2, 0, 0, 0, 3, 7, 5, 4},
[]NaluType{NALU_AUD, NALU_SPS},
},
}
for _, tc := range testCases {
got := FindNaluTypes(tc.input)
if diff := deep.Equal(got, tc.wanted); diff != nil {
t.Errorf("%s: %v", tc.name, diff)
}
for _, w := range tc.wanted {
if !ContainsNaluType(tc.input, w) {
t.Errorf("%s: wanted %v in %v", tc.name, w, tc.input)
}
if w == NALU_IDR && !IsIDRSample(tc.input) {
t.Errorf("%s: wanted IDR in %v", tc.name, tc.input)
}
}
}
}
func TestNaluTypeStrings(t *testing.T) {
named := make([]int, 0, 9)
for i := 0; i < 14; i++ {
nt := NaluType(i)
if !strings.HasPrefix(nt.String(), "Other") {
named = append(named, i)
}
}
if len(named) != 9 {
t.Errorf("Expected 9 named NaluTypes, got %d", len(named))
}
}
func TestHasParameterSets(t *testing.T) {
testCases := []struct {
name string
input []byte
wanted bool
}{
{
"Only IDR",
[]byte{0, 0, 0, 2, 5, 0},
false,
},
{
"AUD, SPS, PPS, IDRx2",
[]byte{0, 0, 0, 2, 9, 2,
0, 0, 0, 3, 7, 5, 4,
0, 0, 0, 3, 8, 1, 2,
0, 0, 0, 2, 5, 0,
0, 0, 0, 2, 5, 0},
true,
},
}
for _, tc := range testCases {
got := HasParameterSets(tc.input)
if got != tc.wanted {
t.Errorf("%s: got %t instead of %t", tc.name, got, tc.wanted)
}
}
}
func TestGetParameterSets(t *testing.T) {
testCases := []struct {
name string
input []byte
wantedSPS [][]byte
wantedPPS [][]byte
}{
{
"Only IDR",
[]byte{0, 0, 0, 2, 5, 0},
nil, nil,
},
{
"AUD, SPS, PPS, IDRx2",
[]byte{0, 0, 0, 2, 9, 2,
0, 0, 0, 3, 7, 5, 4,
0, 0, 0, 3, 8, 1, 2,
0, 0, 0, 2, 5, 0,
0, 0, 0, 2, 5, 0},
[][]byte{{7, 5, 4}},
[][]byte{{8, 1, 2}},
},
}
for _, tc := range testCases {
gotSPS, gotPPS := GetParameterSets(tc.input)
if diff := deep.Equal(gotSPS, tc.wantedSPS); diff != nil {
t.Errorf("%s: %v", tc.name, diff)
}
if diff := deep.Equal(gotPPS, tc.wantedPPS); diff != nil {
t.Errorf("%s: %v", tc.name, diff)
}
}
}
func TestIsVideoNaluType(t *testing.T) {
testCases := []struct {
name string
naluType NaluType
want bool
}{
{
name: "video type - NALU_NON_IDR (1)",
naluType: NALU_NON_IDR,
want: true,
},
{
name: "video type - NALU_IDR (5)",
naluType: NALU_IDR,
want: true,
},
{
name: "non-video type - NALU_SEI (6)",
naluType: NALU_SEI,
want: false,
},
{
name: "non-video type - NALU_SPS (7)",
naluType: NALU_SPS,
want: false,
},
{
name: "non-video type - NALU_AUD (9)",
naluType: NALU_AUD,
want: false,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
got := IsVideoNaluType(tc.naluType)
if got != tc.want {
t.Errorf("IsVideoNaluType(%d) = %v; want %v", tc.naluType, got, tc.want)
}
})
}
}