alsa: Try to support non-standard rates in alsa-sink/source

We inadvertantly stopped supporting non-standard rates when the
passthrough work was done. This makes sure that if no standard rates are
supported, we try to fallback to whatever ALSA gives us.
This commit is contained in:
Arun Raghavan 2012-12-03 11:27:27 +05:30
parent 5a791f8a16
commit 2a48c2d66f
4 changed files with 22 additions and 12 deletions

View file

@ -2202,7 +2202,7 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca
if (is_iec958(u) || is_hdmi(u))
set_formats = TRUE;
u->rates = pa_alsa_get_supported_rates(u->pcm_handle);
u->rates = pa_alsa_get_supported_rates(u->pcm_handle, ss.rate);
if (!u->rates) {
pa_log_error("Failed to find any supported sample rates.");
goto fail;

View file

@ -1922,7 +1922,7 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p
pa_log_info("Disabling latency range changes on overrun");
}
u->rates = pa_alsa_get_supported_rates(u->pcm_handle);
u->rates = pa_alsa_get_supported_rates(u->pcm_handle, ss.rate);
if (!u->rates) {
pa_log_error("Failed to find any supported sample rates.");
goto fail;

View file

@ -1326,7 +1326,7 @@ char *pa_alsa_get_reserve_name(const char *device) {
return pa_sprintf_malloc("Audio%i", i);
}
unsigned int *pa_alsa_get_supported_rates(snd_pcm_t *pcm) {
unsigned int *pa_alsa_get_supported_rates(snd_pcm_t *pcm, unsigned int fallback_rate) {
static unsigned int all_rates[] = { 8000, 11025, 12000,
16000, 22050, 24000,
32000, 44100, 48000,
@ -1352,9 +1352,7 @@ unsigned int *pa_alsa_get_supported_rates(snd_pcm_t *pcm) {
}
}
if (n == 0)
return NULL;
if (n > 0) {
rates = pa_xnew(unsigned int, n + 1);
for (i = 0, j = 0; i < PA_ELEMENTSOF(all_rates); i++) {
@ -1363,6 +1361,18 @@ unsigned int *pa_alsa_get_supported_rates(snd_pcm_t *pcm) {
}
rates[j] = 0;
} else {
rates = pa_xnew(unsigned int, 2);
rates[0] = fallback_rate;
if ((ret = snd_pcm_hw_params_set_rate_near(pcm, hwparams, &rates[0], NULL)) < 0) {
pa_log_debug("snd_pcm_hw_params_set_rate_near() failed: %s", pa_alsa_strerror(ret));
pa_xfree(rates);
return NULL;
}
rates[1] = 0;
}
return rates;
}

View file

@ -133,7 +133,7 @@ char *pa_alsa_get_driver_name_by_pcm(snd_pcm_t *pcm);
char *pa_alsa_get_reserve_name(const char *device);
unsigned int *pa_alsa_get_supported_rates(snd_pcm_t *pcm);
unsigned int *pa_alsa_get_supported_rates(snd_pcm_t *pcm, unsigned int fallback_rate);
pa_bool_t pa_alsa_pcm_is_hw(snd_pcm_t *pcm);
pa_bool_t pa_alsa_pcm_is_modem(snd_pcm_t *pcm);