Skip to content

Commit

Permalink
Merge pull request #1 from orangebook/feat/rtpCount
Browse files Browse the repository at this point in the history
rtp count
  • Loading branch information
退之 authored Dec 11, 2018
2 parents 13438a5 + d00c144 commit 2530064
Show file tree
Hide file tree
Showing 8 changed files with 1,709 additions and 11 deletions.
3 changes: 2 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ module.exports = function(grunt) {
'dev/remote-candidate.js',
'dev/dataSentReceived.js',
'dev/ssrc.js',
'dev/tail.js'
'dev/bound-rtp.js',
'dev/tail.js',
],
dest: 'getStats.js',
},
Expand Down
23 changes: 23 additions & 0 deletions dev/bound-rtp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* statistical pliCount,nackCount,firCount adapter for `Android Webrtc SDK`
* {
* googPlisSent(googPlisReceived): pliCount,
* googNacksSent(googNacksSent): nackCount,
* googFirsSent(googFirsSent): firCount
* }
* @param {*} result
*/
getStatsParser.boundRtp = function(result) {

if (result.type == 'inbound-rtp') {
creatVideoCounter(result, 'nackCount', 'recv', '+', 1, 'googNacksReceived');
creatVideoCounter(result, 'pliCount', 'recv', '+', 1, 'googPlisReceived');
creatVideoCounter(result, 'firCount', 'recv', '+', 1, 'googFirsReceived');
}

if (result.type == 'outbound-rtp') {
creatVideoCounter(result, 'nackCount', 'send', '+', 1, 'googNacksSent');
creatVideoCounter(result, 'pliCount', 'send', '+', 1, 'googPlisSent');
creatVideoCounter(result, 'firCount', 'send', '+', 1, 'googFirsSent');
}
}
36 changes: 34 additions & 2 deletions dev/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,19 @@ var getStatsResult = {
tracks: [],
codecs: [],
availableBandwidth: 0,
streams: 0
streams: 0,
googNacksSent: 0,
googPlisSent: 0,
googFirsReceived: 0
},
recv: {
tracks: [],
codecs: [],
availableBandwidth: 0,
streams: 0
streams: 0,
googNacksReceived: 0,
googPlisReceived: 0,
googFirsReceived: 0
},
bytesSent: 0,
bytesReceived: 0
Expand Down Expand Up @@ -113,3 +119,29 @@ var getStatsParser = {
}
}
};

/**
* Video Counter helper function
* @param {*} paramName
* @param {*} op - default `+`
* @param {*} scale - default 1
* @param {*} userFiled - default paramName
* @returns {NULL}
*/
function creatVideoCounter(result, paramName, type, op, scale, userFiled) {
// 当参数合并后,根据 googNacksSent 来判断recv/send Kb Mb Gb
if (!!result[paramName] && result[paramName] !== '0') {
var Count = 0;
if (!getStatsResult.internal.video[type]['prev' + paramName] || getStatsResult.internal.video[type]['prev' + paramName] > result[paramName]) {
getStatsResult.internal.video[type]['prev' + paramName] = result[paramName];
}
if ((op || '+') === '+') {
Count = result[paramName] + getStatsResult.internal.video[type]['prev' + paramName];
} else {
Count = result[paramName] - getStatsResult.internal.video[type]['prev' + paramName];
}
getStatsResult.internal.video[type]['prev' + paramName] = result[paramName];
return getStatsResult.video[type][userFiled || paramName] = Count * (scale || 1);
}
return;
}
7 changes: 6 additions & 1 deletion dev/ssrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ getStatsParser.ssrc = function(result) {
if (SSRC[result.mediaType][sendrecvType].indexOf(result.ssrc) === -1) {
SSRC[result.mediaType][sendrecvType].push(result.ssrc)
}

creatVideoCounter(result, 'googNacksSent', 'send');
creatVideoCounter(result, 'googPlisSent', 'send');
creatVideoCounter(result, 'googFirsSent', 'send');
creatVideoCounter(result, 'googNacksReceived', 'recv');
creatVideoCounter(result, 'googPlisReceived', 'recv');
creatVideoCounter(result, 'googFirsReceived', 'recv');
getStatsResult[result.mediaType][sendrecvType].streams = SSRC[result.mediaType][sendrecvType].length;
};
60 changes: 56 additions & 4 deletions getStats.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

// Last time updated: 2018-11-26 6:19:49 AM UTC
// Last time updated: 2018-12-10 9:49:44 AM UTC

// _______________
// getStats v1.0.10
Expand Down Expand Up @@ -45,13 +45,19 @@ window.getStats = function(mediaStreamTrack, callback, interval) {
tracks: [],
codecs: [],
availableBandwidth: 0,
streams: 0
streams: 0,
googNacksSent: 0,
googPlisSent: 0,
googFirsReceived: 0
},
recv: {
tracks: [],
codecs: [],
availableBandwidth: 0,
streams: 0
streams: 0,
googNacksReceived: 0,
googPlisReceived: 0,
googFirsReceived: 0
},
bytesSent: 0,
bytesReceived: 0
Expand Down Expand Up @@ -130,6 +136,32 @@ window.getStats = function(mediaStreamTrack, callback, interval) {
}
};

/**
* Video Counter helper function
* @param {*} paramName
* @param {*} op - default `+`
* @param {*} scale - default 1
* @param {*} userFiled - default paramName
* @returns {NULL}
*/
function creatVideoCounter(result, paramName, type, op, scale, userFiled) {
// 当参数合并后,根据 googNacksSent 来判断recv/send Kb Mb Gb
if (!!result[paramName] && result[paramName] !== '0') {
var Count = 0;
if (!getStatsResult.internal.video[type]['prev' + paramName] || getStatsResult.internal.video[type]['prev' + paramName] > result[paramName]) {
getStatsResult.internal.video[type]['prev' + paramName] = result[paramName];
}
if ((op || '+') === '+') {
Count = result[paramName] + getStatsResult.internal.video[type]['prev' + paramName];
} else {
Count = result[paramName] - getStatsResult.internal.video[type]['prev' + paramName];
}
getStatsResult.internal.video[type]['prev' + paramName] = result[paramName];
return getStatsResult.video[type][userFiled || paramName] = Count * (scale || 1);
}
return;
}

function preHandler(result) {
// 根据codeId\trackId映射 - 处理关联关系
var idMap = result.reduce(function(map, item) {
Expand Down Expand Up @@ -649,10 +681,30 @@ window.getStats = function(mediaStreamTrack, callback, interval) {
if (SSRC[result.mediaType][sendrecvType].indexOf(result.ssrc) === -1) {
SSRC[result.mediaType][sendrecvType].push(result.ssrc)
}

creatVideoCounter(result, 'googNacksSent', 'send');
creatVideoCounter(result, 'googPlisSent', 'send');
creatVideoCounter(result, 'googFirsSent', 'send');
creatVideoCounter(result, 'googNacksReceived', 'recv');
creatVideoCounter(result, 'googPlisReceived', 'recv');
creatVideoCounter(result, 'googFirsReceived', 'recv');
getStatsResult[result.mediaType][sendrecvType].streams = SSRC[result.mediaType][sendrecvType].length;
};

getStatsParser.boundRtp = function(result) {

if (result.type == 'inbound-rtp') {
creatVideoCounter(result, 'nackCount', 'recv', '+', 1, 'googNacksReceived');
creatVideoCounter(result, 'pliCount', 'recv', '+', 1, 'googPlisReceived');
creatVideoCounter(result, 'firCount', 'recv', '+', 1, 'googFirsReceived');
}

if (result.type == 'outbound-rtp') {
creatVideoCounter(result, 'nackCount', 'send', '+', 1, 'googNacksSent');
creatVideoCounter(result, 'pliCount', 'send', '+', 1, 'googPlisSent');
creatVideoCounter(result, 'firCount', 'send', '+', 1, 'googFirsSent');
}
}

getStatsLooper();

};
4 changes: 2 additions & 2 deletions getStats.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit 2530064

Please sign in to comment.