Skip to content

opus: register Opus as a SIP/SDP codec#72

Closed
inechay wants to merge 1 commit into
livekit:mainfrom
inechay:opus-sip-codec
Closed

opus: register Opus as a SIP/SDP codec#72
inechay wants to merge 1 commit into
livekit:mainfrom
inechay:opus-sip-codec

Conversation

@inechay

@inechay inechay commented Jul 10, 2026

Copy link
Copy Markdown

What

Register Opus as a SIP/SDP codec so it can be offered and negotiated on the RTP (telephone) leg.

Why

Opus is implemented in this repo (opus/opus.go) but only wired into the internal WebRTC leg — it is never registered as a SIP/SDP codec (no init() / RegisterCodec), unlike g711 / g722 / amrwb. As a result livekit/sip can only offer G711/G722 on the telephone leg, capping wideband calls at G.722 16 kHz even when the softphone offers Opus.

This is the media-sdk side of livekit/sip#281.

Change

opus/opus.go — register Opus the same way g722.go / amrwb.go do:

  • CodecInfo{SDPName: "opus/48000/2", SampleRate: 48000, RTPClockRate: 48000, RTPIsStatic: false, Priority: 100}
  • mono encode/decode adapters over the existing Encode / Decode
  • encoder tuned for telephony: inband FEC + a packet-loss estimate (so lossy mobile paths degrade gracefully), max complexity, a generous bitrate — kept separate from the shared Encode so the WebRTC leg (its own bandwidth estimation) is untouched
  • codec-init failures fail the individual call (via a small failWriter) instead of panic-ing the whole process

The RTP media path (rtp.EncodePCM / rtp.DecodePCM) is already generic over CodecInfo + AudioCodec, so this registration is sufficient end to end — no per-codec wiring. Happy to make the encoder settings configurable / less opinionated if preferred.

Companion change

livekit/sip needs a one-line change to enable opus in its default codec set (pkg/sip/media_codecs.go); I'll open that PR once this lands.

Testing

Built into a custom livekit-sip image and verified on a live inbound call from a softphone (Zoiper with Opus above G722): SDP answer a=rtpmap:106 opus/48000/2, log using codecs … audio-codec=opus/48000/2, clean 48 kHz media (expected_pcm_hz=48000, packets_failed=0, write_errors=0, no decode errors), DTMF/telephone-event intact, and audibly better than G.722.

Refs: livekit/sip#281

Opus is implemented here but only wired into the WebRTC leg; it is never
registered as a SIP/SDP codec, so livekit/sip can only offer G711/G722 on the
telephone leg (livekit/sip#281). Register it like g722/amrwb: SDPName
opus/48000/2, 48 kHz, dynamic payload type, mono encode/decode adapters over the
existing Opus impl. The encoder is tuned for telephony (inband FEC + a
packet-loss estimate for lossy mobile paths, plus max complexity and a generous
bitrate); codec init failures fail the call rather than panicking the process.

The RTP media path is already generic over CodecInfo + AudioCodec, so this
registration is sufficient end to end. Enabling it in livekit/sip's default
codec set is a companion one-line change there.

Refs: livekit/sip#281
@inechay inechay requested review from a team as code owners July 10, 2026 18:23
@CLAassistant

CLAassistant commented Jul 10, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@inechay

inechay commented Jul 10, 2026

Copy link
Copy Markdown
Author

Closing in favor of #69, which takes the same approach (register Opus in the media-sdk opus package via init()) and predates this — I hadn't seen it when I opened this one. Thanks @thetillhoff for already carrying this (and the companion livekit/sip#738).

I've left notes on #69 with live-test results and an optional telephony encoder tuning that could go on top once it lands.

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.

2 participants