streaming

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

commit b93d0c2e5b69b49940dc51d9ad13ae286366a0d8
parent 0d150658248fae47a082e21d7233c0ef8af80ff6
Author: Oliver Lowe <o@olowe.co>
Date:   Mon, 10 Jun 2024 13:06:16 +1000

mpegts: pack PID in the header correctly

While here add validation for PacketID.

Diffstat:
Mmpegts/codec.go | 7++++++-
Mmpegts/mpegts.go | 4++--
2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/mpegts/codec.go b/mpegts/codec.go @@ -135,7 +135,12 @@ func Encode(w io.Writer, p *Packet) error { if p.Priority { buf[1] |= 0x20 } - binary.BigEndian.PutUint16(buf[1:3], uint16(p.PID)) + if p.PID > PacketNull { + return fmt.Errorf("packet id %s greater than max %s", p.PID, PacketNull) + } + buf[1] |= byte(p.PID >> 8) + buf[2] = byte(p.PID) + buf[3] |= byte(p.Scrambling) if p.Adaptation != nil || p.emptyAdaptation { buf[3] |= 0x20 diff --git a/mpegts/mpegts.go b/mpegts/mpegts.go @@ -41,8 +41,8 @@ const ( CAT // Conditional access table TSDT // Transport stream description table IPMP - _ // reserved through to - PacketNull = 8191 + _ // reserved through to + PacketNull PacketID = 8191 // max 13-bit integer ) func (id PacketID) String() string {