Title: [290829] trunk/Source/WebKit
Revision
290829
Author
[email protected]
Date
2022-03-04 05:22:09 -0800 (Fri, 04 Mar 2022)

Log Message

LibWebRTCCodecs::setEncodeRates should send LibWebRTCCodecsProxy::SetEncodeRates only when the encoder is live
https://bugs.webkit.org/show_bug.cgi?id=237421

Reviewed by Darin Adler.

We were previously not asserting in LibWebRTCCodecsProxy::setEncodeRates and we were missing some encode rate orders.
This is due to the fact that when creating an encoder, we are hopping to main thread, then to work queue to send the message to create an encoder.
In LibWebRTCCodecs::setEncodeRates, we were hopping to main thread if needed.
If the encoder connection is null, we are now hopping to main thread, then to work queue as done when creating an encoder.
Since there is a time where LibWebRTCCodecsProxy::setEncodeRates might have sent encode rates, we bail out early to not set based on old bitrates.

Covered by existing tests not crashing in LibWebRTCCodecsProxy::setEncodeRates.

* WebProcess/GPU/webrtc/LibWebRTCCodecs.cpp:
(WebKit::LibWebRTCCodecs::setEncodeRates):
* WebProcess/GPU/webrtc/LibWebRTCCodecs.h:

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (290828 => 290829)


--- trunk/Source/WebKit/ChangeLog	2022-03-04 13:16:16 UTC (rev 290828)
+++ trunk/Source/WebKit/ChangeLog	2022-03-04 13:22:09 UTC (rev 290829)
@@ -1,3 +1,22 @@
+2022-03-04  Youenn Fablet  <[email protected]>
+
+        LibWebRTCCodecs::setEncodeRates should send LibWebRTCCodecsProxy::SetEncodeRates only when the encoder is live
+        https://bugs.webkit.org/show_bug.cgi?id=237421
+
+        Reviewed by Darin Adler.
+
+        We were previously not asserting in LibWebRTCCodecsProxy::setEncodeRates and we were missing some encode rate orders.
+        This is due to the fact that when creating an encoder, we are hopping to main thread, then to work queue to send the message to create an encoder.
+        In LibWebRTCCodecs::setEncodeRates, we were hopping to main thread if needed.
+        If the encoder connection is null, we are now hopping to main thread, then to work queue as done when creating an encoder.
+        Since there is a time where LibWebRTCCodecsProxy::setEncodeRates might have sent encode rates, we bail out early to not set based on old bitrates.
+
+        Covered by existing tests not crashing in LibWebRTCCodecsProxy::setEncodeRates.
+
+        * WebProcess/GPU/webrtc/LibWebRTCCodecs.cpp:
+        (WebKit::LibWebRTCCodecs::setEncodeRates):
+        * WebProcess/GPU/webrtc/LibWebRTCCodecs.h:
+
 2022-03-04  Adrian Perez de Castro  <[email protected]>
 
         [GTK][WPE] Documentation for webkit_web_context_set_spell_checking_languages() is incomplete

Modified: trunk/Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.cpp (290828 => 290829)


--- trunk/Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.cpp	2022-03-04 13:16:16 UTC (rev 290828)
+++ trunk/Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.cpp	2022-03-04 13:22:09 UTC (rev 290829)
@@ -519,11 +519,20 @@
 
     auto* connection = encoderConnection(encoder);
     if (!connection) {
-        callOnMainRunLoop([encoderIdentifier = encoder.identifier, bitRate, frameRate] {
-            WebProcess::singleton().ensureGPUProcessConnection().connection().send(Messages::LibWebRTCCodecsProxy::SetEncodeRates { encoderIdentifier, bitRate, frameRate }, 0);
+        ensureGPUProcessConnectionAndDispatchToThread([this, hasSentInitialEncodeRates = &encoder.hasSentInitialEncodeRates, encoderIdentifier = encoder.identifier, bitRate, frameRate] {
+            assertIsCurrent(workQueue());
+            ASSERT(m_encoders.get(encoderIdentifier));
+
+            // hasSentInitialEncodeRates remains valid as encoder destruction goes through ensureGPUProcessConnectionAndDispatchToThread.
+            if (*hasSentInitialEncodeRates)
+                return;
+
+            Locker locker { m_connectionLock };
+            m_connection->send(Messages::LibWebRTCCodecsProxy::SetEncodeRates { encoderIdentifier, bitRate, frameRate }, 0);
         });
         return;
     }
+    encoder.hasSentInitialEncodeRates = true;
     connection->send(Messages::LibWebRTCCodecsProxy::SetEncodeRates { encoder.identifier, bitRate, frameRate }, 0);
 }
 

Modified: trunk/Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.h (290828 => 290829)


--- trunk/Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.h	2022-03-04 13:16:16 UTC (rev 290828)
+++ trunk/Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.h	2022-03-04 13:22:09 UTC (rev 290829)
@@ -108,6 +108,7 @@
         Lock encodedImageCallbackLock;
         RefPtr<IPC::Connection> connection;
         SharedVideoFrameWriter sharedVideoFrameWriter;
+        bool hasSentInitialEncodeRates { false };
     };
 
     Encoder* createEncoder(Type, const std::map<std::string, std::string>&);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to