diff --git a/src/compat/should_call_generate_request_before_buffering_media.ts b/src/compat/should_call_generate_request_before_buffering_media.ts new file mode 100644 index 0000000000..6403c939f8 --- /dev/null +++ b/src/compat/should_call_generate_request_before_buffering_media.ts @@ -0,0 +1,23 @@ +/** + * (2024-07-23) We noticed issues with most devices relying on PlayReady when + * playing some contents with a mix of encrypted and clear segments (not with + * Canal+ own contents weirdly enough, yet with multiple others both encoded + * and packaged differently). + * The issue fixed itself when we called the + * `MediaKeySession.prototype.generateRequest` EME API **BEFORE** any segment + * was buffered. + * + * So this function returns `true` when calling `generateRequest` should + * probably be performed before buffering any segment. + * + * @param {string} keySystem - The key system in use. + * @returns {boolean} + */ +export default function shouldCallGenerateRequestBeforeBufferingMedia( + keySystem: string, +): boolean { + if (keySystem.indexOf("playready") !== -1) { + return true; + } + return false; +} diff --git a/src/main_thread/decrypt/content_decryptor.ts b/src/main_thread/decrypt/content_decryptor.ts index 5aed88295b..6e26b96c8c 100644 --- a/src/main_thread/decrypt/content_decryptor.ts +++ b/src/main_thread/decrypt/content_decryptor.ts @@ -16,6 +16,7 @@ import type { ICustomMediaKeys, ICustomMediaKeySystemAccess } from "../../compat/eme"; import eme, { getInitData } from "../../compat/eme"; +import shouldCallGenerateRequestBeforeBufferingMedia from "../../compat/should_call_generate_request_before_buffering_media"; import config from "../../config"; import { EncryptedMediaError, OtherError } from "../../errors"; import log from "../../log"; @@ -54,6 +55,7 @@ import { areSomeKeyIdsContainedIn, } from "./utils/key_id_comparison"; import type KeySessionRecord from "./utils/key_session_record"; +import performFakeGenerateRequest from "./utils/perform_fake_generate_request"; /** * Module communicating with the Content Decryption Module (or CDM) to be able @@ -291,6 +293,22 @@ export default class ContentDecryptor extends EventEmitter { + const session = mediaKeys.createSession(); + const initData = generatePlayReadyInitData(DUMMY_PLAY_READY_HEADER); + await session.generateRequest("cenc", initData); + closeSession(session).catch((err) => { + const error = err instanceof Error ? err : new Error("Unknown Error"); + log.warn("DRM: unable to close fake MediaKeySession", error); + }); +}