Skip to content

Commit

Permalink
Fix 0.11.1 Regressions (video-dev#2028)
Browse files Browse the repository at this point in the history
* Create sourceBuffers if the max of 2 tracks has been reached, regardless of buffer codec events received

* Replace Object.values with [].slice.call
  • Loading branch information
johnBartos authored Dec 6, 2018
1 parent 674b7bf commit e8d95a4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/controller/buffer-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ class BufferController extends EventHandler {
// Check if we've received all of the expected bufferCodec events. When none remain, create all the sourceBuffers at once.
// This is important because the MSE spec allows implementations to throw QuotaExceededErrors if creating new sourceBuffers after
// data has been appended to existing ones.
if (Object.keys(pendingTracks).length && !bufferCodecEventsExpected) {
// 2 tracks is the max (one for audio, one for video). If we've reach this max go ahead and create the buffers.
const pendingTracksCount = Object.keys(pendingTracks).length;
if ((pendingTracksCount && !bufferCodecEventsExpected) || pendingTracksCount === 2) {
// ok, let's create them now !
this.createSourceBuffers(pendingTracks);
this.pendingTracks = {};
Expand Down Expand Up @@ -275,8 +277,7 @@ class BufferController extends EventHandler {

const { mediaSource } = this;
this.bufferCodecEventsExpected = Math.max(this.bufferCodecEventsExpected - 1, 0);
if (mediaSource && mediaSource.readyState === 'open' && !this.bufferCodecEventsExpected) {
// try to create sourcebuffers if mediasource opened, and all expected bufferCodec events have been received
if (mediaSource && mediaSource.readyState === 'open') {
this.checkPendingTracks();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/controller/timeline-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class TimelineController extends EventHandler {
this.tracks.forEach((track, index) => {
let textTrack;
if (index < inUseTracks.length) {
const inUseTrack = Object.values(inUseTracks).find(inUseTrack => canReuseVttTextTrack(inUseTrack, track));
const inUseTrack = [].slice.call(inUseTracks).find(inUseTrack => canReuseVttTextTrack(inUseTrack, track));
// Reuse tracks with the same label, but do not reuse 608/708 tracks
if (inUseTrack) {
textTrack = inUseTrack;
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/controller/buffer-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,11 @@ describe('BufferController tests', function () {
bufferController.bufferCodecEventsExpected = 2;

bufferController.onBufferCodecs({});
assert.strictEqual(checkPendingTracksSpy.notCalled, true);
assert.strictEqual(checkPendingTracksSpy.calledOnce, true);
assert.strictEqual(bufferController.bufferCodecEventsExpected, 1);

bufferController.onBufferCodecs({});
assert.strictEqual(checkPendingTracksSpy.calledOnce, true);
assert.strictEqual(checkPendingTracksSpy.calledTwice, true);
assert.strictEqual(bufferController.bufferCodecEventsExpected, 0);
});

Expand Down

0 comments on commit e8d95a4

Please sign in to comment.