output/alsa: probe all sample formats in a loop

More code simplification.  Probe all formats, no matter which input
format.
This commit is contained in:
Max Kellermann 2010-01-16 18:08:13 +01:00
parent 96546c1a8a
commit da47afe7d1

View File

@ -259,6 +259,24 @@ alsa_output_try_reverse(snd_pcm_t *pcm, snd_pcm_hw_params_t *hwparams,
return err; return err;
} }
/**
* Attempts to configure the specified sample format, and tries the
* reversed host byte order if was not supported.
*/
static int
alsa_output_try_format_both(snd_pcm_t *pcm, snd_pcm_hw_params_t *hwparams,
struct audio_format *audio_format,
enum sample_format sample_format)
{
int err = alsa_output_try_format(pcm, hwparams, audio_format,
sample_format);
if (err == -EINVAL)
err = alsa_output_try_reverse(pcm, hwparams, audio_format,
sample_format);
return err;
}
/** /**
* Configure a sample format, and probe other formats if that fails. * Configure a sample format, and probe other formats if that fails.
*/ */
@ -266,49 +284,29 @@ static int
alsa_output_setup_format(snd_pcm_t *pcm, snd_pcm_hw_params_t *hwparams, alsa_output_setup_format(snd_pcm_t *pcm, snd_pcm_hw_params_t *hwparams,
struct audio_format *audio_format) struct audio_format *audio_format)
{ {
snd_pcm_format_t bitformat = get_bitformat(audio_format->format); /* try the input format first */
if (bitformat == SND_PCM_FORMAT_UNKNOWN) {
/* sample format is not supported by this plugin -
fall back to 16 bit samples */
audio_format->format = SAMPLE_FORMAT_S16; int err = alsa_output_try_format_both(pcm, hwparams, audio_format,
bitformat = SND_PCM_FORMAT_S16; audio_format->format);
}
int err = snd_pcm_hw_params_set_format(pcm, hwparams, bitformat);
if (err != -EINVAL) if (err != -EINVAL)
return err; return err;
err = alsa_output_try_reverse(pcm, hwparams, audio_format, /* if unsupported by the hardware, try other formats */
audio_format->format);
if (err != -EINVAL)
return err;
if (audio_format->format == SAMPLE_FORMAT_S24_P32 || static const enum sample_format probe_formats[] = {
audio_format->format == SAMPLE_FORMAT_S16) { SAMPLE_FORMAT_S24_P32,
/* fall back to 32 bit, let pcm_convert.c do the conversion */ SAMPLE_FORMAT_S32,
SAMPLE_FORMAT_S16,
SAMPLE_FORMAT_S8,
SAMPLE_FORMAT_UNDEFINED,
};
err = alsa_output_try_format(pcm, hwparams, audio_format, for (unsigned i = 0; probe_formats[i] != SAMPLE_FORMAT_UNDEFINED; ++i) {
SAMPLE_FORMAT_S24_P32); if (probe_formats[i] == audio_format->format)
if (err != -EINVAL) continue;
return err;
err = alsa_output_try_reverse(pcm, hwparams, audio_format, err = alsa_output_try_format_both(pcm, hwparams, audio_format,
SAMPLE_FORMAT_S24_P32); probe_formats[i]);
if (err != -EINVAL)
return err;
}
if (audio_format->format != SAMPLE_FORMAT_S16) {
/* fall back to 16 bit, let pcm_convert.c do the conversion */
err = alsa_output_try_format(pcm, hwparams, audio_format,
SAMPLE_FORMAT_S16);
if (err != -EINVAL)
return err;
err = alsa_output_try_reverse(pcm, hwparams, audio_format,
SAMPLE_FORMAT_S16);
if (err != -EINVAL) if (err != -EINVAL)
return err; return err;
} }