streaming

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

commit 0cf1dfb386ded8d8b966ebeca50bbca10bb82d11
parent c21d893e35cf8d4d9dbcd2d26159b88ce5016440
Author: Oliver Lowe <o@olowe.co>
Date:   Fri, 14 Jun 2024 16:11:24 +1000

mpegts: shorten boolean field setting from bitfield

Nice trick, and doesn't impact readability I'd say!

Diffstat:
Mmpegts/codec.go | 24++++++------------------
Mmpegts/codec_test.go | 3++-
2 files changed, 8 insertions(+), 19 deletions(-)

diff --git a/mpegts/codec.go b/mpegts/codec.go @@ -13,15 +13,9 @@ func Unmarshal(buf []byte, p *Packet) error { if buf[0] != Sync { return fmt.Errorf("expected sync byte, got %x", buf[0]) } - if buf[1]&0x80 > 0 { - p.Error = true - } - if buf[1]&0x40 > 0 { - p.PayloadStart = true - } - if buf[1]&0x20 > 0 { - p.Priority = true - } + p.Error = (buf[1] & 0x80) > 0 + p.PayloadStart = (buf[1] & 0x40) > 0 + p.Priority = (buf[1] & 0x20) > 0 // Want next 13 bits. 5 from buf[1] and all of buf[2]. pid := binary.BigEndian.Uint16([]byte{buf[1] & 0x1f, buf[2]}) p.PID = PacketID(pid) @@ -79,15 +73,9 @@ func parseAdaptationField(buf []byte) *Adaptation { var af Adaptation flags := buf[0] buf = buf[1:] - if flags&0x80 > 0 { - af.Discontinuous = true - } - if flags&0x40 > 0 { - af.RandomAccess = true - } - if flags&0x20 > 0 { - af.Priority = true - } + af.Discontinuous = flags&0x80 > 0 + af.RandomAccess = flags&0x40 > 0 + af.Priority = flags&0x20 > 0 if flags&0x10 > 0 { var p [6]byte copy(p[:], buf[:6]) diff --git a/mpegts/codec_test.go b/mpegts/codec_test.go @@ -10,7 +10,8 @@ import ( ) func TestDecode(t *testing.T) { - f, err := os.Open("testdata/193039199_mp4_h264_aac_hq_7.ts") + // f, err := os.Open("testdata/193039199_mp4_h264_aac_hq_7.ts") + f, err := os.Open("testdata/bbb.ts") if err != nil { t.Fatal(err) }