| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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/pacing/bitrate_prober.h" | 11 #include "webrtc/modules/pacing/bitrate_prober.h" |
| 12 | 12 |
| 13 #include <algorithm> | 13 #include <algorithm> |
| 14 | 14 |
| 15 #include "webrtc/base/checks.h" | 15 #include "webrtc/base/checks.h" |
| 16 #include "webrtc/base/logging.h" | 16 #include "webrtc/base/logging.h" |
| 17 #include "webrtc/modules/pacing/paced_sender.h" | 17 #include "webrtc/modules/pacing/paced_sender.h" |
| 18 | 18 |
| 19 namespace webrtc { | 19 namespace webrtc { |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 // Inactivity threshold above which probing is restarted. | 23 // Inactivity threshold above which probing is restarted. |
| 24 constexpr int kInactivityThresholdMs = 5000; | 24 constexpr int kInactivityThresholdMs = 5000; |
| 25 | 25 |
| 26 // A minimum interval between probes to allow scheduling to be feasible. | 26 // A minimum interval between probes to allow scheduling to be feasible. |
| 27 constexpr int kMinProbeDeltaMs = 1; | 27 constexpr int kMinProbeDeltaMs = 1; |
| 28 | 28 |
| 29 int ComputeDeltaFromBitrate(size_t probe_size, uint32_t bitrate_bps) { | 29 int ComputeDeltaFromBitrate(size_t probe_size, uint32_t bitrate_bps) { |
| 30 RTC_CHECK_GT(bitrate_bps, 0u); | 30 RTC_CHECK_GT(bitrate_bps, 0); |
| 31 // Compute the time delta needed to send probe_size bytes at bitrate_bps | 31 // Compute the time delta needed to send probe_size bytes at bitrate_bps |
| 32 // bps. Result is in milliseconds. | 32 // bps. Result is in milliseconds. |
| 33 return static_cast<int>((1000ll * probe_size * 8) / bitrate_bps); | 33 return static_cast<int>((1000ll * probe_size * 8) / bitrate_bps); |
| 34 } | 34 } |
| 35 } // namespace | 35 } // namespace |
| 36 | 36 |
| 37 BitrateProber::BitrateProber() | 37 BitrateProber::BitrateProber() |
| 38 : probing_state_(ProbingState::kDisabled), | 38 : probing_state_(ProbingState::kDisabled), |
| 39 probe_size_last_sent_(0), | 39 probe_size_last_sent_(0), |
| 40 time_last_probe_sent_ms_(-1), | 40 time_last_probe_sent_ms_(-1), |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 // a minimum of twice |kMinProbeDeltaMs| interval to allow scheduling to be | 146 // a minimum of twice |kMinProbeDeltaMs| interval to allow scheduling to be |
| 147 // feasible. | 147 // feasible. |
| 148 size_t BitrateProber::RecommendedMinProbeSize() const { | 148 size_t BitrateProber::RecommendedMinProbeSize() const { |
| 149 RTC_DCHECK(!clusters_.empty()); | 149 RTC_DCHECK(!clusters_.empty()); |
| 150 return clusters_.front().probe_bitrate_bps * 2 * kMinProbeDeltaMs / | 150 return clusters_.front().probe_bitrate_bps * 2 * kMinProbeDeltaMs / |
| 151 (8 * 1000); | 151 (8 * 1000); |
| 152 } | 152 } |
| 153 | 153 |
| 154 void BitrateProber::ProbeSent(int64_t now_ms, size_t bytes) { | 154 void BitrateProber::ProbeSent(int64_t now_ms, size_t bytes) { |
| 155 RTC_DCHECK(probing_state_ == ProbingState::kActive); | 155 RTC_DCHECK(probing_state_ == ProbingState::kActive); |
| 156 RTC_DCHECK_GT(bytes, 0u); | 156 RTC_DCHECK_GT(bytes, 0); |
| 157 probe_size_last_sent_ = bytes; | 157 probe_size_last_sent_ = bytes; |
| 158 time_last_probe_sent_ms_ = now_ms; | 158 time_last_probe_sent_ms_ = now_ms; |
| 159 if (!clusters_.empty()) { | 159 if (!clusters_.empty()) { |
| 160 ProbeCluster* cluster = &clusters_.front(); | 160 ProbeCluster* cluster = &clusters_.front(); |
| 161 ++cluster->sent_probes; | 161 ++cluster->sent_probes; |
| 162 if (cluster->sent_probes == cluster->max_probes) | 162 if (cluster->sent_probes == cluster->max_probes) |
| 163 clusters_.pop(); | 163 clusters_.pop(); |
| 164 if (clusters_.empty()) | 164 if (clusters_.empty()) |
| 165 probing_state_ = ProbingState::kSuspended; | 165 probing_state_ = ProbingState::kSuspended; |
| 166 } | 166 } |
| 167 } | 167 } |
| 168 } // namespace webrtc | 168 } // namespace webrtc |
| OLD | NEW |