Measure Worker video delivery separately from simulation cadence
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { AppStreamer, StreamType, LogLevel, EventStatus } from "@nvidia/ov-web-rtc";
|
||||
import { StreamDiagnostics } from "../../core/simulation/streamDiagnostics";
|
||||
import type { AiStreamEndpoint } from "../../core/simulation/aiPolygon";
|
||||
import "@nodedc/tokens/tokens.css";
|
||||
import "./streamFrame.css";
|
||||
@@ -19,17 +20,22 @@ window.addEventListener("message",(e:MessageEvent)=>{
|
||||
started=true;
|
||||
const endpoint=e.data.endpoint as AiStreamEndpoint;
|
||||
fitVideo(endpoint.width,endpoint.height);
|
||||
const diagnostics=new StreamDiagnostics();
|
||||
let frames=0,measuredAt=performance.now(),decoded=0;
|
||||
const frame=()=>{frames++;video.requestVideoFrameCallback(frame);};
|
||||
const frame:VideoFrameRequestCallback=(now,metadata)=>{
|
||||
frames++;diagnostics.observeFrame(now,metadata);video.requestVideoFrameCallback(frame);
|
||||
};
|
||||
video.requestVideoFrameCallback(frame);
|
||||
setInterval(()=>{
|
||||
const timer=setInterval(()=>{
|
||||
const now=performance.now();
|
||||
// Presentation callbacks can be throttled independently of decoding in a
|
||||
// background view. Prefer decoded, non-dropped video frames for telemetry.
|
||||
const quality=video.getVideoPlaybackQuality?.();
|
||||
const total=quality?quality.totalVideoFrames-quality.droppedVideoFrames:decoded+frames;
|
||||
const count=Math.max(0,total-decoded);
|
||||
if(count>0)report("live",count*1000/(now-measuredAt));
|
||||
const fps=count*1000/(now-measuredAt);
|
||||
video.dataset.streamDiagnostics=JSON.stringify(diagnostics.snapshot(now,fps));
|
||||
if(count>0)report("live",fps);
|
||||
decoded=total;frames=0;measuredAt=now;
|
||||
},1000);
|
||||
const stream=new AppStreamer();
|
||||
@@ -42,6 +48,7 @@ window.addEventListener("message",(e:MessageEvent)=>{
|
||||
maxReconnects:0,connectivityTimeout:5000,
|
||||
onStart:event=>{if(event.status===EventStatus.ERROR||event.status===EventStatus.CANCELED)report("failed");},
|
||||
onStop:()=>report("failed"),
|
||||
onStreamStats:event=>diagnostics.observeNative(performance.now(),event.data?.stats),
|
||||
}}).catch(()=>report("failed"));
|
||||
window.addEventListener("pagehide",()=>{void stream.terminate(false).catch(()=>undefined);},{once:true});
|
||||
window.addEventListener("pagehide",()=>{clearInterval(timer);delete video.dataset.streamDiagnostics;void stream.terminate(false).catch(()=>undefined);},{once:true});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user