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

Unified Diff: remoting/host/capture_scheduler.cc

Issue 8342040: Gather history of capture and encode time determine next recoring delay (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: done Created 9 years, 2 months 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 side-by-side diff with in-line comments
Download patch
Index: remoting/host/capture_scheduler.cc
diff --git a/remoting/host/capture_scheduler.cc b/remoting/host/capture_scheduler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ba26a6f3ffd12e2b8033163b34aeb6ca0431880f
--- /dev/null
+++ b/remoting/host/capture_scheduler.cc
@@ -0,0 +1,62 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "remoting/host/capture_scheduler.h"
+
+#include <algorithm>
+
+#include "base/logging.h"
+#include "base/sys_info.h"
+#include "base/time.h"
+
+namespace {
+
+// Window for averaging statistics on encode and capture time.
+// This constant controls how many recorded instances are averaged.
Wez 2011/10/25 00:05:37 Please word this more clearly. Intuitively one wo
Alpha Left Google 2011/10/31 18:47:24 Done.
+const int kStatisticsWindow = 3;
Wez 2011/10/25 00:05:37 Why average over three previous samples? Why not
Alpha Left Google 2011/10/31 18:47:24 My intention is to have a relatively steady frame
+
+// The hard limit is 20fps or 50ms per recording cycle.
+const int64 kMinimumRecordingDelay = 50;
Wez 2011/10/25 00:05:37 This still seems unnecessarily low, given that thi
Alpha Left Google 2011/10/31 18:47:24 You have a different opinion than Sergey here, he
Wez 2011/10/31 22:05:53 Sorry, I meant that this value would lead to a low
+
+// Controls how much CPU time we can use for encode and capture.
+// This is capped at 50%.
Wez 2011/10/25 00:05:37 I'd suggest rewording to comment to something desc
Alpha Left Google 2011/10/31 18:47:24 Yes it's a ratio across all corres already.
+const double kRecordingCpuConsumption = 0.5;
+
+} // namespace
+
+namespace remoting {
+
+CaptureScheduler::CaptureScheduler()
+ : num_of_processors_(base::SysInfo::NumberOfProcessors()),
Wez 2011/10/25 00:05:37 nit: This means we don't cope properly with dynami
Alpha Left Google 2011/10/31 18:47:24 Done.
+ capture_time_(kStatisticsWindow),
+ encode_time_(kStatisticsWindow) {
+ DCHECK(num_of_processors_);
+}
+
+CaptureScheduler::~CaptureScheduler() {
+}
+
+base::TimeDelta CaptureScheduler::NextCaptureDelay() {
+ // The algorithm only uses CPU time spent in capture, encode and
Wez 2011/10/25 00:05:37 typo: "... capture, encode and..." -> "... capture
+ // number of processors to determine next capture time.
Wez 2011/10/25 00:05:37 nit: processors -> cores? nit: "determine next cap
Alpha Left Google 2011/10/31 18:47:24 I think we should follow the naming of base::SysIn
+ // We want to make sure time spent in capture and encode doesn't
+ // exceed a predefined value, i.e. kRecordingCpuConsumption.
Wez 2011/10/25 00:05:37 nit: This comment seems to reiterate the basic fun
Alpha Left Google 2011/10/31 18:47:24 Done.
+ double delay =
+ (capture_time_.Average() + encode_time_.Average()) /
Wez 2011/10/25 00:05:38 Note that the encode time will vary considerably d
+ kRecordingCpuConsumption / num_of_processors_;
Wez 2011/10/25 00:05:38 It's clearer to write this formula as: delay =
Alpha Left Google 2011/10/31 18:47:24 Done.
+
+ if (delay < kMinimumRecordingDelay)
+ return base::TimeDelta::FromMilliseconds(kMinimumRecordingDelay);
+ return base::TimeDelta::FromMilliseconds(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());
+}
+
+} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698