mirror of https://bitbucket.org/ausocean/av.git
revid: mtsSender test for segmenting actually working now
This commit is contained in:
parent
b3b8c6bb44
commit
3f3d587eeb
|
@ -29,6 +29,7 @@ LICENSE
|
||||||
package revid
|
package revid
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
@ -58,9 +59,11 @@ type testSender struct {
|
||||||
|
|
||||||
func (ts *testSender) send(d []byte) error {
|
func (ts *testSender) send(d []byte) error {
|
||||||
if ts.tstDiscon && ts.curPktNo == ts.disconAt {
|
if ts.tstDiscon && ts.curPktNo == ts.disconAt {
|
||||||
return nil
|
return errors.New("could not send")
|
||||||
}
|
}
|
||||||
ts.Buf = append(ts.Buf, d)
|
cpy := make([]byte, len(d))
|
||||||
|
copy(cpy, d)
|
||||||
|
ts.Buf = append(ts.Buf, cpy)
|
||||||
ts.curPktNo++
|
ts.curPktNo++
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -100,10 +103,10 @@ func TestSegment(t *testing.T) {
|
||||||
mts.Meta = meta.New()
|
mts.Meta = meta.New()
|
||||||
// Create ringbuffer tst sender, loadsender and the mpegts encoder
|
// Create ringbuffer tst sender, loadsender and the mpegts encoder
|
||||||
rb := ring.NewBuffer(rbSize, rbElementSize, wTimeout)
|
rb := ring.NewBuffer(rbSize, rbElementSize, wTimeout)
|
||||||
tstSender := &testSender{}
|
tstSender := &testSender{Buf: make([][]byte, 0)}
|
||||||
loadSender := newMtsSender(tstSender, log)
|
loadSender := newMtsSender(tstSender, log)
|
||||||
packer := tstPacker{rb: rb}
|
packer := &tstPacker{rb: rb}
|
||||||
encoder := mts.NewEncoder(&packer, 25)
|
encoder := mts.NewEncoder(packer, 25)
|
||||||
|
|
||||||
// Turn time based psi writing off for encoder
|
// Turn time based psi writing off for encoder
|
||||||
const psiSendCount = 10
|
const psiSendCount = 10
|
||||||
|
@ -115,29 +118,32 @@ func TestSegment(t *testing.T) {
|
||||||
encoder.Encode([]byte{byte(i)})
|
encoder.Encode([]byte{byte(i)})
|
||||||
rb.Flush()
|
rb.Flush()
|
||||||
|
|
||||||
next, err := rb.Next(rTimeout)
|
for {
|
||||||
if err != nil {
|
next, err := rb.Next(rTimeout)
|
||||||
t.Fatalf("Unexpected err: %v\n", err)
|
if err != nil {
|
||||||
}
|
break
|
||||||
|
}
|
||||||
|
|
||||||
err = loadSender.load(next)
|
err = loadSender.load(next)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unexpected err: %v\n", err)
|
t.Fatalf("Unexpected err: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = loadSender.send()
|
err = loadSender.send()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unexpected err: %v\n", err)
|
t.Fatalf("Unexpected err: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
loadSender.release()
|
loadSender.release()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result := tstSender.Buf
|
result := tstSender.Buf
|
||||||
|
expectData := 0
|
||||||
for clipNo, clip := range result {
|
for clipNo, clip := range result {
|
||||||
// Check that the clip is the right length
|
// Check that the clip is the right length
|
||||||
clipLen := len(clip)
|
clipLen := len(clip)
|
||||||
if clipLen != psiSendCount {
|
if clipLen != psiSendCount*mts.PacketSize {
|
||||||
t.Fatalf("Clip %v is not correct length. Got: %v Want: %v\n Clip: %v\n", clipNo, clipLen, psiSendCount*mts.PacketSize, clip)
|
t.Fatalf("Clip %v is not correct length. Got: %v Want: %v\n Clip: %v\n", clipNo, clipLen, psiSendCount*mts.PacketSize, clip)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,6 +158,7 @@ func TestSegment(t *testing.T) {
|
||||||
|
|
||||||
// Check that the clip data is okay
|
// Check that the clip data is okay
|
||||||
for i := 0; i < len(clip); i += mts.PacketSize {
|
for i := 0; i < len(clip); i += mts.PacketSize {
|
||||||
|
firstPkt := clip[i : i+mts.PacketSize]
|
||||||
copy(pkt[:], firstPkt)
|
copy(pkt[:], firstPkt)
|
||||||
p := (*packet.Packet)(&pkt)
|
p := (*packet.Packet)(&pkt)
|
||||||
pid := p.PID()
|
pid := p.PID()
|
||||||
|
@ -169,19 +176,18 @@ func TestSegment(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the data from the pes packet and convert to int
|
// Get the data from the pes packet and convert to int
|
||||||
data := int(pes.Data()[0])
|
data := int8(pes.Data()[0])
|
||||||
|
|
||||||
// Calc expected data in the pes and then check
|
// Calc expected data in the pes and then check
|
||||||
expectedData := clipNo*10 + ((i / mts.PacketSize) - 2)
|
if data != int8(expectData) {
|
||||||
if data != expectedData {
|
t.Errorf("Did not get expected pkt data. ClipNo: %v, pktNoInClip: %v, Got: %v, want: %v\n", clipNo, i/mts.PacketSize, data, expectData)
|
||||||
t.Fatalf("Did not get expected pkt data. Got: %v, want: %v\n", data, expectedData)
|
|
||||||
}
|
}
|
||||||
|
expectData++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
func TestSendFailDiscontinuity(t *testing.T) {
|
func TestSendFailDiscontinuity(t *testing.T) {
|
||||||
mts.Meta = meta.New()
|
mts.Meta = meta.New()
|
||||||
// Create ringbuffer tst sender, loadsender and the mpegts encoder
|
// Create ringbuffer tst sender, loadsender and the mpegts encoder
|
||||||
|
@ -212,10 +218,7 @@ func TestSendFailDiscontinuity(t *testing.T) {
|
||||||
t.Fatalf("Unexpected err: %v\n", err)
|
t.Fatalf("Unexpected err: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = loadSender.send()
|
_ = loadSender.send()
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Unexpected err: %v\n", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
loadSender.release()
|
loadSender.release()
|
||||||
}
|
}
|
||||||
|
@ -226,9 +229,8 @@ func TestSendFailDiscontinuity(t *testing.T) {
|
||||||
expectedLen := ((noOfPacketsToWrite / psiSendCount) - 1)
|
expectedLen := ((noOfPacketsToWrite / psiSendCount) - 1)
|
||||||
gotLen := len(result)
|
gotLen := len(result)
|
||||||
if gotLen != expectedLen {
|
if gotLen != expectedLen {
|
||||||
t.Fatalf("We don't have one less clip as we should. Got: %v, want: %v\n", gotLen, expectedLen)
|
t.Errorf("We don't have one less clip as we should. Got: %v, want: %v\n", gotLen, expectedLen)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now check that the discontonuity indicator is set at the disconClip pat
|
// Now check that the discontonuity indicator is set at the disconClip pat
|
||||||
disconClip := result[disconClipNo]
|
disconClip := result[disconClipNo]
|
||||||
firstPkt := disconClip[:mts.PacketSize]
|
firstPkt := disconClip[:mts.PacketSize]
|
||||||
|
@ -242,5 +244,5 @@ func TestSendFailDiscontinuity(t *testing.T) {
|
||||||
if !discon {
|
if !discon {
|
||||||
t.Fatalf("Did not get discontinuity indicator for PAT")
|
t.Fatalf("Did not get discontinuity indicator for PAT")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
|
@ -171,8 +171,10 @@ func (s *mtsSender) send() error {
|
||||||
}
|
}
|
||||||
if pid == mts.VideoPid {
|
if pid == mts.VideoPid {
|
||||||
expect, exists := s.repairer.ExpectedCC(pid)
|
expect, exists := s.repairer.ExpectedCC(pid)
|
||||||
|
s.repairer.IncExpectedCC(pid)
|
||||||
if !exists {
|
if !exists {
|
||||||
s.repairer.SetExpectedCC(pid, cc)
|
s.repairer.SetExpectedCC(pid, cc)
|
||||||
|
s.repairer.IncExpectedCC(pid)
|
||||||
} else if cc != expect {
|
} else if cc != expect {
|
||||||
s.repairer.SetExpectedCC(pid, cc)
|
s.repairer.SetExpectedCC(pid, cc)
|
||||||
s.discard = true
|
s.discard = true
|
||||||
|
|
|
@ -67,7 +67,7 @@ func (dr *DiscontinuityRepairer) Repair(d []byte) error {
|
||||||
}
|
}
|
||||||
cc := p.ContinuityCounter()
|
cc := p.ContinuityCounter()
|
||||||
expect, exists := dr.ExpectedCC(pid)
|
expect, exists := dr.ExpectedCC(pid)
|
||||||
dr.incExpectedCC(pid)
|
dr.IncExpectedCC(pid)
|
||||||
if !exists {
|
if !exists {
|
||||||
dr.SetExpectedCC(pid, cc)
|
dr.SetExpectedCC(pid, cc)
|
||||||
} else if cc != int(expect) {
|
} else if cc != int(expect) {
|
||||||
|
@ -95,7 +95,7 @@ func (dr *DiscontinuityRepairer) ExpectedCC(pid int) (int, bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// incExpectedCC increments the expected cc.
|
// incExpectedCC increments the expected cc.
|
||||||
func (dr *DiscontinuityRepairer) incExpectedCC(pid int) {
|
func (dr *DiscontinuityRepairer) IncExpectedCC(pid int) {
|
||||||
dr.expCC[pid] = (dr.expCC[pid] + 1) & 0xf
|
dr.expCC[pid] = (dr.expCC[pid] + 1) & 0xf
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -171,19 +171,19 @@ const (
|
||||||
func (e *Encoder) TimeBasedPsi(b bool, sendCount int) {
|
func (e *Encoder) TimeBasedPsi(b bool, sendCount int) {
|
||||||
e.timeBasedPsi = b
|
e.timeBasedPsi = b
|
||||||
e.psiSendCount = sendCount
|
e.psiSendCount = sendCount
|
||||||
e.pktCount = e.psiSendCount + 1
|
e.pktCount = e.psiSendCount
|
||||||
}
|
}
|
||||||
|
|
||||||
// generate handles the incoming data and generates equivalent mpegts packets -
|
// generate handles the incoming data and generates equivalent mpegts packets -
|
||||||
// sending them to the output channel.
|
// sending them to the output channel.
|
||||||
func (e *Encoder) Encode(nalu []byte) error {
|
func (e *Encoder) Encode(nalu []byte) error {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
if (e.timeBasedPsi && (now.Sub(e.psiLastTime) > psiInterval)) || e.pktCount > e.psiSendCount {
|
if (e.timeBasedPsi && (now.Sub(e.psiLastTime) > psiInterval)) || e.pktCount >= e.psiSendCount {
|
||||||
|
e.pktCount = 0
|
||||||
err := e.writePSI()
|
err := e.writePSI()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
e.pktCount = 0
|
|
||||||
e.psiLastTime = now
|
e.psiLastTime = now
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue