Skip to content

Commit

Permalink
update dist
Browse files Browse the repository at this point in the history
related to video-dev#516
related to video-dev#600
  • Loading branch information
mangui committed Sep 22, 2016
1 parent 7216066 commit 349724d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 19 deletions.
38 changes: 25 additions & 13 deletions dist/hls.js
Original file line number Diff line number Diff line change
Expand Up @@ -6684,24 +6684,25 @@ var TSDemuxer = function () {
state = 0;
} else {
// not enough byte to read unit type. let's read it on next PES parsing
state = 4;
state = -state - 1;
}
} else {
state = 0;
}
break;
case 4:
// special use case where we found 3 or 4-byte start codes exactly at the end of previous NAL unit
case -3:
case -4:
// special use case where we found 3 or 4-byte start codes exactly at the end of previous PES packet
lastUnitStart = 0;
// NALu type is value read from offset 0
lastUnitType = value;
lastUnitType = value & 0x1f;
state = 0;
break;
default:
break;
}
}
if (lastUnitStart >= 0) {
if (lastUnitStart >= 0 && state >= 0) {
unit = { data: array.subarray(lastUnitStart, len), type: lastUnitType, state: state };
units.push(unit);
//logger.log('pushing NALU, type/size/state:' + unit.type + '/' + unit.data.byteLength + '/' + state);
Expand Down Expand Up @@ -9449,6 +9450,17 @@ var MP4Remuxer = function () {
// logger.log(avcSample.pts + '/' + avcSample.dts + ',' + unitsString + avcSample.units.length);
// }

// handle broken streams with PTS < DTS, tolerance up 200ms (18000 in 90kHz timescale)
var PTSDTSshift = inputSamples.reduce(function (prev, curr) {
return Math.max(Math.min(prev, curr.pts - curr.dts), -18000);
}, 0);
if (PTSDTSshift < 0) {
_logger.logger.warn('PTS < DTS detected in video samples, shifting DTS by ' + Math.round(PTSDTSshift / 90) + ' ms to overcome this issue');
for (var i = 0; i < inputSamples.length; i++) {
inputSamples[i].dts += PTSDTSshift;
}
}

// PTS is coded on 33bits, and can loop from -2^32 to 2^32
// PTSNormalize will make PTS/DTS value monotonic, we use last known DTS value as reference value
var nextAvcDts = void 0;
Expand Down Expand Up @@ -9504,11 +9516,11 @@ var MP4Remuxer = function () {
}

// normalize all PTS/DTS now ...
for (var i = 0; i < inputSamples.length; i++) {
var _sample = inputSamples[i];
for (var _i = 0; _i < inputSamples.length; _i++) {
var _sample = inputSamples[_i];
if (isSafari) {
// sample DTS is computed using a constant decoding offset (mp4SampleDuration) between samples
_sample.dts = firstDTS + i * pes2mp4ScaleFactor * mp4SampleDuration;
_sample.dts = firstDTS + _i * pes2mp4ScaleFactor * mp4SampleDuration;
} else {
// ensure sample monotonic DTS
_sample.dts = Math.max(this._PTSNormalize(_sample.dts - this._initDTS, nextAvcDts), firstDTS);
Expand All @@ -9529,8 +9541,8 @@ var MP4Remuxer = function () {
view.setUint32(0, mdat.byteLength);
mdat.set(_mp4Generator2.default.types.mdat, 4);

for (var _i = 0; _i < inputSamples.length; _i++) {
var avcSample = inputSamples[_i],
for (var _i2 = 0; _i2 < inputSamples.length; _i2++) {
var avcSample = inputSamples[_i2],
mp4SampleLength = 0,
compositionTimeOffset = void 0;
// convert NALU bitstream to MP4 format (prepend NALU with size field)
Expand All @@ -9545,11 +9557,11 @@ var MP4Remuxer = function () {

if (!isSafari) {
// expected sample duration is the Decoding Timestamp diff of consecutive samples
if (_i < inputSamples.length - 1) {
mp4SampleDuration = inputSamples[_i + 1].dts - avcSample.dts;
if (_i2 < inputSamples.length - 1) {
mp4SampleDuration = inputSamples[_i2 + 1].dts - avcSample.dts;
} else {
var config = this.config,
lastFrameDuration = avcSample.dts - inputSamples[_i > 0 ? _i - 1 : _i].dts;
lastFrameDuration = avcSample.dts - inputSamples[_i2 > 0 ? _i2 - 1 : _i2].dts;
if (config.stretchShortVideoTrack) {
// In some cases, a segment's audio track duration may exceed the video track duration.
// Since we've already remuxed audio, and we know how long the audio track is, we look to
Expand Down
6 changes: 3 additions & 3 deletions dist/hls.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit 349724d

Please sign in to comment.