-
Notifications
You must be signed in to change notification settings - Fork 2
/
sdt_test.go
178 lines (160 loc) · 5.58 KB
/
sdt_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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package mpegts
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestSDT_Decode(t *testing.T) {
assert := assert.New(t)
data := []byte{
0x42, 0xF0, 0x27, 0x42, 0x72, 0xDD, 0x00, 0x00,
0x00, 0x00, 0xFF, 0x04, 0x38, 0xFF, 0x80, 0x16,
0x48, 0x14, 0x16, 0x05, 0x01, 0xC0, 0xC2, 0xC0,
0xC1, 0x0C, 0x01, 0x30, 0x38, 0x20, 0xBA, 0xB0,
0xC0, 0xC3, 0xC1, 0xB5, 0xBB, 0xCC, 0x48, 0x2C,
0x39, 0xB0,
}
sdt := new(SDT)
if err := sdt.ParseSdtSection(data); !assert.NoError(err) {
return
}
assert.True(sdt.Actual())
assert.Equal(uint8(14), sdt.Version())
assert.Equal(uint16(17010), sdt.TSID())
assert.Equal(uint16(0), sdt.ONID())
assert.Equal(1, len(sdt.Items))
item := sdt.Items[0]
assert.Equal(uint16(1080), item.ServiceID())
assert.Equal(true, item.IsPresentFollowing())
assert.Equal(true, item.IsSchedule())
assert.Equal(false, item.IsScrambled())
assert.Equal(uint8(0x04), item.RunningStatus())
desc := Descriptors{
0x48, 0x14, 0x16, 0x05, 0x01, 0xC0, 0xC2, 0xC0,
0xC1, 0x0C, 0x01, 0x30, 0x38, 0x20, 0xBA, 0xB0,
0xC0, 0xC3, 0xC1, 0xB5, 0xBB, 0xCC,
}
assert.Equal(desc, item.Descriptors())
}
func TestSDT_Packetize(t *testing.T) {
assert := assert.New(t)
// OC3.demo.ts
expectedTS := []TS{
{
0x47, 0x40, 0x11, 0x10, 0x00, 0x42, 0xF0, 0xD5, 0x00, 0x01, 0xC3, 0x00,
0x00, 0x00, 0x01, 0xFF, 0x00, 0x01, 0xFD, 0x80, 0x1D, 0x48, 0x1B, 0x01,
0x06, 0x41, 0x76, 0x61, 0x6C, 0x70, 0x61, 0x12, 0x41, 0x76, 0x61, 0x6C,
0x70, 0x61, 0x31, 0x3A, 0x20, 0x4D, 0x50, 0x45, 0x47, 0x32, 0x20, 0x4D,
0x48, 0x50, 0x00, 0x02, 0xFD, 0x80, 0x1F, 0x48, 0x1D, 0x01, 0x06, 0x41,
0x76, 0x61, 0x6C, 0x70, 0x61, 0x14, 0x41, 0x76, 0x61, 0x6C, 0x70, 0x61,
0x32, 0x3A, 0x20, 0x4D, 0x50, 0x45, 0x47, 0x32, 0x20, 0x4D, 0x48, 0x45,
0x47, 0x35, 0x00, 0x03, 0xFD, 0x80, 0x1F, 0x48, 0x1D, 0x01, 0x06, 0x41,
0x76, 0x61, 0x6C, 0x70, 0x61, 0x14, 0x41, 0x76, 0x61, 0x6C, 0x70, 0x61,
0x33, 0x3A, 0x20, 0x4D, 0x50, 0x45, 0x47, 0x32, 0x20, 0x48, 0x42, 0x42,
0x54, 0x56, 0x00, 0x04, 0xFD, 0x80, 0x1D, 0x48, 0x1B, 0x01, 0x06, 0x41,
0x76, 0x61, 0x6C, 0x70, 0x61, 0x12, 0x41, 0x76, 0x61, 0x6C, 0x70, 0x61,
0x34, 0x3A, 0x20, 0x4D, 0x50, 0x45, 0x47, 0x32, 0x20, 0x54, 0x58, 0x54,
0x00, 0x05, 0xFD, 0x80, 0x18, 0x48, 0x16,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F, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
},
}
sdt := NewSdt()
sdt.SetVersion(1)
sdt.SetTSID(1)
sdt.SetONID(1)
items := []struct {
service_id uint16
desc Descriptors
}{
{
service_id: 1,
desc: Descriptors{
0x48, 0x1B, 0x01, 0x06, 0x41, 0x76, 0x61, 0x6C,
0x70, 0x61, 0x12, 0x41, 0x76, 0x61, 0x6C, 0x70,
0x61, 0x31, 0x3A, 0x20, 0x4D, 0x50, 0x45, 0x47,
0x32, 0x20, 0x4D, 0x48, 0x50,
},
},
{
service_id: 2,
desc: Descriptors{
0x48, 0x1D, 0x01, 0x06, 0x41, 0x76, 0x61, 0x6C,
0x70, 0x61, 0x14, 0x41, 0x76, 0x61, 0x6C, 0x70,
0x61, 0x32, 0x3A, 0x20, 0x4D, 0x50, 0x45, 0x47,
0x32, 0x20, 0x4D, 0x48, 0x45, 0x47, 0x35,
},
},
{
service_id: 3,
desc: Descriptors{
0x48, 0x1D, 0x01, 0x06, 0x41, 0x76, 0x61, 0x6C,
0x70, 0x61, 0x14, 0x41, 0x76, 0x61, 0x6C, 0x70,
0x61, 0x33, 0x3A, 0x20, 0x4D, 0x50, 0x45, 0x47,
0x32, 0x20, 0x48, 0x42, 0x42, 0x54, 0x56,
},
},
{
service_id: 4,
desc: Descriptors{
0x48, 0x1B, 0x01, 0x06, 0x41, 0x76, 0x61, 0x6C,
0x70, 0x61, 0x12, 0x41, 0x76, 0x61, 0x6C, 0x70,
0x61, 0x34, 0x3A, 0x20, 0x4D, 0x50, 0x45, 0x47,
0x32, 0x20, 0x54, 0x58, 0x54,
},
},
{
service_id: 5,
desc: Descriptors{
0x48, 0x16, 0x16, 0x06, 0x41, 0x76, 0x61, 0x6C,
0x70, 0x61, 0x0D, 0x41, 0x76, 0x61, 0x6C, 0x70,
0x61, 0x35, 0x3A, 0x20, 0x48, 0x32, 0x36, 0x34,
},
},
{
service_id: 6,
desc: Descriptors{
0x48, 0x19, 0x19, 0x06, 0x41, 0x76, 0x61, 0x6C,
0x70, 0x61, 0x10, 0x41, 0x76, 0x61, 0x6C, 0x70,
0x61, 0x36, 0x3A, 0x20, 0x48, 0x44, 0x20, 0x48,
0x32, 0x36, 0x34,
},
},
}
for _, item := range items {
sdtItem := NewSdtItem()
sdtItem.SetServiceID(item.service_id)
sdtItem.SetSchedule(false)
sdtItem.SetPresentFollowing(true)
sdtItem.SetRunningStatus(4)
sdtItem.SetScrambled(false)
sdtItem.AppendDescriptors(item.desc)
sdt.Items = append(sdt.Items, sdtItem)
}
sdt.Finalize()
//
counter := 0
ts := NewTS(17)
for p := sdt.Packetizer(); p.Next(ts); ts.IncrementCC() {
assert.Equal(expectedTS[counter], ts)
counter += 1
}
assert.Equal(2, counter)
}