From 44cda6520e3d1c7263002d0d708d658ef53ffd47 Mon Sep 17 00:00:00 2001 From: brandonocasey Date: Thu, 27 May 2021 12:09:04 -0400 Subject: [PATCH] handle zero length media segments that did not append --- src/segment-loader.js | 4 ++- test/master-playlist-controller.test.js | 38 +++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/segment-loader.js b/src/segment-loader.js index 5f97946a0..4003d08c1 100644 --- a/src/segment-loader.js +++ b/src/segment-loader.js @@ -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_(); diff --git a/test/master-playlist-controller.test.js b/test/master-playlist-controller.test.js index c120d06a3..7951acbdb 100644 --- a/test/master-playlist-controller.test.js +++ b/test/master-playlist-controller.test.js @@ -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();