mirror of
https://github.com/jech/galene.git
synced 2024-11-09 18:25:58 +01:00
Add tests for codec manipulation and rtpconn data stuctures.
This commit is contained in:
parent
6f9d7fc306
commit
435f46c520
2 changed files with 79 additions and 0 deletions
43
rtpconn/codec_test.go
Normal file
43
rtpconn/codec_test.go
Normal file
|
@ -0,0 +1,43 @@
|
|||
package rtpconn
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
var vp8 = []byte{
|
||||
0x80, 0, 0, 42,
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0, 0,
|
||||
|
||||
0x90, 0x80, 0x80, 57,
|
||||
|
||||
0, 0, 0, 0,
|
||||
}
|
||||
|
||||
func TestPacketFlags(t *testing.T) {
|
||||
buf := append([]byte{}, vp8...)
|
||||
seqno, start, pid, tid, sid, layersync, discardable, err :=
|
||||
packetFlags("video/vp8", buf)
|
||||
if seqno != 42 || !start || pid != 57 || sid != 0 || tid != 0 ||
|
||||
layersync || discardable || err != nil {
|
||||
t.Errorf("Got %v, %v, %v, %v, %v, %v (%v)",
|
||||
seqno, start, pid, sid, layersync, discardable, err,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRewrite(t *testing.T) {
|
||||
for i := uint16(0); i < 0x7fff; i++ {
|
||||
buf := append([]byte{}, vp8...)
|
||||
err := rewritePacket("video/vp8", buf, i, i)
|
||||
if err != nil {
|
||||
t.Errorf("rewrite: %v", err)
|
||||
continue
|
||||
}
|
||||
seqno, _, pid, _, _, _, _, err := packetFlags("video/vp8", buf)
|
||||
if err != nil || seqno != i || pid != (57 + i) & 0x7FFF {
|
||||
t.Errorf("Expected %v %v, got %v %v (%v)",
|
||||
i, (57 + i) & 0x7FFF, seqno, pid, err)
|
||||
}
|
||||
}
|
||||
}
|
36
rtpconn/rtpconn_test.go
Normal file
36
rtpconn/rtpconn_test.go
Normal file
|
@ -0,0 +1,36 @@
|
|||
package rtpconn
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/jech/galene/rtptime"
|
||||
)
|
||||
|
||||
func TestDownTrackAtomics(t *testing.T) {
|
||||
down := &rtpDownTrack{
|
||||
atomics: &downTrackAtomics{},
|
||||
maxBitrate: new(bitrate),
|
||||
maxREMBBitrate: new(bitrate),
|
||||
}
|
||||
|
||||
down.SetTimeOffset(1, 2)
|
||||
down.setRTT(3)
|
||||
down.setSRTime(4, 5)
|
||||
down.maxBitrate.Set(6, rtptime.Jiffies())
|
||||
down.maxREMBBitrate.Set(7, rtptime.Jiffies())
|
||||
down.setLayerInfo(8, 9, 10)
|
||||
ntp, rtp := down.getTimeOffset()
|
||||
rtt := down.getRTT()
|
||||
sr, srntp := down.getSRTime()
|
||||
br, lbr := down.GetMaxBitrate()
|
||||
l, w, m := down.getLayerInfo()
|
||||
if ntp != 1 || rtp != 2 || rtt != 3 || sr != 4 || srntp != 5 ||
|
||||
br != 6 || lbr != 8 || l != 8 || w != 9 || m != 10 {
|
||||
t.Errorf(
|
||||
"Expected 1 2 3 4 5 6 8 8 9 10, "+
|
||||
"got %v %v %v %v %v %v %v %v %v %v",
|
||||
ntp, rtp, rtt, sr, srntp, br, lbr, l, w, m,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in a new issue