From 9dc425b5f868cd332eafc7d9b68dbd19c203ffcf Mon Sep 17 00:00:00 2001 From: Johannes Marbach Date: Wed, 11 Nov 2026 13:52:05 +0100 Subject: [PATCH] Apply batched suggestions from code review Improve comments Co-authored-by: Timo <16718859+toger5@users.noreply.github.com> --- src/tracks/BackgroundEffectTransformer.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/tracks/BackgroundEffectTransformer.ts b/src/tracks/BackgroundEffectTransformer.ts index 9c43b0648..0ddfccae8 100644 --- a/src/tracks/BackgroundEffectTransformer.ts +++ b/src/tracks/BackgroundEffectTransformer.ts @@ -54,7 +54,10 @@ const wasmFileset: WasmFileset = { * resource fetched from the public internet. */ export class BackgroundEffectTransformer extends BackgroundTransformer { - /** Called once, when the first frame carrying an effect has been drawn. */ + /** + * Called once, when the first frame carrying an effect has been drawn. + * This is used for drewAFrame$ to show the correct loading state. + */ public onFirstFrame: (() => void) | undefined; private drewAFrame = false; @@ -74,10 +77,16 @@ export class BackgroundEffectTransformer extends BackgroundTransformer { frame: VideoFrame, controller: TransformStreamDefaultController, ): Promise { - // For the first frame, the library enqueues the raw frame ahead of the - // processed one, so that the output shows something while the first - // segmentation runs. The raw frame is the room without the effect, - // so no frame is allowed to count as the first. + // From the LK docs: + // > Render a copy of the first frame is rendered to the screen as soon as possible to act + // > as a less jarring initial state than a solid color while the synchronous work below + // > (segmentation + frame rendering) occurs. + // We do not want this copy (it leaks unblurred media). + // So we always set `isFirstFrame` to false -> never show an unprocessed frame. + // It does not have any impact other than setting the unprocessed frame while loading the processor. + // + // To not show the blank frame, we have our own mechanism for hiding the loading overlay: + // `onFirstFrame` is what the EC UI will listen to and only then show the video feed. this.isFirstFrame = false; await super.transform(frame, controller); }