Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/rand_util.h" | 12 #include "base/rand_util.h" |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 15 #include "base/synchronization/waitable_event.h" | 15 #include "base/synchronization/waitable_event.h" |
| 16 #include "base/task_runner_util.h" | 16 #include "base/task_runner_util.h" |
| 17 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
| 18 #include "jingle/glue/thread_wrapper.h" | 18 #include "jingle/glue/thread_wrapper.h" |
| 19 #include "net/test/test_data_directory.h" | 19 #include "net/test/test_data_directory.h" |
| 20 #include "net/url_request/url_request_context_getter.h" | 20 #include "net/url_request/url_request_context_getter.h" |
| 21 #include "remoting/base/auto_thread.h" | |
| 22 #include "remoting/base/auto_thread_task_runner.h" | |
| 21 #include "remoting/base/rsa_key_pair.h" | 23 #include "remoting/base/rsa_key_pair.h" |
| 22 #include "remoting/base/url_request.h" | 24 #include "remoting/base/url_request.h" |
| 23 #include "remoting/client/audio_player.h" | 25 #include "remoting/client/audio_player.h" |
| 24 #include "remoting/client/chromoting_client.h" | 26 #include "remoting/client/chromoting_client.h" |
| 25 #include "remoting/client/client_context.h" | 27 #include "remoting/client/client_context.h" |
| 26 #include "remoting/client/client_user_interface.h" | 28 #include "remoting/client/client_user_interface.h" |
| 27 #include "remoting/codec/video_decoder_verbatim.h" | 29 #include "remoting/codec/video_decoder_verbatim.h" |
| 28 #include "remoting/codec/video_decoder_vpx.h" | 30 #include "remoting/codec/video_decoder_vpx.h" |
| 29 #include "remoting/host/chromoting_host.h" | 31 #include "remoting/host/chromoting_host.h" |
| 30 #include "remoting/host/chromoting_host_context.h" | 32 #include "remoting/host/chromoting_host_context.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 class ProtocolPerfTest | 101 class ProtocolPerfTest |
| 100 : public testing::Test, | 102 : public testing::Test, |
| 101 public testing::WithParamInterface<NetworkPerformanceParams>, | 103 public testing::WithParamInterface<NetworkPerformanceParams>, |
| 102 public ClientUserInterface, | 104 public ClientUserInterface, |
| 103 public protocol::VideoRenderer, | 105 public protocol::VideoRenderer, |
| 104 public protocol::VideoStub, | 106 public protocol::VideoStub, |
| 105 public protocol::FrameConsumer, | 107 public protocol::FrameConsumer, |
| 106 public HostStatusObserver { | 108 public HostStatusObserver { |
| 107 public: | 109 public: |
| 108 ProtocolPerfTest() | 110 ProtocolPerfTest() |
| 109 : host_thread_("host"), | 111 : host_thread_(new AutoThreadTaskRunner( |
| 110 capture_thread_("capture"), | 112 message_loop_.task_runner(), run_loop_.QuitClosure())) { |
|
Sergey Ulanov
2016/06/27 18:20:24
Previously the host was running on a separate thre
| |
| 111 encode_thread_("encode"), | |
| 112 decode_thread_("decode") { | |
| 113 protocol::VideoFramePump::EnableTimestampsForTests(); | 113 protocol::VideoFramePump::EnableTimestampsForTests(); |
| 114 host_thread_.StartWithOptions( | 114 context_ = ChromotingHostContext::Create(host_thread_); |
| 115 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); | |
| 116 capture_thread_.Start(); | |
| 117 encode_thread_.Start(); | |
| 118 decode_thread_.Start(); | |
| 119 } | 115 } |
| 120 | 116 |
| 121 virtual ~ProtocolPerfTest() { | 117 virtual ~ProtocolPerfTest() { |
| 122 host_thread_.task_runner()->DeleteSoon(FROM_HERE, host_.release()); | 118 host_thread_->DeleteSoon(FROM_HERE, host_.release()); |
| 123 host_thread_.task_runner()->DeleteSoon(FROM_HERE, | 119 host_thread_->DeleteSoon(FROM_HERE, host_signaling_.release()); |
| 124 host_signaling_.release()); | 120 host_thread_->DeleteSoon(FROM_HERE, context_.release()); |
| 125 message_loop_.RunUntilIdle(); | 121 host_thread_ = nullptr; |
| 122 run_loop_.QuitWhenIdle(); | |
| 126 } | 123 } |
| 127 | 124 |
| 128 // ClientUserInterface interface. | 125 // ClientUserInterface interface. |
| 129 void OnConnectionState(protocol::ConnectionToHost::State state, | 126 void OnConnectionState(protocol::ConnectionToHost::State state, |
| 130 protocol::ErrorCode error) override { | 127 protocol::ErrorCode error) override { |
| 131 if (state == protocol::ConnectionToHost::CONNECTED) { | 128 if (state == protocol::ConnectionToHost::CONNECTED) { |
| 132 client_connected_ = true; | 129 client_connected_ = true; |
| 133 if (host_connected_) | 130 if (host_connected_) |
| 134 connecting_loop_->Quit(); | 131 connecting_loop_->Quit(); |
| 135 } | 132 } |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 164 | 161 |
| 165 if (packet->format().has_screen_width() && | 162 if (packet->format().has_screen_width() && |
| 166 packet->format().has_screen_height()) { | 163 packet->format().has_screen_height()) { |
| 167 frame_size_.set(packet->format().screen_width(), | 164 frame_size_.set(packet->format().screen_width(), |
| 168 packet->format().screen_height()); | 165 packet->format().screen_height()); |
| 169 } | 166 } |
| 170 | 167 |
| 171 std::unique_ptr<webrtc::DesktopFrame> frame( | 168 std::unique_ptr<webrtc::DesktopFrame> frame( |
| 172 new webrtc::BasicDesktopFrame(frame_size_)); | 169 new webrtc::BasicDesktopFrame(frame_size_)); |
| 173 base::PostTaskAndReplyWithResult( | 170 base::PostTaskAndReplyWithResult( |
| 174 decode_thread_.task_runner().get(), FROM_HERE, | 171 context_->video_encode_task_runner().get(), FROM_HERE, |
|
Sergey Ulanov
2016/06/27 18:20:24
We want to use separate threads for encoding and d
| |
| 175 base::Bind(&DoDecodeFrame, video_decoder_.get(), packet.get(), | 172 base::Bind(&DoDecodeFrame, video_decoder_.get(), packet.get(), |
| 176 base::Passed(&frame)), | 173 base::Passed(&frame)), |
| 177 base::Bind(&ProtocolPerfTest::OnFrameDecoded, base::Unretained(this), | 174 base::Bind(&ProtocolPerfTest::OnFrameDecoded, base::Unretained(this), |
| 178 base::Passed(&packet), done)); | 175 base::Passed(&packet), done)); |
| 179 } | 176 } |
| 180 | 177 |
| 181 void OnFrameDecoded(std::unique_ptr<VideoPacket> packet, | 178 void OnFrameDecoded(std::unique_ptr<VideoPacket> packet, |
| 182 const base::Closure& done, | 179 const base::Closure& done, |
| 183 std::unique_ptr<webrtc::DesktopFrame> frame) { | 180 std::unique_ptr<webrtc::DesktopFrame> frame) { |
| 184 last_video_packet_ = std::move(packet); | 181 last_video_packet_ = std::move(packet); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 293 case ChannelConfig::CODEC_VERBATIM: | 290 case ChannelConfig::CODEC_VERBATIM: |
| 294 video_decoder_.reset(new VideoDecoderVerbatim()); | 291 video_decoder_.reset(new VideoDecoderVerbatim()); |
| 295 break; | 292 break; |
| 296 case ChannelConfig::CODEC_VP8: | 293 case ChannelConfig::CODEC_VP8: |
| 297 video_decoder_ = VideoDecoderVpx::CreateForVP8(); | 294 video_decoder_ = VideoDecoderVpx::CreateForVP8(); |
| 298 break; | 295 break; |
| 299 default: | 296 default: |
| 300 NOTREACHED(); | 297 NOTREACHED(); |
| 301 } | 298 } |
| 302 | 299 |
| 303 host_thread_.task_runner()->PostTask( | 300 host_thread_->PostTask( |
| 304 FROM_HERE, | 301 FROM_HERE, |
| 305 base::Bind(&ProtocolPerfTest::StartHost, base::Unretained(this))); | 302 base::Bind(&ProtocolPerfTest::StartHost, base::Unretained(this))); |
| 306 } | 303 } |
| 307 | 304 |
| 308 void StartHost() { | 305 void StartHost() { |
| 309 DCHECK(host_thread_.task_runner()->BelongsToCurrentThread()); | 306 DCHECK(host_thread_->BelongsToCurrentThread()); |
| 310 | 307 |
| 311 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); | 308 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); |
| 312 | 309 |
| 313 host_signaling_.reset(new FakeSignalStrategy(kHostJid)); | 310 host_signaling_.reset(new FakeSignalStrategy(kHostJid)); |
| 314 host_signaling_->ConnectTo(client_signaling_.get()); | 311 host_signaling_->ConnectTo(client_signaling_.get()); |
| 315 | 312 |
| 316 protocol::NetworkSettings network_settings( | 313 protocol::NetworkSettings network_settings( |
| 317 protocol::NetworkSettings::NAT_TRAVERSAL_OUTGOING); | 314 protocol::NetworkSettings::NAT_TRAVERSAL_OUTGOING); |
| 318 | 315 |
| 319 std::unique_ptr<FakePortAllocatorFactory> port_allocator_factory( | 316 std::unique_ptr<FakePortAllocatorFactory> port_allocator_factory( |
| 320 new FakePortAllocatorFactory(fake_network_dispatcher_)); | 317 new FakePortAllocatorFactory(fake_network_dispatcher_)); |
| 321 port_allocator_factory->socket_factory()->SetBandwidth( | 318 port_allocator_factory->socket_factory()->SetBandwidth( |
| 322 GetParam().bandwidth, GetParam().max_buffers); | 319 GetParam().bandwidth, GetParam().max_buffers); |
| 323 port_allocator_factory->socket_factory()->SetLatency( | 320 port_allocator_factory->socket_factory()->SetLatency( |
| 324 GetParam().latency_average, GetParam().latency_stddev); | 321 GetParam().latency_average, GetParam().latency_stddev); |
| 325 port_allocator_factory->socket_factory()->set_out_of_order_rate( | 322 port_allocator_factory->socket_factory()->set_out_of_order_rate( |
| 326 GetParam().out_of_order_rate); | 323 GetParam().out_of_order_rate); |
| 327 scoped_refptr<protocol::TransportContext> transport_context( | 324 scoped_refptr<protocol::TransportContext> transport_context( |
| 328 new protocol::TransportContext( | 325 new protocol::TransportContext( |
| 329 host_signaling_.get(), std::move(port_allocator_factory), nullptr, | 326 host_signaling_.get(), std::move(port_allocator_factory), nullptr, |
| 330 network_settings, protocol::TransportRole::SERVER)); | 327 network_settings, protocol::TransportRole::SERVER)); |
| 331 std::unique_ptr<protocol::SessionManager> session_manager( | 328 std::unique_ptr<protocol::SessionManager> session_manager( |
| 332 new protocol::JingleSessionManager(host_signaling_.get())); | 329 new protocol::JingleSessionManager(host_signaling_.get())); |
| 333 session_manager->set_protocol_config(protocol_config_->Clone()); | 330 session_manager->set_protocol_config(protocol_config_->Clone()); |
| 334 | 331 |
| 335 // Encoder runs on a separate thread, main thread is used for everything | 332 // Encoder runs on a separate thread, main thread is used for everything |
| 336 // else. | 333 // else. |
| 337 host_.reset(new ChromotingHost( | 334 host_.reset(new ChromotingHost( |
| 338 &desktop_environment_factory_, std::move(session_manager), | 335 &desktop_environment_factory_, std::move(session_manager), |
| 339 transport_context, host_thread_.task_runner(), | 336 transport_context, |
| 340 encode_thread_.task_runner())); | 337 *context_)); |
| 341 | 338 |
| 342 base::FilePath certs_dir(net::GetTestCertsDirectory()); | 339 base::FilePath certs_dir(net::GetTestCertsDirectory()); |
| 343 | 340 |
| 344 std::string host_cert; | 341 std::string host_cert; |
| 345 ASSERT_TRUE(base::ReadFileToString( | 342 ASSERT_TRUE(base::ReadFileToString( |
| 346 certs_dir.AppendASCII("unittest.selfsigned.der"), &host_cert)); | 343 certs_dir.AppendASCII("unittest.selfsigned.der"), &host_cert)); |
| 347 | 344 |
| 348 base::FilePath key_path = certs_dir.AppendASCII("unittest.key.bin"); | 345 base::FilePath key_path = certs_dir.AppendASCII("unittest.key.bin"); |
| 349 std::string key_string; | 346 std::string key_string; |
| 350 ASSERT_TRUE(base::ReadFileToString(key_path, &key_string)); | 347 ASSERT_TRUE(base::ReadFileToString(key_path, &key_string)); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 461 << (total_latency_big_frames / big_frame_count).InMillisecondsF(); | 458 << (total_latency_big_frames / big_frame_count).InMillisecondsF(); |
| 462 | 459 |
| 463 if (small_frame_count) { | 460 if (small_frame_count) { |
| 464 VLOG(0) | 461 VLOG(0) |
| 465 << "Average latency for small frames: " | 462 << "Average latency for small frames: " |
| 466 << (total_latency_small_frames / small_frame_count).InMillisecondsF(); | 463 << (total_latency_small_frames / small_frame_count).InMillisecondsF(); |
| 467 } | 464 } |
| 468 } | 465 } |
| 469 | 466 |
| 470 base::MessageLoopForIO message_loop_; | 467 base::MessageLoopForIO message_loop_; |
| 468 base::RunLoop run_loop_; | |
| 469 | |
| 470 std::unique_ptr<ChromotingHostContext> context_; | |
| 471 | 471 |
| 472 scoped_refptr<FakeNetworkDispatcher> fake_network_dispatcher_; | 472 scoped_refptr<FakeNetworkDispatcher> fake_network_dispatcher_; |
| 473 | 473 |
| 474 base::Thread host_thread_; | 474 scoped_refptr<AutoThreadTaskRunner> host_thread_; |
|
Sergey Ulanov
2016/06/27 18:20:24
this is a task_runner, so it shouldn't be called h
| |
| 475 base::Thread capture_thread_; | |
| 476 base::Thread encode_thread_; | |
| 477 base::Thread decode_thread_; | |
| 478 FakeDesktopEnvironmentFactory desktop_environment_factory_; | 475 FakeDesktopEnvironmentFactory desktop_environment_factory_; |
| 479 | 476 |
| 480 FakeCursorShapeStub cursor_shape_stub_; | 477 FakeCursorShapeStub cursor_shape_stub_; |
| 481 | 478 |
| 482 std::unique_ptr<protocol::CandidateSessionConfig> protocol_config_; | 479 std::unique_ptr<protocol::CandidateSessionConfig> protocol_config_; |
| 483 | 480 |
| 484 std::unique_ptr<FakeSignalStrategy> host_signaling_; | 481 std::unique_ptr<FakeSignalStrategy> host_signaling_; |
| 485 std::unique_ptr<FakeSignalStrategy> client_signaling_; | 482 std::unique_ptr<FakeSignalStrategy> client_signaling_; |
| 486 | 483 |
| 487 std::unique_ptr<ChromotingHost> host_; | 484 std::unique_ptr<ChromotingHost> host_; |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 633 | 630 |
| 634 TEST_P(ProtocolPerfTest, TotalLatencyIce) { | 631 TEST_P(ProtocolPerfTest, TotalLatencyIce) { |
| 635 MeasureTotalLatency(false); | 632 MeasureTotalLatency(false); |
| 636 } | 633 } |
| 637 | 634 |
| 638 TEST_P(ProtocolPerfTest, TotalLatencyWebrtc) { | 635 TEST_P(ProtocolPerfTest, TotalLatencyWebrtc) { |
| 639 MeasureTotalLatency(true); | 636 MeasureTotalLatency(true); |
| 640 } | 637 } |
| 641 | 638 |
| 642 } // namespace remoting | 639 } // namespace remoting |
| OLD | NEW |