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

Close media key sessions and clear media keys when media detached #2664

Merged
merged 4 commits into from
May 20, 2020

Conversation

springuper
Copy link
Contributor

@springuper springuper commented Apr 20, 2020

This PR will...

Close media key sessions and clear media keys when media detached.

Why is this Pull Request needed?

When we tested Hls.js on Android Webview on FireTV, we found that the player failed to play DRM titles after finishing 5 or 6 titles. After investigation, the root cause is:

whenever we create a new Hls.js instance for a DRM title, it will set new media key and open a new key session to decrypt DRM media data, but it doesn’t release them when the Hls.js instance destroys. Looks like there is a maximum limitation on FireTV platform for opening key sessions, once we reach it, no new session could be created any more.

Related adb logs:

29063 10-30 03:49:57.719   295 13552 I WVCdm   : CdmEngine::QueryStatus                                                                                                                                         29064 10-30 03:49:57.720   295 13552 D OEMCryptoCENC: Use MTKTEEClient                                                                                                                                          29065 10-30 03:49:57.721 14024 14523 E cr_media: Security level: current L1, new L3
29066 10-30 03:49:57.721   295 13552 I WVCdm   : CdmEngine::OpenSession
29067 10-30 03:49:57.722   295 13552 E WVCdm   : OEMCrypto_Open failed: 31, open sessions: 17, initialized: 1
29068 10-30 03:49:57.722   295 13552 E WVCdm   : CdmEngine::OpenSession: bad session init: 9
29069 10-30 03:49:57.726 14024 14523 E cr_media: Cannot open a new session
29070 10-30 03:49:57.726 14024 14523 E cr_media: android.media.ResourceBusyException: Failed to open session
29071 10-30 03:49:57.726 14024 14523 E cr_media:  at android.media.MediaDrm.openSession(Native Method)                                                                                                          29072 10-30 03:49:57.726 14024 14523 E cr_media:  at org.chromium.media.MediaDrmBridge.openSession(MediaDrmBridge.java:361)
29073 10-30 03:49:57.726 14024 14523 E cr_media:  at org.chromium.media.MediaDrmBridge.createMediaCrypto(MediaDrmBridge.java:304)
29074 10-30 03:49:57.726 14024 14523 E cr_media:  at org.chromium.media.MediaDrmBridge.create(MediaDrmBridge.java:444)                                                                                          29075 10-30 03:49:57.726 14024 14523 E cr_media: Cannot create MediaCrypto Session.
29076 10-30 03:49:57.727 14024 14523 E chromium: [ERROR:android_cdm_factory.cc(110)] MediaDrmBridge creation failed

So we borrow Google Shaka player's idea, do these necessary cleanups when media is detached.

Are there any points in the code the reviewer needs to double check?

  • There is one point need further discussion: for recoverMediaError method in Hls class, we need to wait until all cleanups are finished before attachMedia again: https://github.com/video-dev/hls.js/blob/master/src/hls.ts#L332. I would suggest we use a new event EME_DESTROYED to make it work we decide to not add this event for now, will review the DRM API proposal and discuss how to handle it

Resolves issues:

N/A

Checklist

  • changes have been done against master branch, and PR does not conflict
  • new unit / functional tests have been added (whenever applicable)
  • API or design changes are documented in API.md

src/controller/eme-controller.ts Outdated Show resolved Hide resolved
@robwalch robwalch added this to the 0.14.0 milestone May 1, 2020
@robwalch robwalch requested a review from itsjamie May 20, 2020 16:25
... to prevent errors when reattaching a new element synchronously (may need to also prevent further async tampering of _mediaKeysList)
@video-dev video-dev deleted a comment from itsjamie May 20, 2020
src/controller/eme-controller.ts Outdated Show resolved Hide resolved
@robwalch robwalch self-requested a review May 20, 2020 18:01
src/controller/eme-controller.ts Outdated Show resolved Hide resolved
@robwalch robwalch merged commit dd6d5a3 into video-dev:master May 20, 2020
@springuper springuper deleted the chore/eme-destroy branch June 11, 2020 00:24
@springuper
Copy link
Contributor Author

thank @robwalch for editing this PR and merging it, will go to take a look at the DRM API proposal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants