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

feat: usage on rendition change #1088

Merged
merged 4 commits into from
Mar 30, 2021
Merged
Changes from 2 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
20 changes: 14 additions & 6 deletions src/master-playlist-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,18 @@ export class MasterPlaylistController extends videojs.EventTarget {
const nextPlaylist = this.selectPlaylist();

if (this.shouldSwitchToMedia_(nextPlaylist)) {
this.masterPlaylistLoader_.media(nextPlaylist);
this.switchMedia_(nextPlaylist, null, 'abr');
}
}

switchMedia_(playlist, delay, cause) {
const oldMedia = this.masterPlaylistLoader_.media();

this.logger_(`switch media ${oldMedia && (oldMedia.id || oldMedia.uri)} -> ${playlist.id || playlist.uri} from ${cause}`);
brandonocasey marked this conversation as resolved.
Show resolved Hide resolved
this.tech_.trigger({type: 'usage', name: `vhs-rendition-change-${cause}`});
this.masterPlaylistLoader_.media(playlist);
}

/**
* Start a timer that periodically calls checkABR_
*
Expand Down Expand Up @@ -416,7 +424,7 @@ export class MasterPlaylistController extends videojs.EventTarget {

this.initialMedia_ = selectedMedia;

this.masterPlaylistLoader_.media(this.initialMedia_);
this.switchMedia_(this.initialMedia_, null, 'initial');

// Under the standard case where a source URL is provided, loadedplaylist will
// fire again since the playlist will be requested. In the case of vhs-json
Expand Down Expand Up @@ -608,7 +616,7 @@ export class MasterPlaylistController extends videojs.EventTarget {
const nextPlaylist = this.selectPlaylist();

if (this.shouldSwitchToMedia_(nextPlaylist)) {
this.masterPlaylistLoader_.media(nextPlaylist);
this.switchMedia_(this.initialMedia_, null, 'bandwidthupdate');
}

this.tech_.trigger('bandwidthupdate');
Expand Down Expand Up @@ -734,7 +742,7 @@ export class MasterPlaylistController extends videojs.EventTarget {
return;
}

this.masterPlaylistLoader_.media(media);
this.switchMedia_(media, null, 'smooth-quality');

this.mainSegmentLoader_.resetLoader();
// don't need to reset audio as it is reset when media changes
Expand All @@ -754,7 +762,7 @@ export class MasterPlaylistController extends videojs.EventTarget {
return;
}

this.masterPlaylistLoader_.media(media);
this.switchMedia_(media, null, 'fast-quality');

// Delete all buffered data to allow an immediate quality switch, then seek to give
// the browser a kick to remove any cached frames from the previous rendtion (.04 seconds
Expand Down Expand Up @@ -1106,7 +1114,7 @@ export class MasterPlaylistController extends videojs.EventTarget {
(Date.now() - nextPlaylist.lastRequest) <= delayDuration;

// delay if it's a final rendition or if the last refresh is sooner than half targetDuration
return this.masterPlaylistLoader_.media(nextPlaylist, isFinalRendition || shouldDelay);
return this.switchMedia_(nextPlaylist, isFinalRendition || shouldDelay, 'exclude');
}

/**
Expand Down