Skip to content

add bounded buffer to audio_stream, and use 10 frames as the default#945

Merged
xianshijing-lk merged 4 commits intomainfrom
CLT-2637/use-bounded-buffer-for-playback-stream
Mar 18, 2026
Merged

add bounded buffer to audio_stream, and use 10 frames as the default#945
xianshijing-lk merged 4 commits intomainfrom
CLT-2637/use-bounded-buffer-for-playback-stream

Conversation

@xianshijing-lk
Copy link
Copy Markdown
Contributor

No description provided.

@xianshijing-lk xianshijing-lk requested a review from ladvoc March 14, 2026 06:05
Copy link
Copy Markdown
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.

question: Is there a good reason to define a custom async queue primitive here instead of using tokio’s bounded mpsc channel? One possible motivation seems to be providing a synchronous push method. If that’s the goal, mpsc::Sender::try_send already supports that behavior. In general, I’d lean toward using mpsc (or a wrapper around it) here since it’s lock-free, well-tested, and we already pull in tokio as a dependency—unless there's a specific behavior it can't offer.

@xianshijing-lk
Copy link
Copy Markdown
Contributor Author

question: Is there a good reason to define a custom async queue primitive here instead of using tokio’s bounded mpsc channel? One possible motivation seems to be providing a synchronous push method. If that’s the goal, mpsc::Sender::try_send already supports that behavior. In general, I’d lean toward using mpsc (or a wrapper around it) here since it’s lock-free, well-tested, and we already pull in tokio as a dependency—unless there's a specific behavior it can't offer.

The custom queue is not mainly about synchronous push. It exists because we need overwrite/ring-buffer semantics from a synchronous WebRTC callback. tokio::mpsc::try_send covers sync push, but not the drop oldest behavior.

This is my understanding:
The difference is in libwebrtc/src/native/audio_stream.rs:127: the current queue is explicitly drop oldest, keep newest when full. That matches the public contract in libwebrtc/src/audio_stream.rs:34 and livekit-ffi/protocol/
audio_frame.proto:28: keep latency bounded for real-time audio.

tokio::mpsc::Sender::try_send only gives us synchronous non-blocking push. It does not give this overflow policy. On full, it rejects the new item. For audio streaming, drop newest is usually worse than drop oldest, because it
preserves backlog and increases effective latency.

Please let me know if that makes sense, I'd be happy to switch over to mpsc channel if that behavior is more desirable.

@xianshijing-lk xianshijing-lk force-pushed the CLT-2637/use-bounded-buffer-for-playback-stream branch from 9ae7684 to 98acc65 Compare March 16, 2026 05:28
@ladvoc ladvoc self-requested a review March 16, 2026 16:42
Copy link
Copy Markdown
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.

Got it, that makes a lot of sense. There are some specialized channel implementations that use lock-free ring buffers that offer this behavior; rtrb (not async) and async_ringbuf are good references for this. If the locking overhead here is acceptable, I’d stick with the current approach. Otherwise, it may be worth exploring something closer to what rtrb does.

@xianshijing-lk
Copy link
Copy Markdown
Contributor Author

Got it, that makes a lot of sense. There are some specialized channel implementations that use lock-free ring buffers that offer this behavior; rtrb (not async) and async_ringbuf are good references for this. If the locking overhead here is acceptable, I’d stick with the current approach. Otherwise, it may be worth exploring something closer to what rtrb does.

I did some research on rtrb, that is a tiny, high performance lock-free ring buffer, thanks for pointing it out.

I changed the implementation to rtrb, and added some tests there.

@xianshijing-lk xianshijing-lk merged commit 03875c8 into main Mar 18, 2026
23 checks passed
@xianshijing-lk xianshijing-lk deleted the CLT-2637/use-bounded-buffer-for-playback-stream branch March 18, 2026 00:26
@knope-bot knope-bot bot mentioned this pull request Mar 18, 2026
theomonnom pushed a commit that referenced this pull request Mar 23, 2026
> [!IMPORTANT]
> Merging this pull request will create these releases

# libwebrtc 0.3.27 (2026-03-22)
## Features

### E2EE: allow setting key_ring_size and key_derivation_algorithm,
update webrtc to m144

#921 by @onestacked

This PR uses [this webrtc-sdk
PR](webrtc-sdk/webrtc#224) to configure the KDF.

I've tested this with
https://codeberg.org/esoteric_programmer/matrix-jukebox and it is
compatible with Element Call.

Fixed: #796

## Fixes

- Fix H.264 codec matching

### add bounded buffer to audio_stream, and use 10 frames as the default

#945 by @xianshijing-lk

### fix clang build issue from zed patches (#949)

#950 by @cloudwebrtc

* webrtc-sys: Use clang instead of gcc

* Debug CI output for aarch64-linux

* ci: Install lld for aarch64-linux FFI builders

* webrtc-sys: Disable CREL
# livekit 0.7.34 (2026-03-22)
## Features

### E2EE: allow setting key_ring_size and key_derivation_algorithm,
update webrtc to m144

#921 by @onestacked

This PR uses [this webrtc-sdk
PR](webrtc-sdk/webrtc#224) to configure the KDF.

I've tested this with
https://codeberg.org/esoteric_programmer/matrix-jukebox and it is
compatible with Element Call.

Fixed: #796

## Fixes

- Add disconnectReason to Room::close
- End-to-end testing for video streams
- Fix H.264 codec matching

### add bounded buffer to audio_stream, and use 10 frames as the default

#945 by @xianshijing-lk

### fix PC timeout when connecting with can_subscribe=false

#955 by @s-hamdananwar

When a participant connects with `canSubscribe=false` in their token,
the server sends `subscriber_primary=false` in the JoinResponse and does
not send a subscriber offer. This results in `wait_pc_connection` timing
out as it is expecting a subscriber PC even when the publisher PC is
primary. This PR will skip waiting for subscriber PC when
`subscriber_primary=false`.

### Send client os and os_version from rust

#952 by @MaxHeimbrock

Adds [os_info](https://crates.io/crates/os_info) crate as dependency and
sends the data for client connections.
# livekit-ffi 0.12.50 (2026-03-22)
## Features

### E2EE: allow setting key_ring_size and key_derivation_algorithm,
update webrtc to m144

#921 by @onestacked

This PR uses [this webrtc-sdk
PR](webrtc-sdk/webrtc#224) to configure the KDF.

I've tested this with
https://codeberg.org/esoteric_programmer/matrix-jukebox and it is
compatible with Element Call.

Fixed: #796

## Fixes

- Fix H.264 codec matching

### add bounded buffer to audio_stream, and use 10 frames as the default

#945 by @xianshijing-lk

### Send client os and os_version from rust

#952 by @MaxHeimbrock

Adds [os_info](https://crates.io/crates/os_info) crate as dependency and
sends the data for client connections.
# webrtc-sys 0.3.25 (2026-03-22)
## Fixes

- fix: enable AGC2 adaptive digital controller
- Fix H.264 codec matching

### E2EE: allow setting key_ring_size and key_derivation_algorithm,
update webrtc to m144

#921 by @onestacked

This PR uses [this webrtc-sdk
PR](webrtc-sdk/webrtc#224) to configure the KDF.

I've tested this with
https://codeberg.org/esoteric_programmer/matrix-jukebox and it is
compatible with Element Call.

Fixed: #796

### fix clang build issue from zed patches (#949)

#950 by @cloudwebrtc

* webrtc-sys: Use clang instead of gcc

* Debug CI output for aarch64-linux

* ci: Install lld for aarch64-linux FFI builders

* webrtc-sys: Disable CREL
# livekit-datatrack 0.1.1 (2026-03-22)
## Features

- Initial release.
# webrtc-sys-build 0.3.14 (2026-03-22)
## Fixes

### fix: Bump webrtc build to fix build for Android JNI prefixed.

#954 by @cloudwebrtc

### fix clang build issue from zed patches (#949)

#950 by @cloudwebrtc

* webrtc-sys: Use clang instead of gcc

* Debug CI output for aarch64-linux

* ci: Install lld for aarch64-linux FFI builders

* webrtc-sys: Disable CREL
# livekit-protocol 0.7.2 (2026-03-22)
## Fixes

- Add disconnectReason to Room::close
# livekit-api 0.4.16 (2026-03-22)
## Fixes

### Send client os and os_version from rust

#952 by @MaxHeimbrock

Adds [os_info](https://crates.io/crates/os_info) crate as dependency and
sends the data for client connections.

Co-authored-by: knope-bot[bot] <152252888+knope-bot[bot]@users.noreply.github.com>
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