View Source ExRTP.Packet (ex_rtp v0.1.0)
RTP packet encoding and decoding functionalities.
Examples
iex> alias ExRTP.Packet
iex> alias ExRTP.Packet.Extension.AudioLevelExtension
iex> extension = AudioLevelExtension.new(true, 120) |> AudioLevelExtension.to_raw(5)
iex> payload = <<3, 5, 5, 0>>
iex> encoded =
...> payload
...> |> Packet.new(120, 50_000, 1_000_000, 500_000)
...> |> Packet.set_extension(:one_byte, [extension])
...> |> Packet.encode()
iex> {:ok, %Packet{payload: <<3, 5, 5, 0>>}} = Packet.decode(encoded)
Summary
Functions
Decodes binary into an RTP packet.
Encodes an RTP packet and returns resulting binary.
Fetch extension with specified id
.
Create new ExRTP.Packet.t/0
struct.
Specify extension profile and add header extensions to the packet.
Types
@type t() :: %ExRTP.Packet{ csrc: [uint32()], extension: boolean(), extension_profile: uint16() | nil, extensions: [ExRTP.Packet.Extension.t()], marker: boolean(), padding: boolean(), padding_size: uint8(), payload: binary(), payload_type: uint7(), sequence_number: uint16(), ssrc: uint32(), timestamp: uint32(), version: 0..3 }
Struct representing an RTP packet.
@type uint7() :: 0..127
@type uint8() :: 0..255
@type uint16() :: 0..65535
@type uint32() :: 0..4_294_967_295
Functions
Decodes binary into an RTP packet.
If packet is too short to ba valid, this function
will fail with :not_enough_data
error.
Encodes an RTP packet and returns resulting binary.
@spec fetch_extension(t(), non_neg_integer()) :: {:ok, ExRTP.Packet.Extension.t()} | :error
Fetch extension with specified id
.
If no extension with id
is found, :error
is returned.
new(payload, payload_type, sequence_number, timestamp, ssrc, opts \\ [])
View Source@spec new(binary(), uint7(), uint16(), uint32(), uint32(), csrc: [uint32()], marker: boolean(), padding: uint8() ) :: t()
Create new ExRTP.Packet.t/0
struct.
Options:
csrc
- CSRC list, by default[]
, must be shorter than 16, otherwise function will raisemarker
- if marker field is set, by defaultfalse
padding
- length of payload padding, by default no padding is added
@spec set_extension(t(), :one_byte | :two_byte | uint16(), [ ExRTP.Packet.Extension.t() ]) :: t()
Specify extension profile and add header extensions to the packet.
If extensions were set previously, this function will override them.
If profile is not one-byte or two-byte profile, extension
should contain only one element.
Function will raise if extension format is invalid.