1
0
mirror of https://github.com/mpv-player/mpv synced 2025-02-18 05:37:04 +00:00

audio: move start() calls outside of lock

Pull based AOs might want to call ao_read_data() inside start().
This fixes ao_opensles deadlocking.
This commit is contained in:
sfan5 2020-09-20 14:45:45 +02:00
parent 03047a0169
commit c1db4630e6

View File

@ -327,6 +327,7 @@ void ao_reset(struct ao *ao)
void ao_start(struct ao *ao) void ao_start(struct ao *ao)
{ {
struct buffer_state *p = ao->buffer_state; struct buffer_state *p = ao->buffer_state;
bool do_start = false;
pthread_mutex_lock(&p->lock); pthread_mutex_lock(&p->lock);
@ -334,11 +335,15 @@ void ao_start(struct ao *ao)
if (!ao->driver->write && !p->streaming) { if (!ao->driver->write && !p->streaming) {
p->streaming = true; p->streaming = true;
ao->driver->start(ao); do_start = true;
} }
pthread_mutex_unlock(&p->lock); pthread_mutex_unlock(&p->lock);
// Pull AOs might call ao_read_data() so do this outside the lock.
if (do_start)
ao->driver->start(ao);
ao_wakeup_playthread(ao); ao_wakeup_playthread(ao);
} }
@ -346,7 +351,7 @@ void ao_set_paused(struct ao *ao, bool paused)
{ {
struct buffer_state *p = ao->buffer_state; struct buffer_state *p = ao->buffer_state;
bool wakeup = false; bool wakeup = false;
bool do_reset = false; bool do_reset = false, do_start = false;
pthread_mutex_lock(&p->lock); pthread_mutex_lock(&p->lock);
@ -376,7 +381,7 @@ void ao_set_paused(struct ao *ao, bool paused)
p->hw_paused = false; p->hw_paused = false;
} else { } else {
if (!p->streaming) if (!p->streaming)
ao->driver->start(ao); do_start = true;
p->streaming = true; p->streaming = true;
} }
wakeup = true; wakeup = true;
@ -387,6 +392,8 @@ void ao_set_paused(struct ao *ao, bool paused)
if (do_reset) if (do_reset)
ao->driver->reset(ao); ao->driver->reset(ao);
if (do_start)
ao->driver->start(ao);
if (wakeup) if (wakeup)
ao_wakeup_playthread(ao); ao_wakeup_playthread(ao);