protocol/rtp: removed extHeaderLen func

This commit is contained in:
Saxon 2019-04-08 20:31:55 +09:30
parent 6ccb0d70d9
commit a16ba22527
2 changed files with 1 additions and 27 deletions

View File

@ -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 {

View File

@ -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) {