summaryrefslogtreecommitdiffstats
path: root/audio/out/ao_oss.c
diff options
context:
space:
mode:
authorLeonardo Taccari <iamleot@gmail.com>2018-10-23 15:22:09 +0200
committerwm4 <1387750+wm4@users.noreply.github.com>2019-09-21 15:38:46 +0200
commit3d911d8ef06ddf3992dd6e8e2dce3c1b915742f8 (patch)
tree67e061d9e697d0c75dc707b5e0cd1d1e07203dfa /audio/out/ao_oss.c
parent48740dfec5303a390e223b0626daf4730f65f948 (diff)
downloadmpv-3d911d8ef06ddf3992dd6e8e2dce3c1b915742f8.tar.bz2
mpv-3d911d8ef06ddf3992dd6e8e2dce3c1b915742f8.tar.xz
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.
Diffstat (limited to 'audio/out/ao_oss.c')
-rw-r--r--audio/out/ao_oss.c16
1 files changed, 10 insertions, 6 deletions
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);