| 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/client/jni/chromoting_jni_instance.h" | 5 #include "remoting/client/jni/chromoting_jni_instance.h" |
| 6 | 6 |
| 7 #include <android/log.h> | 7 #include <android/log.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "net/socket/client_socket_factory.h" | 11 #include "net/socket/client_socket_factory.h" |
| 12 #include "remoting/client/audio_player.h" | 12 #include "remoting/client/audio_player.h" |
| 13 #include "remoting/client/jni/android_keymap.h" | 13 #include "remoting/client/jni/android_keymap.h" |
| 14 #include "remoting/client/jni/chromoting_jni_runtime.h" | 14 #include "remoting/client/jni/chromoting_jni_runtime.h" |
| 15 #include "remoting/client/software_video_renderer.h" |
| 15 #include "remoting/jingle_glue/chromium_port_allocator.h" | 16 #include "remoting/jingle_glue/chromium_port_allocator.h" |
| 16 #include "remoting/jingle_glue/chromium_socket_factory.h" | 17 #include "remoting/jingle_glue/chromium_socket_factory.h" |
| 17 #include "remoting/jingle_glue/network_settings.h" | 18 #include "remoting/jingle_glue/network_settings.h" |
| 18 #include "remoting/protocol/host_stub.h" | 19 #include "remoting/protocol/host_stub.h" |
| 19 #include "remoting/protocol/libjingle_transport_factory.h" | 20 #include "remoting/protocol/libjingle_transport_factory.h" |
| 20 | 21 |
| 21 namespace remoting { | 22 namespace remoting { |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 | 182 |
| 182 void ChromotingJniInstance::RecordPaintTime(int64 paint_time_ms) { | 183 void ChromotingJniInstance::RecordPaintTime(int64 paint_time_ms) { |
| 183 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) { | 184 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) { |
| 184 jni_runtime_->network_task_runner()->PostTask( | 185 jni_runtime_->network_task_runner()->PostTask( |
| 185 FROM_HERE, base::Bind(&ChromotingJniInstance::RecordPaintTime, this, | 186 FROM_HERE, base::Bind(&ChromotingJniInstance::RecordPaintTime, this, |
| 186 paint_time_ms)); | 187 paint_time_ms)); |
| 187 return; | 188 return; |
| 188 } | 189 } |
| 189 | 190 |
| 190 if (stats_logging_enabled_) | 191 if (stats_logging_enabled_) |
| 191 client_->GetStats()->video_paint_ms()->Record(paint_time_ms); | 192 video_renderer_->GetStats()->video_paint_ms()->Record(paint_time_ms); |
| 192 } | 193 } |
| 193 | 194 |
| 194 void ChromotingJniInstance::OnConnectionState( | 195 void ChromotingJniInstance::OnConnectionState( |
| 195 protocol::ConnectionToHost::State state, | 196 protocol::ConnectionToHost::State state, |
| 196 protocol::ErrorCode error) { | 197 protocol::ErrorCode error) { |
| 197 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); | 198 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); |
| 198 | 199 |
| 199 EnableStatsLogging(state == protocol::ConnectionToHost::CONNECTED); | 200 EnableStatsLogging(state == protocol::ConnectionToHost::CONNECTED); |
| 200 | 201 |
| 201 if (create_pairing_ && state == protocol::ConnectionToHost::CONNECTED) { | 202 if (create_pairing_ && state == protocol::ConnectionToHost::CONNECTED) { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 | 292 |
| 292 void ChromotingJniInstance::ConnectToHostOnNetworkThread() { | 293 void ChromotingJniInstance::ConnectToHostOnNetworkThread() { |
| 293 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); | 294 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); |
| 294 | 295 |
| 295 client_context_.reset(new ClientContext( | 296 client_context_.reset(new ClientContext( |
| 296 jni_runtime_->network_task_runner().get())); | 297 jni_runtime_->network_task_runner().get())); |
| 297 client_context_->Start(); | 298 client_context_->Start(); |
| 298 | 299 |
| 299 connection_.reset(new protocol::ConnectionToHost(true)); | 300 connection_.reset(new protocol::ConnectionToHost(true)); |
| 300 | 301 |
| 302 SoftwareVideoRenderer* renderer = |
| 303 new SoftwareVideoRenderer(client_context_->main_task_runner(), |
| 304 client_context_->decode_task_runner(), |
| 305 frame_consumer_); |
| 306 view_->set_frame_producer(renderer); |
| 307 video_renderer_.reset(renderer); |
| 308 |
| 301 client_.reset(new ChromotingClient( | 309 client_.reset(new ChromotingClient( |
| 302 client_config_, client_context_.get(), connection_.get(), | 310 client_config_, client_context_.get(), connection_.get(), |
| 303 this, frame_consumer_, scoped_ptr<AudioPlayer>())); | 311 this, video_renderer_.get(), scoped_ptr<AudioPlayer>())); |
| 304 | 312 |
| 305 view_->set_frame_producer(client_->GetFrameProducer()); | |
| 306 | 313 |
| 307 signaling_.reset(new XmppSignalStrategy( | 314 signaling_.reset(new XmppSignalStrategy( |
| 308 net::ClientSocketFactory::GetDefaultFactory(), | 315 net::ClientSocketFactory::GetDefaultFactory(), |
| 309 jni_runtime_->url_requester(), xmpp_config_)); | 316 jni_runtime_->url_requester(), xmpp_config_)); |
| 310 | 317 |
| 311 NetworkSettings network_settings(NetworkSettings::NAT_TRAVERSAL_ENABLED); | 318 NetworkSettings network_settings(NetworkSettings::NAT_TRAVERSAL_ENABLED); |
| 312 | 319 |
| 313 // Use Chrome's network stack to allocate ports for peer-to-peer channels. | 320 // Use Chrome's network stack to allocate ports for peer-to-peer channels. |
| 314 scoped_ptr<ChromiumPortAllocator> port_allocator( | 321 scoped_ptr<ChromiumPortAllocator> port_allocator( |
| 315 ChromiumPortAllocator::Create(jni_runtime_->url_requester(), | 322 ChromiumPortAllocator::Create(jni_runtime_->url_requester(), |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 } | 373 } |
| 367 stats_logging_enabled_ = enabled; | 374 stats_logging_enabled_ = enabled; |
| 368 } | 375 } |
| 369 | 376 |
| 370 void ChromotingJniInstance::LogPerfStats() { | 377 void ChromotingJniInstance::LogPerfStats() { |
| 371 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); | 378 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); |
| 372 | 379 |
| 373 if (!stats_logging_enabled_) | 380 if (!stats_logging_enabled_) |
| 374 return; | 381 return; |
| 375 | 382 |
| 376 ChromotingStats* stats = client_->GetStats(); | 383 ChromotingStats* stats = video_renderer_->GetStats(); |
| 377 __android_log_print(ANDROID_LOG_INFO, "stats", | 384 __android_log_print(ANDROID_LOG_INFO, "stats", |
| 378 "Bandwidth:%.0f FrameRate:%.1f Capture:%.1f Encode:%.1f " | 385 "Bandwidth:%.0f FrameRate:%.1f Capture:%.1f Encode:%.1f " |
| 379 "Decode:%.1f Render:%.1f Latency:%.0f", | 386 "Decode:%.1f Render:%.1f Latency:%.0f", |
| 380 stats->video_bandwidth()->Rate(), | 387 stats->video_bandwidth()->Rate(), |
| 381 stats->video_frame_rate()->Rate(), | 388 stats->video_frame_rate()->Rate(), |
| 382 stats->video_capture_ms()->Average(), | 389 stats->video_capture_ms()->Average(), |
| 383 stats->video_encode_ms()->Average(), | 390 stats->video_encode_ms()->Average(), |
| 384 stats->video_decode_ms()->Average(), | 391 stats->video_decode_ms()->Average(), |
| 385 stats->video_paint_ms()->Average(), | 392 stats->video_paint_ms()->Average(), |
| 386 stats->round_trip_ms()->Average()); | 393 stats->round_trip_ms()->Average()); |
| 387 | 394 |
| 388 jni_runtime_->network_task_runner()->PostDelayedTask( | 395 jni_runtime_->network_task_runner()->PostDelayedTask( |
| 389 FROM_HERE, base::Bind(&ChromotingJniInstance::LogPerfStats, this), | 396 FROM_HERE, base::Bind(&ChromotingJniInstance::LogPerfStats, this), |
| 390 base::TimeDelta::FromMilliseconds(kPerfStatsIntervalMs)); | 397 base::TimeDelta::FromMilliseconds(kPerfStatsIntervalMs)); |
| 391 } | 398 } |
| 392 | 399 |
| 393 } // namespace remoting | 400 } // namespace remoting |
| OLD | NEW |