Embed: mews: disable ABR when the viewer has selected a specific video track

This commit is contained in:
Cat 2021-08-05 15:33:09 +02:00 committed by Thulinma
parent e17420534d
commit 2f12c9fca7
7 changed files with 135 additions and 26 deletions

View file

@ -727,8 +727,6 @@ p.prototype.build = function (MistVideo,callback) {
}
var data = new Uint8Array(e.data);
if (data) {
//if (new Date().getTime() - MistVideo.bootMs > 15e3) { data.fill(0,0,Math.floor(data.length*0.1)); } //corrupt the data pl0x :D
if (player.monitor && player.monitor.bitCounter) {
for (var i in player.monitor.bitCounter) {
player.monitor.bitCounter[i] += e.data.byteLength*8;
@ -902,6 +900,7 @@ p.prototype.build = function (MistVideo,callback) {
if (player.sb) { player.sb.paused = true; }
},
setTracks: function(obj){
if (!MistUtil.object.keys(obj).length) { return; }
obj.type = "tracks";
obj = MistUtil.object.extend({
type: "tracks",
@ -1063,22 +1062,62 @@ p.prototype.build = function (MistVideo,callback) {
});
}
this.ABR = {
size: null,
bitrate: null,
generateString: function(type,raw){
switch (type) {
case "size": {
return "~"+[raw.width,raw.height].join("x");
}
case "bitrate": {
return "<"+Math.round(raw)+"bps,minbps";
}
default: {
throw "Unknown ABR type";
}
}
},
request: function(type,value){
this[type] = value;
var request = [];
if (this.bitrate !== null) {
request.push(this.generateString("bitrate",this.bitrate));
}
if (this.size !== null) {
request.push(this.generateString("size",this.size));
}
else {
request.push("maxbps");
}
return player.api.setTracks({
video: request.join(",|")
});
}
}
this.api.ABR_resize = function(size){
MistVideo.log("Requesting the video track with the resolution that best matches the player size");
player.ABR.request("size",size);
};
//ABR: monitor playback issues and switch to lower bitrate track if available
//NB: this ABR requests a lower bitrate if needed, but it can never go back up
this.monitor = {
bitCounter: [],
bitsSince: [],
currentBps: null,
nWaiting: 0,
nWaitingThreshold: 3,
listener: MistUtil.event.addListener(video,"waiting",function(){
listener: MistVideo.options.ABR_bitrate ? MistUtil.event.addListener(video,"waiting",function(){
player.monitor.nWaiting++;
if (player.monitor.nWaiting >= player.monitor.nWaitingThreshold) {
player.monitor.nWaiting = 0;
MistVideo.log("ABR threshold triggered, requesting lower quality");
player.monitor.action();
}
}),
}) : null,
getBitRate: function(){
if (player.sb && !player.sb.paused) {
@ -1098,18 +1137,20 @@ p.prototype.build = function (MistVideo,callback) {
var dt = new Date().getTime() - since;
this.currentBps = bits / (dt*1e-3);
//console.log(MistUtil.format.bytes(this.currentBps)+"its/s");
//console.log(MistUtil.format.bits(this.currentBps)+"its/s");
}
MistVideo.timers.start(function(){
player.monitor.getBitRate();
},500);
},
action: function(){
player.api.setTracks({video:"max<"+Math.round(this.currentBps)+"bps"});
if (MistVideo.options.setTracks && MistVideo.options.setTracks.video) {
//a video track was selected by the user, do not change it
return;
}
MistVideo.log("ABR threshold triggered, requesting lower quality");
player.ABR.request("bitrate",this.currentBps);
}
};
this.monitor.getBitRate();
};

View file

@ -724,6 +724,11 @@ p.prototype.build = function (MistVideo,callback) {
};
f();
}
me.api.ABR_resize = function(size){
MistVideo.log("Requesting the video track with the resolution that best matches the player size");
me.api.setTracks({video:"~"+[size.width,size.height].join("x")});
};
me.api.unload = function(){
try {