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

Side by Side Diff: remoting/host/capture_scheduler_unittest.cc

Issue 850983002: Implement video frame acknowledgements in the chromoting protocol. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "remoting/host/capture_scheduler.h" 5 #include "remoting/host/capture_scheduler.h"
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/test/simple_test_tick_clock.h" 8 #include "base/test/simple_test_tick_clock.h"
9 #include "base/timer/mock_timer.h" 9 #include "base/timer/mock_timer.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 11
12 namespace remoting { 12 namespace remoting {
13 13
14 static const int kTestInputs[] = { 100, 50, 30, 20, 10, 30, 60, 80 }; 14 static const int kTestInputs[] = { 100, 50, 30, 20, 10, 30, 60, 80 };
15 static const int kMinumumFrameIntervalMs = 50; 15 static const int kMinumumFrameIntervalMs = 50;
16 16
17 class CaptureSchedulerTest : public testing::Test { 17 class CaptureSchedulerTest : public testing::Test {
18 public: 18 public:
19 CaptureSchedulerTest() : capture_called_(false) {} 19 CaptureSchedulerTest() : capture_called_(false) {}
20 20
21 void InitScheduler() { 21 void InitScheduler(bool acks_supported) {
22 scheduler_.reset(new CaptureScheduler( 22 scheduler_.reset(new CaptureScheduler(
23 base::Bind(&CaptureSchedulerTest::DoCapture, base::Unretained(this)))); 23 base::Bind(&CaptureSchedulerTest::DoCapture, base::Unretained(this)),
24 acks_supported));
24 scheduler_->set_minimum_interval( 25 scheduler_->set_minimum_interval(
25 base::TimeDelta::FromMilliseconds(kMinumumFrameIntervalMs)); 26 base::TimeDelta::FromMilliseconds(kMinumumFrameIntervalMs));
26 tick_clock_ = new base::SimpleTestTickClock(); 27 tick_clock_ = new base::SimpleTestTickClock();
27 scheduler_->set_tick_clock_for_tests(make_scoped_ptr(tick_clock_)); 28 scheduler_->set_tick_clock_for_tests(make_scoped_ptr(tick_clock_));
28 capture_timer_ = new base::MockTimer(false, false); 29 capture_timer_ = new base::MockTimer(false, false);
29 scheduler_->set_timer_for_tests(make_scoped_ptr(capture_timer_)); 30 scheduler_->set_timer_for_tests(make_scoped_ptr(capture_timer_));
30 scheduler_->Start(); 31 scheduler_->Start();
31 } 32 }
32 33
33 void DoCapture() { 34 void DoCapture() {
34 capture_called_ = true; 35 capture_called_ = true;
35 } 36 }
36 37
37 void CheckCaptureCalled() { 38 void CheckCaptureCalled() {
38 EXPECT_TRUE(capture_called_); 39 EXPECT_TRUE(capture_called_);
39 capture_called_ = false; 40 capture_called_ = false;
40 } 41 }
41 42
42 void SimulateSingleFrameCapture( 43 void SimulateSingleFrameCapture(
43 base::TimeDelta capture_delay, 44 base::TimeDelta capture_delay,
44 base::TimeDelta encode_delay, 45 base::TimeDelta encode_delay,
45 base::TimeDelta expected_delay_between_frames) { 46 base::TimeDelta expected_delay_between_frames) {
46 capture_timer_->Fire(); 47 capture_timer_->Fire();
47 CheckCaptureCalled(); 48 CheckCaptureCalled();
48 tick_clock_->Advance(capture_delay); 49 tick_clock_->Advance(capture_delay);
49 scheduler_->OnCaptureCompleted(); 50 scheduler_->OnCaptureCompleted();
50 scheduler_->OnFrameEncoded(encode_delay); 51 scheduler_->OnFrameEncoded(encode_delay);
51 scheduler_->OnFrameSent(); 52 scheduler_->OnFrameSent();
53 scheduler_->OnFrameAck();
52 54
53 EXPECT_TRUE(capture_timer_->IsRunning()); 55 EXPECT_TRUE(capture_timer_->IsRunning());
54 EXPECT_EQ(std::max(base::TimeDelta(), 56 EXPECT_EQ(std::max(base::TimeDelta(),
55 expected_delay_between_frames - capture_delay), 57 expected_delay_between_frames - capture_delay),
56 capture_timer_->GetCurrentDelay()); 58 capture_timer_->GetCurrentDelay());
57 } 59 }
58 60
59 protected: 61 protected:
60 base::MessageLoop message_loop_; 62 base::MessageLoop message_loop_;
61 63
62 scoped_ptr<CaptureScheduler> scheduler_; 64 scoped_ptr<CaptureScheduler> scheduler_;
63 65
64 // Owned by |scheduler_|. 66 // Owned by |scheduler_|.
65 base::SimpleTestTickClock* tick_clock_; 67 base::SimpleTestTickClock* tick_clock_;
66 base::MockTimer* capture_timer_; 68 base::MockTimer* capture_timer_;
67 69
68 bool capture_called_; 70 bool capture_called_;
69 }; 71 };
70 72
71 TEST_F(CaptureSchedulerTest, SingleSampleSameTimes) { 73 TEST_F(CaptureSchedulerTest, SingleSampleSameTimes) {
72 const int kTestResults[][arraysize(kTestInputs)] = { 74 const int kTestResults[][arraysize(kTestInputs)] = {
73 { 400, 200, 120, 80, 50, 120, 240, 320 }, // One core. 75 { 400, 200, 120, 80, 50, 120, 240, 320 }, // One core.
74 { 200, 100, 60, 50, 50, 60, 120, 160 }, // Two cores. 76 { 200, 100, 60, 50, 50, 60, 120, 160 }, // Two cores.
75 { 100, 50, 50, 50, 50, 50, 60, 80 }, // Four cores. 77 { 100, 50, 50, 50, 50, 50, 60, 80 }, // Four cores.
76 { 50, 50, 50, 50, 50, 50, 50, 50 } // Eight cores. 78 { 50, 50, 50, 50, 50, 50, 50, 50 } // Eight cores.
77 }; 79 };
78 80
79 for (size_t i = 0; i < arraysize(kTestResults); ++i) { 81 for (size_t i = 0; i < arraysize(kTestResults); ++i) {
80 for (size_t j = 0; j < arraysize(kTestInputs); ++j) { 82 for (size_t j = 0; j < arraysize(kTestInputs); ++j) {
81 InitScheduler(); 83 InitScheduler(true);
82 scheduler_->set_num_of_processors_for_tests(1 << i); 84 scheduler_->set_num_of_processors_for_tests(1 << i);
83 85
84 SimulateSingleFrameCapture( 86 SimulateSingleFrameCapture(
85 base::TimeDelta::FromMilliseconds(kTestInputs[j]), 87 base::TimeDelta::FromMilliseconds(kTestInputs[j]),
86 base::TimeDelta::FromMilliseconds(kTestInputs[j]), 88 base::TimeDelta::FromMilliseconds(kTestInputs[j]),
87 base::TimeDelta::FromMilliseconds(kTestResults[i][j])); 89 base::TimeDelta::FromMilliseconds(kTestResults[i][j]));
88 } 90 }
89 } 91 }
90 } 92 }
91 93
92 TEST_F(CaptureSchedulerTest, SingleSampleDifferentTimes) { 94 TEST_F(CaptureSchedulerTest, SingleSampleDifferentTimes) {
93 const int kTestResults[][arraysize(kTestInputs)] = { 95 const int kTestResults[][arraysize(kTestInputs)] = {
94 { 360, 220, 120, 60, 60, 120, 220, 360 }, // One core. 96 { 360, 220, 120, 60, 60, 120, 220, 360 }, // One core.
95 { 180, 110, 60, 50, 50, 60, 110, 180 }, // Two cores. 97 { 180, 110, 60, 50, 50, 60, 110, 180 }, // Two cores.
96 { 90, 55, 50, 50, 50, 50, 55, 90 }, // Four cores. 98 { 90, 55, 50, 50, 50, 50, 55, 90 }, // Four cores.
97 { 50, 50, 50, 50, 50, 50, 50, 50 } // Eight cores. 99 { 50, 50, 50, 50, 50, 50, 50, 50 } // Eight cores.
98 }; 100 };
99 101
100 for (size_t i = 0; i < arraysize(kTestResults); ++i) { 102 for (size_t i = 0; i < arraysize(kTestResults); ++i) {
101 for (size_t j = 0; j < arraysize(kTestInputs); ++j) { 103 for (size_t j = 0; j < arraysize(kTestInputs); ++j) {
102 InitScheduler(); 104 InitScheduler(true);
103 scheduler_->set_num_of_processors_for_tests(1 << i); 105 scheduler_->set_num_of_processors_for_tests(1 << i);
104 106
105 SimulateSingleFrameCapture( 107 SimulateSingleFrameCapture(
106 base::TimeDelta::FromMilliseconds(kTestInputs[j]), 108 base::TimeDelta::FromMilliseconds(kTestInputs[j]),
107 base::TimeDelta::FromMilliseconds( 109 base::TimeDelta::FromMilliseconds(
108 kTestInputs[arraysize(kTestInputs) - 1 - j]), 110 kTestInputs[arraysize(kTestInputs) - 1 - j]),
109 base::TimeDelta::FromMilliseconds(kTestResults[i][j])); 111 base::TimeDelta::FromMilliseconds(kTestResults[i][j]));
110 } 112 }
111 } 113 }
112 } 114 }
113 115
114 TEST_F(CaptureSchedulerTest, RollingAverageDifferentTimes) { 116 TEST_F(CaptureSchedulerTest, RollingAverageDifferentTimes) {
115 const int kTestResults[][arraysize(kTestInputs)] = { 117 const int kTestResults[][arraysize(kTestInputs)] = {
116 { 360, 290, 233, 133, 80, 80, 133, 233 }, // One core. 118 { 360, 290, 233, 133, 80, 80, 133, 233 }, // One core.
117 { 180, 145, 116, 66, 50, 50, 66, 116 }, // Two cores. 119 { 180, 145, 116, 66, 50, 50, 66, 116 }, // Two cores.
118 { 90, 72, 58, 50, 50, 50, 50, 58 }, // Four cores. 120 { 90, 72, 58, 50, 50, 50, 50, 58 }, // Four cores.
119 { 50, 50, 50, 50, 50, 50, 50, 50 } // Eight cores. 121 { 50, 50, 50, 50, 50, 50, 50, 50 } // Eight cores.
120 }; 122 };
121 123
122 for (size_t i = 0; i < arraysize(kTestResults); ++i) { 124 for (size_t i = 0; i < arraysize(kTestResults); ++i) {
123 InitScheduler(); 125 InitScheduler(true);
124 scheduler_->set_num_of_processors_for_tests(1 << i); 126 scheduler_->set_num_of_processors_for_tests(1 << i);
125 for (size_t j = 0; j < arraysize(kTestInputs); ++j) { 127 for (size_t j = 0; j < arraysize(kTestInputs); ++j) {
126 SimulateSingleFrameCapture( 128 SimulateSingleFrameCapture(
127 base::TimeDelta::FromMilliseconds(kTestInputs[j]), 129 base::TimeDelta::FromMilliseconds(kTestInputs[j]),
128 base::TimeDelta::FromMilliseconds( 130 base::TimeDelta::FromMilliseconds(
129 kTestInputs[arraysize(kTestInputs) - 1 - j]), 131 kTestInputs[arraysize(kTestInputs) - 1 - j]),
130 base::TimeDelta::FromMilliseconds(kTestResults[i][j])); 132 base::TimeDelta::FromMilliseconds(kTestResults[i][j]));
131 } 133 }
132 } 134 }
133 } 135 }
134 136
135 // Verify that we never have more than 2 pending frames. 137 // Verify that we never have more than 2 encoding frames.
136 TEST_F(CaptureSchedulerTest, MaximumPendingFrames) { 138 TEST_F(CaptureSchedulerTest, MaximumEncodingFrames) {
137 InitScheduler(); 139 InitScheduler(true);
138 140
139 capture_timer_->Fire(); 141 capture_timer_->Fire();
140 CheckCaptureCalled(); 142 CheckCaptureCalled();
141 scheduler_->OnCaptureCompleted(); 143 scheduler_->OnCaptureCompleted();
142 144
143 capture_timer_->Fire(); 145 capture_timer_->Fire();
144 CheckCaptureCalled(); 146 CheckCaptureCalled();
145 scheduler_->OnCaptureCompleted(); 147 scheduler_->OnCaptureCompleted();
146 148
147 EXPECT_FALSE(capture_timer_->IsRunning()); 149 EXPECT_FALSE(capture_timer_->IsRunning());
148
149 scheduler_->OnFrameEncoded(base::TimeDelta()); 150 scheduler_->OnFrameEncoded(base::TimeDelta());
150 scheduler_->OnFrameSent();
151
152 EXPECT_TRUE(capture_timer_->IsRunning()); 151 EXPECT_TRUE(capture_timer_->IsRunning());
153 } 152 }
154 153
154 // Verify that the scheduler doesn't exceed maximum number of pending frames.
155 TEST_F(CaptureSchedulerTest, MaximumPendingFrames) {
156 InitScheduler(true);
157
158 scheduler_->set_maximum_pending_frames(2);
159
160 capture_timer_->Fire();
161 CheckCaptureCalled();
162 scheduler_->OnCaptureCompleted();
163 scheduler_->OnFrameEncoded(base::TimeDelta());
164
165 capture_timer_->Fire();
Wez 2015/02/03 00:54:32 Should you be checking that the timer is running b
Sergey Ulanov 2015/02/09 19:14:54 No. MockTimer::Fire() DCHECKs if the timer is not
166 CheckCaptureCalled();
167 scheduler_->OnCaptureCompleted();
168 scheduler_->OnFrameEncoded(base::TimeDelta());
169
170 EXPECT_FALSE(capture_timer_->IsRunning());
171 scheduler_->OnFrameSent();
172 EXPECT_FALSE(capture_timer_->IsRunning());
173 scheduler_->OnFrameAck();
174 EXPECT_TRUE(capture_timer_->IsRunning());
175 }
176
177 // Verify that the scheduler doesn't exceed maximum number of pending frames
178 // when acks are not supported.
179 TEST_F(CaptureSchedulerTest, MaximumPendingFramesNoAcks) {
180 InitScheduler(false);
181
182 scheduler_->set_maximum_pending_frames(2);
183
184 capture_timer_->Fire();
185 CheckCaptureCalled();
186 scheduler_->OnCaptureCompleted();
187 scheduler_->OnFrameEncoded(base::TimeDelta());
188
189 capture_timer_->Fire();
190 CheckCaptureCalled();
191 scheduler_->OnCaptureCompleted();
192 scheduler_->OnFrameEncoded(base::TimeDelta());
193
194 EXPECT_FALSE(capture_timer_->IsRunning());
195 scheduler_->OnFrameSent();
196 EXPECT_TRUE(capture_timer_->IsRunning());
197 }
155 } // namespace remoting 198 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698