don't hit an assert if a kernel driver reports invalid dB information, instead just warn the user

This commit is contained in:
Lennart Poettering 2008-10-01 04:15:05 +02:00
parent 5d18b62033
commit 3853070a21
2 changed files with 24 additions and 17 deletions

View file

@ -1474,14 +1474,15 @@ int pa__init(pa_module*m) {
pa_assert(u->mixer_elem); pa_assert(u->mixer_elem);
if (snd_mixer_selem_has_playback_volume(u->mixer_elem)) { if (snd_mixer_selem_has_playback_volume(u->mixer_elem)) {
pa_bool_t suitable = TRUE; pa_bool_t suitable = FALSE;
if (snd_mixer_selem_get_playback_volume_range(u->mixer_elem, &u->hw_volume_min, &u->hw_volume_max) < 0) { if (snd_mixer_selem_get_playback_volume_range(u->mixer_elem, &u->hw_volume_min, &u->hw_volume_max) < 0)
pa_log_info("Failed to get volume range. Falling back to software volume control."); pa_log_info("Failed to get volume range. Falling back to software volume control.");
suitable = FALSE; else if (u->hw_volume_min >= u->hw_volume_max)
} else { pa_log_warn("Your kernel driver is broken: it reports a volume range from %li to %li which makes no sense.", u->hw_volume_min, u->hw_volume_max);
else {
pa_log_info("Volume ranges from %li to %li.", u->hw_volume_min, u->hw_volume_max); pa_log_info("Volume ranges from %li to %li.", u->hw_volume_min, u->hw_volume_max);
pa_assert(u->hw_volume_min < u->hw_volume_max); suitable = TRUE;
} }
if (snd_mixer_selem_get_playback_dB_range(u->mixer_elem, &u->hw_dB_min, &u->hw_dB_max) < 0) if (snd_mixer_selem_get_playback_dB_range(u->mixer_elem, &u->hw_dB_min, &u->hw_dB_max) < 0)
@ -1492,10 +1493,13 @@ int pa__init(pa_module*m) {
VALGRIND_MAKE_MEM_DEFINED(&u->hw_dB_max, sizeof(u->hw_dB_max)); VALGRIND_MAKE_MEM_DEFINED(&u->hw_dB_max, sizeof(u->hw_dB_max));
#endif #endif
if (u->hw_dB_min >= u->hw_dB_max)
pa_log_warn("Your kernel driver is broken: it reports a volume range from %0.2f dB to %0.2f dB which makes no sense.", (double) u->hw_dB_min/100.0, (double) u->hw_dB_max/100.0);
else {
pa_log_info("Volume ranges from %0.2f dB to %0.2f dB.", (double) u->hw_dB_min/100.0, (double) u->hw_dB_max/100.0); pa_log_info("Volume ranges from %0.2f dB to %0.2f dB.", (double) u->hw_dB_min/100.0, (double) u->hw_dB_max/100.0);
pa_assert(u->hw_dB_min < u->hw_dB_max);
u->hw_dB_supported = TRUE; u->hw_dB_supported = TRUE;
} }
}
if (suitable && if (suitable &&
!u->hw_dB_supported && !u->hw_dB_supported &&

View file

@ -1295,14 +1295,15 @@ int pa__init(pa_module*m) {
pa_assert(u->mixer_elem); pa_assert(u->mixer_elem);
if (snd_mixer_selem_has_capture_volume(u->mixer_elem)) { if (snd_mixer_selem_has_capture_volume(u->mixer_elem)) {
pa_bool_t suitable = TRUE; pa_bool_t suitable = FALSE;
if (snd_mixer_selem_get_capture_volume_range(u->mixer_elem, &u->hw_volume_min, &u->hw_volume_max) < 0) { if (snd_mixer_selem_get_capture_volume_range(u->mixer_elem, &u->hw_volume_min, &u->hw_volume_max) < 0)
pa_log_info("Failed to get volume range. Falling back to software volume control."); pa_log_info("Failed to get volume range. Falling back to software volume control.");
suitable = FALSE; else if (u->hw_volume_min >= u->hw_volume_max)
} else { pa_log_warn("Your kernel driver is broken: it reports a volume range from %li to %li which makes no sense.", u->hw_volume_min, u->hw_volume_max);
else {
pa_log_info("Volume ranges from %li to %li.", u->hw_volume_min, u->hw_volume_max); pa_log_info("Volume ranges from %li to %li.", u->hw_volume_min, u->hw_volume_max);
pa_assert(u->hw_volume_min < u->hw_volume_max); suitable = TRUE;
} }
if (snd_mixer_selem_get_capture_dB_range(u->mixer_elem, &u->hw_dB_min, &u->hw_dB_max) < 0) if (snd_mixer_selem_get_capture_dB_range(u->mixer_elem, &u->hw_dB_min, &u->hw_dB_max) < 0)
@ -1313,10 +1314,13 @@ int pa__init(pa_module*m) {
VALGRIND_MAKE_MEM_DEFINED(&u->hw_dB_max, sizeof(u->hw_dB_max)); VALGRIND_MAKE_MEM_DEFINED(&u->hw_dB_max, sizeof(u->hw_dB_max));
#endif #endif
if (u->hw_dB_min >= u->hw_dB_max)
pa_log_warn("Your kernel driver is broken: it reports a volume range from %0.2f dB to %0.2f dB which makes no sense.", (double) u->hw_dB_min/100.0, (double) u->hw_dB_max/100.0);
else {
pa_log_info("Volume ranges from %0.2f dB to %0.2f dB.", (double) u->hw_dB_min/100.0, (double) u->hw_dB_max/100.0); pa_log_info("Volume ranges from %0.2f dB to %0.2f dB.", (double) u->hw_dB_min/100.0, (double) u->hw_dB_max/100.0);
pa_assert(u->hw_dB_min < u->hw_dB_max);
u->hw_dB_supported = TRUE; u->hw_dB_supported = TRUE;
} }
}
if (suitable && if (suitable &&
!u->hw_dB_supported && !u->hw_dB_supported &&
@ -1326,7 +1330,6 @@ int pa__init(pa_module*m) {
suitable = FALSE; suitable = FALSE;
} }
if (suitable) { if (suitable) {
u->mixer_seperate_channels = pa_alsa_calc_mixer_map(u->mixer_elem, &map, u->mixer_map, FALSE) >= 0; u->mixer_seperate_channels = pa_alsa_calc_mixer_map(u->mixer_elem, &map, u->mixer_map, FALSE) >= 0;