From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Sat, 26 Feb 2022 08:33:19 +0000 (+0000) Subject: Add a special-purpose flush routine called sub_flush. It doesn't close the device... X-Git-Tag: 4.1-rc1~24^2~278 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=70ef99e924c6e51c5b468b46eb93d52ffded980f;p=thirdparty%2Fshairport-sync.git Add a special-purpose flush routine called sub_flush. It doesn't close the device ever. --- diff --git a/audio_alsa.c b/audio_alsa.c index 88a4bb0c..d971ca2e 100644 --- a/audio_alsa.c +++ b/audio_alsa.c @@ -1834,6 +1834,24 @@ int do_close() { return derr; } +int sub_flush() { + if (alsa_backend_state == abm_disconnected) + debug(1, "alsa: do_flush() -- closing the output device when it is already " + "disconnected"); + int derr = 0; + if (alsa_handle) { + debug(2,"alsa: do_flush() -- flushing the output device"); + frames_sent_break_occurred = 1; + if ((derr = snd_pcm_drop(alsa_handle))) + debug(1, "Error %d (\"%s\") dropping output device.", derr, snd_strerror(derr)); + if ((derr = snd_pcm_prepare(alsa_handle))) + debug(1, "Error %d (\"%s\") preparing output device after flush.", derr, snd_strerror(derr)); + } else { + debug(1, "alsa: do_flush() -- output device already closed."); + } + return derr; +} + int play(void *buf, int samples) { // play() will change the state of the alsa_backend_mode to abm_playing @@ -1896,18 +1914,9 @@ int prepare(void) { static void flush(void) { // debug(2,"audio_alsa flush called."); pthread_cleanup_debug_mutex_lock(&alsa_mutex, 10000, 1); - // mute_requested_internally = 1; // request a mute for backend's reasons - // debug(2, "flush() set_mute_state"); - // set_mute_state(); - // do_mute(1); // mute for backend's own reasons if (alsa_backend_state != abm_disconnected) { // must be playing or connected... - if (config.keep_dac_busy != 0) { - debug(2, "alsa: flush() -- alsa_backend_state => abm_connected."); - alsa_backend_state = abm_connected; - } else { - debug(2, "alsa: flush() -- closing the output device"); - do_close(); // will change the state to disconnected - debug(2, "alsa: flush() -- alsa_backend_state => abm_disconnected."); + if (config.keep_dac_busy == 0) { + sub_flush(); } } else debug(3, "alsa: flush() -- called on a disconnected alsa backend");