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.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.
Core Switching Engine
The heart of FreeSWITCH is libfreeswitch, compiled fromsrc/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_tobjects 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.
Module Categories
FreeSWITCH ships with modules organised into well-defined categories. Each category corresponds to a subdirectory undersrc/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.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.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.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.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).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.
Database Layer
FreeSWITCH uses SQLite as its embedded internal database (initialized viasqlite3_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_dbandmod_hashfor rate limiting.
mod_sofia) to an external ODBC-compatible database.
XML Configuration
All configuration in FreeSWITCH is expressed in XML. On startup (and onreloadxml), the core runs an XML preprocessor that:
- Reads
freeswitch.xml(the root document). - Expands
<X-PRE-PROCESS cmd="include" data="..."/>directives to pull in additional files. - Expands
<X-PRE-PROCESS cmd="set" data="var=value"/>to create global variables available as$${var}. - Builds the XML registry — an in-memory tree consulted by all subsystems.
| Section | Enum | Purpose |
|---|---|---|
configuration | SWITCH_XML_SECTION_CONFIG | Module configuration (autoload_configs/*.xml) |
dialplan | SWITCH_XML_SECTION_DIALPLAN | Call routing contexts and extensions |
directory | SWITCH_XML_SECTION_DIRECTORY | User and device credentials |
chatplan | SWITCH_XML_SECTION_CHATPLAN | Instant message routing |
languages | SWITCH_XML_SECTION_LANGUAGES | Phrase macro definitions |
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.