Skip to content

Tune WebRTC bitrate ramp#2333

Open
balthazur wants to merge 3 commits into
codex/h264-nvenc-webrtcfrom
codex/webrtc-bitrate-ramp-tuning
Open

Tune WebRTC bitrate ramp#2333
balthazur wants to merge 3 commits into
codex/h264-nvenc-webrtcfrom
codex/webrtc-bitrate-ramp-tuning

Conversation

@balthazur
Copy link
Copy Markdown
Contributor

@balthazur balthazur commented May 12, 2026

Summary

  • Add a small aiortc WebRTC bitrate tuning module for server/browser streaming.
  • Use one shared aiortc WebRTC bitrate policy for H.264, VP8, and REMB: 6 Mbps start/default, 2 Mbps min, and 16 Mbps max.
  • Seed and clamp aiortc receiver REMB feedback with the same shared policy so browser upload can ramp faster.
  • Prefer H.264 in the aiortc answer when available, keeping the browser's other codecs as fallback.
  • Add StreamConfig(video_codec=...) to the Python SDK, defaulting to h264 with auto and vp8 escape 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.py
  • venv/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.py
  • venv/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.py
  • venv/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.py
  • venv/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.py
  • venv/bin/python -m pytest tests/inference_sdk/unit_tests/webrtc/test_codec_preferences.py
  • venv/bin/python -m black --check inference/core/interfaces/webrtc_worker/aiortc_bitrate.py
  • venv/bin/python -m isort --check-only inference/core/interfaces/webrtc_worker/aiortc_bitrate.py
  • venv/bin/python -m py_compile inference/core/interfaces/webrtc_worker/aiortc_bitrate.py
  • git diff --check

Notes

  • This does not add env flags or frontend changes.
  • H.264 and VP8 intentionally use the same bitrate constants so browser/backend behavior is consistent across codec choice.
  • Local make check_code_quality could not run directly because this machine's system python3 lacks 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-3 using the fast deploy path without warmup/spawn calls.


Note

Medium Risk
Touches WebRTC media negotiation and monkey-patches aiortc codec/rate-control internals, which could impact connection stability or bandwidth usage across different clients/networks.

Overview
Adds a new aiortc_bitrate module 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.py and webrtc_worker/webrtc.py) and updates the SDP answer flow to call prefer_h264_for_peer_connection() after setRemoteDescription, 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.

@balthazur balthazur force-pushed the codex/webrtc-bitrate-ramp-tuning branch from 3127ed2 to 1d73fa0 Compare May 13, 2026 07:27
Comment thread inference/core/interfaces/webrtc_worker/aiortc_bitrate.py
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 6e009ef. Configure here.

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.

1 participant