Changeset 269739 in webkit


Ignore:
Timestamp:
Nov 12, 2020 10:26:24 AM (3 years ago)
Author:
youenn@apple.com
Message:

WebProcess should process WebRTC codecs IPC messages from the GPU Process in a background thread
https://bugs.webkit.org/show_bug.cgi?id=218790

Reviewed by Eric Carlson.

Use a WorkQueue to process GPU WebRTC codec IPC messages.
For that reason, handle encoder and decoder map within that queue.

Covered by existing tests.

  • GPUProcess/webrtc/LibWebRTCCodecsProxy.mm:

(WebKit::LibWebRTCCodecsProxy::setEncodeRates):

  • WebProcess/GPU/GPUProcessConnection.cpp:

(WebKit::GPUProcessConnection::dispatchMessage):

  • WebProcess/GPU/webrtc/LibWebRTCCodecs.cpp:

(WebKit::LibWebRTCCodecs::LibWebRTCCodecs):
(WebKit::LibWebRTCCodecs::~LibWebRTCCodecs):
(WebKit::LibWebRTCCodecs::setConnection):
(WebKit::LibWebRTCCodecs::createDecoder):
(WebKit::LibWebRTCCodecs::releaseDecoder):
(WebKit::LibWebRTCCodecs::failedDecoding):
(WebKit::LibWebRTCCodecs::completedDecoding):
(WebKit::LibWebRTCCodecs::createEncoder):
(WebKit::LibWebRTCCodecs::releaseEncoder):
(WebKit::LibWebRTCCodecs::initializeEncoder):
(WebKit::LibWebRTCCodecs::setEncodeRates):
(WebKit::LibWebRTCCodecs::completedEncoding):
(WebKit::LibWebRTCCodecs::dispatchToThread):

  • WebProcess/GPU/webrtc/LibWebRTCCodecs.h:
Location:
trunk/Source/WebKit
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r269727 r269739  
     12020-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
    1332020-11-12  Diego Pino Garcia  <dpino@igalia.com>
    234
  • trunk/Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.mm

    r269642 r269739  
    193193void LibWebRTCCodecsProxy::setEncodeRates(RTCEncoderIdentifier identifier, uint32_t bitRate, uint32_t frameRate)
    194194{
    195     ASSERT(m_encoders.contains(identifier));
    196195    auto encoder = m_encoders.get(identifier);
    197196    if (!encoder)
  • trunk/Source/WebKit/WebProcess/GPU/GPUProcessConnection.cpp

    r269698 r269739  
    151151    }
    152152#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 #endif
    159153#if USE(AUDIO_SESSION)
    160154    if (decoder.messageReceiverName() == Messages::RemoteAudioSession::messageReceiverName()) {
  • trunk/Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.cpp

    r269642 r269739  
    3131#include "DataReference.h"
    3232#include "GPUProcessConnection.h"
     33#include "LibWebRTCCodecsMessages.h"
    3334#include "LibWebRTCCodecsProxyMessages.h"
    3435#include "WebCoreArgumentCoders.h"
     
    134135}
    135136
     137LibWebRTCCodecs::LibWebRTCCodecs()
     138    : m_queue(WorkQueue::create("LibWebRTCCodecs", WorkQueue::Type::Serial, WorkQueue::QOS::UserInteractive))
     139{
     140}
     141
     142LibWebRTCCodecs::~LibWebRTCCodecs()
     143{
     144    if (m_connection)
     145        m_connection->removeThreadMessageReceiver(Messages::LibWebRTCCodecsProxy::messageReceiverName());
     146}
     147
    136148void LibWebRTCCodecs::setCallbacks(bool useGPUProcess)
    137149{
     
    157169}
    158170
     171void 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
    159183LibWebRTCCodecs::Decoder* LibWebRTCCodecs::createDecoder(Type type)
    160184{
     
    165189
    166190    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
    170196        switch (type) {
    171197        case Type::H264:
    172             decoder->connection->send(Messages::LibWebRTCCodecsProxy::CreateH264Decoder { decoderIdentifier }, 0);
     198            decoder->connection->send(Messages::LibWebRTCCodecsProxy::CreateH264Decoder { decoder->identifier }, 0);
    173199            break;
    174200        case Type::H265:
    175             decoder->connection->send(Messages::LibWebRTCCodecsProxy::CreateH265Decoder { decoderIdentifier }, 0);
     201            decoder->connection->send(Messages::LibWebRTCCodecsProxy::CreateH265Decoder { decoder->identifier }, 0);
    176202            break;
    177203        case Type::VP9:
    178             decoder->connection->send(Messages::LibWebRTCCodecsProxy::CreateVP9Decoder { decoderIdentifier }, 0);
     204            decoder->connection->send(Messages::LibWebRTCCodecsProxy::CreateVP9Decoder { decoder->identifier }, 0);
    179205            break;
    180206        }
    181207
    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        });
    184213    });
    185214    return result;
     
    192221
    193222    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
    197228        WebProcess::singleton().ensureGPUProcessConnection().connection().send(Messages::LibWebRTCCodecsProxy::ReleaseDecoder { decoderIdentifier }, 0);
    198229    });
     
    222253void LibWebRTCCodecs::failedDecoding(RTCDecoderIdentifier decoderIdentifier)
    223254{
    224     ASSERT(isMainThread());
     255    ASSERT(!isMainThread());
    225256
    226257    if (auto* decoder = m_decoders.get(decoderIdentifier))
     
    230261void LibWebRTCCodecs::completedDecoding(RTCDecoderIdentifier decoderIdentifier, uint32_t timeStamp, WebCore::RemoteVideoSample&& remoteSample)
    231262{
    232     ASSERT(isMainThread());
     263    ASSERT(!isMainThread());
    233264
    234265    // FIXME: Do error logging.
     
    297328
    298329    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        });
    304337    });
    305338    return result;
     
    312345
    313346    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        });
    317351        WebProcess::singleton().ensureGPUProcessConnection().connection().send(Messages::LibWebRTCCodecsProxy::ReleaseEncoder { encoderIdentifier }, 0);
    318352    });
     
    323357{
    324358    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        });
    331370    });
    332371    return 0;
     
    379418{
    380419    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] {
    385421            WebProcess::singleton().ensureGPUProcessConnection().connection().send(Messages::LibWebRTCCodecsProxy::SetEncodeRates { encoderIdentifier, bitRate, frameRate }, 0);
    386422        });
     
    392428void LibWebRTCCodecs::completedEncoding(RTCEncoderIdentifier identifier, IPC::DataReference&& data, const webrtc::WebKitEncodedFrameInfo& info)
    393429{
    394     ASSERT(isMainThread());
     430    ASSERT(!isMainThread());
    395431
    396432    // FIXME: Do error logging.
     
    419455}
    420456
     457void LibWebRTCCodecs::dispatchToThread(Function<void()>&& callback)
     458{
     459    m_queue->dispatch(WTFMove(callback));
     460}
     461
    421462}
    422463
  • trunk/Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.h

    r269642 r269739  
    2828#if USE(LIBWEBRTC) && PLATFORM(COCOA) && ENABLE(GPU_PROCESS)
    2929
     30#include "Connection.h"
    3031#include "MessageReceiver.h"
    3132#include "RTCDecoderIdentifier.h"
     
    5859namespace WebKit {
    5960
    60 class LibWebRTCCodecs : private IPC::MessageReceiver {
     61class LibWebRTCCodecs : public IPC::Connection::ThreadMessageReceiverRefCounted {
    6162    WTF_MAKE_FAST_ALLOCATED;
    6263public:
    63     LibWebRTCCodecs() = default;
     64    LibWebRTCCodecs();
     65    ~LibWebRTCCodecs();
    6466
    6567    static void setCallbacks(bool useGPUProcess);
     
    112114    RetainPtr<CVPixelBufferRef> convertToBGRA(CVPixelBufferRef);
    113115
     116    void setConnection(IPC::Connection&);
     117
     118    // IPC::Connection::ThreadMessageReceiver
     119    void dispatchToThread(Function<void()>&&) final;
     120
    114121private:
    115122    HashMap<RTCDecoderIdentifier, std::unique_ptr<Decoder>> m_decoders;
     
    118125    HashMap<RTCEncoderIdentifier, std::unique_ptr<Encoder>> m_encoders;
    119126
     127    RefPtr<IPC::Connection> m_connection;
     128    Ref<WorkQueue> m_queue;
    120129    std::unique_ptr<WebCore::ImageTransferSessionVT> m_imageTransferSession;
    121130    std::unique_ptr<WebCore::PixelBufferConformerCV> m_pixelBufferConformer;
Note: See TracChangeset for help on using the changeset viewer.