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.
This commit is contained in:
wm4 2016-01-05 19:52:05 +01:00
parent 861c126b08
commit c1002f6a28
1 changed files with 7 additions and 2 deletions

View File

@ -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",