Skip to content

Commit

Permalink
Revert "code review"
Browse files Browse the repository at this point in the history
This reverts commit d23ef3c.
  • Loading branch information
peaBerberian committed Aug 12, 2024
1 parent 61ed480 commit 2402edf
Showing 1 changed file with 14 additions and 58 deletions.
72 changes: 14 additions & 58 deletions src/main_thread/decrypt/content_decryptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import type { IMediaElement } from "../../compat/browser_compatibility_types";
import { isSafariDesktop } from "../../compat/browser_detection";
import type { ICustomMediaKeys, ICustomMediaKeySystemAccess } from "../../compat/eme";
import eme, { getInitData } from "../../compat/eme";
import config from "../../config";
Expand Down Expand Up @@ -730,6 +731,19 @@ export default class ContentDecryptor extends EventEmitter<IContentDecryptorEven
mediaKeysData: IAttachedMediaKeysData,
): boolean {
const { stores, options } = mediaKeysData;
/**
* On Safari using Directfile, the old EME implementation triggers
* the "webkitneedkey" event instead of "encrypted". There's an issue in Safari
* where "webkitneedkey" fires too early before all tracks are added from an HLS playlist.
* Safari incorrectly assumes some keys are missing for these tracks,
* leading to repeated "webkitneedkey" events. Because RxPlayer recognizes
* it already has a session for these keys and ignores the events,
* the content remains frozen. To resolve this, we handle the event
* assuming no session exists for the key.
*/
if (this._context.isDirectFile && isSafariDesktop) {
return false;
}

/**
* If set, a currently-used key session is already compatible to this
Expand All @@ -743,22 +757,6 @@ export default class ContentDecryptor extends EventEmitter<IContentDecryptorEven
return false;
}

/**
* On Safari using Directfile, the old EME implementation triggers
* the "webkitneedkey" event instead of "encrypted". There's an issue in Safari
* where "webkitneedkey" fires too early before all tracks are added from an HLS playlist.
* Safari incorrectly assumes some keys are missing for these tracks,
* leading to repeated "webkitneedkey" events. Because RxPlayer recognizes
* it already has a session for these keys and ignores the events,
* the content remains frozen. To resolve this, the session is re-created.
*/
const forceSessionRecreation =
eme.implementation === "webkit" && this._context.isDirectFile;
if (forceSessionRecreation) {
this.removeSessionForInitData(initializationData, mediaKeysData);
return false;
}

// Check if the compatible session is blacklisted
const blacklistedSessionError = compatibleSessionInfo.blacklistedSessionError;
if (!isNullOrUndefined(blacklistedSessionError)) {
Expand Down Expand Up @@ -863,48 +861,6 @@ export default class ContentDecryptor extends EventEmitter<IContentDecryptorEven
return false;
}

/**
* Remove the session corresponding to the initData provided, and close it.
* It does nothing if no session was found for this initData.
* @param {Object} initData : The initialization data corresponding to the session
* that need to be removed
* @param {Object} mediaKeysData : The media keys data
*/
private removeSessionForInitData(
initData: IProcessedProtectionData,
mediaKeysData: IAttachedMediaKeysData,
) {
const { stores } = mediaKeysData;
/** Remove the session and close it from the loadedSessionStore */
const entry = stores.loadedSessionsStore.reuse(initData);
if (entry !== null) {
stores.loadedSessionsStore
.closeSession(entry.mediaKeySession)
.catch(() =>
log.error("DRM: Cannot close the session from the loaded session store"),
);
}

/**
* If set, a currently-used key session is already compatible to this
* initialization data.
*/
const compatibleSessionInfo = arrayFind(this._currentSessions, (x) =>
x.record.isCompatibleWith(initData),
);
if (compatibleSessionInfo === undefined) {
return;
}
/** Remove the session from the currentSessions */
const indexOf = this._currentSessions.indexOf(compatibleSessionInfo);
if (indexOf !== -1) {
log.debug(
"DRM: A session from a processed init is removed due to forceSessionRecreation policy.",
);
this._currentSessions.splice(indexOf, 1);
}
}

/**
* Callback that should be called if an error that made the current
* `ContentDecryptor` instance unusable arised.
Expand Down

0 comments on commit 2402edf

Please sign in to comment.