Skip to content

Fix the fast path in capture_frame function, without buffering - #778

Merged
ladvoc merged 2 commits into
mainfrom
sxian/CLT-1549/fix_fast_path_capture_frame
Nov 4, 2025
Merged

Fix the fast path in capture_frame function, without buffering#778
ladvoc merged 2 commits into
mainfrom
sxian/CLT-1549/fix_fast_path_capture_frame

Conversation

@xianshijing-lk

Copy link
Copy Markdown
Contributor

As context:
queue_size_ms=0 is supposed to disable the buffer:

if (queue_size_samples_) {
int available =
(queue_size_samples_ + notify_threshold_samples_) - buffer_.size();
if (available < data.size())
return false;
if (on_complete_ || capture_userdata_)
return false;
buffer_.insert(buffer_.end(), data.begin(), data.end());
if (buffer_.size() <= notify_threshold_samples_) {
on_complete(ctx); // complete directly
} else {
on_complete_ = on_complete;
capture_userdata_ = ctx;
}
} else {
// capture directly when the queue buffer is 0 (frame size must be 10ms)
for (auto sink : sinks_)
sink->OnData(data.data(), sizeof(int16_t) * 8, sample_rate,
number_of_channels, number_of_frames);
}

But it is incorrectly handled in audio_source.rs:

for chunk in frame.data.chunks(self.queue_size_samples as usize) {

Calling chunks with 0 causes panic.

This PR implements the fast path that push the frame to webrtc directly

@xianshijing-lk
xianshijing-lk requested a review from ladvoc November 4, 2025 03:56

@ladvoc ladvoc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM ✅, just one small suggestion.

Comment thread libwebrtc/src/native/audio_source.rs
@xianshijing-lk

Copy link
Copy Markdown
Contributor Author

I need to go out for a doctor appt, feel free to land it or wait until I am back this evening.

Thanks

@ladvoc
ladvoc merged commit 0a193a4 into main Nov 4, 2025
22 of 23 checks passed
@ladvoc
ladvoc deleted the sxian/CLT-1549/fix_fast_path_capture_frame branch November 4, 2025 05:17
@github-actions github-actions Bot mentioned this pull request Nov 4, 2025
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