mirror of
https://github.com/mpv-player/mpv.git
synced 2025-12-28 05:33:14 +00:00
The problem here is likely ao_alsa specific and has the same symptons as what the previous commit fixed (audio not playing when the file changes but the details are a bit different here and the sample rate does not matter. When using gapless audio (the default), the core player immediately marks the audio status as EOF after it starts draining and allows the remaining audio buffers to play while it marches on. This works fine. When not using gapless audio, it doesn't immediately set EOF and instead waits for the audio to finish playing before it does anything else. The problem is that ao_is_playing is always true so the core waits forever thinking audio is still playing when it actually isn't. ao_play_data is what is in charge of setting the mp_pcm_state with it calling out to the backend for additional help. Unfortunately, this doesn't work for alsa because it's too dumb to signal the desired states in this edge case so we have to help it a bit. The main thing to notice here is that even though we can get EOF from a frame, there can still be additional valid samples that compe after it. So we can't just immediately quit after EOF is seen. The approach here is to simply save if we got eof sometime in the past, wait until we get no more samples, mark state.playing as false and then jump over to the eof code. This will set p->playing to false as desired which allows the core code to set EOF and finally we can go through the reset logic and actually play audio for the next file.