streaming

Media streaming and broadcast systems in Go
Log | Files | Refs | README | LICENSE

commit c0a87bbed2f0947fe30ae80a5466bdae4de7621b
parent f2aae646ea349e196c882dea120da8243efb37f6
Author: Oliver Lowe <o@olowe.co>
Date:   Fri, 31 May 2024 13:51:31 +1000

scte35: Add most important docs

Still more to go but these are the most crucial bits that most users
of the package - including us! - would need. In particuclar:

- package overview
- all fields of Splice
- example encoding splice

Diffstat:
Mscte35/codec_test.go | 35+++++++++++++++++++++++++++++++++++
Mscte35/splice.go | 30+++++++++++++++++++++++++++---
2 files changed, 62 insertions(+), 3 deletions(-)

diff --git a/scte35/codec_test.go b/scte35/codec_test.go @@ -33,3 +33,38 @@ func Example() { // 28980000 // /DA0AAAAAAAA///wBQb+cr0AUAAeAhxDVUVJSAAAjn/PAAG6MyAICAAAAAAsoKGKNAIAQO/SuQ== } + +func ExampleEncode() { + when := uint64(12 * 60 * 60 * 90000) // 12 hours since midnight UTC as 90KHz ticks + duration := uint64(60 * 90000) // 60 seconds as 90KHz ticks + splice := scte35.Splice{ + SAPType: scte35.SAPNone, + Tier: 0x0fff, + Command: &scte35.Command{ + Type: scte35.TimeSignal, + TimeSignal: &when, + }, + Descriptors: []scte35.SpliceDescriptor{ + scte35.SegmentationDescriptor{ + EventID: 1234, + Restrictions: scte35.NoRegionalBlackout | scte35.ArchiveAllowed | scte35.DeviceRestrictionsNone, + Duration: &duration, + UPID: scte35.UPID{ + Type: scte35.UPIDTI, + Value: []byte{0x00, 0x00, 0x00, 0x00, 0x2c, 0xa0, 0xa1, 0x8a}, + }, + Type: 0x34, + Number: 2, + Expected: 0, + }, + }, + } + b, err := scte35.Encode(&splice) + if err != nil { + // handle error... + } + // SCTE 35 time_signal() commands can be inserted into HLS playlists using the + // EXT-X-DATERANGE tag. See "Mapping SCTE-35 into EXT-X-DATERANGE" + // RFC 8216 section 4.3.2.7.1. + fmt.Printf("#EXT-X-DATERANGE:ID=\"example\",SCTE35-CMD=%#x\n", b) +} diff --git a/scte35/splice.go b/scte35/splice.go @@ -1,3 +1,8 @@ +// Package scte35 implements a subset of the +// Digital Program Insertion Cueing Message standard +// as specified in [ANSI/SCTE 35]. +// +// [ANSI/SCTE 35]: https://www.scte.org/standards/library/catalog/scte-35-digital-program-insertion-cueing-message/ package scte35 import ( @@ -33,15 +38,34 @@ func (t SAPType) String() string { type Splice struct { SAPType SAPType + + // If true, indicates that the contents of Command, + // Descriptors and CRC32 are encrypted with Cipher. + // TODO(otl): encoding and decoding of encrypted splices is not supported. Encrypted bool Cipher Cipher - // Holds a 33-bit unsigned integer representing the number of ticks of a 90KHz clock. - PTSAdjustment uint64 + // The control word (key) used to decrypt the message. CWIndex uint8 - // Holds a 12-bit field representing an authorization tier. + + // Holds a 33-bit unsigned integer representing the number of + // ticks of a 90KHz clock. The value is an offset added to + // timestamps in Descriptors by splice devices when executing the + // provided Command. + PTSAdjustment uint64 + + // Holds a 12-bit field representing an authorization tier. In + // most cases, its value should be 0x0fff for backwards + // compatibility. See 'tier' in SCTE 35 section 9.6.1. Tier uint16 + + // Command points to this splice's specific instruction for splice devices. Command *Command + // Descriptors holds zero or more parameters to Command. Descriptors []SpliceDescriptor + + // A checksum of the encoded splice. Splices returned from + // Decode() will hold a non-zero value. Splices passed to + // Encode() will have their checksums calculated automatically. CRC32 uint32 }