Skip to content

Commit

Permalink
feat(MediaCap): make StreamUtils.filterManifest async
Browse files Browse the repository at this point in the history
Player.filterManifest() does two things:
1. Filter the manifest with Drm, codecs and currentVariant's
   compatibility in StreamUtil.
2. Filter the manifest with PlayerConfiguration.restrictions.

In applyConfig_(), only the restrictions config affects filtering
the manifests. We don't need to call StreamUtils.filterManifest().

2. Make the filterManifest function async.

Issue #1391

Change-Id: I2fba9cabb3f3a3e89f5d990c4eeb19cc74924de9
  • Loading branch information
michellezhuogg committed Feb 5, 2021
1 parent dee67f6 commit 5bb8c1c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
37 changes: 29 additions & 8 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -1745,7 +1745,7 @@ shaka.Player = class extends shaka.util.FakeEventTarget {

// Now that we have drm information, filter the manifest (again) so that we
// can ensure we only use variants with the selected key system.
this.filterManifest_(this.manifest_);
await this.filterManifest_(this.manifest_);
}

/**
Expand Down Expand Up @@ -1908,7 +1908,8 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
}

// Re-filter the manifest after streams have been chosen.
this.filterManifest_(this.manifest_);
await this.filterManifest_(this.manifest_);

// Dispatch a 'trackschanged' event now that all initial filtering is done.
this.onTracksChanged_();
// Since the first streams just became active, send an adaptation event.
Expand Down Expand Up @@ -2727,8 +2728,8 @@ shaka.Player = class extends shaka.util.FakeEventTarget {

// Need to apply the restrictions.
try {
// this.filterManifest_() may throw.
this.filterManifest_(this.manifest_);
// this.filterManifestWithRestrictions_() may throw.
this.filterManifestWithRestrictions_(this.manifest_);
} catch (error) {
this.onError_(error);
}
Expand Down Expand Up @@ -4493,19 +4494,29 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
* @param {?shaka.extern.Manifest} manifest
* @private
*/
filterManifest_(manifest) {
async filterManifest_(manifest) {
await this.filterManifestWithStreamUtils_(manifest);
this.filterManifestWithRestrictions_(manifest);
}

/**
* Filters a manifest, removing unplayable streams/variants.
*
* @param {?shaka.extern.Manifest} manifest
* @private
*/
async filterManifestWithStreamUtils_(manifest) {
goog.asserts.assert(manifest, 'Manifest should exist!');
goog.asserts.assert(this.video_, 'Must not be destroyed');
const StreamUtils = shaka.util.StreamUtils;

/** @type {?shaka.extern.Variant} */
const currentVariant = this.streamingEngine_ ?
this.streamingEngine_.getCurrentVariant() : null;

StreamUtils.filterManifest(
await shaka.util.StreamUtils.filterManifest(
this.drmEngine_, currentVariant, manifest);

const valid = manifest.variants.some(StreamUtils.isPlayable);
const valid = manifest.variants.some(shaka.util.StreamUtils.isPlayable);

// If none of the variants are playable, throw
// CONTENT_UNSUPPORTED_BY_BROWSER.
Expand All @@ -4515,7 +4526,17 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
shaka.util.Error.Category.MANIFEST,
shaka.util.Error.Code.CONTENT_UNSUPPORTED_BY_BROWSER);
}
}


/**
* Apply the restrictions configuration to the manifest, and check if there's
* a variant that meets the restrictions.
*
* @param {?shaka.extern.Manifest} manifest
* @private
*/
filterManifestWithRestrictions_(manifest) {
const tracksChanged = shaka.util.StreamUtils.applyRestrictions(
manifest.variants, this.config_.restrictions, this.maxHwRes_);
if (tracksChanged && this.streamingEngine_) {
Expand Down
5 changes: 4 additions & 1 deletion lib/util/stream_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ shaka.util.StreamUtils = class {
* @param {?shaka.extern.Variant} currentVariant
* @param {shaka.extern.Manifest} manifest
*/
static filterManifest(drmEngine, currentVariant, manifest) {
static async filterManifest(drmEngine, currentVariant, manifest) {
const StreamUtils = shaka.util.StreamUtils;

// Filter variants.
Expand Down Expand Up @@ -260,6 +260,9 @@ shaka.util.StreamUtils = class {

return keep;
});

// TODO: remove this after adopting MediaCapabilities.
await Promise.resolve();
}


Expand Down

0 comments on commit 5bb8c1c

Please sign in to comment.