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

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

Issue 2378103005: Reland: Fix race / crash in OnNetworkRouteChanged(). (Closed)
Patch Set: . Created 4 years, 2 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
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/modules/congestion_controller/include/congestion_controller.h" 11 #include "webrtc/modules/congestion_controller/include/congestion_controller.h"
12 12
13 #include <algorithm> 13 #include <algorithm>
14 #include <memory> 14 #include <memory>
15 #include <vector> 15 #include <vector>
16 16
17 #include "webrtc/base/checks.h" 17 #include "webrtc/base/checks.h"
18 #include "webrtc/base/constructormagic.h" 18 #include "webrtc/base/constructormagic.h"
19 #include "webrtc/base/logging.h" 19 #include "webrtc/base/logging.h"
20 #include "webrtc/base/rate_limiter.h" 20 #include "webrtc/base/rate_limiter.h"
21 #include "webrtc/base/socket.h" 21 #include "webrtc/base/socket.h"
22 #include "webrtc/base/thread_annotations.h" 22 #include "webrtc/base/thread_annotations.h"
23 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" 23 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h"
24 #include "webrtc/modules/congestion_controller/delay_based_bwe.h"
25 #include "webrtc/modules/congestion_controller/probe_controller.h" 24 #include "webrtc/modules/congestion_controller/probe_controller.h"
26 #include "webrtc/modules/remote_bitrate_estimator/include/send_time_history.h" 25 #include "webrtc/modules/remote_bitrate_estimator/include/send_time_history.h"
27 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_s end_time.h" 26 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_s end_time.h"
28 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_singl e_stream.h" 27 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_singl e_stream.h"
29 #include "webrtc/modules/utility/include/process_thread.h" 28 #include "webrtc/modules/utility/include/process_thread.h"
30 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" 29 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
31 #include "webrtc/video/payload_router.h" 30 #include "webrtc/video/payload_router.h"
32 31
33 namespace webrtc { 32 namespace webrtc {
34 namespace { 33 namespace {
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 packet_router_(new PacketRouter()), 163 packet_router_(new PacketRouter()),
165 pacer_(new PacedSender(clock_, packet_router_.get())), 164 pacer_(new PacedSender(clock_, packet_router_.get())),
166 remote_bitrate_estimator_( 165 remote_bitrate_estimator_(
167 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)), 166 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)),
168 bitrate_controller_( 167 bitrate_controller_(
169 BitrateController::CreateBitrateController(clock_, event_log)), 168 BitrateController::CreateBitrateController(clock_, event_log)),
170 probe_controller_(new ProbeController(pacer_.get(), clock_)), 169 probe_controller_(new ProbeController(pacer_.get(), clock_)),
171 retransmission_rate_limiter_( 170 retransmission_rate_limiter_(
172 new RateLimiter(clock, kRetransmitWindowSizeMs)), 171 new RateLimiter(clock, kRetransmitWindowSizeMs)),
173 remote_estimator_proxy_(clock_, packet_router_.get()), 172 remote_estimator_proxy_(clock_, packet_router_.get()),
174 transport_feedback_adapter_(clock_), 173 transport_feedback_adapter_(clock_, bitrate_controller_.get()),
175 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps), 174 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps),
176 max_bitrate_bps_(0), 175 max_bitrate_bps_(0),
177 last_reported_bitrate_bps_(0), 176 last_reported_bitrate_bps_(0),
178 last_reported_fraction_loss_(0), 177 last_reported_fraction_loss_(0),
179 last_reported_rtt_(0), 178 last_reported_rtt_(0),
180 network_state_(kNetworkUp) { 179 network_state_(kNetworkUp) {
181 Init(); 180 Init();
182 } 181 }
183 182
184 CongestionController::CongestionController( 183 CongestionController::CongestionController(
(...skipping 10 matching lines...) Expand all
195 remote_bitrate_estimator_( 194 remote_bitrate_estimator_(
196 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)), 195 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)),
197 // Constructed last as this object calls the provided callback on 196 // Constructed last as this object calls the provided callback on
198 // construction. 197 // construction.
199 bitrate_controller_( 198 bitrate_controller_(
200 BitrateController::CreateBitrateController(clock_, event_log)), 199 BitrateController::CreateBitrateController(clock_, event_log)),
201 probe_controller_(new ProbeController(pacer_.get(), clock_)), 200 probe_controller_(new ProbeController(pacer_.get(), clock_)),
202 retransmission_rate_limiter_( 201 retransmission_rate_limiter_(
203 new RateLimiter(clock, kRetransmitWindowSizeMs)), 202 new RateLimiter(clock, kRetransmitWindowSizeMs)),
204 remote_estimator_proxy_(clock_, packet_router_.get()), 203 remote_estimator_proxy_(clock_, packet_router_.get()),
205 transport_feedback_adapter_(clock_), 204 transport_feedback_adapter_(clock_, bitrate_controller_.get()),
206 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps), 205 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps),
207 max_bitrate_bps_(0), 206 max_bitrate_bps_(0),
208 last_reported_bitrate_bps_(0), 207 last_reported_bitrate_bps_(0),
209 last_reported_fraction_loss_(0), 208 last_reported_fraction_loss_(0),
210 last_reported_rtt_(0), 209 last_reported_rtt_(0),
211 network_state_(kNetworkUp) { 210 network_state_(kNetworkUp) {
212 Init(); 211 Init();
213 } 212 }
214 213
215 CongestionController::~CongestionController() {} 214 CongestionController::~CongestionController() {}
216 215
217 void CongestionController::Init() { 216 void CongestionController::Init() {
218 transport_feedback_adapter_.SetBitrateEstimator( 217 transport_feedback_adapter_.InitBwe();
219 new DelayBasedBwe(bitrate_controller_.get(), clock_)); 218 transport_feedback_adapter_.SetMinBitrate(min_bitrate_bps_);
220 transport_feedback_adapter_.GetBitrateEstimator()->SetMinBitrate(
221 min_bitrate_bps_);
222 } 219 }
223 220
224 void CongestionController::SetBweBitrates(int min_bitrate_bps, 221 void CongestionController::SetBweBitrates(int min_bitrate_bps,
225 int start_bitrate_bps, 222 int start_bitrate_bps,
226 int max_bitrate_bps) { 223 int max_bitrate_bps) {
227 ClampBitrates(&start_bitrate_bps, &min_bitrate_bps, &max_bitrate_bps); 224 ClampBitrates(&start_bitrate_bps, &min_bitrate_bps, &max_bitrate_bps);
228 bitrate_controller_->SetBitrates(start_bitrate_bps, 225 bitrate_controller_->SetBitrates(start_bitrate_bps,
229 min_bitrate_bps, 226 min_bitrate_bps,
230 max_bitrate_bps); 227 max_bitrate_bps);
231 228
232 probe_controller_->SetBitrates(min_bitrate_bps, start_bitrate_bps, 229 probe_controller_->SetBitrates(min_bitrate_bps, start_bitrate_bps,
233 max_bitrate_bps); 230 max_bitrate_bps);
234 max_bitrate_bps_ = max_bitrate_bps; 231 max_bitrate_bps_ = max_bitrate_bps;
235 232
236 if (remote_bitrate_estimator_) 233 if (remote_bitrate_estimator_)
237 remote_bitrate_estimator_->SetMinBitrate(min_bitrate_bps); 234 remote_bitrate_estimator_->SetMinBitrate(min_bitrate_bps);
238 min_bitrate_bps_ = min_bitrate_bps; 235 min_bitrate_bps_ = min_bitrate_bps;
239 transport_feedback_adapter_.GetBitrateEstimator()->SetMinBitrate( 236 transport_feedback_adapter_.SetMinBitrate(min_bitrate_bps_);
240 min_bitrate_bps_);
241 MaybeTriggerOnNetworkChanged(); 237 MaybeTriggerOnNetworkChanged();
242 } 238 }
243 239
244 void CongestionController::ResetBweAndBitrates(int bitrate_bps, 240 void CongestionController::ResetBweAndBitrates(int bitrate_bps,
245 int min_bitrate_bps, 241 int min_bitrate_bps,
246 int max_bitrate_bps) { 242 int max_bitrate_bps) {
247 ClampBitrates(&bitrate_bps, &min_bitrate_bps, &max_bitrate_bps); 243 ClampBitrates(&bitrate_bps, &min_bitrate_bps, &max_bitrate_bps);
248 // TODO(honghaiz): Recreate this object once the bitrate controller is 244 // TODO(honghaiz): Recreate this object once the bitrate controller is
249 // no longer exposed outside CongestionController. 245 // no longer exposed outside CongestionController.
250 bitrate_controller_->ResetBitrates(bitrate_bps, min_bitrate_bps, 246 bitrate_controller_->ResetBitrates(bitrate_bps, min_bitrate_bps,
251 max_bitrate_bps); 247 max_bitrate_bps);
252 min_bitrate_bps_ = min_bitrate_bps; 248 min_bitrate_bps_ = min_bitrate_bps;
253 max_bitrate_bps_ = max_bitrate_bps; 249 max_bitrate_bps_ = max_bitrate_bps;
254 // TODO(honghaiz): Recreate this object once the remote bitrate estimator is 250 // TODO(honghaiz): Recreate this object once the remote bitrate estimator is
255 // no longer exposed outside CongestionController. 251 // no longer exposed outside CongestionController.
256 if (remote_bitrate_estimator_) 252 if (remote_bitrate_estimator_)
257 remote_bitrate_estimator_->SetMinBitrate(min_bitrate_bps); 253 remote_bitrate_estimator_->SetMinBitrate(min_bitrate_bps);
258 254
259 RemoteBitrateEstimator* rbe = 255 transport_feedback_adapter_.InitBwe();
260 new DelayBasedBwe(bitrate_controller_.get(), clock_); 256 transport_feedback_adapter_.SetMinBitrate(min_bitrate_bps);
261 transport_feedback_adapter_.SetBitrateEstimator(rbe);
262 rbe->SetMinBitrate(min_bitrate_bps);
263 // TODO(holmer): Trigger a new probe once mid-call probing is implemented. 257 // TODO(holmer): Trigger a new probe once mid-call probing is implemented.
264 MaybeTriggerOnNetworkChanged(); 258 MaybeTriggerOnNetworkChanged();
265 } 259 }
266 260
267 BitrateController* CongestionController::GetBitrateController() const { 261 BitrateController* CongestionController::GetBitrateController() const {
268 return bitrate_controller_.get(); 262 return bitrate_controller_.get();
269 } 263 }
270 264
271 RemoteBitrateEstimator* CongestionController::GetRemoteBitrateEstimator( 265 RemoteBitrateEstimator* CongestionController::GetRemoteBitrateEstimator(
272 bool send_side_bwe) { 266 bool send_side_bwe) {
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 bool CongestionController::IsSendQueueFull() const { 372 bool CongestionController::IsSendQueueFull() const {
379 return pacer_->ExpectedQueueTimeMs() > PacedSender::kMaxQueueLengthMs; 373 return pacer_->ExpectedQueueTimeMs() > PacedSender::kMaxQueueLengthMs;
380 } 374 }
381 375
382 bool CongestionController::IsNetworkDown() const { 376 bool CongestionController::IsNetworkDown() const {
383 rtc::CritScope cs(&critsect_); 377 rtc::CritScope cs(&critsect_);
384 return network_state_ == kNetworkDown; 378 return network_state_ == kNetworkDown;
385 } 379 }
386 380
387 } // namespace webrtc 381 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/congestion_controller/BUILD.gn ('k') | webrtc/modules/congestion_controller/congestion_controller.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698