Skip to content

Commit

Permalink
AVAudioSession: enable for visionOS
Browse files Browse the repository at this point in the history
This also enables spatial audio if requested by the user
  • Loading branch information
fkuehne authored and robUx4 committed Jun 4, 2024
1 parent 492a941 commit 6efd3de
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions modules/audio_output/apple/avaudiosession_common.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@
#import <AVFoundation/AVFoundation.h>
#import "avaudiosession_common.h"

// work-around to fix compilation on older Xcode releases
#if defined(TARGET_OS_VISION) && TARGET_OS_VISION
#define MIN_VISIONOS 1.0
#define VISIONOS_API_AVAILABLE , visionos(MIN_VISIONOS)
#define VISIONOS_AVAILABLE , visionOS MIN_VISIONOS
#else
#define VISIONOS_API_AVAILABLE
#define VISIONOS_AVAILABLE
#endif

void
avas_PrepareFormat(audio_output_t *p_aout, AVAudioSession *instance,
audio_sample_format_t *fmt, bool spatial_audio)
Expand Down Expand Up @@ -61,7 +71,7 @@

if (spatial_audio)
{
if (@available(iOS 15.0, tvOS 15.0, *))
if (@available(iOS 15.0, tvOS 15.0 VISIONOS_AVAILABLE, *))
{
/* Not mandatory, SpatialAudio can work without it. It just signals to
* the user that he is playing spatial content */
Expand Down Expand Up @@ -117,21 +127,21 @@
return VLC_SUCCESS;
}

struct API_AVAILABLE(ios(11.0))
struct API_AVAILABLE(ios(11.0) VISIONOS_API_AVAILABLE)
role2policy
{
char role[sizeof("accessibility")];
AVAudioSessionRouteSharingPolicy policy;
};

static int API_AVAILABLE(ios(11.0))
static int API_AVAILABLE(ios(11.0) VISIONOS_API_AVAILABLE)
role2policy_cmp(const void *key, const void *val)
{
const struct role2policy *entry = val;
return strcmp(key, entry->role);
}

static AVAudioSessionRouteSharingPolicy API_AVAILABLE(ios(11.0))
static AVAudioSessionRouteSharingPolicy API_AVAILABLE(ios(11.0) VISIONOS_API_AVAILABLE)
GetRouteSharingPolicy(audio_output_t *p_aout)
{
#if __IPHONEOS_VERSION_MAX_ALLOWED < 130000
Expand All @@ -144,7 +154,7 @@ static AVAudioSessionRouteSharingPolicy API_AVAILABLE(ios(11.0))
AVAudioSessionRouteSharingPolicy policy = AVAudioSessionRouteSharingPolicyLongFormAudio;
AVAudioSessionRouteSharingPolicy video_policy;
#if !TARGET_OS_TV
if (@available(iOS 13.0, *))
if (@available(iOS 13.0 VISIONOS_AVAILABLE, *))
video_policy = AVAudioSessionRouteSharingPolicyLongFormVideo;
else
#endif
Expand Down Expand Up @@ -188,7 +198,7 @@ static AVAudioSessionRouteSharingPolicy API_AVAILABLE(ios(11.0))

if (active)
{
if (@available(iOS 11.0, tvOS 11.0, *))
if (@available(iOS 11.0, tvOS 11.0 VISIONOS_AVAILABLE, *))
{
AVAudioSessionRouteSharingPolicy policy = GetRouteSharingPolicy(p_aout);

Expand Down

0 comments on commit 6efd3de

Please sign in to comment.