mirror of https://bitbucket.org/ausocean/av.git
protocol/rtp: removed extHeaderLen func
This commit is contained in:
parent
6ccb0d70d9
commit
a16ba22527
|
@ -42,19 +42,12 @@ func Payload(d []byte) ([]byte, error) {
|
||||||
}
|
}
|
||||||
extLen := 0
|
extLen := 0
|
||||||
if hasExt(d) {
|
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
|
payloadIdx := optionalFieldIdx + 4*csrcCount(d) + extLen
|
||||||
return d[payloadIdx:], nil
|
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
|
// hasExt returns true if an extension is present in the RTP packet. The version
|
||||||
// must be compatible otherwise we panic.
|
// must be compatible otherwise we panic.
|
||||||
func hasExt(d []byte) bool {
|
func hasExt(d []byte) bool {
|
||||||
|
|
|
@ -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
|
// TestPayload checks that we can correctly get the payload of an RTP packet
|
||||||
// using Payload for a variety of RTP packet configurations.
|
// using Payload for a variety of RTP packet configurations.
|
||||||
func TestPayload(t *testing.T) {
|
func TestPayload(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue