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

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

Issue 1704983002: Simplify CongestionController. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Comments addressed. Created 4 years, 10 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 unified diff | Download patch
« no previous file with comments | « webrtc/call/congestion_controller.h ('k') | webrtc/call/mock/mock_congestion_controller.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <algorithm> 13 #include <algorithm>
14 #include <vector> 14 #include <vector>
15 15
16 #include "webrtc/base/checks.h" 16 #include "webrtc/base/checks.h"
17 #include "webrtc/base/logging.h" 17 #include "webrtc/base/logging.h"
18 #include "webrtc/base/socket.h" 18 #include "webrtc/base/socket.h"
19 #include "webrtc/base/thread_annotations.h" 19 #include "webrtc/base/thread_annotations.h"
20 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" 20 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h"
21 #include "webrtc/modules/pacing/paced_sender.h" 21 #include "webrtc/modules/pacing/paced_sender.h"
22 #include "webrtc/modules/pacing/packet_router.h"
23 #include "webrtc/modules/remote_bitrate_estimator/include/send_time_history.h" 22 #include "webrtc/modules/remote_bitrate_estimator/include/send_time_history.h"
24 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_s end_time.h" 23 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_s end_time.h"
25 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_singl e_stream.h" 24 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_singl e_stream.h"
26 #include "webrtc/modules/remote_bitrate_estimator/remote_estimator_proxy.h"
27 #include "webrtc/modules/remote_bitrate_estimator/transport_feedback_adapter.h"
28 #include "webrtc/modules/utility/include/process_thread.h" 25 #include "webrtc/modules/utility/include/process_thread.h"
29 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" 26 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
30 #include "webrtc/video/call_stats.h"
31 #include "webrtc/video/payload_router.h" 27 #include "webrtc/video/payload_router.h"
32 28
33 namespace webrtc { 29 namespace webrtc {
34 namespace { 30 namespace {
35 31
36 static const uint32_t kTimeOffsetSwitchThreshold = 30; 32 static const uint32_t kTimeOffsetSwitchThreshold = 30;
37 33
38 class WrappingBitrateEstimator : public RemoteBitrateEstimator { 34 class WrappingBitrateEstimator : public RemoteBitrateEstimator {
39 public: 35 public:
40 WrappingBitrateEstimator(RemoteBitrateObserver* observer, Clock* clock) 36 WrappingBitrateEstimator(RemoteBitrateObserver* observer, Clock* clock)
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 uint32_t packets_since_absolute_send_time_; 129 uint32_t packets_since_absolute_send_time_;
134 int min_bitrate_bps_; 130 int min_bitrate_bps_;
135 131
136 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(WrappingBitrateEstimator); 132 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(WrappingBitrateEstimator);
137 }; 133 };
138 134
139 } // namespace 135 } // namespace
140 136
141 CongestionController::CongestionController( 137 CongestionController::CongestionController(
142 Clock* clock, 138 Clock* clock,
143 ProcessThread* process_thread,
144 CallStats* call_stats,
145 BitrateObserver* bitrate_observer, 139 BitrateObserver* bitrate_observer,
146 RemoteBitrateObserver* remote_bitrate_observer) 140 RemoteBitrateObserver* remote_bitrate_observer)
147 : clock_(clock), 141 : clock_(clock),
148 packet_router_(new PacketRouter()),
149 pacer_(new PacedSender(clock_, 142 pacer_(new PacedSender(clock_,
150 packet_router_.get(), 143 &packet_router_,
151 BitrateController::kDefaultStartBitrateKbps, 144 BitrateController::kDefaultStartBitrateKbps,
152 PacedSender::kDefaultPaceMultiplier * 145 PacedSender::kDefaultPaceMultiplier *
153 BitrateController::kDefaultStartBitrateKbps, 146 BitrateController::kDefaultStartBitrateKbps,
154 0)), 147 0)),
155 remote_bitrate_estimator_( 148 remote_bitrate_estimator_(
156 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)), 149 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)),
157 remote_estimator_proxy_(
158 new RemoteEstimatorProxy(clock_, packet_router_.get())),
159 process_thread_(process_thread),
160 call_stats_(call_stats),
161 pacer_thread_(ProcessThread::Create("PacerThread")), 150 pacer_thread_(ProcessThread::Create("PacerThread")),
162 // Constructed last as this object calls the provided callback on 151 // Constructed last as this object calls the provided callback on
163 // construction. 152 // construction.
164 bitrate_controller_( 153 bitrate_controller_(
165 BitrateController::CreateBitrateController(clock_, bitrate_observer)), 154 BitrateController::CreateBitrateController(clock_, bitrate_observer)),
155 remote_estimator_proxy_(clock_, &packet_router_),
156 transport_feedback_adapter_(bitrate_controller_.get(), clock_),
166 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps) { 157 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps) {
167 call_stats_->RegisterStatsObserver(remote_bitrate_estimator_.get()); 158 transport_feedback_adapter_.SetBitrateEstimator(
168 159 new RemoteBitrateEstimatorAbsSendTime(&transport_feedback_adapter_,
160 clock_));
161 transport_feedback_adapter_.GetBitrateEstimator()->SetMinBitrate(
162 min_bitrate_bps_);
169 pacer_thread_->RegisterModule(pacer_.get()); 163 pacer_thread_->RegisterModule(pacer_.get());
170 pacer_thread_->RegisterModule(remote_estimator_proxy_.get()); 164 pacer_thread_->RegisterModule(&remote_estimator_proxy_);
171 pacer_thread_->Start(); 165 pacer_thread_->Start();
172
173 process_thread_->RegisterModule(remote_bitrate_estimator_.get());
174 process_thread_->RegisterModule(bitrate_controller_.get());
175 } 166 }
176 167
177 CongestionController::~CongestionController() { 168 CongestionController::~CongestionController() {
178 pacer_thread_->Stop(); 169 pacer_thread_->Stop();
179 pacer_thread_->DeRegisterModule(pacer_.get()); 170 pacer_thread_->DeRegisterModule(pacer_.get());
180 pacer_thread_->DeRegisterModule(remote_estimator_proxy_.get()); 171 pacer_thread_->DeRegisterModule(&remote_estimator_proxy_);
181 process_thread_->DeRegisterModule(bitrate_controller_.get());
182 process_thread_->DeRegisterModule(remote_bitrate_estimator_.get());
183 call_stats_->DeregisterStatsObserver(remote_bitrate_estimator_.get());
184 if (transport_feedback_adapter_.get())
185 call_stats_->DeregisterStatsObserver(transport_feedback_adapter_.get());
186 } 172 }
187 173
188 174
189 void CongestionController::SetBweBitrates(int min_bitrate_bps, 175 void CongestionController::SetBweBitrates(int min_bitrate_bps,
190 int start_bitrate_bps, 176 int start_bitrate_bps,
191 int max_bitrate_bps) { 177 int max_bitrate_bps) {
178 RTC_DCHECK(config_thread_checker_.CalledOnValidThread());
192 // TODO(holmer): We should make sure the default bitrates are set to 10 kbps, 179 // TODO(holmer): We should make sure the default bitrates are set to 10 kbps,
193 // and that we don't try to set the min bitrate to 0 from any applications. 180 // and that we don't try to set the min bitrate to 0 from any applications.
194 // The congestion controller should allow a min bitrate of 0. 181 // The congestion controller should allow a min bitrate of 0.
195 const int kMinBitrateBps = 10000; 182 const int kMinBitrateBps = 10000;
196 if (min_bitrate_bps < kMinBitrateBps) 183 if (min_bitrate_bps < kMinBitrateBps)
197 min_bitrate_bps = kMinBitrateBps; 184 min_bitrate_bps = kMinBitrateBps;
198 if (max_bitrate_bps > 0) 185 if (max_bitrate_bps > 0)
199 max_bitrate_bps = std::max(min_bitrate_bps, max_bitrate_bps); 186 max_bitrate_bps = std::max(min_bitrate_bps, max_bitrate_bps);
200 if (start_bitrate_bps > 0) { 187 if (start_bitrate_bps > 0) {
201 start_bitrate_bps = std::max(min_bitrate_bps, start_bitrate_bps); 188 start_bitrate_bps = std::max(min_bitrate_bps, start_bitrate_bps);
202 bitrate_controller_->SetStartBitrate(start_bitrate_bps); 189 bitrate_controller_->SetStartBitrate(start_bitrate_bps);
203 } 190 }
204 bitrate_controller_->SetMinMaxBitrate(min_bitrate_bps, max_bitrate_bps); 191 bitrate_controller_->SetMinMaxBitrate(min_bitrate_bps, max_bitrate_bps);
205 if (remote_bitrate_estimator_.get()) 192 if (remote_bitrate_estimator_)
206 remote_bitrate_estimator_->SetMinBitrate(min_bitrate_bps); 193 remote_bitrate_estimator_->SetMinBitrate(min_bitrate_bps);
207 if (transport_feedback_adapter_.get())
208 transport_feedback_adapter_->GetBitrateEstimator()->SetMinBitrate(
209 min_bitrate_bps);
210 min_bitrate_bps_ = min_bitrate_bps; 194 min_bitrate_bps_ = min_bitrate_bps;
195 transport_feedback_adapter_.GetBitrateEstimator()->SetMinBitrate(
196 min_bitrate_bps_);
211 } 197 }
212 198
213 BitrateController* CongestionController::GetBitrateController() const { 199 BitrateController* CongestionController::GetBitrateController() const {
214 return bitrate_controller_.get(); 200 return bitrate_controller_.get();
215 } 201 }
216 202
217 RemoteBitrateEstimator* CongestionController::GetRemoteBitrateEstimator( 203 RemoteBitrateEstimator* CongestionController::GetRemoteBitrateEstimator(
218 bool send_side_bwe) const { 204 bool send_side_bwe) {
219 205 if (send_side_bwe) {
220 if (send_side_bwe) 206 return &remote_estimator_proxy_;
221 return remote_estimator_proxy_.get(); 207 } else {
222 else
223 return remote_bitrate_estimator_.get(); 208 return remote_bitrate_estimator_.get();
209 }
224 } 210 }
225 211
226 TransportFeedbackObserver* 212 TransportFeedbackObserver*
227 CongestionController::GetTransportFeedbackObserver() { 213 CongestionController::GetTransportFeedbackObserver() {
228 if (transport_feedback_adapter_.get() == nullptr) { 214 RTC_DCHECK(config_thread_checker_.CalledOnValidThread());
229 transport_feedback_adapter_.reset(new TransportFeedbackAdapter( 215 return &transport_feedback_adapter_;
230 bitrate_controller_.get(), clock_, process_thread_));
231 transport_feedback_adapter_->SetBitrateEstimator(
232 new RemoteBitrateEstimatorAbsSendTime(transport_feedback_adapter_.get(),
233 clock_));
234 transport_feedback_adapter_->GetBitrateEstimator()->SetMinBitrate(
235 min_bitrate_bps_);
236 call_stats_->RegisterStatsObserver(transport_feedback_adapter_.get());
237 }
238 return transport_feedback_adapter_.get();
239 } 216 }
240 217
241 void CongestionController::UpdatePacerBitrate(int bitrate_kbps, 218 void CongestionController::UpdatePacerBitrate(int bitrate_kbps,
242 int max_bitrate_kbps, 219 int max_bitrate_kbps,
243 int min_bitrate_kbps) { 220 int min_bitrate_kbps) {
244 pacer_->UpdateBitrate(bitrate_kbps, max_bitrate_kbps, min_bitrate_kbps); 221 pacer_->UpdateBitrate(bitrate_kbps, max_bitrate_kbps, min_bitrate_kbps);
245 } 222 }
246 223
247 int64_t CongestionController::GetPacerQueuingDelayMs() const { 224 int64_t CongestionController::GetPacerQueuingDelayMs() const {
248 return pacer_->QueueInMs(); 225 return pacer_->QueueInMs();
249 } 226 }
250 227
251 void CongestionController::SignalNetworkState(NetworkState state) { 228 void CongestionController::SignalNetworkState(NetworkState state) {
252 if (state == kNetworkUp) { 229 if (state == kNetworkUp) {
253 pacer_->Resume(); 230 pacer_->Resume();
254 } else { 231 } else {
255 pacer_->Pause(); 232 pacer_->Pause();
256 } 233 }
257 } 234 }
258 235
259 void CongestionController::OnSentPacket(const rtc::SentPacket& sent_packet) { 236 void CongestionController::OnSentPacket(const rtc::SentPacket& sent_packet) {
260 if (transport_feedback_adapter_) { 237 transport_feedback_adapter_.OnSentPacket(sent_packet.packet_id,
261 transport_feedback_adapter_->OnSentPacket(sent_packet.packet_id, 238 sent_packet.send_time_ms);
262 sent_packet.send_time_ms);
263 }
264 } 239 }
240
241 void CongestionController::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) {
242 remote_bitrate_estimator_->OnRttUpdate(avg_rtt_ms, max_rtt_ms);
243 transport_feedback_adapter_.OnRttUpdate(avg_rtt_ms, max_rtt_ms);
244 }
245
246 int64_t CongestionController::TimeUntilNextProcess() {
247 return std::min(bitrate_controller_->TimeUntilNextProcess(),
248 remote_bitrate_estimator_->TimeUntilNextProcess());
249 }
250
251 int32_t CongestionController::Process() {
252 bitrate_controller_->Process();
253 remote_bitrate_estimator_->Process();
254 return 0;
255 }
256
265 } // namespace webrtc 257 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/call/congestion_controller.h ('k') | webrtc/call/mock/mock_congestion_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698