Line-oriented SDP parser.
What problem this solves
Incoming SDP arrives as a multiline string from SIP INVITE bodies or trickle
ICE updates. Turning that into structs requires walking session and media lines
in order and promoting WebRTC attributes into typed fields. This module is the
line-oriented parser behind XMediaLib.SDP.parse/1.
Walks CRLF- or LF-separated lines, building %XMediaLib.SDP{} and nested
media structs. Session lines (v=, o=, s=, c=, t=, session a=)
update the root struct. Each m= starts a new %XMediaLib.SDP.Media{};
following lines until the next m= belong to that section.
Well-known WebRTC attributes are promoted to typed fields via
XMediaLib.SDP.Parser.Helpers. By default, unrecognized non-a= lines are
skipped; :strict mode surfaces them as errors instead.
Prefer XMediaLib.SDP.parse/1 at application boundaries; use this module
when you need parser-specific options or tests.
RFCs
Summary
Types
SDP parse result: {:ok, %SDP{}} or {:error, reason}.
Types
@type parse_result() :: {:ok, XMediaLib.SDP.t()} | {:error, term()}
SDP parse result: {:ok, %SDP{}} or {:error, reason}.
Functions
@spec parse(binary()) :: parse_result()
Parses an SDP binary into %XMediaLib.SDP{}.
Equivalent to parse/2 with default options (non-strict).
Examples
iex> {:ok, sdp} = XMediaLib.SDP.Parser.parse("v=0\r\no=- 0 0 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\n")
iex> sdp.version
0
@spec parse( binary(), keyword() ) :: parse_result()
Parses an SDP binary with options.
Options:
:strict- whentrue, unknown non-a=lines return{:error, {:unsupported_line, line}}instead of being skipped
Malformed numeric fields or invalid promoted attributes raise internally
and surface as {:error, :parse_failed}.
Examples
iex> raw = "v=0\r\no=- 0 0 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\nz=bad\r\n"
iex> {:error, {:unsupported_line, "z=bad"}} = XMediaLib.SDP.Parser.parse(raw, strict: true)