Media, Codecs & Audio QualityKnowledge baseFreeSWITCH · 1.10.x

Opus Codec Adaptation and Dynamic Bandwidth Management in FreeSWITCH

by Provider Adminlast verified 2026-07-29

Overview

Learn how FreeSWITCH leverages the flexible Opus audio codec to dynamically adapt audio parameters in response to real-time network conditions. This guide explores the architecture of mod_opus, SDP parameter negotiation, Forward Error Correction (FEC), Discontinuous Transmission (DTX), and fine-tuning FreeSWITCH for optimal voice quality across unstable IP networks.

Illustration for Opus Codec Adaptation and Dynamic Bandwidth Management in FreeSWITCH

Key takeaways

  • Opus combines technology from SILK and CELT to scale seamlessly from low-bitrate narrowband speech (6 kbps) to fullband high-fidelity audio (510 kbps).
  • FreeSWITCH's mod_opus dynamically adjusts bitrates, packet loss resilience, and audio bandwidth based on incoming RTCP feedback reports.
  • SDP FMTP parameters such as useinbandfec, usedtx, and maxaveragebitrate define initial channel boundaries during SIP session setup.
  • Channel variables allow per-call or dynamic policy overrides to enforce bandwidth constraints or maximize error recovery in poor network environments.

Prerequisites

  • Basic understanding of SIP session establishment and SDP offer/answer exchange.
  • Fundamental knowledge of RTP/RTCP transport mechanisms and network metrics (jitter, packet loss, latency).
  • Administrative access to a FreeSWITCH 1.10+ deployment with mod_opus compiled and loaded.

Guide

  1. section #1

    Architecture of Opus in FreeSWITCH The Opus audio codec (RFC 6716) is a highly versatile standard built by combining Skype's speech-oriented SILK codec and Xiph.Org's music-oriented CELT codec. In FreeSWITCH, Opus support is provided via the mod_opus module, which interfaces directly with the core media engine (switch_core_codec). Unlike legacy codecs like G.711 or G.729 that operate at fixed bitrates and sampling frequencies, Opus can adjust its internal operation modes—narrowband, wideband, super-wideband, and fullband—on the fly without re-negotiating the media session. FreeSWITCH utilizes this elasticity to maintain call clarity despite changing transport conditions over WAN or cellular networks.

  2. section #2

    SDP FMTP Parameter Negotiation During the SIP offer/answer exchange, FreeSWITCH uses the Format Specific Parameters (fmtp) attribute within the SDP to define codec operational parameters. Parameters such as maxaveragebitrate, maxplaybackrate, useinbandfec, and usedtx inform the remote endpoint of local capabilities and constraints. FreeSWITCH parses incoming fmtp lines to program the underlying libopus encoder/decoder contexts. If a remote user agent requests maxaveragebitrate=24000, FreeSWITCH enforces an upper limit on its outbound audio stream to honor the remote party's bandwidth allowance.

    m=audio 16422 RTP/SAVPF 108 101
    a=rtpmap:108 opus/48000/2
    a=fmtp:108 maxaveragebitrate=32000;maxplaybackrate=16000;useinbandfec=1;usedtx=1
    a=rtpmap:101 telephone-event/8000
  3. section #3

    In-Band Forward Error Correction (FEC) and DTX Opus features built-in Forward Error Correction (FEC) designed to protect audio against bursty packet loss without requiring additional RTP streams or heavy retransmission overhead. When enabled via useinbandfec=1, the encoder embeds a reduced-redundancy copy of the previous frame into the current packet. If the decoder misses packet N-1 but receives packet N, it extracts the backup frame data to reconstruct the lost payload seamlessly. Discontinuous Transmission (DTX) complements this by stopping RTP transmission during periods of silence, replacing missing packets with localized comfort noise generation (CNG) to conserve network resources.

  4. section #4

    Dynamic Bitrate Adaptation via RTCP Feedback FreeSWITCH's mod_opus features real-time dynamic bandwidth management driven by RTCP Receiver Reports (RR). As the media stream runs, the FreeSWITCH RTP engine analyzes loss fraction, jitter, and round-trip time (RTT) reported by the far end. When elevated packet loss or network congestion is detected, mod_opus instructs the Opus encoder to lower its target bitrate and increase the proportion of FEC redundant data embedded into the payload. Conversely, when RTCP reports signal pristine network conditions, FreeSWITCH incrementally ramps up the bitrate toward the configured maximum, maximizing voice fidelity.

  5. section #5

    Configuring mod_opus in opus.conf.xml Global defaults and default encoder parameters for mod_opus are managed in the autoload_configs/opus.conf.xml configuration file. Engineers can control baseline parameters such as default-bitrate, maxaveragebitrate, use-inband-fec, and force-channels. Tuning these settings establishes strict operational boundaries for all endpoints connecting to the FreeSWITCH instance, preventing individual high-bitrate sessions from saturating system memory or WAN capacity.

    <configuration name="opus.conf" description="Opus Codec Configuration">
      <settings>
        <param name="default-bitrate" value="28000"/>
        <param name="maxaveragebitrate" value="32000"/>
        <param name="maxplaybackrate" value="48000"/>
        <param name="use-inband-fec" value="true"/>
        <param name="use-dtx" value="true"/>
        <param name="complexity" value="8"/>
        <param name="packet-loss-percent" value="10"/>
        <param name="asymmetric-sample-rates" value="1"/>
        <param name="keep-asymmetric-session" value="true"/>
      </settings>
    </configuration>
  6. section #6

    Dynamic Override via Channel Variables In multi-tenant or WebRTC environments, application logic often requires per-call bandwidth controls. FreeSWITCH exposes channel variables that override mod_opus defaults prior to channel bridge or media setup. Setting variables like opus_bitrate, opus_use_inband_fec, or opus_debug in the dialplan gives system administrators total control over media processing based on user tier, network location, or call direction.

    <extension name="opus_bandwidth_control">
      <condition field="destination_number" expression="^1000$">
        <!-- Force lower bitrate and enable FEC for mobile WAN clients -->
        <action application="set" data="opus_bitrate=18000"/>
        <action application="set" data="opus_use_inband_fec=1"/>
        <action application="set" data="opus_use_dtx=1"/>
        <action application="bridge" data="user/1000@${domain_name}"/>
      </condition>
    </extension>

Further reading

  • RFC 6716: Definition of the Opus Audio Codec
  • RFC 7587: RTP Payload Format for the Opus Speech and Audio Codec
  • FreeSWITCH Wiki: mod_opus Module Reference
  • Opus Codec Official Documentation and IETF Guidelines