summaryrefslogtreecommitdiffstats
path: root/audio/out
diff options
context:
space:
mode:
authorDudemanguy <random342@airmail.cc>2023-08-09 22:50:05 -0500
committerDudemanguy <random342@airmail.cc>2023-08-11 22:28:50 +0000
commit41c03212083485afd683c4b6231d49b9557bb0a4 (patch)
tree57e9d607f60e8da20631187ee07b7c7fa2beca8f /audio/out
parent908dc791299672042b0fc24de64b57f88bba313c (diff)
downloadmpv-41c03212083485afd683c4b6231d49b9557bb0a4.tar.bz2
mpv-41c03212083485afd683c4b6231d49b9557bb0a4.tar.xz
audio: drain ao before setting pause
There's an edge cause with gapless audio and pausing. Since, gapless audio works by sending an EOF immediately, it's possible to pause on the next file before audio actually finishes playing and thus the sound gets cut off. The fix is to simply just always do an ao_drain if the ao is about to set a pause on EOF and we still have audio playing. Fixes #8898.
Diffstat (limited to 'audio/out')
-rw-r--r--audio/out/ao.h2
-rw-r--r--audio/out/buffer.c7
2 files changed, 7 insertions, 2 deletions
diff --git a/audio/out/ao.h b/audio/out/ao.h
index 78f21c9ed9..18c7cdc02f 100644
--- a/audio/out/ao.h
+++ b/audio/out/ao.h
@@ -98,7 +98,7 @@ void ao_set_gain(struct ao *ao, float gain);
double ao_get_delay(struct ao *ao);
void ao_reset(struct ao *ao);
void ao_start(struct ao *ao);
-void ao_set_paused(struct ao *ao, bool paused);
+void ao_set_paused(struct ao *ao, bool paused, bool eof);
void ao_drain(struct ao *ao);
bool ao_is_playing(struct ao *ao);
struct mp_async_queue;
diff --git a/audio/out/buffer.c b/audio/out/buffer.c
index 673ec7a84e..77506d8363 100644
--- a/audio/out/buffer.c
+++ b/audio/out/buffer.c
@@ -349,12 +349,17 @@ void ao_start(struct ao *ao)
ao_wakeup_playthread(ao);
}
-void ao_set_paused(struct ao *ao, bool paused)
+void ao_set_paused(struct ao *ao, bool paused, bool eof)
{
struct buffer_state *p = ao->buffer_state;
bool wakeup = false;
bool do_reset = false, do_start = false;
+ // If we are going to pause on eof and ao is still playing,
+ // be sure to drain the ao first for gapless.
+ if (eof && paused && ao_is_playing(ao))
+ ao_drain(ao);
+
pthread_mutex_lock(&p->lock);
if ((p->playing || !ao->driver->write) && !p->paused && paused) {