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

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

Issue 1958113003: Remove SendPacer from ViEEncoder and make sure SendPacer starts at a valid bitrate (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Removed initial bitrate from PacedSender. Updated unittests. 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 remote_bitrate_estimator_(
147 PacedSender::kDefaultPaceMultiplier * 148 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)),
148 BitrateController::kDefaultStartBitrateKbps, 149 bitrate_controller_(
149 0)), 150 BitrateController::CreateBitrateController(clock_, bitrate_observer)),
151 remote_estimator_proxy_(clock_, packet_router_.get()),
152 transport_feedback_adapter_(bitrate_controller_.get(), clock_),
153 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps),
154 send_queue_is_full_(false) {
155 Init();
156 }
157
158 CongestionController::CongestionController(
159 Clock* clock,
160 Observer* observer,
161 RemoteBitrateObserver* remote_bitrate_observer)
162 : clock_(clock),
163 observer_(observer),
164 packet_router_(new PacketRouter()),
165 pacer_(new PacedSender(clock_,
166 packet_router_.get())),
167 remote_bitrate_estimator_(
168 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)),
169 bitrate_controller_(BitrateController::CreateBitrateController(clock_)),
170 remote_estimator_proxy_(clock_, packet_router_.get()),
171 transport_feedback_adapter_(bitrate_controller_.get(), clock_),
172 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps),
173 send_queue_is_full_(false) {
174 Init();
175 }
176
177 CongestionController::CongestionController(
178 Clock* clock,
179 Observer* observer,
180 RemoteBitrateObserver* remote_bitrate_observer,
181 std::unique_ptr<PacketRouter> packet_router,
182 std::unique_ptr<PacedSender> pacer)
183 : clock_(clock),
184 observer_(observer),
185 packet_router_(std::move(packet_router)),
186 pacer_(std::move(pacer)),
150 remote_bitrate_estimator_( 187 remote_bitrate_estimator_(
151 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)), 188 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)),
152 // Constructed last as this object calls the provided callback on 189 // Constructed last as this object calls the provided callback on
153 // construction. 190 // construction.
154 bitrate_controller_( 191 bitrate_controller_(BitrateController::CreateBitrateController(clock_)),
155 BitrateController::CreateBitrateController(clock_, bitrate_observer)), 192 remote_estimator_proxy_(clock_, packet_router_.get()),
156 remote_estimator_proxy_(clock_, &packet_router_),
157 transport_feedback_adapter_(bitrate_controller_.get(), clock_), 193 transport_feedback_adapter_(bitrate_controller_.get(), clock_),
158 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps) { 194 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps),
195 send_queue_is_full_(false) {
196 Init();
197 }
198
199 CongestionController::~CongestionController() {}
200
201 void CongestionController::Init() {
159 transport_feedback_adapter_.SetBitrateEstimator( 202 transport_feedback_adapter_.SetBitrateEstimator(
160 new RemoteBitrateEstimatorAbsSendTime(&transport_feedback_adapter_)); 203 new RemoteBitrateEstimatorAbsSendTime(&transport_feedback_adapter_));
161 transport_feedback_adapter_.GetBitrateEstimator()->SetMinBitrate( 204 transport_feedback_adapter_.GetBitrateEstimator()->SetMinBitrate(
162 min_bitrate_bps_); 205 min_bitrate_bps_);
163 } 206 }
164 207
165 CongestionController::~CongestionController() {
166 }
167
168 208
169 void CongestionController::SetBweBitrates(int min_bitrate_bps, 209 void CongestionController::SetBweBitrates(int min_bitrate_bps,
170 int start_bitrate_bps, 210 int start_bitrate_bps,
171 int max_bitrate_bps) { 211 int max_bitrate_bps) {
172 // TODO(holmer): We should make sure the default bitrates are set to 10 kbps, 212 // 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. 213 // 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. 214 // The congestion controller should allow a min bitrate of 0.
175 const int kMinBitrateBps = 10000; 215 const int kMinBitrateBps = 10000;
176 if (min_bitrate_bps < kMinBitrateBps) 216 if (min_bitrate_bps < kMinBitrateBps)
177 min_bitrate_bps = kMinBitrateBps; 217 min_bitrate_bps = kMinBitrateBps;
178 if (max_bitrate_bps > 0) 218 if (max_bitrate_bps > 0)
179 max_bitrate_bps = std::max(min_bitrate_bps, max_bitrate_bps); 219 max_bitrate_bps = std::max(min_bitrate_bps, max_bitrate_bps);
180 if (start_bitrate_bps > 0) 220 if (start_bitrate_bps > 0)
181 start_bitrate_bps = std::max(min_bitrate_bps, start_bitrate_bps); 221 start_bitrate_bps = std::max(min_bitrate_bps, start_bitrate_bps);
182 222
183 bitrate_controller_->SetBitrates(start_bitrate_bps, 223 bitrate_controller_->SetBitrates(start_bitrate_bps,
184 min_bitrate_bps, 224 min_bitrate_bps,
185 max_bitrate_bps); 225 max_bitrate_bps);
186 226
187 if (remote_bitrate_estimator_) 227 if (remote_bitrate_estimator_)
188 remote_bitrate_estimator_->SetMinBitrate(min_bitrate_bps); 228 remote_bitrate_estimator_->SetMinBitrate(min_bitrate_bps);
189 min_bitrate_bps_ = min_bitrate_bps; 229 min_bitrate_bps_ = min_bitrate_bps;
190 transport_feedback_adapter_.GetBitrateEstimator()->SetMinBitrate( 230 transport_feedback_adapter_.GetBitrateEstimator()->SetMinBitrate(
191 min_bitrate_bps_); 231 min_bitrate_bps_);
232 MaybeTriggerOnNetworkChanged();
192 } 233 }
193 234
194 BitrateController* CongestionController::GetBitrateController() const { 235 BitrateController* CongestionController::GetBitrateController() const {
195 return bitrate_controller_.get(); 236 return bitrate_controller_.get();
196 } 237 }
197 238
198 RemoteBitrateEstimator* CongestionController::GetRemoteBitrateEstimator( 239 RemoteBitrateEstimator* CongestionController::GetRemoteBitrateEstimator(
199 bool send_side_bwe) { 240 bool send_side_bwe) {
200 if (send_side_bwe) { 241 if (send_side_bwe) {
201 return &remote_estimator_proxy_; 242 return &remote_estimator_proxy_;
202 } else { 243 } else {
203 return remote_bitrate_estimator_.get(); 244 return remote_bitrate_estimator_.get();
204 } 245 }
205 } 246 }
206 247
207 TransportFeedbackObserver* 248 TransportFeedbackObserver*
208 CongestionController::GetTransportFeedbackObserver() { 249 CongestionController::GetTransportFeedbackObserver() {
209 return &transport_feedback_adapter_; 250 return &transport_feedback_adapter_;
210 } 251 }
211 252
212 void CongestionController::UpdatePacerBitrate(int bitrate_kbps, 253 void CongestionController::SetAllocatedSendBitrate(int allocated_bitrate_bps,
213 int max_bitrate_kbps, 254 int padding_bitrate_bps) {
214 int min_bitrate_kbps) { 255 pacer_->SetAllocatedSendBitrate(allocated_bitrate_bps, padding_bitrate_bps);
215 pacer_->UpdateBitrate(bitrate_kbps, max_bitrate_kbps, min_bitrate_kbps);
216 } 256 }
217 257
218 int64_t CongestionController::GetPacerQueuingDelayMs() const { 258 int64_t CongestionController::GetPacerQueuingDelayMs() const {
219 return pacer_->QueueInMs(); 259 return pacer_->QueueInMs();
220 } 260 }
221 261
222 void CongestionController::SignalNetworkState(NetworkState state) { 262 void CongestionController::SignalNetworkState(NetworkState state) {
223 if (state == kNetworkUp) { 263 if (state == kNetworkUp) {
224 pacer_->Resume(); 264 pacer_->Resume();
225 } else { 265 } else {
(...skipping 12 matching lines...) Expand all
238 } 278 }
239 279
240 int64_t CongestionController::TimeUntilNextProcess() { 280 int64_t CongestionController::TimeUntilNextProcess() {
241 return std::min(bitrate_controller_->TimeUntilNextProcess(), 281 return std::min(bitrate_controller_->TimeUntilNextProcess(),
242 remote_bitrate_estimator_->TimeUntilNextProcess()); 282 remote_bitrate_estimator_->TimeUntilNextProcess());
243 } 283 }
244 284
245 void CongestionController::Process() { 285 void CongestionController::Process() {
246 bitrate_controller_->Process(); 286 bitrate_controller_->Process();
247 remote_bitrate_estimator_->Process(); 287 remote_bitrate_estimator_->Process();
288 MaybeTriggerOnNetworkChanged();
289 }
290
291 void CongestionController::MaybeTriggerOnNetworkChanged() {
292 // TODO(perkj): |observer_| can be nullptr if the ctor that accepts a
293 // BitrateObserver is used. Remove this check once the ctor is removed.
294 if (!observer_)
295 return;
296
297 uint32_t bitrate_bps;
298 uint8_t fraction_loss;
299 int64_t rtt;
300 bool network_changed = bitrate_controller_->GetNetworkParameters(
301 &bitrate_bps, &fraction_loss, &rtt);
302 if (network_changed)
303 pacer_->SetEstimatedBitrate(bitrate_bps);
304 bool send_queue_is_full =
305 pacer_->ExpectedQueueTimeMs() > PacedSender::kMaxQueueLengthMs;
306 bitrate_bps = send_queue_is_full ? 0 : bitrate_bps;
307 if ((network_changed && !send_queue_is_full) ||
308 UpdateSendQueueStatus(send_queue_is_full)) {
309 observer_->OnNetworkChanged(bitrate_bps, fraction_loss, rtt);
310 }
311 }
312
313 bool CongestionController::UpdateSendQueueStatus(bool send_queue_is_full) {
314 rtc::CritScope cs(&critsect_);
315 bool result = send_queue_is_full_ != send_queue_is_full;
316 send_queue_is_full_ = send_queue_is_full;
317 return result;
248 } 318 }
249 319
250 } // namespace webrtc 320 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698