| 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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 num_overuse_detections_(0), | 207 num_overuse_detections_(0), |
| 208 last_rampup_time_(0), | 208 last_rampup_time_(0), |
| 209 in_quick_rampup_(false), | 209 in_quick_rampup_(false), |
| 210 current_rampup_delay_ms_(kStandardRampUpDelayMs), | 210 current_rampup_delay_ms_(kStandardRampUpDelayMs), |
| 211 num_pixels_(0), | 211 num_pixels_(0), |
| 212 last_encode_sample_ms_(0), | 212 last_encode_sample_ms_(0), |
| 213 encode_time_(new EncodeTimeAvg()), | 213 encode_time_(new EncodeTimeAvg()), |
| 214 usage_(new SendProcessingUsage(options)), | 214 usage_(new SendProcessingUsage(options)), |
| 215 frame_queue_(new FrameQueue()), | 215 frame_queue_(new FrameQueue()), |
| 216 last_sample_time_ms_(0) { | 216 last_sample_time_ms_(0) { |
| 217 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 } |
| 227 | 227 |
| 228 int OveruseFrameDetector::LastProcessingTimeMs() const { | 228 int OveruseFrameDetector::LastProcessingTimeMs() const { |
| 229 rtc::CritScope cs(&crit_); | 229 rtc::CritScope cs(&crit_); |
| 230 return frame_queue_->last_processing_time_ms(); | 230 return frame_queue_->last_processing_time_ms(); |
| 231 } | 231 } |
| 232 | 232 |
| 233 int OveruseFrameDetector::FramesInQueue() const { | 233 int OveruseFrameDetector::FramesInQueue() const { |
| 234 rtc::CritScope cs(&crit_); | 234 rtc::CritScope cs(&crit_); |
| 235 return frame_queue_->NumFrames(); | 235 return frame_queue_->NumFrames(); |
| 236 } | 236 } |
| 237 | 237 |
| 238 void OveruseFrameDetector::UpdateCpuOveruseMetrics() { | 238 void OveruseFrameDetector::UpdateCpuOveruseMetrics() { |
| 239 metrics_.avg_encode_time_ms = encode_time_->Value(); | 239 metrics_.avg_encode_time_ms = encode_time_->Value(); |
| 240 metrics_.encode_usage_percent = usage_->Value(); | 240 metrics_.encode_usage_percent = usage_->Value(); |
| 241 | 241 |
| 242 metrics_observer_->CpuOveruseMetricsUpdated(metrics_); | 242 metrics_observer_->CpuOveruseMetricsUpdated(metrics_); |
| 243 } | 243 } |
| 244 | 244 |
| 245 int64_t OveruseFrameDetector::TimeUntilNextProcess() { | 245 int64_t OveruseFrameDetector::TimeUntilNextProcess() { |
| 246 DCHECK(processing_thread_.CalledOnValidThread()); | 246 RTC_DCHECK(processing_thread_.CalledOnValidThread()); |
| 247 return next_process_time_ - clock_->TimeInMilliseconds(); | 247 return next_process_time_ - clock_->TimeInMilliseconds(); |
| 248 } | 248 } |
| 249 | 249 |
| 250 bool OveruseFrameDetector::FrameSizeChanged(int num_pixels) const { | 250 bool OveruseFrameDetector::FrameSizeChanged(int num_pixels) const { |
| 251 if (num_pixels != num_pixels_) { | 251 if (num_pixels != num_pixels_) { |
| 252 return true; | 252 return true; |
| 253 } | 253 } |
| 254 return false; | 254 return false; |
| 255 } | 255 } |
| 256 | 256 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 void OveruseFrameDetector::AddProcessingTime(int elapsed_ms) { | 321 void OveruseFrameDetector::AddProcessingTime(int elapsed_ms) { |
| 322 int64_t now = clock_->TimeInMilliseconds(); | 322 int64_t now = clock_->TimeInMilliseconds(); |
| 323 if (last_sample_time_ms_ != 0) { | 323 if (last_sample_time_ms_ != 0) { |
| 324 int64_t diff_ms = now - last_sample_time_ms_; | 324 int64_t diff_ms = now - last_sample_time_ms_; |
| 325 usage_->AddSample(elapsed_ms, diff_ms); | 325 usage_->AddSample(elapsed_ms, diff_ms); |
| 326 } | 326 } |
| 327 last_sample_time_ms_ = now; | 327 last_sample_time_ms_ = now; |
| 328 } | 328 } |
| 329 | 329 |
| 330 int32_t OveruseFrameDetector::Process() { | 330 int32_t OveruseFrameDetector::Process() { |
| 331 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 rtc::CritScope cs(&crit_); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 if (time_now < last_rampup_time_ + delay) | 405 if (time_now < last_rampup_time_ + delay) |
| 406 return false; | 406 return false; |
| 407 | 407 |
| 408 bool underusing = false; | 408 bool underusing = false; |
| 409 if (options_.enable_encode_usage_method) | 409 if (options_.enable_encode_usage_method) |
| 410 underusing = usage_->Value() < options_.low_encode_usage_threshold_percent; | 410 underusing = usage_->Value() < options_.low_encode_usage_threshold_percent; |
| 411 | 411 |
| 412 return underusing; | 412 return underusing; |
| 413 } | 413 } |
| 414 } // namespace webrtc | 414 } // namespace webrtc |
| OLD | NEW |