Title: [275417] trunk
Revision
275417
Author
[email protected]
Date
2021-04-02 06:19:00 -0700 (Fri, 02 Apr 2021)

Log Message

No audio output when unplugged wired headset during a call
https://bugs.webkit.org/show_bug.cgi?id=216389
<rdar://problem/68692800>

Reviewed by Eric Carlson.

Source/WebCore:

Implement shouldOverridePauseDuringRouteChange for media elements.
If it is a media stream backed video element, do not pause on active audio route change.

Implement internal API to write a layout test.

Refactoring to share more code between WebCore and WebKit and implement the internal API.
Improve isolation of MediaSessionHelper by moving all its members from protected to private.

Test: fast/mediastream/MediaStream-video-element-change-audio-route.html

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::shouldOverridePauseDuringRouteChange const):
* html/HTMLMediaElement.h:
* platform/audio/ios/MediaSessionHelperIOS.h:
(WebCore::MediaSessionHelper::MediaSessionHelper):
* platform/audio/ios/MediaSessionHelperIOS.mm:
(MediaSessionHelper::activeAudioRouteDidChange):
(MediaSessionHelper::applicationWillEnterForeground):
(MediaSessionHelper::applicationDidEnterBackground):
(MediaSessionHelper::applicationWillBecomeInactive):
(MediaSessionHelper::applicationDidBecomeActive):
(MediaSessionHelper::mediaServerConnectionDied):
(MediaSessionHelper::externalOutputDeviceAvailableDidChange):
(MediaSessionHelper::isPlayingToAutomotiveHeadUnitDidChange):
(MediaSessionHelper::activeVideoRouteDidChange):
(MediaSessionHelper::startMonitoringWirelessRoutes):
(MediaSessionHelper::stopMonitoringWirelessRoutes):
(MediaSessionHelperiOS::MediaSessionHelperiOS):
(MediaSessionHelperiOS::startMonitoringWirelessRoutesInternal):
(MediaSessionHelperiOS::stopMonitoringWirelessRoutesInternal):
(MediaSessionHelperiOS::mediaServerConnectionDied):
(MediaSessionHelperiOS::setIsPlayingToAutomotiveHeadUnit):
(MediaSessionHelperiOS::activeAudioRouteDidChange):
(MediaSessionHelperiOS::activeVideoRouteDidChange):
(MediaSessionHelperiOS::externalOutputDeviceAvailableDidChange):
(MediaSessionHelperiOS::startMonitoringWirelessRoutes): Deleted.
(MediaSessionHelperiOS::stopMonitoringWirelessRoutes): Deleted.
(MediaSessionHelperiOS::applicationDidBecomeActive): Deleted.
(MediaSessionHelperiOS::applicationDidEnterBackground): Deleted.
(MediaSessionHelperiOS::applicationWillBecomeInactive): Deleted.
(MediaSessionHelperiOS::applicationWillEnterForeground): Deleted.
* testing/Internals.cpp:
(WebCore::Internals::activeAudioRouteDidChange):
* testing/Internals.h:
* testing/Internals.idl:

Source/WebKit:

Make use of WebCore methods instead of reimplementing them here.

* WebProcess/GPU/media/ios/RemoteMediaSessionHelper.cpp:
(WebKit::RemoteMediaSessionHelper::startMonitoringWirelessRoutesInternal):
(WebKit::RemoteMediaSessionHelper::stopMonitoringWirelessRoutesInternal):
(WebKit::RemoteMediaSessionHelper::activeVideoRouteDidChange):
(WebKit::RemoteMediaSessionHelper::startMonitoringWirelessRoutes): Deleted.
(WebKit::RemoteMediaSessionHelper::stopMonitoringWirelessRoutes): Deleted.
(WebKit::RemoteMediaSessionHelper::applicationWillEnterForeground): Deleted.
(WebKit::RemoteMediaSessionHelper::applicationDidEnterBackground): Deleted.
(WebKit::RemoteMediaSessionHelper::applicationWillBecomeInactive): Deleted.
(WebKit::RemoteMediaSessionHelper::applicationDidBecomeActive): Deleted.
(WebKit::RemoteMediaSessionHelper::externalOutputDeviceAvailableDidChange): Deleted.
(WebKit::RemoteMediaSessionHelper::isPlayingToAutomotiveHeadUnitDidChange): Deleted.
(WebKit::RemoteMediaSessionHelper::activeAudioRouteDidChange): Deleted.
* WebProcess/GPU/media/ios/RemoteMediaSessionHelper.h:

LayoutTests:

* fast/mediastream/MediaStream-video-element-change-audio-route-expected.txt: Added.
* fast/mediastream/MediaStream-video-element-change-audio-route.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (275416 => 275417)


--- trunk/LayoutTests/ChangeLog	2021-04-02 10:59:39 UTC (rev 275416)
+++ trunk/LayoutTests/ChangeLog	2021-04-02 13:19:00 UTC (rev 275417)
@@ -1,3 +1,14 @@
+2021-04-02  Youenn Fablet  <[email protected]>
+
+        No audio output when unplugged wired headset during a call
+        https://bugs.webkit.org/show_bug.cgi?id=216389
+        <rdar://problem/68692800>
+
+        Reviewed by Eric Carlson.
+
+        * fast/mediastream/MediaStream-video-element-change-audio-route-expected.txt: Added.
+        * fast/mediastream/MediaStream-video-element-change-audio-route.html: Added.
+
 2021-04-02  Sergio Villar Senin  <[email protected]>
 
         [css-flexbox] align-content issues

Added: trunk/LayoutTests/fast/mediastream/MediaStream-video-element-change-audio-route-expected.txt (0 => 275417)


--- trunk/LayoutTests/fast/mediastream/MediaStream-video-element-change-audio-route-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/mediastream/MediaStream-video-element-change-audio-route-expected.txt	2021-04-02 13:19:00 UTC (rev 275417)
@@ -0,0 +1,4 @@
+
+
+PASS MediaStream video should not be paused when audio route changes
+

Added: trunk/LayoutTests/fast/mediastream/MediaStream-video-element-change-audio-route.html (0 => 275417)


--- trunk/LayoutTests/fast/mediastream/MediaStream-video-element-change-audio-route.html	                        (rev 0)
+++ trunk/LayoutTests/fast/mediastream/MediaStream-video-element-change-audio-route.html	2021-04-02 13:19:00 UTC (rev 275417)
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <meta charset="utf-8">
+    <title>Change of audio route</title>
+    <script src=""
+    <script src=""
+</head>
+<body>
+    <video id="video" autoplay playsInline></video>
+    <script>
+promise_test(async (test) => {
+    video.srcObject = await navigator.mediaDevices.getUserMedia({ audio: true, video: true });
+
+    await video.play();
+
+    if (window.internals)
+        internals.activeAudioRouteDidChange(true);
+
+    await new Promise(resolve => setTimeout(resolve, 50));
+    assert_false(video.paused, "video paused");
+}, "MediaStream video should not be paused when audio route changes");
+    </script>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (275416 => 275417)


--- trunk/Source/WebCore/ChangeLog	2021-04-02 10:59:39 UTC (rev 275416)
+++ trunk/Source/WebCore/ChangeLog	2021-04-02 13:19:00 UTC (rev 275417)
@@ -1,5 +1,59 @@
 2021-04-02  Youenn Fablet  <[email protected]>
 
+        No audio output when unplugged wired headset during a call
+        https://bugs.webkit.org/show_bug.cgi?id=216389
+        <rdar://problem/68692800>
+
+        Reviewed by Eric Carlson.
+
+        Implement shouldOverridePauseDuringRouteChange for media elements.
+        If it is a media stream backed video element, do not pause on active audio route change.
+
+        Implement internal API to write a layout test.
+
+        Refactoring to share more code between WebCore and WebKit and implement the internal API.
+        Improve isolation of MediaSessionHelper by moving all its members from protected to private.
+
+        Test: fast/mediastream/MediaStream-video-element-change-audio-route.html
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::shouldOverridePauseDuringRouteChange const):
+        * html/HTMLMediaElement.h:
+        * platform/audio/ios/MediaSessionHelperIOS.h:
+        (WebCore::MediaSessionHelper::MediaSessionHelper):
+        * platform/audio/ios/MediaSessionHelperIOS.mm:
+        (MediaSessionHelper::activeAudioRouteDidChange):
+        (MediaSessionHelper::applicationWillEnterForeground):
+        (MediaSessionHelper::applicationDidEnterBackground):
+        (MediaSessionHelper::applicationWillBecomeInactive):
+        (MediaSessionHelper::applicationDidBecomeActive):
+        (MediaSessionHelper::mediaServerConnectionDied):
+        (MediaSessionHelper::externalOutputDeviceAvailableDidChange):
+        (MediaSessionHelper::isPlayingToAutomotiveHeadUnitDidChange):
+        (MediaSessionHelper::activeVideoRouteDidChange):
+        (MediaSessionHelper::startMonitoringWirelessRoutes):
+        (MediaSessionHelper::stopMonitoringWirelessRoutes):
+        (MediaSessionHelperiOS::MediaSessionHelperiOS):
+        (MediaSessionHelperiOS::startMonitoringWirelessRoutesInternal):
+        (MediaSessionHelperiOS::stopMonitoringWirelessRoutesInternal):
+        (MediaSessionHelperiOS::mediaServerConnectionDied):
+        (MediaSessionHelperiOS::setIsPlayingToAutomotiveHeadUnit):
+        (MediaSessionHelperiOS::activeAudioRouteDidChange):
+        (MediaSessionHelperiOS::activeVideoRouteDidChange):
+        (MediaSessionHelperiOS::externalOutputDeviceAvailableDidChange):
+        (MediaSessionHelperiOS::startMonitoringWirelessRoutes): Deleted.
+        (MediaSessionHelperiOS::stopMonitoringWirelessRoutes): Deleted.
+        (MediaSessionHelperiOS::applicationDidBecomeActive): Deleted.
+        (MediaSessionHelperiOS::applicationDidEnterBackground): Deleted.
+        (MediaSessionHelperiOS::applicationWillBecomeInactive): Deleted.
+        (MediaSessionHelperiOS::applicationWillEnterForeground): Deleted.
+        * testing/Internals.cpp:
+        (WebCore::Internals::activeAudioRouteDidChange):
+        * testing/Internals.h:
+        * testing/Internals.idl:
+
+2021-04-02  Youenn Fablet  <[email protected]>
+
         Start observing outgoing audio/video sources asynchronously
         https://bugs.webkit.org/show_bug.cgi?id=224040
 

Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (275416 => 275417)


--- trunk/Source/WebCore/html/HTMLMediaElement.cpp	2021-04-02 10:59:39 UTC (rev 275416)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp	2021-04-02 13:19:00 UTC (rev 275417)
@@ -7661,6 +7661,15 @@
     updateSleepDisabling();
 }
 
+bool HTMLMediaElement::shouldOverridePauseDuringRouteChange() const
+{
+#if ENABLE(MEDIA_STREAM)
+    return hasMediaStreamSrcObject();
+#else
+    return false;
+#endif
+}
+
 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
 
 void HTMLMediaElement::scheduleUpdateMediaState()

Modified: trunk/Source/WebCore/html/HTMLMediaElement.h (275416 => 275417)


--- trunk/Source/WebCore/html/HTMLMediaElement.h	2021-04-02 10:59:39 UTC (rev 275416)
+++ trunk/Source/WebCore/html/HTMLMediaElement.h	2021-04-02 13:19:00 UTC (rev 275417)
@@ -872,6 +872,7 @@
     bool canProduceAudio() const final;
     bool hasMediaStreamSource() const final;
     void processIsSuspendedChanged() final;
+    bool shouldOverridePauseDuringRouteChange() const final;
 
     void pageMutedStateDidChange() override;
 

Modified: trunk/Source/WebCore/platform/audio/ios/MediaSessionHelperIOS.h (275416 => 275417)


--- trunk/Source/WebCore/platform/audio/ios/MediaSessionHelperIOS.h	2021-04-02 10:59:39 UTC (rev 275416)
+++ trunk/Source/WebCore/platform/audio/ios/MediaSessionHelperIOS.h	2021-04-02 13:19:00 UTC (rev 275417)
@@ -65,15 +65,18 @@
     static void resetSharedHelper();
 
     MediaSessionHelper() = default;
+    explicit MediaSessionHelper(bool isExternalOutputDeviceAvailable);
     virtual ~MediaSessionHelper() = default;
 
     void addClient(MediaSessionHelperClient&);
     void removeClient(MediaSessionHelperClient&);
 
-    virtual void startMonitoringWirelessRoutes() = 0;
-    virtual void stopMonitoringWirelessRoutes() = 0;
+    void startMonitoringWirelessRoutes();
+    void stopMonitoringWirelessRoutes();
     virtual void providePresentingApplicationPID(int) = 0;
 
+    void setIsExternalOutputDeviceAvailable(bool);
+
     bool isMonitoringWirelessRoutes() const { return m_monitoringWirelessRoutesCount; }
     bool isExternalOutputDeviceAvailable() const { return m_isExternalOutputDeviceAvailable; }
     bool activeVideoRouteSupportsAirPlayVideo() const { return m_activeVideoRouteSupportsAirPlayVideo; }
@@ -81,15 +84,46 @@
 
     MediaPlaybackTarget* playbackTarget() const { return m_playbackTarget.get(); }
 
+    using HasAvailableTargets = MediaSessionHelperClient::HasAvailableTargets;
+    using PlayingToAutomotiveHeadUnit = MediaSessionHelperClient::PlayingToAutomotiveHeadUnit;
+    using ShouldPause = MediaSessionHelperClient::ShouldPause;
+    using SupportsAirPlayVideo = MediaSessionHelperClient::SupportsAirPlayVideo;
+    using SuspendedUnderLock = MediaSessionHelperClient::SuspendedUnderLock;
+
+    void activeAudioRouteDidChange(ShouldPause);
+    void applicationWillEnterForeground(SuspendedUnderLock);
+    void applicationDidEnterBackground(SuspendedUnderLock);
+    void applicationWillBecomeInactive();
+    void applicationDidBecomeActive();
+    void mediaServerConnectionDied();
+
 protected:
+    void externalOutputDeviceAvailableDidChange(HasAvailableTargets);
+    void isPlayingToAutomotiveHeadUnitDidChange(PlayingToAutomotiveHeadUnit);
+    void activeVideoRouteDidChange(SupportsAirPlayVideo, Ref<MediaPlaybackTarget>&&);
+
+private:
+    virtual void startMonitoringWirelessRoutesInternal() = 0;
+    virtual void stopMonitoringWirelessRoutesInternal() = 0;
+
     WeakHashSet<MediaSessionHelperClient> m_clients;
+    bool m_isExternalOutputDeviceAvailable { false };
     uint32_t m_monitoringWirelessRoutesCount { 0 };
-    bool m_isExternalOutputDeviceAvailable { false };
     bool m_activeVideoRouteSupportsAirPlayVideo { false };
     bool m_isPlayingToAutomotiveHeadUnit { false };
     RefPtr<MediaPlaybackTarget> m_playbackTarget;
 };
 
+inline MediaSessionHelper::MediaSessionHelper(bool isExternalOutputDeviceAvailable)
+    : m_isExternalOutputDeviceAvailable(isExternalOutputDeviceAvailable)
+{
 }
 
+inline void MediaSessionHelper::setIsExternalOutputDeviceAvailable(bool isExternalOutputDeviceAvailable)
+{
+    m_isExternalOutputDeviceAvailable = isExternalOutputDeviceAvailable;
+}
+
+}
+
 #endif

Modified: trunk/Source/WebCore/platform/audio/ios/MediaSessionHelperIOS.mm (275416 => 275417)


--- trunk/Source/WebCore/platform/audio/ios/MediaSessionHelperIOS.mm	2021-04-02 10:59:39 UTC (rev 275416)
+++ trunk/Source/WebCore/platform/audio/ios/MediaSessionHelperIOS.mm	2021-04-02 13:19:00 UTC (rev 275417)
@@ -96,10 +96,6 @@
     ~MediaSessionHelperiOS();
 
     void externalOutputDeviceAvailableDidChange();
-    void applicationWillEnterForeground(MediaSessionHelperClient::SuspendedUnderLock);
-    void applicationDidEnterBackground(MediaSessionHelperClient::SuspendedUnderLock);
-    void applicationWillBecomeInactive();
-    void applicationDidBecomeActive();
 #if HAVE(CELESTIAL)
     void mediaServerConnectionDied();
     void updateCarPlayIsConnected(Optional<bool>&&);
@@ -110,17 +106,11 @@
 #endif
 
 private:
-    using HasAvailableTargets = MediaSessionHelperClient::HasAvailableTargets;
-    using PlayingToAutomotiveHeadUnit = MediaSessionHelperClient::PlayingToAutomotiveHeadUnit;
-    using ShouldPause = MediaSessionHelperClient::ShouldPause;
-    using SupportsAirPlayVideo = MediaSessionHelperClient::SupportsAirPlayVideo;
-    using SuspendedUnderLock = MediaSessionHelperClient::SuspendedUnderLock;
-
     void setIsPlayingToAutomotiveHeadUnit(bool);
 
     void providePresentingApplicationPID(int) final;
-    void startMonitoringWirelessRoutes() final;
-    void stopMonitoringWirelessRoutes() final;
+    void startMonitoringWirelessRoutesInternal() final;
+    void stopMonitoringWirelessRoutesInternal() final;
 
     RetainPtr<WebMediaSessionHelper> m_objcObserver;
 #if HAVE(CELESTIAL)
@@ -166,11 +156,92 @@
     m_clients.remove(client);
 }
 
+void MediaSessionHelper::activeAudioRouteDidChange(ShouldPause shouldPause)
+{
+    for (auto& client : m_clients)
+        client.activeAudioRouteDidChange(shouldPause);
+}
+
+void MediaSessionHelper::applicationWillEnterForeground(SuspendedUnderLock suspendedUnderLock)
+{
+    for (auto& client : m_clients)
+        client.applicationWillEnterForeground(suspendedUnderLock);
+}
+
+void MediaSessionHelper::applicationDidEnterBackground(SuspendedUnderLock suspendedUnderLock)
+{
+    for (auto& client : m_clients)
+        client.applicationDidEnterBackground(suspendedUnderLock);
+}
+
+void MediaSessionHelper::applicationWillBecomeInactive()
+{
+    for (auto& client : m_clients)
+        client.applicationWillBecomeInactive();
+}
+
+void MediaSessionHelper::applicationDidBecomeActive()
+{
+    for (auto& client : m_clients)
+        client.applicationDidBecomeActive();
+}
+
+void MediaSessionHelper::mediaServerConnectionDied()
+{
+    for (auto& client : m_clients)
+        client.mediaServerConnectionDied();
+}
+
+void MediaSessionHelper::externalOutputDeviceAvailableDidChange(HasAvailableTargets hasAvailableTargets)
+{
+    m_isExternalOutputDeviceAvailable = hasAvailableTargets == HasAvailableTargets::Yes;
+    for (auto& client : m_clients)
+        client.externalOutputDeviceAvailableDidChange(hasAvailableTargets);
+}
+
+void MediaSessionHelper::isPlayingToAutomotiveHeadUnitDidChange(PlayingToAutomotiveHeadUnit playingToAutomotiveHeadUnit)
+{
+    bool newValue = playingToAutomotiveHeadUnit == PlayingToAutomotiveHeadUnit::Yes;
+    if (newValue == m_isPlayingToAutomotiveHeadUnit)
+        return;
+
+    m_isPlayingToAutomotiveHeadUnit = newValue;
+    for (auto& client : m_clients)
+        client.isPlayingToAutomotiveHeadUnitDidChange(playingToAutomotiveHeadUnit);
+}
+
+void MediaSessionHelper::activeVideoRouteDidChange(SupportsAirPlayVideo supportsAirPlayVideo, Ref<MediaPlaybackTarget>&& playbackTarget)
+{
+    m_playbackTarget = WTFMove(playbackTarget);
+    m_activeVideoRouteSupportsAirPlayVideo = supportsAirPlayVideo == SupportsAirPlayVideo::Yes;
+    for (auto& client : m_clients)
+        client.activeVideoRouteDidChange(supportsAirPlayVideo, *m_playbackTarget);
+}
+
+void MediaSessionHelper::startMonitoringWirelessRoutes()
+{
+    if (m_monitoringWirelessRoutesCount++)
+        return;
+    startMonitoringWirelessRoutesInternal();
+}
+
+void MediaSessionHelper::stopMonitoringWirelessRoutes()
+{
+    if (!m_monitoringWirelessRoutesCount) {
+        ASSERT_NOT_REACHED();
+        return;
+    }
+
+    if (--m_monitoringWirelessRoutesCount)
+        return;
+    stopMonitoringWirelessRoutesInternal();
+}
+
 MediaSessionHelperiOS::MediaSessionHelperiOS()
 {
     BEGIN_BLOCK_OBJC_EXCEPTIONS
     m_objcObserver = adoptNS([[WebMediaSessionHelper alloc] initWithCallback:this]);
-    m_isExternalOutputDeviceAvailable = [m_objcObserver hasWirelessTargetsAvailable];
+    setIsExternalOutputDeviceAvailable([m_objcObserver hasWirelessTargetsAvailable]);
     END_BLOCK_OBJC_EXCEPTIONS
 
 #if HAVE(CELESTIAL)
@@ -207,11 +278,8 @@
 #endif
 }
 
-void MediaSessionHelperiOS::startMonitoringWirelessRoutes()
+void MediaSessionHelperiOS::startMonitoringWirelessRoutesInternal()
 {
-    if (m_monitoringWirelessRoutesCount++)
-        return;
-
     BEGIN_BLOCK_OBJC_EXCEPTIONS
 #if !PLATFORM(WATCHOS)
     [m_objcObserver startMonitoringAirPlayRoutes];
@@ -219,16 +287,8 @@
     END_BLOCK_OBJC_EXCEPTIONS
 }
 
-void MediaSessionHelperiOS::stopMonitoringWirelessRoutes()
+void MediaSessionHelperiOS::stopMonitoringWirelessRoutesInternal()
 {
-    if (!m_monitoringWirelessRoutesCount) {
-        ASSERT_NOT_REACHED();
-        return;
-    }
-
-    if (--m_monitoringWirelessRoutesCount)
-        return;
-
     BEGIN_BLOCK_OBJC_EXCEPTIONS
 #if !PLATFORM(WATCHOS)
     [m_objcObserver stopMonitoringAirPlayRoutes];
@@ -249,8 +309,7 @@
         return;
 
     m_havePresentedApplicationPID = false;
-    for (auto& client : m_clients)
-        client.mediaServerConnectionDied();
+    MediaSessionHelper::mediaServerConnectionDied();
 }
 
 void MediaSessionHelperiOS::updateCarPlayIsConnected(Optional<bool>&& carPlayIsConnected)
@@ -270,12 +329,7 @@
 
 void MediaSessionHelperiOS::setIsPlayingToAutomotiveHeadUnit(bool isPlaying)
 {
-    if (isPlaying == m_isPlayingToAutomotiveHeadUnit)
-        return;
-
-    m_isPlayingToAutomotiveHeadUnit = isPlaying;
-    for (auto& client : m_clients)
-        client.isPlayingToAutomotiveHeadUnitDidChange(m_isPlayingToAutomotiveHeadUnit ? PlayingToAutomotiveHeadUnit::Yes : PlayingToAutomotiveHeadUnit::No);
+    isPlayingToAutomotiveHeadUnitDidChange(isPlaying ? PlayingToAutomotiveHeadUnit::Yes : PlayingToAutomotiveHeadUnit::No);
 }
 #endif // HAVE(CELESTIAL)
 
@@ -282,51 +336,25 @@
 #if PLATFORM(IOS_FAMILY) && !PLATFORM(IOS_FAMILY_SIMULATOR) && !PLATFORM(MACCATALYST) && !PLATFORM(WATCHOS)
 void MediaSessionHelperiOS::activeAudioRouteDidChange(bool shouldPause)
 {
-    for (auto& client : m_clients)
-        client.activeAudioRouteDidChange(shouldPause ? ShouldPause::Yes : ShouldPause::No);
+    MediaSessionHelper::activeAudioRouteDidChange(shouldPause ? ShouldPause::Yes : ShouldPause::No);
 }
 
 void MediaSessionHelperiOS::activeVideoRouteDidChange()
 {
-    m_playbackTarget = MediaPlaybackTargetCocoa::create();
-    m_activeVideoRouteSupportsAirPlayVideo = m_playbackTarget->supportsRemoteVideoPlayback();
-    for (auto& client : m_clients)
-        client.activeVideoRouteDidChange(m_activeVideoRouteSupportsAirPlayVideo ? SupportsAirPlayVideo::Yes : SupportsAirPlayVideo::No, *m_playbackTarget);
+    auto target = MediaPlaybackTargetCocoa::create();
+    auto supportsRemoteVideoPlayback = target->supportsRemoteVideoPlayback() ? SupportsAirPlayVideo::Yes : SupportsAirPlayVideo::No;
+    MediaSessionHelper::activeVideoRouteDidChange(supportsRemoteVideoPlayback, WTFMove(target));
 }
 #endif
 
-void MediaSessionHelperiOS::applicationDidBecomeActive()
-{
-    for (auto& client : m_clients)
-        client.applicationDidBecomeActive();
-}
-
-void MediaSessionHelperiOS::applicationDidEnterBackground(MediaSessionHelperClient::SuspendedUnderLock underLock)
-{
-    for (auto& client : m_clients)
-        client.applicationDidEnterBackground(underLock);
-}
-
-void MediaSessionHelperiOS::applicationWillBecomeInactive()
-{
-    for (auto& client : m_clients)
-        client.applicationWillBecomeInactive();
-}
-
-void MediaSessionHelperiOS::applicationWillEnterForeground(MediaSessionHelperClient::SuspendedUnderLock underLock)
-{
-    for (auto& client : m_clients)
-        client.applicationWillEnterForeground(underLock);
-}
-
 void MediaSessionHelperiOS::externalOutputDeviceAvailableDidChange()
 {
+    HasAvailableTargets hasAvailableTargets;
     BEGIN_BLOCK_OBJC_EXCEPTIONS
-    m_isExternalOutputDeviceAvailable = [m_objcObserver hasWirelessTargetsAvailable];
+    hasAvailableTargets = [m_objcObserver hasWirelessTargetsAvailable] ? HasAvailableTargets::Yes : HasAvailableTargets::No;
     END_BLOCK_OBJC_EXCEPTIONS
 
-    for (auto& client : m_clients)
-        client.externalOutputDeviceAvailableDidChange(m_isExternalOutputDeviceAvailable ? HasAvailableTargets::Yes : HasAvailableTargets::No);
+    MediaSessionHelper::externalOutputDeviceAvailableDidChange(hasAvailableTargets);
 }
 
 @implementation WebMediaSessionHelper

Modified: trunk/Source/WebCore/testing/Internals.cpp (275416 => 275417)


--- trunk/Source/WebCore/testing/Internals.cpp	2021-04-02 10:59:39 UTC (rev 275416)
+++ trunk/Source/WebCore/testing/Internals.cpp	2021-04-02 13:19:00 UTC (rev 275417)
@@ -328,6 +328,7 @@
 #endif
 
 #if PLATFORM(COCOA)
+#include "MediaSessionHelperIOS.h"
 #include "SystemBattery.h"
 #include "VP9UtilitiesCocoa.h"
 #include <pal/spi/cf/CoreTextSPI.h>
@@ -4327,6 +4328,15 @@
     return { };
 }
 
+void Internals::activeAudioRouteDidChange(bool shouldPause)
+{
+#if PLATFORM(IOS)
+    MediaSessionHelper::sharedHelper().activeAudioRouteDidChange(shouldPause ? MediaSessionHelperClient::ShouldPause::Yes : MediaSessionHelperClient::ShouldPause::No);
+#else
+    UNUSED_PARAM(shouldPause);
+#endif
+}
+
 bool Internals::elementIsBlockingDisplaySleep(HTMLMediaElement& element) const
 {
     return element.isDisablingSleep();

Modified: trunk/Source/WebCore/testing/Internals.h (275416 => 275417)


--- trunk/Source/WebCore/testing/Internals.h	2021-04-02 10:59:39 UTC (rev 275416)
+++ trunk/Source/WebCore/testing/Internals.h	2021-04-02 13:19:00 UTC (rev 275417)
@@ -684,6 +684,7 @@
     ExceptionOr<String> mediaSessionRestrictions(const String& mediaType) const;
     void setMediaElementRestrictions(HTMLMediaElement&, StringView restrictionsString);
     ExceptionOr<void> postRemoteControlCommand(const String&, float argument);
+    void activeAudioRouteDidChange(bool shouldPause);
     bool elementIsBlockingDisplaySleep(HTMLMediaElement&) const;
 #endif
 

Modified: trunk/Source/WebCore/testing/Internals.idl (275416 => 275417)


--- trunk/Source/WebCore/testing/Internals.idl	2021-04-02 10:59:39 UTC (rev 275416)
+++ trunk/Source/WebCore/testing/Internals.idl	2021-04-02 13:19:00 UTC (rev 275417)
@@ -721,6 +721,8 @@
     [Conditional=VIDEO] undefined setMediaElementRestrictions(HTMLMediaElement element, DOMString restrictions);
     [Conditional=WEB_AUDIO] undefined setAudioContextRestrictions((AudioContext or WebKitAudioContext) context, DOMString restrictions);
     [Conditional=VIDEO] undefined postRemoteControlCommand(DOMString command, optional unrestricted float argument = 0);
+    [Conditional=VIDEO] undefined activeAudioRouteDidChange(boolean shouldPause);
+
     [Conditional=WIRELESS_PLAYBACK_TARGET] undefined setMockMediaPlaybackTargetPickerEnabled(boolean enabled);
     [Conditional=WIRELESS_PLAYBACK_TARGET] undefined setMockMediaPlaybackTargetPickerState(DOMString deviceName, DOMString deviceState);
     [Conditional=WIRELESS_PLAYBACK_TARGET] undefined mockMediaPlaybackTargetPickerDismissPopup();

Modified: trunk/Source/WebKit/ChangeLog (275416 => 275417)


--- trunk/Source/WebKit/ChangeLog	2021-04-02 10:59:39 UTC (rev 275416)
+++ trunk/Source/WebKit/ChangeLog	2021-04-02 13:19:00 UTC (rev 275417)
@@ -1,5 +1,30 @@
 2021-04-02  Youenn Fablet  <[email protected]>
 
+        No audio output when unplugged wired headset during a call
+        https://bugs.webkit.org/show_bug.cgi?id=216389
+        <rdar://problem/68692800>
+
+        Reviewed by Eric Carlson.
+
+        Make use of WebCore methods instead of reimplementing them here.
+
+        * WebProcess/GPU/media/ios/RemoteMediaSessionHelper.cpp:
+        (WebKit::RemoteMediaSessionHelper::startMonitoringWirelessRoutesInternal):
+        (WebKit::RemoteMediaSessionHelper::stopMonitoringWirelessRoutesInternal):
+        (WebKit::RemoteMediaSessionHelper::activeVideoRouteDidChange):
+        (WebKit::RemoteMediaSessionHelper::startMonitoringWirelessRoutes): Deleted.
+        (WebKit::RemoteMediaSessionHelper::stopMonitoringWirelessRoutes): Deleted.
+        (WebKit::RemoteMediaSessionHelper::applicationWillEnterForeground): Deleted.
+        (WebKit::RemoteMediaSessionHelper::applicationDidEnterBackground): Deleted.
+        (WebKit::RemoteMediaSessionHelper::applicationWillBecomeInactive): Deleted.
+        (WebKit::RemoteMediaSessionHelper::applicationDidBecomeActive): Deleted.
+        (WebKit::RemoteMediaSessionHelper::externalOutputDeviceAvailableDidChange): Deleted.
+        (WebKit::RemoteMediaSessionHelper::isPlayingToAutomotiveHeadUnitDidChange): Deleted.
+        (WebKit::RemoteMediaSessionHelper::activeAudioRouteDidChange): Deleted.
+        * WebProcess/GPU/media/ios/RemoteMediaSessionHelper.h:
+
+2021-04-02  Youenn Fablet  <[email protected]>
+
         [MacOS] Enable NSURLSession WebSocket code path in WebKitTestRunner
         https://bugs.webkit.org/show_bug.cgi?id=220973
         <rdar://problem/73655870>

Modified: trunk/Source/WebKit/WebProcess/GPU/media/ios/RemoteMediaSessionHelper.cpp (275416 => 275417)


--- trunk/Source/WebKit/WebProcess/GPU/media/ios/RemoteMediaSessionHelper.cpp	2021-04-02 10:59:39 UTC (rev 275416)
+++ trunk/Source/WebKit/WebProcess/GPU/media/ios/RemoteMediaSessionHelper.cpp	2021-04-02 13:19:00 UTC (rev 275417)
@@ -67,24 +67,13 @@
     connectToGPUProcess();
 }
 
-void RemoteMediaSessionHelper::startMonitoringWirelessRoutes()
+void RemoteMediaSessionHelper::startMonitoringWirelessRoutesInternal()
 {
-    if (m_monitoringWirelessRoutesCount++)
-        return;
-
     connection().send(Messages::RemoteMediaSessionHelperProxy::StartMonitoringWirelessRoutes(), { });
 }
 
-void RemoteMediaSessionHelper::stopMonitoringWirelessRoutes()
+void RemoteMediaSessionHelper::stopMonitoringWirelessRoutesInternal()
 {
-    if (!m_monitoringWirelessRoutesCount) {
-        ASSERT_NOT_REACHED();
-        return;
-    }
-
-    if (--m_monitoringWirelessRoutesCount)
-        return;
-
     connection().send(Messages::RemoteMediaSessionHelperProxy::StopMonitoringWirelessRoutes(), { });
 }
 
@@ -93,60 +82,14 @@
     connection().send(Messages::RemoteMediaSessionHelperProxy::ProvidePresentingApplicationPID(pid), { });
 }
 
-void RemoteMediaSessionHelper::applicationWillEnterForeground(SuspendedUnderLock suspendedUnderLock)
-{
-    for (auto& client : m_clients)
-        client.applicationWillEnterForeground(suspendedUnderLock);
-}
-
-void RemoteMediaSessionHelper::applicationDidEnterBackground(SuspendedUnderLock suspendedUnderLock)
-{
-    for (auto& client : m_clients)
-        client.applicationDidEnterBackground(suspendedUnderLock);
-}
-
-void RemoteMediaSessionHelper::applicationWillBecomeInactive()
-{
-    for (auto& client : m_clients)
-        client.applicationWillBecomeInactive();
-}
-
-void RemoteMediaSessionHelper::applicationDidBecomeActive()
-{
-    for (auto& client : m_clients)
-        client.applicationDidBecomeActive();
-}
-
-void RemoteMediaSessionHelper::externalOutputDeviceAvailableDidChange(HasAvailableTargets hasAvailableTargets)
-{
-    for (auto& client : m_clients)
-        client.externalOutputDeviceAvailableDidChange(hasAvailableTargets);
-}
-
-void RemoteMediaSessionHelper::isPlayingToAutomotiveHeadUnitDidChange(PlayingToAutomotiveHeadUnit playingToAutomotiveHeadUnit)
-{
-    for (auto& client : m_clients)
-        client.isPlayingToAutomotiveHeadUnitDidChange(playingToAutomotiveHeadUnit);
-}
-
-void RemoteMediaSessionHelper::activeAudioRouteDidChange(ShouldPause shouldPause)
-{
-    for (auto& client : m_clients)
-        client.activeAudioRouteDidChange(shouldPause);
-}
-
 void RemoteMediaSessionHelper::activeVideoRouteDidChange(SupportsAirPlayVideo supportsAirPlayVideo, MediaPlaybackTargetContext&& targetContext)
 {
-    RefPtr<MediaPlaybackTarget> targetObject;
-    if (targetContext.type() == MediaPlaybackTargetContext::AVOutputContextType)
-        m_playbackTarget = WebCore::MediaPlaybackTargetCocoa::create(targetContext.avOutputContext());
-    else {
+    if (targetContext.type() != MediaPlaybackTargetContext::AVOutputContextType) {
         ASSERT_NOT_REACHED();
         return;
     }
 
-    for (auto& client : m_clients)
-        client.activeVideoRouteDidChange(supportsAirPlayVideo, *m_playbackTarget);
+    WebCore::MediaSessionHelper::activeVideoRouteDidChange(supportsAirPlayVideo, WebCore::MediaPlaybackTargetCocoa::create(targetContext.avOutputContext()));
 }
 
 }

Modified: trunk/Source/WebKit/WebProcess/GPU/media/ios/RemoteMediaSessionHelper.h (275416 => 275417)


--- trunk/Source/WebKit/WebProcess/GPU/media/ios/RemoteMediaSessionHelper.h	2021-04-02 10:59:39 UTC (rev 275416)
+++ trunk/Source/WebKit/WebProcess/GPU/media/ios/RemoteMediaSessionHelper.h	2021-04-02 13:19:00 UTC (rev 275417)
@@ -62,18 +62,11 @@
     void gpuProcessConnectionDidClose(GPUProcessConnection&) final;
 
     // MediaSessionHelper
-    void startMonitoringWirelessRoutes() final;
-    void stopMonitoringWirelessRoutes() final;
+    void startMonitoringWirelessRoutesInternal() final;
+    void stopMonitoringWirelessRoutesInternal() final;
     void providePresentingApplicationPID(int) final;
 
     // Messages
-    void applicationWillEnterForeground(SuspendedUnderLock);
-    void applicationDidEnterBackground(SuspendedUnderLock);
-    void applicationWillBecomeInactive();
-    void applicationDidBecomeActive();
-    void externalOutputDeviceAvailableDidChange(HasAvailableTargets);
-    void isPlayingToAutomotiveHeadUnitDidChange(PlayingToAutomotiveHeadUnit);
-    void activeAudioRouteDidChange(ShouldPause);
     void activeVideoRouteDidChange(SupportsAirPlayVideo, WebCore::MediaPlaybackTargetContext&&);
 
     WebProcess& m_process;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to