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

fix(preload): Wait for drm keys when preloading #7698

Merged
merged 4 commits into from
Dec 3, 2024
Merged
Changes from 1 commit
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
Next Next commit
feat(preload): Wait for drm keys when preloading
Closes #7600
theodab committed Nov 30, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit da228b1a2e61299ce2f83e36f23f0d16adc24c45
12 changes: 12 additions & 0 deletions lib/media/drm_engine.js
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ goog.provide('shaka.media.DrmEngine');
goog.require('goog.asserts');
goog.require('shaka.log');
goog.require('shaka.net.NetworkingEngine');
goog.require('shaka.util.ArrayUtils');
goog.require('shaka.util.BufferUtils');
goog.require('shaka.util.Destroyer');
goog.require('shaka.util.DrmUtils');
@@ -67,6 +68,9 @@ shaka.media.DrmEngine = class {
*/
this.activeSessions_ = new Map();

/** @private {!Array.<!shaka.net.NetworkingEngine.PendingRequest>} */
this.activeRequests_ = [];

/**
* @private {!Map<string,
* {initData: ?Uint8Array, initDataType: ?string}>}
@@ -1387,6 +1391,12 @@ shaka.media.DrmEngine = class {
this.video_.paused && !this.initialRequestsSent_);
}

/** @return {!Promise} */
async waitForActiveRequests() {
await this.allSessionsLoaded_;
await Promise.all(this.activeRequests_.map((req) => req.promise));
}

/**
* Sends a license request.
* @param {!MediaKeyMessageEvent} event
@@ -1446,7 +1456,9 @@ shaka.media.DrmEngine = class {
try {
const req = this.playerInterface_.netEngine.request(
requestType, request, {isPreload: this.isPreload_()});
this.activeRequests_.push(req);
response = await req.promise;
shaka.util.ArrayUtils.remove(this.activeRequests_, req);
} catch (error) {
if (this.destroyer_.destroyed()) {
return;
12 changes: 9 additions & 3 deletions lib/media/preload_manager.js
Original file line number Diff line number Diff line change
@@ -398,7 +398,13 @@ shaka.media.PreloadManager = class extends shaka.util.FakeEventTarget {
await this.initializeDrmInner_();
this.throwIfDestroyed_();

await this.chooseInitialVariantInner_();
await this.chooseInitialVariantAndPrefetchInner_();
this.throwIfDestroyed_();

// We don't need the drm keys to load completely for the initial variant
// to be chosen, but we won't mark the load as a success until it has
// been loaded. So wait for it here, not inside initializeDrmInner_.
await this.drmEngine_.waitForActiveRequests();
this.throwIfDestroyed_();

this.successPromise_.resolve();
@@ -610,12 +616,12 @@ shaka.media.PreloadManager = class extends shaka.util.FakeEventTarget {

/**
* Performs a final filtering of the manifest, and chooses the initial
* variant.
* variant. Also prefetches segments.
*
* @return {!Promise}
* @private
*/
async chooseInitialVariantInner_() {
async chooseInitialVariantAndPrefetchInner_() {
goog.asserts.assert(
this.manifest_, 'The manifest should already be parsed.');