Skip to content

Remove the usage of the forked aiortc-getstream lib#221

Merged
dangusev merged 7 commits intomainfrom
fix/remove-aiortc-getstream
Mar 17, 2026
Merged

Remove the usage of the forked aiortc-getstream lib#221
dangusev merged 7 commits intomainfrom
fix/remove-aiortc-getstream

Conversation

@dangusev
Copy link
Copy Markdown
Contributor

@dangusev dangusev commented Mar 13, 2026

aiortc-getstream patches the default bitrate values for vpx and h264 codecs to support higher video quality.
But it's outdated and not maintained.

This PR introduces the original aiortc lib back and a patches these bitrate values on-the-fly.
This way, we can stay up-to-date with recent aiortc and pyav quickly.

It also adds a canary test that must fail if the upstream interface changes (e.g., if constants are renamed).

The patching behavior can be disabled via passing the STREAM_PATCH_AIORTC_BITRATES=0|off|false|no env var.

aiortc-getstream patches the default bitrate values for vpx and h264 codecs to support higher video quality.
But it's outdated and not maintained.

This PR introduces the original `aiortc` lib back and patches these bitrate values on-the-fly.
It also adds a canary test that must fail if the upstream interface changes (e.g. the constants were renamed, etc.)

The patching behavior can be disabled via passing the `STREAM_PATCH_AIORTC_BITRATES=0|off|false|no` env var.
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 13, 2026

📝 Walkthrough

Walkthrough

Adds new public RTC exports (audio track, connection manager, codecs, models, location discovery, track utilities), introduces an import-time aiortc video-bitrate patch controlled by PATCH_AIORTC_BITRATES, and relaxes aiortc/av version constraints in the webrtc dependency group.

Changes

Cohort / File(s) Summary
RTC Module Exports & Init
getstream/video/rtc/__init__.py
Added public exports (AudioStreamTrack, ConnectionManager, join_call_coordinator_request, G711Encoding/G711Mapping, HTTPHintLocationDiscovery and constants, JoinCallRequest/Response/ServerCredentials, PcmData/Resampler/AudioFormat, Credentials). Added _patch_aiortc_video_bitrates() and import-time invocation guarded by PATCH_AIORTC_BITRATES. Reordered imports and __all__.
Dependency Updates
pyproject.toml
Loosened webrtc pins: aiortc changed from ==1.13.0.post1 to >=1.14.0, <2; av changed from >=14.0.0,<14.3 to >=14.2.0,<17.
Bitrate Patching Tests
tests/rtc/test_bitrate_patch.py
New test suite validating patch applied/disabled behavior, upstream-assumption canary, idempotence, and helpers to reset/reload codec defaults during tests.

Sequence Diagram(s)

sequenceDiagram
  participant Importer
  participant RTC_Module
  participant Env as Environment
  participant Aiortc as aiortc_library

  Importer->>RTC_Module: import getstream.video.rtc
  RTC_Module->>Env: read PATCH_AIORTC_BITRATES
  Env-->>RTC_Module: value (enabled/disabled)
  alt enabled
    RTC_Module->>Aiortc: _patch_aiortc_video_bitrates()
    Aiortc-->>RTC_Module: adjust codec DEFAULT/MIN/MAX
  else disabled
    RTC_Module-->>Aiortc: no patch applied
  end
  RTC_Module-->>Importer: expose public exports (tracks, models, codecs, utils)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 I nudged bitrates with a careful paw,

Exposed new tracks and creds to all I saw.
Tests hop in, they check and play,
A patched aiortc greets the day,
The rabbit hums — code patched with awe.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Remove the usage of the forked aiortc-getstream lib' directly and clearly describes the main objective of the PR, which is to eliminate the dependency on the forked aiortc-getstream library and replace it with upstream aiortc.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/remove-aiortc-getstream
📝 Coding Plan
  • Generate coding plan for human review comments

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.

Tip

CodeRabbit can use TruffleHog to scan for secrets in your code with verification capabilities.

Add a TruffleHog config file (e.g. trufflehog-config.yml, trufflehog.yml) to your project to customize detectors and scanning behavior. The tool runs only when a config file is present.

Copy link
Copy Markdown

@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: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@getstream/video/rtc/__init__.py`:
- Around line 69-73: Normalize the STREAM_PATCH_AIORTC_BITRATES environment
value before comparing so values like " False ", "OFF", or mixed case are
recognized as opt-outs; update the handling of the PATCH_AIORTC_BITRATES
variable (the constant assigned from os.getenv) to strip whitespace and
lowercase (or casefold) and then check membership against
("0","false","no","off"); only call _patch_aiortc_video_bitrates() when the
normalized value is not in that set.
- Around line 45-67: The imports for aiortc submodules (_h264_codec and
_vpx_codec) are executed outside the exception handler so an import error would
bypass the try/except; move the two imports (aiortc.codecs.h264 and
aiortc.codecs.vpx) inside the try block at the start of
_patch_aiortc_video_bitrates(), then keep the existing bitrate assignments and
the except block unchanged so failures to import or assign are caught and logged
by logger.warning/logger.debug.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: de285763-bea8-4b7b-875c-07a08a6fa798

📥 Commits

Reviewing files that changed from the base of the PR and between efc3da8 and f58c767.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (3)
  • getstream/video/rtc/__init__.py
  • pyproject.toml
  • tests/rtc/test_bitrate_patch.py

Copy link
Copy Markdown

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@getstream/video/rtc/__init__.py`:
- Around line 45-67: The _patch_aiortc_video_bitrates function currently mutates
_vpx_codec and _h264_codec constants one-by-one and can leave partial changes if
a later assignment fails; change it to be all-or-nothing by first importing
aiortc.codecs.h264 and aiortc.codecs.vpx and preparing the desired bitrate
values in local variables, then perform the attribute assignments for
_vpx_codec.DEFAULT_BITRATE, _vpx_codec.MIN_BITRATE, _vpx_codec.MAX_BITRATE and
_h264_codec.DEFAULT_BITRATE, _h264_codec.MIN_BITRATE in a single atomic step (or
apply them and on exception revert to original values using saved backups) so
that either all codec constants are updated or none are changed, and keep the
existing logging in the except block.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7b259502-0c5c-4f58-8d76-2602ce271448

📥 Commits

Reviewing files that changed from the base of the PR and between f58c767 and 5d7f53d.

📒 Files selected for processing (1)
  • getstream/video/rtc/__init__.py

@dangusev dangusev marked this pull request as draft March 13, 2026 17:27
New approach - patch only specific methods inside the RTCRtpSender class.
This way, the changes are applied only to Stream-specific code, and the global constants inside aiortc are not affected.
@dangusev dangusev marked this pull request as ready for review March 16, 2026 13:51
@dangusev dangusev merged commit 64754d9 into main Mar 17, 2026
13 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