aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar wm4 <wm4@nowhere>2016-11-08 17:46:42 +0100
committerGravatar wm4 <wm4@nowhere>2016-11-08 17:49:40 +0100
commit33012b4141fda7aaa35ba3eee32f31265ed837cc (patch)
tree593f312b5d0bfe00b38849dc9528bb90758fb86d
parent1d51dc20eadd0873b1870d14e7156aa03c67e511 (diff)
ao_alsa: fill unused ALSA channels with silence
This happens when ALSA gives us more channels than we asked for, for whatever reasons. It looks like this wasn't handled correctly. The mpv and ALSA channel counts could mismatch, which would lead to UB. I couldn't actually trigger this case, though. I'm fairly sure that drivers or plugins exist that do it anyway. (Inofficial ALSA motto: if it can be broken, then why not break it?)
-rw-r--r--audio/out/ao_alsa.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/audio/out/ao_alsa.c b/audio/out/ao_alsa.c
index f80a46a5cc..f30417ff68 100644
--- a/audio/out/ao_alsa.c
+++ b/audio/out/ao_alsa.c
@@ -794,8 +794,13 @@ static int init_device(struct ao *ao, int mode)
if (num_channels != ao->channels.num) {
int req = ao->channels.num;
mp_chmap_from_channels(&ao->channels, MPMIN(2, num_channels));
+ mp_chmap_fill_na(&ao->channels, num_channels);
MP_ERR(ao, "Asked for %d channels, got %d - fallback to %s.\n", req,
num_channels, mp_chmap_to_str(&ao->channels));
+ if (num_channels != ao->channels.num) {
+ MP_FATAL(ao, "mismatching channel counts.\n");
+ goto alsa_error;
+ }
}
err = snd_pcm_hw_params_get_buffer_size(alsa_hwparams, &p->buffersize);