Skip to content

Commit

Permalink
[visionOS] Changing video.src while in video fullscreen results in bl…
Browse files Browse the repository at this point in the history
…ack video

https://bugs.webkit.org/show_bug.cgi?id=274002
rdar://125926759

Reviewed by NOBODY (OOPS!).

A FigVideoTarget can only be used with one renderer at a time, and once a target has been created from an XPC
endpoint, it cannot be re-used to create another FigVideoTarget. The combination of these requirements means
that once a FigVideoTarget has been created for a given HTMLMediaElement, it must be cached and re-used for
subsequent MediaPlayers created by that HTMLMediaElement.

To allow the WebCore/platform layer to identify the owner of a MediaPlayer (typically a HTMLMediaElement, but
in WebKit this will be a RemoteMediaPlayerProxy), add a new MediaPlayerClientIdentifier and make the existing
HTMLMediaElementIdentifier an alias for that new identifier.

Add a utility class/namespace to convert XPC endpoints to a FigVideoTarget, and add a new PlatformVideoTarget
type to wrap FigVideoTarget.

Add methods to MediaPlayer to allow MediaPlayerPrivates to query for an existing PlatformVideoTarget. Rename
MediaPlayer setVideoEndpoint() methods to setVideoTarget().

Add a cache of PlatformVideoTargets (and endpoints, and MediaPlayerIdentifiers) in RemoteMediaPlayerManagerProxy.
Having the cache exist on this object means that it will automatically be cleared when the associated WebContent
process exits.

Add new messaging from the UIProcess to explicitly clear cached PlatformVideoTargets when the video interface
in the UIProcess is closed.

* Source/WebCore/Headers.cmake:
* Source/WebCore/SourcesCocoa.txt:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/html/HTMLMediaElement.h:
* Source/WebCore/html/HTMLMediaElementIdentifier.h:
* Source/WebCore/platform/VideoReceiverEndpoint.h:
* Source/WebCore/platform/graphics/MediaPlayer.h:
(WebCore::MediaPlayerClient::mediaPlayerVideoTarget const):
(WebCore::MediaPlayerClient::mediaPlayerClientIdentifier const):
* Source/WebCore/platform/graphics/MediaPlayerClientIdentifier.h: Copied from Source/WebCore/html/HTMLMediaElementIdentifier.h.
* Source/WebCore/platform/graphics/MediaPlayerPrivate.h:
(WebCore::MediaPlayerPrivateInterface::setVideoTarget):
(WebCore::MediaPlayerPrivateInterface::setVideoReceiverEndpoint): Deleted.
* Source/WebCore/platform/graphics/VideoTarget.h: Copied from Source/WebCore/platform/VideoReceiverEndpoint.h.
* Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
* Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::MediaPlayerPrivateAVFoundationObjC::MediaPlayerPrivateAVFoundationObjC):
(WebCore::MediaPlayerPrivateAVFoundationObjC::cancelLoad):
(WebCore::MediaPlayerPrivateAVFoundationObjC::createAVPlayer):
(WebCore::MediaPlayerPrivateAVFoundationObjC::setVideoTarget):
(WebCore::MediaPlayerPrivateAVFoundationObjC::isInFullscreenOrPictureInPictureChanged):
(WebCore::MediaPlayerPrivateAVFoundationObjC::setVideoReceiverEndpoint): Deleted.
* Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.h:
* Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm:
(WebCore::MediaPlayerPrivateMediaSourceAVFObjC::MediaPlayerPrivateMediaSourceAVFObjC):
(WebCore::MediaPlayerPrivateMediaSourceAVFObjC::destroyVideoRenderer):
(WebCore::MediaPlayerPrivateMediaSourceAVFObjC::setVideoTarget):
(WebCore::MediaPlayerPrivateMediaSourceAVFObjC::setVideoReceiverEndpoint): Deleted.
* Source/WebCore/platform/graphics/cocoa/MediaPlayerCocoa.mm:
(WebCore::MediaPlayer::setVideoTarget):
(WebCore::MediaPlayer::setVideoReceiverEndpoint): Deleted.
* Source/WebCore/platform/graphics/cocoa/VideoTargetFactory.h: Copied from Source/WebCore/platform/VideoReceiverEndpoint.h.
* Source/WebCore/platform/graphics/cocoa/VideoTargetFactory.mm: Copied from Source/WebCore/platform/VideoReceiverEndpoint.h.
(WebCore::VideoTargetFactory::createTargetFromEndpoint):
* Source/WebKit/GPUProcess/media/RemoteMediaPlayerManagerProxy.cpp:
(WebKit::RemoteMediaPlayerManagerProxy::createMediaPlayer):
* Source/WebKit/GPUProcess/media/RemoteMediaPlayerManagerProxy.h:
* Source/WebKit/GPUProcess/media/RemoteMediaPlayerManagerProxy.messages.in:
* Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.cpp:
(WebKit::RemoteMediaPlayerProxy::create):
(WebKit::RemoteMediaPlayerProxy::RemoteMediaPlayerProxy):
(WebKit::RemoteMediaPlayerProxy::mediaPlayerVideoTarget const):
* Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.h:
* Source/WebKit/GPUProcess/media/cocoa/RemoteMediaPlayerManagerProxyCocoa.mm: Added.
(WebKit::RemoteMediaPlayerManagerProxy::videoTargetForMediaElementIdentifier):
(WebKit::RemoteMediaPlayerManagerProxy::handleVideoReceiverEndpointMessage):
* Source/WebKit/Platform/ios/VideoReceiverEndpointMessage.h:
(WebKit::VideoReceiverEndpointMessage::mediaElementIdentifier const):
* Source/WebKit/Platform/ios/VideoReceiverEndpointMessage.mm:
(WebKit::VideoReceiverEndpointMessage::VideoReceiverEndpointMessage):
(WebKit::VideoReceiverEndpointMessage::decode):
(WebKit::VideoReceiverEndpointMessage::encode const):
* Source/WebKit/Scripts/webkit/messages.py:
(serialized_identifiers):
* Source/WebKit/Shared/EntryPointUtilities/Cocoa/XPCService/XPCEndpointMessages.mm:
(WebKit::handleVideoReceiverEndpointMessage):
* Source/WebKit/Shared/WTFArgumentCoders.serialization.in:
* Source/WebKit/SourcesCocoa.txt:
* Source/WebKit/UIProcess/Cocoa/PlaybackSessionManagerProxy.h:
* Source/WebKit/UIProcess/Cocoa/PlaybackSessionManagerProxy.mm:
(WebKit::PlaybackSessionModelContext::~PlaybackSessionModelContext):
(WebKit::PlaybackSessionModelContext::setVideoReceiverEndpoint):
(WebKit::PlaybackSessionManagerProxy::setVideoReceiverEndpoint):
(WebKit::PlaybackSessionManagerProxy::uncacheVideoReceiverEndpoint):
* Source/WebKit/UIProcess/WebPageProxy.h:
* Source/WebKit/WebKit.xcodeproj/project.pbxproj:
* Source/WebKit/WebProcess/GPU/media/RemoteMediaPlayerManager.cpp:
(WebKit::RemoteMediaPlayerManager::createRemoteMediaPlayer):
  • Loading branch information
jernoble committed May 10, 2024
1 parent fdea881 commit 415dbd7
Show file tree
Hide file tree
Showing 34 changed files with 483 additions and 66 deletions.
2 changes: 2 additions & 0 deletions Source/WebCore/Headers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1995,6 +1995,7 @@ set(WebCore_PRIVATE_FRAMEWORK_HEADERS
platform/graphics/MediaPlaybackTargetClient.h
platform/graphics/MediaPlaybackTargetPicker.h
platform/graphics/MediaPlayer.h
platform/graphics/MediaPlayerClientIdentifier.h
platform/graphics/MediaPlayerEnums.h
platform/graphics/MediaPlayerIdentifier.h
platform/graphics/MediaPlayerPrivate.h
Expand Down Expand Up @@ -2066,6 +2067,7 @@ set(WebCore_PRIVATE_FRAMEWORK_HEADERS
platform/graphics/VelocityData.h
platform/graphics/VideoLayerManager.h
platform/graphics/VideoPlaybackQualityMetrics.h
platform/graphics/VideoTarget.h
platform/graphics/VideoTrackPrivate.h
platform/graphics/VideoTrackPrivateClient.h
platform/graphics/WidthCache.h
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/SourcesCocoa.txt
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ platform/graphics/cocoa/TextTrackRepresentationCocoa.mm
platform/graphics/cocoa/TransformationMatrixCocoa.cpp
platform/graphics/cocoa/UnrealizedCoreTextFont.cpp
platform/graphics/cocoa/VP9UtilitiesCocoa.mm @no-unify
platform/graphics/cocoa/VideoTargetFactory.mm @no-unify
platform/graphics/cocoa/WebActionDisablingCALayerDelegate.mm
platform/graphics/cocoa/WebCoreCALayerExtras.mm
platform/graphics/cocoa/WebCoreDecompressionSession.mm
Expand Down
16 changes: 16 additions & 0 deletions Source/WebCore/WebCore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -5150,6 +5150,7 @@
CD3EEF4125799FD9006563BB /* TransferFunction.h in Headers */ = {isa = PBXBuildFile; fileRef = CD4E4E9A2357CB9C007895C3 /* TransferFunction.h */; settings = {ATTRIBUTES = (Private, ); }; };
CD3EEF422579B44A006563BB /* MediaEngineConfigurationFactory.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC6F02521148F5400CBDA06 /* MediaEngineConfigurationFactory.h */; settings = {ATTRIBUTES = (Private, ); }; };
CD4AC52A1496AE9A0087C4EF /* Composite.wav in Copy Audio Resources */ = {isa = PBXBuildFile; fileRef = CD4AC5281496AE2F0087C4EF /* Composite.wav */; };
CD51ECD12BEE06FD00632253 /* MediaPlayerClientIdentifier.h in Headers */ = {isa = PBXBuildFile; fileRef = CD51ECD02BEE06FD00632253 /* MediaPlayerClientIdentifier.h */; settings = {ATTRIBUTES = (Private, ); }; };
CD5209E41B0BD8380077184E /* MediaPlayerEnums.h in Headers */ = {isa = PBXBuildFile; fileRef = CD5209E31B0BD8380077184E /* MediaPlayerEnums.h */; settings = {ATTRIBUTES = (Private, ); }; };
CD5209E61B0BD9E10077184E /* HTMLMediaElementEnums.h in Headers */ = {isa = PBXBuildFile; fileRef = CD5209E51B0BD9E10077184E /* HTMLMediaElementEnums.h */; settings = {ATTRIBUTES = (Private, ); }; };
CD525BA41EE0B10700788DF5 /* FourCC.h in Headers */ = {isa = PBXBuildFile; fileRef = CD525BA21EE0B10700788DF5 /* FourCC.h */; settings = {ATTRIBUTES = (Private, ); }; };
Expand Down Expand Up @@ -5223,6 +5224,9 @@
CDAB6D3117C9259500C60B34 /* UserAgentScripts.h in Headers */ = {isa = PBXBuildFile; fileRef = CDAB6D2F17C9259500C60B34 /* UserAgentScripts.h */; };
CDAC068324C6A95A002F727F /* VP9UtilitiesCocoa.h in Headers */ = {isa = PBXBuildFile; fileRef = CD6FE5B724BCE645009FCDA4 /* VP9UtilitiesCocoa.h */; settings = {ATTRIBUTES = (Private, ); }; };
CDAD1A5A27AFC27C00699285 /* ContentTypeUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = CDAD1A5727AFBF3900699285 /* ContentTypeUtilities.h */; settings = {ATTRIBUTES = (Private, ); }; };
CDAD8DF12BEC7EDF00107D24 /* VideoTargetFactory.mm in Sources */ = {isa = PBXBuildFile; fileRef = CDAD8DEE2BEC7B8000107D24 /* VideoTargetFactory.mm */; };
CDAD8DFB2BED3B0200107D24 /* VideoTarget.h in Headers */ = {isa = PBXBuildFile; fileRef = CDAD8DF42BED37E600107D24 /* VideoTarget.h */; settings = {ATTRIBUTES = (Private, ); }; };
CDAD8DFC2BED4D2C00107D24 /* VideoTargetFactory.h in Headers */ = {isa = PBXBuildFile; fileRef = CDAD8DED2BEC7B8000107D24 /* VideoTargetFactory.h */; settings = {ATTRIBUTES = (Private, ); }; };
CDB6354923F6023A00C0F9DE /* WebAVPlayerController.h in Headers */ = {isa = PBXBuildFile; fileRef = CDA29A2C1CBF73FC00901CCF /* WebAVPlayerController.h */; settings = {ATTRIBUTES = (Private, ); }; };
CDB7045A1F7465A1003923DF /* CDMFairPlayStreaming.h in Headers */ = {isa = PBXBuildFile; fileRef = CDB704581F7465A1003923DF /* CDMFairPlayStreaming.h */; };
CDB7045B1F7465A1003923DF /* CDMFairPlayStreaming.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDB704591F7465A1003923DF /* CDMFairPlayStreaming.cpp */; };
Expand Down Expand Up @@ -18276,6 +18280,7 @@
CD4E4E9A2357CB9C007895C3 /* TransferFunction.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = TransferFunction.h; path = mediacapabilities/TransferFunction.h; sourceTree = "<group>"; };
CD4E4E9B2357CB9D007895C3 /* ColorGamut.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ColorGamut.h; path = mediacapabilities/ColorGamut.h; sourceTree = "<group>"; };
CD4E4E9C2357CB9D007895C3 /* HdrMetadataType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = HdrMetadataType.h; path = mediacapabilities/HdrMetadataType.h; sourceTree = "<group>"; };
CD51ECD02BEE06FD00632253 /* MediaPlayerClientIdentifier.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MediaPlayerClientIdentifier.h; sourceTree = "<group>"; };
CD5209E31B0BD8380077184E /* MediaPlayerEnums.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaPlayerEnums.h; sourceTree = "<group>"; };
CD5209E51B0BD9E10077184E /* HTMLMediaElementEnums.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTMLMediaElementEnums.h; sourceTree = "<group>"; };
CD525BA21EE0B10700788DF5 /* FourCC.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FourCC.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -18442,6 +18447,9 @@
CDAB6D3017C9259500C60B34 /* UserAgentScriptsData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UserAgentScriptsData.cpp; sourceTree = "<group>"; };
CDAD1A5727AFBF3900699285 /* ContentTypeUtilities.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ContentTypeUtilities.h; sourceTree = "<group>"; };
CDAD1A5827AFBF3900699285 /* ContentTypeUtilities.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ContentTypeUtilities.cpp; sourceTree = "<group>"; };
CDAD8DED2BEC7B8000107D24 /* VideoTargetFactory.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VideoTargetFactory.h; sourceTree = "<group>"; };
CDAD8DEE2BEC7B8000107D24 /* VideoTargetFactory.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = VideoTargetFactory.mm; sourceTree = "<group>"; };
CDAD8DF42BED37E600107D24 /* VideoTarget.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VideoTarget.h; sourceTree = "<group>"; };
CDAE8C071746B95700532D78 /* PlatformMediaSessionManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PlatformMediaSessionManager.cpp; sourceTree = "<group>"; };
CDAE8C081746B95700532D78 /* PlatformMediaSessionManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformMediaSessionManager.h; sourceTree = "<group>"; };
CDB704581F7465A1003923DF /* CDMFairPlayStreaming.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CDMFairPlayStreaming.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -32894,6 +32902,7 @@
078E43D81ABB6C7E001C2FA6 /* MediaPlaybackTargetPicker.h */,
E4B41E0C0CBF90BD00AF2ECE /* MediaPlayer.cpp */,
E4B41E0D0CBF90BD00AF2ECE /* MediaPlayer.h */,
CD51ECD02BEE06FD00632253 /* MediaPlayerClientIdentifier.h */,
CD5209E31B0BD8380077184E /* MediaPlayerEnums.h */,
F429261725264D4400007898 /* MediaPlayerIdentifier.h */,
CD90C0702992D5D6004C21AD /* MediaPlayerPrivate.cpp */,
Expand Down Expand Up @@ -33021,6 +33030,7 @@
0F1A0C36229A481800D37ADB /* VelocityData.h */,
1DAB3113251D725C00FC9485 /* VideoLayerManager.h */,
075033A6252BD36800F70CE3 /* VideoPlaybackQualityMetrics.h */,
CDAD8DF42BED37E600107D24 /* VideoTarget.h */,
BEF29EEA1715DD0900C4B4C9 /* VideoTrackPrivate.h */,
CD1F9B12270235F700617EB6 /* VideoTrackPrivateClient.h */,
CD6FE5BB24BCE7B6009FCDA4 /* VP9Utilities.cpp */,
Expand Down Expand Up @@ -33184,6 +33194,8 @@
1C436D122999889400C59A5E /* UnrealizedCoreTextFont.h */,
512FF6D42B312DAD00899005 /* VideoMediaSampleRenderer.h */,
512FF6D52B312DAD00899005 /* VideoMediaSampleRenderer.mm */,
CDAD8DED2BEC7B8000107D24 /* VideoTargetFactory.h */,
CDAD8DEE2BEC7B8000107D24 /* VideoTargetFactory.mm */,
CDF994FF24C28136002EA062 /* VideoTrackPrivateWebM.cpp */,
CDF994FE24C28136002EA062 /* VideoTrackPrivateWebM.h */,
CD6FE5B724BCE645009FCDA4 /* VP9UtilitiesCocoa.h */,
Expand Down Expand Up @@ -41020,6 +41032,7 @@
078E43DD1ABB6F6F001C2FA6 /* MediaPlaybackTargetPickerMac.h in Headers */,
077B64131B94F12E003E9AD5 /* MediaPlaybackTargetPickerMock.h in Headers */,
E44613E40CD681A200FADA75 /* MediaPlayer.h in Headers */,
CD51ECD12BEE06FD00632253 /* MediaPlayerClientIdentifier.h in Headers */,
CD5209E41B0BD8380077184E /* MediaPlayerEnums.h in Headers */,
CD3578AE2A28F5AA0059D97D /* MediaPlayerEnumsCocoa.h in Headers */,
F429261825264D4400007898 /* MediaPlayerIdentifier.h in Headers */,
Expand Down Expand Up @@ -42907,6 +42920,8 @@
52D5A1A81C5748A300DE34A3 /* VideoPresentationModelVideoElement.h in Headers */,
0757B13E214AE79900794B0D /* VideoPreset.h in Headers */,
A1DD618A2B7EB59400075A92 /* VideoReceiverEndpoint.h in Headers */,
CDAD8DFB2BED3B0200107D24 /* VideoTarget.h in Headers */,
CDAD8DFC2BED4D2C00107D24 /* VideoTargetFactory.h in Headers */,
CDC939A81E9BDFB100BB768D /* VideoToolboxSoftLink.h in Headers */,
BE88E0DF1715D2A200658D98 /* VideoTrack.h in Headers */,
CD1F9B1827023A2A00617EB6 /* VideoTrackClient.h in Headers */,
Expand Down Expand Up @@ -44619,6 +44634,7 @@
41FFD2C42756570F00501BBF /* VideoLayerManagerObjC.mm in Sources */,
1F7DDE742B6C66EF001816A1 /* VideoPresentationInterfaceAVKit.mm in Sources */,
3FBC4AF3189881560046EE38 /* VideoPresentationInterfaceIOS.mm in Sources */,
CDAD8DF12BEC7EDF00107D24 /* VideoTargetFactory.mm in Sources */,
26F9A83818A046AC00AEB88A /* ViewportConfiguration.cpp in Sources */,
CDED1C3C24CD305700934E12 /* VP9UtilitiesCocoa.mm in Sources */,
A14832B1187F61E100DA63A6 /* WAKAppKitStubs.m in Sources */,
Expand Down
2 changes: 2 additions & 0 deletions Source/WebCore/html/HTMLMediaElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,8 @@ class HTMLMediaElement
FloatSize mediaPlayerVideoLayerSize() const final { return videoLayerSize(); }
void mediaPlayerVideoLayerSizeDidChange(const FloatSize& size) final { m_videoLayerSize = size; }

MediaPlayerClientIdentifier mediaPlayerClientIdentifier() const final { return identifier(); }

void pendingActionTimerFired();
void progressEventTimerFired();
void playbackProgressTimerFired();
Expand Down
5 changes: 2 additions & 3 deletions Source/WebCore/html/HTMLMediaElementIdentifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@

#pragma once

#include <wtf/ObjectIdentifier.h>
#include "MediaPlayerClientIdentifier.h"

namespace WebCore {

struct HTMLMediaElementIdentifierType;
using HTMLMediaElementIdentifier = ObjectIdentifier<HTMLMediaElementIdentifierType>;
using HTMLMediaElementIdentifier = MediaPlayerClientIdentifier;

}
3 changes: 1 addition & 2 deletions Source/WebCore/platform/VideoReceiverEndpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@

#pragma once

#include <wtf/Forward.h>

#if ENABLE(LINEAR_MEDIA_PLAYER)
#include <wtf/OSObjectPtr.h>
#include <xpc/xpc.h>
#endif

Expand Down
12 changes: 10 additions & 2 deletions Source/WebCore/platform/graphics/MediaPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "FourCC.h"
#include "GraphicsTypesGL.h"
#include "LayoutRect.h"
#include "MediaPlayerClientIdentifier.h"
#include "MediaPlayerEnums.h"
#include "MediaPlayerIdentifier.h"
#include "MediaPromiseTypes.h"
Expand All @@ -41,7 +42,7 @@
#include "SecurityOriginData.h"
#include "Timer.h"
#include "VideoPlaybackQualityMetrics.h"
#include "VideoReceiverEndpoint.h"
#include "VideoTarget.h"
#include <JavaScriptCore/Forward.h>
#include <wtf/CompletionHandler.h>
#include <wtf/Function.h>
Expand Down Expand Up @@ -316,6 +317,10 @@ class MediaPlayerClient : public CanMakeWeakPtr<MediaPlayerClient> {

virtual bool isGStreamerHolePunchingEnabled() const { return false; }

virtual PlatformVideoTarget mediaPlayerVideoTarget() const { return nullptr; }

virtual MediaPlayerClientIdentifier mediaPlayerClientIdentifier() const { return { WTF::HashTableDeletedValue }; }

#if !RELEASE_LOG_DISABLED
virtual const void* mediaPlayerLogIdentifier() { return nullptr; }
virtual const Logger& mediaPlayerLogger() = 0;
Expand Down Expand Up @@ -749,7 +754,7 @@ class WEBCORE_EXPORT MediaPlayer : public MediaPlayerEnums, public ThreadSafeRef

void setResourceOwner(const ProcessIdentity&);

void setVideoReceiverEndpoint(const VideoReceiverEndpoint&);
void setVideoTarget(const PlatformVideoTarget&);

#if HAVE(SPATIAL_TRACKING_LABEL)
const String& defaultSpatialTrackingLabel() const;
Expand All @@ -762,6 +767,9 @@ class WEBCORE_EXPORT MediaPlayer : public MediaPlayerEnums, public ThreadSafeRef
void setInFullscreenOrPictureInPicture(bool);
bool isInFullscreenOrPictureInPicture() const;

PlatformVideoTarget videoTarget() const { return client().mediaPlayerVideoTarget(); }
MediaPlayerClientIdentifier clientIdentifier() const { return client().mediaPlayerClientIdentifier(); }

private:
MediaPlayer(MediaPlayerClient&);
MediaPlayer(MediaPlayerClient&, MediaPlayerEnums::MediaEngineIdentifier);
Expand Down
35 changes: 35 additions & 0 deletions Source/WebCore/platform/graphics/MediaPlayerClientIdentifier.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (C) 2024 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/ObjectIdentifier.h>

namespace WebCore {

struct MediaPlayerClientIdentifierType;
using MediaPlayerClientIdentifier = ObjectIdentifier<MediaPlayerClientIdentifierType>;

} // namespace WebCore
2 changes: 1 addition & 1 deletion Source/WebCore/platform/graphics/MediaPlayerPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ class MediaPlayerPrivateInterface {
virtual void setShouldCheckHardwareSupport(bool value) { m_shouldCheckHardwareSupport = value; }
bool shouldCheckHardwareSupport() const { return m_shouldCheckHardwareSupport; }

virtual void setVideoReceiverEndpoint(const VideoReceiverEndpoint&) { }
virtual void setVideoTarget(const PlatformVideoTarget&) { }

#if HAVE(SPATIAL_TRACKING_LABEL)
virtual const String& defaultSpatialTrackingLabel() const { return emptyString(); }
Expand Down
41 changes: 41 additions & 0 deletions Source/WebCore/platform/graphics/VideoTarget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (C) 2024 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

#if ENABLE(LINEAR_MEDIA_PLAYER)
#include <wtf/RetainPtr.h>
typedef struct OpaqueFigVideoTarget *FigVideoTargetRef;
#endif

namespace WebCore {

#if ENABLE(LINEAR_MEDIA_PLAYER)
using PlatformVideoTarget = RetainPtr<FigVideoTargetRef>;
#else
using PlatformVideoTarget = void*;
#endif

}
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ class MediaPlayerPrivateAVFoundationObjC final : public MediaPlayerPrivateAVFoun

std::optional<VideoPlaybackQualityMetrics> videoPlaybackQualityMetrics(AVPlayerLayer*) const;

void setVideoReceiverEndpoint(const VideoReceiverEndpoint&) final;
void setVideoTarget(const PlatformVideoTarget&) final;

#if HAVE(SPATIAL_TRACKING_LABEL)
const String& defaultSpatialTrackingLabel() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,9 @@ static WallTime toSystemClockTime(NSDate *date)
m_defaultSpatialTrackingLabel = player->defaultSpatialTrackingLabel();
m_spatialTrackingLabel = player->spatialTrackingLabel();
#endif
#if ENABLE(LINEAR_MEDIA_PLAYER)
setVideoTarget(player->videoTarget());
#endif
}

MediaPlayerPrivateAVFoundationObjC::~MediaPlayerPrivateAVFoundationObjC()
Expand Down Expand Up @@ -534,6 +537,11 @@ static WallTime toSystemClockTime(NSDate *date)
m_videoFrameMetadataGatheringObserver = nil;
}

#if ENABLE(LINEAR_MEDIA_PLAYER)
if (m_videoTarget)
[m_avPlayer removeVideoTarget:m_videoTarget.get()];
#endif

m_avPlayer = nil;
}

Expand Down Expand Up @@ -1189,6 +1197,13 @@ static URL conformFragmentIdentifierForURL(const URL& url)
});
}];

#if ENABLE(LINEAR_MEDIA_PLAYER)
if (m_videoTarget) {
INFO_LOG(LOGIDENTIFIER, "Setting videoTarget");
[m_avPlayer addVideoTarget:m_videoTarget.get()];
}
#endif

if (m_isGatheringVideoFrameMetadata)
startVideoFrameMetadataGathering();
}
Expand Down Expand Up @@ -4075,25 +4090,26 @@ void determineChangedTracksFromNewTracksAndOldItems(MediaSelectionGroupAVFObjC*
}
#endif

void MediaPlayerPrivateAVFoundationObjC::setVideoReceiverEndpoint(const VideoReceiverEndpoint& endpoint)
void MediaPlayerPrivateAVFoundationObjC::setVideoTarget(const PlatformVideoTarget& videoTarget)
{
#if ENABLE(LINEAR_MEDIA_PLAYER)
assertIsMainThread();

if (!endpoint) {
[m_videoLayer setPlayer:m_avPlayer.get()];
if (m_videoTarget.get() == videoTarget.get())
return;
}

FigVideoTargetRef videoTarget;
OSStatus status = FigVideoTargetCreateWithVideoReceiverEndpointID(kCFAllocatorDefault, endpoint.get(), nullptr, &videoTarget);
if (status != noErr)
return;
ALWAYS_LOG(LOGIDENTIFIER, !!videoTarget);
if (m_videoTarget)
[m_avPlayer removeVideoTarget:m_videoTarget.get()];

m_videoTarget = adoptCF(videoTarget);
[m_avPlayer addVideoTarget:m_videoTarget.get()];
m_videoTarget = videoTarget;

if (m_videoTarget)
[m_avPlayer addVideoTarget:m_videoTarget.get()];
else
[m_videoLayer setPlayer:m_avPlayer.get()];
#else
UNUSED_PARAM(endpoint);
UNUSED_PARAM(videoTarget);
#endif
}

Expand All @@ -4104,8 +4120,10 @@ void determineChangedTracksFromNewTracksAndOldItems(MediaSelectionGroupAVFObjC*

if (isInFullscreenOrPictureInPicture)
[m_videoLayer setPlayer:nil];
else if (RetainPtr videoTarget = std::exchange(m_videoTarget, nullptr))
else if (RetainPtr videoTarget = std::exchange(m_videoTarget, nullptr)) {
INFO_LOG(LOGIDENTIFIER, "Clearing videoTarget");
[m_avPlayer removeVideoTarget:videoTarget.get()];
}
#else
UNUSED_PARAM(isInFullscreenOrPictureInPicture);
#endif
Expand Down

0 comments on commit 415dbd7

Please sign in to comment.