mirror of https://bitbucket.org/ausocean/av.git
rtp: writing test function inside rtp_test.go
This commit is contained in:
parent
4e7e779de7
commit
9f329d49b6
|
@ -36,17 +36,17 @@ const (
|
|||
)
|
||||
|
||||
type Pkt struct {
|
||||
V byte
|
||||
P byte
|
||||
X byte
|
||||
CC byte
|
||||
M byte
|
||||
PT byte
|
||||
SN int16
|
||||
TS int32
|
||||
SSRC int32
|
||||
Payload []byte
|
||||
Padding int
|
||||
V byte // Version (currently 2)
|
||||
P byte // Padding indicator (0 => padding, 1 => padding)
|
||||
X byte // Extension header indicator
|
||||
CC byte // CSRC count
|
||||
M byte // Marker bit
|
||||
PT byte // Packet type
|
||||
SN int16 // Synch number
|
||||
TS int32 // Timestamp
|
||||
SSRC int32 // Synchronisation source identifier
|
||||
Payload []byte // H264 Payload data
|
||||
Padding int // No of bytes of padding
|
||||
}
|
||||
|
||||
func (p *Pkt) Bytes() []byte {
|
||||
|
@ -64,6 +64,14 @@ func (p *Pkt) Bytes() []byte {
|
|||
panic("CC has been set to something other than 0 - this is not supported yet!")
|
||||
}
|
||||
|
||||
if p.X != 0 {
|
||||
panic("rtp: X (extension header indicator) not 0, but extensiion headers not currently supported!")
|
||||
}
|
||||
|
||||
if p.CC != 0 {
|
||||
panic("rtp: CC (CSRC count) not 0, but CSRC headers not yet supported!")
|
||||
}
|
||||
|
||||
buf := make([]byte, defaultHeadSize, defaultHeadSize+len(p.Payload)+p.Padding)
|
||||
// First 4 bytes
|
||||
buf[0] |= p.V<<6 | p.P<<5 | p.CC
|
||||
|
|
|
@ -27,17 +27,44 @@ LICENSE
|
|||
|
||||
package rtp
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var rtpTests = []struct {
|
||||
pkt Pkt
|
||||
byteOutput []byte
|
||||
num int
|
||||
pkt Pkt
|
||||
want []byte
|
||||
}{
|
||||
{
|
||||
pkt: Pkt{},
|
||||
},
|
||||
{
|
||||
name: "null short",
|
||||
input: []byte{0x00, 0x00, 0x01, 0x0},
|
||||
delay: 0,
|
||||
want: [][]byte{{0x0, 0x0, 0x1, 0x9, 0xf0, 0x00, 0x00, 0x01, 0x0}},
|
||||
num: 1,
|
||||
pkt: Pkt{
|
||||
V: 2,
|
||||
P: 0,
|
||||
X: 0,
|
||||
CC: 0,
|
||||
M: 0,
|
||||
PT: 6,
|
||||
SN: 167,
|
||||
TS: 160,
|
||||
SSRC: 10,
|
||||
Payload: []byte{0x00, 0x01, 0x07, 0xf0, 0x56, 0x37, 0x0a, 0x0f},
|
||||
Padding: 0,
|
||||
},
|
||||
want: []byte{
|
||||
0x80, 0x06, 0x00, 0xa7,
|
||||
0x00, 0x00, 0x00, 0xa0,
|
||||
0x00, 0x00, 0x00, 0x0a,
|
||||
0x00, 0x01, 0x07, 0xf0,
|
||||
0x56, 0x37, 0x0a, 0x0f,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func TestRtpPktToByteSlice(t *testing.T) {
|
||||
got := rtpTests.pkt
|
||||
if !reflect.DeepEqual(got, tests.Want) {
|
||||
t.Errorf("unexpected error for %q: got:%v want:%v", test.num, got, tests.Want)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue