From ed1430622b8fb8a657a69b75c3cb0f8b42fcf2de Mon Sep 17 00:00:00 2001 From: Christoph Hohmann Date: Tue, 7 Oct 2014 21:55:24 +0200 Subject: [PATCH] Force PulseAudio sample format if the source format is not supported by OBS If the sample format used by PulseAudio can not be converted into an OBS audio format it will be handled as AUDIO_FORMAT_UNKNOWN which will not result in a proper audio recording. So instead we request a format that OBS supports from PulseAudio and let it do the format conversion. --- plugins/linux-pulseaudio/pulse-input.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/plugins/linux-pulseaudio/pulse-input.c b/plugins/linux-pulseaudio/pulse-input.c index ced5dfc8c..80a4b5c04 100644 --- a/plugins/linux-pulseaudio/pulse-input.c +++ b/plugins/linux-pulseaudio/pulse-input.c @@ -183,16 +183,25 @@ static void pulse_source_info(pa_context *c, const pa_source_info *i, int eol, if (eol != 0) goto skip; - data->format = i->sample_spec.format; + blog(LOG_INFO, "Audio format: %s, %"PRIu32" Hz" + ", %"PRIu8" channels", + pa_sample_format_to_string(i->sample_spec.format), + i->sample_spec.rate, + i->sample_spec.channels); + + pa_sample_format_t format = i->sample_spec.format; + if (pulse_to_obs_audio_format(format) == AUDIO_FORMAT_UNKNOWN) { + format = PA_SAMPLE_S16LE; + + blog(LOG_INFO, "Sample format %s not supported by OBS, using %s instead for recording", + pa_sample_format_to_string(i->sample_spec.format), + pa_sample_format_to_string(format)); + } + + data->format = format; data->samples_per_sec = i->sample_spec.rate; data->channels = i->sample_spec.channels; - blog(LOG_INFO, "Audio format: %s, %"PRIuFAST32" Hz" - ", %"PRIuFAST8" channels", - pa_sample_format_to_string(data->format), - data->samples_per_sec, - data->channels); - skip: pulse_signal(0); }