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

Side by Side Diff: webrtc/modules/bitrate_controller/bitrate_controller_impl.cc

Issue 1917793002: 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 11
12 #include "webrtc/modules/bitrate_controller/bitrate_controller_impl.h" 12 #include "webrtc/modules/bitrate_controller/bitrate_controller_impl.h"
13 13
14 #include <algorithm> 14 #include <algorithm>
15 #include <map> 15 #include <map>
16 #include <utility> 16 #include <utility>
17 17
18 #include "webrtc/base/checks.h"
19 #include "webrtc/base/logging.h"
18 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" 20 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
19 21
20 namespace webrtc { 22 namespace webrtc {
21 23
22 class BitrateControllerImpl::RtcpBandwidthObserverImpl 24 class BitrateControllerImpl::RtcpBandwidthObserverImpl
23 : public RtcpBandwidthObserver { 25 : public RtcpBandwidthObserver {
24 public: 26 public:
25 explicit RtcpBandwidthObserverImpl(BitrateControllerImpl* owner) 27 explicit RtcpBandwidthObserverImpl(BitrateControllerImpl* owner)
26 : owner_(owner) { 28 : owner_(owner) {
27 } 29 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 total_number_of_packets, now_ms); 74 total_number_of_packets, now_ms);
73 } 75 }
74 76
75 private: 77 private:
76 std::map<uint32_t, uint32_t> ssrc_to_last_received_extended_high_seq_num_; 78 std::map<uint32_t, uint32_t> ssrc_to_last_received_extended_high_seq_num_;
77 BitrateControllerImpl* owner_; 79 BitrateControllerImpl* owner_;
78 }; 80 };
79 81
80 BitrateController* BitrateController::CreateBitrateController( 82 BitrateController* BitrateController::CreateBitrateController(
81 Clock* clock, 83 Clock* clock,
82 BitrateObserver* observer) { 84 BitrateObserver* observer,
83 return new BitrateControllerImpl(clock, observer); 85 PacedSender* pacer) {
86 return new BitrateControllerImpl(clock, observer, pacer);
84 } 87 }
85 88
86 BitrateControllerImpl::BitrateControllerImpl(Clock* clock, 89 BitrateControllerImpl::BitrateControllerImpl(Clock* clock,
87 BitrateObserver* observer) 90 BitrateObserver* observer,
91 PacedSender* pacer)
88 : clock_(clock), 92 : clock_(clock),
89 observer_(observer), 93 observer_(observer),
94 pacer_(pacer),
90 last_bitrate_update_ms_(clock_->TimeInMilliseconds()), 95 last_bitrate_update_ms_(clock_->TimeInMilliseconds()),
91 bandwidth_estimation_(), 96 bandwidth_estimation_(),
92 reserved_bitrate_bps_(0), 97 reserved_bitrate_bps_(0),
93 last_bitrate_bps_(0), 98 last_bitrate_bps_(0),
94 last_fraction_loss_(0), 99 last_fraction_loss_(0),
95 last_rtt_ms_(0), 100 last_rtt_ms_(0),
96 last_reserved_bitrate_bps_(0) { 101 last_reserved_bitrate_bps_(0),
102 send_queue_full_(false) {
103 RTC_DCHECK(observer_);
104 RTC_DCHECK(pacer_);
97 // This calls the observer_, which means that the observer provided by the 105 // This calls the observer_, which means that the observer provided by the
98 // user must be ready to accept a bitrate update when it constructs the 106 // user must be ready to accept a bitrate update when it constructs the
99 // controller. We do this to avoid having to keep synchronized initial values 107 // controller. We do this to avoid having to keep synchronized initial values
100 // in both the controller and the allocator. 108 // in both the controller and the allocator.
101 MaybeTriggerOnNetworkChanged(); 109 MaybeTriggerOnNetworkChanged();
102 } 110 }
103 111
104 RtcpBandwidthObserver* BitrateControllerImpl::CreateRtcpBandwidthObserver() { 112 RtcpBandwidthObserver* BitrateControllerImpl::CreateRtcpBandwidthObserver() {
105 return new RtcpBandwidthObserverImpl(this); 113 return new RtcpBandwidthObserverImpl(this);
106 } 114 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 int64_t now_ms) { 188 int64_t now_ms) {
181 { 189 {
182 rtc::CritScope cs(&critsect_); 190 rtc::CritScope cs(&critsect_);
183 bandwidth_estimation_.UpdateReceiverBlock(fraction_loss, rtt, 191 bandwidth_estimation_.UpdateReceiverBlock(fraction_loss, rtt,
184 number_of_packets, now_ms); 192 number_of_packets, now_ms);
185 } 193 }
186 MaybeTriggerOnNetworkChanged(); 194 MaybeTriggerOnNetworkChanged();
187 } 195 }
188 196
189 void BitrateControllerImpl::MaybeTriggerOnNetworkChanged() { 197 void BitrateControllerImpl::MaybeTriggerOnNetworkChanged() {
190 uint32_t bitrate; 198 uint32_t bitrate_bps;
191 uint8_t fraction_loss; 199 uint8_t fraction_loss;
192 int64_t rtt; 200 int64_t rtt;
193 if (GetNetworkParameters(&bitrate, &fraction_loss, &rtt)) 201
194 observer_->OnNetworkChanged(bitrate, fraction_loss, rtt); 202 bool network_changed =
203 GetNetworkParameters(&bitrate_bps, &fraction_loss, &rtt);
204 if (network_changed) {
205 pacer_->SetNetWorkEstimateTargetBitrate(bitrate_bps);
stefan-webrtc 2016/04/29 10:48:38 I'd prefer keeping this in OnNetworkChanged and no
perkj_webrtc 2016/05/02 11:29:10 ok- as discussed.
206 }
207 bool send_queue_full =
208 pacer_->ExpectedQueueTimeMs() > PacedSender::kMaxQueueLengthMs;
209
210 bitrate_bps = send_queue_full ? 0 : bitrate_bps;
211 if (UpdateSendQueueStatus(send_queue_full) ||
212 (network_changed && !send_queue_full)) {
213 observer_->OnNetworkChanged(bitrate_bps, fraction_loss, rtt);
214 return;
215 }
195 } 216 }
196 217
197 bool BitrateControllerImpl::GetNetworkParameters(uint32_t* bitrate, 218 bool BitrateControllerImpl::GetNetworkParameters(uint32_t* bitrate,
198 uint8_t* fraction_loss, 219 uint8_t* fraction_loss,
199 int64_t* rtt) { 220 int64_t* rtt) {
200 rtc::CritScope cs(&critsect_); 221 rtc::CritScope cs(&critsect_);
201 int current_bitrate; 222 int current_bitrate;
202 bandwidth_estimation_.CurrentEstimate(&current_bitrate, fraction_loss, rtt); 223 bandwidth_estimation_.CurrentEstimate(&current_bitrate, fraction_loss, rtt);
203 *bitrate = current_bitrate; 224 *bitrate = current_bitrate;
204 *bitrate -= std::min(*bitrate, reserved_bitrate_bps_); 225 *bitrate -= std::min(*bitrate, reserved_bitrate_bps_);
205 *bitrate = 226 *bitrate =
206 std::max<uint32_t>(*bitrate, bandwidth_estimation_.GetMinBitrate()); 227 std::max<uint32_t>(*bitrate, bandwidth_estimation_.GetMinBitrate());
207 228
208 bool new_bitrate = false; 229 bool new_bitrate = false;
209 if (*bitrate != last_bitrate_bps_ || *fraction_loss != last_fraction_loss_ || 230 if (*bitrate != last_bitrate_bps_ || *fraction_loss != last_fraction_loss_ ||
210 *rtt != last_rtt_ms_ || 231 *rtt != last_rtt_ms_ ||
211 last_reserved_bitrate_bps_ != reserved_bitrate_bps_) { 232 last_reserved_bitrate_bps_ != reserved_bitrate_bps_) {
212 last_bitrate_bps_ = *bitrate; 233 last_bitrate_bps_ = *bitrate;
213 last_fraction_loss_ = *fraction_loss; 234 last_fraction_loss_ = *fraction_loss;
214 last_rtt_ms_ = *rtt; 235 last_rtt_ms_ = *rtt;
215 last_reserved_bitrate_bps_ = reserved_bitrate_bps_; 236 last_reserved_bitrate_bps_ = reserved_bitrate_bps_;
216 new_bitrate = true; 237 new_bitrate = true;
217 } 238 }
239
218 return new_bitrate; 240 return new_bitrate;
219 } 241 }
220 242
243 bool BitrateControllerImpl::UpdateSendQueueStatus(bool is_full) {
244 rtc::CritScope cs(&critsect_);
245 bool changed = is_full != send_queue_full_;
246 send_queue_full_ = is_full;
247 if (changed) {
248 LOG(LS_INFO) << "Send queue status changed state. "
249 << " Queue is " << (changed ? "full" : "not full.");
250 }
251 return changed;
252 }
253
221 bool BitrateControllerImpl::AvailableBandwidth(uint32_t* bandwidth) const { 254 bool BitrateControllerImpl::AvailableBandwidth(uint32_t* bandwidth) const {
222 rtc::CritScope cs(&critsect_); 255 rtc::CritScope cs(&critsect_);
223 int bitrate; 256 int bitrate;
224 uint8_t fraction_loss; 257 uint8_t fraction_loss;
225 int64_t rtt; 258 int64_t rtt;
226 bandwidth_estimation_.CurrentEstimate(&bitrate, &fraction_loss, &rtt); 259 bandwidth_estimation_.CurrentEstimate(&bitrate, &fraction_loss, &rtt);
227 if (bitrate > 0) { 260 if (bitrate > 0) {
228 bitrate = bitrate - std::min<int>(bitrate, reserved_bitrate_bps_); 261 bitrate = bitrate - std::min<int>(bitrate, reserved_bitrate_bps_);
229 bitrate = std::max(bitrate, bandwidth_estimation_.GetMinBitrate()); 262 bitrate = std::max(bitrate, bandwidth_estimation_.GetMinBitrate());
230 *bandwidth = bitrate; 263 *bandwidth = bitrate;
231 return true; 264 return true;
232 } 265 }
233 return false; 266 return false;
234 } 267 }
235 } // namespace webrtc 268 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698