mirror of https://bitbucket.org/ausocean/av.git
container/mts/encoder_test.go: finished writing test TestEncodeVideo
Test is also now checking payload data as well as MPEGTS headers.
This commit is contained in:
parent
3292ce0506
commit
977dab9673
|
@ -52,15 +52,15 @@ func (d *destination) Write(p []byte) (int, error) {
|
||||||
return len(p), nil
|
return len(p), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// TestEncodeVideo checks that we can correctly encode some dummy data into a
|
||||||
|
// valid MPEGTS stream. This checks for correct MPEGTS headers and also that the
|
||||||
|
// original data is stored correctly and is retreivable.
|
||||||
func TestEncodeVideo(t *testing.T) {
|
func TestEncodeVideo(t *testing.T) {
|
||||||
Meta = meta.New()
|
Meta = meta.New()
|
||||||
|
|
||||||
const headAndAdaptLen = 12
|
|
||||||
const adaptNoStuffLen = 7
|
|
||||||
const dataLength = 440
|
const dataLength = 440
|
||||||
const numOfPackets = 3
|
const numOfPackets = 3
|
||||||
const stuffingLen = 88
|
const stuffingLen = 100
|
||||||
|
|
||||||
// Generate test data.
|
// Generate test data.
|
||||||
data := make([]byte, 0, dataLength)
|
data := make([]byte, 0, dataLength)
|
||||||
|
@ -83,17 +83,17 @@ func TestEncodeVideo(t *testing.T) {
|
||||||
0x47, // Sync byte.
|
0x47, // Sync byte.
|
||||||
0x01, // TEI=0, PUSI=0, TP=0, PID=00001 (256).
|
0x01, // TEI=0, PUSI=0, TP=0, PID=00001 (256).
|
||||||
0x00, // PID(Cont)=00000000.
|
0x00, // PID(Cont)=00000000.
|
||||||
0x31, // TSC=00, AFC=11(adaptation followed by payload), CC=0000(0).
|
0x31, // TSC=00, AFC=11(adaptation followed by payload), CC=0001(1).
|
||||||
0x07, // AFL= 7.
|
0x01, // AFL= 1.
|
||||||
0x10, // DI=0,RAI=0,ESPI=0,PCRF=1,OPCRF=0,SPF=0,TPDF=0, AFEF=0.
|
0x00, // DI=0,RAI=0,ESPI=0,PCRF=0,OPCRF=0,SPF=0,TPDF=0, AFEF=0.
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
0x47, // Sync byte.
|
0x47, // Sync byte.
|
||||||
0x01, // TEI=0, PUSI=0, TP=0, PID=00001 (256).
|
0x01, // TEI=0, PUSI=0, TP=0, PID=00001 (256).
|
||||||
0x00, // PID(Cont)=00000000.
|
0x00, // PID(Cont)=00000000.
|
||||||
0x31, // TSC=00, AFC=11(adaptation followed by payload), CC=0000(0).
|
0x32, // TSC=00, AFC=11(adaptation followed by payload), CC=0010(2).
|
||||||
byte(adaptNoStuffLen + stuffingLen), // AFL= 7+stuffingLen.
|
0x57, // AFL= 1+stuffingLen.
|
||||||
0x10, // DI=0,RAI=0,ESPI=0,PCRF=1,OPCRF=0,SPF=0,TPDF=0, AFEF=0.
|
0x00, // DI=0,RAI=0,ESPI=0,PCRF=1,OPCRF=0,SPF=0,TPDF=0, AFEF=0.
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,17 +116,39 @@ func TestEncodeVideo(t *testing.T) {
|
||||||
if pid == VideoPid {
|
if pid == VideoPid {
|
||||||
// Get mts header, excluding PCR.
|
// Get mts header, excluding PCR.
|
||||||
gotHeader := p[0:6]
|
gotHeader := p[0:6]
|
||||||
fmt.Printf("got: %v\n", p)
|
|
||||||
wantHeader := expectedHeaders[expectedIdx]
|
wantHeader := expectedHeaders[expectedIdx]
|
||||||
fmt.Printf("want: %v\n", expectedHeaders[expectedIdx])
|
|
||||||
if !bytes.Equal(gotHeader, wantHeader) {
|
if !bytes.Equal(gotHeader, wantHeader) {
|
||||||
t.Errorf("did not get expected header.\n Got: %v\n Want: %v\n", gotHeader, wantHeader)
|
t.Errorf("did not get expected header for idx: %v.\n Got: %v\n Want: %v\n", expectedIdx, gotHeader, wantHeader)
|
||||||
}
|
}
|
||||||
expectedIdx++
|
expectedIdx++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Gather payload data from packets to form the total PES packet.
|
||||||
|
var pesData []byte
|
||||||
|
for _, p := range dst.packets {
|
||||||
|
var _p packet.Packet
|
||||||
|
copy(_p[:], p)
|
||||||
|
pid := packet.Pid(&_p)
|
||||||
|
if pid == VideoPid {
|
||||||
|
payload, err := packet.Payload(&_p)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("could not get payload from mts packet, failed with err: %v\n", err)
|
||||||
|
}
|
||||||
|
pesData = append(pesData, payload...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get data from the PES packet and compare with the original data.
|
||||||
|
pes, err := pes.NewPESHeader(pesData)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("got error from pes creation: %v\n", err)
|
||||||
|
}
|
||||||
|
_data := pes.Data()
|
||||||
|
if !bytes.Equal(data, _data) {
|
||||||
|
t.Errorf("did not get expected result.\n Got: %v\n Want: %v\n", data, _data)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
// TestEncodePcm tests the mpegts encoder's ability to encode pcm audio data.
|
// TestEncodePcm tests the mpegts encoder's ability to encode pcm audio data.
|
||||||
// It reads and encodes input pcm data into mpegts, then decodes the mpegts and compares the result to the input pcm.
|
// It reads and encodes input pcm data into mpegts, then decodes the mpegts and compares the result to the input pcm.
|
||||||
|
|
Loading…
Reference in New Issue