Update AudioSession route sharing policy
authoreric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 12 Apr 2019 18:04:56 +0000 (18:04 +0000)
committereric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 12 Apr 2019 18:04:56 +0000 (18:04 +0000)
https://bugs.webkit.org/show_bug.cgi?id=196776
<rdar://problem/46501611>

Reviewed by Jer Noble.

Source/WebCore:

No new tests, updated an API test.

* platform/audio/AudioSession.cpp:
(WebCore::convertEnumerationToString):
* platform/audio/AudioSession.h:
(WTF::LogArgument<WebCore::RouteSharingPolicy>::toString):
(WTF::LogArgument<WebCore::AudioSession::CategoryType>::toString):
* platform/audio/cocoa/MediaSessionManagerCocoa.mm:
(MediaSessionManagerCocoa::updateSessionState):
* platform/audio/ios/AudioSessionIOS.mm:
(WebCore::AudioSession::setCategory):
(WebCore::AudioSession::routeSharingPolicy const):
* platform/audio/mac/AudioSessionMac.cpp:
(WebCore::AudioSession::setCategory):

Source/WebKit:

* UIProcess/ios/forms/WKAirPlayRoutePicker.mm:
(-[WKAirPlayRoutePicker showFromView:routeSharingPolicy:routingContextUID:hasVideo:]):

Source/WTF:

* wtf/Platform.h: Define HAVE_ROUTE_SHARING_POLICY_LONG_FORM_VIDEO.

Tools:

* TestWebKitAPI/Tests/WebKitLegacy/ios/AudioSessionCategoryIOS.mm:
(TestWebKitAPI::routeSharingPolicyLongFormVideo):
(TestWebKitAPI::routeSharingPolicyLongFormAudio):
(TestWebKitAPI::TEST):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@244223 268f45cc-cd09-0410-ab3c-d52691b4dbfc

13 files changed:
Source/WTF/ChangeLog
Source/WTF/wtf/Platform.h
Source/WebCore/ChangeLog
Source/WebCore/platform/audio/AudioSession.cpp
Source/WebCore/platform/audio/AudioSession.h
Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.mm
Source/WebCore/platform/audio/ios/AudioSessionIOS.mm
Source/WebCore/platform/audio/mac/AudioSessionMac.cpp
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/ios/forms/WKAirPlayRoutePicker.mm
Source/WebKitLegacy/mac/Plugins/WebPluginController.mm
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKitLegacy/ios/AudioSessionCategoryIOS.mm

index 94365b5..6e26505 100644 (file)
@@ -1,3 +1,13 @@
+2019-04-12  Eric Carlson  <eric.carlson@apple.com>
+
+        Update AudioSession route sharing policy
+        https://bugs.webkit.org/show_bug.cgi?id=196776
+        <rdar://problem/46501611>
+
+        Reviewed by Jer Noble.
+
+        * wtf/Platform.h: Define HAVE_ROUTE_SHARING_POLICY_LONG_FORM_VIDEO.
+
 2019-04-10  Said Abou-Hallawa  <sabouhallawa@apple.com>
 
         requestAnimationFrame should execute before the next frame
index 03431df..7d6bc42 100644 (file)
 #if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 130000) || (PLATFORM(WATCHOS) && __WATCH_OS_VERSION_MIN_REQUIRED >= 60000) || (PLATFORM(APPLETV) && __TV_OS_VERSION_MIN_REQUIRED >= 130000)
 #define HAVE_ALLOWS_SENSITIVE_LOGGING 1
 #endif
+
+#if (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 130000)
+#define HAVE_ROUTE_SHARING_POLICY_LONG_FORM_VIDEO 1
+#endif
index be2e807..6986955 100644 (file)
@@ -1,3 +1,26 @@
+2019-04-12  Eric Carlson  <eric.carlson@apple.com>
+
+        Update AudioSession route sharing policy
+        https://bugs.webkit.org/show_bug.cgi?id=196776
+        <rdar://problem/46501611>
+
+        Reviewed by Jer Noble.
+
+        No new tests, updated an API test.
+
+        * platform/audio/AudioSession.cpp:
+        (WebCore::convertEnumerationToString):
+        * platform/audio/AudioSession.h:
+        (WTF::LogArgument<WebCore::RouteSharingPolicy>::toString):
+        (WTF::LogArgument<WebCore::AudioSession::CategoryType>::toString):
+        * platform/audio/cocoa/MediaSessionManagerCocoa.mm:
+        (MediaSessionManagerCocoa::updateSessionState):
+        * platform/audio/ios/AudioSessionIOS.mm:
+        (WebCore::AudioSession::setCategory):
+        (WebCore::AudioSession::routeSharingPolicy const):
+        * platform/audio/mac/AudioSessionMac.cpp:
+        (WebCore::AudioSession::setCategory):
+
 2019-04-12  Antoine Quint  <graouts@apple.com>
 
         Opt some websites into the simulated mouse events dispatch quirk when in modern compatibility mode
index f60eae8..5c1bf2a 100644 (file)
@@ -60,7 +60,7 @@ AudioSession::AudioSession()
 
 AudioSession::~AudioSession() = default;
 
-void AudioSession::setCategory(CategoryType)
+void AudioSession::setCategory(CategoryType, RouteSharingPolicy)
 {
     notImplemented();
 }
@@ -129,6 +129,43 @@ String AudioSession::routingContextUID() const
 
 #endif // !PLATFORM(COCOA)
 
+String convertEnumerationToString(RouteSharingPolicy enumerationValue)
+{
+    static const NeverDestroyed<String> values[] = {
+        MAKE_STATIC_STRING_IMPL("Default"),
+        MAKE_STATIC_STRING_IMPL("LongFormAudio"),
+        MAKE_STATIC_STRING_IMPL("Independent"),
+        MAKE_STATIC_STRING_IMPL("LongFormVideo"),
+    };
+    static_assert(!static_cast<size_t>(RouteSharingPolicy::Default), "RouteSharingPolicy::Default is not 0 as expected");
+    static_assert(static_cast<size_t>(RouteSharingPolicy::LongFormAudio) == 1, "RouteSharingPolicy::LongFormAudio is not 1 as expected");
+    static_assert(static_cast<size_t>(RouteSharingPolicy::Independent) == 2, "RouteSharingPolicy::Independent is not 2 as expected");
+    static_assert(static_cast<size_t>(RouteSharingPolicy::LongFormVideo) == 3, "RouteSharingPolicy::LongFormVideo is not 3 as expected");
+    ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values));
+    return values[static_cast<size_t>(enumerationValue)];
+}
+
+String convertEnumerationToString(AudioSession::CategoryType enumerationValue)
+{
+    static const NeverDestroyed<String> values[] = {
+        MAKE_STATIC_STRING_IMPL("None"),
+        MAKE_STATIC_STRING_IMPL("AmbientSound"),
+        MAKE_STATIC_STRING_IMPL("SoloAmbientSound"),
+        MAKE_STATIC_STRING_IMPL("MediaPlayback"),
+        MAKE_STATIC_STRING_IMPL("RecordAudio"),
+        MAKE_STATIC_STRING_IMPL("PlayAndRecord"),
+        MAKE_STATIC_STRING_IMPL("AudioProcessing"),
+    };
+    static_assert(!static_cast<size_t>(AudioSession::CategoryType::None), "AudioSession::CategoryType::None is not 0 as expected");
+    static_assert(static_cast<size_t>(AudioSession::CategoryType::AmbientSound) == 1, "AudioSession::CategoryType::AmbientSound is not 1 as expected");
+    static_assert(static_cast<size_t>(AudioSession::CategoryType::SoloAmbientSound) == 2, "AudioSession::CategoryType::SoloAmbientSound is not 2 as expected");
+    static_assert(static_cast<size_t>(AudioSession::CategoryType::MediaPlayback) == 3, "AudioSession::CategoryType::MediaPlayback is not 3 as expected");
+    static_assert(static_cast<size_t>(AudioSession::CategoryType::RecordAudio) == 4, "AudioSession::CategoryType::RecordAudio is not 4 as expected");
+    static_assert(static_cast<size_t>(AudioSession::CategoryType::PlayAndRecord) == 5, "AudioSession::CategoryType::PlayAndRecord is not 5 as expected");
+    static_assert(static_cast<size_t>(AudioSession::CategoryType::AudioProcessing) == 6, "AudioSession::CategoryType::AudioProcessing is not 6 as expected");
+    ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values));
+    return values[static_cast<size_t>(enumerationValue)];
+}
 }
 
 #endif // USE(AUDIO_SESSION)
index cabb874..17da81b 100644 (file)
@@ -31,6 +31,7 @@
 #include <wtf/HashSet.h>
 #include <wtf/NeverDestroyed.h>
 #include <wtf/Noncopyable.h>
+#include <wtf/text/WTFString.h>
 
 namespace WebCore {
 
@@ -38,8 +39,9 @@ class AudioSessionPrivate;
 
 enum class RouteSharingPolicy : uint8_t {
     Default,
-    LongForm,
+    LongFormAudio,
     Independent,
+    LongFormVideo
 };
 
 class AudioSession {
@@ -56,7 +58,7 @@ public:
         PlayAndRecord,
         AudioProcessing,
     };
-    WEBCORE_EXPORT void setCategory(CategoryType);
+    WEBCORE_EXPORT void setCategory(CategoryType, RouteSharingPolicy);
     WEBCORE_EXPORT CategoryType category() const;
 
     void setCategoryOverride(CategoryType);
@@ -101,17 +103,41 @@ private:
     bool m_active { false }; // Used only for testing.
 };
 
-}
+String convertEnumerationToString(RouteSharingPolicy);
+String convertEnumerationToString(AudioSession::CategoryType);
+
+} // namespace WebCore
 
 namespace WTF {
 template<> struct EnumTraits<WebCore::RouteSharingPolicy> {
     using values = EnumValues<
     WebCore::RouteSharingPolicy,
     WebCore::RouteSharingPolicy::Default,
-    WebCore::RouteSharingPolicy::LongForm,
-    WebCore::RouteSharingPolicy::Independent
+    WebCore::RouteSharingPolicy::LongFormAudio,
+    WebCore::RouteSharingPolicy::Independent,
+    WebCore::RouteSharingPolicy::LongFormVideo
     >;
 };
-}
+
+template<typename Type>
+struct LogArgument;
+
+template <>
+struct LogArgument<WebCore::RouteSharingPolicy> {
+    static String toString(const WebCore::RouteSharingPolicy policy)
+    {
+        return convertEnumerationToString(policy);
+    }
+};
+
+template <>
+struct LogArgument<WebCore::AudioSession::CategoryType> {
+    static String toString(const WebCore::AudioSession::CategoryType category)
+    {
+        return convertEnumerationToString(category);
+    }
+};
+
+} // namespace WTF
 
 #endif // USE(AUDIO_SESSION)
index b73fdef..04d42c1 100644 (file)
@@ -62,19 +62,25 @@ PlatformMediaSessionManager* PlatformMediaSessionManager::sharedManagerIfExists(
 
 void MediaSessionManagerCocoa::updateSessionState()
 {
+    int videoCount = count(PlatformMediaSession::Video);
+    int videoAudioCount = count(PlatformMediaSession::VideoAudio);
+    int audioCount = count(PlatformMediaSession::Audio);
+    int webAudioCount = count(PlatformMediaSession::WebAudio);
+    int captureCount = count(PlatformMediaSession::MediaStreamCapturingAudio);
     ALWAYS_LOG(LOGIDENTIFIER, "types: "
-        "Video(", count(PlatformMediaSession::Video), "), "
-        "Audio(", count(PlatformMediaSession::Audio), "), "
-        "VideoAudio(", count(PlatformMediaSession::VideoAudio), "), "
-        "WebAudio(", count(PlatformMediaSession::WebAudio), ")");
+        "AudioCapture(", captureCount, "), "
+        "Video(", videoCount, "), "
+        "Audio(", audioCount, "), "
+        "VideoAudio(", videoAudioCount, "), "
+        "WebAudio(", webAudioCount, ")");
 
-    if (has(PlatformMediaSession::WebAudio))
+    if (webAudioCount)
         AudioSession::sharedSession().setPreferredBufferSize(kWebAudioBufferSize);
     // In case of audio capture, we want to grab 20 ms chunks to limit the latency so that it is not noticeable by users
     // while having a large enough buffer so that the audio rendering remains stable, hence a computation based on sample rate.
-    else if (has(PlatformMediaSession::MediaStreamCapturingAudio))
+    else if (captureCount)
         AudioSession::sharedSession().setPreferredBufferSize(AudioSession::sharedSession().sampleRate() / 50);
-    else if ((has(PlatformMediaSession::VideoAudio) || has(PlatformMediaSession::Audio)) && DeprecatedGlobalSettings::lowPowerVideoAudioBufferSizeEnabled()) {
+    else if ((videoAudioCount || audioCount) && DeprecatedGlobalSettings::lowPowerVideoAudioBufferSizeEnabled()) {
         // FIXME: <http://webkit.org/b/116725> Figure out why enabling the code below
         // causes media LayoutTests to fail on 10.8.
 
@@ -90,27 +96,30 @@ void MediaSessionManagerCocoa::updateSessionState()
     if (!DeprecatedGlobalSettings::shouldManageAudioSessionCategory())
         return;
 
-    bool hasWebAudioType = false;
     bool hasAudibleAudioOrVideoMediaType = false;
-    bool hasAudioCapture = anyOfSessions([&hasWebAudioType, &hasAudibleAudioOrVideoMediaType] (PlatformMediaSession& session, size_t) mutable {
+    forEachSession([&hasAudibleAudioOrVideoMediaType] (PlatformMediaSession& session, size_t) mutable {
         auto type = session.mediaType();
-        if (type == PlatformMediaSession::WebAudio)
-            hasWebAudioType = true;
         if ((type == PlatformMediaSession::VideoAudio || type == PlatformMediaSession::Audio) && session.canProduceAudio() && session.hasPlayedSinceLastInterruption())
             hasAudibleAudioOrVideoMediaType = true;
         if (session.isPlayingToWirelessPlaybackTarget())
             hasAudibleAudioOrVideoMediaType = true;
-        return (type == PlatformMediaSession::MediaStreamCapturingAudio);
     });
 
-    if (hasAudioCapture)
-        AudioSession::sharedSession().setCategory(AudioSession::PlayAndRecord);
-    else if (hasAudibleAudioOrVideoMediaType)
-        AudioSession::sharedSession().setCategory(AudioSession::MediaPlayback);
-    else if (hasWebAudioType)
-        AudioSession::sharedSession().setCategory(AudioSession::AmbientSound);
-    else
-        AudioSession::sharedSession().setCategory(AudioSession::None);
+    RouteSharingPolicy policy = RouteSharingPolicy::Default;
+    AudioSession::CategoryType category = AudioSession::None;
+    if (captureCount)
+        category = AudioSession::PlayAndRecord;
+    else if (hasAudibleAudioOrVideoMediaType) {
+        category = AudioSession::MediaPlayback;
+        if (videoCount || videoAudioCount)
+            policy = RouteSharingPolicy::LongFormVideo;
+        else
+            policy = RouteSharingPolicy::LongFormAudio;
+    } else if (webAudioCount)
+        category = AudioSession::AmbientSound;
+
+    ALWAYS_LOG(LOGIDENTIFIER, "setting category = ", category, ", policy = ", policy);
+    AudioSession::sharedSession().setCategory(category, policy);
 }
 
 void MediaSessionManagerCocoa::beginInterruption(PlatformMediaSession::InterruptionType type)
index a4c4801..3824211 100644 (file)
@@ -100,8 +100,13 @@ AudioSession::~AudioSession()
 {
 }
 
-void AudioSession::setCategory(CategoryType newCategory)
+void AudioSession::setCategory(CategoryType newCategory, RouteSharingPolicy policy)
 {
+#if !HAVE(ROUTE_SHARING_POLICY_LONG_FORM_VIDEO)
+    if (policy == RouteSharingPolicy::LongFormVideo)
+        policy = RouteSharingPolicy::LongFormAudio;
+#endif
+
     LOG(Media, "AudioSession::setCategory() - category = %s", categoryName(newCategory));
 
     if (categoryOverride() && categoryOverride() != newCategory) {
@@ -112,7 +117,6 @@ void AudioSession::setCategory(CategoryType newCategory)
     NSString *categoryString;
     NSString *categoryMode = AVAudioSessionModeDefault;
     AVAudioSessionCategoryOptions options = 0;
-    AVAudioSessionRouteSharingPolicy policy = AVAudioSessionRouteSharingPolicyDefault;
 
     switch (newCategory) {
     case AmbientSound:
@@ -123,10 +127,7 @@ void AudioSession::setCategory(CategoryType newCategory)
         break;
     case MediaPlayback:
         categoryString = AVAudioSessionCategoryPlayback;
-ALLOW_DEPRECATED_DECLARATIONS_BEGIN
-        policy = AVAudioSessionRouteSharingPolicyLongForm;
         break;
-ALLOW_DEPRECATED_DECLARATIONS_END
     case RecordAudio:
         categoryString = AVAudioSessionCategoryRecord;
         break;
@@ -144,7 +145,7 @@ ALLOW_DEPRECATED_DECLARATIONS_END
     }
 
     NSError *error = nil;
-    [[AVAudioSession sharedInstance] setCategory:categoryString mode:categoryMode routeSharingPolicy:policy options:options error:&error];
+    [[AVAudioSession sharedInstance] setCategory:categoryString mode:categoryMode routeSharingPolicy:static_cast<AVAudioSessionRouteSharingPolicy>(policy) options:options error:&error];
 #if !PLATFORM(IOS_FAMILY_SIMULATOR) && !PLATFORM(IOSMAC)
     ASSERT(!error);
 #endif
@@ -171,13 +172,16 @@ AudioSession::CategoryType AudioSession::category() const
 RouteSharingPolicy AudioSession::routeSharingPolicy() const
 {
     static_assert(static_cast<size_t>(RouteSharingPolicy::Default) == static_cast<size_t>(AVAudioSessionRouteSharingPolicyDefault), "RouteSharingPolicy::Default is not AVAudioSessionRouteSharingPolicyDefault as expected");
-ALLOW_DEPRECATED_DECLARATIONS_BEGIN
-    static_assert(static_cast<size_t>(RouteSharingPolicy::LongForm) == static_cast<size_t>(AVAudioSessionRouteSharingPolicyLongForm), "RouteSharingPolicy::LongForm is not AVAudioSessionRouteSharingPolicyLongForm as expected");
-ALLOW_DEPRECATED_DECLARATIONS_END
+#if HAVE(ROUTE_SHARING_POLICY_LONG_FORM_VIDEO)
+    static_assert(static_cast<size_t>(RouteSharingPolicy::LongFormAudio) == static_cast<size_t>(AVAudioSessionRouteSharingPolicyLongFormAudio), "RouteSharingPolicy::LongFormAudio is not AVAudioSessionRouteSharingPolicyLongFormAudio as expected");
+    static_assert(static_cast<size_t>(RouteSharingPolicy::LongFormVideo) == static_cast<size_t>(AVAudioSessionRouteSharingPolicyLongFormVideo), "RouteSharingPolicy::LongFormVideo is not AVAudioSessionRouteSharingPolicyLongFormVideo as expected");
+#else
+    static_assert(static_cast<size_t>(RouteSharingPolicy::LongFormAudio) == static_cast<size_t>(AVAudioSessionRouteSharingPolicyLongForm), "RouteSharingPolicy::LongFormAudio is not AVAudioSessionRouteSharingPolicyLongForm as expected");
+#endif
     static_assert(static_cast<size_t>(RouteSharingPolicy::Independent) == static_cast<size_t>(AVAudioSessionRouteSharingPolicyIndependent), "RouteSharingPolicy::Independent is not AVAudioSessionRouteSharingPolicyIndependent as expected");
 
     AVAudioSessionRouteSharingPolicy policy = [[AVAudioSession sharedInstance] routeSharingPolicy];
-    ASSERT(static_cast<RouteSharingPolicy>(policy) <= RouteSharingPolicy::Independent);
+    ASSERT(static_cast<RouteSharingPolicy>(policy) <= RouteSharingPolicy::LongFormVideo);
     return static_cast<RouteSharingPolicy>(policy);
 }
 
@@ -196,7 +200,7 @@ void AudioSession::setCategoryOverride(CategoryType category)
         return;
 
     m_private->m_categoryOverride = category;
-    setCategory(category);
+    setCategory(category, RouteSharingPolicy::Default);
 }
 
 AudioSession::CategoryType AudioSession::categoryOverride() const
index b6e3ed0..881aa33 100644 (file)
@@ -73,7 +73,7 @@ AudioSession::CategoryType AudioSession::category() const
     return m_private->category;
 }
 
-void AudioSession::setCategory(CategoryType category)
+void AudioSession::setCategory(CategoryType category, RouteSharingPolicy)
 {
     m_private->category = category;
 }
index dce9845..8a414e3 100644 (file)
@@ -1,3 +1,14 @@
+2019-04-12  Eric Carlson  <eric.carlson@apple.com>
+
+        Update AudioSession route sharing policy
+        https://bugs.webkit.org/show_bug.cgi?id=196776
+        <rdar://problem/46501611>
+
+        Reviewed by Jer Noble.
+
+        * UIProcess/ios/forms/WKAirPlayRoutePicker.mm:
+        (-[WKAirPlayRoutePicker showFromView:routeSharingPolicy:routingContextUID:hasVideo:]):
+
 2019-04-12  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         WebsitePolicies doesn't copy its media source policy in WebsitePolicies::copy
index 31f5604..3e3d760 100644 (file)
@@ -178,8 +178,9 @@ SOFT_LINK_CLASS(MediaPlayer, MPMediaControlsViewController)
 
 enum {
     WKAirPlayRoutePickerRouteSharingPolicyDefault = 0,
-    WKAirPlayRoutePickerRouteSharingPolicyLongForm = 1,
+    WKAirPlayRoutePickerRouteSharingPolicyLongFormAudio = 1,
     WKAirPlayRoutePickerRouteSharingPolicyIndependent = 2,
+    WKAirPlayRoutePickerRouteSharingPolicyLongFormVideo = 3,
 };
 typedef NSInteger WKAirPlayRoutePickerRouteSharingPolicy;
 
@@ -201,9 +202,9 @@ typedef NSInteger WKAirPlayRoutePickerRouteSharingPolicy;
 - (void)showFromView:(UIView *)view routeSharingPolicy:(WebCore::RouteSharingPolicy)routeSharingPolicy routingContextUID:(NSString *)routingContextUID hasVideo:(BOOL)hasVideo
 {
     static_assert(static_cast<size_t>(WebCore::RouteSharingPolicy::Default) == static_cast<size_t>(WKAirPlayRoutePickerRouteSharingPolicyDefault), "RouteSharingPolicy::Default is not WKAirPlayRoutePickerRouteSharingPolicyDefault as expected");
-    static_assert(static_cast<size_t>(WebCore::RouteSharingPolicy::LongForm) == static_cast<size_t>(WKAirPlayRoutePickerRouteSharingPolicyLongForm), "RouteSharingPolicy::LongForm is not WKAirPlayRoutePickerRouteSharingPolicyLongForm as expected");
+    static_assert(static_cast<size_t>(WebCore::RouteSharingPolicy::LongFormAudio) == static_cast<size_t>(WKAirPlayRoutePickerRouteSharingPolicyLongFormAudio), "RouteSharingPolicy::LongFormAudio is not WKAirPlayRoutePickerRouteSharingPolicyLongFormAudio as expected");
     static_assert(static_cast<size_t>(WebCore::RouteSharingPolicy::Independent) == static_cast<size_t>(WKAirPlayRoutePickerRouteSharingPolicyIndependent), "RouteSharingPolicy::Independent is not WKAirPlayRoutePickerRouteSharingPolicyIndependent as expected");
-
+    static_assert(static_cast<size_t>(WebCore::RouteSharingPolicy::LongFormVideo) == static_cast<size_t>(WKAirPlayRoutePickerRouteSharingPolicyLongFormVideo), "RouteSharingPolicy::LongFormVideo is not WKAirPlayRoutePickerRouteSharingPolicyLongFormVideo as expected");
     if (_actionSheet)
         return;
 
index 94053e3..0f2fd9c 100644 (file)
@@ -114,7 +114,7 @@ static void initializeAudioSession()
     if (!WebCore::IOSApplication::isMobileSafari())
         return;
 
-    AudioSession::sharedSession().setCategory(AudioSession::MediaPlayback);
+    AudioSession::sharedSession().setCategory(AudioSession::MediaPlayback, RouteSharingPolicy::Default);
 }
 #endif
 
index 42fef77..7561f3f 100644 (file)
@@ -1,3 +1,16 @@
+2019-04-12  Eric Carlson  <eric.carlson@apple.com>
+
+        Update AudioSession route sharing policy
+        https://bugs.webkit.org/show_bug.cgi?id=196776
+        <rdar://problem/46501611>
+
+        Reviewed by Jer Noble.
+
+        * TestWebKitAPI/Tests/WebKitLegacy/ios/AudioSessionCategoryIOS.mm:
+        (TestWebKitAPI::routeSharingPolicyLongFormVideo):
+        (TestWebKitAPI::routeSharingPolicyLongFormAudio):
+        (TestWebKitAPI::TEST):
+
 2019-04-12  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         [iOS] Software keyboard is shown too frequently on some websites
index f2705e4..7ce46ea 100644 (file)
@@ -71,6 +71,24 @@ static void waitUntilAudioSessionCategoryIsEqualTo(NSString *expectedValue)
     } while (++tries <= 100);
 }
 
+static AVAudioSessionRouteSharingPolicy routeSharingPolicyLongFormVideo()
+{
+#if HAVE(ROUTE_SHARING_POLICY_LONG_FORM_VIDEO)
+    return AVAudioSessionRouteSharingPolicyLongFormVideo;
+#else
+    return AVAudioSessionRouteSharingPolicyLongForm;
+#endif
+}
+
+static AVAudioSessionRouteSharingPolicy routeSharingPolicyLongFormAudio()
+{
+#if HAVE(ROUTE_SHARING_POLICY_LONG_FORM_VIDEO)
+    return AVAudioSessionRouteSharingPolicyLongFormAudio;
+#else
+    return AVAudioSessionRouteSharingPolicyLongForm;
+#endif
+}
+
 TEST(WebKitLegacy, AudioSessionCategoryIOS)
 {
     WebCore::DeprecatedGlobalSettings::setShouldManageAudioSessionCategory(true);
@@ -84,12 +102,15 @@ TEST(WebKitLegacy, AudioSessionCategoryIOS)
     RetainPtr<AudioSessionCategoryUIWebViewDelegate> uiDelegate = adoptNS([[AudioSessionCategoryUIWebViewDelegate alloc] init]);
     uiWebView.get().delegate = uiDelegate.get();
 
+    EXPECT_EQ([[getAVAudioSessionClass() sharedInstance] routeSharingPolicy], AVAudioSessionRouteSharingPolicyDefault);
+
     [uiWebView loadRequest:[NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"video-with-audio" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]];
 
     Util::run(&didBeginPlaying);
 
     waitUntilAudioSessionCategoryIsEqualTo(getAVAudioSessionCategoryPlayback());
     EXPECT_WK_STREQ(getAVAudioSessionCategoryPlayback(), [[getAVAudioSessionClass() sharedInstance] category]);
+    EXPECT_EQ([[getAVAudioSessionClass() sharedInstance] routeSharingPolicy], routeSharingPolicyLongFormVideo());
 
     didBeginPlaying = false;
 
@@ -99,6 +120,7 @@ TEST(WebKitLegacy, AudioSessionCategoryIOS)
 
     waitUntilAudioSessionCategoryIsEqualTo(getAVAudioSessionCategoryAmbient());
     EXPECT_WK_STREQ(getAVAudioSessionCategoryAmbient(), [[getAVAudioSessionClass() sharedInstance] category]);
+    EXPECT_EQ([[getAVAudioSessionClass() sharedInstance] routeSharingPolicy], AVAudioSessionRouteSharingPolicyDefault);
 
     didBeginPlaying = false;
 
@@ -108,6 +130,7 @@ TEST(WebKitLegacy, AudioSessionCategoryIOS)
 
     waitUntilAudioSessionCategoryIsEqualTo(getAVAudioSessionCategoryAmbient());
     EXPECT_WK_STREQ(getAVAudioSessionCategoryAmbient(), [[getAVAudioSessionClass() sharedInstance] category]);
+    EXPECT_EQ([[getAVAudioSessionClass() sharedInstance] routeSharingPolicy], AVAudioSessionRouteSharingPolicyDefault);
 
     didBeginPlaying = false;
 
@@ -117,6 +140,7 @@ TEST(WebKitLegacy, AudioSessionCategoryIOS)
 
     waitUntilAudioSessionCategoryIsEqualTo(getAVAudioSessionCategoryAmbient());
     EXPECT_WK_STREQ(getAVAudioSessionCategoryAmbient(), [[getAVAudioSessionClass() sharedInstance] category]);
+    EXPECT_EQ([[getAVAudioSessionClass() sharedInstance] routeSharingPolicy], AVAudioSessionRouteSharingPolicyDefault);
 
     didBeginPlaying = false;
 
@@ -126,6 +150,17 @@ TEST(WebKitLegacy, AudioSessionCategoryIOS)
 
     waitUntilAudioSessionCategoryIsEqualTo(getAVAudioSessionCategoryPlayback());
     EXPECT_WK_STREQ(getAVAudioSessionCategoryPlayback(), [[getAVAudioSessionClass() sharedInstance] category]);
+    EXPECT_EQ([[getAVAudioSessionClass() sharedInstance] routeSharingPolicy], routeSharingPolicyLongFormVideo());
+
+    didBeginPlaying = false;
+
+    [uiWebView loadRequest:[NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"audio-only" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]];
+
+    Util::run(&didBeginPlaying);
+
+    waitUntilAudioSessionCategoryIsEqualTo(getAVAudioSessionCategoryPlayback());
+    EXPECT_WK_STREQ(getAVAudioSessionCategoryPlayback(), [[getAVAudioSessionClass() sharedInstance] category]);
+    EXPECT_EQ([[getAVAudioSessionClass() sharedInstance] routeSharingPolicy], routeSharingPolicyLongFormAudio());
 }
 
 }