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

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

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

Powered by Google App Engine
This is Rietveld 408576698