go2rtc icon indicating copy to clipboard operation
go2rtc copied to clipboard

HomeKit server: Home app talk fails when the camera backchannel is PCMU only (no Opus conversion)

Open StaunchLemur29 opened this issue 1 month ago • 1 comments

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: a pcm_mulaw sender 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=audio to it needs an explicit #backchannel=1.

StaunchLemur29 avatar Oct 10 '26 01:10 StaunchLemur29

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:

  1. Inspect the destination backchannel codecs and retain direct forwarding when compatible.
  2. If necessary, decode the negotiated HomeKit audio, resample it, and encode PCMU/PCMA in the format accepted by the camera.
  3. 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.
  4. A session-scoped, managed FFmpeg worker could be an initial implementation, depending on project preferences.
  5. Preserve correct packet pacing and RTP timestamps after conversion, keep buffering bounded, and define behavior for microphone pauses and competing talk sessions.
  6. 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.

Totte23 avatar Oct 26 '26 20:10 Totte23