Fixed multiple instances running on Twitch/clips.twitch. Fixed lockups on reddit/embedded. Fixed aspect ratio calculations on fitw and fith modes

This commit is contained in:
Tamius Han 2019-05-07 23:40:13 +02:00
parent 887cbaab0a
commit 2f5acd9d9e
4 changed files with 68 additions and 20 deletions

View File

@ -7,7 +7,7 @@ var Debug = {
init: true, init: true,
debug: true, debug: true,
// debug: false, // debug: false,
keyboard: true, // keyboard: true,
debugResizer: true, debugResizer: true,
debugArDetect: true, debugArDetect: true,
scaler: true, scaler: true,
@ -18,9 +18,9 @@ var Debug = {
// showArDetectCanvas: true, // showArDetectCanvas: true,
// flushStoredSettings: true, // flushStoredSettings: true,
// flushStoredSettings: false, // flushStoredSettings: false,
// playerDetectDebug: true, playerDetectDebug: true,
// periodic: true, periodic: true,
// videoRescan: true, videoRescan: true,
// mousemove: true, // mousemove: true,
arDetect: { arDetect: {
// edgeDetect: true // edgeDetect: true

View File

@ -113,12 +113,11 @@ class PageInfo {
if (videoExists) { if (videoExists) {
continue; continue;
} else { } else {
if(Debug.debug && Debug.periodic && Debug.videoRescan){ if (Debug.debug && Debug.periodic && Debug.videoRescan) {
console.log("[PageInfo::rescan] found new video candidate:", video, "NOTE:: Video initialization starts here:\n--------------------------------\n") console.log("[PageInfo::rescan] found new video candidate:", video, "NOTE:: Video initialization starts here:\n--------------------------------\n")
} }
v = new VideoData(video, this.settings, this); v = new VideoData(video, this.settings, this);
// console.log("[PageInfo::rescan] v is:", v) // console.log("[PageInfo::rescan] v is:", v)
// debugger;
v.initArDetection(); v.initArDetection();
this.videos.push(v); this.videos.push(v);
@ -148,8 +147,21 @@ class PageInfo {
} }
} }
}catch(e){ } catch(e) {
console.log("rescan error:",e) // če pride do zajeba, potem lahko domnevamo da na strani ni nobenega videa. Uničimo vse objekte videoData
// da preprečimo večkratno inicializacijo. Če smo se z našim ugibom zmotili, potem se bodo vsi videi ponovno
// našli ob naslednjem preiskovanju
//
// if we encounter a fuckup, we can assume that no videos were found on the page. We destroy all videoData
// objects to prevent multiple initalization (which happened, but I don't know why). No biggie if we destroyed
// videoData objects in error — they'll be back in the next rescan
if (Debug.debug) {
console.log("rescan error: — destroying all videoData objects",e);
}
for (const v of this.videos) {
v.destroy();
}
return;
} }
if(rescanReason == RescanReason.PERIODIC){ if(rescanReason == RescanReason.PERIODIC){

View File

@ -24,6 +24,8 @@ class Resizer {
this.stretcher = new Stretcher(this.conf); this.stretcher = new Stretcher(this.conf);
this.zoom = new Zoom(this.conf); this.zoom = new Zoom(this.conf);
this.cssCheckDisabled = false;
// load up default values // load up default values
this.correctedVideoDimensions = {}; this.correctedVideoDimensions = {};
this.currentCss = {}; this.currentCss = {};
@ -74,7 +76,7 @@ class Resizer {
calculateRatioForLegacyOptions(ar){ calculateRatioForLegacyOptions(ar){
// also present as modeToAr in Scaler.js // also present as modeToAr in Scaler.js
if (ar.ratio) { if (ar.type !== AspectRatio.FitWidth && ar.type !== AspectRatio.FitHeight && ar.ratio) {
return ar; return ar;
} }
// Skrbi za "stare" možnosti, kot na primer "na širino zaslona", "na višino zaslona" in "ponastavi". // Skrbi za "stare" možnosti, kot na primer "na širino zaslona", "na višino zaslona" in "ponastavi".
@ -94,6 +96,9 @@ class Resizer {
if (! this.conf.player.dimensions) { if (! this.conf.player.dimensions) {
ratioOut = screen.width / screen.height; ratioOut = screen.width / screen.height;
} else { } else {
if (Debug.debug && Debug.debugResizer) {
console.log(`[Resizer::calculateRatioForLegacyOptions] <rid:${this.resizerId}> Player dimensions:`, this.conf.player.dimensions.width ,'x', this.conf.player.dimensions.height,'aspect ratio:', this.conf.player.dimensions.width / this.conf.player.dimensions.height)
}
ratioOut = this.conf.player.dimensions.width / this.conf.player.dimensions.height; ratioOut = this.conf.player.dimensions.width / this.conf.player.dimensions.height;
} }
@ -138,7 +143,8 @@ class Resizer {
} }
if (lastAr) { if (lastAr) {
this.lastAr = lastAr; this.lastAr = this.calculateRatioForLegacyOptions(lastAr);
ar = this.calculateRatioForLegacyOptions(ar);
} else { } else {
// NOTE: "fitw" "fith" and "reset" should ignore ar.ratio bit, but // NOTE: "fitw" "fith" and "reset" should ignore ar.ratio bit, but
// I'm not sure whether they do. Check that. // I'm not sure whether they do. Check that.
@ -190,10 +196,20 @@ class Resizer {
if(Debug.debug){ if(Debug.debug){
console.log("[Resizer::setAr] <rid:"+this.resizerId+"> failed to set AR due to problem with calculating crop. Error:", (stretchFactors ? stretchFactors.error : stretchFactors)); console.log("[Resizer::setAr] <rid:"+this.resizerId+"> failed to set AR due to problem with calculating crop. Error:", (stretchFactors ? stretchFactors.error : stretchFactors));
} }
if(stretchFactors.error === 'no_video'){ if (stretchFactors.error === 'no_video'){
this.conf.destroy(); this.conf.destroy();
} }
if (stretchFactors.error === 'illegal_video_dimensions') {
if(Debug.debug){
console.log("[Resizer::setAr] <rid:"+this.resizerId+"> Illegal video dimensions found. We will pause everything.");
}
// if we get illegal video dimensions, cssWatcher goes nuts. This is harmful,
// so we stop it until that sorts itself out
this.stopCssWatcher();
}
return; return;
} else {
this.startCssWatcher();
} }
if(this.stretcher.mode === Stretch.Conditional){ if(this.stretcher.mode === Stretch.Conditional){
this.stretcher.applyConditionalStretch(stretchFactors, ar.ratio); this.stretcher.applyConditionalStretch(stretchFactors, ar.ratio);
@ -301,7 +317,8 @@ class Resizer {
return; return;
} }
// this.haltCssWatcher = false; this.cssCheckDisabled = false;
if(!this.cssWatcherTimer){ if(!this.cssWatcherTimer){
this.scheduleCssWatcher(1); this.scheduleCssWatcher(1);
} else { } else {
@ -320,6 +337,11 @@ class Resizer {
return; return;
} }
// one extra check to ensure we don't run css checks when we aren't supposed to
if (this.cssCheckDisabled) {
return;
}
if(this.cssWatcherTimeout) { if(this.cssWatcherTimeout) {
clearTimeout(this.cssWatcherTimer); clearTimeout(this.cssWatcherTimer);
} }
@ -328,7 +350,9 @@ class Resizer {
this.cssWatcherTimer = setTimeout(function () { this.cssWatcherTimer = setTimeout(function () {
ths.cssWatcherTimer = null; ths.cssWatcherTimer = null;
try { try {
ths.cssCheck(); if (! ths.cssCheckDisabled) {
ths.cssCheck();
}
} catch (e) { } catch (e) {
if(Debug.debug) { if(Debug.debug) {
console.log("[Resizer.js::scheduleCssWatcher] Css check failed. Error:", e); console.log("[Resizer.js::scheduleCssWatcher] Css check failed. Error:", e);
@ -339,9 +363,9 @@ class Resizer {
stopCssWatcher() { stopCssWatcher() {
if (Debug.debug) { if (Debug.debug) {
console.log("[Resizer.js] STOPPING CSS WATCHER!") console.log(`[Resizer.js] <${this.resizerId}> STOPPING CSS WATCHER!`)
} }
this.cssCheckDisabled = true;
clearInterval(this.cssWatcherTimeout); clearInterval(this.cssWatcherTimeout);
} }
@ -551,6 +575,10 @@ class Resizer {
} }
cssCheck(){ cssCheck(){
if (this.cssCheckDisabled) {
throw "fucking dont"
return;
}
// this means we haven't set our CSS yet, or that we changed video. // this means we haven't set our CSS yet, or that we changed video.
// if(! this.currentCss.tranform) { // if(! this.currentCss.tranform) {
// this.scheduleCssWatcher(200); // this.scheduleCssWatcher(200);
@ -584,11 +612,10 @@ class Resizer {
} }
this.restore(); this.restore();
this.scheduleCssWatcher(10); this.scheduleCssWatcher(10);
return;
} }
if (this.cssWatcherIncreasedFrequencyCounter > 0) { if (this.cssWatcherIncreasedFrequencyCounter > 0) {
--this.cssWatcherIncreasedFrequencyCounter; --this.cssWatcherIncreasedFrequencyCounter;
this.scheduleCssWatcher(20); this.scheduleCssWatcher(20);
} else { } else {
this.scheduleCssWatcher(1000); this.scheduleCssWatcher(1000);
} }

View File

@ -18,7 +18,7 @@ class Scaler {
// Približevanje opuščeno. // Približevanje opuščeno.
// handles "legacy" options, such as 'fit to widht', 'fit to height' and AspectRatio.Reset. No zoom tho // handles "legacy" options, such as 'fit to widht', 'fit to height' and AspectRatio.Reset. No zoom tho
modeToAr (ar) { modeToAr (ar) {
if (ar.ratio) { if (ar.type !== AspectRatio.FitWidth && ar.type !== AspectRatio.FitHeight && ar.ratio) {
return ar.ratio; return ar.ratio;
} }
@ -70,14 +70,23 @@ class Scaler {
} }
calculateCrop(ar) { calculateCrop(ar) {
if(!this.conf.video || this.conf.video.videoWidth == 0 || this.conf.video.videoHeight == 0){ if(!this.conf.video){
if (Debug.debug) { if (Debug.debug) {
console.log("[Scaler::calculateCrop] ERROR — no video detected."); console.log("[Scaler::calculateCrop] ERROR — no video detected. Conf:", this.conf, "video:", this.conf.video, "video dimensions:", this.conf.video && this.conf.video.videoWidth, '×', this.conf.video && this.conf.video.videoHeight);
} }
this.conf.destroy(); this.conf.destroy();
return {error: "no_video"}; return {error: "no_video"};
} }
if (this.conf.video.videoWidth == 0 || this.conf.video.videoHeight == 0) {
// that's illegal, but not illegal enough to just blast our shit to high hell
// mr officer will let you go with a warning this time around
if (Debug.debug) {
console.log("[Scaler::calculateCrop] Video has illegal dimensions. Video dimensions:", this.conf.video && this.conf.video.videoWidth, '×', this.conf.video && this.conf.video.videoHeight);
}
return {error: "illegal_video_dimensions"};
}
if (ar.type === AspectRatio.Reset){ if (ar.type === AspectRatio.Reset){
return {xFactor: 1, yFactor: 1} return {xFactor: 1, yFactor: 1}