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

When operating the MediaCodec in asynchronous mode, we are seeing NPEs raised from the DefaultAudioSink because output buffers are pushed to the DefaultAudioSink with the DefaultAudioSink not configured yet. This is possible to happen if an output buffer is passed with MediaCodecAudioRenderer.processOutputBuffer() before an output format change. One possible code path to trigger this is when an output format change is pending and we flush MediaCodec (e.g. for a seek): the callback is waiting in the looper's queue but we ignore all currently queued callbacks after a flush(). This commit checks for a pending output format change during a flush(): if one exists, and the next MediaCodec output callback right after the flush() is an output buffer (and not a new output format), then the pending output format is propagated first. The only adapter that needs to change is the AsynchronousMediaCodecAdapter which previsouly deleted all pending callbacks immediately on flush(). The AsynchronousMediaCodecAdapter now needs to also handle every enqueued callback in order to identify is there's a pending output format change. Testing: added unit tests for the new code. I have verified that if we pass an output buffer to the audio renderer before the output format, it will result on the specific NPE, but I cannot reproduce the base scenario (an output format change is pending when flushing) on a real device because we can't know if an output format is indeed pending. PiperOrigin-RevId: 310885283
ExoPlayer library
The ExoPlayer library is split into multiple modules. See ExoPlayer's top level README for more information about the available library modules and how to use them.