Add audio encoder reconfiguration#1362
Conversation
|
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
✅ Files skipped from review due to trivial changes (2)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughThe audio encoder now creates its AudioConfig lazily from the first captured audio frame: the worklet message handler reads data.channels.length and calls a new 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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.
Actionable comments posted: 1
🧹 Nitpick comments (1)
js/publish/src/audio/encoder.ts (1)
135-145: Extract the Opus defaults into named constants.
32_000and20are now part of the encoder policy, so keeping them inline makes later tuning harder and hides intent.As per coding guidelines, "Avoid using magic numbers; use named constants instead."♻️ Suggested refactor
+const OPUS_BITRATE_PER_CHANNEL = 32_000; +const OPUS_FRAME_DURATION_MS = 20 as Time.Milli; + `#createConfig`(worklet: AudioWorkletNode, channelCount: number): Catalog.AudioConfig { return { codec: "opus", sampleRate: Catalog.u53(worklet.context.sampleRate), numberOfChannels: Catalog.u53(channelCount), - bitrate: Catalog.u53(channelCount * 32_000), + bitrate: Catalog.u53(channelCount * OPUS_BITRATE_PER_CHANNEL), container: { kind: "legacy" } as const, // TODO parse the actual frame duration instead of assuming 20ms. // Opus supports 2.5–60ms but 20ms is the real-time default. - jitter: Catalog.u53(20), + jitter: Catalog.u53(OPUS_FRAME_DURATION_MS), }; }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@js/publish/src/audio/encoder.ts` around lines 135 - 145, Extract the magic numbers in `#createConfig` into named constants (e.g., DEFAULT_OPUS_BITRATE_PER_CHANNEL = 32000 and DEFAULT_OPUS_FRAME_MS = 20) defined near the top of the module and replace the inline literals (32_000 and 20) in the bitrate and jitter calculations with those constants (use Catalog.u53(DEFAULT_OPUS_BITRATE_PER_CHANNEL * channelCount) for bitrate and Catalog.u53(DEFAULT_OPUS_FRAME_MS) for jitter) so the encoder policy values are explicit and easier to tune later.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@js/publish/src/audio/encoder.ts`:
- Around line 122-125: The cleanup currently clears the encoder config via
this.#config.set(undefined) but leaves the derived catalog stale; update the
effect.cleanup block (the same place that nulls worklet.port.onmessage and calls
this.#config.set(undefined)) to also reset the derived catalog produced by
`#runCatalog` — e.g., call the catalog-reset method/property (the internal
`#catalog` setter/clear function) so that `#catalog` no longer exposes the previous
rendition after source teardown or reinit.
---
Nitpick comments:
In `@js/publish/src/audio/encoder.ts`:
- Around line 135-145: Extract the magic numbers in `#createConfig` into named
constants (e.g., DEFAULT_OPUS_BITRATE_PER_CHANNEL = 32000 and
DEFAULT_OPUS_FRAME_MS = 20) defined near the top of the module and replace the
inline literals (32_000 and 20) in the bitrate and jitter calculations with
those constants (use Catalog.u53(DEFAULT_OPUS_BITRATE_PER_CHANNEL *
channelCount) for bitrate and Catalog.u53(DEFAULT_OPUS_FRAME_MS) for jitter) so
the encoder policy values are explicit and easier to tune later.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 303c3d0b-f618-4cc8-8dc4-0ca6da4ac682
📒 Files selected for processing (1)
js/publish/src/audio/encoder.ts
For some platforms (looking at you Apple) we can't reliably get the channel count from the media track, this information becomes available only when looking at the data inside of audio worklet callback. The following changes allow for config creation only after receiving the first batch of samples.
fb88a5c to
fb72613
Compare
For some platforms (looking at you Apple) we can't reliably get the channel count from the media track, this information becomes available only when looking at the data inside of audio worklet callback.
The following changes allow for config creation only after receiving the first batch of samples.