Skip to content

Add Opus payloader #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 22, 2023
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