Skip to content

Commit f08cb26

Browse files
committed
Write test for Live wip
1 parent 712ad7c commit f08cb26

File tree

4 files changed

+103
-3
lines changed

4 files changed

+103
-3
lines changed

mix.exs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,16 @@ defmodule Membrane.HTTPAdaptiveStream.MixProject do
6868
{:membrane_mp4_plugin, "~> 0.35.0"},
6969
{:membrane_aac_plugin, "~> 0.19.0"},
7070
{:membrane_h26x_plugin, "~> 0.10.0"},
71-
{:ex_hls,
72-
github: "membraneframework-labs/ex_hls", ref: "88847ba9a547366fd3f4868d49b72bd1e68ae412"},
71+
{
72+
:ex_hls,
73+
# github: "membraneframework-labs/ex_hls", ref: "88847ba9a547366fd3f4868d49b72bd1e68ae412"},
74+
path: "../ex_hls"
75+
},
7376
{:bunch, "~> 1.6"},
7477
{:qex, "~> 0.5"},
78+
{:muontrap, "~> 1.6", only: :test},
79+
# {:membrane_sdl_plugin, "~> 0.18.5", only: :test},
80+
# {:membrane_portaudio_plugin, "~> 0.19.2", only: :test},
7581
{:membrane_hackney_plugin, "~> 0.11.0", only: :test},
7682
{:membrane_transcoder_plugin, "~> 0.3.2", only: :test},
7783
# {:membrane_transcoder_plugin, path: "../membrane_transcoder_plugin", only: :test},

mix.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"credo": {:hex, :credo, "1.7.12", "9e3c20463de4b5f3f23721527fcaf16722ec815e70ff6c60b86412c695d426c1", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "8493d45c656c5427d9c729235b99d498bd133421f3e0a683e5c1b561471291e5"},
1010
"dialyxir": {:hex, :dialyxir, "1.4.5", "ca1571ac18e0f88d4ab245f0b60fa31ff1b12cbae2b11bd25d207f865e8ae78a", [:mix], [{:erlex, ">= 0.2.7", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "b0fb08bb8107c750db5c0b324fa2df5ceaa0f9307690ee3c1f6ba5b9eb5d35c3"},
1111
"earmark_parser": {:hex, :earmark_parser, "1.4.44", "f20830dd6b5c77afe2b063777ddbbff09f9759396500cdbe7523efd58d7a339c", [:mix], [], "hexpm", "4778ac752b4701a5599215f7030989c989ffdc4f6df457c5f36938cc2d2a2750"},
12+
"elixir_make": {:hex, :elixir_make, "0.9.0", "6484b3cd8c0cee58f09f05ecaf1a140a8c97670671a6a0e7ab4dc326c3109726", [:mix], [], "hexpm", "db23d4fd8b757462ad02f8aa73431a426fe6671c80b200d9710caf3d1dd0ffdb"},
1213
"elixir_uuid": {:hex, :elixir_uuid, "1.2.1", "dce506597acb7e6b0daeaff52ff6a9043f5919a4c3315abb4143f0b00378c097", [:mix], [], "hexpm", "f7eba2ea6c3555cea09706492716b0d87397b88946e6380898c2889d68585752"},
1314
"erlex": {:hex, :erlex, "0.2.7", "810e8725f96ab74d17aac676e748627a07bc87eb950d2b83acd29dc047a30595", [:mix], [], "hexpm", "3ed95f79d1a844c3f6bf0cea61e0d5612a42ce56da9c03f01df538685365efb0"},
1415
"ex_doc": {:hex, :ex_doc, "0.38.2", "504d25eef296b4dec3b8e33e810bc8b5344d565998cd83914ffe1b8503737c02", [:mix], [{:earmark_parser, "~> 1.4.44", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "732f2d972e42c116a70802f9898c51b54916e542cc50968ac6980512ec90f42b"},
@@ -65,6 +66,7 @@
6566
"mint": {:hex, :mint, "1.7.1", "113fdb2b2f3b59e47c7955971854641c61f378549d73e829e1768de90fc1abf1", [:mix], [{:castore, "~> 0.1.0 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:hpax, "~> 0.1.1 or ~> 0.2.0 or ~> 1.0", [hex: :hpax, repo: "hexpm", optional: false]}], "hexpm", "fceba0a4d0f24301ddee3024ae116df1c3f4bb7a563a731f45fdfeb9d39a231b"},
6667
"mockery": {:hex, :mockery, "2.3.3", "3dba87bd0422a513e6af6e0d811383f38f82ac6be5d3d285a5fcca9c299bd0ac", [:mix], [], "hexpm", "17282be00613286254298117cd25e607a39f15ac03b41c631f60e52f5b5ec974"},
6768
"mpeg_ts": {:git, "https://github.com/membraneframework-labs/kim_mpeg_ts.git", "8c036fca6558a4339033a5a8697ebf147728f36b", [branch: "backport-v1.0.3"]},
69+
"muontrap": {:hex, :muontrap, "1.6.1", "4a81a159f64e4c7bf01162a7863559d634bc48929218690ada309a9a98a9ac22", [:make, :mix], [{:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "8ad31072402bebed3f554c9a463aa272c6dd964168c9cb81385f8711f068ed47"},
6870
"nimble_options": {:hex, :nimble_options, "1.1.1", "e3a492d54d85fc3fd7c5baf411d9d2852922f66e69476317787a7b2bb000a61b", [:mix], [], "hexpm", "821b2470ca9442c4b6984882fe9bb0389371b8ddec4d45a9504f00a66f650b44"},
6971
"nimble_parsec": {:hex, :nimble_parsec, "1.4.2", "8efba0122db06df95bfaa78f791344a89352ba04baedd3849593bfce4d0dc1c6", [:mix], [], "hexpm", "4b21398942dda052b403bbe1da991ccd03a053668d147d53fb8c4e0efe09c973"},
7072
"nimble_pool": {:hex, :nimble_pool, "1.1.0", "bf9c29fbdcba3564a8b800d1eeb5a3c58f36e1e11d7b7fb2e084a643f645f06b", [:mix], [], "hexpm", "af2e4e6b34197db81f7aad230c1118eac993acc0dae6bc83bac0126d4ae0813a"},

test/membrane_http_adaptive_stream/integration_test/source_test.exs

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,57 @@ defmodule Membrane.HTTPAdaptiveStream.Source.Test do
118118
end
119119
end
120120

121+
@tag :live
122+
@tag :tmp_dir
123+
test "live 1", %{tmp_dir: tmp_dir} do
124+
bbb_mp4_url =
125+
"https://github.com/membraneframework/static/raw/refs/heads/gh-pages/samples/big-buck-bunny/bun33s.mp4"
126+
127+
index_m3u8 = Path.join(tmp_dir, "index.m3u8")
128+
index_m3u8 = Path.join("/Users/feliks/costam/sier2025", "index.m3u8")
129+
130+
IO.puts("output: " <> index_m3u8)
131+
132+
start_link_supervised!({
133+
MuonTrap.Daemon,
134+
[
135+
"ffmpeg",
136+
[
137+
"-re",
138+
"-i",
139+
bbb_mp4_url,
140+
"-c:v",
141+
"libx264",
142+
"-preset",
143+
"veryfast",
144+
"-b:v",
145+
"2000k",
146+
"-c:a",
147+
"aac",
148+
"-b:a",
149+
"128k",
150+
"-f",
151+
"hls",
152+
"-hls_time",
153+
"10",
154+
"-hls_list_size",
155+
"0",
156+
# "-hls_segment_filename",
157+
# "segment_%03d.ts",
158+
index_m3u8
159+
]
160+
]
161+
})
162+
163+
await_until_file_exists(index_m3u8)
164+
165+
pipeline = Testing.Pipeline.start_link_supervised!(spec: playing_pipeline_spec(index_m3u8))
166+
167+
Process.sleep(40_000)
168+
169+
# {MuonTrap.Daemon, ["long_running_command", ["arg1", "arg2"], options]}
170+
end
171+
121172
defp test_new_tracks_notification(hls_url, video_format_validator, audio_format_validator) do
122173
source_spec =
123174
child(:hls_source, %Membrane.HTTPAdaptiveStream.Source{
@@ -181,6 +232,32 @@ defmodule Membrane.HTTPAdaptiveStream.Source.Test do
181232
]
182233
end
183234

235+
defp playing_pipeline_spec(url) do
236+
# Video pipeline
237+
[
238+
child(:hls_source, %Membrane.HTTPAdaptiveStream.Source{
239+
url: url,
240+
variant_selection_policy: :lowest_resolution
241+
})
242+
|> via_out(:video_output)
243+
|> child(:video_decoder, %Membrane.Transcoder{
244+
output_stream_format: Membrane.RawVideo
245+
})
246+
|> child(:realtimer_video, Membrane.Realtimer)
247+
|> child(:video_sink, Membrane.SDL.Player),
248+
249+
# Audio pipeline
250+
get_child(:hls_source)
251+
|> via_out(:audio_output)
252+
|> child(:audio_parser, %Membrane.AAC.Parser{out_encapsulation: :ADTS})
253+
|> child(:audio_decoder, %Membrane.Transcoder{
254+
output_stream_format: Membrane.RawAudio
255+
})
256+
|> child(:realtimer_audio, Membrane.Realtimer)
257+
|> child(:audio_sink, Membrane.PortAudio.Sink)
258+
]
259+
end
260+
184261
defp assert_track(result_file, reference_file, asserted_bytes) do
185262
<<expected_prefix::binary-size(asserted_bytes), _sufix::binary>> =
186263
reference_file |> File.read!()
@@ -189,4 +266,18 @@ defmodule Membrane.HTTPAdaptiveStream.Source.Test do
189266
|> File.read!()
190267
|> String.starts_with?(expected_prefix)
191268
end
269+
270+
defp await_until_file_exists(file_path, wait_s \\ 10) do
271+
cond do
272+
wait_s <= 0 ->
273+
raise "File #{file_path} does not exist after waiting for 10 seconds"
274+
275+
File.exists?(file_path) ->
276+
:ok
277+
278+
true ->
279+
Process.sleep(1000)
280+
await_until_file_exists(file_path, wait_s - 1)
281+
end
282+
end
192283
end

test/test_helper.exs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
ExUnit.start(capture_log: true)
1+
# ExUnit.start(capture_log: true)
2+
ExUnit.start()

0 commit comments

Comments
 (0)