diff --git a/cmd/mjpeg-player/hlsjs/mts-demuxer.js b/cmd/mjpeg-player/hlsjs/mts-demuxer.js index 415b057c..443d3bcc 100644 --- a/cmd/mjpeg-player/hlsjs/mts-demuxer.js +++ b/cmd/mjpeg-player/hlsjs/mts-demuxer.js @@ -64,13 +64,14 @@ class MTSDemuxer{ }; } - // _syncOffset scans the first 1000 bytes and returns an offset to the beginning of the first three MTS packets, + // _syncOffset scans the first 'maxScanWindow' bytes and returns an offset to the beginning of the first three MTS packets, // or -1 if three are not found. // A TS fragment should contain at least 3 TS packets, a PAT, a PMT, and one PID, each starting with 0x47. static _syncOffset (data) { - const scanwindow = Math.min(1000, data.length - 3 * 188); + const maxScanWindow = 1000; // 1000 is a reasonable number of bytes to search for the first MTS packets. + const scanWindow = Math.min(maxScanWindow, data.length - 3 * 188); let i = 0; - while (i < scanwindow) { + while (i < scanWindow) { if (data[i] === 0x47 && data[i + 188] === 0x47 && data[i + 2 * 188] === 0x47) { return i; } else {