From c6a3b71a28bbe9e004c14545721851f999be7978 Mon Sep 17 00:00:00 2001 From: Kurt Kartaltepe Date: Sat, 3 Oct 2020 12:24:36 -0700 Subject: [PATCH] linux-alsa: Support more device formats OBS already handles a couple of different audio formats, this expands alsa input to try these additional formats for devices with weird format support. fixes #3547 --- plugins/linux-alsa/alsa-input.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/plugins/linux-alsa/alsa-input.c b/plugins/linux-alsa/alsa-input.c index 568a74614..6a113b087 100644 --- a/plugins/linux-alsa/alsa-input.c +++ b/plugins/linux-alsa/alsa-input.c @@ -440,9 +440,27 @@ bool _alsa_configure(struct alsa_data *data) return false; } - data->format = SND_PCM_FORMAT_S16; - err = snd_pcm_hw_params_set_format(data->handle, hwparams, - data->format); +#define FORMAT_SIZE 4 + snd_pcm_format_t formats[FORMAT_SIZE] = {SND_PCM_FORMAT_S16_LE, + SND_PCM_FORMAT_S32_LE, + SND_PCM_FORMAT_FLOAT_LE, + SND_PCM_FORMAT_U8}; + bool format_found = false; + for (int i = 0; i < FORMAT_SIZE; ++i) { + data->format = formats[i]; + err = snd_pcm_hw_params_test_format(data->handle, hwparams, + data->format); + if (err == 0) { + format_found = true; + break; + } + } +#undef FORMAT_SIZE + if (!format_found) { + blog(LOG_ERROR, "device doesnt support any OBS formats"); + return false; + } + snd_pcm_hw_params_set_format(data->handle, hwparams, data->format); if (err < 0) { blog(LOG_ERROR, "snd_pcm_hw_params_set_format failed: %s", snd_strerror(err));