Skip to content

Commit 4426e66

Browse files
authored
Merge pull request #104 from slaveofcode/fix/optical-progress
fix(optical-transfer): honest progress (frames collected, not solved blocks)
2 parents d018211 + ab066b1 commit 4426e66

2 files changed

Lines changed: 15 additions & 8 deletions

File tree

src/islands/network/OpticalTransfer.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ function Receiver({ onBack }: { onBack: () => void }) {
128128
useEffect(() => {
129129
if (!stream) return;
130130
if (!captureRef.current) captureRef.current = document.createElement('canvas');
131-
let collected = 0;
132131

133132
const scan = () => {
134133
const video = videoRef.current;
@@ -149,13 +148,9 @@ function Receiver({ onBack }: { onBack: () => void }) {
149148
decoderRef.current = new LtDecoder(frame.k, BLOCK_SIZE);
150149
}
151150
if (frame.session === metaRef.current.session && decoderRef.current) {
152-
const before = decoderRef.current.solvedCount;
153151
const done = decoderRef.current.addFrame(frame.seq, frame.payload);
154-
if (decoderRef.current.solvedCount !== before || decoderRef.current.progress() > 0) {
155-
collected++;
156-
setFrames(collected);
157-
setProgress(decoderRef.current.progress());
158-
}
152+
setFrames(decoderRef.current.framesSeen);
153+
setProgress(decoderRef.current.progress());
159154
if (done) finish();
160155
}
161156
}

src/tools/optical/fountain.lib.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,20 @@ export class LtDecoder {
127127
return this.solvedCount >= this.k;
128128
}
129129

130+
/** Unique frames received so far. */
131+
get framesSeen(): number {
132+
return this.seenSeq.size;
133+
}
134+
135+
/**
136+
* Collection progress 0..1. LT codes solve almost nothing until they avalanche
137+
* near the end, so reporting solved-blocks looks stuck at 0%. Report frames
138+
* collected vs. the ~k×1.15 typically needed instead (capped below 1 until done).
139+
*/
130140
progress(): number {
131-
return this.k === 0 ? 1 : this.solvedCount / this.k;
141+
if (this.done) return 1;
142+
if (this.k === 0) return 1;
143+
return Math.min(0.99, this.framesSeen / (this.k * 1.15));
132144
}
133145

134146
/** Feed one frame. Returns true once the whole file is solved. */

0 commit comments

Comments
 (0)