Skip to content

Commit

Permalink
Fix some typos. Don't set sender_ssrc in record_packet. Refactor test.
Browse files Browse the repository at this point in the history
  • Loading branch information
mickel8 committed Jan 31, 2025
1 parent f5a0198 commit b36e75d
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
6 changes: 5 additions & 1 deletion lib/ex_webrtc/peer_connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ defmodule ExWebRTC.PeerConnection do
should be used for sending.
Once the first RTP packet is sent (via `send_rtp/4`), `set_sender_codec/3`
can only be called with a codec with the clock rate.
can only be called with a codec with the same clock rate.
Although very unlikely, keep in mind that after renegotiation,
the selected codec may no longer be supported by the remote side and you might
Expand All @@ -177,6 +177,10 @@ defmodule ExWebRTC.PeerConnection do
{:ok, pc} = PeerConnection.start_link()
{:ok, rtp_sender} = PeerConnection.add_track(MediaStreamTrack.new(:video))
# exchange SDP with the remote side
# {:ok, offer} = PeerConnection.create_offer(pc)
# ...
tr =
pc
|> PeerConnection.get_transceivers()
Expand Down
4 changes: 2 additions & 2 deletions lib/ex_webrtc/rtp_sender.ex
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ defmodule ExWebRTC.RTPSender do
defp rtx?(codec), do: String.ends_with?(codec.mime_type, "rtx")
defp supported?(sender, codec), do: codec in sender.codecs

# As long as report recorder is not initialized i.e. we have not send any RTP packet
# allow for codec changes. Once we start sending RTP packet, require the same clock rate.
# As long as report recorder is not initialized i.e. we have not sent any RTP packet,
# allow for codec changes. Once we start sending RTP packets, require the same clock rate.
defp same_clock_rate?(%{report_recorder: %{clock_rate: nil}}, _codec), do: true
defp same_clock_rate?(sender, codec), do: sender.report_recorder.clock_rate == codec.clock_rate

Expand Down
3 changes: 1 addition & 2 deletions lib/ex_webrtc/rtp_sender/report_recorder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ defmodule ExWebRTC.RTPSender.ReportRecorder do
def record_packet(%{last_seq_no: nil} = recorder, packet, time) do
%__MODULE__{
recorder
| sender_ssrc: packet.ssrc,
last_rtp_timestamp: packet.timestamp,
| last_rtp_timestamp: packet.timestamp,
last_seq_no: packet.sequence_number,
last_timestamp: time,
packet_count: 1,
Expand Down
2 changes: 1 addition & 1 deletion test/ex_webrtc/rtp_sender/report_recorder_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ defmodule ExWebRTC.RTPSender.ReportRecorderTest do
@rtp_ts 234_444
@clock_rate 90_000
@packet ExRTP.Packet.new(<<>>, sequence_number: @seq_no, timestamp: @rtp_ts)
@recorder %ReportRecorder{sender_ssrc: 123_467, clock_rate: @clock_rate}
@recorder ReportRecorder.init(%ReportRecorder{}, 123_467, @clock_rate)

@ntp_offset 2_208_988_800
@max_u32 0xFFFFFFFF
Expand Down
2 changes: 1 addition & 1 deletion test/ex_webrtc/rtp_sender_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ defmodule ExWebRTC.RTPSenderTest do
%{sender: sender}
end

test "new/6" do
test "new/7" do
track = MediaStreamTrack.new(:video)

codecs = [@vp8, @av1, @av1_45khz, @rtx]
Expand Down

0 comments on commit b36e75d

Please sign in to comment.