-
Notifications
You must be signed in to change notification settings - Fork 86
/
avcdecoderconfig_test.go
65 lines (57 loc) · 1.67 KB
/
avcdecoderconfig_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
package avc
import (
"bytes"
"encoding/hex"
"os"
"testing"
"github.com/go-test/deep"
)
const avcDecoderConfigRecord = "0164001effe100196764001eacd940a02ff9610000030001000003003c8f162d9601000568ebecb22cfdf8f800"
const sps = "6764001eacd940a02ff9610000030001000003003c8f162d96"
const pps = "68ebecb22c"
func TestAvcDecoderConfigRecord(t *testing.T) {
byteData, _ := hex.DecodeString(avcDecoderConfigRecord)
spsBytes, _ := hex.DecodeString(sps)
ppsBytes, _ := hex.DecodeString(pps)
wanted := DecConfRec{
AVCProfileIndication: 100,
ProfileCompatibility: 0,
AVCLevelIndication: 30,
SPSnalus: [][]byte{spsBytes},
PPSnalus: [][]byte{ppsBytes},
ChromaFormat: 1,
BitDepthLumaMinus1: 0,
BitDepthChromaMinus1: 0,
NumSPSExt: 0,
}
got, err := DecodeAVCDecConfRec(byteData)
if err != nil {
t.Error("Error parsing AVCDecoderConfigurationRecord")
}
if diff := deep.Equal(got, wanted); diff != nil {
t.Error(diff)
}
enc := bytes.Buffer{}
err = got.Encode(&enc)
if err != nil {
t.Error("Error encoding AVCDecoderConfigurationRecord")
}
if !bytes.Equal(enc.Bytes(), byteData) {
t.Error("Error encoding AVCDecoderConfigurationRecord")
}
}
func TestCreateAVCDecConfRec(t *testing.T) {
data, err := os.ReadFile("testdata/blackframe.264")
if err != nil {
t.Error("Error reading file")
}
spss := ExtractNalusOfTypeFromByteStream(NALU_SPS, data, true)
ppss := ExtractNalusOfTypeFromByteStream(NALU_PPS, data, true)
if len(spss) != 1 || len(ppss) != 1 {
t.Error("Error extracting SPS/PPS")
}
_, err = CreateAVCDecConfRec(spss, ppss, true)
if err != nil {
t.Error("Error creating AVCDecoderConfigurationRecord")
}
}