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

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

Issue 1247293002: Add support for transport wide sequence numbers (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebase, again Created 5 years, 4 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 */
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 Clock* clock, 80 Clock* clock,
81 BitrateObserver* observer) { 81 BitrateObserver* observer) {
82 return new BitrateControllerImpl(clock, observer); 82 return new BitrateControllerImpl(clock, observer);
83 } 83 }
84 84
85 BitrateControllerImpl::BitrateControllerImpl(Clock* clock, 85 BitrateControllerImpl::BitrateControllerImpl(Clock* clock,
86 BitrateObserver* observer) 86 BitrateObserver* observer)
87 : clock_(clock), 87 : clock_(clock),
88 observer_(observer), 88 observer_(observer),
89 last_bitrate_update_ms_(clock_->TimeInMilliseconds()), 89 last_bitrate_update_ms_(clock_->TimeInMilliseconds()),
90 critsect_(CriticalSectionWrapper::CreateCriticalSection()),
91 bandwidth_estimation_(), 90 bandwidth_estimation_(),
92 reserved_bitrate_bps_(0), 91 reserved_bitrate_bps_(0),
93 last_bitrate_bps_(0), 92 last_bitrate_bps_(0),
94 last_fraction_loss_(0), 93 last_fraction_loss_(0),
95 last_rtt_ms_(0), 94 last_rtt_ms_(0),
96 last_reserved_bitrate_bps_(0) { 95 last_reserved_bitrate_bps_(0) {
97 // This calls the observer_, which means that the observer provided by the 96 // 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 97 // 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 98 // controller. We do this to avoid having to keep synchronized initial values
100 // in both the controller and the allocator. 99 // in both the controller and the allocator.
101 MaybeTriggerOnNetworkChanged(); 100 MaybeTriggerOnNetworkChanged();
102 } 101 }
103 102
104 RtcpBandwidthObserver* BitrateControllerImpl::CreateRtcpBandwidthObserver() { 103 RtcpBandwidthObserver* BitrateControllerImpl::CreateRtcpBandwidthObserver() {
105 return new RtcpBandwidthObserverImpl(this); 104 return new RtcpBandwidthObserverImpl(this);
106 } 105 }
107 106
108 void BitrateControllerImpl::SetStartBitrate(int start_bitrate_bps) { 107 void BitrateControllerImpl::SetStartBitrate(int start_bitrate_bps) {
109 { 108 {
110 CriticalSectionScoped cs(critsect_.get()); 109 rtc::CritScope cs(&critsect_);
111 bandwidth_estimation_.SetSendBitrate(start_bitrate_bps); 110 bandwidth_estimation_.SetSendBitrate(start_bitrate_bps);
112 } 111 }
113 MaybeTriggerOnNetworkChanged(); 112 MaybeTriggerOnNetworkChanged();
114 } 113 }
115 114
116 void BitrateControllerImpl::SetMinMaxBitrate(int min_bitrate_bps, 115 void BitrateControllerImpl::SetMinMaxBitrate(int min_bitrate_bps,
117 int max_bitrate_bps) { 116 int max_bitrate_bps) {
118 { 117 {
119 CriticalSectionScoped cs(critsect_.get()); 118 rtc::CritScope cs(&critsect_);
120 bandwidth_estimation_.SetMinMaxBitrate(min_bitrate_bps, max_bitrate_bps); 119 bandwidth_estimation_.SetMinMaxBitrate(min_bitrate_bps, max_bitrate_bps);
121 } 120 }
122 MaybeTriggerOnNetworkChanged(); 121 MaybeTriggerOnNetworkChanged();
123 } 122 }
124 123
125 void BitrateControllerImpl::SetReservedBitrate(uint32_t reserved_bitrate_bps) { 124 void BitrateControllerImpl::SetReservedBitrate(uint32_t reserved_bitrate_bps) {
126 { 125 {
127 CriticalSectionScoped cs(critsect_.get()); 126 rtc::CritScope cs(&critsect_);
128 reserved_bitrate_bps_ = reserved_bitrate_bps; 127 reserved_bitrate_bps_ = reserved_bitrate_bps;
129 } 128 }
130 MaybeTriggerOnNetworkChanged(); 129 MaybeTriggerOnNetworkChanged();
131 } 130 }
132 131
133 void BitrateControllerImpl::OnReceivedEstimatedBitrate(uint32_t bitrate) { 132 void BitrateControllerImpl::OnReceivedEstimatedBitrate(uint32_t bitrate) {
134 { 133 {
135 CriticalSectionScoped cs(critsect_.get()); 134 rtc::CritScope cs(&critsect_);
136 bandwidth_estimation_.UpdateReceiverEstimate(bitrate); 135 bandwidth_estimation_.UpdateReceiverEstimate(bitrate);
137 } 136 }
138 MaybeTriggerOnNetworkChanged(); 137 MaybeTriggerOnNetworkChanged();
139 } 138 }
140 139
141 int64_t BitrateControllerImpl::TimeUntilNextProcess() { 140 int64_t BitrateControllerImpl::TimeUntilNextProcess() {
142 const int64_t kBitrateControllerUpdateIntervalMs = 25; 141 const int64_t kBitrateControllerUpdateIntervalMs = 25;
143 CriticalSectionScoped cs(critsect_.get()); 142 rtc::CritScope cs(&critsect_);
144 int64_t time_since_update_ms = 143 int64_t time_since_update_ms =
145 clock_->TimeInMilliseconds() - last_bitrate_update_ms_; 144 clock_->TimeInMilliseconds() - last_bitrate_update_ms_;
146 return std::max<int64_t>( 145 return std::max<int64_t>(
147 kBitrateControllerUpdateIntervalMs - time_since_update_ms, 0); 146 kBitrateControllerUpdateIntervalMs - time_since_update_ms, 0);
148 } 147 }
149 148
150 int32_t BitrateControllerImpl::Process() { 149 int32_t BitrateControllerImpl::Process() {
151 if (TimeUntilNextProcess() > 0) 150 if (TimeUntilNextProcess() > 0)
152 return 0; 151 return 0;
153 { 152 {
154 CriticalSectionScoped cs(critsect_.get()); 153 rtc::CritScope cs(&critsect_);
155 bandwidth_estimation_.UpdateEstimate(clock_->TimeInMilliseconds()); 154 bandwidth_estimation_.UpdateEstimate(clock_->TimeInMilliseconds());
156 } 155 }
157 MaybeTriggerOnNetworkChanged(); 156 MaybeTriggerOnNetworkChanged();
158 last_bitrate_update_ms_ = clock_->TimeInMilliseconds(); 157 last_bitrate_update_ms_ = clock_->TimeInMilliseconds();
159 return 0; 158 return 0;
160 } 159 }
161 160
162 void BitrateControllerImpl::OnReceivedRtcpReceiverReport( 161 void BitrateControllerImpl::OnReceivedRtcpReceiverReport(
163 uint8_t fraction_loss, 162 uint8_t fraction_loss,
164 int64_t rtt, 163 int64_t rtt,
165 int number_of_packets, 164 int number_of_packets,
166 int64_t now_ms) { 165 int64_t now_ms) {
167 { 166 {
168 CriticalSectionScoped cs(critsect_.get()); 167 rtc::CritScope cs(&critsect_);
169 bandwidth_estimation_.UpdateReceiverBlock(fraction_loss, rtt, 168 bandwidth_estimation_.UpdateReceiverBlock(fraction_loss, rtt,
170 number_of_packets, now_ms); 169 number_of_packets, now_ms);
171 } 170 }
172 MaybeTriggerOnNetworkChanged(); 171 MaybeTriggerOnNetworkChanged();
173 } 172 }
174 173
175 void BitrateControllerImpl::MaybeTriggerOnNetworkChanged() { 174 void BitrateControllerImpl::MaybeTriggerOnNetworkChanged() {
176 uint32_t bitrate; 175 uint32_t bitrate;
177 uint8_t fraction_loss; 176 uint8_t fraction_loss;
178 int64_t rtt; 177 int64_t rtt;
179 if (GetNetworkParameters(&bitrate, &fraction_loss, &rtt)) 178 if (GetNetworkParameters(&bitrate, &fraction_loss, &rtt))
180 observer_->OnNetworkChanged(bitrate, fraction_loss, rtt); 179 observer_->OnNetworkChanged(bitrate, fraction_loss, rtt);
181 } 180 }
182 181
183 bool BitrateControllerImpl::GetNetworkParameters(uint32_t* bitrate, 182 bool BitrateControllerImpl::GetNetworkParameters(uint32_t* bitrate,
184 uint8_t* fraction_loss, 183 uint8_t* fraction_loss,
185 int64_t* rtt) { 184 int64_t* rtt) {
186 CriticalSectionScoped cs(critsect_.get()); 185 rtc::CritScope cs(&critsect_);
187 int current_bitrate; 186 int current_bitrate;
188 bandwidth_estimation_.CurrentEstimate(&current_bitrate, fraction_loss, rtt); 187 bandwidth_estimation_.CurrentEstimate(&current_bitrate, fraction_loss, rtt);
189 *bitrate = current_bitrate; 188 *bitrate = current_bitrate;
190 *bitrate -= std::min(*bitrate, reserved_bitrate_bps_); 189 *bitrate -= std::min(*bitrate, reserved_bitrate_bps_);
191 *bitrate = 190 *bitrate =
192 std::max<uint32_t>(*bitrate, bandwidth_estimation_.GetMinBitrate()); 191 std::max<uint32_t>(*bitrate, bandwidth_estimation_.GetMinBitrate());
193 192
194 bool new_bitrate = false; 193 bool new_bitrate = false;
195 if (*bitrate != last_bitrate_bps_ || *fraction_loss != last_fraction_loss_ || 194 if (*bitrate != last_bitrate_bps_ || *fraction_loss != last_fraction_loss_ ||
196 *rtt != last_rtt_ms_ || 195 *rtt != last_rtt_ms_ ||
197 last_reserved_bitrate_bps_ != reserved_bitrate_bps_) { 196 last_reserved_bitrate_bps_ != reserved_bitrate_bps_) {
198 last_bitrate_bps_ = *bitrate; 197 last_bitrate_bps_ = *bitrate;
199 last_fraction_loss_ = *fraction_loss; 198 last_fraction_loss_ = *fraction_loss;
200 last_rtt_ms_ = *rtt; 199 last_rtt_ms_ = *rtt;
201 last_reserved_bitrate_bps_ = reserved_bitrate_bps_; 200 last_reserved_bitrate_bps_ = reserved_bitrate_bps_;
202 new_bitrate = true; 201 new_bitrate = true;
203 } 202 }
204 return new_bitrate; 203 return new_bitrate;
205 } 204 }
206 205
207 bool BitrateControllerImpl::AvailableBandwidth(uint32_t* bandwidth) const { 206 bool BitrateControllerImpl::AvailableBandwidth(uint32_t* bandwidth) const {
208 CriticalSectionScoped cs(critsect_.get()); 207 rtc::CritScope cs(&critsect_);
209 int bitrate; 208 int bitrate;
210 uint8_t fraction_loss; 209 uint8_t fraction_loss;
211 int64_t rtt; 210 int64_t rtt;
212 bandwidth_estimation_.CurrentEstimate(&bitrate, &fraction_loss, &rtt); 211 bandwidth_estimation_.CurrentEstimate(&bitrate, &fraction_loss, &rtt);
213 if (bitrate > 0) { 212 if (bitrate > 0) {
214 bitrate = bitrate - std::min<int>(bitrate, reserved_bitrate_bps_); 213 bitrate = bitrate - std::min<int>(bitrate, reserved_bitrate_bps_);
215 bitrate = std::max(bitrate, bandwidth_estimation_.GetMinBitrate()); 214 bitrate = std::max(bitrate, bandwidth_estimation_.GetMinBitrate());
216 *bandwidth = bitrate; 215 *bandwidth = bitrate;
217 return true; 216 return true;
218 } 217 }
219 return false; 218 return false;
220 } 219 }
221
222 } // namespace webrtc 220 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698