mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-12-16 08:56:45 -05:00
alsa: improve rate selection
Make sure we don't select an invalid rate when the default is set or when the card is already opened in some unsupported rate. See #1975
This commit is contained in:
parent
8415fa525f
commit
d8c867b515
1 changed files with 15 additions and 14 deletions
|
|
@ -734,31 +734,32 @@ static int add_rate(struct state *state, uint32_t scale, bool all, uint32_t inde
|
||||||
CHECK(snd_pcm_hw_params_get_rate_min(params, &min, &dir), "get_rate_min");
|
CHECK(snd_pcm_hw_params_get_rate_min(params, &min, &dir), "get_rate_min");
|
||||||
CHECK(snd_pcm_hw_params_get_rate_max(params, &max, &dir), "get_rate_max");
|
CHECK(snd_pcm_hw_params_get_rate_max(params, &max, &dir), "get_rate_max");
|
||||||
|
|
||||||
rate = state->default_rate;
|
|
||||||
if (!state->multi_rate && state->card->format_ref > 0)
|
if (!state->multi_rate && state->card->format_ref > 0)
|
||||||
rate = state->card->rate;
|
rate = state->card->rate;
|
||||||
|
else
|
||||||
|
rate = state->default_rate;
|
||||||
|
|
||||||
if (rate != 0 && !all) {
|
if (rate < min || rate > max)
|
||||||
if (min < rate)
|
rate = 0;
|
||||||
min = rate;
|
|
||||||
if (max > rate)
|
if (rate != 0 && !all)
|
||||||
max = rate;
|
min = max = rate;
|
||||||
}
|
|
||||||
|
if (rate == 0)
|
||||||
|
rate = state->position ? state->position->clock.rate.denom : DEFAULT_RATE;
|
||||||
|
|
||||||
|
rate = SPA_CLAMP(rate, min, max);
|
||||||
|
|
||||||
spa_pod_builder_prop(b, SPA_FORMAT_AUDIO_rate, 0);
|
spa_pod_builder_prop(b, SPA_FORMAT_AUDIO_rate, 0);
|
||||||
|
|
||||||
spa_pod_builder_push_choice(b, &f[0], SPA_CHOICE_None, 0);
|
spa_pod_builder_push_choice(b, &f[0], SPA_CHOICE_None, 0);
|
||||||
choice = (struct spa_pod_choice*)spa_pod_builder_frame(b, &f[0]);
|
choice = (struct spa_pod_choice*)spa_pod_builder_frame(b, &f[0]);
|
||||||
|
|
||||||
if (rate == 0)
|
|
||||||
rate = state->position ? state->position->clock.rate.denom : DEFAULT_RATE;
|
|
||||||
|
|
||||||
if (state->n_allowed_rates > 0) {
|
if (state->n_allowed_rates > 0) {
|
||||||
uint32_t i, v, last = 0, count = 0;
|
uint32_t i, v, last = 0, count = 0;
|
||||||
|
|
||||||
v = SPA_CLAMP(rate, min, max);
|
if (uint32_array_contains(state->allowed_rates, state->n_allowed_rates, rate)) {
|
||||||
if (uint32_array_contains(state->allowed_rates, state->n_allowed_rates, v)) {
|
spa_pod_builder_int(b, rate * scale);
|
||||||
spa_pod_builder_int(b, v * scale);
|
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
for (i = 0; i < state->n_allowed_rates; i++) {
|
for (i = 0; i < state->n_allowed_rates; i++) {
|
||||||
|
|
@ -775,7 +776,7 @@ static int add_rate(struct state *state, uint32_t scale, bool all, uint32_t inde
|
||||||
if (count > 1)
|
if (count > 1)
|
||||||
choice->body.type = SPA_CHOICE_Enum;
|
choice->body.type = SPA_CHOICE_Enum;
|
||||||
} else {
|
} else {
|
||||||
spa_pod_builder_int(b, SPA_CLAMP(rate, min, max) * scale);
|
spa_pod_builder_int(b, rate * scale);
|
||||||
|
|
||||||
if (min != max) {
|
if (min != max) {
|
||||||
spa_pod_builder_int(b, min * scale);
|
spa_pod_builder_int(b, min * scale);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue