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

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

Issue 1947873002: Reland of Remove SendPacer from ViEEncoder (patchset #13 id:240001 of https://codereview.we… (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fixed CongestionController backwards compatibility Created 4 years, 7 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/socket.h" 20 #include "webrtc/base/socket.h"
21 #include "webrtc/base/thread_annotations.h" 21 #include "webrtc/base/thread_annotations.h"
22 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" 22 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h"
23 #include "webrtc/modules/pacing/paced_sender.h"
24 #include "webrtc/modules/remote_bitrate_estimator/include/send_time_history.h" 23 #include "webrtc/modules/remote_bitrate_estimator/include/send_time_history.h"
25 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_s end_time.h" 24 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_s end_time.h"
26 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_singl e_stream.h" 25 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_singl e_stream.h"
27 #include "webrtc/modules/utility/include/process_thread.h" 26 #include "webrtc/modules/utility/include/process_thread.h"
28 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" 27 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
29 #include "webrtc/video/payload_router.h" 28 #include "webrtc/video/payload_router.h"
30 29
31 namespace webrtc { 30 namespace webrtc {
32 namespace { 31 namespace {
33 32
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(WrappingBitrateEstimator); 133 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(WrappingBitrateEstimator);
135 }; 134 };
136 135
137 } // namespace 136 } // namespace
138 137
139 CongestionController::CongestionController( 138 CongestionController::CongestionController(
140 Clock* clock, 139 Clock* clock,
141 BitrateObserver* bitrate_observer, 140 BitrateObserver* bitrate_observer,
142 RemoteBitrateObserver* remote_bitrate_observer) 141 RemoteBitrateObserver* remote_bitrate_observer)
143 : clock_(clock), 142 : clock_(clock),
143 observer_(nullptr),
144 packet_router_(new PacketRouter()),
144 pacer_(new PacedSender(clock_, 145 pacer_(new PacedSender(clock_,
145 &packet_router_, 146 packet_router_.get(),
146 BitrateController::kDefaultStartBitrateKbps, 147 BitrateController::kDefaultStartBitratebps)),
147 PacedSender::kDefaultPaceMultiplier * 148 remote_bitrate_estimator_(
148 BitrateController::kDefaultStartBitrateKbps, 149 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)),
149 0)), 150 bitrate_controller_(
151 BitrateController::CreateBitrateController(clock_, bitrate_observer)),
152 remote_estimator_proxy_(clock_, packet_router_.get()),
153 transport_feedback_adapter_(bitrate_controller_.get(), clock_),
154 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps),
155 send_queue_is_full_(false) {
156 Init();
157 }
158
159 CongestionController::CongestionController(
160 Clock* clock,
161 Observer* observer,
162 RemoteBitrateObserver* remote_bitrate_observer)
163 : clock_(clock),
164 observer_(observer),
165 packet_router_(new PacketRouter()),
166 pacer_(new PacedSender(clock_,
167 packet_router_.get(),
168 BitrateController::kDefaultStartBitratebps)),
169 remote_bitrate_estimator_(
170 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)),
171 bitrate_controller_(BitrateController::CreateBitrateController(clock_)),
172 remote_estimator_proxy_(clock_, packet_router_.get()),
173 transport_feedback_adapter_(bitrate_controller_.get(), clock_),
174 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps),
175 send_queue_is_full_(false) {
176 Init();
177 }
178
179 CongestionController::CongestionController(
180 Clock* clock,
181 Observer* observer,
182 RemoteBitrateObserver* remote_bitrate_observer,
183 std::unique_ptr<PacketRouter> packet_router,
184 std::unique_ptr<PacedSender> pacer)
185 : clock_(clock),
186 observer_(observer),
187 packet_router_(std::move(packet_router)),
188 pacer_(std::move(pacer)),
150 remote_bitrate_estimator_( 189 remote_bitrate_estimator_(
151 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)), 190 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)),
152 // Constructed last as this object calls the provided callback on 191 // Constructed last as this object calls the provided callback on
153 // construction. 192 // construction.
154 bitrate_controller_( 193 bitrate_controller_(BitrateController::CreateBitrateController(clock_)),
155 BitrateController::CreateBitrateController(clock_, bitrate_observer)), 194 remote_estimator_proxy_(clock_, packet_router_.get()),
156 remote_estimator_proxy_(clock_, &packet_router_),
157 transport_feedback_adapter_(bitrate_controller_.get(), clock_), 195 transport_feedback_adapter_(bitrate_controller_.get(), clock_),
158 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps) { 196 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps),
197 send_queue_is_full_(false) {
198 Init();
199 }
200
201 CongestionController::~CongestionController() {}
202
203 void CongestionController::Init() {
159 transport_feedback_adapter_.SetBitrateEstimator( 204 transport_feedback_adapter_.SetBitrateEstimator(
160 new RemoteBitrateEstimatorAbsSendTime(&transport_feedback_adapter_)); 205 new RemoteBitrateEstimatorAbsSendTime(&transport_feedback_adapter_));
161 transport_feedback_adapter_.GetBitrateEstimator()->SetMinBitrate( 206 transport_feedback_adapter_.GetBitrateEstimator()->SetMinBitrate(
162 min_bitrate_bps_); 207 min_bitrate_bps_);
163 } 208 // This calls the observer_, which means that the observer provided by the
164 209 // user must be ready to accept a bitrate update when it constructs the
165 CongestionController::~CongestionController() { 210 // controller. We do this to avoid having to keep synchronized initial values
211 // in both the controller and the allocator.
212 MaybeTriggerOnNetworkChanged();
166 } 213 }
167 214
168 215
169 void CongestionController::SetBweBitrates(int min_bitrate_bps, 216 void CongestionController::SetBweBitrates(int min_bitrate_bps,
170 int start_bitrate_bps, 217 int start_bitrate_bps,
171 int max_bitrate_bps) { 218 int max_bitrate_bps) {
172 // TODO(holmer): We should make sure the default bitrates are set to 10 kbps, 219 // TODO(holmer): We should make sure the default bitrates are set to 10 kbps,
173 // and that we don't try to set the min bitrate to 0 from any applications. 220 // and that we don't try to set the min bitrate to 0 from any applications.
174 // The congestion controller should allow a min bitrate of 0. 221 // The congestion controller should allow a min bitrate of 0.
175 const int kMinBitrateBps = 10000; 222 const int kMinBitrateBps = 10000;
176 if (min_bitrate_bps < kMinBitrateBps) 223 if (min_bitrate_bps < kMinBitrateBps)
177 min_bitrate_bps = kMinBitrateBps; 224 min_bitrate_bps = kMinBitrateBps;
178 if (max_bitrate_bps > 0) 225 if (max_bitrate_bps > 0)
179 max_bitrate_bps = std::max(min_bitrate_bps, max_bitrate_bps); 226 max_bitrate_bps = std::max(min_bitrate_bps, max_bitrate_bps);
180 if (start_bitrate_bps > 0) 227 if (start_bitrate_bps > 0)
181 start_bitrate_bps = std::max(min_bitrate_bps, start_bitrate_bps); 228 start_bitrate_bps = std::max(min_bitrate_bps, start_bitrate_bps);
182 229
183 bitrate_controller_->SetBitrates(start_bitrate_bps, 230 bitrate_controller_->SetBitrates(start_bitrate_bps,
184 min_bitrate_bps, 231 min_bitrate_bps,
185 max_bitrate_bps); 232 max_bitrate_bps);
186 233
187 if (remote_bitrate_estimator_) 234 if (remote_bitrate_estimator_)
188 remote_bitrate_estimator_->SetMinBitrate(min_bitrate_bps); 235 remote_bitrate_estimator_->SetMinBitrate(min_bitrate_bps);
189 min_bitrate_bps_ = min_bitrate_bps; 236 min_bitrate_bps_ = min_bitrate_bps;
190 transport_feedback_adapter_.GetBitrateEstimator()->SetMinBitrate( 237 transport_feedback_adapter_.GetBitrateEstimator()->SetMinBitrate(
191 min_bitrate_bps_); 238 min_bitrate_bps_);
239 MaybeTriggerOnNetworkChanged();
192 } 240 }
193 241
194 BitrateController* CongestionController::GetBitrateController() const { 242 BitrateController* CongestionController::GetBitrateController() const {
195 return bitrate_controller_.get(); 243 return bitrate_controller_.get();
196 } 244 }
197 245
198 RemoteBitrateEstimator* CongestionController::GetRemoteBitrateEstimator( 246 RemoteBitrateEstimator* CongestionController::GetRemoteBitrateEstimator(
199 bool send_side_bwe) { 247 bool send_side_bwe) {
200 if (send_side_bwe) { 248 if (send_side_bwe) {
201 return &remote_estimator_proxy_; 249 return &remote_estimator_proxy_;
202 } else { 250 } else {
203 return remote_bitrate_estimator_.get(); 251 return remote_bitrate_estimator_.get();
204 } 252 }
205 } 253 }
206 254
207 TransportFeedbackObserver* 255 TransportFeedbackObserver*
208 CongestionController::GetTransportFeedbackObserver() { 256 CongestionController::GetTransportFeedbackObserver() {
209 return &transport_feedback_adapter_; 257 return &transport_feedback_adapter_;
210 } 258 }
211 259
212 void CongestionController::UpdatePacerBitrate(int bitrate_kbps, 260 void CongestionController::SetAllocatedSendBitrate(int allocated_bitrate_bps,
213 int max_bitrate_kbps, 261 int padding_bitrate_bps) {
214 int min_bitrate_kbps) { 262 pacer_->SetAllocatedSendBitrate(allocated_bitrate_bps, padding_bitrate_bps);
215 pacer_->UpdateBitrate(bitrate_kbps, max_bitrate_kbps, min_bitrate_kbps);
216 } 263 }
217 264
218 int64_t CongestionController::GetPacerQueuingDelayMs() const { 265 int64_t CongestionController::GetPacerQueuingDelayMs() const {
219 return pacer_->QueueInMs(); 266 return pacer_->QueueInMs();
220 } 267 }
221 268
222 void CongestionController::SignalNetworkState(NetworkState state) { 269 void CongestionController::SignalNetworkState(NetworkState state) {
223 if (state == kNetworkUp) { 270 if (state == kNetworkUp) {
224 pacer_->Resume(); 271 pacer_->Resume();
225 } else { 272 } else {
(...skipping 12 matching lines...) Expand all
238 } 285 }
239 286
240 int64_t CongestionController::TimeUntilNextProcess() { 287 int64_t CongestionController::TimeUntilNextProcess() {
241 return std::min(bitrate_controller_->TimeUntilNextProcess(), 288 return std::min(bitrate_controller_->TimeUntilNextProcess(),
242 remote_bitrate_estimator_->TimeUntilNextProcess()); 289 remote_bitrate_estimator_->TimeUntilNextProcess());
243 } 290 }
244 291
245 void CongestionController::Process() { 292 void CongestionController::Process() {
246 bitrate_controller_->Process(); 293 bitrate_controller_->Process();
247 remote_bitrate_estimator_->Process(); 294 remote_bitrate_estimator_->Process();
295 MaybeTriggerOnNetworkChanged();
296 }
297
298 void CongestionController::MaybeTriggerOnNetworkChanged() {
299 // TODO(perkj): |observer_| can be nullptr if the ctor that accepts a
300 // BitrateObserver is used. Remove this check once the ctor is removed.
301 if (!observer_)
302 return;
303
304 uint32_t bitrate_bps;
305 uint8_t fraction_loss;
306 int64_t rtt;
307 bool network_changed = bitrate_controller_->GetNetworkParameters(
308 &bitrate_bps, &fraction_loss, &rtt);
309 if (network_changed)
310 pacer_->SetEstimatedBitrate(bitrate_bps);
311 bool send_queue_is_full =
312 pacer_->ExpectedQueueTimeMs() > PacedSender::kMaxQueueLengthMs;
313 bitrate_bps = send_queue_is_full ? 0 : bitrate_bps;
314 if ((network_changed && !send_queue_is_full) ||
315 UpdateSendQueueStatus(send_queue_is_full)) {
316 observer_->OnNetworkChanged(bitrate_bps, fraction_loss, rtt);
317 }
318 }
319
320 bool CongestionController::UpdateSendQueueStatus(bool send_queue_is_full) {
321 rtc::CritScope cs(&critsect_);
322 bool result = send_queue_is_full_ != send_queue_is_full;
323 send_queue_is_full_ = send_queue_is_full;
324 return result;
248 } 325 }
249 326
250 } // namespace webrtc 327 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698