Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add muxer #16

Merged
merged 57 commits into from
Mar 24, 2021
Merged
Changes from 1 commit
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
d07a182
starting
Jan 25, 2021
0798d32
pcr write
Jan 27, 2021
c9e1bff
go-astikit replacement until PR is merged
Jan 28, 2021
9c4fa08
packet header, adaptation field, dts write
Jan 28, 2021
8741f0c
dependency cleanup
Feb 1, 2021
905064d
get rid of panic/recover for writing
Feb 2, 2021
f298e1e
make writePCR code more adequate
Feb 2, 2021
5c71b25
writePacket and adaptation field length calculation
Feb 2, 2021
278fce9
writePacket and adaptation field length calculation
Feb 2, 2021
4047b66
s/188/MpegTsPacketSize/
Feb 2, 2021
7dc14a4
writePATSection
Feb 2, 2021
28edb16
Try* -> BitsWriterBatch
Feb 3, 2021
b4a87e9
descriptors WIP
Feb 3, 2021
e7a5601
go-astikit version bump
Feb 3, 2021
3dae8fc
descriptors WIP
Feb 4, 2021
b06993f
descriptor parsing tests refactored to allow reuse for descriptor wri…
Feb 5, 2021
3e5341d
descriptors writing tested
Feb 5, 2021
8aa5b6c
descriptors writing refactoring
Feb 5, 2021
e4788ba
descriptors done, PMT WIP
Feb 5, 2021
28a686e
write PMT section fix
Feb 11, 2021
fc82353
writePSIData works
Feb 12, 2021
f82bc07
WIP
Feb 17, 2021
db031e6
PES WIP
Feb 18, 2021
05b66f0
PES functions pass tests
Feb 19, 2021
705a8d3
minor fix
Feb 20, 2021
9391d51
muxer: pat & pmt
Feb 26, 2021
78bebcd
muxer: more tests
Feb 26, 2021
2475c9b
muxer: payload writing
Feb 27, 2021
05cec28
es-split WIP
Feb 27, 2021
69ec742
es-split seems to work
Feb 28, 2021
f060240
es-split PCR sync; some style fixes
Mar 2, 2021
9191588
Data.Kind cleanup
Mar 2, 2021
074bd9b
comment update
Mar 2, 2021
881e1c3
cleanup
Mar 2, 2021
de205b4
cleanup
Mar 2, 2021
ca51287
go-astikit dep replace removed
Mar 3, 2021
b07932b
comment fix
Mar 3, 2021
e98cd9e
minor fix
Mar 3, 2021
583de87
flush on pid change removed as it seems to be unnecessary
Mar 3, 2021
449222b
added some streamtype info funcs
Mar 4, 2021
3916b58
StreamType and PSITableTypeID are special types now
Mar 5, 2021
b069beb
comment cleanup
Mar 6, 2021
72ce363
use PSITableTypeId more instead of comparing strings
Mar 6, 2021
40fd6af
comment cleanup
Mar 6, 2021
6b7966e
PSITableTypeId -> PSITableTypeID
Mar 9, 2021
a6249bb
PESIsVideoStreamId -> PESIsVideoStreamID
Mar 9, 2021
5064bcb
PSITableTypeID.String() -> PSITableTypeID.Type()
Mar 9, 2021
2abf745
review fixes: first pack: constants and stuff
Mar 22, 2021
5d7277f
packet_buffer read() renamed to peek()
Mar 23, 2021
6af7b0b
tools are moved to cmd directory
Mar 24, 2021
a5c45f3
correct prefixes for muxer and demuxer opts
Mar 24, 2021
18725af
SetPCRPID instead of isPCRPID of AddElementaryStream
Mar 24, 2021
432588a
test fix and some comments
Mar 24, 2021
135fae5
muxer WritePacket export
Mar 24, 2021
f2a492a
`astits.New` renamed to `NewDemuxer`
Mar 24, 2021
e943295
astikit version bump; writeBytesN removed in favor of one in BitsWriter
Mar 24, 2021
bc4c488
WritePayload -> WriteData with MuxerData
Mar 24, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
PES functions pass tests
Ilya Barbashov committed Feb 19, 2021
commit 05b66f0920dc353ee28dde8868a2738b4f875ac2
98 changes: 67 additions & 31 deletions data_pes.go
Original file line number Diff line number Diff line change
@@ -365,12 +365,11 @@ func parsePESOptionalHeader(i *astikit.BytesIterator) (h *PESOptionalHeader, dat
// Extension 2
if h.HasExtension2 {
// Length
var bs []byte
if bs, err = i.NextBytes(2); err != nil {
if b, err = i.NextByte(); err != nil {
err = fmt.Errorf("astits: fetching next bytes failed: %w", err)
return
}
h.Extension2Length = uint8(bs[0]) & 0x7f
h.Extension2Length = uint8(b) & 0x7f

// Data
if h.Extension2Data, err = i.NextBytes(int(h.Extension2Length)); err != nil {
@@ -421,61 +420,83 @@ func parseESCR(i *astikit.BytesIterator) (cr *ClockReference, err error) {
return
}

// will count how many total bytes and payload bytes will be written when writePESData is called with the same arguments
// should be used by the caller of writePESData to determine AF stuffing size needed to be applied
func calcPESDataLength(h *PESHeader, payloadLeft []byte, isPayloadStart bool, bytesAvailable int) (totalBytes, payloadBytes int) {
totalBytes += PESHeaderLength
if isPayloadStart {
totalBytes += int(calcPESOptionalHeaderLength(h.OptionalHeader))
}
bytesAvailable -= totalBytes

if len(payloadLeft) < bytesAvailable {
payloadBytes = len(payloadLeft)
} else {
payloadBytes = bytesAvailable
}

return
}

// first packet will contain PES header with optional PES header and payload, if possible
// all consequential packets will contain just PES header and payload
// last packet will contain AF with stuffing
func writePESData(w *astikit.BitsWriter, h *PESHeader, payloadLeft []byte, isPayloadStart bool, bytesAvailable int) (totalBytesWritten, payloadBytesWritten int, err error) {
var n int

headerLength := PESHeaderLength
//headerLength := PESHeaderLength
//if isPayloadStart {
// headerLength += int(calcPESOptionalHeaderLength(h.OptionalHeader))
//}
//if bytesAvailable-headerLength > len(payloadLeft) {
// // XXX i don't like this, it doesn't belong here
// af := &PacketAdaptationField{}
// afLength := 1+int(calcPacketAdaptationFieldLength(af)) // additional 1 byte is for the AF length field
// af.StuffingLength = bytesAvailable - len(payloadLeft) - headerLength - afLength
// n, err = writePacketAdaptationField(w, af)
// if err != nil {
// return
// }
// totalBytesWritten += n
//}

if isPayloadStart {
headerLength += int(calcPESOptionalHeaderLength(h.OptionalHeader))
}
if bytesAvailable-headerLength > len(payloadLeft) {
// XXX i don't like this
af := &PacketAdaptationField{
StuffingLength: bytesAvailable - len(payloadLeft) - headerLength,
}
n, err = writePacketAdaptationField(w, af)
n, err = writePESHeader(w, h, uint16(len(payloadLeft)))
if err != nil {
return
}
totalBytesWritten += n
}

n, err = writePESHeader(w, h, uint16(len(payloadLeft)), isPayloadStart)
if err != nil {
return
payloadBytesWritten = bytesAvailable - totalBytesWritten
if payloadBytesWritten > len(payloadLeft) {
payloadBytesWritten = len(payloadLeft)
}
totalBytesWritten += n

bytesAvailable -= totalBytesWritten

err = w.Write(payloadLeft[:bytesAvailable])
err = w.Write(payloadLeft[:payloadBytesWritten])
if err != nil {
return
}

payloadBytesWritten = bytesAvailable
totalBytesWritten += payloadBytesWritten
return
}

func writePESHeader(w *astikit.BitsWriter, h *PESHeader, payloadSize uint16, isPayloadStart bool) (int, error) {
func writePESHeader(w *astikit.BitsWriter, h *PESHeader, payloadSize uint16) (int, error) {
b := astikit.NewBitsWriterBatch(w)

b.WriteN(0x000001, 24) // packet_start_code_prefix
b.WriteN(uint32(0x000001), 24) // packet_start_code_prefix
b.Write(h.StreamID)

pesPacketLength := payloadSize
if isPayloadStart && hasPESOptionalHeader(h.StreamID) {
pesPacketLength += calcPESOptionalHeaderLength(h.OptionalHeader)
if hasPESOptionalHeader(h.StreamID) {
pesPacketLength += uint16(calcPESOptionalHeaderLength(h.OptionalHeader))
}
b.Write(pesPacketLength)

bytesWritten := PESHeaderLength

if isPayloadStart && hasPESOptionalHeader(h.StreamID) {
if hasPESOptionalHeader(h.StreamID) {
n, err := writePESOptionalHeader(w, h.OptionalHeader)
if err != nil {
return 0, err
@@ -486,11 +507,14 @@ func writePESHeader(w *astikit.BitsWriter, h *PESHeader, payloadSize uint16, isP
return bytesWritten, b.Err()
}

func calcPESOptionalHeaderLength(h *PESOptionalHeader) uint16 {
func calcPESOptionalHeaderLength(h *PESOptionalHeader) uint8 {
if h == nil {
return 0
}
return 3 + calcPESOptionalHeaderDataLength(h)
}

func calcPESOptionalHeaderDataLength(h *PESOptionalHeader) (length uint16) {
func calcPESOptionalHeaderDataLength(h *PESOptionalHeader) (length uint8) {
if h.PTSDTSIndicator == PTSDTSIndicatorOnlyPTS {
length += PTSorDTSByteLength
} else if h.PTSDTSIndicator == PTSDTSIndicatorBothPresent {
@@ -537,17 +561,21 @@ func calcPESOptionalHeaderDataLength(h *PESOptionalHeader) (length uint16) {
}

if h.HasExtension2 {
length += 1 + uint16(len(h.Extension2Data))
length += 1 + uint8(len(h.Extension2Data))
}
}

return
}

func writePESOptionalHeader(w *astikit.BitsWriter, h *PESOptionalHeader) (int, error) {
if h == nil {
return 0, nil
}

b := astikit.NewBitsWriterBatch(w)

b.WriteN(uint8(0b01), 2) // marker bits
b.WriteN(uint8(0b10), 2) // marker bits
b.WriteN(h.ScramblingControl, 2)
b.Write(h.Priority)
b.Write(h.DataAlignmentIndicator)
@@ -568,7 +596,7 @@ func writePESOptionalHeader(w *astikit.BitsWriter, h *PESOptionalHeader) (int, e

bytesWritten := 3

if h.PTSDTSIndicator == PTSDTSIndicatorOnlyPTS || h.PTSDTSIndicator == PTSDTSIndicatorBothPresent {
if h.PTSDTSIndicator == PTSDTSIndicatorOnlyPTS {
n, err := writePTSOrDTS(w, 0b0010, h.PTS)
if err != nil {
return 0, err
@@ -577,7 +605,13 @@ func writePESOptionalHeader(w *astikit.BitsWriter, h *PESOptionalHeader) (int, e
}

if h.PTSDTSIndicator == PTSDTSIndicatorBothPresent {
n, err := writePTSOrDTS(w, 0b0011, h.DTS)
n, err := writePTSOrDTS(w, 0b0011, h.PTS)
if err != nil {
return 0, err
}
bytesWritten += n

n, err = writePTSOrDTS(w, 0b0001, h.DTS)
if err != nil {
return 0, err
}
@@ -618,6 +652,8 @@ func writePESOptionalHeader(w *astikit.BitsWriter, h *PESOptionalHeader) (int, e
}

if h.HasExtension {
// exp 10110001
// act 10111111
b.Write(h.HasPrivateData)
b.Write(false) // TODO pack_header_field_flag, not implemented
//b.Write(h.HasPackHeaderField)
256 changes: 182 additions & 74 deletions data_pes_test.go
Original file line number Diff line number Diff line change
@@ -146,10 +146,10 @@ func TestWriteDSMTrickMode(t *testing.T) {

var ptsClockReference = &ClockReference{Base: 5726623061}

func ptsBytes() []byte {
func ptsBytes(flag string) []byte {
buf := &bytes.Buffer{}
w := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: buf})
w.Write("0010") // Flag
w.Write(flag) // Flag
w.Write("101") // 32...30
w.Write("1") // Dummy
w.Write("010101010101010") // 29...15
@@ -161,10 +161,10 @@ func ptsBytes() []byte {

var dtsClockReference = &ClockReference{Base: 5726623060}

func dtsBytes() []byte {
func dtsBytes(flag string) []byte {
buf := &bytes.Buffer{}
w := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: buf})
w.Write("0010") // Flag
w.Write(flag) // Flag
w.Write("101") // 32...30
w.Write("1") // Dummy
w.Write("010101010101010") // 29...15
@@ -175,7 +175,7 @@ func dtsBytes() []byte {
}

func TestParsePTSOrDTS(t *testing.T) {
v, err := parsePTSOrDTS(astikit.NewBytesIterator(ptsBytes()))
v, err := parsePTSOrDTS(astikit.NewBytesIterator(ptsBytes("0010")))
assert.Equal(t, v, ptsClockReference)
assert.NoError(t, err)
}
@@ -187,7 +187,7 @@ func TestWritePTSOrDTS(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, n, 5)
assert.Equal(t, n, buf.Len())
assert.Equal(t, dtsBytes(), buf.Bytes())
assert.Equal(t, dtsBytes("0010"), buf.Bytes())
}

func escrBytes() []byte {
@@ -222,19 +222,29 @@ func TestWriteESCR(t *testing.T) {
}

type pesTestCase struct {
name string
bytesFunc func(w *astikit.BitsWriter)
pesData *PESData
name string
headerBytesFunc func(w *astikit.BitsWriter, withStuffing bool, withCRC bool)
optionalHeaderBytesFunc func(w *astikit.BitsWriter, withStuffing bool, withCRC bool)
bytesFunc func(w *astikit.BitsWriter, withStuffing bool, withCRC bool)
pesData *PESData
}

var pesTestCases = []pesTestCase{
{
"without_header",
func(w *astikit.BitsWriter) {
func(w *astikit.BitsWriter, withStuffing bool, withCRC bool) {
w.Write("000000000000000000000001") // Prefix
w.Write(uint8(StreamIDPaddingStream)) // Stream ID
w.Write(uint16(4)) // Packet length
w.Write([]byte("datastuff")) // Data
},
func(w *astikit.BitsWriter, withStuffing bool, withCRC bool) {
// do nothing here
},
func(w *astikit.BitsWriter, withStuffing bool, withCRC bool) {
w.Write([]byte("data")) // Data
if withStuffing {
w.Write([]byte("stuff")) // Stuffing
}
},
&PESData{
Data: []byte("data"),
@@ -246,45 +256,81 @@ var pesTestCases = []pesTestCase{
},
{
"with_header",
func(w *astikit.BitsWriter) {
func(w *astikit.BitsWriter, withStuffing bool, withCRC bool) {
packetLength := 67
stuffing := []byte("stuff")

if !withStuffing {
packetLength -= len(stuffing)
}

if !withCRC {
packetLength -= 2
}

w.Write("000000000000000000000001") // Prefix
w.Write(uint8(1)) // Stream ID
w.Write(uint16(69)) // Packet length
w.Write("10") // Marker bits
w.Write("01") // Scrambling control
w.Write("1") // Priority
w.Write("1") // Data alignment indicator
w.Write("1") // Copyright
w.Write("1") // Original or copy
w.Write("11") // PTS/DTS indicator
w.Write("1") // ESCR flag
w.Write("1") // ES rate flag
w.Write("1") // DSM trick mode flag
w.Write("1") // Additional copy flag
w.Write("1") // CRC flag
w.Write("1") // Extension flag
w.Write(uint8(62)) // Header length
w.Write(ptsBytes()) // PTS
w.Write(dtsBytes()) // DTS
w.Write(escrBytes()) // ESCR
w.Write("101010101010101010101010") // ES rate
w.Write(dsmTrickModeSlowBytes()) // DSM trick mode
w.Write("11111111") // Additional copy info
w.Write(uint16(4)) // CRC
w.Write(uint16(packetLength)) // Packet length

},
func(w *astikit.BitsWriter, withStuffing bool, withCRC bool) {
optionalHeaderLength := 60
stuffing := []byte("stuff")

if !withStuffing {
optionalHeaderLength -= len(stuffing)
}

if !withCRC {
optionalHeaderLength -= 2
}

w.Write("10") // Marker bits
w.Write("01") // Scrambling control
w.Write("1") // Priority
w.Write("1") // Data alignment indicator
w.Write("1") // Copyright
w.Write("1") // Original or copy
w.Write("11") // PTS/DTS indicator
w.Write("1") // ESCR flag
w.Write("1") // ES rate flag
w.Write("1") // DSM trick mode flag
w.Write("1") // Additional copy flag
w.Write(withCRC) // CRC flag
w.Write("1") // Extension flag
w.Write(uint8(optionalHeaderLength)) // Header length
w.Write(ptsBytes("0011")) // PTS
w.Write(dtsBytes("0001")) // DTS
w.Write(escrBytes()) // ESCR
w.Write("101010101010101010101011") // ES rate
w.Write(dsmTrickModeSlowBytes()) // DSM trick mode
w.Write("11111111") // Additional copy info
if withCRC {
w.Write(uint16(4)) // CRC
}
// Extension starts here
w.Write("1") // Private data flag
w.Write("1") // Pack header field flag
w.Write("0") // Pack header field flag
w.Write("1") // Program packet sequence counter flag
w.Write("1") // PSTD buffer flag
w.Write("000") // Dummy
w.Write("111") // Dummy
w.Write("1") // Extension 2 flag
w.Write([]byte("1234567890123456")) // Private data
w.Write(uint8(5)) // Pack field
w.Write("0101010101010101") // Packet sequence counter
w.Write("0111010101010101") // PSTD buffer
w.Write("0000101000000000") // Extension 2 header
w.Write([]byte("extension2")) // Extension 2 data
w.Write([]byte("stuff")) // Optional header stuffing bytes
w.Write([]byte("datastuff")) // Data
//w.Write(uint8(5)) // Pack field
w.Write("1101010111010101") // Packet sequence counter
w.Write("0111010101010101") // PSTD buffer
w.Write("10001010") // Extension 2 header
w.Write([]byte("extension2")) // Extension 2 data
if withStuffing {
w.Write(stuffing) // Optional header stuffing bytes
}
},
func(w *astikit.BitsWriter, withStuffing bool, withCRC bool) {
stuffing := []byte("stuff")
w.Write([]byte("data")) // Data
if withStuffing {
w.Write(stuffing) // Stuffing
}
},
&PESData{
Data: []byte("data"),
@@ -306,27 +352,27 @@ var pesTestCases = []pesTestCase{
HasESRate: true,
HasExtension: true,
HasExtension2: true,
HasPackHeaderField: true,
HasPackHeaderField: false,
HasPrivateData: true,
HasProgramPacketSequenceCounter: true,
HasPSTDBuffer: true,
HeaderLength: 62,
HeaderLength: 60,
IsCopyrighted: true,
IsOriginal: true,
MarkerBits: 2,
MPEG1OrMPEG2ID: 1,
OriginalStuffingLength: 21,
PacketSequenceCounter: 85,
PackField: 5,
Priority: true,
PrivateData: []byte("1234567890123456"),
PSTDBufferScale: 1,
PSTDBufferSize: 5461,
PTSDTSIndicator: 3,
PTS: ptsClockReference,
ScramblingControl: 1,
//PackField: 5,
Priority: true,
PrivateData: []byte("1234567890123456"),
PSTDBufferScale: 1,
PSTDBufferSize: 5461,
PTSDTSIndicator: 3,
PTS: ptsClockReference,
ScramblingControl: 1,
},
PacketLength: 69,
PacketLength: 67,
StreamID: 1,
},
},
@@ -337,7 +383,9 @@ var pesTestCases = []pesTestCase{
func pesWithHeaderBytes() []byte {
buf := bytes.Buffer{}
w := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: &buf})
pesTestCases[1].bytesFunc(w)
pesTestCases[1].headerBytesFunc(w, true, true)
pesTestCases[1].optionalHeaderBytesFunc(w, true, true)
pesTestCases[1].bytesFunc(w, true, true)
return buf.Bytes()
}

@@ -351,29 +399,89 @@ func TestParsePESData(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
buf := bytes.Buffer{}
w := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: &buf})
tc.bytesFunc(w)
tc.headerBytesFunc(w, true, true)
tc.optionalHeaderBytesFunc(w, true, true)
tc.bytesFunc(w, true, true)
d, err := parsePESData(astikit.NewBytesIterator(buf.Bytes()))
assert.NoError(t, err)
assert.Equal(t, tc.pesData, d)
})
}
}

//func TestWritePESData(t *testing.T) {
// for _, tc := range pesTestCases {
// t.Run(tc.name, func(t *testing.T) {
// bufExpected := bytes.Buffer{}
// wExpected := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: &bufExpected})
// tc.bytesFunc(wExpected)
//
// bufActual := bytes.Buffer{}
// wActual := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: &bufActual})
//
// n, err := writePESData(wActual, tc.pesData)
// assert.NoError(t, err)
// assert.Equal(t, n, bufActual.Len())
// assert.Equal(t, bufExpected.Len(), bufActual.Len())
// assert.Equal(t, bufExpected.Bytes(), bufActual.Bytes())
// })
// }
//}
func TestWritePESData(t *testing.T) {
for _, tc := range pesTestCases {
t.Run(tc.name, func(t *testing.T) {
bufExpected := bytes.Buffer{}
wExpected := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: &bufExpected})
tc.headerBytesFunc(wExpected, false, false)
tc.optionalHeaderBytesFunc(wExpected, false, false)
tc.bytesFunc(wExpected, false, false)

bufActual := bytes.Buffer{}
wActual := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: &bufActual})

start := true
totalBytes := 0
payloadPos := 0

for payloadPos+1 < len(tc.pesData.Data) {
n, payloadN, err := writePESData(
wActual,
tc.pesData.Header,
tc.pesData.Data[payloadPos:],
start,
MpegTsPacketSize-MpegTsPacketHeaderSize,
)
assert.NoError(t, err)
start = false

totalBytes += n
payloadPos += payloadN
}

assert.Equal(t, totalBytes, bufActual.Len())
assert.Equal(t, bufExpected.Len(), bufActual.Len())
assert.Equal(t, bufExpected.Bytes(), bufActual.Bytes())
})
}
}

func TestWritePESHeader(t *testing.T) {
for _, tc := range pesTestCases {
t.Run(tc.name, func(t *testing.T) {
bufExpected := bytes.Buffer{}
wExpected := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: &bufExpected})
tc.headerBytesFunc(wExpected, false, false)
tc.optionalHeaderBytesFunc(wExpected, false, false)

bufActual := bytes.Buffer{}
wActual := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: &bufActual})

n, err := writePESHeader(wActual, tc.pesData.Header, uint16(len(tc.pesData.Data)))
assert.NoError(t, err)
assert.Equal(t, n, bufActual.Len())
assert.Equal(t, bufExpected.Len(), bufActual.Len())
assert.Equal(t, bufExpected.Bytes(), bufActual.Bytes())
})
}
}

func TestWritePESOptionalHeader(t *testing.T) {
for _, tc := range pesTestCases {
t.Run(tc.name, func(t *testing.T) {
bufExpected := bytes.Buffer{}
wExpected := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: &bufExpected})
tc.optionalHeaderBytesFunc(wExpected, false, false)

bufActual := bytes.Buffer{}
wActual := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: &bufActual})

n, err := writePESOptionalHeader(wActual, tc.pesData.Header.OptionalHeader)
assert.NoError(t, err)
assert.Equal(t, n, bufActual.Len())
assert.Equal(t, bufExpected.Len(), bufActual.Len())
assert.Equal(t, bufExpected.Bytes(), bufActual.Bytes())
})
}
}
2 changes: 1 addition & 1 deletion packet_test.go
Original file line number Diff line number Diff line change
@@ -189,7 +189,7 @@ func packetAdaptationFieldBytes(a PacketAdaptationField) []byte {
w.Write("010101010101010") // LTW offset
w.Write("11") // Piecewise rate reserved
w.Write("1010101010101010101010") // Piecewise rate
w.Write(dtsBytes()) // Splice type + DTS next access unit
w.Write(dtsBytes("0010")) // Splice type + DTS next access unit
w.WriteN(^uint64(0), 40) // Stuffing bytes
return buf.Bytes()
}