mflodman@webrtc.org | e6168f5 | 2013-06-26 11:23:01 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #include "webrtc/video_engine/overuse_frame_detector.h" |
| 12 | |
mflodman@webrtc.org | d4412fe | 2013-07-31 16:42:21 +0000 | [diff] [blame] | 13 | #include <assert.h> |
pbos@webrtc.org | a957570 | 2013-08-30 17:16:32 +0000 | [diff] [blame] | 14 | #include <math.h> |
mflodman@webrtc.org | d4412fe | 2013-07-31 16:42:21 +0000 | [diff] [blame] | 15 | |
asapersson@webrtc.org | 9e5b034 | 2013-12-04 13:47:44 +0000 | [diff] [blame] | 16 | #include <algorithm> |
| 17 | #include <list> |
asapersson@webrtc.org | 734a532 | 2014-06-10 06:35:22 +0000 | [diff] [blame] | 18 | #include <map> |
asapersson@webrtc.org | 9e5b034 | 2013-12-04 13:47:44 +0000 | [diff] [blame] | 19 | |
minyue@webrtc.org | 74aaf29 | 2014-07-16 21:28:26 +0000 | [diff] [blame] | 20 | #include "webrtc/base/exp_filter.h" |
mflodman@webrtc.org | e6168f5 | 2013-06-26 11:23:01 +0000 | [diff] [blame] | 21 | #include "webrtc/system_wrappers/interface/clock.h" |
| 22 | #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" |
mflodman@webrtc.org | 5574dac | 2014-04-07 10:56:31 +0000 | [diff] [blame] | 23 | #include "webrtc/system_wrappers/interface/logging.h" |
mflodman@webrtc.org | e6168f5 | 2013-06-26 11:23:01 +0000 | [diff] [blame] | 24 | |
| 25 | namespace webrtc { |
| 26 | |
mflodman@webrtc.org | d4412fe | 2013-07-31 16:42:21 +0000 | [diff] [blame] | 27 | // TODO(mflodman) Test different values for all of these to trigger correctly, |
| 28 | // avoid fluctuations etc. |
mflodman@webrtc.org | d4412fe | 2013-07-31 16:42:21 +0000 | [diff] [blame] | 29 | namespace { |
pbos@webrtc.org | a957570 | 2013-08-30 17:16:32 +0000 | [diff] [blame] | 30 | const int64_t kProcessIntervalMs = 5000; |
mflodman@webrtc.org | d4412fe | 2013-07-31 16:42:21 +0000 | [diff] [blame] | 31 | |
asapersson@webrtc.org | e2af622 | 2013-09-23 20:05:39 +0000 | [diff] [blame] | 32 | // Weight factor to apply to the standard deviation. |
| 33 | const float kWeightFactor = 0.997f; |
asapersson@webrtc.org | e2af622 | 2013-09-23 20:05:39 +0000 | [diff] [blame] | 34 | // Weight factor to apply to the average. |
| 35 | const float kWeightFactorMean = 0.98f; |
| 36 | |
pbos@webrtc.org | a957570 | 2013-08-30 17:16:32 +0000 | [diff] [blame] | 37 | // Delay between consecutive rampups. (Used for quick recovery.) |
| 38 | const int kQuickRampUpDelayMs = 10 * 1000; |
| 39 | // Delay between rampup attempts. Initially uses standard, scales up to max. |
asapersson@webrtc.org | 23a4d85 | 2014-08-13 14:33:49 +0000 | [diff] [blame] | 40 | const int kStandardRampUpDelayMs = 40 * 1000; |
asapersson@webrtc.org | 2881ab1 | 2014-06-12 08:46:46 +0000 | [diff] [blame] | 41 | const int kMaxRampUpDelayMs = 240 * 1000; |
pbos@webrtc.org | a957570 | 2013-08-30 17:16:32 +0000 | [diff] [blame] | 42 | // Expontential back-off factor, to prevent annoying up-down behaviour. |
| 43 | const double kRampUpBackoffFactor = 2.0; |
mflodman@webrtc.org | d4412fe | 2013-07-31 16:42:21 +0000 | [diff] [blame] | 44 | |
asapersson@webrtc.org | d980307 | 2014-06-16 14:27:19 +0000 | [diff] [blame] | 45 | // Max number of overuses detected before always applying the rampup delay. |
asapersson@webrtc.org | 23a4d85 | 2014-08-13 14:33:49 +0000 | [diff] [blame] | 46 | const int kMaxOverusesBeforeApplyRampupDelay = 4; |
asapersson@webrtc.org | 9e5b034 | 2013-12-04 13:47:44 +0000 | [diff] [blame] | 47 | |
| 48 | // The maximum exponent to use in VCMExpFilter. |
| 49 | const float kSampleDiffMs = 33.0f; |
| 50 | const float kMaxExp = 7.0f; |
| 51 | |
mflodman@webrtc.org | d4412fe | 2013-07-31 16:42:21 +0000 | [diff] [blame] | 52 | } // namespace |
| 53 | |
asapersson@webrtc.org | 9aed002 | 2014-10-16 06:57:12 +0000 | [diff] [blame] | 54 | // TODO(asapersson): Remove this class. Not used. |
asapersson@webrtc.org | e2af622 | 2013-09-23 20:05:39 +0000 | [diff] [blame] | 55 | Statistics::Statistics() : |
| 56 | sum_(0.0), |
| 57 | count_(0), |
minyue@webrtc.org | 74aaf29 | 2014-07-16 21:28:26 +0000 | [diff] [blame] | 58 | filtered_samples_(new rtc::ExpFilter(kWeightFactorMean)), |
| 59 | filtered_variance_(new rtc::ExpFilter(kWeightFactor)) { |
asapersson@webrtc.org | 8a8c3ef | 2014-03-20 13:15:01 +0000 | [diff] [blame] | 60 | Reset(); |
| 61 | } |
| 62 | |
| 63 | void Statistics::SetOptions(const CpuOveruseOptions& options) { |
| 64 | options_ = options; |
asapersson@webrtc.org | e2af622 | 2013-09-23 20:05:39 +0000 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | void Statistics::Reset() { |
| 68 | sum_ = 0.0; |
| 69 | count_ = 0; |
asapersson@webrtc.org | 8a8c3ef | 2014-03-20 13:15:01 +0000 | [diff] [blame] | 70 | filtered_variance_->Reset(kWeightFactor); |
| 71 | filtered_variance_->Apply(1.0f, InitialVariance()); |
asapersson@webrtc.org | e2af622 | 2013-09-23 20:05:39 +0000 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | void Statistics::AddSample(float sample_ms) { |
| 75 | sum_ += sample_ms; |
| 76 | ++count_; |
| 77 | |
asapersson@webrtc.org | 8a8c3ef | 2014-03-20 13:15:01 +0000 | [diff] [blame] | 78 | if (count_ < static_cast<uint32_t>(options_.min_frame_samples)) { |
asapersson@webrtc.org | e2af622 | 2013-09-23 20:05:39 +0000 | [diff] [blame] | 79 | // Initialize filtered samples. |
| 80 | filtered_samples_->Reset(kWeightFactorMean); |
| 81 | filtered_samples_->Apply(1.0f, InitialMean()); |
asapersson@webrtc.org | e2af622 | 2013-09-23 20:05:39 +0000 | [diff] [blame] | 82 | return; |
| 83 | } |
| 84 | |
asapersson@webrtc.org | 9e5b034 | 2013-12-04 13:47:44 +0000 | [diff] [blame] | 85 | float exp = sample_ms / kSampleDiffMs; |
| 86 | exp = std::min(exp, kMaxExp); |
asapersson@webrtc.org | e2af622 | 2013-09-23 20:05:39 +0000 | [diff] [blame] | 87 | filtered_samples_->Apply(exp, sample_ms); |
minyue@webrtc.org | 74aaf29 | 2014-07-16 21:28:26 +0000 | [diff] [blame] | 88 | filtered_variance_->Apply(exp, (sample_ms - filtered_samples_->filtered()) * |
| 89 | (sample_ms - filtered_samples_->filtered())); |
asapersson@webrtc.org | e2af622 | 2013-09-23 20:05:39 +0000 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | float Statistics::InitialMean() const { |
| 93 | if (count_ == 0) |
| 94 | return 0.0; |
| 95 | return sum_ / count_; |
| 96 | } |
| 97 | |
| 98 | float Statistics::InitialVariance() const { |
| 99 | // Start in between the underuse and overuse threshold. |
asapersson@webrtc.org | 8a8c3ef | 2014-03-20 13:15:01 +0000 | [diff] [blame] | 100 | float average_stddev = (options_.low_capture_jitter_threshold_ms + |
| 101 | options_.high_capture_jitter_threshold_ms) / 2.0f; |
asapersson@webrtc.org | e2af622 | 2013-09-23 20:05:39 +0000 | [diff] [blame] | 102 | return average_stddev * average_stddev; |
| 103 | } |
| 104 | |
minyue@webrtc.org | 74aaf29 | 2014-07-16 21:28:26 +0000 | [diff] [blame] | 105 | float Statistics::Mean() const { return filtered_samples_->filtered(); } |
asapersson@webrtc.org | e2af622 | 2013-09-23 20:05:39 +0000 | [diff] [blame] | 106 | |
| 107 | float Statistics::StdDev() const { |
minyue@webrtc.org | 74aaf29 | 2014-07-16 21:28:26 +0000 | [diff] [blame] | 108 | return sqrt(std::max(filtered_variance_->filtered(), 0.0f)); |
asapersson@webrtc.org | e2af622 | 2013-09-23 20:05:39 +0000 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | uint64_t Statistics::Count() const { return count_; } |
| 112 | |
asapersson@webrtc.org | 9e5b034 | 2013-12-04 13:47:44 +0000 | [diff] [blame] | 113 | |
| 114 | // Class for calculating the average encode time. |
| 115 | class OveruseFrameDetector::EncodeTimeAvg { |
| 116 | public: |
| 117 | EncodeTimeAvg() |
| 118 | : kWeightFactor(0.5f), |
asapersson@webrtc.org | d980307 | 2014-06-16 14:27:19 +0000 | [diff] [blame] | 119 | kInitialAvgEncodeTimeMs(5.0f), |
minyue@webrtc.org | 74aaf29 | 2014-07-16 21:28:26 +0000 | [diff] [blame] | 120 | filtered_encode_time_ms_(new rtc::ExpFilter(kWeightFactor)) { |
asapersson@webrtc.org | 9e5b034 | 2013-12-04 13:47:44 +0000 | [diff] [blame] | 121 | filtered_encode_time_ms_->Apply(1.0f, kInitialAvgEncodeTimeMs); |
| 122 | } |
| 123 | ~EncodeTimeAvg() {} |
| 124 | |
asapersson@webrtc.org | 9aed002 | 2014-10-16 06:57:12 +0000 | [diff] [blame] | 125 | void AddSample(float encode_time_ms, int64_t diff_last_sample_ms) { |
asapersson@webrtc.org | 9e5b034 | 2013-12-04 13:47:44 +0000 | [diff] [blame] | 126 | float exp = diff_last_sample_ms / kSampleDiffMs; |
| 127 | exp = std::min(exp, kMaxExp); |
| 128 | filtered_encode_time_ms_->Apply(exp, encode_time_ms); |
| 129 | } |
| 130 | |
asapersson@webrtc.org | 2881ab1 | 2014-06-12 08:46:46 +0000 | [diff] [blame] | 131 | int Value() const { |
minyue@webrtc.org | 74aaf29 | 2014-07-16 21:28:26 +0000 | [diff] [blame] | 132 | return static_cast<int>(filtered_encode_time_ms_->filtered() + 0.5); |
asapersson@webrtc.org | 9e5b034 | 2013-12-04 13:47:44 +0000 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | private: |
| 136 | const float kWeightFactor; |
asapersson@webrtc.org | d980307 | 2014-06-16 14:27:19 +0000 | [diff] [blame] | 137 | const float kInitialAvgEncodeTimeMs; |
minyue@webrtc.org | 74aaf29 | 2014-07-16 21:28:26 +0000 | [diff] [blame] | 138 | scoped_ptr<rtc::ExpFilter> filtered_encode_time_ms_; |
asapersson@webrtc.org | 9e5b034 | 2013-12-04 13:47:44 +0000 | [diff] [blame] | 139 | }; |
| 140 | |
asapersson@webrtc.org | 9aed002 | 2014-10-16 06:57:12 +0000 | [diff] [blame] | 141 | // Class for calculating the processing usage on the send-side (the average |
| 142 | // processing time of a frame divided by the average time difference between |
| 143 | // captured frames). |
| 144 | class OveruseFrameDetector::SendProcessingUsage { |
asapersson@webrtc.org | 9e5b034 | 2013-12-04 13:47:44 +0000 | [diff] [blame] | 145 | public: |
asapersson@webrtc.org | 9aed002 | 2014-10-16 06:57:12 +0000 | [diff] [blame] | 146 | SendProcessingUsage() |
asapersson@webrtc.org | 9e5b034 | 2013-12-04 13:47:44 +0000 | [diff] [blame] | 147 | : kWeightFactorFrameDiff(0.998f), |
asapersson@webrtc.org | 9aed002 | 2014-10-16 06:57:12 +0000 | [diff] [blame] | 148 | kWeightFactorProcessing(0.995f), |
asapersson@webrtc.org | e41dbee | 2014-05-13 13:45:13 +0000 | [diff] [blame] | 149 | kInitialSampleDiffMs(40.0f), |
| 150 | kMaxSampleDiffMs(45.0f), |
asapersson@webrtc.org | ce12f1f | 2014-03-24 21:59:16 +0000 | [diff] [blame] | 151 | count_(0), |
asapersson@webrtc.org | 9aed002 | 2014-10-16 06:57:12 +0000 | [diff] [blame] | 152 | filtered_processing_ms_(new rtc::ExpFilter(kWeightFactorProcessing)), |
minyue@webrtc.org | 74aaf29 | 2014-07-16 21:28:26 +0000 | [diff] [blame] | 153 | filtered_frame_diff_ms_(new rtc::ExpFilter(kWeightFactorFrameDiff)) { |
asapersson@webrtc.org | ce12f1f | 2014-03-24 21:59:16 +0000 | [diff] [blame] | 154 | Reset(); |
asapersson@webrtc.org | 9e5b034 | 2013-12-04 13:47:44 +0000 | [diff] [blame] | 155 | } |
asapersson@webrtc.org | 9aed002 | 2014-10-16 06:57:12 +0000 | [diff] [blame] | 156 | ~SendProcessingUsage() {} |
asapersson@webrtc.org | 9e5b034 | 2013-12-04 13:47:44 +0000 | [diff] [blame] | 157 | |
asapersson@webrtc.org | ce12f1f | 2014-03-24 21:59:16 +0000 | [diff] [blame] | 158 | void SetOptions(const CpuOveruseOptions& options) { |
| 159 | options_ = options; |
| 160 | } |
| 161 | |
| 162 | void Reset() { |
| 163 | count_ = 0; |
| 164 | filtered_frame_diff_ms_->Reset(kWeightFactorFrameDiff); |
| 165 | filtered_frame_diff_ms_->Apply(1.0f, kInitialSampleDiffMs); |
asapersson@webrtc.org | 9aed002 | 2014-10-16 06:57:12 +0000 | [diff] [blame] | 166 | filtered_processing_ms_->Reset(kWeightFactorProcessing); |
| 167 | filtered_processing_ms_->Apply(1.0f, InitialProcessingMs()); |
asapersson@webrtc.org | ce12f1f | 2014-03-24 21:59:16 +0000 | [diff] [blame] | 168 | } |
| 169 | |
asapersson@webrtc.org | 9aed002 | 2014-10-16 06:57:12 +0000 | [diff] [blame] | 170 | void AddCaptureSample(float sample_ms) { |
asapersson@webrtc.org | 9e5b034 | 2013-12-04 13:47:44 +0000 | [diff] [blame] | 171 | float exp = sample_ms / kSampleDiffMs; |
| 172 | exp = std::min(exp, kMaxExp); |
| 173 | filtered_frame_diff_ms_->Apply(exp, sample_ms); |
| 174 | } |
| 175 | |
asapersson@webrtc.org | 9aed002 | 2014-10-16 06:57:12 +0000 | [diff] [blame] | 176 | void AddSample(float processing_ms, int64_t diff_last_sample_ms) { |
asapersson@webrtc.org | ce12f1f | 2014-03-24 21:59:16 +0000 | [diff] [blame] | 177 | ++count_; |
asapersson@webrtc.org | 9e5b034 | 2013-12-04 13:47:44 +0000 | [diff] [blame] | 178 | float exp = diff_last_sample_ms / kSampleDiffMs; |
| 179 | exp = std::min(exp, kMaxExp); |
asapersson@webrtc.org | 9aed002 | 2014-10-16 06:57:12 +0000 | [diff] [blame] | 180 | filtered_processing_ms_->Apply(exp, processing_ms); |
asapersson@webrtc.org | 9e5b034 | 2013-12-04 13:47:44 +0000 | [diff] [blame] | 181 | } |
| 182 | |
asapersson@webrtc.org | 2881ab1 | 2014-06-12 08:46:46 +0000 | [diff] [blame] | 183 | int Value() const { |
asapersson@webrtc.org | ce12f1f | 2014-03-24 21:59:16 +0000 | [diff] [blame] | 184 | if (count_ < static_cast<uint32_t>(options_.min_frame_samples)) { |
| 185 | return static_cast<int>(InitialUsageInPercent() + 0.5f); |
| 186 | } |
minyue@webrtc.org | 74aaf29 | 2014-07-16 21:28:26 +0000 | [diff] [blame] | 187 | float frame_diff_ms = std::max(filtered_frame_diff_ms_->filtered(), 1.0f); |
asapersson@webrtc.org | ce12f1f | 2014-03-24 21:59:16 +0000 | [diff] [blame] | 188 | frame_diff_ms = std::min(frame_diff_ms, kMaxSampleDiffMs); |
asapersson@webrtc.org | 9e5b034 | 2013-12-04 13:47:44 +0000 | [diff] [blame] | 189 | float encode_usage_percent = |
asapersson@webrtc.org | 9aed002 | 2014-10-16 06:57:12 +0000 | [diff] [blame] | 190 | 100.0f * filtered_processing_ms_->filtered() / frame_diff_ms; |
asapersson@webrtc.org | 9e5b034 | 2013-12-04 13:47:44 +0000 | [diff] [blame] | 191 | return static_cast<int>(encode_usage_percent + 0.5); |
| 192 | } |
| 193 | |
asapersson@webrtc.org | 2881ab1 | 2014-06-12 08:46:46 +0000 | [diff] [blame] | 194 | private: |
asapersson@webrtc.org | ce12f1f | 2014-03-24 21:59:16 +0000 | [diff] [blame] | 195 | float InitialUsageInPercent() const { |
| 196 | // Start in between the underuse and overuse threshold. |
| 197 | return (options_.low_encode_usage_threshold_percent + |
| 198 | options_.high_encode_usage_threshold_percent) / 2.0f; |
| 199 | } |
| 200 | |
asapersson@webrtc.org | 9aed002 | 2014-10-16 06:57:12 +0000 | [diff] [blame] | 201 | float InitialProcessingMs() const { |
asapersson@webrtc.org | ce12f1f | 2014-03-24 21:59:16 +0000 | [diff] [blame] | 202 | return InitialUsageInPercent() * kInitialSampleDiffMs / 100; |
| 203 | } |
| 204 | |
asapersson@webrtc.org | 9e5b034 | 2013-12-04 13:47:44 +0000 | [diff] [blame] | 205 | const float kWeightFactorFrameDiff; |
asapersson@webrtc.org | 9aed002 | 2014-10-16 06:57:12 +0000 | [diff] [blame] | 206 | const float kWeightFactorProcessing; |
asapersson@webrtc.org | ce12f1f | 2014-03-24 21:59:16 +0000 | [diff] [blame] | 207 | const float kInitialSampleDiffMs; |
| 208 | const float kMaxSampleDiffMs; |
| 209 | uint64_t count_; |
| 210 | CpuOveruseOptions options_; |
asapersson@webrtc.org | 9aed002 | 2014-10-16 06:57:12 +0000 | [diff] [blame] | 211 | scoped_ptr<rtc::ExpFilter> filtered_processing_ms_; |
minyue@webrtc.org | 74aaf29 | 2014-07-16 21:28:26 +0000 | [diff] [blame] | 212 | scoped_ptr<rtc::ExpFilter> filtered_frame_diff_ms_; |
asapersson@webrtc.org | 9e5b034 | 2013-12-04 13:47:44 +0000 | [diff] [blame] | 213 | }; |
| 214 | |
asapersson@webrtc.org | 9aed002 | 2014-10-16 06:57:12 +0000 | [diff] [blame] | 215 | // Class for calculating the processing time of frames. |
| 216 | class OveruseFrameDetector::FrameQueue { |
| 217 | public: |
| 218 | FrameQueue() : last_processing_time_ms_(-1) {} |
| 219 | ~FrameQueue() {} |
| 220 | |
| 221 | // Called when a frame is captured. |
| 222 | // Starts the measuring of the processing time of the frame. |
| 223 | void Start(int64_t capture_time, int64_t now) { |
| 224 | const size_t kMaxSize = 90; // Allows for processing time of 1.5s at 60fps. |
| 225 | if (frame_times_.size() > kMaxSize) { |
| 226 | LOG(LS_WARNING) << "Max size reached, removed oldest frame."; |
| 227 | frame_times_.erase(frame_times_.begin()); |
| 228 | } |
| 229 | if (frame_times_.find(capture_time) != frame_times_.end()) { |
| 230 | // Frame should not exist. |
| 231 | assert(false); |
| 232 | return; |
| 233 | } |
| 234 | frame_times_[capture_time] = now; |
| 235 | } |
| 236 | |
| 237 | // Called when the processing of a frame has finished. |
| 238 | // Returns the processing time of the frame. |
| 239 | int End(int64_t capture_time, int64_t now) { |
| 240 | std::map<int64_t, int64_t>::iterator it = frame_times_.find(capture_time); |
| 241 | if (it == frame_times_.end()) { |
| 242 | return -1; |
| 243 | } |
| 244 | // Remove any old frames up to current. |
| 245 | // Old frames have been skipped by the capture process thread. |
| 246 | // TODO(asapersson): Consider measuring time from first frame in list. |
| 247 | last_processing_time_ms_ = now - (*it).second; |
| 248 | frame_times_.erase(frame_times_.begin(), ++it); |
| 249 | return last_processing_time_ms_; |
| 250 | } |
| 251 | |
| 252 | void Reset() { frame_times_.clear(); } |
| 253 | int NumFrames() const { return frame_times_.size(); } |
| 254 | int last_processing_time_ms() const { return last_processing_time_ms_; } |
| 255 | |
| 256 | private: |
| 257 | // Captured frames mapped by the capture time. |
| 258 | std::map<int64_t, int64_t> frame_times_; |
| 259 | int last_processing_time_ms_; |
| 260 | }; |
| 261 | |
| 262 | // TODO(asapersson): Remove this class. Not used. |
asapersson@webrtc.org | 9e5b034 | 2013-12-04 13:47:44 +0000 | [diff] [blame] | 263 | // Class for calculating the capture queue delay change. |
| 264 | class OveruseFrameDetector::CaptureQueueDelay { |
| 265 | public: |
| 266 | CaptureQueueDelay() |
| 267 | : kWeightFactor(0.5f), |
| 268 | delay_ms_(0), |
minyue@webrtc.org | 74aaf29 | 2014-07-16 21:28:26 +0000 | [diff] [blame] | 269 | filtered_delay_ms_per_s_(new rtc::ExpFilter(kWeightFactor)) { |
asapersson@webrtc.org | 9e5b034 | 2013-12-04 13:47:44 +0000 | [diff] [blame] | 270 | filtered_delay_ms_per_s_->Apply(1.0f, 0.0f); |
| 271 | } |
| 272 | ~CaptureQueueDelay() {} |
| 273 | |
| 274 | void FrameCaptured(int64_t now) { |
| 275 | const size_t kMaxSize = 200; |
| 276 | if (frames_.size() > kMaxSize) { |
| 277 | frames_.pop_front(); |
| 278 | } |
| 279 | frames_.push_back(now); |
| 280 | } |
| 281 | |
| 282 | void FrameProcessingStarted(int64_t now) { |
| 283 | if (frames_.empty()) { |
| 284 | return; |
| 285 | } |
| 286 | delay_ms_ = now - frames_.front(); |
| 287 | frames_.pop_front(); |
| 288 | } |
| 289 | |
| 290 | void CalculateDelayChange(int64_t diff_last_sample_ms) { |
| 291 | if (diff_last_sample_ms <= 0) { |
| 292 | return; |
| 293 | } |
| 294 | float exp = static_cast<float>(diff_last_sample_ms) / kProcessIntervalMs; |
| 295 | exp = std::min(exp, kMaxExp); |
| 296 | filtered_delay_ms_per_s_->Apply(exp, |
| 297 | delay_ms_ * 1000.0f / diff_last_sample_ms); |
| 298 | ClearFrames(); |
| 299 | } |
| 300 | |
| 301 | void ClearFrames() { |
| 302 | frames_.clear(); |
| 303 | } |
| 304 | |
| 305 | int delay_ms() const { |
| 306 | return delay_ms_; |
| 307 | } |
| 308 | |
asapersson@webrtc.org | 2881ab1 | 2014-06-12 08:46:46 +0000 | [diff] [blame] | 309 | int Value() const { |
minyue@webrtc.org | 74aaf29 | 2014-07-16 21:28:26 +0000 | [diff] [blame] | 310 | return static_cast<int>(filtered_delay_ms_per_s_->filtered() + 0.5); |
asapersson@webrtc.org | 9e5b034 | 2013-12-04 13:47:44 +0000 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | private: |
| 314 | const float kWeightFactor; |
| 315 | std::list<int64_t> frames_; |
| 316 | int delay_ms_; |
minyue@webrtc.org | 74aaf29 | 2014-07-16 21:28:26 +0000 | [diff] [blame] | 317 | scoped_ptr<rtc::ExpFilter> filtered_delay_ms_per_s_; |
asapersson@webrtc.org | 9e5b034 | 2013-12-04 13:47:44 +0000 | [diff] [blame] | 318 | }; |
| 319 | |
asapersson@webrtc.org | 8a8c3ef | 2014-03-20 13:15:01 +0000 | [diff] [blame] | 320 | OveruseFrameDetector::OveruseFrameDetector(Clock* clock) |
mflodman@webrtc.org | e6168f5 | 2013-06-26 11:23:01 +0000 | [diff] [blame] | 321 | : crit_(CriticalSectionWrapper::CreateCriticalSection()), |
mflodman@webrtc.org | 6879c8a | 2013-07-23 11:35:00 +0000 | [diff] [blame] | 322 | observer_(NULL), |
mflodman@webrtc.org | e6168f5 | 2013-06-26 11:23:01 +0000 | [diff] [blame] | 323 | clock_(clock), |
pbos@webrtc.org | a957570 | 2013-08-30 17:16:32 +0000 | [diff] [blame] | 324 | next_process_time_(clock_->TimeInMilliseconds()), |
asapersson@webrtc.org | b60346e | 2014-02-17 19:02:15 +0000 | [diff] [blame] | 325 | num_process_times_(0), |
pbos@webrtc.org | a957570 | 2013-08-30 17:16:32 +0000 | [diff] [blame] | 326 | last_capture_time_(0), |
| 327 | last_overuse_time_(0), |
| 328 | checks_above_threshold_(0), |
asapersson@webrtc.org | d980307 | 2014-06-16 14:27:19 +0000 | [diff] [blame] | 329 | num_overuse_detections_(0), |
pbos@webrtc.org | a957570 | 2013-08-30 17:16:32 +0000 | [diff] [blame] | 330 | last_rampup_time_(0), |
| 331 | in_quick_rampup_(false), |
asapersson@webrtc.org | e2af622 | 2013-09-23 20:05:39 +0000 | [diff] [blame] | 332 | current_rampup_delay_ms_(kStandardRampUpDelayMs), |
asapersson@webrtc.org | b24d335 | 2013-11-20 13:51:40 +0000 | [diff] [blame] | 333 | num_pixels_(0), |
asapersson@webrtc.org | 9e5b034 | 2013-12-04 13:47:44 +0000 | [diff] [blame] | 334 | last_encode_sample_ms_(0), |
| 335 | encode_time_(new EncodeTimeAvg()), |
asapersson@webrtc.org | 9aed002 | 2014-10-16 06:57:12 +0000 | [diff] [blame] | 336 | usage_(new SendProcessingUsage()), |
| 337 | frame_queue_(new FrameQueue()), |
| 338 | last_sample_time_ms_(0), |
asapersson@webrtc.org | 9e5b034 | 2013-12-04 13:47:44 +0000 | [diff] [blame] | 339 | capture_queue_delay_(new CaptureQueueDelay()) { |
| 340 | } |
mflodman@webrtc.org | e6168f5 | 2013-06-26 11:23:01 +0000 | [diff] [blame] | 341 | |
| 342 | OveruseFrameDetector::~OveruseFrameDetector() { |
| 343 | } |
| 344 | |
mflodman@webrtc.org | 6879c8a | 2013-07-23 11:35:00 +0000 | [diff] [blame] | 345 | void OveruseFrameDetector::SetObserver(CpuOveruseObserver* observer) { |
| 346 | CriticalSectionScoped cs(crit_.get()); |
| 347 | observer_ = observer; |
| 348 | } |
| 349 | |
asapersson@webrtc.org | 8a8c3ef | 2014-03-20 13:15:01 +0000 | [diff] [blame] | 350 | void OveruseFrameDetector::SetOptions(const CpuOveruseOptions& options) { |
| 351 | assert(options.min_frame_samples > 0); |
| 352 | CriticalSectionScoped cs(crit_.get()); |
| 353 | if (options_.Equals(options)) { |
| 354 | return; |
| 355 | } |
| 356 | options_ = options; |
| 357 | capture_deltas_.SetOptions(options); |
asapersson@webrtc.org | 9aed002 | 2014-10-16 06:57:12 +0000 | [diff] [blame] | 358 | usage_->SetOptions(options); |
asapersson@webrtc.org | 8a8c3ef | 2014-03-20 13:15:01 +0000 | [diff] [blame] | 359 | ResetAll(num_pixels_); |
| 360 | } |
| 361 | |
asapersson@webrtc.org | 9e5b034 | 2013-12-04 13:47:44 +0000 | [diff] [blame] | 362 | int OveruseFrameDetector::CaptureQueueDelayMsPerS() const { |
| 363 | CriticalSectionScoped cs(crit_.get()); |
| 364 | return capture_queue_delay_->delay_ms(); |
| 365 | } |
| 366 | |
asapersson@webrtc.org | 9aed002 | 2014-10-16 06:57:12 +0000 | [diff] [blame] | 367 | int OveruseFrameDetector::LastProcessingTimeMs() const { |
| 368 | CriticalSectionScoped cs(crit_.get()); |
| 369 | return frame_queue_->last_processing_time_ms(); |
| 370 | } |
| 371 | |
| 372 | int OveruseFrameDetector::FramesInQueue() const { |
| 373 | CriticalSectionScoped cs(crit_.get()); |
| 374 | return frame_queue_->NumFrames(); |
| 375 | } |
| 376 | |
asapersson@webrtc.org | ab6bf4f | 2014-05-27 07:43:15 +0000 | [diff] [blame] | 377 | void OveruseFrameDetector::GetCpuOveruseMetrics( |
| 378 | CpuOveruseMetrics* metrics) const { |
| 379 | CriticalSectionScoped cs(crit_.get()); |
| 380 | metrics->capture_jitter_ms = static_cast<int>(capture_deltas_.StdDev() + 0.5); |
asapersson@webrtc.org | 2881ab1 | 2014-06-12 08:46:46 +0000 | [diff] [blame] | 381 | metrics->avg_encode_time_ms = encode_time_->Value(); |
asapersson@webrtc.org | 7f10513 | 2014-10-29 10:05:21 +0000 | [diff] [blame] | 382 | metrics->encode_rsd = 0; |
asapersson@webrtc.org | 9aed002 | 2014-10-16 06:57:12 +0000 | [diff] [blame] | 383 | metrics->encode_usage_percent = usage_->Value(); |
asapersson@webrtc.org | 2881ab1 | 2014-06-12 08:46:46 +0000 | [diff] [blame] | 384 | metrics->capture_queue_delay_ms_per_s = capture_queue_delay_->Value(); |
asapersson@webrtc.org | ab6bf4f | 2014-05-27 07:43:15 +0000 | [diff] [blame] | 385 | } |
| 386 | |
asapersson@webrtc.org | 9e5b034 | 2013-12-04 13:47:44 +0000 | [diff] [blame] | 387 | int32_t OveruseFrameDetector::TimeUntilNextProcess() { |
| 388 | CriticalSectionScoped cs(crit_.get()); |
| 389 | return next_process_time_ - clock_->TimeInMilliseconds(); |
| 390 | } |
| 391 | |
asapersson@webrtc.org | 8a8c3ef | 2014-03-20 13:15:01 +0000 | [diff] [blame] | 392 | bool OveruseFrameDetector::FrameSizeChanged(int num_pixels) const { |
| 393 | if (num_pixels != num_pixels_) { |
| 394 | return true; |
| 395 | } |
| 396 | return false; |
| 397 | } |
| 398 | |
| 399 | bool OveruseFrameDetector::FrameTimeoutDetected(int64_t now) const { |
asapersson@webrtc.org | b60346e | 2014-02-17 19:02:15 +0000 | [diff] [blame] | 400 | if (last_capture_time_ == 0) { |
| 401 | return false; |
| 402 | } |
asapersson@webrtc.org | 8a8c3ef | 2014-03-20 13:15:01 +0000 | [diff] [blame] | 403 | return (now - last_capture_time_) > options_.frame_timeout_interval_ms; |
| 404 | } |
| 405 | |
| 406 | void OveruseFrameDetector::ResetAll(int num_pixels) { |
| 407 | num_pixels_ = num_pixels; |
| 408 | capture_deltas_.Reset(); |
asapersson@webrtc.org | 9aed002 | 2014-10-16 06:57:12 +0000 | [diff] [blame] | 409 | usage_->Reset(); |
asapersson@webrtc.org | 9aed002 | 2014-10-16 06:57:12 +0000 | [diff] [blame] | 410 | frame_queue_->Reset(); |
asapersson@webrtc.org | 8a8c3ef | 2014-03-20 13:15:01 +0000 | [diff] [blame] | 411 | capture_queue_delay_->ClearFrames(); |
| 412 | last_capture_time_ = 0; |
| 413 | num_process_times_ = 0; |
asapersson@webrtc.org | b60346e | 2014-02-17 19:02:15 +0000 | [diff] [blame] | 414 | } |
| 415 | |
asapersson@webrtc.org | 9aed002 | 2014-10-16 06:57:12 +0000 | [diff] [blame] | 416 | void OveruseFrameDetector::FrameCaptured(int width, |
| 417 | int height, |
| 418 | int64_t capture_time_ms) { |
mflodman@webrtc.org | d4412fe | 2013-07-31 16:42:21 +0000 | [diff] [blame] | 419 | CriticalSectionScoped cs(crit_.get()); |
asapersson@webrtc.org | e2af622 | 2013-09-23 20:05:39 +0000 | [diff] [blame] | 420 | |
asapersson@webrtc.org | b60346e | 2014-02-17 19:02:15 +0000 | [diff] [blame] | 421 | int64_t now = clock_->TimeInMilliseconds(); |
asapersson@webrtc.org | 8a8c3ef | 2014-03-20 13:15:01 +0000 | [diff] [blame] | 422 | if (FrameSizeChanged(width * height) || FrameTimeoutDetected(now)) { |
| 423 | ResetAll(width * height); |
asapersson@webrtc.org | e2af622 | 2013-09-23 20:05:39 +0000 | [diff] [blame] | 424 | } |
| 425 | |
pbos@webrtc.org | a957570 | 2013-08-30 17:16:32 +0000 | [diff] [blame] | 426 | if (last_capture_time_ != 0) { |
asapersson@webrtc.org | b60346e | 2014-02-17 19:02:15 +0000 | [diff] [blame] | 427 | capture_deltas_.AddSample(now - last_capture_time_); |
asapersson@webrtc.org | 9aed002 | 2014-10-16 06:57:12 +0000 | [diff] [blame] | 428 | usage_->AddCaptureSample(now - last_capture_time_); |
pbos@webrtc.org | a957570 | 2013-08-30 17:16:32 +0000 | [diff] [blame] | 429 | } |
asapersson@webrtc.org | b60346e | 2014-02-17 19:02:15 +0000 | [diff] [blame] | 430 | last_capture_time_ = now; |
asapersson@webrtc.org | 9e5b034 | 2013-12-04 13:47:44 +0000 | [diff] [blame] | 431 | |
asapersson@webrtc.org | b60346e | 2014-02-17 19:02:15 +0000 | [diff] [blame] | 432 | capture_queue_delay_->FrameCaptured(now); |
asapersson@webrtc.org | 9aed002 | 2014-10-16 06:57:12 +0000 | [diff] [blame] | 433 | |
| 434 | if (options_.enable_extended_processing_usage) { |
| 435 | frame_queue_->Start(capture_time_ms, now); |
| 436 | } |
asapersson@webrtc.org | 9e5b034 | 2013-12-04 13:47:44 +0000 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | void OveruseFrameDetector::FrameProcessingStarted() { |
| 440 | CriticalSectionScoped cs(crit_.get()); |
| 441 | capture_queue_delay_->FrameProcessingStarted(clock_->TimeInMilliseconds()); |
mflodman@webrtc.org | e6168f5 | 2013-06-26 11:23:01 +0000 | [diff] [blame] | 442 | } |
| 443 | |
asapersson@webrtc.org | c7ff8f9 | 2013-11-26 11:12:33 +0000 | [diff] [blame] | 444 | void OveruseFrameDetector::FrameEncoded(int encode_time_ms) { |
asapersson@webrtc.org | b24d335 | 2013-11-20 13:51:40 +0000 | [diff] [blame] | 445 | CriticalSectionScoped cs(crit_.get()); |
asapersson@webrtc.org | 9aed002 | 2014-10-16 06:57:12 +0000 | [diff] [blame] | 446 | int64_t now = clock_->TimeInMilliseconds(); |
asapersson@webrtc.org | 9e5b034 | 2013-12-04 13:47:44 +0000 | [diff] [blame] | 447 | if (last_encode_sample_ms_ != 0) { |
asapersson@webrtc.org | 9aed002 | 2014-10-16 06:57:12 +0000 | [diff] [blame] | 448 | int64_t diff_ms = now - last_encode_sample_ms_; |
| 449 | encode_time_->AddSample(encode_time_ms, diff_ms); |
asapersson@webrtc.org | 9e5b034 | 2013-12-04 13:47:44 +0000 | [diff] [blame] | 450 | } |
asapersson@webrtc.org | 9aed002 | 2014-10-16 06:57:12 +0000 | [diff] [blame] | 451 | last_encode_sample_ms_ = now; |
| 452 | |
| 453 | if (!options_.enable_extended_processing_usage) { |
| 454 | AddProcessingTime(encode_time_ms); |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | void OveruseFrameDetector::FrameSent(int64_t capture_time_ms) { |
| 459 | CriticalSectionScoped cs(crit_.get()); |
| 460 | if (!options_.enable_extended_processing_usage) { |
| 461 | return; |
| 462 | } |
| 463 | int delay_ms = frame_queue_->End(capture_time_ms, |
| 464 | clock_->TimeInMilliseconds()); |
| 465 | if (delay_ms > 0) { |
| 466 | AddProcessingTime(delay_ms); |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | void OveruseFrameDetector::AddProcessingTime(int elapsed_ms) { |
| 471 | int64_t now = clock_->TimeInMilliseconds(); |
| 472 | if (last_sample_time_ms_ != 0) { |
| 473 | int64_t diff_ms = now - last_sample_time_ms_; |
| 474 | usage_->AddSample(elapsed_ms, diff_ms); |
asapersson@webrtc.org | 9aed002 | 2014-10-16 06:57:12 +0000 | [diff] [blame] | 475 | } |
| 476 | last_sample_time_ms_ = now; |
asapersson@webrtc.org | c7ff8f9 | 2013-11-26 11:12:33 +0000 | [diff] [blame] | 477 | } |
| 478 | |
mflodman@webrtc.org | e6168f5 | 2013-06-26 11:23:01 +0000 | [diff] [blame] | 479 | int32_t OveruseFrameDetector::Process() { |
| 480 | CriticalSectionScoped cs(crit_.get()); |
pbos@webrtc.org | a957570 | 2013-08-30 17:16:32 +0000 | [diff] [blame] | 481 | |
mflodman@webrtc.org | 6879c8a | 2013-07-23 11:35:00 +0000 | [diff] [blame] | 482 | int64_t now = clock_->TimeInMilliseconds(); |
pbos@webrtc.org | a957570 | 2013-08-30 17:16:32 +0000 | [diff] [blame] | 483 | |
| 484 | // Used to protect against Process() being called too often. |
| 485 | if (now < next_process_time_) |
mflodman@webrtc.org | e6168f5 | 2013-06-26 11:23:01 +0000 | [diff] [blame] | 486 | return 0; |
| 487 | |
asapersson@webrtc.org | 9e5b034 | 2013-12-04 13:47:44 +0000 | [diff] [blame] | 488 | int64_t diff_ms = now - next_process_time_ + kProcessIntervalMs; |
pbos@webrtc.org | a957570 | 2013-08-30 17:16:32 +0000 | [diff] [blame] | 489 | next_process_time_ = now + kProcessIntervalMs; |
asapersson@webrtc.org | b60346e | 2014-02-17 19:02:15 +0000 | [diff] [blame] | 490 | ++num_process_times_; |
mflodman@webrtc.org | d4412fe | 2013-07-31 16:42:21 +0000 | [diff] [blame] | 491 | |
asapersson@webrtc.org | 9e5b034 | 2013-12-04 13:47:44 +0000 | [diff] [blame] | 492 | capture_queue_delay_->CalculateDelayChange(diff_ms); |
| 493 | |
asapersson@webrtc.org | 8a8c3ef | 2014-03-20 13:15:01 +0000 | [diff] [blame] | 494 | if (num_process_times_ <= options_.min_process_count) { |
asapersson@webrtc.org | b60346e | 2014-02-17 19:02:15 +0000 | [diff] [blame] | 495 | return 0; |
| 496 | } |
| 497 | |
mflodman@webrtc.org | d4412fe | 2013-07-31 16:42:21 +0000 | [diff] [blame] | 498 | if (IsOverusing()) { |
pbos@webrtc.org | a957570 | 2013-08-30 17:16:32 +0000 | [diff] [blame] | 499 | // If the last thing we did was going up, and now have to back down, we need |
| 500 | // to check if this peak was short. If so we should back off to avoid going |
| 501 | // back and forth between this load, the system doesn't seem to handle it. |
| 502 | bool check_for_backoff = last_rampup_time_ > last_overuse_time_; |
| 503 | if (check_for_backoff) { |
asapersson@webrtc.org | d980307 | 2014-06-16 14:27:19 +0000 | [diff] [blame] | 504 | if (now - last_rampup_time_ < kStandardRampUpDelayMs || |
| 505 | num_overuse_detections_ > kMaxOverusesBeforeApplyRampupDelay) { |
pbos@webrtc.org | a957570 | 2013-08-30 17:16:32 +0000 | [diff] [blame] | 506 | // Going up was not ok for very long, back off. |
| 507 | current_rampup_delay_ms_ *= kRampUpBackoffFactor; |
| 508 | if (current_rampup_delay_ms_ > kMaxRampUpDelayMs) |
| 509 | current_rampup_delay_ms_ = kMaxRampUpDelayMs; |
| 510 | } else { |
| 511 | // Not currently backing off, reset rampup delay. |
| 512 | current_rampup_delay_ms_ = kStandardRampUpDelayMs; |
| 513 | } |
| 514 | } |
| 515 | |
| 516 | last_overuse_time_ = now; |
| 517 | in_quick_rampup_ = false; |
| 518 | checks_above_threshold_ = 0; |
asapersson@webrtc.org | d980307 | 2014-06-16 14:27:19 +0000 | [diff] [blame] | 519 | ++num_overuse_detections_; |
pbos@webrtc.org | a957570 | 2013-08-30 17:16:32 +0000 | [diff] [blame] | 520 | |
| 521 | if (observer_ != NULL) |
| 522 | observer_->OveruseDetected(); |
mflodman@webrtc.org | d4412fe | 2013-07-31 16:42:21 +0000 | [diff] [blame] | 523 | } else if (IsUnderusing(now)) { |
pbos@webrtc.org | a957570 | 2013-08-30 17:16:32 +0000 | [diff] [blame] | 524 | last_rampup_time_ = now; |
| 525 | in_quick_rampup_ = true; |
| 526 | |
| 527 | if (observer_ != NULL) |
| 528 | observer_->NormalUsage(); |
mflodman@webrtc.org | e6168f5 | 2013-06-26 11:23:01 +0000 | [diff] [blame] | 529 | } |
pbos@webrtc.org | a957570 | 2013-08-30 17:16:32 +0000 | [diff] [blame] | 530 | |
mflodman@webrtc.org | 5574dac | 2014-04-07 10:56:31 +0000 | [diff] [blame] | 531 | int rampup_delay = |
| 532 | in_quick_rampup_ ? kQuickRampUpDelayMs : current_rampup_delay_ms_; |
asapersson@webrtc.org | d980307 | 2014-06-16 14:27:19 +0000 | [diff] [blame] | 533 | LOG(LS_VERBOSE) << " Frame stats: capture avg: " << capture_deltas_.Mean() |
| 534 | << " capture stddev " << capture_deltas_.StdDev() |
asapersson@webrtc.org | 9aed002 | 2014-10-16 06:57:12 +0000 | [diff] [blame] | 535 | << " encode usage " << usage_->Value() |
asapersson@webrtc.org | d980307 | 2014-06-16 14:27:19 +0000 | [diff] [blame] | 536 | << " overuse detections " << num_overuse_detections_ |
| 537 | << " rampup delay " << rampup_delay; |
asapersson@webrtc.org | e2af622 | 2013-09-23 20:05:39 +0000 | [diff] [blame] | 538 | return 0; |
| 539 | } |
| 540 | |
| 541 | bool OveruseFrameDetector::IsOverusing() { |
asapersson@webrtc.org | ce12f1f | 2014-03-24 21:59:16 +0000 | [diff] [blame] | 542 | bool overusing = false; |
| 543 | if (options_.enable_capture_jitter_method) { |
| 544 | overusing = capture_deltas_.StdDev() >= |
| 545 | options_.high_capture_jitter_threshold_ms; |
| 546 | } else if (options_.enable_encode_usage_method) { |
asapersson@webrtc.org | 7f10513 | 2014-10-29 10:05:21 +0000 | [diff] [blame] | 547 | overusing = usage_->Value() >= options_.high_encode_usage_threshold_percent; |
asapersson@webrtc.org | ce12f1f | 2014-03-24 21:59:16 +0000 | [diff] [blame] | 548 | } |
| 549 | |
asapersson@webrtc.org | 8a8c3ef | 2014-03-20 13:15:01 +0000 | [diff] [blame] | 550 | if (overusing) { |
pbos@webrtc.org | a957570 | 2013-08-30 17:16:32 +0000 | [diff] [blame] | 551 | ++checks_above_threshold_; |
| 552 | } else { |
| 553 | checks_above_threshold_ = 0; |
| 554 | } |
asapersson@webrtc.org | 8a8c3ef | 2014-03-20 13:15:01 +0000 | [diff] [blame] | 555 | return checks_above_threshold_ >= options_.high_threshold_consecutive_count; |
mflodman@webrtc.org | d4412fe | 2013-07-31 16:42:21 +0000 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | bool OveruseFrameDetector::IsUnderusing(int64_t time_now) { |
pbos@webrtc.org | a957570 | 2013-08-30 17:16:32 +0000 | [diff] [blame] | 559 | int delay = in_quick_rampup_ ? kQuickRampUpDelayMs : current_rampup_delay_ms_; |
| 560 | if (time_now < last_rampup_time_ + delay) |
mflodman@webrtc.org | d4412fe | 2013-07-31 16:42:21 +0000 | [diff] [blame] | 561 | return false; |
mflodman@webrtc.org | d4412fe | 2013-07-31 16:42:21 +0000 | [diff] [blame] | 562 | |
asapersson@webrtc.org | ce12f1f | 2014-03-24 21:59:16 +0000 | [diff] [blame] | 563 | bool underusing = false; |
| 564 | if (options_.enable_capture_jitter_method) { |
| 565 | underusing = capture_deltas_.StdDev() < |
| 566 | options_.low_capture_jitter_threshold_ms; |
| 567 | } else if (options_.enable_encode_usage_method) { |
asapersson@webrtc.org | 7f10513 | 2014-10-29 10:05:21 +0000 | [diff] [blame] | 568 | underusing = usage_->Value() < options_.low_encode_usage_threshold_percent; |
asapersson@webrtc.org | ce12f1f | 2014-03-24 21:59:16 +0000 | [diff] [blame] | 569 | } |
asapersson@webrtc.org | 8a8c3ef | 2014-03-20 13:15:01 +0000 | [diff] [blame] | 570 | return underusing; |
mflodman@webrtc.org | d4412fe | 2013-07-31 16:42:21 +0000 | [diff] [blame] | 571 | } |
mflodman@webrtc.org | e6168f5 | 2013-06-26 11:23:01 +0000 | [diff] [blame] | 572 | } // namespace webrtc |