Skip to content

Commit

Permalink
fix: look at all program map tables for ts stream types (#28)
Browse files Browse the repository at this point in the history
use of maxPes in `m2ts-helpers#parseTs` is deprecated. We should always look at all pes packets to prevent being caught off guard by changes in that stream that happen after the pes specified.
  • Loading branch information
brandonocasey authored Jul 15, 2021
1 parent 808b1d5 commit e00a396
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/format-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ const parseCodecFrom = {
},

ts(bytes) {
const result = parseTs(bytes, 2);
const result = parseTs(bytes);
const codecs = {};

Object.keys(result.streams).forEach(function(esPid) {
Expand Down
7 changes: 5 additions & 2 deletions src/m2ts-helpers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import {bytesMatch, toUint8} from './byte-helpers.js';
const SYNC_BYTE = 0x47;

// use of maxPes is deprecated as we should always look at
// all pes packets to prevent being caught off gaurd by changes
// in that stream that happen after the pes specified
export const parseTs = function(bytes, maxPes = Infinity) {
bytes = toUint8(bytes);

Expand All @@ -27,14 +30,14 @@ export const parseTs = function(bytes, maxPes = Infinity) {

if (pid === 0 && !pmt.pid) {
pmt.pid = (packet[payloadOffset + 10] & 0x1f) << 8 | packet[payloadOffset + 11];
} else if (pmt.pid && pid === pmt.pid && !pmt.streams) {
} else if (pmt.pid && pid === pmt.pid) {
const isNotForward = packet[payloadOffset + 5] & 0x01;

// ignore forward pmt delarations
if (!isNotForward) {
continue;
}
pmt.streams = {};
pmt.streams = pmt.streams || {};

const sectionLength = (packet[payloadOffset + 1] & 0x0f) << 8 | packet[payloadOffset + 2];
const tableEnd = 3 + sectionLength - 4;
Expand Down

0 comments on commit e00a396

Please sign in to comment.