diff --git a/ledder/server/RenderRealtime.ts b/ledder/server/RenderRealtime.ts index dd62a8d..84c2764 100644 --- a/ledder/server/RenderRealtime.ts +++ b/ledder/server/RenderRealtime.ts @@ -7,7 +7,6 @@ import {Render} from "./Render.js" export class RenderRealtime extends Render { private nextTimeMicros: number - private lastFrameMicros: number private keepRendering: boolean @@ -24,7 +23,6 @@ export class RenderRealtime extends Render { if (!this.keepRendering) { this.keepRendering = true this.nextTimeMicros = Date.now() * 1000 - this.lastFrameMicros = 0 this.lastStatUpdate=Date.now() this.lateFrames=0 @@ -47,29 +45,29 @@ export class RenderRealtime extends Render { this.nextTimeMicros+= await this.scheduler.__step(true) //max 10 frames difference - if (Math.abs(this.nextTimeMicros-nowUS)>this.scheduler.__frameTimeMicros*10) { + + let diffUS=this.nextTimeMicros-nowUS + + //too slow, or other clock problem + if (Math.abs(this.nextTimeMicros-nowUS)>this.scheduler.__frameTimeMicros*2) { //reset - this.nextTimeMicros = nowUS+this.scheduler.__frameTimeMicros; + this.nextTimeMicros = nowUS+this.scheduler.__frameTimeMicros + this.droppedFrames++ } - if ( nowUS-this.lastFrameMicros >= this.display.minFrameTimeMicros) { - try { - this.display.render(this.box) - } catch (e) { - console.error("Exception while rendering:", e) - } - this.display.frame(this.nextTimeMicros) - this.lastFrameMicros = nowUS - } - else - { - this.droppedFrames++; + try { + this.display.render(this.box) + } catch (e) { + console.error("Exception while rendering:", e) } + this.display.frame(this.nextTimeMicros) if (nowUS-this.lastStatUpdate>1000000) { - - console.log(`RenderRealtime: ${this.lateFrames} late. ${this.droppedFrames} dropped. ${ Math.round( ( 1000-this.idleMS)/10) }% busy.`) + let busy=Math.round( ( 1000-this.idleMS)/10) + if (busy<0) + busy=0 + console.log(`RenderRealtime: ${this.lateFrames} late. ${this.droppedFrames} dropped. ${ busy }% busy.`) this.lastStatUpdate=nowUS this.droppedFrames=0; this.lateFrames=0; diff --git a/ledder/server/drivers/DisplayQOISudp.ts b/ledder/server/drivers/DisplayQOISudp.ts index 196392c..e0fa942 100644 --- a/ledder/server/drivers/DisplayQOISudp.ts +++ b/ledder/server/drivers/DisplayQOISudp.ts @@ -29,7 +29,7 @@ export class DisplayQOISudp extends DisplayQOIS { * @param pixelsPerChannel Number of pixels per channel you want to use. Doesnt have to correspondent with how you compiled ledder, leds will be skipped/cropped. Or 0 to use all the leds available in the firmware. * @param maxFps Maximum frames per second. This depends on the total leds and leds per channel (512 leds per channel is max 58fps or less). We use 50fps to be on the safe side. Keep an eye ledstream and see if the udpbuffer keeps overflowing. */ - constructor(mapper: OffsetMapper, ips, port, pixelsPerChannel = 0, maxFps=50) { + constructor(mapper: OffsetMapper, ips, port, pixelsPerChannel = 0, maxFps=60) { super(mapper, pixelsPerChannel) @@ -91,7 +91,7 @@ export class DisplayQOISudp extends DisplayQOIS { const frameBytes = [] - const maxFramesLag = 12 + const maxFramesLag = 24 const maxTimeLag = 250 //buffer this many frames