From efa0d38aad04d92fab809f8bcda985d67a9f2bcd Mon Sep 17 00:00:00 2001 From: Saxon Date: Tue, 2 Apr 2019 21:49:11 +1030 Subject: [PATCH] protocol/rtp: removed Len field from ExtensionHeader struct as we can gather from len(ExtensionHeader.Header) --- protocol/rtp/rtp.go | 12 ++++-------- protocol/rtp/rtp_test.go | 3 +-- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/protocol/rtp/rtp.go b/protocol/rtp/rtp.go index 5805151b..1bbef690 100644 --- a/protocol/rtp/rtp.go +++ b/protocol/rtp/rtp.go @@ -64,7 +64,6 @@ type Pkt struct { // ExtensionHeader header provides fields for an RTP packet extension header. type ExtensionHeader struct { ID uint16 - Len uint16 Header [][4]byte } @@ -73,10 +72,7 @@ func (p *Pkt) Bytes(buf []byte) []byte { // Calculate the required length for the RTP packet. headerExtensionLen := 0 if p.X { - if p.Extension.Len != uint16(len(p.Extension.Header)) { - panic("bad rtp packet extension length field") - } - headerExtensionLen = int(4 + 4*p.Extension.Len) + headerExtensionLen = int(4 + 4*len(p.Extension.Header)) } requiredPktLen := defaultHeadSize + uint8(4*p.CC) + uint8(headerExtensionLen) + uint8(len(p.Payload)) + uint8(len(p.Padding)) @@ -110,12 +106,12 @@ func (p *Pkt) Bytes(buf []byte) []byte { if p.X { binary.BigEndian.PutUint16(buf[idx:idx+2], p.Extension.ID) idx += 2 - binary.BigEndian.PutUint16(buf[idx:idx+2], p.Extension.Len) + binary.BigEndian.PutUint16(buf[idx:idx+2], uint16(len(p.Extension.Header))) idx += 2 - for i := 0; i < int(p.Extension.Len); i++ { + for i := 0; i < len(p.Extension.Header); i++ { copy(buf[idx+i*4:], p.Extension.Header[i][:]) } - idx += int(p.Extension.Len * 4) + idx += len(p.Extension.Header) * 4 } // If there is payload, add to the buffer. diff --git a/protocol/rtp/rtp_test.go b/protocol/rtp/rtp_test.go index 3c6d07f9..2622fb81 100644 --- a/protocol/rtp/rtp_test.go +++ b/protocol/rtp/rtp_test.go @@ -156,8 +156,7 @@ var rtpTests = []struct { {0x05, 0x06, 0x07, 0x08}, }, Extension: ExtensionHeader{ - ID: 15, - Len: 2, + ID: 15, Header: [][4]byte{ {0x01, 0x02, 0x03, 0x04}, {0x05, 0x06, 0x07, 0x08},