-
Notifications
You must be signed in to change notification settings - Fork 937
fix: clamp opus rate selection for high input #1268
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
fix: clamp opus rate selection for high input #1268
Conversation
WalkthroughRefactored Opus encoder's inline rate-selection into a private helper Changes
Sequence Diagram(s)sequenceDiagram
participant Caller as Opus encoder setup
participant Helper as select_output_rate()
participant Rates as supported_rates
Caller->>Helper: provide input_rate, supported_rates
Helper->>Rates: search for first rate >= input_rate
alt found
Rates-->>Helper: matching_rate
Helper-->>Caller: return matching_rate
else not found
Rates-->>Helper: no match (all < input_rate)
Helper->>Rates: select highest_supported_rate
Rates-->>Helper: highest_rate
Helper-->>Caller: return highest_rate
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used📓 Path-based instructions (2)**/*.rs📄 CodeRabbit inference engine (AGENTS.md)
Files:
crates/*/src/**/*📄 CodeRabbit inference engine (AGENTS.md)
Files:
🧬 Code graph analysis (1)crates/enc-ffmpeg/src/audio/buffered_resampler.rs (1)
⏰ 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). (3)
🔇 Additional comments (1)
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 (1)
crates/enc-ffmpeg/src/audio/opus.rs (1)
105-111: Clean and efficient implementation!The logic correctly handles all cases:
- Returns the first supported rate ≥ input rate
- Falls back to the maximum supported rate when input exceeds all options
- Returns
Nonefor empty slices (properly handled by the caller)Optional: Consider adding a doc comment noting that
supported_ratesshould be sorted for optimal results, though this is already ensured by the caller on line 60.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
crates/enc-ffmpeg/src/audio/opus.rs(2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.rs
📄 CodeRabbit inference engine (AGENTS.md)
**/*.rs: Format Rust code usingrustfmtand ensure all Rust code passes workspace-level clippy lints.
Rust modules should be named with snake_case, and crate directories should be in kebab-case.
Files:
crates/enc-ffmpeg/src/audio/opus.rs
crates/*/src/**/*
📄 CodeRabbit inference engine (AGENTS.md)
Rust crates should place tests within the
src/and/or a siblingtests/directory for each crate insidecrates/*.
Files:
crates/enc-ffmpeg/src/audio/opus.rs
🧬 Code graph analysis (1)
crates/enc-ffmpeg/src/audio/opus.rs (1)
crates/media-info/src/lib.rs (1)
rate(125-127)
⏰ 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). (3)
- GitHub Check: Build Desktop (x86_64-pc-windows-msvc, windows-latest)
- GitHub Check: Build Desktop (aarch64-apple-darwin, macos-latest)
- GitHub Check: Analyze (rust)
🔇 Additional comments (2)
crates/enc-ffmpeg/src/audio/opus.rs (2)
62-63: Excellent refactoring that fixes the high input rate bug!The extraction of rate selection logic into
select_output_rate()improves testability and correctly handles the edge case where input rate exceeds all supported rates. The function now properly clamps to the maximum supported rate instead of falling back to the minimum, ensuring better audio quality for high input rates.
113-134: Comprehensive test coverage!The three test cases effectively validate the function's behavior:
- Exact matching rate selection
- Clamping to the highest supported rate for high inputs (validates the bug fix)
- Selecting the nearest higher rate for low inputs
The tests prevent regression of the original bug where high input rates would incorrectly fall back to the minimum instead of the maximum supported rate.
Summary by CodeRabbit
Tests
Refactor