Remove the usage of the forked aiortc-getstream lib#221
Conversation
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.
📝 WalkthroughWalkthroughAdds 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
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)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
📝 Coding Plan
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. Comment 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. |
There was a problem hiding this comment.
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
⛔ Files ignored due to path filters (1)
uv.lockis excluded by!**/*.lock
📒 Files selected for processing (3)
getstream/video/rtc/__init__.pypyproject.tomltests/rtc/test_bitrate_patch.py
There was a problem hiding this comment.
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
📒 Files selected for processing (1)
getstream/video/rtc/__init__.py
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.
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
aiortclib back and a patches these bitrate values on-the-fly.This way, we can stay up-to-date with recent
aiortcandpyavquickly.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|noenv var.