Skip to content

Commit a08e996

Browse files
authored
Merge branch 'main' into juli/decode-from-bytes
2 parents 98679a9 + 7d0d3f5 commit a08e996

File tree

1 file changed

+145
-124
lines changed

1 file changed

+145
-124
lines changed

README.md

Lines changed: 145 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ The results can be output as a:
3636
* XML - compliant with the [SCTE 35 XML Schema](./docs/scte_35_20220816.xsd)
3737
* JSON - for integrating with JSON based tools such as [jq](https://stedolan.github.io/jq/)
3838

39-
[decode.go](../examples/decode.go)
39+
[examples/simple_decode/main.go](examples/simple_decode/main.go)
4040

4141
```go
4242
package main
@@ -54,7 +54,7 @@ func main() {
5454
sis, _ := scte35.DecodeBase64("/DA8AAAAAAAAAP///wb+06ACpQAmAiRDVUVJAACcHX//AACky4AMEERJU0NZTVdGMDQ1MjAwMEgxAQEMm4c0")
5555

5656
// details
57-
_, _ = fmt.Fprintf(os.Stdout, "\nDetails: \n%s\n", sis)
57+
_, _ = fmt.Fprintf(os.Stdout, "\nTable: \n%s\n", sis.Table("", "\t"))
5858

5959
// xml
6060
b, _ := xml.MarshalIndent(sis, "", "\t")
@@ -67,96 +67,94 @@ func main() {
6767
```
6868

6969
```shell
70-
$ go run ./examples/decode.go
70+
$ go run examples/simple_decode/main.go
7171

72-
Details:
72+
Table:
7373
splice_info_section() {
74-
table_id: 0xfc
75-
section_syntax_indicator: false
76-
private_indicator: false
77-
sap_type: Not Specified
78-
section_length: 60 bytes
74+
table_id: 0xfc
75+
section_syntax_indicator: false
76+
private_indicator: false
77+
sap_type: 3 (Not Specified)
78+
section_length: 60
7979
}
8080
protocol_version: 0
81-
encrypted_packet: false
82-
encryption_algorithm: No encryption
83-
pts_adjustment: 0 ticks (0s)
81+
encryption_algorithm: 0 (No encryption)
82+
pts_adjustment: 0
8483
cw_index: 0
8584
tier: 4095
86-
splice_command_length: 5 bytes
85+
splice_command_length: 5
8786
splice_command_type: 0x06
8887
time_signal() {
89-
time_specified_flag: true
90-
pts_time: 3550479013 ticks (10h57m29.766811111s)
88+
time_specified_flag: true
89+
pts_time: 3550479013
9190
}
92-
descriptor_loop_length: 38 bytes
93-
avail_descriptor() {
94-
splice_descriptor_tag: 0x02
95-
descriptor_length: 36 bytes
96-
identifier: CUEI
97-
segmentation_event_id: 39965
98-
segmentation_event_cancel_indicator: false
99-
program_segmentation_flag: true
100-
segmentation_duration_flag: true
101-
delivery_not_restricted_flag: true
102-
segmentation_duration: 10800000 ticks (2m0s)
103-
segmentation_upid_length: 16 bytes
104-
segmentation_upid {
105-
segmentation_upid_type: MPU() (0x0c)
106-
format_identifer: DISC
107-
segmentation_upid: 0x44495343594d57463034353230303048
108-
}
109-
segmentation_type_id: Provider Advertisement End (0x31)
110-
segment_num: 1
111-
segments_expected: 1
91+
descriptor_loop_length: 38
92+
segmentation_descriptor() {
93+
splice_descriptor_tag: 0x02
94+
descriptor_length: 36
95+
identifier: 0x43554549 (CUEI)
96+
segmentation_event_id: 39965
97+
segmentation_event_cancel_indicator: false
98+
segmentation_event_id_compliance_indicator: false
99+
program_segmentation_flag: true
100+
segmentation_duration_flag: true
101+
delivery_not_restricted_flag: true
102+
segmentation_duration: 10800000
103+
segmentation_upid_length: 16
104+
segmentation_upid[0] {
105+
segmentation_upid_type: 0x0c (MPU())
106+
format_identifier: DISC
107+
segmentation_upid: WU1XRjA0NTIwMDBI
108+
}
109+
segmentation_type_id: 0x31 (Provider Advertisement End)
110+
segment_num: 1
111+
segments_expected: 1
112112
}
113113

114-
XML:
114+
115+
XML:
115116
<SpliceInfoSection xmlns="http://www.scte.org/schemas/35" sapType="3" tier="4095">
116-
<EncryptedPacket xmlns="http://www.scte.org/schemas/35" encryptionAlgorithm="0" cwIndex="0"></EncryptedPacket>
117-
<TimeSignal xmlns="http://www.scte.org/schemas/35">
118-
<SpliceTime xmlns="http://www.scte.org/schemas/35" ptsTime="3550479013"></SpliceTime>
119-
</TimeSignal>
120-
<SegmentationDescriptor xmlns="http://www.scte.org/schemas/35" segmentationEventId="39965" segmentationDuration="10800000" segmentationTypeId="49" segmentNum="1" segmentsExpected="1">
121-
<SegmentationUpid xmlns="http://www.scte.org/schemas/35" segmentationUpidType="12" segmentationUpidFormat="base-64" formatIdentifier="1145656131">WU1XRjA0NTIwMDBI</SegmentationUpid>
122-
</SegmentationDescriptor>
117+
<EncryptedPacket xmlns="http://www.scte.org/schemas/35" encryptionAlgorithm="0" cwIndex="0"></EncryptedPacket>
118+
<TimeSignal xmlns="http://www.scte.org/schemas/35">
119+
<SpliceTime xmlns="http://www.scte.org/schemas/35" ptsTime="3550479013"></SpliceTime>
120+
</TimeSignal>
121+
<SegmentationDescriptor xmlns="http://www.scte.org/schemas/35" segmentationEventId="39965" segmentationDuration="10800000" segmentationTypeId="49" segmentNum="1" segmentsExpected="1">
122+
<SegmentationUpid xmlns="http://www.scte.org/schemas/35" segmentationUpidType="12" segmentationUpidFormat="base-64" formatIdentifier="1145656131">WU1XRjA0NTIwMDBI</SegmentationUpid>
123+
</SegmentationDescriptor>
123124
</SpliceInfoSection>
124125

125-
JSON:
126+
JSON:
126127
{
127-
"protocolVersion": 0,
128-
"ptsAdjustment": 0,
129-
"sapType": 3,
130-
"spliceCommand": {
131-
"type": 6,
132-
"spliceTime": {
133-
"ptsTime": 3550479013
134-
}
135-
},
136-
"spliceDescriptors": [
137-
{
138-
"type": 2,
139-
"deliveryRestrictions": null,
140-
"segmentationUpids": [
141-
{
142-
"segmentationUpidType": 12,
143-
"formatIdentifier": 1145656131,
144-
"format": "base-64",
145-
"value": "WU1XRjA0NTIwMDBI"
146-
}
147-
],
148-
"components": null,
149-
"segmentationEventId": 39965,
150-
"segmentationEventCancelIndicator": false,
151-
"segmentationDuration": 10800000,
152-
"segmentationTypeId": 49,
153-
"segmentNum": 1,
154-
"segmentsExpected": 1,
155-
"subSegmentNum": null,
156-
"subSegmentsExpected": null
157-
}
158-
],
159-
"tier": 4095
128+
"encryptedPacket": {
129+
"encryptionAlgorithm": 0,
130+
"cwIndex": 0
131+
},
132+
"sapType": 3,
133+
"spliceCommand": {
134+
"type": 6,
135+
"spliceTime": {
136+
"ptsTime": 3550479013
137+
}
138+
},
139+
"spliceDescriptors": [
140+
{
141+
"type": 2,
142+
"segmentationUpids": [
143+
{
144+
"segmentationUpidType": 12,
145+
"segmentationUpidFormat": "base-64",
146+
"formatIdentifier": 1145656131,
147+
"value": "WU1XRjA0NTIwMDBI"
148+
}
149+
],
150+
"segmentationEventId": 39965,
151+
"segmentationDuration": 10800000,
152+
"segmentationTypeId": 49,
153+
"segmentNum": 1,
154+
"segmentsExpected": 1
155+
}
156+
],
157+
"tier": 4095
160158
}
161159
```
162160

@@ -166,7 +164,7 @@ Encoding signals is equally simple. You can start from scratch and build a
166164
`scte35.SpliceInfoSection` or decode an existing signal and modify it to suit
167165
your needs.
168166

169-
[encode.go](./examples/encode.go)
167+
[examples/simple_encode/main.go](examples/simple_encode/main.go)
170168

171169
```go
172170
package main
@@ -197,9 +195,12 @@ func main() {
197195
SegmentNum: 2,
198196
},
199197
},
200-
EncryptedPacket: scte35.EncryptedPacket{CWIndex: 255},
201-
Tier: 4095,
202-
SAPType: 3,
198+
EncryptedPacket: scte35.EncryptedPacket{
199+
EncryptionAlgorithm: scte35.EncryptionAlgorithmNone,
200+
CWIndex: 255,
201+
},
202+
Tier: 4095,
203+
SAPType: 3,
203204
}
204205

205206
// encode it
@@ -216,20 +217,18 @@ func main() {
216217
)
217218

218219
// encode it again
219-
_, _ = fmt.Fprintf(os.Stdout, "\nModified:\n")
220+
_, _ = fmt.Fprintf(os.Stdout, "Original:\n")
220221
_, _ = fmt.Fprintf(os.Stdout, "base-64: %s\n", sis.Base64())
221222
_, _ = fmt.Fprintf(os.Stdout, "hex : %s\n", sis.Hex())
222223
}
223-
224224
```
225225

226226
```shell
227-
$ go run ./examples/encode.go
227+
$ go run examples/simple_encode/main.go
228228
Original:
229229
base-64: /DAvAAAAAAAA///wBQb+cr0AUAAZAhdDVUVJSAAAjn+PCAg3ODUxMTQ1MjQCADhqB9E=
230230
hex : fc302f000000000000fffff00506fe72bd005000190217435545494800008e7f8f08083738353131343532340200386a07d1
231-
232-
Modified:
231+
Original:
233232
base-64: /DA7AAAAAAAA///wBQb+cr0AUAAlAhdDVUVJSAAAjn+PCAg3ODUxMTQ1MjQCAAEKQ1VFSQCfQUJDKqtwQlQ=
234233
hex : fc303b000000000000fffff00506fe72bd005000250217435545494800008e7f8f08083738353131343532340200010a43554549009f4142432aab704254
235234
```
@@ -240,7 +239,7 @@ The SCTE 35 decoder will always return a non-nil `SpliceInfoSection`, even when
240239
an error occurs. This is done to help better identify the specific cause of the
241240
decoding failure.
242241

243-
[bad-signal](./examples/bad_signal.go)
242+
[examples/bad_signal/main.go](examples/bad_signal/main.go)
244243

245244
```go
246245
package main
@@ -249,79 +248,101 @@ import (
249248
"fmt"
250249
"os"
251250

252-
"code.comcast.com/jbaile223/scte35/pkg/scte35"
251+
"github.com/Comcast/scte35-go/pkg/scte35"
253252
)
254253

255254
func main() {
256255
sis, err := scte35.DecodeBase64("FkC1lwP3uTQD0VvxHwVBEH89G6B7VjzaZ9eNuyUF9q8pYAIXsRM9ZpDCczBeDbytQhXkssQstGJVGcvjZ3tiIMULiA4BpRHlzLGFa0q6aVMtzk8ZRUeLcxtKibgVOKBBnkCbOQyhSflFiDkrAAIp+Fk+VRsByTSkPN3RvyK+lWcjHElhwa9hNFcAy4dm3DdeRXnrD3I2mISNc7DkgS0ReotPyp94FV77xMHT4D7SYL48XU20UM4bgg==")
257256
if err != nil {
258-
fmt.Fprintf(os.Stdout, "Error: %s\n", err)
257+
_, _ = fmt.Fprintf(os.Stdout, "Error: %s\n", err)
259258
}
260-
// splice info section contains best-effort decoding
261-
fmt.Fprintf(os.Stdout, "Signal: %s", sis)
259+
_, _ = fmt.Fprintf(os.Stdout, "%s\n", sis.Table("", "\t"))
262260
}
263261
```
264262

265263
As we can see from the output below, the signal has a corrupted `component_count`,
266264
causing the decoder to return a `scte.ErrBufferOverflow`:
267265

268266
```shell
269-
$ go run ./examples/bad_signal.go
267+
$ go run examples/bad_signal/main.go
270268
Error: splice_insert: buffer overflow
271-
Signal: splice_info_section() {
272-
table_id: 0xfc
273-
section_syntax_indicator: false
274-
private_indicator: false
275-
sap_type: Type 1
276-
section_length: 343 bytes
269+
splice_info_section() {
270+
table_id: 0xfc
271+
section_syntax_indicator: false
272+
private_indicator: false
273+
sap_type: 0 (Type 1)
274+
section_length: 347
277275
}
278276
protocol_version: 151
279-
encrypted_packet: false
280-
encryption_algorithm: No encryption
281-
pts_adjustment: 8451077123 ticks (26h5m0.856922222s)
277+
encryption_algorithm: 1 (DES – ECB mode)
278+
pts_adjustment: 8451077123
282279
cw_index: 209
283280
tier: 1471
284-
splice_command_length: 326 bytes
281+
splice_command_length: 326
285282
splice_command_type: 0x05
286283
splice_insert() {
287-
splice_event_id: 1091600189
288-
splice_event_cancel_indicator: false
289-
out_of_network_indicator: true
290-
program_splice_flag: false
291-
duration_flag: true
292-
splice_immediate_flag: false
293-
component_count: 123
294-
component[0] {
295-
component_tag: 86
296-
time_specified_flag: false
284+
splice_event_id: 1091600189
285+
splice_event_cancel_indicator: false
286+
out_of_network_indicator: true
287+
program_splice_flag: false
288+
duration_flag: true
289+
splice_immediate_flag: false
290+
component_count: 123
291+
component[0]
292+
component_tag: 86
293+
time_specified_flag: false
297294
}
298295

299296
... additional components removed
300297

301-
component[122] {
302-
component_tag: 0
303-
time_specified_flag: false
304-
}
305-
auto_return: false
306-
duration: 0 ticks (0s)
307-
unique_program_id: 0
308-
avail_num: 0
309-
avails_expected: 0
298+
auto_return: false
299+
duration: 0
300+
unique_program_id: 0
301+
avail_num: 0
302+
avails_expected: 0
310303
}
304+
descriptor_loop_length: 0
311305
```
312306

313307
#### CRC_32 Validation
314308

315309
The SCTE 35 decoder performs automatic `CRC_32` validation. The returned error
316310
can be explicitly ignored if desired.
317311

312+
[examples/ignore_crc32/main.go](examples/ignore_crc32/main.go)
313+
318314
```go
319-
sis, err := scte35.DecodeBase64("/DA4AAAAAAAAAP/wFAUABDEAf+//mWEhzP4Azf5gAQAAAAATAhFDVUVJAAAAAX+/AQIwNAEAAKeYO3Q=")
320-
if err != nil && !errors.Is(err, scte35.ErrCRC32Invalid) {
321-
return err
315+
package main
316+
317+
import (
318+
"errors"
319+
"fmt"
320+
"os"
321+
322+
"github.com/Comcast/scte35-go/pkg/scte35"
323+
)
324+
325+
func main() {
326+
scte35.Logger.SetOutput(os.Stdout)
327+
328+
sis, err := scte35.DecodeBase64("/DA4AAAAAAAAAP/wFAUABDEAf+//mWEhzP4Azf5gAQAAAAATAhFDVUVJAAAAAX+/AQIwNAEAAKeYO3Q=")
329+
if errors.Is(err, scte35.ErrCRC32Invalid) {
330+
_, _ = fmt.Fprintf(os.Stderr, "Warning: CRC32 check failed!\n")
331+
}
332+
_, _ = fmt.Fprintf(os.Stdout, "%s\n", sis.Table("", "\t"))
322333
}
323334
```
324335

336+
```shell
337+
$ go run examples/ignore_crc32/main.go
338+
2025/03/15 00:44:42 CRC_32 calculated (2811771763) != reported (2811771764)
339+
Warning: CRC32 check failed!
340+
splice_info_section() {
341+
table_id: 0xfc
342+
343+
... more output removed ...
344+
```
345+
325346
#### Logging
326347
327348
Additional diagnostics can be enabled by redirecting the output of

0 commit comments

Comments
 (0)