mirror of https://bitbucket.org/ausocean/av.git
Pes packet passing tests
This commit is contained in:
parent
862c3a67e2
commit
da11e2888f
34
pes/Pes.go
34
pes/Pes.go
|
@ -26,6 +26,9 @@ LICENSE
|
|||
|
||||
package pes
|
||||
|
||||
import (
|
||||
"../tools"
|
||||
)
|
||||
/*
|
||||
The below data struct encapsulates the fields of an PES packet. Below is
|
||||
the formatting of a PES packet for reference!
|
||||
|
@ -42,7 +45,7 @@ the formatting of a PES packet for reference!
|
|||
----------------------------------------------------------------------------
|
||||
| octet 3 | Stream ID (0xE0 for video) |
|
||||
----------------------------------------------------------------------------
|
||||
| octet 4 | PES Packet Length (no bytes in packet after this field) |
|
||||
| octet 4 | PES Packet Length (no of bytes in packet after this field) |
|
||||
----------------------------------------------------------------------------
|
||||
| octet 5 | PES Length cont. |
|
||||
----------------------------------------------------------------------------
|
||||
|
@ -81,8 +84,12 @@ type PESPacket struct {
|
|||
CRCF bool // Not sure
|
||||
EF bool // Extension flag
|
||||
HeaderLength byte // Pes header length
|
||||
OptFields []byte // Optional fields
|
||||
Stuffing []byte // Stuffing bytes
|
||||
PTS uint64 // Presentation time stamp
|
||||
DTS uint64 // Decoding timestamp
|
||||
ESCR uint64 // Elementary stream clock reference
|
||||
ESR uint32 // Elementary stream rate reference
|
||||
// TODO: add DSMTM, ACI, CRC, Ext fields
|
||||
Stuff []byte // Stuffing bytes
|
||||
Data []byte // Pes packet data
|
||||
}
|
||||
|
||||
|
@ -92,12 +99,23 @@ func (p *PESPacket) ToByteSlice() (output []byte) {
|
|||
p.StreamID,
|
||||
byte((p.Length & 0xFF00) >> 8),
|
||||
byte(p.Length & 0x00FF),
|
||||
(0x2<<6 | p.SC<<4 | boolToByte(p.Priority)<<3 | boolToByte(p.DAI)<<2 |
|
||||
boolToByte(p.Copyright)<<1 | boolToByte(p.Original)),
|
||||
(p.PDI<<6 | boolToByte(p.ESCRF)<<5 | boolToByte(p.ESRF)<<4 | boolToByte(p.DSMTMF)<<3 |
|
||||
boolToByte(p.ACIF)<<2 | boolToByte(p.CRCF)<<1 | boolToByte(p.EF)),
|
||||
(0x2<<6 | p.SC<<4 | tools.BoolToByte(p.Priority)<<3 | tools.BoolToByte(p.DAI)<<2 |
|
||||
tools.BoolToByte(p.Copyright)<<1 | tools.BoolToByte(p.Original)),
|
||||
(p.PDI<<6 | tools.BoolToByte(p.ESCRF)<<5 | tools.BoolToByte(p.ESRF)<<4 | tools.BoolToByte(p.DSMTMF)<<3 |
|
||||
tools.BoolToByte(p.ACIF)<<2 | tools.BoolToByte(p.CRCF)<<1 | tools.BoolToByte(p.EF)),
|
||||
p.HeaderLength,
|
||||
}...)
|
||||
output = append(output, append(p.OptFields, append(p.Stuffing, p.Data...)...)...)
|
||||
if p.PDI == byte(2) {
|
||||
pts := 0x2100010001 | (p.PTS & 0x1C0000000) << 3 | (p.PTS & 0x3FFF8000)<<2 |
|
||||
(p.PTS & 0x7FFF) << 1
|
||||
output = append(output, []byte{
|
||||
byte((pts & 0xFF00000000)>> 32),
|
||||
byte((pts & 0x00FF000000)>> 24),
|
||||
byte((pts & 0x0000FF0000)>>16),
|
||||
byte((pts & 0x000000FF00)>>8),
|
||||
byte(pts & 0x00000000FF),
|
||||
}...)
|
||||
}
|
||||
output = append(output, append(p.Stuff, p.Data...)...)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -38,28 +38,12 @@ const (
|
|||
|
||||
func TestPesToByteSlice(t *testing.T) {
|
||||
pesPkt := PESPacket{
|
||||
byte(0xE0), // StreamID
|
||||
uint16(6), // Length
|
||||
byte(0), // ScramblingControl
|
||||
bool(true), // Priority
|
||||
bool(false), // DAI
|
||||
bool(false), // copyright
|
||||
bool(true), // Original
|
||||
byte(0), // PDI
|
||||
bool(false), // Escr
|
||||
bool(false), // ESRate
|
||||
bool(false), // DSMTrickMode
|
||||
bool(false), // ACI
|
||||
bool(false), // CRC
|
||||
bool(false), // Ext
|
||||
byte(0), // header length
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
[]byte{ // data
|
||||
0xEA,
|
||||
0x4B,
|
||||
0x12,
|
||||
},
|
||||
StreamID: 0xE0, // StreamID
|
||||
PDI: byte(2),
|
||||
PTS: 100000,
|
||||
HeaderLength: byte(11),
|
||||
Stuff: []byte{0xFF,0xFF,},
|
||||
Data: []byte{ 0xEA, 0x4B, 0x12, },
|
||||
}
|
||||
pesExpectedOutput := []byte{
|
||||
0x00, // packet start code prefix byte 1
|
||||
|
@ -67,10 +51,17 @@ func TestPesToByteSlice(t *testing.T) {
|
|||
0x01, // packet start code prefix byte 3
|
||||
0xE0, // stream ID
|
||||
0x00, // PES Packet length byte 1
|
||||
0x06, // PES packet length byte 2
|
||||
0x89, // Marker bits,ScramblingControl, Priority, DAI, Copyright, Original
|
||||
0x00, // PDI, ESCR, ESRate, DSMTrickMode, ACI, CRC, Ext
|
||||
0x00, // header length
|
||||
0x00, // PES packet length byte 2
|
||||
0x80, // Marker bits,ScramblingControl, Priority, DAI, Copyright, Original
|
||||
0x80, // PDI, ESCR, ESRate, DSMTrickMode, ACI, CRC, Ext
|
||||
byte(11), // header length
|
||||
0x21, // PCR byte 1
|
||||
0x00, // pcr byte 2
|
||||
0x07, // pcr byte 3
|
||||
0x0D, // pcr byte 4
|
||||
0x41, // pcr byte 5
|
||||
0xFF, // Stuffing byte 1
|
||||
0xFF, // stuffing byte 3
|
||||
0xEA, // data byte 1
|
||||
0x4B, // data byte 2
|
||||
0x12, // data byte 3
|
||||
|
|
Loading…
Reference in New Issue