From 3d911d8ef06ddf3992dd6e8e2dce3c1b915742f8 Mon Sep 17 00:00:00 2001 From: Leonardo Taccari Date: Tue, 23 Oct 2018 15:22:09 +0200 Subject: 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. --- audio/out/ao_oss.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'audio/out/ao_oss.c') diff --git a/audio/out/ao_oss.c b/audio/out/ao_oss.c index f037812e70..4a1e483cfb 100644 --- a/audio/out/ao_oss.c +++ b/audio/out/ao_oss.c @@ -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); -- cgit v1.2.3