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

fix(m2ts): PES packets missing timestamp rollover #437

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 16 additions & 1 deletion lib/m2ts/m2ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
var Stream = require('../utils/stream.js'),
CaptionStream = require('./caption-stream'),
StreamTypes = require('./stream-types'),
TimestampRolloverStream = require('./timestamp-rollover-stream').TimestampRolloverStream;
TimestampRolloverStream = require('./timestamp-rollover-stream').TimestampRolloverStream,
handleRollover = require('./timestamp-rollover-stream').handleRollover;

// object types
var TransportPacketStream, TransportParseStream, ElementaryStream;
Expand Down Expand Up @@ -309,6 +310,8 @@ ElementaryStream = function() {
size: 0
},
programMapTable,
referenceDTS,
referencePTS,
parsePes = function(payload, pes) {
var ptsDtsFlags;
const startPrefix = payload[0] << 16 | payload[1] << 8 | payload[2]
Expand Down Expand Up @@ -360,6 +363,18 @@ ElementaryStream = function() {
pes.dts += (payload[18] & 0x06) >>> 1; // OR by the two LSBs
}
}

if (referencePTS === undefined) {
referencePTS = pes.pts;
}

if (referenceDTS === undefined) {
referenceDTS = pes.dts;
}

pes.dts = handleRollover(pes.dts, referenceDTS);
pes.pts = handleRollover(pes.pts, referencePTS);

// the data section starts immediately after the PES header.
// pes_header_data_length specifies the number of header bytes
// that follow the last byte of the field.
Expand Down