Revert of Report viewport memory and timing correctly for Slimming Paint. (patchset...
[chromium-blink-merge.git] / remoting / host / capture_scheduler.cc
blobc6b3be0a1d23fd87759d1cf4cddf39d7b303cb82
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "remoting/host/capture_scheduler.h"
7 #include <algorithm>
9 #include "base/logging.h"
10 #include "base/sys_info.h"
11 #include "base/time/time.h"
13 namespace {
15 // Number of samples to average the most recent capture and encode time
16 // over.
17 const int kStatisticsWindow = 3;
19 // The hard limit is 30fps or 33ms per recording cycle.
20 const int64 kDefaultMinimumIntervalMs = 33;
22 // Controls how much CPU time we can use for encode and capture.
23 // Range of this value is between 0 to 1. 0 means using 0% of of all CPUs
24 // available while 1 means using 100% of all CPUs available.
25 const double kRecordingCpuConsumption = 0.5;
27 } // namespace
29 namespace remoting {
31 // We assume that the number of available cores is constant.
32 CaptureScheduler::CaptureScheduler()
33 : minimum_interval_(
34 base::TimeDelta::FromMilliseconds(kDefaultMinimumIntervalMs)),
35 num_of_processors_(base::SysInfo::NumberOfProcessors()),
36 capture_time_(kStatisticsWindow),
37 encode_time_(kStatisticsWindow) {
38 DCHECK(num_of_processors_);
41 CaptureScheduler::~CaptureScheduler() {
44 base::TimeDelta CaptureScheduler::NextCaptureDelay() {
45 // Delay by an amount chosen such that if capture and encode times
46 // continue to follow the averages, then we'll consume the target
47 // fraction of CPU across all cores.
48 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(
49 (capture_time_.Average() + encode_time_.Average()) /
50 (kRecordingCpuConsumption * num_of_processors_));
52 if (delay < minimum_interval_)
53 return minimum_interval_;
54 return delay;
57 void CaptureScheduler::RecordCaptureTime(base::TimeDelta capture_time) {
58 capture_time_.Record(capture_time.InMilliseconds());
61 void CaptureScheduler::RecordEncodeTime(base::TimeDelta encode_time) {
62 encode_time_.Record(encode_time.InMilliseconds());
65 void CaptureScheduler::SetNumOfProcessorsForTest(int num_of_processors) {
66 num_of_processors_ = num_of_processors;
69 } // namespace remoting