View Source ExWebRTC.RTP.Munger (ex_webrtc v0.6.2)

RTP Munger allows for converting RTP packet timestamps and sequence numbers to a common domain.

This is useful when e.g. changing between Simulcast layers - the sender sends three separate RTP streams (also called layers or encodings), but the receiver can receive only a single RTP stream.

# assume you receive two layers: "h" (high) and "l" (low)
# and this is a GenServer

def init() do
  {:ok, %{munger: Munger.new(90_000), layer: "h"}}
end

def handle_info({:ex_webrtc, _from, {:rtp, _id, rid, packet}}, state) do
  if rid == state.layer do
    {packet, munger} = Munger.munge(state.munger, packet)
    send_packet_somewhere(packet)
    {:noreply, %{state | munger: munger}}
  else
    {:noreply, state}
  end
end

def handle_info({:change_layer, layer}, state) do
  # indicate to the munger that the next packet will be from a new layer
  munger = Munger.update(state.munger)
  {:noreply, %{munger: munger, layer: layer}
end

Summary

Functions

Updates the RTP packet to match the common timestamp/sequence number domain.

Informs the munger that the next packet passed to munge/2 will come from a different RTP stream.

Types

Functions

@spec munge(t(), ExRTP.Packet.t()) :: {ExRTP.Packet.t(), t()}

Updates the RTP packet to match the common timestamp/sequence number domain.

@spec new(non_neg_integer()) :: t()

Creates a new ExWebRTC.RTP.Munger.t/0.

clock_rate is the clock rate of the codec carried in munged RTP packets.

@spec update(t()) :: t()

Informs the munger that the next packet passed to munge/2 will come from a different RTP stream.