Skip to content

Conversation

@theomonnom
Copy link
Member

@theomonnom theomonnom commented Jan 19, 2026

allow to reduce overhead of protocol buf for tiny frames

Summary by CodeRabbit

  • Refactor
    • Audio processing changed to handle input in 10ms chunks with validation that data is non-empty and aligned to the chunk size.
    • Processing now iterates over chunks and returns an internal error immediately on any chunk failure; overall success unchanged when all chunks succeed.

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

@coderabbitai
Copy link

coderabbitai bot commented Jan 19, 2026

📝 Walkthrough

Walkthrough

Audio processing in the APM module was refactored to handle input data in consecutive 10ms chunks instead of processing it all at once. Input validation was added to ensure data length is a non-empty multiple of the chunk size. Error handling and overall success behavior remain unchanged.

Changes

Cohort / File(s) Summary
Audio Processing Chunking
libwebrtc/src/native/apm.rs
Refactored process_stream and process_reverse_stream to iterate over 10ms audio chunks with per-chunk validation and early-return on per-chunk failures; replaced single-shot processing with loop-based chunked processing; added input-length validation (non-empty multiple of chunk size).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 Ten-millisecond hops across the stream,
I nibble bytes and stitch the seam,
Chunk by chunk the echoes mend,
A rabbit-rhythm to the end,
Soft validations guard each leap.

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately captures the main change: enabling APM to process frames that are 10ms multiples instead of requiring exact 10ms frames, which directly matches the chunked processing implementation.

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

✨ Finishing touches
  • 📝 Generate docstrings

🧹 Recent nitpick comments
libwebrtc/src/native/apm.rs (1)

83-106: Consider extracting shared chunk‑processing helper to avoid drift.

process_stream and process_reverse_stream duplicate validation, chunking, and error mapping; a private helper would keep behavior aligned and reduce maintenance overhead.

📜 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 4fc8c52 and d94d61e.

📒 Files selected for processing (1)
  • libwebrtc/src/native/apm.rs
⏰ 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 (armv7-linux-androideabi)
  • GitHub Check: Build (aarch64-apple-ios)
  • GitHub Check: Build (aarch64-apple-darwin)
  • GitHub Check: Build (x86_64-pc-windows-msvc)
  • GitHub Check: Build (x86_64-linux-android)
  • GitHub Check: Build (aarch64-linux-android)
  • GitHub Check: Build (x86_64-unknown-linux-gnu)
  • GitHub Check: Build (x86_64-apple-darwin)
  • GitHub Check: Build (aarch64-apple-ios-sim)
  • GitHub Check: Build (aarch64-unknown-linux-gnu)
  • GitHub Check: Build (aarch64-pc-windows-msvc)
  • GitHub Check: Test (x86_64-unknown-linux-gnu)
  • GitHub Check: Test (x86_64-apple-darwin)
  • GitHub Check: Test (x86_64-pc-windows-msvc)

✏️ 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.

@theomonnom theomonnom requested review from a team and davidzhao January 19, 2026 20:34
@theomonnom theomonnom changed the title allow apm 10ms multiple allow apm >=10ms frames Jan 19, 2026
Copy link

@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 `@libwebrtc/src/native/apm.rs`:
- Around line 49-54: Guard against zero sample_rate or num_channels before
computing samples_per_10ms and doing the modulo: add an early check (e.g.,
assert!(sample_rate > 0 && num_channels > 0, "sample_rate and num_channels must
be > 0") or return an Err) using the existing variables sample_rate and
num_channels, then compute samples_per_10ms and keep the existing assertion on
data.len() % samples_per_10ms; this prevents a division-by-zero when evaluating
samples_per_10ms or the modulo operation.
🧹 Nitpick comments (1)
libwebrtc/src/native/apm.rs (1)

86-91: Duplicate validation logic.

This validation is identical to process_stream. Consider extracting the chunk size calculation and validation into a helper function or macro to reduce duplication and ensure consistency.

Example helper extraction
fn samples_per_10ms_chunk(sample_rate: i32, num_channels: i32) -> usize {
    assert!(sample_rate > 0 && num_channels > 0, "sample_rate and num_channels must be positive");
    (sample_rate as usize / 100) * num_channels as usize
}

fn validate_chunk_alignment(data_len: usize, chunk_size: usize) {
    assert!(
        data_len % chunk_size == 0 && data_len >= chunk_size,
        "slice must have a multiple of 10ms worth of samples"
    );
}
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2975ff4 and 4fc8c52.

📒 Files selected for processing (1)
  • libwebrtc/src/native/apm.rs
⏰ 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-apple-ios)
  • GitHub Check: Build (armv7-linux-androideabi)
  • GitHub Check: Build (x86_64-apple-darwin)
  • GitHub Check: Build (x86_64-linux-android)
  • GitHub Check: Build (x86_64-unknown-linux-gnu)
  • GitHub Check: Build (aarch64-pc-windows-msvc)
  • GitHub Check: Build (aarch64-unknown-linux-gnu)
  • GitHub Check: Build (aarch64-linux-android)
  • GitHub Check: Build (aarch64-apple-ios-sim)
  • GitHub Check: Build (x86_64-pc-windows-msvc)
  • GitHub Check: Build (aarch64-apple-darwin)
  • GitHub Check: Test (x86_64-unknown-linux-gnu)
  • GitHub Check: Test (x86_64-apple-darwin)
  • GitHub Check: Test (x86_64-pc-windows-msvc)
🔇 Additional comments (2)
libwebrtc/src/native/apm.rs (2)

56-75: Partial buffer modification on mid-processing failure.

If processing fails on a later chunk, earlier chunks will have already been modified in-place. Callers should be aware that on error, the data buffer may be in a partially processed state. Verify this is acceptable for all call sites, or consider processing into a temporary buffer and copying back on success if atomicity is required.


93-114: LGTM!

The chunked processing loop correctly iterates over 10ms segments and handles errors appropriately. Same partial-modification caveat as process_stream applies.

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

Comment on lines 49 to 54
// 10ms worth of samples per chunk
let samples_per_10ms = (sample_rate as usize / 100) * num_channels as usize;
assert!(
data.len() % samples_per_10ms == 0 && data.len() >= samples_per_10ms,
"slice must have a multiple of 10ms worth of samples"
);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Potential division-by-zero before assertion.

If sample_rate or num_channels is zero, samples_per_10ms will be zero, causing a panic on the modulo operation before the assertion message is shown. Consider adding a guard or separate assertion for these parameters if they could ever be invalid.

Suggested defensive check
         // 10ms worth of samples per chunk
+        assert!(sample_rate > 0 && num_channels > 0, "sample_rate and num_channels must be positive");
         let samples_per_10ms = (sample_rate as usize / 100) * num_channels as usize;
         assert!(
             data.len() % samples_per_10ms == 0 && data.len() >= samples_per_10ms,
             "slice must have a multiple of 10ms worth of samples"
         );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// 10ms worth of samples per chunk
let samples_per_10ms = (sample_rate as usize / 100) * num_channels as usize;
assert!(
data.len() % samples_per_10ms == 0 && data.len() >= samples_per_10ms,
"slice must have a multiple of 10ms worth of samples"
);
// 10ms worth of samples per chunk
assert!(sample_rate > 0 && num_channels > 0, "sample_rate and num_channels must be positive");
let samples_per_10ms = (sample_rate as usize / 100) * num_channels as usize;
assert!(
data.len() % samples_per_10ms == 0 && data.len() >= samples_per_10ms,
"slice must have a multiple of 10ms worth of samples"
);
🤖 Prompt for AI Agents
In `@libwebrtc/src/native/apm.rs` around lines 49 - 54, Guard against zero
sample_rate or num_channels before computing samples_per_10ms and doing the
modulo: add an early check (e.g., assert!(sample_rate > 0 && num_channels > 0,
"sample_rate and num_channels must be > 0") or return an Err) using the existing
variables sample_rate and num_channels, then compute samples_per_10ms and keep
the existing assertion on data.len() % samples_per_10ms; this prevents a
division-by-zero when evaluating samples_per_10ms or the modulo operation.

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.

2 participants