Inject network thread to Call.

This will allow for transitioning PacketReceiver callbacks and
network related callbacks from being posted over to the worker thread
and instead can stay on the network thread along with related state.

Bug: webrtc:11993
Change-Id: I38df462d4dee064015c490f2b8f809cb47f23cf1
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/202039
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Commit-Queue: Tommi <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33116}
This commit is contained in:
Tomas Gunnarsson 2021-01-30 16:15:21 +01:00 committed by Commit Bot
parent cedc3c7200
commit 41bfcf4a63
4 changed files with 19 additions and 9 deletions

View File

@ -325,7 +325,7 @@ class Call final : public webrtc::Call,
Clock* const clock_;
TaskQueueFactory* const task_queue_factory_;
TaskQueueBase* const worker_thread_;
RTC_NO_UNIQUE_ADDRESS SequenceChecker network_thread_;
TaskQueueBase* const network_thread_;
const int num_cpu_cores_;
const rtc::scoped_refptr<SharedModuleThread> module_process_thread_;
@ -602,6 +602,10 @@ Call::Call(Clock* clock,
: clock_(clock),
task_queue_factory_(task_queue_factory),
worker_thread_(GetCurrentTaskQueueOrThread()),
// If |network_task_queue_| was set to nullptr, network related calls
// must be made on |worker_thread_| (i.e. they're one and the same).
network_thread_(config.network_task_queue_ ? config.network_task_queue_
: worker_thread_),
num_cpu_cores_(CpuInfo::DetectNumberOfCores()),
module_process_thread_(std::move(module_process_thread)),
call_stats_(new CallStats(clock_, worker_thread_)),
@ -628,10 +632,9 @@ Call::Call(Clock* clock,
transport_send_(std::move(transport_send)) {
RTC_DCHECK(config.event_log != nullptr);
RTC_DCHECK(config.trials != nullptr);
RTC_DCHECK(network_thread_);
RTC_DCHECK(worker_thread_->IsCurrent());
network_thread_.Detach();
// Do not remove this call; it is here to convince the compiler that the
// WebRTC source timestamp string needs to be in the final binary.
LoadWebRTCVersionInRegister();
@ -768,7 +771,6 @@ void Call::UpdateReceiveHistograms() {
}
PacketReceiver* Call::Receiver() {
RTC_DCHECK_RUN_ON(worker_thread_);
return this;
}
@ -1429,7 +1431,7 @@ void Call::DeliverPacketAsync(MediaType media_type,
rtc::CopyOnWriteBuffer packet,
int64_t packet_time_us,
PacketCallback callback) {
RTC_DCHECK_RUN_ON(&network_thread_);
RTC_DCHECK_RUN_ON(network_thread_);
TaskQueueBase* network_thread = rtc::Thread::Current();
RTC_DCHECK(network_thread);

View File

@ -14,7 +14,9 @@
namespace webrtc {
CallConfig::CallConfig(RtcEventLog* event_log) : event_log(event_log) {
CallConfig::CallConfig(RtcEventLog* event_log,
TaskQueueBase* network_task_queue /* = nullptr*/)
: event_log(event_log), network_task_queue_(network_task_queue) {
RTC_DCHECK(event_log);
}

View File

@ -26,7 +26,11 @@ class AudioProcessing;
class RtcEventLog;
struct CallConfig {
explicit CallConfig(RtcEventLog* event_log);
// If |network_task_queue| is set to nullptr, Call will assume that network
// related callbacks will be made on the same TQ as the Call instance was
// constructed on.
explicit CallConfig(RtcEventLog* event_log,
TaskQueueBase* network_task_queue = nullptr);
CallConfig(const CallConfig&);
~CallConfig();
@ -42,7 +46,7 @@ struct CallConfig {
// RtcEventLog to use for this call. Required.
// Use webrtc::RtcEventLog::CreateNull() for a null implementation.
RtcEventLog* event_log = nullptr;
RtcEventLog* const event_log = nullptr;
// FecController to use for this call.
FecControllerFactoryInterface* fec_controller_factory = nullptr;
@ -63,6 +67,8 @@ struct CallConfig {
// Key-value mapping of internal configurations to apply,
// e.g. field trials.
const WebRtcKeyValueConfig* trials = nullptr;
TaskQueueBase* const network_task_queue_ = nullptr;
};
} // namespace webrtc

View File

@ -313,7 +313,7 @@ std::unique_ptr<Call> PeerConnectionFactory::CreateCall_w(
RtcEventLog* event_log) {
RTC_DCHECK_RUN_ON(worker_thread());
webrtc::Call::Config call_config(event_log);
webrtc::Call::Config call_config(event_log, network_thread());
if (!channel_manager()->media_engine() || !context_->call_factory()) {
return nullptr;
}