Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion examples/send_from_file/example.exs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ defmodule Peer do
PeerConnection,
RTPCodecParameters,
RTP.VP8Payloader,
RTP.OpusPayloader,
RTPTransceiver,
SessionDescription
}
Expand Down Expand Up @@ -159,7 +160,8 @@ defmodule Peer do
# that's why you might hear short pauses in audio playback, when using this example
Process.send_after(self(), :send_audio_packet, duration)
# values set to 0 are handled by PeerConnection.set_rtp
rtp_packet = ExRTP.Packet.new(packet, 0, 0, state.last_audio_timestamp, 0)
rtp_packet = OpusPayloader.payload(packet)
rtp_packet = %{rtp_packet | timestamp: state.last_audio_timestamp}
PeerConnection.send_rtp(state.peer_connection, state.audio_track_id, rtp_packet)

# OggReader.next_packet/1 returns duration in ms
Expand Down
15 changes: 15 additions & 0 deletions lib/ex_webrtc/rtp/opus_payloader.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
defmodule ExWebRTC.RTP.OpusPayloader do
@moduledoc """
Encapsulates Opus audio packet into an RTP packet.
"""

@doc """
Packs Opus packet into an RTP packet.

Fields from RTP header like ssrc, timestamp etc. are set to 0.
"""
@spec payload(binary()) :: ExRTP.Packet.t()
def payload(packet) when packet != <<>> do
ExRTP.Packet.new(packet, 0, 0, 0, 0)
end
end