Skip to content

Commit

Permalink
Check H264 FMTP params
Browse files Browse the repository at this point in the history
  • Loading branch information
mickel8 committed Dec 6, 2024
1 parent a7a7f29 commit 5d799e0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
2 changes: 1 addition & 1 deletion examples/whip_whep/lib/whip_whep/peer_supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ defmodule WhipWhep.PeerSupervisor do
receive do
{:ex_webrtc, ^pc, {:ice_gathering_state_change, :complete}} -> :ok
after
1000 -> {:error, :timeout}
1000 -> :ok
end
end

Expand Down
37 changes: 30 additions & 7 deletions lib/ex_webrtc/peer_connection/configuration.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,22 @@ defmodule ExWebRTC.PeerConnection.Configuration do
clock_rate: 90_000,
sdp_fmtp_line: %FMTP{
pt: 98,
level_asymmetry_allowed: 1,
level_asymmetry_allowed: true,
packetization_mode: 0,
profile_level_id: 0x42E01F
}
},
%RTPCodecParameters{
payload_type: 99,
mime_type: "video/H264",
clock_rate: 90_000,
sdp_fmtp_line: %FMTP{
pt: 99,
level_asymmetry_allowed: true,
packetization_mode: 1,
profile_level_id: 0x42E01F
}
},
%RTPCodecParameters{
payload_type: 45,
mime_type: "video/AV1",
Expand Down Expand Up @@ -454,11 +465,12 @@ defmodule ExWebRTC.PeerConnection.Configuration do
{codecs, {free_pts, mapping}} =
Enum.map_reduce(codecs, {free_pts, %{}}, fn codec, {free_pts, mapping} ->
sdp_codecs
|> Enum.find(
&(String.downcase(&1.mime_type) == String.downcase(codec.mime_type) and
&1.clock_rate == codec.clock_rate and
&1.channels == codec.channels)
)
|> Enum.find(fn sdp_codec ->
String.downcase(sdp_codec.mime_type) == String.downcase(codec.mime_type) and
sdp_codec.clock_rate == codec.clock_rate and
sdp_codec.channels == codec.channels and
compare_fmtp(sdp_codec.sdp_fmtp_line, codec.sdp_fmtp_line)
end)
|> case do
nil ->
[pt | rest] = free_pts
Expand Down Expand Up @@ -522,7 +534,8 @@ defmodule ExWebRTC.PeerConnection.Configuration do
&(String.downcase(&1.mime_type) == String.downcase(sdp_codec.mime_type) and
&1.payload_type == sdp_codec.payload_type and
&1.clock_rate == sdp_codec.clock_rate and
&1.channels == sdp_codec.channels)
&1.channels == sdp_codec.channels and
compare_fmtp(&1.sdp_fmtp_line, sdp_codec.sdp_fmtp_line))
)
|> case do
nil ->
Expand All @@ -535,6 +548,16 @@ defmodule ExWebRTC.PeerConnection.Configuration do
end)
end

# compare H264 FMTP as profile_level_id compatibility is crucial for proper decoding;
# in other cases, accept everything
defp compare_fmtp(sdp_fmtp, conf_fmtp) when sdp_fmtp != nil and conf_fmtp != nil do
sdp_fmtp.profile_level_id == conf_fmtp.profile_level_id and
sdp_fmtp.packetization_mode == conf_fmtp.packetization_mode and
sdp_fmtp.level_asymmetry_allowed == conf_fmtp.level_asymmetry_allowed
end

defp compare_fmtp(_sdp_fmtp, _codec_fmtp), do: true

@doc false
@spec intersect_extensions(t(), ExSDP.Media.t()) :: [Extmap.t()]
def intersect_extensions(config, mline) do
Expand Down

0 comments on commit 5d799e0

Please sign in to comment.