streaming

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

commit 644fd6ef8abc28c7d2f45510e31c805fbe391592
parent 6fdf3f5dfcf476c83866ac084b8609cd5c9db62f
Author: Oliver Lowe <o@olowe.co>
Date:   Tue, 11 Jun 2024 18:27:35 +1000

scte35: simplify setting booleans from bitfields

Shorter and I don't think we're losing any readability; we're just
setting true/false. Makes some things clearer, like the Encrypted flag
and what consequences if that's set.

Diffstat:
Mscte35/break_duration.go | 4+---
Mscte35/splice.go | 29+++++++++--------------------
Mscte35/splice_descriptor.go | 9++-------
3 files changed, 12 insertions(+), 30 deletions(-)

diff --git a/scte35/break_duration.go b/scte35/break_duration.go @@ -26,9 +26,7 @@ func packBreakDuration(b *BreakDuration) [5]byte { func readBreakDuration(a [5]byte) *BreakDuration { var bd BreakDuration - if a[0]&(1<<7) > 0 { - bd.AutoReturn = true - } + bd.AutoReturn = a[0]&(1<<7) > 0 a[0] &= 0x01 // first, allocate 3 empty bytes, then add the remaining 5; // enough for the uint64 (8 bytes). diff --git a/scte35/splice.go b/scte35/splice.go @@ -163,9 +163,9 @@ func Decode(buf []byte) (*Splice, error) { return nil, fmt.Errorf("message declares %d bytes but have %d", length, len(buf)) } - // skip version byte, we don't store version as it's constant. - if buf[1]&0b10000000 == 1 { - splice.Encrypted = true + // skip version byte at buf[0]. We don't store version as it's constant. + splice.Encrypted = buf[1]&0b10000000 > 0 + if splice.Encrypted { // right-most bit is used by PTSAdjustment. splice.Cipher = Cipher(buf[1] & 0b01111110) } @@ -227,29 +227,18 @@ func decodeCommand(buf []byte) (*Command, error) { case SpliceInsert: var ins Insert ins.ID = binary.BigEndian.Uint32(buf[1:5]) - if buf[5]&0x80 > 0 { - ins.Cancel = true + ins.Cancel = buf[5]&0x80 > 0 + if ins.Cancel { cmd.Insert = &ins // rebelelder told us to do this. return &cmd, nil } - if buf[6]&(1<<7) > 0 { - ins.OutOfNetwork = true - } - + ins.OutOfNetwork = buf[6]&(1<<7) > 0 // assume program_splice is set at bit 6; - - var durflag bool - if buf[6]&(1<<5) > 0 { - durflag = true - } // we don't support deprecated component mode. - if buf[6]&(1<<4) > 0 { - ins.Immediate = true - } - if buf[6]&(1<<3) > 0 { - ins.idCompliance = true - } + durflag := buf[6]&(1<<5) > 0 + ins.Immediate = buf[6]&(1<<4) > 0 + ins.idCompliance = buf[6]&(1<<3) > 0 // next 3 bits are reserved. if !ins.Immediate { diff --git a/scte35/splice_descriptor.go b/scte35/splice_descriptor.go @@ -184,12 +184,8 @@ func (d SegmentationDescriptor) Data() []byte { func unmarshalSegDescriptor(buf []byte) SegmentationDescriptor { var desc SegmentationDescriptor desc.EventID = binary.BigEndian.Uint32(buf[:4]) - if buf[4]&0b10000000 > 0 { - desc.Cancel = true - } - if buf[4]&0b01000000 > 0 { - desc.idCompliance = true - } + desc.Cancel = buf[4]&(1<<7) > 0 + desc.idCompliance = buf[4]&(1<<6) > 0 // next 6 bits are reserved // always assume program_segmentation_flag is set at 0b10000000 @@ -217,7 +213,6 @@ func unmarshalSegDescriptor(buf []byte) SegmentationDescriptor { } buf = buf[2+uplen:] - // TODO(otl): use named constants from section 10.3.3.1 Table 23 - segmentation_type_id desc.Type = uint8(buf[0]) desc.Number = uint8(buf[1]) desc.Expected = uint8(buf[2])