From 748fc2b752091ec9d8addbc5c4041d55e877c196 Mon Sep 17 00:00:00 2001 From: Callum Moffat Date: Thu, 12 Dec 2024 23:40:10 -0500 Subject: [PATCH] ao_audiounit: add --audio-exclusiv support, make non-exclusive default --- DOCS/interface-changes/audiounit-exclusive.txt | 1 + DOCS/man/options.rst | 4 ++-- audio/out/ao_audiounit.m | 7 ++++++- 3 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 DOCS/interface-changes/audiounit-exclusive.txt diff --git a/DOCS/interface-changes/audiounit-exclusive.txt b/DOCS/interface-changes/audiounit-exclusive.txt new file mode 100644 index 0000000000000..07c5061a9d986 --- /dev/null +++ b/DOCS/interface-changes/audiounit-exclusive.txt @@ -0,0 +1 @@ +add --audio-exclusive option support for ao=audiounit and make non-exclusive the new default diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst index 209db453a6998..b1d70ed861218 100644 --- a/DOCS/man/options.rst +++ b/DOCS/man/options.rst @@ -2001,8 +2001,8 @@ Audio Enable exclusive output mode. In this mode, the system is usually locked out, and only mpv will be able to output audio. - This only works for some audio outputs, such as ``wasapi``, ``coreaudio`` - and ``pipewire``. Other audio outputs silently ignore this option. + This only works for some audio outputs, such as ``wasapi``, ``coreaudio``, + ``pipewire`` and ``audiounit``. Other audio outputs silently ignore this option. They either have no concept of exclusive mode, or the mpv side of the implementation is missing. diff --git a/audio/out/ao_audiounit.m b/audio/out/ao_audiounit.m index d35912ceb8b80..8d4eb4d3756df 100644 --- a/audio/out/ao_audiounit.m +++ b/audio/out/ao_audiounit.m @@ -115,7 +115,12 @@ static bool init_audiounit(struct ao *ao) MP_VERBOSE(ao, "max channels: %ld, requested: %d\n", maxChannels, (int)ao->channels.num); - [instance setCategory:AVAudioSessionCategoryPlayback error:nil]; + AVAudioSessionCategoryOptions options = 0; + if (!(ao->init_flags & AO_INIT_EXCLUSIVE)) { + options |= AVAudioSessionCategoryOptionMixWithOthers; + } + + [instance setCategory:AVAudioSessionCategoryPlayback withOptions:options error:nil]; [instance setMode:AVAudioSessionModeMoviePlayback error:nil]; [instance setActive:YES error:nil]; [instance setPreferredOutputNumberOfChannels:prefChannels error:nil];