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

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

Issue 1228853004: Reduce locking in overuse frame detector now that (as of r9508) the observer_ and options_ can only (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 2 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_engine/overuse_frame_detector.h ('k') | no next file » | 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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 192
193 OveruseFrameDetector::OveruseFrameDetector( 193 OveruseFrameDetector::OveruseFrameDetector(
194 Clock* clock, 194 Clock* clock,
195 const CpuOveruseOptions& options, 195 const CpuOveruseOptions& options,
196 CpuOveruseObserver* observer, 196 CpuOveruseObserver* observer,
197 CpuOveruseMetricsObserver* metrics_observer) 197 CpuOveruseMetricsObserver* metrics_observer)
198 : options_(options), 198 : options_(options),
199 observer_(observer), 199 observer_(observer),
200 metrics_observer_(metrics_observer), 200 metrics_observer_(metrics_observer),
201 clock_(clock), 201 clock_(clock),
202 next_process_time_(clock_->TimeInMilliseconds()),
203 num_process_times_(0), 202 num_process_times_(0),
204 last_capture_time_(0), 203 last_capture_time_(0),
204 num_pixels_(0),
205 next_process_time_(clock_->TimeInMilliseconds()),
205 last_overuse_time_(0), 206 last_overuse_time_(0),
206 checks_above_threshold_(0), 207 checks_above_threshold_(0),
207 num_overuse_detections_(0), 208 num_overuse_detections_(0),
208 last_rampup_time_(0), 209 last_rampup_time_(0),
209 in_quick_rampup_(false), 210 in_quick_rampup_(false),
210 current_rampup_delay_ms_(kStandardRampUpDelayMs), 211 current_rampup_delay_ms_(kStandardRampUpDelayMs),
211 num_pixels_(0),
212 last_encode_sample_ms_(0), 212 last_encode_sample_ms_(0),
213 last_sample_time_ms_(0),
213 encode_time_(new EncodeTimeAvg()), 214 encode_time_(new EncodeTimeAvg()),
214 usage_(new SendProcessingUsage(options)), 215 usage_(new SendProcessingUsage(options)),
215 frame_queue_(new FrameQueue()), 216 frame_queue_(new FrameQueue()) {
216 last_sample_time_ms_(0) {
217 RTC_DCHECK(metrics_observer != nullptr); 217 RTC_DCHECK(metrics_observer != nullptr);
218 // Make sure stats are initially up-to-date. This simplifies unit testing 218 // Make sure stats are initially up-to-date. This simplifies unit testing
219 // since we don't have to trigger an update using one of the methods which 219 // since we don't have to trigger an update using one of the methods which
220 // would also alter the overuse state. 220 // would also alter the overuse state.
221 UpdateCpuOveruseMetrics(); 221 UpdateCpuOveruseMetrics();
222 processing_thread_.DetachFromThread(); 222 processing_thread_.DetachFromThread();
223 } 223 }
224 224
225 OveruseFrameDetector::~OveruseFrameDetector() { 225 OveruseFrameDetector::~OveruseFrameDetector() {
226 } 226 }
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 RTC_DCHECK(processing_thread_.CalledOnValidThread()); 331 RTC_DCHECK(processing_thread_.CalledOnValidThread());
332 332
333 int64_t now = clock_->TimeInMilliseconds(); 333 int64_t now = clock_->TimeInMilliseconds();
334 334
335 // Used to protect against Process() being called too often. 335 // Used to protect against Process() being called too often.
336 if (now < next_process_time_) 336 if (now < next_process_time_)
337 return 0; 337 return 0;
338 338
339 next_process_time_ = now + kProcessIntervalMs; 339 next_process_time_ = now + kProcessIntervalMs;
340 340
341 rtc::CritScope cs(&crit_); 341 CpuOveruseMetrics current_metrics;
342 ++num_process_times_; 342 {
343 rtc::CritScope cs(&crit_);
344 ++num_process_times_;
343 345
344 if (num_process_times_ <= options_.min_process_count) { 346 current_metrics = metrics_;
345 return 0; 347 if (num_process_times_ <= options_.min_process_count)
348 return 0;
346 } 349 }
347 350
348 if (IsOverusing()) { 351 if (IsOverusing(current_metrics)) {
349 // If the last thing we did was going up, and now have to back down, we need 352 // If the last thing we did was going up, and now have to back down, we need
350 // to check if this peak was short. If so we should back off to avoid going 353 // to check if this peak was short. If so we should back off to avoid going
351 // back and forth between this load, the system doesn't seem to handle it. 354 // back and forth between this load, the system doesn't seem to handle it.
352 bool check_for_backoff = last_rampup_time_ > last_overuse_time_; 355 bool check_for_backoff = last_rampup_time_ > last_overuse_time_;
353 if (check_for_backoff) { 356 if (check_for_backoff) {
354 if (now - last_rampup_time_ < kStandardRampUpDelayMs || 357 if (now - last_rampup_time_ < kStandardRampUpDelayMs ||
355 num_overuse_detections_ > kMaxOverusesBeforeApplyRampupDelay) { 358 num_overuse_detections_ > kMaxOverusesBeforeApplyRampupDelay) {
356 // Going up was not ok for very long, back off. 359 // Going up was not ok for very long, back off.
357 current_rampup_delay_ms_ *= kRampUpBackoffFactor; 360 current_rampup_delay_ms_ *= kRampUpBackoffFactor;
358 if (current_rampup_delay_ms_ > kMaxRampUpDelayMs) 361 if (current_rampup_delay_ms_ > kMaxRampUpDelayMs)
359 current_rampup_delay_ms_ = kMaxRampUpDelayMs; 362 current_rampup_delay_ms_ = kMaxRampUpDelayMs;
360 } else { 363 } else {
361 // Not currently backing off, reset rampup delay. 364 // Not currently backing off, reset rampup delay.
362 current_rampup_delay_ms_ = kStandardRampUpDelayMs; 365 current_rampup_delay_ms_ = kStandardRampUpDelayMs;
363 } 366 }
364 } 367 }
365 368
366 last_overuse_time_ = now; 369 last_overuse_time_ = now;
367 in_quick_rampup_ = false; 370 in_quick_rampup_ = false;
368 checks_above_threshold_ = 0; 371 checks_above_threshold_ = 0;
369 ++num_overuse_detections_; 372 ++num_overuse_detections_;
370 373
371 if (observer_ != NULL) 374 if (observer_ != NULL)
372 observer_->OveruseDetected(); 375 observer_->OveruseDetected();
373 } else if (IsUnderusing(now)) { 376 } else if (IsUnderusing(current_metrics, now)) {
374 last_rampup_time_ = now; 377 last_rampup_time_ = now;
375 in_quick_rampup_ = true; 378 in_quick_rampup_ = true;
376 379
377 if (observer_ != NULL) 380 if (observer_ != NULL)
378 observer_->NormalUsage(); 381 observer_->NormalUsage();
379 } 382 }
380 383
381 int rampup_delay = 384 int rampup_delay =
382 in_quick_rampup_ ? kQuickRampUpDelayMs : current_rampup_delay_ms_; 385 in_quick_rampup_ ? kQuickRampUpDelayMs : current_rampup_delay_ms_;
383 LOG(LS_VERBOSE) << " Frame stats: encode usage: " << usage_->Value() 386
387 LOG(LS_VERBOSE) << " Frame stats: "
388 << " encode usage " << current_metrics.encode_usage_percent
384 << " overuse detections " << num_overuse_detections_ 389 << " overuse detections " << num_overuse_detections_
385 << " rampup delay " << rampup_delay; 390 << " rampup delay " << rampup_delay;
386 391
387 return 0; 392 return 0;
388 } 393 }
389 394
390 bool OveruseFrameDetector::IsOverusing() { 395 bool OveruseFrameDetector::IsOverusing(const CpuOveruseMetrics& metrics) {
391 bool overusing = false; 396 bool overusing = false;
392 if (options_.enable_encode_usage_method) 397 if (options_.enable_encode_usage_method) {
393 overusing = usage_->Value() >= options_.high_encode_usage_threshold_percent; 398 overusing = metrics.encode_usage_percent >=
394 399 options_.high_encode_usage_threshold_percent;
400 }
395 if (overusing) { 401 if (overusing) {
396 ++checks_above_threshold_; 402 ++checks_above_threshold_;
397 } else { 403 } else {
398 checks_above_threshold_ = 0; 404 checks_above_threshold_ = 0;
399 } 405 }
400 return checks_above_threshold_ >= options_.high_threshold_consecutive_count; 406 return checks_above_threshold_ >= options_.high_threshold_consecutive_count;
401 } 407 }
402 408
403 bool OveruseFrameDetector::IsUnderusing(int64_t time_now) { 409 bool OveruseFrameDetector::IsUnderusing(const CpuOveruseMetrics& metrics,
410 int64_t time_now) {
404 int delay = in_quick_rampup_ ? kQuickRampUpDelayMs : current_rampup_delay_ms_; 411 int delay = in_quick_rampup_ ? kQuickRampUpDelayMs : current_rampup_delay_ms_;
405 if (time_now < last_rampup_time_ + delay) 412 if (time_now < last_rampup_time_ + delay)
406 return false; 413 return false;
407 414
408 bool underusing = false; 415 bool underusing = false;
409 if (options_.enable_encode_usage_method) 416 if (options_.enable_encode_usage_method) {
410 underusing = usage_->Value() < options_.low_encode_usage_threshold_percent; 417 underusing = metrics.encode_usage_percent <
411 418 options_.low_encode_usage_threshold_percent;
419 }
412 return underusing; 420 return underusing;
413 } 421 }
414 } // namespace webrtc 422 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/video_engine/overuse_frame_detector.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698