Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Florent-Bouisset committed Apr 30, 2024
1 parent e78c575 commit 4528c5a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
7 changes: 7 additions & 0 deletions src/compat/can_rely_on_request_media_key_system_access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,10 @@ export function canRelyOnRequestMediaKeySystemAccess(keySystem: string): boolean
}
return true;
}
/**
* The PlayReadyHeader sample that will be used to test if the CDM is supported.
* The KID does not matter because no content will be played, it's only to check if
* the CDM is capable of creating a session and generating a request.
*/
export const PLAY_READY_HEADER_EXAMPLE =
'<WRMHEADER xmlns="http://schemas.microsoft.com/DRM/2007/03/PlayReadyHeader" version="4.0.0.0"><DATA><PROTECTINFO><KEYLEN>16</KEYLEN><ALGID>AESCTR</ALGID></PROTECTINFO><KID>ckB07BNLskeUq0qd83fTbA==</KID><DS_ID>yYIPDBca1kmMfL60IsfgAQ==</DS_ID><CUSTOMATTRIBUTES xmlns=""><encryptionref>312_4024_2018127108</encryptionref></CUSTOMATTRIBUTES><CHECKSUM>U/tsUYRgMzw=</CHECKSUM></DATA></WRMHEADER>';
14 changes: 7 additions & 7 deletions src/main_thread/decrypt/find_key_system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
* limitations under the License.
*/

import { canRelyOnRequestMediaKeySystemAccess } from "../../compat/can_rely_on_request_media_key_system_access";
import {
canRelyOnRequestMediaKeySystemAccess,
PLAY_READY_HEADER_EXAMPLE,
} from "../../compat/can_rely_on_request_media_key_system_access";
import type { ICustomMediaKeySystemAccess } from "../../compat/eme";
import eme from "../../compat/eme";
import shouldRenewMediaKeySystemAccess from "../../compat/should_renew_media_key_system_access";
Expand Down Expand Up @@ -378,7 +381,7 @@ export default function getMediaKeySystemAccess(
);

try {
const keySystemAccess = await testOneKeySystem(keyType, keySystemConfigurations);
const keySystemAccess = await testKeySystem(keyType, keySystemConfigurations);
log.info("DRM: Found compatible keysystem", keyType, index + 1);
return {
type: "create-media-key-system-access" as const,
Expand All @@ -403,7 +406,7 @@ export default function getMediaKeySystemAccess(
* @param {Array.<MediaKeySystemMediaCapability>} keySystemConfigurations - Configurations for this keySystem
* @returns Promise resolving with the MediaKeySystemAccess. Rejects if unsupported.
*/
export async function testOneKeySystem(
export async function testKeySystem(
keyType: string,
keySystemConfigurations: MediaKeySystemConfiguration[],
) {
Expand All @@ -416,10 +419,7 @@ export async function testOneKeySystem(
try {
const mediaKeys = await keySystemAccess.createMediaKeys();
const session = mediaKeys.createSession();
// this is just and an example initData to test if the CDM is capable of generating a request
const playReadyHeader =
'<WRMHEADER xmlns="http://schemas.microsoft.com/DRM/2007/03/PlayReadyHeader" version="4.0.0.0"><DATA><PROTECTINFO><KEYLEN>16</KEYLEN><ALGID>AESCTR</ALGID></PROTECTINFO><KID>ckB07BNLskeUq0qd83fTbA==</KID><LA_URL>http://drm.canal-plus.com/</LA_URL><LUI_URL>http://drm.canal-plus.com/</LUI_URL><DS_ID>yYIPDBca1kmMfL60IsfgAQ==</DS_ID><CUSTOMATTRIBUTES xmlns=""><encryptionref>312_4024_2018127108</encryptionref></CUSTOMATTRIBUTES><CHECKSUM>U/tsUYRgMzw=</CHECKSUM></DATA></WRMHEADER>';
const initData = generatePlayReadyInitData(playReadyHeader);
const initData = generatePlayReadyInitData(PLAY_READY_HEADER_EXAMPLE);
await session.generateRequest("cenc", initData);
} catch (err) {
log.debug("DRM: KeySystemAccess was granted but it is not usable");
Expand Down
4 changes: 2 additions & 2 deletions src/utils/__tests__/generate_init_data.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { utf16LEToStr } from "../string_parsing";

describe("utils - generatePlayReadyInitData", () => {
const playReadyHeader =
'<WRMHEADER xmlns="http://schemas.microsoft.com/DRM/2007/03/PlayReadyHeader" version="4.0.0.0"><DATA><PROTECTINFO><KEYLEN>16</KEYLEN><ALGID>AESCTR</ALGID></PROTECTINFO><KID>ckB07BNLskeUq0qd83fTbA==</KID><LA_URL>http://drm.canal-plus.com/</LA_URL><LUI_URL>http://drm.canal-plus.com/</LUI_URL><DS_ID>yYIPDBca1kmMfL60IsfgAQ==</DS_ID><CUSTOMATTRIBUTES xmlns=""><encryptionref>312_4024_2018127108</encryptionref></CUSTOMATTRIBUTES><CHECKSUM>U/tsUYRgMzw=</CHECKSUM></DATA></WRMHEADER>';
'<WRMHEADER xmlns="http://schemas.microsoft.com/DRM/2007/03/PlayReadyHeader" version="4.0.0.0"><DATA><PROTECTINFO><KEYLEN>16</KEYLEN><ALGID>AESCTR</ALGID></PROTECTINFO><KID>ckB07BNLskeUq0qd83fTbA==</KID><DS_ID>yYIPDBca1kmMfL60IsfgAQ==</DS_ID><CUSTOMATTRIBUTES xmlns=""><encryptionref>312_4024_2018127108</encryptionref></CUSTOMATTRIBUTES></DATA></WRMHEADER>';

const initData = generatePlayReadyInitData(playReadyHeader);
const decodedInitDataUtf16LE = utf16LEToStr(initData);

it("has correct length", () => {
// the expected length for an initData with that PlayReady header.
expect(initData.length).toBe(996);
expect(initData.length).toBe(754);
});

it("has the playerReadyHeader in it", () => {
Expand Down

0 comments on commit 4528c5a

Please sign in to comment.