Skip to content

Commit

Permalink
Merge branch 'main' into caption-services
Browse files Browse the repository at this point in the history
  • Loading branch information
gkatsev authored Jun 11, 2021
2 parents c2f0567 + 44905d4 commit 22351a9
Show file tree
Hide file tree
Showing 12 changed files with 151 additions and 164 deletions.
23 changes: 14 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Video.js Compatibility: 6.0, 7.0
- [parse708captions](#parse708captions)
- [overrideNative](#overridenative)
- [blacklistDuration](#blacklistduration)
- [maxPlaylistRetries](#maxplaylistretries)
- [bandwidth](#bandwidth)
- [useBandwidthFromLocalStorage](#usebandwidthfromlocalstorage)
- [enableLowInitialPlaylist](#enablelowinitialplaylist)
Expand Down Expand Up @@ -365,6 +366,14 @@ if a playlist is blacklisted, it will be blacklisted for a period of that
customized duration. This enables the blacklist duration to be configured
by the user.

#### maxPlaylistRetries
* Type: `number`
* Default: `Infinity`
* can be used as an initialization option

The max number of times that a playlist will retry loading following an error
before being indefinitely excluded from the rendition selection algorithm. Note: the number of retry attempts needs to _exceed_ this value before a playlist will be excluded.

##### bandwidth
* Type: `number`
* can be used as an initialization option
Expand Down Expand Up @@ -405,20 +414,16 @@ If true, this will take the device pixel ratio into account when doing rendition
This setting is `false` by default.

##### smoothQualityChange
* NOTE: DEPRECATED
* Type: `boolean`
* can be used as a source option
* can be used as an initialization option

When the `smoothQualityChange` property is set to `true`, a manual quality
change triggered via the [representations API](#vhsrepresentations) will use
smooth quality switching rather than the default fast (buffer-ejecting)
quality switching. Using smooth quality switching will mean no loading spinner
will appear during quality switches, but will cause quality switches to only
be visible after a few seconds.
smoothQualityChange is deprecated and will be removed in the next major version of VHS.

Note that this _only_ affects quality changes triggered via the representations
API; automatic quality switches based on available bandwidth will always be
smooth switches.
Instead of its prior behavior, smoothQualityChange will now call fastQualityChange, which
clears the buffer, chooses a new rendition, and starts loading content from the current
playhead position.

##### allowSeeksWithinUnsafeLiveWindow
* Type: `boolean`
Expand Down
2 changes: 1 addition & 1 deletion scripts/index-demo-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
rep.playlist.disabled = rep.id !== id;
});

window.mpc.smoothQualityChange_();
window.mpc.fastQualityChange_();
});
var hlsOptGroup = document.querySelector('[label="hls"]');
var dashOptGroup = document.querySelector('[label="dash"]');
Expand Down
1 change: 1 addition & 0 deletions src/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export const forEachMediaGroup = (master, callback) => {
*/
export const setupMediaPlaylist = ({ playlist, uri, id }) => {
playlist.id = id;
playlist.playlistErrors_ = 0;

if (uri) {
// For media playlists, m3u8-parser does not have access to a URI, as HLS media
Expand Down
26 changes: 17 additions & 9 deletions src/master-playlist-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export class MasterPlaylistController extends videojs.EventTarget {
bandwidth,
externVhs,
useCueTags,
maxPlaylistRetries,
blacklistDuration,
enableLowInitialPlaylist,
sourceType,
Expand All @@ -160,6 +161,7 @@ export class MasterPlaylistController extends videojs.EventTarget {
this.sourceType_ = sourceType;
this.useCueTags_ = useCueTags;
this.blacklistDuration = blacklistDuration;
this.maxPlaylistRetries = maxPlaylistRetries;
this.enableLowInitialPlaylist = enableLowInitialPlaylist;
if (this.useCueTags_) {
this.cueTagsTrack_ = this.tech_.addTextTrack(
Expand All @@ -172,6 +174,7 @@ export class MasterPlaylistController extends videojs.EventTarget {
this.requestOptions_ = {
withCredentials,
handleManifestRedirects,
maxPlaylistRetries,
timeout: null
};

Expand Down Expand Up @@ -848,16 +851,10 @@ export class MasterPlaylistController extends videojs.EventTarget {
* removing already buffered content
*
* @private
* @deprecated
*/
smoothQualityChange_(media = this.selectPlaylist()) {
if (media === this.masterPlaylistLoader_.media()) {
return;
}

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

this.mainSegmentLoader_.resetLoader();
// don't need to reset audio as it is reset when media changes
this.fastQualityChange_(media);
}

/**
Expand Down Expand Up @@ -1138,6 +1135,8 @@ export class MasterPlaylistController extends videojs.EventTarget {
return;
}

currentPlaylist.playlistErrors_++;

const playlists = this.masterPlaylistLoader_.master.playlists;
const enabledPlaylists = playlists.filter(isEnabled);
const isFinalRendition = enabledPlaylists.length === 1 && enabledPlaylists[0] === currentPlaylist;
Expand Down Expand Up @@ -1185,7 +1184,16 @@ export class MasterPlaylistController extends videojs.EventTarget {
}

// Blacklist this playlist
currentPlaylist.excludeUntil = Date.now() + (blacklistDuration * 1000);
let excludeUntil;

if (currentPlaylist.playlistErrors_ > this.maxPlaylistRetries) {
excludeUntil = Infinity;
} else {
excludeUntil = Date.now() + (blacklistDuration * 1000);
}

currentPlaylist.excludeUntil = excludeUntil;

if (error.reason) {
currentPlaylist.lastExcludeReason_ = error.reason;
}
Expand Down
4 changes: 1 addition & 3 deletions src/segment-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2177,9 +2177,7 @@ export default class SegmentLoader extends videojs.EventTarget {
`video buffer: ${timeRangesToArray(videoBuffered).join(', ')}, `);
this.error({
message: 'Quota exceeded error with append of a single segment of content',
// To prevent any possible repeated downloads for content we can't actually
// append, blacklist forever.
blacklistDuration: Infinity
excludeUntil: Infinity
});
this.trigger('error');
return;
Expand Down
11 changes: 10 additions & 1 deletion src/videojs-http-streaming.js
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,12 @@ class VhsHandler extends Component {
document.msFullscreenElement;

if (fullscreenElement && fullscreenElement.contains(this.tech_.el())) {
this.masterPlaylistController_.smoothQualityChange_();
this.masterPlaylistController_.fastQualityChange_();
} else {
// When leaving fullscreen, since the in page pixel dimensions should be smaller
// than full screen, see if there should be a rendition switch down to preserve
// bandwidth.
this.masterPlaylistController_.checkABR_();
}
});

Expand Down Expand Up @@ -708,6 +713,10 @@ class VhsHandler extends Component {
this.tech_.setCurrentTime(time);
};

if (this.options_.smoothQualityChange) {
videojs.log.warn('smoothQualityChange is deprecated and will be removed in the next major version');
}

this.masterPlaylistController_ = new MasterPlaylistController(this.options_);

const playbackWatcherOptions = videojs.mergeOptions(
Expand Down
5 changes: 0 additions & 5 deletions test/configuration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ const options = [{
default: 4194304,
test: 5,
alt: 555
}, {
name: 'smoothQualityChange',
default: false,
test: true,
alt: false
}, {
name: 'useBandwidthFromLocalStorage',
default: false,
Expand Down
2 changes: 2 additions & 0 deletions test/manifest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,14 @@ QUnit.module('manifest', function() {
const expectedPlaylist0 = {
attributes: {},
resolvedUri: urlTo('uri-0'),
playlistErrors_: 0,
uri: 'uri-0',
id: '0-uri-0'
};
const expectedPlaylist1 = {
attributes: {},
resolvedUri: urlTo('uri-1'),
playlistErrors_: 0,
uri: 'uri-1',
id: '1-uri-1'
};
Expand Down
Loading

0 comments on commit 22351a9

Please sign in to comment.