Title: [257913] trunk/Source
Revision
257913
Author
you...@apple.com
Date
2020-03-05 03:53:35 -0800 (Thu, 05 Mar 2020)

Log Message

Export NowPlaying commands to GPUProcess when media playing in GPUProcess is enabled
https://bugs.webkit.org/show_bug.cgi?id=208568

Source/WebCore:

Reviewed by Eric Carlson.

Removed PlatformMediaSessionClient NowPlaying getters since only HTMLMediaElement is eligible.
Let MediaElementSession generates its own NowPlayingInfo when requested by the session manager.
Use platform strategies to abstract out how to execute NowPlaying orders.

Manually tested for NowPlaying functionality.
Also covered by existing tests for the refactoring bits.

* Headers.cmake:
* Modules/webaudio/AudioContext.cpp:
(WebCore::AudioContext::sourceApplicationIdentifier const): Deleted.
* Modules/webaudio/AudioContext.h:
* WebCore.xcodeproj/project.pbxproj:
* html/HTMLMediaElement.h:
* html/MediaElementSession.cpp:
(WebCore::MediaElementSession::allowsPlaybackControlsForAutoplayingAudio const):
(WebCore::MediaElementSession::nowPlayingInfo const):
(WebCore::MediaElementSession::allowsNowPlayingControlsVisibility const): Deleted.
* html/MediaElementSession.h:
* platform/MediaStrategy.h:
* platform/audio/AudioSession.h:
* platform/audio/NowPlayingInfo.h: Added.
(WebCore::NowPlayingInfo::encode const):
(WebCore::NowPlayingInfo::decode):
* platform/audio/PlatformMediaSession.cpp:
(WebCore::PlatformMediaSession::nowPlayingInfo const):
(WebCore::PlatformMediaSession::uniqueIdentifier const): Deleted.
(WebCore::PlatformMediaSession::title const): Deleted.
(WebCore::PlatformMediaSession::duration const): Deleted.
(WebCore::PlatformMediaSession::currentTime const): Deleted.
(WebCore::PlatformMediaSession::sourceApplicationIdentifier const): Deleted.
(WebCore::PlatformMediaSessionClient::mediaSessionUniqueIdentifier const): Deleted.
(WebCore::PlatformMediaSessionClient::mediaSessionTitle const): Deleted.
(WebCore::PlatformMediaSessionClient::mediaSessionDuration const): Deleted.
(WebCore::PlatformMediaSessionClient::mediaSessionCurrentTime const): Deleted.
* platform/audio/PlatformMediaSession.h:
(WebCore::PlatformMediaSession::allowsNowPlayingControlsVisibility const): Deleted.
* platform/audio/cocoa/MediaSessionManagerCocoa.h:
* platform/audio/cocoa/MediaSessionManagerCocoa.mm:
(MediaSessionManagerCocoa::clearNowPlayingInfo):
(MediaSessionManagerCocoa::setNowPlayingInfo):
(MediaSessionManagerCocoa::nowPlayingEligibleSession):
(MediaSessionManagerCocoa::updateNowPlayingInfo):
* platform/audio/ios/MediaSessionManagerIOS.h:
* platform/audio/ios/MediaSessionManagerIOS.mm:
(WebCore::MediaSessionManageriOS::providePresentingApplicationPIDIfNecessary):
(WebCore::MediaSessionManageriOS::providePresentingApplicationPID):

Source/WebKit:

Reviewed by Eric Carlson.

Export NowPlaying orders to GPU process through IPC if GPUProcess is turned on.
Otherwise use the regular in process implementation.
Make sure to sync the hasAudio state so that it gets set properly in WebProcess.

Remove the use of a PlatformMediaSessionManager for capture since it is now using platform strategies in two places.
Instead use directly static methods of MediaSessionManageriOS to implement pid forwarding and AudioSession to set category and buffer size.
A follow-up refactoring should probably rearchitect AudioSession handling.

* GPUProcess/GPUConnectionToWebProcess.cpp:
(WebKit::GPUConnectionToWebProcess::clearNowPlayingInfo):
(WebKit::GPUConnectionToWebProcess::setNowPlayingInfo):
(WebKit::GPUConnectionToWebProcess::sessionManager): Deleted.
* GPUProcess/GPUConnectionToWebProcess.h:
* GPUProcess/GPUConnectionToWebProcess.messages.in:
* GPUProcess/media/RemoteMediaPlayerProxy.cpp:
(WebKit::RemoteMediaPlayerProxy::updateCachedState):
* UIProcess/Cocoa/UserMediaCaptureManagerProxy.cpp:
(WebKit::UserMediaCaptureManagerProxy::SourceProxy::SourceProxy):
(WebKit::UserMediaCaptureManagerProxy::SourceProxy::~SourceProxy):
(WebKit::UserMediaCaptureManagerProxy::createMediaSourceForCaptureDeviceWithConstraints):
(WebKit::UserMediaCaptureManagerProxy::clone):
* UIProcess/Cocoa/UserMediaCaptureManagerProxy.h:
* UIProcess/WebProcessProxy.cpp:
* WebProcess/GPU/media/WebMediaStrategy.cpp:
(WebKit::WebMediaStrategy::clearNowPlayingInfo):
(WebKit::WebMediaStrategy::setNowPlayingInfo):
* WebProcess/GPU/media/WebMediaStrategy.h:

Source/WebKitLegacy/mac:

Reviewed by Eric Carlson.

Use in-process now playing implementation.

* WebCoreSupport/WebPlatformStrategies.mm:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (257912 => 257913)


--- trunk/Source/WebCore/ChangeLog	2020-03-05 09:51:14 UTC (rev 257912)
+++ trunk/Source/WebCore/ChangeLog	2020-03-05 11:53:35 UTC (rev 257913)
@@ -1,3 +1,57 @@
+2020-03-05  Youenn Fablet  <you...@apple.com>
+
+        Export NowPlaying commands to GPUProcess when media playing in GPUProcess is enabled
+        https://bugs.webkit.org/show_bug.cgi?id=208568
+
+        Reviewed by Eric Carlson.
+
+        Removed PlatformMediaSessionClient NowPlaying getters since only HTMLMediaElement is eligible.
+        Let MediaElementSession generates its own NowPlayingInfo when requested by the session manager.
+        Use platform strategies to abstract out how to execute NowPlaying orders.
+
+        Manually tested for NowPlaying functionality.
+        Also covered by existing tests for the refactoring bits.
+
+        * Headers.cmake:
+        * Modules/webaudio/AudioContext.cpp:
+        (WebCore::AudioContext::sourceApplicationIdentifier const): Deleted.
+        * Modules/webaudio/AudioContext.h:
+        * WebCore.xcodeproj/project.pbxproj:
+        * html/HTMLMediaElement.h:
+        * html/MediaElementSession.cpp:
+        (WebCore::MediaElementSession::allowsPlaybackControlsForAutoplayingAudio const):
+        (WebCore::MediaElementSession::nowPlayingInfo const):
+        (WebCore::MediaElementSession::allowsNowPlayingControlsVisibility const): Deleted.
+        * html/MediaElementSession.h:
+        * platform/MediaStrategy.h:
+        * platform/audio/AudioSession.h:
+        * platform/audio/NowPlayingInfo.h: Added.
+        (WebCore::NowPlayingInfo::encode const):
+        (WebCore::NowPlayingInfo::decode):
+        * platform/audio/PlatformMediaSession.cpp:
+        (WebCore::PlatformMediaSession::nowPlayingInfo const):
+        (WebCore::PlatformMediaSession::uniqueIdentifier const): Deleted.
+        (WebCore::PlatformMediaSession::title const): Deleted.
+        (WebCore::PlatformMediaSession::duration const): Deleted.
+        (WebCore::PlatformMediaSession::currentTime const): Deleted.
+        (WebCore::PlatformMediaSession::sourceApplicationIdentifier const): Deleted.
+        (WebCore::PlatformMediaSessionClient::mediaSessionUniqueIdentifier const): Deleted.
+        (WebCore::PlatformMediaSessionClient::mediaSessionTitle const): Deleted.
+        (WebCore::PlatformMediaSessionClient::mediaSessionDuration const): Deleted.
+        (WebCore::PlatformMediaSessionClient::mediaSessionCurrentTime const): Deleted.
+        * platform/audio/PlatformMediaSession.h:
+        (WebCore::PlatformMediaSession::allowsNowPlayingControlsVisibility const): Deleted.
+        * platform/audio/cocoa/MediaSessionManagerCocoa.h:
+        * platform/audio/cocoa/MediaSessionManagerCocoa.mm:
+        (MediaSessionManagerCocoa::clearNowPlayingInfo):
+        (MediaSessionManagerCocoa::setNowPlayingInfo):
+        (MediaSessionManagerCocoa::nowPlayingEligibleSession):
+        (MediaSessionManagerCocoa::updateNowPlayingInfo):
+        * platform/audio/ios/MediaSessionManagerIOS.h:
+        * platform/audio/ios/MediaSessionManagerIOS.mm:
+        (WebCore::MediaSessionManageriOS::providePresentingApplicationPIDIfNecessary):
+        (WebCore::MediaSessionManageriOS::providePresentingApplicationPID):
+
 2020-03-04  Yusuke Suzuki  <ysuz...@apple.com>
 
         Put all generated JSCells in WebCore into IsoSubspace

Modified: trunk/Source/WebCore/Headers.cmake (257912 => 257913)


--- trunk/Source/WebCore/Headers.cmake	2020-03-05 09:51:14 UTC (rev 257912)
+++ trunk/Source/WebCore/Headers.cmake	2020-03-05 11:53:35 UTC (rev 257913)
@@ -1031,6 +1031,7 @@
     platform/audio/AudioSession.h
     platform/audio/AudioSourceProvider.h
     platform/audio/AudioStreamDescription.h
+    platform/audio/NowPlayingInfo.h
     platform/audio/PlatformAudioData.h
     platform/audio/PlatformMediaSession.h
     platform/audio/PlatformMediaSessionManager.h

Modified: trunk/Source/WebCore/Modules/webaudio/AudioContext.cpp (257912 => 257913)


--- trunk/Source/WebCore/Modules/webaudio/AudioContext.cpp	2020-03-05 09:51:14 UTC (rev 257912)
+++ trunk/Source/WebCore/Modules/webaudio/AudioContext.cpp	2020-03-05 11:53:35 UTC (rev 257913)
@@ -373,16 +373,6 @@
     return document ? document->identifier() : DocumentIdentifier { };
 }
 
-String AudioContext::sourceApplicationIdentifier() const
-{
-    Document* document = this->document();
-    if (Frame* frame = document ? document->frame() : nullptr) {
-        if (NetworkingContext* networkingContext = frame->loader().networkingContext())
-            return networkingContext->sourceApplicationIdentifier();
-    }
-    return emptyString();
-}
-
 bool AudioContext::isSuspended() const
 {
     return !document() || document()->activeDOMObjectsAreSuspended() || document()->activeDOMObjectsAreStopped();

Modified: trunk/Source/WebCore/Modules/webaudio/AudioContext.h (257912 => 257913)


--- trunk/Source/WebCore/Modules/webaudio/AudioContext.h	2020-03-05 09:51:14 UTC (rev 257912)
+++ trunk/Source/WebCore/Modules/webaudio/AudioContext.h	2020-03-05 11:53:35 UTC (rev 257913)
@@ -355,7 +355,6 @@
     void didReceiveRemoteControlCommand(PlatformMediaSession::RemoteControlCommandType, const PlatformMediaSession::RemoteCommandArgument*) override { }
     bool supportsSeeking() const override { return false; }
     bool shouldOverrideBackgroundPlaybackRestriction(PlatformMediaSession::InterruptionType) const override { return false; }
-    String sourceApplicationIdentifier() const override;
     bool canProduceAudio() const final { return true; }
     bool isSuspended() const final;
 

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (257912 => 257913)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2020-03-05 09:51:14 UTC (rev 257912)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2020-03-05 11:53:35 UTC (rev 257913)
@@ -1085,6 +1085,7 @@
 		416E6FE81BBD12DF000A6053 /* WritableStreamInternalsBuiltins.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B03D8061BB3110D00B764E9 /* WritableStreamInternalsBuiltins.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		416E6FE91BBD12E5000A6043 /* ReadableStreamBuiltins.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B03D8061BB3110D00B764D8 /* ReadableStreamBuiltins.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		416E6FE91BBD12E5000A6053 /* WritableStreamBuiltins.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B03D8061BB3110D00B764E8 /* WritableStreamBuiltins.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		416FD25F240FA4E5006661D8 /* NowPlayingInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 416FD25D240EE1AE006661D8 /* NowPlayingInfo.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		417253AB1354BBBC00360F2A /* MediaControlElements.h in Headers */ = {isa = PBXBuildFile; fileRef = 417253A91354BBBC00360F2A /* MediaControlElements.h */; };
 		417612AF1E3A994000C3D81D /* LibWebRTCMediaEndpoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 417612AB1E3A993B00C3D81D /* LibWebRTCMediaEndpoint.cpp */; };
 		417612B01E3A994000C3D81D /* LibWebRTCMediaEndpoint.h in Headers */ = {isa = PBXBuildFile; fileRef = 417612AC1E3A993B00C3D81D /* LibWebRTCMediaEndpoint.h */; };
@@ -7367,6 +7368,7 @@
 		416D759F20C6441300D02D2C /* NetworkLoadInformation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkLoadInformation.h; sourceTree = "<group>"; };
 		416E0B37209BC3C2004A95D9 /* FetchIdentifier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FetchIdentifier.h; sourceTree = "<group>"; };
 		416E29A5102FA962007FC14E /* WorkerReportingProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WorkerReportingProxy.h; sourceTree = "<group>"; };
+		416FD25D240EE1AE006661D8 /* NowPlayingInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NowPlayingInfo.h; sourceTree = "<group>"; };
 		4170A2E91D8C0CC000318452 /* JSDOMWrapper.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSDOMWrapper.cpp; sourceTree = "<group>"; };
 		417253A81354BBBC00360F2A /* MediaControlElements.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MediaControlElements.cpp; sourceTree = "<group>"; };
 		417253A91354BBBC00360F2A /* MediaControlElements.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaControlElements.h; sourceTree = "<group>"; };
@@ -28773,6 +28775,7 @@
 				FD31606B12B026F700C1A359 /* HRTFPanner.h */,
 				FDB1700314A2BAB200A2B5D9 /* MultiChannelResampler.cpp */,
 				FDB1700414A2BAB200A2B5D9 /* MultiChannelResampler.h */,
+				416FD25D240EE1AE006661D8 /* NowPlayingInfo.h */,
 				FD31606C12B026F700C1A359 /* Panner.cpp */,
 				FD31606D12B026F700C1A359 /* Panner.h */,
 				CDE667A11E4BBA4D00E8154A /* PlatformAudioData.h */,
@@ -31664,6 +31667,7 @@
 				7CC2DDFB1EC9415A0027B774 /* NotificationPermission.h in Headers */,
 				31FE6DFA15004C2A0004EBC4 /* NotificationPermissionCallback.h in Headers */,
 				98EB1F951313FE0500D0E1EA /* NotImplemented.h in Headers */,
+				416FD25F240FA4E5006661D8 /* NowPlayingInfo.h in Headers */,
 				1A569D0B0D7E2B82007C3983 /* NP_jsobject.h in Headers */,
 				1A927FD21416A15B003A83C8 /* npapi.h in Headers */,
 				1A219B3B0DCA87AB0040E3A0 /* npfunctions.h in Headers */,

Modified: trunk/Source/WebCore/html/HTMLMediaElement.h (257912 => 257913)


--- trunk/Source/WebCore/html/HTMLMediaElement.h	2020-03-05 09:51:14 UTC (rev 257912)
+++ trunk/Source/WebCore/html/HTMLMediaElement.h	2020-03-05 11:53:35 UTC (rev 257913)
@@ -592,6 +592,10 @@
     void applicationWillResignActive();
     void applicationDidBecomeActive();
 
+    uint64_t mediaSessionUniqueIdentifier() const;
+    String mediaSessionTitle() const;
+    String sourceApplicationIdentifier() const;
+
 protected:
     HTMLMediaElement(const QualifiedName&, Document&, bool createdByParser);
     virtual void finishInitialization();
@@ -735,7 +739,6 @@
 
     void mediaPlayerActiveSourceBuffersChanged() override;
 
-    String sourceApplicationIdentifier() const override;
     String mediaPlayerSourceApplicationIdentifier() const override { return sourceApplicationIdentifier(); }
     Vector<String> mediaPlayerPreferredAudioCharacteristics() const override;
 
@@ -882,10 +885,6 @@
     void suspendPlayback() override;
     void resumeAutoplaying() override;
     void mayResumePlayback(bool shouldResume) override;
-    uint64_t mediaSessionUniqueIdentifier() const final;
-    String mediaSessionTitle() const override;
-    double mediaSessionDuration() const override { return duration(); }
-    double mediaSessionCurrentTime() const override { return currentTime(); }
     bool canReceiveRemoteControlCommands() const override { return true; }
     void didReceiveRemoteControlCommand(PlatformMediaSession::RemoteControlCommandType, const PlatformMediaSession::RemoteCommandArgument*) override;
     bool shouldOverrideBackgroundPlaybackRestriction(PlatformMediaSession::InterruptionType) const override;

Modified: trunk/Source/WebCore/html/MediaElementSession.cpp (257912 => 257913)


--- trunk/Source/WebCore/html/MediaElementSession.cpp	2020-03-05 09:51:14 UTC (rev 257912)
+++ trunk/Source/WebCore/html/MediaElementSession.cpp	2020-03-05 11:53:35 UTC (rev 257913)
@@ -40,6 +40,7 @@
 #include "HTMLVideoElement.h"
 #include "HitTestResult.h"
 #include "Logging.h"
+#include "NowPlayingInfo.h"
 #include "Page.h"
 #include "PlatformMediaSessionManager.h"
 #include "Quirks.h"
@@ -977,16 +978,24 @@
     return m_isMainContent;
 }
 
-bool MediaElementSession::allowsNowPlayingControlsVisibility() const
+bool MediaElementSession::allowsPlaybackControlsForAutoplayingAudio() const
 {
     auto page = m_element.document().page();
-    return page && !page->isVisibleAndActive();
+    return page && page->allowsPlaybackControlsForAutoplayingAudio();
 }
 
-bool MediaElementSession::allowsPlaybackControlsForAutoplayingAudio() const
+Optional<NowPlayingInfo> MediaElementSession::nowPlayingInfo() const
 {
-    auto page = m_element.document().page();
-    return page && page->allowsPlaybackControlsForAutoplayingAudio();
+    auto* page = m_element.document().page();
+    bool allowsNowPlayingControlsVisibility = page && !page->isVisibleAndActive();
+    bool isPlaying = state() == PlatformMediaSession::Playing;
+    bool supportsSeeking = m_element.supportsSeeking();
+    double duration = supportsSeeking ? m_element.duration() : MediaPlayer::invalidTime();
+    double currentTime = m_element.currentTime();
+    if (!std::isfinite(currentTime) || !supportsSeeking)
+        currentTime = MediaPlayer::invalidTime();
+
+    return NowPlayingInfo { m_element.mediaSessionTitle(), m_element.sourceApplicationIdentifier(), duration, currentTime, supportsSeeking, m_element.mediaSessionUniqueIdentifier(), isPlaying, allowsNowPlayingControlsVisibility };
 }
 
 String convertEnumerationToString(const MediaPlaybackDenialReason enumerationValue)

Modified: trunk/Source/WebCore/html/MediaElementSession.h (257912 => 257913)


--- trunk/Source/WebCore/html/MediaElementSession.h	2020-03-05 09:51:14 UTC (rev 257912)
+++ trunk/Source/WebCore/html/MediaElementSession.h	2020-03-05 11:53:35 UTC (rev 257913)
@@ -149,7 +149,6 @@
     MonotonicTime mostRecentUserInteractionTime() const;
 
     bool allowsPlaybackControlsForAutoplayingAudio() const;
-    bool allowsNowPlayingControlsVisibility() const override;
 
     static bool isMediaElementSessionMediaType(MediaType type)
     {
@@ -158,6 +157,8 @@
             || type == MediaType::VideoAudio;
     }
 
+    Optional<NowPlayingInfo> nowPlayingInfo() const final;
+
 #if !RELEASE_LOG_DISABLED
     const void* logIdentifier() const final { return m_logIdentifier; }
     const char* logClassName() const final { return "MediaElementSession"; }

Modified: trunk/Source/WebCore/platform/MediaStrategy.h (257912 => 257913)


--- trunk/Source/WebCore/platform/MediaStrategy.h	2020-03-05 09:51:14 UTC (rev 257912)
+++ trunk/Source/WebCore/platform/MediaStrategy.h	2020-03-05 11:53:35 UTC (rev 257913)
@@ -32,6 +32,7 @@
 class AudioDestination;
 class AudioIOCallback;
 class CDMFactory;
+struct NowPlayingInfo;
 
 class WEBCORE_EXPORT MediaStrategy {
 public:
@@ -42,6 +43,11 @@
 #if ENABLE(ENCRYPTED_MEDIA)
     virtual void registerCDMFactories(Vector<CDMFactory*>&) = 0;
 #endif
+#if PLATFORM(COCOA)
+    virtual void clearNowPlayingInfo() = 0;
+    virtual void setNowPlayingInfo(bool setAsNowPlayingApplication, const NowPlayingInfo&) = 0;
+#endif
+
 protected:
     virtual ~MediaStrategy() = default;
 };

Modified: trunk/Source/WebCore/platform/audio/AudioSession.h (257912 => 257913)


--- trunk/Source/WebCore/platform/audio/AudioSession.h	2020-03-05 09:51:14 UTC (rev 257912)
+++ trunk/Source/WebCore/platform/audio/AudioSession.h	2020-03-05 11:53:35 UTC (rev 257913)
@@ -68,7 +68,7 @@
     RouteSharingPolicy routeSharingPolicy() const;
     String routingContextUID() const;
 
-    float sampleRate() const;
+    WEBCORE_EXPORT float sampleRate() const;
     size_t bufferSize() const;
     size_t numberOfOutputChannels() const;
 
@@ -75,7 +75,7 @@
     bool tryToSetActive(bool);
 
     WEBCORE_EXPORT size_t preferredBufferSize() const;
-    void setPreferredBufferSize(size_t);
+    WEBCORE_EXPORT void setPreferredBufferSize(size_t);
 
     class MutedStateObserver {
     public:

Added: trunk/Source/WebCore/platform/audio/NowPlayingInfo.h (0 => 257913)


--- trunk/Source/WebCore/platform/audio/NowPlayingInfo.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/audio/NowPlayingInfo.h	2020-03-05 11:53:35 UTC (rev 257913)
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+struct NowPlayingInfo {
+    String title;
+    String sourceApplicationIdentifier;
+    double duration { 0 };
+    double currentTime { 0 };
+    bool supportsSeeking { false };
+    uint64_t uniqueIdentifier { 0 };
+    bool isPlaying { false };
+    bool allowsNowPlayingControlsVisibility { false };
+
+    template<class Encoder> void encode(Encoder&) const;
+    template<class Decoder> static Optional<NowPlayingInfo> decode(Decoder&);
+};
+
+template<class Encoder> inline void NowPlayingInfo::encode(Encoder& encoder) const
+{
+    encoder << title << sourceApplicationIdentifier << duration << currentTime << supportsSeeking << uniqueIdentifier << isPlaying << allowsNowPlayingControlsVisibility;
+}
+
+template<class Decoder> inline Optional<NowPlayingInfo> NowPlayingInfo::decode(Decoder& decoder)
+{
+    String title;
+    if (!decoder.decode(title))
+        return { };
+
+    String sourceApplicationIdentifier;
+    if (!decoder.decode(sourceApplicationIdentifier))
+        return { };
+
+    double duration;
+    if (!decoder.decode(duration))
+        return { };
+
+    double currentTime;
+    if (!decoder.decode(currentTime))
+        return { };
+
+    bool supportsSeeking;
+    if (!decoder.decode(supportsSeeking))
+        return { };
+
+    uint64_t uniqueIdentifier;
+    if (!decoder.decode(uniqueIdentifier))
+        return { };
+
+    bool isPlaying;
+    if (!decoder.decode(isPlaying))
+        return { };
+
+    bool allowsNowPlayingControlsVisibility;
+    if (!decoder.decode(allowsNowPlayingControlsVisibility))
+        return { };
+
+    return NowPlayingInfo { WTFMove(title), WTFMove(sourceApplicationIdentifier), duration, currentTime, supportsSeeking, uniqueIdentifier, isPlaying, allowsNowPlayingControlsVisibility };
+}
+
+} // namespace WebCore

Modified: trunk/Source/WebCore/platform/audio/PlatformMediaSession.cpp (257912 => 257913)


--- trunk/Source/WebCore/platform/audio/PlatformMediaSession.cpp	2020-03-05 09:51:14 UTC (rev 257912)
+++ trunk/Source/WebCore/platform/audio/PlatformMediaSession.cpp	2020-03-05 11:53:35 UTC (rev 257913)
@@ -30,6 +30,7 @@
 #include "HTMLMediaElement.h"
 #include "Logging.h"
 #include "MediaPlayer.h"
+#include "NowPlayingInfo.h"
 #include "PlatformMediaSessionManager.h"
 
 namespace WebCore {
@@ -275,28 +276,6 @@
     return m_client.presentationType();
 }
 
-#if ENABLE(VIDEO)
-uint64_t PlatformMediaSession::uniqueIdentifier() const
-{
-    return m_client.mediaSessionUniqueIdentifier();
-}
-
-String PlatformMediaSession::title() const
-{
-    return m_client.mediaSessionTitle();
-}
-
-double PlatformMediaSession::duration() const
-{
-    return m_client.mediaSessionDuration();
-}
-
-double PlatformMediaSession::currentTime() const
-{
-    return m_client.mediaSessionCurrentTime();
-}
-#endif
-    
 bool PlatformMediaSession::canReceiveRemoteControlCommands() const
 {
     return m_client.canReceiveRemoteControlCommands();
@@ -314,11 +293,6 @@
     return m_client.supportsSeeking();
 }
 
-String PlatformMediaSession::sourceApplicationIdentifier() const
-{
-    return m_client.sourceApplicationIdentifier();
-}
-
 bool PlatformMediaSession::isSuspended() const
 {
     return m_client.isSuspended();
@@ -367,28 +341,6 @@
     m_manager->sessionCanProduceAudioChanged();
 }
 
-#if ENABLE(VIDEO)
-uint64_t PlatformMediaSessionClient::mediaSessionUniqueIdentifier() const
-{
-    return 0;
-}
-
-String PlatformMediaSessionClient::mediaSessionTitle() const
-{
-    return String();
-}
-
-double PlatformMediaSessionClient::mediaSessionDuration() const
-{
-    return MediaPlayer::invalidTime();
-}
-
-double PlatformMediaSessionClient::mediaSessionCurrentTime() const
-{
-    return MediaPlayer::invalidTime();
-}
-#endif
-
 void PlatformMediaSession::clientCharacteristicsChanged()
 {
     m_manager->clientCharacteristicsChanged(*this);
@@ -409,6 +361,11 @@
     return *m_manager;
 }
 
+Optional<NowPlayingInfo> PlatformMediaSession::nowPlayingInfo() const
+{
+    return { };
+}
+
 #if !RELEASE_LOG_DISABLED
 WTFLogChannel& PlatformMediaSession::logChannel() const
 {

Modified: trunk/Source/WebCore/platform/audio/PlatformMediaSession.h (257912 => 257913)


--- trunk/Source/WebCore/platform/audio/PlatformMediaSession.h	2020-03-05 09:51:14 UTC (rev 257912)
+++ trunk/Source/WebCore/platform/audio/PlatformMediaSession.h	2020-03-05 11:53:35 UTC (rev 257913)
@@ -43,6 +43,7 @@
 class PlatformMediaSessionClient;
 class PlatformMediaSessionManager;
 enum class DelayCallingUpdateNowPlaying { No, Yes };
+struct NowPlayingInfo;
 
 class PlatformMediaSession
     : public CanMakeWeakPtr<PlatformMediaSession>
@@ -113,13 +114,6 @@
     virtual void suspendBuffering() { }
     virtual void resumeBuffering() { }
     
-#if ENABLE(VIDEO)
-    uint64_t uniqueIdentifier() const;
-    String title() const;
-    double duration() const;
-    double currentTime() const;
-#endif
-
     typedef union {
         double asDouble;
     } RemoteCommandArgument;
@@ -174,8 +168,6 @@
     virtual void resetPlaybackSessionState() { }
     String sourceApplicationIdentifier() const;
 
-    virtual bool allowsNowPlayingControlsVisibility() const { return false; }
-
     bool hasPlayedSinceLastInterruption() const { return m_hasPlayedSinceLastInterruption; }
     void clearHasPlayedSinceLastInterruption() { m_hasPlayedSinceLastInterruption = false; }
 
@@ -195,6 +187,8 @@
         virtual bool isCapturingAudio() const = 0;
     };
 
+    virtual Optional<NowPlayingInfo> nowPlayingInfo() const;
+
 protected:
     PlatformMediaSession(PlatformMediaSessionManager&, PlatformMediaSessionClient&);
     PlatformMediaSessionClient& client() const { return m_client; }
@@ -235,13 +229,6 @@
     virtual void mayResumePlayback(bool shouldResume) = 0;
     virtual void suspendPlayback() = 0;
 
-#if ENABLE(VIDEO)
-    virtual uint64_t mediaSessionUniqueIdentifier() const;
-    virtual String mediaSessionTitle() const;
-    virtual double mediaSessionDuration() const;
-    virtual double mediaSessionCurrentTime() const;
-#endif
-    
     virtual bool canReceiveRemoteControlCommands() const = 0;
     virtual void didReceiveRemoteControlCommand(PlatformMediaSession::RemoteControlCommandType, const PlatformMediaSession::RemoteCommandArgument*) = 0;
     virtual bool supportsSeeking() const = 0;
@@ -261,7 +248,6 @@
     virtual bool isPlayingOnSecondScreen() const { return false; }
 
     virtual DocumentIdentifier hostingDocumentIdentifier() const = 0;
-    virtual String sourceApplicationIdentifier() const = 0;
 
     virtual bool hasMediaStreamSource() const { return false; }
 

Modified: trunk/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.h (257912 => 257913)


--- trunk/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.h	2020-03-05 09:51:14 UTC (rev 257912)
+++ trunk/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.h	2020-03-05 11:53:35 UTC (rev 257913)
@@ -35,6 +35,8 @@
 
 namespace WebCore {
 
+struct NowPlayingInfo;
+
 class MediaSessionManagerCocoa
     : public PlatformMediaSessionManager
     , private RemoteCommandListenerClient
@@ -55,6 +57,9 @@
     bool registeredAsNowPlayingApplication() const final { return m_registeredAsNowPlayingApplication; }
     void prepareToSendUserMediaPermissionRequest() final;
 
+    static WEBCORE_EXPORT void clearNowPlayingInfo();
+    static WEBCORE_EXPORT void setNowPlayingInfo(bool setAsNowPlayingApplication, const NowPlayingInfo&);
+
 protected:
     void scheduleUpdateNowPlayingInfo() final;
     void updateNowPlayingInfo();

Modified: trunk/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.mm (257912 => 257913)


--- trunk/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.mm	2020-03-05 09:51:14 UTC (rev 257912)
+++ trunk/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.mm	2020-03-05 11:53:35 UTC (rev 257913)
@@ -33,7 +33,10 @@
 #include "HTMLMediaElement.h"
 #include "Logging.h"
 #include "MediaPlayer.h"
+#include "MediaStrategy.h"
+#include "NowPlayingInfo.h"
 #include "PlatformMediaSession.h"
+#include "PlatformStrategies.h"
 #include <wtf/BlockObjCExceptions.h>
 #include <wtf/Function.h>
 
@@ -204,8 +207,73 @@
     scheduleUpdateNowPlayingInfo();
 }
 
+void MediaSessionManagerCocoa::clearNowPlayingInfo()
+{
+    if (canLoad_MediaRemote_MRMediaRemoteSetNowPlayingVisibility())
+        MRMediaRemoteSetNowPlayingVisibility(MRMediaRemoteGetLocalOrigin(), MRNowPlayingClientVisibilityNeverVisible);
+
+    MRMediaRemoteSetCanBeNowPlayingApplication(false);
+    MRMediaRemoteSetNowPlayingInfo(nullptr);
+    MRMediaRemoteSetNowPlayingApplicationPlaybackStateForOrigin(MRMediaRemoteGetLocalOrigin(), kMRPlaybackStateStopped, dispatch_get_main_queue(), ^(MRMediaRemoteError error) {
+#if LOG_DISABLED
+        UNUSED_PARAM(error);
+#else
+        if (error)
+            WTFLogAlways("MRMediaRemoteSetNowPlayingApplicationPlaybackStateForOrigin(stopped) failed with error ", error);
+#endif
+    });
+}
+
+void MediaSessionManagerCocoa::setNowPlayingInfo(bool setAsNowPlayingApplication, const NowPlayingInfo& nowPlayingInfo)
+{
+    if (setAsNowPlayingApplication)
+        MRMediaRemoteSetCanBeNowPlayingApplication(true);
+
+    auto info = adoptCF(CFDictionaryCreateMutable(kCFAllocatorDefault, 4, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
+
+    if (!nowPlayingInfo.title.isEmpty())
+        CFDictionarySetValue(info.get(), kMRMediaRemoteNowPlayingInfoTitle, nowPlayingInfo.title.createCFString().get());
+
+    if (std::isfinite(nowPlayingInfo.duration) && nowPlayingInfo.duration != MediaPlayer::invalidTime()) {
+        auto cfDuration = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberDoubleType, &nowPlayingInfo.duration));
+        CFDictionarySetValue(info.get(), kMRMediaRemoteNowPlayingInfoDuration, cfDuration.get());
+    }
+
+    double rate = nowPlayingInfo.isPlaying ? 1 : 0;
+    auto cfRate = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberDoubleType, &rate));
+    CFDictionarySetValue(info.get(), kMRMediaRemoteNowPlayingInfoPlaybackRate, cfRate.get());
+
+    auto lastUpdatedNowPlayingInfoUniqueIdentifier = nowPlayingInfo.uniqueIdentifier;
+    auto cfIdentifier = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberLongLongType, &lastUpdatedNowPlayingInfoUniqueIdentifier));
+    CFDictionarySetValue(info.get(), kMRMediaRemoteNowPlayingInfoUniqueIdentifier, cfIdentifier.get());
+
+    if (std::isfinite(nowPlayingInfo.currentTime) && nowPlayingInfo.currentTime != MediaPlayer::invalidTime() && nowPlayingInfo.supportsSeeking) {
+        auto cfCurrentTime = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberDoubleType, &nowPlayingInfo.currentTime));
+        CFDictionarySetValue(info.get(), kMRMediaRemoteNowPlayingInfoElapsedTime, cfCurrentTime.get());
+    }
+
+    if (canLoad_MediaRemote_MRMediaRemoteSetParentApplication() && !nowPlayingInfo.sourceApplicationIdentifier.isEmpty())
+        MRMediaRemoteSetParentApplication(MRMediaRemoteGetLocalOrigin(), nowPlayingInfo.sourceApplicationIdentifier.createCFString().get());
+
+    MRPlaybackState playbackState = (nowPlayingInfo.isPlaying) ? kMRPlaybackStatePlaying : kMRPlaybackStatePaused;
+    MRMediaRemoteSetNowPlayingApplicationPlaybackStateForOrigin(MRMediaRemoteGetLocalOrigin(), playbackState, dispatch_get_main_queue(), ^(MRMediaRemoteError error) {
+#if LOG_DISABLED
+        UNUSED_PARAM(error);
+#else
+        WTFLogAlways("MRMediaRemoteSetNowPlayingApplicationPlaybackStateForOrigin(playing) failed with error ", error);
+#endif
+    });
+    MRMediaRemoteSetNowPlayingInfo(info.get());
+
+    if (canLoad_MediaRemote_MRMediaRemoteSetNowPlayingVisibility()) {
+        MRNowPlayingClientVisibility visibility = nowPlayingInfo.allowsNowPlayingControlsVisibility ? MRNowPlayingClientVisibilityAlwaysVisible : MRNowPlayingClientVisibilityNeverVisible;
+        MRMediaRemoteSetNowPlayingVisibility(MRMediaRemoteGetLocalOrigin(), visibility);
+    }
+}
+
 PlatformMediaSession* MediaSessionManagerCocoa::nowPlayingEligibleSession()
 {
+    // FIXME: Fix this layering violation.
     if (auto element = HTMLMediaElement::bestMediaElementForShowingPlaybackControlsManager(MediaElementSession::PlaybackControlsPurpose::NowPlaying))
         return &element->mediaSession();
 
@@ -220,94 +288,48 @@
 
     BEGIN_BLOCK_OBJC_EXCEPTIONS
 
-    const PlatformMediaSession* currentSession = this->nowPlayingEligibleSession();
+    Optional<NowPlayingInfo> nowPlayingInfo;
+    if (auto* session = nowPlayingEligibleSession())
+        nowPlayingInfo = session->nowPlayingInfo();
 
-    ALWAYS_LOG(LOGIDENTIFIER, "currentSession: ", currentSession ? currentSession->logIdentifier() : nullptr);
-
-    if (!currentSession) {
-        if (canLoad_MediaRemote_MRMediaRemoteSetNowPlayingVisibility())
-            MRMediaRemoteSetNowPlayingVisibility(MRMediaRemoteGetLocalOrigin(), MRNowPlayingClientVisibilityNeverVisible);
-
+    if (!nowPlayingInfo) {
         ALWAYS_LOG(LOGIDENTIFIER, "clearing now playing info");
+        platformStrategies()->mediaStrategy().clearNowPlayingInfo();
 
-        MRMediaRemoteSetCanBeNowPlayingApplication(false);
         m_registeredAsNowPlayingApplication = false;
-
-        MRMediaRemoteSetNowPlayingInfo(nullptr);
         m_nowPlayingActive = false;
         m_lastUpdatedNowPlayingTitle = emptyString();
         m_lastUpdatedNowPlayingDuration = NAN;
         m_lastUpdatedNowPlayingElapsedTime = NAN;
         m_lastUpdatedNowPlayingInfoUniqueIdentifier = 0;
-        MRMediaRemoteSetNowPlayingApplicationPlaybackStateForOrigin(MRMediaRemoteGetLocalOrigin(), kMRPlaybackStateStopped, dispatch_get_main_queue(), ^(MRMediaRemoteError error) {
-#if LOG_DISABLED
-            UNUSED_PARAM(error);
-#else
-            if (error)
-                ALWAYS_LOG(LOGIDENTIFIER, "MRMediaRemoteSetNowPlayingApplicationPlaybackStateForOrigin(stopped) failed with error ", error);
-#endif
-        });
 
         return;
     }
 
+    ALWAYS_LOG(LOGIDENTIFIER, "title = \"", nowPlayingInfo->title, "\", isPlaying = ", nowPlayingInfo->isPlaying, ", duration = ", nowPlayingInfo->duration, ", now = ", nowPlayingInfo->currentTime, ", id = ", nowPlayingInfo->uniqueIdentifier, ", registered = ", m_registeredAsNowPlayingApplication);
+
+    platformStrategies()->mediaStrategy().setNowPlayingInfo(!m_registeredAsNowPlayingApplication, *nowPlayingInfo);
+
     if (!m_registeredAsNowPlayingApplication) {
         m_registeredAsNowPlayingApplication = true;
         providePresentingApplicationPIDIfNecessary();
-        MRMediaRemoteSetCanBeNowPlayingApplication(true);
     }
 
-    String title = currentSession->title();
-    double duration = currentSession->supportsSeeking() ? currentSession->duration() : MediaPlayer::invalidTime();
-    double rate = currentSession->state() == PlatformMediaSession::Playing ? 1 : 0;
-    auto info = adoptCF(CFDictionaryCreateMutable(kCFAllocatorDefault, 4, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
+    if (!nowPlayingInfo->title.isEmpty())
+        m_lastUpdatedNowPlayingTitle = nowPlayingInfo->title;
 
-    if (!title.isEmpty()) {
-        CFDictionarySetValue(info.get(), kMRMediaRemoteNowPlayingInfoTitle, title.createCFString().get());
-        m_lastUpdatedNowPlayingTitle = title;
-    }
-
-    if (std::isfinite(duration) && duration != MediaPlayer::invalidTime()) {
-        auto cfDuration = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberDoubleType, &duration));
-        CFDictionarySetValue(info.get(), kMRMediaRemoteNowPlayingInfoDuration, cfDuration.get());
+    double duration = nowPlayingInfo->duration;
+    if (std::isfinite(duration) && duration != MediaPlayer::invalidTime())
         m_lastUpdatedNowPlayingDuration = duration;
-    }
 
-    auto cfRate = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberDoubleType, &rate));
-    CFDictionarySetValue(info.get(), kMRMediaRemoteNowPlayingInfoPlaybackRate, cfRate.get());
+    m_lastUpdatedNowPlayingInfoUniqueIdentifier = nowPlayingInfo->uniqueIdentifier;
 
-    m_lastUpdatedNowPlayingInfoUniqueIdentifier = currentSession->uniqueIdentifier();
-    auto cfIdentifier = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberLongLongType, &m_lastUpdatedNowPlayingInfoUniqueIdentifier));
-    CFDictionarySetValue(info.get(), kMRMediaRemoteNowPlayingInfoUniqueIdentifier, cfIdentifier.get());
-
-    double currentTime = currentSession->currentTime();
-    if (std::isfinite(currentTime) && currentTime != MediaPlayer::invalidTime() && currentSession->supportsSeeking()) {
-        auto cfCurrentTime = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberDoubleType, &currentTime));
-        CFDictionarySetValue(info.get(), kMRMediaRemoteNowPlayingInfoElapsedTime, cfCurrentTime.get());
+    double currentTime = nowPlayingInfo->currentTime;
+    if (std::isfinite(currentTime) && currentTime != MediaPlayer::invalidTime() && nowPlayingInfo->supportsSeeking)
         m_lastUpdatedNowPlayingElapsedTime = currentTime;
-    }
 
-    ALWAYS_LOG(LOGIDENTIFIER, "title = \"", title, "\", rate = ", rate, ", duration = ", duration, ", now = ", currentTime);
+    m_nowPlayingActive = nowPlayingInfo->allowsNowPlayingControlsVisibility;
 
-    String parentApplication = currentSession->sourceApplicationIdentifier();
-    if (canLoad_MediaRemote_MRMediaRemoteSetParentApplication() && !parentApplication.isEmpty())
-        MRMediaRemoteSetParentApplication(MRMediaRemoteGetLocalOrigin(), parentApplication.createCFString().get());
-
-    m_nowPlayingActive = currentSession->allowsNowPlayingControlsVisibility();
-    MRPlaybackState playbackState = (currentSession->state() == PlatformMediaSession::Playing) ? kMRPlaybackStatePlaying : kMRPlaybackStatePaused;
-    MRMediaRemoteSetNowPlayingApplicationPlaybackStateForOrigin(MRMediaRemoteGetLocalOrigin(), playbackState, dispatch_get_main_queue(), ^(MRMediaRemoteError error) {
-#if LOG_DISABLED
-        UNUSED_PARAM(error);
-#else
-        ALWAYS_LOG(LOGIDENTIFIER, "MRMediaRemoteSetNowPlayingApplicationPlaybackStateForOrigin(playing) failed with error ", error);
-#endif
-    });
-    MRMediaRemoteSetNowPlayingInfo(info.get());
-
-    if (canLoad_MediaRemote_MRMediaRemoteSetNowPlayingVisibility()) {
-        MRNowPlayingClientVisibility visibility = currentSession->allowsNowPlayingControlsVisibility() ? MRNowPlayingClientVisibilityAlwaysVisible : MRNowPlayingClientVisibilityNeverVisible;
-        MRMediaRemoteSetNowPlayingVisibility(MRMediaRemoteGetLocalOrigin(), visibility);
-    }
     END_BLOCK_OBJC_EXCEPTIONS
 #endif // USE(MEDIAREMOTE)
 }

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


--- trunk/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.h	2020-03-05 09:51:14 UTC (rev 257912)
+++ trunk/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.h	2020-03-05 11:53:35 UTC (rev 257913)
@@ -53,6 +53,7 @@
     void activeAudioRouteDidChange(Optional<bool>&&);
     void activeVideoRouteDidChange(Optional<bool>&&);
 #endif
+    static WEBCORE_EXPORT void providePresentingApplicationPID();
 
 private:
     friend class PlatformMediaSessionManager;

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


--- trunk/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm	2020-03-05 09:51:14 UTC (rev 257912)
+++ trunk/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm	2020-03-05 11:53:35 UTC (rev 257913)
@@ -174,7 +174,13 @@
     if (m_havePresentedApplicationPID)
         return;
     m_havePresentedApplicationPID = true;
+    providePresentingApplicationPID();
+#endif
+}
 
+void MediaSessionManageriOS::providePresentingApplicationPID()
+{
+#if HAVE(CELESTIAL)
     if (!canLoadAVSystemController_PIDToInheritApplicationStateFrom())
         return;
 

Modified: trunk/Source/WebKit/ChangeLog (257912 => 257913)


--- trunk/Source/WebKit/ChangeLog	2020-03-05 09:51:14 UTC (rev 257912)
+++ trunk/Source/WebKit/ChangeLog	2020-03-05 11:53:35 UTC (rev 257913)
@@ -1,3 +1,38 @@
+2020-03-05  Youenn Fablet  <you...@apple.com>
+
+        Export NowPlaying commands to GPUProcess when media playing in GPUProcess is enabled
+        https://bugs.webkit.org/show_bug.cgi?id=208568
+
+        Reviewed by Eric Carlson.
+
+        Export NowPlaying orders to GPU process through IPC if GPUProcess is turned on.
+        Otherwise use the regular in process implementation.
+        Make sure to sync the hasAudio state so that it gets set properly in WebProcess.
+
+        Remove the use of a PlatformMediaSessionManager for capture since it is now using platform strategies in two places.
+        Instead use directly static methods of MediaSessionManageriOS to implement pid forwarding and AudioSession to set category and buffer size.
+        A follow-up refactoring should probably rearchitect AudioSession handling.
+
+        * GPUProcess/GPUConnectionToWebProcess.cpp:
+        (WebKit::GPUConnectionToWebProcess::clearNowPlayingInfo):
+        (WebKit::GPUConnectionToWebProcess::setNowPlayingInfo):
+        (WebKit::GPUConnectionToWebProcess::sessionManager): Deleted.
+        * GPUProcess/GPUConnectionToWebProcess.h:
+        * GPUProcess/GPUConnectionToWebProcess.messages.in:
+        * GPUProcess/media/RemoteMediaPlayerProxy.cpp:
+        (WebKit::RemoteMediaPlayerProxy::updateCachedState):
+        * UIProcess/Cocoa/UserMediaCaptureManagerProxy.cpp:
+        (WebKit::UserMediaCaptureManagerProxy::SourceProxy::SourceProxy):
+        (WebKit::UserMediaCaptureManagerProxy::SourceProxy::~SourceProxy):
+        (WebKit::UserMediaCaptureManagerProxy::createMediaSourceForCaptureDeviceWithConstraints):
+        (WebKit::UserMediaCaptureManagerProxy::clone):
+        * UIProcess/Cocoa/UserMediaCaptureManagerProxy.h:
+        * UIProcess/WebProcessProxy.cpp:
+        * WebProcess/GPU/media/WebMediaStrategy.cpp:
+        (WebKit::WebMediaStrategy::clearNowPlayingInfo):
+        (WebKit::WebMediaStrategy::setNowPlayingInfo):
+        * WebProcess/GPU/media/WebMediaStrategy.h:
+
 2020-03-05  Carlos Garcia Campos  <cgar...@igalia.com>
 
         REGRESSION(r257667): [UNIX] Tests http/tests/incremental/split-hex-entities.pl and http/tests/misc/large-js-program.php are crashing

Modified: trunk/Source/WebKit/GPUProcess/GPUConnectionToWebProcess.cpp (257912 => 257913)


--- trunk/Source/WebKit/GPUProcess/GPUConnectionToWebProcess.cpp	2020-03-05 09:51:14 UTC (rev 257912)
+++ trunk/Source/WebKit/GPUProcess/GPUConnectionToWebProcess.cpp	2020-03-05 11:53:35 UTC (rev 257913)
@@ -63,6 +63,11 @@
 #include <WebCore/MockRealtimeMediaSourceCenter.h>
 #include <WebCore/PlatformMediaSessionManager.h>
 
+#if PLATFORM(COCOA)
+#include <WebCore/MediaSessionManagerCocoa.h>
+#include <WebCore/MediaSessionManagerIOS.h>
+#endif
+
 #if ENABLE(ENCRYPTED_MEDIA)
 #include "RemoteCDMFactoryProxy.h"
 #include "RemoteCDMFactoryProxyMessages.h"
@@ -88,9 +93,18 @@
     void addMessageReceiver(IPC::StringReference messageReceiverName, IPC::MessageReceiver& receiver) final { }
     void removeMessageReceiver(IPC::StringReference messageReceiverName) final { }
     IPC::Connection& connection() final { return m_process.connection(); }
-    PlatformMediaSessionManager& sessionManager() final { return m_process.sessionManager(); }
-    void willStartCameraCapture() final { sessionManager().prepareToSendUserMediaPermissionRequest(); }
+#if PLATFORM(IOS)
+    void willStartCameraCapture() final
+    {
+        if (m_providedPresentingApplicationPID)
+            return;
+        m_providedPresentingApplicationPID = true;
+        MediaSessionManageriOS::providePresentingApplicationPID();
+    }
 
+    bool m_providedPresentingApplicationPID { false };
+#endif
+
     GPUConnectionToWebProcess& m_process;
 };
 #endif
@@ -231,6 +245,18 @@
     ASSERT_UNUSED(found, found);
 }
 
+#if PLATFORM(COCOA)
+void GPUConnectionToWebProcess::clearNowPlayingInfo()
+{
+    MediaSessionManagerCocoa::clearNowPlayingInfo();
+}
+
+void GPUConnectionToWebProcess::setNowPlayingInfo(bool setAsNowPlayingApplication, const NowPlayingInfo& nowPlayingInfo)
+{
+    MediaSessionManagerCocoa::setNowPlayingInfo(setAsNowPlayingApplication, nowPlayingInfo);
+}
+#endif
+
 bool GPUConnectionToWebProcess::dispatchMessage(IPC::Connection& connection, IPC::Decoder& decoder)
 {
     if (decoder.messageReceiverName() == Messages::RemoteAudioDestinationManager::messageReceiverName()) {
@@ -371,13 +397,6 @@
 }
 #endif
 
-PlatformMediaSessionManager& GPUConnectionToWebProcess::sessionManager()
-{
-    if (!m_sessionManager)
-        m_sessionManager = PlatformMediaSessionManager::create();
-    return *m_sessionManager;
-}
-
 #if ENABLE(MEDIA_STREAM)
 void GPUConnectionToWebProcess::setOrientationForMediaCapture(uint64_t orientation)
 {

Modified: trunk/Source/WebKit/GPUProcess/GPUConnectionToWebProcess.h (257912 => 257913)


--- trunk/Source/WebKit/GPUProcess/GPUConnectionToWebProcess.h	2020-03-05 09:51:14 UTC (rev 257912)
+++ trunk/Source/WebKit/GPUProcess/GPUConnectionToWebProcess.h	2020-03-05 11:53:35 UTC (rev 257913)
@@ -84,8 +84,6 @@
     void setOrientationForMediaCapture(uint64_t orientation);
 #endif
 
-    WebCore::PlatformMediaSessionManager& sessionManager();
-
 #if ENABLE(ENCRYPTED_MEDIA)
     RemoteCDMFactoryProxy& cdmFactoryProxy();
 #endif
@@ -108,6 +106,10 @@
 #endif
     void createRenderingBackend(RenderingBackendIdentifier);
     void releaseRenderingBackend(RenderingBackendIdentifier);
+#if PLATFORM(COCOA)
+    void clearNowPlayingInfo();
+    void setNowPlayingInfo(bool setAsNowPlayingApplication, const WebCore::NowPlayingInfo&);
+#endif
 
     // IPC::Connection::Client
     void didClose(IPC::Connection&) final;

Modified: trunk/Source/WebKit/GPUProcess/GPUConnectionToWebProcess.messages.in (257912 => 257913)


--- trunk/Source/WebKit/GPUProcess/GPUConnectionToWebProcess.messages.in	2020-03-05 09:51:14 UTC (rev 257912)
+++ trunk/Source/WebKit/GPUProcess/GPUConnectionToWebProcess.messages.in	2020-03-05 11:53:35 UTC (rev 257913)
@@ -25,6 +25,10 @@
 messages -> GPUConnectionToWebProcess WantsDispatchMessage {
     void CreateRenderingBackend(WebKit::RenderingBackendIdentifier renderingBackendIdentifier)
     void ReleaseRenderingBackend(WebKit::RenderingBackendIdentifier renderingBackendIdentifier)
+#if PLATFORM(COCOA)
+    void ClearNowPlayingInfo();
+    void SetNowPlayingInfo(bool setAsNowPlayingApplication, struct WebCore::NowPlayingInfo nowPlayingInfo);
+#endif
 }
 
 #endif // ENABLE(GPU_PROCESS)

Modified: trunk/Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.cpp (257912 => 257913)


--- trunk/Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.cpp	2020-03-05 09:51:14 UTC (rev 257912)
+++ trunk/Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.cpp	2020-03-05 11:53:35 UTC (rev 257913)
@@ -679,6 +679,7 @@
     m_cachedState.readyState = m_player->readyState();
     m_cachedState.paused = m_player->paused();
     m_cachedState.loadingProgressed = m_player->didLoadingProgress();
+    m_cachedState.hasAudio = m_player->hasAudio();
 
     if (m_bufferedChanged) {
         m_bufferedChanged = false;

Modified: trunk/Source/WebKit/UIProcess/Cocoa/UserMediaCaptureManagerProxy.cpp (257912 => 257913)


--- trunk/Source/WebKit/UIProcess/Cocoa/UserMediaCaptureManagerProxy.cpp	2020-03-05 09:51:14 UTC (rev 257912)
+++ trunk/Source/WebKit/UIProcess/Cocoa/UserMediaCaptureManagerProxy.cpp	2020-03-05 11:53:35 UTC (rev 257913)
@@ -33,9 +33,9 @@
 #include "UserMediaCaptureManagerProxyMessages.h"
 #include "WebCoreArgumentCoders.h"
 #include "WebProcessProxy.h"
+#include <WebCore/AudioSession.h>
 #include <WebCore/CARingBuffer.h>
 #include <WebCore/MediaConstraints.h>
-#include <WebCore/PlatformMediaSessionManager.h>
 #include <WebCore/RealtimeMediaSourceCenter.h>
 #include <WebCore/RemoteVideoSample.h>
 #include <WebCore/WebAudioBufferList.h>
@@ -46,21 +46,16 @@
 
 class UserMediaCaptureManagerProxy::SourceProxy
     : public RealtimeMediaSource::Observer
-    , public SharedRingBufferStorage::Client
-    , public PlatformMediaSession::AudioCaptureSource {
+    , public SharedRingBufferStorage::Client {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    SourceProxy(RealtimeMediaSourceIdentifier id, PlatformMediaSessionManager& sessionManager, Ref<IPC::Connection>&& connection, Ref<RealtimeMediaSource>&& source)
+    SourceProxy(RealtimeMediaSourceIdentifier id, Ref<IPC::Connection>&& connection, Ref<RealtimeMediaSource>&& source)
         : m_id(id)
-        , m_sessionManager(makeWeakPtr(sessionManager))
         , m_connection(WTFMove(connection))
         , m_source(WTFMove(source))
         , m_ringBuffer(makeUniqueRef<SharedRingBufferStorage>(makeUniqueRef<SharedRingBufferStorage>(this)))
     {
         m_source->addObserver(*this);
-
-        if (m_source->type() == RealtimeMediaSource::Type::Audio)
-            sessionManager.addAudioCaptureSource(*this);
     }
 
     ~SourceProxy()
@@ -67,9 +62,6 @@
     {
         storage().invalidate();
         m_source->removeObserver(*this);
-
-        if (m_source->type() == RealtimeMediaSource::Type::Audio && m_sessionManager)
-            m_sessionManager->removeAudioCaptureSource(*this);
     }
 
     RealtimeMediaSource& source() { return m_source; }
@@ -77,12 +69,13 @@
     CAAudioStreamDescription& description() { return m_description; }
     int64_t numberOfFrames() { return m_numberOfFrames; }
 
-    bool isCapturingAudio() const final { return !m_isEnded && m_source->isProducingData(); }
-
     void audioUnitWillStart() final
     {
-        if (!m_isEnded && m_sessionManager)
-            m_sessionManager->sessionCanProduceAudioChanged();
+        // FIXME: WebProcess might want to set the category/bufferSize itself, in which case we should remove that code.
+        auto bufferSize = AudioSession::sharedSession().sampleRate() / 50;
+        if (AudioSession::sharedSession().preferredBufferSize() > bufferSize)
+            AudioSession::sharedSession().setPreferredBufferSize(bufferSize);
+        AudioSession::sharedSession().setCategory(AudioSession::PlayAndRecord, RouteSharingPolicy::Default);
     }
 
     void start()
@@ -214,7 +207,7 @@
         auto source = sourceOrError.source();
         settings = source->settings();
         ASSERT(!m_proxies.contains(id));
-        m_proxies.add(id, makeUnique<SourceProxy>(id, m_connectionProxy->sessionManager(), m_connectionProxy->connection(), WTFMove(source)));
+        m_proxies.add(id, makeUnique<SourceProxy>(id, m_connectionProxy->connection(), WTFMove(source)));
     } else
         invalidConstraints = WTFMove(sourceOrError.errorMessage);
     completionHandler(succeeded, invalidConstraints, WTFMove(settings));
@@ -270,7 +263,7 @@
     ASSERT(m_proxies.contains(clonedID));
     ASSERT(!m_proxies.contains(newSourceID));
     if (auto* proxy = m_proxies.get(clonedID))
-        m_proxies.add(newSourceID, makeUnique<SourceProxy>(newSourceID, m_connectionProxy->sessionManager(), m_connectionProxy->connection(), proxy->source().clone()));
+        m_proxies.add(newSourceID, makeUnique<SourceProxy>(newSourceID, m_connectionProxy->connection(), proxy->source().clone()));
 }
 
 void UserMediaCaptureManagerProxy::requestToEnd(RealtimeMediaSourceIdentifier sourceID)

Modified: trunk/Source/WebKit/UIProcess/Cocoa/UserMediaCaptureManagerProxy.h (257912 => 257913)


--- trunk/Source/WebKit/UIProcess/Cocoa/UserMediaCaptureManagerProxy.h	2020-03-05 09:51:14 UTC (rev 257912)
+++ trunk/Source/WebKit/UIProcess/Cocoa/UserMediaCaptureManagerProxy.h	2020-03-05 11:53:35 UTC (rev 257913)
@@ -53,7 +53,6 @@
         virtual void addMessageReceiver(IPC::StringReference, IPC::MessageReceiver&) = 0;
         virtual void removeMessageReceiver(IPC::StringReference) = 0;
         virtual IPC::Connection& connection() = 0;
-        virtual WebCore::PlatformMediaSessionManager& sessionManager() = 0;
         virtual void willStartCameraCapture() { }
     };
     explicit UserMediaCaptureManagerProxy(UniqueRef<ConnectionProxy>&&);

Modified: trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp (257912 => 257913)


--- trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp	2020-03-05 09:51:14 UTC (rev 257912)
+++ trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp	2020-03-05 11:53:35 UTC (rev 257913)
@@ -160,7 +160,6 @@
     void addMessageReceiver(IPC::StringReference messageReceiverName, IPC::MessageReceiver& receiver) final { m_process.addMessageReceiver(messageReceiverName, receiver); }
     void removeMessageReceiver(IPC::StringReference messageReceiverName) final { m_process.removeMessageReceiver(messageReceiverName); }
     IPC::Connection& connection() final { return *m_process.connection(); }
-    PlatformMediaSessionManager& sessionManager() final { return PlatformMediaSessionManager::sharedManager(); }
 
     WebProcessProxy& m_process;
 };

Modified: trunk/Source/WebKit/WebProcess/GPU/media/WebMediaStrategy.cpp (257912 => 257913)


--- trunk/Source/WebKit/WebProcess/GPU/media/WebMediaStrategy.cpp	2020-03-05 09:51:14 UTC (rev 257912)
+++ trunk/Source/WebKit/WebProcess/GPU/media/WebMediaStrategy.cpp	2020-03-05 11:53:35 UTC (rev 257913)
@@ -26,6 +26,7 @@
 #include "config.h"
 #include "WebMediaStrategy.h"
 
+#include "GPUConnectionToWebProcess.h"
 #include "GPUProcessConnection.h"
 #include "RemoteAudioDestinationProxy.h"
 #include "RemoteCDMFactory.h"
@@ -33,7 +34,12 @@
 #include <WebCore/AudioDestination.h>
 #include <WebCore/AudioIOCallback.h>
 #include <WebCore/CDMFactory.h>
+#include <WebCore/NowPlayingInfo.h>
 
+#if PLATFORM(COCOA)
+#include <WebCore/MediaSessionManagerCocoa.h>
+#endif
+
 namespace WebKit {
 
 WebMediaStrategy::~WebMediaStrategy() = default;
@@ -63,4 +69,30 @@
 }
 #endif
 
+#if PLATFORM(COCOA)
+void WebMediaStrategy::clearNowPlayingInfo()
+{
+#if ENABLE(GPU_PROCESS)
+    if (m_useGPUProcess) {
+        auto& connection = WebProcess::singleton().ensureGPUProcessConnection().connection();
+        connection.send(Messages::GPUConnectionToWebProcess::ClearNowPlayingInfo { }, 0);
+        return;
+    }
+#endif
+    MediaSessionManagerCocoa::clearNowPlayingInfo();
+}
+
+void WebMediaStrategy::setNowPlayingInfo(bool setAsNowPlayingApplication, const WebCore::NowPlayingInfo& nowPlayingInfo)
+{
+#if ENABLE(GPU_PROCESS)
+    if (m_useGPUProcess) {
+        auto& connection = WebProcess::singleton().ensureGPUProcessConnection().connection();
+        connection.send(Messages::GPUConnectionToWebProcess::SetNowPlayingInfo { setAsNowPlayingApplication, nowPlayingInfo }, 0);
+        return;
+    }
+#endif
+    MediaSessionManagerCocoa::setNowPlayingInfo(setAsNowPlayingApplication, nowPlayingInfo);
+}
+#endif
+
 } // namespace WebKit

Modified: trunk/Source/WebKit/WebProcess/GPU/media/WebMediaStrategy.h (257912 => 257913)


--- trunk/Source/WebKit/WebProcess/GPU/media/WebMediaStrategy.h	2020-03-05 09:51:14 UTC (rev 257912)
+++ trunk/Source/WebKit/WebProcess/GPU/media/WebMediaStrategy.h	2020-03-05 11:53:35 UTC (rev 257913)
@@ -45,6 +45,10 @@
 #if ENABLE(ENCRYPTED_MEDIA)
     void registerCDMFactories(Vector<WebCore::CDMFactory*>&) override;
 #endif
+#if PLATFORM(COCOA)
+    void clearNowPlayingInfo() final;
+    void setNowPlayingInfo(bool setAsNowPlayingApplication, const WebCore::NowPlayingInfo&) final;
+#endif
 
 #if ENABLE(GPU_PROCESS)
     bool m_useGPUProcess { false };

Modified: trunk/Source/WebKitLegacy/mac/ChangeLog (257912 => 257913)


--- trunk/Source/WebKitLegacy/mac/ChangeLog	2020-03-05 09:51:14 UTC (rev 257912)
+++ trunk/Source/WebKitLegacy/mac/ChangeLog	2020-03-05 11:53:35 UTC (rev 257913)
@@ -1,3 +1,14 @@
+2020-03-05  youenn fablet  <you...@apple.com>
+
+        Export NowPlaying commands to GPUProcess when media playing in GPUProcess is enabled
+        https://bugs.webkit.org/show_bug.cgi?id=208568
+
+        Reviewed by Eric Carlson.
+
+        Use in-process now playing implementation.
+
+        * WebCoreSupport/WebPlatformStrategies.mm:
+
 2020-03-04  Ben Nham  <n...@apple.com>
 
         Remove initial layout throttler

Modified: trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebPlatformStrategies.mm (257912 => 257913)


--- trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebPlatformStrategies.mm	2020-03-05 09:51:14 UTC (rev 257912)
+++ trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebPlatformStrategies.mm	2020-03-05 11:53:35 UTC (rev 257913)
@@ -33,6 +33,7 @@
 #import <WebCore/CDMFactory.h>
 #import <WebCore/Color.h>
 #import <WebCore/Frame.h>
+#import <WebCore/MediaSessionManagerCocoa.h>
 #import <WebCore/MediaStrategy.h>
 #import <WebCore/NetworkStorageSession.h>
 #import <WebCore/PasteboardItemInfo.h>
@@ -80,6 +81,15 @@
         return WebCore::CDMFactory::platformRegisterFactories(factories);
     }
 #endif
+    void clearNowPlayingInfo() final
+    {
+        MediaSessionManagerCocoa::clearNowPlayingInfo();
+    }
+
+    void setNowPlayingInfo(bool setAsNowPlayingApplication, const NowPlayingInfo& nowPlayingInfo) final
+    {
+        MediaSessionManagerCocoa::setNowPlayingInfo(setAsNowPlayingApplication, nowPlayingInfo);
+    }
 };
 
 MediaStrategy* WebPlatformStrategies::createMediaStrategy()
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to