-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathaac_test.go
107 lines (96 loc) · 2.32 KB
/
aac_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
package aac
import (
"bytes"
"encoding/hex"
"testing"
"github.com/go-test/deep"
)
func TestAudioSpecificConfigEncodeDecode(t *testing.T) {
testCases := []AudioSpecificConfig{
{
ObjectType: AAClc,
ChannelConfiguration: 2,
SamplingFrequency: 48000,
ExtensionFrequency: 0,
SBRPresentFlag: false,
PSPresentFlag: false,
},
{
ObjectType: HEAACv1,
ChannelConfiguration: 2,
SamplingFrequency: 24000,
ExtensionFrequency: 48000,
SBRPresentFlag: true,
PSPresentFlag: false,
},
{
ObjectType: HEAACv2,
ChannelConfiguration: 1,
SamplingFrequency: 24000,
ExtensionFrequency: 48000,
SBRPresentFlag: true,
PSPresentFlag: true,
},
}
for _, asc := range testCases {
buf := &bytes.Buffer{}
err := asc.Encode(buf)
if err != nil {
t.Error(err)
}
ascBytes := buf.Bytes()
t.Logf("ASC: %s\n", hex.EncodeToString(ascBytes))
readBuf := bytes.NewBuffer(ascBytes)
gotAsc, err := DecodeAudioSpecificConfig(readBuf)
if err != nil {
t.Error(err)
}
diff := deep.Equal(*gotAsc, asc)
if diff != nil {
t.Errorf("Diff %v for %+v", diff, asc)
}
}
}
func TestVariousInputs(t *testing.T) {
testCases := []struct {
desc string
data []byte
expectedError string
}{
{
desc: "unsupported object type",
data: []byte{0x0f, 0x00},
expectedError: "unsupported object type: 1",
},
{
desc: "bad frequency index",
data: []byte{0x17, 0x30},
expectedError: "strange frequency index",
},
{
desc: "too short extended frequency",
data: []byte{0x17, 0x80, 0x40},
expectedError: "strange frequency index",
},
}
for _, c := range testCases {
t.Run(c.desc, func(t *testing.T) {
readBuf := bytes.NewBuffer(c.data)
_, err := DecodeAudioSpecificConfig(readBuf)
if err == nil || err.Error() != c.expectedError {
t.Errorf("Expected error: %s", c.expectedError)
}
})
}
t.Run("32768Hz", func(t *testing.T) {
data := []byte{0x17, 0x80, 0x40, 0x00, 0x00}
readBuf := bytes.NewBuffer(data)
gotAsc, err := DecodeAudioSpecificConfig(readBuf)
if err != nil {
t.Error(err)
}
if gotAsc.SamplingFrequency != 32768 {
t.Errorf("Expected 32768Hz, got %d", gotAsc.SamplingFrequency)
}
})
}