Fixed some problems with recursion in autodetection startup. Fixed problems with autodetection sometimes not starting.

This commit is contained in:
Tamius Han 2018-05-20 23:17:09 +02:00
parent 009a440ce8
commit ad1436289b
5 changed files with 70 additions and 23 deletions

View File

@ -44,25 +44,34 @@ class PlayerData {
} }
startChangeDetection(){ startChangeDetection(){
this.ghettoWatcher
this.watchTimeout = setInterval(this.ghettoWatcher, 100, this); this.watchTimeout = setInterval(this.ghettoWatcher, 100, this);
} }
stopChangeDetection(){ scheduleGhettoWatcher(){
clearInterval(this.watchTimeout); ths = this;
this.watchTimeout = setTimeout(function(){
ths.ghettoWatcher();
ths.scheduleGhettoWatcher();
}, 100)
} }
ghettoWatcher(ths){ stopChangeDetection(){
if(ths.checkPlayerSizeChange()){ clearTimeout(this.watchTimeout);
}
ghettoWatcher(){
if(this.checkPlayerSizeChange()){
if(Debug.debug){ if(Debug.debug){
console.log("[uw::ghettoOnChange] change detected"); console.log("[uw::ghettoOnChange] change detected");
} }
ths.getPlayerDimensions(); this.getPlayerDimensions();
if(! ths.element ){ if(! this.element ){
return; return;
} }
ths.videoData.resizer.restore(); // note: this returns true if change goes through, false otherwise. this.videoData.resizer.restore(); // note: this returns true if change goes through, false otherwise.
return; return;
} }
@ -71,18 +80,18 @@ class PlayerData {
// sometimes, checkPlayerSizeChange might not detect a change to fullscreen. This means we need to // sometimes, checkPlayerSizeChange might not detect a change to fullscreen. This means we need to
// trick it into doing that // trick it into doing that
if(ths.dimensions.fullscreen != PlayerData.isFullScreen()) { if(this.dimensions.fullscreen != PlayerData.isFullScreen()) {
if(Debug.debug){ if(Debug.debug){
console.log("[PlayerData::ghettoWatcher] fullscreen switch detected (basic change detection failed)"); console.log("[PlayerData::ghettoWatcher] fullscreen switch detected (basic change detection failed)");
} }
ths.getPlayerDimensions(); this.getPlayerDimensions();
if(! ths.element ){ if(! this.element ){
return; return;
} }
ths.videoData.resizer.restore(); this.videoData.resizer.restore();
} }
} }

View File

@ -22,10 +22,13 @@ class VideoData {
} }
initArDetection() { initArDetection() {
if(ths.arDetector) if(this.arDetector){
this.arDetector.init(); this.arDetector.init();
else }
else{
this.arDetector = new ArDetector(this); this.arDetector = new ArDetector(this);
this.arDetector.init();
}
} }
startArDetection() { startArDetection() {

View File

@ -14,15 +14,12 @@ class ArDetector {
this.fallbackMode = false; this.fallbackMode = false;
this.blackLevel = ExtensionConf.arDetect.blackLevel_default; this.blackLevel = ExtensionConf.arDetect.blackLevel_default;
this.init();
} }
init(){ init(){
if(Debug.debug){ if(Debug.debug){
console.log("[ArDetect::init] Initializing autodetection") console.log("[ArDetect::init] Initializing autodetection")
} }
this.setup(ExtensionConf.arDetect.hSamples, ExtensionConf.arDetect.vSamples); this.setup(ExtensionConf.arDetect.hSamples, ExtensionConf.arDetect.vSamples);
} }
@ -48,8 +45,8 @@ class ArDetector {
try{ try{
if(Debug.debug){ if(Debug.debug){
console.log("%c[ArDetect::_ard_setup] Starting automatic aspect ratio detection.", _ard_console_start); console.log("%c[ArDetect::setup] Starting automatic aspect ratio detection.", _ard_console_start);
console.log("[ArDetect::_ard_setup] Choice config bits:\ncanvas dimensions:",cwidth, "×", cheight, "\nsamplingInterval (ExtensionConf):", ExtensionConf.arDetect.samplingInterval, "width/interval:", parseInt(cheight / ExtensionConf.arDetect.samplingInterval)); console.log("[ArDetect::setup] Choice config bits:\ncanvas dimensions:",cwidth, "×", cheight, "\nvideoData:", this.conf);
} }
this._halted = false; this._halted = false;
@ -66,12 +63,12 @@ class ArDetector {
if(this.canvas){ if(this.canvas){
if(Debug.debug) if(Debug.debug)
console.log("[ArDetect::_ard_setup] existing canvas found. REMOVING KEBAB removing kebab\n\n\n\n(im hungry and you're not authorized to have it)"); console.log("[ArDetect::setup] existing canvas found. REMOVING KEBAB removing kebab\n\n\n\n(im hungry and you're not authorized to have it)");
this.canvas.remove(); this.canvas.remove();
if(Debug.debug) if(Debug.debug)
console.log("[ArDetect::_ard_setup] canvas removed"); console.log("[ArDetect::setup] canvas removed");
} }
// imamo video, pa tudi problem. Ta problem bo verjetno kmalu popravljen, zato setup začnemo hitreje kot prej // imamo video, pa tudi problem. Ta problem bo verjetno kmalu popravljen, zato setup začnemo hitreje kot prej
@ -79,8 +76,11 @@ class ArDetector {
// less delay than before // less delay than before
if(this.video.videoWidth === 0 || this.video.videoHeight === 0 ){ if(this.video.videoWidth === 0 || this.video.videoHeight === 0 ){
if(! this.timer)
this.setupTimer = setTimeout(this.init(), 100); if(Debug.debug){
console.log("[ArDetector::setup] video has no width or height!", this.video.videoWidth,"×", this.video.videoHeight)
}
this.scheduleInitRestart();
return; return;
} }
@ -175,6 +175,27 @@ class ArDetector {
return ! this._halted; return ! this._halted;
} }
scheduleInitRestart(timeout, force_reset){
if(! timeout){
timeout = 100;
}
// don't allow more than 1 instance
if(this.setupTimer){
clearTimeout(this.setupTimer);
}
var ths = this;
this.setupTimer = setTimeout(function(){
ths.setupTimer = null;
try{
ths.init();
}catch(e){console.log("[ArDetector::scheduleInitRestart] Failed to start init(). Error:",e)}
ths = null;
},
timeout
);
}
scheduleFrameCheck(timeout, force_reset){ scheduleFrameCheck(timeout, force_reset){
if(! timeout){ if(! timeout){
this.frameCheck(); this.frameCheck();

View File

@ -44,22 +44,35 @@ class PageInfo {
// } // }
if(! vids[0].offsetWidth || ! vids[0].offsetHeight){ if(! vids[0].offsetWidth || ! vids[0].offsetHeight){
this.hasVideos = false; this.hasVideos = false;
if(Debug.debug){
console.log("[PageInfo::rescan] video lacks offsetwidth or offsetheight, doing nothing")
}
this.scheduleRescan(); this.scheduleRescan();
return; return;
} }
if(this.videos.length > 0){ if(this.videos.length > 0){
if(vids[0] == this.videos[0].video){ if(vids[0] == this.videos[0].video){
console.log("[PageInfo::rescan] videos are equal, doing nothing")
// do nothing // do nothing
} else { } else {
console.log("videos not equal!", vids[0], this.videos[0].video)
this.videos[0].destroy(); this.videos[0].destroy();
this.videos[0] = new VideoData(vids[0]); this.videos[0] = new VideoData(vids[0]);
this.videos[0].initArDetection();
} }
} else { } else {
if(Debug.debug)
console.log("[PageInfo::rescan] Adding new video!", vids[0], ";", vids[0].offsetWidth, "×", vids[0].offsetHeight);
this.videos.push(new VideoData(vids[0])); this.videos.push(new VideoData(vids[0]));
this.videos[0].initArDetection();
} }
console.log("Rescan complete. Total videos?", this.videos.length) // console.log("Rescan complete. Total videos?", this.videos.length)
}catch(e){ }catch(e){
console.log("rescan error:",e) console.log("rescan error:",e)
} }

View File

@ -361,6 +361,7 @@ class Resizer {
ths.conf.destroy(); ths.conf.destroy();
return; return;
} }
console.log("css watcher running. video?", ths.video)
// // our current css is fucky? Null, undefined and 0 are invalid values. // // our current css is fucky? Null, undefined and 0 are invalid values.
// if(! GlobalVars.currentCss.width || ! GlobalVars.currentCss.height ) // if(! GlobalVars.currentCss.width || ! GlobalVars.currentCss.height )