Prefer the go2rtc restream for HomeKit camera streams - #175605
Conversation
|
Hey there @home-assistant/core, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
|
Hey there @bdraco, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
There was a problem hiding this comment.
Pull request overview
This PR updates HomeKit camera streaming to prefer consuming streams via the Home Assistant–managed go2rtc RTSP restream, reducing per-session upstream connections to the camera.
Changes:
- Prefer go2rtc’s managed RTSP restream URL in HomeKit camera streaming when available, with fallback to the camera’s raw stream source.
- Expose a go2rtc helper (
async_get_rtsp_stream_url) and a shared managed RTSP port constant to keep server config and consumers in sync. - Add/extend tests covering the new helper behavior and HomeKit’s selection logic, and ensure HomeKit loads after go2rtc.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
homeassistant/components/homekit/type_cameras.py |
Prefer go2rtc RTSP restream URL before falling back to the raw camera stream source. |
homeassistant/components/homekit/manifest.json |
Ensure HomeKit is set up after go2rtc so the restream preference can be used when available. |
homeassistant/components/go2rtc/__init__.py |
Add a public helper to return the managed RTSP restream URL and make the stream registration method public. |
homeassistant/components/go2rtc/const.py |
Introduce HA_MANAGED_RTSP_PORT constant for the managed RTSP endpoint. |
homeassistant/components/go2rtc/server.py |
Use the managed RTSP port constant in the generated go2rtc server config. |
tests/components/go2rtc/test_init.py |
Add test coverage for the new RTSP restream helper and its fallback/None cases. |
tests/components/homekit/test_type_cameras.py |
Add tests verifying HomeKit prefers go2rtc restream and that configured stream sources bypass go2rtc. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
PR Review — Prefer the go2rtc restream for HomeKit camera streamsSolid, well-scoped change that routes HomeKit camera streams through the shared go2rtc restream. Merge-ready with minor nits. Strengths:
🟢 Suggestions
1. Host `127.0.0.1` literal duplicated across modules
|
Breaking change
Proposed change
Depends on #175600 — until that merges, this draft's diff includes both changes; only the HomeKit commit is new here.
Make HomeKit consume camera streams through the go2rtc restream instead of opening a connection to the camera per streaming session:
_async_get_stream_sourceprefersgo2rtc.async_get_rtsp_stream_url; when it returnsNone(go2rtc absent, user-provided server, unsupported source) the previous raw-source path is used unchanged.stream_sourceoption keeps absolute priority, so users pointing HomeKit at a substream or external restream are unaffected.go2rtcis added to HomeKit'safter_dependencies.Today each HomeKit live session spawns an ffmpeg pulling directly from the camera (up to
stream_count, default 3, per camera) — on top of go2rtc's own upstream for dashboard WebRTC. With this change all HomeKit sessions, dashboard WebRTC views and go2rtc snapshots share go2rtc's single upstream connection per camera; ffmpeg keeps its per-session role (SRTP toward the Apple device, Opus audio, scaling) with a local, already-primed input.Validated live against a UniFi Protect camera: real HomeKit sessions each consumed
rtsp://127.0.0.1:18554/<identifier>, parallel consumers resulted in exactly one upstream connection to the camera, and go2rtc released it after the last consumer ended. (Dev-machine validation of the managed-server path; only the docker environment detection was bypassed, everything behind it is unmodified production code.)Type of change
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: