Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRM: Fix potential race condition issues on setMediaKeys and quick content switching #1594

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

peaBerberian
Copy link
Collaborator

@peaBerberian peaBerberian commented Nov 15, 2024

We've recently noticed on some LG TVs only that we triggered a MEDIA_KEYS_ATTACHMENT_ERROR if loading different contents very fast (e.g. "zapping" like crazy on the remote ~15-20 times on those).

Turns out that the issue was due to a complex combination of optimizations and work-arounds, where we would "reset" the MediaKeys instance attached to the HTMLMediaElement (that's the work-around part of some LG issues) by calling the setMediaKeys API with a null MediaKeys (as documented in the EME recommendation), yet without awaiting that the original setMediaKeys call with the actual MediaKeys instance for that same content to be finished.

Doing multiple setMediaKeys call without waiting for the previous one to finish leading to an error is an actually documented behavior in the EME recommendation so this could be categorized as a bug on our side.

To fix this, I tried an easy way first but found out that there could be multiple other issues with MediaKeys attachment: if for whatever reason the still-pending setMediaKeys call for a previous content ends up failing when another content, which needs to rely on the same MediaKeys instance, is playing, no MEDIA_KEYS_ATTACHMENT_ERROR will be triggered and the RxPlayer could instead end up rebuffering indefinitely.

So I decided to do a bigger code update: Now the method returning information on the MediaKeys attached to the HTMLMediaElement is always asynchronous (it returns a Promise) just in case the attachment task is still pending (and to also handle cases where it would fail).

I still let a synchronous call for the getKeySystemConfiguration API, where it may thus also for now return the "expected" MediaKeys information (e.g. it will return the future expected state when attachment is still pending), because I wasn't sure of the behavior we want here - though I still am.

@peaBerberian peaBerberian added bug This is an RxPlayer issue (unexpected result when comparing to the API) DRM Relative to DRM (EncryptedMediaExtensions) labels Nov 15, 2024
…ntent switching

We've recently noticed on some LG TVs only that we triggered a
`MEDIA_KEYS_ATTACHMENT_ERROR` if loading different contents very fast
(e.g. "zapping" like crazy on the remote ~15-20 times on those).

Turns out that the issue was due to a complex combination of
optimizations and work-arounds, where we would "reset" the `MediaKeys`
instance attached to the `HTMLMediaElement` (that's the work-around part of
some LG issues) by calling the `setMediaKeys` API with a `null` `MediaKeys`
(as documented in the EME recommendation), yet without awaiting that the
original `setMediaKeys` call with the actual `MediaKeys` instance for
that same content to be finished.

Doing multiple `setMediaKeys` call without waiting for the previous one
to finish leading to an error is an actually documented behavior in the EME
recommendation so this could be categorized as a bug on our side.

To fix this, I tried an easy way first but found out that there could be
multiple other issues with `MediaKeys` attachment: if for whatever the
still-pending `setMediaKeys` call for a previous content ends up
failing when another content, which needs to rely on the same `MediaKeys`
instance, is playing, no `MEDIA_KEYS_ATTACHMENT_ERROR` will be triggered
and the RxPlayer could instead end up rebuffering indefinitely.

So I decided to do a bigger code update: Now the method returning
information on the `MediaKeys` attached to the `HTMLMediaElement` is always
asynchronous (it returns a Promise) just in case the attachment task is
still pending (and to also handle cases where it would fail).

I still let a synchronous call for the `getKeySystemConfiguration` API, where
it may thus also for now return the "expected" `MediaKeys` information
(e.g. it will return the future expected state when attachment is still
pending), because I wasn't sure of the behavior we want here - though I
still am.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This is an RxPlayer issue (unexpected result when comparing to the API) DRM Relative to DRM (EncryptedMediaExtensions)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant