Changeset 289100 in webkit


Ignore:
Timestamp:
Feb 3, 2022, 6:45:45 PM (4 years ago)
Author:
Wenson Hsieh
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):

Location:
trunk/Source
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r289099 r289100  
     12022-02-03  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Teach VideoFullscreenInterface to keep track of its corresponding MediaPlayer's MediaPlayerIdentifier
     4        https://bugs.webkit.org/show_bug.cgi?id=236090
     5
     6        Reviewed by Eric Carlson.
     7
     8        Add plumbing for an optional MediaPlayerIdentifier through the video fullscreen model. This identifier is
     9        invalidated upon `loadstart`, and updated once we observe `loadedmetadata`, which ensures that if the media
     10        engine (and media player) changes out from underneath the video fullscreen model, we still keep the new player
     11        ID up to date.
     12
     13        See WebKit/ChangeLog for more details.
     14
     15        * platform/cocoa/VideoFullscreenModel.h:
     16        (WebCore::VideoFullscreenModelClient::setPlayerIdentifier):
     17        * platform/cocoa/VideoFullscreenModelVideoElement.h:
     18        * platform/cocoa/VideoFullscreenModelVideoElement.mm:
     19        (WebCore::VideoFullscreenModelVideoElement::updateForEventName):
     20        (WebCore::VideoFullscreenModelVideoElement::observedEventNames):
     21
     22        Additionally listen for `loadstartEvent` and `loadedmetadataEvent` (see above).
     23
     24        (WebCore::VideoFullscreenModelVideoElement::setPlayerIdentifier):
     25        * platform/ios/VideoFullscreenInterfaceAVKit.h:
     26        * platform/mac/VideoFullscreenInterfaceMac.h:
     27        (WebCore::VideoFullscreenInterfaceMac::playerIdentifier const):
     28
    1292022-02-03  Commit Queue  <commit-queue@webkit.org>
    230
  • trunk/Source/WebCore/platform/cocoa/VideoFullscreenModel.h

    r273276 r289100  
    3333#include "HTMLMediaElementEnums.h"
    3434#include "MediaPlayerEnums.h"
     35#include "MediaPlayerIdentifier.h"
    3536#include "PlaybackSessionModel.h"
    3637#include <wtf/CompletionHandler.h>
     
    8586    virtual void didExitPictureInPicture() { }
    8687    virtual void modelDestroyed() { }
     88    virtual void setPlayerIdentifier(std::optional<MediaPlayerIdentifier>) { }
    8789};
    8890   
  • trunk/Source/WebCore/platform/cocoa/VideoFullscreenModelVideoElement.h

    r287138 r289100  
    3333#include "HTMLMediaElementEnums.h"
    3434#include "MediaPlayerEnums.h"
     35#include "MediaPlayerIdentifier.h"
    3536#include "PlatformLayer.h"
    3637#include "VideoFullscreenModel.h"
     
    8283    void setHasVideo(bool);
    8384    void setVideoDimensions(const FloatSize&);
     85    void setPlayerIdentifier(std::optional<MediaPlayerIdentifier>);
    8486
    8587    void willEnterPictureInPicture() override;
     
    101103    Vector<RefPtr<TextTrack>> m_legibleTracksForMenu;
    102104    Vector<RefPtr<AudioTrack>> m_audioTracksForMenu;
     105    std::optional<MediaPlayerIdentifier> m_playerIdentifier;
    103106};
    104107
  • trunk/Source/WebCore/platform/cocoa/VideoFullscreenModelVideoElement.mm

    r287138 r289100  
    104104        setVideoDimensions(m_videoElement ? FloatSize(m_videoElement->videoWidth(), m_videoElement->videoHeight()) : FloatSize());
    105105    }
     106
     107    if (all
     108        || eventName == eventNames().loadedmetadataEvent || eventName == eventNames().loadstartEvent) {
     109        setPlayerIdentifier([&]() -> std::optional<MediaPlayerIdentifier> {
     110            if (eventName == eventNames().loadstartEvent)
     111                return std::nullopt;
     112
     113            if (!m_videoElement)
     114                return std::nullopt;
     115
     116            auto player = m_videoElement->player();
     117            if (!player)
     118                return std::nullopt;
     119
     120            if (auto identifier = player->identifier())
     121                return identifier;
     122
     123            return std::nullopt;
     124        }());
     125    }
    106126}
    107127
     
    181201Span<const AtomString> VideoFullscreenModelVideoElement::observedEventNames()
    182202{
    183     static NeverDestroyed names = std::array { eventNames().resizeEvent };
     203    static NeverDestroyed names = std::array { eventNames().resizeEvent, eventNames().loadstartEvent, eventNames().loadedmetadataEvent };
    184204    return names.get();
    185205}
     
    239259}
    240260
     261void VideoFullscreenModelVideoElement::setPlayerIdentifier(std::optional<MediaPlayerIdentifier> identifier)
     262{
     263    if (m_playerIdentifier == identifier)
     264        return;
     265
     266    m_playerIdentifier = identifier;
     267
     268    for (auto* client : copyToVector(m_clients))
     269        client->setPlayerIdentifier(identifier);
     270}
     271
    241272void VideoFullscreenModelVideoElement::willEnterPictureInPicture()
    242273{
  • trunk/Source/WebCore/platform/ios/VideoFullscreenInterfaceAVKit.h

    r284857 r289100  
    3131#include "EventListener.h"
    3232#include "HTMLMediaElementEnums.h"
     33#include "MediaPlayerIdentifier.h"
    3334#include "PlatformLayer.h"
    3435#include "PlaybackSessionInterfaceAVKit.h"
     
    7778    WEBCORE_EXPORT void videoDimensionsChanged(const FloatSize&) final;
    7879    WEBCORE_EXPORT void modelDestroyed() final;
     80    void setPlayerIdentifier(std::optional<MediaPlayerIdentifier> identifier) final { m_playerIdentifier = identifier; }
    7981
    8082    // PlaybackSessionModelClient
     
    160162    WEBCORE_EXPORT bool pictureInPictureWasStartedWhenEnteringBackground() const;
    161163
     164    std::optional<MediaPlayerIdentifier> playerIdentifier() const { return m_playerIdentifier; }
     165
    162166protected:
    163167    WEBCORE_EXPORT VideoFullscreenInterfaceAVKit(PlaybackSessionInterfaceAVKit&);
     
    172176
    173177    Ref<PlaybackSessionInterfaceAVKit> m_playbackSessionInterface;
     178    std::optional<MediaPlayerIdentifier> m_playerIdentifier;
    174179    RetainPtr<WebAVPlayerViewControllerDelegate> m_playerViewControllerDelegate;
    175180    RetainPtr<WebAVPlayerViewController> m_playerViewController;
  • trunk/Source/WebCore/platform/mac/VideoFullscreenInterfaceMac.h

    r279043 r289100  
    2929
    3030#include "HTMLMediaElementEnums.h"
     31#include "MediaPlayerIdentifier.h"
    3132#include "PlaybackSessionInterfaceMac.h"
    3233#include "PlaybackSessionModel.h"
     
    7172    WEBCORE_EXPORT void hasVideoChanged(bool) final;
    7273    WEBCORE_EXPORT void videoDimensionsChanged(const FloatSize&) final;
     74    void setPlayerIdentifier(std::optional<MediaPlayerIdentifier> identifier) final { m_playerIdentifier = identifier; }
    7375
    7476    WEBCORE_EXPORT void setupFullscreen(NSView& layerHostedView, const IntRect& initialRect, NSWindow *parentWindow, HTMLMediaElementEnums::VideoFullscreenMode, bool allowsPictureInPicturePlayback);
     
    9799    WEBCORE_EXPORT void requestHideAndExitPiP();
    98100
     101    std::optional<MediaPlayerIdentifier> playerIdentifier() const { return m_playerIdentifier; }
     102
    99103private:
    100104    WEBCORE_EXPORT VideoFullscreenInterfaceMac(PlaybackSessionInterfaceMac&);
    101105    Ref<PlaybackSessionInterfaceMac> m_playbackSessionInterface;
     106    std::optional<MediaPlayerIdentifier> m_playerIdentifier;
    102107    WeakPtr<VideoFullscreenModel> m_videoFullscreenModel;
    103108    WeakPtr<VideoFullscreenChangeObserver> m_fullscreenChangeObserver;
  • trunk/Source/WebKit/ChangeLog

    r289091 r289100  
     12022-02-03  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Teach VideoFullscreenInterface to keep track of its corresponding MediaPlayer's MediaPlayerIdentifier
     4        https://bugs.webkit.org/show_bug.cgi?id=236090
     5
     6        Reviewed by Eric Carlson.
     7
     8        Add an IPC message between VideoFullscreenManager and VideoFullscreenManagerProxy to update the media player ID
     9        corresponding to a given PlaybackSessionContextIdentifier. This is sent if the underlying media player changes
     10        (and subsequently fires `loadstart` and `loadedmetadata` events), and also sent upon entering fullscreen video.
     11
     12        In a future patch, this mechanism will be used to teach VideoFullscreenManagerProxy to grab an image bitmap from
     13        the GPU process for a given PlaybackSessionContextIdentifier.
     14
     15        * UIProcess/Cocoa/VideoFullscreenManagerProxy.h:
     16        * UIProcess/Cocoa/VideoFullscreenManagerProxy.messages.in:
     17        * UIProcess/Cocoa/VideoFullscreenManagerProxy.mm:
     18        (WebKit::VideoFullscreenManagerProxy::setPlayerIdentifier):
     19        * WebProcess/cocoa/VideoFullscreenManager.h:
     20        * WebProcess/cocoa/VideoFullscreenManager.mm:
     21        (WebKit::VideoFullscreenInterfaceContext::setPlayerIdentifier):
     22        (WebKit::VideoFullscreenManager::enterVideoFullscreenForVideoElement):
     23        (WebKit::VideoFullscreenManager::setPlayerIdentifier):
     24
    1252022-02-03  Michael Saboff  <msaboff@apple.com>
    226
  • trunk/Source/WebKit/UIProcess/Cocoa/VideoFullscreenManagerProxy.h

    r289090 r289100  
    3333#include <WebCore/AudioSession.h>
    3434#include <WebCore/GraphicsLayer.h>
     35#include <WebCore/MediaPlayerIdentifier.h>
    3536#include <WebCore/PlatformView.h>
    3637#include <WebCore/VideoFullscreenChangeObserver.h>
     
    181182    void preparedToExitFullscreen(PlaybackSessionContextIdentifier);
    182183    void exitFullscreenWithoutAnimationToMode(PlaybackSessionContextIdentifier, WebCore::HTMLMediaElementEnums::VideoFullscreenMode);
     184    void setPlayerIdentifier(PlaybackSessionContextIdentifier, std::optional<WebCore::MediaPlayerIdentifier>);
    183185
    184186    // Messages to VideoFullscreenManager
  • trunk/Source/WebKit/UIProcess/Cocoa/VideoFullscreenManagerProxy.messages.in

    r277242 r289100  
    2626    SetVideoDimensions(WebKit::PlaybackSessionContextIdentifier contextId, WebCore::FloatSize videoDimensions)
    2727    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)
     28    SetPlayerIdentifier(WebKit::PlaybackSessionContextIdentifier contextId, std::optional<WebCore::MediaPlayerIdentifier> playerIdentifier)
    2829#if !PLATFORM(IOS_FAMILY)
    2930    EnterFullscreen(WebKit::PlaybackSessionContextIdentifier contextId)
  • trunk/Source/WebKit/UIProcess/Cocoa/VideoFullscreenManagerProxy.mm

    r289090 r289100  
    572572}
    573573
     574void VideoFullscreenManagerProxy::setPlayerIdentifier(PlaybackSessionContextIdentifier contextId, std::optional<MediaPlayerIdentifier> playerIdentifier)
     575{
     576    if (m_mockVideoPresentationModeEnabled)
     577        return;
     578
     579    if (auto* interface = findInterface(contextId))
     580        interface->setPlayerIdentifier(playerIdentifier);
     581}
     582
    574583void VideoFullscreenManagerProxy::setHasVideo(PlaybackSessionContextIdentifier contextId, bool hasVideo)
    575584{
  • trunk/Source/WebKit/WebProcess/cocoa/VideoFullscreenManager.h

    r278253 r289100  
    9999    void hasVideoChanged(bool) override;
    100100    void videoDimensionsChanged(const WebCore::FloatSize&) override;
     101    void setPlayerIdentifier(std::optional<WebCore::MediaPlayerIdentifier>) final;
    101102
    102103    VideoFullscreenInterfaceContext(VideoFullscreenManager&, PlaybackSessionContextIdentifier);
     
    147148    void hasVideoChanged(PlaybackSessionContextIdentifier, bool hasVideo);
    148149    void videoDimensionsChanged(PlaybackSessionContextIdentifier, const WebCore::FloatSize&);
     150    void setPlayerIdentifier(PlaybackSessionContextIdentifier, std::optional<WebCore::MediaPlayerIdentifier>);
    149151
    150152    // Messages from VideoFullscreenManagerProxy
  • trunk/Source/WebKit/WebProcess/cocoa/VideoFullscreenManager.mm

    r287731 r289100  
    111111}
    112112
     113void VideoFullscreenInterfaceContext::setPlayerIdentifier(std::optional<MediaPlayerIdentifier> identifier)
     114{
     115    if (m_manager)
     116        m_manager->setPlayerIdentifier(m_contextId, identifier);
     117}
     118
    113119#pragma mark - VideoFullscreenManager
    114120
     
    310316
    311317    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()));
     318
     319    if (auto player = videoElement.player()) {
     320        if (auto identifier = player->identifier())
     321            setPlayerIdentifier(contextId, identifier);
     322    }
    312323}
    313324
     
    376387    if (m_page)
    377388        m_page->send(Messages::VideoFullscreenManagerProxy::SetVideoDimensions(contextId, videoDimensions));
     389}
     390
     391void VideoFullscreenManager::setPlayerIdentifier(PlaybackSessionContextIdentifier contextIdentifier, std::optional<MediaPlayerIdentifier> playerIdentifier)
     392{
     393    if (m_page)
     394        m_page->send(Messages::VideoFullscreenManagerProxy::SetPlayerIdentifier(contextIdentifier, playerIdentifier));
    378395}
    379396
Note: See TracChangeset for help on using the changeset viewer.