From 0cc440f2919f7281d31f0ce16c7d757b4145a8a7 Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 26 Oct 2015 15:55:11 +0100 Subject: ao_coreaudio_exclusive: fallback to stereo on unknown channel layouts This is intended for the case when CoreAudio returns only unknown channel layouts, or no channel layout matches the number of channels the CoreAudio device forces. Assume that outputting stereo or mono to the first channels is safe, and that it's better than outputting nothing. It's notable that XBMC/kodi falls back to a static channel layout in this case. For some messed up reason, the layout it uses happens to match with the channel order in ALSA's/mpv's "7.1(alsa)" layout. --- audio/out/ao_coreaudio_chmap.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'audio') diff --git a/audio/out/ao_coreaudio_chmap.c b/audio/out/ao_coreaudio_chmap.c index d5a38d325e..bdd625ff53 100644 --- a/audio/out/ao_coreaudio_chmap.c +++ b/audio/out/ao_coreaudio_chmap.c @@ -281,6 +281,7 @@ void ca_get_active_chmap(struct ao *ao, AudioDeviceID device, int channel_count, struct mp_chmap_sel chmap_sel = {0}; ca_retrieve_layouts(ao, &chmap_sel, device); + // Use any exact match. for (int n = 0; n < chmap_sel.num_chmaps; n++) { if (chmap_sel.chmaps[n].num == channel_count) { MP_VERBOSE(ao, "mismatching channels - fallback #%d\n", n); @@ -289,5 +290,13 @@ void ca_get_active_chmap(struct ao *ao, AudioDeviceID device, int channel_count, } } - out_map->num = 0; + // Fall back to stereo or mono, and fill the rest with silence. (We don't + // know what the device expects. We could use a larger default layout here, + // but let's not.) + mp_chmap_from_channels(out_map, MPMIN(2, channel_count)); + out_map->num = channel_count; + for (int n = 2; n < out_map->num; n++) + out_map->speaker[n] = MP_SPEAKER_ID_NA; + MP_WARN(ao, "mismatching channels - falling back to %s\n", + mp_chmap_to_str(out_map)); } -- cgit v1.2.3