Skip to content

fix the 440->441 samples issue and pass a noop callback for release#848

Merged
xianshijing-lk merged 6 commits intomainfrom
sxian/BOT-207/fix_ffi_audio_frame_req
Jan 28, 2026
Merged

fix the 440->441 samples issue and pass a noop callback for release#848
xianshijing-lk merged 6 commits intomainfrom
sxian/BOT-207/fix_ffi_audio_frame_req

Conversation

@xianshijing-lk
Copy link
Contributor

@xianshijing-lk xianshijing-lk commented Jan 23, 2026

this PR does:

  1. fix the issues that it will use 440 as number of 10ms samples when sample rate is 44100, which will split the 441 samples into 440 + 1 samples in two callbacks
  2. fix the issue that when queue_size_ms is 0, audio_source.rs will passing null callback will crash the app in release mode.
    3

Summary by CodeRabbit

Bug Fixes

  • Audio Processing Improvements: Fixed audio queue sizing calculation to ensure accurate rounding behavior and corrected initialization of audio parameters to prevent indeterminate states. Enhanced fast-path handling for scenarios with no audio buffering, improving stability and predictability of audio stream processing.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 23, 2026

📝 Walkthrough

Walkthrough

These changes modify audio source queue initialization across Rust and C++ components, adjusting queue size calculation order, introducing explicit zero-initialization of struct members, and adding a no-op callback for fast-path handling when no buffering is needed.

Changes

Cohort / File(s) Summary
Audio Queue Calculation & Fast-Path Handling
libwebrtc/src/native/audio_source.rs
Queue size calculation reordered from queue_size_ms * (sample_rate / 1000) * num_channels to (queue_size_ms * sample_rate * num_channels) / 1000 to alter evaluation order and rounding behavior; extern "C" no-op callback added for fast-path handling without buffering.
webrtc-sys/include/livekit/audio_track.h
webrtc-sys/src/audio_track.cpp

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A queue so swift, now properly aligned,
From calculation reordered with care in mind,
With zero-paths clear and no-ops defined,
Audio buffers dance—synchronized and refined! 🎵

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly addresses the two main objectives of the pull request: fixing the 440→441 samples calculation issue and passing a noop callback for release mode stability.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b092a2d and 3c06381.

📒 Files selected for processing (3)
  • libwebrtc/src/native/audio_source.rs
  • webrtc-sys/include/livekit/audio_track.h
  • webrtc-sys/src/audio_track.cpp
🚧 Files skipped from review as they are similar to previous changes (3)
  • webrtc-sys/src/audio_track.cpp
  • libwebrtc/src/native/audio_source.rs
  • webrtc-sys/include/livekit/audio_track.h
⏰ 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). (10)
  • GitHub Check: Build (aarch64-unknown-linux-gnu)
  • GitHub Check: Build (aarch64-pc-windows-msvc)
  • GitHub Check: Build (aarch64-apple-ios)
  • GitHub Check: Build (aarch64-apple-darwin)
  • GitHub Check: Build (x86_64-pc-windows-msvc)
  • GitHub Check: Build (aarch64-linux-android)
  • GitHub Check: Build (x86_64-unknown-linux-gnu)
  • GitHub Check: Build (aarch64-apple-ios-sim)
  • GitHub Check: Test (x86_64-apple-darwin)
  • GitHub Check: Build (x86_64-apple-darwin)

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

// Pass null ctx + null callback; C++ ignores them in direct mode
let data: &[i16] = frame.data.as_ref();
// Use a valid no-op callback instead of null for safety
// In release mode, transmuting null pointers can cause UB
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL, makes sense

Copy link
Contributor

@ladvoc ladvoc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM ✅

@xianshijing-lk xianshijing-lk force-pushed the sxian/BOT-207/fix_ffi_audio_frame_req branch from ac6eb83 to b092a2d Compare January 28, 2026 00:58
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@examples/local_video/src/list_devices.rs`:
- Around line 104-111: The formatter error is due to the multi-line expression
building fps_text from fps_list; reformat the block (or run cargo fmt --package
local_video) so the chained iterator/map/collect/join call meets rustfmt style:
locate the fps_text assignment that references fps_list, the iterator .map(|fps|
fps.to_string()).collect::<Vec<String>>().join(", "), and re-run rustfmt (cargo
fmt) or adjust line breaks to match rustfmt expectations.
🧹 Nitpick comments (1)
examples/local_video/Cargo.toml (1)

46-52: Consider removing the top-level objc2 dependency.

objc2 is only needed for macOS, but it's declared twice: once at the top level (line 46) and again under [target.'cfg(target_os = "macos")'.dependencies] (line 52). The top-level declaration will pull in objc2 on all platforms unnecessarily.

♻️ Suggested fix: Remove redundant top-level objc2
 bytemuck = { version = "1.16", features = ["derive"] }
 
-objc2 = { version = "0.6.0", features = ["relax-sign-encoding"] }
-
 nokhwa = { version = "0.10", default-features = false, features = ["output-threaded"] }
 
 [target.'cfg(target_os = "macos")'.dependencies]
 nokhwa = { version = "0.10", default-features = false, features = ["input-avfoundation", "output-threaded"] }
 objc2 = { version = "0.6.0", features = ["relax-sign-encoding"] }
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 25f7738 and b092a2d.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (2)
  • examples/local_video/Cargo.toml
  • examples/local_video/src/list_devices.rs
🧰 Additional context used
🪛 GitHub Actions: Rust Formatting
examples/local_video/src/list_devices.rs

[error] 104-108: cargo fmt -- --check failed: formatting difference detected in list_devices.rs; expected single-line join expression (currently multi-line) after refactor. Run 'cargo fmt' to fix formatting.

⏰ 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). (14)
  • GitHub Check: Build (aarch64-pc-windows-msvc)
  • GitHub Check: Build (armv7-linux-androideabi)
  • GitHub Check: Build (aarch64-linux-android)
  • GitHub Check: Build (aarch64-unknown-linux-gnu)
  • GitHub Check: Build (x86_64-pc-windows-msvc)
  • GitHub Check: Build (x86_64-linux-android)
  • GitHub Check: Build (aarch64-apple-ios)
  • GitHub Check: Build (x86_64-unknown-linux-gnu)
  • GitHub Check: Build (aarch64-apple-ios-sim)
  • GitHub Check: Build (x86_64-apple-darwin)
  • GitHub Check: Build (aarch64-apple-darwin)
  • GitHub Check: Test (x86_64-apple-darwin)
  • GitHub Check: Test (x86_64-unknown-linux-gnu)
  • GitHub Check: Test (x86_64-pc-windows-msvc)
🔇 Additional comments (4)
examples/local_video/src/list_devices.rs (2)

30-43: LGTM! Good portability improvement.

The refactoring to use only Nokhwa public APIs instead of platform-specific bindings like nokhwa_bindings_macos is a solid approach for cross-platform support. The defensive .clone() on the camera index is appropriate.


48-67: LGTM! FourCC enumeration with fallback is well-structured.

The logic correctly tries FourCC-based queries first and falls back to generic camera formats when unavailable. Sorting and deduping the FPS lists ensures consistent output.

examples/local_video/Cargo.toml (2)

7-8: LGTM! Feature gate for desktop binaries.

The empty desktop feature serves as a clean opt-in gate for the desktop-specific binaries. This is a reasonable pattern to prevent accidental compilation on unsupported platforms.


48-58: LGTM! Per-target nokhwa configuration is well-structured.

The pattern of declaring a base nokhwa dependency with output-threaded and then overriding with platform-specific input features (input-avfoundation, input-v4l, input-msmf) is correct. Cargo merges features from both declarations, ensuring each platform gets the appropriate input backend.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

@xianshijing-lk xianshijing-lk force-pushed the sxian/BOT-207/fix_ffi_audio_frame_req branch from b092a2d to a3cd2be Compare January 28, 2026 02:34
@xianshijing-lk xianshijing-lk merged commit 128101e into main Jan 28, 2026
22 checks passed
@xianshijing-lk xianshijing-lk deleted the sxian/BOT-207/fix_ffi_audio_frame_req branch January 28, 2026 03:27
@github-actions github-actions bot mentioned this pull request Jan 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants