-
Notifications
You must be signed in to change notification settings - Fork 134
Properly cancel the video encoder. #590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Walkthrough
Pre-merge checks (3 passed)✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
js/hang/src/publish/video/encoder.ts (3)
119-139: Avoid dropping trailing chunks on graceful stop: break + flush.A
returninside the loop skips flushing pending output. Prefer breaking the loop and flushing, racing withcancelto stay responsive.Apply:
encoder.encode(frame, { keyFrame }); - next = await Promise.race([reader.read(), cancel]); - if (!next || !next.value) return; + next = await Promise.race([reader.read(), cancel]); + if (!next || !next.value) break; frame = next.value; } + // Drain any queued output unless we're canceled. + await Promise.race([encoder.flush(), cancel]).catch(() => {}); + effect.set(this.#active, false, false);
131-133: Guard against encoder queue backpressure.
encode()can throw whenencodeQueueSizegrows. Throttle slightly to avoid spikes in software paths.For example:
- encoder.encode(frame, { keyFrame }); + // Backpressure: keep queue small for realtime. + while (encoder.encodeQueueSize > 2) { + await Promise.race([new Promise(r => setTimeout(r, 1)), cancel]); + } + encoder.encode(frame, { keyFrame });
286-291: Nit: spelling in comments.“nessisarily” → “necessarily” (twice).
- // Annex-B allows changing the resolution without nessisarily updating the catalog (description). + // Annex-B allows changing the resolution without necessarily updating the catalog (description).
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
js/hang/src/publish/broadcast.ts(0 hunks)js/hang/src/publish/video/encoder.ts(1 hunks)
💤 Files with no reviewable changes (1)
- js/hang/src/publish/broadcast.ts
🧰 Additional context used
📓 Path-based instructions (1)
{rs,js}/hang/**
📄 CodeRabbit inference engine (CLAUDE.md)
{rs,js}/hang/**: All media-specific logic (encoding/streaming, codec handling) must live in the hang layer.
Keep the hang layer generic: expose primitives (e.g., access to individual frames) and avoid application/UI-specific code.
Files:
js/hang/src/publish/video/encoder.ts
🧠 Learnings (1)
📓 Common learnings
Learnt from: CR
PR: kixelated/moq#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-11T20:16:03.101Z
Learning: Applies to {rs,js}/hang/** : All media-specific logic (encoding/streaming, codec handling) must live in the hang layer.
🧬 Code graph analysis (1)
js/hang/src/publish/video/encoder.ts (1)
js/hang/src/frame.ts (1)
cancel(87-108)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Check
🔇 Additional comments (1)
js/hang/src/publish/video/encoder.ts (1)
133-137: Nice: cancellation now exits the read loop promptly.Racing
reader.read()withcancelinside the loop prevents blocking on reads and brings this code in line with the pattern used in frame.ts. LGTM.
Summary by CodeRabbit