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.
18 * @param {remoting.ClientPlugin} plugin
20 * @implements {remoting.WindowShape.ClientUI}
21 * @implements {base.Disposable}
23 remoting
.ConnectionStats = function(statsElement
, plugin
) {
25 this.statsElement_
= statsElement
;
27 /** @private {remoting.ClientSession.PerfStats} */
28 this.mostRecent_
= null
31 this.plugin_
= plugin
;
36 this.timer_
= new base
.RepeatingTimer(function(){
37 that
.update(plugin
.getPerfStats());
40 remoting
.windowShape
.addCallback(this);
43 remoting
.ConnectionStats
.prototype.dispose = function() {
44 base
.dispose(this.timer_
);
50 * @return {remoting.ClientSession.PerfStats} The most recently-set PerfStats,
51 * or null if update() has not yet been called.
53 remoting
.ConnectionStats
.prototype.mostRecent = function() {
54 return this.mostRecent_
;
58 * Show or hide the connection stats div.
60 remoting
.ConnectionStats
.prototype.toggle = function() {
61 this.statsElement_
.hidden
= !this.statsElement_
.hidden
;
67 remoting
.ConnectionStats
.prototype.isVisible = function() {
68 return !this.statsElement_
.hidden
;
72 * Show or hide the connection stats div.
73 * @param {boolean} show
75 remoting
.ConnectionStats
.prototype.show = function(show
) {
76 this.statsElement_
.hidden
= !show
;
80 * If the stats panel is visible, add its bounding rectangle to the specified
82 * @param {Array<{left: number, top: number, width: number, height: number}>}
83 * rects List of rectangles.
86 remoting
.ConnectionStats
.prototype.addToRegion = function(rects
) {
87 if (!this.statsElement_
.hidden
) {
88 rects
.push(this.statsElement_
.getBoundingClientRect());
93 * Update the statistics panel.
94 * @param {remoting.ClientSession.PerfStats} stats The connection statistics.
96 remoting
.ConnectionStats
.prototype.update = function(stats
) {
97 this.mostRecent_
= stats
;
99 var videoBandwidth
= stats
.videoBandwidth
;
100 if (videoBandwidth
!= undefined) {
101 if (videoBandwidth
< 1024) {
103 } else if (videoBandwidth
< 1048576) {
105 videoBandwidth
= videoBandwidth
/ 1024;
106 } else if (videoBandwidth
< 1073741824) {
108 videoBandwidth
= videoBandwidth
/ 1048576;
111 videoBandwidth
= videoBandwidth
/ 1073741824;
116 * @param {number} value
117 * @param {string} units
118 * @return {string} Formatted number.
120 function formatStatNumber(value
, units
) {
121 if (value
!= undefined) {
122 return value
.toFixed(2) + ' ' + units
;
128 var statistics
= document
.getElementById('statistics');
129 this.statsElement_
.innerText
= (
130 'Bandwidth: ' + formatStatNumber(videoBandwidth
, units
) +
131 ', Frame Rate: ' + formatStatNumber(stats
.videoFrameRate
, 'fps') +
132 ', Capture: ' + formatStatNumber(stats
.captureLatency
, 'ms') +
133 ', Encode: ' + formatStatNumber(stats
.encodeLatency
, 'ms') +
134 ', Decode: ' + formatStatNumber(stats
.decodeLatency
, 'ms') +
135 ', Render: ' + formatStatNumber(stats
.renderLatency
, 'ms') +
136 ', Latency: ' + formatStatNumber(stats
.roundtripLatency
, 'ms'));