From a16ba22527e0a5c999df381b794f3c1e81d01198 Mon Sep 17 00:00:00 2001 From: Saxon Date: Mon, 8 Apr 2019 20:31:55 +0930 Subject: [PATCH] protocol/rtp: removed extHeaderLen func --- protocol/rtp/parse.go | 9 +-------- protocol/rtp/parse_test.go | 19 ------------------- 2 files changed, 1 insertion(+), 27 deletions(-) diff --git a/protocol/rtp/parse.go b/protocol/rtp/parse.go index ede12ece..a0daf3c7 100644 --- a/protocol/rtp/parse.go +++ b/protocol/rtp/parse.go @@ -42,19 +42,12 @@ func Payload(d []byte) ([]byte, error) { } extLen := 0 if hasExt(d) { - extLen = 4 + 4*extHeaderLen(d) + extLen = 4 + 4*(int(binary.BigEndian.Uint16(d[optionalFieldIdx+4*csrcCount(d)+2:]))) } payloadIdx := optionalFieldIdx + 4*csrcCount(d) + extLen return d[payloadIdx:], nil } -// extHeaderLen returns the extension header length. The RTP packet must have -// a compatible version, and must have an extension field, otherwise we panic. -func extHeaderLen(d []byte) int { - extIdx := optionalFieldIdx + 4*csrcCount(d) - return int(binary.BigEndian.Uint16(d[extIdx+2 : extIdx+4])) -} - // hasExt returns true if an extension is present in the RTP packet. The version // must be compatible otherwise we panic. func hasExt(d []byte) bool { diff --git a/protocol/rtp/parse_test.go b/protocol/rtp/parse_test.go index a41e1041..ec779e5d 100644 --- a/protocol/rtp/parse_test.go +++ b/protocol/rtp/parse_test.go @@ -86,25 +86,6 @@ func TestHasExt(t *testing.T) { } } -// TestExtHeaderLen checks for a correct extension header len for an RTP packet. -func TestExtHeaderLen(t *testing.T) { - const ver, expect = 2, 3 - - pkt := (&Pkt{ - V: ver, - X: true, - Extension: ExtensionHeader{ - ID: 0, - Header: make([][4]byte, expect), - }, - }).Bytes(nil) - - got := extHeaderLen(pkt) - if got != expect { - t.Errorf("Unexpected extension header len. Got: %v\n Want: %v\n", got, expect) - } -} - // TestPayload checks that we can correctly get the payload of an RTP packet // using Payload for a variety of RTP packet configurations. func TestPayload(t *testing.T) {