Modified: trunk/Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.h (276222 => 276223)
--- trunk/Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.h 2021-04-18 05:23:02 UTC (rev 276222)
+++ trunk/Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.h 2021-04-18 07:10:05 UTC (rev 276223)
@@ -82,14 +82,13 @@
void encodeFrame(RTCEncoderIdentifier, WebCore::RemoteVideoSample&&, uint32_t timeStamp, bool shouldEncodeAsKeyFrame);
void setEncodeRates(RTCEncoderIdentifier, uint32_t bitRate, uint32_t frameRate);
- void updateHasEncodersOrDecoders();
-
CFDictionaryRef ioSurfacePixelBufferCreationOptions(IOSurfaceRef);
GPUConnectionToWebProcess& m_gpuConnectionToWebProcess;
+
+ mutable Lock m_lock;
HashMap<RTCDecoderIdentifier, webrtc::LocalDecoder> m_decoders;
HashMap<RTCEncoderIdentifier, webrtc::LocalEncoder> m_encoders;
- std::atomic<bool> m_hasEncodersOrDecoders;
Ref<WorkQueue> m_queue;
std::unique_ptr<WebCore::ImageTransferSessionVT> m_imageTransferSession;
Modified: trunk/Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.mm (276222 => 276223)
--- trunk/Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.mm 2021-04-18 05:23:02 UTC (rev 276222)
+++ trunk/Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.mm 2021-04-18 07:10:05 UTC (rev 276223)
@@ -62,6 +62,7 @@
m_gpuConnectionToWebProcess.connection().removeThreadMessageReceiver(Messages::LibWebRTCCodecsProxy::messageReceiverName());
dispatchToThread([this, protectedThis = makeRef(*this)] {
+ auto locker = holdLock(m_lock);
auto decoders = WTFMove(m_decoders);
for (auto decoder : decoders.values())
webrtc::releaseLocalDecoder(decoder);
@@ -73,45 +74,49 @@
void LibWebRTCCodecsProxy::createH264Decoder(RTCDecoderIdentifier identifier)
{
+ ASSERT(!isMainRunLoop());
+ auto locker = holdLock(m_lock);
ASSERT(!m_decoders.contains(identifier));
m_decoders.add(identifier, webrtc::createLocalH264Decoder(makeBlockPtr([connection = makeRef(m_gpuConnectionToWebProcess.connection()), identifier](CVPixelBufferRef pixelBuffer, uint32_t timeStampNs, uint32_t timeStamp) {
if (auto sample = WebCore::RemoteVideoSample::create(pixelBuffer, MediaTime(timeStampNs, 1)))
connection->send(Messages::LibWebRTCCodecs::CompletedDecoding { identifier, timeStamp, *sample }, 0);
}).get()));
- updateHasEncodersOrDecoders();
}
void LibWebRTCCodecsProxy::createH265Decoder(RTCDecoderIdentifier identifier)
{
+ ASSERT(!isMainRunLoop());
+ auto locker = holdLock(m_lock);
ASSERT(!m_decoders.contains(identifier));
m_decoders.add(identifier, webrtc::createLocalH265Decoder(makeBlockPtr([connection = makeRef(m_gpuConnectionToWebProcess.connection()), identifier](CVPixelBufferRef pixelBuffer, uint32_t timeStampNs, uint32_t timeStamp) {
if (auto sample = WebCore::RemoteVideoSample::create(pixelBuffer, MediaTime(timeStampNs, 1)))
connection->send(Messages::LibWebRTCCodecs::CompletedDecoding { identifier, timeStamp, *sample }, 0);
}).get()));
- updateHasEncodersOrDecoders();
}
void LibWebRTCCodecsProxy::createVP9Decoder(RTCDecoderIdentifier identifier)
{
+ ASSERT(!isMainRunLoop());
+ auto locker = holdLock(m_lock);
ASSERT(!m_decoders.contains(identifier));
m_decoders.add(identifier, webrtc::createLocalVP9Decoder(makeBlockPtr([connection = makeRef(m_gpuConnectionToWebProcess.connection()), identifier](CVPixelBufferRef pixelBuffer, uint32_t timeStampNs, uint32_t timeStamp) {
if (auto sample = WebCore::RemoteVideoSample::create(pixelBuffer, MediaTime(timeStampNs, 1)))
connection->send(Messages::LibWebRTCCodecs::CompletedDecoding { identifier, timeStamp, *sample }, 0);
}).get()));
- updateHasEncodersOrDecoders();
}
void LibWebRTCCodecsProxy::releaseDecoder(RTCDecoderIdentifier identifier)
{
+ ASSERT(!isMainRunLoop());
+ auto locker = holdLock(m_lock);
ASSERT(m_decoders.contains(identifier));
- if (auto decoder = m_decoders.take(identifier)) {
+ if (auto decoder = m_decoders.take(identifier))
webrtc::releaseLocalDecoder(decoder);
- updateHasEncodersOrDecoders();
- }
}
void LibWebRTCCodecsProxy::decodeFrame(RTCDecoderIdentifier identifier, uint32_t timeStamp, const IPC::DataReference& data)
{
+ ASSERT(!isMainRunLoop());
ASSERT(m_decoders.contains(identifier));
auto decoder = m_decoders.get(identifier);
if (!decoder)
@@ -123,6 +128,7 @@
void LibWebRTCCodecsProxy::setFrameSize(RTCDecoderIdentifier identifier, uint16_t width, uint16_t height)
{
+ ASSERT(!isMainRunLoop());
ASSERT(m_decoders.contains(identifier));
auto decoder = m_decoders.get(identifier);
if (!decoder)
@@ -133,6 +139,8 @@
void LibWebRTCCodecsProxy::createEncoder(RTCEncoderIdentifier identifier, const String& formatName, const Vector<std::pair<String, String>>& parameters, bool useLowLatency)
{
+ ASSERT(!isMainRunLoop());
+ auto locker = holdLock(m_lock);
ASSERT(!m_encoders.contains(identifier));
std::map<std::string, std::string> rtcParameters;
@@ -144,20 +152,20 @@
}).get());
webrtc::setLocalEncoderLowLatency(encoder, useLowLatency);
m_encoders.add(identifier, encoder);
- updateHasEncodersOrDecoders();
}
void LibWebRTCCodecsProxy::releaseEncoder(RTCEncoderIdentifier identifier)
{
+ ASSERT(!isMainRunLoop());
+ auto locker = holdLock(m_lock);
ASSERT(m_encoders.contains(identifier));
- if (auto encoder = m_encoders.take(identifier)) {
+ if (auto encoder = m_encoders.take(identifier))
webrtc::releaseLocalEncoder(encoder);
- updateHasEncodersOrDecoders();
- }
}
void LibWebRTCCodecsProxy::initializeEncoder(RTCEncoderIdentifier identifier, uint16_t width, uint16_t height, unsigned startBitrate, unsigned maxBitrate, unsigned minBitrate, uint32_t maxFramerate)
{
+ ASSERT(!isMainRunLoop());
ASSERT(m_encoders.contains(identifier));
auto encoder = m_encoders.get(identifier);
if (!encoder)
@@ -184,6 +192,7 @@
void LibWebRTCCodecsProxy::encodeFrame(RTCEncoderIdentifier identifier, WebCore::RemoteVideoSample&& sample, uint32_t timeStamp, bool shouldEncodeAsKeyFrame)
{
+ ASSERT(!isMainRunLoop());
ASSERT(m_encoders.contains(identifier));
auto encoder = m_encoders.get(identifier);
if (!encoder)
@@ -200,6 +209,7 @@
void LibWebRTCCodecsProxy::setEncodeRates(RTCEncoderIdentifier identifier, uint32_t bitRate, uint32_t frameRate)
{
+ ASSERT(!isMainRunLoop());
auto encoder = m_encoders.get(identifier);
if (!encoder)
return;
@@ -207,14 +217,11 @@
webrtc::setLocalEncoderRates(encoder, bitRate, frameRate);
}
-void LibWebRTCCodecsProxy::updateHasEncodersOrDecoders()
-{
- m_hasEncodersOrDecoders = !m_encoders.isEmpty() || !m_decoders.isEmpty();
-}
-
bool LibWebRTCCodecsProxy::allowsExitUnderMemoryPressure() const
{
- return !m_hasEncodersOrDecoders;
+ ASSERT(isMainRunLoop());
+ auto locker = holdLock(m_lock);
+ return m_encoders.isEmpty() && m_decoders.isEmpty();
}
}