Title: [290175] trunk
Revision
290175
Author
commit-qu...@webkit.org
Date
2022-02-18 14:48:08 -0800 (Fri, 18 Feb 2022)

Log Message

WebGL GPUP: Crash when running fast/mediastream/getUserMedia-to-canvas-1.html
https://bugs.webkit.org/show_bug.cgi?id=236502
Source/WebCore:

<rdar://problem/88862921>

Patch by Kimmo Kinnunen <kkinnu...@apple.com> on 2022-02-18
Reviewed by Eric Carlson.

Add a polymorphic function asVideoFrameCV to convert VideoFrame to VideoFrameCV.
VideoFrameCV is used to draw the in-process video frame to in-process WebGL.

RemoteVideoFrameProxy will implement asVideoFrameCV by fetching the data from
GPUP and returning a new object exposing the data.

No new tests, tested by now unskipped tests.

* platform/VideoFrame.h:
* platform/graphics/cocoa/GraphicsContextGLCocoa.mm:
(WebCore::GraphicsContextGLCocoa::copyTextureFromMedia):
* platform/graphics/cv/VideoFrameCV.h:
* platform/graphics/cv/VideoFrameCV.mm:
(WebCore::VideoFrameCV::asVideoFrameCV):

Source/WebKit:

The crash is about MediaPlayerPrivateMediaStreamAVFObjC being in WP while other
media player private variants are proxied to GPUP. The previous implementation
would send media player identifiers to GPUP for copying.
This patch will implement the copy by the media player creating a reference
to VideoFrame. WebGL would send reference of the VideoFrame to GPUP for copying.

Make WP MediaPlayerPrivateRemote always return RemoteVideoFrameProxy objects
instead of WP in-process VideoFrame instances (for Cocoa VideoFrameCV) that
would hold the video data in process.

WP MediaPlayerPrivateMediaStreamAVFObjC already returns RemoteVideoFrameProxy
objects. This way GPUP WebGL implementation can obtain the read reference
to the remote object and send it in copyTextureFromVideoFrame message.

The WP in-process WebGL implementation converts the RemoteVideoFrameProxy
to VideoFrameCV with the new RemoteVideoFrameProxy::asVideoFrameCV.

Patch by Kimmo Kinnunen <kkinnu...@apple.com> on 2022-02-18
Reviewed by Eric Carlson.

* GPUProcess/graphics/RemoteGraphicsContextGL.cpp:
(WebKit::RemoteGraphicsContextGL::RemoteGraphicsContextGL):
(WebKit::RemoteGraphicsContextGL::copyTextureFromVideoFrame):
* GPUProcess/graphics/RemoteGraphicsContextGL.h:
* GPUProcess/graphics/RemoteGraphicsContextGL.messages.in:
* GPUProcess/graphics/RemoteGraphicsContextGLCocoa.cpp:
(WebKit::RemoteGraphicsContextGL::copyTextureFromVideoFrame):
(WebKit::RemoteGraphicsContextGL::create):
(WebKit::RemoteGraphicsContextGLCocoa::RemoteGraphicsContextGLCocoa):
(WebKit::RemoteGraphicsContextGLCocoa::platformWorkQueueInitialize):
(WebKit::RemoteGraphicsContextGLCocoa::prepareForDisplay):
* GPUProcess/media/RemoteMediaPlayerManagerProxy.cpp:
(WebKit::RemoteMediaPlayerManagerProxy::createMediaPlayer):
* GPUProcess/media/RemoteMediaPlayerProxy.cpp:
(WebKit::RemoteMediaPlayerProxy::RemoteMediaPlayerProxy):
(WebKit::RemoteMediaPlayerProxy::videoFrameForCurrentTimeIfChanged):
* GPUProcess/media/RemoteMediaPlayerProxy.h:
* GPUProcess/media/RemoteMediaPlayerProxy.messages.in:
* WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.cpp:
(WebKit::RemoteGraphicsContextGLProxy::copyTextureFromMedia):
* WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.h:
* WebProcess/GPU/media/MediaPlayerPrivateRemote.cpp:
(WebKit::MediaPlayerPrivateRemote::videoFrameForCurrentTime):
* WebProcess/GPU/media/MediaPlayerPrivateRemote.h:
* WebProcess/GPU/media/RemoteVideoFrameProxy.cpp:
(WebKit::RemoteVideoFrameProxy::asVideoFrameCV):
* WebProcess/GPU/media/RemoteVideoFrameProxy.h:

LayoutTests:

Unskip the previous crashes caused by the lack of implementation.

Patch by Kimmo Kinnunen <kkinnu...@apple.com> on 2022-02-18
Reviewed by Eric Carlson.

* platform/ios-wk2/TestExpectations:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (290174 => 290175)


--- trunk/LayoutTests/ChangeLog	2022-02-18 22:43:33 UTC (rev 290174)
+++ trunk/LayoutTests/ChangeLog	2022-02-18 22:48:08 UTC (rev 290175)
@@ -1,3 +1,14 @@
+2022-02-18  Kimmo Kinnunen  <kkinnu...@apple.com>
+
+        WebGL GPUP: Crash when running fast/mediastream/getUserMedia-to-canvas-1.html
+        https://bugs.webkit.org/show_bug.cgi?id=236502
+
+        Unskip the previous crashes caused by the lack of implementation.
+
+        Reviewed by Eric Carlson.
+
+        * platform/ios-wk2/TestExpectations:
+
 2022-02-18  Jon Lee  <jon...@apple.com>
 
         REGRESSION (r289990): [iOS] fast/backgrounds/gradient-background-shadow.html is consistently failing

Modified: trunk/LayoutTests/platform/ios-wk2/TestExpectations (290174 => 290175)


--- trunk/LayoutTests/platform/ios-wk2/TestExpectations	2022-02-18 22:43:33 UTC (rev 290174)
+++ trunk/LayoutTests/platform/ios-wk2/TestExpectations	2022-02-18 22:48:08 UTC (rev 290175)
@@ -2211,10 +2211,5 @@
 webkit.org/b/234536 webgl/max-active-contexts-gc.html
 webkit.org/b/234536 webgl/max-active-contexts-oldest-context-lost.html
 webkit.org/b/234536 webxr/high-performance.html
-webkit.org/b/234536 fast/mediastream/getUserMedia-to-canvas-1.html [ Crash ]
-webkit.org/b/234536 fast/mediastream/getUserMedia-to-canvas-2.html [ Crash ]
 webkit.org/b/234536 webgl/max-active-contexts-webglcontextlost-prevent-default.html [ Timeout ]
 webkit.org/b/234536 webgl/1.0.3/conformance/state/gl-object-get-calls.html [ Timeout ]
-
-# Captured WebGL to another context2d or WebGL not implemented yet.
-webkit.org/b/236496 fast/mediastream/captureStream/canvas3d.html [ Timeout ]
\ No newline at end of file

Modified: trunk/Source/WebCore/ChangeLog (290174 => 290175)


--- trunk/Source/WebCore/ChangeLog	2022-02-18 22:43:33 UTC (rev 290174)
+++ trunk/Source/WebCore/ChangeLog	2022-02-18 22:48:08 UTC (rev 290175)
@@ -1,3 +1,26 @@
+2022-02-18  Kimmo Kinnunen  <kkinnu...@apple.com>
+
+        WebGL GPUP: Crash when running fast/mediastream/getUserMedia-to-canvas-1.html
+        https://bugs.webkit.org/show_bug.cgi?id=236502
+        <rdar://problem/88862921>
+
+        Reviewed by Eric Carlson.
+
+        Add a polymorphic function asVideoFrameCV to convert VideoFrame to VideoFrameCV.
+        VideoFrameCV is used to draw the in-process video frame to in-process WebGL.
+
+        RemoteVideoFrameProxy will implement asVideoFrameCV by fetching the data from
+        GPUP and returning a new object exposing the data.
+
+        No new tests, tested by now unskipped tests.
+
+        * platform/VideoFrame.h:
+        * platform/graphics/cocoa/GraphicsContextGLCocoa.mm:
+        (WebCore::GraphicsContextGLCocoa::copyTextureFromMedia):
+        * platform/graphics/cv/VideoFrameCV.h:
+        * platform/graphics/cv/VideoFrameCV.mm:
+        (WebCore::VideoFrameCV::asVideoFrameCV):
+
 2022-02-18  Eric Carlson  <eric.carl...@apple.com>
 
         [macOS] Allow screen and window capture to be done in the GPU Process

Modified: trunk/Source/WebCore/platform/VideoFrame.h (290174 => 290175)


--- trunk/Source/WebCore/platform/VideoFrame.h	2022-02-18 22:43:33 UTC (rev 290174)
+++ trunk/Source/WebCore/platform/VideoFrame.h	2022-02-18 22:48:08 UTC (rev 290175)
@@ -31,6 +31,11 @@
 
 namespace WebCore {
 
+#if USE(AVFOUNDATION)
+class VideoFrameCV;
+#endif
+
+
 // A class representing a video frame from a decoder, capture source, or similar.
 // FIXME: Currently for implementation purposes inherts from MediaSample until capture code
 // stops referring to MediaSample
@@ -49,6 +54,7 @@
     virtual bool isRemoteProxy() const { return false; }
 #if USE(AVFOUNDATION)
     virtual bool isCV() const { return false; }
+    virtual RefPtr<WebCore::VideoFrameCV> asVideoFrameCV() = 0;
 #endif
 
 protected:

Modified: trunk/Source/WebCore/platform/cocoa/SharedVideoFrameInfo.h (290174 => 290175)


--- trunk/Source/WebCore/platform/cocoa/SharedVideoFrameInfo.h	2022-02-18 22:43:33 UTC (rev 290174)
+++ trunk/Source/WebCore/platform/cocoa/SharedVideoFrameInfo.h	2022-02-18 22:48:08 UTC (rev 290175)
@@ -25,7 +25,7 @@
 
 #pragma once
 
-#if ENABLE(MEDIA_STREAM) && PLATFORM(COCOA)
+#if ENABLE(VIDEO) && PLATFORM(COCOA)
 
 #include <wtf/RetainPtr.h>
 #include <wtf/Span.h>

Modified: trunk/Source/WebCore/platform/cocoa/SharedVideoFrameInfo.mm (290174 => 290175)


--- trunk/Source/WebCore/platform/cocoa/SharedVideoFrameInfo.mm	2022-02-18 22:43:33 UTC (rev 290174)
+++ trunk/Source/WebCore/platform/cocoa/SharedVideoFrameInfo.mm	2022-02-18 22:48:08 UTC (rev 290175)
@@ -26,7 +26,7 @@
 #include "config.h"
 #include "SharedVideoFrameInfo.h"
 
-#if ENABLE(MEDIA_STREAM) && PLATFORM(COCOA)
+#if ENABLE(VIDEO) && PLATFORM(COCOA)
 
 #include "CVUtilities.h"
 #include "IOSurface.h"

Modified: trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.mm (290174 => 290175)


--- trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.mm	2022-02-18 22:43:33 UTC (rev 290174)
+++ trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.mm	2022-02-18 22:48:08 UTC (rev 290175)
@@ -38,7 +38,6 @@
 #import "PixelBuffer.h"
 #import "ProcessIdentity.h"
 #import "RuntimeApplicationChecks.h"
-#import "VideoFrameCV.h"
 #import <CoreGraphics/CGBitmapContext.h>
 #import <Metal/Metal.h>
 #import <pal/spi/cocoa/MetalSPI.h>
@@ -50,13 +49,14 @@
 #endif
 
 #if ENABLE(VIDEO)
-#include "GraphicsContextGLCVCocoa.h"
-#include "MediaPlayerPrivate.h"
+#import "GraphicsContextGLCVCocoa.h"
+#import "MediaPlayerPrivate.h"
+#import "VideoFrameCV.h"
 #endif
 
 #if ENABLE(MEDIA_STREAM)
-#include "ImageRotationSessionVT.h"
-#include "MediaSampleAVFObjC.h"
+#import "ImageRotationSessionVT.h"
+#import "MediaSampleAVFObjC.h"
 #endif
 
 namespace WebCore {
@@ -783,8 +783,9 @@
     auto videoFrame = player.videoFrameForCurrentTime();
     if (!videoFrame)
         return false;
-    ASSERT(is<VideoFrameCV>(*videoFrame));
-
+    auto videoFrameCV = videoFrame->asVideoFrameCV();
+    if (!videoFrameCV)
+        return false;
     auto contextCV = asCV();
     if (!contextCV)
         return false;
@@ -791,7 +792,7 @@
 
     UNUSED_VARIABLE(premultiplyAlpha);
     ASSERT_UNUSED(outputTarget, outputTarget == GraphicsContextGL::TEXTURE_2D);
-    return contextCV->copyVideoSampleToTexture(downcast<VideoFrameCV>(*videoFrame), outputTexture, level, internalFormat, format, type, GraphicsContextGL::FlipY(flipY));
+    return contextCV->copyVideoSampleToTexture(*videoFrameCV, outputTexture, level, internalFormat, format, type, GraphicsContextGL::FlipY(flipY));
 }
 #endif
 

Modified: trunk/Source/WebCore/platform/graphics/cv/CVUtilities.h (290174 => 290175)


--- trunk/Source/WebCore/platform/graphics/cv/CVUtilities.h	2022-02-18 22:43:33 UTC (rev 290174)
+++ trunk/Source/WebCore/platform/graphics/cv/CVUtilities.h	2022-02-18 22:48:08 UTC (rev 290175)
@@ -54,4 +54,6 @@
 // Should be called with non-empty ProcessIdentity.
 WEBCORE_EXPORT void setOwnershipIdentityForCVPixelBuffer(CVPixelBufferRef, const ProcessIdentity&);
 
+WEBCORE_EXPORT RetainPtr<CVPixelBufferRef> createBlackPixelBuffer(size_t width, size_t height);
+
 }

Modified: trunk/Source/WebCore/platform/graphics/cv/CVUtilities.mm (290174 => 290175)


--- trunk/Source/WebCore/platform/graphics/cv/CVUtilities.mm	2022-02-18 22:43:33 UTC (rev 290174)
+++ trunk/Source/WebCore/platform/graphics/cv/CVUtilities.mm	2022-02-18 22:48:08 UTC (rev 290175)
@@ -28,6 +28,7 @@
 
 #import "ColorSpaceCG.h"
 #import "IOSurface.h"
+#import "RealtimeVideoUtilities.h"
 #import <wtf/StdLibExtras.h>
 #import <wtf/cf/TypeCastsCF.h>
 #import "CoreVideoSoftLink.h"
@@ -162,4 +163,31 @@
     IOSurface::setOwnershipIdentity(surface, owner);
 }
 
+RetainPtr<CVPixelBufferRef> createBlackPixelBuffer(size_t width, size_t height)
+{
+    OSType format = preferedPixelBufferFormat();
+    ASSERT(format == kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange || format == kCVPixelFormatType_420YpCbCr8BiPlanarFullRange);
+
+    CVPixelBufferRef pixelBuffer = nullptr;
+    auto status = CVPixelBufferCreate(kCFAllocatorDefault, width, height, format, nullptr, &pixelBuffer);
+    ASSERT_UNUSED(status, status == noErr);
+
+    status = CVPixelBufferLockBaseAddress(pixelBuffer, 0);
+    ASSERT(status == noErr);
+
+    auto* yPlane = static_cast<uint8_t*>(CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, 0));
+    size_t yStride = CVPixelBufferGetBytesPerRowOfPlane(pixelBuffer, 0);
+    for (unsigned i = 0; i < height; ++i)
+        memset(&yPlane[i * yStride], 0, width);
+
+    auto* uvPlane = static_cast<uint8_t*>(CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, 1));
+    size_t uvStride = CVPixelBufferGetBytesPerRowOfPlane(pixelBuffer, 1);
+    for (unsigned i = 0; i < height / 2; ++i)
+        memset(&uvPlane[i * uvStride], 128, width);
+
+    status = CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
+    ASSERT(!status);
+    return adoptCF(pixelBuffer);
 }
+
+}

Modified: trunk/Source/WebCore/platform/graphics/cv/VideoFrameCV.h (290174 => 290175)


--- trunk/Source/WebCore/platform/graphics/cv/VideoFrameCV.h	2022-02-18 22:43:33 UTC (rev 290174)
+++ trunk/Source/WebCore/platform/graphics/cv/VideoFrameCV.h	2022-02-18 22:48:08 UTC (rev 290175)
@@ -47,9 +47,10 @@
     template<typename Decoder> static std::optional<RefPtr<VideoFrameCV>> decode(Decoder&);
 
     // VideoFrame overrides.
-    WebCore::FloatSize presentationSize() const final;
-    uint32_t videoPixelFormat() const final;
+    WEBCORE_EXPORT WebCore::FloatSize presentationSize() const final;
+    WEBCORE_EXPORT uint32_t videoPixelFormat() const final;
     bool isCV() const final { return true; }
+    WEBCORE_EXPORT RefPtr<WebCore::VideoFrameCV> asVideoFrameCV() final;
 
 private:
     WEBCORE_EXPORT VideoFrameCV(MediaTime presentationTime, bool isMirrored, VideoRotation, RetainPtr<CVPixelBufferRef>&&);

Modified: trunk/Source/WebCore/platform/graphics/cv/VideoFrameCV.mm (290174 => 290175)


--- trunk/Source/WebCore/platform/graphics/cv/VideoFrameCV.mm	2022-02-18 22:43:33 UTC (rev 290174)
+++ trunk/Source/WebCore/platform/graphics/cv/VideoFrameCV.mm	2022-02-18 22:48:08 UTC (rev 290175)
@@ -54,7 +54,12 @@
 {
     return CVPixelBufferGetPixelFormatType(m_pixelBuffer.get());
 }
+RefPtr<WebCore::VideoFrameCV> VideoFrameCV::asVideoFrameCV()
+{
+    return this;
+}
 
+
 ImageOrientation VideoFrameCV::orientation() const
 {
     // Sample transform first flips x-coordinates, then rotates.

Modified: trunk/Source/WebCore/platform/mediarecorder/MediaRecorderPrivateAVFImpl.cpp (290174 => 290175)


--- trunk/Source/WebCore/platform/mediarecorder/MediaRecorderPrivateAVFImpl.cpp	2022-02-18 22:43:33 UTC (rev 290174)
+++ trunk/Source/WebCore/platform/mediarecorder/MediaRecorderPrivateAVFImpl.cpp	2022-02-18 22:48:08 UTC (rev 290175)
@@ -30,6 +30,7 @@
 
 #include "AudioStreamDescription.h"
 #include "CAAudioStreamDescription.h"
+#include "CVUtilities.h"
 #include "Logging.h"
 #include "MediaRecorderPrivateWriterCocoa.h"
 #include "MediaSampleAVFObjC.h"

Modified: trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSourceCocoa.h (290174 => 290175)


--- trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSourceCocoa.h	2022-02-18 22:43:33 UTC (rev 290174)
+++ trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSourceCocoa.h	2022-02-18 22:48:08 UTC (rev 290175)
@@ -68,8 +68,6 @@
     webrtc::BufferType m_pixelBufferPoolBufferType;
 };
 
-WEBCORE_EXPORT RetainPtr<CVPixelBufferRef> createBlackPixelBuffer(size_t width, size_t height);
-
 } // namespace WebCore
 
 #endif // USE(LIBWEBRTC)

Modified: trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSourceCocoa.mm (290174 => 290175)


--- trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSourceCocoa.mm	2022-02-18 22:43:33 UTC (rev 290174)
+++ trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSourceCocoa.mm	2022-02-18 22:48:08 UTC (rev 290175)
@@ -33,7 +33,6 @@
 #import "CVUtilities.h"
 #import "Logging.h"
 #import "MediaSampleAVFObjC.h"
-#import "RealtimeVideoUtilities.h"
 #import <wtf/cf/TypeCastsCF.h>
 
 ALLOW_UNUSED_PARAMETERS_BEGIN
@@ -62,33 +61,6 @@
 {
 }
 
-RetainPtr<CVPixelBufferRef> createBlackPixelBuffer(size_t width, size_t height)
-{
-    OSType format = preferedPixelBufferFormat();
-    ASSERT(format == kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange || format == kCVPixelFormatType_420YpCbCr8BiPlanarFullRange);
-
-    CVPixelBufferRef pixelBuffer = nullptr;
-    auto status = CVPixelBufferCreate(kCFAllocatorDefault, width, height, format, nullptr, &pixelBuffer);
-    ASSERT_UNUSED(status, status == noErr);
-
-    status = CVPixelBufferLockBaseAddress(pixelBuffer, 0);
-    ASSERT(status == noErr);
-
-    auto* yPlane = static_cast<uint8_t*>(CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, 0));
-    size_t yStride = CVPixelBufferGetBytesPerRowOfPlane(pixelBuffer, 0);
-    for (unsigned i = 0; i < height; ++i)
-        memset(&yPlane[i * yStride], 0, width);
-
-    auto* uvPlane = static_cast<uint8_t*>(CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, 1));
-    size_t uvStride = CVPixelBufferGetBytesPerRowOfPlane(pixelBuffer, 1);
-    for (unsigned i = 0; i < height / 2; ++i)
-        memset(&uvPlane[i * uvStride], 128, width);
-
-    status = CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
-    ASSERT(!status);
-    return adoptCF(pixelBuffer);
-}
-
 CVPixelBufferPoolRef RealtimeIncomingVideoSourceCocoa::pixelBufferPool(size_t width, size_t height, webrtc::BufferType bufferType)
 {
     if (!m_pixelBufferPool || m_pixelBufferPoolWidth != width || m_pixelBufferPoolHeight != height || m_pixelBufferPoolBufferType != bufferType) {

Modified: trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingVideoSourceCocoa.cpp (290174 => 290175)


--- trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingVideoSourceCocoa.cpp	2022-02-18 22:43:33 UTC (rev 290174)
+++ trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingVideoSourceCocoa.cpp	2022-02-18 22:48:08 UTC (rev 290175)
@@ -28,6 +28,7 @@
 
 #if USE(LIBWEBRTC)
 
+#include "CVUtilities.h"
 #include "ImageRotationSessionVT.h"
 #include "Logging.h"
 #include "RealtimeIncomingVideoSourceCocoa.h"

Modified: trunk/Source/WebKit/ChangeLog (290174 => 290175)


--- trunk/Source/WebKit/ChangeLog	2022-02-18 22:43:33 UTC (rev 290174)
+++ trunk/Source/WebKit/ChangeLog	2022-02-18 22:48:08 UTC (rev 290175)
@@ -1,3 +1,55 @@
+2022-02-18  Kimmo Kinnunen  <kkinnu...@apple.com>
+
+        WebGL GPUP: Crash when running fast/mediastream/getUserMedia-to-canvas-1.html
+        https://bugs.webkit.org/show_bug.cgi?id=236502
+
+        The crash is about MediaPlayerPrivateMediaStreamAVFObjC being in WP while other
+        media player private variants are proxied to GPUP. The previous implementation
+        would send media player identifiers to GPUP for copying.
+        This patch will implement the copy by the media player creating a reference
+        to VideoFrame. WebGL would send reference of the VideoFrame to GPUP for copying.
+
+        Make WP MediaPlayerPrivateRemote always return RemoteVideoFrameProxy objects
+        instead of WP in-process VideoFrame instances (for Cocoa VideoFrameCV) that
+        would hold the video data in process.
+
+        WP MediaPlayerPrivateMediaStreamAVFObjC already returns RemoteVideoFrameProxy
+        objects. This way GPUP WebGL implementation can obtain the read reference
+        to the remote object and send it in copyTextureFromVideoFrame message.
+
+        The WP in-process WebGL implementation converts the RemoteVideoFrameProxy
+        to VideoFrameCV with the new RemoteVideoFrameProxy::asVideoFrameCV.
+
+        Reviewed by Eric Carlson.
+
+        * GPUProcess/graphics/RemoteGraphicsContextGL.cpp:
+        (WebKit::RemoteGraphicsContextGL::RemoteGraphicsContextGL):
+        (WebKit::RemoteGraphicsContextGL::copyTextureFromVideoFrame):
+        * GPUProcess/graphics/RemoteGraphicsContextGL.h:
+        * GPUProcess/graphics/RemoteGraphicsContextGL.messages.in:
+        * GPUProcess/graphics/RemoteGraphicsContextGLCocoa.cpp:
+        (WebKit::RemoteGraphicsContextGL::copyTextureFromVideoFrame):
+        (WebKit::RemoteGraphicsContextGL::create):
+        (WebKit::RemoteGraphicsContextGLCocoa::RemoteGraphicsContextGLCocoa):
+        (WebKit::RemoteGraphicsContextGLCocoa::platformWorkQueueInitialize):
+        (WebKit::RemoteGraphicsContextGLCocoa::prepareForDisplay):
+        * GPUProcess/media/RemoteMediaPlayerManagerProxy.cpp:
+        (WebKit::RemoteMediaPlayerManagerProxy::createMediaPlayer):
+        * GPUProcess/media/RemoteMediaPlayerProxy.cpp:
+        (WebKit::RemoteMediaPlayerProxy::RemoteMediaPlayerProxy):
+        (WebKit::RemoteMediaPlayerProxy::videoFrameForCurrentTimeIfChanged):
+        * GPUProcess/media/RemoteMediaPlayerProxy.h:
+        * GPUProcess/media/RemoteMediaPlayerProxy.messages.in:
+        * WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.cpp:
+        (WebKit::RemoteGraphicsContextGLProxy::copyTextureFromMedia):
+        * WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.h:
+        * WebProcess/GPU/media/MediaPlayerPrivateRemote.cpp:
+        (WebKit::MediaPlayerPrivateRemote::videoFrameForCurrentTime):
+        * WebProcess/GPU/media/MediaPlayerPrivateRemote.h:
+        * WebProcess/GPU/media/RemoteVideoFrameProxy.cpp:
+        (WebKit::RemoteVideoFrameProxy::asVideoFrameCV):
+        * WebProcess/GPU/media/RemoteVideoFrameProxy.h:
+
 2022-02-18  Eric Carlson  <eric.carl...@apple.com>
 
         [macOS] Allow screen and window capture to be done in the GPU Process

Modified: trunk/Source/WebKit/GPUProcess/GPUConnectionToWebProcess.cpp (290174 => 290175)


--- trunk/Source/WebKit/GPUProcess/GPUConnectionToWebProcess.cpp	2022-02-18 22:43:33 UTC (rev 290174)
+++ trunk/Source/WebKit/GPUProcess/GPUConnectionToWebProcess.cpp	2022-02-18 22:48:08 UTC (rev 290175)
@@ -141,7 +141,6 @@
 #endif
 
 #if ENABLE(MEDIA_STREAM)
-#include "RemoteVideoFrameObjectHeap.h"
 #include <WebCore/SecurityOrigin.h>
 #endif
 
@@ -154,6 +153,10 @@
 #include "IPCTesterMessages.h"
 #endif
 
+#if ENABLE(VIDEO)
+#include "RemoteVideoFrameObjectHeap.h"
+#endif
+
 namespace WebKit {
 using namespace WebCore;
 
@@ -244,7 +247,7 @@
 #if ENABLE(MEDIA_STREAM)
     , m_captureOrigin(SecurityOrigin::createUnique())
 #endif
-#if ENABLE(MEDIA_STREAM)
+#if ENABLE(VIDEO)
     , m_videoFrameObjectHeap(RemoteVideoFrameObjectHeap::create(*this))
 #endif
 #if PLATFORM(COCOA) && USE(LIBWEBRTC)
@@ -305,7 +308,7 @@
         m_audioSessionProxy = nullptr;
     }
 #endif
-#if ENABLE(MEDIA_STREAM)
+#if ENABLE(VIDEO)
     m_videoFrameObjectHeap.reset();
 #endif
     // RemoteRenderingBackend objects ref their GPUConnectionToWebProcess so we need to make sure
@@ -948,14 +951,15 @@
 {
 }
 #endif
+#endif // ENABLE(MEDIA_STREAM)
 
+#if ENABLE(VIDEO)
 RemoteVideoFrameObjectHeap& GPUConnectionToWebProcess::videoFrameObjectHeap() const
 {
     return *m_videoFrameObjectHeap.get();
 }
+#endif
 
-#endif // ENABLE(MEDIA_STREAM)
-
 #if PLATFORM(MAC)
 void GPUConnectionToWebProcess::displayConfigurationChanged(CGDirectDisplayID, CGDisplayChangeSummaryFlags flags)
 {

Modified: trunk/Source/WebKit/GPUProcess/GPUConnectionToWebProcess.h (290174 => 290175)


--- trunk/Source/WebKit/GPUProcess/GPUConnectionToWebProcess.h	2022-02-18 22:43:33 UTC (rev 290174)
+++ trunk/Source/WebKit/GPUProcess/GPUConnectionToWebProcess.h	2022-02-18 22:48:08 UTC (rev 290175)
@@ -106,7 +106,7 @@
 class RemoteWCLayerTreeHost;
 #endif
 
-#if ENABLE(MEDIA_STREAM)
+#if ENABLE(VIDEO)
 class RemoteVideoFrameObjectHeap;
 #endif
 
@@ -145,9 +145,10 @@
     bool allowsAudioCapture() const { return m_allowsAudioCapture; }
     bool allowsVideoCapture() const { return m_allowsVideoCapture; }
     bool allowsDisplayCapture() const { return m_allowsDisplayCapture; }
+#endif
+#if ENABLE(VIDEO)
     RemoteVideoFrameObjectHeap& videoFrameObjectHeap() const;
 #endif
-
 #if PLATFORM(COCOA) && ENABLE(MEDIA_STREAM)
     void startCapturingAudio();
     void processIsStartingToCaptureAudio(GPUConnectionToWebProcess&);
@@ -307,6 +308,8 @@
     bool m_allowsAudioCapture { false };
     bool m_allowsVideoCapture { false };
     bool m_allowsDisplayCapture { false };
+#endif
+#if ENABLE(VIDEO)
     IPC::ScopedActiveMessageReceiveQueue<RemoteVideoFrameObjectHeap> m_videoFrameObjectHeap;
 #endif
 #if PLATFORM(COCOA) && USE(LIBWEBRTC)

Modified: trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.cpp (290174 => 290175)


--- trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.cpp	2022-02-18 22:43:33 UTC (rev 290174)
+++ trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.cpp	2022-02-18 22:48:08 UTC (rev 290175)
@@ -38,11 +38,7 @@
 #include <wtf/MainThread.h>
 #include <wtf/NeverDestroyed.h>
 
-#if USE(AVFOUNDATION)
-#include <WebCore/GraphicsContextGLCV.h>
-#endif
-
-#if ENABLE(MEDIA_STREAM)
+#if ENABLE(VIDEO)
 #include "RemoteVideoFrameObjectHeap.h"
 #endif
 
@@ -72,7 +68,7 @@
     , m_streamConnection(IPC::StreamServerConnection::create(gpuConnectionToWebProcess.connection(), WTFMove(stream), remoteGraphicsContextGLStreamWorkQueue()))
     , m_graphicsContextGLIdentifier(graphicsContextGLIdentifier)
     , m_renderingBackend(renderingBackend)
-#if ENABLE(MEDIA_STREAM)
+#if ENABLE(VIDEO)
     , m_videoFrameObjectHeap(gpuConnectionToWebProcess.videoFrameObjectHeap())
 #endif
     , m_renderingResourcesRequest(ScopedWebGLRenderingResourcesRequest::acquire())
@@ -280,51 +276,14 @@
     completionHandler();
 }
 
-void RemoteGraphicsContextGL::copyTextureFromMedia(WebCore::MediaPlayerIdentifier mediaPlayerIdentifier, uint32_t texture, uint32_t target, int32_t level, uint32_t internalFormat, uint32_t format, uint32_t type, bool premultiplyAlpha, bool flipY, CompletionHandler<void(bool)>&& completionHandler)
+#if ENABLE(VIDEO) && !USE(AVFOUNDATION)
+void RemoteGraphicsContextGL::copyTextureFromVideoFrame(WebKit::RemoteVideoFrameReadReference read, uint32_t, uint32_t, int32_t, uint32_t, uint32_t, uint32_t, bool, bool , CompletionHandler<void(bool)>&& completionHandler)
 {
-    assertIsCurrent(m_streamThread);
-#if USE(AVFOUNDATION)
-    UNUSED_VARIABLE(premultiplyAlpha);
-    ASSERT_UNUSED(target, target == GraphicsContextGL::TEXTURE_2D);
-
-    RefPtr<VideoFrame> videoFrame;
-    auto getVideoFrame = [&] {
-        if (!m_gpuConnectionToWebProcess)
-            return;
-
-        if (auto mediaPlayer = m_gpuConnectionToWebProcess->remoteMediaPlayerManagerProxy().mediaPlayer(mediaPlayerIdentifier))
-            videoFrame = mediaPlayer->videoFrameForCurrentTime();
-    };
-
-    callOnMainRunLoopAndWait(WTFMove(getVideoFrame));
-
-    if (!videoFrame || !is<VideoFrameCV>(*videoFrame)) {
-        completionHandler(false);
-        return;
-    }
-
-    auto contextCV = m_context->asCV();
-    if (!contextCV) {
-        completionHandler(false);
-        return;
-    }
-
-    completionHandler(contextCV->copyVideoSampleToTexture(downcast<VideoFrameCV>(*videoFrame), texture, level, internalFormat, format, type, GraphicsContextGL::FlipY(flipY)));
-#else
-    UNUSED_VARIABLE(mediaPlayerIdentifier);
-    UNUSED_VARIABLE(texture);
-    UNUSED_VARIABLE(target);
-    UNUSED_VARIABLE(level);
-    UNUSED_VARIABLE(internalFormat);
-    UNUSED_VARIABLE(format);
-    UNUSED_VARIABLE(type);
-    UNUSED_VARIABLE(premultiplyAlpha);
-    UNUSED_VARIABLE(flipY);
-
     notImplemented();
+    m_videoFrameObjectHeap->retire(WTFMove(read), defaultTimeout);
     completionHandler(false);
+}
 #endif
-}
 
 void RemoteGraphicsContextGL::simulateEventForTesting(WebCore::GraphicsContextGL::SimulatedEventForTesting event)
 {

Modified: trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.h (290174 => 290175)


--- trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.h	2022-02-18 22:43:33 UTC (rev 290174)
+++ trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.h	2022-02-18 22:48:08 UTC (rev 290175)
@@ -53,7 +53,7 @@
 #include "WCContentBufferIdentifier.h"
 #endif
 
-#if ENABLE(MEDIA_STREAM)
+#if ENABLE(VIDEO)
 #include "RemoteVideoFrameIdentifier.h"
 #include "RemoteVideoFrameProxy.h"
 #endif
@@ -65,7 +65,7 @@
 #endif
 
 namespace WebKit {
-#if ENABLE(MEDIA_STREAM)
+#if ENABLE(VIDEO)
 class RemoteVideoFrameObjectHeap;
 #endif
 
@@ -118,7 +118,9 @@
 #if ENABLE(MEDIA_STREAM)
     void paintCompositedResultsToMediaSample(CompletionHandler<void(std::optional<WebKit::RemoteVideoFrameProxy::Properties>&&)>&&);
 #endif
-    void copyTextureFromMedia(WebCore::MediaPlayerIdentifier, uint32_t texture, uint32_t target, int32_t level, uint32_t internalFormat, uint32_t format, uint32_t type, bool premultiplyAlpha, bool flipY, CompletionHandler<void(bool)>&&);
+#if ENABLE(VIDEO)
+    void copyTextureFromVideoFrame(RemoteVideoFrameReadReference, uint32_t texture, uint32_t target, int32_t level, uint32_t internalFormat, uint32_t format, uint32_t type, bool premultiplyAlpha, bool flipY, CompletionHandler<void(bool)>&&);
+#endif
     void simulateEventForTesting(WebCore::GraphicsContextGL::SimulatedEventForTesting);
 
 #include "RemoteGraphicsContextGLFunctionsGenerated.h" // NOLINT
@@ -131,6 +133,7 @@
 protected:
     WeakPtr<GPUConnectionToWebProcess> m_gpuConnectionToWebProcess;
     RefPtr<IPC::StreamServerConnection> m_streamConnection;
+    static constexpr Seconds defaultTimeout = 10_s;
 #if PLATFORM(COCOA)
     using GCGLContext = WebCore::GraphicsContextGLCocoa;
 #else
@@ -140,7 +143,7 @@
     RefPtr<GCGLContext> m_context WTF_GUARDED_BY_LOCK(m_streamThread);
     GraphicsContextGLIdentifier m_graphicsContextGLIdentifier;
     Ref<RemoteRenderingBackend> m_renderingBackend;
-#if ENABLE(MEDIA_STREAM)
+#if ENABLE(VIDEO)
     Ref<RemoteVideoFrameObjectHeap> m_videoFrameObjectHeap;
 #endif
     ScopedWebGLRenderingResourcesRequest m_renderingResourcesRequest;

Modified: trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.messages.in (290174 => 290175)


--- trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.messages.in	2022-02-18 22:43:33 UTC (rev 290174)
+++ trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.messages.in	2022-02-18 22:48:08 UTC (rev 290175)
@@ -41,7 +41,9 @@
     void GetError() -> (uint32_t returnValue) Synchronous
     void PaintRenderingResultsToCanvas(WebCore::RenderingResourceIdentifier imageBuffer) -> () Synchronous
     void PaintCompositedResultsToCanvas(WebCore::RenderingResourceIdentifier imageBuffer) -> () Synchronous
-    void CopyTextureFromMedia(WebCore::MediaPlayerIdentifier identifier, uint32_t texture, uint32_t target, int32_t level, uint32_t internalFormat, uint32_t format, uint32_t type, bool premultiplyAlpha, bool flipY) -> (bool success) Synchronous
+#if ENABLE(VIDEO)
+    void CopyTextureFromVideoFrame(WebKit::RemoteVideoFrameReadReference videoFrame, uint32_t texture, uint32_t target, int32_t level, uint32_t internalFormat, uint32_t format, uint32_t type, bool premultiplyAlpha, bool flipY) -> (bool success) Synchronous
+#endif
 #if ENABLE(MEDIA_STREAM)
     void PaintCompositedResultsToMediaSample() -> (std::optional<WebKit::RemoteVideoFrameProxy::Properties> properties) Synchronous
 #endif

Modified: trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGLCocoa.cpp (290174 => 290175)


--- trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGLCocoa.cpp	2022-02-18 22:43:33 UTC (rev 290174)
+++ trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGLCocoa.cpp	2022-02-18 22:48:08 UTC (rev 290175)
@@ -29,12 +29,56 @@
 #if ENABLE(GPU_PROCESS) && ENABLE(WEBGL) && PLATFORM(COCOA)
 
 #include "GPUConnectionToWebProcess.h"
+#include "IPCTester.h"
 #include <WebCore/ProcessIdentity.h>
 #include <wtf/MachSendRight.h>
 
+
+#if ENABLE(VIDEO)
+#include "RemoteVideoFrameObjectHeap.h"
+#include <WebCore/GraphicsContextGLCV.h>
+#include <WebCore/MediaSampleAVFObjC.h>
+#include <WebCore/VideoFrameCV.h>
+#endif
+
 namespace WebKit {
-using namespace WebCore;
 
+#if ENABLE(VIDEO)
+void RemoteGraphicsContextGL::copyTextureFromVideoFrame(WebKit::RemoteVideoFrameReadReference read, uint32_t texture, uint32_t target, int32_t level, uint32_t internalFormat, uint32_t format, uint32_t type, bool premultiplyAlpha, bool flipY, CompletionHandler<void(bool)>&& completionHandler)
+{
+    assertIsCurrent(m_streamThread);
+    UNUSED_VARIABLE(premultiplyAlpha);
+    ASSERT_UNUSED(target, target == WebCore::GraphicsContextGL::TEXTURE_2D);
+
+    auto videoFrame = m_videoFrameObjectHeap->retire(WTFMove(read), defaultTimeout);
+    if (!videoFrame) {
+        ASSERT_IS_TESTING_IPC();
+        completionHandler(false);
+        return;
+    }
+    // Note: This extra casting is needed since VideoFrames are still MediaSamples.
+    RefPtr<WebCore::VideoFrameCV> videoFrameCV;
+    if (is<WebCore::VideoFrameCV>(*videoFrame))
+        videoFrameCV = &downcast<WebCore::VideoFrameCV>(*videoFrame);
+    else if (is<WebCore::MediaSampleAVFObjC>(*videoFrame))
+        videoFrameCV = downcast<WebCore::MediaSampleAVFObjC>(*videoFrame).videoFrame();
+    else {
+        ASSERT_NOT_REACHED(); // Programming error, not a IPC attack.
+        completionHandler(false);
+        return;
+    }
+
+    auto contextCV = m_context->asCV();
+    if (!contextCV) {
+        ASSERT_NOT_REACHED();
+        completionHandler(false);
+        return;
+    }
+
+    completionHandler(contextCV->copyVideoSampleToTexture(*videoFrameCV, texture, level, internalFormat, format, type, WebCore::GraphicsContextGL::FlipY(flipY)));
+}
+#endif
+
 namespace {
 
 class RemoteGraphicsContextGLCocoa final : public RemoteGraphicsContextGL {
@@ -46,12 +90,12 @@
     void platformWorkQueueInitialize(WebCore::GraphicsContextGLAttributes&&) final;
     void prepareForDisplay(CompletionHandler<void(WTF::MachSendRight&&)>&&) final;
 private:
-    const ProcessIdentity m_resourceOwner;
+    const WebCore::ProcessIdentity m_resourceOwner;
 };
 
 }
 
-Ref<RemoteGraphicsContextGL> RemoteGraphicsContextGL::create(GPUConnectionToWebProcess& gpuConnectionToWebProcess, GraphicsContextGLAttributes&& attributes, GraphicsContextGLIdentifier graphicsContextGLIdentifier, RemoteRenderingBackend& renderingBackend, IPC::StreamConnectionBuffer&& stream)
+Ref<RemoteGraphicsContextGL> RemoteGraphicsContextGL::create(GPUConnectionToWebProcess& gpuConnectionToWebProcess, WebCore::GraphicsContextGLAttributes&& attributes, GraphicsContextGLIdentifier graphicsContextGLIdentifier, RemoteRenderingBackend& renderingBackend, IPC::StreamConnectionBuffer&& stream)
 {
     auto instance = adoptRef(*new RemoteGraphicsContextGLCocoa(gpuConnectionToWebProcess, graphicsContextGLIdentifier, renderingBackend, WTFMove(stream)));
     instance->initialize(WTFMove(attributes));
@@ -62,13 +106,12 @@
     : RemoteGraphicsContextGL(gpuConnectionToWebProcess, graphicsContextGLIdentifier, renderingBackend, WTFMove(stream))
     , m_resourceOwner(gpuConnectionToWebProcess.webProcessIdentity())
 {
-
 }
 
 void RemoteGraphicsContextGLCocoa::platformWorkQueueInitialize(WebCore::GraphicsContextGLAttributes&& attributes)
 {
     assertIsCurrent(m_streamThread);
-    m_context = GraphicsContextGLCocoa::create(WTFMove(attributes), ProcessIdentity { m_resourceOwner });
+    m_context = WebCore::GraphicsContextGLCocoa::create(WTFMove(attributes), WebCore::ProcessIdentity { m_resourceOwner });
 }
 
 void RemoteGraphicsContextGLCocoa::prepareForDisplay(CompletionHandler<void(WTF::MachSendRight&&)>&& completionHandler)
@@ -76,7 +119,7 @@
     assertIsCurrent(m_streamThread);
     m_context->prepareForDisplay();
     MachSendRight sendRight;
-    IOSurface* displayBuffer = m_context->displayBuffer();
+    WebCore::IOSurface* displayBuffer = m_context->displayBuffer();
     if (displayBuffer) {
         m_context->markDisplayBufferInUse();
         sendRight = displayBuffer->createSendRight();

Modified: trunk/Source/WebKit/GPUProcess/media/RemoteMediaPlayerManagerProxy.cpp (290174 => 290175)


--- trunk/Source/WebKit/GPUProcess/media/RemoteMediaPlayerManagerProxy.cpp	2022-02-18 22:43:33 UTC (rev 290174)
+++ trunk/Source/WebKit/GPUProcess/media/RemoteMediaPlayerManagerProxy.cpp	2022-02-18 22:48:08 UTC (rev 290175)
@@ -67,7 +67,7 @@
     ASSERT(m_gpuConnectionToWebProcess);
     ASSERT(!m_proxies.contains(identifier));
 
-    auto proxy = makeUnique<RemoteMediaPlayerProxy>(*this, identifier, m_gpuConnectionToWebProcess->connection(), engineIdentifier, WTFMove(proxyConfiguration));
+    auto proxy = makeUnique<RemoteMediaPlayerProxy>(*this, identifier, m_gpuConnectionToWebProcess->connection(), engineIdentifier, WTFMove(proxyConfiguration), m_gpuConnectionToWebProcess->videoFrameObjectHeap());
     m_proxies.add(identifier, WTFMove(proxy));
 }
 

Modified: trunk/Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.cpp (290174 => 290175)


--- trunk/Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.cpp	2022-02-18 22:43:33 UTC (rev 290174)
+++ trunk/Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.cpp	2022-02-18 22:48:08 UTC (rev 290175)
@@ -44,6 +44,8 @@
 #include "RemoteMediaResourceLoader.h"
 #include "RemoteMediaResourceManager.h"
 #include "RemoteTextTrackProxy.h"
+#include "RemoteVideoFrameObjectHeap.h"
+#include "RemoteVideoFrameProxy.h"
 #include "RemoteVideoTrackProxy.h"
 #include "TextTrackPrivateRemoteConfiguration.h"
 #include "TrackPrivateRemoteConfiguration.h"
@@ -74,7 +76,7 @@
 
 using namespace WebCore;
 
-RemoteMediaPlayerProxy::RemoteMediaPlayerProxy(RemoteMediaPlayerManagerProxy& manager, MediaPlayerIdentifier identifier, Ref<IPC::Connection>&& connection, MediaPlayerEnums::MediaEngineIdentifier engineIdentifier, RemoteMediaPlayerProxyConfiguration&& configuration)
+RemoteMediaPlayerProxy::RemoteMediaPlayerProxy(RemoteMediaPlayerManagerProxy& manager, MediaPlayerIdentifier identifier, Ref<IPC::Connection>&& connection, MediaPlayerEnums::MediaEngineIdentifier engineIdentifier, RemoteMediaPlayerProxyConfiguration&& configuration, RemoteVideoFrameObjectHeap& videoFrameObjectHeap)
     : m_id(identifier)
     , m_webProcessConnection(WTFMove(connection))
     , m_manager(manager)
@@ -82,6 +84,7 @@
     , m_updateCachedStateMessageTimer(RunLoop::main(), this, &RemoteMediaPlayerProxy::timerFired)
     , m_configuration(configuration)
     , m_renderingResourcesRequest(ScopedRenderingResourcesRequest::acquire())
+    , m_videoFrameObjectHeap(videoFrameObjectHeap)
 #if !RELEASE_LOG_DISABLED
     , m_logger(manager.logger())
 #endif
@@ -868,11 +871,9 @@
     m_webProcessConnection->send(Messages::MediaPlayerPrivateRemote::CurrentTimeChanged(mediaTime, MonotonicTime::now(), !mediaPlayerPausedOrStalled()), m_id);
 }
 
-// FIXME: This will be turned into cross-platform code soon.
-#if PLATFORM(COCOA)
-void RemoteMediaPlayerProxy::videoFrameForCurrentTimeIfChanged(CompletionHandler<void(std::optional<RefPtr<WebCore::VideoFrameCV>>&&, bool)>&& completionHandler)
+void RemoteMediaPlayerProxy::videoFrameForCurrentTimeIfChanged(CompletionHandler<void(std::optional<RemoteVideoFrameProxy::Properties>&&, bool)>&& completionHandler)
 {
-    std::optional<RefPtr<WebCore::VideoFrameCV>> result;
+    std::optional<RemoteVideoFrameProxy::Properties> result;
     bool changed = false;
     RefPtr<WebCore::VideoFrame> videoFrame;
     if (m_player)
@@ -880,16 +881,15 @@
     if (m_videoFrameForCurrentTime != videoFrame) {
         m_videoFrameForCurrentTime = videoFrame;
         changed = true;
-        RefPtr<VideoFrameCV> videoFrameCV;
         if (videoFrame) {
-            ASSERT(is<VideoFrameCV>(*videoFrame));
-            videoFrameCV = &downcast<VideoFrameCV>(*videoFrame);
+            auto write = RemoteVideoFrameWriteReference::generateForAdd();
+            auto newFrameReference = write.retiredReference();
+            result = RemoteVideoFrameProxy::properties(WTFMove(newFrameReference), *videoFrame);
+            m_videoFrameObjectHeap->retire(WTFMove(write), WTFMove(videoFrame), std::nullopt);
         }
-        result = WTFMove(videoFrameCV);
     }
     completionHandler(WTFMove(result), changed);
 }
-#endif
 
 void RemoteMediaPlayerProxy::updateCachedState(bool forceCurrentTimeUpdate)
 {

Modified: trunk/Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.h (290174 => 290175)


--- trunk/Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.h	2022-02-18 22:43:33 UTC (rev 290174)
+++ trunk/Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.h	2022-02-18 22:48:08 UTC (rev 290175)
@@ -34,6 +34,7 @@
 #include "RemoteMediaPlayerProxyConfiguration.h"
 #include "RemoteMediaPlayerState.h"
 #include "RemoteMediaResourceIdentifier.h"
+#include "RemoteVideoFrameProxy.h"
 #include "SandboxExtension.h"
 #include "ScopedRenderingResourcesRequest.h"
 #include "TrackPrivateRemoteIdentifier.h"
@@ -98,6 +99,7 @@
 class RemoteAudioSourceProviderProxy;
 class RemoteMediaPlayerManagerProxy;
 class RemoteTextTrackProxy;
+class RemoteVideoFrameObjectHeap;
 class RemoteVideoTrackProxy;
 
 class RemoteMediaPlayerProxy final
@@ -105,7 +107,7 @@
     , public IPC::MessageReceiver {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    RemoteMediaPlayerProxy(RemoteMediaPlayerManagerProxy&, WebCore::MediaPlayerIdentifier, Ref<IPC::Connection>&&, WebCore::MediaPlayerEnums::MediaEngineIdentifier, RemoteMediaPlayerProxyConfiguration&&);
+    RemoteMediaPlayerProxy(RemoteMediaPlayerManagerProxy&, WebCore::MediaPlayerIdentifier, Ref<IPC::Connection>&&, WebCore::MediaPlayerEnums::MediaEngineIdentifier, RemoteMediaPlayerProxyConfiguration&&, RemoteVideoFrameObjectHeap&);
     ~RemoteMediaPlayerProxy();
 
     WebCore::MediaPlayerIdentifier idendifier() const { return m_id; }
@@ -333,8 +335,8 @@
 #if PLATFORM(COCOA)
     void nativeImageForCurrentTime(CompletionHandler<void(std::optional<WTF::MachSendRight>&&, WebCore::DestinationColorSpace)>&&);
     void colorSpace(CompletionHandler<void(WebCore::DestinationColorSpace)>&&);
-    void videoFrameForCurrentTimeIfChanged(CompletionHandler<void(std::optional<RefPtr<WebCore::VideoFrameCV>>&&, bool)>&&);
 #endif
+    void videoFrameForCurrentTimeIfChanged(CompletionHandler<void(std::optional<RemoteVideoFrameProxy::Properties>&&, bool)>&&);
 
 #if !RELEASE_LOG_DISABLED
     const Logger& mediaPlayerLogger() final { return m_logger; }
@@ -390,6 +392,7 @@
     ScopedRenderingResourcesRequest m_renderingResourcesRequest;
 
     bool m_observingTimeChanges { false };
+    Ref<RemoteVideoFrameObjectHeap> m_videoFrameObjectHeap;
     RefPtr<WebCore::VideoFrame> m_videoFrameForCurrentTime;
 #if !RELEASE_LOG_DISABLED
     const Logger& m_logger;

Modified: trunk/Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.messages.in (290174 => 290175)


--- trunk/Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.messages.in	2022-02-18 22:43:33 UTC (rev 290174)
+++ trunk/Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.messages.in	2022-02-18 22:48:08 UTC (rev 290175)
@@ -125,8 +125,8 @@
 #if PLATFORM(COCOA)
     NativeImageForCurrentTime() -> (std::optional<MachSendRight> sendRight, WebCore::DestinationColorSpace colorSpace) Synchronous
     ColorSpace() -> (WebCore::DestinationColorSpace colorSpace) Synchronous
-    VideoFrameForCurrentTimeIfChanged() -> (std::optional<RefPtr<WebCore::VideoFrameCV>> videoFrame, bool changed) Synchronous
 #endif
+    VideoFrameForCurrentTimeIfChanged() -> (std::optional<WebKit::RemoteVideoFrameProxy::Properties> videoFrame, bool changed) Synchronous
 
     PlayAtHostTime(MonotonicTime time)
     PauseAtHostTime(MonotonicTime time)

Modified: trunk/Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.cpp (290174 => 290175)


--- trunk/Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.cpp	2022-02-18 22:43:33 UTC (rev 290174)
+++ trunk/Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.cpp	2022-02-18 22:48:08 UTC (rev 290175)
@@ -26,13 +26,15 @@
 #include "config.h"
 #include "RemoteVideoFrameObjectHeap.h"
 
-#if ENABLE(GPU_PROCESS) && ENABLE(MEDIA_STREAM)
+#if ENABLE(GPU_PROCESS) && ENABLE(VIDEO)
 #include "GPUConnectionToWebProcess.h"
 #include "RemoteVideoFrameObjectHeapMessages.h"
 #include "RemoteVideoFrameObjectHeapProxyProcessorMessages.h"
 #include "RemoteVideoFrameProxy.h"
 
+#if PLATFORM(COCOA)
 #include <pal/cf/CoreMediaSoftLink.h>
+#endif
 
 namespace WebKit {
 
@@ -57,7 +59,9 @@
 void RemoteVideoFrameObjectHeap::stopListeningForIPC(Ref<RemoteVideoFrameObjectHeap>&& refFromConnection)
 {
     assertIsCurrent(m_consumeThread);
+#if PLATFORM(COCOA)
     m_sharedVideoFrameWriter.disable();
+#endif
 
     if (auto* gpuConnectionToWebProcess = std::exchange(m_gpuConnectionToWebProcess, nullptr)) {
         gpuConnectionToWebProcess->messageReceiverMap().removeMessageReceiver(Messages::RemoteVideoFrameObjectHeap::messageReceiverName());
@@ -82,6 +86,7 @@
     retireRemove(WTFMove(write));
 }
 
+#if PLATFORM(COCOA)
 void RemoteVideoFrameObjectHeap::getVideoFrameBuffer(RemoteVideoFrameReadReference&& read)
 {
     auto identifier = read.identifier();
@@ -99,6 +104,7 @@
     );
     m_connection->send(Messages::RemoteVideoFrameObjectHeapProxyProcessor::NewVideoFrameBuffer { identifier }, 0);
 }
+#endif
 
 }
 

Modified: trunk/Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.h (290174 => 290175)


--- trunk/Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.h	2022-02-18 22:43:33 UTC (rev 290174)
+++ trunk/Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.h	2022-02-18 22:48:08 UTC (rev 290175)
@@ -25,13 +25,16 @@
 
 #pragma once
 
-#if ENABLE(GPU_PROCESS) && ENABLE(MEDIA_STREAM)
+#if ENABLE(GPU_PROCESS) && ENABLE(VIDEO)
 #include "RemoteVideoFrameIdentifier.h"
-#include "SharedVideoFrame.h"
 #include "ThreadSafeObjectHeap.h"
 #include <WebCore/MediaSample.h>
 #include <wtf/ThreadAssertions.h>
 
+#if PLATFORM(COCOA)
+#include "SharedVideoFrame.h"
+#endif
+
 namespace WebKit {
 class GPUConnectionToWebProcess;
 
@@ -57,12 +60,16 @@
 
     // Messages.
     void releaseVideoFrame(RemoteVideoFrameWriteReference&&);
+#if PLATFORM(COCOA)
     void getVideoFrameBuffer(RemoteVideoFrameReadReference&&);
+#endif
 
     GPUConnectionToWebProcess* m_gpuConnectionToWebProcess WTF_GUARDED_BY_LOCK(m_consumeThread);
     const Ref<IPC::Connection> m_connection;
     ThreadAssertion m_consumeThread NO_UNIQUE_ADDRESS;
+#if PLATFORM(COCOA)
     SharedVideoFrameWriter m_sharedVideoFrameWriter;
+#endif
 };
 
 

Modified: trunk/Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.messages.in (290174 => 290175)


--- trunk/Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.messages.in	2022-02-18 22:43:33 UTC (rev 290174)
+++ trunk/Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.messages.in	2022-02-18 22:48:08 UTC (rev 290175)
@@ -21,9 +21,11 @@
 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 # THE POSSIBILITY OF SUCH DAMAGE.
 
-#if ENABLE(GPU_PROCESS) && ENABLE(MEDIA_STREAM)
+#if ENABLE(GPU_PROCESS) && ENABLE(VIDEO)
 messages -> RemoteVideoFrameObjectHeap NotRefCounted {
+#if PLATFORM(COCOA)
     GetVideoFrameBuffer(WebKit::RemoteVideoFrameReadReference identifier)
+#endif
     ReleaseVideoFrame(WebKit::RemoteVideoFrameWriteReference identifier)
 }
 #endif

Modified: trunk/Source/WebKit/Shared/ThreadSafeObjectHeap.h (290174 => 290175)


--- trunk/Source/WebKit/Shared/ThreadSafeObjectHeap.h	2022-02-18 22:43:33 UTC (rev 290174)
+++ trunk/Source/WebKit/Shared/ThreadSafeObjectHeap.h	2022-02-18 22:48:08 UTC (rev 290175)
@@ -25,7 +25,6 @@
 
 #pragma once
 
-#if ENABLE(GPU_PROCESS) && ENABLE(MEDIA_STREAM)
 #include "IPCTester.h"
 #include "ObjectIdentifierReferenceTracker.h"
 #include <wtf/Condition.h>
@@ -200,4 +199,3 @@
 }
 
 }
-#endif

Modified: trunk/Source/WebKit/WebProcess/GPU/GPUProcessConnection.cpp (290174 => 290175)


--- trunk/Source/WebKit/WebProcess/GPU/GPUProcessConnection.cpp	2022-02-18 22:43:33 UTC (rev 290174)
+++ trunk/Source/WebKit/WebProcess/GPU/GPUProcessConnection.cpp	2022-02-18 22:48:08 UTC (rev 290175)
@@ -76,7 +76,7 @@
 #include "UserMediaCaptureManagerMessages.h"
 #endif
 
-#if ENABLE(MEDIA_STREAM)
+#if ENABLE(VIDEO)
 #include "RemoteVideoFrameObjectHeapProxy.h"
 #include "RemoteVideoFrameProxy.h"
 #endif
@@ -166,7 +166,7 @@
 }
 #endif
 
-#if ENABLE(MEDIA_STREAM)
+#if ENABLE(VIDEO)
 RemoteVideoFrameObjectHeapProxy& GPUProcessConnection::videoFrameObjectHeapProxy()
 {
     if (!m_videoFrameObjectHeapProxy)

Modified: trunk/Source/WebKit/WebProcess/GPU/GPUProcessConnection.h (290174 => 290175)


--- trunk/Source/WebKit/WebProcess/GPU/GPUProcessConnection.h	2022-02-18 22:43:33 UTC (rev 290174)
+++ trunk/Source/WebKit/WebProcess/GPU/GPUProcessConnection.h	2022-02-18 22:48:08 UTC (rev 290175)
@@ -57,7 +57,7 @@
 struct OverrideScreenDataForTesting;
 struct WebPageCreationParameters;
 
-#if ENABLE(MEDIA_STREAM)
+#if ENABLE(VIDEO)
 class RemoteVideoFrameObjectHeapProxy;
 #endif
 
@@ -82,7 +82,7 @@
     SampleBufferDisplayLayerManager& sampleBufferDisplayLayerManager();
     void resetAudioMediaStreamTrackRendererInternalUnit(AudioMediaStreamTrackRendererInternalUnitIdentifier);
 #endif
-#if ENABLE(MEDIA_STREAM)
+#if ENABLE(VIDEO)
     RemoteVideoFrameObjectHeapProxy& videoFrameObjectHeapProxy();
 #endif
 
@@ -148,7 +148,7 @@
 #if PLATFORM(COCOA) && ENABLE(MEDIA_STREAM)
     std::unique_ptr<SampleBufferDisplayLayerManager> m_sampleBufferDisplayLayerManager;
 #endif
-#if ENABLE(MEDIA_STREAM)
+#if ENABLE(VIDEO)
     RefPtr<RemoteVideoFrameObjectHeapProxy> m_videoFrameObjectHeapProxy;
 #endif
 #if PLATFORM(COCOA) && ENABLE(WEB_AUDIO)

Modified: trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.cpp (290174 => 290175)


--- trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.cpp	2022-02-18 22:43:33 UTC (rev 290174)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.cpp	2022-02-18 22:48:08 UTC (rev 290175)
@@ -32,11 +32,11 @@
 #include "GPUProcessConnection.h"
 #include "RemoteGraphicsContextGLMessages.h"
 #include "RemoteGraphicsContextGLProxyMessages.h"
-#include "RemoteVideoFrameObjectHeapProxy.h"
 #include "WebProcess.h"
 #include <WebCore/ImageBuffer.h>
 
-#if ENABLE(MEDIA_STREAM)
+#if ENABLE(VIDEO)
+#include "RemoteVideoFrameObjectHeapProxy.h"
 #include "RemoteVideoFrameProxy.h"
 #endif
 
@@ -182,10 +182,15 @@
 }
 #endif
 
+#if ENABLE(VIDEO)
 bool RemoteGraphicsContextGLProxy::copyTextureFromMedia(MediaPlayer& mediaPlayer, PlatformGLObject texture, GCGLenum target, GCGLint level, GCGLenum internalFormat, GCGLenum format, GCGLenum type, bool premultiplyAlpha, bool flipY)
 {
+    auto videoFrame = mediaPlayer.videoFrameForCurrentTime();
+    // Video in WP while WebGL in GPUP is not supported.
+    if (!videoFrame || !is<RemoteVideoFrameProxy>(*videoFrame))
+        return false;
     bool result = false;
-    auto sendResult = sendSync(Messages::RemoteGraphicsContextGL::CopyTextureFromMedia(mediaPlayer.identifier(), texture, target, level, internalFormat, format, type, premultiplyAlpha, flipY), Messages::RemoteGraphicsContextGL::CopyTextureFromMedia::Reply(result));
+    auto sendResult = sendSync(Messages::RemoteGraphicsContextGL::CopyTextureFromVideoFrame(downcast<RemoteVideoFrameProxy>(*videoFrame).read(), texture, target, level, internalFormat, format, type, premultiplyAlpha, flipY), Messages::RemoteGraphicsContextGL::CopyTextureFromVideoFrame::Reply(result));
     if (!sendResult) {
         markContextLost();
         return false;
@@ -193,6 +198,7 @@
 
     return result;
 }
+#endif
 
 void RemoteGraphicsContextGLProxy::synthesizeGLError(GCGLenum error)
 {

Modified: trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.h (290174 => 290175)


--- trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.h	2022-02-18 22:43:33 UTC (rev 290174)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.h	2022-02-18 22:48:08 UTC (rev 290175)
@@ -73,7 +73,9 @@
 #endif
     void synthesizeGLError(GCGLenum error) final;
     GCGLenum getError() final;
+#if ENABLE(VIDEO)
     bool copyTextureFromMedia(WebCore::MediaPlayer&, PlatformGLObject texture, GCGLenum target, GCGLint level, GCGLenum internalFormat, GCGLenum format, GCGLenum type, bool premultiplyAlpha, bool flipY) final;
+#endif
     void simulateEventForTesting(SimulatedEventForTesting) final;
 
     // Functions with a generated implementation. This list is used by generate-gpup-webgl script.

Modified: trunk/Source/WebKit/WebProcess/GPU/media/MediaPlayerPrivateRemote.cpp (290174 => 290175)


--- trunk/Source/WebKit/WebProcess/GPU/media/MediaPlayerPrivateRemote.cpp	2022-02-18 22:43:33 UTC (rev 290174)
+++ trunk/Source/WebKit/WebProcess/GPU/media/MediaPlayerPrivateRemote.cpp	2022-02-18 22:48:08 UTC (rev 290175)
@@ -1005,19 +1005,16 @@
 
 RefPtr<WebCore::VideoFrame> MediaPlayerPrivateRemote::videoFrameForCurrentTime()
 {
-// FIXME: This will be made cross-platform again soon. There are no other platforms using this at the moment.
-#if PLATFORM(COCOA)
-    std::optional<RefPtr<WebCore::VideoFrameCV>> result;
+    std::optional<RemoteVideoFrameProxy::Properties> result;
     bool changed = false;
     if (!connection().sendSync(Messages::RemoteMediaPlayerProxy::VideoFrameForCurrentTimeIfChanged(), Messages::RemoteMediaPlayerProxy::VideoFrameForCurrentTimeIfChanged::Reply(result, changed), m_id))
-        return m_videoFrameForCurrentTime;
+        return nullptr;
     if (changed) {
         if (result)
-            m_videoFrameForCurrentTime = WTFMove(*result);
+            m_videoFrameForCurrentTime = RemoteVideoFrameProxy::create(connection(), videoFrameObjectHeapProxy(), WTFMove(*result));
         else
             m_videoFrameForCurrentTime = nullptr;
     }
-#endif
     return m_videoFrameForCurrentTime;
 }
 

Modified: trunk/Source/WebKit/WebProcess/GPU/media/MediaPlayerPrivateRemote.h (290174 => 290175)


--- trunk/Source/WebKit/WebProcess/GPU/media/MediaPlayerPrivateRemote.h	2022-02-18 22:43:33 UTC (rev 290174)
+++ trunk/Source/WebKit/WebProcess/GPU/media/MediaPlayerPrivateRemote.h	2022-02-18 22:48:08 UTC (rev 290175)
@@ -34,6 +34,8 @@
 #include "RemoteMediaPlayerState.h"
 #include "RemoteMediaResourceIdentifier.h"
 #include "RemoteMediaResourceProxy.h"
+#include "RemoteVideoFrameObjectHeapProxy.h"
+#include "RemoteVideoFrameProxy.h"
 #include "TextTrackPrivateRemote.h"
 #include "TrackPrivateRemoteIdentifier.h"
 #include "VideoTrackPrivateRemote.h"
@@ -413,6 +415,7 @@
 #if PLATFORM(COCOA)
     void pushVideoFrameMetadata(WebCore::VideoFrameMetadata&&, RetainPtr<CVPixelBufferRef>&&);
 #endif
+    RemoteVideoFrameObjectHeapProxy& videoFrameObjectHeapProxy() const { return m_manager.gpuProcessConnection().videoFrameObjectHeapProxy(); }
 
     WeakPtr<WebCore::MediaPlayer> m_player;
     Ref<WebCore::PlatformMediaResourceLoader> m_mediaResourceLoader;
@@ -461,7 +464,7 @@
     bool m_waitingForKey { false };
     bool m_timeIsProgressing { false };
     bool m_renderingCanBeAccelerated { false };
-    RefPtr<WebCore::VideoFrame> m_videoFrameForCurrentTime;
+    RefPtr<RemoteVideoFrameProxy> m_videoFrameForCurrentTime;
 #if PLATFORM(COCOA)
     RetainPtr<CVPixelBufferRef> m_pixelBufferGatheredWithVideoFrameMetadata;
     std::unique_ptr<WebCore::PixelBufferConformerCV> m_pixelBufferConformer;

Modified: trunk/Source/WebKit/WebProcess/GPU/media/RemoteVideoFrameIdentifier.h (290174 => 290175)


--- trunk/Source/WebKit/WebProcess/GPU/media/RemoteVideoFrameIdentifier.h	2022-02-18 22:43:33 UTC (rev 290174)
+++ trunk/Source/WebKit/WebProcess/GPU/media/RemoteVideoFrameIdentifier.h	2022-02-18 22:48:08 UTC (rev 290175)
@@ -25,7 +25,7 @@
 
 #pragma once
 
-#if ENABLE(GPU_PROCESS) && ENABLE(MEDIA_STREAM)
+#if ENABLE(GPU_PROCESS) && ENABLE(VIDEO)
 
 #include "ObjectIdentifierReferenceTracker.h"
 #include <WebCore/ProcessQualified.h>

Modified: trunk/Source/WebKit/WebProcess/GPU/media/RemoteVideoFrameProxy.cpp (290174 => 290175)


--- trunk/Source/WebKit/WebProcess/GPU/media/RemoteVideoFrameProxy.cpp	2022-02-18 22:43:33 UTC (rev 290174)
+++ trunk/Source/WebKit/WebProcess/GPU/media/RemoteVideoFrameProxy.cpp	2022-02-18 22:48:08 UTC (rev 290175)
@@ -26,13 +26,15 @@
 #include "config.h"
 #include "RemoteVideoFrameProxy.h"
 
-#if ENABLE(GPU_PROCESS) && ENABLE(MEDIA_STREAM)
+#if ENABLE(GPU_PROCESS) && ENABLE(VIDEO)
 #include "GPUConnectionToWebProcess.h"
 #include "RemoteVideoFrameObjectHeapMessages.h"
 #include "RemoteVideoFrameObjectHeapProxy.h"
-#include <WebCore/RealtimeIncomingVideoSourceCocoa.h>
 
 #if PLATFORM(COCOA)
+#include <WebCore/CVUtilities.h>
+#include <WebCore/RealtimeIncomingVideoSourceCocoa.h>
+#include <WebCore/VideoFrameCV.h>
 #include <wtf/threads/BinarySemaphore.h>
 #endif
 
@@ -119,6 +121,15 @@
     }
     return m_pixelBuffer.get();
 }
+
+RefPtr<WebCore::VideoFrameCV> RemoteVideoFrameProxy::asVideoFrameCV()
+{
+    auto buffer = pixelBuffer();
+    if (!buffer)
+        return nullptr;
+    return VideoFrameCV::create(m_presentationTime, m_isMirrored, m_rotation, RetainPtr { buffer });
+}
+
 #endif
 
 TextStream& operator<<(TextStream& ts, const RemoteVideoFrameProxy::Properties& properties)

Modified: trunk/Source/WebKit/WebProcess/GPU/media/RemoteVideoFrameProxy.h (290174 => 290175)


--- trunk/Source/WebKit/WebProcess/GPU/media/RemoteVideoFrameProxy.h	2022-02-18 22:43:33 UTC (rev 290174)
+++ trunk/Source/WebKit/WebProcess/GPU/media/RemoteVideoFrameProxy.h	2022-02-18 22:48:08 UTC (rev 290175)
@@ -25,7 +25,7 @@
 
 #pragma once
 
-#if ENABLE(GPU_PROCESS) && ENABLE(MEDIA_STREAM)
+#if ENABLE(GPU_PROCESS) && ENABLE(VIDEO)
 
 #include "GPUProcessConnection.h"
 #include "RemoteVideoFrameIdentifier.h"
@@ -36,6 +36,12 @@
 class Decoder;
 }
 
+namespace WebCore {
+#if PLATFORM(COCOA)
+class VideoFrameCV;
+#endif
+}
+
 namespace WebKit {
 
 class GPUProcessConnection;
@@ -80,16 +86,15 @@
     // WebCore::VideoFrame overrides.
     WebCore::FloatSize presentationSize() const final { return m_size; }
     uint32_t videoPixelFormat() const final;
+    bool isRemoteProxy() const final { return true; }
 #if PLATFORM(COCOA)
     CVPixelBufferRef pixelBuffer() const final;
+    RefPtr<WebCore::VideoFrameCV> asVideoFrameCV() final;
 #endif
-    bool isRemoteProxy() const final { return true; }
 
 private:
     RemoteVideoFrameProxy(IPC::Connection&, RemoteVideoFrameObjectHeapProxy&, Properties&&);
 
-
-
     const Ref<IPC::Connection> m_connection;
     RemoteVideoFrameReferenceTracker m_referenceTracker;
     const WebCore::IntSize m_size;

Modified: trunk/Source/WebKit/WebProcess/GPU/media/RemoteVideoFrameProxyIdentifier.h (290174 => 290175)


--- trunk/Source/WebKit/WebProcess/GPU/media/RemoteVideoFrameProxyIdentifier.h	2022-02-18 22:43:33 UTC (rev 290174)
+++ trunk/Source/WebKit/WebProcess/GPU/media/RemoteVideoFrameProxyIdentifier.h	2022-02-18 22:48:08 UTC (rev 290175)
@@ -25,7 +25,7 @@
 
 #pragma once
 
-#if ENABLE(MEDIA_STREAM)
+#if ENABLE(GPU_PROCESS) && ENABLE(VIDEO)
 
 #include "ObjectIdentifierReferenceTracker.h"
 #include <WebCore/RemoteVideoFrameIdentifier.h>
@@ -39,4 +39,4 @@
 
 } // namespace WebKit
 
-#endif // ENABLE(MEDIA_STREAM)
+#endif

Modified: trunk/Source/WebKit/WebProcess/GPU/webrtc/MediaRecorderPrivate.cpp (290174 => 290175)


--- trunk/Source/WebKit/WebProcess/GPU/webrtc/MediaRecorderPrivate.cpp	2022-02-18 22:43:33 UTC (rev 290174)
+++ trunk/Source/WebKit/WebProcess/GPU/webrtc/MediaRecorderPrivate.cpp	2022-02-18 22:48:08 UTC (rev 290175)
@@ -35,6 +35,7 @@
 #include "RemoteVideoFrameProxy.h"
 #include "WebProcess.h"
 #include <WebCore/CARingBuffer.h>
+#include <WebCore/CVUtilities.h>
 #include <WebCore/MediaStreamPrivate.h>
 #include <WebCore/MediaStreamTrackPrivate.h>
 #include <WebCore/RealtimeIncomingVideoSourceCocoa.h>

Modified: trunk/Source/WebKit/WebProcess/GPU/webrtc/RemoteVideoFrameObjectHeapProxy.h (290174 => 290175)


--- trunk/Source/WebKit/WebProcess/GPU/webrtc/RemoteVideoFrameObjectHeapProxy.h	2022-02-18 22:43:33 UTC (rev 290174)
+++ trunk/Source/WebKit/WebProcess/GPU/webrtc/RemoteVideoFrameObjectHeapProxy.h	2022-02-18 22:48:08 UTC (rev 290175)
@@ -25,12 +25,23 @@
 
 #pragma once
 
-#if ENABLE(MEDIA_STREAM) && ENABLE(GPU_PROCESS)
+#if ENABLE(GPU_PROCESS) && ENABLE(VIDEO)
 
+#include <wtf/Ref.h>
+#include <wtf/ThreadSafeRefCounted.h>
+
+#if PLATFORM(COCOA)
 #include "RemoteVideoFrameObjectHeapProxyProcessor.h"
+#endif
 
 namespace WebKit {
 
+class GPUProcessConnection;
+
+#if PLATFORM(COCOA)
+class RemoteVideoFrameProxy;
+#endif
+
 // Wrapper around RemoteVideoFrameObjectHeapProxyProcessor that will always be destroeyd on main thread.
 class RemoteVideoFrameObjectHeapProxy : public ThreadSafeRefCounted<RemoteVideoFrameObjectHeapProxy, WTF::DestructionThread::MainRunLoop> {
 public:

Modified: trunk/Source/WebKit/WebProcess/GPU/webrtc/RemoteVideoFrameObjectHeapProxyProcessor.cpp (290174 => 290175)


--- trunk/Source/WebKit/WebProcess/GPU/webrtc/RemoteVideoFrameObjectHeapProxyProcessor.cpp	2022-02-18 22:43:33 UTC (rev 290174)
+++ trunk/Source/WebKit/WebProcess/GPU/webrtc/RemoteVideoFrameObjectHeapProxyProcessor.cpp	2022-02-18 22:48:08 UTC (rev 290175)
@@ -26,10 +26,11 @@
 #include "config.h"
 #include "RemoteVideoFrameObjectHeapProxy.h"
 
-#if ENABLE(MEDIA_STREAM) && PLATFORM(COCOA) && ENABLE(GPU_PROCESS)
+#if PLATFORM(COCOA) && ENABLE(GPU_PROCESS) && ENABLE(VIDEO)
 
 #include "RemoteVideoFrameObjectHeapMessages.h"
 #include "RemoteVideoFrameObjectHeapProxyProcessorMessages.h"
+#include "RemoteVideoFrameProxy.h"
 
 namespace WebKit {
 

Modified: trunk/Source/WebKit/WebProcess/GPU/webrtc/RemoteVideoFrameObjectHeapProxyProcessor.h (290174 => 290175)


--- trunk/Source/WebKit/WebProcess/GPU/webrtc/RemoteVideoFrameObjectHeapProxyProcessor.h	2022-02-18 22:43:33 UTC (rev 290174)
+++ trunk/Source/WebKit/WebProcess/GPU/webrtc/RemoteVideoFrameObjectHeapProxyProcessor.h	2022-02-18 22:48:08 UTC (rev 290175)
@@ -25,7 +25,7 @@
 
 #pragma once
 
-#if ENABLE(MEDIA_STREAM) && PLATFORM(COCOA) && ENABLE(GPU_PROCESS)
+#if ENABLE(GPU_PROCESS) && PLATFORM(COCOA) && ENABLE(VIDEO)
 
 #include "Connection.h"
 #include "GPUProcessConnection.h"
@@ -32,6 +32,7 @@
 #include "MessageReceiver.h"
 #include "RemoteVideoFrameIdentifier.h"
 #include "SharedVideoFrame.h"
+
 #include <wtf/Function.h>
 #include <wtf/HashMap.h>
 #include <wtf/Lock.h>

Modified: trunk/Source/WebKit/WebProcess/GPU/webrtc/RemoteVideoFrameObjectHeapProxyProcessor.messages.in (290174 => 290175)


--- trunk/Source/WebKit/WebProcess/GPU/webrtc/RemoteVideoFrameObjectHeapProxyProcessor.messages.in	2022-02-18 22:43:33 UTC (rev 290174)
+++ trunk/Source/WebKit/WebProcess/GPU/webrtc/RemoteVideoFrameObjectHeapProxyProcessor.messages.in	2022-02-18 22:48:08 UTC (rev 290175)
@@ -20,7 +20,7 @@
 # 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.
 
-#if ENABLE(MEDIA_STREAM) && PLATFORM(COCOA) && ENABLE(GPU_PROCESS)
+#if PLATFORM(COCOA) && ENABLE(GPU_PROCESS) && ENABLE(VIDEO)
 
 messages -> RemoteVideoFrameObjectHeapProxyProcessor {
     SetSharedVideoFrameSemaphore(IPC::Semaphore semaphore)
@@ -29,4 +29,4 @@
     NewVideoFrameBuffer(WebKit::RemoteVideoFrameIdentifier identifier)
 }
 
-#endif // ENABLE(MEDIA_STREAM) && PLATFORM(COCOA) && ENABLE(GPU_PROCESS)
+#endif

Modified: trunk/Source/WebKit/WebProcess/GPU/webrtc/SharedVideoFrame.cpp (290174 => 290175)


--- trunk/Source/WebKit/WebProcess/GPU/webrtc/SharedVideoFrame.cpp	2022-02-18 22:43:33 UTC (rev 290174)
+++ trunk/Source/WebKit/WebProcess/GPU/webrtc/SharedVideoFrame.cpp	2022-02-18 22:48:08 UTC (rev 290175)
@@ -26,7 +26,7 @@
 #include "config.h"
 #include "SharedVideoFrame.h"
 
-#if ENABLE(MEDIA_STREAM) && PLATFORM(COCOA)
+#if ENABLE(GPU_PROCESS) && PLATFORM(COCOA) && ENABLE(VIDEO)
 
 #include "Logging.h"
 #include <WebCore/SharedVideoFrameInfo.h>
@@ -152,4 +152,4 @@
 
 }
 
-#endif // ENABLE(MEDIA_STREAM) && PLATFORM(COCOA)
+#endif

Modified: trunk/Source/WebKit/WebProcess/GPU/webrtc/SharedVideoFrame.h (290174 => 290175)


--- trunk/Source/WebKit/WebProcess/GPU/webrtc/SharedVideoFrame.h	2022-02-18 22:43:33 UTC (rev 290174)
+++ trunk/Source/WebKit/WebProcess/GPU/webrtc/SharedVideoFrame.h	2022-02-18 22:48:08 UTC (rev 290175)
@@ -25,7 +25,7 @@
 
 #pragma once
 
-#if ENABLE(MEDIA_STREAM) && PLATFORM(COCOA)
+#if ENABLE(GPU_PROCESS) && PLATFORM(COCOA) && ENABLE(VIDEO)
 
 #include "IPCSemaphore.h"
 #include "SharedMemory.h"
@@ -97,7 +97,6 @@
 {
 }
 
-
 }
 
-#endif // ENABLE(MEDIA_STREAM)
+#endif
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to