Style
This commit is contained in:
parent
5b1f73a69e
commit
502ce707e1
@ -342,13 +342,16 @@ class ArDetector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.animationFrameHandle = window.requestAnimationFrame( (ts) => this.animationFrameBootstrap(ts));
|
this.animationFrameHandle = window.requestAnimationFrame( (ts) => this.animationFrameBootstrap(ts));
|
||||||
|
this.logger.log('info', 'debug', `"%c[ArDetect::startLoop] <@${this.arid}> AARD loop started.`, _ard_console_start);
|
||||||
}
|
}
|
||||||
|
|
||||||
stop() {
|
stop() {
|
||||||
if (this.animationFrameHandle) {
|
if (this.animationFrameHandle) {
|
||||||
|
this.logger.log('info', 'debug', `"%c[ArDetect::stop] <@${this.arid}> Stopping AnimationFrame loop.`, _ard_console_stop);
|
||||||
window.cancelAnimationFrame(this.animationFrameHandle);
|
window.cancelAnimationFrame(this.animationFrameHandle);
|
||||||
|
} else {
|
||||||
|
this.logger.log('info', 'debug', `"%c[ArDetect::stop] <@${this.arid}> AnimationFrame loop is already paused (due to an earlier call of this function).`);
|
||||||
}
|
}
|
||||||
this.logger.log('info', 'debug', `"%c[ArDetect::stop] <@${this.arid}> Stopping AnimationFrame loop.`, _ard_console_stop);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unpause() {
|
unpause() {
|
||||||
@ -415,6 +418,7 @@ class ArDetector {
|
|||||||
// if video was paused & we know that we already checked that frame,
|
// if video was paused & we know that we already checked that frame,
|
||||||
// we will not check it again.
|
// we will not check it again.
|
||||||
const videoState = this.getVideoPlaybackState();
|
const videoState = this.getVideoPlaybackState();
|
||||||
|
|
||||||
if (videoState !== VideoPlaybackState.Playing) {
|
if (videoState !== VideoPlaybackState.Playing) {
|
||||||
if (this.status.lastVideoStatus === videoState) {
|
if (this.status.lastVideoStatus === videoState) {
|
||||||
return false;
|
return false;
|
||||||
@ -528,12 +532,16 @@ class ArDetector {
|
|||||||
* This is the "main loop" for aspect ratio autodetection
|
* This is the "main loop" for aspect ratio autodetection
|
||||||
*/
|
*/
|
||||||
private async animationFrameBootstrap(timestamp: number) {
|
private async animationFrameBootstrap(timestamp: number) {
|
||||||
|
// this.logger.log('info', 'arDetect_verbose', `[ArDetect::animationFrameBootstrap] <@${this.arid}> New animation frame.\nmanualTickEnabled: ${!this.manualTickEnabled}\ncan trigger frame check? ${this.canTriggerFrameCheck()}\nnext tick? ${this._nextTick}\n => (a&b | c) => Can we do tick? ${ (!this.manualTickEnabled && this.canTriggerFrameCheck()) || this._nextTick}\n\ncan we continue running? ${this && !this._halted && !this._paused}`);
|
||||||
|
|
||||||
// do timekeeping first
|
// do timekeeping first
|
||||||
this.addPerformanceTimeMeasure(this.performance.animationFrame, timestamp - this.performance.animationFrame.lastTime);
|
this.addPerformanceTimeMeasure(this.performance.animationFrame, timestamp - this.performance.animationFrame.lastTime);
|
||||||
this.performance.animationFrame.lastTime = timestamp;
|
this.performance.animationFrame.lastTime = timestamp;
|
||||||
|
|
||||||
// trigger frame check, if we're allowed to
|
// trigger frame check, if we're allowed to
|
||||||
if ( (!this.manualTickEnabled && this.canTriggerFrameCheck()) || this._nextTick) {
|
if ( (!this.manualTickEnabled && this.canTriggerFrameCheck()) || this._nextTick) {
|
||||||
|
this.logger.log('info', 'arDetect_verbose', `[ArDetect::animationFrameBootstrap] <@${this.arid}> Processing next tick.`);
|
||||||
|
|
||||||
this._nextTick = false;
|
this._nextTick = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -541,17 +549,17 @@ class ArDetector {
|
|||||||
await this.frameCheck();
|
await this.frameCheck();
|
||||||
this.addPerformanceTimeMeasure(this.performance.aard, performance.now() - startTime);
|
this.addPerformanceTimeMeasure(this.performance.aard, performance.now() - startTime);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.log('error', 'debug', `%c[ArDetect::main] <@${this.arid}> Frame check failed:`, "color: #000, background: #f00", e);
|
this.logger.log('error', 'debug', `%c[ArDetect::animationFrameBootstrap] <@${this.arid}> Frame check failed:`, "color: #000, background: #f00", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this && !this._halted && !this._paused) {
|
if (this && !this._halted && !this._paused) {
|
||||||
this.animationFrameHandle = window.requestAnimationFrame( (ts) => this.animationFrameBootstrap(ts));
|
this.animationFrameHandle = window.requestAnimationFrame( (ts) => this.animationFrameBootstrap(ts));
|
||||||
} else if (this._halted) {
|
} else if (this._halted) {
|
||||||
this.logger.log('info', 'debug', `%c[ArDetect::main] <@${this.arid}> Main autodetection loop exited. Halted? ${this._halted}`, _ard_console_stop);
|
this.logger.log('info', 'debug', `%c[ArDetect::animationFrameBootstrap] <@${this.arid}> Main autodetection loop exited. Halted? ${this._halted}`, _ard_console_stop);
|
||||||
this._exited = true;
|
this._exited = true;
|
||||||
} else {
|
} else {
|
||||||
this.logger.log('info', 'debug', `[ArDetect::main] <@${this.arid}> Not renewing animation frame for some reason. Paused? ${this._paused}; Halted?: ${this._halted}, Exited?: ${this._exited}`);
|
this.logger.log('info', 'debug', `[ArDetect::animationFrameBootstrap] <@${this.arid}> Not renewing animation frame for some reason. Paused? ${this._paused}; Halted?: ${this._halted}, Exited?: ${this._exited}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -740,10 +748,12 @@ class ArDetector {
|
|||||||
return; // it's prolly just a fluke, so we do nothing special here
|
return; // it's prolly just a fluke, so we do nothing special here
|
||||||
}
|
}
|
||||||
// draw blackframe sample from our main sample:
|
// draw blackframe sample from our main sample:
|
||||||
await new Promise<void>(resolve => {
|
await new Promise<void>(
|
||||||
this.blackframeContext.drawImage(this.canvas, this.blackframeCanvas.width, this.blackframeCanvas.height);
|
resolve => {
|
||||||
resolve();
|
this.blackframeContext.drawImage(this.canvas, this.blackframeCanvas.width, this.blackframeCanvas.height);
|
||||||
});
|
resolve();
|
||||||
|
}
|
||||||
|
);
|
||||||
partialDrawImageTime += performance.now() - startTime;
|
partialDrawImageTime += performance.now() - startTime;
|
||||||
|
|
||||||
this.logger.log('info', 'arDetect_verbose', `%c[ArDetect::frameCheck] canvas.drawImage seems to have worked`, "color:#000; backgroud:#2f5;");
|
this.logger.log('info', 'arDetect_verbose', `%c[ArDetect::frameCheck] canvas.drawImage seems to have worked`, "color:#000; backgroud:#2f5;");
|
||||||
@ -760,10 +770,12 @@ class ArDetector {
|
|||||||
// if we are in normal mode though, the frame has yet to be drawn
|
// if we are in normal mode though, the frame has yet to be drawn
|
||||||
if (!this.fallbackMode) {
|
if (!this.fallbackMode) {
|
||||||
startTime = performance.now();
|
startTime = performance.now();
|
||||||
await new Promise<void>(resolve => {
|
await new Promise<void>(
|
||||||
this.context.drawImage(this.video, 0, 0, this.canvas.width, this.canvas.height);
|
resolve => {
|
||||||
resolve();
|
this.context.drawImage(this.video, 0, 0, this.canvas.width, this.canvas.height);
|
||||||
})
|
resolve();
|
||||||
|
}
|
||||||
|
)
|
||||||
partialDrawImageTime += performance.now() - startTime;
|
partialDrawImageTime += performance.now() - startTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user