From 7e95d9f9c02d3cf6d9b4769c7880b4ac3c1934e8 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 14 Sep 2015 04:15:02 -0700 Subject: [PATCH] PulseAudio: fix soundio_outstream_pause triggering assertion when called from within write_callback. closes #24 --- src/pulseaudio.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/pulseaudio.cpp b/src/pulseaudio.cpp index 6561014..f9511ae 100644 --- a/src/pulseaudio.cpp +++ b/src/pulseaudio.cpp @@ -800,7 +800,9 @@ static int outstream_pause_pa(SoundIoPrivate *si, SoundIoOutStreamPrivate *os, b SoundIoOutStreamPulseAudio *ospa = &os->backend_data.pulseaudio; SoundIoPulseAudio *sipa = &si->backend_data.pulseaudio; - pa_threaded_mainloop_lock(sipa->main_loop); + if (!pa_threaded_mainloop_in_thread(sipa->main_loop)) { + pa_threaded_mainloop_lock(sipa->main_loop); + } if (pause != pa_stream_is_corked(ospa->stream)) { pa_operation *op = pa_stream_cork(ospa->stream, pause, NULL, NULL); @@ -811,7 +813,9 @@ static int outstream_pause_pa(SoundIoPrivate *si, SoundIoOutStreamPrivate *os, b pa_operation_unref(op); } - pa_threaded_mainloop_unlock(sipa->main_loop); + if (!pa_threaded_mainloop_in_thread(sipa->main_loop)) { + pa_threaded_mainloop_unlock(sipa->main_loop); + } return 0; } @@ -1026,7 +1030,9 @@ static int instream_pause_pa(SoundIoPrivate *si, SoundIoInStreamPrivate *is, boo SoundIoInStreamPulseAudio *ispa = &is->backend_data.pulseaudio; SoundIoPulseAudio *sipa = &si->backend_data.pulseaudio; - pa_threaded_mainloop_lock(sipa->main_loop); + if (!pa_threaded_mainloop_in_thread(sipa->main_loop)) { + pa_threaded_mainloop_lock(sipa->main_loop); + } if (pause != pa_stream_is_corked(ispa->stream)) { pa_operation *op = pa_stream_cork(ispa->stream, pause, NULL, NULL); @@ -1035,7 +1041,9 @@ static int instream_pause_pa(SoundIoPrivate *si, SoundIoInStreamPrivate *is, boo pa_operation_unref(op); } - pa_threaded_mainloop_unlock(sipa->main_loop); + if (!pa_threaded_mainloop_in_thread(sipa->main_loop)) { + pa_threaded_mainloop_unlock(sipa->main_loop); + } return 0; }