HomeKit server: Home app talk fails when the camera backchannel is PCMU only (no Opus conversion)
Summary
With the HomeKit server in the dev build, two-way audio from the Apple Home app never reaches a camera whose backchannel only accepts PCMU. The same stream's backchannel works from a browser over WebRTC. It looks like the HomeKit consumer only offers Opus for the talk direction, so there is no common codec with the camera and no sender is created.
Request: convert the Home app's talk audio to the camera's backchannel codec (PCMU/PCMA), or provide an option to do so.
Environment
- go2rtc
1.9.14+dev.6361dcb(Home Assistant add-on "go2rtc (dev)") - Camera: 2N IP Solo intercom, ONVIF profile with audio backchannel
- Client: Apple Home app on iPhone, Apple TV 4K as home hub
Config
streams:
front_gate:
- "rtsp://user:[email protected]/onvif/media?transport=unicast&profile=2FF07D44-8FF7-4983-99CB-31AF589BFB3A#media=audio#backchannel=1"
- "ffmpeg:rtsp://user:[email protected]:554/mjpeg_stream#video=h264#audio=opus"
- "ffmpeg:front_gate#audio=aac"
homekit:
front_gate:
name: Front Gate
hksv: true
motion: continuous
speaker: true
What works
- Live video and audio in the Home app.
- The HKSV consumer attaches with H264 + AAC.
- WebRTC two-way audio (
video+audio+microphone) on this exact stream: apcm_mulawsender attaches to the ONVIF producer and my voice is heard from the intercom's speaker.
What doesn't work
Pressing the microphone button in the Home app. No sender is created on the ONVIF producer, and the network view shows nothing coming back from the HomeKit consumer.
Why I think it happens
The camera only offers PCMU for the backchannel:
"medias": [
"audio, recvonly, PCMU/8000",
"audio, sendonly, PCMU/8000"
]
In pkg/homekit/consumer.go on the dev branch, the recvonly audio media for the backchannel declares only Opus, and incoming packets are written to the receiver without conversion. Opus and PCMU have no match, so the backchannel is never set up.
Suggested fix
Any of these would solve it:
- Transcode HomeKit backchannel audio to PCMU/PCMA when that is all the producer accepts.
- An option on the
homekit:entry to run talk audio through ffmpeg before it reaches the producer.
Many doorbells and intercoms only accept G.711 on their backchannel, so this would make speaker: true usable with most of them.
Related
- #1904 (2N two-way audio over RTSP). For that issue, in case it helps: on a 2N IP Solo the backchannel works when the ONVIF profile link is the first source, and adding
#media=audioto it needs an explicit#backchannel=1.
I would also like to request HomeKit talk-back support for cameras whose return channel accepts PCMU/PCMA rather than Opus.
The dev branch already has an Opus receive path in pkg/homekit/consumer.go. Could an optional codec-adaptation stage bridge that path to a G.711 camera backchannel?
Proposed design, for discussion:
- Inspect the destination backchannel codecs and retain direct forwarding when compatible.
- If necessary, decode the negotiated HomeKit audio, resample it, and encode PCMU/PCMA in the format accepted by the camera.
- Connect this conversion stage into stream routing even when the original codec sets do not intersect. Advertising additional codecs alone would not perform the conversion.
- A session-scoped, managed FFmpeg worker could be an initial implementation, depending on project preferences.
- Preserve correct packet pacing and RTP timestamps after conversion, keep buffering bounded, and define behavior for microphone pauses and competing talk sessions.
- Stop the converter and detach the return track on disconnect or timeout, while keeping camera-to-Home audio and recording independent.
Useful acceptance tests would include audible speech, repeated start/stop and reconnects, pause/resume, continued video and incoming audio, and cleanup without orphan workers or growing queues.
The aim is direct Apple Home two-way audio through go2rtc without needing a separate Homebridge return-audio adapter. This is a feature/design proposal, not a claim that this conversion has already been implemented or tested in the dev build.