Diff
Modified: trunk/LayoutTests/ChangeLog (289380 => 289381)
--- trunk/LayoutTests/ChangeLog 2022-02-08 17:03:38 UTC (rev 289380)
+++ trunk/LayoutTests/ChangeLog 2022-02-08 17:14:48 UTC (rev 289381)
@@ -1,3 +1,14 @@
+2022-02-08 Youenn Fablet <[email protected]>
+
+ LibWebRTCCodecs SharedVideoFrameWriters can deadlock in case of GPUProcess crash
+ https://bugs.webkit.org/show_bug.cgi?id=236132
+
+ Reviewed by Eric Carlson.
+
+ * platform/gtk/TestExpectations: Skip test as it is crashing in GTK bot.
+ * webrtc/vp8-then-h264-gpu-process-crash-expected.txt: Added.
+ * webrtc/vp8-then-h264-gpu-process-crash.html: Added.
+
2022-02-08 Jon Lee <[email protected]>
Enable GPU Process for WebGL by default on iOS
Modified: trunk/LayoutTests/platform/gtk/TestExpectations (289380 => 289381)
--- trunk/LayoutTests/platform/gtk/TestExpectations 2022-02-08 17:03:38 UTC (rev 289380)
+++ trunk/LayoutTests/platform/gtk/TestExpectations 2022-02-08 17:14:48 UTC (rev 289381)
@@ -217,6 +217,9 @@
webkit.org/b/208988 imported/w3c/web-platform-tests/webxr [ Skip ]
webkit.org/b/208988 webxr [ Skip ]
+# Crash on EWS bot.
+webrtc/vp8-then-h264-gpu-process-crash.html [ Skip ]
+
#//////////////////////////////////////////////////////////////////////////////////////////
# End of Triaged Expectations
# Legacy Expectations sections below
Added: trunk/LayoutTests/webrtc/vp8-then-h264-gpu-process-crash-expected.txt (0 => 289381)
--- trunk/LayoutTests/webrtc/vp8-then-h264-gpu-process-crash-expected.txt (rev 0)
+++ trunk/LayoutTests/webrtc/vp8-then-h264-gpu-process-crash-expected.txt 2022-02-08 17:14:48 UTC (rev 289381)
@@ -0,0 +1,6 @@
+
+
+PASS Setting video exchange with VP8
+PASS Setting exchange with H264 using VP8 decoded stream as input
+PASS Frames should be coming even after gpu process crash
+
Added: trunk/LayoutTests/webrtc/vp8-then-h264-gpu-process-crash.html (0 => 289381)
--- trunk/LayoutTests/webrtc/vp8-then-h264-gpu-process-crash.html (rev 0)
+++ trunk/LayoutTests/webrtc/vp8-then-h264-gpu-process-crash.html 2022-02-08 17:14:48 UTC (rev 289381)
@@ -0,0 +1,94 @@
+<!doctype html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Testing GPU process crash</title>
+ <script src=""
+ <script src=""
+ </head>
+ <body>
+ <video id="video1" autoplay playsInline width="320" height="240"></video>
+ <video id="video2" autoplay playsInline width="320" height="240"></video>
+ <script src =""
+ <script>
+var receivingConnection;
+promise_test((test) => {
+ return navigator.mediaDevices.getUserMedia({video: true}).then((localStream) => {
+ return new Promise((resolve, reject) => {
+ track = localStream.getVideoTracks()[0];
+
+ createConnections((firstConnection) => {
+ firstConnection.addTrack(track, localStream);
+ firstConnection.getTransceivers()[0].setCodecPreferences([{mimeType: "video/VP8", clockRate: 90000}]);
+ }, (secondConnection) => {
+ receivingConnection = secondConnection;
+ secondConnection._ontrack_ = (trackEvent) => {
+ remoteTrack = trackEvent.track;
+ resolve(trackEvent.streams[0]);
+ };
+ });
+ setTimeout(() => reject("Test timed out"), 5000);
+ });
+ }).then((remoteStream) => {
+ video1.srcObject = remoteStream;
+ return video1.play();
+ });
+}, "Setting video exchange with VP8");
+
+promise_test(async () => {
+ video2.srcObject = await new Promise((resolve, reject) => {
+ createConnections((firstConnection) => {
+ firstConnection.addTrack(video1.srcObject.getVideoTracks()[0], video1.srcObject);
+ }, (secondConnection) => {
+ receivingConnection = secondConnection;
+ secondConnection._ontrack_ = (trackEvent) => {
+ remoteTrack = trackEvent.track;
+ resolve(trackEvent.streams[0]);
+ };
+ });
+ setTimeout(() => reject("Test timed out"), 5000);
+ });
+ await video2.play();
+}, "Setting exchange with H264 using VP8 decoded stream as input");
+
+async function getInboundRTPStatsNumberOfDecodedFrames(connection)
+{
+ var report = await connection.getStats();
+ var framesDecoded;
+ report.forEach((statItem) => {
+ if (statItem.type === "inbound-rtp")
+ framesDecoded = statItem.framesDecoded;
+ });
+ return framesDecoded;
+}
+
+async function testFrameDecodedIncreased(connection, count, previousFramesNumber)
+{
+ if (previousFramesNumber === undefined) {
+ let number = await getInboundRTPStatsNumberOfDecodedFrames(connection);
+ await waitFor(1000);
+ return testFrameDecodedIncreased(connection, 0, number);
+ }
+
+ var number = await getInboundRTPStatsNumberOfDecodedFrames(connection);
+ if (previousFramesNumber && number > previousFramesNumber)
+ return;
+
+ if (count >= 20)
+ return Promise.reject("test increasing frame decoded timed out");
+
+ await waitFor(1000);
+ return testFrameDecodedIncreased(connection, ++count, previousFramesNumber);
+}
+
+
+promise_test(async (test) => {
+ await testFrameDecodedIncreased(receivingConnection);
+ if (window.testRunner)
+ testRunner.terminateGPUProcess();
+ await new Promise(resolve => setTimeout(resolve, 1000));
+ await testFrameDecodedIncreased(receivingConnection);
+}, "Frames should be coming even after gpu process crash");
+ </script>
+ </body>
+</html>
Modified: trunk/Source/WebKit/ChangeLog (289380 => 289381)
--- trunk/Source/WebKit/ChangeLog 2022-02-08 17:03:38 UTC (rev 289380)
+++ trunk/Source/WebKit/ChangeLog 2022-02-08 17:14:48 UTC (rev 289381)
@@ -1,3 +1,29 @@
+2022-02-08 Youenn Fablet <[email protected]>
+
+ LibWebRTCCodecs SharedVideoFrameWriters can deadlock in case of GPUProcess crash
+ https://bugs.webkit.org/show_bug.cgi?id=236132
+
+ Reviewed by Eric Carlson.
+
+ When sending sampels through SharedVideoFrameWriters, we might lock on a binary semaphore controlled by GPUProcess.
+ It is not always the case that the semaphore will unblock in case of GPUProcess crash for instance.
+ To prevent this, whenever we detect a GPUProcess crash, we disable SharedVideoFrameWriters, which has the effect of
+ disabling semaphore wait for future call and unlocking any current wait by calling semaphore.signal.
+ Then, the SharedVideoFrameWriter is recreated as needed by owner classes such as LibWebRTCCodecs or SampleBufferDisplayLayer.
+
+ In the case of LibWebRTCCodecs, we further reduce locking cases by introducing a lock dedicated to encoders.
+ Previously, the lock for encoders was also encompassing the codecs connection and the decoders.
+
+ Test: webrtc/vp8-then-h264-gpu-process-crash.html
+
+ * WebProcess/GPU/webrtc/LibWebRTCCodecs.cpp:
+ * WebProcess/GPU/webrtc/LibWebRTCCodecs.h:
+ * WebProcess/GPU/webrtc/MediaRecorderPrivate.cpp:
+ * WebProcess/GPU/webrtc/MediaRecorderPrivate.h:
+ * WebProcess/GPU/webrtc/SampleBufferDisplayLayer.cpp:
+ * WebProcess/GPU/webrtc/SharedVideoFrame.cpp:
+ * WebProcess/GPU/webrtc/SharedVideoFrame.h:
+
2022-02-08 Alex Christensen <[email protected]>
Reduce allocations and increase thread safety of constructedPath
Modified: trunk/Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.cpp (289380 => 289381)
--- trunk/Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.cpp 2022-02-08 17:03:38 UTC (rev 289380)
+++ trunk/Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.cpp 2022-02-08 17:14:48 UTC (rev 289381)
@@ -379,11 +379,15 @@
parameters.append(std::make_pair(String::fromUTF8(keyValue.first.data(), keyValue.first.length()), String::fromUTF8(keyValue.second.data(), keyValue.second.length())));
ensureGPUProcessConnectionAndDispatchToThread([this, encoder = WTFMove(encoder), type, parameters = WTFMove(parameters)]() mutable {
- Locker locker { m_connectionLock };
- encoder->connection = m_connection;
+ {
+ Locker locker { m_connectionLock };
+ encoder->connection = m_connection;
+ }
+
encoder->connection->send(Messages::LibWebRTCCodecsProxy::CreateEncoder { encoder->identifier, formatNameFromCodecType(type), parameters, RuntimeEnabledFeatures::sharedFeatures().webRTCH264LowLatencyEncoderEnabled() }, 0);
encoder->parameters = WTFMove(parameters);
+ Locker locker { m_encodersLock };
auto encoderIdentifier = encoder->identifier;
ASSERT(!m_encoders.contains(encoderIdentifier));
m_encoders.add(encoderIdentifier, WTFMove(encoder));
@@ -400,6 +404,7 @@
}
#endif
ensureGPUProcessConnectionAndDispatchToThread([this, encoderIdentifier = encoder.identifier] {
+ Locker locker { m_encodersLock };
ASSERT(m_encoders.contains(encoderIdentifier));
auto encoder = m_encoders.take(encoderIdentifier);
encoder->connection->send(Messages::LibWebRTCCodecsProxy::ReleaseEncoder { encoderIdentifier }, 0);
@@ -418,26 +423,18 @@
return 0;
}
-bool LibWebRTCCodecs::copySharedVideoFrame(Encoder& encoder, CVPixelBufferRef pixelBuffer)
+template<typename Buffer>
+bool copySharedVideoFrame(LibWebRTCCodecs::Encoder& encoder, Buffer&& frameBuffer)
{
- return encoder.sharedVideoFrameWriter.write(pixelBuffer,
- [&encoder](auto& semaphore) { encoder.connection->send(Messages::LibWebRTCCodecsProxy::SetSharedVideoFrameSemaphore { encoder.identifier, semaphore }, 0); },
- [&encoder](auto& handle) { encoder.connection->send(Messages::LibWebRTCCodecsProxy::SetSharedVideoFrameMemory { encoder.identifier, handle }, 0); }
+ return encoder.sharedVideoFrameWriter.write(frameBuffer,
+ [&](auto& semaphore) { encoder.connection->send(Messages::LibWebRTCCodecsProxy::SetSharedVideoFrameSemaphore { encoder.identifier, semaphore }, 0); },
+ [&](auto& handle) { encoder.connection->send(Messages::LibWebRTCCodecsProxy::SetSharedVideoFrameMemory { encoder.identifier, handle }, 0); }
);
}
-bool LibWebRTCCodecs::copySharedVideoFrame(Encoder& encoder, const webrtc::VideoFrame& frame)
-{
- return encoder.sharedVideoFrameWriter.write(frame,
- [&encoder](auto& semaphore) { encoder.connection->send(Messages::LibWebRTCCodecsProxy::SetSharedVideoFrameSemaphore { encoder.identifier, semaphore }, 0); },
- [&encoder](auto& handle) { encoder.connection->send(Messages::LibWebRTCCodecsProxy::SetSharedVideoFrameMemory { encoder.identifier, handle }, 0); }
- );
-}
-
int32_t LibWebRTCCodecs::encodeFrame(Encoder& encoder, const webrtc::VideoFrame& frame, bool shouldEncodeAsKeyFrame)
{
- Locker locker { m_connectionLock };
-
+ Locker locker { m_encodersLock };
if (!encoder.connection)
return WEBRTC_VIDEO_CODEC_ERROR;
@@ -467,7 +464,7 @@
void LibWebRTCCodecs::setEncodeRates(Encoder& encoder, uint32_t bitRate, uint32_t frameRate)
{
- Locker locker { m_connectionLock };
+ Locker locker { m_encodersLock };
if (!encoder.connection) {
callOnMainRunLoop([encoderIdentifier = encoder.identifier, bitRate, frameRate] {
@@ -527,21 +524,24 @@
return;
ensureGPUProcessConnectionOnMainThreadWithLock();
- dispatchToThread([this]() {
- // Lock everything so that we can update encoder/decoder connection.
- Locker locker { m_connectionLock };
- // Recreate encoders and initialize them, recreate decoders.
+ dispatchToThread([this, connection = m_connection]() {
+ for (auto& decoder : m_decoders.values()) {
+ createRemoteDecoder(*decoder, *connection);
+ decoder->connection = connection.get();
+ }
+
+ // In case we are waiting for GPUProcess, let's end the wait to not deadlock.
+ for (auto& encoder : m_encoders.values())
+ encoder->sharedVideoFrameWriter.disable();
+
+ Locker locker { m_encodersLock };
for (auto& encoder : m_encoders.values()) {
- m_connection->send(Messages::LibWebRTCCodecsProxy::CreateEncoder { encoder->identifier, formatNameFromWebRTCCodecType(encoder->codecType), encoder->parameters, RuntimeEnabledFeatures::sharedFeatures().webRTCH264LowLatencyEncoderEnabled() }, 0);
+ connection->send(Messages::LibWebRTCCodecsProxy::CreateEncoder { encoder->identifier, formatNameFromWebRTCCodecType(encoder->codecType), encoder->parameters, RuntimeEnabledFeatures::sharedFeatures().webRTCH264LowLatencyEncoderEnabled() }, 0);
if (encoder->initializationData)
- m_connection->send(Messages::LibWebRTCCodecsProxy::InitializeEncoder { encoder->identifier, encoder->initializationData->width, encoder->initializationData->height, encoder->initializationData->startBitRate, encoder->initializationData->maxBitRate, encoder->initializationData->minBitRate, encoder->initializationData->maxFrameRate }, 0);
+ connection->send(Messages::LibWebRTCCodecsProxy::InitializeEncoder { encoder->identifier, encoder->initializationData->width, encoder->initializationData->height, encoder->initializationData->startBitRate, encoder->initializationData->maxBitRate, encoder->initializationData->minBitRate, encoder->initializationData->maxFrameRate }, 0);
+ encoder->connection = connection.get();
encoder->sharedVideoFrameWriter = { };
- encoder->connection = m_connection.get();
}
- for (auto& decoder : m_decoders.values()) {
- createRemoteDecoder(*decoder, *m_connection);
- decoder->connection = m_connection.get();
- }
});
}
Modified: trunk/Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.h (289380 => 289381)
--- trunk/Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.h 2022-02-08 17:03:38 UTC (rev 289380)
+++ trunk/Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.h 2022-02-08 17:14:48 UTC (rev 289381)
@@ -138,13 +138,11 @@
// GPUProcessConnection::Client
void gpuProcessConnectionDidClose(GPUProcessConnection&);
- bool copySharedVideoFrame(Encoder&, CVPixelBufferRef);
- bool copySharedVideoFrame(Encoder&, const webrtc::VideoFrame&);
-
private:
HashMap<RTCDecoderIdentifier, std::unique_ptr<Decoder>> m_decoders;
HashSet<RTCDecoderIdentifier> m_decodingErrors;
+ Lock m_encodersLock;
HashMap<RTCEncoderIdentifier, std::unique_ptr<Encoder>> m_encoders;
std::atomic<bool> m_needsGPUProcessConnection;
Modified: trunk/Source/WebKit/WebProcess/GPU/webrtc/MediaRecorderPrivate.cpp (289380 => 289381)
--- trunk/Source/WebKit/WebProcess/GPU/webrtc/MediaRecorderPrivate.cpp 2022-02-08 17:03:38 UTC (rev 289380)
+++ trunk/Source/WebKit/WebProcess/GPU/webrtc/MediaRecorderPrivate.cpp 2022-02-08 17:14:48 UTC (rev 289381)
@@ -54,6 +54,7 @@
, m_options(options)
, m_hasVideo(stream.hasVideo())
{
+ WebProcess::singleton().ensureGPUProcessConnection().addClient(*this);
}
void MediaRecorderPrivate::startRecording(StartRecordingCallback&& callback)
@@ -87,6 +88,7 @@
MediaRecorderPrivate::~MediaRecorderPrivate()
{
m_connection->send(Messages::RemoteMediaRecorderManager::ReleaseRecorder { m_identifier }, 0);
+ WebProcess::singleton().ensureGPUProcessConnection().removeClient(*this);
}
void MediaRecorderPrivate::videoSampleAvailable(MediaSample& sample, VideoSampleMetadata)
@@ -176,6 +178,7 @@
void MediaRecorderPrivate::fetchData(CompletionHandler<void(RefPtr<WebCore::FragmentedSharedBuffer>&&, const String& mimeType, double)>&& completionHandler)
{
m_connection->sendWithAsyncReply(Messages::RemoteMediaRecorder::FetchData { }, [completionHandler = WTFMove(completionHandler), mimeType = mimeType()](auto&& data, double timeCode) mutable {
+ // FIXME: If completion handler is called following a GPUProcess connection being closed, we should fail the MediaRecorder.
RefPtr<FragmentedSharedBuffer> buffer;
if (data.size())
buffer = SharedBuffer::create(data.data(), data.size());
@@ -206,6 +209,11 @@
return m_hasVideo ? videoMP4 : audioMP4;
}
+void MediaRecorderPrivate::gpuProcessConnectionDidClose(GPUProcessConnection&)
+{
+ m_sharedVideoFrameWriter.disable();
}
+}
+
#endif // PLATFORM(COCOA) && ENABLE(GPU_PROCESS) && ENABLE(MEDIA_STREAM)
Modified: trunk/Source/WebKit/WebProcess/GPU/webrtc/MediaRecorderPrivate.h (289380 => 289381)
--- trunk/Source/WebKit/WebProcess/GPU/webrtc/MediaRecorderPrivate.h 2022-02-08 17:03:38 UTC (rev 289380)
+++ trunk/Source/WebKit/WebProcess/GPU/webrtc/MediaRecorderPrivate.h 2022-02-08 17:14:48 UTC (rev 289381)
@@ -48,7 +48,7 @@
class MediaRecorderPrivate final
: public WebCore::MediaRecorderPrivate
- , public CanMakeWeakPtr<MediaRecorderPrivate> {
+ , public GPUProcessConnection::Client {
WTF_MAKE_FAST_ALLOCATED;
public:
MediaRecorderPrivate(WebCore::MediaStreamPrivate&, const WebCore::MediaRecorderPrivateOptions&);
@@ -65,6 +65,9 @@
void pauseRecording(CompletionHandler<void()>&&) final;
void resumeRecording(CompletionHandler<void()>&&) final;
+ // GPUProcessConnection::Client
+ void gpuProcessConnectionDidClose(GPUProcessConnection&) final;
+
void storageChanged(SharedMemory*, const WebCore::CAAudioStreamDescription& format, size_t frameCount);
bool copySharedVideoFrame(CVPixelBufferRef);
Modified: trunk/Source/WebKit/WebProcess/GPU/webrtc/SampleBufferDisplayLayer.cpp (289380 => 289381)
--- trunk/Source/WebKit/WebProcess/GPU/webrtc/SampleBufferDisplayLayer.cpp 2022-02-08 17:03:38 UTC (rev 289380)
+++ trunk/Source/WebKit/WebProcess/GPU/webrtc/SampleBufferDisplayLayer.cpp 2022-02-08 17:14:48 UTC (rev 289381)
@@ -170,6 +170,7 @@
void SampleBufferDisplayLayer::gpuProcessConnectionDidClose(GPUProcessConnection&)
{
+ m_sharedVideoFrameWriter.disable();
m_didFail = true;
if (m_client)
m_client->sampleBufferDisplayLayerStatusDidFail();
Modified: trunk/Source/WebKit/WebProcess/GPU/webrtc/SharedVideoFrame.cpp (289380 => 289381)
--- trunk/Source/WebKit/WebProcess/GPU/webrtc/SharedVideoFrame.cpp 2022-02-08 17:03:38 UTC (rev 289380)
+++ trunk/Source/WebKit/WebProcess/GPU/webrtc/SharedVideoFrame.cpp 2022-02-08 17:14:48 UTC (rev 289381)
@@ -35,14 +35,19 @@
namespace WebKit {
using namespace WebCore;
+SharedVideoFrameWriter::SharedVideoFrameWriter()
+ : m_semaphore(makeUniqueRef<IPC::Semaphore>())
+{
+}
+
bool SharedVideoFrameWriter::wait(const Function<void(IPC::Semaphore&)>& newSemaphoreCallback)
{
- if (!m_semaphore) {
- m_semaphore = makeUnique<IPC::Semaphore>();
- newSemaphoreCallback(*m_semaphore);
+ if (!m_isSemaphoreInUse) {
+ m_isSemaphoreInUse = true;
+ newSemaphoreCallback(m_semaphore.get());
return true;
}
- return m_semaphore->wait();
+ return !m_isDisabled && m_semaphore->wait();
}
bool SharedVideoFrameWriter::allocateStorage(size_t size, const Function<void(const SharedMemory::IPCHandle&)>& newMemoryCallback)
@@ -95,6 +100,12 @@
}
#endif
+void SharedVideoFrameWriter::disable()
+{
+ m_isDisabled = true;
+ m_semaphore->signal();
+}
+
RetainPtr<CVPixelBufferRef> SharedVideoFrameReader::read()
{
if (!m_storage)
Modified: trunk/Source/WebKit/WebProcess/GPU/webrtc/SharedVideoFrame.h (289380 => 289381)
--- trunk/Source/WebKit/WebProcess/GPU/webrtc/SharedVideoFrame.h 2022-02-08 17:03:38 UTC (rev 289380)
+++ trunk/Source/WebKit/WebProcess/GPU/webrtc/SharedVideoFrame.h 2022-02-08 17:14:48 UTC (rev 289381)
@@ -31,6 +31,7 @@
#include "SharedMemory.h"
#include <wtf/RefPtr.h>
#include <wtf/RetainPtr.h>
+#include <wtf/UniqueRef.h>
typedef struct __CVBuffer* CVPixelBufferRef;
typedef struct __CVPixelBufferPool* CVPixelBufferPoolRef;
@@ -48,12 +49,13 @@
class SharedVideoFrameWriter {
WTF_MAKE_FAST_ALLOCATED;
public:
- SharedVideoFrameWriter() = default;
+ SharedVideoFrameWriter();
bool write(CVPixelBufferRef, const Function<void(IPC::Semaphore&)>&, const Function<void(const SharedMemory::IPCHandle&)>&);
#if USE(LIBWEBRTC)
bool write(const webrtc::VideoFrame&, const Function<void(IPC::Semaphore&)>&, const Function<void(const SharedMemory::IPCHandle&)>&);
#endif
+ void disable();
private:
bool wait(const Function<void(IPC::Semaphore&)>&);
@@ -60,8 +62,10 @@
bool allocateStorage(size_t, const Function<void(const SharedMemory::IPCHandle&)>&);
bool prepareWriting(const WebCore::SharedVideoFrameInfo&, const Function<void(IPC::Semaphore&)>&, const Function<void(const SharedMemory::IPCHandle&)>&);
- std::unique_ptr<IPC::Semaphore> m_semaphore;
+ UniqueRef<IPC::Semaphore> m_semaphore;
RefPtr<SharedMemory> m_storage;
+ bool m_isSemaphoreInUse { false };
+ bool m_isDisabled { false };
};
class SharedVideoFrameReader {