Skip to content

Commit

Permalink
Reuse cache even if key system type given in API is not the same
Browse files Browse the repository at this point in the history
Thanks to the PR #1478, that basically allows integration tests on our
DRM logic without a real encrypted or decodable contents nor MSE/EME
available, I noticed that I very recently brought a minor regression in
the rewrite of the `MediaKeySystemAccess` cache reusage rules.

We relied on the `keySystems[].type` API to see if the cached one was
compatible to the new wanted one, we probably wanted to compare the
former with the `type` actually provided as argument to the
`navigator.requestMediaKeySystemAccess` API instead (e.g.
`keySystems[].type` could be set just to `widevine`, in which case the
RxPlayer will probably ask for `com.widevine.alpha` instead).

Thankfully, EME defines a
[`MediaKeySystemAccess.prototype.keySystem`](https://www.w3.org/TR/encrypted-media-2/#dom-navigator-requestmediakeysystemaccess)
property that seems to (according to that recommendation) always be equal
to the asked `keySystem`.
  • Loading branch information
peaBerberian committed Dec 23, 2024
1 parent e7277b1 commit 8aec1c3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/main_thread/decrypt/__tests__/find_key_system.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ describe("find_key_systems - ", () => {
it("should create a media key the first time and then reuse the previous one if it's the same configuration", async () => {
requestMediaKeySystemAccessMock.mockImplementation(() => {
return {
keySystem: "com.widevine.alpha",
createMediaKeys: () => ({
createSession: () => ({
// eslint-disable-next-line @typescript-eslint/no-empty-function
Expand Down Expand Up @@ -200,6 +201,7 @@ describe("find_key_systems - ", () => {
it("should create a media key the first time and then create another one if the previous is not compatible.", async () => {
requestMediaKeySystemAccessMock.mockImplementation(() => {
return {
keySystem: "com.widevine.alpha",
createMediaKeys: () => ({
createSession: () => ({
// eslint-disable-next-line @typescript-eslint/no-empty-function
Expand Down Expand Up @@ -258,6 +260,7 @@ describe("find_key_systems - ", () => {
it("should create a media key the first time and then reuse the previous one if it's a different configuration but it's a compatible configuration.", async () => {
requestMediaKeySystemAccessMock.mockImplementation(() => {
return {
keySystem: "com.widevine.alpha",
createMediaKeys: () => ({
createSession: () => ({
// eslint-disable-next-line @typescript-eslint/no-empty-function
Expand Down
2 changes: 1 addition & 1 deletion src/main_thread/decrypt/find_key_system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ export default function getMediaKeySystemAccess(
currentState !== null &&
!shouldRenewMediaKeySystemAccess() &&
// TODO: Do it with MediaKeySystemAccess.prototype.keySystem instead?
keyType === currentState.keySystemOptions.type &&
keyType === currentState.mediaKeySystemAccess.keySystem &&
eme.implementation === currentState.emeImplementation.implementation &&
isNewMediaKeySystemConfigurationCompatibleWithPreviousOne(
keySystemConfiguration,
Expand Down

0 comments on commit 8aec1c3

Please sign in to comment.