diff --git a/src/csui/src/PlayerUIWindow.vue b/src/csui/src/PlayerUIWindow.vue index e8457e6..a56ea84 100644 --- a/src/csui/src/PlayerUIWindow.vue +++ b/src/csui/src/PlayerUIWindow.vue @@ -183,7 +183,7 @@ export default { // {id: 'videoSettings', label: 'Video settings', icon: 'crop'}, {id: 'extensionSettings', label: 'Site and Extension options', icon: 'cogs' }, {id: 'playerDetection', label: 'Player detection', icon: 'television-play'}, - // {id: 'autodetectionSettings', label: 'Autodetection options', icon: ''}, + {id: 'autodetectionSettings', label: 'Autodetection options', icon: ''}, // {id: 'advancedOptions', label: 'Advanced options', icon: 'cogs' }, // {id: 'debugging', label: 'Debugging', icon: 'bug-outline' } {id: 'changelog', label: 'What\'s new', icon: 'information-box-outline' }, diff --git a/src/ext/lib/aard/Aard.ts b/src/ext/lib/aard/Aard.ts index b079905..1595d1d 100644 --- a/src/ext/lib/aard/Aard.ts +++ b/src/ext/lib/aard/Aard.ts @@ -4,9 +4,10 @@ import Logger from '../Logger'; import Settings from '../Settings'; import VideoData from '../video-data/VideoData'; import { Corner } from './enums/corner.enum'; +import { VideoPlaybackState } from './enums/video-playback-state.enum'; import { GlCanvas } from './gl/GlCanvas'; import { AardCanvasStore } from './interfaces/aard-canvas-store.interface'; -import { AardDetectionSample, generateSampleArray } from './interfaces/aard-detection-sample.interface'; +import { AardDetectionSample, generateSampleArray, resetSamples } from './interfaces/aard-detection-sample.interface'; import { AardStatus, initAardStatus } from './interfaces/aard-status.interface'; import { AardTestResults, initAardTestResults, resetAardTestResults } from './interfaces/aard-test-results.interface'; import { AardTimers, initAardTimers } from './interfaces/aard-timers.interface'; @@ -210,7 +211,7 @@ import { AardTimers, initAardTimers } from './interfaces/aard-timers.interface'; * - - - - - - - - - - - - - - - - - - - - - * */ -class Aard { +export class Aard { //#region configuration parameters private logger: Logger; @@ -376,7 +377,9 @@ class Aard { private onAnimationFrame(ts: DOMHighResTimeStamp) { if (this.canTriggerFrameCheck()) { resetAardTestResults(this.testResults); + resetSamples(this.canvasSamples); this.main(); + } else { } this.animationFrame = window.requestAnimationFrame( (ts: DOMHighResTimeStamp) => this.onAnimationFrame(ts)); } @@ -427,7 +430,8 @@ class Aard { this.settings.active.arDetect.canvasDimensions.sampleCanvas.height ); } - if (! this.testResults.imageLine.invalidated) { + // Both need to be checked + if (! (this.testResults.imageLine.invalidated || this.testResults.guardLine.invalidated)) { // TODO: ensure no aspect ratio changes happen this.testResults.lastStage = 2; break; @@ -625,6 +629,10 @@ class Aard { || this.testResults.guardLine.bottom < 0 || this.testResults.guardLine.bottom > height ) { + // we also need to reset guardline if out-of-bounds was detected, + // otherwise edgeScan might not work correctly + this.testResults.guardLine.top = -1; + this.testResults.guardLine.bottom = -1; this.testResults.guardLine.invalidated = true; return; } @@ -1047,7 +1055,7 @@ class Aard { // Detect upper edge { - row = topStart; + row = Math.max(topStart, 0); x = 0; isImage = false; finishedRows = 0; @@ -1063,16 +1071,16 @@ class Aard { // check for image, after we're done `x` points to alpha channel isImage = - imageData[rowOffset + x++] > this.testResults.blackLevel - || imageData[rowOffset + x++] > this.testResults.blackLevel - || imageData[rowOffset + x++] > this.testResults.blackLevel; + imageData[rowOffset + x] > this.testResults.blackLevel + || imageData[rowOffset + x + 1] > this.testResults.blackLevel + || imageData[rowOffset + x + 2] > this.testResults.blackLevel; if (!isImage) { // TODO: maybe some day mark this pixel as checked by writing to alpha channel i++; continue; } - if (!this.canvasSamples.top[i]) { + if (this.canvasSamples.top[i] === -1) { this.canvasSamples.top[i] = row; finishedRows++; } @@ -1111,16 +1119,16 @@ class Aard { // check for image, after we're done `x` points to alpha channel isImage = - imageData[rowOffset + x++] > this.testResults.blackLevel - || imageData[rowOffset + x++] > this.testResults.blackLevel - || imageData[rowOffset + x++] > this.testResults.blackLevel; + imageData[rowOffset + x] > this.testResults.blackLevel + || imageData[rowOffset + x + 1] > this.testResults.blackLevel + || imageData[rowOffset + x + 2] > this.testResults.blackLevel; if (!isImage) { // TODO: maybe some day mark this pixel as checked by writing to alpha channel i++; continue; } - if (!this.canvasSamples.bottom[i]) { + if (this.canvasSamples.bottom[i] === -1) { this.canvasSamples.bottom[i] = row; finishedRows++; } @@ -1131,8 +1139,6 @@ class Aard { if (finishedRows >= detectionLimit) { break; } - - row++; } } } @@ -1306,7 +1312,7 @@ class Aard { // didn't change meaningfully from the first, in which chance we aren't. If the brightness increased // anywhere between 'not enough' and 'too much', we mark the measurement as invalid. if (lastSubpixel - firstSubpixel > this.settings.active.arDetect.edgeDetection.gradientTestMinDelta) { - this.canvasSamples.top[i] = -1; + this.canvasSamples.bottom[i] = -1; } } @@ -1610,6 +1616,12 @@ class Aard { this.testResults.aspectRatioUncertain = true; return; } + if (maxOffset > 2) { + this.testResults.imageLine.top = this.testResults.aspectRatioCheck.topCandidate === Infinity ? -1 : this.testResults.aspectRatioCheck.topCandidate; + this.testResults.imageLine.bottom = this.testResults.aspectRatioCheck.bottomCandidate === Infinity ? -1 : this.testResults.aspectRatioCheck.bottomCandidate; + this.testResults.guardLine.top = Math.max(this.testResults.imageLine.top - 2, 0); + this.testResults.guardLine.bottom = Math.max(this.testResults.imageLine.bottom + 2, this.canvasStore.main.height - 1); + } this.testResults.aspectRatioUncertain = false; this.testResults.letterboxWidth = candidateAvg; this.testResults.letterboxOffset = diff; diff --git a/src/ext/lib/aard/enums/video-playback-state.enum.ts b/src/ext/lib/aard/enums/video-playback-state.enum.ts index 0500882..44ab55e 100644 --- a/src/ext/lib/aard/enums/video-playback-state.enum.ts +++ b/src/ext/lib/aard/enums/video-playback-state.enum.ts @@ -1,4 +1,4 @@ -enum VideoPlaybackState { +export enum VideoPlaybackState { NotInitialized, Playing, Paused, diff --git a/src/ext/lib/aard/interfaces/aard-status.interface.ts b/src/ext/lib/aard/interfaces/aard-status.interface.ts index 14931fe..5055a3b 100644 --- a/src/ext/lib/aard/interfaces/aard-status.interface.ts +++ b/src/ext/lib/aard/interfaces/aard-status.interface.ts @@ -1,3 +1,5 @@ +import {VideoPlaybackState} from '../enums/video-playback-state.enum'; + export interface AardStatus { aardActive: boolean, checkInProgress: boolean, diff --git a/src/ext/lib/aard/interfaces/aard-test-results.interface.ts b/src/ext/lib/aard/interfaces/aard-test-results.interface.ts index d77c02b..8b99b0d 100644 --- a/src/ext/lib/aard/interfaces/aard-test-results.interface.ts +++ b/src/ext/lib/aard/interfaces/aard-test-results.interface.ts @@ -74,7 +74,8 @@ export function resetAardTestResults(results: AardTestResults): void { results.isFinished = false; results.lastStage = 0; results.notLetterbox = false; - results.guardLine.invalidated = false + results.imageLine.invalidated = false; + results.guardLine.invalidated = false; results.guardLine.cornerViolations[0] = false; results.guardLine.cornerViolations[1] = false; results.guardLine.cornerViolations[2] = false; diff --git a/src/ext/lib/video-data/VideoData.ts b/src/ext/lib/video-data/VideoData.ts index f806734..350e82c 100644 --- a/src/ext/lib/video-data/VideoData.ts +++ b/src/ext/lib/video-data/VideoData.ts @@ -1,7 +1,6 @@ import Debug from '../../conf/Debug'; import PlayerData from './PlayerData'; import Resizer from '../video-transform/Resizer'; -import ArDetector from '../ar-detect/ArDetector'; import AspectRatioType from '../../../common/enums/AspectRatioType.enum'; import CropModePersistence from '../../../common/enums/CropModePersistence.enum'; import * as _ from 'lodash'; @@ -16,6 +15,7 @@ import { SiteSettings } from '../settings/SiteSettings'; import { Ar } from '../../../common/interfaces/ArInterface'; import { ExtensionStatus } from './ExtensionStatus'; import { RunLevel } from '../../enum/run-level.enum'; +import { Aard } from '../aard/Aard'; /** * VideoData — handles CSS for the video element. @@ -70,7 +70,9 @@ class VideoData { pageInfo: PageInfo; player: PlayerData; resizer: Resizer; - arDetector: ArDetector; + + aard: Aard; + eventBus: EventBus; extensionStatus: ExtensionStatus; //#endregion @@ -240,7 +242,15 @@ class VideoData { return; } this.resizer = new Resizer(this); - this.arDetector = new ArDetector(this); // this starts Ar detection. needs optional parameter that prevents ArDetector from starting + + console.log('before init aard'); + try { + this.aard = new Aard(this); // this starts Ar detection. needs optional parameter that prevents ArDetector from starting + console.log('after init aard'); + } catch (e) { + console.error('Failed to start Aard!', e); + } + this.logger.log('info', ['debug', 'init'], '[VideoData::ctor] Created videoData with vdid', this.vdid); @@ -358,10 +368,10 @@ class VideoData { this.eventBus?.unsetUpstreamBus(); try { - this.arDetector.stop(); - this.arDetector.destroy(); + this.aard.stop(); + // this.arDetector.destroy(); } catch (e) {} - this.arDetector = undefined; + this.aard = undefined; try { this.resizer.destroy(); } catch (e) {} @@ -419,7 +429,7 @@ class VideoData { disable(options?: {fromPlayer?: boolean}) { this.enabled = false; - this.arDetector?.stop(); + this.aard?.stop(); this.video.classList.remove(this.baseCssName); this.video.classList.remove(this.userCssClassName); @@ -662,12 +672,8 @@ class VideoData { // throw {error: 'VIDEO_DATA_DESTROYED', data: {videoData: this}}; return; } - if (this.arDetector){ - this.arDetector.init(); - } - else{ - this.arDetector = new ArDetector(this); - this.arDetector.init(); + if (! this.aard){ + this.aard = new Aard(this); } } @@ -686,24 +692,24 @@ class VideoData { this.hasDrm = false; } - if (!this.arDetector) { + if (!this.aard) { this.initArDetection(); } - this.arDetector.start(); + this.aard.start(); } catch (e) { this.logger.log('warn', 'debug', '[VideoData::startArDetection()] Could not start aard for some reason. Was the function was called too early?', e); } } resumeAutoAr(){ - if(this.arDetector){ + if(this.aard){ this.startArDetection(); } } stopArDetection() { - if (this.arDetector) { - this.arDetector.stop(); + if (this.aard) { + this.aard.stop(); } } //#endregion diff --git a/src/ext/lib/video-transform/Resizer.ts b/src/ext/lib/video-transform/Resizer.ts index 86fd07e..3853824 100644 --- a/src/ext/lib/video-transform/Resizer.ts +++ b/src/ext/lib/video-transform/Resizer.ts @@ -286,10 +286,10 @@ class Resizer { // handle autodetection stuff if (ar.type === AspectRatioType.Automatic) { - this.videoData.arDetector?.start(); + this.videoData.aard?.start(); return; } else if (ar.type !== AspectRatioType.AutomaticUpdate) { - this.videoData.arDetector?.stop(); + this.videoData.aard?.stop(); } if (ar.type !== AspectRatioType.AutomaticUpdate) { @@ -357,11 +357,11 @@ class Resizer { // // unpause when using other modes if ((ar.type !== AspectRatioType.Automatic && ar.type !== AspectRatioType.AutomaticUpdate) || this.stretcher.mode === StretchType.Basic) { - this.videoData?.arDetector?.pause(); + this.videoData?.aard?.stop(); } else { if (ar.type !== AspectRatioType.AutomaticUpdate) { if (this.lastAr.type === AspectRatioType.Automatic || this.lastAr.type === AspectRatioType.AutomaticUpdate) { - this.videoData?.arDetector?.unpause(); + this.videoData?.aard?.stop(); } } }