RAM leak issue should be fixed for the most part. We did it ~~reddit~~github! (NOTE: there's still other things that need fixing before I let this into prod)

This commit is contained in:
Tamius Han 2018-03-08 22:22:42 +01:00
parent 93d3b064da
commit 7db22fb466
5 changed files with 53 additions and 31 deletions

View File

@ -106,8 +106,8 @@ var Settings = {
period: 2.0 // per this period period: 2.0 // per this period
}, },
edgeDetection: { edgeDetection: {
sampleWidth: 20, // we take a sample this wide for edge detection sampleWidth: 8, // we take a sample this wide for edge detection
detectionTreshold: 10, // sample needs to have this many non-black pixels to be a valid edge detectionTreshold: 4, // sample needs to have this many non-black pixels to be a valid edge
singleSideConfirmationTreshold: 0.3, // we need this much edges (out of all samples, not just edges) in order singleSideConfirmationTreshold: 0.3, // we need this much edges (out of all samples, not just edges) in order
// to confirm an edge in case there's no edges on top or bottom (other // to confirm an edge in case there's no edges on top or bottom (other
// than logo, of course) // than logo, of course)

View File

@ -148,6 +148,7 @@ var _arSetup = function(cwidth, cheight){
GlobalVars.canvas.width = canvasWidth; GlobalVars.canvas.width = canvasWidth;
GlobalVars.canvas.height = canvasHeight; GlobalVars.canvas.height = canvasHeight;
GlobalVars.canvas.imageDataRowLength = canvasWidth * 4; GlobalVars.canvas.imageDataRowLength = canvasWidth * 4;
GlobalVars.arDetect.noLetterboxCanvasReset = false;
_ard_vdraw(0); _ard_vdraw(0);
} }
catch(ex){ catch(ex){
@ -268,11 +269,13 @@ var _ard_vdraw = function (timeout, force_reset){
var executions = 0; var executions = 0;
setInterval(function(){ if(Debug.debug){
console.log("STATS FOR LAST SECOND\nexecutions:", executions,"; vdraw timeouts cleared:", clearTimeoutCount); setInterval(function(){
executions = 0; console.log("STATS FOR LAST SECOND\nexecutions:", executions,"; vdraw timeouts cleared:", clearTimeoutCount);
clearTimeoutCount = 0; executions = 0;
}, 1000); clearTimeoutCount = 0;
}, 1000);
}
var _ard_vdraw_but_for_reals = function() { var _ard_vdraw_but_for_reals = function() {
// thanks dude: // thanks dude:
@ -299,12 +302,18 @@ var _ard_vdraw_but_for_reals = function() {
var how_far_treshold = 8; // how much can the edge pixel vary (*4) var how_far_treshold = 8; // how much can the edge pixel vary (*4)
if(GlobalVars.video == null || GlobalVars.video.paused || GlobalVars.video.ended || Status.arStrat != "auto"){ if(GlobalVars.video == null || GlobalVars.video.ended || Status.arStrat != "auto"){
// we slow down if paused, no detection // we slow down if ended, null, or not auto. Detecting is pointless.
_ard_vdraw(Settings.arDetect.timer_paused); _ard_vdraw(Settings.arDetect.timer_paused);
return false; return false;
} }
if(GlobalVars.video.paused){
// if the video is paused, we still do autodetection. We just increase the interval.
baseTimeout = Settings.arDetect.timer_paused;
}
try{ try{
GlobalVars.canvas.context.drawImage(GlobalVars.video, 0,0, GlobalVars.canvas.width, GlobalVars.canvas.height); GlobalVars.canvas.context.drawImage(GlobalVars.video, 0,0, GlobalVars.canvas.width, GlobalVars.canvas.height);
} }
@ -416,18 +425,31 @@ var _ard_vdraw_but_for_reals = function() {
if(Debug.debug){ if(Debug.debug){
console.log("%c[ArDetect::_ard_vdraw] no edge detected. canvas has no edge.", "color: #aaf"); console.log("%c[ArDetect::_ard_vdraw] no edge detected. canvas has no edge.", "color: #aaf");
} }
image = null; image = null;
Resizer.reset(); // Pogledamo, ali smo že kdaj ponastavili CSS. Če še nismo, potem to storimo. Če smo že, potem ne.
GlobalVars.lastAr = {type: "auto", ar: null}; // Ponastavimo tudi guardline (na null).
// let's chec if we ever reset CSS. If we haven't, then we do so. If we did, then we don't.
// while resetting the CSS, we also reset guardline top and bottom back to null.
if(! GlobalVars.arDetect.noLetterboxCanvasReset){
Resizer.reset();
GlobalVars.lastAr = {type: "auto", ar: null};
GlobalVars.arDetect.guardLine.top = null;
GlobalVars.arDetect.guardLine.bottom = null;
GlobalVars.arDetect.noLetterboxCanvasReset = true;
}
triggerTimeout = _ard_getTimeout(baseTimeout, startTime); triggerTimeout = _ard_getTimeout(baseTimeout, startTime);
_ard_vdraw(triggerTimeout); //no letterbox, no problem _ard_vdraw(triggerTimeout); //no letterbox, no problem
return; return;
} }
// Če preverjamo naprej, potem moramo postaviti to vrednost nazaj na 'false'. V nasprotnem primeru se bo
// css resetiral enkrat na video/pageload namesto vsakič, ko so za nekaj časa obrobe odstranejene
// if we look further we need to reset this value back to false. Otherwise we'll only get CSS reset once
// per video/pageload instead of every time letterbox goes away (this can happen more than once per vid)
GlobalVars.arDetect.noLetterboxCanvasReset = false;
// let's do a quick test to see if we're on a black frame // let's do a quick test to see if we're on a black frame
// TODO: reimplement but with less bullshit // TODO: reimplement but with less bullshit
@ -453,6 +475,9 @@ var _ard_vdraw_but_for_reals = function() {
// če sta obe funkciji uspeli, potem se razmerje stranic ni spremenilo. // če sta obe funkciji uspeli, potem se razmerje stranic ni spremenilo.
// if both succeed, then aspect ratio hasn't changed. // if both succeed, then aspect ratio hasn't changed.
if(imageDetectResult && guardLineResult){ if(imageDetectResult && guardLineResult){
console.log("STATS: both guardLine and imageTest tests succeeded. AR didn't change. Guard line:", GlobalVars.arDetect.guardLine);
delete image; delete image;
triggerTimeout = _ard_getTimeout(baseTimeout, startTime); triggerTimeout = _ard_getTimeout(baseTimeout, startTime);
_ard_vdraw(triggerTimeout); //no letterbox, no problem _ard_vdraw(triggerTimeout); //no letterbox, no problem
@ -861,11 +886,7 @@ var _ard_guardLineImageDetect = function(image){
var offset = parseInt(GlobalVars.canvas.width * Settings.arDetect.guardLine.ignoreEdgeMargin) * 4; var offset = parseInt(GlobalVars.canvas.width * Settings.arDetect.guardLine.ignoreEdgeMargin) * 4;
var offenders = [];
var firstOffender = -1;
var offenderCount = -1; // doing it this way means first offender has offenderCount==0. Ez index.
// TODO: implement logo check. // TODO: implement logo check.

View File

@ -85,9 +85,9 @@ var _res_legacyAr = function(action){
GlobalVars.lastAr = {type: "legacy", action: action}; GlobalVars.lastAr = {type: "legacy", action: action};
} }
var _res_setAr = function(ar, playerDimensions){ var _res_setAr = function(ar){
if(Debug.debug) if(Debug.debug)
console.log("[Resizer::_res_setAr] trying to set ar. args are: ar->",ar,"; playerDimensions->",playerDimensions); console.log("[Resizer::_res_setAr] trying to set ar. args are: ar->",ar,"; playerDimensions->",GlobalVars.playerDimensions);
GlobalVars.lastAr = {type: "static", ar: ar}; GlobalVars.lastAr = {type: "static", ar: ar};
@ -115,7 +115,7 @@ var _res_setAr = function(ar, playerDimensions){
if(Debug.debug) if(Debug.debug)
console.log("[Resizer::_res_setAr] ar is " ,ar, ", file ar is", fileAr, ", playerDimensions are ", playerDimensions); console.log("[Resizer::_res_setAr] ar is " ,ar, ", file ar is", fileAr, ", playerDimensions are ", GlobalVars.playerDimensions);
var videoDimensions = { var videoDimensions = {
width: 0, width: 0,
@ -123,33 +123,33 @@ var _res_setAr = function(ar, playerDimensions){
} }
if(playerDimensions === undefined){ if(GlobalVars.playerDimensions === undefined){
playerDimensions = PlayerDetect.getPlayerDimensions(vid); GlobalVars.playerDimensions = PlayerDetect.getPlayerDimensions(vid);
if(Debug.debug) if(Debug.debug)
console.log("[Resizer::_res_setAr] playerDimensions are undefined, trying to determine new ones ... new dimensions:",playerDimensions); console.log("[Resizer::_res_setAr] playerDimensions are undefined, trying to determine new ones ... new dimensions:",GlobalVars.playerDimensions);
} }
if(Debug.debug){ if(Debug.debug){
console.log("[Resizer::_res_setAr] Player dimensions?",playerDimensions); console.log("[Resizer::_res_setAr] Player dimensions?",GlobalVars.playerDimensions);
} }
if( fileAr < ar ){ if( fileAr < ar ){
// imamo letterbox zgoraj in spodaj -> spremenimo velikost videa (ampak nikoli na več, kot je širina zaslona) // imamo letterbox zgoraj in spodaj -> spremenimo velikost videa (ampak nikoli na več, kot je širina zaslona)
// letterbox -> change video size (but never to wider than monitor width) // letterbox -> change video size (but never to wider than monitor width)
videoDimensions.width = Math.min(playerDimensions.height * ar, playerDimensions.width); videoDimensions.width = Math.min(GlobalVars.playerDimensions.height * ar, GlobalVars.playerDimensions.width);
videoDimensions.height = videoDimensions.width * (1/fileAr); videoDimensions.height = videoDimensions.width * (1/fileAr);
} }
else{ else{
videoDimensions.height = Math.min(playerDimensions.width * (1/ar), playerDimensions.height); videoDimensions.height = Math.min(GlobalVars.playerDimensions.width * (1/ar), GlobalVars.playerDimensions.height);
videoDimensions.width = videoDimensions.height * fileAr; videoDimensions.width = videoDimensions.height * fileAr;
} }
if(Debug.debug){ if(Debug.debug){
console.log("[Resizer::_res_setAr] Video dimensions: ",videoDimensions, "playerDimensions:",playerDimensions); console.log("[Resizer::_res_setAr] Video dimensions: ",videoDimensions, "playerDimensions:",GlobalVars.playerDimensions);
} }
var cssValues = _res_computeOffsets(videoDimensions, playerDimensions); var cssValues = _res_computeOffsets(videoDimensions, GlobalVars.playerDimensions);
if(Debug.debug){ if(Debug.debug){
console.log("[Resizer::_res_setAr] Offsets for css are: ",cssValues); console.log("[Resizer::_res_setAr] Offsets for css are: ",cssValues);

View File

@ -19,6 +19,7 @@ var GlobalVars = {
canvas: null, canvas: null,
blackLevel: 10, blackLevel: 10,
sampleCols_current: 0, sampleCols_current: 0,
noLetterboxCanvasReset: false,
guardLine: { guardLine: {
top: null, top: null,
bottom: null, bottom: null,

View File

@ -60,7 +60,7 @@ async function main(){
} }
browser.runtime.onMessage.addListener(receiveMessage); browser.runtime.onMessage.addListener(receiveMessage);
setInterval( ghettoOnChange, 10000); setInterval( ghettoOnChange, 100);
setInterval( ghettoUrlWatcher, 500); setInterval( ghettoUrlWatcher, 500);
// ko se na ticevki zamenja video, console.log pravi da ultrawidify spremeni razmerje stranic. preglej element // ko se na ticevki zamenja video, console.log pravi da ultrawidify spremeni razmerje stranic. preglej element
@ -78,7 +78,7 @@ async function main(){
// tukaj gledamo, ali se je velikost predvajalnika spremenila. Če se je, ponovno prožimo resizer // tukaj gledamo, ali se je velikost predvajalnika spremenila. Če se je, ponovno prožimo resizer
// here we check (in the most ghetto way) whether player size has changed. If it has, we retrigger resizer. // here we check (in the most ghetto way) whether player size has changed. If it has, we retrigger resizer.
var _video_recheck_counter = 0; var _video_recheck_counter = 5;
var _video_recheck_period = 1; // on this many retries var _video_recheck_period = 1; // on this many retries
function ghettoOnChange(){ function ghettoOnChange(){