Skip to content

Commit

Permalink
ao_pulse: attempt to fall back to an arbitrary sample format
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wm4 committed Jan 5, 2016
1 parent 861c126 commit c1002f6
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions audio/out/ao_pulse.c
Expand Up @@ -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",
Expand Down

0 comments on commit c1002f6

Please sign in to comment.