mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00

`mediaCrypto` is initialized before `codec` in `maybeInitCodecOrBypass`. Before this change, it was possible for `maybeInitCodecOrBypass` to complete with `mediaCrypto != null` and `codec == null`, in particular if it was run as part of clearing the player surface (since in that case, no video codec is initialized). This inconsistent state then causes issues during a later invocation of `maybeInitCodecOrBypass`, when `mediaCrypto` is still non-null, and `mediaCryptoRequiresSecureDecoder = true`, but the content has been changed to unencrypted with no associated DRM session. This results in a playback error, because a secure decoder is initialized but there's no DRM session available to work with it. This change ensures that when `maybeInitCodecOrBypass` completes, either both `mediaCrypto != null` and `codec != null` (i.e. codec initialization was completed) or `mediaCrypto == null` and `codec == null` (i.e. codec initialization was not completed). We also ensure that when nulling out `mediaCrypto` we also set `maybeInitCodecOrBypass = false`. A later change should be able to demote `maybeInitCodecOrBypass` from a field to a local in order to remove any risk of that part of state becoming out of sync. This resolves the issue, because during the second invocation of `maybeInitCodecOrBypass` an insecure decoder is now (correctly) initialized and the unencrypted content is successfully played. #minor-release PiperOrigin-RevId: 587713911