Diff
Modified: trunk/Source/WebKit/ChangeLog (292460 => 292461)
--- trunk/Source/WebKit/ChangeLog 2022-04-06 12:36:55 UTC (rev 292460)
+++ trunk/Source/WebKit/ChangeLog 2022-04-06 13:29:47 UTC (rev 292461)
@@ -1,3 +1,39 @@
+2022-04-06 Kimmo Kinnunen <kkinnu...@apple.com>
+
+ Media and WebRTC code uses ThreadMessageReceiverRefCounted with WorkQueues
+ https://bugs.webkit.org/show_bug.cgi?id=238858
+
+ Reviewed by Youenn Fablet.
+
+ Media and WebRTC code uses IPC::Connection::ThreadMessageReceiverRefCounted
+ to submit work to a WorkQueue. For this use-case, IPC::Connection has
+ IPC::Connection::WorkQueueMessageReceiver, which does the same.
+
+ This is work towards simplifying IPC::Connection by removing
+ ThreadMessageReceiverRefCounted.
+
+ No new tests, refactor.
+
+ * GPUProcess/webrtc/LibWebRTCCodecsProxy.h:
+ * GPUProcess/webrtc/LibWebRTCCodecsProxy.mm:
+ (WebKit::LibWebRTCCodecsProxy::stopListeningForIPC):
+ (WebKit::LibWebRTCCodecsProxy::initialize):
+ * GPUProcess/webrtc/RemoteSampleBufferDisplayLayerManager.cpp:
+ (WebKit::RemoteSampleBufferDisplayLayerManager::startListeningForIPC):
+ (WebKit::RemoteSampleBufferDisplayLayerManager::close):
+ (WebKit::RemoteSampleBufferDisplayLayerManager::createLayer):
+ (WebKit::RemoteSampleBufferDisplayLayerManager::releaseLayer):
+ * GPUProcess/webrtc/RemoteSampleBufferDisplayLayerManager.h:
+ * WebProcess/GPU/webrtc/LibWebRTCCodecs.cpp:
+ (WebKit::LibWebRTCCodecs::ensureGPUProcessConnectionOnMainThreadWithLock):
+ (WebKit::LibWebRTCCodecs::ensureGPUProcessConnectionAndDispatchToThread):
+ (WebKit::LibWebRTCCodecs::gpuProcessConnectionDidClose):
+ * WebProcess/GPU/webrtc/LibWebRTCCodecs.h:
+ * WebProcess/cocoa/RemoteCaptureSampleManager.cpp:
+ (WebKit::RemoteCaptureSampleManager::stopListeningForIPC):
+ (WebKit::RemoteCaptureSampleManager::setConnection):
+ * WebProcess/cocoa/RemoteCaptureSampleManager.h:
+
2022-04-06 Carlos Garcia Campos <cgar...@igalia.com>
Unreviewed. Fix GTK build after r292458
Modified: trunk/Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.h (292460 => 292461)
--- trunk/Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.h 2022-04-06 12:36:55 UTC (rev 292460)
+++ trunk/Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.h 2022-04-06 13:29:47 UTC (rev 292461)
@@ -56,7 +56,7 @@
struct SharedVideoFrame;
class SharedVideoFrameReader;
-class LibWebRTCCodecsProxy final : public IPC::Connection::ThreadMessageReceiverRefCounted {
+class LibWebRTCCodecsProxy final : public IPC::Connection::WorkQueueMessageReceiver {
WTF_MAKE_FAST_ALLOCATED;
public:
static Ref<LibWebRTCCodecsProxy> create(GPUConnectionToWebProcess&);
@@ -70,11 +70,9 @@
auto createDecoderCallback(RTCDecoderIdentifier, bool useRemoteFrames);
WorkQueue& workQueue() const { return m_queue; }
- // IPC::Connection::ThreadMessageReceiver
- void dispatchToThread(Function<void()>&&) final;
+ // IPC::Connection::WorkQueueMessageReceiver overrides.
+ void didReceiveMessage(IPC::Connection&, IPC::Decoder&) final;
- // IPC::MessageReceiver
- void didReceiveMessage(IPC::Connection&, IPC::Decoder&) final;
void createH264Decoder(RTCDecoderIdentifier, bool useRemoteFrames);
void createH265Decoder(RTCDecoderIdentifier, bool useRemoteFrames);
void createVP9Decoder(RTCDecoderIdentifier, bool useRemoteFrames);
Modified: trunk/Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.mm (292460 => 292461)
--- trunk/Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.mm 2022-04-06 12:36:55 UTC (rev 292460)
+++ trunk/Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.mm 2022-04-06 13:29:47 UTC (rev 292461)
@@ -68,9 +68,9 @@
void LibWebRTCCodecsProxy::stopListeningForIPC(Ref<LibWebRTCCodecsProxy>&& refFromConnection)
{
- m_connection->removeThreadMessageReceiver(Messages::LibWebRTCCodecsProxy::messageReceiverName());
+ m_connection->removeWorkQueueMessageReceiver(Messages::LibWebRTCCodecsProxy::messageReceiverName());
- dispatchToThread([this, protectedThis = WTFMove(refFromConnection)] {
+ m_queue->dispatch([this, protectedThis = WTFMove(refFromConnection)] {
assertIsCurrent(workQueue());
auto decoders = WTFMove(m_decoders);
for (auto decoder : decoders.values())
@@ -83,14 +83,9 @@
void LibWebRTCCodecsProxy::initialize()
{
- m_connection->addThreadMessageReceiver(Messages::LibWebRTCCodecsProxy::messageReceiverName(), this);
+ m_connection->addWorkQueueMessageReceiver(Messages::LibWebRTCCodecsProxy::messageReceiverName(), m_queue, *this);
}
-void LibWebRTCCodecsProxy::dispatchToThread(Function<void()>&& function)
-{
- m_queue->dispatch(WTFMove(function));
-}
-
auto LibWebRTCCodecsProxy::createDecoderCallback(RTCDecoderIdentifier identifier, bool useRemoteFrames)
{
RefPtr<RemoteVideoFrameObjectHeap> videoFrameObjectHeap;
Modified: trunk/Source/WebKit/GPUProcess/webrtc/RemoteSampleBufferDisplayLayerManager.cpp (292460 => 292461)
--- trunk/Source/WebKit/GPUProcess/webrtc/RemoteSampleBufferDisplayLayerManager.cpp 2022-04-06 12:36:55 UTC (rev 292460)
+++ trunk/Source/WebKit/GPUProcess/webrtc/RemoteSampleBufferDisplayLayerManager.cpp 2022-04-06 13:29:47 UTC (rev 292461)
@@ -47,8 +47,8 @@
void RemoteSampleBufferDisplayLayerManager::startListeningForIPC()
{
- m_connectionToWebProcess.connection().addThreadMessageReceiver(Messages::RemoteSampleBufferDisplayLayer::messageReceiverName(), this);
- m_connectionToWebProcess.connection().addThreadMessageReceiver(Messages::RemoteSampleBufferDisplayLayerManager::messageReceiverName(), this);
+ m_connectionToWebProcess.connection().addWorkQueueMessageReceiver(Messages::RemoteSampleBufferDisplayLayer::messageReceiverName(), m_queue, *this);
+ m_connectionToWebProcess.connection().addWorkQueueMessageReceiver(Messages::RemoteSampleBufferDisplayLayerManager::messageReceiverName(), m_queue, *this);
}
RemoteSampleBufferDisplayLayerManager::~RemoteSampleBufferDisplayLayerManager() = default;
@@ -55,18 +55,13 @@
void RemoteSampleBufferDisplayLayerManager::close()
{
- m_connectionToWebProcess.connection().removeThreadMessageReceiver(Messages::RemoteSampleBufferDisplayLayer::messageReceiverName());
- m_connectionToWebProcess.connection().removeThreadMessageReceiver(Messages::RemoteSampleBufferDisplayLayerManager::messageReceiverName());
- dispatchToThread([this, protectedThis = Ref { *this }] {
+ m_connectionToWebProcess.connection().removeWorkQueueMessageReceiver(Messages::RemoteSampleBufferDisplayLayer::messageReceiverName());
+ m_connectionToWebProcess.connection().removeWorkQueueMessageReceiver(Messages::RemoteSampleBufferDisplayLayerManager::messageReceiverName());
+ m_queue->dispatch([this, protectedThis = Ref { *this }] {
callOnMainRunLoop([layers = WTFMove(m_layers)] { });
});
}
-void RemoteSampleBufferDisplayLayerManager::dispatchToThread(Function<void()>&& callback)
-{
- m_queue->dispatch(WTFMove(callback));
-}
-
bool RemoteSampleBufferDisplayLayerManager::dispatchMessage(IPC::Connection& connection, IPC::Decoder& decoder)
{
if (!decoder.destinationID())
@@ -84,7 +79,7 @@
auto layer = RemoteSampleBufferDisplayLayer::create(m_connectionToWebProcess, identifier, m_connection.copyRef());
auto& layerReference = *layer;
layerReference.initialize(hideRootLayer, size, [this, protectedThis = Ref { *this }, callback = WTFMove(callback), identifier, layer = WTFMove(layer)](auto layerId) mutable {
- dispatchToThread([this, protectedThis = WTFMove(protectedThis), callback = WTFMove(callback), identifier, layer = WTFMove(layer), layerId = WTFMove(layerId)]() mutable {
+ m_queue->dispatch([this, protectedThis = WTFMove(protectedThis), callback = WTFMove(callback), identifier, layer = WTFMove(layer), layerId = WTFMove(layerId)]() mutable {
ASSERT(!m_layers.contains(identifier));
m_layers.add(identifier, WTFMove(layer));
callback(WTFMove(layerId));
@@ -96,7 +91,7 @@
void RemoteSampleBufferDisplayLayerManager::releaseLayer(SampleBufferDisplayLayerIdentifier identifier)
{
callOnMainRunLoop([this, protectedThis = Ref { *this }, identifier]() mutable {
- dispatchToThread([this, protectedThis = WTFMove(protectedThis), identifier] {
+ m_queue->dispatch([this, protectedThis = WTFMove(protectedThis), identifier] {
ASSERT(m_layers.contains(identifier));
callOnMainRunLoop([layer = m_layers.take(identifier)] { });
});
Modified: trunk/Source/WebKit/GPUProcess/webrtc/RemoteSampleBufferDisplayLayerManager.h (292460 => 292461)
--- trunk/Source/WebKit/GPUProcess/webrtc/RemoteSampleBufferDisplayLayerManager.h 2022-04-06 12:36:55 UTC (rev 292460)
+++ trunk/Source/WebKit/GPUProcess/webrtc/RemoteSampleBufferDisplayLayerManager.h 2022-04-06 13:29:47 UTC (rev 292461)
@@ -46,7 +46,7 @@
class GPUConnectionToWebProcess;
class RemoteSampleBufferDisplayLayer;
-class RemoteSampleBufferDisplayLayerManager final : public IPC::Connection::ThreadMessageReceiverRefCounted {
+class RemoteSampleBufferDisplayLayerManager final : public IPC::Connection::WorkQueueMessageReceiver {
WTF_MAKE_FAST_ALLOCATED;
public:
static Ref<RemoteSampleBufferDisplayLayerManager> create(GPUConnectionToWebProcess& connection)
@@ -65,11 +65,9 @@
explicit RemoteSampleBufferDisplayLayerManager(GPUConnectionToWebProcess&);
void startListeningForIPC();
- // IPC::Connection::ThreadMessageReceiver
- void dispatchToThread(Function<void()>&&) final;
+ // IPC::Connection::WorkQueueMessageReceiver overrides.
+ void didReceiveMessage(IPC::Connection&, IPC::Decoder&) final;
- // IPC::MessageReceiver
- void didReceiveMessage(IPC::Connection&, IPC::Decoder&) final;
bool dispatchMessage(IPC::Connection&, IPC::Decoder&);
using LayerCreationCallback = CompletionHandler<void(std::optional<LayerHostingContextID>)>&&;
Modified: trunk/Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.cpp (292460 => 292461)
--- trunk/Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.cpp 2022-04-06 12:36:55 UTC (rev 292460)
+++ trunk/Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.cpp 2022-04-06 13:29:47 UTC (rev 292461)
@@ -186,7 +186,7 @@
gpuConnection.addClient(*this);
m_connection = &gpuConnection.connection();
m_videoFrameObjectHeapProxy = &gpuConnection.videoFrameObjectHeapProxy();
- m_connection->addThreadMessageReceiver(Messages::LibWebRTCCodecs::messageReceiverName(), this);
+ m_connection->addWorkQueueMessageReceiver(Messages::LibWebRTCCodecs::messageReceiverName(), m_queue, *this);
if (m_loggingLevel)
m_connection->send(Messages::LibWebRTCCodecsProxy::SetRTCLoggingLevel { *m_loggingLevel }, 0);
@@ -201,7 +201,7 @@
// Fast path when we already have a connection.
if (m_connection) {
- dispatchToThread(WTFMove(task));
+ m_queue->dispatch(WTFMove(task));
return;
}
@@ -214,7 +214,7 @@
Locker locker { m_connectionLock };
ensureGPUProcessConnectionOnMainThreadWithLock();
for (auto& task : std::exchange(m_tasksToDispatchAfterEstablishingConnection, { }))
- dispatchToThread(WTFMove(task));
+ m_queue->dispatch(WTFMove(task));
});
}
@@ -568,22 +568,17 @@
return m_pixelBufferPool.get();
}
-void LibWebRTCCodecs::dispatchToThread(Function<void()>&& callback)
-{
- m_queue->dispatch(WTFMove(callback));
-}
-
void LibWebRTCCodecs::gpuProcessConnectionDidClose(GPUProcessConnection&)
{
ASSERT(isMainRunLoop());
Locker locker { m_connectionLock };
- std::exchange(m_connection, nullptr)->removeThreadMessageReceiver(Messages::LibWebRTCCodecs::messageReceiverName());
+ std::exchange(m_connection, nullptr)->removeWorkQueueMessageReceiver(Messages::LibWebRTCCodecs::messageReceiverName());
if (!m_needsGPUProcessConnection)
return;
ensureGPUProcessConnectionOnMainThreadWithLock();
- dispatchToThread([this, connection = m_connection]() {
+ m_queue->dispatch([this, connection = m_connection]() {
assertIsCurrent(workQueue());
{
Locker locker { m_connectionLock };
Modified: trunk/Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.h (292460 => 292461)
--- trunk/Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.h 2022-04-06 12:36:55 UTC (rev 292460)
+++ trunk/Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.h 2022-04-06 13:29:47 UTC (rev 292461)
@@ -60,7 +60,7 @@
class RemoteVideoFrameObjectHeapProxy;
-class LibWebRTCCodecs : public IPC::Connection::ThreadMessageReceiverRefCounted, public GPUProcessConnection::Client {
+class LibWebRTCCodecs : public IPC::Connection::WorkQueueMessageReceiver, public GPUProcessConnection::Client {
WTF_MAKE_FAST_ALLOCATED;
public:
static Ref<LibWebRTCCodecs> create();
@@ -135,9 +135,6 @@
void completedEncoding(RTCEncoderIdentifier, IPC::DataReference&&, const webrtc::WebKitEncodedFrameInfo&);
RetainPtr<CVPixelBufferRef> convertToBGRA(CVPixelBufferRef);
- // IPC::Connection::ThreadMessageReceiver
- void dispatchToThread(Function<void()>&&) final;
-
// GPUProcessConnection::Client
void gpuProcessConnectionDidClose(GPUProcessConnection&);
Modified: trunk/Source/WebKit/WebProcess/cocoa/RemoteCaptureSampleManager.cpp (292460 => 292461)
--- trunk/Source/WebKit/WebProcess/cocoa/RemoteCaptureSampleManager.cpp 2022-04-06 12:36:55 UTC (rev 292460)
+++ trunk/Source/WebKit/WebProcess/cocoa/RemoteCaptureSampleManager.cpp 2022-04-06 13:29:47 UTC (rev 292461)
@@ -54,7 +54,7 @@
void RemoteCaptureSampleManager::stopListeningForIPC()
{
if (m_isRegisteredToParentProcessConnection)
- WebProcess::singleton().parentProcessConnection()->removeThreadMessageReceiver(Messages::RemoteCaptureSampleManager::messageReceiverName());
+ WebProcess::singleton().parentProcessConnection()->removeWorkQueueMessageReceiver(Messages::RemoteCaptureSampleManager::messageReceiverName());
setConnection(nullptr);
}
@@ -67,17 +67,17 @@
if (connection == parentConnection) {
if (!m_isRegisteredToParentProcessConnection) {
m_isRegisteredToParentProcessConnection = true;
- parentConnection->addThreadMessageReceiver(Messages::RemoteCaptureSampleManager::messageReceiverName(), this);
+ parentConnection->addWorkQueueMessageReceiver(Messages::RemoteCaptureSampleManager::messageReceiverName(), m_queue, *this);
}
return;
}
if (m_connection)
- m_connection->removeThreadMessageReceiver(Messages::RemoteCaptureSampleManager::messageReceiverName());
+ m_connection->removeWorkQueueMessageReceiver(Messages::RemoteCaptureSampleManager::messageReceiverName());
m_connection = WTFMove(connection);
if (m_connection)
- m_connection->addThreadMessageReceiver(Messages::RemoteCaptureSampleManager::messageReceiverName(), this);
+ m_connection->addWorkQueueMessageReceiver(Messages::RemoteCaptureSampleManager::messageReceiverName(), m_queue, *this);
}
void RemoteCaptureSampleManager::addSource(Ref<RemoteRealtimeAudioSource>&& source)
@@ -128,11 +128,6 @@
m_videoFrameObjectHeapProxy = proxy;
}
-void RemoteCaptureSampleManager::dispatchToThread(Function<void()>&& callback)
-{
- m_queue->dispatch(WTFMove(callback));
-}
-
void RemoteCaptureSampleManager::audioStorageChanged(WebCore::RealtimeMediaSourceIdentifier identifier, const SharedMemory::IPCHandle& ipcHandle, const WebCore::CAAudioStreamDescription& description, uint64_t numberOfFrames, IPC::Semaphore&& semaphore, const MediaTime& mediaTime, size_t frameChunkSize)
{
ASSERT(!WTF::isMainRunLoop());
Modified: trunk/Source/WebKit/WebProcess/cocoa/RemoteCaptureSampleManager.h (292460 => 292461)
--- trunk/Source/WebKit/WebProcess/cocoa/RemoteCaptureSampleManager.h 2022-04-06 12:36:55 UTC (rev 292460)
+++ trunk/Source/WebKit/WebProcess/cocoa/RemoteCaptureSampleManager.h 2022-04-06 13:29:47 UTC (rev 292461)
@@ -49,7 +49,7 @@
namespace WebKit {
class RemoteVideoFrameObjectHeapProxy;
-class RemoteCaptureSampleManager : public IPC::Connection::ThreadMessageReceiverRefCounted {
+class RemoteCaptureSampleManager : public IPC::Connection::WorkQueueMessageReceiver {
WTF_MAKE_FAST_ALLOCATED;
public:
RemoteCaptureSampleManager();
@@ -63,12 +63,10 @@
void didUpdateSourceConnection(IPC::Connection*);
void setVideoFrameObjectHeapProxy(RemoteVideoFrameObjectHeapProxy*);
+ // IPC::Connection::WorkQueueMessageReceiver overrides.
void didReceiveMessage(IPC::Connection&, IPC::Decoder&);
private:
- // IPC::Connection::ThreadMessageReceiver
- void dispatchToThread(Function<void()>&&) final;
-
// Messages
void audioStorageChanged(WebCore::RealtimeMediaSourceIdentifier, const SharedMemory::IPCHandle&, const WebCore::CAAudioStreamDescription&, uint64_t numberOfFrames, IPC::Semaphore&&, const MediaTime&, size_t frameSampleSize);
void audioSamplesAvailable(WebCore::RealtimeMediaSourceIdentifier, MediaTime, uint64_t numberOfFrames);