Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/signalwire/freeswitch/llms.txt

Use this file to discover all available pages before exploring further.

FreeSWITCH is built around a small, stable core library — libfreeswitch — that handles session management, media processing, and event dispatch. All protocol support, codec handling, scripting languages, and telephony applications live in independently loadable modules. This separation lets you extend or replace virtually every layer of the system without touching the core, and it lets the system run on hardware ranging from embedded devices to large carrier-class servers.
┌──────────────────────────────────────────────────────────────────┐
│                         FreeSWITCH Core                          │
│                                                                  │
│  ┌─────────────┐  ┌──────────────┐  ┌─────────────────────────┐ │
│  │  XML Config  │  │ Session/Chan │  │     Event System        │ │
│  │  Preprocessor│  │  Manager     │  │  (APR FIFO + threads)   │ │
│  └──────┬──────┘  └──────┬───────┘  └──────────┬──────────────┘ │
│         │                │                      │                │
│  ┌──────▼──────┐  ┌──────▼───────┐  ┌──────────▼──────────────┐ │
│  │  SQLite DB   │  │  RTP Engine  │  │  Module Loader          │ │
│  │  (state, reg)│  │  Jitter Buf  │  │  (switch_loadable_module)│ │
│  └─────────────┘  └──────────────┘  └─────────────────────────┘ │
└─────────────────────────────┬────────────────────────────────────┘
                              │  dlopen / shared libs
        ┌──────────┬──────────┼──────────┬──────────┐
        ▼          ▼          ▼          ▼          ▼
   Endpoints   Codecs    Dialplans   Applications  Event
  (mod_sofia) (mod_opus)(mod_dialplan_xml)(mod_dptools)(mod_event_socket)

Core Switching Engine

The heart of FreeSWITCH is libfreeswitch, compiled from src/switch_core.c and its companion headers. It provides the runtime object (struct switch_runtime) that tracks global state, session counts, timers, and system-wide configuration. The library is built on top of APR (Apache Portable Runtime), which supplies portable abstractions for threads, mutexes, memory pools, and hash tables — the same foundation used by the Apache HTTP server. Key responsibilities of the core engine:
  • Memory management — every session allocates its own APR memory pool; the pool is destroyed when the call ends, reclaiming all resources at once.
  • Session lifecycle — the core creates, tracks, and destroys switch_core_session_t objects and enforces the channel state machine.
  • Thread management — each active session runs in its own thread; a configurable cap (max-sessions) prevents resource exhaustion.
  • RTP / media engine — the core contains a built-in RTP stack, jitter buffer, and DTMF detection that endpoints use to send and receive media.
  • Event FIFO — a thread-safe APR queue dispatches events to all registered listeners without blocking the originating thread.
/* From src/switch_core.c — global runtime structure */
struct switch_runtime runtime = { 0 };

/* Time duration breakdown used in heartbeat events */
struct switch_core_time_duration {
    uint32_t mms;   /* microseconds */
    uint32_t ms;    /* milliseconds */
    uint32_t sec;
    uint32_t min;
    uint32_t hr;
    uint32_t day;
    uint32_t yr;
};

Module Categories

FreeSWITCH ships with modules organised into well-defined categories. Each category corresponds to a subdirectory under src/mod/ and a distinct interface type registered by the module at load time.

applications

Dialplan applications executed on a channel: mod_dptools, mod_conference, mod_voicemail, mod_callcenter, etc.

endpoints

Signaling protocol drivers that create sessions: mod_sofia (SIP), mod_verto (WebRTC JSON-RPC), mod_skinny (SCCP), mod_loopback.

codecs

Audio and video codec plugins: mod_opus, mod_g729, mod_amr, mod_g723_1, mod_openh264, mod_silk.

dialplans

Routing engines that map an incoming call to a list of applications: mod_dialplan_xml (default), mod_dialplan_asterisk.

event_handlers

Modules that consume the event bus: mod_event_socket (ESL), mod_json_cdr, mod_cdr_csv, mod_amqp, mod_snmp.

formats

Audio/video file format readers and writers: mod_sndfile, mod_shout (MP3/Shoutcast), mod_av (FFmpeg).

languages

Embedded scripting runtimes: mod_lua, mod_python, mod_javascript, mod_perl, mod_v8.

loggers

Log sinks: mod_logfile (rolling file), mod_syslog, mod_console.

say

Language-aware text-to-speech phrase rendering: mod_say_en, mod_say_es, mod_say_de, etc.

timers

High-resolution timer backends: mod_timerfd (Linux), mod_posix_timer.

xml_int

XML source providers that populate the XML registry: mod_xml_curl, mod_xml_rpc, mod_xml_cdr, mod_xml_ldap.

asr_tts

Automatic speech recognition and text-to-speech engines: mod_unimrcp, mod_flite, mod_tts_commandline.

databases

External database backend connectors for limit and ODBC interfaces: mod_mariadb, mod_pgsql.

directories

User directory providers that resolve credentials and user profiles: mod_ldap.

Session Lifecycle

Every telephone call follows the same lifecycle inside FreeSWITCH, regardless of the signaling protocol.
1

Channel Creation

An endpoint module (e.g., mod_sofia) receives an inbound SIP INVITE or is asked to originate an outbound call. It calls into the core to allocate a new switch_core_session_t. The session starts in state CS_NEW, then immediately transitions to CS_INIT.
2

Routing

The session enters CS_ROUTING. The core asks the configured dialplan module (typically mod_dialplan_xml) to evaluate the caller’s profile against the active context. The dialplan returns an ordered list of applications to execute.
3

Execution

The session transitions to CS_EXECUTE. Each application in the extension list is called in sequence — playing prompts, bridging to another party, collecting DTMF, running IVR logic, etc.
4

Bridge / Exchange Media

When two sessions are bridged together, both channels enter CS_EXCHANGE_MEDIA. RTP packets flow directly between the two RTP engines (or through the core if transcoding is required).
5

Hangup and Reporting

When a party hangs up, the channel is flagged CS_HANGUP. After all applications clean up, the session enters CS_REPORTING (CDR writing) and finally CS_DESTROY, where its memory pool is released.

Media Handling

FreeSWITCH contains a full RTP engine in the core. It handles:
  • Packetisation and de-packetisation of audio and video frames.
  • Jitter buffering — adaptive jitter buffer to smooth out network timing variation.
  • DTMF detection — both in-band (audio energy) and out-of-band (RFC 2833 / SIP INFO).
  • SRTP / DTLS-SRTP — encrypted media for WebRTC and secure SIP trunks.
  • Media bugs — the switch_core_media_bug_add() API lets any module tap into the raw audio or video stream of a session without interrupting the call. Used by recording, speech recognition, and analytics modules.
/* Attach a media tap to a live session (from switch_core.h) */
SWITCH_DECLARE(switch_status_t) switch_core_media_bug_add(
    switch_core_session_t *session,
    const char *function,
    const char *target,
    switch_media_bug_callback_t callback,
    void *user_data,
    time_t stop_time,
    switch_media_bug_flag_t flags,
    switch_media_bug_t **new_bug
);

Database Layer

FreeSWITCH uses SQLite as its embedded internal database (initialized via sqlite3_initialize() during core startup). The database persists:
  • Active session state — fast lookups by UUID for API commands and ESL.
  • SIP registrations — endpoint registration records written by mod_sofia.
  • FIFO queue state — caller and agent positions maintained by mod_fifo.
  • Limit counters — call counts used by mod_db and mod_hash for rate limiting.
For production deployments requiring shared state across multiple FreeSWITCH nodes, the internal SQLite database can be replaced or supplemented by connecting modules (like mod_sofia) to an external ODBC-compatible database.

XML Configuration

All configuration in FreeSWITCH is expressed in XML. On startup (and on reloadxml), the core runs an XML preprocessor that:
  1. Reads freeswitch.xml (the root document).
  2. Expands <X-PRE-PROCESS cmd="include" data="..."/> directives to pull in additional files.
  3. Expands <X-PRE-PROCESS cmd="set" data="var=value"/> to create global variables available as $${var}.
  4. Builds the XML registry — an in-memory tree consulted by all subsystems.
The registry is divided into named sections, each with a defined purpose:
SectionEnumPurpose
configurationSWITCH_XML_SECTION_CONFIGModule configuration (autoload_configs/*.xml)
dialplanSWITCH_XML_SECTION_DIALPLANCall routing contexts and extensions
directorySWITCH_XML_SECTION_DIRECTORYUser and device credentials
chatplanSWITCH_XML_SECTION_CHATPLANInstant message routing
languagesSWITCH_XML_SECTION_LANGUAGESPhrase macro definitions
Modules can register as XML providers via mod_xml_curl or mod_xml_rpc, allowing the XML registry to be populated dynamically from a remote HTTP service rather than static files on disk.

Build docs developers (and LLMs) love