-
Notifications
You must be signed in to change notification settings - Fork 84
/
esds_test.go
67 lines (58 loc) · 1.78 KB
/
esds_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
package mp4
import (
"bytes"
"encoding/hex"
"testing"
"github.com/Eyevinn/mp4ff/bits"
)
const (
esdsProgIn = `00000036657364730000000003808080250002000480808017401500000000010d88000003f80580808005128856e500068080800102`
esdsMp4Box = `0000002a6573647300000000031c0000000414401500000000010d88000003f80505128856e500060102`
esdsEncAudio = `0000003365736473000000000380808022000000048080801440150018000003eb100002710005808080021190068080800102`
esdsLongEnd = `0000002f65736473000000000321000000041140150002440001ea940001ea94050212100680808080808080800102`
)
func TestEsdsEncodeAndDecode(t *testing.T) {
decCfg := []byte{0x11, 0x90}
esdsIn := CreateEsdsBox(decCfg)
// Write to a buffer so that we can read and check
var buf bytes.Buffer
err := esdsIn.Encode(&buf)
if err != nil {
t.Fatal(err)
}
// Read back from buffer
decodedBox, err := DecodeBox(0, &buf)
if err != nil {
t.Error("Did not get a box back")
}
esdsOut := decodedBox.(*EsdsBox)
decCfgOut := esdsOut.DecConfigDescriptor.DecSpecificInfo.DecConfig
if !bytes.Equal(decCfgOut, decCfg) {
t.Errorf("Decode cfg out %s differs from decode cfg in %s",
hex.EncodeToString(decCfgOut), hex.EncodeToString(decCfg))
}
boxDiffAfterEncodeAndDecode(t, esdsIn)
}
func TestDecodeEncodeEsds(t *testing.T) {
inputs := []string{esdsProgIn, esdsMp4Box, esdsEncAudio, esdsLongEnd}
for i, inp := range inputs {
data, err := hex.DecodeString(inp)
if err != nil {
t.Error(err)
}
sr := bits.NewFixedSliceReader(data)
esds, err := DecodeBoxSR(0, sr)
if err != nil {
t.Error(err)
}
out := make([]byte, len(data))
sw := bits.NewFixedSliceWriterFromSlice(out)
err = esds.EncodeSW(sw)
if err != nil {
t.Error(err)
}
if !bytes.Equal(sw.Bytes(), data) {
t.Errorf("case %d does not reproduce esds", i)
}
}
}