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
3 // found in the LICENSE file.
7 * Module to support debug overlay window with connection stats.
12 /** @suppress {duplicate} */
13 var remoting
= remoting
|| {};
17 * @param {Element} statsElement The HTML div to which to update stats.
19 remoting
.ConnectionStats = function(statsElement
) {
20 this.statsElement
= statsElement
;
24 * Show or hide the connection stats div.
26 remoting
.ConnectionStats
.prototype.toggle = function() {
27 this.statsElement
.hidden
= !this.statsElement
.hidden
;
31 * Update the statistics panel.
32 * @param {remoting.ClientSession.PerfStats} stats The connection statistics.
34 remoting
.ConnectionStats
.prototype.update = function(stats
) {
36 var videoBandwidth
= stats
.videoBandwidth
;
37 if (videoBandwidth
!= undefined) {
38 if (videoBandwidth
< 1024) {
40 } else if (videoBandwidth
< 1048576) {
42 videoBandwidth
= videoBandwidth
/ 1024;
43 } else if (videoBandwidth
< 1073741824) {
45 videoBandwidth
= videoBandwidth
/ 1048576;
48 videoBandwidth
= videoBandwidth
/ 1073741824;
53 * @param {number} value
54 * @param {string} units
55 * @return {string} Formatted number.
57 function formatStatNumber(value
, units
) {
58 if (value
!= undefined) {
59 return value
.toFixed(2) + ' ' + units
;
65 var statistics
= document
.getElementById('statistics');
66 this.statsElement
.innerText
= (
67 'Bandwidth: ' + formatStatNumber(videoBandwidth
, units
) +
68 ', Frame Rate: ' + formatStatNumber(stats
.videoFrameRate
, 'fps') +
69 ', Capture: ' + formatStatNumber(stats
.captureLatency
, 'ms') +
70 ', Encode: ' + formatStatNumber(stats
.encodeLatency
, 'ms') +
71 ', Decode: ' + formatStatNumber(stats
.decodeLatency
, 'ms') +
72 ', Render: ' + formatStatNumber(stats
.renderLatency
, 'ms') +
73 ', Latency: ' + formatStatNumber(stats
.roundtripLatency
, 'ms'));
77 * Check for the debug toggle hot-key.
79 * @param {Event} event The keyboard event.
80 * @return {void} Nothing.
82 remoting
.ConnectionStats
.onKeydown = function(event
) {
83 var element
= /** @type {Element} */ (event
.target
);
84 if (element
.tagName
== 'INPUT' || element
.tagName
== 'TEXTAREA') {
87 if (String
.fromCharCode(event
.which
) == 'D') {
88 remoting
.stats
.toggle();
92 /** @type {remoting.ConnectionStats} */
93 remoting
.stats
= null;