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 <tommi@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38045}
This commit is contained in:
Danil Chapovalov
2022-09-08 18:38:10 +02:00
committed by WebRTC LUCI CQ
parent b190ca9e70
commit 9e09a1f327
54 changed files with 209 additions and 320 deletions

View File

@ -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<void>(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<void>(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<RtpParameters>(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<RtpParameters>(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<RTCError>(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<RTCError>(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<void>(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<void>(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<bool>(
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<bool>(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<bool>(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<bool>(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<bool>(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<bool>(RTC_FROM_HERE, [&] {
return video_media_channel()->SetVideoSend(ssrc_, nullptr, nullptr);
});
worker_thread_->BlockingCall(
[&] { video_media_channel()->SetVideoSend(ssrc_, nullptr, nullptr); });
}
} // namespace webrtc