Skip to content

fix(rtc): deliver media stream events only to their own stream - #910

Merged
cloudwebrtc merged 1 commit into
livekit:mainfrom
swayamg20:fix/563-per-stream-ffi-filter
Nov 2, 2026
Merged

cloudwebrtc merged 1 commit into
livekit:mainfrom
swayamg20:fix/563-per-stream-ffi-filter

Conversation

@swayamg20

Copy link
Copy Markdown
Contributor

Summary

#564 added event-type filtering, which fixed the leak in the title, but every AudioStream and VideoStream subscriber still received every other stream's frame events, so the event-loop work grew with the square of the stream count. AudioSource.capture_frame also subscribed to all FFI events on every frame.

  • AudioStream and VideoStream filters also match stream_handle against the stream's own handle once the create request returns. They still subscribe before creating the stream, so no early frames or EOS are missed
  • capture_frame subscribes only to capture_audio_frame events, narrowed to its own async_id once the request returns

This uses the same handle filter as data_track.py and data_stream.py, and doesn't touch FfiQueue, so it's independent of #892.

Refs #563

Testing

  • uv run pytest tests/rtc/test_media_ffi_filter.py tests/rtc/test_ffi_queue.py tests/rtc/test_room_ffi_filter.py -q -W error
  • uv run mypy livekit-rtc
  • uv run ruff check . and uv run ruff format --check .

@devin-ai-integration devin-ai-integration Bot 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.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@cloudwebrtc cloudwebrtc 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!

@cloudwebrtc
cloudwebrtc merged commit e205a8c into livekit:main Nov 2, 2026
40 checks passed
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