From 9e09a1f327018143723c330069b51b16613a6f11 Mon Sep 17 00:00:00 2001 From: Danil Chapovalov Date: Thu, 8 Sep 2022 18:38:10 +0200 Subject: [PATCH] Replace Thread::Invoke with Thread::BlockingCall BlockingCall doesn't take rtc::Location parameter and thus most of the dependencies on location can be removed Bug: webrtc:11318 Change-Id: I91a17e342dd9a9e3e2c8f7fbe267474c98a8d0e5 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/274620 Reviewed-by: Tomas Gunnarsson Commit-Queue: Danil Chapovalov Cr-Commit-Position: refs/heads/main@{#38045} --- audio/voip/BUILD.gn | 1 - audio/voip/audio_channel.cc | 1 - call/BUILD.gn | 2 - call/call.cc | 1 - call/degraded_call.cc | 1 - call/flexfec_receive_stream_impl.cc | 1 - call/rtp_video_sender.cc | 1 - .../androidvoip/jni/android_voip_client.cc | 4 +- modules/pacing/BUILD.gn | 1 - modules/video_coding/BUILD.gn | 2 - .../video_coding/jitter_buffer_unittest.cc | 1 - modules/video_coding/video_receiver.cc | 1 - pc/BUILD.gn | 16 ---- pc/audio_rtp_receiver.cc | 5 +- pc/channel.cc | 11 ++- pc/connection_context.cc | 4 +- pc/data_channel_controller.cc | 14 ++- pc/dtmf_sender.cc | 7 +- pc/dtmf_sender.h | 4 +- pc/jsep_transport_controller.cc | 31 +++---- pc/legacy_stats_collector.cc | 11 ++- pc/peer_connection.cc | 89 ++++++++----------- pc/peer_connection_factory.cc | 17 ++-- pc/rtc_stats_collector.cc | 9 +- pc/rtp_sender.cc | 40 ++++----- pc/rtp_transceiver.cc | 80 +++++++---------- pc/sctp_data_channel.cc | 1 - pc/sctp_transport.cc | 4 +- pc/sdp_offer_answer.cc | 65 +++++++------- pc/video_rtp_receiver.cc | 5 +- pc/video_track.cc | 3 +- rtc_base/BUILD.gn | 2 - rtc_base/fake_mdns_responder.h | 1 - rtc_base/network.cc | 2 +- rtc_base/rtc_certificate_generator.cc | 1 - rtc_base/socket_unittest.cc | 3 +- rtc_base/stream.cc | 1 - rtc_base/synchronization/BUILD.gn | 1 - rtc_base/task_queue.h | 1 - rtc_base/thread.h | 3 +- rtc_base/time_utils_unittest.cc | 1 - rtc_tools/network_tester/test_controller.cc | 6 +- sdk/android/src/jni/pc/peer_connection.cc | 4 +- sdk/objc/api/peerconnection/RTCMediaStream.mm | 22 +++-- .../api/peerconnection/RTCPeerConnection.mm | 28 +++--- sdk/objc/api/peerconnection/RTCVideoTrack.mm | 5 +- .../native/src/objc_audio_device_delegate.mm | 2 +- test/time_controller/BUILD.gn | 1 - .../time_controller_conformance_test.cc | 5 +- video/BUILD.gn | 2 - video/call_stats2.cc | 1 - video/receive_statistics_proxy2.cc | 2 +- video/rtp_video_stream_receiver2.cc | 1 - video/video_stream_encoder.cc | 1 - 54 files changed, 209 insertions(+), 320 deletions(-) diff --git a/audio/voip/BUILD.gn b/audio/voip/BUILD.gn index a70d1c382e..1b8c29e5a7 100644 --- a/audio/voip/BUILD.gn +++ b/audio/voip/BUILD.gn @@ -46,7 +46,6 @@ rtc_library("audio_channel") { "../../modules/rtp_rtcp", "../../modules/rtp_rtcp:rtp_rtcp_format", "../../rtc_base:criticalsection", - "../../rtc_base:location", "../../rtc_base:logging", "../../rtc_base:refcount", ] diff --git a/audio/voip/audio_channel.cc b/audio/voip/audio_channel.cc index 4650d195f2..a70e33ec38 100644 --- a/audio/voip/audio_channel.cc +++ b/audio/voip/audio_channel.cc @@ -17,7 +17,6 @@ #include "api/task_queue/task_queue_factory.h" #include "modules/rtp_rtcp/include/receive_statistics.h" #include "modules/rtp_rtcp/source/rtp_rtcp_impl2.h" -#include "rtc_base/location.h" #include "rtc_base/logging.h" namespace webrtc { diff --git a/call/BUILD.gn b/call/BUILD.gn index 2e24e325b2..36f42d868f 100644 --- a/call/BUILD.gn +++ b/call/BUILD.gn @@ -209,7 +209,6 @@ rtc_library("rtp_sender") { "../rtc_base", "../rtc_base:checks", "../rtc_base:event_tracer", - "../rtc_base:location", "../rtc_base:logging", "../rtc_base:macromagic", "../rtc_base:race_checker", @@ -318,7 +317,6 @@ rtc_library("call") { "../rtc_base:checks", "../rtc_base:copy_on_write_buffer", "../rtc_base:event_tracer", - "../rtc_base:location", "../rtc_base:logging", "../rtc_base:macromagic", "../rtc_base:rate_limiter", diff --git a/call/call.cc b/call/call.cc index 959d028241..ae796cf6a0 100644 --- a/call/call.cc +++ b/call/call.cc @@ -52,7 +52,6 @@ #include "modules/rtp_rtcp/source/rtp_util.h" #include "modules/video_coding/fec_controller_default.h" #include "rtc_base/checks.h" -#include "rtc_base/location.h" #include "rtc_base/logging.h" #include "rtc_base/strings/string_builder.h" #include "rtc_base/system/no_unique_address.h" diff --git a/call/degraded_call.cc b/call/degraded_call.cc index bc3f587dbc..8c3da5730f 100644 --- a/call/degraded_call.cc +++ b/call/degraded_call.cc @@ -14,7 +14,6 @@ #include #include "absl/strings/string_view.h" -#include "rtc_base/location.h" namespace webrtc { diff --git a/call/flexfec_receive_stream_impl.cc b/call/flexfec_receive_stream_impl.cc index 9e00078f96..db8b7e7edb 100644 --- a/call/flexfec_receive_stream_impl.cc +++ b/call/flexfec_receive_stream_impl.cc @@ -24,7 +24,6 @@ #include "modules/rtp_rtcp/include/receive_statistics.h" #include "modules/rtp_rtcp/source/rtp_packet_received.h" #include "rtc_base/checks.h" -#include "rtc_base/location.h" #include "rtc_base/logging.h" #include "rtc_base/strings/string_builder.h" #include "system_wrappers/include/clock.h" diff --git a/call/rtp_video_sender.cc b/call/rtp_video_sender.cc index a7e2f692ab..0e4f8d8059 100644 --- a/call/rtp_video_sender.cc +++ b/call/rtp_video_sender.cc @@ -28,7 +28,6 @@ #include "modules/rtp_rtcp/source/rtp_sender.h" #include "modules/video_coding/include/video_codec_interface.h" #include "rtc_base/checks.h" -#include "rtc_base/location.h" #include "rtc_base/logging.h" #include "rtc_base/task_queue.h" #include "rtc_base/trace_event.h" diff --git a/examples/androidvoip/jni/android_voip_client.cc b/examples/androidvoip/jni/android_voip_client.cc index 9f17ed0913..cf07e87e50 100644 --- a/examples/androidvoip/jni/android_voip_client.cc +++ b/examples/androidvoip/jni/android_voip_client.cc @@ -135,7 +135,7 @@ void AndroidVoipClient::Init( // Due to consistent thread requirement on // modules/audio_device/android/audio_device_template.h, // code is invoked in the context of voip_thread_. - voip_thread_->Invoke(RTC_FROM_HERE, [this, &config] { + voip_thread_->BlockingCall([this, &config] { RTC_DCHECK_RUN_ON(voip_thread_.get()); supported_codecs_ = config.encoder_factory->GetSupportedEncoders(); @@ -145,7 +145,7 @@ void AndroidVoipClient::Init( } AndroidVoipClient::~AndroidVoipClient() { - voip_thread_->Invoke(RTC_FROM_HERE, [this] { + voip_thread_->BlockingCall([this] { RTC_DCHECK_RUN_ON(voip_thread_.get()); JavaVM* jvm = nullptr; diff --git a/modules/pacing/BUILD.gn b/modules/pacing/BUILD.gn index 5ce38a3936..5f3556a5ca 100644 --- a/modules/pacing/BUILD.gn +++ b/modules/pacing/BUILD.gn @@ -46,7 +46,6 @@ rtc_library("pacing") { "../../logging:rtc_event_pacing", "../../rtc_base:checks", "../../rtc_base:event_tracer", - "../../rtc_base:location", "../../rtc_base:logging", "../../rtc_base:macromagic", "../../rtc_base:rtc_numerics", diff --git a/modules/video_coding/BUILD.gn b/modules/video_coding/BUILD.gn index e69fb867cd..031db70564 100644 --- a/modules/video_coding/BUILD.gn +++ b/modules/video_coding/BUILD.gn @@ -381,7 +381,6 @@ rtc_library("video_coding_legacy") { "../../modules/rtp_rtcp:rtp_video_header", "../../rtc_base:checks", "../../rtc_base:event_tracer", - "../../rtc_base:location", "../../rtc_base:logging", "../../rtc_base:macromagic", "../../rtc_base:one_time_event", @@ -1220,7 +1219,6 @@ if (rtc_include_tests) { "../../rtc_base", "../../rtc_base:checks", "../../rtc_base:histogram_percentile_counter", - "../../rtc_base:location", "../../rtc_base:platform_thread", "../../rtc_base:random", "../../rtc_base:refcount", diff --git a/modules/video_coding/jitter_buffer_unittest.cc b/modules/video_coding/jitter_buffer_unittest.cc index 930eca5d91..cc791fe110 100644 --- a/modules/video_coding/jitter_buffer_unittest.cc +++ b/modules/video_coding/jitter_buffer_unittest.cc @@ -21,7 +21,6 @@ #include "modules/video_coding/media_opt_util.h" #include "modules/video_coding/packet.h" #include "modules/video_coding/test/stream_generator.h" -#include "rtc_base/location.h" #include "system_wrappers/include/clock.h" #include "system_wrappers/include/metrics.h" #include "test/gmock.h" diff --git a/modules/video_coding/video_receiver.cc b/modules/video_coding/video_receiver.cc index 51d74c9981..38b70f87cd 100644 --- a/modules/video_coding/video_receiver.cc +++ b/modules/video_coding/video_receiver.cc @@ -30,7 +30,6 @@ #include "modules/video_coding/timing/timing.h" #include "modules/video_coding/video_coding_impl.h" #include "rtc_base/checks.h" -#include "rtc_base/location.h" #include "rtc_base/logging.h" #include "rtc_base/one_time_event.h" #include "rtc_base/trace_event.h" diff --git a/pc/BUILD.gn b/pc/BUILD.gn index e99fc01025..46bf22d16b 100644 --- a/pc/BUILD.gn +++ b/pc/BUILD.gn @@ -87,7 +87,6 @@ rtc_source_set("channel") { "../rtc_base:checks", "../rtc_base:copy_on_write_buffer", "../rtc_base:event_tracer", - "../rtc_base:location", "../rtc_base:logging", "../rtc_base:macromagic", "../rtc_base:socket", @@ -294,7 +293,6 @@ rtc_source_set("jsep_transport_controller") { "../rtc_base:checks", "../rtc_base:copy_on_write_buffer", "../rtc_base:event_tracer", - "../rtc_base:location", "../rtc_base:logging", "../rtc_base:macromagic", "../rtc_base:threading", @@ -482,7 +480,6 @@ rtc_source_set("sctp_transport") { "../p2p:rtc_p2p", "../rtc_base", "../rtc_base:checks", - "../rtc_base:location", "../rtc_base:logging", "../rtc_base:macromagic", "../rtc_base:threading", @@ -854,7 +851,6 @@ rtc_library("sctp_data_channel") { "../media:rtc_media_base", "../rtc_base:checks", "../rtc_base:copy_on_write_buffer", - "../rtc_base:location", "../rtc_base:logging", "../rtc_base:macromagic", "../rtc_base:rtc_base", @@ -935,7 +931,6 @@ rtc_source_set("data_channel_controller") { "../rtc_base", "../rtc_base:checks", "../rtc_base:copy_on_write_buffer", - "../rtc_base:location", "../rtc_base:logging", "../rtc_base:macromagic", "../rtc_base:threading", @@ -1021,7 +1016,6 @@ rtc_source_set("rtc_stats_collector") { "../rtc_base:checks", "../rtc_base:event_tracer", "../rtc_base:ip_address", - "../rtc_base:location", "../rtc_base:logging", "../rtc_base:network_constants", "../rtc_base:refcount", @@ -1107,7 +1101,6 @@ rtc_source_set("sdp_offer_answer") { "../rtc_base", "../rtc_base:checks", "../rtc_base:event_tracer", - "../rtc_base:location", "../rtc_base:logging", "../rtc_base:macromagic", "../rtc_base:rtc_operations_chain", @@ -1209,7 +1202,6 @@ rtc_source_set("peer_connection") { "../rtc_base:copy_on_write_buffer", "../rtc_base:event_tracer", "../rtc_base:ip_address", - "../rtc_base:location", "../rtc_base:logging", "../rtc_base:macromagic", "../rtc_base:network_constants", @@ -1294,7 +1286,6 @@ rtc_source_set("legacy_stats_collector") { "../rtc_base:checks", "../rtc_base:event_tracer", "../rtc_base:ip_address", - "../rtc_base:location", "../rtc_base:logging", "../rtc_base:macromagic", "../rtc_base:network_constants", @@ -1484,7 +1475,6 @@ rtc_source_set("peer_connection_factory") { "../pc:session_description", "../pc:video_track", "../rtc_base:checks", - "../rtc_base:location", "../rtc_base:logging", "../rtc_base:macromagic", "../rtc_base:rtc_base", @@ -1561,7 +1551,6 @@ rtc_library("rtp_transceiver") { "../api/video:video_bitrate_allocator_factory", "../media:rtc_media_base", "../rtc_base:checks", - "../rtc_base:location", "../rtc_base:logging", "../rtc_base:macromagic", "../rtc_base:threading", @@ -1693,7 +1682,6 @@ rtc_library("audio_rtp_receiver") { "../media:rtc_media_base", "../rtc_base", "../rtc_base:checks", - "../rtc_base:location", "../rtc_base:macromagic", "../rtc_base:threading", "../rtc_base/system:no_unique_address", @@ -1732,7 +1720,6 @@ rtc_library("video_rtp_receiver") { "../media:rtc_media_base", "../rtc_base", "../rtc_base:checks", - "../rtc_base:location", "../rtc_base:logging", "../rtc_base:macromagic", "../rtc_base:threading", @@ -1795,7 +1782,6 @@ rtc_library("video_track") { "../media:rtc_media_base", "../rtc_base", "../rtc_base:checks", - "../rtc_base:location", "../rtc_base:macromagic", "../rtc_base:threading", "../rtc_base/system:no_unique_address", @@ -1877,7 +1863,6 @@ rtc_library("rtp_sender") { "../media:rtc_media_base", "../rtc_base:checks", "../rtc_base:event_tracer", - "../rtc_base:location", "../rtc_base:logging", "../rtc_base:macromagic", "../rtc_base:rtc_base", @@ -1932,7 +1917,6 @@ rtc_library("dtmf_sender") { "../api/task_queue:pending_task_safety_flag", "../api/units:time_delta", "../rtc_base:checks", - "../rtc_base:location", "../rtc_base:logging", "../rtc_base:macromagic", "../rtc_base:refcount", diff --git a/pc/audio_rtp_receiver.cc b/pc/audio_rtp_receiver.cc index e58b74ec72..0dbdf0b713 100644 --- a/pc/audio_rtp_receiver.cc +++ b/pc/audio_rtp_receiver.cc @@ -20,7 +20,6 @@ #include "pc/audio_track.h" #include "pc/media_stream_track_proxy.h" #include "rtc_base/checks.h" -#include "rtc_base/location.h" namespace webrtc { @@ -101,7 +100,7 @@ void AudioRtpReceiver::OnSetVolume(double volume) { RTC_DCHECK_LE(volume, 10); bool track_enabled = track_->internal()->enabled(); - worker_thread_->Invoke(RTC_FROM_HERE, [&]() { + worker_thread_->BlockingCall([&]() { RTC_DCHECK_RUN_ON(worker_thread_); // Update the cached_volume_ even when stopped, to allow clients to set // the volume before starting/restarting, eg see crbug.com/1272566. @@ -168,7 +167,7 @@ void AudioRtpReceiver::RestartMediaChannel(absl::optional ssrc) { RTC_DCHECK_RUN_ON(&signaling_thread_checker_); bool enabled = track_->internal()->enabled(); MediaSourceInterface::SourceState state = source_->state(); - worker_thread_->Invoke(RTC_FROM_HERE, [&]() { + worker_thread_->BlockingCall([&]() { RTC_DCHECK_RUN_ON(worker_thread_); RestartMediaChannel_w(std::move(ssrc), enabled, state); }); diff --git a/pc/channel.cc b/pc/channel.cc index 077731493e..0e2345b2c9 100644 --- a/pc/channel.cc +++ b/pc/channel.cc @@ -29,7 +29,6 @@ #include "pc/rtp_media_utils.h" #include "rtc_base/checks.h" #include "rtc_base/copy_on_write_buffer.h" -#include "rtc_base/location.h" #include "rtc_base/logging.h" #include "rtc_base/network_route.h" #include "rtc_base/strings/string_format.h" @@ -269,8 +268,8 @@ bool BaseChannel::SetPayloadTypeDemuxingEnabled(bool enabled) { // network thread. At the moment there's a workaround for inconsistent state // between the worker and network thread because of this (see // OnDemuxerCriteriaUpdatePending elsewhere in this file) and - // SetPayloadTypeDemuxingEnabled_w has an Invoke over to the network thread - // to apply state updates. + // SetPayloadTypeDemuxingEnabled_w has a BlockingCall over to the network + // thread to apply state updates. RTC_DCHECK_RUN_ON(worker_thread()); TRACE_EVENT0("webrtc", "BaseChannel::SetPayloadTypeDemuxingEnabled"); return SetPayloadTypeDemuxingEnabled_w(enabled); @@ -461,7 +460,7 @@ bool BaseChannel::MaybeUpdateDemuxerAndRtpExtensions_w( if (update_demuxer) media_channel()->OnDemuxerCriteriaUpdatePending(); - bool success = network_thread()->Invoke(RTC_FROM_HERE, [&]() mutable { + bool success = network_thread()->BlockingCall([&]() mutable { RTC_DCHECK_RUN_ON(network_thread()); // NOTE: This doesn't take the BUNDLE case in account meaning the RTP header // extension maps are not merged when BUNDLE is enabled. This is fine @@ -491,8 +490,8 @@ bool BaseChannel::RegisterRtpDemuxerSink_w() { media_channel_->OnDemuxerCriteriaUpdatePending(); // Copy demuxer criteria, since they're a worker-thread variable // and we want to pass them to the network thread - bool ret = network_thread_->Invoke( - RTC_FROM_HERE, [this, demuxer_criteria = demuxer_criteria_] { + bool ret = network_thread_->BlockingCall( + [this, demuxer_criteria = demuxer_criteria_] { RTC_DCHECK_RUN_ON(network_thread()); if (!rtp_transport_) { // Transport was disconnected before attempting to update the diff --git a/pc/connection_context.cc b/pc/connection_context.cc index 13c598ae87..ec6f21cc13 100644 --- a/pc/connection_context.cc +++ b/pc/connection_context.cc @@ -167,13 +167,13 @@ ConnectionContext::ConnectionContext( if (media_engine_) { // TODO(tommi): Change VoiceEngine to do ctor time initialization so that // this isn't necessary. - worker_thread_->Invoke(RTC_FROM_HERE, [&] { media_engine_->Init(); }); + worker_thread_->BlockingCall([&] { media_engine_->Init(); }); } } ConnectionContext::~ConnectionContext() { RTC_DCHECK_RUN_ON(signaling_thread_); - worker_thread_->Invoke(RTC_FROM_HERE, [&] { + worker_thread_->BlockingCall([&] { RTC_DCHECK_RUN_ON(worker_thread()); // While `media_engine_` is const throughout the ConnectionContext's // lifetime, it requires destruction to happen on the worker thread. Instead diff --git a/pc/data_channel_controller.cc b/pc/data_channel_controller.cc index b655b530a5..36f11fe12e 100644 --- a/pc/data_channel_controller.cc +++ b/pc/data_channel_controller.cc @@ -16,7 +16,6 @@ #include "api/rtc_error.h" #include "pc/peer_connection_internal.h" #include "pc/sctp_utils.h" -#include "rtc_base/location.h" #include "rtc_base/logging.h" namespace webrtc { @@ -81,7 +80,7 @@ void DataChannelController::DisconnectDataChannel( void DataChannelController::AddSctpDataStream(int sid) { if (data_channel_transport()) { - network_thread()->Invoke(RTC_FROM_HERE, [this, sid] { + network_thread()->BlockingCall([this, sid] { if (data_channel_transport()) { data_channel_transport()->OpenChannel(sid); } @@ -91,7 +90,7 @@ void DataChannelController::AddSctpDataStream(int sid) { void DataChannelController::RemoveSctpDataStream(int sid) { if (data_channel_transport()) { - network_thread()->Invoke(RTC_FROM_HERE, [this, sid] { + network_thread()->BlockingCall([this, sid] { if (data_channel_transport()) { data_channel_transport()->CloseChannel(sid); } @@ -382,15 +381,14 @@ bool DataChannelController::DataChannelSendData( const rtc::CopyOnWriteBuffer& payload, cricket::SendDataResult* result) { // TODO(bugs.webrtc.org/11547): Expect method to be called on the network - // thread instead. Remove the Invoke() below and move assocated state to + // thread instead. Remove the BlockingCall() below and move assocated state to // the network thread. RTC_DCHECK_RUN_ON(signaling_thread()); RTC_DCHECK(data_channel_transport()); - RTCError error = network_thread()->Invoke( - RTC_FROM_HERE, [this, sid, params, payload] { - return data_channel_transport()->SendData(sid, params, payload); - }); + RTCError error = network_thread()->BlockingCall([this, sid, params, payload] { + return data_channel_transport()->SendData(sid, params, payload); + }); if (error.ok()) { *result = cricket::SendDataResult::SDR_SUCCESS; diff --git a/pc/dtmf_sender.cc b/pc/dtmf_sender.cc index c3bd4b6b7b..45a4a58abb 100644 --- a/pc/dtmf_sender.cc +++ b/pc/dtmf_sender.cc @@ -142,7 +142,7 @@ bool DtmfSender::InsertDtmf(const std::string& tones, } safety_flag_ = PendingTaskSafetyFlag::Create(); // Kick off a new DTMF task. - QueueInsertDtmf(RTC_FROM_HERE, 1 /*ms*/); + QueueInsertDtmf(1 /*ms*/); return true; } @@ -166,8 +166,7 @@ int DtmfSender::comma_delay() const { return comma_delay_; } -void DtmfSender::QueueInsertDtmf(const rtc::Location& posted_from, - uint32_t delay_ms) { +void DtmfSender::QueueInsertDtmf(uint32_t delay_ms) { signaling_thread_->PostDelayedHighPrecisionTask( SafeTask(safety_flag_, [this] { @@ -232,7 +231,7 @@ void DtmfSender::DoInsertDtmf() { tones_.erase(0, first_tone_pos + 1); // Continue with the next tone. - QueueInsertDtmf(RTC_FROM_HERE, tone_gap); + QueueInsertDtmf(tone_gap); } void DtmfSender::StopSending() { diff --git a/pc/dtmf_sender.h b/pc/dtmf_sender.h index c295f032f9..c99c7bee50 100644 --- a/pc/dtmf_sender.h +++ b/pc/dtmf_sender.h @@ -21,7 +21,6 @@ #include "api/task_queue/pending_task_safety_flag.h" #include "api/task_queue/task_queue_base.h" #include "pc/proxy.h" -#include "rtc_base/location.h" #include "rtc_base/ref_count.h" #include "rtc_base/thread_annotations.h" @@ -77,8 +76,7 @@ class DtmfSender : public DtmfSenderInterface { private: DtmfSender(); - void QueueInsertDtmf(const rtc::Location& posted_from, uint32_t delay_ms) - RTC_RUN_ON(signaling_thread_); + void QueueInsertDtmf(uint32_t delay_ms) RTC_RUN_ON(signaling_thread_); // The DTMF sending task. void DoInsertDtmf() RTC_RUN_ON(signaling_thread_); diff --git a/pc/jsep_transport_controller.cc b/pc/jsep_transport_controller.cc index 7b445741a2..95ab7991c7 100644 --- a/pc/jsep_transport_controller.cc +++ b/pc/jsep_transport_controller.cc @@ -29,7 +29,6 @@ #include "p2p/base/p2p_constants.h" #include "p2p/base/port.h" #include "rtc_base/checks.h" -#include "rtc_base/location.h" #include "rtc_base/logging.h" #include "rtc_base/thread.h" #include "rtc_base/trace_event.h" @@ -77,8 +76,8 @@ RTCError JsepTransportController::SetLocalDescription( const cricket::SessionDescription* description) { TRACE_EVENT0("webrtc", "JsepTransportController::SetLocalDescription"); if (!network_thread_->IsCurrent()) { - return network_thread_->Invoke( - RTC_FROM_HERE, [=] { return SetLocalDescription(type, description); }); + return network_thread_->BlockingCall( + [=] { return SetLocalDescription(type, description); }); } RTC_DCHECK_RUN_ON(network_thread_); @@ -98,8 +97,8 @@ RTCError JsepTransportController::SetRemoteDescription( const cricket::SessionDescription* description) { TRACE_EVENT0("webrtc", "JsepTransportController::SetRemoteDescription"); if (!network_thread_->IsCurrent()) { - return network_thread_->Invoke( - RTC_FROM_HERE, [=] { return SetRemoteDescription(type, description); }); + return network_thread_->BlockingCall( + [=] { return SetRemoteDescription(type, description); }); } RTC_DCHECK_RUN_ON(network_thread_); @@ -199,8 +198,7 @@ absl::optional JsepTransportController::GetDtlsRole( // thread during negotiations, potentially multiple times. // WebRtcSessionDescriptionFactory::InternalCreateAnswer is one example. if (!network_thread_->IsCurrent()) { - return network_thread_->Invoke>( - RTC_FROM_HERE, [&] { return GetDtlsRole(mid); }); + return network_thread_->BlockingCall([&] { return GetDtlsRole(mid); }); } RTC_DCHECK_RUN_ON(network_thread_); @@ -215,8 +213,8 @@ absl::optional JsepTransportController::GetDtlsRole( bool JsepTransportController::SetLocalCertificate( const rtc::scoped_refptr& certificate) { if (!network_thread_->IsCurrent()) { - return network_thread_->Invoke( - RTC_FROM_HERE, [&] { return SetLocalCertificate(certificate); }); + return network_thread_->BlockingCall( + [&] { return SetLocalCertificate(certificate); }); } RTC_DCHECK_RUN_ON(network_thread_); @@ -274,8 +272,7 @@ JsepTransportController::GetRemoteSSLCertChain( void JsepTransportController::MaybeStartGathering() { if (!network_thread_->IsCurrent()) { - network_thread_->Invoke(RTC_FROM_HERE, - [&] { MaybeStartGathering(); }); + network_thread_->BlockingCall([&] { MaybeStartGathering(); }); return; } @@ -301,8 +298,8 @@ RTCError JsepTransportController::AddRemoteCandidates( RTCError JsepTransportController::RemoveRemoteCandidates( const cricket::Candidates& candidates) { if (!network_thread_->IsCurrent()) { - return network_thread_->Invoke( - RTC_FROM_HERE, [&] { return RemoveRemoteCandidates(candidates); }); + return network_thread_->BlockingCall( + [&] { return RemoveRemoteCandidates(candidates); }); } RTC_DCHECK_RUN_ON(network_thread_); @@ -361,9 +358,8 @@ bool JsepTransportController::GetStats(const std::string& transport_name, void JsepTransportController::SetActiveResetSrtpParams( bool active_reset_srtp_params) { if (!network_thread_->IsCurrent()) { - network_thread_->Invoke(RTC_FROM_HERE, [=] { - SetActiveResetSrtpParams(active_reset_srtp_params); - }); + network_thread_->BlockingCall( + [=] { SetActiveResetSrtpParams(active_reset_srtp_params); }); return; } RTC_DCHECK_RUN_ON(network_thread_); @@ -378,8 +374,7 @@ void JsepTransportController::SetActiveResetSrtpParams( RTCError JsepTransportController::RollbackTransports() { if (!network_thread_->IsCurrent()) { - return network_thread_->Invoke( - RTC_FROM_HERE, [=] { return RollbackTransports(); }); + return network_thread_->BlockingCall([=] { return RollbackTransports(); }); } RTC_DCHECK_RUN_ON(network_thread_); bundles_.Rollback(); diff --git a/pc/legacy_stats_collector.cc b/pc/legacy_stats_collector.cc index 393e0efe7e..b710bc16e6 100644 --- a/pc/legacy_stats_collector.cc +++ b/pc/legacy_stats_collector.cc @@ -46,7 +46,6 @@ #include "pc/transport_stats.h" #include "rtc_base/checks.h" #include "rtc_base/ip_address.h" -#include "rtc_base/location.h" #include "rtc_base/logging.h" #include "rtc_base/rtc_certificate.h" #include "rtc_base/socket_address.h" @@ -861,9 +860,9 @@ std::map LegacyStatsCollector::ExtractSessionInfo() { SessionStats stats; auto transceivers = pc_->GetTransceiversInternal(); - pc_->network_thread()->Invoke( - RTC_FROM_HERE, [&, sctp_transport_name = pc_->sctp_transport_name(), - sctp_mid = pc_->sctp_mid()]() mutable { + pc_->network_thread()->BlockingCall( + [&, sctp_transport_name = pc_->sctp_transport_name(), + sctp_mid = pc_->sctp_mid()]() mutable { stats = ExtractSessionInfo_n( transceivers, std::move(sctp_transport_name), std::move(sctp_mid)); }); @@ -1049,7 +1048,7 @@ void LegacyStatsCollector::ExtractBweInfo() { } if (!video_media_channels.empty()) { - pc_->worker_thread()->Invoke(RTC_FROM_HERE, [&] { + pc_->worker_thread()->BlockingCall([&] { for (const auto& channel : video_media_channels) { channel->FillBitrateInfo(&bwe_info); } @@ -1200,7 +1199,7 @@ void LegacyStatsCollector::ExtractMediaInfo( } } - pc_->worker_thread()->Invoke(RTC_FROM_HERE, [&] { + pc_->worker_thread()->BlockingCall([&] { rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls; // Populate `receiver_track_id_by_ssrc` for the gatherers. int i = 0; diff --git a/pc/peer_connection.cc b/pc/peer_connection.cc index 1c0e695158..517669d226 100644 --- a/pc/peer_connection.cc +++ b/pc/peer_connection.cc @@ -52,7 +52,6 @@ #include "pc/webrtc_session_description_factory.h" #include "rtc_base/helpers.h" #include "rtc_base/ip_address.h" -#include "rtc_base/location.h" #include "rtc_base/logging.h" #include "rtc_base/net_helper.h" #include "rtc_base/network.h" @@ -525,7 +524,7 @@ PeerConnection::PeerConnection( data_channel_controller_(this), message_handler_(signaling_thread()), weak_factory_(this) { - worker_thread()->Invoke(RTC_FROM_HERE, [this] { + worker_thread()->BlockingCall([this] { RTC_DCHECK_RUN_ON(worker_thread()); worker_thread_safety_ = PendingTaskSafetyFlag::Create(); if (!call_) @@ -569,7 +568,7 @@ PeerConnection::~PeerConnection() { // port_allocator_ and transport_controller_ live on the network thread and // should be destroyed there. transport_controller_copy_ = nullptr; - network_thread()->Invoke(RTC_FROM_HERE, [this] { + network_thread()->BlockingCall([this] { RTC_DCHECK_RUN_ON(network_thread()); TeardownDataChannelTransport_n(); transport_controller_.reset(); @@ -579,7 +578,7 @@ PeerConnection::~PeerConnection() { }); // call_ and event_log_ must be destroyed on the worker thread. - worker_thread()->Invoke(RTC_FROM_HERE, [this] { + worker_thread()->BlockingCall([this] { RTC_DCHECK_RUN_ON(worker_thread()); worker_thread_safety_->SetNotAlive(); call_.reset(); @@ -618,7 +617,7 @@ RTCError PeerConnection::Initialize( // Network thread initialization. transport_controller_copy_ = - network_thread()->Invoke(RTC_FROM_HERE, [&] { + network_thread()->BlockingCall([&] { RTC_DCHECK_RUN_ON(network_thread()); network_thread_safety_ = PendingTaskSafetyFlag::Create(); InitializePortAllocatorResult pa_result = InitializePortAllocator_n( @@ -940,13 +939,12 @@ RtpTransportInternal* PeerConnection::GetRtpTransport(const std::string& mid) { // TODO(bugs.webrtc.org/9987): Avoid the thread jump. // This might be done by caching the value on the signaling thread. RTC_DCHECK_RUN_ON(signaling_thread()); - return network_thread()->Invoke( - RTC_FROM_HERE, [this, &mid] { - RTC_DCHECK_RUN_ON(network_thread()); - auto rtp_transport = transport_controller_->GetRtpTransport(mid); - RTC_DCHECK(rtp_transport); - return rtp_transport; - }); + return network_thread()->BlockingCall([this, &mid] { + RTC_DCHECK_RUN_ON(network_thread()); + auto rtp_transport = transport_controller_->GetRtpTransport(mid); + RTC_DCHECK(rtp_transport); + return rtp_transport; + }); } RTCErrorOr> @@ -1556,8 +1554,7 @@ RTCError PeerConnection::SetConfiguration( // Apply part of the configuration on the network thread. In theory this // shouldn't fail. - if (!network_thread()->Invoke( - RTC_FROM_HERE, + if (!network_thread()->BlockingCall( [this, needs_ice_restart, &ice_config, &stun_servers, &turn_servers, &modified_config, has_local_description] { RTC_DCHECK_RUN_ON(network_thread()); @@ -1583,8 +1580,8 @@ RTCError PeerConnection::SetConfiguration( if (configuration_.active_reset_srtp_params != modified_config.active_reset_srtp_params) { - // TODO(tommi): merge invokes - network_thread()->Invoke(RTC_FROM_HERE, [this, &modified_config] { + // TODO(tommi): merge BlockingCalls + network_thread()->BlockingCall([this, &modified_config] { RTC_DCHECK_RUN_ON(network_thread()); transport_controller_->SetActiveResetSrtpParams( modified_config.active_reset_srtp_params); @@ -1603,8 +1600,7 @@ RTCError PeerConnection::SetConfiguration( video_channel->media_channel())); } - worker_thread()->Invoke( - RTC_FROM_HERE, + worker_thread()->BlockingCall( [channels = std::move(channels), allow_codec_switching = *modified_config.allow_codec_switching]() { for (auto* ch : channels) @@ -1643,8 +1639,7 @@ bool PeerConnection::RemoveIceCandidates( RTCError PeerConnection::SetBitrate(const BitrateSettings& bitrate) { if (!worker_thread()->IsCurrent()) { - return worker_thread()->Invoke( - RTC_FROM_HERE, [&]() { return SetBitrate(bitrate); }); + return worker_thread()->BlockingCall([&]() { return SetBitrate(bitrate); }); } RTC_DCHECK_RUN_ON(worker_thread()); @@ -1685,8 +1680,8 @@ RTCError PeerConnection::SetBitrate(const BitrateSettings& bitrate) { void PeerConnection::SetAudioPlayout(bool playout) { if (!worker_thread()->IsCurrent()) { - worker_thread()->Invoke( - RTC_FROM_HERE, [this, playout] { SetAudioPlayout(playout); }); + worker_thread()->BlockingCall( + [this, playout] { SetAudioPlayout(playout); }); return; } auto audio_state = context_->media_engine()->voice().GetAudioState(); @@ -1695,8 +1690,8 @@ void PeerConnection::SetAudioPlayout(bool playout) { void PeerConnection::SetAudioRecording(bool recording) { if (!worker_thread()->IsCurrent()) { - worker_thread()->Invoke( - RTC_FROM_HERE, [this, recording] { SetAudioRecording(recording); }); + worker_thread()->BlockingCall( + [this, recording] { SetAudioRecording(recording); }); return; } auto audio_state = context_->media_engine()->voice().GetAudioState(); @@ -1706,9 +1701,8 @@ void PeerConnection::SetAudioRecording(bool recording) { void PeerConnection::AddAdaptationResource( rtc::scoped_refptr resource) { if (!worker_thread()->IsCurrent()) { - return worker_thread()->Invoke(RTC_FROM_HERE, [this, resource]() { - return AddAdaptationResource(resource); - }); + return worker_thread()->BlockingCall( + [this, resource]() { return AddAdaptationResource(resource); }); } RTC_DCHECK_RUN_ON(worker_thread()); if (!call_) { @@ -1724,8 +1718,7 @@ bool PeerConnection::ConfiguredForMedia() const { bool PeerConnection::StartRtcEventLog(std::unique_ptr output, int64_t output_period_ms) { - return worker_thread()->Invoke( - RTC_FROM_HERE, + return worker_thread()->BlockingCall( [this, output = std::move(output), output_period_ms]() mutable { return StartRtcEventLog_w(std::move(output), output_period_ms); }); @@ -1741,7 +1734,7 @@ bool PeerConnection::StartRtcEventLog( } void PeerConnection::StopRtcEventLog() { - worker_thread()->Invoke(RTC_FROM_HERE, [this] { StopRtcEventLog_w(); }); + worker_thread()->BlockingCall([this] { StopRtcEventLog_w(); }); } rtc::scoped_refptr @@ -1755,11 +1748,10 @@ PeerConnection::LookupDtlsTransportByMidInternal(const std::string& mid) { RTC_DCHECK_RUN_ON(signaling_thread()); // TODO(bugs.webrtc.org/9987): Avoid the thread jump. // This might be done by caching the value on the signaling thread. - return network_thread()->Invoke>( - RTC_FROM_HERE, [this, mid]() { - RTC_DCHECK_RUN_ON(network_thread()); - return transport_controller_->LookupDtlsTransportByMid(mid); - }); + return network_thread()->BlockingCall([this, mid]() { + RTC_DCHECK_RUN_ON(network_thread()); + return transport_controller_->LookupDtlsTransportByMid(mid); + }); } rtc::scoped_refptr PeerConnection::GetSctpTransport() @@ -1856,7 +1848,7 @@ void PeerConnection::Close() { rtp_manager_->Close(); } - network_thread()->Invoke(RTC_FROM_HERE, [this] { + network_thread()->BlockingCall([this] { // Data channels will already have been unset via the DestroyAllChannels() // call above, which triggers a call to TeardownDataChannelTransport_n(). // TODO(tommi): ^^ That's not exactly optimal since this is yet another @@ -1870,7 +1862,7 @@ void PeerConnection::Close() { } }); - worker_thread()->Invoke(RTC_FROM_HERE, [this] { + worker_thread()->BlockingCall([this] { RTC_DCHECK_RUN_ON(worker_thread()); worker_thread_safety_->SetNotAlive(); call_.reset(); @@ -2225,11 +2217,10 @@ bool PeerConnection::GetSctpSslRole(rtc::SSLRole* role) { absl::optional dtls_role; if (sctp_mid_s_) { - dtls_role = network_thread()->Invoke>( - RTC_FROM_HERE, [this] { - RTC_DCHECK_RUN_ON(network_thread()); - return transport_controller_->GetDtlsRole(*sctp_mid_n_); - }); + dtls_role = network_thread()->BlockingCall([this] { + RTC_DCHECK_RUN_ON(network_thread()); + return transport_controller_->GetDtlsRole(*sctp_mid_n_); + }); if (!dtls_role && sdp_handler_->is_caller().has_value()) { // This works fine if we are the offerer, but can be a mistake if // we are the answerer and the remote offer is ACTIVE. In that @@ -2259,11 +2250,10 @@ bool PeerConnection::GetSslRole(const std::string& content_name, return false; } - auto dtls_role = network_thread()->Invoke>( - RTC_FROM_HERE, [this, content_name]() { - RTC_DCHECK_RUN_ON(network_thread()); - return transport_controller_->GetDtlsRole(content_name); - }); + auto dtls_role = network_thread()->BlockingCall([this, content_name]() { + RTC_DCHECK_RUN_ON(network_thread()); + return transport_controller_->GetDtlsRole(content_name); + }); if (dtls_role) { *role = *dtls_role; return true; @@ -2360,7 +2350,7 @@ bool PeerConnection::IceRestartPending(const std::string& content_name) const { } bool PeerConnection::NeedsIceRestart(const std::string& content_name) const { - return network_thread()->Invoke(RTC_FROM_HERE, [this, &content_name] { + return network_thread()->BlockingCall([this, &content_name] { RTC_DCHECK_RUN_ON(network_thread()); return transport_controller_->NeedsIceRestart(content_name); }); @@ -2489,8 +2479,7 @@ bool PeerConnection::GetLocalCandidateMediaIndex( Call::Stats PeerConnection::GetCallStats() { if (!worker_thread()->IsCurrent()) { - return worker_thread()->Invoke( - RTC_FROM_HERE, [this] { return GetCallStats(); }); + return worker_thread()->BlockingCall([this] { return GetCallStats(); }); } RTC_DCHECK_RUN_ON(worker_thread()); rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls; diff --git a/pc/peer_connection_factory.cc b/pc/peer_connection_factory.cc index 6460a904f3..cec909f03e 100644 --- a/pc/peer_connection_factory.cc +++ b/pc/peer_connection_factory.cc @@ -46,7 +46,6 @@ #include "rtc_base/checks.h" #include "rtc_base/experiments/field_trial_parser.h" #include "rtc_base/experiments/field_trial_units.h" -#include "rtc_base/location.h" #include "rtc_base/logging.h" #include "rtc_base/numerics/safe_conversions.h" #include "rtc_base/rtc_certificate_generator.h" @@ -60,12 +59,9 @@ CreateModularPeerConnectionFactory( // The PeerConnectionFactory must be created on the signaling thread. if (dependencies.signaling_thread && !dependencies.signaling_thread->IsCurrent()) { - return dependencies.signaling_thread - ->Invoke>( - RTC_FROM_HERE, [&dependencies] { - return CreateModularPeerConnectionFactory( - std::move(dependencies)); - }); + return dependencies.signaling_thread->BlockingCall([&dependencies] { + return CreateModularPeerConnectionFactory(std::move(dependencies)); + }); } auto pc_factory = PeerConnectionFactory::Create(std::move(dependencies)); @@ -238,13 +234,12 @@ PeerConnectionFactory::CreatePeerConnectionOrError( dependencies.allocator->SetVpnList(configuration.vpn_list); std::unique_ptr event_log = - worker_thread()->Invoke>( - RTC_FROM_HERE, [this] { return CreateRtcEventLog_w(); }); + worker_thread()->BlockingCall([this] { return CreateRtcEventLog_w(); }); const FieldTrialsView* trials = dependencies.trials ? dependencies.trials.get() : &field_trials(); - std::unique_ptr call = worker_thread()->Invoke>( - RTC_FROM_HERE, [this, &event_log, trials] { + std::unique_ptr call = + worker_thread()->BlockingCall([this, &event_log, trials] { return CreateCall_w(event_log.get(), *trials); }); diff --git a/pc/rtc_stats_collector.cc b/pc/rtc_stats_collector.cc index 15e72c4530..c27533a9fe 100644 --- a/pc/rtc_stats_collector.cc +++ b/pc/rtc_stats_collector.cc @@ -50,7 +50,6 @@ #include "pc/webrtc_sdp.h" #include "rtc_base/checks.h" #include "rtc_base/ip_address.h" -#include "rtc_base/location.h" #include "rtc_base/logging.h" #include "rtc_base/network_constants.h" #include "rtc_base/rtc_certificate.h" @@ -2316,9 +2315,9 @@ void RTCStatsCollector::PrepareTransceiverStatsInfosAndCallStats_s_w_n() { auto transceivers = pc_->GetTransceiversInternal(); // TODO(tommi): See if we can avoid synchronously blocking the signaling - // thread while we do this (or avoid the Invoke at all). - network_thread_->Invoke(RTC_FROM_HERE, [this, &transceivers, - &voice_stats, &video_stats] { + // thread while we do this (or avoid the BlockingCall at all). + network_thread_->BlockingCall([this, &transceivers, &voice_stats, + &video_stats] { rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls; for (const auto& transceiver_proxy : transceivers) { @@ -2363,7 +2362,7 @@ void RTCStatsCollector::PrepareTransceiverStatsInfosAndCallStats_s_w_n() { // well as GetCallStats(). At the same time we construct the // TrackMediaInfoMaps, which also needs info from the worker thread. This // minimizes the number of thread jumps. - worker_thread_->Invoke(RTC_FROM_HERE, [&] { + worker_thread_->BlockingCall([&] { rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls; for (auto& pair : voice_stats) { diff --git a/pc/rtp_sender.cc b/pc/rtp_sender.cc index b42e439b2e..aa640f3829 100644 --- a/pc/rtp_sender.cc +++ b/pc/rtp_sender.cc @@ -24,7 +24,6 @@ #include "pc/legacy_stats_collector_interface.h" #include "rtc_base/checks.h" #include "rtc_base/helpers.h" -#include "rtc_base/location.h" #include "rtc_base/logging.h" #include "rtc_base/trace_event.h" @@ -125,9 +124,8 @@ void RtpSenderBase::SetFrameEncryptor( frame_encryptor_ = std::move(frame_encryptor); // Special Case: Set the frame encryptor to any value on any existing channel. if (media_channel_ && ssrc_ && !stopped_) { - worker_thread_->Invoke(RTC_FROM_HERE, [&] { - media_channel_->SetFrameEncryptor(ssrc_, frame_encryptor_); - }); + worker_thread_->BlockingCall( + [&] { media_channel_->SetFrameEncryptor(ssrc_, frame_encryptor_); }); } } @@ -142,7 +140,7 @@ void RtpSenderBase::SetEncoderSelector( void RtpSenderBase::SetEncoderSelectorOnChannel() { RTC_DCHECK_RUN_ON(signaling_thread_); if (media_channel_ && ssrc_ && !stopped_) { - worker_thread_->Invoke(RTC_FROM_HERE, [&] { + worker_thread_->BlockingCall([&] { media_channel_->SetEncoderSelector(ssrc_, encoder_selector_.get()); }); } @@ -162,7 +160,7 @@ RtpParameters RtpSenderBase::GetParametersInternal() const { if (!media_channel_ || !ssrc_) { return init_parameters_; } - return worker_thread_->Invoke(RTC_FROM_HERE, [&] { + return worker_thread_->BlockingCall([&] { RtpParameters result = media_channel_->GetRtpSendParameters(ssrc_); RemoveEncodingLayers(disabled_rids_, &result.encodings); return result; @@ -177,7 +175,7 @@ RtpParameters RtpSenderBase::GetParametersInternalWithAllLayers() const { if (!media_channel_ || !ssrc_) { return init_parameters_; } - return worker_thread_->Invoke(RTC_FROM_HERE, [&] { + return worker_thread_->BlockingCall([&] { RtpParameters result = media_channel_->GetRtpSendParameters(ssrc_); return result; }); @@ -208,7 +206,7 @@ RTCError RtpSenderBase::SetParametersInternal(const RtpParameters& parameters) { } return result; } - return worker_thread_->Invoke(RTC_FROM_HERE, [&] { + return worker_thread_->BlockingCall([&] { RtpParameters rtp_parameters = parameters; if (!disabled_rids_.empty()) { // Need to add the inactive layers. @@ -239,7 +237,7 @@ RTCError RtpSenderBase::SetParametersInternalWithAllLayers( } return result; } - return worker_thread_->Invoke(RTC_FROM_HERE, [&] { + return worker_thread_->BlockingCall([&] { RtpParameters rtp_parameters = parameters; return media_channel_->SetRtpSendParameters(ssrc_, rtp_parameters); }); @@ -345,7 +343,7 @@ void RtpSenderBase::SetSsrc(uint32_t ssrc) { } if (!init_parameters_.encodings.empty() || init_parameters_.degradation_preference.has_value()) { - worker_thread_->Invoke(RTC_FROM_HERE, [&] { + worker_thread_->BlockingCall([&] { RTC_DCHECK(media_channel_); // Get the current parameters, which are constructed from the SDP. // The number of layers in the SDP is currently authoritative to support @@ -454,7 +452,7 @@ void RtpSenderBase::SetEncoderToPacketizerFrameTransformer( RTC_DCHECK_RUN_ON(signaling_thread_); frame_transformer_ = std::move(frame_transformer); if (media_channel_ && ssrc_ && !stopped_) { - worker_thread_->Invoke(RTC_FROM_HERE, [&] { + worker_thread_->BlockingCall([&] { media_channel_->SetEncoderToPacketizerFrameTransformer( ssrc_, frame_transformer_); }); @@ -526,8 +524,8 @@ bool AudioRtpSender::CanInsertDtmf() { RTC_LOG(LS_ERROR) << "CanInsertDtmf: Sender does not have SSRC."; return false; } - return worker_thread_->Invoke( - RTC_FROM_HERE, [&] { return voice_media_channel()->CanInsertDtmf(); }); + return worker_thread_->BlockingCall( + [&] { return voice_media_channel()->CanInsertDtmf(); }); } bool AudioRtpSender::InsertDtmf(int code, int duration) { @@ -539,9 +537,8 @@ bool AudioRtpSender::InsertDtmf(int code, int duration) { RTC_LOG(LS_ERROR) << "InsertDtmf: Sender does not have SSRC."; return false; } - bool success = worker_thread_->Invoke(RTC_FROM_HERE, [&] { - return voice_media_channel()->InsertDtmf(ssrc_, code, duration); - }); + bool success = worker_thread_->BlockingCall( + [&] { return voice_media_channel()->InsertDtmf(ssrc_, code, duration); }); if (!success) { RTC_LOG(LS_ERROR) << "Failed to insert DTMF to channel."; } @@ -610,7 +607,7 @@ void AudioRtpSender::SetSend() { // `track_->enabled()` hops to the signaling thread, so call it before we hop // to the worker thread or else it will deadlock. bool track_enabled = track_->enabled(); - bool success = worker_thread_->Invoke(RTC_FROM_HERE, [&] { + bool success = worker_thread_->BlockingCall([&] { return voice_media_channel()->SetAudioSend(ssrc_, track_enabled, &options, sink_adapter_.get()); }); @@ -628,7 +625,7 @@ void AudioRtpSender::ClearSend() { return; } cricket::AudioOptions options; - bool success = worker_thread_->Invoke(RTC_FROM_HERE, [&] { + bool success = worker_thread_->BlockingCall([&] { return voice_media_channel()->SetAudioSend(ssrc_, false, &options, nullptr); }); if (!success) { @@ -704,7 +701,7 @@ void VideoRtpSender::SetSend() { options.is_screencast = true; break; } - bool success = worker_thread_->Invoke(RTC_FROM_HERE, [&] { + bool success = worker_thread_->BlockingCall([&] { return video_media_channel()->SetVideoSend(ssrc_, &options, video_track().get()); }); @@ -722,9 +719,8 @@ void VideoRtpSender::ClearSend() { // Allow SetVideoSend to fail since `enable` is false and `source` is null. // This the normal case when the underlying media channel has already been // deleted. - worker_thread_->Invoke(RTC_FROM_HERE, [&] { - return video_media_channel()->SetVideoSend(ssrc_, nullptr, nullptr); - }); + worker_thread_->BlockingCall( + [&] { video_media_channel()->SetVideoSend(ssrc_, nullptr, nullptr); }); } } // namespace webrtc diff --git a/pc/rtp_transceiver.cc b/pc/rtp_transceiver.cc index 44a96d4c61..db49468c07 100644 --- a/pc/rtp_transceiver.cc +++ b/pc/rtp_transceiver.cc @@ -28,7 +28,6 @@ #include "pc/rtp_media_utils.h" #include "pc/session_description.h" #include "rtc_base/checks.h" -#include "rtc_base/location.h" #include "rtc_base/logging.h" #include "rtc_base/thread.h" @@ -185,57 +184,42 @@ RTCError RtpTransceiver::CreateChannel( // TODO(bugs.webrtc.org/11992): Remove this workaround after updates in // PeerConnection and add the expectation that we're already on the right // thread. - new_channel = - context() - ->worker_thread() - ->Invoke>( - RTC_FROM_HERE, [&]() -> std::unique_ptr { - RTC_DCHECK_RUN_ON(context()->worker_thread()); + context()->worker_thread()->BlockingCall([&] { + RTC_DCHECK_RUN_ON(context()->worker_thread()); - cricket::VoiceMediaChannel* media_channel = - media_engine()->voice().CreateMediaChannel( - call_ptr, media_config, audio_options, - crypto_options); - if (!media_channel) { - return nullptr; - } + cricket::VoiceMediaChannel* media_channel = + media_engine()->voice().CreateMediaChannel( + call_ptr, media_config, audio_options, crypto_options); + if (!media_channel) { + return; + } - auto voice_channel = std::make_unique( - context()->worker_thread(), context()->network_thread(), - context()->signaling_thread(), - absl::WrapUnique(media_channel), mid, srtp_required, - crypto_options, context()->ssrc_generator()); - - return voice_channel; - }); + new_channel = std::make_unique( + context()->worker_thread(), context()->network_thread(), + context()->signaling_thread(), absl::WrapUnique(media_channel), mid, + srtp_required, crypto_options, context()->ssrc_generator()); + }); } else { RTC_DCHECK_EQ(cricket::MEDIA_TYPE_VIDEO, media_type()); // TODO(bugs.webrtc.org/11992): CreateVideoChannel internally switches to // the worker thread. We shouldn't be using the `call_ptr_` hack here but // simply be on the worker thread and use `call_` (update upstream code). - new_channel = - context() - ->worker_thread() - ->Invoke>( - RTC_FROM_HERE, [&]() -> std::unique_ptr { - RTC_DCHECK_RUN_ON(context()->worker_thread()); - cricket::VideoMediaChannel* media_channel = - media_engine()->video().CreateMediaChannel( - call_ptr, media_config, video_options, crypto_options, - video_bitrate_allocator_factory); - if (!media_channel) { - return nullptr; - } + context()->worker_thread()->BlockingCall([&] { + RTC_DCHECK_RUN_ON(context()->worker_thread()); + cricket::VideoMediaChannel* media_channel = + media_engine()->video().CreateMediaChannel( + call_ptr, media_config, video_options, crypto_options, + video_bitrate_allocator_factory); + if (!media_channel) { + return; + } - auto video_channel = std::make_unique( - context()->worker_thread(), context()->network_thread(), - context()->signaling_thread(), - absl::WrapUnique(media_channel), mid, srtp_required, - crypto_options, context()->ssrc_generator()); - - return video_channel; - }); + new_channel = std::make_unique( + context()->worker_thread(), context()->network_thread(), + context()->signaling_thread(), absl::WrapUnique(media_channel), mid, + srtp_required, crypto_options, context()->ssrc_generator()); + }); } if (!new_channel) { // TODO(hta): Must be a better way @@ -274,7 +258,7 @@ void RtpTransceiver::SetChannel( // Similarly, if the channel() accessor is limited to the network thread, that // helps with keeping the channel implementation requirements being met and // avoids synchronization for accessing the pointer or network related state. - context()->network_thread()->Invoke(RTC_FROM_HERE, [&]() { + context()->network_thread()->BlockingCall([&]() { if (channel_) { channel_->SetFirstPacketReceivedCallback(nullptr); channel_->SetRtpTransport(nullptr); @@ -310,7 +294,7 @@ void RtpTransceiver::ClearChannel() { } std::unique_ptr channel_to_delete; - context()->network_thread()->Invoke(RTC_FROM_HERE, [&]() { + context()->network_thread()->BlockingCall([&]() { if (channel_) { channel_->SetFirstPacketReceivedCallback(nullptr); channel_->SetRtpTransport(nullptr); @@ -331,7 +315,7 @@ void RtpTransceiver::PushNewMediaChannelAndDeleteChannel( if (!channel_to_delete && senders_.empty() && receivers_.empty()) { return; } - context()->worker_thread()->Invoke(RTC_FROM_HERE, [&]() { + context()->worker_thread()->BlockingCall([&]() { // Push down the new media_channel, if any, otherwise clear it. auto* media_channel = channel_ ? channel_->media_channel() : nullptr; for (const auto& sender : senders_) { @@ -399,7 +383,7 @@ bool RtpTransceiver::RemoveReceiver(RtpReceiverInterface* receiver) { } (*it)->internal()->Stop(); - context()->worker_thread()->Invoke(RTC_FROM_HERE, [&]() { + context()->worker_thread()->BlockingCall([&]() { // `Stop()` will clear the receiver's pointer to the media channel. (*it)->internal()->SetMediaChannel(nullptr); }); @@ -533,7 +517,7 @@ void RtpTransceiver::StopSendingAndReceiving() { for (const auto& receiver : receivers_) receiver->internal()->Stop(); - context()->worker_thread()->Invoke(RTC_FROM_HERE, [&]() { + context()->worker_thread()->BlockingCall([&]() { // 5 Stop receiving media with receiver. for (const auto& receiver : receivers_) receiver->internal()->SetMediaChannel(nullptr); diff --git a/pc/sctp_data_channel.cc b/pc/sctp_data_channel.cc index a5e0d76b5b..0591bcc087 100644 --- a/pc/sctp_data_channel.cc +++ b/pc/sctp_data_channel.cc @@ -20,7 +20,6 @@ #include "pc/proxy.h" #include "pc/sctp_utils.h" #include "rtc_base/checks.h" -#include "rtc_base/location.h" #include "rtc_base/logging.h" #include "rtc_base/system/unused.h" #include "rtc_base/thread.h" diff --git a/pc/sctp_transport.cc b/pc/sctp_transport.cc index f411883605..eabaa04a57 100644 --- a/pc/sctp_transport.cc +++ b/pc/sctp_transport.cc @@ -17,7 +17,6 @@ #include "api/dtls_transport_interface.h" #include "api/sequence_checker.h" #include "rtc_base/checks.h" -#include "rtc_base/location.h" #include "rtc_base/logging.h" namespace webrtc { @@ -50,8 +49,7 @@ SctpTransportInformation SctpTransport::Information() const { // expected thread. Chromium currently calls this method from // TransceiverStateSurfacer. if (!owner_thread_->IsCurrent()) { - return owner_thread_->Invoke( - RTC_FROM_HERE, [this] { return Information(); }); + return owner_thread_->BlockingCall([this] { return Information(); }); } RTC_DCHECK_RUN_ON(owner_thread_); return info_; diff --git a/pc/sdp_offer_answer.cc b/pc/sdp_offer_answer.cc index 9a5023cd0b..35e65e0105 100644 --- a/pc/sdp_offer_answer.cc +++ b/pc/sdp_offer_answer.cc @@ -55,7 +55,6 @@ #include "pc/usage_pattern.h" #include "pc/webrtc_session_description_factory.h" #include "rtc_base/helpers.h" -#include "rtc_base/location.h" #include "rtc_base/logging.h" #include "rtc_base/rtc_certificate.h" #include "rtc_base/ssl_stream_adapter.h" @@ -691,13 +690,12 @@ rtc::scoped_refptr LookupDtlsTransportByMid( JsepTransportController* controller, const std::string& mid) { // TODO(tommi): Can we post this (and associated operations where this - // function is called) to the network thread and avoid this Invoke? + // function is called) to the network thread and avoid this BlockingCall? // We might be able to simplify a few things if we set the transport on // the network thread and then update the implementation to check that // the set_ and relevant get methods are always called on the network // thread (we'll need to update proxy maps). - return network_thread->Invoke>( - RTC_FROM_HERE, + return network_thread->BlockingCall( [controller, &mid] { return controller->LookupDtlsTransportByMid(mid); }); } @@ -1813,7 +1811,7 @@ RTCError SdpOfferAnswerHandler::ReplaceRemoteDescription( ReportSimulcastApiVersion(kSimulcastVersionApplyRemoteDescription, *session_desc); - // NOTE: This will perform an Invoke() to the network thread. + // NOTE: This will perform a BlockingCall() to the network thread. return transport_controller_s()->SetRemoteDescription(sdp_type, session_desc); } @@ -2200,8 +2198,8 @@ void SdpOfferAnswerHandler::DoSetLocalDescription( // TODO(deadbeef): We already had to hop to the network thread for // MaybeStartGathering... - context_->network_thread()->Invoke( - RTC_FROM_HERE, [this] { port_allocator()->DiscardCandidatePool(); }); + context_->network_thread()->BlockingCall( + [this] { port_allocator()->DiscardCandidatePool(); }); // Make UMA notes about what was agreed to. ReportNegotiatedSdpSemantics(*local_description()); } @@ -2404,8 +2402,8 @@ void SdpOfferAnswerHandler::SetRemoteDescriptionPostProcess(bool was_answer) { if (was_answer) { // TODO(deadbeef): We already had to hop to the network thread for // MaybeStartGathering... - context_->network_thread()->Invoke( - RTC_FROM_HERE, [this] { port_allocator()->DiscardCandidatePool(); }); + context_->network_thread()->BlockingCall( + [this] { port_allocator()->DiscardCandidatePool(); }); // Make UMA notes about what was agreed to. ReportNegotiatedSdpSemantics(*remote_description()); } @@ -3831,8 +3829,7 @@ void SdpOfferAnswerHandler::GetOptionsForOffer( session_options->rtcp_cname = rtcp_cname_; session_options->crypto_options = pc_->GetCryptoOptions(); session_options->pooled_ice_credentials = - context_->network_thread()->Invoke>( - RTC_FROM_HERE, + context_->network_thread()->BlockingCall( [this] { return port_allocator()->GetPooledIceCredentials(); }); session_options->offer_extmap_allow_mixed = pc_->configuration()->offer_extmap_allow_mixed; @@ -4095,8 +4092,7 @@ void SdpOfferAnswerHandler::GetOptionsForAnswer( session_options->rtcp_cname = rtcp_cname_; session_options->crypto_options = pc_->GetCryptoOptions(); session_options->pooled_ice_credentials = - context_->network_thread()->Invoke>( - RTC_FROM_HERE, + context_->network_thread()->BlockingCall( [this] { return port_allocator()->GetPooledIceCredentials(); }); } @@ -4525,8 +4521,8 @@ RTCError SdpOfferAnswerHandler::PushdownMediaDescription( RTC_DCHECK(sdesc); if (ConfiguredForMedia()) { - // Note: This will perform an Invoke over to the worker thread, which we'll - // also do in a loop below. + // Note: This will perform a BlockingCall over to the worker thread, which + // we'll also do in a loop below. if (!UpdatePayloadTypeDemuxingState(source, bundle_groups_by_mid)) { // Note that this is never expected to fail, since RtpDemuxer doesn't // return an error when changing payload type demux criteria, which is all @@ -4570,7 +4566,7 @@ RTCError SdpOfferAnswerHandler::PushdownMediaDescription( for (const auto& entry : channels) { std::string error; bool success = - context_->worker_thread()->Invoke(RTC_FROM_HERE, [&]() { + context_->worker_thread()->BlockingCall([&]() { return (source == cricket::CS_LOCAL) ? entry.first->SetLocalContent(entry.second, type, error) : entry.first->SetRemoteContent(entry.second, type, @@ -4918,7 +4914,7 @@ RTCError SdpOfferAnswerHandler::CreateChannels(const SessionDescription& desc) { bool SdpOfferAnswerHandler::CreateDataChannel(const std::string& mid) { RTC_DCHECK_RUN_ON(signaling_thread()); - if (!context_->network_thread()->Invoke(RTC_FROM_HERE, [this, &mid] { + if (!context_->network_thread()->BlockingCall([this, &mid] { RTC_DCHECK_RUN_ON(context_->network_thread()); return pc_->SetupDataChannelTransport_n(mid); })) { @@ -4940,7 +4936,7 @@ void SdpOfferAnswerHandler::DestroyDataChannelTransport(RTCError error) { if (has_sctp) data_channel_controller()->OnTransportChannelClosed(error); - context_->network_thread()->Invoke(RTC_FROM_HERE, [this] { + context_->network_thread()->BlockingCall([this] { RTC_DCHECK_RUN_ON(context_->network_thread()); pc_->TeardownDataChannelTransport_n(); }); @@ -5174,7 +5170,7 @@ bool SdpOfferAnswerHandler::UpdatePayloadTypeDemuxingState( pt_demuxing_has_been_used_video_; // Gather all updates ahead of time so that all channels can be updated in a - // single Invoke; necessary due to thread guards. + // single BlockingCall; necessary due to thread guards. std::vector> channels_to_update; for (const auto& transceiver : transceivers()->ListInternal()) { cricket::ChannelInterface* channel = transceiver->channel(); @@ -5226,22 +5222,21 @@ bool SdpOfferAnswerHandler::UpdatePayloadTypeDemuxingState( return true; } - // TODO(bugs.webrtc.org/11993): This Invoke() will also invoke on the network - // thread for every demuxer sink that needs to be updated. The demuxer state - // needs to be fully (and only) managed on the network thread and once that's - // the case, there's no need to stop by on the worker. Ideally we could also - // do this without blocking. - return context_->worker_thread()->Invoke( - RTC_FROM_HERE, [&channels_to_update]() { - for (const auto& it : channels_to_update) { - if (!it.second->SetPayloadTypeDemuxingEnabled(it.first)) { - // Note that the state has already been irrevocably changed at this - // point. Is it useful to stop the loop? - return false; - } - } - return true; - }); + // TODO(bugs.webrtc.org/11993): This BlockingCall() will also block on the + // network thread for every demuxer sink that needs to be updated. The demuxer + // state needs to be fully (and only) managed on the network thread and once + // that's the case, there's no need to stop by on the worker. Ideally we could + // also do this without blocking. + return context_->worker_thread()->BlockingCall([&channels_to_update]() { + for (const auto& it : channels_to_update) { + if (!it.second->SetPayloadTypeDemuxingEnabled(it.first)) { + // Note that the state has already been irrevocably changed at this + // point. Is it useful to stop the loop? + return false; + } + } + return true; + }); } bool SdpOfferAnswerHandler::ConfiguredForMedia() const { diff --git a/pc/video_rtp_receiver.cc b/pc/video_rtp_receiver.cc index d6272e760c..e01a33fd31 100644 --- a/pc/video_rtp_receiver.cc +++ b/pc/video_rtp_receiver.cc @@ -19,7 +19,6 @@ #include "api/video/recordable_encoded_frame.h" #include "pc/video_track.h" #include "rtc_base/checks.h" -#include "rtc_base/location.h" #include "rtc_base/logging.h" namespace webrtc { @@ -117,7 +116,7 @@ void VideoRtpReceiver::RestartMediaChannel(absl::optional ssrc) { RTC_DCHECK_RUN_ON(&signaling_thread_checker_); MediaSourceInterface::SourceState state = source_->state(); // TODO(tommi): Can we restart the media channel without blocking? - worker_thread_->Invoke(RTC_FROM_HERE, [&] { + worker_thread_->BlockingCall([&] { RTC_DCHECK_RUN_ON(worker_thread_); RestartMediaChannel_w(std::move(ssrc), state); }); @@ -316,7 +315,7 @@ void VideoRtpReceiver::SetupMediaChannel(absl::optional ssrc, RTC_DCHECK_RUN_ON(&signaling_thread_checker_); RTC_DCHECK(media_channel); MediaSourceInterface::SourceState state = source_->state(); - worker_thread_->Invoke(RTC_FROM_HERE, [&] { + worker_thread_->BlockingCall([&] { RTC_DCHECK_RUN_ON(worker_thread_); SetMediaChannel_w(media_channel); RestartMediaChannel_w(std::move(ssrc), state); diff --git a/pc/video_track.cc b/pc/video_track.cc index c979995f0a..0bf8687af3 100644 --- a/pc/video_track.cc +++ b/pc/video_track.cc @@ -16,7 +16,6 @@ #include "api/notifier.h" #include "api/sequence_checker.h" #include "rtc_base/checks.h" -#include "rtc_base/location.h" namespace webrtc { @@ -95,7 +94,7 @@ bool VideoTrack::set_enabled(bool enable) { bool ret = MediaStreamTrack::set_enabled(enable); - worker_thread_->Invoke(RTC_FROM_HERE, [&]() { + worker_thread_->BlockingCall([&]() { RTC_DCHECK_RUN_ON(worker_thread_); enabled_w_ = enable; for (auto& sink_pair : sink_pairs()) { diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn index c3e4be9a14..12676a05db 100644 --- a/rtc_base/BUILD.gn +++ b/rtc_base/BUILD.gn @@ -1492,7 +1492,6 @@ if (rtc_include_tests) { ":checks", ":gunit_helpers", ":ip_address", - ":location", ":logging", ":macromagic", ":net_helpers", @@ -1581,7 +1580,6 @@ if (rtc_include_tests) { ":gunit_helpers", ":histogram_percentile_counter", ":ip_address", - ":location", ":logging", ":macromagic", ":mod_ops", diff --git a/rtc_base/fake_mdns_responder.h b/rtc_base/fake_mdns_responder.h index 8be6f1ccda..706c11b913 100644 --- a/rtc_base/fake_mdns_responder.h +++ b/rtc_base/fake_mdns_responder.h @@ -17,7 +17,6 @@ #include "absl/strings/string_view.h" #include "rtc_base/ip_address.h" -#include "rtc_base/location.h" #include "rtc_base/mdns_responder_interface.h" #include "rtc_base/thread.h" diff --git a/rtc_base/network.cc b/rtc_base/network.cc index 673a11300a..ce77cbc3e7 100644 --- a/rtc_base/network.cc +++ b/rtc_base/network.cc @@ -1253,7 +1253,7 @@ void BasicNetworkManager::set_vpn_list(const std::vector& vpn) { if (thread_ == nullptr) { vpn_ = vpn; } else { - thread_->Invoke(RTC_FROM_HERE, [this, vpn] { vpn_ = vpn; }); + thread_->BlockingCall([this, vpn] { vpn_ = vpn; }); } } diff --git a/rtc_base/rtc_certificate_generator.cc b/rtc_base/rtc_certificate_generator.cc index 739890e2b8..bdd90f209e 100644 --- a/rtc_base/rtc_certificate_generator.cc +++ b/rtc_base/rtc_certificate_generator.cc @@ -17,7 +17,6 @@ #include #include "rtc_base/checks.h" -#include "rtc_base/location.h" #include "rtc_base/message_handler.h" #include "rtc_base/ssl_identity.h" diff --git a/rtc_base/socket_unittest.cc b/rtc_base/socket_unittest.cc index 2ac563456d..ea6407ae6e 100644 --- a/rtc_base/socket_unittest.cc +++ b/rtc_base/socket_unittest.cc @@ -23,7 +23,6 @@ #include "rtc_base/async_udp_socket.h" #include "rtc_base/buffer.h" #include "rtc_base/gunit.h" -#include "rtc_base/location.h" #include "rtc_base/logging.h" #include "rtc_base/net_helpers.h" #include "rtc_base/socket_address.h" @@ -730,7 +729,7 @@ void SocketTest::SocketServerWaitInternal(const IPAddress& loopback) { // Shouldn't signal when blocked in a thread Send, where process_io is false. std::unique_ptr thread(Thread::CreateWithSocketServer()); thread->Start(); - thread->Invoke(RTC_FROM_HERE, [] { Thread::SleepMs(500); }); + thread->BlockingCall([] { Thread::SleepMs(500); }); EXPECT_FALSE(sink.Check(accepted.get(), SSE_READ)); // But should signal when process_io is true. diff --git a/rtc_base/stream.cc b/rtc_base/stream.cc index 30c767888c..e1aab8cc22 100644 --- a/rtc_base/stream.cc +++ b/rtc_base/stream.cc @@ -16,7 +16,6 @@ #include #include "rtc_base/checks.h" -#include "rtc_base/location.h" #include "rtc_base/thread.h" namespace rtc { diff --git a/rtc_base/synchronization/BUILD.gn b/rtc_base/synchronization/BUILD.gn index 5890e75e46..5f2b04ef6f 100644 --- a/rtc_base/synchronization/BUILD.gn +++ b/rtc_base/synchronization/BUILD.gn @@ -86,7 +86,6 @@ if (rtc_include_tests) { ":yield", ":yield_policy", "..:checks", - "..:location", "..:macromagic", "..:platform_thread", "..:rtc_base", diff --git a/rtc_base/task_queue.h b/rtc_base/task_queue.h index 0ef0ffe992..cae95340bc 100644 --- a/rtc_base/task_queue.h +++ b/rtc_base/task_queue.h @@ -90,7 +90,6 @@ class RTC_LOCKABLE RTC_EXPORT TaskQueue { // Returns non-owning pointer to the task queue implementation. webrtc::TaskQueueBase* Get() { return impl_; } - // TODO(tommi): For better debuggability, implement RTC_FROM_HERE. void PostTask(absl::AnyInvocable task) { impl_->PostTask(std::move(task)); } diff --git a/rtc_base/thread.h b/rtc_base/thread.h index ad286a801e..435aff6d94 100644 --- a/rtc_base/thread.h +++ b/rtc_base/thread.h @@ -349,7 +349,8 @@ class RTC_LOCKABLE RTC_EXPORT Thread : public webrtc::TaskQueueBase { // Deprecated, use `BlockingCall` instead. template - ReturnT Invoke(const Location& posted_from, FunctionView functor) { + [[deprecated]] ReturnT Invoke(const Location& /*posted_from*/, + FunctionView functor) { return BlockingCall(functor); } diff --git a/rtc_base/time_utils_unittest.cc b/rtc_base/time_utils_unittest.cc index 7e72c5ff93..2c73b0f201 100644 --- a/rtc_base/time_utils_unittest.cc +++ b/rtc_base/time_utils_unittest.cc @@ -16,7 +16,6 @@ #include "rtc_base/event.h" #include "rtc_base/fake_clock.h" #include "rtc_base/helpers.h" -#include "rtc_base/location.h" #include "rtc_base/message_handler.h" #include "rtc_base/thread.h" #include "test/gtest.h" diff --git a/rtc_tools/network_tester/test_controller.cc b/rtc_tools/network_tester/test_controller.cc index 4ba43cc166..6fe83fd430 100644 --- a/rtc_tools/network_tester/test_controller.cc +++ b/rtc_tools/network_tester/test_controller.cc @@ -38,7 +38,7 @@ TestController::TestController(int min_port, send_data_.fill(42); packet_sender_thread_->SetName("PacketSender", nullptr); packet_sender_thread_->Start(); - packet_sender_thread_->Invoke(RTC_FROM_HERE, [&] { + packet_sender_thread_->BlockingCall([&] { RTC_DCHECK_RUN_ON(packet_sender_thread_.get()); udp_socket_ = std::unique_ptr(socket_factory_.CreateUdpSocket( @@ -49,8 +49,8 @@ TestController::TestController(int min_port, TestController::~TestController() { RTC_DCHECK_RUN_ON(&test_controller_thread_checker_); - packet_sender_thread_->Invoke( - RTC_FROM_HERE, [this]() { task_safety_flag_->SetNotAlive(); }); + packet_sender_thread_->BlockingCall( + [this]() { task_safety_flag_->SetNotAlive(); }); } void TestController::SendConnectTo(const std::string& hostname, int port) { diff --git a/sdk/android/src/jni/pc/peer_connection.cc b/sdk/android/src/jni/pc/peer_connection.cc index 502763a2d0..03321a53c1 100644 --- a/sdk/android/src/jni/pc/peer_connection.cc +++ b/sdk/android/src/jni/pc/peer_connection.cc @@ -516,7 +516,7 @@ static ScopedJavaLocalRef JNI_PeerConnection_GetLocalDescription( // must do this odd dance. std::string sdp; std::string type; - pc->signaling_thread()->Invoke(RTC_FROM_HERE, [pc, &sdp, &type] { + pc->signaling_thread()->BlockingCall([pc, &sdp, &type] { const SessionDescriptionInterface* desc = pc->local_description(); if (desc) { RTC_CHECK(desc->ToString(&sdp)) << "got so far: " << sdp; @@ -535,7 +535,7 @@ static ScopedJavaLocalRef JNI_PeerConnection_GetRemoteDescription( // must do this odd dance. std::string sdp; std::string type; - pc->signaling_thread()->Invoke(RTC_FROM_HERE, [pc, &sdp, &type] { + pc->signaling_thread()->BlockingCall([pc, &sdp, &type] { const SessionDescriptionInterface* desc = pc->remote_description(); if (desc) { RTC_CHECK(desc->ToString(&sdp)) << "got so far: " << sdp; diff --git a/sdk/objc/api/peerconnection/RTCMediaStream.mm b/sdk/objc/api/peerconnection/RTCMediaStream.mm index beb4a7a91b..0018dd6945 100644 --- a/sdk/objc/api/peerconnection/RTCMediaStream.mm +++ b/sdk/objc/api/peerconnection/RTCMediaStream.mm @@ -36,16 +36,14 @@ - (NSArray *)audioTracks { if (!_signalingThread->IsCurrent()) { - return _signalingThread->Invoke *>( - RTC_FROM_HERE, [self]() { return self.audioTracks; }); + return _signalingThread->BlockingCall([self]() { return self.audioTracks; }); } return [_audioTracks copy]; } - (NSArray *)videoTracks { if (!_signalingThread->IsCurrent()) { - return _signalingThread->Invoke *>( - RTC_FROM_HERE, [self]() { return self.videoTracks; }); + return _signalingThread->BlockingCall([self]() { return self.videoTracks; }); } return [_videoTracks copy]; } @@ -56,8 +54,8 @@ - (void)addAudioTrack:(RTC_OBJC_TYPE(RTCAudioTrack) *)audioTrack { if (!_signalingThread->IsCurrent()) { - return _signalingThread->Invoke( - RTC_FROM_HERE, [audioTrack, self]() { return [self addAudioTrack:audioTrack]; }); + return _signalingThread->BlockingCall( + [audioTrack, self]() { return [self addAudioTrack:audioTrack]; }); } if (_nativeMediaStream->AddTrack(audioTrack.nativeAudioTrack)) { [_audioTracks addObject:audioTrack]; @@ -66,8 +64,8 @@ - (void)addVideoTrack:(RTC_OBJC_TYPE(RTCVideoTrack) *)videoTrack { if (!_signalingThread->IsCurrent()) { - return _signalingThread->Invoke( - RTC_FROM_HERE, [videoTrack, self]() { return [self addVideoTrack:videoTrack]; }); + return _signalingThread->BlockingCall( + [videoTrack, self]() { return [self addVideoTrack:videoTrack]; }); } if (_nativeMediaStream->AddTrack(videoTrack.nativeVideoTrack)) { [_videoTracks addObject:videoTrack]; @@ -76,8 +74,8 @@ - (void)removeAudioTrack:(RTC_OBJC_TYPE(RTCAudioTrack) *)audioTrack { if (!_signalingThread->IsCurrent()) { - return _signalingThread->Invoke( - RTC_FROM_HERE, [audioTrack, self]() { return [self removeAudioTrack:audioTrack]; }); + return _signalingThread->BlockingCall( + [audioTrack, self]() { return [self removeAudioTrack:audioTrack]; }); } NSUInteger index = [_audioTracks indexOfObjectIdenticalTo:audioTrack]; if (index == NSNotFound) { @@ -91,8 +89,8 @@ - (void)removeVideoTrack:(RTC_OBJC_TYPE(RTCVideoTrack) *)videoTrack { if (!_signalingThread->IsCurrent()) { - return _signalingThread->Invoke( - RTC_FROM_HERE, [videoTrack, self]() { return [self removeVideoTrack:videoTrack]; }); + return _signalingThread->BlockingCall( + [videoTrack, self]() { return [self removeVideoTrack:videoTrack]; }); } NSUInteger index = [_videoTracks indexOfObjectIdenticalTo:videoTrack]; if (index == NSNotFound) { diff --git a/sdk/objc/api/peerconnection/RTCPeerConnection.mm b/sdk/objc/api/peerconnection/RTCPeerConnection.mm index f4db472380..df99030111 100644 --- a/sdk/objc/api/peerconnection/RTCPeerConnection.mm +++ b/sdk/objc/api/peerconnection/RTCPeerConnection.mm @@ -392,26 +392,22 @@ void PeerConnectionDelegateAdapter::OnRemoveTrack( - (RTC_OBJC_TYPE(RTCSessionDescription) *)localDescription { // It's only safe to operate on SessionDescriptionInterface on the signaling thread. - return _peerConnection->signaling_thread()->Invoke( - RTC_FROM_HERE, [self] { - const webrtc::SessionDescriptionInterface *description = - _peerConnection->local_description(); - return description ? - [[RTC_OBJC_TYPE(RTCSessionDescription) alloc] initWithNativeDescription:description] : - nil; - }); + return _peerConnection->signaling_thread()->BlockingCall([self] { + const webrtc::SessionDescriptionInterface *description = _peerConnection->local_description(); + return description ? + [[RTC_OBJC_TYPE(RTCSessionDescription) alloc] initWithNativeDescription:description] : + nil; + }); } - (RTC_OBJC_TYPE(RTCSessionDescription) *)remoteDescription { // It's only safe to operate on SessionDescriptionInterface on the signaling thread. - return _peerConnection->signaling_thread()->Invoke( - RTC_FROM_HERE, [self] { - const webrtc::SessionDescriptionInterface *description = - _peerConnection->remote_description(); - return description ? - [[RTC_OBJC_TYPE(RTCSessionDescription) alloc] initWithNativeDescription:description] : - nil; - }); + return _peerConnection->signaling_thread()->BlockingCall([self] { + const webrtc::SessionDescriptionInterface *description = _peerConnection->remote_description(); + return description ? + [[RTC_OBJC_TYPE(RTCSessionDescription) alloc] initWithNativeDescription:description] : + nil; + }); } - (RTCSignalingState)signalingState { diff --git a/sdk/objc/api/peerconnection/RTCVideoTrack.mm b/sdk/objc/api/peerconnection/RTCVideoTrack.mm index fb015c6207..d4862e3748 100644 --- a/sdk/objc/api/peerconnection/RTCVideoTrack.mm +++ b/sdk/objc/api/peerconnection/RTCVideoTrack.mm @@ -72,7 +72,7 @@ - (void)addRenderer:(id)renderer { if (!_workerThread->IsCurrent()) { - _workerThread->Invoke(RTC_FROM_HERE, [renderer, self] { [self addRenderer:renderer]; }); + _workerThread->BlockingCall([renderer, self] { [self addRenderer:renderer]; }); return; } @@ -93,8 +93,7 @@ - (void)removeRenderer:(id)renderer { if (!_workerThread->IsCurrent()) { - _workerThread->Invoke(RTC_FROM_HERE, - [renderer, self] { [self removeRenderer:renderer]; }); + _workerThread->BlockingCall([renderer, self] { [self removeRenderer:renderer]; }); return; } __block NSUInteger indexToRemove = NSNotFound; diff --git a/sdk/objc/native/src/objc_audio_device_delegate.mm b/sdk/objc/native/src/objc_audio_device_delegate.mm index b7bb4e4294..156d6326a4 100644 --- a/sdk/objc/native/src/objc_audio_device_delegate.mm +++ b/sdk/objc/native/src/objc_audio_device_delegate.mm @@ -178,7 +178,7 @@ class AudioDeviceDelegateImpl final : public rtc::RefCountedNonVirtualInvoke(RTC_FROM_HERE, [block] { + thread->BlockingCall([block] { @autoreleasepool { block(); } diff --git a/test/time_controller/BUILD.gn b/test/time_controller/BUILD.gn index c810eae1b4..8f552a8452 100644 --- a/test/time_controller/BUILD.gn +++ b/test/time_controller/BUILD.gn @@ -60,7 +60,6 @@ if (rtc_include_tests) { "../../api:time_controller", "../../api/units:time_delta", "../../rtc_base", - "../../rtc_base:location", "../../rtc_base:macromagic", "../../rtc_base:rtc_event", "../../rtc_base:rtc_task_queue", diff --git a/test/time_controller/time_controller_conformance_test.cc b/test/time_controller/time_controller_conformance_test.cc index 4b03be3513..300dd9175c 100644 --- a/test/time_controller/time_controller_conformance_test.cc +++ b/test/time_controller/time_controller_conformance_test.cc @@ -14,7 +14,6 @@ #include "api/test/time_controller.h" #include "api/units/time_delta.h" #include "rtc_base/event.h" -#include "rtc_base/location.h" #include "rtc_base/synchronization/mutex.h" #include "rtc_base/thread.h" #include "rtc_base/thread_annotations.h" @@ -121,7 +120,7 @@ TEST_P(SimulatedRealTimeControllerConformanceTest, ThreadPostInvokeOrderTest) { // posted/invoked. ExecutionOrderKeeper execution_order; thread->PostTask([&]() { execution_order.Executed(1); }); - thread->Invoke(RTC_FROM_HERE, [&]() { execution_order.Executed(2); }); + thread->BlockingCall([&]() { execution_order.Executed(2); }); time_controller->AdvanceTime(TimeDelta::Millis(100)); EXPECT_THAT(execution_order.order(), ElementsAreArray({1, 2})); // Destroy `thread` before `execution_order` to be sure `execution_order` @@ -140,7 +139,7 @@ TEST_P(SimulatedRealTimeControllerConformanceTest, ExecutionOrderKeeper execution_order; thread->PostTask([&]() { thread->PostTask([&]() { execution_order.Executed(2); }); - thread->Invoke(RTC_FROM_HERE, [&]() { execution_order.Executed(1); }); + thread->BlockingCall([&]() { execution_order.Executed(1); }); }); time_controller->AdvanceTime(TimeDelta::Millis(100)); EXPECT_THAT(execution_order.order(), ElementsAreArray({1, 2})); diff --git a/video/BUILD.gn b/video/BUILD.gn index f0c0add650..82bd9e4b6f 100644 --- a/video/BUILD.gn +++ b/video/BUILD.gn @@ -106,7 +106,6 @@ rtc_library("video") { "../rtc_base:checks", "../rtc_base:event_tracer", "../rtc_base:histogram_percentile_counter", - "../rtc_base:location", "../rtc_base:logging", "../rtc_base:macromagic", "../rtc_base:mod_ops", @@ -405,7 +404,6 @@ rtc_library("video_stream_encoder_impl") { "../rtc_base:checks", "../rtc_base:criticalsection", "../rtc_base:event_tracer", - "../rtc_base:location", "../rtc_base:logging", "../rtc_base:macromagic", "../rtc_base:race_checker", diff --git a/video/call_stats2.cc b/video/call_stats2.cc index 95a4e99534..ef575d2667 100644 --- a/video/call_stats2.cc +++ b/video/call_stats2.cc @@ -16,7 +16,6 @@ #include "absl/algorithm/container.h" #include "rtc_base/checks.h" -#include "rtc_base/location.h" #include "system_wrappers/include/metrics.h" namespace webrtc { diff --git a/video/receive_statistics_proxy2.cc b/video/receive_statistics_proxy2.cc index 073b1a6332..a3a7bca8ef 100644 --- a/video/receive_statistics_proxy2.cc +++ b/video/receive_statistics_proxy2.cc @@ -594,7 +594,7 @@ VideoReceiveStreamInterface::Stats ReceiveStatisticsProxy::GetStats() const { RTC_DCHECK_RUN_ON(&main_thread_); // Like VideoReceiveStreamInterface::GetStats, called on the worker thread - // from StatsCollector::ExtractMediaInfo via worker_thread()->Invoke(). + // from StatsCollector::ExtractMediaInfo via worker_thread()->BlockingCall(). // WebRtcVideoChannel::GetStats(), GetVideoReceiverInfo. // Get current frame rates here, as only updating them on new frames prevents diff --git a/video/rtp_video_stream_receiver2.cc b/video/rtp_video_stream_receiver2.cc index d2ba1b6e86..4748257c1e 100644 --- a/video/rtp_video_stream_receiver2.cc +++ b/video/rtp_video_stream_receiver2.cc @@ -42,7 +42,6 @@ #include "modules/video_coding/nack_requester.h" #include "modules/video_coding/packet_buffer.h" #include "rtc_base/checks.h" -#include "rtc_base/location.h" #include "rtc_base/logging.h" #include "rtc_base/strings/string_builder.h" #include "system_wrappers/include/metrics.h" diff --git a/video/video_stream_encoder.cc b/video/video_stream_encoder.cc index bde8881fdb..8bf8ce2272 100644 --- a/video/video_stream_encoder.cc +++ b/video/video_stream_encoder.cc @@ -42,7 +42,6 @@ #include "rtc_base/experiments/alr_experiment.h" #include "rtc_base/experiments/encoder_info_settings.h" #include "rtc_base/experiments/rate_control_settings.h" -#include "rtc_base/location.h" #include "rtc_base/logging.h" #include "rtc_base/strings/string_builder.h" #include "rtc_base/system/no_unique_address.h"