OLD | NEW |
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 "remoting/proto/video.pb.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
11 | 12 |
12 namespace remoting { | 13 namespace remoting { |
13 | 14 |
14 static const int kTestInputs[] = { 100, 50, 30, 20, 10, 30, 60, 80 }; | 15 static const int kTestInputs[] = { 100, 50, 30, 20, 10, 30, 60, 80 }; |
15 static const int kMinumumFrameIntervalMs = 50; | 16 static const int kMinumumFrameIntervalMs = 50; |
16 | 17 |
17 class CaptureSchedulerTest : public testing::Test { | 18 class CaptureSchedulerTest : public testing::Test { |
18 public: | 19 public: |
19 CaptureSchedulerTest() : capture_called_(false) {} | 20 CaptureSchedulerTest() : capture_called_(false) {} |
(...skipping 20 matching lines...) Expand all Loading... |
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 |
| 52 VideoPacket packet; |
| 53 packet.set_encode_time_ms(encode_delay.InMilliseconds()); |
| 54 scheduler_->OnFrameEncoded(&packet); |
| 55 |
51 scheduler_->OnFrameSent(); | 56 scheduler_->OnFrameSent(); |
52 | 57 |
| 58 scoped_ptr<VideoAck> ack(new VideoAck()); |
| 59 ack->set_frame_id(packet.frame_id()); |
| 60 scheduler_->ProcessVideoAck(ack.Pass()); |
| 61 |
53 EXPECT_TRUE(capture_timer_->IsRunning()); | 62 EXPECT_TRUE(capture_timer_->IsRunning()); |
54 EXPECT_EQ(std::max(base::TimeDelta(), | 63 EXPECT_EQ(std::max(base::TimeDelta(), |
55 expected_delay_between_frames - capture_delay), | 64 expected_delay_between_frames - capture_delay), |
56 capture_timer_->GetCurrentDelay()); | 65 capture_timer_->GetCurrentDelay()); |
57 } | 66 } |
58 | 67 |
59 protected: | 68 protected: |
60 base::MessageLoop message_loop_; | 69 base::MessageLoop message_loop_; |
61 | 70 |
62 scoped_ptr<CaptureScheduler> scheduler_; | 71 scoped_ptr<CaptureScheduler> scheduler_; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 for (size_t j = 0; j < arraysize(kTestInputs); ++j) { | 134 for (size_t j = 0; j < arraysize(kTestInputs); ++j) { |
126 SimulateSingleFrameCapture( | 135 SimulateSingleFrameCapture( |
127 base::TimeDelta::FromMilliseconds(kTestInputs[j]), | 136 base::TimeDelta::FromMilliseconds(kTestInputs[j]), |
128 base::TimeDelta::FromMilliseconds( | 137 base::TimeDelta::FromMilliseconds( |
129 kTestInputs[arraysize(kTestInputs) - 1 - j]), | 138 kTestInputs[arraysize(kTestInputs) - 1 - j]), |
130 base::TimeDelta::FromMilliseconds(kTestResults[i][j])); | 139 base::TimeDelta::FromMilliseconds(kTestResults[i][j])); |
131 } | 140 } |
132 } | 141 } |
133 } | 142 } |
134 | 143 |
135 // Verify that we never have more than 2 pending frames. | 144 // Verify that we never have more than 2 encoding frames. |
136 TEST_F(CaptureSchedulerTest, MaximumPendingFrames) { | 145 TEST_F(CaptureSchedulerTest, MaximumEncodingFrames) { |
137 InitScheduler(); | 146 InitScheduler(); |
138 | 147 |
| 148 // Process the first frame to let the scheduler know that receiver supports |
| 149 // ACKs. |
| 150 SimulateSingleFrameCapture( |
| 151 base::TimeDelta(), base::TimeDelta(), |
| 152 base::TimeDelta::FromMilliseconds(kMinumumFrameIntervalMs)); |
| 153 |
139 capture_timer_->Fire(); | 154 capture_timer_->Fire(); |
140 CheckCaptureCalled(); | 155 CheckCaptureCalled(); |
141 scheduler_->OnCaptureCompleted(); | 156 scheduler_->OnCaptureCompleted(); |
142 | 157 |
143 capture_timer_->Fire(); | 158 capture_timer_->Fire(); |
144 CheckCaptureCalled(); | 159 CheckCaptureCalled(); |
145 scheduler_->OnCaptureCompleted(); | 160 scheduler_->OnCaptureCompleted(); |
146 | 161 |
147 EXPECT_FALSE(capture_timer_->IsRunning()); | 162 EXPECT_FALSE(capture_timer_->IsRunning()); |
148 | 163 VideoPacket packet; |
149 scheduler_->OnFrameEncoded(base::TimeDelta()); | 164 scheduler_->OnFrameEncoded(&packet); |
150 scheduler_->OnFrameSent(); | |
151 | |
152 EXPECT_TRUE(capture_timer_->IsRunning()); | 165 EXPECT_TRUE(capture_timer_->IsRunning()); |
153 } | 166 } |
154 | 167 |
| 168 // Verify that the scheduler doesn't exceed maximum number of pending frames. |
| 169 TEST_F(CaptureSchedulerTest, MaximumPendingFrames) { |
| 170 InitScheduler(); |
| 171 |
| 172 // Process the first frame to let the scheduler know that receiver supports |
| 173 // ACKs. |
| 174 SimulateSingleFrameCapture( |
| 175 base::TimeDelta(), base::TimeDelta(), |
| 176 base::TimeDelta::FromMilliseconds(kMinumumFrameIntervalMs)); |
| 177 |
| 178 // Queue some frames until the sender is blocked. |
| 179 while (capture_timer_->IsRunning()) { |
| 180 capture_timer_->Fire(); |
| 181 CheckCaptureCalled(); |
| 182 scheduler_->OnCaptureCompleted(); |
| 183 VideoPacket packet; |
| 184 scheduler_->OnFrameEncoded(&packet); |
| 185 scheduler_->OnFrameSent(); |
| 186 } |
| 187 |
| 188 // Next frame should be scheduled, once one of the queued frames is |
| 189 // acknowledged. |
| 190 EXPECT_FALSE(capture_timer_->IsRunning()); |
| 191 scheduler_->ProcessVideoAck(make_scoped_ptr(new VideoAck())); |
| 192 EXPECT_TRUE(capture_timer_->IsRunning()); |
| 193 } |
| 194 |
| 195 // Verify that the scheduler doesn't exceed maximum number of pending frames |
| 196 // when acks are not supported. |
| 197 TEST_F(CaptureSchedulerTest, MaximumPendingFramesNoAcks) { |
| 198 InitScheduler(); |
| 199 |
| 200 // Queue some frames until the sender is blocked. |
| 201 while (capture_timer_->IsRunning()) { |
| 202 capture_timer_->Fire(); |
| 203 CheckCaptureCalled(); |
| 204 scheduler_->OnCaptureCompleted(); |
| 205 VideoPacket packet; |
| 206 scheduler_->OnFrameEncoded(&packet); |
| 207 } |
| 208 |
| 209 // Next frame should be scheduled, once one of the queued frames is sent. |
| 210 EXPECT_FALSE(capture_timer_->IsRunning()); |
| 211 scheduler_->OnFrameSent(); |
| 212 EXPECT_TRUE(capture_timer_->IsRunning()); |
| 213 } |
155 } // namespace remoting | 214 } // namespace remoting |
OLD | NEW |