From b134b874df55a70895f899b121099e499b9d9785 Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 22 Dec 2017 18:42:03 +1030 Subject: [PATCH] Performed some testing on MpegTs Now completed testing utilities for mpegts - which looks good. Now I need to look at testing the rtpToTsConverter. --- packets/MpegTs.go | 8 +++++--- packets/packets_test.go | 32 +++++++++++++++++++++----------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/packets/MpegTs.go b/packets/MpegTs.go index e124b1e2..a6f65544 100644 --- a/packets/MpegTs.go +++ b/packets/MpegTs.go @@ -83,9 +83,11 @@ func (p *MpegTsPacket) ToByteSlice() (output []byte) { } //copy(output[4:4+len(p.AF)],p.AF) //headerSize := packetLength-len(p.Payload) - headerSize := 4 + len(p.AF) - for ii := headerSize; ii < packetLength; ii++ { - output[ii] = p.Payload[ii-headerSize] + fmt.Printf("Length of AF: %v\n", len(p.AF)) + payloadIndex := 4 + len(p.AF) + for ii := payloadIndex; ii < packetLength; ii++ { + output[ii] = p.Payload[ii-payloadIndex] + fmt.Println(ii) } fmt.Printf("Packet size: %v\n",len(output)) //fmt.Printf("Packet: %v\n",output) diff --git a/packets/packets_test.go b/packets/packets_test.go index 468eb737..70c4340e 100644 --- a/packets/packets_test.go +++ b/packets/packets_test.go @@ -292,6 +292,13 @@ Mpegts testing ********************************************************/ func TestMpegTsToByteSlice(t *testing.T){ + afRemainderLength := 180 + afField := make([]byte, afRemainderLength+1) + afField[0] = byte(afRemainderLength) + afField[1] = byte(0) + for i := 2; i < len(afField); i++ { + afField[i] = 0xFF + } tsPkt := MpegTsPacket{ byte(0x47), // sync byte bool(false), // TEI @@ -301,12 +308,7 @@ func TestMpegTsToByteSlice(t *testing.T){ byte(0), // TSC byte(3), // AFC byte(6), // CC - []byte{ - byte(3), // AF length after this byte 1 + 2*stuffing byte - byte(0), // AF flags for optional fields - 0xFF, // stuffing byte 1 - 0xFF, // stuffing byte 2 - }, + afField, // AF []byte{ // data 0x67, 0xB2, @@ -318,7 +320,7 @@ func TestMpegTsToByteSlice(t *testing.T){ 0x01, 0x00, 0x36, - 0x03, + byte(afRemainderLength), 0x00, // this is where stuffing is, expect that to be 0xFF 0x67, @@ -333,16 +335,24 @@ func TestMpegTsToByteSlice(t *testing.T){ } } // Check that the stuffing is all there - for ii := 6; ii < 179; ii++ { + for ii := 6; ii < 185; ii++ { if tsPktAsByteSlice[ii] != 0xFF { t.Errorf("Conversion to byte slice bad! Byte: %v Wanted: %v Got: %v", - ii, expectedOutput[ii], tsPktAsByteSlice[ii]) + ii, byte(0xFF), tsPktAsByteSlice[ii]) } } - for ii := 6; ii < 179; ii++ { - if tsPktAsByteSlice[ii] != 0xFF { + for ii := 185; ii < 188; ii++ { + if tsPktAsByteSlice[ii] != expectedOutput[ii-185+6] { t.Errorf("Conversion to byte slice bad! Byte: %v Wanted: %v Got: %v", ii, expectedOutput[ii], tsPktAsByteSlice[ii]) } } } + +/******************************************************* +RtpToTsConverter testing +********************************************************/ + +func TestRtpToTsConverter(t *testing.T){ + +}