XMediaLib

XMediaLib is a media and signaling toolkit for VoIP and WebRTC on Erlang/Elixir. It provides wire-format helpers and optional native codecs for RTP/RTCP, SRTP, STUN/TURN, SDP, SIP, and ZRTP. Parts of the API descend from Peter Lemenkov's RTPLib.

Published home: https://github.com/Lazarus404/xmedialib

What problem this solves

Building a phone or conference app means more than HTTP. Peers must agree on codecs and network paths (SDP, ICE), authenticate and encrypt media (DTLS-SRTP in WebRTC, or ZRTP as an in-band alternative), and move packets through NAT (STUN/TURN). XMediaLib packages those building blocks as Elixir modules plus optional NIF- or port-backed drivers where performance matters.

Main modules

RFCs

Codecs and media:

Signaling and connectivity:

ZRTP and related:

Prerequisites

To run all tests and use all codec features, install the native libraries the port drivers link against:

Example on Ubuntu:

# install libilbc
wget https://github.com/TimothyGu/libilbc/releases/download/v2.0.2/libilbc-2.0.2.tar.gz
tar -xzvf libilbc-2.0.2.tar.gz
cd libilbc-2.0.2
./configure
make && sudo make install
# install bcg729
git clone git@github.com:BelledonneCommunications/bcg729.git
cd bcg729/
cmake . -DENABLE_STATIC=YES
make && sudo make install
# install remaining libs
sudo add-apt-repository ppa:jonathonf/ffmpeg-3
sudo apt-get update
sudo apt-get install libsamplerate-dev libspandsp-dev libopus-dev libopus0 opus-tools libspeex-dev

Without these libraries, codec drivers that need them will not load; other modules (RTP, SDP, STUN, and so on) still work.

SIP (optional NIF)

XMediaLib.SIP.parse/1 and encode/1 always work: they use the PJSIP NIF when priv/sip_nif.so is built, otherwise the pure-Elixir fallback (XMediaLib.SIP.Elixir).

Building the NIF requires PJSIP (libpjproject). If PJSIP is not installed, make prints skip sip_nif: PJSIP not found and continues. NIF-specific tests skip automatically; Elixir-path tests always run.

Install PJSIP (example on macOS with Homebrew):

brew install pjproject

Then from xmedialib/:

make
mix test test/sip/

SDP

XMediaLib.SDP.parse/1 and encode/1 parse and serialize Session Description Protocol for WebRTC-oriented offers and answers. Media attributes such as ICE candidates, fingerprints, rtpmap/fmtp, and SCTP data-channel fields are promoted onto %XMediaLib.SDP.Media{}.

mix test test/sdp/

Codec (Opus FEC / PLC)

XMediaLib.Codec loads Erlang port drivers under priv/. Opus supports:

Non-Opus codecs return {:error, :unsupported} for FEC/PLC setters and decoders (no silent no-op). Parse SDP fmtp with XMediaLib.Codec.OpusFmtp.parse/1, then call set_inband_fec/2 after start_link/1 when useinbandfec is true.

mix test test/codecs/codec_opus_test.exs

Installation

Add xmedialib to your mix.exs dependencies:

def deps do
[{:xmedialib, "~> 0.3.0"}]
end

Contact

For questions or suggestions, email experts@xirsys.com

Copyright (c) 2013 - 2026 Jahred Love & Xirsys LLC

All rights reserved.

XMediaLib is licensed by Xirsys, with permission, under the Apache License Version 2.0. See LICENSE for the full license text.