From: Mike Brady Date: Wed, 17 May 2017 16:29:18 +0000 (+0100) Subject: Use lock and unlock to improve stability, ahem. X-Git-Tag: 3.1d16~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=66f13c46f9ac0e86bb8d1700ff2b1bdca501e930;p=thirdparty%2Fshairport-sync.git Use lock and unlock to improve stability, ahem. --- diff --git a/audio_pa.c b/audio_pa.c index f243244a..3e26da3c 100644 --- a/audio_pa.c +++ b/audio_pa.c @@ -156,7 +156,10 @@ static void play(short buf[], int samples) { } if ((audio_occupancy >= 11025 * 2 * 2) && (pa_stream_is_corked(stream))) { debug(1,"Uncorked"); + pa_threaded_mainloop_lock(mainloop); pa_stream_cork(stream, 0, stream_success_cb, mainloop); + pa_threaded_mainloop_unlock(mainloop); + } } @@ -165,7 +168,9 @@ int pa_delay(long *the_delay) { int reply = -ENODEV; pa_usec_t latency; int negative; + pa_threaded_mainloop_lock(mainloop); int gl = pa_stream_get_latency(stream, &latency, &negative); + pa_threaded_mainloop_unlock(mainloop); if (gl == PA_ERR_NODATA) { debug(1, "No latency data yet."); reply = -ENODEV; @@ -182,11 +187,13 @@ int pa_delay(long *the_delay) { void flush(void) { // Cork the stream so it will stop playing + pa_threaded_mainloop_lock(mainloop); if (pa_stream_is_corked(stream)==0) { debug(1,"Flush for flush."); pa_stream_flush(stream, stream_success_cb, NULL); // pa_stream_cork(stream, 1, stream_success_cb, mainloop); } + pa_threaded_mainloop_unlock(mainloop); audio_toq = audio_eoq = audio_lmb; audio_umb = audio_lmb + audio_size; audio_occupancy = 0; @@ -194,11 +201,13 @@ void flush(void) { static void stop(void) { // Cork the stream so it will stop playing + pa_threaded_mainloop_lock(mainloop); if (pa_stream_is_corked(stream)==0) { debug(1,"Flush and cork for stop."); pa_stream_flush(stream, stream_success_cb, NULL); pa_stream_cork(stream, 1, stream_success_cb, mainloop); } + pa_threaded_mainloop_unlock(mainloop); audio_toq = audio_eoq = audio_lmb; audio_umb = audio_lmb + audio_size; audio_occupancy = 0; @@ -279,7 +288,7 @@ void stream_write_cb(pa_stream *stream, size_t requested_bytes, void *userdata) } // bytes we can transfer will never be greater than the bytes available - + pa_stream_begin_write(stream, (void **)&buffer, &bytes_we_can_transfer); if (bytes_we_can_transfer <= (audio_umb - audio_toq)) { // the bytes are all in a row in the audo buffer