Fix stale decryptOnlyCodecFormat used for non-DRM periods - #3390
Open
kmate-dolby wants to merge 1 commit into
Open
Fix stale decryptOnlyCodecFormat used for non-DRM periods#3390kmate-dolby wants to merge 1 commit into
kmate-dolby wants to merge 1 commit into
Conversation
When an audio stream is played back directly (passthrough or offload) but is DRM protected, MediaCodecAudioRenderer still instantiates a MediaCodec that is used only to decrypt the samples. In that case getMediaCodecConfiguration() stores the input format in decryptOnlyCodecFormat, and onOutputFormatChanged() uses it to configure the AudioSink with the original (encoded) format instead of the codec's raw output. decryptOnlyCodecFormat is only ever assigned in getMediaCodecConfiguration(), which runs from initCodec() and is therefore only reached for periods that actually create a codec. It was never cleared when the codec was released, so it lived for as long as the renderer did. As a result, for a DRM, non-DRM, DRM period sequence the non-DRM period is played through codec bypass and does not initialize a codec, so getMediaCodecConfiguration() is not called. onOutputFormatChanged() then still sees the decryptOnlyCodecFormat left over from the previous DRM period and configures the AudioSink with that stale format instead of the current one. Because the two formats can differ (for example in channel count), the sink is configured with the wrong input format. Fix this by clearing decryptOnlyCodecFormat when the codec is released, by overriding resetCodecStateForRelease() in MediaCodecAudioRenderer.
Author
|
Hi @tianyif, thank you for self assigning. Anything I can do to help you review my proposed fix? Thank you in advance. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
When an audio stream is played back directly (passthrough or offload) but is DRM protected, MediaCodecAudioRenderer still instantiates a MediaCodec that is used only to decrypt the samples. In that case getMediaCodecConfiguration() stores the input format in decryptOnlyCodecFormat, and onOutputFormatChanged() uses it to configure the AudioSink with the original (encoded) format instead of the codec's raw output.
decryptOnlyCodecFormat is only ever assigned in
getMediaCodecConfiguration(), which runs from initCodec() and is therefore only reached for periods that actually create a codec. It was never cleared when the codec was released, so it lived for as long as the renderer did.
As a result, for a DRM, non-DRM, DRM period sequence the non-DRM period is played through codec bypass and does not initialize a codec, so getMediaCodecConfiguration() is not called. onOutputFormatChanged() then still sees the decryptOnlyCodecFormat left over from the previous DRM period and configures the AudioSink with that stale format instead of the current one. Because the two formats can differ (for example in channel count), the sink is configured with the wrong input format.
Fix this by clearing decryptOnlyCodecFormat when the codec is released, by overriding resetCodecStateForRelease() in MediaCodecAudioRenderer.