DRM: Fix potential race condition issues on setMediaKeys and quick content switching #1594
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 theHTMLMediaElement
(that's the work-around part of some LG issues) by calling thesetMediaKeys
API with anull
MediaKeys
(as documented in the EME recommendation), yet without awaiting that the originalsetMediaKeys
call with the actualMediaKeys
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-pendingsetMediaKeys
call for a previous content ends up failing when another content, which needs to rely on the sameMediaKeys
instance, is playing, noMEDIA_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 theHTMLMediaElement
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.