From: Mike Brady Date: Thu, 31 Jan 2019 13:35:11 +0000 (+0000) Subject: Make mute work only if not diconnected. Clewan up some debug messages. X-Git-Tag: 3.3RC0~66^2~29 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=60487c86b1ca8409faae05037dcb9818ee7d1cf0;p=thirdparty%2Fshairport-sync.git Make mute work only if not diconnected. Clewan up some debug messages. --- diff --git a/audio_alsa.c b/audio_alsa.c index 9be90890..a9f89cfe 100644 --- a/audio_alsa.c +++ b/audio_alsa.c @@ -521,17 +521,17 @@ int actual_open_alsa_device(void) { debug(log_level, "PCM handle name = '%s'", snd_pcm_name(alsa_handle)); - // ret = snd_pcm_hw_params_any(alsa_handle, alsa_params); - // if (ret < 0) { - // die("audio_alsa: Cannpot get configuration for + // ret = snd_pcm_hw_params_any(alsa_handle, alsa_params); + // if (ret < 0) { + // die("audio_alsa: Cannpot get configuration for // device //\"%s\": // no // configurations //" - // "available", - // alsa_out_dev); - // } + // "available", + // alsa_out_dev); + // } debug(log_level, "alsa device parameters:"); @@ -649,7 +649,6 @@ int open_alsa_device(void) { } int do_alsa_device_init_if_needed() { - debug(1, "do_alsa_device_init_if_needed()"); int response = 0; // do any alsa device initialisation (general case) if needed // at present, this is only needed if a hardware mixer is being used @@ -657,6 +656,7 @@ int do_alsa_device_init_if_needed() { if (alsa_device_initialised == 0) { alsa_device_initialised = 1; if (hardware_mixer) { + debug(2, "alsa: hardware mixer init"); int oldState; pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldState); // make this un-cancellable @@ -1052,38 +1052,37 @@ static void deinit(void) { } int set_mute_state() { - debug(1, "set_mute_state"); - int response = 1; // some problem expected, e.g. no mixer or not allowed to use it - if (config.alsa_use_hardware_mute == 1) { + int response = 1; // some problem expected, e.g. no mixer or not allowed to use it or disconnected + if ((alsa_backend_state != abm_disconnected) && (config.alsa_use_hardware_mute == 1) && (open_mixer() == 1)) { + response = 0; // okay if actually using the mute facility + debug(1, "set_mute_state"); int mute = 0; if ((mute_requested_externally != 0) || (mute_requested_internally != 0)) - mute = 1; - if (open_mixer() == 1) { - response = 0; // okay if actually using the mute facility - if (mute == 1) { - debug(1, "Hardware mute switched on"); - if (snd_mixer_selem_has_playback_switch(alsa_mix_elem)) - snd_mixer_selem_set_playback_switch_all(alsa_mix_elem, 0); - else { - volume_based_mute_is_active = 1; - do_snd_mixer_selem_set_playback_dB_all(alsa_mix_elem, alsa_mix_mute); - } - } else { - debug(1, "Hardware mute switched off"); - if (snd_mixer_selem_has_playback_switch(alsa_mix_elem)) - snd_mixer_selem_set_playback_switch_all(alsa_mix_elem, 1); - else { - volume_based_mute_is_active = 0; - do_snd_mixer_selem_set_playback_dB_all(alsa_mix_elem, set_volume); - } + mute = 1; + if (mute == 1) { + debug(1, "Hardware mute switched on"); + if (snd_mixer_selem_has_playback_switch(alsa_mix_elem)) + snd_mixer_selem_set_playback_switch_all(alsa_mix_elem, 0); + else { + volume_based_mute_is_active = 1; + do_snd_mixer_selem_set_playback_dB_all(alsa_mix_elem, alsa_mix_mute); + } + } else { + debug(1, "Hardware mute switched off"); + if (snd_mixer_selem_has_playback_switch(alsa_mix_elem)) + snd_mixer_selem_set_playback_switch_all(alsa_mix_elem, 1); + else { + volume_based_mute_is_active = 0; + do_snd_mixer_selem_set_playback_dB_all(alsa_mix_elem, set_volume); } - close_mixer(); } + close_mixer(); } return response; } + static void start(int i_sample_rate, int i_sample_format) { - debug(1, "audio_alsa start called."); + debug(3, "audio_alsa start called."); if (i_sample_rate == 0) desired_sample_rate = 44100; // default else @@ -1100,7 +1099,7 @@ static void start(int i_sample_rate, int i_sample_format) { stall_monitor_start_time = 0; stall_monitor_frame_count = 0; if (alsa_device_initialised == 0) { - debug(1, "alsa: start() calling do_alsa_device_init_if_needed."); + debug(2, "alsa: start() calling do_alsa_device_init_if_needed."); do_alsa_device_init_if_needed(); } } @@ -1326,7 +1325,7 @@ int do_open() { if (audio_alsa.volume) do_volume(set_volume); if (audio_alsa.mute) { - debug(1, "do_open() set_mute_state"); + debug(2, "do_open() set_mute_state"); set_mute_state(); // the mute_requested_externally flag will have been // set accordingly // do_mute(0); // complete unmute @@ -1387,7 +1386,7 @@ int play(void *buf, int samples) { alsa_backend_state = abm_playing; mute_requested_internally = 0; // stop requesting a mute for backend's own // reasons, which might have been a flush - debug(1, "play() set_mute_state"); + debug(2, "play() set_mute_state"); set_mute_state(); // try to action the request and return a status // do_mute(0); // unmute for backend's reason } @@ -1403,7 +1402,7 @@ 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(1, "flush() set_mute_state"); + 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... @@ -1499,9 +1498,8 @@ linear_volume; int mute(int mute_state_requested) { // these would be for external reasons, not // because of the // state of the backend. - debug(1, "alsa: mute(%d)", mute_state_requested); mute_requested_externally = mute_state_requested; // request a mute for external reasons - debug(1, "mute(%d) set_mute_state", mute_state_requested); + debug(2, "mute(%d) set_mute_state", mute_state_requested); return set_mute_state(); } /* @@ -1514,7 +1512,7 @@ void alsa_buffer_monitor_thread_cleanup_function(__attribute__((unused)) void void *alsa_buffer_monitor_thread_code(__attribute__((unused)) void *arg) { while (1) { if ((config.keep_dac_busy != 0) && (alsa_device_initialised == 0)) { - debug(1, "alsa: alsa_buffer_monitor_thread_code() calling " + debug(2, "alsa: alsa_buffer_monitor_thread_code() calling " "do_alsa_device_init_if_needed."); do_alsa_device_init_if_needed(); } diff --git a/player.c b/player.c index eb2be192..fa2e2c3c 100644 --- a/player.c +++ b/player.c @@ -2542,7 +2542,7 @@ void *player_thread_func(void *arg) { } void player_volume_without_notification(double airplay_volume, rtsp_conn_info *conn) { - debug(1, "player_volume_without_notification %f", airplay_volume); + debug(2, "player_volume_without_notification %f", airplay_volume); // first, see if we are hw only, sw only, both with hw attenuation on the top or both with sw // attenuation on top @@ -2614,10 +2614,10 @@ void player_volume_without_notification(double airplay_volume, rtsp_conn_info *c if (airplay_volume == -144.0) { if ((config.output->mute) && (config.output->mute(1) == 0)) - debug(1, "player: hardware mute is enabled."); + debug(2, "player_volume_without_notification: volume mode is %d, airplay_volume is %f, hardware mute is enabled.", volume_mode, airplay_volume); else { conn->software_mute_enabled = 1; - debug(1, "player: software mute is enabled."); + debug(2, "player_volume_without_notification: volume mode is %d, airplay_volume is %f, software mute is enabled.", volume_mode, airplay_volume); } } else { @@ -2639,7 +2639,7 @@ void player_volume_without_notification(double airplay_volume, rtsp_conn_info *c min_db = 0; break; default: - debug(1, "error in pv -- not in a volume mode"); + debug(1, "player_volume_without_notification: error: not in a volume mode"); break; } double scaled_attenuation = 0.0; @@ -2649,7 +2649,7 @@ void player_volume_without_notification(double airplay_volume, rtsp_conn_info *c scaled_attenuation = flat_vol2attn(airplay_volume, max_db, min_db); // no cancellation points else - debug(1, "Unrecognised volume control profile"); + debug(1, "player_volume_without_notification: unrecognised volume control profile"); // so here we have the scaled attenuation. If it's for hw or sw only, it's straightforward. double hardware_attenuation = 0.0; @@ -2692,7 +2692,7 @@ void player_volume_without_notification(double airplay_volume, rtsp_conn_info *c } break; default: - debug(1, "error in pv -- not in a volume mode"); + debug(1, "player_volume_without_notification: error: not in a volume mode"); break; } @@ -2737,9 +2737,9 @@ void player_volume_without_notification(double airplay_volume, rtsp_conn_info *c config.output->mute(0); conn->software_mute_enabled = 0; - debug(1, "pv: volume mode is %d, software_attenuation: %f, hardware_attenuation: %f, muting " + debug(2, "player_volume_without_notification: volume mode is %d, airplay volume is %f, software_attenuation: %f, hardware_attenuation: %f, muting " "is disabled.", - volume_mode, software_attenuation, hardware_attenuation); + volume_mode, airplay_volume, software_attenuation, hardware_attenuation); } } config.airplay_volume = airplay_volume;