| 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> |
| 6 |
| 5 #include "base/base64.h" | 7 #include "base/base64.h" |
| 6 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 7 #include "base/macros.h" | 9 #include "base/macros.h" |
| 8 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 9 #include "base/rand_util.h" | 11 #include "base/rand_util.h" |
| 10 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 11 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 12 #include "base/synchronization/waitable_event.h" | 14 #include "base/synchronization/waitable_event.h" |
| 13 #include "base/thread_task_runner_handle.h" | 15 #include "base/thread_task_runner_handle.h" |
| 14 #include "jingle/glue/thread_wrapper.h" | 16 #include "jingle/glue/thread_wrapper.h" |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 | 127 |
| 126 // protocol::VideoStub interface. | 128 // protocol::VideoStub interface. |
| 127 void ProcessVideoPacket(scoped_ptr<VideoPacket> video_packet, | 129 void ProcessVideoPacket(scoped_ptr<VideoPacket> video_packet, |
| 128 const base::Closure& done) override { | 130 const base::Closure& done) override { |
| 129 if (video_packet->data().empty()) { | 131 if (video_packet->data().empty()) { |
| 130 // Ignore keep-alive packets | 132 // Ignore keep-alive packets |
| 131 done.Run(); | 133 done.Run(); |
| 132 return; | 134 return; |
| 133 } | 135 } |
| 134 | 136 |
| 135 last_video_packet_ = video_packet.Pass(); | 137 last_video_packet_ = std::move(video_packet); |
| 136 | 138 |
| 137 if (!on_frame_task_.is_null()) | 139 if (!on_frame_task_.is_null()) |
| 138 on_frame_task_.Run(); | 140 on_frame_task_.Run(); |
| 139 | 141 |
| 140 done.Run(); | 142 done.Run(); |
| 141 } | 143 } |
| 142 | 144 |
| 143 // HostStatusObserver interface. | 145 // HostStatusObserver interface. |
| 144 void OnClientConnected(const std::string& jid) override { | 146 void OnClientConnected(const std::string& jid) override { |
| 145 message_loop_.PostTask( | 147 message_loop_.PostTask( |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 scoped_ptr<FakePortAllocatorFactory> port_allocator_factory( | 231 scoped_ptr<FakePortAllocatorFactory> port_allocator_factory( |
| 230 new FakePortAllocatorFactory(fake_network_dispatcher_)); | 232 new FakePortAllocatorFactory(fake_network_dispatcher_)); |
| 231 port_allocator_factory->socket_factory()->SetBandwidth( | 233 port_allocator_factory->socket_factory()->SetBandwidth( |
| 232 GetParam().bandwidth, GetParam().max_buffers); | 234 GetParam().bandwidth, GetParam().max_buffers); |
| 233 port_allocator_factory->socket_factory()->SetLatency( | 235 port_allocator_factory->socket_factory()->SetLatency( |
| 234 GetParam().latency_average, GetParam().latency_stddev); | 236 GetParam().latency_average, GetParam().latency_stddev); |
| 235 port_allocator_factory->socket_factory()->set_out_of_order_rate( | 237 port_allocator_factory->socket_factory()->set_out_of_order_rate( |
| 236 GetParam().out_of_order_rate); | 238 GetParam().out_of_order_rate); |
| 237 scoped_refptr<protocol::TransportContext> transport_context( | 239 scoped_refptr<protocol::TransportContext> transport_context( |
| 238 new protocol::TransportContext( | 240 new protocol::TransportContext( |
| 239 host_signaling_.get(), port_allocator_factory.Pass(), | 241 host_signaling_.get(), std::move(port_allocator_factory), |
| 240 network_settings, protocol::TransportRole::SERVER)); | 242 network_settings, protocol::TransportRole::SERVER)); |
| 241 | 243 |
| 242 scoped_ptr<protocol::SessionManager> session_manager( | 244 scoped_ptr<protocol::SessionManager> session_manager( |
| 243 new protocol::JingleSessionManager( | 245 new protocol::JingleSessionManager( |
| 244 make_scoped_ptr( | 246 make_scoped_ptr( |
| 245 new protocol::IceTransportFactory(transport_context)), | 247 new protocol::IceTransportFactory(transport_context)), |
| 246 host_signaling_.get())); | 248 host_signaling_.get())); |
| 247 session_manager->set_protocol_config(protocol_config_->Clone()); | 249 session_manager->set_protocol_config(protocol_config_->Clone()); |
| 248 | 250 |
| 249 // Encoder runs on a separate thread, main thread is used for everything | 251 // Encoder runs on a separate thread, main thread is used for everything |
| 250 // else. | 252 // else. |
| 251 host_.reset(new ChromotingHost(&desktop_environment_factory_, | 253 host_.reset(new ChromotingHost( |
| 252 session_manager.Pass(), | 254 &desktop_environment_factory_, std::move(session_manager), |
| 253 host_thread_.task_runner(), | 255 host_thread_.task_runner(), host_thread_.task_runner(), |
| 254 host_thread_.task_runner(), | 256 capture_thread_.task_runner(), encode_thread_.task_runner(), |
| 255 capture_thread_.task_runner(), | 257 host_thread_.task_runner(), host_thread_.task_runner())); |
| 256 encode_thread_.task_runner(), | |
| 257 host_thread_.task_runner(), | |
| 258 host_thread_.task_runner())); | |
| 259 | 258 |
| 260 base::FilePath certs_dir(net::GetTestCertsDirectory()); | 259 base::FilePath certs_dir(net::GetTestCertsDirectory()); |
| 261 | 260 |
| 262 std::string host_cert; | 261 std::string host_cert; |
| 263 ASSERT_TRUE(base::ReadFileToString( | 262 ASSERT_TRUE(base::ReadFileToString( |
| 264 certs_dir.AppendASCII("unittest.selfsigned.der"), &host_cert)); | 263 certs_dir.AppendASCII("unittest.selfsigned.der"), &host_cert)); |
| 265 | 264 |
| 266 base::FilePath key_path = certs_dir.AppendASCII("unittest.key.bin"); | 265 base::FilePath key_path = certs_dir.AppendASCII("unittest.key.bin"); |
| 267 std::string key_string; | 266 std::string key_string; |
| 268 ASSERT_TRUE(base::ReadFileToString(key_path, &key_string)); | 267 ASSERT_TRUE(base::ReadFileToString(key_path, &key_string)); |
| 269 std::string key_base64; | 268 std::string key_base64; |
| 270 base::Base64Encode(key_string, &key_base64); | 269 base::Base64Encode(key_string, &key_base64); |
| 271 scoped_refptr<RsaKeyPair> key_pair = RsaKeyPair::FromString(key_base64); | 270 scoped_refptr<RsaKeyPair> key_pair = RsaKeyPair::FromString(key_base64); |
| 272 ASSERT_TRUE(key_pair.get()); | 271 ASSERT_TRUE(key_pair.get()); |
| 273 | 272 |
| 274 protocol::SharedSecretHash host_secret; | 273 protocol::SharedSecretHash host_secret; |
| 275 host_secret.hash_function = protocol::AuthenticationMethod::NONE; | 274 host_secret.hash_function = protocol::AuthenticationMethod::NONE; |
| 276 host_secret.value = "123456"; | 275 host_secret.value = "123456"; |
| 277 scoped_ptr<protocol::AuthenticatorFactory> auth_factory = | 276 scoped_ptr<protocol::AuthenticatorFactory> auth_factory = |
| 278 protocol::Me2MeHostAuthenticatorFactory::CreateWithSharedSecret( | 277 protocol::Me2MeHostAuthenticatorFactory::CreateWithSharedSecret( |
| 279 true, kHostOwner, host_cert, key_pair, host_secret, nullptr); | 278 true, kHostOwner, host_cert, key_pair, host_secret, nullptr); |
| 280 host_->SetAuthenticatorFactory(auth_factory.Pass()); | 279 host_->SetAuthenticatorFactory(std::move(auth_factory)); |
| 281 | 280 |
| 282 host_->AddStatusObserver(this); | 281 host_->AddStatusObserver(this); |
| 283 host_->Start(kHostOwner); | 282 host_->Start(kHostOwner); |
| 284 | 283 |
| 285 message_loop_.PostTask(FROM_HERE, | 284 message_loop_.PostTask(FROM_HERE, |
| 286 base::Bind(&ProtocolPerfTest::StartClientAfterHost, | 285 base::Bind(&ProtocolPerfTest::StartClientAfterHost, |
| 287 base::Unretained(this))); | 286 base::Unretained(this))); |
| 288 } | 287 } |
| 289 | 288 |
| 290 void StartClientAfterHost() { | 289 void StartClientAfterHost() { |
| 291 client_signaling_->ConnectTo(host_signaling_.get()); | 290 client_signaling_->ConnectTo(host_signaling_.get()); |
| 292 | 291 |
| 293 protocol::NetworkSettings network_settings( | 292 protocol::NetworkSettings network_settings( |
| 294 protocol::NetworkSettings::NAT_TRAVERSAL_OUTGOING); | 293 protocol::NetworkSettings::NAT_TRAVERSAL_OUTGOING); |
| 295 | 294 |
| 296 // Initialize client. | 295 // Initialize client. |
| 297 client_context_.reset( | 296 client_context_.reset( |
| 298 new ClientContext(base::ThreadTaskRunnerHandle::Get())); | 297 new ClientContext(base::ThreadTaskRunnerHandle::Get())); |
| 299 | 298 |
| 300 scoped_ptr<FakePortAllocatorFactory> port_allocator_factory( | 299 scoped_ptr<FakePortAllocatorFactory> port_allocator_factory( |
| 301 new FakePortAllocatorFactory(fake_network_dispatcher_)); | 300 new FakePortAllocatorFactory(fake_network_dispatcher_)); |
| 302 port_allocator_factory->socket_factory()->SetBandwidth( | 301 port_allocator_factory->socket_factory()->SetBandwidth( |
| 303 GetParam().bandwidth, GetParam().max_buffers); | 302 GetParam().bandwidth, GetParam().max_buffers); |
| 304 port_allocator_factory->socket_factory()->SetLatency( | 303 port_allocator_factory->socket_factory()->SetLatency( |
| 305 GetParam().latency_average, GetParam().latency_stddev); | 304 GetParam().latency_average, GetParam().latency_stddev); |
| 306 port_allocator_factory->socket_factory()->set_out_of_order_rate( | 305 port_allocator_factory->socket_factory()->set_out_of_order_rate( |
| 307 GetParam().out_of_order_rate); | 306 GetParam().out_of_order_rate); |
| 308 scoped_refptr<protocol::TransportContext> transport_context( | 307 scoped_refptr<protocol::TransportContext> transport_context( |
| 309 new protocol::TransportContext( | 308 new protocol::TransportContext( |
| 310 host_signaling_.get(), port_allocator_factory.Pass(), | 309 host_signaling_.get(), std::move(port_allocator_factory), |
| 311 network_settings, protocol::TransportRole::SERVER)); | 310 network_settings, protocol::TransportRole::SERVER)); |
| 312 | 311 |
| 313 std::vector<protocol::AuthenticationMethod> auth_methods; | 312 std::vector<protocol::AuthenticationMethod> auth_methods; |
| 314 auth_methods.push_back(protocol::AuthenticationMethod::Spake2( | 313 auth_methods.push_back(protocol::AuthenticationMethod::Spake2( |
| 315 protocol::AuthenticationMethod::NONE)); | 314 protocol::AuthenticationMethod::NONE)); |
| 316 scoped_ptr<protocol::Authenticator> client_authenticator( | 315 scoped_ptr<protocol::Authenticator> client_authenticator( |
| 317 new protocol::NegotiatingClientAuthenticator( | 316 new protocol::NegotiatingClientAuthenticator( |
| 318 std::string(), // client_pairing_id | 317 std::string(), // client_pairing_id |
| 319 std::string(), // client_pairing_secret | 318 std::string(), // client_pairing_secret |
| 320 std::string(), // authentication_tag | 319 std::string(), // authentication_tag |
| 321 base::Bind(&ProtocolPerfTest::FetchPin, base::Unretained(this)), | 320 base::Bind(&ProtocolPerfTest::FetchPin, base::Unretained(this)), |
| 322 nullptr, | 321 nullptr, auth_methods)); |
| 323 auth_methods)); | |
| 324 client_.reset( | 322 client_.reset( |
| 325 new ChromotingClient(client_context_.get(), this, this, nullptr)); | 323 new ChromotingClient(client_context_.get(), this, this, nullptr)); |
| 326 client_->set_protocol_config(protocol_config_->Clone()); | 324 client_->set_protocol_config(protocol_config_->Clone()); |
| 327 client_->Start(client_signaling_.get(), client_authenticator.Pass(), | 325 client_->Start(client_signaling_.get(), std::move(client_authenticator), |
| 328 transport_context, kHostJid, std::string()); | 326 transport_context, kHostJid, std::string()); |
| 329 } | 327 } |
| 330 | 328 |
| 331 void FetchPin( | 329 void FetchPin( |
| 332 bool pairing_supported, | 330 bool pairing_supported, |
| 333 const protocol::SecretFetchedCallback& secret_fetched_callback) { | 331 const protocol::SecretFetchedCallback& secret_fetched_callback) { |
| 334 secret_fetched_callback.Run("123456"); | 332 secret_fetched_callback.Run("123456"); |
| 335 } | 333 } |
| 336 | 334 |
| 337 base::MessageLoopForIO message_loop_; | 335 base::MessageLoopForIO message_loop_; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 fresh_frame = true; | 439 fresh_frame = true; |
| 442 } | 440 } |
| 443 ++frame_index_; | 441 ++frame_index_; |
| 444 | 442 |
| 445 scoped_ptr<webrtc::DesktopFrame> result(current_frame_->Share()); | 443 scoped_ptr<webrtc::DesktopFrame> result(current_frame_->Share()); |
| 446 result->mutable_updated_region()->Clear(); | 444 result->mutable_updated_region()->Clear(); |
| 447 if (fresh_frame) { | 445 if (fresh_frame) { |
| 448 result->mutable_updated_region()->AddRect( | 446 result->mutable_updated_region()->AddRect( |
| 449 webrtc::DesktopRect::MakeXYWH(0, 0, kWidth, kHeight)); | 447 webrtc::DesktopRect::MakeXYWH(0, 0, kWidth, kHeight)); |
| 450 } | 448 } |
| 451 return result.Pass(); | 449 return result; |
| 452 } | 450 } |
| 453 | 451 |
| 454 private: | 452 private: |
| 455 ~IntermittentChangeFrameGenerator() {} | 453 ~IntermittentChangeFrameGenerator() {} |
| 456 friend class base::RefCountedThreadSafe<IntermittentChangeFrameGenerator>; | 454 friend class base::RefCountedThreadSafe<IntermittentChangeFrameGenerator>; |
| 457 | 455 |
| 458 int frame_index_; | 456 int frame_index_; |
| 459 scoped_ptr<webrtc::SharedDesktopFrame> current_frame_; | 457 scoped_ptr<webrtc::SharedDesktopFrame> current_frame_; |
| 460 | 458 |
| 461 DISALLOW_COPY_AND_ASSIGN(IntermittentChangeFrameGenerator); | 459 DISALLOW_COPY_AND_ASSIGN(IntermittentChangeFrameGenerator); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 488 << "ms Encode: " << last_video_packet_->encode_time_ms() | 486 << "ms Encode: " << last_video_packet_->encode_time_ms() |
| 489 << "ms Capture: " << last_video_packet_->capture_time_ms() | 487 << "ms Capture: " << last_video_packet_->capture_time_ms() |
| 490 << "ms"; | 488 << "ms"; |
| 491 sum += latency; | 489 sum += latency; |
| 492 } | 490 } |
| 493 | 491 |
| 494 LOG(INFO) << "Average: " << (sum / kFrames).InMillisecondsF(); | 492 LOG(INFO) << "Average: " << (sum / kFrames).InMillisecondsF(); |
| 495 } | 493 } |
| 496 | 494 |
| 497 } // namespace remoting | 495 } // namespace remoting |
| OLD | NEW |