mirror of
https://github.com/mpv-player/mpv.git
synced 2026-10-28 14:29:25 +08:00
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?)
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user