This source file includes following definitions.
- encode_time_
- NextCaptureDelay
- RecordCaptureTime
- RecordEncodeTime
- SetNumOfProcessorsForTest
#include "remoting/host/capture_scheduler.h"
#include <algorithm>
#include "base/logging.h"
#include "base/sys_info.h"
#include "base/time/time.h"
namespace {
const int kStatisticsWindow = 3;
const int64 kDefaultMinimumIntervalMs = 33;
const double kRecordingCpuConsumption = 0.5;
}
namespace remoting {
CaptureScheduler::CaptureScheduler()
: minimum_interval_(
base::TimeDelta::FromMilliseconds(kDefaultMinimumIntervalMs)),
num_of_processors_(base::SysInfo::NumberOfProcessors()),
capture_time_(kStatisticsWindow),
encode_time_(kStatisticsWindow) {
DCHECK(num_of_processors_);
}
CaptureScheduler::~CaptureScheduler() {
}
base::TimeDelta CaptureScheduler::NextCaptureDelay() {
base::TimeDelta delay = base::TimeDelta::FromMilliseconds(
(capture_time_.Average() + encode_time_.Average()) /
(kRecordingCpuConsumption * num_of_processors_));
if (delay < minimum_interval_)
return minimum_interval_;
return delay;
}
void CaptureScheduler::RecordCaptureTime(base::TimeDelta capture_time) {
capture_time_.Record(capture_time.InMilliseconds());
}
void CaptureScheduler::RecordEncodeTime(base::TimeDelta encode_time) {
encode_time_.Record(encode_time.InMilliseconds());
}
void CaptureScheduler::SetNumOfProcessorsForTest(int num_of_processors) {
num_of_processors_ = num_of_processors;
}
}