mirror of
https://github.com/mpv-player/mpv
synced 2024-11-14 22:48:35 +01:00
ao_oss: Fallback to stereo when the device does not support >2 channels
ioctl(..., SNDCTL_DSP_CHANNELS, &nchannels) for not supported nchannels does not return an error and instead set nchannels to the default value. Instead of failing with no audio, fallback to stereo.
This commit is contained in:
parent
48740dfec5
commit
3d911d8ef0
@ -336,19 +336,23 @@ static int reopen_device(struct ao *ao, bool allow_format_changes)
|
||||
mp_chmap_sel_add_map(&sel, &oss_layouts[n]);
|
||||
if (!ao_chmap_sel_adjust(ao, &sel, &channels))
|
||||
goto fail;
|
||||
int reqchannels = channels.num;
|
||||
int c, nchannels, reqchannels;
|
||||
nchannels = reqchannels = channels.num;
|
||||
// We only use SNDCTL_DSP_CHANNELS for >2 channels, in case some drivers don't have it
|
||||
if (reqchannels > 2) {
|
||||
int nchannels = reqchannels;
|
||||
if (ioctl(p->audio_fd, SNDCTL_DSP_CHANNELS, &nchannels) == -1 ||
|
||||
nchannels != reqchannels)
|
||||
{
|
||||
if (ioctl(p->audio_fd, SNDCTL_DSP_CHANNELS, &nchannels) == -1) {
|
||||
MP_ERR(ao, "Failed to set audio device to %d channels.\n",
|
||||
reqchannels);
|
||||
goto fail;
|
||||
}
|
||||
if (nchannels != reqchannels) {
|
||||
// Fallback to stereo
|
||||
nchannels = 2;
|
||||
goto stereo;
|
||||
}
|
||||
} else {
|
||||
int c = reqchannels - 1;
|
||||
stereo:
|
||||
c = nchannels - 1;
|
||||
if (ioctl(p->audio_fd, SNDCTL_DSP_STEREO, &c) == -1) {
|
||||
MP_ERR(ao, "Failed to set audio device to %d channels.\n",
|
||||
reqchannels);
|
||||
|
Loading…
Reference in New Issue
Block a user