streaming

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

commit e5e0b3ba7bd6e3fcf66815ddf2a646bddd91ed69
parent 3aeb4229e0897e37bbd3cbe9099840c712a98489
Author: Oliver Lowe <o@olowe.co>
Date:   Sun, 12 May 2024 15:29:07 +1000

internal/scte35: clarify splice info encryption, ptsadjust packing

Only do crypto packing logic if we know the message is actually
encrpyted. Then we can get rid of the magic '4' slice index by
appending it all in one hit when we've set all the values we need.

Diffstat:
Minternal/scte35/splice_info.go | 19++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/internal/scte35/splice_info.go b/internal/scte35/splice_info.go @@ -67,19 +67,20 @@ func encodeSpliceInfo(sis *SpliceInfo) ([]byte, error) { // length, buf[1,2] set at the end buf[3] = protocolVersion - buf = append(buf, 0x00) + var b byte if sis.Encrypted { - buf[4] |= (1 << 7) - } - if sis.Cipher > maxCipher { - return nil, fmt.Errorf("encryption algorithm %d larger than max value %d", sis.Cipher, maxCipher) + b |= (1 << 7) + if sis.Cipher > maxCipher { + return nil, fmt.Errorf("cipher %d larger than max %d", sis.Cipher, maxCipher) + } + // pack cipher, keeping 1 bit for PTSAdjustment. + b |= byte(sis.Cipher) << 1 } - // pack 6-bit cipher into next 6. Keep 1 bit for PTSAdjustment. - buf[4] |= byte(sis.Cipher) << 1 pts := toPTS(sis.PTSAdjustment) - buf[4] |= pts[0] + // set the remaining 1 bit in b from the 33-bit timestamp. append the rest. + b |= pts[0] + buf = append(buf, b) buf = append(buf, pts[1:]...) - buf = append(buf, byte(sis.CWIndex)) if sis.Tier > maxTier {