Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions src/islands/network/OpticalTransfer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ function Receiver({ onBack }: { onBack: () => void }) {
useEffect(() => {
if (!stream) return;
if (!captureRef.current) captureRef.current = document.createElement('canvas');
let collected = 0;

const scan = () => {
const video = videoRef.current;
Expand All @@ -149,13 +148,9 @@ function Receiver({ onBack }: { onBack: () => void }) {
decoderRef.current = new LtDecoder(frame.k, BLOCK_SIZE);
}
if (frame.session === metaRef.current.session && decoderRef.current) {
const before = decoderRef.current.solvedCount;
const done = decoderRef.current.addFrame(frame.seq, frame.payload);
if (decoderRef.current.solvedCount !== before || decoderRef.current.progress() > 0) {
collected++;
setFrames(collected);
setProgress(decoderRef.current.progress());
}
setFrames(decoderRef.current.framesSeen);
setProgress(decoderRef.current.progress());
if (done) finish();
}
}
Expand Down
14 changes: 13 additions & 1 deletion src/tools/optical/fountain.lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,20 @@ export class LtDecoder {
return this.solvedCount >= this.k;
}

/** Unique frames received so far. */
get framesSeen(): number {
return this.seenSeq.size;
}

/**
* Collection progress 0..1. LT codes solve almost nothing until they avalanche
* near the end, so reporting solved-blocks looks stuck at 0%. Report frames
* collected vs. the ~k×1.15 typically needed instead (capped below 1 until done).
*/
progress(): number {
return this.k === 0 ? 1 : this.solvedCount / this.k;
if (this.done) return 1;
if (this.k === 0) return 1;
return Math.min(0.99, this.framesSeen / (this.k * 1.15));
}

/** Feed one frame. Returns true once the whole file is solved. */
Expand Down
Loading