mirror of https://bitbucket.org/ausocean/av.git
rtp: fixed bug by actually checking to see if there is padding before adding padding size to end buf - which would mean there's actually padding
This commit is contained in:
parent
a6cbfee22b
commit
1a15889522
|
@ -73,6 +73,7 @@ func (p *Pkt) Bytes() []byte {
|
|||
}
|
||||
|
||||
buf := make([]byte, defaultHeadSize, defaultHeadSize+len(p.Payload)+p.Padding)
|
||||
|
||||
// First 4 bytes
|
||||
buf[0] |= p.V<<6 | p.P<<5 | p.CC
|
||||
buf[1] |= p.M<<7 | p.PT
|
||||
|
@ -88,8 +89,11 @@ func (p *Pkt) Bytes() []byte {
|
|||
buf[9] |= byte(p.SSRC >> 16)
|
||||
buf[10] |= byte(p.SSRC >> 8)
|
||||
buf[11] |= byte(p.SSRC)
|
||||
|
||||
// Add payload and padding
|
||||
buf = append(buf, p.Payload...)
|
||||
buf = append(buf, append(make([]byte, p.Padding-1, p.Padding), byte(p.Padding))...)
|
||||
if p.Padding != 0 {
|
||||
buf = append(buf, append(make([]byte, p.Padding-1, p.Padding), byte(p.Padding))...)
|
||||
}
|
||||
return buf
|
||||
}
|
||||
|
|
|
@ -64,9 +64,9 @@ var rtpTests = []struct {
|
|||
|
||||
func TestRtpPktToByteSlice(t *testing.T) {
|
||||
for _, test := range rtpTests {
|
||||
got := test.pkt
|
||||
got := test.pkt.Bytes()
|
||||
if !reflect.DeepEqual(got, test.want) {
|
||||
t.Errorf("unexpected error for %q: got:%v want:%v", test.num, got, test.want)
|
||||
t.Errorf("unexpected error for test %v: got:%v want:%v", test.num, got, test.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue