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

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

Issue 1278383002: Remove avg encode time from CpuOveruseMetric struct and use value from OnEncodedFrame instead. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years 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
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 26 matching lines...) Expand all
37 37
38 // Max number of overuses detected before always applying the rampup delay. 38 // Max number of overuses detected before always applying the rampup delay.
39 const int kMaxOverusesBeforeApplyRampupDelay = 4; 39 const int kMaxOverusesBeforeApplyRampupDelay = 4;
40 40
41 // The maximum exponent to use in VCMExpFilter. 41 // The maximum exponent to use in VCMExpFilter.
42 const float kSampleDiffMs = 33.0f; 42 const float kSampleDiffMs = 33.0f;
43 const float kMaxExp = 7.0f; 43 const float kMaxExp = 7.0f;
44 44
45 } // namespace 45 } // namespace
46 46
47 // Class for calculating the average encode time.
48 class OveruseFrameDetector::EncodeTimeAvg {
49 public:
50 EncodeTimeAvg()
51 : kWeightFactor(0.5f),
52 kInitialAvgEncodeTimeMs(5.0f),
53 filtered_encode_time_ms_(new rtc::ExpFilter(kWeightFactor)) {
54 filtered_encode_time_ms_->Apply(1.0f, kInitialAvgEncodeTimeMs);
55 }
56 ~EncodeTimeAvg() {}
57
58 void AddSample(float encode_time_ms, int64_t diff_last_sample_ms) {
59 float exp = diff_last_sample_ms / kSampleDiffMs;
60 exp = std::min(exp, kMaxExp);
61 filtered_encode_time_ms_->Apply(exp, encode_time_ms);
62 }
63
64 int Value() const {
65 return static_cast<int>(filtered_encode_time_ms_->filtered() + 0.5);
66 }
67
68 private:
69 const float kWeightFactor;
70 const float kInitialAvgEncodeTimeMs;
71 rtc::scoped_ptr<rtc::ExpFilter> filtered_encode_time_ms_;
72 };
73
74 // Class for calculating the processing usage on the send-side (the average 47 // Class for calculating the processing usage on the send-side (the average
75 // processing time of a frame divided by the average time difference between 48 // processing time of a frame divided by the average time difference between
76 // captured frames). 49 // captured frames).
77 class OveruseFrameDetector::SendProcessingUsage { 50 class OveruseFrameDetector::SendProcessingUsage {
78 public: 51 public:
79 explicit SendProcessingUsage(const CpuOveruseOptions& options) 52 explicit SendProcessingUsage(const CpuOveruseOptions& options)
80 : kWeightFactorFrameDiff(0.998f), 53 : kWeightFactorFrameDiff(0.998f),
81 kWeightFactorProcessing(0.995f), 54 kWeightFactorProcessing(0.995f),
82 kInitialSampleDiffMs(40.0f), 55 kInitialSampleDiffMs(40.0f),
83 kMaxSampleDiffMs(45.0f), 56 kMaxSampleDiffMs(45.0f),
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 num_process_times_(0), 175 num_process_times_(0),
203 last_capture_time_(0), 176 last_capture_time_(0),
204 num_pixels_(0), 177 num_pixels_(0),
205 next_process_time_(clock_->TimeInMilliseconds()), 178 next_process_time_(clock_->TimeInMilliseconds()),
206 last_overuse_time_(0), 179 last_overuse_time_(0),
207 checks_above_threshold_(0), 180 checks_above_threshold_(0),
208 num_overuse_detections_(0), 181 num_overuse_detections_(0),
209 last_rampup_time_(0), 182 last_rampup_time_(0),
210 in_quick_rampup_(false), 183 in_quick_rampup_(false),
211 current_rampup_delay_ms_(kStandardRampUpDelayMs), 184 current_rampup_delay_ms_(kStandardRampUpDelayMs),
212 last_encode_sample_ms_(0),
213 last_sample_time_ms_(0), 185 last_sample_time_ms_(0),
214 encode_time_(new EncodeTimeAvg()),
215 usage_(new SendProcessingUsage(options)), 186 usage_(new SendProcessingUsage(options)),
216 frame_queue_(new FrameQueue()) { 187 frame_queue_(new FrameQueue()) {
217 RTC_DCHECK(metrics_observer != nullptr); 188 RTC_DCHECK(metrics_observer != nullptr);
218 // Make sure stats are initially up-to-date. This simplifies unit testing 189 // 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 190 // since we don't have to trigger an update using one of the methods which
220 // would also alter the overuse state. 191 // would also alter the overuse state.
221 UpdateCpuOveruseMetrics(); 192 UpdateCpuOveruseMetrics();
222 processing_thread_.DetachFromThread(); 193 processing_thread_.DetachFromThread();
223 } 194 }
224 195
225 OveruseFrameDetector::~OveruseFrameDetector() { 196 OveruseFrameDetector::~OveruseFrameDetector() {
226 } 197 }
227 198
228 int OveruseFrameDetector::LastProcessingTimeMs() const { 199 int OveruseFrameDetector::LastProcessingTimeMs() const {
229 rtc::CritScope cs(&crit_); 200 rtc::CritScope cs(&crit_);
230 return frame_queue_->last_processing_time_ms(); 201 return frame_queue_->last_processing_time_ms();
231 } 202 }
232 203
233 int OveruseFrameDetector::FramesInQueue() const { 204 int OveruseFrameDetector::FramesInQueue() const {
234 rtc::CritScope cs(&crit_); 205 rtc::CritScope cs(&crit_);
235 return frame_queue_->NumFrames(); 206 return frame_queue_->NumFrames();
236 } 207 }
237 208
238 void OveruseFrameDetector::UpdateCpuOveruseMetrics() { 209 void OveruseFrameDetector::UpdateCpuOveruseMetrics() {
239 metrics_.avg_encode_time_ms = encode_time_->Value();
240 metrics_.encode_usage_percent = usage_->Value(); 210 metrics_.encode_usage_percent = usage_->Value();
241 211
242 metrics_observer_->CpuOveruseMetricsUpdated(metrics_); 212 metrics_observer_->CpuOveruseMetricsUpdated(metrics_);
243 } 213 }
244 214
245 int64_t OveruseFrameDetector::TimeUntilNextProcess() { 215 int64_t OveruseFrameDetector::TimeUntilNextProcess() {
246 RTC_DCHECK(processing_thread_.CalledOnValidThread()); 216 RTC_DCHECK(processing_thread_.CalledOnValidThread());
247 return next_process_time_ - clock_->TimeInMilliseconds(); 217 return next_process_time_ - clock_->TimeInMilliseconds();
248 } 218 }
249 219
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 usage_->AddCaptureSample(now - last_capture_time_); 254 usage_->AddCaptureSample(now - last_capture_time_);
285 255
286 last_capture_time_ = now; 256 last_capture_time_ = now;
287 257
288 if (options_.enable_extended_processing_usage) { 258 if (options_.enable_extended_processing_usage) {
289 frame_queue_->Start(capture_time_ms, now); 259 frame_queue_->Start(capture_time_ms, now);
290 } 260 }
291 } 261 }
292 262
293 void OveruseFrameDetector::FrameEncoded(int encode_time_ms) { 263 void OveruseFrameDetector::FrameEncoded(int encode_time_ms) {
264 if (options_.enable_extended_processing_usage)
265 return;
266
294 rtc::CritScope cs(&crit_); 267 rtc::CritScope cs(&crit_);
295 int64_t now = clock_->TimeInMilliseconds(); 268 AddProcessingTime(encode_time_ms);
296 if (last_encode_sample_ms_ != 0) {
297 int64_t diff_ms = now - last_encode_sample_ms_;
298 encode_time_->AddSample(encode_time_ms, diff_ms);
299 }
300 last_encode_sample_ms_ = now;
301
302 if (!options_.enable_extended_processing_usage) {
303 AddProcessingTime(encode_time_ms);
304 }
305 UpdateCpuOveruseMetrics();
306 } 269 }
307 270
308 void OveruseFrameDetector::FrameSent(int64_t capture_time_ms) { 271 void OveruseFrameDetector::FrameSent(int64_t capture_time_ms) {
272 if (!options_.enable_extended_processing_usage)
273 return;
274
309 rtc::CritScope cs(&crit_); 275 rtc::CritScope cs(&crit_);
310 if (!options_.enable_extended_processing_usage) {
311 return;
312 }
313 int delay_ms = frame_queue_->End(capture_time_ms, 276 int delay_ms = frame_queue_->End(capture_time_ms,
314 clock_->TimeInMilliseconds()); 277 clock_->TimeInMilliseconds());
315 if (delay_ms > 0) { 278 if (delay_ms > 0) {
316 AddProcessingTime(delay_ms); 279 AddProcessingTime(delay_ms);
317 } 280 }
318 UpdateCpuOveruseMetrics();
319 } 281 }
320 282
321 void OveruseFrameDetector::AddProcessingTime(int elapsed_ms) { 283 void OveruseFrameDetector::AddProcessingTime(int elapsed_ms) {
322 int64_t now = clock_->TimeInMilliseconds(); 284 int64_t now = clock_->TimeInMilliseconds();
323 if (last_sample_time_ms_ != 0) { 285 if (last_sample_time_ms_ != 0) {
324 int64_t diff_ms = now - last_sample_time_ms_; 286 int64_t diff_ms = now - last_sample_time_ms_;
325 usage_->AddSample(elapsed_ms, diff_ms); 287 usage_->AddSample(elapsed_ms, diff_ms);
326 } 288 }
327 last_sample_time_ms_ = now; 289 last_sample_time_ms_ = now;
290 UpdateCpuOveruseMetrics();
328 } 291 }
329 292
330 int32_t OveruseFrameDetector::Process() { 293 int32_t OveruseFrameDetector::Process() {
331 RTC_DCHECK(processing_thread_.CalledOnValidThread()); 294 RTC_DCHECK(processing_thread_.CalledOnValidThread());
332 295
333 int64_t now = clock_->TimeInMilliseconds(); 296 int64_t now = clock_->TimeInMilliseconds();
334 297
335 // Used to protect against Process() being called too often. 298 // Used to protect against Process() being called too often.
336 if (now < next_process_time_) 299 if (now < next_process_time_)
337 return 0; 300 return 0;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 return false; 376 return false;
414 377
415 bool underusing = false; 378 bool underusing = false;
416 if (options_.enable_encode_usage_method) { 379 if (options_.enable_encode_usage_method) {
417 underusing = metrics.encode_usage_percent < 380 underusing = metrics.encode_usage_percent <
418 options_.low_encode_usage_threshold_percent; 381 options_.low_encode_usage_threshold_percent;
419 } 382 }
420 return underusing; 383 return underusing;
421 } 384 }
422 } // namespace webrtc 385 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698