Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/plugin/chromoting_instance.h" | 5 #include "remoting/client/plugin/chromoting_instance.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #if defined(OS_NACL) | 10 #if defined(OS_NACL) |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 #include "base/threading/thread.h" | 25 #include "base/threading/thread.h" |
| 26 #include "base/values.h" | 26 #include "base/values.h" |
| 27 #include "crypto/random.h" | 27 #include "crypto/random.h" |
| 28 #include "jingle/glue/thread_wrapper.h" | 28 #include "jingle/glue/thread_wrapper.h" |
| 29 #include "media/base/yuv_convert.h" | 29 #include "media/base/yuv_convert.h" |
| 30 #include "net/socket/ssl_server_socket.h" | 30 #include "net/socket/ssl_server_socket.h" |
| 31 #include "ppapi/cpp/completion_callback.h" | 31 #include "ppapi/cpp/completion_callback.h" |
| 32 #include "ppapi/cpp/dev/url_util_dev.h" | 32 #include "ppapi/cpp/dev/url_util_dev.h" |
| 33 #include "ppapi/cpp/image_data.h" | 33 #include "ppapi/cpp/image_data.h" |
| 34 #include "ppapi/cpp/input_event.h" | 34 #include "ppapi/cpp/input_event.h" |
| 35 #include "ppapi/cpp/private/uma_private.h" | |
| 35 #include "ppapi/cpp/rect.h" | 36 #include "ppapi/cpp/rect.h" |
| 36 #include "ppapi/cpp/var_array_buffer.h" | 37 #include "ppapi/cpp/var_array_buffer.h" |
| 37 #include "ppapi/cpp/var_dictionary.h" | 38 #include "ppapi/cpp/var_dictionary.h" |
| 38 #include "remoting/base/constants.h" | 39 #include "remoting/base/constants.h" |
| 39 #include "remoting/base/util.h" | 40 #include "remoting/base/util.h" |
| 40 #include "remoting/client/chromoting_client.h" | 41 #include "remoting/client/chromoting_client.h" |
| 41 #include "remoting/client/plugin/delegating_signal_strategy.h" | 42 #include "remoting/client/plugin/delegating_signal_strategy.h" |
| 42 #include "remoting/client/plugin/normalizing_input_filter_cros.h" | 43 #include "remoting/client/plugin/normalizing_input_filter_cros.h" |
| 43 #include "remoting/client/plugin/normalizing_input_filter_mac.h" | 44 #include "remoting/client/plugin/normalizing_input_filter_mac.h" |
| 44 #include "remoting/client/plugin/pepper_audio_player.h" | 45 #include "remoting/client/plugin/pepper_audio_player.h" |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 60 #undef PostMessage | 61 #undef PostMessage |
| 61 #endif | 62 #endif |
| 62 | 63 |
| 63 namespace remoting { | 64 namespace remoting { |
| 64 | 65 |
| 65 namespace { | 66 namespace { |
| 66 | 67 |
| 67 // Default DPI to assume for old clients that use notifyClientResolution. | 68 // Default DPI to assume for old clients that use notifyClientResolution. |
| 68 const int kDefaultDPI = 96; | 69 const int kDefaultDPI = 96; |
| 69 | 70 |
| 70 // Interval at which to sample performance statistics. | |
| 71 const int kPerfStatsIntervalMs = 1000; | |
| 72 | |
| 73 // URL scheme used by Chrome apps and extensions. | 71 // URL scheme used by Chrome apps and extensions. |
| 74 const char kChromeExtensionUrlScheme[] = "chrome-extension"; | 72 const char kChromeExtensionUrlScheme[] = "chrome-extension"; |
| 75 | 73 |
| 74 // The boundary value for the FPS histogram: we don't expect video frame-rate to | |
| 75 // be greater than 40fps. Leaving some room for future improvements, we'll set | |
| 76 // the max frame rate to 60fps. | |
| 77 // Histograms expect samples to be less than the boundary value, so set to 61. | |
| 78 const int kMaxFramesPerSec = 61; | |
| 79 | |
| 80 // For bandwidth, based on expected real-world numbers, we'll use a histogram | |
| 81 // ranging from 0 to 10MB/s, spread across 100 buckets. | |
| 82 // Histograms are log-scaled by default. This results in fine-grained buckets at | |
| 83 // lower values and wider-ranged buckets closer to the maximum. | |
| 84 // Values above the maximum defined here are not discarded; they end up in the | |
| 85 // max-bucket. | |
| 86 // Also, if the minimum for a UMA histogram is set to be < 1, it is implicitly | |
| 87 // normalized to 1. So we'll set the minimum to 1. | |
|
Wez
2015/07/16 19:03:36
Why not set it to zero and let UMA "implicitly nor
anandc
2015/07/16 20:18:48
Done.
asvitkine@: do you know why UMA normalizes h
Alexei Svitkine (slow)
2015/07/16 20:50:58
I think the comment is a bit confusing. It's not t
| |
| 88 // See $/src/base/metrics/histogram.h for more details. | |
| 89 const int kBandwidthHistogramMinBps = 1; | |
| 90 const int kBandwidthHistogramMaxBps = 10 * 1000 * 1000; | |
| 91 const int kBandwidthHistogramBuckets = 100; | |
| 92 | |
| 76 #if defined(USE_OPENSSL) | 93 #if defined(USE_OPENSSL) |
| 77 // Size of the random seed blob used to initialize RNG in libjingle. Libjingle | 94 // Size of the random seed blob used to initialize RNG in libjingle. Libjingle |
| 78 // uses the seed only for OpenSSL builds. OpenSSL needs at least 32 bytes of | 95 // uses the seed only for OpenSSL builds. OpenSSL needs at least 32 bytes of |
| 79 // entropy (see http://wiki.openssl.org/index.php/Random_Numbers), but stores | 96 // entropy (see http://wiki.openssl.org/index.php/Random_Numbers), but stores |
| 80 // 1039 bytes of state, so we initialize it with 1k or random data. | 97 // 1039 bytes of state, so we initialize it with 1k or random data. |
| 81 const int kRandomSeedSize = 1024; | 98 const int kRandomSeedSize = 1024; |
| 82 #endif // defined(USE_OPENSSL) | 99 #endif // defined(USE_OPENSSL) |
| 83 | 100 |
| 84 std::string ConnectionStateToString(protocol::ConnectionToHost::State state) { | 101 std::string ConnectionStateToString(protocol::ConnectionToHost::State state) { |
| 85 // Values returned by this function must match the | 102 // Values returned by this function must match the |
| (...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 725 fetch_secret_callback, token_fetcher.Pass(), auth_methods)); | 742 fetch_secret_callback, token_fetcher.Pass(), auth_methods)); |
| 726 | 743 |
| 727 // Kick off the connection. | 744 // Kick off the connection. |
| 728 client_->Start(signal_strategy_.get(), authenticator.Pass(), | 745 client_->Start(signal_strategy_.get(), authenticator.Pass(), |
| 729 transport_factory.Pass(), host_jid, capabilities); | 746 transport_factory.Pass(), host_jid, capabilities); |
| 730 | 747 |
| 731 // Start timer that periodically sends perf stats. | 748 // Start timer that periodically sends perf stats. |
| 732 plugin_task_runner_->PostDelayedTask( | 749 plugin_task_runner_->PostDelayedTask( |
| 733 FROM_HERE, base::Bind(&ChromotingInstance::SendPerfStats, | 750 FROM_HERE, base::Bind(&ChromotingInstance::SendPerfStats, |
| 734 weak_factory_.GetWeakPtr()), | 751 weak_factory_.GetWeakPtr()), |
| 735 base::TimeDelta::FromMilliseconds(kPerfStatsIntervalMs)); | 752 base::TimeDelta::FromSeconds( |
| 753 ChromotingStats::kStatsUpdateFrequencyInSeconds)); | |
| 736 } | 754 } |
| 737 | 755 |
| 738 void ChromotingInstance::HandleDisconnect(const base::DictionaryValue& data) { | 756 void ChromotingInstance::HandleDisconnect(const base::DictionaryValue& data) { |
| 739 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); | 757 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); |
| 740 Disconnect(); | 758 Disconnect(); |
| 741 } | 759 } |
| 742 | 760 |
| 743 void ChromotingInstance::HandleOnIncomingIq(const base::DictionaryValue& data) { | 761 void ChromotingInstance::HandleOnIncomingIq(const base::DictionaryValue& data) { |
| 744 std::string iq; | 762 std::string iq; |
| 745 if (!data.GetString("iq", &iq)) { | 763 if (!data.GetString("iq", &iq)) { |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1045 } | 1063 } |
| 1046 | 1064 |
| 1047 void ChromotingInstance::SendPerfStats() { | 1065 void ChromotingInstance::SendPerfStats() { |
| 1048 if (!video_renderer_.get()) { | 1066 if (!video_renderer_.get()) { |
| 1049 return; | 1067 return; |
| 1050 } | 1068 } |
| 1051 | 1069 |
| 1052 plugin_task_runner_->PostDelayedTask( | 1070 plugin_task_runner_->PostDelayedTask( |
| 1053 FROM_HERE, base::Bind(&ChromotingInstance::SendPerfStats, | 1071 FROM_HERE, base::Bind(&ChromotingInstance::SendPerfStats, |
| 1054 weak_factory_.GetWeakPtr()), | 1072 weak_factory_.GetWeakPtr()), |
| 1055 base::TimeDelta::FromMilliseconds(kPerfStatsIntervalMs)); | 1073 base::TimeDelta::FromSeconds( |
| 1074 ChromotingStats::kStatsUpdateFrequencyInSeconds)); | |
| 1056 | 1075 |
| 1076 // Fetch performance stats from the VideoRenderer and send them to the client | |
| 1077 // for display to users. | |
| 1057 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); | 1078 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); |
| 1058 ChromotingStats* stats = video_renderer_->GetStats(); | 1079 ChromotingStats* stats = video_renderer_->GetStats(); |
| 1059 data->SetDouble("videoBandwidth", stats->video_bandwidth()->Rate()); | 1080 data->SetDouble("videoBandwidth", stats->video_bandwidth()->Rate()); |
| 1060 data->SetDouble("videoFrameRate", stats->video_frame_rate()->Rate()); | 1081 data->SetDouble("videoFrameRate", stats->video_frame_rate()->Rate()); |
| 1061 data->SetDouble("captureLatency", stats->video_capture_ms()->Average()); | 1082 data->SetDouble("captureLatency", stats->video_capture_ms()->Average()); |
| 1062 data->SetDouble("encodeLatency", stats->video_encode_ms()->Average()); | 1083 data->SetDouble("encodeLatency", stats->video_encode_ms()->Average()); |
| 1063 data->SetDouble("decodeLatency", stats->video_decode_ms()->Average()); | 1084 data->SetDouble("decodeLatency", stats->video_decode_ms()->Average()); |
| 1064 data->SetDouble("renderLatency", stats->video_paint_ms()->Average()); | 1085 data->SetDouble("renderLatency", stats->video_paint_ms()->Average()); |
| 1065 data->SetDouble("roundtripLatency", stats->round_trip_ms()->Average()); | 1086 data->SetDouble("roundtripLatency", stats->round_trip_ms()->Average()); |
| 1066 PostLegacyJsonMessage("onPerfStats", data.Pass()); | 1087 PostLegacyJsonMessage("onPerfStats", data.Pass()); |
| 1088 | |
| 1089 // Record the video frame-rate, packet-rate and bandwidth stats to UMA. | |
| 1090 pp::UMAPrivate uma(this); | |
| 1091 uma.HistogramEnumeration("Chromoting.Video.FrameRate", | |
| 1092 stats->video_frame_rate()->Rate(), kMaxFramesPerSec); | |
| 1093 uma.HistogramEnumeration("Chromoting.Video.PacketRate", | |
| 1094 stats->video_packet_rate()->Rate(), | |
| 1095 kMaxFramesPerSec); | |
| 1096 uma.HistogramCustomCounts( | |
| 1097 "Chromoting.Video.Bandwidth", stats->video_bandwidth()->Rate(), | |
| 1098 kBandwidthHistogramMinBps, kBandwidthHistogramMaxBps, | |
| 1099 kBandwidthHistogramBuckets); | |
| 1067 } | 1100 } |
| 1068 | 1101 |
| 1069 // static | 1102 // static |
| 1070 void ChromotingInstance::RegisterLogMessageHandler() { | 1103 void ChromotingInstance::RegisterLogMessageHandler() { |
| 1071 base::AutoLock lock(g_logging_lock.Get()); | 1104 base::AutoLock lock(g_logging_lock.Get()); |
| 1072 | 1105 |
| 1073 VLOG(1) << "Registering global log handler"; | 1106 VLOG(1) << "Registering global log handler"; |
| 1074 | 1107 |
| 1075 // Record previous handler so we can call it in a chain. | 1108 // Record previous handler so we can call it in a chain. |
| 1076 g_logging_old_handler = logging::GetLogMessageHandler(); | 1109 g_logging_old_handler = logging::GetLogMessageHandler(); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1196 | 1229 |
| 1197 #if !defined(OS_NACL) | 1230 #if !defined(OS_NACL) |
| 1198 // Log messages are forwarded to the webapp only in PNaCl version of the | 1231 // Log messages are forwarded to the webapp only in PNaCl version of the |
| 1199 // plugin, so ProcessLogToUI() needs to be called explicitly in the non-PNaCl | 1232 // plugin, so ProcessLogToUI() needs to be called explicitly in the non-PNaCl |
| 1200 // version. | 1233 // version. |
| 1201 ProcessLogToUI(message); | 1234 ProcessLogToUI(message); |
| 1202 #endif // !defined(OS_NACL) | 1235 #endif // !defined(OS_NACL) |
| 1203 } | 1236 } |
| 1204 | 1237 |
| 1205 } // namespace remoting | 1238 } // namespace remoting |
| OLD | NEW |