From c1db4630e61abd4367e07c6a6658601aa2047f66 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 20 Sep 2020 14:45:45 +0200 Subject: audio: move start() calls outside of lock Pull based AOs might want to call ao_read_data() inside start(). This fixes ao_opensles deadlocking. --- audio/out/buffer.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/audio/out/buffer.c b/audio/out/buffer.c index 07545a1bca..f20d79ab08 100644 --- a/audio/out/buffer.c +++ b/audio/out/buffer.c @@ -327,6 +327,7 @@ void ao_reset(struct ao *ao) void ao_start(struct ao *ao) { struct buffer_state *p = ao->buffer_state; + bool do_start = false; pthread_mutex_lock(&p->lock); @@ -334,11 +335,15 @@ void ao_start(struct ao *ao) if (!ao->driver->write && !p->streaming) { p->streaming = true; - ao->driver->start(ao); + do_start = true; } 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); } @@ -346,7 +351,7 @@ void ao_set_paused(struct ao *ao, bool paused) { struct buffer_state *p = ao->buffer_state; bool wakeup = false; - bool do_reset = false; + bool do_reset = false, do_start = false; pthread_mutex_lock(&p->lock); @@ -376,7 +381,7 @@ void ao_set_paused(struct ao *ao, bool paused) p->hw_paused = false; } else { if (!p->streaming) - ao->driver->start(ao); + do_start = true; p->streaming = true; } wakeup = true; @@ -387,6 +392,8 @@ void ao_set_paused(struct ao *ao, bool paused) if (do_reset) ao->driver->reset(ao); + if (do_start) + ao->driver->start(ao); if (wakeup) ao_wakeup_playthread(ao); -- cgit v1.2.3