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

For the [0.5; 1) speed range, the combination of having a "slow down" speed (i.e. more output frames than input frames), and Sonic potentially needing to copy more input frames that are available in the input buffer can lead to an unexpected underflow. Specifically, the underflow happens in Sonic#queueEndOfStream() when the following conditions are met (skipping some minor ones): 1. `inputFrameCount < remainingInputToCopyFrameCount` 2. `0.5f <= speed < 1`. 3. `outputFrameCount < (inputFrameCount / remainingInputToCopyFrameCount) / 2`. This underflow caused `SonicAudioProcessor#isEnded()` to return a false negative (because `getOutputSize() != 0`), which would stall the `DefaultAudioSink` waiting for processing to end after EOS. In practical terms, the underflow is relatively easy to reproduce if we consume all of Sonic's output and then immediately queue EOS without queueing any more input in between. This should cause both `inputFrameCount` and `outputFrameCount` to drop to 0. PiperOrigin-RevId: 711773565