Title: [289100] trunk/Source
Revision
289100
Author
wenson_hs...@apple.com
Date
2022-02-03 18:45:45 -0800 (Thu, 03 Feb 2022)

Log Message

Teach VideoFullscreenInterface to keep track of its corresponding MediaPlayer's MediaPlayerIdentifier
https://bugs.webkit.org/show_bug.cgi?id=236090

Reviewed by Eric Carlson.

Source/WebCore:

Add plumbing for an optional MediaPlayerIdentifier through the video fullscreen model. This identifier is
invalidated upon `loadstart`, and updated once we observe `loadedmetadata`, which ensures that if the media
engine (and media player) changes out from underneath the video fullscreen model, we still keep the new player
ID up to date.

See WebKit/ChangeLog for more details.

* platform/cocoa/VideoFullscreenModel.h:
(WebCore::VideoFullscreenModelClient::setPlayerIdentifier):
* platform/cocoa/VideoFullscreenModelVideoElement.h:
* platform/cocoa/VideoFullscreenModelVideoElement.mm:
(WebCore::VideoFullscreenModelVideoElement::updateForEventName):
(WebCore::VideoFullscreenModelVideoElement::observedEventNames):

Additionally listen for `loadstartEvent` and `loadedmetadataEvent` (see above).

(WebCore::VideoFullscreenModelVideoElement::setPlayerIdentifier):
* platform/ios/VideoFullscreenInterfaceAVKit.h:
* platform/mac/VideoFullscreenInterfaceMac.h:
(WebCore::VideoFullscreenInterfaceMac::playerIdentifier const):

Source/WebKit:

Add an IPC message between VideoFullscreenManager and VideoFullscreenManagerProxy to update the media player ID
corresponding to a given PlaybackSessionContextIdentifier. This is sent if the underlying media player changes
(and subsequently fires `loadstart` and `loadedmetadata` events), and also sent upon entering fullscreen video.

In a future patch, this mechanism will be used to teach VideoFullscreenManagerProxy to grab an image bitmap from
the GPU process for a given PlaybackSessionContextIdentifier.

* UIProcess/Cocoa/VideoFullscreenManagerProxy.h:
* UIProcess/Cocoa/VideoFullscreenManagerProxy.messages.in:
* UIProcess/Cocoa/VideoFullscreenManagerProxy.mm:
(WebKit::VideoFullscreenManagerProxy::setPlayerIdentifier):
* WebProcess/cocoa/VideoFullscreenManager.h:
* WebProcess/cocoa/VideoFullscreenManager.mm:
(WebKit::VideoFullscreenInterfaceContext::setPlayerIdentifier):
(WebKit::VideoFullscreenManager::enterVideoFullscreenForVideoElement):
(WebKit::VideoFullscreenManager::setPlayerIdentifier):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (289099 => 289100)


--- trunk/Source/WebCore/ChangeLog	2022-02-04 02:26:07 UTC (rev 289099)
+++ trunk/Source/WebCore/ChangeLog	2022-02-04 02:45:45 UTC (rev 289100)
@@ -1,3 +1,31 @@
+2022-02-03  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        Teach VideoFullscreenInterface to keep track of its corresponding MediaPlayer's MediaPlayerIdentifier
+        https://bugs.webkit.org/show_bug.cgi?id=236090
+
+        Reviewed by Eric Carlson.
+
+        Add plumbing for an optional MediaPlayerIdentifier through the video fullscreen model. This identifier is
+        invalidated upon `loadstart`, and updated once we observe `loadedmetadata`, which ensures that if the media
+        engine (and media player) changes out from underneath the video fullscreen model, we still keep the new player
+        ID up to date.
+
+        See WebKit/ChangeLog for more details.
+
+        * platform/cocoa/VideoFullscreenModel.h:
+        (WebCore::VideoFullscreenModelClient::setPlayerIdentifier):
+        * platform/cocoa/VideoFullscreenModelVideoElement.h:
+        * platform/cocoa/VideoFullscreenModelVideoElement.mm:
+        (WebCore::VideoFullscreenModelVideoElement::updateForEventName):
+        (WebCore::VideoFullscreenModelVideoElement::observedEventNames):
+
+        Additionally listen for `loadstartEvent` and `loadedmetadataEvent` (see above).
+
+        (WebCore::VideoFullscreenModelVideoElement::setPlayerIdentifier):
+        * platform/ios/VideoFullscreenInterfaceAVKit.h:
+        * platform/mac/VideoFullscreenInterfaceMac.h:
+        (WebCore::VideoFullscreenInterfaceMac::playerIdentifier const):
+
 2022-02-03  Commit Queue  <commit-qu...@webkit.org>
 
         Unreviewed, reverting r289096.

Modified: trunk/Source/WebCore/platform/cocoa/VideoFullscreenModel.h (289099 => 289100)


--- trunk/Source/WebCore/platform/cocoa/VideoFullscreenModel.h	2022-02-04 02:26:07 UTC (rev 289099)
+++ trunk/Source/WebCore/platform/cocoa/VideoFullscreenModel.h	2022-02-04 02:45:45 UTC (rev 289100)
@@ -32,6 +32,7 @@
 #include "FloatRect.h"
 #include "HTMLMediaElementEnums.h"
 #include "MediaPlayerEnums.h"
+#include "MediaPlayerIdentifier.h"
 #include "PlaybackSessionModel.h"
 #include <wtf/CompletionHandler.h>
 #include <wtf/WeakPtr.h>
@@ -84,6 +85,7 @@
     virtual void willExitPictureInPicture() { }
     virtual void didExitPictureInPicture() { }
     virtual void modelDestroyed() { }
+    virtual void setPlayerIdentifier(std::optional<MediaPlayerIdentifier>) { }
 };
     
 }

Modified: trunk/Source/WebCore/platform/cocoa/VideoFullscreenModelVideoElement.h (289099 => 289100)


--- trunk/Source/WebCore/platform/cocoa/VideoFullscreenModelVideoElement.h	2022-02-04 02:26:07 UTC (rev 289099)
+++ trunk/Source/WebCore/platform/cocoa/VideoFullscreenModelVideoElement.h	2022-02-04 02:45:45 UTC (rev 289100)
@@ -32,6 +32,7 @@
 #include "FloatRect.h"
 #include "HTMLMediaElementEnums.h"
 #include "MediaPlayerEnums.h"
+#include "MediaPlayerIdentifier.h"
 #include "PlatformLayer.h"
 #include "VideoFullscreenModel.h"
 #include <wtf/Function.h>
@@ -81,6 +82,7 @@
 private:
     void setHasVideo(bool);
     void setVideoDimensions(const FloatSize&);
+    void setPlayerIdentifier(std::optional<MediaPlayerIdentifier>);
 
     void willEnterPictureInPicture() override;
     void didEnterPictureInPicture() override;
@@ -100,6 +102,7 @@
     FloatRect m_videoFrame;
     Vector<RefPtr<TextTrack>> m_legibleTracksForMenu;
     Vector<RefPtr<AudioTrack>> m_audioTracksForMenu;
+    std::optional<MediaPlayerIdentifier> m_playerIdentifier;
 };
 
 }

Modified: trunk/Source/WebCore/platform/cocoa/VideoFullscreenModelVideoElement.mm (289099 => 289100)


--- trunk/Source/WebCore/platform/cocoa/VideoFullscreenModelVideoElement.mm	2022-02-04 02:26:07 UTC (rev 289099)
+++ trunk/Source/WebCore/platform/cocoa/VideoFullscreenModelVideoElement.mm	2022-02-04 02:45:45 UTC (rev 289100)
@@ -103,6 +103,26 @@
         setHasVideo(m_videoElement);
         setVideoDimensions(m_videoElement ? FloatSize(m_videoElement->videoWidth(), m_videoElement->videoHeight()) : FloatSize());
     }
+
+    if (all
+        || eventName == eventNames().loadedmetadataEvent || eventName == eventNames().loadstartEvent) {
+        setPlayerIdentifier([&]() -> std::optional<MediaPlayerIdentifier> {
+            if (eventName == eventNames().loadstartEvent)
+                return std::nullopt;
+
+            if (!m_videoElement)
+                return std::nullopt;
+
+            auto player = m_videoElement->player();
+            if (!player)
+                return std::nullopt;
+
+            if (auto identifier = player->identifier())
+                return identifier;
+
+            return std::nullopt;
+        }());
+    }
 }
 
 void VideoFullscreenModelVideoElement::willExitFullscreen()
@@ -180,7 +200,7 @@
 
 Span<const AtomString> VideoFullscreenModelVideoElement::observedEventNames()
 {
-    static NeverDestroyed names = std::array { eventNames().resizeEvent };
+    static NeverDestroyed names = std::array { eventNames().resizeEvent, eventNames().loadstartEvent, eventNames().loadedmetadataEvent };
     return names.get();
 }
 
@@ -238,6 +258,17 @@
         client->videoDimensionsChanged(m_videoDimensions);
 }
 
+void VideoFullscreenModelVideoElement::setPlayerIdentifier(std::optional<MediaPlayerIdentifier> identifier)
+{
+    if (m_playerIdentifier == identifier)
+        return;
+
+    m_playerIdentifier = identifier;
+
+    for (auto* client : copyToVector(m_clients))
+        client->setPlayerIdentifier(identifier);
+}
+
 void VideoFullscreenModelVideoElement::willEnterPictureInPicture()
 {
     for (auto& client : copyToVector(m_clients))

Modified: trunk/Source/WebCore/platform/ios/VideoFullscreenInterfaceAVKit.h (289099 => 289100)


--- trunk/Source/WebCore/platform/ios/VideoFullscreenInterfaceAVKit.h	2022-02-04 02:26:07 UTC (rev 289099)
+++ trunk/Source/WebCore/platform/ios/VideoFullscreenInterfaceAVKit.h	2022-02-04 02:45:45 UTC (rev 289100)
@@ -30,6 +30,7 @@
 
 #include "EventListener.h"
 #include "HTMLMediaElementEnums.h"
+#include "MediaPlayerIdentifier.h"
 #include "PlatformLayer.h"
 #include "PlaybackSessionInterfaceAVKit.h"
 #include "VideoFullscreenModel.h"
@@ -76,6 +77,7 @@
     WEBCORE_EXPORT void hasVideoChanged(bool) final;
     WEBCORE_EXPORT void videoDimensionsChanged(const FloatSize&) final;
     WEBCORE_EXPORT void modelDestroyed() final;
+    void setPlayerIdentifier(std::optional<MediaPlayerIdentifier> identifier) final { m_playerIdentifier = identifier; }
 
     // PlaybackSessionModelClient
     WEBCORE_EXPORT void externalPlaybackChanged(bool enabled, PlaybackSessionModel::ExternalPlaybackTargetType, const String& localizedDeviceName) final;
@@ -159,6 +161,8 @@
     WebAVPlayerLayerView* playerLayerView() const { return m_playerLayerView.get(); }
     WEBCORE_EXPORT bool pictureInPictureWasStartedWhenEnteringBackground() const;
 
+    std::optional<MediaPlayerIdentifier> playerIdentifier() const { return m_playerIdentifier; }
+
 protected:
     WEBCORE_EXPORT VideoFullscreenInterfaceAVKit(PlaybackSessionInterfaceAVKit&);
 
@@ -171,6 +175,7 @@
     WebAVPlayerController *playerController() const;
 
     Ref<PlaybackSessionInterfaceAVKit> m_playbackSessionInterface;
+    std::optional<MediaPlayerIdentifier> m_playerIdentifier;
     RetainPtr<WebAVPlayerViewControllerDelegate> m_playerViewControllerDelegate;
     RetainPtr<WebAVPlayerViewController> m_playerViewController;
     VideoFullscreenModel* m_videoFullscreenModel { nullptr };

Modified: trunk/Source/WebCore/platform/mac/VideoFullscreenInterfaceMac.h (289099 => 289100)


--- trunk/Source/WebCore/platform/mac/VideoFullscreenInterfaceMac.h	2022-02-04 02:26:07 UTC (rev 289099)
+++ trunk/Source/WebCore/platform/mac/VideoFullscreenInterfaceMac.h	2022-02-04 02:45:45 UTC (rev 289100)
@@ -28,6 +28,7 @@
 #if PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE)
 
 #include "HTMLMediaElementEnums.h"
+#include "MediaPlayerIdentifier.h"
 #include "PlaybackSessionInterfaceMac.h"
 #include "PlaybackSessionModel.h"
 #include "VideoFullscreenModel.h"
@@ -70,6 +71,7 @@
     // VideoFullscreenModelClient
     WEBCORE_EXPORT void hasVideoChanged(bool) final;
     WEBCORE_EXPORT void videoDimensionsChanged(const FloatSize&) final;
+    void setPlayerIdentifier(std::optional<MediaPlayerIdentifier> identifier) final { m_playerIdentifier = identifier; }
 
     WEBCORE_EXPORT void setupFullscreen(NSView& layerHostedView, const IntRect& initialRect, NSWindow *parentWindow, HTMLMediaElementEnums::VideoFullscreenMode, bool allowsPictureInPicturePlayback);
     WEBCORE_EXPORT void enterFullscreen();
@@ -96,9 +98,12 @@
 
     WEBCORE_EXPORT void requestHideAndExitPiP();
 
+    std::optional<MediaPlayerIdentifier> playerIdentifier() const { return m_playerIdentifier; }
+
 private:
     WEBCORE_EXPORT VideoFullscreenInterfaceMac(PlaybackSessionInterfaceMac&);
     Ref<PlaybackSessionInterfaceMac> m_playbackSessionInterface;
+    std::optional<MediaPlayerIdentifier> m_playerIdentifier;
     WeakPtr<VideoFullscreenModel> m_videoFullscreenModel;
     WeakPtr<VideoFullscreenChangeObserver> m_fullscreenChangeObserver;
     HTMLMediaElementEnums::VideoFullscreenMode m_mode { HTMLMediaElementEnums::VideoFullscreenModeNone };

Modified: trunk/Source/WebKit/ChangeLog (289099 => 289100)


--- trunk/Source/WebKit/ChangeLog	2022-02-04 02:26:07 UTC (rev 289099)
+++ trunk/Source/WebKit/ChangeLog	2022-02-04 02:45:45 UTC (rev 289100)
@@ -1,3 +1,27 @@
+2022-02-03  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        Teach VideoFullscreenInterface to keep track of its corresponding MediaPlayer's MediaPlayerIdentifier
+        https://bugs.webkit.org/show_bug.cgi?id=236090
+
+        Reviewed by Eric Carlson.
+
+        Add an IPC message between VideoFullscreenManager and VideoFullscreenManagerProxy to update the media player ID
+        corresponding to a given PlaybackSessionContextIdentifier. This is sent if the underlying media player changes
+        (and subsequently fires `loadstart` and `loadedmetadata` events), and also sent upon entering fullscreen video.
+
+        In a future patch, this mechanism will be used to teach VideoFullscreenManagerProxy to grab an image bitmap from
+        the GPU process for a given PlaybackSessionContextIdentifier.
+
+        * UIProcess/Cocoa/VideoFullscreenManagerProxy.h:
+        * UIProcess/Cocoa/VideoFullscreenManagerProxy.messages.in:
+        * UIProcess/Cocoa/VideoFullscreenManagerProxy.mm:
+        (WebKit::VideoFullscreenManagerProxy::setPlayerIdentifier):
+        * WebProcess/cocoa/VideoFullscreenManager.h:
+        * WebProcess/cocoa/VideoFullscreenManager.mm:
+        (WebKit::VideoFullscreenInterfaceContext::setPlayerIdentifier):
+        (WebKit::VideoFullscreenManager::enterVideoFullscreenForVideoElement):
+        (WebKit::VideoFullscreenManager::setPlayerIdentifier):
+
 2022-02-03  Michael Saboff  <msab...@apple.com>
 
         WebKit projects have incorrect install name for the frameworks for Catalyst builds with the system content path

Modified: trunk/Source/WebKit/UIProcess/Cocoa/VideoFullscreenManagerProxy.h (289099 => 289100)


--- trunk/Source/WebKit/UIProcess/Cocoa/VideoFullscreenManagerProxy.h	2022-02-04 02:26:07 UTC (rev 289099)
+++ trunk/Source/WebKit/UIProcess/Cocoa/VideoFullscreenManagerProxy.h	2022-02-04 02:45:45 UTC (rev 289100)
@@ -32,6 +32,7 @@
 #include "PlaybackSessionContextIdentifier.h"
 #include <WebCore/AudioSession.h>
 #include <WebCore/GraphicsLayer.h>
+#include <WebCore/MediaPlayerIdentifier.h>
 #include <WebCore/PlatformView.h>
 #include <WebCore/VideoFullscreenChangeObserver.h>
 #include <WebCore/VideoFullscreenModel.h>
@@ -180,6 +181,7 @@
     void preparedToReturnToInline(PlaybackSessionContextIdentifier, bool visible, WebCore::FloatRect inlineRect);
     void preparedToExitFullscreen(PlaybackSessionContextIdentifier);
     void exitFullscreenWithoutAnimationToMode(PlaybackSessionContextIdentifier, WebCore::HTMLMediaElementEnums::VideoFullscreenMode);
+    void setPlayerIdentifier(PlaybackSessionContextIdentifier, std::optional<WebCore::MediaPlayerIdentifier>);
 
     // Messages to VideoFullscreenManager
     void requestFullscreenMode(PlaybackSessionContextIdentifier, WebCore::HTMLMediaElementEnums::VideoFullscreenMode, bool finishedWithMedia = false);

Modified: trunk/Source/WebKit/UIProcess/Cocoa/VideoFullscreenManagerProxy.messages.in (289099 => 289100)


--- trunk/Source/WebKit/UIProcess/Cocoa/VideoFullscreenManagerProxy.messages.in	2022-02-04 02:26:07 UTC (rev 289099)
+++ trunk/Source/WebKit/UIProcess/Cocoa/VideoFullscreenManagerProxy.messages.in	2022-02-04 02:45:45 UTC (rev 289100)
@@ -25,6 +25,7 @@
     SetHasVideo(WebKit::PlaybackSessionContextIdentifier contextId, bool hasVideo)
     SetVideoDimensions(WebKit::PlaybackSessionContextIdentifier contextId, WebCore::FloatSize videoDimensions)
     SetupFullscreenWithID(WebKit::PlaybackSessionContextIdentifier contextId, WebKit::LayerHostingContextID videoLayerID, WebCore::FloatRect initialRect, WebCore::FloatSize videoDimensions, float hostingScaleFactor, WebCore::HTMLMediaElementEnums::VideoFullscreenMode videoFullscreenMode, bool allowsPictureInPicture, bool standby, bool blocksReturnToFullscreenFromPictureInPicture)
+    SetPlayerIdentifier(WebKit::PlaybackSessionContextIdentifier contextId, std::optional<WebCore::MediaPlayerIdentifier> playerIdentifier)
 #if !PLATFORM(IOS_FAMILY)
     EnterFullscreen(WebKit::PlaybackSessionContextIdentifier contextId)
 #endif

Modified: trunk/Source/WebKit/UIProcess/Cocoa/VideoFullscreenManagerProxy.mm (289099 => 289100)


--- trunk/Source/WebKit/UIProcess/Cocoa/VideoFullscreenManagerProxy.mm	2022-02-04 02:26:07 UTC (rev 289099)
+++ trunk/Source/WebKit/UIProcess/Cocoa/VideoFullscreenManagerProxy.mm	2022-02-04 02:45:45 UTC (rev 289100)
@@ -571,6 +571,15 @@
 #endif
 }
 
+void VideoFullscreenManagerProxy::setPlayerIdentifier(PlaybackSessionContextIdentifier contextId, std::optional<MediaPlayerIdentifier> playerIdentifier)
+{
+    if (m_mockVideoPresentationModeEnabled)
+        return;
+
+    if (auto* interface = findInterface(contextId))
+        interface->setPlayerIdentifier(playerIdentifier);
+}
+
 void VideoFullscreenManagerProxy::setHasVideo(PlaybackSessionContextIdentifier contextId, bool hasVideo)
 {
     if (m_mockVideoPresentationModeEnabled)

Modified: trunk/Source/WebKit/WebProcess/cocoa/VideoFullscreenManager.h (289099 => 289100)


--- trunk/Source/WebKit/WebProcess/cocoa/VideoFullscreenManager.h	2022-02-04 02:26:07 UTC (rev 289099)
+++ trunk/Source/WebKit/WebProcess/cocoa/VideoFullscreenManager.h	2022-02-04 02:45:45 UTC (rev 289100)
@@ -98,6 +98,7 @@
     // VideoFullscreenModelClient
     void hasVideoChanged(bool) override;
     void videoDimensionsChanged(const WebCore::FloatSize&) override;
+    void setPlayerIdentifier(std::optional<WebCore::MediaPlayerIdentifier>) final;
 
     VideoFullscreenInterfaceContext(VideoFullscreenManager&, PlaybackSessionContextIdentifier);
 
@@ -146,6 +147,7 @@
     // Interface to VideoFullscreenInterfaceContext
     void hasVideoChanged(PlaybackSessionContextIdentifier, bool hasVideo);
     void videoDimensionsChanged(PlaybackSessionContextIdentifier, const WebCore::FloatSize&);
+    void setPlayerIdentifier(PlaybackSessionContextIdentifier, std::optional<WebCore::MediaPlayerIdentifier>);
 
     // Messages from VideoFullscreenManagerProxy
     void requestFullscreenMode(PlaybackSessionContextIdentifier, WebCore::HTMLMediaElementEnums::VideoFullscreenMode, bool finishedWithMedia);

Modified: trunk/Source/WebKit/WebProcess/cocoa/VideoFullscreenManager.mm (289099 => 289100)


--- trunk/Source/WebKit/WebProcess/cocoa/VideoFullscreenManager.mm	2022-02-04 02:26:07 UTC (rev 289099)
+++ trunk/Source/WebKit/WebProcess/cocoa/VideoFullscreenManager.mm	2022-02-04 02:45:45 UTC (rev 289100)
@@ -110,6 +110,12 @@
         m_manager->videoDimensionsChanged(m_contextId, videoDimensions);
 }
 
+void VideoFullscreenInterfaceContext::setPlayerIdentifier(std::optional<MediaPlayerIdentifier> identifier)
+{
+    if (m_manager)
+        m_manager->setPlayerIdentifier(m_contextId, identifier);
+}
+
 #pragma mark - VideoFullscreenManager
 
 Ref<VideoFullscreenManager> VideoFullscreenManager::create(WebPage& page, PlaybackSessionManager& playbackSessionManager)
@@ -309,6 +315,11 @@
     }
 
     m_page->send(Messages::VideoFullscreenManagerProxy::SetupFullscreenWithID(contextId, interface->layerHostingContext()->contextID(), videoRect, FloatSize(videoElement.videoWidth(), videoElement.videoHeight()), m_page->deviceScaleFactor(), interface->fullscreenMode(), allowsPictureInPicture, standby, videoElement.document().quirks().blocksReturnToFullscreenFromPictureInPictureQuirk()));
+
+    if (auto player = videoElement.player()) {
+        if (auto identifier = player->identifier())
+            setPlayerIdentifier(contextId, identifier);
+    }
 }
 
 void VideoFullscreenManager::exitVideoFullscreenForVideoElement(HTMLVideoElement& videoElement, CompletionHandler<void(bool)>&& completionHandler)
@@ -377,6 +388,12 @@
         m_page->send(Messages::VideoFullscreenManagerProxy::SetVideoDimensions(contextId, videoDimensions));
 }
 
+void VideoFullscreenManager::setPlayerIdentifier(PlaybackSessionContextIdentifier contextIdentifier, std::optional<MediaPlayerIdentifier> playerIdentifier)
+{
+    if (m_page)
+        m_page->send(Messages::VideoFullscreenManagerProxy::SetPlayerIdentifier(contextIdentifier, playerIdentifier));
+}
+
 #pragma mark Messages from VideoFullscreenManagerProxy:
 
 void VideoFullscreenManager::requestFullscreenMode(PlaybackSessionContextIdentifier contextId, WebCore::HTMLMediaElementEnums::VideoFullscreenMode mode, bool finishedWithMedia)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to