Title: [290513] trunk/Source/WebKit
Revision
290513
Author
[email protected]
Date
2022-02-25 08:56:17 -0800 (Fri, 25 Feb 2022)

Log Message

Better isolate RemoteVideoFrameObjectHeap clients from ThreadSafeObjectHeap implementation details
https://bugs.webkit.org/show_bug.cgi?id=237191

Reviewed by Kimmo Kinnunen.

Refactoring to make RemoteVideoFrameObjectHeap API independent of ThreadSafeObjectHeap.
This makes code more readable and simplifies client side usage as well,
for instance by not having to care about timers, or using more known names like add/get instead of retire.

No change of behavior.

* GPUProcess/graphics/RemoteGraphicsContextGL.cpp:
* GPUProcess/graphics/RemoteGraphicsContextGL.h:
* GPUProcess/graphics/RemoteGraphicsContextGLCocoa.cpp:
* GPUProcess/media/RemoteMediaPlayerProxy.cpp:
* GPUProcess/media/RemoteVideoFrameObjectHeap.cpp:
* GPUProcess/media/RemoteVideoFrameObjectHeap.h:
* GPUProcess/webrtc/LibWebRTCCodecsProxy.mm:
* GPUProcess/webrtc/RemoteSampleBufferDisplayLayer.cpp:
* Shared/ThreadSafeObjectHeap.h:
* WebProcess/GPU/webrtc/SharedVideoFrame.cpp:

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (290512 => 290513)


--- trunk/Source/WebKit/ChangeLog	2022-02-25 16:44:23 UTC (rev 290512)
+++ trunk/Source/WebKit/ChangeLog	2022-02-25 16:56:17 UTC (rev 290513)
@@ -1,3 +1,27 @@
+2022-02-25  Youenn Fablet  <[email protected]>
+
+        Better isolate RemoteVideoFrameObjectHeap clients from ThreadSafeObjectHeap implementation details
+        https://bugs.webkit.org/show_bug.cgi?id=237191
+
+        Reviewed by Kimmo Kinnunen.
+
+        Refactoring to make RemoteVideoFrameObjectHeap API independent of ThreadSafeObjectHeap.
+        This makes code more readable and simplifies client side usage as well,
+        for instance by not having to care about timers, or using more known names like add/get instead of retire.
+
+        No change of behavior.
+
+        * GPUProcess/graphics/RemoteGraphicsContextGL.cpp:
+        * GPUProcess/graphics/RemoteGraphicsContextGL.h:
+        * GPUProcess/graphics/RemoteGraphicsContextGLCocoa.cpp:
+        * GPUProcess/media/RemoteMediaPlayerProxy.cpp:
+        * GPUProcess/media/RemoteVideoFrameObjectHeap.cpp:
+        * GPUProcess/media/RemoteVideoFrameObjectHeap.h:
+        * GPUProcess/webrtc/LibWebRTCCodecsProxy.mm:
+        * GPUProcess/webrtc/RemoteSampleBufferDisplayLayer.cpp:
+        * Shared/ThreadSafeObjectHeap.h:
+        * WebProcess/GPU/webrtc/SharedVideoFrame.cpp:
+
 2022-02-25  Per Arne Vollan  <[email protected]>
 
         Remove unused soft linking declarations

Modified: trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.cpp (290512 => 290513)


--- trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.cpp	2022-02-25 16:44:23 UTC (rev 290512)
+++ trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.cpp	2022-02-25 16:56:17 UTC (rev 290513)
@@ -228,12 +228,8 @@
 {
     assertIsCurrent(workQueue());
     std::optional<WebKit::RemoteVideoFrameProxy::Properties> result;
-    if (auto videoFrame = m_context->paintCompositedResultsToMediaSample()) {
-        auto write = RemoteVideoFrameWriteReference::generateForAdd();
-        auto newFrameReference = write.retiredReference();
-        result = RemoteVideoFrameProxy::properties(WTFMove(newFrameReference), *videoFrame);
-        m_videoFrameObjectHeap->retire(WTFMove(write), WTFMove(videoFrame), std::nullopt);
-    }
+    if (auto videoFrame = m_context->paintCompositedResultsToMediaSample())
+        result = m_videoFrameObjectHeap->add(videoFrame.releaseNonNull());
     completionHandler(WTFMove(result));
 }
 #endif
@@ -277,7 +273,7 @@
 void RemoteGraphicsContextGL::copyTextureFromVideoFrame(WebKit::RemoteVideoFrameReadReference read, uint32_t, uint32_t, int32_t, uint32_t, uint32_t, uint32_t, bool, bool , CompletionHandler<void(bool)>&& completionHandler)
 {
     notImplemented();
-    m_videoFrameObjectHeap->retire(WTFMove(read), defaultTimeout);
+    m_videoFrameObjectHeap->get(WTFMove(read));
     completionHandler(false);
 }
 #endif

Modified: trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.h (290512 => 290513)


--- trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.h	2022-02-25 16:44:23 UTC (rev 290512)
+++ trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.h	2022-02-25 16:56:17 UTC (rev 290513)
@@ -137,7 +137,6 @@
 protected:
     WeakPtr<GPUConnectionToWebProcess> m_gpuConnectionToWebProcess;
     RefPtr<IPC::StreamServerConnection> m_streamConnection;
-    static constexpr Seconds defaultTimeout = 10_s;
 #if PLATFORM(COCOA)
     using GCGLContext = WebCore::GraphicsContextGLCocoa;
 #else

Modified: trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGLCocoa.cpp (290512 => 290513)


--- trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGLCocoa.cpp	2022-02-25 16:44:23 UTC (rev 290512)
+++ trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGLCocoa.cpp	2022-02-25 16:56:17 UTC (rev 290513)
@@ -50,7 +50,7 @@
     UNUSED_VARIABLE(premultiplyAlpha);
     ASSERT_UNUSED(target, target == WebCore::GraphicsContextGL::TEXTURE_2D);
 
-    auto videoFrame = m_videoFrameObjectHeap->retire(WTFMove(read), defaultTimeout);
+    auto videoFrame = m_videoFrameObjectHeap->get(WTFMove(read));
     if (!videoFrame) {
         ASSERT_IS_TESTING_IPC();
         completionHandler(false);

Modified: trunk/Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.cpp (290512 => 290513)


--- trunk/Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.cpp	2022-02-25 16:44:23 UTC (rev 290512)
+++ trunk/Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.cpp	2022-02-25 16:56:17 UTC (rev 290513)
@@ -879,12 +879,8 @@
     if (m_videoFrameForCurrentTime != videoFrame) {
         m_videoFrameForCurrentTime = videoFrame;
         changed = true;
-        if (videoFrame) {
-            auto write = RemoteVideoFrameWriteReference::generateForAdd();
-            auto newFrameReference = write.retiredReference();
-            result = RemoteVideoFrameProxy::properties(WTFMove(newFrameReference), *videoFrame);
-            m_videoFrameObjectHeap->retire(WTFMove(write), WTFMove(videoFrame), std::nullopt);
-        }
+        if (videoFrame)
+            result = m_videoFrameObjectHeap->add(videoFrame.releaseNonNull());
     }
     completionHandler(WTFMove(result), changed);
 }

Modified: trunk/Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.cpp (290512 => 290513)


--- trunk/Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.cpp	2022-02-25 16:44:23 UTC (rev 290512)
+++ trunk/Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.cpp	2022-02-25 16:56:17 UTC (rev 290513)
@@ -47,7 +47,7 @@
 
 RemoteVideoFrameObjectHeap::RemoteVideoFrameObjectHeap(GPUConnectionToWebProcess& connectionToWebProcess)
     : m_gpuConnectionToWebProcess(&connectionToWebProcess)
-    , m_connection(m_gpuConnectionToWebProcess->connection())
+    , m_connection(connectionToWebProcess.connection())
 {
     m_gpuConnectionToWebProcess->messageReceiverMap().addMessageReceiver(Messages::RemoteVideoFrameObjectHeap::messageReceiverName(), *this);
 }
@@ -69,7 +69,7 @@
         // Clients might hold on to the ref after this happens. They should also stop themselves, but if they do not,
         // avoid big memory leaks by clearing the frames. The clients should fail gracefully (do nothing) in case they fail to look up
         // frames.
-        clear();
+        m_heap.clear();
         // TODO: add can happen after stopping.
     }
 }
@@ -78,16 +78,16 @@
 RemoteVideoFrameIdentifier RemoteVideoFrameObjectHeap::createRemoteVideoFrame(Ref<WebCore::MediaSample>&& frame)
 {
     auto identifier = RemoteVideoFrameIdentifier::generateThreadSafe();
-    add(identifier, WTFMove(frame));
+    m_heap.add(identifier, WTFMove(frame));
     return identifier;
 }
 
-RemoteVideoFrameProxy::Properties RemoteVideoFrameObjectHeap::addVideoFrame(Ref<WebCore::MediaSample>&& frame)
+RemoteVideoFrameProxy::Properties RemoteVideoFrameObjectHeap::add(Ref<WebCore::MediaSample>&& frame)
 {
     auto write = RemoteVideoFrameWriteReference::generateForAdd();
     auto newFrameReference = write.retiredReference();
     auto properties = RemoteVideoFrameProxy::properties(WTFMove(newFrameReference), frame);
-    retire(WTFMove(write), WTFMove(frame), std::nullopt);
+    m_heap.retire(WTFMove(write), WTFMove(frame), std::nullopt);
     return properties;
 }
 
@@ -94,7 +94,7 @@
 void RemoteVideoFrameObjectHeap::releaseVideoFrame(RemoteVideoFrameWriteReference&& write)
 {
     assertIsMainThread();
-    retireRemove(WTFMove(write));
+    m_heap.retireRemove(WTFMove(write));
 }
 
 #if PLATFORM(COCOA)
@@ -101,7 +101,7 @@
 void RemoteVideoFrameObjectHeap::getVideoFrameBuffer(RemoteVideoFrameReadReference&& read)
 {
     auto identifier = read.identifier();
-    auto videoFrame = retire(WTFMove(read), 0_s);
+    auto videoFrame = m_heap.retire(WTFMove(read), 0_s);
 
     if (!videoFrame) {
         m_connection->send(Messages::RemoteVideoFrameObjectHeapProxyProcessor::VideoFrameBufferNotFound { identifier }, 0);
@@ -129,23 +129,16 @@
 
 void RemoteVideoFrameObjectHeap::pixelBuffer(RemoteVideoFrameReadReference&& read, CompletionHandler<void(RetainPtr<CVPixelBufferRef>)>&& completionHandler)
 {
-    auto videoFrame = retire(WTFMove(read), defaultTimeout);
+    auto videoFrame = m_heap.retire(WTFMove(read), 0_s);
     if (!videoFrame) {
         ASSERT_IS_TESTING_IPC();
         completionHandler(nullptr);
         return;
     }
-    RetainPtr<CVPixelBufferRef> pixelBuffer;
-    if (is<VideoFrameCV>(videoFrame))
-        pixelBuffer = downcast<VideoFrameCV>(*videoFrame).pixelBuffer();
-    else if (is<MediaSampleAVFObjC>(*videoFrame))
-        pixelBuffer = downcast<MediaSampleAVFObjC>(*videoFrame).pixelBuffer();
-    else {
-        ASSERT_NOT_REACHED();
-        completionHandler(nullptr);
-        return;
-    }
-    completionHandler(pixelBuffer);
+
+    auto pixelBuffer = videoFrame->pixelBuffer();
+    ASSERT(pixelBuffer);
+    completionHandler(WTFMove(pixelBuffer));
 }
 
 #endif

Modified: trunk/Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.h (290512 => 290513)


--- trunk/Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.h	2022-02-25 16:44:23 UTC (rev 290512)
+++ trunk/Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.h	2022-02-25 16:56:17 UTC (rev 290513)
@@ -26,11 +26,10 @@
 #pragma once
 
 #if ENABLE(GPU_PROCESS) && ENABLE(VIDEO)
-#include "RemoteVideoFrameIdentifier.h"
 #include "RemoteVideoFrameProxy.h"
 #include "ThreadSafeObjectHeap.h"
 #include <WebCore/MediaSample.h>
-#include <wtf/ThreadAssertions.h>
+#include <wtf/ThreadSafeRefCounted.h>
 
 #if PLATFORM(COCOA)
 #include "SharedVideoFrame.h"
@@ -39,24 +38,20 @@
 namespace WebKit {
 class GPUConnectionToWebProcess;
 
-// Holds references to all VideoFrame instances that are mapped from Web process to GPU process two processes.
-// As currently there is no special state for RemoteVideoFrame, the object heap stores VideoFrame instances (MediaSample).
-// As currently there is no RemoteVideoFrame, responsible for dispatching the VideoFrame methods to the objects.
-// Consume thread is the thread that uses the VideoFrame. For GPUP this is the media player thread, the main thread.
-// FIXME: currently VideoFrame instances are MediaSample instances.
-class RemoteVideoFrameObjectHeap final : public ThreadSafeObjectHeap<RemoteVideoFrameIdentifier, RefPtr<WebCore::MediaSample>>, private IPC::MessageReceiver {
+// Holds references to all VideoFrame instances that are mapped from GPU process to Web process.
+class RemoteVideoFrameObjectHeap final : public ThreadSafeRefCounted<RemoteVideoFrameObjectHeap>, private IPC::MessageReceiver {
 public:
     static Ref<RemoteVideoFrameObjectHeap> create(GPUConnectionToWebProcess&);
     ~RemoteVideoFrameObjectHeap();
 
-    // FIXME: This will be removed once call sites use addVideoFrame().
     RemoteVideoFrameIdentifier createRemoteVideoFrame(Ref<WebCore::MediaSample>&&);
-    RemoteVideoFrameProxy::Properties addVideoFrame(Ref<WebCore::MediaSample>&&);
+    RemoteVideoFrameProxy::Properties add(Ref<WebCore::MediaSample>&&);
+    RefPtr<WebCore::MediaSample> get(RemoteVideoFrameReadReference&& read) { return m_heap.retire(WTFMove(read), 0_s); }
 
     void stopListeningForIPC(Ref<RemoteVideoFrameObjectHeap>&& refFromConnection);
 
 private:
-    RemoteVideoFrameObjectHeap(GPUConnectionToWebProcess&);
+    explicit RemoteVideoFrameObjectHeap(GPUConnectionToWebProcess&);
 
     // IPC::MessageReceiver overrides.
     void didReceiveMessage(IPC::Connection&, IPC::Decoder&) final;
@@ -68,10 +63,10 @@
     void getVideoFrameBuffer(RemoteVideoFrameReadReference&&);
     void pixelBuffer(RemoteVideoFrameReadReference&&, CompletionHandler<void(RetainPtr<CVPixelBufferRef>)>&&);
 #endif
-    inline static Seconds defaultTimeout = 10_s;
 
     GPUConnectionToWebProcess* m_gpuConnectionToWebProcess WTF_GUARDED_BY_CAPABILITY(mainThread);
     const Ref<IPC::Connection> m_connection;
+    ThreadSafeObjectHeap<RemoteVideoFrameIdentifier, RefPtr<WebCore::MediaSample>> m_heap;
 #if PLATFORM(COCOA)
     SharedVideoFrameWriter m_sharedVideoFrameWriter;
 #endif

Modified: trunk/Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.mm (290512 => 290513)


--- trunk/Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.mm	2022-02-25 16:44:23 UTC (rev 290512)
+++ trunk/Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.mm	2022-02-25 16:56:17 UTC (rev 290513)
@@ -91,7 +91,7 @@
         if (resourceOwner)
             sample->setOwnershipIdentity(resourceOwner);
         if (useRemoteFrames) {
-            auto properties = videoFrameObjectHeap->addVideoFrame(sample.releaseNonNull());
+            auto properties = videoFrameObjectHeap->add(sample.releaseNonNull());
             connection->send(Messages::LibWebRTCCodecs::CompletedDecoding { identifier, timeStamp, WTFMove(properties) }, 0);
             return;
         }
@@ -231,7 +231,7 @@
 {
     RetainPtr<CVPixelBufferRef> pixelBuffer;
     if (sampleReference) {
-        auto sample = m_videoFrameObjectHeap->retire(WTFMove(*sampleReference), 0_s);
+        auto sample = m_videoFrameObjectHeap->get(WTFMove(*sampleReference));
         if (!sample)
             return;
 

Modified: trunk/Source/WebKit/GPUProcess/webrtc/RemoteSampleBufferDisplayLayer.cpp (290512 => 290513)


--- trunk/Source/WebKit/GPUProcess/webrtc/RemoteSampleBufferDisplayLayer.cpp	2022-02-25 16:44:23 UTC (rev 290512)
+++ trunk/Source/WebKit/GPUProcess/webrtc/RemoteSampleBufferDisplayLayer.cpp	2022-02-25 16:56:17 UTC (rev 290513)
@@ -37,7 +37,6 @@
 #include <WebCore/RemoteVideoSample.h>
 
 namespace WebKit {
-static constexpr Seconds defaultTimeout { 1_s };
 
 using namespace WebCore;
 

Modified: trunk/Source/WebKit/Shared/ThreadSafeObjectHeap.h (290512 => 290513)


--- trunk/Source/WebKit/Shared/ThreadSafeObjectHeap.h	2022-02-25 16:44:23 UTC (rev 290512)
+++ trunk/Source/WebKit/Shared/ThreadSafeObjectHeap.h	2022-02-25 16:56:17 UTC (rev 290513)
@@ -31,7 +31,6 @@
 #include <wtf/HashMap.h>
 #include <wtf/Lock.h>
 #include <wtf/ThreadAssertions.h>
-#include <wtf/ThreadSafeRefCounted.h>
 
 namespace WebKit {
 
@@ -45,7 +44,7 @@
 // Currently implemented only for read-only (create-read-destroy) or copy-on-write types,
 // e.g. no two-phase get() operations are not implemented yet.
 template<typename Identifier, typename HeldType>
-class ThreadSafeObjectHeap : public ThreadSafeRefCounted<ThreadSafeObjectHeap<Identifier, HeldType>> {
+class ThreadSafeObjectHeap {
 public:
     using ReadReference = typename ObjectIdentifierReferenceTracker<Identifier>::ReadReference;
     using WriteReference = typename ObjectIdentifierReferenceTracker<Identifier>::WriteReference;

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


--- trunk/Source/WebKit/WebProcess/GPU/webrtc/SharedVideoFrame.cpp	2022-02-25 16:44:23 UTC (rev 290512)
+++ trunk/Source/WebKit/WebProcess/GPU/webrtc/SharedVideoFrame.cpp	2022-02-25 16:56:17 UTC (rev 290513)
@@ -177,7 +177,7 @@
         if (!m_objectHeap)
             return nullptr;
 
-        auto sample = m_objectHeap->retire(WTFMove(reference), 0_s);
+        auto sample = m_objectHeap->get(WTFMove(reference));
         if (!sample)
             return nullptr;
         ASSERT(sample->pixelBuffer());
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to