OLD | NEW |
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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 }; | 168 }; |
169 | 169 |
170 class IntervalBudget { | 170 class IntervalBudget { |
171 public: | 171 public: |
172 explicit IntervalBudget(int initial_target_rate_kbps) | 172 explicit IntervalBudget(int initial_target_rate_kbps) |
173 : target_rate_kbps_(initial_target_rate_kbps), | 173 : target_rate_kbps_(initial_target_rate_kbps), |
174 bytes_remaining_(0) {} | 174 bytes_remaining_(0) {} |
175 | 175 |
176 void set_target_rate_kbps(int target_rate_kbps) { | 176 void set_target_rate_kbps(int target_rate_kbps) { |
177 target_rate_kbps_ = target_rate_kbps; | 177 target_rate_kbps_ = target_rate_kbps; |
| 178 bytes_remaining_ = |
| 179 std::max(-kWindowMs * target_rate_kbps_ / 8, bytes_remaining_); |
178 } | 180 } |
179 | 181 |
180 void IncreaseBudget(int64_t delta_time_ms) { | 182 void IncreaseBudget(int64_t delta_time_ms) { |
181 int64_t bytes = target_rate_kbps_ * delta_time_ms / 8; | 183 int64_t bytes = target_rate_kbps_ * delta_time_ms / 8; |
182 if (bytes_remaining_ < 0) { | 184 if (bytes_remaining_ < 0) { |
183 // We overused last interval, compensate this interval. | 185 // We overused last interval, compensate this interval. |
184 bytes_remaining_ = bytes_remaining_ + bytes; | 186 bytes_remaining_ = bytes_remaining_ + bytes; |
185 } else { | 187 } else { |
186 // If we underused last interval we can't use it this interval. | 188 // If we underused last interval we can't use it this interval. |
187 bytes_remaining_ = bytes; | 189 bytes_remaining_ = bytes; |
188 } | 190 } |
189 } | 191 } |
190 | 192 |
191 void UseBudget(size_t bytes) { | 193 void UseBudget(size_t bytes) { |
192 bytes_remaining_ = std::max(bytes_remaining_ - static_cast<int>(bytes), | 194 bytes_remaining_ = std::max(bytes_remaining_ - static_cast<int>(bytes), |
193 -500 * target_rate_kbps_ / 8); | 195 -kWindowMs * target_rate_kbps_ / 8); |
194 } | 196 } |
195 | 197 |
196 size_t bytes_remaining() const { | 198 size_t bytes_remaining() const { |
197 return static_cast<size_t>(std::max(0, bytes_remaining_)); | 199 return static_cast<size_t>(std::max(0, bytes_remaining_)); |
198 } | 200 } |
199 | 201 |
200 int target_rate_kbps() const { return target_rate_kbps_; } | 202 int target_rate_kbps() const { return target_rate_kbps_; } |
201 | 203 |
202 private: | 204 private: |
| 205 static const int kWindowMs = 500; |
| 206 |
203 int target_rate_kbps_; | 207 int target_rate_kbps_; |
204 int bytes_remaining_; | 208 int bytes_remaining_; |
205 }; | 209 }; |
206 } // namespace paced_sender | 210 } // namespace paced_sender |
207 | 211 |
208 const float PacedSender::kDefaultPaceMultiplier = 2.5f; | 212 const float PacedSender::kDefaultPaceMultiplier = 2.5f; |
209 | 213 |
210 PacedSender::PacedSender(Clock* clock, | 214 PacedSender::PacedSender(Clock* clock, |
211 Callback* callback, | 215 Callback* callback, |
212 int bitrate_kbps, | 216 int bitrate_kbps, |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 void PacedSender::UpdateBytesPerInterval(int64_t delta_time_ms) { | 406 void PacedSender::UpdateBytesPerInterval(int64_t delta_time_ms) { |
403 media_budget_->IncreaseBudget(delta_time_ms); | 407 media_budget_->IncreaseBudget(delta_time_ms); |
404 padding_budget_->IncreaseBudget(delta_time_ms); | 408 padding_budget_->IncreaseBudget(delta_time_ms); |
405 } | 409 } |
406 | 410 |
407 bool PacedSender::ProbingExperimentIsEnabled() const { | 411 bool PacedSender::ProbingExperimentIsEnabled() const { |
408 return webrtc::field_trial::FindFullName("WebRTC-BitrateProbing") == | 412 return webrtc::field_trial::FindFullName("WebRTC-BitrateProbing") == |
409 "Enabled"; | 413 "Enabled"; |
410 } | 414 } |
411 } // namespace webrtc | 415 } // namespace webrtc |
OLD | NEW |