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,