Skip to content

Commit a056f08

Browse files
committed
Fix MPEG-TS probing when PAT and PMT are not present in the first three TS packets (#5252)
Fixes regression in #5251
1 parent bf49dd2 commit a056f08

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/controller/base-stream-controller.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -506,8 +506,8 @@ export default class BaseStreamController
506506
part ? ' part: ' + part.index : ''
507507
} of ${this.logPrefix === '[stream-controller]' ? 'level' : 'track'} ${
508508
frag.level
509-
} (frag:[${(frag.startPTS || NaN).toFixed(3)}-${(
510-
frag.endPTS || NaN
509+
} (frag:[${(frag.startPTS ?? NaN).toFixed(3)}-${(
510+
frag.endPTS ?? NaN
511511
).toFixed(3)}] > buffer:${
512512
media
513513
? TimeRanges.toString(BufferHelper.getBuffered(media))

src/demux/tsdemuxer.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,14 @@ class TSDemuxer implements Demuxer {
9999
}
100100

101101
static syncOffset(data: Uint8Array): number {
102+
const length = data.length;
102103
const scanwindow =
103104
Math.min(PACKET_LENGTH * 5, data.length - PACKET_LENGTH) + 1;
104105
let i = 0;
105106
while (i < scanwindow) {
106107
// a TS init segment should contain at least 2 TS packets: PAT and PMT, each starting with 0x47
107108
let foundPat = false;
108-
for (let j = 0; j < scanwindow; j += PACKET_LENGTH) {
109+
for (let j = i; j < length; j += PACKET_LENGTH) {
109110
if (data[j] === 0x47) {
110111
if (!foundPat && parsePID(data, j) === 0) {
111112
foundPat = true;
@@ -357,7 +358,9 @@ class TSDemuxer implements Demuxer {
357358
}
358359

359360
if (unknownPID !== null && !pmtParsed) {
360-
logger.log(`unknown PID '${unknownPID}' in TS found`);
361+
logger.warn(
362+
`MPEG-TS PMT found at ${start} after unknown PID '${unknownPID}'. Backtracking to sync byte @${syncOffset} to parse all TS packets.`
363+
);
361364
unknownPID = null;
362365
// we set it to -188, the += 188 in the for loop will reset start to 0
363366
start = syncOffset - 188;

0 commit comments

Comments
 (0)