-
Notifications
You must be signed in to change notification settings - Fork 50
/
data_pmt_test.go
73 lines (62 loc) · 1.91 KB
/
data_pmt_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
package astits
import (
"bytes"
"testing"
"github.com/asticode/go-astikit"
"github.com/stretchr/testify/assert"
)
var pmt = &PMTData{
ElementaryStreams: []*PMTElementaryStream{{
ElementaryPID: 2730,
ElementaryStreamDescriptors: descriptors,
StreamType: StreamTypeMPEG1Audio,
}},
PCRPID: 5461,
ProgramDescriptors: descriptors,
ProgramNumber: 1,
}
func pmtBytes() []byte {
buf := &bytes.Buffer{}
w := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: buf})
w.Write("111") // Reserved bits
w.Write("1010101010101") // PCR PID
w.Write("1111") // Reserved
descriptorsBytes(w) // Program descriptors
w.Write(uint8(StreamTypeMPEG1Audio)) // Stream #1 stream type
w.Write("111") // Stream #1 reserved
w.Write("0101010101010") // Stream #1 PID
w.Write("1111") // Stream #1 reserved
descriptorsBytes(w) // Stream #1 descriptors
return buf.Bytes()
}
func TestParsePMTSection(t *testing.T) {
var b = pmtBytes()
d, err := parsePMTSection(astikit.NewBytesIterator(b), len(b), uint16(1))
assert.Equal(t, d, pmt)
assert.NoError(t, err)
}
func TestWritePMTSection(t *testing.T) {
buf := bytes.Buffer{}
w := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: &buf})
n, err := writePMTSection(w, pmt)
assert.NoError(t, err)
assert.Equal(t, n, buf.Len())
assert.Equal(t, pmtBytes(), buf.Bytes())
}
func BenchmarkParsePMTSection(b *testing.B) {
b.ReportAllocs()
bs := pmtBytes()
for i := 0; i < b.N; i++ {
parsePMTSection(astikit.NewBytesIterator(bs), len(bs), uint16(1))
}
}
func BenchmarkWritePMTSection(b *testing.B) {
b.ReportAllocs()
bw := &bytes.Buffer{}
bw.Grow(1024)
w := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: bw})
for i := 0; i < b.N; i++ {
bw.Reset()
writePMTSection(w, pmt)
}
}