alsa: Prevent pitch element probe from stepping on bind ctls

Since they're both using the same device, we want to make sure one
doesn't cause the other to be closed on failure.
This commit is contained in:
Arun Raghavan 2023-11-09 09:24:09 -05:00
parent caf7eb33e4
commit 3bbd1e66d2

View file

@ -868,16 +868,20 @@ static int probe_pitch_ctl(struct state *state, const char* device_name)
state->stream == SND_PCM_STREAM_CAPTURE ?
"Capture Pitch 1000000" :
"Playback Pitch 1000000";
bool opened = false;
int err;
snd_lib_error_set_handler(silence_error_handler);
err = snd_ctl_open(&state->ctl, device_name, SND_CTL_NONBLOCK);
if (err < 0) {
spa_log_info(state->log, "%s could not find ctl device: %s",
device_name, snd_strerror(err));
state->ctl = NULL;
goto error;
if (!state->ctl) {
err = snd_ctl_open(&state->ctl, device_name, SND_CTL_NONBLOCK);
if (err < 0) {
spa_log_info(state->log, "%s could not find ctl device: %s",
device_name, snd_strerror(err));
state->ctl = NULL;
goto error;
}
opened = true;
}
snd_ctl_elem_id_alloca(&id);
@ -895,9 +899,11 @@ static int probe_pitch_ctl(struct state *state, const char* device_name)
snd_ctl_elem_value_free(state->pitch_elem);
state->pitch_elem = NULL;
snd_ctl_close(state->ctl);
state->ctl = NULL;
goto error;
if (opened) {
snd_ctl_close(state->ctl);
state->ctl = NULL;
goto error;
}
}
snd_ctl_elem_value_set_integer(state->pitch_elem, 0, 1000000);