commit 52483617f8dc2116b504a6a85274b3c44a119ecd
parent 3b1acc9102e2f96d3b40224dee1007a820c89675
Author: Oliver Lowe <o@olowe.co>
Date: Sat, 17 Aug 2024 11:28:33 +1000
scte35: support decoding private commands
Resolves: https://github.com/untangledco/streaming/issues/29
Diffstat:
2 files changed, 16 insertions(+), 0 deletions(-)
diff --git a/scte35/command.go b/scte35/command.go
@@ -178,6 +178,16 @@ func encodePrivateCommand(c *PrivateCommand) []byte {
return buf
}
+func decodePrivateCommand(b []byte) (PrivateCommand, error) {
+ if len(b) < 4 {
+ return PrivateCommand{}, fmt.Errorf("need at least 4 bytes, have %d", len(b))
+ }
+ return PrivateCommand{
+ ID: binary.BigEndian.Uint32(b[:4]),
+ Data: b[4:],
+ }, nil
+}
+
// Insert represents the splice_insert command
// as specified in SCTE 35 section 9.7.3.
type Insert struct {
diff --git a/scte35/splice.go b/scte35/splice.go
@@ -263,6 +263,12 @@ func decodeCommand(buf []byte) (*Command, error) {
ins.AvailNum = uint8(buf[2])
ins.AvailExpected = uint8(buf[3])
cmd.Insert = &ins
+ case Private:
+ pcmd, err := decodePrivateCommand(buf[1:])
+ if err != nil {
+ return nil, fmt.Errorf("decode private command: %w", err)
+ }
+ cmd.Private = &pcmd
default:
// TODO(otl): we could support more commands but we
// just haven't written the code yet. See issues