Changeset 269739 in webkit
- Timestamp:
- Nov 12, 2020 10:26:24 AM (3 years ago)
- Location:
- trunk/Source/WebKit
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r269727 r269739 1 2020-11-12 Youenn Fablet <youenn@apple.com> 2 3 WebProcess should process WebRTC codecs IPC messages from the GPU Process in a background thread 4 https://bugs.webkit.org/show_bug.cgi?id=218790 5 6 Reviewed by Eric Carlson. 7 8 Use a WorkQueue to process GPU WebRTC codec IPC messages. 9 For that reason, handle encoder and decoder map within that queue. 10 11 Covered by existing tests. 12 13 * GPUProcess/webrtc/LibWebRTCCodecsProxy.mm: 14 (WebKit::LibWebRTCCodecsProxy::setEncodeRates): 15 * WebProcess/GPU/GPUProcessConnection.cpp: 16 (WebKit::GPUProcessConnection::dispatchMessage): 17 * WebProcess/GPU/webrtc/LibWebRTCCodecs.cpp: 18 (WebKit::LibWebRTCCodecs::LibWebRTCCodecs): 19 (WebKit::LibWebRTCCodecs::~LibWebRTCCodecs): 20 (WebKit::LibWebRTCCodecs::setConnection): 21 (WebKit::LibWebRTCCodecs::createDecoder): 22 (WebKit::LibWebRTCCodecs::releaseDecoder): 23 (WebKit::LibWebRTCCodecs::failedDecoding): 24 (WebKit::LibWebRTCCodecs::completedDecoding): 25 (WebKit::LibWebRTCCodecs::createEncoder): 26 (WebKit::LibWebRTCCodecs::releaseEncoder): 27 (WebKit::LibWebRTCCodecs::initializeEncoder): 28 (WebKit::LibWebRTCCodecs::setEncodeRates): 29 (WebKit::LibWebRTCCodecs::completedEncoding): 30 (WebKit::LibWebRTCCodecs::dispatchToThread): 31 * WebProcess/GPU/webrtc/LibWebRTCCodecs.h: 32 1 33 2020-11-12 Diego Pino Garcia <dpino@igalia.com> 2 34 -
trunk/Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.mm
r269642 r269739 193 193 void LibWebRTCCodecsProxy::setEncodeRates(RTCEncoderIdentifier identifier, uint32_t bitRate, uint32_t frameRate) 194 194 { 195 ASSERT(m_encoders.contains(identifier));196 195 auto encoder = m_encoders.get(identifier); 197 196 if (!encoder) -
trunk/Source/WebKit/WebProcess/GPU/GPUProcessConnection.cpp
r269698 r269739 151 151 } 152 152 #endif // PLATFORM(COCOA) && ENABLE(MEDIA_STREAM) 153 #if USE(LIBWEBRTC) && PLATFORM(COCOA)154 if (decoder.messageReceiverName() == Messages::LibWebRTCCodecs::messageReceiverName()) {155 WebProcess::singleton().libWebRTCCodecs().didReceiveMessage(connection, decoder);156 return true;157 }158 #endif159 153 #if USE(AUDIO_SESSION) 160 154 if (decoder.messageReceiverName() == Messages::RemoteAudioSession::messageReceiverName()) { -
trunk/Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.cpp
r269642 r269739 31 31 #include "DataReference.h" 32 32 #include "GPUProcessConnection.h" 33 #include "LibWebRTCCodecsMessages.h" 33 34 #include "LibWebRTCCodecsProxyMessages.h" 34 35 #include "WebCoreArgumentCoders.h" … … 134 135 } 135 136 137 LibWebRTCCodecs::LibWebRTCCodecs() 138 : m_queue(WorkQueue::create("LibWebRTCCodecs", WorkQueue::Type::Serial, WorkQueue::QOS::UserInteractive)) 139 { 140 } 141 142 LibWebRTCCodecs::~LibWebRTCCodecs() 143 { 144 if (m_connection) 145 m_connection->removeThreadMessageReceiver(Messages::LibWebRTCCodecsProxy::messageReceiverName()); 146 } 147 136 148 void LibWebRTCCodecs::setCallbacks(bool useGPUProcess) 137 149 { … … 157 169 } 158 170 171 void LibWebRTCCodecs::setConnection(IPC::Connection& connection) 172 { 173 if (m_connection.get() == &connection) 174 return; 175 176 if (m_connection) 177 m_connection->removeThreadMessageReceiver(Messages::LibWebRTCCodecs::messageReceiverName()); 178 179 m_connection = &connection; 180 m_connection->addThreadMessageReceiver(Messages::LibWebRTCCodecs::messageReceiverName(), this); 181 } 182 159 183 LibWebRTCCodecs::Decoder* LibWebRTCCodecs::createDecoder(Type type) 160 184 { … … 165 189 166 190 callOnMainRunLoop([this, decoder = WTFMove(decoder), type]() mutable { 167 decoder->connection = &WebProcess::singleton().ensureGPUProcessConnection().connection(); 168 169 auto decoderIdentifier = decoder->identifier; 191 auto& connection = WebProcess::singleton().ensureGPUProcessConnection().connection(); 192 setConnection(connection); 193 194 decoder->connection = &connection; 195 170 196 switch (type) { 171 197 case Type::H264: 172 decoder->connection->send(Messages::LibWebRTCCodecsProxy::CreateH264Decoder { decoder Identifier }, 0);198 decoder->connection->send(Messages::LibWebRTCCodecsProxy::CreateH264Decoder { decoder->identifier }, 0); 173 199 break; 174 200 case Type::H265: 175 decoder->connection->send(Messages::LibWebRTCCodecsProxy::CreateH265Decoder { decoder Identifier }, 0);201 decoder->connection->send(Messages::LibWebRTCCodecsProxy::CreateH265Decoder { decoder->identifier }, 0); 176 202 break; 177 203 case Type::VP9: 178 decoder->connection->send(Messages::LibWebRTCCodecsProxy::CreateVP9Decoder { decoder Identifier }, 0);204 decoder->connection->send(Messages::LibWebRTCCodecsProxy::CreateVP9Decoder { decoder->identifier }, 0); 179 205 break; 180 206 } 181 207 182 ASSERT(!m_decoders.contains(decoderIdentifier)); 183 m_decoders.add(decoderIdentifier, WTFMove(decoder)); 208 dispatchToThread([this, decoder = WTFMove(decoder)]() mutable { 209 auto decoderIdentifier = decoder->identifier; 210 ASSERT(!m_decoders.contains(decoderIdentifier)); 211 m_decoders.add(decoderIdentifier, WTFMove(decoder)); 212 }); 184 213 }); 185 214 return result; … … 192 221 193 222 callOnMainRunLoop([this, decoderIdentifier = decoder.identifier] { 194 ASSERT(m_decoders.contains(decoderIdentifier)); 195 196 m_decoders.remove(decoderIdentifier); 223 dispatchToThread([this, decoderIdentifier] { 224 ASSERT(m_decoders.contains(decoderIdentifier)); 225 m_decoders.remove(decoderIdentifier); 226 }); 227 197 228 WebProcess::singleton().ensureGPUProcessConnection().connection().send(Messages::LibWebRTCCodecsProxy::ReleaseDecoder { decoderIdentifier }, 0); 198 229 }); … … 222 253 void LibWebRTCCodecs::failedDecoding(RTCDecoderIdentifier decoderIdentifier) 223 254 { 224 ASSERT( isMainThread());255 ASSERT(!isMainThread()); 225 256 226 257 if (auto* decoder = m_decoders.get(decoderIdentifier)) … … 230 261 void LibWebRTCCodecs::completedDecoding(RTCDecoderIdentifier decoderIdentifier, uint32_t timeStamp, WebCore::RemoteVideoSample&& remoteSample) 231 262 { 232 ASSERT( isMainThread());263 ASSERT(!isMainThread()); 233 264 234 265 // FIXME: Do error logging. … … 297 328 298 329 callOnMainRunLoop([this, encoder = WTFMove(encoder), type, parameters = WTFMove(parameters)]() mutable { 299 auto encoderIdentifier = encoder->identifier; 300 ASSERT(!m_encoders.contains(encoderIdentifier)); 301 302 WebProcess::singleton().ensureGPUProcessConnection().connection().send(Messages::LibWebRTCCodecsProxy::CreateEncoder { encoderIdentifier, formatNameFromCodecType(type), parameters, RuntimeEnabledFeatures::sharedFeatures().webRTCH264LowLatencyEncoderEnabled() }, 0); 303 m_encoders.add(encoderIdentifier, WTFMove(encoder)); 330 WebProcess::singleton().ensureGPUProcessConnection().connection().send(Messages::LibWebRTCCodecsProxy::CreateEncoder { encoder->identifier, formatNameFromCodecType(type), parameters, RuntimeEnabledFeatures::sharedFeatures().webRTCH264LowLatencyEncoderEnabled() }, 0); 331 332 dispatchToThread([this, encoder = WTFMove(encoder)]() mutable { 333 auto encoderIdentifier = encoder->identifier; 334 ASSERT(!m_encoders.contains(encoderIdentifier)); 335 m_encoders.add(encoderIdentifier, WTFMove(encoder)); 336 }); 304 337 }); 305 338 return result; … … 312 345 313 346 callOnMainRunLoop([this, encoderIdentifier = encoder.identifier] { 314 ASSERT(m_encoders.contains(encoderIdentifier)); 315 316 m_encoders.remove(encoderIdentifier); 347 dispatchToThread([this, encoderIdentifier] { 348 ASSERT(m_encoders.contains(encoderIdentifier)); 349 m_encoders.remove(encoderIdentifier); 350 }); 317 351 WebProcess::singleton().ensureGPUProcessConnection().connection().send(Messages::LibWebRTCCodecsProxy::ReleaseEncoder { encoderIdentifier }, 0); 318 352 }); … … 323 357 { 324 358 callOnMainRunLoop([this, encoderIdentifier = encoder.identifier, width, height, startBitRate, maxBitRate, minBitRate, maxFrameRate] { 325 if (auto* encoder = m_encoders.get(encoderIdentifier)) { 326 auto& connection = WebProcess::singleton().ensureGPUProcessConnection().connection(); 327 connection.send(Messages::LibWebRTCCodecsProxy::InitializeEncoder { encoderIdentifier, width, height, startBitRate, maxBitRate, minBitRate, maxFrameRate }, 0); 328 // We set encoder->connection here so that InitializeEncoder is sent before any EncodeFrame message. 329 encoder->connection = &connection; 330 } 359 auto& connection = WebProcess::singleton().ensureGPUProcessConnection().connection(); 360 setConnection(connection); 361 362 connection.send(Messages::LibWebRTCCodecsProxy::InitializeEncoder { encoderIdentifier, width, height, startBitRate, maxBitRate, minBitRate, maxFrameRate }, 0); 363 364 dispatchToThread([this, encoderIdentifier, connection = makeRef(connection)]() mutable { 365 if (auto* encoder = m_encoders.get(encoderIdentifier)) { 366 // We set encoder->connection here so that InitializeEncoder is sent before any EncodeFrame message. 367 encoder->connection = WTFMove(connection); 368 } 369 }); 331 370 }); 332 371 return 0; … … 379 418 { 380 419 if (!encoder.connection) { 381 callOnMainRunLoop([this, encoderIdentifier = encoder.identifier, bitRate, frameRate] { 382 UNUSED_PARAM(this); 383 ASSERT(m_encoders.contains(encoderIdentifier)); 384 ASSERT(m_encoders.get(encoderIdentifier)->connection); 420 callOnMainRunLoop([encoderIdentifier = encoder.identifier, bitRate, frameRate] { 385 421 WebProcess::singleton().ensureGPUProcessConnection().connection().send(Messages::LibWebRTCCodecsProxy::SetEncodeRates { encoderIdentifier, bitRate, frameRate }, 0); 386 422 }); … … 392 428 void LibWebRTCCodecs::completedEncoding(RTCEncoderIdentifier identifier, IPC::DataReference&& data, const webrtc::WebKitEncodedFrameInfo& info) 393 429 { 394 ASSERT( isMainThread());430 ASSERT(!isMainThread()); 395 431 396 432 // FIXME: Do error logging. … … 419 455 } 420 456 457 void LibWebRTCCodecs::dispatchToThread(Function<void()>&& callback) 458 { 459 m_queue->dispatch(WTFMove(callback)); 460 } 461 421 462 } 422 463 -
trunk/Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.h
r269642 r269739 28 28 #if USE(LIBWEBRTC) && PLATFORM(COCOA) && ENABLE(GPU_PROCESS) 29 29 30 #include "Connection.h" 30 31 #include "MessageReceiver.h" 31 32 #include "RTCDecoderIdentifier.h" … … 58 59 namespace WebKit { 59 60 60 class LibWebRTCCodecs : p rivate IPC::MessageReceiver{61 class LibWebRTCCodecs : public IPC::Connection::ThreadMessageReceiverRefCounted { 61 62 WTF_MAKE_FAST_ALLOCATED; 62 63 public: 63 LibWebRTCCodecs() = default; 64 LibWebRTCCodecs(); 65 ~LibWebRTCCodecs(); 64 66 65 67 static void setCallbacks(bool useGPUProcess); … … 112 114 RetainPtr<CVPixelBufferRef> convertToBGRA(CVPixelBufferRef); 113 115 116 void setConnection(IPC::Connection&); 117 118 // IPC::Connection::ThreadMessageReceiver 119 void dispatchToThread(Function<void()>&&) final; 120 114 121 private: 115 122 HashMap<RTCDecoderIdentifier, std::unique_ptr<Decoder>> m_decoders; … … 118 125 HashMap<RTCEncoderIdentifier, std::unique_ptr<Encoder>> m_encoders; 119 126 127 RefPtr<IPC::Connection> m_connection; 128 Ref<WorkQueue> m_queue; 120 129 std::unique_ptr<WebCore::ImageTransferSessionVT> m_imageTransferSession; 121 130 std::unique_ptr<WebCore::PixelBufferConformerCV> m_pixelBufferConformer;
Note: See TracChangeset
for help on using the changeset viewer.