alsa: handle driver bugs better

Use the NEAREST flag when setting a format. This only works for raw
formats and will update the format with the nearest accepted rate
or channels. We can then query the real configured format and use that
for the converter.

This makes things work when a driver tells us it can do 44100Hz but then
refuses and changes the rate to 48000.

See #2197, #2457, #2455, rhbz#2096193
This commit is contained in:
Wim Taymans 2022-06-23 10:20:49 +02:00
parent ecc0eecf0f
commit 0f62d3442c
4 changed files with 35 additions and 12 deletions

View file

@ -1409,7 +1409,10 @@ int spa_alsa_set_format(struct state *state, struct spa_audio_info *fmt, uint32_
state->props.device, rchannels, val);
if (!SPA_FLAG_IS_SET(flags, SPA_NODE_PARAM_FLAG_NEAREST))
return -EINVAL;
if (fmt->media_subtype != SPA_MEDIA_SUBTYPE_raw)
return -EINVAL;
rchannels = val;
fmt->info.raw.channels = rchannels;
match = false;
}
@ -1429,7 +1432,10 @@ int spa_alsa_set_format(struct state *state, struct spa_audio_info *fmt, uint32_
state->props.device, rrate, val);
if (!SPA_FLAG_IS_SET(flags, SPA_NODE_PARAM_FLAG_NEAREST))
return -EINVAL;
if (fmt->media_subtype != SPA_MEDIA_SUBTYPE_raw)
return -EINVAL;
rrate = val;
fmt->info.raw.rate = rrate;
match = false;
}