mirror of https://bitbucket.org/ausocean/av.git
stream/mts: checking data is also good in mts segment test
This commit is contained in:
parent
a5cb1c5abb
commit
b3b8c6bb44
|
@ -38,6 +38,7 @@ import (
|
|||
"bitbucket.org/ausocean/utils/logger"
|
||||
"bitbucket.org/ausocean/utils/ring"
|
||||
"github.com/Comcast/gots/packet"
|
||||
"github.com/Comcast/gots/pes"
|
||||
)
|
||||
|
||||
// Ring buffer sizes and read/write timeouts.
|
||||
|
@ -49,11 +50,18 @@ const (
|
|||
)
|
||||
|
||||
type testSender struct {
|
||||
Buf [][]byte
|
||||
Buf [][]byte
|
||||
tstDiscon bool
|
||||
disconAt int
|
||||
curPktNo int
|
||||
}
|
||||
|
||||
func (ts *testSender) send(d []byte) error {
|
||||
if ts.tstDiscon && ts.curPktNo == ts.disconAt {
|
||||
return nil
|
||||
}
|
||||
ts.Buf = append(ts.Buf, d)
|
||||
ts.curPktNo++
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -139,11 +147,100 @@ func TestSegment(t *testing.T) {
|
|||
copy(pkt[:], firstPkt)
|
||||
pid := (*packet.Packet)(&pkt).PID()
|
||||
if pid != mts.PatPid {
|
||||
t.Fatalf("First packte of clip %v is not pat, but rather: %v\n", clipNo, pid)
|
||||
t.Fatalf("First packet of clip %v is not pat, but rather: %v\n", clipNo, pid)
|
||||
}
|
||||
|
||||
// Check that the clip data is okay
|
||||
for i := 0; i < len(clip); i += mts.PacketSize {
|
||||
copy(pkt[:], firstPkt)
|
||||
p := (*packet.Packet)(&pkt)
|
||||
pid := p.PID()
|
||||
if pid == mts.VideoPid {
|
||||
// Mts payload
|
||||
payload, err := p.Payload()
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected err: %v\n", err)
|
||||
}
|
||||
|
||||
// Parse pes from the mts payload
|
||||
pes, err := pes.NewPESHeader(payload)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected err: %v\n", err)
|
||||
}
|
||||
|
||||
// Get the data from the pes packet and convert to int
|
||||
data := int(pes.Data()[0])
|
||||
|
||||
// Calc expected data in the pes and then check
|
||||
expectedData := clipNo*10 + ((i / mts.PacketSize) - 2)
|
||||
if data != expectedData {
|
||||
t.Fatalf("Did not get expected pkt data. Got: %v, want: %v\n", data, expectedData)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiscontinuity(t *testing.T) {
|
||||
/*
|
||||
func TestSendFailDiscontinuity(t *testing.T) {
|
||||
mts.Meta = meta.New()
|
||||
// Create ringbuffer tst sender, loadsender and the mpegts encoder
|
||||
rb := ring.NewBuffer(rbSize, rbElementSize, wTimeout)
|
||||
const disconClipNo = 3
|
||||
tstSender := &testSender{tstDiscon: true, disconAt: disconClipNo}
|
||||
loadSender := newMtsSender(tstSender, log)
|
||||
packer := tstPacker{rb: rb}
|
||||
encoder := mts.NewEncoder(&packer, 25)
|
||||
|
||||
// Turn time based psi writing off for encoder
|
||||
const psiSendCount = 10
|
||||
encoder.TimeBasedPsi(false, psiSendCount)
|
||||
|
||||
const noOfPacketsToWrite = 100
|
||||
for i := 0; i < noOfPacketsToWrite; i++ {
|
||||
// Our payload will just be packet no
|
||||
encoder.Encode([]byte{byte(i)})
|
||||
rb.Flush()
|
||||
|
||||
next, err := rb.Next(rTimeout)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected err: %v\n", err)
|
||||
}
|
||||
|
||||
err = loadSender.load(next)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected err: %v\n", err)
|
||||
}
|
||||
|
||||
err = loadSender.send()
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected err: %v\n", err)
|
||||
}
|
||||
|
||||
loadSender.release()
|
||||
}
|
||||
|
||||
result := tstSender.Buf
|
||||
|
||||
// First check that we have less clips
|
||||
expectedLen := ((noOfPacketsToWrite / psiSendCount) - 1)
|
||||
gotLen := len(result)
|
||||
if gotLen != expectedLen {
|
||||
t.Fatalf("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
|
||||
disconClip := result[disconClipNo]
|
||||
firstPkt := disconClip[:mts.PacketSize]
|
||||
var pkt [mts.PacketSize]byte
|
||||
copy(pkt[:], firstPkt)
|
||||
discon, err := (*packet.AdaptationField)((*packet.Packet)(&pkt)).Discontinuity()
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected err: %v\n", err)
|
||||
}
|
||||
|
||||
if !discon {
|
||||
t.Fatalf("Did not get discontinuity indicator for PAT")
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue