|
15 | 15 | */
|
16 | 16 |
|
17 | 17 | import type { ICustomMediaKeys, ICustomMediaKeySystemAccess } from "../../compat/eme";
|
18 |
| -import eme, { getInitData } from "../../compat/eme"; |
| 18 | +import eme, { closeSession, getInitData } from "../../compat/eme"; |
| 19 | +import { |
| 20 | + DUMMY_PLAY_READY_HEADER, |
| 21 | + generatePlayReadyInitData, |
| 22 | +} from "../../compat/generate_init_data"; |
| 23 | +import shouldCallGenerateRequestBeforeBufferingMedia from "../../compat/should_call_generate_request_before_buffering_media"; |
19 | 24 | import config from "../../config";
|
20 | 25 | import { EncryptedMediaError, OtherError } from "../../errors";
|
21 | 26 | import log from "../../log";
|
@@ -291,6 +296,28 @@ export default class ContentDecryptor extends EventEmitter<IContentDecryptorEven
|
291 | 296 | return;
|
292 | 297 | }
|
293 | 298 |
|
| 299 | + if ( |
| 300 | + shouldCallGenerateRequestBeforeBufferingMedia(mediaKeySystemAccess.keySystem) |
| 301 | + ) { |
| 302 | + try { |
| 303 | + const session = mediaKeys.createSession(); |
| 304 | + const initData = generatePlayReadyInitData(DUMMY_PLAY_READY_HEADER); |
| 305 | + await session.generateRequest("cenc", initData); |
| 306 | + closeSession(session).catch((err) => { |
| 307 | + const error = err instanceof Error ? err : new Error("Unknown Error"); |
| 308 | + log.warn("DRM: unable to close initial fake MediaKeySession", error); |
| 309 | + }); |
| 310 | + } catch (err) { |
| 311 | + const error = err instanceof Error ? err : new Error("Unknown Error"); |
| 312 | + log.warn("DRM: unable to fully perform fake generateRequest call", error); |
| 313 | + } |
| 314 | + } |
| 315 | + |
| 316 | + if (this._isStopped()) { |
| 317 | + // We might be stopped since then |
| 318 | + return; |
| 319 | + } |
| 320 | + |
294 | 321 | const prevState = this._stateData.state;
|
295 | 322 | this._stateData = {
|
296 | 323 | state: ContentDecryptorState.ReadyForContent,
|
|
0 commit comments