From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Fri, 22 Jul 2022 14:52:16 +0000 (+0100) Subject: If the default device is inaccessible with EHOSTDOWN, try hw:0 instead. Works for... X-Git-Tag: 4.1-rc1~24^2~67 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=449e024c951e691ea5ed420d070de3288c8b837a;p=thirdparty%2Fshairport-sync.git If the default device is inaccessible with EHOSTDOWN, try hw:0 instead. Works for Fedora 36 Workstation. Might need to make it a bit smarter. --- diff --git a/audio_alsa.c b/audio_alsa.c index 9673da5f..4ee19bcc 100644 --- a/audio_alsa.c +++ b/audio_alsa.c @@ -131,7 +131,8 @@ yndk_type precision_delay_available_status = YNDK_DONT_KNOW; // initially, we don't know if the device can do precision delay snd_pcm_t *alsa_handle = NULL; -int alsa_handle_status = ENODEV; // if alsa_handle is NULL, this should say why with a unix error code +int alsa_handle_status = + ENODEV; // if alsa_handle is NULL, this should say why with a unix error code static snd_pcm_hw_params_t *alsa_params = NULL; static snd_pcm_sw_params_t *alsa_swparams = NULL; static snd_ctl_t *ctl = NULL; @@ -417,15 +418,27 @@ int actual_open_alsa_device(int do_auto_setup) { audio_alsa.delay = NULL; ret = snd_pcm_open(&alsa_handle, alsa_out_dev, SND_PCM_STREAM_PLAYBACK, 0); + // EHOSTDOWN seems to signify that it's a PipeWire pseudo device that can't be accessed by this + // user. So, try the first device ALSA device and log it. + if ((ret == -EHOSTDOWN) && (strcmp(alsa_out_dev, "default") == 0)) { + ret = snd_pcm_open(&alsa_handle, "hw:0", SND_PCM_STREAM_PLAYBACK, 0); + if ((ret == 0) || (ret == -EBUSY)) { + // being busy should be okay + inform("the default ALSA device is inaccessible -- \"hw:0\" used instead.", alsa_out_dev); + set_alsa_out_dev("hw:0"); + } + } if (ret == 0) { if (alsa_handle_status == -EBUSY) - warn("The output device \"%s\" is no longer busy and will be used by Shairport Sync.", alsa_out_dev); + warn("The output device \"%s\" is no longer busy and will be used by Shairport Sync.", + alsa_out_dev); alsa_handle_status = ret; // all cool } else { alsa_handle = NULL; // to be sure to be sure if (ret == -EBUSY) { if (alsa_handle_status != -EBUSY) - warn("The output device \"%s\" is busy and can't be used by Shairport Sync at present.", alsa_out_dev); + warn("The output device \"%s\" is busy and can't be used by Shairport Sync at present.", + alsa_out_dev); debug(2, "the alsa output_device \"%s\" is busy.", alsa_out_dev); } else if (ret == -ENOENT) { die("the alsa output_device \"%s\" can not be found.", alsa_out_dev);