Embed: added jitter buffer latency to dev skin output for webrtc player

This commit is contained in:
Cat 2020-09-03 14:52:52 +02:00 committed by Thulinma
parent fc0ad25778
commit 4b56936845
4 changed files with 70 additions and 3 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -429,7 +429,7 @@ MistSkins["default"] = {
}
MistUtil.event.addListener(MistVideo.video,"volumechange",fu);
});
},function(){});
}
}
});
@ -2198,6 +2198,13 @@ MistSkins.dev = {
label.set = function(val){
if (val !== 0) { this.style.display = ""; }
if (typeof val == "object") {
if (val instanceof Promise) {
val.then(function(val){
label.set(val)
},function(){});
return;
}
if ("val" in val) {
value.nodeValue = val.val;
valuec.className = "value";
@ -2329,6 +2336,26 @@ MistSkins.dev = {
if (MistVideo.player.api) {
return MistUtil.format.bytes(MistVideo.player.api.bytesReceived);
}
},
"Local latency [ms]": function(){
if ((MistVideo.player.api) && ("getLatency" in MistVideo.player.api)) {
var p = MistVideo.player.api.getLatency();
if (p) {
return new Promise(function(resolve,reject) {
p.then(function(result){
var r = [];
for (var i in result) {
if (result[i]) {
r.push(i[0]+Math.round(result[i]*1e3));
}
}
if (r.length) { resolve(r.join(" ")); }
else { resolve(); }
},reject)
});
}
return new Promise(function(resolve,reject){resolve();},function(){});
}
}
};
var updates = [];

View file

@ -532,6 +532,46 @@ p.prototype.build = function (MistVideo,callback) {
}
};
me.api.getStats = function(){
if (me.webrtc && me.webrtc.isConnected) {
return new Promise(function(resolve,reject) {
me.webrtc.peerConn.getStats().then((a) => {
var r = {
audio: null,
video: null
};
for (let dictionary of a.values()) {
if (dictionary.type == "track") {
//average jitter buffer in seconds
r[dictionary.kind] = dictionary;
}
}
resolve(r);
})
});
}
};
me.api.getLatency = function() {
var p = MistVideo.player.api.getStats();
if (p) {
return new Promise(function(resolve,reject){
p.then(function(first){
setTimeout(function(){
var p = me.api.getStats();
if (!p) { reject(); return; }
p.then(function(last){
var r = {};
for (var i in first) {
r[i] = first[i] && last[i] ? (last[i].jitterBufferDelay - first[i].jitterBufferDelay) / (last[i].jitterBufferEmittedCount - first[i].jitterBufferEmittedCount) : null;
}
resolve(r);
},reject);
},1e3);
},reject);
});
}
}
//redirect pause
me.api.pause = function(){
video.pause();