XMediaLib.SDP.Encoder (xmedialib v0.3.0)

Copy Markdown View Source

Encodes %XMediaLib.SDP{} to wire-format SDP.

What problem this solves

After negotiating or modifying a session in memory, you must serialize %XMediaLib.SDP{} back to wire text for SIP bodies or WebRTC signaling. Each line prefix (v=, o=, m=, a=) and CRLF rule comes from RFC 8866. This module performs that serialization; callers usually invoke XMediaLib.SDP.encode/1.

Serializes session-level lines first (v=, o=, s=, c=, t=, groups, session attributes), then each %XMediaLib.SDP.Media{} block in list order. Output uses CRLF line endings as commonly seen on the wire and in browser offer/answer text.

Prefer XMediaLib.SDP.encode/1 at application boundaries; use this module when encoding from tests or internal pipelines that already hold a parsed struct.

RFCs

Summary

Functions

Serializes a session description to SDP bytes.

Functions

encode(sdp)

@spec encode(XMediaLib.SDP.t()) :: {:ok, binary()} | {:error, term()}

Serializes a session description to SDP bytes.

Returns {:ok, binary()} on success or {:error, :encoding_failed} if an unexpected value prevents serialization.

Examples

iex> sdp = %XMediaLib.SDP{version: 0, session_name: "-", time: [%XMediaLib.SDP.Time{}]}
iex> {:ok, bin} = XMediaLib.SDP.Encoder.encode(sdp)
iex> String.starts_with?(bin, "v=0")
true