Tune WebRTC bitrate ramp#2333
Conversation
85cfb13 to
3127ed2
Compare
3127ed2 to
1d73fa0
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 6e009ef. Configure here.
|
|
||
| WEBRTC_START_BITRATE_BPS = 6_000_000 | ||
| WEBRTC_MIN_BITRATE_BPS = 2_000_000 | ||
| WEBRTC_MAX_BITRATE_BPS = 16_000_000 |
There was a problem hiding this comment.
Max bitrate constant contradicts documented 20 Mbps intent
Medium Severity
WEBRTC_MAX_BITRATE_BPS is set to 16_000_000 (16 Mbps), but the PR description and the author's review comment both explicitly state the shared max is 20 Mbps. This constant feeds into the codec MAX_BITRATE override for both H.264 and VP8, and into the REMB clamp, so the effective cap on bitrate is 4 Mbps lower than intended — potentially limiting video quality for users with strong connections.
Reviewed by Cursor Bugbot for commit 6e009ef. Configure here.


Summary
6 Mbpsstart/default,2 Mbpsmin, and16 Mbpsmax.StreamConfig(video_codec=...)to the Python SDK, defaulting toh264withautoandvp8escape hatches.Why
This is stacked on top of #2329. NVENC makes H.264 encoding fast on Modal GPUs; this PR lets aiortc actually request and advertise higher bitrates instead of starting/capping too conservatively.
The shared max is intentionally high enough for users with strong connections to get clean 1080p quality, but capped at 16 Mbps to reduce overshoot risk versus the earlier 20 Mbps ceiling. The shared min/start stay lower than the max to avoid forcing very weak connections into an aggressive fixed bitrate.
The SDK change keeps Python clients aligned with the browser default by preferring H.264 before offer creation while preserving fallback codecs in negotiation.
Testing
venv/bin/python -m black --check inference/core/interfaces/webrtc_worker/aiortc_bitrate.py inference/core/interfaces/webrtc_worker/webrtc.py inference/core/interfaces/stream_manager/manager_app/webrtc.pyvenv/bin/python -m isort --check-only inference/core/interfaces/webrtc_worker/aiortc_bitrate.py inference/core/interfaces/webrtc_worker/webrtc.py inference/core/interfaces/stream_manager/manager_app/webrtc.pyvenv/bin/python -m py_compile inference/core/interfaces/webrtc_worker/aiortc_bitrate.py inference/core/interfaces/webrtc_worker/webrtc.py inference/core/interfaces/stream_manager/manager_app/webrtc.pyvenv/bin/python -m black --check inference_sdk/webrtc/config.py inference_sdk/webrtc/codec_preferences.py inference_sdk/webrtc/session.py tests/inference_sdk/unit_tests/webrtc/test_codec_preferences.pyvenv/bin/python -m isort --check-only inference_sdk/webrtc/config.py inference_sdk/webrtc/codec_preferences.py inference_sdk/webrtc/session.py tests/inference_sdk/unit_tests/webrtc/test_codec_preferences.pyvenv/bin/python -m pytest tests/inference_sdk/unit_tests/webrtc/test_codec_preferences.pyvenv/bin/python -m black --check inference/core/interfaces/webrtc_worker/aiortc_bitrate.pyvenv/bin/python -m isort --check-only inference/core/interfaces/webrtc_worker/aiortc_bitrate.pyvenv/bin/python -m py_compile inference/core/interfaces/webrtc_worker/aiortc_bitrate.pygit diff --checkNotes
make check_code_qualitycould not run directly because this machine's systempython3lacks Black, so I ran the same formatter/import checks through the repo venv.Staging
Deployed to Modal staging with GPU image
roboflow/roboflow-inference-server-gpu:1.2.7-bh-bitrate-ramp-3using the fast deploy path without warmup/spawn calls.Note
Medium Risk
Touches WebRTC media negotiation and monkey-patches
aiortccodec/rate-control internals, which could impact connection stability or bandwidth usage across different clients/networks.Overview
Adds a new
aiortc_bitratemodule that raises default/min/max codec bitrates (start 6 Mbps, min 2 Mbps, max 16 Mbps) and patches aiortc’s REMB estimator to seed and clamp receiver bitrate feedback within the same range.Applies this tuning at import time in both WebRTC entrypoints (
stream_manager/manager_app/webrtc.pyandwebrtc_worker/webrtc.py) and updates the SDP answer flow to callprefer_h264_for_peer_connection()aftersetRemoteDescription, prioritizing H.264 when offered while keeping other codecs as fallback.Reviewed by Cursor Bugbot for commit 1d73fa0. Bugbot is set up for automated code reviews on this repo. Configure here.