Skip to content

Commit 4095ede

Browse files
authored
Fix issue with rejecting non-matching FMTP (#67)
1 parent 57d04fc commit 4095ede

File tree

14 files changed

+114
-178
lines changed

14 files changed

+114
-178
lines changed

examples/echo/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ While in `examples/echo` directory
66

77
1. Run `mix deps.get`
88
2. Run `mix run --no-halt`
9-
3. Visit `http://127.0.0.1:8829` in your browser and press the `play` button.
9+
3. Visit `http://127.0.0.1:8829/index.html` in your browser and press the `play` button.

examples/echo/lib/echo/peer_handler.ex

+2-6
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ defmodule Echo.PeerHandler do
1919
%RTPCodecParameters{
2020
payload_type: 96,
2121
mime_type: "video/VP8",
22-
clock_rate: 90_000,
23-
channels: nil,
24-
sdp_fmtp_line: nil,
25-
rtcp_fbs: []
22+
clock_rate: 90_000
2623
}
2724
]
2825

@@ -31,8 +28,7 @@ defmodule Echo.PeerHandler do
3128
payload_type: 111,
3229
mime_type: "audio/opus",
3330
clock_rate: 48_000,
34-
channels: 2,
35-
sdp_fmtp_line: %ExSDP.Attribute.FMTP{pt: 111, minptime: 10, useinbandfec: true}
31+
channels: 2
3632
}
3733
]
3834

examples/echo/lib/echo/router.ex

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
11
defmodule Echo.Router do
22
use Plug.Router
33

4-
@assets "assets"
5-
4+
plug(Plug.Static, at: "/", from: "assets")
65
plug(:match)
76
plug(:dispatch)
87

9-
get "/" do
10-
send_file(conn, 200, "#{@assets}/index.html")
11-
end
12-
13-
get "/script.js" do
14-
send_file(conn, 200, "#{@assets}/script.js")
15-
end
16-
178
get "/ws" do
189
WebSockAdapter.upgrade(conn, Echo.PeerHandler, %{}, [])
1910
end

examples/echo/mix.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"elixir_make": {:hex, :elixir_make, "0.7.8", "505026f266552ee5aabca0b9f9c229cbb496c689537c9f922f3eb5431157efc7", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:certifi, "~> 2.0", [hex: :certifi, repo: "hexpm", optional: true]}], "hexpm", "7a71945b913d37ea89b06966e1342c85cfe549b15e6d6d081e8081c493062c07"},
99
"elixir_uuid": {:hex, :elixir_uuid, "1.2.1", "dce506597acb7e6b0daeaff52ff6a9043f5919a4c3315abb4143f0b00378c097", [:mix], [], "hexpm", "f7eba2ea6c3555cea09706492716b0d87397b88946e6380898c2889d68585752"},
1010
"ex_dtls": {:hex, :ex_dtls, "0.15.0", "71a11b0379f4ebeb781548ead0e72194e650cfb6d6c435015c8b36e9e5574f62", [:mix], [{:unifex, "~> 1.0", [hex: :unifex, repo: "hexpm", optional: false]}], "hexpm", "3ff1d9ef6c4b0cc800105979c1c58dc67cada91c593beeae56e05094fdbce865"},
11-
"ex_ice": {:hex, :ex_ice, "0.5.0", "8e380afb611b4d48a74d4a8016a0284ed11c77400230e2840e2476856cf6d572", [:mix], [{:ex_stun, "~> 0.1.0", [hex: :ex_stun, repo: "hexpm", optional: false]}], "hexpm", "d5a9d5d4b54650385a9b5365b38d919d5158ab2fec5c13669ae45db494516bb6"},
11+
"ex_ice": {:hex, :ex_ice, "0.6.0", "7deb747f3813501a34b1103a8243981beed07767512d2b7007ee2c61e43b5f83", [:mix], [{:ex_stun, "~> 0.1.0", [hex: :ex_stun, repo: "hexpm", optional: false]}], "hexpm", "743917f921c26f12c13a096e93299b7a61bda0a6a44fe202e6fc5d0e2d5154af"},
1212
"ex_libsrtp": {:hex, :ex_libsrtp, "0.7.2", "211bd89c08026943ce71f3e2c0231795b99cee748808ed3ae7b97cd8d2450b6b", [:mix], [{:bunch, "~> 1.6", [hex: :bunch, repo: "hexpm", optional: false]}, {:bundlex, "~> 1.3", [hex: :bundlex, repo: "hexpm", optional: false]}, {:membrane_precompiled_dependency_provider, "~> 0.1.0", [hex: :membrane_precompiled_dependency_provider, repo: "hexpm", optional: false]}, {:unifex, "~> 1.1", [hex: :unifex, repo: "hexpm", optional: false]}], "hexpm", "2e20645d0d739a4ecdcf8d4810a0c198120c8a2f617f2b75b2e2e704d59f492a"},
1313
"ex_rtcp": {:hex, :ex_rtcp, "0.1.0", "2e02d23fc6ccc7e00aed13358ffdbcb23e34d3a7f35c66cadaa54447383ecae4", [:mix], [], "hexpm", "1c9a7e636f3950fbcefedce31f3e4ca60b84ea80ad519789f9d215167c60cb2b"},
1414
"ex_rtp": {:hex, :ex_rtp, "0.3.0", "d18d0de39875958902816284f79c8cd51ec83d39bdd14edf6a5b069926268a43", [:mix], [], "hexpm", "cec8398237095b02438842cfc74487c3cbaeb7fe29e4c62ae11457a0ddd99754"},

examples/save_to_file/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ While in `examples/save_to_file` directory
66

77
1. Run `mix deps.get`
88
2. Run `mix run --no-halt`
9-
3. Visit `http://127.0.0.1:8829` in your browser.
9+
3. Visit `http://127.0.0.1:8829/index.html` in your browser.
1010
4. Press the `Start` button to start recording.
1111
5. Press the `Stop` button to stop recording.
1212

examples/save_to_file/lib/save_to_file/peer_handler.ex

+2-6
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ defmodule SaveToFile.PeerHandler do
2525
%RTPCodecParameters{
2626
payload_type: 96,
2727
mime_type: "video/VP8",
28-
clock_rate: 90_000,
29-
channels: nil,
30-
sdp_fmtp_line: nil,
31-
rtcp_fbs: []
28+
clock_rate: 90_000
3229
}
3330
]
3431

@@ -37,8 +34,7 @@ defmodule SaveToFile.PeerHandler do
3734
payload_type: 111,
3835
mime_type: "audio/opus",
3936
clock_rate: 48_000,
40-
channels: 2,
41-
sdp_fmtp_line: %ExSDP.Attribute.FMTP{pt: 111, minptime: 10, useinbandfec: true}
37+
channels: 2
4238
}
4339
]
4440

examples/save_to_file/lib/save_to_file/router.ex

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
11
defmodule SaveToFile.Router do
22
use Plug.Router
33

4-
@assets "assets"
5-
4+
plug(Plug.Static, at: "/", from: "assets")
65
plug(:match)
76
plug(:dispatch)
87

9-
get "/" do
10-
send_file(conn, 200, "#{@assets}/index.html")
11-
end
12-
13-
get "/script.js" do
14-
send_file(conn, 200, "#{@assets}/script.js")
15-
end
16-
178
get "/ws" do
189
WebSockAdapter.upgrade(conn, SaveToFile.PeerHandler, %{}, [])
1910
end

examples/save_to_file/mix.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"elixir_make": {:hex, :elixir_make, "0.7.8", "505026f266552ee5aabca0b9f9c229cbb496c689537c9f922f3eb5431157efc7", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:certifi, "~> 2.0", [hex: :certifi, repo: "hexpm", optional: true]}], "hexpm", "7a71945b913d37ea89b06966e1342c85cfe549b15e6d6d081e8081c493062c07"},
99
"elixir_uuid": {:hex, :elixir_uuid, "1.2.1", "dce506597acb7e6b0daeaff52ff6a9043f5919a4c3315abb4143f0b00378c097", [:mix], [], "hexpm", "f7eba2ea6c3555cea09706492716b0d87397b88946e6380898c2889d68585752"},
1010
"ex_dtls": {:hex, :ex_dtls, "0.15.0", "71a11b0379f4ebeb781548ead0e72194e650cfb6d6c435015c8b36e9e5574f62", [:mix], [{:unifex, "~> 1.0", [hex: :unifex, repo: "hexpm", optional: false]}], "hexpm", "3ff1d9ef6c4b0cc800105979c1c58dc67cada91c593beeae56e05094fdbce865"},
11-
"ex_ice": {:hex, :ex_ice, "0.5.0", "8e380afb611b4d48a74d4a8016a0284ed11c77400230e2840e2476856cf6d572", [:mix], [{:ex_stun, "~> 0.1.0", [hex: :ex_stun, repo: "hexpm", optional: false]}], "hexpm", "d5a9d5d4b54650385a9b5365b38d919d5158ab2fec5c13669ae45db494516bb6"},
11+
"ex_ice": {:hex, :ex_ice, "0.6.0", "7deb747f3813501a34b1103a8243981beed07767512d2b7007ee2c61e43b5f83", [:mix], [{:ex_stun, "~> 0.1.0", [hex: :ex_stun, repo: "hexpm", optional: false]}], "hexpm", "743917f921c26f12c13a096e93299b7a61bda0a6a44fe202e6fc5d0e2d5154af"},
1212
"ex_libsrtp": {:hex, :ex_libsrtp, "0.7.2", "211bd89c08026943ce71f3e2c0231795b99cee748808ed3ae7b97cd8d2450b6b", [:mix], [{:bunch, "~> 1.6", [hex: :bunch, repo: "hexpm", optional: false]}, {:bundlex, "~> 1.3", [hex: :bundlex, repo: "hexpm", optional: false]}, {:membrane_precompiled_dependency_provider, "~> 0.1.0", [hex: :membrane_precompiled_dependency_provider, repo: "hexpm", optional: false]}, {:unifex, "~> 1.1", [hex: :unifex, repo: "hexpm", optional: false]}], "hexpm", "2e20645d0d739a4ecdcf8d4810a0c198120c8a2f617f2b75b2e2e704d59f492a"},
1313
"ex_rtcp": {:hex, :ex_rtcp, "0.1.0", "2e02d23fc6ccc7e00aed13358ffdbcb23e34d3a7f35c66cadaa54447383ecae4", [:mix], [], "hexpm", "1c9a7e636f3950fbcefedce31f3e4ca60b84ea80ad519789f9d215167c60cb2b"},
1414
"ex_rtp": {:hex, :ex_rtp, "0.3.0", "d18d0de39875958902816284f79c8cd51ec83d39bdd14edf6a5b069926268a43", [:mix], [], "hexpm", "cec8398237095b02438842cfc74487c3cbaeb7fe29e4c62ae11457a0ddd99754"},

examples/send_from_file/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ You may use your own files, if they meet the requirements:
1717

1818
2. Run `mix deps.get`
1919
3. Run `mix run --no-halt`
20-
4. Visit `http://127.0.0.1:8829` in your browser and press the `play` button.
20+
4. Visit `http://127.0.0.1:8829/index.html` in your browser and press the `play` button.
2121

2222
The video and audio will loop infinitely.

examples/send_from_file/lib/send_from_file/peer_handler.ex

+2-6
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ defmodule SendFromFile.PeerHandler do
2929
%RTPCodecParameters{
3030
payload_type: 96,
3131
mime_type: "video/VP8",
32-
clock_rate: 90_000,
33-
channels: nil,
34-
sdp_fmtp_line: nil,
35-
rtcp_fbs: []
32+
clock_rate: 90_000
3633
}
3734
]
3835

@@ -41,8 +38,7 @@ defmodule SendFromFile.PeerHandler do
4138
payload_type: 111,
4239
mime_type: "audio/opus",
4340
clock_rate: 48_000,
44-
channels: 2,
45-
sdp_fmtp_line: %ExSDP.Attribute.FMTP{pt: 111, minptime: 10, useinbandfec: true}
41+
channels: 2
4642
}
4743
]
4844

examples/send_from_file/lib/send_from_file/router.ex

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
11
defmodule SendFromFile.Router do
22
use Plug.Router
33

4-
@assets "assets"
5-
4+
plug(Plug.Static, at: "/", from: "assets")
65
plug(:match)
76
plug(:dispatch)
87

9-
get "/" do
10-
send_file(conn, 200, "#{@assets}/index.html")
11-
end
12-
13-
get "/script.js" do
14-
send_file(conn, 200, "#{@assets}/script.js")
15-
end
16-
178
get "/ws" do
189
WebSockAdapter.upgrade(conn, SendFromFile.PeerHandler, %{}, [])
1910
end

examples/send_from_file/mix.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"elixir_make": {:hex, :elixir_make, "0.7.8", "505026f266552ee5aabca0b9f9c229cbb496c689537c9f922f3eb5431157efc7", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:certifi, "~> 2.0", [hex: :certifi, repo: "hexpm", optional: true]}], "hexpm", "7a71945b913d37ea89b06966e1342c85cfe549b15e6d6d081e8081c493062c07"},
99
"elixir_uuid": {:hex, :elixir_uuid, "1.2.1", "dce506597acb7e6b0daeaff52ff6a9043f5919a4c3315abb4143f0b00378c097", [:mix], [], "hexpm", "f7eba2ea6c3555cea09706492716b0d87397b88946e6380898c2889d68585752"},
1010
"ex_dtls": {:hex, :ex_dtls, "0.15.0", "71a11b0379f4ebeb781548ead0e72194e650cfb6d6c435015c8b36e9e5574f62", [:mix], [{:unifex, "~> 1.0", [hex: :unifex, repo: "hexpm", optional: false]}], "hexpm", "3ff1d9ef6c4b0cc800105979c1c58dc67cada91c593beeae56e05094fdbce865"},
11-
"ex_ice": {:hex, :ex_ice, "0.5.0", "8e380afb611b4d48a74d4a8016a0284ed11c77400230e2840e2476856cf6d572", [:mix], [{:ex_stun, "~> 0.1.0", [hex: :ex_stun, repo: "hexpm", optional: false]}], "hexpm", "d5a9d5d4b54650385a9b5365b38d919d5158ab2fec5c13669ae45db494516bb6"},
11+
"ex_ice": {:hex, :ex_ice, "0.6.0", "7deb747f3813501a34b1103a8243981beed07767512d2b7007ee2c61e43b5f83", [:mix], [{:ex_stun, "~> 0.1.0", [hex: :ex_stun, repo: "hexpm", optional: false]}], "hexpm", "743917f921c26f12c13a096e93299b7a61bda0a6a44fe202e6fc5d0e2d5154af"},
1212
"ex_libsrtp": {:hex, :ex_libsrtp, "0.7.2", "211bd89c08026943ce71f3e2c0231795b99cee748808ed3ae7b97cd8d2450b6b", [:mix], [{:bunch, "~> 1.6", [hex: :bunch, repo: "hexpm", optional: false]}, {:bundlex, "~> 1.3", [hex: :bundlex, repo: "hexpm", optional: false]}, {:membrane_precompiled_dependency_provider, "~> 0.1.0", [hex: :membrane_precompiled_dependency_provider, repo: "hexpm", optional: false]}, {:unifex, "~> 1.1", [hex: :unifex, repo: "hexpm", optional: false]}], "hexpm", "2e20645d0d739a4ecdcf8d4810a0c198120c8a2f617f2b75b2e2e704d59f492a"},
1313
"ex_rtcp": {:hex, :ex_rtcp, "0.1.0", "2e02d23fc6ccc7e00aed13358ffdbcb23e34d3a7f35c66cadaa54447383ecae4", [:mix], [], "hexpm", "1c9a7e636f3950fbcefedce31f3e4ca60b84ea80ad519789f9d215167c60cb2b"},
1414
"ex_rtp": {:hex, :ex_rtp, "0.3.0", "d18d0de39875958902816284f79c8cd51ec83d39bdd14edf6a5b069926268a43", [:mix], [], "hexpm", "cec8398237095b02438842cfc74487c3cbaeb7fe29e4c62ae11457a0ddd99754"},

lib/ex_webrtc/peer_connection/configuration.ex

+36-69
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,9 @@ defmodule ExWebRTC.PeerConnection.Configuration do
162162
# This function doesn't check if rtcp-fb is supported.
163163
# Instead, `supported_rtcp_fb?` has to be used to filter out
164164
# rtcp-fb that are not supported.
165+
# TODO: this function doesn't compare fmtp at all
165166
Enum.any?(config.audio_codecs ++ config.video_codecs, fn supported_codec ->
166-
%{supported_codec | rtcp_fbs: codec.rtcp_fbs} == codec
167+
%{supported_codec | rtcp_fbs: codec.rtcp_fbs, sdp_fmtp_line: codec.sdp_fmtp_line} == codec
167168
end)
168169
end
169170

@@ -228,90 +229,56 @@ defmodule ExWebRTC.PeerConnection.Configuration do
228229
{audio_codecs, video_codecs}
229230
end
230231

231-
defp update_codecs(
232-
[%{mime_type: "audio/" <> _} = codec | sdp_codecs],
233-
audio_codecs,
234-
video_codecs
235-
) do
236-
audio_codec =
237-
audio_codecs
238-
|> Stream.with_index()
239-
|> Enum.find(fn {audio_codec, _idx} ->
240-
# For the time of comparision, assume the same payload type and rtcp_fbs.
232+
defp update_codecs([sdp_codec | sdp_codecs], audio_codecs, video_codecs) do
233+
type =
234+
case sdp_codec.mime_type do
235+
"audio/" <> _ -> :audio
236+
"video/" <> _ -> :video
237+
end
238+
239+
codecs = if type == :audio, do: audio_codecs, else: video_codecs
240+
241+
codec =
242+
codecs
243+
|> Enum.with_index()
244+
|> Enum.find(fn {codec, _idx} ->
245+
# For the time of comparision, assume the same payload type and rtcp_fbs and fmtp.
241246
# We don't want to take into account rtcp_fbs as they can be negotiated
242247
# i.e. we can reject those that are not supported by us.
243-
fmtp =
244-
if audio_codec.sdp_fmtp_line != nil and codec.sdp_fmtp_line != nil do
245-
%FMTP{audio_codec.sdp_fmtp_line | pt: codec.payload_type}
246-
else
247-
audio_codec.sdp_fmtp_line
248-
end
249-
250-
audio_codec = %RTPCodecParameters{
251-
audio_codec
252-
| payload_type: codec.payload_type,
253-
sdp_fmtp_line: fmtp,
254-
rtcp_fbs: codec.rtcp_fbs
248+
codec = %RTPCodecParameters{
249+
codec
250+
| payload_type: sdp_codec.payload_type,
251+
sdp_fmtp_line: sdp_codec.sdp_fmtp_line,
252+
rtcp_fbs: sdp_codec.rtcp_fbs
255253
}
256254

257-
audio_codec == codec
255+
codec == sdp_codec
258256
end)
259257

260-
case audio_codec do
258+
case codec do
261259
nil ->
262260
update_codecs(sdp_codecs, audio_codecs, video_codecs)
263261

264-
{audio_codec, idx} ->
265-
audio_codec = %RTPCodecParameters{
266-
audio_codec
267-
| payload_type: codec.payload_type,
268-
sdp_fmtp_line: codec.sdp_fmtp_line
269-
}
270-
271-
audio_codecs = List.insert_at(audio_codecs, idx, audio_codec)
272-
update_codecs(sdp_codecs, audio_codecs, video_codecs)
273-
end
274-
end
275-
276-
defp update_codecs(
277-
[%{mime_type: "video/" <> _} = codec | sdp_codecs],
278-
audio_codecs,
279-
video_codecs
280-
) do
281-
video_codec =
282-
video_codecs
283-
|> Stream.with_index()
284-
|> Enum.find(fn {video_codec, _idx} ->
262+
{codec, idx} ->
285263
fmtp =
286-
if video_codec.sdp_fmtp_line != nil and codec.sdp_fmtp_line != nil do
287-
%FMTP{video_codec.sdp_fmtp_line | pt: codec.payload_type}
264+
if codec.sdp_fmtp_line != nil do
265+
%{codec.sdp_fmtp_line | pt: sdp_codec.payload_type}
288266
else
289-
video_codec.sdp_fmtp_line
267+
nil
290268
end
291269

292-
video_codec = %RTPCodecParameters{
293-
video_codec
294-
| payload_type: codec.payload_type,
295-
sdp_fmtp_line: fmtp,
296-
rtcp_fbs: codec.rtcp_fbs
270+
codec = %RTPCodecParameters{
271+
codec
272+
| payload_type: sdp_codec.payload_type,
273+
sdp_fmtp_line: fmtp
297274
}
298275

299-
video_codec == codec
300-
end)
301-
302-
case video_codec do
303-
nil ->
304-
update_codecs(sdp_codecs, audio_codecs, video_codecs)
305-
306-
{video_codec, idx} ->
307-
video_codec = %RTPCodecParameters{
308-
video_codec
309-
| payload_type: codec.payload_type,
310-
sdp_fmtp_line: codec.sdp_fmtp_line
311-
}
276+
codecs = List.insert_at(codecs, idx, codec)
312277

313-
video_codecs = List.insert_at(video_codecs, idx, video_codec)
314-
update_codecs(sdp_codecs, audio_codecs, video_codecs)
278+
case type do
279+
:audio -> update_codecs(sdp_codecs, codecs, video_codecs)
280+
:video -> update_codecs(sdp_codecs, audio_codecs, codecs)
281+
end
315282
end
316283
end
317284

0 commit comments

Comments
 (0)