OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <utility> | 5 #include <utility> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 } | 216 } |
217 | 217 |
218 run_loop.Run(); | 218 run_loop.Run(); |
219 | 219 |
220 if (is_using_webrtc()) { | 220 if (is_using_webrtc()) { |
221 EXPECT_EQ( | 221 EXPECT_EQ( |
222 client_video_renderer_.GetFrameConsumer()->received_frames().size(), | 222 client_video_renderer_.GetFrameConsumer()->received_frames().size(), |
223 1U); | 223 1U); |
224 EXPECT_EQ( | 224 EXPECT_EQ( |
225 client_video_renderer_.GetVideoStub()->received_packets().size(), 0U); | 225 client_video_renderer_.GetVideoStub()->received_packets().size(), 0U); |
| 226 client_video_renderer_.GetFrameConsumer()->set_on_frame_callback( |
| 227 base::Closure()); |
226 } else { | 228 } else { |
227 EXPECT_EQ( | 229 EXPECT_EQ( |
228 client_video_renderer_.GetFrameConsumer()->received_frames().size(), | 230 client_video_renderer_.GetFrameConsumer()->received_frames().size(), |
229 0U); | 231 0U); |
230 EXPECT_EQ( | 232 EXPECT_EQ( |
231 client_video_renderer_.GetVideoStub()->received_packets().size(), 1U); | 233 client_video_renderer_.GetVideoStub()->received_packets().size(), 1U); |
| 234 client_video_renderer_.GetVideoStub()->set_on_frame_callback( |
| 235 base::Closure()); |
232 } | 236 } |
233 } | 237 } |
234 | 238 |
| 239 void WaitFirstFrameStats() { |
| 240 if (!client_video_renderer_.GetFrameStatsConsumer() |
| 241 ->received_stats() |
| 242 .empty()) { |
| 243 return; |
| 244 } |
| 245 |
| 246 base::RunLoop run_loop; |
| 247 client_video_renderer_.GetFrameStatsConsumer()->set_on_stats_callback( |
| 248 base::Bind(&base::RunLoop::Quit, base::Unretained(&run_loop))); |
| 249 run_loop.Run(); |
| 250 client_video_renderer_.GetFrameStatsConsumer()->set_on_stats_callback( |
| 251 base::Closure()); |
| 252 |
| 253 EXPECT_FALSE(client_video_renderer_.GetFrameStatsConsumer() |
| 254 ->received_stats() |
| 255 .empty()); |
| 256 } |
| 257 |
235 base::MessageLoopForIO message_loop_; | 258 base::MessageLoopForIO message_loop_; |
236 std::unique_ptr<base::RunLoop> run_loop_; | 259 std::unique_ptr<base::RunLoop> run_loop_; |
237 | 260 |
238 MockConnectionToClientEventHandler host_event_handler_; | 261 MockConnectionToClientEventHandler host_event_handler_; |
239 MockClipboardStub host_clipboard_stub_; | 262 MockClipboardStub host_clipboard_stub_; |
240 MockHostStub host_stub_; | 263 MockHostStub host_stub_; |
241 MockInputStub host_input_stub_; | 264 MockInputStub host_input_stub_; |
242 std::unique_ptr<ConnectionToClient> host_connection_; | 265 std::unique_ptr<ConnectionToClient> host_connection_; |
243 FakeSession* host_session_; // Owned by |host_connection_|. | 266 FakeSession* host_session_; // Owned by |host_connection_|. |
244 bool host_connected_ = false; | 267 bool host_connected_ = false; |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 EXPECT_CALL(host_input_stub_, InjectKeyEvent(EqualsKeyEvent(event))) | 385 EXPECT_CALL(host_input_stub_, InjectKeyEvent(EqualsKeyEvent(event))) |
363 .WillOnce(DoAll(InvokeWithoutArgs(this, &ConnectionTest::DestroyHost), | 386 .WillOnce(DoAll(InvokeWithoutArgs(this, &ConnectionTest::DestroyHost), |
364 QuitRunLoop(&run_loop))); | 387 QuitRunLoop(&run_loop))); |
365 | 388 |
366 // Send key event from the client. | 389 // Send key event from the client. |
367 client_connection_->input_stub()->InjectKeyEvent(event); | 390 client_connection_->input_stub()->InjectKeyEvent(event); |
368 | 391 |
369 run_loop.Run(); | 392 run_loop.Run(); |
370 } | 393 } |
371 | 394 |
| 395 TEST_P(ConnectionTest, VideoStats) { |
| 396 // Currently this test only works for WebRTC because for ICE connections stats |
| 397 // are reported by SoftwareVideoRenderer which is not used in this test. |
| 398 // TODO(sergeyu): Fix this. |
| 399 if (!is_using_webrtc()) |
| 400 return; |
| 401 |
| 402 Connect(); |
| 403 |
| 404 base::TimeTicks start_time = base::TimeTicks::Now(); |
| 405 |
| 406 std::unique_ptr<VideoStream> video_stream = |
| 407 host_connection_->StartVideoStream( |
| 408 base::WrapUnique(new TestScreenCapturer())); |
| 409 |
| 410 // Simulate an input invent injected at the start. |
| 411 video_stream->OnInputEventReceived(start_time.ToInternalValue()); |
| 412 |
| 413 WaitFirstVideoFrame(); |
| 414 |
| 415 base::TimeTicks finish_time = base::TimeTicks::Now(); |
| 416 |
| 417 WaitFirstFrameStats(); |
| 418 |
| 419 const FrameStats& stats = |
| 420 client_video_renderer_.GetFrameStatsConsumer()->received_stats().front(); |
| 421 |
| 422 EXPECT_TRUE(stats.host_stats.frame_size > 0); |
| 423 |
| 424 EXPECT_TRUE(stats.host_stats.latest_event_timestamp == start_time); |
| 425 EXPECT_TRUE(stats.host_stats.capture_delay != base::TimeDelta::Max()); |
| 426 EXPECT_TRUE(stats.host_stats.capture_overhead_delay != |
| 427 base::TimeDelta::Max()); |
| 428 EXPECT_TRUE(stats.host_stats.encode_delay != base::TimeDelta::Max()); |
| 429 EXPECT_TRUE(stats.host_stats.send_pending_delay != base::TimeDelta::Max()); |
| 430 |
| 431 EXPECT_FALSE(stats.client_stats.time_received.is_null()); |
| 432 EXPECT_FALSE(stats.client_stats.time_decoded.is_null()); |
| 433 EXPECT_FALSE(stats.client_stats.time_rendered.is_null()); |
| 434 |
| 435 EXPECT_TRUE(start_time + stats.host_stats.capture_pending_delay + |
| 436 stats.host_stats.capture_delay + |
| 437 stats.host_stats.capture_overhead_delay + |
| 438 stats.host_stats.encode_delay + |
| 439 stats.host_stats.send_pending_delay <= |
| 440 stats.client_stats.time_received); |
| 441 EXPECT_TRUE(stats.client_stats.time_received <= |
| 442 stats.client_stats.time_decoded); |
| 443 EXPECT_TRUE(stats.client_stats.time_decoded <= |
| 444 stats.client_stats.time_rendered); |
| 445 EXPECT_TRUE(stats.client_stats.time_rendered <= finish_time); |
| 446 } |
| 447 |
372 } // namespace protocol | 448 } // namespace protocol |
373 } // namespace remoting | 449 } // namespace remoting |
OLD | NEW |