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

Side by Side Diff: webrtc/video/overuse_frame_detector.cc

Issue 2918143003: Set overuse detector max frame interval based on target frame rate. (Closed)
Patch Set: Rebase Created 3 years, 6 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
« no previous file with comments | « webrtc/video/overuse_frame_detector.h ('k') | webrtc/video/overuse_frame_detector_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 // Delay between rampup attempts. Initially uses standard, scales up to max. 42 // Delay between rampup attempts. Initially uses standard, scales up to max.
43 const int kStandardRampUpDelayMs = 40 * 1000; 43 const int kStandardRampUpDelayMs = 40 * 1000;
44 const int kMaxRampUpDelayMs = 240 * 1000; 44 const int kMaxRampUpDelayMs = 240 * 1000;
45 // Expontential back-off factor, to prevent annoying up-down behaviour. 45 // Expontential back-off factor, to prevent annoying up-down behaviour.
46 const double kRampUpBackoffFactor = 2.0; 46 const double kRampUpBackoffFactor = 2.0;
47 47
48 // Max number of overuses detected before always applying the rampup delay. 48 // Max number of overuses detected before always applying the rampup delay.
49 const int kMaxOverusesBeforeApplyRampupDelay = 4; 49 const int kMaxOverusesBeforeApplyRampupDelay = 4;
50 50
51 // The maximum exponent to use in VCMExpFilter. 51 // The maximum exponent to use in VCMExpFilter.
52 const float kSampleDiffMs = 33.0f;
53 const float kMaxExp = 7.0f; 52 const float kMaxExp = 7.0f;
53 // Default value used before first reconfiguration.
54 const int kDefaultFrameRate = 30;
55 // Default sample diff, default frame rate.
56 const float kDefaultSampleDiffMs = 1000.0f / kDefaultFrameRate;
57 // A factor applied to the sample diff on OnTargetFramerateUpdated to determine
58 // a max limit for the sample diff. For instance, with a framerate of 30fps,
59 // the sample diff is capped to (1000 / 30) * 1.35 = 45ms. This prevents
60 // triggering too soon if there are individual very large outliers.
61 const float kMaxSampleDiffMarginFactor = 1.35f;
62 // Minimum framerate allowed for usage calculation. This prevents crazy long
63 // encode times from being accepted if the frame rate happens to be low.
64 const int kMinFramerate = 7;
65 const int kMaxFramerate = 30;
54 66
55 const auto kScaleReasonCpu = AdaptationObserverInterface::AdaptReason::kCpu; 67 const auto kScaleReasonCpu = AdaptationObserverInterface::AdaptReason::kCpu;
56 } // namespace 68 } // namespace
57 69
58 CpuOveruseOptions::CpuOveruseOptions() 70 CpuOveruseOptions::CpuOveruseOptions()
59 : high_encode_usage_threshold_percent(85), 71 : high_encode_usage_threshold_percent(85),
60 frame_timeout_interval_ms(1500), 72 frame_timeout_interval_ms(1500),
61 min_frame_samples(120), 73 min_frame_samples(120),
62 min_process_count(3), 74 min_process_count(3),
63 high_threshold_consecutive_count(2) { 75 high_threshold_consecutive_count(2) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 118
107 // Class for calculating the processing usage on the send-side (the average 119 // Class for calculating the processing usage on the send-side (the average
108 // processing time of a frame divided by the average time difference between 120 // processing time of a frame divided by the average time difference between
109 // captured frames). 121 // captured frames).
110 class OveruseFrameDetector::SendProcessingUsage { 122 class OveruseFrameDetector::SendProcessingUsage {
111 public: 123 public:
112 explicit SendProcessingUsage(const CpuOveruseOptions& options) 124 explicit SendProcessingUsage(const CpuOveruseOptions& options)
113 : kWeightFactorFrameDiff(0.998f), 125 : kWeightFactorFrameDiff(0.998f),
114 kWeightFactorProcessing(0.995f), 126 kWeightFactorProcessing(0.995f),
115 kInitialSampleDiffMs(40.0f), 127 kInitialSampleDiffMs(40.0f),
116 kMaxSampleDiffMs(45.0f),
117 count_(0), 128 count_(0),
118 options_(options), 129 options_(options),
130 max_sample_diff_ms_(kDefaultSampleDiffMs * kMaxSampleDiffMarginFactor),
119 filtered_processing_ms_(new rtc::ExpFilter(kWeightFactorProcessing)), 131 filtered_processing_ms_(new rtc::ExpFilter(kWeightFactorProcessing)),
120 filtered_frame_diff_ms_(new rtc::ExpFilter(kWeightFactorFrameDiff)) { 132 filtered_frame_diff_ms_(new rtc::ExpFilter(kWeightFactorFrameDiff)) {
121 Reset(); 133 Reset();
122 } 134 }
123 virtual ~SendProcessingUsage() {} 135 virtual ~SendProcessingUsage() {}
124 136
125 void Reset() { 137 void Reset() {
126 count_ = 0; 138 count_ = 0;
139 max_sample_diff_ms_ = kDefaultSampleDiffMs * kMaxSampleDiffMarginFactor;
127 filtered_frame_diff_ms_->Reset(kWeightFactorFrameDiff); 140 filtered_frame_diff_ms_->Reset(kWeightFactorFrameDiff);
128 filtered_frame_diff_ms_->Apply(1.0f, kInitialSampleDiffMs); 141 filtered_frame_diff_ms_->Apply(1.0f, kInitialSampleDiffMs);
129 filtered_processing_ms_->Reset(kWeightFactorProcessing); 142 filtered_processing_ms_->Reset(kWeightFactorProcessing);
130 filtered_processing_ms_->Apply(1.0f, InitialProcessingMs()); 143 filtered_processing_ms_->Apply(1.0f, InitialProcessingMs());
131 } 144 }
132 145
146 void SetMaxSampleDiffMs(float diff_ms) { max_sample_diff_ms_ = diff_ms; }
147
133 void AddCaptureSample(float sample_ms) { 148 void AddCaptureSample(float sample_ms) {
134 float exp = sample_ms / kSampleDiffMs; 149 float exp = sample_ms / kDefaultSampleDiffMs;
135 exp = std::min(exp, kMaxExp); 150 exp = std::min(exp, kMaxExp);
136 filtered_frame_diff_ms_->Apply(exp, sample_ms); 151 filtered_frame_diff_ms_->Apply(exp, sample_ms);
137 } 152 }
138 153
139 void AddSample(float processing_ms, int64_t diff_last_sample_ms) { 154 void AddSample(float processing_ms, int64_t diff_last_sample_ms) {
140 ++count_; 155 ++count_;
141 float exp = diff_last_sample_ms / kSampleDiffMs; 156 float exp = diff_last_sample_ms / kDefaultSampleDiffMs;
142 exp = std::min(exp, kMaxExp); 157 exp = std::min(exp, kMaxExp);
143 filtered_processing_ms_->Apply(exp, processing_ms); 158 filtered_processing_ms_->Apply(exp, processing_ms);
144 } 159 }
145 160
146 virtual int Value() { 161 virtual int Value() {
147 if (count_ < static_cast<uint32_t>(options_.min_frame_samples)) { 162 if (count_ < static_cast<uint32_t>(options_.min_frame_samples)) {
148 return static_cast<int>(InitialUsageInPercent() + 0.5f); 163 return static_cast<int>(InitialUsageInPercent() + 0.5f);
149 } 164 }
150 float frame_diff_ms = std::max(filtered_frame_diff_ms_->filtered(), 1.0f); 165 float frame_diff_ms = std::max(filtered_frame_diff_ms_->filtered(), 1.0f);
151 frame_diff_ms = std::min(frame_diff_ms, kMaxSampleDiffMs); 166 frame_diff_ms = std::min(frame_diff_ms, max_sample_diff_ms_);
152 float encode_usage_percent = 167 float encode_usage_percent =
153 100.0f * filtered_processing_ms_->filtered() / frame_diff_ms; 168 100.0f * filtered_processing_ms_->filtered() / frame_diff_ms;
154 return static_cast<int>(encode_usage_percent + 0.5); 169 return static_cast<int>(encode_usage_percent + 0.5);
155 } 170 }
156 171
157 private: 172 private:
158 float InitialUsageInPercent() const { 173 float InitialUsageInPercent() const {
159 // Start in between the underuse and overuse threshold. 174 // Start in between the underuse and overuse threshold.
160 return (options_.low_encode_usage_threshold_percent + 175 return (options_.low_encode_usage_threshold_percent +
161 options_.high_encode_usage_threshold_percent) / 2.0f; 176 options_.high_encode_usage_threshold_percent) / 2.0f;
162 } 177 }
163 178
164 float InitialProcessingMs() const { 179 float InitialProcessingMs() const {
165 return InitialUsageInPercent() * kInitialSampleDiffMs / 100; 180 return InitialUsageInPercent() * kInitialSampleDiffMs / 100;
166 } 181 }
167 182
168 const float kWeightFactorFrameDiff; 183 const float kWeightFactorFrameDiff;
169 const float kWeightFactorProcessing; 184 const float kWeightFactorProcessing;
170 const float kInitialSampleDiffMs; 185 const float kInitialSampleDiffMs;
171 const float kMaxSampleDiffMs;
172 uint64_t count_; 186 uint64_t count_;
173 const CpuOveruseOptions options_; 187 const CpuOveruseOptions options_;
188 float max_sample_diff_ms_;
174 std::unique_ptr<rtc::ExpFilter> filtered_processing_ms_; 189 std::unique_ptr<rtc::ExpFilter> filtered_processing_ms_;
175 std::unique_ptr<rtc::ExpFilter> filtered_frame_diff_ms_; 190 std::unique_ptr<rtc::ExpFilter> filtered_frame_diff_ms_;
176 }; 191 };
177 192
178 // Class used for manual testing of overuse, enabled via field trial flag. 193 // Class used for manual testing of overuse, enabled via field trial flag.
179 class OveruseFrameDetector::OverdoseInjector 194 class OveruseFrameDetector::OverdoseInjector
180 : public OveruseFrameDetector::SendProcessingUsage { 195 : public OveruseFrameDetector::SendProcessingUsage {
181 public: 196 public:
182 OverdoseInjector(const CpuOveruseOptions& options, 197 OverdoseInjector(const CpuOveruseOptions& options,
183 int64_t normal_period_ms, 198 int64_t normal_period_ms,
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 : check_overuse_task_(nullptr), 339 : check_overuse_task_(nullptr),
325 options_(options), 340 options_(options),
326 observer_(observer), 341 observer_(observer),
327 encoder_timing_(encoder_timing), 342 encoder_timing_(encoder_timing),
328 metrics_observer_(metrics_observer), 343 metrics_observer_(metrics_observer),
329 num_process_times_(0), 344 num_process_times_(0),
330 // TODO(nisse): Use rtc::Optional 345 // TODO(nisse): Use rtc::Optional
331 last_capture_time_us_(-1), 346 last_capture_time_us_(-1),
332 last_processed_capture_time_us_(-1), 347 last_processed_capture_time_us_(-1),
333 num_pixels_(0), 348 num_pixels_(0),
349 max_framerate_(kDefaultFrameRate),
334 last_overuse_time_ms_(-1), 350 last_overuse_time_ms_(-1),
335 checks_above_threshold_(0), 351 checks_above_threshold_(0),
336 num_overuse_detections_(0), 352 num_overuse_detections_(0),
337 last_rampup_time_ms_(-1), 353 last_rampup_time_ms_(-1),
338 in_quick_rampup_(false), 354 in_quick_rampup_(false),
339 current_rampup_delay_ms_(kStandardRampUpDelayMs), 355 current_rampup_delay_ms_(kStandardRampUpDelayMs),
340 usage_(CreateSendProcessingUsage(options)) { 356 usage_(CreateSendProcessingUsage(options)) {
341 task_checker_.Detach(); 357 task_checker_.Detach();
342 } 358 }
343 359
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 391
376 bool OveruseFrameDetector::FrameTimeoutDetected(int64_t now_us) const { 392 bool OveruseFrameDetector::FrameTimeoutDetected(int64_t now_us) const {
377 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_); 393 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_);
378 if (last_capture_time_us_ == -1) 394 if (last_capture_time_us_ == -1)
379 return false; 395 return false;
380 return (now_us - last_capture_time_us_) > 396 return (now_us - last_capture_time_us_) >
381 options_.frame_timeout_interval_ms * rtc::kNumMicrosecsPerMillisec; 397 options_.frame_timeout_interval_ms * rtc::kNumMicrosecsPerMillisec;
382 } 398 }
383 399
384 void OveruseFrameDetector::ResetAll(int num_pixels) { 400 void OveruseFrameDetector::ResetAll(int num_pixels) {
401 // Reset state, as a result resolution being changed. Do not however change
402 // the current frame rate back to the default.
385 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_); 403 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_);
386 num_pixels_ = num_pixels; 404 num_pixels_ = num_pixels;
387 usage_->Reset(); 405 usage_->Reset();
388 frame_timing_.clear(); 406 frame_timing_.clear();
389 last_capture_time_us_ = -1; 407 last_capture_time_us_ = -1;
390 last_processed_capture_time_us_ = -1; 408 last_processed_capture_time_us_ = -1;
391 num_process_times_ = 0; 409 num_process_times_ = 0;
392 metrics_ = rtc::Optional<CpuOveruseMetrics>(); 410 metrics_ = rtc::Optional<CpuOveruseMetrics>();
411 OnTargetFramerateUpdated(max_framerate_);
412 }
413
414 void OveruseFrameDetector::OnTargetFramerateUpdated(int framerate_fps) {
415 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_);
416 RTC_DCHECK_GE(framerate_fps, 0);
417 max_framerate_ = std::min(kMaxFramerate, framerate_fps);
418 usage_->SetMaxSampleDiffMs((1000 / std::max(kMinFramerate, max_framerate_)) *
419 kMaxSampleDiffMarginFactor);
393 } 420 }
394 421
395 void OveruseFrameDetector::FrameCaptured(const VideoFrame& frame, 422 void OveruseFrameDetector::FrameCaptured(const VideoFrame& frame,
396 int64_t time_when_first_seen_us) { 423 int64_t time_when_first_seen_us) {
397 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_); 424 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_);
398 425
399 if (FrameSizeChanged(frame.width() * frame.height()) || 426 if (FrameSizeChanged(frame.width() * frame.height()) ||
400 FrameTimeoutDetected(time_when_first_seen_us)) { 427 FrameTimeoutDetected(time_when_first_seen_us)) {
401 ResetAll(frame.width() * frame.height()); 428 ResetAll(frame.width() * frame.height());
402 } 429 }
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 int64_t time_now) { 553 int64_t time_now) {
527 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_); 554 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_);
528 int delay = in_quick_rampup_ ? kQuickRampUpDelayMs : current_rampup_delay_ms_; 555 int delay = in_quick_rampup_ ? kQuickRampUpDelayMs : current_rampup_delay_ms_;
529 if (time_now < last_rampup_time_ms_ + delay) 556 if (time_now < last_rampup_time_ms_ + delay)
530 return false; 557 return false;
531 558
532 return metrics.encode_usage_percent < 559 return metrics.encode_usage_percent <
533 options_.low_encode_usage_threshold_percent; 560 options_.low_encode_usage_threshold_percent;
534 } 561 }
535 } // namespace webrtc 562 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/video/overuse_frame_detector.h ('k') | webrtc/video/overuse_frame_detector_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698