RFC 4566 SDP parser and generator. Port of NkSIP's nksip_sdp.
Lines must appear in the order mandated by the RFC. As in NkSIP, b=
lines found among the a= lines are accepted (FreeSWITCH sends them).
iex> {:ok, sdp} = Caracola.SDP.parse("v=0\r\no=- 1 2 IN IP4 h\r\ns=-\r\nt=0 0\r\nm=audio 4000 RTP/AVP 0\r\na=sendrecv\r\n")
iex> [media] = sdp.medias
iex> {media.media, media.port, media.fmt, media.attributes}
{"audio", 4000, ["0"], [{"sendrecv", []}]}
Summary
Types
A connection address: network type, address type and address.
An attribute: its name and values.
A media description to build a session with Caracola.SDP.new/2: media type, port and codecs or attributes.
The direction of a media stream.
A session description (RFC 8866).
A time description: start, stop and repeats.
Functions
Serializes an SDP, using CRLF line endings.
Returns the SDP in the body of a message, if its Content-Type is
application/sdp.
Increments the SDP version.
Builds a basic SDP for host with one m= section per media spec.
Returns true if sdp2 has a higher version than sdp1. Returns false
if any of them is nil.
Parses an SDP body. Both CRLF and LF line endings are accepted.
Serializes an SDP as iodata.
Sets the direction of all medias to status, replacing any previous one,
and increments the version.
Types
A connection address: network type, address type and address.
An attribute: its name and values.
@type media_spec() :: {media :: String.t(), port :: :inet.port_number(), [{:rtpmap, non_neg_integer(), String.t()} | String.t() | atom()]}
A media description to build a session with Caracola.SDP.new/2: media type, port and codecs or attributes.
@type media_status() :: :inactive | :recvonly | :sendonly | :sendrecv
The direction of a media stream.
@type t() :: %Caracola.SDP{ address: address(), attributes: [attribute()], bandwidth: [String.t()], connect: address() | nil, email: String.t() | nil, id: non_neg_integer(), info: String.t() | nil, key: String.t() | nil, medias: [Caracola.SDP.Media.t()], phone: String.t() | nil, sdp_vsn: String.t(), session: String.t(), time: [time()], uri: String.t() | nil, user: String.t(), vsn: non_neg_integer(), zone: String.t() | nil }
A session description (RFC 8866).
@type time() :: {start :: non_neg_integer(), stop :: non_neg_integer(), reps :: [String.t()]}
A time description: start, stop and repeats.
Functions
Serializes an SDP, using CRLF line endings.
@spec from_message(Caracola.Message.t()) :: t() | nil
Returns the SDP in the body of a message, if its Content-Type is
application/sdp.
Increments the SDP version.
@spec new(String.t(), [media_spec()]) :: t()
Builds a basic SDP for host with one m= section per media spec.
Each spec is {media, port, attributes}, where an attribute is either
{:rtpmap, payload, data} (which also adds the payload to the format list)
or a raw attribute like "ptime:20" or :sendrecv. The protocol is
RTP/AVP.
iex> sdp = Caracola.SDP.new("10.0.0.1", [{"audio", 4000, [{:rtpmap, 0, "PCMU/8000"}, :sendrecv]}])
iex> {sdp.connect, hd(sdp.medias).fmt, hd(sdp.medias).attributes}
{{"IN", "IP4", "10.0.0.1"}, ["0"], [{"rtpmap", ["0", "PCMU/8000"]}, {"sendrecv", []}]}
Returns true if sdp2 has a higher version than sdp1. Returns false
if any of them is nil.
Parses an SDP body. Both CRLF and LF line endings are accepted.
Serializes an SDP as iodata.
@spec update(t(), media_status()) :: t()
Sets the direction of all medias to status, replacing any previous one,
and increments the version.