From 6f1515cc467e99feb52e069315f1a86d97a49898 Mon Sep 17 00:00:00 2001 From: saxon Date: Wed, 21 Nov 2018 13:00:48 +1030 Subject: [PATCH] rtp: simplified addition of padding to rtp packet --- stream/rtp/rtp.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/stream/rtp/rtp.go b/stream/rtp/rtp.go index b9234b0f..fa62d9fb 100644 --- a/stream/rtp/rtp.go +++ b/stream/rtp/rtp.go @@ -45,7 +45,7 @@ type Pkt struct { TS uint32 // Timestamp SSRC uint32 // Synchronisation source identifier Payload []byte // H264 Payload data - Padding int // No of bytes of padding + Padding byte // No of bytes of padding } func (p *Pkt) Bytes() []byte { @@ -72,7 +72,7 @@ func (p *Pkt) Bytes() []byte { } const headSize = 3 * 4 // bytes - buf := make([]byte, headSize, headSize+len(p.Payload)+p.Padding) + buf := make([]byte, headSize, headSize+len(p.Payload)+int(p.Padding)) buf[0] = p.V<<6 | p.P<<5 | p.CC buf[1] = p.M<<7 | p.PT @@ -89,7 +89,8 @@ func (p *Pkt) Bytes() []byte { buf = append(buf, p.Payload...) if p.Padding != 0 { - buf = append(buf, append(make([]byte, p.Padding-1, p.Padding), byte(p.Padding))...) + buf = buf[:cap(buf)] + buf[len(buf)-1] = byte(p.Padding) } return buf }