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

Side by Side Diff: webrtc/call/congestion_controller.cc

Issue 1441673002: Move BitrateAllocator from BitrateController logic to Call. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebase Created 5 years, 1 month 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/call/congestion_controller.h" 11 #include "webrtc/call/congestion_controller.h"
12 12
13 #include "webrtc/base/checks.h" 13 #include "webrtc/base/checks.h"
14 #include "webrtc/base/thread_annotations.h" 14 #include "webrtc/base/thread_annotations.h"
15 #include "webrtc/common.h" 15 #include "webrtc/common.h"
16 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h"
16 #include "webrtc/modules/pacing/include/paced_sender.h" 17 #include "webrtc/modules/pacing/include/paced_sender.h"
17 #include "webrtc/modules/pacing/include/packet_router.h" 18 #include "webrtc/modules/pacing/include/packet_router.h"
18 #include "webrtc/modules/remote_bitrate_estimator/include/send_time_history.h" 19 #include "webrtc/modules/remote_bitrate_estimator/include/send_time_history.h"
19 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_s end_time.h" 20 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_s end_time.h"
20 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_singl e_stream.h" 21 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_singl e_stream.h"
21 #include "webrtc/modules/remote_bitrate_estimator/remote_estimator_proxy.h" 22 #include "webrtc/modules/remote_bitrate_estimator/remote_estimator_proxy.h"
22 #include "webrtc/modules/remote_bitrate_estimator/transport_feedback_adapter.h" 23 #include "webrtc/modules/remote_bitrate_estimator/transport_feedback_adapter.h"
23 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" 24 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
24 #include "webrtc/modules/utility/include/process_thread.h" 25 #include "webrtc/modules/utility/include/process_thread.h"
25 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" 26 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 bool using_absolute_send_time_; 138 bool using_absolute_send_time_;
138 uint32_t packets_since_absolute_send_time_; 139 uint32_t packets_since_absolute_send_time_;
139 int min_bitrate_bps_; 140 int min_bitrate_bps_;
140 141
141 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(WrappingBitrateEstimator); 142 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(WrappingBitrateEstimator);
142 }; 143 };
143 144
144 } // namespace 145 } // namespace
145 146
146 CongestionController::CongestionController(ProcessThread* process_thread, 147 CongestionController::CongestionController(ProcessThread* process_thread,
147 CallStats* call_stats) 148 CallStats* call_stats,
149 BitrateObserver* bitrate_observer)
148 : remb_(new VieRemb()), 150 : remb_(new VieRemb()),
149 bitrate_allocator_(new BitrateAllocator()),
150 packet_router_(new PacketRouter()), 151 packet_router_(new PacketRouter()),
151 pacer_(new PacedSender(Clock::GetRealTimeClock(), 152 pacer_(new PacedSender(Clock::GetRealTimeClock(),
152 packet_router_.get(), 153 packet_router_.get(),
153 BitrateController::kDefaultStartBitrateKbps, 154 BitrateController::kDefaultStartBitrateKbps,
154 PacedSender::kDefaultPaceMultiplier * 155 PacedSender::kDefaultPaceMultiplier *
155 BitrateController::kDefaultStartBitrateKbps, 156 BitrateController::kDefaultStartBitrateKbps,
156 0)), 157 0)),
157 remote_bitrate_estimator_( 158 remote_bitrate_estimator_(
158 new WrappingBitrateEstimator(remb_.get(), Clock::GetRealTimeClock())), 159 new WrappingBitrateEstimator(remb_.get(), Clock::GetRealTimeClock())),
159 remote_estimator_proxy_( 160 remote_estimator_proxy_(
160 new RemoteEstimatorProxy(Clock::GetRealTimeClock(), 161 new RemoteEstimatorProxy(Clock::GetRealTimeClock(),
161 packet_router_.get())), 162 packet_router_.get())),
162 process_thread_(process_thread), 163 process_thread_(process_thread),
163 call_stats_(call_stats), 164 call_stats_(call_stats),
164 pacer_thread_(ProcessThread::Create("PacerThread")), 165 pacer_thread_(ProcessThread::Create("PacerThread")),
165 // Constructed last as this object calls the provided callback on 166 // Constructed last as this object calls the provided callback on
166 // construction. 167 // construction.
167 bitrate_controller_( 168 bitrate_controller_(
168 BitrateController::CreateBitrateController(Clock::GetRealTimeClock(), 169 BitrateController::CreateBitrateController(Clock::GetRealTimeClock(),
169 this)), 170 bitrate_observer)),
170 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps) { 171 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps) {
171 call_stats_->RegisterStatsObserver(remote_bitrate_estimator_.get()); 172 call_stats_->RegisterStatsObserver(remote_bitrate_estimator_.get());
172 173
173 pacer_thread_->RegisterModule(pacer_.get()); 174 pacer_thread_->RegisterModule(pacer_.get());
174 pacer_thread_->Start(); 175 pacer_thread_->Start();
175 176
176 process_thread->RegisterModule(remote_estimator_proxy_.get()); 177 process_thread->RegisterModule(remote_estimator_proxy_.get());
177 process_thread->RegisterModule(remote_bitrate_estimator_.get()); 178 process_thread->RegisterModule(remote_bitrate_estimator_.get());
178 process_thread->RegisterModule(bitrate_controller_.get()); 179 process_thread->RegisterModule(bitrate_controller_.get());
179 } 180 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 transport_feedback_adapter_->SetBitrateEstimator( 243 transport_feedback_adapter_->SetBitrateEstimator(
243 new RemoteBitrateEstimatorAbsSendTime( 244 new RemoteBitrateEstimatorAbsSendTime(
244 transport_feedback_adapter_.get(), Clock::GetRealTimeClock())); 245 transport_feedback_adapter_.get(), Clock::GetRealTimeClock()));
245 transport_feedback_adapter_->GetBitrateEstimator()->SetMinBitrate( 246 transport_feedback_adapter_->GetBitrateEstimator()->SetMinBitrate(
246 min_bitrate_bps_); 247 min_bitrate_bps_);
247 call_stats_->RegisterStatsObserver(transport_feedback_adapter_.get()); 248 call_stats_->RegisterStatsObserver(transport_feedback_adapter_.get());
248 } 249 }
249 return transport_feedback_adapter_.get(); 250 return transport_feedback_adapter_.get();
250 } 251 }
251 252
253 void CongestionController::UpdatePacerBitrate(int bitrate_kbps,
254 int max_bitrate_kbps,
255 int min_bitrate_kbps) {
256 pacer_->UpdateBitrate(bitrate_kbps, max_bitrate_kbps, min_bitrate_kbps);
257 }
258
252 int64_t CongestionController::GetPacerQueuingDelayMs() const { 259 int64_t CongestionController::GetPacerQueuingDelayMs() const {
253 return pacer_->QueueInMs(); 260 return pacer_->QueueInMs();
254 } 261 }
255 262
256 // TODO(mflodman): Move out of this class. 263 // TODO(mflodman): Move out of this class.
257 void CongestionController::SetChannelRembStatus(bool sender, 264 void CongestionController::SetChannelRembStatus(bool sender,
258 bool receiver, 265 bool receiver,
259 RtpRtcp* rtp_module) { 266 RtpRtcp* rtp_module) {
260 rtp_module->SetREMBStatus(sender || receiver); 267 rtp_module->SetREMBStatus(sender || receiver);
261 if (sender) { 268 if (sender) {
262 remb_->AddRembSender(rtp_module); 269 remb_->AddRembSender(rtp_module);
263 } else { 270 } else {
264 remb_->RemoveRembSender(rtp_module); 271 remb_->RemoveRembSender(rtp_module);
265 } 272 }
266 if (receiver) { 273 if (receiver) {
267 remb_->AddReceiveChannel(rtp_module); 274 remb_->AddReceiveChannel(rtp_module);
268 } else { 275 } else {
269 remb_->RemoveReceiveChannel(rtp_module); 276 remb_->RemoveReceiveChannel(rtp_module);
270 } 277 }
271 } 278 }
272 279
273 void CongestionController::SignalNetworkState(NetworkState state) { 280 void CongestionController::SignalNetworkState(NetworkState state) {
274 if (state == kNetworkUp) { 281 if (state == kNetworkUp) {
275 pacer_->Resume(); 282 pacer_->Resume();
276 } else { 283 } else {
277 pacer_->Pause(); 284 pacer_->Pause();
278 } 285 }
279 } 286 }
280 287
281 // TODO(mflodman): Move this logic out from CongestionController.
282 void CongestionController::OnNetworkChanged(uint32_t target_bitrate_bps,
283 uint8_t fraction_loss,
284 int64_t rtt) {
285 uint32_t allocated_bitrate_bps = bitrate_allocator_->OnNetworkChanged(
286 target_bitrate_bps, fraction_loss, rtt);
287 int pad_up_to_bitrate_bps = 0;
288 {
289 rtc::CritScope lock(&encoder_crit_);
290 for (const auto& encoder : encoders_)
291 pad_up_to_bitrate_bps += encoder->GetPaddingNeededBps();
292 }
293 // Allocated bitrate might be higher than bitrate estimate if enforcing min
294 // bitrate, or lower if estimate is higher than the sum of max bitrates, so
295 // set the pacer bitrate to the maximum of the two.
296 uint32_t pacer_bitrate_bps =
297 std::max(target_bitrate_bps, allocated_bitrate_bps);
298 pacer_->UpdateBitrate(
299 pacer_bitrate_bps / 1000,
300 PacedSender::kDefaultPaceMultiplier * pacer_bitrate_bps / 1000,
301 pad_up_to_bitrate_bps / 1000);
302 }
303
304 void CongestionController::OnSentPacket(const rtc::SentPacket& sent_packet) { 288 void CongestionController::OnSentPacket(const rtc::SentPacket& sent_packet) {
305 if (transport_feedback_adapter_) { 289 if (transport_feedback_adapter_) {
306 transport_feedback_adapter_->OnSentPacket(sent_packet.packet_id, 290 transport_feedback_adapter_->OnSentPacket(sent_packet.packet_id,
307 sent_packet.send_time_ms); 291 sent_packet.send_time_ms);
308 } 292 }
309 } 293 }
310 } // namespace webrtc 294 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698