Bandwidth stats display in constraints-and-stats.

Also shows off the report type and ID field, and logs less useless info.

BUG=

Review URL: https://webrtc-codereview.appspot.com/1212007

git-svn-id: http://webrtc.googlecode.com/svn/trunk@3706 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
hta@webrtc.org 2013-03-22 08:48:16 +00:00
parent 999e900fb6
commit 3ed599adb5

View File

@ -8,6 +8,8 @@
var mystream; var mystream;
var pc1; var pc1;
var pc2; var pc2;
var bytesPrev = 0;
var timestampPrev = 0;
$ = function(id) { $ = function(id) {
return document.getElementById(id); return document.getElementById(id);
@ -117,12 +119,10 @@ var statCollector = setInterval(function() {
display("No stream"); display("No stream");
if (pc2 && pc2.getRemoteStreams()[0]) { if (pc2 && pc2.getRemoteStreams()[0]) {
if (pc2.getStats) { if (pc2.getStats) {
display('No stats callback');
pc2.getStats(function(stats) { pc2.getStats(function(stats) {
log('Raw stats ' + stats);
var statsString = ''; var statsString = '';
var results = stats.result(); var results = stats.result();
log('Raw results ' + results); var bitrateText = 'No bitrate stats';
for (var i = 0; i < results.length; ++i) { for (var i = 0; i < results.length; ++i) {
var res = results[i]; var res = results[i];
statsString += '<h3>Report '; statsString += '<h3>Report ';
@ -130,6 +130,20 @@ var statCollector = setInterval(function() {
statsString += '</h3>'; statsString += '</h3>';
if (!res.local || res.local === res) { if (!res.local || res.local === res) {
statsString += dumpStats(res); statsString += dumpStats(res);
// The bandwidth info for video is in a type ssrc stats record
// with googFrameHeightReceived defined.
// Should check for mediatype = video, but this is not
// implemented yet.
if (res.type == 'ssrc' && res.stat('googFrameHeightReceived')) {
var bytesNow = res.stat('bytesReceived');
if (timestampPrev > 0) {
var bitRate = Math.round((bytesNow - bytesPrev) * 8 /
(res.timestamp - timestampPrev));
bitrateText = bitRate + ' kbits/sec';
}
timestampPrev = res.timestamp;
bytesPrev = bytesNow;
}
} else { } else {
// Pre-227.0.1445 (188719) browser // Pre-227.0.1445 (188719) browser
if (res.local) { if (res.local) {
@ -143,7 +157,7 @@ var statCollector = setInterval(function() {
} }
} }
$('stats').innerHTML = statsString; $('stats').innerHTML = statsString;
display('No bitrate stats'); display(bitrateText);
}); });
} else { } else {
display('No stats function. Use at least Chrome 24.0.1285'); display('No stats function. Use at least Chrome 24.0.1285');
@ -169,8 +183,15 @@ var statCollector = setInterval(function() {
function dumpStats(obj) { function dumpStats(obj) {
var statsString = 'Timestamp:'; var statsString = 'Timestamp:';
statsString += obj.timestamp; statsString += obj.timestamp;
if (obj.id) {
statsString += " id ";
statsString += obj.id;
}
if (obj.type) {
statsString += " type ";
statsString += obj.type;
}
if (obj.names) { if (obj.names) {
log('Have names function');
names = obj.names(); names = obj.names();
for (var i = 0; i < names.length; ++i) { for (var i = 0; i < names.length; ++i) {
statsString += '<br>'; statsString += '<br>';
@ -179,7 +200,6 @@ function dumpStats(obj) {
statsString += obj.stat(names[i]); statsString += obj.stat(names[i]);
} }
} else { } else {
log('No names function');
if (obj.stat('audioOutputLevel')) { if (obj.stat('audioOutputLevel')) {
statsString += "audioOutputLevel: "; statsString += "audioOutputLevel: ";
statsString += obj.stat('audioOutputLevel'); statsString += obj.stat('audioOutputLevel');