Skip to content
This repository has been archived by the owner on Jan 12, 2019. It is now read-only.

Fix a segment hop in live #928

Merged
merged 2 commits into from
Dec 21, 2016
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/segment-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -992,16 +992,14 @@ export default class SegmentLoader extends videojs.EventTarget {

log('handleUpdateEnd_');

if (!segmentInfo.isSyncRequest) {
this.mediaIndex = segmentInfo.mediaIndex;
this.fetchAtBuffer_ = true;
}

let currentMediaIndex = segmentInfo.mediaIndex;

currentMediaIndex +=
segmentInfo.playlist.mediaSequence - this.playlist_.mediaSequence;

this.mediaIndex = currentMediaIndex;
this.fetchAtBuffer_ = true;

// any time an update finishes and the last segment is in the
// buffer, end the stream. this ensures the "ended" event will
// fire if playback reaches that point.
Expand Down
29 changes: 29 additions & 0 deletions test/segment-loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,35 @@ QUnit.test('checks the goal buffer configuration every loading opportunity', fun
Config.GOAL_BUFFER_LENGTH = defaultGoal;
});

QUnit.test('does not skip over segment if live playlist update occurs while processing',
function(assert) {
let playlist = playlistWithDuration(40);

playlist.endList = false;

loader.playlist(playlist);
loader.mimeType(this.mimeType);
loader.load();

assert.equal(loader.pendingSegment_.uri, '0.ts', 'retrieving first segment');
assert.equal(loader.state, 'WAITING', 'waiting for response');

this.requests[0].response = new Uint8Array(10).buffer;
this.requests.shift().respond(200, null, '');
// playlist updated during append
let playlistUpdated = playlistWithDuration(40);

playlistUpdated.segments.shift();
playlistUpdated.mediaSequence++;
loader.playlist(playlistUpdated);
// finish append
mediaSource.sourceBuffers[0].buffered = videojs.createTimeRanges([[0, 10]]);
mediaSource.sourceBuffers[0].trigger('updateend');

assert.equal(loader.pendingSegment_.uri, '1.ts', 'retrieving second segment');
assert.equal(loader.state, 'WAITING', 'waiting for response');
});

QUnit.module('Segment Loading Calculation', {
beforeEach(assert) {
this.env = useFakeEnvironment(assert);
Expand Down