Skip to content

Conversation

@tbarbugli
Copy link
Member

@tbarbugli tbarbugli commented Nov 12, 2025

Summary by CodeRabbit

  • New Features

    • Introduced from_numpy() method for audio data creation with improved validation and type handling.
    • Enhanced audio track handling to maintain participant context throughout the processing pipeline.
  • Refactor

    • Simplified subscriber audio event handler for improved data flow clarity.
  • Tests

    • Expanded test coverage for new PCM data API and error handling scenarios.

@coderabbitai
Copy link

coderabbitai bot commented Nov 12, 2025

Walkthrough

Changes refactor PCM audio data handling to use numpy arrays exclusively, attach participant context directly to PCM objects rather than passing as tuples, simplify audio callbacks to accept only PCM data, and introduce helper utilities for centralized chunk processing and width calculations.

Changes

Cohort / File(s) Summary
Audio handler refactoring
getstream/video/rtc/pc.py, getstream/video/rtc/peer_connection.py
Refactored audio emission flow: participant context now attached to PCM objects (pcm.participant) before emission rather than passed as tuple; audio callbacks simplified to accept only pcm_data parameter; inline lambda handlers replaced with explicit helper functions.
PcmData API refactoring
getstream/video/rtc/track_util.py
Renamed from_data to from_numpy (numpy arrays only); removed bytes/bytearray/memoryview support paths; added helper functions (_calculate_sample_width, _process_iterator_chunk, _finalize_iterator_buffer); refactored from_response and streaming logic to centralize width calculation and chunk emission.
Test updates
tests/rtc/test_pcm_data.py
Updated existing tests to use from_numpy instead of from_data; added new test cases for numpy-specific validation and error handling (test_from_numpy_handles_conversion_automatically, test_from_numpy_rejects_bytes); adjusted error message expectations to reference new API paths.

Sequence Diagram

sequenceDiagram
    autonumber
    participant Subscriber
    participant AudioTrack as AudioTrackHandler
    participant OldHandler as Old: Inline Lambda
    participant NewHandler as New: _emit_pcm
    participant Listener as Audio Listener

    Note over Subscriber,Listener: Before (on_track lambda)
    Subscriber->>AudioTrack: receive PCM chunk
    AudioTrack->>OldHandler: emit(pcm, user)
    OldHandler->>Listener: on_audio(pcm, user)

    Note over Subscriber,Listener: After (_emit_pcm helper)
    Subscriber->>AudioTrack: receive PCM chunk
    AudioTrack->>NewHandler: _emit_pcm(pcm)
    NewHandler->>NewHandler: pcm.participant = user
    NewHandler->>Listener: on_audio(pcm)
    Listener->>Listener: extract participant from pcm.participant
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • API signature changes: from_datafrom_numpy affects all call sites; review existing usages to ensure correct parameter types (numpy arrays only).
  • Participant context flow: Verify participant attachment logic in pc.py correctly associates users with PCM objects before emission, and that listeners properly access pcm.participant.
  • Helper function correctness: Validate _calculate_sample_width, _process_iterator_chunk, and _finalize_iterator_buffer handle frame boundaries, padding, and chunk emission correctly.
  • Streaming refactoring: Ensure both async and sync iterator paths in from_response produce equivalent PCM chunks with no data loss or duplication.

Possibly related PRs

  • add participant to pcm #176: Adds and propagates participant attribute on PcmData; directly related to this PR's participant context attachment approach.
  • More audio utils #173: Modifies PCM/audio handling in rtc modules with related event and handler flow changes.
  • Audio utils #170: Updates PcmData API and implementation in track_util.py; shares overlapping refactoring scope.

Poem

🐰 A hop through audio streams so fine,
Where participants now ride the PCM line,
NumPy arrays cleaned up the way,
No more tuples to carry the day—
Chunks flow cleaner, helpers align! 🎧

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ 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 summarizes the two main objectives of the changeset: refactoring PcmData constructors (from_data → from_numpy) and ensuring participant information is populated in audio events.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch pcmdata-cleaner

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between ece3982 and ddc4203.

📒 Files selected for processing (4)
  • getstream/video/rtc/pc.py (1 hunks)
  • getstream/video/rtc/peer_connection.py (1 hunks)
  • getstream/video/rtc/track_util.py (5 hunks)
  • tests/rtc/test_pcm_data.py (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (4)
getstream/video/rtc/pc.py (1)
getstream/video/rtc/track_util.py (2)
  • PcmData (87-1403)
  • AudioTrackHandler (1943-2054)
getstream/video/rtc/peer_connection.py (1)
getstream/utils/event_emitter.py (1)
  • emit (21-85)
getstream/video/rtc/track_util.py (1)
getstream/stream_response.py (1)
  • data (22-24)
tests/rtc/test_pcm_data.py (1)
getstream/video/rtc/track_util.py (2)
  • PcmData (87-1403)
  • from_numpy (361-429)
🔇 Additional comments (1)
getstream/video/rtc/peer_connection.py (1)

45-47: Confirm downstream audio listeners match new signature.

connection_manager.emit("audio", pcm_data) now provides a single argument. Please double-check every registered "audio" listener (internal and customer-facing) no longer expects (pcm, user) and instead reads the participant from pcm_data.participant, otherwise this will break audio delivery once released.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@tbarbugli tbarbugli merged commit 60d59d8 into main Nov 12, 2025
4 of 5 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