Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1819)

Unified Diff: webrtc/call/call.cc

Issue 2685673003: Define RtpTransportControllerSendInterface. (Closed)
Patch Set: Comment improvements. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/call/call.cc
diff --git a/webrtc/call/call.cc b/webrtc/call/call.cc
index bb83b7201671488289d4df52344cee29b5ebc931..8319346459eece7906d2f2321e9e3883d25d6ae0 100644
--- a/webrtc/call/call.cc
+++ b/webrtc/call/call.cc
@@ -33,6 +33,7 @@
#include "webrtc/call/bitrate_allocator.h"
#include "webrtc/call/call.h"
#include "webrtc/call/flexfec_receive_stream_impl.h"
+#include "webrtc/call/rtp_transport_controller.h"
#include "webrtc/config.h"
#include "webrtc/logging/rtc_event_log/rtc_event_log.h"
#include "webrtc/modules/bitrate_controller/include/bitrate_controller.h"
@@ -87,6 +88,45 @@ bool UseSendSideBwe(const FlexfecReceiveStream::Config& config) {
return UseSendSideBwe(config.rtp_header_extensions, config.transport_cc);
}
+class RtpTransportController : public RtpTransportControllerSendInterface {
+ public:
+ RtpTransportController(Clock* clock, webrtc::RtcEventLog* event_log);
+ void InitCongestionControl(CongestionController::Observer* observer);
+ VieRemb* remb() override { return &remb_; }
+ PacketRouter* packet_router() override { return &packet_router_; }
+ CongestionController* congestion_controller() override {
+ return congestion_controller_.get();
+ }
+ TransportFeedbackObserver* transport_feedback_observer() override {
+ return congestion_controller_.get();
+ }
+ RtpPacketSender* packet_sender() override {
+ return congestion_controller_->pacer();
+ }
+
+ private:
+ Clock* const clock_;
+ webrtc::RtcEventLog* const event_log_;
+ VieRemb remb_;
+ PacketRouter packet_router_;
+ // Construction delayed until InitCongestionControl, since the
+ // CongestionController wants its observer as a construction time
+ // argument, and setting it later seems no-trivial.
+ std::unique_ptr<CongestionController> congestion_controller_;
+};
+
+RtpTransportController::RtpTransportController(Clock* clock,
+ webrtc::RtcEventLog* event_log)
+ : clock_(clock), event_log_(event_log), remb_(clock) {}
+
+void RtpTransportController::InitCongestionControl(
+ CongestionController::Observer* observer) {
+ // Must be called only once.
+ RTC_CHECK(!congestion_controller_);
+ congestion_controller_.reset(new CongestionController(
+ clock_, observer, &remb_, event_log_, &packet_router_));
+}
+
} // namespace
namespace internal {
@@ -97,7 +137,8 @@ class Call : public webrtc::Call,
public CongestionController::Observer,
public BitrateAllocator::LimitObserver {
public:
- explicit Call(const Call::Config& config);
+ Call(const Call::Config& config,
+ std::unique_ptr<RtpTransportController> transport);
virtual ~Call();
// Implements webrtc::Call.
@@ -271,11 +312,7 @@ class Call : public webrtc::Call,
std::map<std::string, rtc::NetworkRoute> network_routes_;
- VieRemb remb_;
- PacketRouter packet_router_;
- // TODO(nisse): Could be a direct member, except for constness
- // issues with GetRemoteBitrateEstimator (and maybe others).
- const std::unique_ptr<CongestionController> congestion_controller_;
+ std::unique_ptr<RtpTransportController> transport_;
const std::unique_ptr<SendDelayStats> video_send_delay_stats_;
const int64_t start_ms_;
// TODO(perkj): |worker_queue_| is supposed to replace
@@ -301,12 +338,16 @@ std::string Call::Stats::ToString(int64_t time_ms) const {
}
Call* Call::Create(const Call::Config& config) {
- return new internal::Call(config);
+ return new internal::Call(
+ config,
+ std::unique_ptr<RtpTransportController>(new RtpTransportController(
+ Clock::GetRealTimeClock(), config.event_log)));
}
namespace internal {
-Call::Call(const Call::Config& config)
+Call::Call(const Call::Config& config,
+ std::unique_ptr<RtpTransportController> transport)
: clock_(Clock::GetRealTimeClock()),
num_cpu_cores_(CpuInfo::DetectNumberOfCores()),
module_process_thread_(ProcessThread::Create("ModuleProcessThread")),
@@ -328,12 +369,7 @@ Call::Call(const Call::Config& config)
configured_max_padding_bitrate_bps_(0),
estimated_send_bitrate_kbps_counter_(clock_, nullptr, true),
pacer_bitrate_kbps_counter_(clock_, nullptr, true),
- remb_(clock_),
- congestion_controller_(new CongestionController(clock_,
- this,
- &remb_,
- event_log_,
- &packet_router_)),
+ transport_(std::move(transport)),
video_send_delay_stats_(new SendDelayStats(clock_)),
start_ms_(clock_->TimeInMilliseconds()),
worker_queue_("call_worker_queue") {
@@ -347,26 +383,28 @@ Call::Call(const Call::Config& config)
config.bitrate_config.start_bitrate_bps);
}
Trace::CreateTrace();
- call_stats_->RegisterStatsObserver(congestion_controller_.get());
-
- congestion_controller_->SignalNetworkState(kNetworkDown);
- congestion_controller_->SetBweBitrates(
+ transport_->InitCongestionControl(this);
+ transport_->congestion_controller()->SignalNetworkState(kNetworkDown);
+ transport_->congestion_controller()->SetBweBitrates(
config_.bitrate_config.min_bitrate_bps,
config_.bitrate_config.start_bitrate_bps,
config_.bitrate_config.max_bitrate_bps);
+ call_stats_->RegisterStatsObserver(transport_->congestion_controller());
module_process_thread_->Start();
module_process_thread_->RegisterModule(call_stats_.get(), RTC_FROM_HERE);
- module_process_thread_->RegisterModule(congestion_controller_.get(),
+ module_process_thread_->RegisterModule(transport_->congestion_controller(),
RTC_FROM_HERE);
- pacer_thread_->RegisterModule(congestion_controller_->pacer(), RTC_FROM_HERE);
+ pacer_thread_->RegisterModule(transport_->congestion_controller()->pacer(),
+ RTC_FROM_HERE);
pacer_thread_->RegisterModule(
- congestion_controller_->GetRemoteBitrateEstimator(true), RTC_FROM_HERE);
+ transport_->congestion_controller()->GetRemoteBitrateEstimator(true),
+ RTC_FROM_HERE);
pacer_thread_->Start();
}
Call::~Call() {
- RTC_DCHECK(!remb_.InUse());
+ RTC_DCHECK(!transport_->remb()->InUse());
RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
RTC_CHECK(audio_send_ssrcs_.empty());
@@ -377,13 +415,13 @@ Call::~Call() {
RTC_CHECK(video_receive_streams_.empty());
pacer_thread_->Stop();
- pacer_thread_->DeRegisterModule(congestion_controller_->pacer());
+ pacer_thread_->DeRegisterModule(transport_->congestion_controller()->pacer());
pacer_thread_->DeRegisterModule(
- congestion_controller_->GetRemoteBitrateEstimator(true));
- module_process_thread_->DeRegisterModule(congestion_controller_.get());
+ transport_->congestion_controller()->GetRemoteBitrateEstimator(true));
+ module_process_thread_->DeRegisterModule(transport_->congestion_controller());
module_process_thread_->DeRegisterModule(call_stats_.get());
module_process_thread_->Stop();
- call_stats_->DeregisterStatsObserver(congestion_controller_.get());
+ call_stats_->DeregisterStatsObserver(transport_->congestion_controller());
// Only update histograms after process threads have been shut down, so that
// they won't try to concurrently update stats.
@@ -501,9 +539,8 @@ webrtc::AudioSendStream* Call::CreateAudioSendStream(
RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
event_log_->LogAudioSendStreamConfig(config);
AudioSendStream* send_stream = new AudioSendStream(
- config, config_.audio_state, &worker_queue_, &packet_router_,
- congestion_controller_.get(), bitrate_allocator_.get(), event_log_,
- call_stats_->rtcp_rtt_stats());
+ config, config_.audio_state, &worker_queue_, transport_.get(),
+ bitrate_allocator_.get(), event_log_, call_stats_->rtcp_rtt_stats());
{
WriteLockScoped write_lock(*send_crit_);
RTC_DCHECK(audio_send_ssrcs_.find(config.rtp.ssrc) ==
@@ -556,8 +593,7 @@ webrtc::AudioReceiveStream* Call::CreateAudioReceiveStream(
RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
event_log_->LogAudioReceiveStreamConfig(config);
AudioReceiveStream* receive_stream = new AudioReceiveStream(
- &packet_router_, config,
- config_.audio_state, event_log_);
+ transport_->packet_router(), config, config_.audio_state, event_log_);
{
WriteLockScoped write_lock(*receive_crit_);
RTC_DCHECK(audio_receive_ssrcs_.find(config.rtp.remote_ssrc) ==
@@ -591,7 +627,8 @@ void Call::DestroyAudioReceiveStream(
WriteLockScoped write_lock(*receive_crit_);
const AudioReceiveStream::Config& config = audio_receive_stream->config();
uint32_t ssrc = config.rtp.remote_ssrc;
- congestion_controller_->GetRemoteBitrateEstimator(UseSendSideBwe(config))
+ transport_->congestion_controller()
+ ->GetRemoteBitrateEstimator(UseSendSideBwe(config))
->RemoveStream(ssrc);
size_t num_deleted = audio_receive_ssrcs_.erase(ssrc);
RTC_DCHECK(num_deleted == 1);
@@ -623,10 +660,9 @@ webrtc::VideoSendStream* Call::CreateVideoSendStream(
std::vector<uint32_t> ssrcs = config.rtp.ssrcs;
VideoSendStream* send_stream = new VideoSendStream(
num_cpu_cores_, module_process_thread_.get(), &worker_queue_,
- call_stats_.get(), congestion_controller_.get(), &packet_router_,
- bitrate_allocator_.get(), video_send_delay_stats_.get(), &remb_,
- event_log_, std::move(config), std::move(encoder_config),
- suspended_video_send_ssrcs_);
+ call_stats_.get(), transport_.get(), bitrate_allocator_.get(),
+ video_send_delay_stats_.get(), event_log_, std::move(config),
+ std::move(encoder_config), suspended_video_send_ssrcs_);
{
WriteLockScoped write_lock(*send_crit_);
@@ -683,8 +719,9 @@ webrtc::VideoReceiveStream* Call::CreateVideoReceiveStream(
RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
VideoReceiveStream* receive_stream = new VideoReceiveStream(
- num_cpu_cores_, &packet_router_, std::move(configuration),
- module_process_thread_.get(), call_stats_.get(), &remb_);
+ num_cpu_cores_, transport_->packet_router(),
+ std::move(configuration), module_process_thread_.get(), call_stats_.get(),
+ transport_->remb());
const webrtc::VideoReceiveStream::Config& config = receive_stream->config();
ReceiveRtpConfig receive_config(config.rtp.extensions,
@@ -740,7 +777,8 @@ void Call::DestroyVideoReceiveStream(
}
const VideoReceiveStream::Config& config = receive_stream_impl->config();
- congestion_controller_->GetRemoteBitrateEstimator(UseSendSideBwe(config))
+ transport_->congestion_controller()
+ ->GetRemoteBitrateEstimator(UseSendSideBwe(config))
->RemoveStream(config.rtp.remote_ssrc);
UpdateAggregateNetworkState();
@@ -816,7 +854,8 @@ void Call::DestroyFlexfecReceiveStream(FlexfecReceiveStream* receive_stream) {
++media_it;
}
- congestion_controller_->GetRemoteBitrateEstimator(UseSendSideBwe(config))
+ transport_->congestion_controller()
+ ->GetRemoteBitrateEstimator(UseSendSideBwe(config))
->RemoveStream(ssrc);
flexfec_receive_streams_.erase(receive_stream_impl);
@@ -832,15 +871,18 @@ Call::Stats Call::GetStats() const {
Stats stats;
// Fetch available send/receive bitrates.
uint32_t send_bandwidth = 0;
- congestion_controller_->GetBitrateController()->AvailableBandwidth(
- &send_bandwidth);
+ transport_->congestion_controller()
+ ->GetBitrateController()
+ ->AvailableBandwidth(&send_bandwidth);
std::vector<unsigned int> ssrcs;
uint32_t recv_bandwidth = 0;
- congestion_controller_->GetRemoteBitrateEstimator(false)->LatestEstimate(
- &ssrcs, &recv_bandwidth);
+ transport_->congestion_controller()
+ ->GetRemoteBitrateEstimator(false)
+ ->LatestEstimate(&ssrcs, &recv_bandwidth);
stats.send_bandwidth_bps = send_bandwidth;
stats.recv_bandwidth_bps = recv_bandwidth;
- stats.pacer_delay_ms = congestion_controller_->GetPacerQueuingDelayMs();
+ stats.pacer_delay_ms =
+ transport_->congestion_controller()->GetPacerQueuingDelayMs();
stats.rtt_ms = call_stats_->rtcp_rtt_stats()->LastProcessedRtt();
{
rtc::CritScope cs(&bitrate_crit_);
@@ -873,9 +915,9 @@ void Call::SetBitrateConfig(
config_.bitrate_config.start_bitrate_bps = bitrate_config.start_bitrate_bps;
config_.bitrate_config.max_bitrate_bps = bitrate_config.max_bitrate_bps;
RTC_DCHECK_NE(bitrate_config.start_bitrate_bps, 0);
- congestion_controller_->SetBweBitrates(bitrate_config.min_bitrate_bps,
- bitrate_config.start_bitrate_bps,
- bitrate_config.max_bitrate_bps);
+ transport_->congestion_controller()->SetBweBitrates(
+ bitrate_config.min_bitrate_bps, bitrate_config.start_bitrate_bps,
+ bitrate_config.max_bitrate_bps);
}
void Call::SignalChannelNetworkState(MediaType media, NetworkState state) {
@@ -970,7 +1012,7 @@ void Call::OnNetworkRouteChanged(const std::string& transport_name,
<< " bps, max: " << config_.bitrate_config.start_bitrate_bps
<< " bps.";
RTC_DCHECK_GT(config_.bitrate_config.start_bitrate_bps, 0);
- congestion_controller_->ResetBweAndBitrates(
+ transport_->congestion_controller()->ResetBweAndBitrates(
config_.bitrate_config.start_bitrate_bps,
config_.bitrate_config.min_bitrate_bps,
config_.bitrate_config.max_bitrate_bps);
@@ -1006,7 +1048,7 @@ void Call::UpdateAggregateNetworkState() {
LOG(LS_INFO) << "UpdateAggregateNetworkState: aggregate_state="
<< (aggregate_state == kNetworkUp ? "up" : "down");
- congestion_controller_->SignalNetworkState(aggregate_state);
+ transport_->congestion_controller()->SignalNetworkState(aggregate_state);
}
void Call::OnSentPacket(const rtc::SentPacket& sent_packet) {
@@ -1014,7 +1056,7 @@ void Call::OnSentPacket(const rtc::SentPacket& sent_packet) {
first_packet_sent_ms_ = clock_->TimeInMilliseconds();
video_send_delay_stats_->OnSentPacket(sent_packet.packet_id,
clock_->TimeInMilliseconds());
- congestion_controller_->OnSentPacket(sent_packet);
+ transport_->congestion_controller()->OnSentPacket(sent_packet);
}
void Call::OnNetworkChanged(uint32_t target_bitrate_bps,
@@ -1065,7 +1107,7 @@ void Call::OnNetworkChanged(uint32_t target_bitrate_bps,
void Call::OnAllocationLimitsChanged(uint32_t min_send_bitrate_bps,
uint32_t max_padding_bitrate_bps) {
- congestion_controller_->SetAllocatedSendBitrateLimits(
+ transport_->congestion_controller()->SetAllocatedSendBitrateLimits(
min_send_bitrate_bps, max_padding_bitrate_bps);
rtc::CritScope lock(&bitrate_crit_);
min_allocated_send_bitrate_bps_ = min_send_bitrate_bps;
@@ -1278,11 +1320,12 @@ void Call::NotifyBweOfReceivedPacket(const RtpPacketReceived& packet,
// should be fixed to use the same MediaType as the production code.
if (media_type != MediaType::AUDIO ||
(use_send_side_bwe && header.extension.hasTransportSequenceNumber)) {
- congestion_controller_->OnReceivedPacket(
+ transport_->congestion_controller()->OnReceivedPacket(
packet.arrival_time_ms(), packet.payload_size() + packet.padding_size(),
header);
}
}
} // namespace internal
+
} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698