threefive3 3.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- scte35/__init__.py +27 -0
- scte35/base.py +189 -0
- scte35/bitn.py +193 -0
- scte35/commands.py +326 -0
- scte35/crc.py +49 -0
- scte35/cue.py +456 -0
- scte35/descriptors.py +549 -0
- scte35/hls.py +1171 -0
- scte35/packetdata.py +39 -0
- scte35/section.py +194 -0
- scte35/segment.py +128 -0
- scte35/segmentation.py +71 -0
- scte35/sixfix.py +194 -0
- scte35/spare.py +12 -0
- scte35/stream.py +686 -0
- scte35/streamtypes.py +127 -0
- scte35/sxp.py +350 -0
- scte35/upids.py +403 -0
- scte35/version.py +6 -0
- scte35/xml.py +355 -0
- threefive3-3.0.1.data/scripts/scte35 +365 -0
- threefive3-3.0.1.dist-info/LICENSE +24 -0
- threefive3-3.0.1.dist-info/METADATA +261 -0
- threefive3-3.0.1.dist-info/RECORD +26 -0
- threefive3-3.0.1.dist-info/WHEEL +5 -0
- threefive3-3.0.1.dist-info/top_level.txt +1 -0
scte35/descriptors.py
ADDED
|
@@ -0,0 +1,549 @@
|
|
|
1
|
+
"""
|
|
2
|
+
SCTE35 Splice Descriptors
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from .bitn import BitBin
|
|
6
|
+
from .base import SCTE35Base
|
|
7
|
+
from .segmentation import table20, table22, dvb_table2
|
|
8
|
+
from .upids import upid_map
|
|
9
|
+
from .xml import Node
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def k_by_v(adict, avalue):
|
|
13
|
+
"""
|
|
14
|
+
dict key lookup by value
|
|
15
|
+
"""
|
|
16
|
+
flipped = {v: k for k, v in adict.items()}
|
|
17
|
+
return (None, flipped[avalue])[avalue in flipped]
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class SpliceDescriptor(SCTE35Base):
|
|
21
|
+
"""
|
|
22
|
+
SpliceDescriptor is the
|
|
23
|
+
base class for all splice descriptors.
|
|
24
|
+
It should not be used directly
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
def __init__(self, bites=None):
|
|
28
|
+
|
|
29
|
+
self.tag = None
|
|
30
|
+
self.identifier = "CUEI"
|
|
31
|
+
self.name = None
|
|
32
|
+
self.bites = bites
|
|
33
|
+
self.parse_tag_and_len()
|
|
34
|
+
self.parse_id()
|
|
35
|
+
self.private_data = None
|
|
36
|
+
|
|
37
|
+
def parse_tag_and_len(self):
|
|
38
|
+
"""
|
|
39
|
+
parse_tag_and_len
|
|
40
|
+
parses the descriptors tag and length
|
|
41
|
+
from self.bites
|
|
42
|
+
"""
|
|
43
|
+
if self.bites:
|
|
44
|
+
self.tag = self.bites[0]
|
|
45
|
+
self.descriptor_length = self.bites[1]
|
|
46
|
+
self.bites = self.bites[2:]
|
|
47
|
+
|
|
48
|
+
def parse_id(self):
|
|
49
|
+
"""
|
|
50
|
+
parse splice descriptor identifier
|
|
51
|
+
"""
|
|
52
|
+
if self.bites:
|
|
53
|
+
self.identifier = self.bites[:4].decode()
|
|
54
|
+
# disabled for ffmv30
|
|
55
|
+
# if self.identifier != "CUEI":
|
|
56
|
+
# raise Exception('Identifier Is Not "CUEI"')
|
|
57
|
+
self.bites = self.bites[4:]
|
|
58
|
+
|
|
59
|
+
def decode(self):
|
|
60
|
+
"""
|
|
61
|
+
decode handles Private Descriptors
|
|
62
|
+
"""
|
|
63
|
+
self.private_data = self.bites.decode()
|
|
64
|
+
if isinstance(self.private_data, bytes):
|
|
65
|
+
self.private_data = self.bites.decode()
|
|
66
|
+
|
|
67
|
+
def encode(self, nbin=None):
|
|
68
|
+
"""
|
|
69
|
+
SpliceDescriptor.encode
|
|
70
|
+
"""
|
|
71
|
+
nbin = self._chk_nbin(nbin)
|
|
72
|
+
self._encode_id(nbin)
|
|
73
|
+
if self.private_data:
|
|
74
|
+
if isinstance(self.private_data, str):
|
|
75
|
+
self.private_data = self.private_data.encode()
|
|
76
|
+
nbin.add_bites(self.private_data)
|
|
77
|
+
if self.tag in descriptor_map:
|
|
78
|
+
return nbin
|
|
79
|
+
return nbin.bites
|
|
80
|
+
|
|
81
|
+
def _encode_id(self, nbin):
|
|
82
|
+
"""
|
|
83
|
+
parse splice descriptor identifier
|
|
84
|
+
"""
|
|
85
|
+
# self.identifier = "CUEI"
|
|
86
|
+
id_int = int.from_bytes(self.identifier.encode(), byteorder="big")
|
|
87
|
+
nbin.add_int(id_int, 32)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
class DVBDASDescriptor(SpliceDescriptor):
|
|
91
|
+
"""
|
|
92
|
+
Experimental DVB Descriptor Support
|
|
93
|
+
"""
|
|
94
|
+
|
|
95
|
+
def __init__(self, bites=None):
|
|
96
|
+
super().__init__(bites)
|
|
97
|
+
self.tag = 240 # 0xf0
|
|
98
|
+
self.name = "DVD DAS Descriptor"
|
|
99
|
+
self.identifier = "DVB_"
|
|
100
|
+
self.break_num = 0
|
|
101
|
+
self.breaks_expected = 0
|
|
102
|
+
self.equivalent_segmentation_type = None
|
|
103
|
+
self.equivalent_segmentation_message = None
|
|
104
|
+
self.upid_type = 0x0F
|
|
105
|
+
self.upid_type_name = None
|
|
106
|
+
self.upid_length = None
|
|
107
|
+
self.upid = None
|
|
108
|
+
|
|
109
|
+
def decode(self):
|
|
110
|
+
"""
|
|
111
|
+
Decode DVB DAS Descriptor
|
|
112
|
+
"""
|
|
113
|
+
bitbin = BitBin(self.bites)
|
|
114
|
+
self.break_num = bitbin.as_int(8)
|
|
115
|
+
self.breaks_expected = bitbin.as_int(8)
|
|
116
|
+
bitbin.forward(4)
|
|
117
|
+
self.equivalent_segmentation_type = bitbin.as_int(4)
|
|
118
|
+
if self.equivalent_segmentation_type in dvb_table2:
|
|
119
|
+
self.equivalent_segmentation_message = dvb_table2[
|
|
120
|
+
self.equivalent_segmentation_type
|
|
121
|
+
]
|
|
122
|
+
self.upid_length = len(self.bites) - 3
|
|
123
|
+
the_upid = upid_map[self.upid_type][1](bitbin, self.upid_type, self.upid_length)
|
|
124
|
+
self.upid_type_name, self.upid = the_upid.decode()
|
|
125
|
+
|
|
126
|
+
def encode(self, nbin=None):
|
|
127
|
+
"""
|
|
128
|
+
encode DVB DAS Descriptor
|
|
129
|
+
"""
|
|
130
|
+
nbin = super().encode(nbin)
|
|
131
|
+
nbin.add_int(self.break_num, 8)
|
|
132
|
+
nbin.add_int(self.breaks_expected, 8)
|
|
133
|
+
nbin.forward(4)
|
|
134
|
+
nbin.add_int(self.equivalent_segmentation_type, 4)
|
|
135
|
+
the_upid = upid_map[self.upid_type][1](None, self.upid_type, self.upid_length)
|
|
136
|
+
the_upid.encode(nbin, self.upid)
|
|
137
|
+
return nbin.bites
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
class AvailDescriptor(SpliceDescriptor):
|
|
141
|
+
"""
|
|
142
|
+
Table 17 - avail_descriptor()
|
|
143
|
+
"""
|
|
144
|
+
|
|
145
|
+
def __init__(self, bites=None):
|
|
146
|
+
super().__init__(bites)
|
|
147
|
+
self.name = "Avail Descriptor"
|
|
148
|
+
self.tag = 0
|
|
149
|
+
self.provider_avail_id = None
|
|
150
|
+
|
|
151
|
+
def decode(self):
|
|
152
|
+
"""
|
|
153
|
+
decode SCTE35 Avail Descriptor
|
|
154
|
+
"""
|
|
155
|
+
bitbin = BitBin(self.bites)
|
|
156
|
+
self.provider_avail_id = bitbin.as_int(32)
|
|
157
|
+
|
|
158
|
+
def encode(self, nbin=None):
|
|
159
|
+
"""
|
|
160
|
+
encode SCTE35 Avail Descriptor
|
|
161
|
+
"""
|
|
162
|
+
nbin = super().encode(nbin)
|
|
163
|
+
self._chk_var(int, nbin.add_int, "provider_avail_id", 32)
|
|
164
|
+
return nbin.bites
|
|
165
|
+
|
|
166
|
+
def xml(self, ns="scte35"):
|
|
167
|
+
"""
|
|
168
|
+
Create a Node describing the AvailDescriptor
|
|
169
|
+
"""
|
|
170
|
+
ad = Node(
|
|
171
|
+
"AvailDescriptor", attrs={"providerAvailId": self.provider_avail_id}, ns=ns
|
|
172
|
+
)
|
|
173
|
+
return ad
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
class DtmfDescriptor(SpliceDescriptor):
|
|
177
|
+
"""
|
|
178
|
+
Table 18 - DTMF_descriptor()
|
|
179
|
+
"""
|
|
180
|
+
|
|
181
|
+
def __init__(self, bites=None):
|
|
182
|
+
super().__init__(bites)
|
|
183
|
+
self.name = "DTMF Descriptor"
|
|
184
|
+
self.tag = 1
|
|
185
|
+
self.preroll = None
|
|
186
|
+
self.dtmf_count = 0
|
|
187
|
+
self.dtmf_chars = None
|
|
188
|
+
|
|
189
|
+
def decode(self):
|
|
190
|
+
"""
|
|
191
|
+
decode SCTE35 Dtmf Descriptor
|
|
192
|
+
"""
|
|
193
|
+
self.preroll = self.bites[0]
|
|
194
|
+
self.dtmf_count = self.bites[1] >> 5
|
|
195
|
+
self.bites = self.bites[2:]
|
|
196
|
+
self.dtmf_chars = list(self.bites[: self.dtmf_count].decode())
|
|
197
|
+
|
|
198
|
+
def encode(self, nbin=None):
|
|
199
|
+
"""
|
|
200
|
+
encode SCTE35 Dtmf Descriptor
|
|
201
|
+
"""
|
|
202
|
+
nbin = super().encode(nbin)
|
|
203
|
+
self._chk_var(int, nbin.add_int, "preroll", 8)
|
|
204
|
+
d_c = 0
|
|
205
|
+
self._chk_var(int, nbin.add_int, "dtmf_count", 3)
|
|
206
|
+
nbin.forward(5)
|
|
207
|
+
while d_c < self.dtmf_count:
|
|
208
|
+
nbin.add_int(ord(self.dtmf_chars[d_c]), 8)
|
|
209
|
+
d_c += 1
|
|
210
|
+
return nbin.bites
|
|
211
|
+
|
|
212
|
+
def xml(self, ns="scte35"):
|
|
213
|
+
"""
|
|
214
|
+
Create a Node describing a DTMFDescriptor
|
|
215
|
+
"""
|
|
216
|
+
dd = Node(
|
|
217
|
+
"DTMFDescriptor",
|
|
218
|
+
attrs={
|
|
219
|
+
"preroll": self.preroll,
|
|
220
|
+
"chars": "".join(self.dtmf_chars),
|
|
221
|
+
},
|
|
222
|
+
ns=ns,
|
|
223
|
+
)
|
|
224
|
+
return dd
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
## def from_xml(self, gonzo):
|
|
228
|
+
## """
|
|
229
|
+
## Load an DTMFDescriptor from XML
|
|
230
|
+
## """
|
|
231
|
+
## if "DTMFDescriptor" in gonzo:
|
|
232
|
+
## gonzo["DTMFDescriptor"]["dtmf_chars"] = gonzo["DTMFDescriptor"].pop("chars")
|
|
233
|
+
## self.load(gonzo["DTMFDescriptor"])
|
|
234
|
+
## self.dtmf_count = len(self.dtmf_chars)
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
class TimeDescriptor(SpliceDescriptor):
|
|
238
|
+
"""
|
|
239
|
+
Table 25 - time_descriptor()
|
|
240
|
+
"""
|
|
241
|
+
|
|
242
|
+
def __init__(self, bites=None):
|
|
243
|
+
super().__init__(bites)
|
|
244
|
+
self.tag = 3
|
|
245
|
+
self.name = "Time Descriptor"
|
|
246
|
+
self.tai_seconds = 0
|
|
247
|
+
self.tai_ns = 0
|
|
248
|
+
self.utc_offset = 0
|
|
249
|
+
|
|
250
|
+
def decode(self):
|
|
251
|
+
"""
|
|
252
|
+
decode SCTE35 Time Descriptor
|
|
253
|
+
"""
|
|
254
|
+
bitbin = BitBin(self.bites)
|
|
255
|
+
self.tai_seconds = bitbin.as_int(48)
|
|
256
|
+
self.tai_ns = bitbin.as_int(32)
|
|
257
|
+
self.utc_offset = bitbin.as_int(16)
|
|
258
|
+
|
|
259
|
+
def encode(self, nbin=None):
|
|
260
|
+
"""
|
|
261
|
+
encode SCTE35 Time Descriptor
|
|
262
|
+
"""
|
|
263
|
+
nbin = super().encode(nbin)
|
|
264
|
+
self._chk_var(int, nbin.add_int, "tai_seconds", 48)
|
|
265
|
+
self._chk_var(int, nbin.add_int, "tai_ns", 32)
|
|
266
|
+
self._chk_var(int, nbin.add_int, "utc_offset", 16)
|
|
267
|
+
return nbin.bites
|
|
268
|
+
|
|
269
|
+
def xml(self, ns="scte35"):
|
|
270
|
+
"""
|
|
271
|
+
create a Node describing a TimeDescriptor
|
|
272
|
+
"""
|
|
273
|
+
td = Node(
|
|
274
|
+
"TimeDescriptor",
|
|
275
|
+
attrs={
|
|
276
|
+
"tai_seconds": self.tai_seconds,
|
|
277
|
+
"tai_ns": self.tai_ns,
|
|
278
|
+
"utc_offset": self.utc_offset,
|
|
279
|
+
},
|
|
280
|
+
ns=ns,
|
|
281
|
+
)
|
|
282
|
+
return td
|
|
283
|
+
|
|
284
|
+
class SegmentationDescriptor(SpliceDescriptor):
|
|
285
|
+
"""
|
|
286
|
+
Table 19 - segmentation_descriptor()
|
|
287
|
+
"""
|
|
288
|
+
|
|
289
|
+
SUB_SEG_TYPES = [
|
|
290
|
+
0x30,
|
|
291
|
+
0x32,
|
|
292
|
+
0x34,
|
|
293
|
+
0x36,
|
|
294
|
+
0x38,
|
|
295
|
+
0x3A,
|
|
296
|
+
0x44,
|
|
297
|
+
0x46,
|
|
298
|
+
]
|
|
299
|
+
|
|
300
|
+
def __init__(self, bites=None):
|
|
301
|
+
super().__init__(bites)
|
|
302
|
+
self.tag = 2
|
|
303
|
+
self.name = "Segmentation Descriptor"
|
|
304
|
+
self.segmentation_event_cancel_indicator = None
|
|
305
|
+
self.segmentation_event_id = None
|
|
306
|
+
self.segmentation_event_id_compliance_indicator = None
|
|
307
|
+
self.program_segmentation_flag = None
|
|
308
|
+
self.segmentation_duration_flag = None
|
|
309
|
+
self.delivery_not_restricted_flag = None
|
|
310
|
+
self.web_delivery_allowed_flag = None
|
|
311
|
+
self.no_regional_blackout_flag = None
|
|
312
|
+
self.archive_allowed_flag = None
|
|
313
|
+
self.device_restrictions = None
|
|
314
|
+
self.segmentation_duration = None
|
|
315
|
+
self.segmentation_message = None
|
|
316
|
+
self.segmentation_type_id = None
|
|
317
|
+
self.segmentation_upid_length = None
|
|
318
|
+
self.segmentation_upid_type = None
|
|
319
|
+
self.segmentation_upid_type_name = None
|
|
320
|
+
self.segmentation_upid = None
|
|
321
|
+
self.segment_num = None
|
|
322
|
+
self.segments_expected = None
|
|
323
|
+
self.sub_segment_num = None
|
|
324
|
+
self.sub_segments_expected = None
|
|
325
|
+
|
|
326
|
+
def decode(self):
|
|
327
|
+
"""
|
|
328
|
+
decode a segmentation descriptor
|
|
329
|
+
"""
|
|
330
|
+
bitbin = BitBin(self.bites)
|
|
331
|
+
self.segmentation_event_id = bitbin.as_hex(32)
|
|
332
|
+
self.segmentation_event_cancel_indicator = bitbin.as_flag(1)
|
|
333
|
+
self.segmentation_event_id_compliance_indicator = bitbin.as_flag(1)
|
|
334
|
+
bitbin.forward(6)
|
|
335
|
+
if not self.segmentation_event_cancel_indicator:
|
|
336
|
+
self._decode_flags(bitbin)
|
|
337
|
+
self._decode_segmentation(bitbin)
|
|
338
|
+
|
|
339
|
+
def _decode_flags(self, bitbin):
|
|
340
|
+
self.program_segmentation_flag = bitbin.as_flag(1)
|
|
341
|
+
self.segmentation_duration_flag = bitbin.as_flag(1)
|
|
342
|
+
self.delivery_not_restricted_flag = bitbin.as_flag(1)
|
|
343
|
+
if not self.delivery_not_restricted_flag:
|
|
344
|
+
self.web_delivery_allowed_flag = bitbin.as_flag(1)
|
|
345
|
+
self.no_regional_blackout_flag = bitbin.as_flag(1)
|
|
346
|
+
self.archive_allowed_flag = bitbin.as_flag(1)
|
|
347
|
+
self.device_restrictions = table20[bitbin.as_int(2)]
|
|
348
|
+
else:
|
|
349
|
+
bitbin.forward(5)
|
|
350
|
+
|
|
351
|
+
def _decode_segmentation(self, bitbin):
|
|
352
|
+
if self.segmentation_duration_flag:
|
|
353
|
+
segmentation_duration_ticks = bitbin.as_int(40)
|
|
354
|
+
self.segmentation_duration = self.as_90k(segmentation_duration_ticks)
|
|
355
|
+
self.segmentation_upid_type = bitbin.as_int(8)
|
|
356
|
+
self.segmentation_upid_length = bitbin.as_int(8)
|
|
357
|
+
the_upid = self.mk_the_upid(bitbin)
|
|
358
|
+
self.segmentation_upid_type_name, self.segmentation_upid = the_upid.decode()
|
|
359
|
+
self.segmentation_type_id = bitbin.as_int(8)
|
|
360
|
+
if self.segmentation_type_id in table22:
|
|
361
|
+
self.segmentation_message = table22[self.segmentation_type_id]
|
|
362
|
+
self._decode_segments(bitbin)
|
|
363
|
+
|
|
364
|
+
def _chk_sub_segments(self):
|
|
365
|
+
"""
|
|
366
|
+
chk_sub_segments sets sub_segment vars if not present
|
|
367
|
+
"""
|
|
368
|
+
if self.segmentation_type_id in self.SUB_SEG_TYPES:
|
|
369
|
+
if not self.sub_segment_num:
|
|
370
|
+
self.sub_segment_num = 0
|
|
371
|
+
self.sub_segments_expected = 0
|
|
372
|
+
|
|
373
|
+
def _decode_segments(self, bitbin):
|
|
374
|
+
self.segment_num = bitbin.as_int(8)
|
|
375
|
+
self.segments_expected = bitbin.as_int(8)
|
|
376
|
+
if self.segmentation_type_id in self.SUB_SEG_TYPES:
|
|
377
|
+
# if sub_segment_num and sub_segments_expected
|
|
378
|
+
# are not available set both of them to zero
|
|
379
|
+
try:
|
|
380
|
+
self.sub_segment_num = bitbin.as_int(8)
|
|
381
|
+
self.sub_segments_expected = bitbin.as_int(8)
|
|
382
|
+
finally:
|
|
383
|
+
self._chk_sub_segments()
|
|
384
|
+
|
|
385
|
+
def encode(self, nbin=None):
|
|
386
|
+
"""
|
|
387
|
+
encode a segmentation descriptor
|
|
388
|
+
"""
|
|
389
|
+
nbin = super().encode(nbin)
|
|
390
|
+
self._chk_var(str, nbin.add_hex, "segmentation_event_id", 32)
|
|
391
|
+
self._chk_var(bool, nbin.add_flag, "segmentation_event_cancel_indicator", 1)
|
|
392
|
+
self._chk_var(
|
|
393
|
+
bool, nbin.add_flag, "segmentation_event_id_compliance_indicator", 1
|
|
394
|
+
)
|
|
395
|
+
nbin.forward(6)
|
|
396
|
+
if not self.segmentation_event_cancel_indicator:
|
|
397
|
+
self._encode_flags(nbin)
|
|
398
|
+
|
|
399
|
+
self._encode_segmentation(nbin)
|
|
400
|
+
return nbin.bites
|
|
401
|
+
|
|
402
|
+
def _encode_flags(self, nbin):
|
|
403
|
+
self._chk_var(bool, nbin.add_flag, "program_segmentation_flag", 1)
|
|
404
|
+
self._chk_var(bool, nbin.add_flag, "segmentation_duration_flag", 1)
|
|
405
|
+
self._chk_var(bool, nbin.add_flag, "delivery_not_restricted_flag", 1)
|
|
406
|
+
if not self.delivery_not_restricted_flag:
|
|
407
|
+
self._chk_var(bool, nbin.add_flag, "web_delivery_allowed_flag", 1)
|
|
408
|
+
self._chk_var(bool, nbin.add_flag, "no_regional_blackout_flag", 1)
|
|
409
|
+
self._chk_var(bool, nbin.add_flag, "archive_allowed_flag", 1)
|
|
410
|
+
a_key = k_by_v(table20, self.device_restrictions)
|
|
411
|
+
nbin.add_int(a_key, 2)
|
|
412
|
+
else:
|
|
413
|
+
nbin.reserve(5)
|
|
414
|
+
|
|
415
|
+
def mk_the_upid(self, bitbin=None):
|
|
416
|
+
"""
|
|
417
|
+
mk_the_upid create a upid instance
|
|
418
|
+
and return it. the bitbin arg is only
|
|
419
|
+
used in decode()
|
|
420
|
+
"""
|
|
421
|
+
upid_type = self.segmentation_upid_type
|
|
422
|
+
if upid_type not in upid_map:
|
|
423
|
+
upid_type = 0xFD
|
|
424
|
+
the_upid = upid_map[upid_type][1](
|
|
425
|
+
bitbin, upid_type, self.segmentation_upid_length
|
|
426
|
+
)
|
|
427
|
+
return the_upid
|
|
428
|
+
|
|
429
|
+
def _encode_segmentation(self, nbin):
|
|
430
|
+
if self.segmentation_duration_flag:
|
|
431
|
+
nbin.add_int(self.as_ticks(self.segmentation_duration), 40)
|
|
432
|
+
self._chk_var(int, nbin.add_int, "segmentation_upid_type", 8)
|
|
433
|
+
self._chk_var(int, nbin.add_int, "segmentation_upid_length", 8)
|
|
434
|
+
upid_type = self.segmentation_upid_type
|
|
435
|
+
if upid_type not in upid_map:
|
|
436
|
+
upid_type = 0xFD
|
|
437
|
+
the_upid = upid_map[upid_type][1](
|
|
438
|
+
None, upid_type, self.segmentation_upid_length
|
|
439
|
+
)
|
|
440
|
+
the_upid.encode(nbin, self.segmentation_upid)
|
|
441
|
+
self._chk_var(int, nbin.add_int, "segmentation_type_id", 8)
|
|
442
|
+
self._encode_segments(nbin)
|
|
443
|
+
|
|
444
|
+
def _encode_segments(self, nbin):
|
|
445
|
+
self._chk_var(int, nbin.add_int, "segment_num", 8)
|
|
446
|
+
self._chk_var(int, nbin.add_int, "segments_expected", 8)
|
|
447
|
+
if self.segmentation_type_id in [
|
|
448
|
+
0x30,
|
|
449
|
+
0x32,
|
|
450
|
+
0x34,
|
|
451
|
+
0x36,
|
|
452
|
+
0x38,
|
|
453
|
+
0x3A,
|
|
454
|
+
0x44,
|
|
455
|
+
0x46,
|
|
456
|
+
]:
|
|
457
|
+
try:
|
|
458
|
+
self._chk_var(int, nbin.add_int, "sub_segment_num", 8)
|
|
459
|
+
self._chk_var(int, nbin.add_int, "sub_segments_expected", 8)
|
|
460
|
+
except:
|
|
461
|
+
nbin.add_int(0, 8)
|
|
462
|
+
nbin.add_int(0, 8)
|
|
463
|
+
|
|
464
|
+
def _xml_sub_segs(self, sd_attrs):
|
|
465
|
+
if self.segmentation_type_id in self.SUB_SEG_TYPES:
|
|
466
|
+
sd_attrs["sub_segment_num"] = self.sub_segment_num
|
|
467
|
+
sd_attrs["sub_segments_expected"] = self.sub_segments_expected
|
|
468
|
+
if self.segmentation_duration_flag:
|
|
469
|
+
sd_attrs["segmentation_duration"] = self.as_ticks(
|
|
470
|
+
self.segmentation_duration
|
|
471
|
+
)
|
|
472
|
+
return sd_attrs
|
|
473
|
+
|
|
474
|
+
def xml(self, ns="scte35"):
|
|
475
|
+
"""
|
|
476
|
+
Create a Node describing a SegmentationDescriptor
|
|
477
|
+
"""
|
|
478
|
+
sd_attrs = {
|
|
479
|
+
"segmentation_event_id": int(self.segmentation_event_id, 0),
|
|
480
|
+
"segmentation_event_cancel_indicator": self.segmentation_event_cancel_indicator,
|
|
481
|
+
"segmentation_event_id_compliance_indicator": self.segmentation_event_id_compliance_indicator,
|
|
482
|
+
"segmentation_type_id": self.segmentation_type_id,
|
|
483
|
+
"segment_num": self.segment_num,
|
|
484
|
+
"segments_expected": self.segments_expected,
|
|
485
|
+
}
|
|
486
|
+
sd_attrs = self._xml_sub_segs(sd_attrs)
|
|
487
|
+
sd = Node("SegmentationDescriptor", attrs=sd_attrs, ns=ns)
|
|
488
|
+
the_upid = self.mk_the_upid()
|
|
489
|
+
the_upid.upid_value = self.segmentation_upid
|
|
490
|
+
upid_node = the_upid.xml(ns=ns)
|
|
491
|
+
if not self.delivery_not_restricted_flag:
|
|
492
|
+
dr_attrs = {
|
|
493
|
+
"web_delivery_allowed_flag": self.web_delivery_allowed_flag,
|
|
494
|
+
"no_regional_blackout_flag": self.no_regional_blackout_flag,
|
|
495
|
+
"archive_allowed_flag": self.archive_allowed_flag,
|
|
496
|
+
"device_restrictions": k_by_v(table20, self.device_restrictions),
|
|
497
|
+
}
|
|
498
|
+
dr = Node("DeliveryRestrictions", attrs=dr_attrs, ns=ns)
|
|
499
|
+
sd.add_child(dr)
|
|
500
|
+
comment = f"{upid_map[self.segmentation_upid_type][0]}"
|
|
501
|
+
sd.add_comment(comment)
|
|
502
|
+
if isinstance(upid_node, list):
|
|
503
|
+
for node in upid_node:
|
|
504
|
+
sd.add_child(node)
|
|
505
|
+
else:
|
|
506
|
+
sd.add_child(upid_node)
|
|
507
|
+
return sd
|
|
508
|
+
|
|
509
|
+
def xml_redecode(self):
|
|
510
|
+
"""
|
|
511
|
+
redecode is for decoding complex xml upids
|
|
512
|
+
before encoding to another format.
|
|
513
|
+
"""
|
|
514
|
+
seg_upid = self.segmentation_upid
|
|
515
|
+
if isinstance(seg_upid, str):
|
|
516
|
+
bites = b""
|
|
517
|
+
bitbin = None
|
|
518
|
+
try:
|
|
519
|
+
bites = bytes.fromhex(seg_upid)
|
|
520
|
+
except ValueError:
|
|
521
|
+
bites = seg_upid.encode()
|
|
522
|
+
bitbin = BitBin(bites)
|
|
523
|
+
self.segmentation_upid_length = len(bites)
|
|
524
|
+
the_upid = self.mk_the_upid(bitbin=bitbin)
|
|
525
|
+
self.segmentation_upid_type_name, self.segmentation_upid = the_upid.decode()
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
# map of known descriptors and associated classes
|
|
529
|
+
descriptor_map = {
|
|
530
|
+
0: AvailDescriptor,
|
|
531
|
+
1: DtmfDescriptor,
|
|
532
|
+
2: SegmentationDescriptor,
|
|
533
|
+
3: TimeDescriptor,
|
|
534
|
+
240: DVBDASDescriptor,
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
|
|
538
|
+
def splice_descriptor(bites):
|
|
539
|
+
"""
|
|
540
|
+
replaced splice_descriptor
|
|
541
|
+
"""
|
|
542
|
+
spliced = None
|
|
543
|
+
tag = bites[0]
|
|
544
|
+
if tag in descriptor_map:
|
|
545
|
+
spliced = descriptor_map[tag](bites)
|
|
546
|
+
else:
|
|
547
|
+
spliced = SpliceDescriptor(bites)
|
|
548
|
+
spliced.decode()
|
|
549
|
+
return spliced
|