diff options
-rw-r--r-- | audio/out/ao.c | 14 | ||||
-rw-r--r-- | audio/out/internal.h | 1 | ||||
-rw-r--r-- | audio/out/pull.c | 9 | ||||
-rw-r--r-- | audio/out/push.c | 7 |
4 files changed, 16 insertions, 15 deletions
diff --git a/audio/out/ao.c b/audio/out/ao.c index 977b8eb69a..8e1ceb4bf1 100644 --- a/audio/out/ao.c +++ b/audio/out/ao.c @@ -31,7 +31,6 @@ #include "options/options.h" #include "options/m_config.h" -#include "osdep/timer.h" #include "common/msg.h" #include "common/common.h" #include "common/global.h" @@ -313,22 +312,11 @@ void ao_resume(struct ao *ao) ao->api->resume(ao); } -// Be careful with locking -void ao_wait_drain(struct ao *ao) -{ - // This is probably not entirely accurate, but good enough. - mp_sleep_us(ao_get_delay(ao) * 1000000); - ao_reset(ao); -} - // Block until the current audio buffer has played completely. void ao_drain(struct ao *ao) { - if (ao->api->drain) { + if (ao->api->drain) ao->api->drain(ao); - } else { - ao_wait_drain(ao); - } } bool ao_eof_reached(struct ao *ao) diff --git a/audio/out/internal.h b/audio/out/internal.h index 3d586f3848..75f5798bff 100644 --- a/audio/out/internal.h +++ b/audio/out/internal.h @@ -158,7 +158,6 @@ struct ao_driver { // These functions can be called by AOs. int ao_play_silence(struct ao *ao, int samples); -void ao_wait_drain(struct ao *ao); int ao_read_data(struct ao *ao, void **data, int samples, int64_t out_time_us); struct pollfd; int ao_wait_poll(struct ao *ao, struct pollfd *fds, int num_fds, diff --git a/audio/out/pull.c b/audio/out/pull.c index 7902c9afb6..eb77be81a2 100644 --- a/audio/out/pull.c +++ b/audio/out/pull.c @@ -193,6 +193,14 @@ static void resume(struct ao *ao) ao->driver->resume(ao); } +static void drain(struct ao *ao) +{ + struct ao_pull_state *p = ao->api_priv; + if (atomic_load(&p->state) == AO_STATE_PLAY) + mp_sleep_us(get_delay(ao) * 1000000); + reset(ao); +} + static void uninit(struct ao *ao) { ao->driver->uninit(ao); @@ -212,6 +220,7 @@ const struct ao_driver ao_api_pull = { .init = init, .control = control, .uninit = uninit, + .drain = drain, .reset = reset, .get_space = get_space, .play = play, diff --git a/audio/out/push.c b/audio/out/push.c index 6b04586b43..0ecba19da7 100644 --- a/audio/out/push.c +++ b/audio/out/push.c @@ -146,6 +146,10 @@ static void drain(struct ao *ao) struct ao_push_state *p = ao->api_priv; pthread_mutex_lock(&p->lock); + if (p->paused) { + pthread_mutex_unlock(&p->lock); + return; + } p->final_chunk = true; p->drain = true; wakeup_playthread(ao); @@ -154,7 +158,8 @@ static void drain(struct ao *ao) pthread_mutex_unlock(&p->lock); if (!ao->driver->drain) - ao_wait_drain(ao); + mp_sleep_us(get_delay(ao) * 1000000); + reset(ao); } static int unlocked_get_space(struct ao *ao) |