alsa: only use default rate and channels when valid

Check the user provided rate and channels and only use them to limit the
rate and channels when they are valid.
This commit is contained in:
Wim Taymans 2025-05-08 18:16:53 +02:00
parent e7610de305
commit a66377cf42

View file

@ -1568,15 +1568,18 @@ static int add_channels(struct state *state, bool all, uint32_t index, uint32_t
spa_log_debug(state->log, "channels (%d %d) default:%d all:%d",
min, max, state->default_channels, all);
if (state->default_channels != 0 && !all) {
if (min < state->default_channels)
min = state->default_channels;
if (max > state->default_channels)
max = state->default_channels;
}
min = SPA_MIN(min, SPA_AUDIO_MAX_CHANNELS);
max = SPA_MIN(max, SPA_AUDIO_MAX_CHANNELS);
if (state->default_channels != 0 && !all) {
if (min > state->default_channels ||
max < state->default_channels)
spa_log_warn(state->log, "given audio.channels %d out of range:%d-%d",
state->default_channels, min, max);
else
min = max = state->default_channels;
}
spa_pod_builder_prop(b, SPA_FORMAT_AUDIO_channels, 0);
if (state->props.use_chmap && (maps = snd_pcm_query_chmaps(hndl)) != NULL) {
@ -1847,10 +1850,12 @@ static int enum_iec958_formats(struct state *state, uint32_t index, uint32_t *ne
spa_log_debug(state->log, "rate (%d %d)", rmin, rmax);
if (state->default_rate != 0) {
if (rmin < state->default_rate)
rmin = state->default_rate;
if (rmax > state->default_rate)
rmax = state->default_rate;
if (rmin > state->default_rate ||
rmax < state->default_rate)
spa_log_warn(state->log, "given audio.rate %d out of range:%d-%d",
state->default_rate, rmin, rmax);
else
rmin = rmax = state->default_rate;
}
spa_pod_builder_prop(b, SPA_FORMAT_AUDIO_iec958Codec, 0);