streaming

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

commit c70d8b514a2f9bf9fe8ff5cfc5dd69d6143b117f
parent bc72cfd4e08026c5399b8e62231a837b517737b2
Author: Oliver Lowe <o@olowe.co>
Date:   Fri, 10 May 2024 19:43:37 +1000

internal/scte35: implement BreakDuration decoding

with a test!

Diffstat:
Minternal/scte35/break_duration.go | 20++++++++++++++++++++
Minternal/scte35/break_duration_test.go | 9+++++++++
2 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/internal/scte35/break_duration.go b/internal/scte35/break_duration.go @@ -1,5 +1,10 @@ package scte35 +import ( + "encoding/binary" + "fmt" +) + type BreakDuration struct { AutoReturn bool // Holds a number of ticks of a 90KHz clock. @@ -22,3 +27,18 @@ func packBreakDuration(b *BreakDuration) [5]byte { p[4] = pts[4] return p } + +func readBreakDuration(a [5]byte) *BreakDuration { + fmt.Printf("%#x\n", a) + var bd BreakDuration + if a[0]&(1<<7) > 0 { + bd.AutoReturn = true + } + a[0] &= 0x01 + // first, allocate 3 empty bytes, then add the remaining 5; + // enough for the uint64 (8 bytes). + b := []byte{0, 0, 0} + b = append(b, a[:]...) + bd.Duration = binary.BigEndian.Uint64(b) + return &bd +} diff --git a/internal/scte35/break_duration_test.go b/internal/scte35/break_duration_test.go @@ -19,3 +19,12 @@ func TestPackBreakDuration(t *testing.T) { t.Errorf("packBreakDuration(%v) = %08b, want %08b", bd, got, want) } } + +func TestReadBreakDuration(t *testing.T) { + want := samples[1].want.Command.Insert.Duration.Duration + a := [5]byte{0xfe, 0x00, 0x52, 0xcc, 0xf5} + got := readBreakDuration(a) + if want != got.Duration { + t.Errorf("readBreakDuration(%#x) = %d, want %d", a, got.Duration, want) + } +}