Skip to content

Commit d4de029

Browse files
wendemat-hek
authored andcommitted
webrtc included
1 parent 08c0bb3 commit d4de029

File tree

2 files changed

+54
-81
lines changed

2 files changed

+54
-81
lines changed

test/boombox_test.exs

Lines changed: 53 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -25,100 +25,79 @@ defmodule BoomboxTest do
2525
file_file_mp4_audio: {[@bbb_mp4_a, "output.mp4"], "ref_bun10s_aac.mp4", kinds: [:audio]},
2626
file_file_mp4_video: {[@bbb_mp4_v, "output.mp4"], "ref_bun10s_aac.mp4", kinds: [:video]},
2727
http_file_mp4: {[@bbb_mp4_url, "output.mp4"], "ref_bun10s_aac.mp4", []},
28-
file_file_file_mp4: {[@bbb_mp4, "mid_output.mp4", "output.mp4"], "ref_bun10s_aac.mp4", []}
28+
file_file_file_mp4: {[@bbb_mp4, "mid_output.mp4", "output.mp4"], "ref_bun10s_aac.mp4", []},
29+
file_webrtc:
30+
{[@bbb_mp4, {:async, {:webrtc, quote(do: Membrane.WebRTC.Signaling.new())}}, "output.mp4"],
31+
"ref_bun10s_opus_aac.mp4", []},
32+
file_whip:
33+
{[@bbb_mp4, {:async, {:whip, quote(do: get_free_local_address())}}, "output.mp4"],
34+
"ref_bun10s_opus_aac.mp4", []},
35+
http_webrtc:
36+
{[
37+
@bbb_mp4_url,
38+
{:async, {:webrtc, quote(do: Membrane.WebRTC.Signaling.new())}},
39+
"output.mp4"
40+
], "ref_bun10s_opus_aac.mp4", []},
41+
webrtc_audio:
42+
{[
43+
@bbb_mp4_a,
44+
{:async, {:webrtc, quote(do: Membrane.WebRTC.Signaling.new())}},
45+
"output.mp4"
46+
], "ref_bun10s_opus_aac.mp4", [kinds: [:audio]]},
47+
webrtc_video:
48+
{[
49+
@bbb_mp4_v,
50+
{:async, {:webrtc, quote(do: Membrane.WebRTC.Signaling.new())}},
51+
"output.mp4"
52+
], "ref_bun10s_opus_aac.mp4", [kinds: [:video]]},
53+
webrtc_webrtc:
54+
{[
55+
@bbb_mp4,
56+
{:async, {:webrtc, quote(do: Membrane.WebRTC.Signaling.new())}},
57+
{:async, {:webrtc, quote(do: Membrane.WebRTC.Signaling.new())}},
58+
"output.mp4"
59+
], "ref_bun10s_opus_aac.mp4", []}
2960
]
3061
|> Enum.each(fn {tag, {[input | io], fixture, opts}} ->
3162
@tag tag
3263
async_test "#{tag}", %{tmp_dir: tmp} do
64+
Keyword.get(unquote(opts), :setup, fn -> :ok end).()
65+
3366
reduce_test(unquote(io), unquote(input), unquote(fixture), [{:tmp_dir, tmp} | unquote(opts)])
3467
end
3568
end)
3669

70+
defp reduce_test([{:async, output} | next], input, fixture, opts) do
71+
t = Boombox.async(input: input, output: output)
72+
73+
reduce_test(
74+
next,
75+
output,
76+
fixture,
77+
Keyword.put(opts, :async, [t | Keyword.get(opts, :async, [])])
78+
)
79+
end
80+
3781
defp reduce_test([output | next], input, fixture, opts) do
3882
output_path = Path.join(opts[:tmp_dir], output)
3983
Boombox.run(input: input, output: output_path)
4084
reduce_test(next, output_path, fixture, opts)
4185
end
4286

4387
defp reduce_test([], input, fixture, opts) do
88+
Task.await_many(Keyword.get(opts, :async, []))
4489
Compare.compare(input, "test/fixtures/#{fixture}", opts)
4590
end
4691

47-
@tag :file_webrtc
48-
async_test "mp4 file -> webrtc -> mp4 file", %{tmp_dir: tmp} do
49-
output = Path.join(tmp, "output.mp4")
50-
signaling = Membrane.WebRTC.Signaling.new()
51-
t = Boombox.async(input: @bbb_mp4, output: {:webrtc, signaling})
52-
Boombox.run(input: {:webrtc, signaling}, output: output)
53-
Task.await(t)
54-
Compare.compare(output, "test/fixtures/ref_bun10s_opus_aac.mp4")
55-
end
56-
57-
@tag :file_whip
58-
async_test "mp4 file -> webrtc/whip -> mp4 file", %{tmp_dir: tmp} do
59-
output = Path.join(tmp, "output.mp4")
60-
61-
port = get_free_port()
62-
63-
t = Boombox.async(input: @bbb_mp4, output: {:whip, "http://127.0.0.1:#{port}"})
64-
65-
Boombox.run(input: {:whip, "http://127.0.0.1:#{port}"}, output: output)
66-
Task.await(t)
67-
Compare.compare(output, "test/fixtures/ref_bun10s_opus_aac.mp4")
68-
end
69-
70-
@tag :http_webrtc
71-
async_test "http mp4 -> webrtc -> mp4 file", %{tmp_dir: tmp} do
72-
output = Path.join(tmp, "output.mp4")
73-
signaling = Membrane.WebRTC.Signaling.new()
74-
t = Boombox.async(input: @bbb_mp4_url, output: {:webrtc, signaling})
75-
Boombox.run(input: {:webrtc, signaling}, output: output)
76-
Task.await(t)
77-
Compare.compare(output, "test/fixtures/ref_bun10s_opus_aac.mp4")
78-
end
79-
80-
@tag :webrtc_audio
81-
async_test "mp4 -> webrtc -> mp4 audio", %{tmp_dir: tmp} do
82-
output = Path.join(tmp, "output.mp4")
83-
signaling = Membrane.WebRTC.Signaling.new()
84-
85-
t =
86-
Boombox.async(input: @bbb_mp4_a, output: {:webrtc, signaling})
87-
88-
Boombox.run(input: {:webrtc, signaling}, output: "#{tmp}/output.mp4")
89-
Task.await(t)
90-
Compare.compare(output, "test/fixtures/ref_bun10s_opus_aac.mp4", kinds: [:audio])
91-
end
92-
93-
@tag :webrtc_video
94-
async_test "mp4 -> webrtc -> mp4 video", %{tmp_dir: tmp} do
95-
output = Path.join(tmp, "output.mp4")
96-
signaling = Membrane.WebRTC.Signaling.new()
97-
98-
t =
99-
Boombox.async(input: @bbb_mp4_v, output: {:webrtc, signaling})
100-
101-
Boombox.run(input: {:webrtc, signaling}, output: output)
102-
Task.await(t)
103-
Compare.compare(output, "test/fixtures/ref_bun10s_opus_aac.mp4", kinds: [:video])
92+
defp get_free_local_address() do
93+
"http://127.0.0.1:#{get_free_port()}"
10494
end
10595

106-
@tag :webrtc2
107-
async_test "mp4 -> webrtc -> webrtc -> mp4", %{tmp_dir: tmp} do
108-
output = Path.join(tmp, "output.mp4")
109-
signaling1 = Membrane.WebRTC.Signaling.new()
110-
signaling2 = Membrane.WebRTC.Signaling.new()
111-
112-
t1 =
113-
Boombox.async(input: @bbb_mp4, output: {:webrtc, signaling1})
114-
115-
t2 =
116-
Boombox.async(input: {:webrtc, signaling1}, output: {:webrtc, signaling2})
117-
118-
Boombox.run(input: {:webrtc, signaling2}, output: output)
119-
Task.await(t1)
120-
Task.await(t2)
121-
Compare.compare(output, "test/fixtures/ref_bun10s_opus2_aac.mp4")
96+
defp get_free_port() do
97+
{:ok, s} = :gen_tcp.listen(0, active: false)
98+
{:ok, port} = :inet.port(s)
99+
:ok = :gen_tcp.close(s)
100+
port
122101
end
123102

124103
@tag :rtmp
@@ -413,11 +392,4 @@ defmodule BoomboxTest do
413392

414393
p
415394
end
416-
417-
defp get_free_port() do
418-
{:ok, s} = :gen_tcp.listen(0, active: false)
419-
{:ok, port} = :inet.port(s)
420-
:ok = :gen_tcp.close(s)
421-
port
422-
end
423395
end

test/test_helper.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ max_cases =
33
do: 1,
44
else: System.schedulers_online() * 2
55

6+
Logger.configure(level: :warning)
67
ExUnit.start(capture_log: true, max_cases: max_cases)

0 commit comments

Comments
 (0)