OLD | NEW |
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 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 int64_t diff_ms = timing.capture_ms - last_processed_capture_time_ms_; | 290 int64_t diff_ms = timing.capture_ms - last_processed_capture_time_ms_; |
291 usage_->AddSample(encode_duration_ms, diff_ms); | 291 usage_->AddSample(encode_duration_ms, diff_ms); |
292 } | 292 } |
293 last_processed_capture_time_ms_ = timing.capture_ms; | 293 last_processed_capture_time_ms_ = timing.capture_ms; |
294 EncodedFrameTimeMeasured(encode_duration_ms); | 294 EncodedFrameTimeMeasured(encode_duration_ms); |
295 } | 295 } |
296 frame_timing_.pop_front(); | 296 frame_timing_.pop_front(); |
297 } | 297 } |
298 } | 298 } |
299 | 299 |
300 int32_t OveruseFrameDetector::Process() { | 300 void OveruseFrameDetector::Process() { |
301 RTC_DCHECK(processing_thread_.CalledOnValidThread()); | 301 RTC_DCHECK(processing_thread_.CalledOnValidThread()); |
302 | 302 |
303 int64_t now = clock_->TimeInMilliseconds(); | 303 int64_t now = clock_->TimeInMilliseconds(); |
304 | 304 |
305 // Used to protect against Process() being called too often. | 305 // Used to protect against Process() being called too often. |
306 if (now < next_process_time_ms_) | 306 if (now < next_process_time_ms_) |
307 return 0; | 307 return; |
308 | 308 |
309 next_process_time_ms_ = now + kProcessIntervalMs; | 309 next_process_time_ms_ = now + kProcessIntervalMs; |
310 | 310 |
311 CpuOveruseMetrics current_metrics; | 311 CpuOveruseMetrics current_metrics; |
312 { | 312 { |
313 rtc::CritScope cs(&crit_); | 313 rtc::CritScope cs(&crit_); |
314 ++num_process_times_; | 314 ++num_process_times_; |
315 if (num_process_times_ <= options_.min_process_count || !metrics_) | 315 if (num_process_times_ <= options_.min_process_count || !metrics_) |
316 return 0; | 316 return; |
317 | 317 |
318 current_metrics = *metrics_; | 318 current_metrics = *metrics_; |
319 } | 319 } |
320 | 320 |
321 if (IsOverusing(current_metrics)) { | 321 if (IsOverusing(current_metrics)) { |
322 // If the last thing we did was going up, and now have to back down, we need | 322 // If the last thing we did was going up, and now have to back down, we need |
323 // to check if this peak was short. If so we should back off to avoid going | 323 // to check if this peak was short. If so we should back off to avoid going |
324 // back and forth between this load, the system doesn't seem to handle it. | 324 // back and forth between this load, the system doesn't seem to handle it. |
325 bool check_for_backoff = last_rampup_time_ms_ > last_overuse_time_ms_; | 325 bool check_for_backoff = last_rampup_time_ms_ > last_overuse_time_ms_; |
326 if (check_for_backoff) { | 326 if (check_for_backoff) { |
(...skipping 24 matching lines...) Expand all Loading... |
351 observer_->NormalUsage(); | 351 observer_->NormalUsage(); |
352 } | 352 } |
353 | 353 |
354 int rampup_delay = | 354 int rampup_delay = |
355 in_quick_rampup_ ? kQuickRampUpDelayMs : current_rampup_delay_ms_; | 355 in_quick_rampup_ ? kQuickRampUpDelayMs : current_rampup_delay_ms_; |
356 | 356 |
357 LOG(LS_VERBOSE) << " Frame stats: " | 357 LOG(LS_VERBOSE) << " Frame stats: " |
358 << " encode usage " << current_metrics.encode_usage_percent | 358 << " encode usage " << current_metrics.encode_usage_percent |
359 << " overuse detections " << num_overuse_detections_ | 359 << " overuse detections " << num_overuse_detections_ |
360 << " rampup delay " << rampup_delay; | 360 << " rampup delay " << rampup_delay; |
361 | |
362 return 0; | |
363 } | 361 } |
364 | 362 |
365 bool OveruseFrameDetector::IsOverusing(const CpuOveruseMetrics& metrics) { | 363 bool OveruseFrameDetector::IsOverusing(const CpuOveruseMetrics& metrics) { |
366 if (metrics.encode_usage_percent >= | 364 if (metrics.encode_usage_percent >= |
367 options_.high_encode_usage_threshold_percent) { | 365 options_.high_encode_usage_threshold_percent) { |
368 ++checks_above_threshold_; | 366 ++checks_above_threshold_; |
369 } else { | 367 } else { |
370 checks_above_threshold_ = 0; | 368 checks_above_threshold_ = 0; |
371 } | 369 } |
372 return checks_above_threshold_ >= options_.high_threshold_consecutive_count; | 370 return checks_above_threshold_ >= options_.high_threshold_consecutive_count; |
373 } | 371 } |
374 | 372 |
375 bool OveruseFrameDetector::IsUnderusing(const CpuOveruseMetrics& metrics, | 373 bool OveruseFrameDetector::IsUnderusing(const CpuOveruseMetrics& metrics, |
376 int64_t time_now) { | 374 int64_t time_now) { |
377 int delay = in_quick_rampup_ ? kQuickRampUpDelayMs : current_rampup_delay_ms_; | 375 int delay = in_quick_rampup_ ? kQuickRampUpDelayMs : current_rampup_delay_ms_; |
378 if (time_now < last_rampup_time_ms_ + delay) | 376 if (time_now < last_rampup_time_ms_ + delay) |
379 return false; | 377 return false; |
380 | 378 |
381 return metrics.encode_usage_percent < | 379 return metrics.encode_usage_percent < |
382 options_.low_encode_usage_threshold_percent; | 380 options_.low_encode_usage_threshold_percent; |
383 } | 381 } |
384 } // namespace webrtc | 382 } // namespace webrtc |
OLD | NEW |