Skip to content

Commit

Permalink
handle zero length media segments that did not append
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonocasey committed May 27, 2021
1 parent 6cd2015 commit 44cda65
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/segment-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -3005,7 +3005,9 @@ export default class SegmentLoader extends videojs.EventTarget {
// used for testing
this.trigger('appended');

this.mediaAppends++;
if (segmentInfo.hasAppendedData_) {
this.mediaAppends++;
}

if (!this.paused()) {
this.monitorBuffer_();
Expand Down
38 changes: 38 additions & 0 deletions test/master-playlist-controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,44 @@ QUnit.test('basic timeToLoadedData, mediaAppends, appendsToLoadedData stats', fu
});
});

QUnit.test('timeToLoadedData, mediaAppends, appendsToLoadedData stats with 0 length appends', function(assert) {
this.player.tech_.trigger('loadstart');
this.masterPlaylistController.mediaSource.trigger('sourceopen');
// master
this.standardXHRResponse(this.requests.shift());
// media
this.standardXHRResponse(this.requests.shift());

const segmentLoader = this.masterPlaylistController.mainSegmentLoader_;

return requestAndAppendSegment({
request: this.requests.shift(),
segmentLoader,
clock: this.clock
}).then(() => {
// mock a zero length segment, by setting hasAppendedData_ to false.
segmentLoader.one('appendsdone', () => {
segmentLoader.pendingSegment_.hasAppendedData_ = false;
});
return requestAndAppendSegment({
request: this.requests.shift(),
segmentLoader,
clock: this.clock
});
}).then(() => {

this.player.tech_.trigger('loadeddata');
const vhs = this.player.tech_.vhs;

// only one media append as the second was zero length.
assert.equal(vhs.stats.mediaAppends, 1, 'one media append');
assert.equal(vhs.stats.appendsToLoadedData, 1, 'appends to first frame is also 1');
assert.equal(vhs.stats.mainAppendsToLoadedData, 1, 'main appends to first frame is also 1');
assert.equal(vhs.stats.audioAppendsToLoadedData, 0, 'audio appends to first frame is 0');
assert.ok(vhs.stats.timeToLoadedData > 0, 'time to first frame is valid');
});
});

QUnit.test('preload none timeToLoadedData, mediaAppends, appendsToLoadedData stats', function(assert) {
this.requests.length = 0;
this.player.dispose();
Expand Down

0 comments on commit 44cda65

Please sign in to comment.