[vlc-commits] [Git][videolan/vlc][master] 2 commits: audiounit_ios: setup the RouteSharingPolicy

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Sat Nov 13 11:20:10 UTC 2021



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
5abc4ea8 by Thomas Guillem at 2021-11-13T10:59:22+00:00
audiounit_ios: setup the RouteSharingPolicy

Starting iOS 11.0

Setting it to LongFormAudio or LongFormVideo will select audio devices
that are used for long playback (music or video) in priority.

- - - - -
6fd238d9 by Thomas Guillem at 2021-11-13T10:59:22+00:00
audiounit_ios: don't register the aout in case of failure

- - - - -


1 changed file:

- modules/audio_output/audiounit_ios.m


Changes:

=====================================
modules/audio_output/audiounit_ios.m
=====================================
@@ -357,6 +357,59 @@ avas_GetOptimalChannelLayout(audio_output_t *p_aout, enum port_type *pport_type,
     return VLC_SUCCESS;
 }
 
+struct role2policy
+{
+    char role[sizeof("accessibility")];
+    AVAudioSessionRouteSharingPolicy policy;
+};
+
+static int role2policy_cmp(const void *key, const void *val)
+{
+    const struct role2policy *entry = val;
+    return strcmp(key, entry->role);
+}
+
+static AVAudioSessionRouteSharingPolicy
+GetRouteSharingPolicy(audio_output_t *p_aout)
+{
+    /* LongFormAudio by defaut */
+    AVAudioSessionRouteSharingPolicy policy = AVAudioSessionRouteSharingPolicyLongFormAudio;
+    AVAudioSessionRouteSharingPolicy video_policy;
+#if !TARGET_OS_TV
+    if (@available(iOS 13.0, *))
+        video_policy = AVAudioSessionRouteSharingPolicyLongFormVideo;
+    else
+#endif
+        video_policy = AVAudioSessionRouteSharingPolicyLongFormAudio;
+
+    char *str = var_InheritString(p_aout, "role");
+    if (str != NULL)
+    {
+        const struct role2policy role_list[] =
+        {
+            { "accessibility", AVAudioSessionRouteSharingPolicyDefault },
+            { "animation",     AVAudioSessionRouteSharingPolicyDefault },
+            { "communication", AVAudioSessionRouteSharingPolicyDefault },
+            { "game",          AVAudioSessionRouteSharingPolicyLongFormAudio },
+            { "music",         AVAudioSessionRouteSharingPolicyLongFormAudio },
+            { "notification",  AVAudioSessionRouteSharingPolicyDefault },
+            { "production",    AVAudioSessionRouteSharingPolicyDefault },
+            { "test",          AVAudioSessionRouteSharingPolicyDefault },
+            { "video",         video_policy},
+        };
+
+        const struct role2policy *entry =
+            bsearch(str, role_list, ARRAY_SIZE(role_list),
+                    sizeof (*role_list), role2policy_cmp);
+        free(str);
+        if (entry != NULL)
+            policy = entry->policy;
+    }
+
+    return policy;
+}
+
+
 static int
 avas_SetActive(audio_output_t *p_aout, bool active, NSUInteger options)
 {
@@ -367,13 +420,31 @@ avas_SetActive(audio_output_t *p_aout, bool active, NSUInteger options)
 
     if (active)
     {
-        ret = [instance setCategory:AVAudioSessionCategoryPlayback error:&error];
-        ret = ret && [instance setMode:AVAudioSessionModeMoviePlayback error:&error];
+        AVAudioSessionCategory category = AVAudioSessionCategoryPlayback;
+        AVAudioSessionMode mode = AVAudioSessionModeMoviePlayback;
+        AVAudioSessionRouteSharingPolicy policy = GetRouteSharingPolicy(p_aout);
+
+        if (@available(iOS 11.0, tvOS 11.0, *))
+        {
+            ret = [instance setCategory:category
+                                   mode:mode
+                     routeSharingPolicy:policy
+                                options:0
+                                  error:&error];
+        }
+        else
+        {
+            ret = [instance setCategory:category
+                                  error:&error];
+            ret = ret && [instance setMode:mode error:&error];
+            /* Not AVAudioSessionRouteSharingPolicy on older devices */
+        }
         if (@available(iOS 15.0, tvOS 15.0, *)) {
             ret = ret && [instance setSupportsMultichannelContent:p_sys->b_spatial_audio_supported error:&error];
         }
         ret = ret && [instance setActive:YES withOptions:options error:&error];
-        [[SessionManager sharedInstance] addAoutInstance: p_sys->aoutWrapper];
+        if (ret)
+            [[SessionManager sharedInstance] addAoutInstance: p_sys->aoutWrapper];
     } else {
         NSInteger numberOfRegisteredInstances = [[SessionManager sharedInstance] removeAoutInstance: p_sys->aoutWrapper];
         if (numberOfRegisteredInstances == 0) {



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/7d15e8a8396143de94bcb6e39d8e2c748e1e94aa...6fd238d9c9b7f640cd862b0ebca543ad8fb642e2

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/7d15e8a8396143de94bcb6e39d8e2c748e1e94aa...6fd238d9c9b7f640cd862b0ebca543ad8fb642e2
You're receiving this email because of your account on code.videolan.org.




More information about the vlc-commits mailing list