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 {
|
type Pkt struct {
|
||||||
V byte
|
V byte // Version (currently 2)
|
||||||
P byte
|
P byte // Padding indicator (0 => padding, 1 => padding)
|
||||||
X byte
|
X byte // Extension header indicator
|
||||||
CC byte
|
CC byte // CSRC count
|
||||||
M byte
|
M byte // Marker bit
|
||||||
PT byte
|
PT byte // Packet type
|
||||||
SN int16
|
SN int16 // Synch number
|
||||||
TS int32
|
TS int32 // Timestamp
|
||||||
SSRC int32
|
SSRC int32 // Synchronisation source identifier
|
||||||
Payload []byte
|
Payload []byte // H264 Payload data
|
||||||
Padding int
|
Padding int // No of bytes of padding
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Pkt) Bytes() []byte {
|
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!")
|
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)
|
buf := make([]byte, defaultHeadSize, defaultHeadSize+len(p.Payload)+p.Padding)
|
||||||
// First 4 bytes
|
// First 4 bytes
|
||||||
buf[0] |= p.V<<6 | p.P<<5 | p.CC
|
buf[0] |= p.V<<6 | p.P<<5 | p.CC
|
||||||
|
|
|
@ -27,17 +27,44 @@ LICENSE
|
||||||
|
|
||||||
package rtp
|
package rtp
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
var rtpTests = []struct {
|
var rtpTests = []struct {
|
||||||
pkt Pkt
|
num int
|
||||||
byteOutput []byte
|
pkt Pkt
|
||||||
|
want []byte
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
pkt: Pkt{},
|
num: 1,
|
||||||
},
|
pkt: Pkt{
|
||||||
{
|
V: 2,
|
||||||
name: "null short",
|
P: 0,
|
||||||
input: []byte{0x00, 0x00, 0x01, 0x0},
|
X: 0,
|
||||||
delay: 0,
|
CC: 0,
|
||||||
want: [][]byte{{0x0, 0x0, 0x1, 0x9, 0xf0, 0x00, 0x00, 0x01, 0x0}},
|
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