@@ -2,57 +2,102 @@ defmodule Membrane.HLS.Source.Test do
22 use ExUnit.Case , async: true
33
44 import Membrane.ChildrenSpec
5- import Membrane.Testing.Assertions
6-
75 alias Membrane.Testing
86
97 @ mpegts_url "https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8"
108 @ fmp4_url "https://raw.githubusercontent.com/membraneframework-labs/ex_hls/refs/heads/plug-demuxing-engine-into-client/fixture/output.m3u8"
119
12- @ tag :a
13- test "fmp4" do
14- spec = [
15- child ( :hls_source , % Membrane.HLS.Source { url: @ fmp4_url } )
16- |> via_out ( :video_output )
17- |> child ( % Membrane.Transcoder { output_stream_format: Membrane.RawVideo } )
18- |> child ( Membrane.SDL.Player ) ,
19- get_child ( :hls_source )
20- |> via_out ( :audio_output )
21- |> child ( % Membrane.Transcoder { output_stream_format: Membrane.RawAudio } )
22- |> child ( Membrane.PortAudio.Sink )
23- ]
10+ @ hls_source_fixtures "test/membrane_http_adaptive_stream/integration_test/fixtures/hls_source"
11+ @ fmp4_video_fixture Path . join ( @ hls_source_fixtures , "fmp4/video.h264" )
12+ @ fmp4_audio_fixture Path . join ( @ hls_source_fixtures , "fmp4/audio.aac" )
13+ @ mpeg_ts_video_fixture Path . join ( @ hls_source_fixtures , "mpeg_ts/video.h264" )
14+ @ mpeg_ts_audio_fixture Path . join ( @ hls_source_fixtures , "mpeg_ts/audio.aac" )
15+
16+ describe "Membrane.HLS.Source demuxes audio and video from HLS stream" do
17+ @ tag :tmp_dir
18+ test "(fMP4)" , % { tmp_dir: tmp_dir } do
19+ audio_result_file = Path . join ( tmp_dir , "audio.aac" )
20+ video_result_file = Path . join ( tmp_dir , "video.h264" )
21+
22+ spec =
23+ pipeline_spec (
24+ @ fmp4_url ,
25+ % Membrane.Transcoder { output_stream_format: Membrane.AAC } ,
26+ audio_result_file ,
27+ video_result_file
28+ )
29+
30+ pipeline = Testing.Pipeline . start_link_supervised! ( spec: spec )
31+ Process . sleep ( 10_000 )
32+ Testing.Pipeline . terminate ( pipeline )
2433
25- pipeline = Testing.Pipeline . start_link_supervised! ( spec: spec )
34+ # fixtures created locally with a quite good internet connection have
35+ # - 139_085 bytes for audio
36+ # - 500_571 bytes for video
37+ assert_track ( audio_result_file , @ fmp4_audio_fixture , 70_000 )
38+ assert_track ( video_result_file , @ fmp4_video_fixture , 200_000 )
39+ end
2640
27- Process . sleep ( 10_000 )
28- Testing.Pipeline . terminate ( pipeline )
41+ @ tag :tmp_dir
42+ test "(MPEG-TS)" , % { tmp_dir: tmp_dir } do
43+ audio_result_file = Path . join ( tmp_dir , "audio.aac" )
44+ video_result_file = Path . join ( tmp_dir , "video.h264" )
45+
46+ spec =
47+ pipeline_spec (
48+ @ mpegts_url ,
49+ % Membrane.Transcoder {
50+ assumed_input_stream_format: % Membrane.AAC {
51+ encapsulation: :ADTS
52+ } ,
53+ output_stream_format: Membrane.AAC
54+ } ,
55+ audio_result_file ,
56+ video_result_file
57+ )
58+
59+ pipeline = Testing.Pipeline . start_link_supervised! ( spec: spec )
60+ Process . sleep ( 10_000 )
61+ Testing.Pipeline . terminate ( pipeline )
62+
63+ # fixtures created locally with a quite good internet connection have
64+ # - 78_732 bytes for audio
65+ # - 136_754 bytes for video
66+ assert_track ( audio_result_file , @ mpeg_ts_audio_fixture , 40_000 )
67+ assert_track ( video_result_file , @ mpeg_ts_video_fixture , 70_000 )
68+ end
2969 end
3070
31- @ tag :b
32- test "mpeg-ts" do
33- spec = [
34- child ( :hls_source , % Membrane.HLS.Source { url: @ mpegts_url } )
71+ defp pipeline_spec ( url , audio_transcoder , audio_result_file , video_result_file ) do
72+ [
73+ child ( :hls_source , % Membrane.HLS.Source {
74+ url: url ,
75+ variant_selection_policy: :lowest_resolution
76+ } )
3577 |> via_out ( :video_output )
3678 |> child ( % Membrane.Transcoder {
37- output_stream_format: Membrane.RawVideo
79+ output_stream_format: Membrane.H264
3880 } )
3981 |> child ( Membrane.Realtimer )
40- |> child ( Membrane.SDL.Player ) ,
82+ |> child ( % Membrane.File.Sink {
83+ location: video_result_file
84+ } ) ,
4185 get_child ( :hls_source )
4286 |> via_out ( :audio_output )
43- |> child ( % Membrane.Transcoder {
44- assumed_input_stream_format: % Membrane.AAC {
45- encapsulation: :ADTS
46- } ,
47- output_stream_format: Membrane.RawAudio
48- } )
87+ |> child ( audio_transcoder )
4988 |> child ( Membrane.Realtimer )
50- |> child ( Membrane.PortAudio.Sink )
89+ |> child ( % Membrane.File.Sink {
90+ location: audio_result_file
91+ } )
5192 ]
93+ end
5294
53- pipeline = Testing.Pipeline . start_link_supervised! ( spec: spec )
95+ defp assert_track ( result_file , fixture , asserted_bytes ) do
96+ << expected_prefix :: binary - size ( asserted_bytes ) , _sufix :: binary >> =
97+ fixture |> File . read! ( )
5498
55- Process . sleep ( 10_000 )
56- Testing.Pipeline . terminate ( pipeline )
99+ assert result_file
100+ |> File . read! ( )
101+ |> String . starts_with? ( expected_prefix )
57102 end
58103end
0 commit comments