commit 30b26b3a29925cb03f8aeb7e15c85c7d3ff3b585 parent 5609b8b7519d1eab4dc5520cfae4cb70897f3d4e Author: Dan Baker <dbaker@mozilla.com> Date: Tue, 2 Dec 2025 01:16:48 -0700 Bug 2000941 - Vendor libwebrtc from 6d15b49fbd Upstream commit: https://webrtc.googlesource.com/src/+/6d15b49fbd111ed1be040333f7a80c627dbb70c8 Enforce const access to media engine from signaling thread Restrict access to `MediaEngineInterface` from the signaling thread by providing only a `const` pointer. This limits interactions to `const` methods and state, transitively reducing the API surface for the voice and video engines on this thread. This change improves thread safety by preventing incorrect usage. All non-`const` operations on the media engine must run on the worker thread, and this restriction now enforces that rule at compile time, reducing the risk of concurrency errors. Bug: none Change-Id: I48a64222a7db2c9d03f2e42496ca3bcd28ec3a51 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/412321 Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Reviewed-by: Danil Chapovalov <danilchap@webrtc.org> Cr-Commit-Position: refs/heads/main@{#45752} Diffstat:
13 files changed, 20 insertions(+), 24 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-02T08:13:41.981550+00:00. +libwebrtc updated from /Users/danielbaker/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2025-12-02T08:16:34.787600+00:00. # base of lastest vendoring -357a26c099 +6d15b49fbd diff --git a/third_party/libwebrtc/pc/codec_vendor.cc b/third_party/libwebrtc/pc/codec_vendor.cc @@ -9,7 +9,6 @@ */ #include "pc/codec_vendor.h" -#include <cstddef> #include <map> #include <optional> #include <string> @@ -834,7 +833,7 @@ RTCErrorOr<Codecs> CodecVendor::GetNegotiatedCodecsForAnswer( } CodecVendor::CodecVendor( - MediaEngineInterface* media_engine, + const MediaEngineInterface* media_engine, bool rtx_enabled, const FieldTrialsView& trials) { // Null media_engine is permitted in // order to allow unit testing where diff --git a/third_party/libwebrtc/pc/codec_vendor.h b/third_party/libwebrtc/pc/codec_vendor.h @@ -42,7 +42,7 @@ namespace webrtc { // - Thread guard class CodecVendor { public: - CodecVendor(MediaEngineInterface* media_engine, + CodecVendor(const MediaEngineInterface* media_engine, bool rtx_enabled, const FieldTrialsView& trials); diff --git a/third_party/libwebrtc/pc/media_session.cc b/third_party/libwebrtc/pc/media_session.cc @@ -45,6 +45,7 @@ #include "pc/simulcast_description.h" #include "pc/used_ids.h" #include "rtc_base/checks.h" +#include "rtc_base/experiments/field_trial_parser.h" #include "rtc_base/logging.h" #include "rtc_base/unique_id_generator.h" @@ -680,7 +681,7 @@ bool AcceptOfferWithRfc8888(const FieldTrialsView& field_trials) { } // namespace MediaSessionDescriptionFactory::MediaSessionDescriptionFactory( - MediaEngineInterface* media_engine, + const MediaEngineInterface* media_engine, bool rtx_enabled, UniqueRandomIdGenerator* ssrc_generator, const TransportDescriptionFactory* transport_desc_factory, diff --git a/third_party/libwebrtc/pc/media_session.h b/third_party/libwebrtc/pc/media_session.h @@ -28,7 +28,6 @@ #include "pc/codec_vendor.h" #include "pc/media_options.h" #include "pc/session_description.h" -#include "rtc_base/experiments/field_trial_parser.h" #include "rtc_base/memory/always_valid_pointer.h" #include "rtc_base/unique_id_generator.h" @@ -52,7 +51,7 @@ class MediaSessionDescriptionFactory { // The TransportDescriptionFactory, the UniqueRandomIdGenerator, and the // PayloadTypeSuggester are not owned by MediaSessionDescriptionFactory, so // they must be kept alive by the user of this class. - MediaSessionDescriptionFactory(MediaEngineInterface* media_engine, + MediaSessionDescriptionFactory(const MediaEngineInterface* media_engine, bool rtx_enabled, UniqueRandomIdGenerator* ssrc_generator, const TransportDescriptionFactory* factory, diff --git a/third_party/libwebrtc/pc/peer_connection_factory.cc b/third_party/libwebrtc/pc/peer_connection_factory.cc @@ -101,10 +101,7 @@ PeerConnectionFactory::PeerConnectionFactory( : env_(env), context_(context ? context : ConnectionContext::Create(env_, dependencies)), - codec_vendor_(context_->media_engine(), - context_->use_rtx(), - env_.field_trials()), - + codec_vendor_(media_engine(), context_->use_rtx(), env_.field_trials()), event_log_factory_(std::move(dependencies->event_log_factory)), fec_controller_factory_(std::move(dependencies->fec_controller_factory)), network_state_predictor_factory_( @@ -193,16 +190,16 @@ scoped_refptr<AudioSourceInterface> PeerConnectionFactory::CreateAudioSource( bool PeerConnectionFactory::StartAecDump(FILE* file, int64_t max_size_bytes) { RTC_DCHECK_RUN_ON(worker_thread()); - return media_engine()->voice().StartAecDump(FileWrapper(file), - max_size_bytes); + return context_->media_engine()->voice().StartAecDump(FileWrapper(file), + max_size_bytes); } void PeerConnectionFactory::StopAecDump() { RTC_DCHECK_RUN_ON(worker_thread()); - media_engine()->voice().StopAecDump(); + context_->media_engine()->voice().StopAecDump(); } -MediaEngineInterface* PeerConnectionFactory::media_engine() const { +const MediaEngineInterface* PeerConnectionFactory::media_engine() const { RTC_DCHECK(context_); return context_->media_engine(); } diff --git a/third_party/libwebrtc/pc/peer_connection_factory.h b/third_party/libwebrtc/pc/peer_connection_factory.h @@ -104,7 +104,7 @@ class PeerConnectionFactory : public PeerConnectionFactoryInterface { const FieldTrialsView& field_trials() const { return env_.field_trials(); } - MediaEngineInterface* media_engine() const; + const MediaEngineInterface* media_engine() const; CodecVendor& CodecVendorForTesting() { return codec_vendor_; } protected: diff --git a/third_party/libwebrtc/pc/rtp_transmission_manager.cc b/third_party/libwebrtc/pc/rtp_transmission_manager.cc @@ -763,7 +763,7 @@ RtpTransmissionManager::FindReceiverById(const std::string& receiver_id) const { return nullptr; } -MediaEngineInterface* RtpTransmissionManager::media_engine() const { +const MediaEngineInterface* RtpTransmissionManager::media_engine() const { return context_->media_engine(); } diff --git a/third_party/libwebrtc/pc/rtp_transmission_manager.h b/third_party/libwebrtc/pc/rtp_transmission_manager.h @@ -245,7 +245,7 @@ class RtpTransmissionManager : public RtpSenderBase::SetStreamsObserver { absl::AnyInvocable<void(webrtc::PeerConnectionObserver*) &&>); void OnNegotiationNeeded(); - MediaEngineInterface* media_engine() const; + const MediaEngineInterface* media_engine() const; UniqueRandomIdGenerator* ssrc_generator() const { return context_->ssrc_generator(); diff --git a/third_party/libwebrtc/pc/sdp_offer_answer.cc b/third_party/libwebrtc/pc/sdp_offer_answer.cc @@ -1525,7 +1525,7 @@ void SdpOfferAnswerHandler::Initialize( // ================================================================== // Access to pc_ variables -MediaEngineInterface* SdpOfferAnswerHandler::media_engine() const { +const MediaEngineInterface* SdpOfferAnswerHandler::media_engine() const { RTC_DCHECK(context_); return context_->media_engine(); } diff --git a/third_party/libwebrtc/pc/sdp_offer_answer.h b/third_party/libwebrtc/pc/sdp_offer_answer.h @@ -25,6 +25,7 @@ #include "absl/strings/string_view.h" #include "api/audio_options.h" #include "api/candidate.h" +#include "api/environment/environment.h" #include "api/jsep.h" #include "api/media_stream_interface.h" #include "api/media_types.h" @@ -566,7 +567,7 @@ class SdpOfferAnswerHandler : public SdpStateProvider { // ================================================================== // Access to pc_ variables - MediaEngineInterface* media_engine() const; + const MediaEngineInterface* media_engine() const; TransceiverList* transceivers(); const TransceiverList* transceivers() const; DataChannelController* data_channel_controller(); diff --git a/third_party/libwebrtc/pc/typed_codec_vendor.cc b/third_party/libwebrtc/pc/typed_codec_vendor.cc @@ -10,7 +10,6 @@ #include "pc/typed_codec_vendor.h" -#include <cstddef> #include <functional> #include <map> #include <vector> @@ -94,7 +93,7 @@ std::vector<Codec> CollectAudioCodecs( } // namespace -TypedCodecVendor::TypedCodecVendor(MediaEngineInterface* media_engine, +TypedCodecVendor::TypedCodecVendor(const MediaEngineInterface* media_engine, MediaType type, bool is_sender, bool rtx_enabled, diff --git a/third_party/libwebrtc/pc/typed_codec_vendor.h b/third_party/libwebrtc/pc/typed_codec_vendor.h @@ -26,7 +26,7 @@ class TypedCodecVendor { // Constructor for the case where media engine is not provided. The resulting // vendor will always return an empty codec list. TypedCodecVendor() {} - TypedCodecVendor(MediaEngineInterface* media_engine, + TypedCodecVendor(const MediaEngineInterface* media_engine, MediaType type, bool is_sender, bool rtx_enabled,