From c1002f6a28dc7419c28b47826353e321733681e3 Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 5 Jan 2016 19:52:05 +0100 Subject: [PATCH] ao_pulse: attempt to fall back to an arbitrary sample format Normally, PulseAudio accepts any combination of sample format, sample rate, channel count/map. Sometimes it does not. For example, the channel rate or channel count have fixed maximum values. We should not fail fatally in such cases, but attempt to fall back to a working format. We could just send pass an "unset" format to Pulse, but this is not too attractive. Pulse could use a format which we do not support, and also doing so much for an obscure corner case is not reasonable. So just pick a format that is very likely supported. This still could fail at runtime (the stream could fail instead of going to the ready state), but this sounds also too complicated. In particular, it doesn't look like pulse will tell us the cause of the stream failure. (Or maybe it does - but I didn't find anything.) Last but not least, our fallback could be less dumb, and e.g. try to fix only one of samplerate or channel count first to reduce the loss, but this is also not particularly worthy the effort. Fixes #2654. --- audio/out/ao_pulse.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/audio/out/ao_pulse.c b/audio/out/ao_pulse.c index 13813745f9..d553b6700c 100644 --- a/audio/out/ao_pulse.c +++ b/audio/out/ao_pulse.c @@ -431,8 +431,13 @@ static int init(struct ao *ao) goto unlock_and_fail; if (!set_format(ao, format)) { - MP_ERR(ao, "Invalid audio format\n"); - goto unlock_and_fail; + ao->channels = (struct mp_chmap) MP_CHMAP_INIT_STEREO; + ao->samplerate = 48000; + ao->format = AF_FORMAT_FLOAT; + if (!set_format(ao, format)) { + MP_ERR(ao, "Invalid audio format\n"); + goto unlock_and_fail; + } } if (!(priv->stream = pa_stream_new_extended(priv->context, "audio stream",