Title: [248962] trunk/Source/WebCore
Revision
248962
Author
[email protected]
Date
2019-08-21 14:29:52 -0700 (Wed, 21 Aug 2019)

Log Message

Adopt AVSystemController_ActiveAudioRouteDidChangeNotification
https://bugs.webkit.org/show_bug.cgi?id=200992
<rdar://problem/54408993>

Reviewed by Eric Carlson.

When the system notifies us that the active audio route has changed in such a way
that necessitates pausing, pause all media sessions, exempting those that are
associated with WebRTC, since "pausing" an active audio conference isn't really
possible.

* Modules/mediastream/MediaStream.h:
* platform/audio/PlatformMediaSession.cpp:
(WebCore::PlatformMediaSession::shouldOverridePauseDuringRouteChange const):
* platform/audio/PlatformMediaSession.h:
(WebCore::PlatformMediaSessionClient::shouldOverridePauseDuringRouteChange const):
* platform/audio/ios/MediaSessionManagerIOS.h:
* platform/audio/ios/MediaSessionManagerIOS.mm:
(WebCore::MediaSessionManageriOS::activeRouteDidChange):
(-[WebMediaSessionHelper initWithCallback:]):
(-[WebMediaSessionHelper activeAudioRouteDidChange:]):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (248961 => 248962)


--- trunk/Source/WebCore/ChangeLog	2019-08-21 20:26:54 UTC (rev 248961)
+++ trunk/Source/WebCore/ChangeLog	2019-08-21 21:29:52 UTC (rev 248962)
@@ -1,3 +1,27 @@
+2019-08-21  Jer Noble  <[email protected]>
+
+        Adopt AVSystemController_ActiveAudioRouteDidChangeNotification
+        https://bugs.webkit.org/show_bug.cgi?id=200992
+        <rdar://problem/54408993>
+
+        Reviewed by Eric Carlson.
+
+        When the system notifies us that the active audio route has changed in such a way
+        that necessitates pausing, pause all media sessions, exempting those that are
+        associated with WebRTC, since "pausing" an active audio conference isn't really
+        possible.
+
+        * Modules/mediastream/MediaStream.h:
+        * platform/audio/PlatformMediaSession.cpp:
+        (WebCore::PlatformMediaSession::shouldOverridePauseDuringRouteChange const):
+        * platform/audio/PlatformMediaSession.h:
+        (WebCore::PlatformMediaSessionClient::shouldOverridePauseDuringRouteChange const):
+        * platform/audio/ios/MediaSessionManagerIOS.h:
+        * platform/audio/ios/MediaSessionManagerIOS.mm:
+        (WebCore::MediaSessionManageriOS::activeRouteDidChange):
+        (-[WebMediaSessionHelper initWithCallback:]):
+        (-[WebMediaSessionHelper activeAudioRouteDidChange:]):
+
 2019-08-21  Ryosuke Niwa  <[email protected]>
 
         Put keygen element behind a runtime flag and disable it by default

Modified: trunk/Source/WebCore/Modules/mediastream/MediaStream.h (248961 => 248962)


--- trunk/Source/WebCore/Modules/mediastream/MediaStream.h	2019-08-21 20:26:54 UTC (rev 248961)
+++ trunk/Source/WebCore/Modules/mediastream/MediaStream.h	2019-08-21 21:29:52 UTC (rev 248962)
@@ -159,6 +159,7 @@
     bool canProduceAudio() const final;
     Document* hostingDocument() const final { return document(); }
     bool processingUserGestureForMedia() const final;
+    bool shouldOverridePauseDuringRouteChange() const { return true; }
 
     // ActiveDOMObject API.
     void stop() final;

Modified: trunk/Source/WebCore/platform/audio/PlatformMediaSession.cpp (248961 => 248962)


--- trunk/Source/WebCore/platform/audio/PlatformMediaSession.cpp	2019-08-21 20:26:54 UTC (rev 248961)
+++ trunk/Source/WebCore/platform/audio/PlatformMediaSession.cpp	2019-08-21 21:29:52 UTC (rev 248962)
@@ -393,6 +393,11 @@
     return m_client.hasMediaStreamSource() && otherSession.m_client.hasMediaStreamSource();
 }
 
+bool PlatformMediaSession::shouldOverridePauseDuringRouteChange() const
+{
+    return m_client.shouldOverridePauseDuringRouteChange();
+}
+
 #if !RELEASE_LOG_DISABLED
 WTFLogChannel& PlatformMediaSession::logChannel() const
 {

Modified: trunk/Source/WebCore/platform/audio/PlatformMediaSession.h (248961 => 248962)


--- trunk/Source/WebCore/platform/audio/PlatformMediaSession.h	2019-08-21 20:26:54 UTC (rev 248961)
+++ trunk/Source/WebCore/platform/audio/PlatformMediaSession.h	2019-08-21 21:29:52 UTC (rev 248962)
@@ -192,6 +192,7 @@
 #endif
 
     bool canPlayConcurrently(const PlatformMediaSession&) const;
+    bool shouldOverridePauseDuringRouteChange() const;
 
 protected:
     PlatformMediaSessionClient& client() const { return m_client; }
@@ -261,6 +262,8 @@
 
     virtual void processIsSuspendedChanged() { }
 
+    virtual bool shouldOverridePauseDuringRouteChange() const { return false; }
+
 protected:
     virtual ~PlatformMediaSessionClient() = default;
 };

Modified: trunk/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.h (248961 => 248962)


--- trunk/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.h	2019-08-21 20:26:54 UTC (rev 248961)
+++ trunk/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.h	2019-08-21 21:29:52 UTC (rev 248962)
@@ -50,6 +50,7 @@
 #if HAVE(CELESTIAL)
     void carPlayServerDied();
     void updateCarPlayIsConnected(Optional<bool>&&);
+    void activeRouteDidChange(Optional<bool>&&);
 #endif
 
 private:

Modified: trunk/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm (248961 => 248962)


--- trunk/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm	2019-08-21 20:26:54 UTC (rev 248961)
+++ trunk/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm	2019-08-21 21:29:52 UTC (rev 248962)
@@ -60,6 +60,8 @@
 SOFT_LINK_CONSTANT_MAY_FAIL(Celestial, AVSystemController_CarPlayIsConnectedDidChangeNotification, NSString *)
 SOFT_LINK_CONSTANT_MAY_FAIL(Celestial, AVSystemController_CarPlayIsConnectedNotificationParameter, NSString *)
 SOFT_LINK_CONSTANT_MAY_FAIL(Celestial, AVSystemController_ServerConnectionDiedNotification, NSString *)
+SOFT_LINK_CONSTANT_MAY_FAIL(Celestial, AVSystemController_ActiveAudioRouteDidChangeNotification, NSString *)
+SOFT_LINK_CONSTANT_MAY_FAIL(Celestial, AVSystemController_ActiveAudioRouteDidChangeNotificationParameter_ShouldPause, NSString *)
 #endif
 
 using namespace WebCore;
@@ -223,6 +225,17 @@
 
     setIsPlayingToAutomotiveHeadUnit([[[getAVSystemControllerClass() sharedAVSystemController] attributeForKey:getAVSystemController_CarPlayIsConnectedAttribute()] boolValue]);
 }
+
+void MediaSessionManageriOS::activeRouteDidChange(Optional<bool>&& shouldPause)
+{
+    if (!shouldPause || !shouldPause.value())
+        return;
+
+    forEachSession([](auto& session) {
+        if (!session.shouldOverridePauseDuringRouteChange())
+            session.pauseSession();
+    });
+}
 #endif
 
 } // namespace WebCore
@@ -254,6 +267,8 @@
         [center addObserver:self selector:@selector(carPlayServerDied:) name:getAVSystemController_ServerConnectionDiedNotification() object:nil];
     if (canLoadAVSystemController_CarPlayIsConnectedDidChangeNotification())
         [center addObserver:self selector:@selector(carPlayIsConnectedDidChange:) name:getAVSystemController_CarPlayIsConnectedDidChangeNotification() object:nil];
+    if (canLoadAVSystemController_ActiveAudioRouteDidChangeNotification())
+        [center addObserver:self selector:@selector(activeAudioRouteDidChange:) name:getAVSystemController_ActiveAudioRouteDidChangeNotification() object:nil];
 #endif
 
     // Now playing won't work unless we turn on the delivery of remote control events.
@@ -484,6 +499,26 @@
             callback->updateCarPlayIsConnected(WTFMove(carPlayIsConnected));
     });
 }
+
+- (void)activeAudioRouteDidChange:(NSNotification *)notification
+{
+    if (!_callback)
+        return;
+
+    UNUSED_PARAM(notification);
+    Optional<bool> shouldPause;
+    if (notification && canLoadAVSystemController_ActiveAudioRouteDidChangeNotificationParameter_ShouldPause()) {
+        NSNumber* nsShouldPause = [notification.userInfo valueForKey:getAVSystemController_ActiveAudioRouteDidChangeNotificationParameter_ShouldPause()];
+        if (nsShouldPause)
+            shouldPause = nsShouldPause.boolValue;
+    }
+
+    callOnWebThreadOrDispatchAsyncOnMainThread([protectedSelf = retainPtr(self), shouldPause = WTFMove(shouldPause)]() mutable {
+        if (auto* callback = protectedSelf->_callback)
+            callback->activeRouteDidChange(WTFMove(shouldPause));
+    });
+
+}
 #endif // HAVE(CELESTIAL)
 @end
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to