Skip to content

Commit

Permalink
Version 43:
Browse files Browse the repository at this point in the history
* Reverted jmuxer update from version 42 which caused many playback bugs.
  • Loading branch information
bp2008 committed Jul 12, 2018
1 parent 112e2a0 commit 706223b
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 149 deletions.
2 changes: 1 addition & 1 deletion ui3.htm
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
};
</script>
<script type="text/javascript">
var ui_version = "42";
var ui_version = "43";
var bi_version = "%%VERSION%%";
var combined_version = ui_version + "-" + bi_version;
//if (!!navigator.userAgent.match(/ Android /))
Expand Down
124 changes: 29 additions & 95 deletions ui3/libs-src/jmuxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2075,24 +2075,28 @@ var BufferController = function (_Event) {
}
}, {
key: 'initCleanup',
value: function initCleanup(cleanMaxLimit) {
if (this.sourceBuffer.updating) {
this.pendingCleaning = cleanMaxLimit;
return;
}
if (this.sourceBuffer.buffered && this.sourceBuffer.buffered.length && !this.cleaning) {
for (var i = 0; i < this.sourceBuffer.buffered.length; ++i) {
var start = this.sourceBuffer.buffered.start(i);
var end = this.sourceBuffer.buffered.end(i);

if (cleanMaxLimit - start > this.cleanOffset) {
end = cleanMaxLimit - this.cleanOffset;
if (start < end) {
this.cleanRanges.push([start, end]);
value: function initCleanup(currentTime) {
try {
if (this.sourceBuffer.updating) {
this.pendingCleaning = currentTime;
return;
}
if (this.sourceBuffer.buffered && this.sourceBuffer.buffered.length && !this.cleaning) {
for (var i = 0; i < this.sourceBuffer.buffered.length; ++i) {
var start = this.sourceBuffer.buffered.start(i);
var end = this.sourceBuffer.buffered.end(i);

if (currentTime - start > this.cleanOffset) {
end = currentTime - this.cleanOffset;
if (start < end) {
this.cleanRanges.push([start, end]);
}
}
}
this.doCleanup();
}
this.doCleanup();
} catch (e) {
error('Error occured in initCleanup of ' + this.type + ' buffer - ' + e.name + ': ' + e.message);
}
}
}, {
Expand Down Expand Up @@ -2149,6 +2153,7 @@ var JMuxmer = function (_Event) {
mode: 'both', // both, audio, video
flushingTime: 1500,
clearBuffer: true,
cleanOffset: 2, // when clearing buffers, go back this many seconds
onReady: null, // function called when MSE is ready to accept frames
fps: 30,
debug: false
Expand Down Expand Up @@ -2183,8 +2188,6 @@ var JMuxmer = function (_Event) {

_this.mseReady = false;
_this.lastCleaningTime = Date.now();
_this.keyframeCache = [];
_this.frameCounter = 0;

/* events callback */
_this.remuxController.on('buffer', _this.onBuffer.bind(_this));
Expand Down Expand Up @@ -2216,7 +2219,9 @@ var JMuxmer = function (_Event) {
};

if (!data) return;

duration = data.duration ? parseInt(data.duration) : 0;

if (data.video) {
nalus = H264Parser.extractNALu(data.video);
if (nalus.length > 0) {
Expand All @@ -2232,7 +2237,7 @@ var JMuxmer = function (_Event) {
}
}
if (!remux) {
error('Input object must have video and/or audio property. Make sure it is not empty and valid typed array');
error('No video element found to feed. Input object must have audio and/or video property');
return;
}
this.remuxController.remux(chunks);
Expand All @@ -2245,8 +2250,7 @@ var JMuxmer = function (_Event) {
samples = [],
naluObj = void 0,
sampleDuration = void 0,
adjustDuration = 0,
numberOfFrames = [];
adjustDuration = 0;

var _iteratorNormalCompletion = true;
var _didIteratorError = false;
Expand All @@ -2261,12 +2265,6 @@ var JMuxmer = function (_Event) {
if (naluObj.type() === NALU.IDR || naluObj.type() === NALU.NDR) {
samples.push({ units: units });
units = [];
if (this.options.clearBuffer) {
if (naluObj.type() === NALU.IDR) {
numberOfFrames.push(this.frameCounter);
}
this.frameCounter++;
}
}
}
} catch (err) {
Expand Down Expand Up @@ -2296,14 +2294,6 @@ var JMuxmer = function (_Event) {
adjustDuration--;
}
});

/* cache keyframe times if clearBuffer set true */
if (this.options.clearBuffer) {
numberOfFrames = numberOfFrames.map(function (total) {
return total * sampleDuration / 1000;
});
this.keyframeCache = this.keyframeCache.concat(numberOfFrames);
}
return samples;
}
}, {
Expand Down Expand Up @@ -2359,51 +2349,15 @@ var JMuxmer = function (_Event) {
this.stopInterval();
if (this.mediaSource) {
try {
var sbs = this.mediaSource.sourceBuffers;
var _iteratorNormalCompletion3 = true;
var _didIteratorError3 = false;
var _iteratorError3 = undefined;

try {
for (var _iterator3 = sbs[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
var sb = _step3.value;

this.mediaSource.removeSourceBuffer(sb);
}
} catch (err) {
_didIteratorError3 = true;
_iteratorError3 = err;
} finally {
try {
if (!_iteratorNormalCompletion3 && _iterator3.return) {
_iterator3.return();
}
} finally {
if (_didIteratorError3) {
throw _iteratorError3;
}
}
}

if (this.bufferControllers) {
this.mediaSource.endOfStream();
}
this.mediaSource.endOfStream();
} catch (e) {
error('mediasource is not available to end ' + e.message);
error('mediasource is not available to end');
}
this.mediaSource = null;
}
if (this.remuxController) {
this.remuxController.destroy();
this.remuxController = null;
}
if (this.bufferControllers) {
for (var type in this.bufferControllers) {
this.bufferControllers[type].destroy();
}
this.bufferControllers = null;
}
this.node = false;
this.mseReady = false;
this.videoStarted = false;
}
Expand All @@ -2420,6 +2374,7 @@ var JMuxmer = function (_Event) {
}
var sb = this.mediaSource.addSourceBuffer(type + '/mp4; codecs="' + track.mp4track.codec + '"');
this.bufferControllers[type] = new BufferController(sb, type);
this.bufferControllers[type].cleanOffset = this.options.cleanOffset;
this.sourceBuffers[type] = sb;
this.bufferControllers[type].on('error', this.onBufferError.bind(this));
}
Expand Down Expand Up @@ -2450,41 +2405,20 @@ var JMuxmer = function (_Event) {
this.bufferControllers[type].doAppend();
}
}
}, {
key: 'getSafeBufferClearLimit',
value: function getSafeBufferClearLimit(offset) {
var maxLimit = offset,
adjacentOffset = void 0;

for (var i = 0; i < this.keyframeCache.length; i++) {
if (this.keyframeCache[i] >= offset) {
break;
}
adjacentOffset = this.keyframeCache[i];
}

this.keyframeCache = this.keyframeCache.filter(function (keyframePoint) {
if (keyframePoint < adjacentOffset) {
maxLimit = keyframePoint;
}
return keyframePoint >= adjacentOffset;
});
return maxLimit;
}
}, {
key: 'clearBuffer',
value: function clearBuffer() {
if (this.options.clearBuffer && Date.now() - this.lastCleaningTime > 10000) {
for (var type in this.bufferControllers) {
var cleanMaxLimit = this.getSafeBufferClearLimit(this.node.currentTime);
this.bufferControllers[type].initCleanup(cleanMaxLimit);
this.bufferControllers[type].initCleanup(this.node.currentTime);
}
this.lastCleaningTime = Date.now();
}
}
}, {
key: 'onBuffer',
value: function onBuffer(data) {

if (this.bufferControllers && this.bufferControllers[data.type]) {
this.bufferControllers[data.type].feed(data.payload);
}
Expand Down
Loading

0 comments on commit 706223b

Please sign in to comment.