alsa: use configured rate and channels when enumerating formats

When we have a rate or channels configured, set this in the hw_params
to restrict the enumeration of the remaining parameters. If we,
for example want 8 channels, some cards restrict the formats in that
case and we don't want to enumerate impossible combinations.

Fixes #782
This commit is contained in:
Wim Taymans 2021-02-23 17:17:14 +01:00
parent d54da879bf
commit d2fb6db21f

View file

@ -272,6 +272,7 @@ spa_alsa_enum_format(struct state *state, int seq, uint32_t start, uint32_t num,
size_t i, j;
int err, dir;
unsigned int min, max;
unsigned int rrate, rchannels;
uint8_t buffer[4096];
struct spa_pod_builder b = { 0 };
struct spa_pod_choice *choice;
@ -298,6 +299,25 @@ spa_alsa_enum_format(struct state *state, int seq, uint32_t start, uint32_t num,
snd_pcm_hw_params_alloca(&params);
CHECK(snd_pcm_hw_params_any(hndl, params), "Broken configuration: no configurations available");
CHECK(snd_pcm_hw_params_set_rate_resample(hndl, params, 0), "set_rate_resample");
if (state->default_channels != 0) {
rchannels = state->default_channels;
CHECK(snd_pcm_hw_params_set_channels_near(hndl, params, &rchannels), "set_channels");
if (state->default_channels != rchannels) {
spa_log_warn(state->log, NAME" %s: Channels doesn't match (requested %u, got %u)",
state->props.device, state->default_channels, rchannels);
}
}
if (state->default_rate != 0) {
rrate = state->default_rate;
CHECK(snd_pcm_hw_params_set_rate_near(hndl, params, &rrate, 0), "set_rate_near");
if (state->default_rate != rrate) {
spa_log_warn(state->log, NAME" %s: Rate doesn't match (requested %u, got %u)",
state->props.device, state->default_rate, rrate);
}
}
spa_pod_builder_push_object(&b, &f[0], SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat);
spa_pod_builder_add(&b,
SPA_FORMAT_mediaType, SPA_POD_Id(SPA_MEDIA_TYPE_audio),