audio: don't wait for draining if paused

Logic for this was missing from pull.c. For push.c it was missing if the
driver didn't support it. But even if the driver supported it (such as
with ao_alsa), strange behavior was observed by users. See issue #933.

Always check explicitly whether the AO is in paused mode, and if so,
don't drain.

Possibly fixes #933.

CC: @mpv-player/stable
This commit is contained in:
wm4 2014-07-13 20:06:33 +02:00
parent b505cab597
commit fb54a1436a
4 changed files with 16 additions and 15 deletions

View File

@ -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)

View File

@ -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,

View File

@ -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,

View File

@ -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)