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 for IE11 missing Number.MAX_SAFE_INTEGER #2891

Merged
merged 1 commit into from Jul 14, 2020
Merged
Show file tree
Hide file tree
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
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