From 6c08c24b075157241eaca3543bb77107a1b9b853 Mon Sep 17 00:00:00 2001 From: Thomas Guillem Date: Tue, 3 Jan 2023 15:20:27 +0100 Subject: [PATCH] audiounit: fix surround input on stereo output setPreferredOutputNumberOfChannels can fail, don't configure more channels than accepted. The OS will drop the extra channels instead of downmixing it. When I first tested it, the apple TV was configured to always accept surround even with a stereo output (Change Format = Off) but this is not necessarily the case. --- modules/audio_output/audiounit_ios.m | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/modules/audio_output/audiounit_ios.m b/modules/audio_output/audiounit_ios.m index f41336112fd3..d23d4131c190 100644 --- a/modules/audio_output/audiounit_ios.m +++ b/modules/audio_output/audiounit_ios.m @@ -602,6 +602,14 @@ static int role2policy_cmp(const void *key, const void *val) (long) [p_sys->avInstance outputNumberOfChannels], p_sys->b_spatial_audio_supported); + if (!p_sys->b_preferred_channels_set && fmt->i_channels > 2) + { + /* Ask the core to downmix to stereo if the preferred number of + * channels can't be set. */ + fmt->i_physical_channels = AOUT_CHANS_STEREO; + aout_FormatPrepare(fmt); + } + p_aout->current_sink_info.headphones = port_type == PORT_TYPE_HEADPHONES; p_sys->au_unit = au_NewOutputInstance(p_aout, kAudioUnitSubType_RemoteIO);