Skip to content

Commit

Permalink
Merge pull request #2891 from video-dev/bugfix/ie11-number
Browse files Browse the repository at this point in the history
Fix for IE11 missing Number.MAX_SAFE_INTEGER
  • Loading branch information
robwalch committed Jul 14, 2020
2 parents 45d5a92 + ef9420d commit 397c6a5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/polyfills/number-isFinite.js → src/polyfills/number.js
@@ -1,3 +1,5 @@
export const isFiniteNumber = Number.isFinite || function (value) {
return typeof value === 'number' && isFinite(value);
};

export const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991;
12 changes: 6 additions & 6 deletions src/remux/mp4-remuxer.js
Expand Up @@ -192,8 +192,8 @@ class MP4Remuxer {
let moof;
let firstDTS;
let lastDTS;
let minPTS = Number.MAX_SAFE_INTEGER;
let maxPTS = -Number.MAX_SAFE_INTEGER;
let minPTS = Number.POSITIVE_INFINITY;
let maxPTS = Number.NEGATIVE_INFINITY;
const timeScale = track.timescale;
const inputSamples = track.samples;
const outputSamples = [];
Expand All @@ -217,7 +217,7 @@ class MP4Remuxer {
// consecutive fragments are frags with
// - less than 100ms gaps between new time offset (if accurate) and next expected PTS OR
// - less than 200 ms PTS gaps (timeScale/5)
contiguous |= (inputSamples.length && nextAvcDts &&
contiguous |= (nbSamples && nextAvcDts &&
((accurateTimeOffset && Math.abs(timeOffset - nextAvcDts / timeScale) < 0.1) ||
Math.abs((inputSamples[0].pts - nextAvcDts - initPTS)) < timeScale / 5)
);
Expand Down Expand Up @@ -249,14 +249,14 @@ class MP4Remuxer {
let PTSDTSshift = inputSamples.reduce((prev, curr) => Math.max(Math.min(prev, curr.pts - curr.dts), -1 * PTS_DTS_SHIFT_TOLERANCE_90KHZ), 0);
if (PTSDTSshift < 0) {
logger.warn(`PTS < DTS detected in video samples, shifting DTS by ${toMsFromMpegTsClock(PTSDTSshift, true)} ms to overcome this issue`);
for (let i = 0; i < inputSamples.length; i++) {
for (let i = 0; i < nbSamples; i++) {
inputSamples[i].dts = Math.max(0, inputSamples[i].dts + PTSDTSshift);
}
}

// Get first/last DTS
firstDTS = inputSamples[0].dts;
lastDTS = inputSamples[inputSamples.length - 1].dts;
lastDTS = inputSamples[nbSamples - 1].dts;

// check timestamp continuity across consecutive fragments (this is to remove inter-fragment gap/hole)
const delta = firstDTS - nextAvcDts;
Expand All @@ -282,7 +282,7 @@ class MP4Remuxer {
// sample duration (as expected by trun MP4 boxes), should be the delta between sample DTS
// set this constant duration as being the avg delta between consecutive DTS.
if (isSafari) {
mp4SampleDuration = Math.round((lastDTS - firstDTS) / (inputSamples.length - 1));
mp4SampleDuration = Math.round((lastDTS - firstDTS) / (nbSamples - 1));
}

// Clamp first DTS to 0 so that we're still aligning on initPTS,
Expand Down
4 changes: 3 additions & 1 deletion webpack.config.js
Expand Up @@ -76,7 +76,9 @@ const baseConfig = {
visitor: {
CallExpression: function (espath) {
if (espath.get('callee').matchesPattern('Number.isFinite')) {
espath.node.callee = importHelper.addNamed(espath, 'isFiniteNumber', path.resolve('src/polyfills/number-isFinite'));
espath.node.callee = importHelper.addNamed(espath, 'isFiniteNumber', path.resolve('src/polyfills/number'));
} else if (espath.get('callee').matchesPattern('Number.MAX_SAFE_INTEGER')) {
espath.node.callee = importHelper.addNamed(espath, 'MAX_SAFE_INTEGER', path.resolve('src/polyfills/number'));
}
}
}
Expand Down

0 comments on commit 397c6a5

Please sign in to comment.