Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wait for both main and audio loaders for endOfStream if main starting media unknown #44

Merged
merged 2 commits into from
Feb 23, 2018
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
7 changes: 4 additions & 3 deletions src/master-playlist-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -623,10 +623,11 @@ export class MasterPlaylistController extends videojs.EventTarget {

if (this.mediaTypes_.AUDIO.activePlaylistLoader) {
// if the audio playlist loader exists, then alternate audio is active
if (this.mainSegmentLoader_.startingMedia_ &&
if (!this.mainSegmentLoader_.startingMedia_ ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens in the event that we only have alternate audio, it hits the end of its playlist, and mainSegmentLoader_.startingMedia_ is not yet set?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not believe this is a scenario we can get into. STREAM-INFs are REQUIRED to have a URI line by the spec. So there will always be a main stream that the main segment loader is loading from. In addition to that, until the way audio buffer ownership is overhauled, there isn't actually any mechanism to stop the main segment loader in an audio only stream with alternate audio activated. So even if audio only and alternate audio activated, the main segment loader will continue to request its audio segments, and then the VirtualSourceBuffer just drops them on the floor because it doesn't own the audio buffer. (Yes this is wasted bandwidth, even more reason to change the way we handle audio)

this.mainSegmentLoader_.startingMedia_.containsVideo) {
// if the main segment loader contains video, then we need to wait for both the
// main and audio segment loaders to call endOfStream
// if we do not know if the main segment loader contains video yet or if we
// definitively know the main segment loader contains video, then we need to wait
// for both main and audio segment loaders to call endOfStream
isEndOfStream = isEndOfStream && this.audioSegmentLoader_.ended_;
} else {
// otherwise just rely on the audio loader
Expand Down
66 changes: 65 additions & 1 deletion test/master-playlist-controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ function(assert) {

MPC.mediaSource.sourceBuffers[0].trigger('updateend');

assert.equal(videoEnded, 1, 'main segment loader triggered endded');
assert.equal(videoEnded, 1, 'main segment loader triggered ended');
assert.equal(audioEnded, 0, 'audio segment loader did not trigger ended');
assert.equal(MPC.mediaSource.readyState, 'open', 'Media Source not yet ended');

Expand All @@ -603,6 +603,70 @@ function(assert) {
assert.equal(MPC.mediaSource.readyState, 'ended', 'Media Source ended');
});

QUnit.test('waits for both main and audio loaders to finish before calling endOfStream' +
' if main loader starting media is unknown', function(assert) {
openMediaSource(this.player, this.clock);

const videoMedia = '#EXTM3U\n' +
'#EXT-X-VERSION:3\n' +
'#EXT-X-PLAYLIST-TYPE:VOD\n' +
'#EXT-X-MEDIA-SEQUENCE:0\n' +
'#EXT-X-TARGETDURATION:10\n' +
'#EXTINF:10,\n' +
'video-0.ts\n' +
'#EXT-X-ENDLIST\n';

const audioMedia = '#EXTM3U\n' +
'#EXT-X-VERSION:3\n' +
'#EXT-X-PLAYLIST-TYPE:VOD\n' +
'#EXT-X-MEDIA-SEQUENCE:0\n' +
'#EXT-X-TARGETDURATION:10\n' +
'#EXTINF:10,\n' +
'audio-0.ts\n' +
'#EXT-X-ENDLIST\n';

let videoEnded = 0;
let audioEnded = 0;

const MPC = this.masterPlaylistController;

MPC.mainSegmentLoader_.on('ended', () => videoEnded++);
MPC.audioSegmentLoader_.on('ended', () => audioEnded++);

MPC.audioSegmentLoader_.startingMedia_ = { containsAudio: true };

// master
this.standardXHRResponse(this.requests.shift(), manifests.demuxed);

// video media
this.standardXHRResponse(this.requests.shift(), videoMedia);

// audio media
this.standardXHRResponse(this.requests.shift(), audioMedia);

// this.requests === [videoSegment, audioSegment]

// audio segment
this.standardXHRResponse(this.requests[1]);
// audio source buffer
MPC.mediaSource.sourceBuffers[1].trigger('updateend');

assert.equal(videoEnded, 0, 'main segment loader did not trigger ended');
assert.equal(audioEnded, 1, 'audio segment loader triggered ended');
assert.equal(MPC.mediaSource.readyState, 'open', 'Media Source not yet ended');

// video segment
this.standardXHRResponse(this.requests[0]);

MPC.mainSegmentLoader_.startingMedia_ = { containsVideo: true };
// main source buffer
MPC.mediaSource.sourceBuffers[0].trigger('updateend');

assert.equal(videoEnded, 1, 'main segment loader triggered ended');
assert.equal(audioEnded, 1, 'audio segment loader did not trigger ended again');
assert.equal(MPC.mediaSource.readyState, 'ended', 'Media Source ended');
});

QUnit.test('does not wait for main loader to finish before calling endOfStream with' +
' audio only stream and alternate audio active', function(assert) {
openMediaSource(this.player, this.clock);
Expand Down