commit b209623b9b2d5e27d37e430b76665d4daea373e3
parent b6ecc6301c439b8a542c92f76d8ffe9f5f0994ad
Author: Dan Baker <dbaker@mozilla.com>
Date: Mon, 1 Dec 2025 21:44:57 -0700
Bug 2000941 - Vendor libwebrtc from 224de905c9
Upstream commit: https://webrtc.googlesource.com/src/+/224de905c9d4f546fe04ce25734de2b1b20bdc77
Delete legacy AsyncUDPSocket constructor and factory functions
All callers were updated to provide Environment and to pass Socket with unique_ptr rather than raw pointer.
This is a preparation for quering current time through Environment instead of through TimeMillis free functions.
Bug: webrtc:42223992
Change-Id: I52a3b13f8fd0daddd12b8e7ae04e0935efc2d619
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/409822
Auto-Submit: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#45675}
Diffstat:
7 files changed, 42 insertions(+), 51 deletions(-)
diff --git a/third_party/libwebrtc/README.mozilla.last-vendor b/third_party/libwebrtc/README.mozilla.last-vendor
@@ -1,4 +1,4 @@
# ./mach python dom/media/webrtc/third_party_build/vendor-libwebrtc.py --from-local /Users/danielbaker/elm/.moz-fast-forward/moz-libwebrtc --commit mozpatches libwebrtc
-libwebrtc updated from /Users/danielbaker/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2025-12-02T04:42:25.076032+00:00.
+libwebrtc updated from /Users/danielbaker/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2025-12-02T04:44:43.178244+00:00.
# base of lastest vendoring
-ffb3f04cf6
+224de905c9
diff --git a/third_party/libwebrtc/examples/androidvoip/BUILD.gn b/third_party/libwebrtc/examples/androidvoip/BUILD.gn
@@ -56,14 +56,18 @@ if (is_android) {
deps = [
":generated_jni",
"../../api:array_view",
+ "../../api:sequence_checker",
"../../api/audio:builtin_audio_processing_builder",
+ "../../api/environment",
"../../api/environment:environment_factory",
"../../rtc_base:async_packet_socket",
"../../rtc_base:async_udp_socket",
"../../rtc_base:checks",
+ "../../rtc_base:ip_address",
"../../rtc_base:logging",
"../../rtc_base:macromagic",
"../../rtc_base:network",
+ "../../rtc_base:socket",
"../../rtc_base:socket_address",
"../../rtc_base:socket_server",
"../../rtc_base:ssl_adapter",
diff --git a/third_party/libwebrtc/examples/androidvoip/jni/android_voip_client.cc b/third_party/libwebrtc/examples/androidvoip/jni/android_voip_client.cc
@@ -11,19 +11,28 @@
#include "examples/androidvoip/jni/android_voip_client.h"
#include <errno.h>
+#include <jni.h>
#include <sys/socket.h> // no-presubmit-check
#include <algorithm>
+#include <cstdint>
+#include <functional>
#include <map>
#include <memory>
+#include <optional>
+#include <string>
#include <utility>
#include <vector>
#include "absl/memory/memory.h"
+#include "api/array_view.h"
#include "api/audio/builtin_audio_processing_builder.h"
+#include "api/audio_codecs/audio_format.h"
#include "api/audio_codecs/builtin_audio_decoder_factory.h"
#include "api/audio_codecs/builtin_audio_encoder_factory.h"
+#include "api/call/transport.h"
#include "api/environment/environment_factory.h"
+#include "api/sequence_checker.h"
#include "api/units/time_delta.h"
#include "api/voip/voip_base.h"
#include "api/voip/voip_codec.h"
@@ -31,13 +40,19 @@
#include "api/voip/voip_network.h"
#include "api/voip/voip_statistics.h"
#include "examples/androidvoip/generated_jni/VoipClient_jni.h"
+#include "rtc_base/async_packet_socket.h"
+#include "rtc_base/async_udp_socket.h"
+#include "rtc_base/checks.h"
+#include "rtc_base/ip_address.h"
#include "rtc_base/logging.h"
-#include "rtc_base/network.h"
+#include "rtc_base/network/received_packet.h"
+#include "rtc_base/socket.h"
+#include "rtc_base/socket_address.h"
#include "rtc_base/socket_server.h"
#include "sdk/android/native_api/audio_device_module/audio_device_android.h"
#include "sdk/android/native_api/jni/java_types.h"
#include "sdk/android/native_api/jni/jvm.h"
-#include "sdk/android/native_api/jni/scoped_java_ref.h"
+#include "third_party/jni_zero/jni_zero.h"
namespace {
@@ -121,13 +136,20 @@ int GetPayloadType(const std::string& codec_name) {
namespace webrtc_examples {
+AndroidVoipClient::AndroidVoipClient(
+ JNIEnv* env,
+ const jni_zero::JavaParamRef<jobject>& j_voip_client)
+ : webrtc_env_(webrtc::CreateEnvironment()),
+ voip_thread_(webrtc::Thread::CreateWithSocketServer()),
+ j_voip_client_(env, j_voip_client) {}
+
void AndroidVoipClient::Init(
JNIEnv* env,
const jni_zero::JavaParamRef<jobject>& application_context) {
webrtc::VoipEngineConfig config;
config.encoder_factory = webrtc::CreateBuiltinAudioEncoderFactory();
config.decoder_factory = webrtc::CreateBuiltinAudioDecoderFactory();
- config.env = webrtc::CreateEnvironment();
+ config.env = webrtc_env_;
config.audio_device_module = webrtc::CreateJavaAudioDeviceModule(
env, *config.env, application_context.obj());
config.audio_processing_builder =
@@ -308,8 +330,8 @@ void AndroidVoipClient::StartSession(JNIEnv* env) {
// CreateChannel guarantees to return valid channel id.
channel_ = voip_engine_->Base().CreateChannel(this, std::nullopt);
- rtp_socket_.reset(webrtc::AsyncUDPSocket::Create(voip_thread_->socketserver(),
- rtp_local_address_));
+ rtp_socket_ = webrtc::AsyncUDPSocket::Create(webrtc_env_, rtp_local_address_,
+ *voip_thread_->socketserver());
if (!rtp_socket_) {
RTC_LOG_ERR(LS_ERROR) << "Socket creation failed";
Java_VoipClient_onStartSessionCompleted(env_, j_voip_client_,
@@ -322,8 +344,8 @@ void AndroidVoipClient::StartSession(JNIEnv* env) {
OnSignalReadRTPPacket(socket, packet);
});
- rtcp_socket_.reset(webrtc::AsyncUDPSocket::Create(
- voip_thread_->socketserver(), rtcp_local_address_));
+ rtcp_socket_ = webrtc::AsyncUDPSocket::Create(
+ webrtc_env_, rtcp_local_address_, *voip_thread_->socketserver());
if (!rtcp_socket_) {
RTC_LOG_ERR(LS_ERROR) << "Socket creation failed";
Java_VoipClient_onStartSessionCompleted(env_, j_voip_client_,
diff --git a/third_party/libwebrtc/examples/androidvoip/jni/android_voip_client.h b/third_party/libwebrtc/examples/androidvoip/jni/android_voip_client.h
@@ -22,6 +22,7 @@
#include "api/array_view.h"
#include "api/audio_codecs/audio_format.h"
#include "api/call/transport.h"
+#include "api/environment/environment.h"
#include "api/voip/voip_base.h"
#include "api/voip/voip_engine.h"
#include "rtc_base/async_packet_socket.h"
@@ -134,9 +135,7 @@ class AndroidVoipClient : public webrtc::Transport {
private:
AndroidVoipClient(JNIEnv* env,
- const jni_zero::JavaParamRef<jobject>& j_voip_client)
- : voip_thread_(webrtc::Thread::CreateWithSocketServer()),
- j_voip_client_(env, j_voip_client) {}
+ const jni_zero::JavaParamRef<jobject>& j_voip_client);
void Init(JNIEnv* env,
const jni_zero::JavaParamRef<jobject>& application_context);
@@ -158,6 +157,7 @@ class AndroidVoipClient : public webrtc::Transport {
// Method to print out ChannelStatistics
void LogChannelStatistics(JNIEnv* env);
+ const webrtc::Environment webrtc_env_;
// Used to invoke operations and send/receive RTP/RTCP packets.
std::unique_ptr<webrtc::Thread> voip_thread_;
// Reference to the VoipClient java instance used to
diff --git a/third_party/libwebrtc/moz-patch-stack/s0102.patch b/third_party/libwebrtc/moz-patch-stack/s0102.patch
@@ -397,7 +397,7 @@ index 26d136a1d8..1b3d2f3884 100644
deps = [
":generated_jni",
diff --git a/examples/androidvoip/BUILD.gn b/examples/androidvoip/BUILD.gn
-index af82ba39db..2306fe1886 100644
+index 1954875050..8dee85583a 100644
--- a/examples/androidvoip/BUILD.gn
+++ b/examples/androidvoip/BUILD.gn
@@ -50,8 +50,8 @@ if (is_android) {
diff --git a/third_party/libwebrtc/rtc_base/async_udp_socket.cc b/third_party/libwebrtc/rtc_base/async_udp_socket.cc
@@ -48,30 +48,10 @@ absl_nullable std::unique_ptr<AsyncUDPSocket> AsyncUDPSocket::Create(
return std::make_unique<AsyncUDPSocket>(env, std::move(socket));
}
-AsyncUDPSocket* AsyncUDPSocket::Create(Socket* socket,
- const SocketAddress& bind_address) {
- std::unique_ptr<Socket> owned_socket(socket);
- if (socket->Bind(bind_address) < 0) {
- RTC_LOG(LS_ERROR) << "Bind() failed with error " << socket->GetError();
- return nullptr;
- }
- return new AsyncUDPSocket(owned_socket.release());
-}
-
-AsyncUDPSocket* AsyncUDPSocket::Create(SocketFactory* factory,
- const SocketAddress& bind_address) {
- Socket* socket = factory->CreateSocket(bind_address.family(), SOCK_DGRAM);
- if (!socket)
- return nullptr;
- return Create(socket, bind_address);
-}
-
-AsyncUDPSocket::AsyncUDPSocket(const Environment& env,
+AsyncUDPSocket::AsyncUDPSocket(const Environment& /*env*/,
absl_nonnull std::unique_ptr<Socket> socket)
- : AsyncUDPSocket(socket.release()) {}
-
-AsyncUDPSocket::AsyncUDPSocket(Socket* socket) : socket_(socket) {
- sequence_checker_.Detach();
+ : sequence_checker_(SequenceChecker::kDetached),
+ socket_(std::move(socket)) {
// The socket should start out readable but not writable.
socket_->SignalReadEvent.connect(this, &AsyncUDPSocket::OnReadEvent);
socket_->SignalWriteEvent.connect(this, &AsyncUDPSocket::OnWriteEvent);
diff --git a/third_party/libwebrtc/rtc_base/async_udp_socket.h b/third_party/libwebrtc/rtc_base/async_udp_socket.h
@@ -41,23 +41,8 @@ class AsyncUDPSocket : public AsyncPacketSocket {
const SocketAddress& bind_address,
SocketFactory& factory);
- // TODO: bugs.webrtc.org/42223992 - Delete or deprecate 2 factory functions
- // below when WebRTC is updated to use factory that provides Environment.
- // Binds `socket` and creates AsyncUDPSocket for it. Takes ownership
- // of `socket`. Returns null if bind() fails (`socket` is destroyed
- // in that case).
- static AsyncUDPSocket* Create(Socket* socket,
- const SocketAddress& bind_address);
- // Creates a new socket for sending asynchronous UDP packets using an
- // asynchronous socket from the given factory.
- static AsyncUDPSocket* Create(SocketFactory* factory,
- const SocketAddress& bind_address);
-
AsyncUDPSocket(const Environment& env,
absl_nonnull std::unique_ptr<Socket> socket);
- // TODO: bugs.webrtc.org/42223992 - Delete or deprecate constructor below when
- // WebRTC is updated to use constructor that provides Environment.
- explicit AsyncUDPSocket(Socket* socket);
~AsyncUDPSocket() = default;
SocketAddress GetLocalAddress() const override;