From 0531b9542b3650458ed83de9f6f99ddcd76a1766 Mon Sep 17 00:00:00 2001 From: saxon Date: Sat, 24 Nov 2018 12:22:17 +1030 Subject: [PATCH] rtp: client only needs to specify padding length and then padding indicator is set based on this --- stream/rtp/encoder.go | 1 - stream/rtp/rtp.go | 11 +++++------ stream/rtp/rtp_test.go | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/stream/rtp/encoder.go b/stream/rtp/encoder.go index eb6e404e..c8750e95 100644 --- a/stream/rtp/encoder.go +++ b/stream/rtp/encoder.go @@ -83,7 +83,6 @@ func (e *Encoder) Write(data []byte) (int, error) { func (e *Encoder) Encode(payload []byte) error { pkt := Pkt{ V: rtpVer, // version - P: no, // padding X: no, // header extension CC: no, // CSRC count M: no, // NOTE: need to check if this works (decoders should ignore this) diff --git a/stream/rtp/rtp.go b/stream/rtp/rtp.go index 45898a32..4e393679 100644 --- a/stream/rtp/rtp.go +++ b/stream/rtp/rtp.go @@ -37,9 +37,10 @@ const ( ) // Pkt provides fields consistent with RFC3550 definition of an rtp packet +// The padding indicator does not need to be set manually, only the padding length type Pkt struct { V byte // Version (currently 2) - P byte // Padding indicator (0 => padding, 1 => padding) + p byte // Padding indicator (0 => padding, 1 => padding) X byte // Extension header indicator CC byte // CSRC count M byte // Marker bit @@ -57,10 +58,8 @@ func (p *Pkt) Bytes() []byte { p.V = rtpVer } - if p.P != 0 && p.Padding == 0 { - panic("Padding bit set to something other than 1, but there is no padding size defined.") - } else if p.P == 0 && p.Padding != 0 { - panic("Padding bit is set to zero, but it's indicated that there is padding.") + if p.Padding > 0 { + p.p = 1 } if p.CC != 0 { @@ -78,7 +77,7 @@ func (p *Pkt) Bytes() []byte { const headSize = 3 * 4 // bytes buf := make([]byte, headSize, headSize+len(p.Payload)+int(p.Padding)) - buf[0] = p.V<<6 | p.P<<5 | p.CC + buf[0] = p.V<<6 | p.p<<5 | p.CC buf[1] = p.M<<7 | p.PT buf[2] = byte(p.SN >> 8) buf[3] = byte(p.SN) diff --git a/stream/rtp/rtp_test.go b/stream/rtp/rtp_test.go index 3d034c32..85b33590 100644 --- a/stream/rtp/rtp_test.go +++ b/stream/rtp/rtp_test.go @@ -42,7 +42,7 @@ var rtpTests = []struct { num: 1, pkt: Pkt{ V: 2, - P: 0, + p: 0, X: 0, CC: 0, M: 0,