Skip to content

Commit 6e2ac5c

Browse files
committed
Update ex_hls to a version which accepts start_at_ms as a parameter. Add start_at option to the source element.
1 parent 712ad7c commit 6e2ac5c

File tree

5 files changed

+57
-10
lines changed

5 files changed

+57
-10
lines changed

lib/membrane_http_adaptive_stream/source.ex

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,17 @@ defmodule Membrane.HTTPAdaptiveStream.Source do
104104
105105
Defaults to `:highest_resolution`.
106106
"""
107+
],
108+
start_at: [
109+
spec: Membrane.Time.t(),
110+
default: 0,
111+
description: """
112+
Specifies the decoding timestamp of
113+
the first sample that should be read from each of the tracks.
114+
115+
If there is no sample with exactly such a timestamp, that sample
116+
will be the first sample with DTS greater than provided timestamp.
117+
"""
107118
]
108119

109120
@impl true
@@ -134,7 +145,7 @@ defmodule Membrane.HTTPAdaptiveStream.Source do
134145
@impl true
135146
def handle_setup(_ctx, state) do
136147
{:ok, client_genserver} =
137-
ClientGenServer.start_link(state.url, state.variant_selection_policy)
148+
ClientGenServer.start_link(state.url, state.variant_selection_policy, Membrane.Time.as_milliseconds(state.start_at, :round))
138149

139150
{[], %{state | client_genserver: client_genserver}}
140151
end

lib/membrane_http_adaptive_stream/source/client_genserver.ex

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ defmodule Membrane.HTTPAdaptiveStream.Source.ClientGenServer do
88

99
@spec start_link(
1010
String.t(),
11-
Membrane.HTTPAdaptiveStream.Source.variant_selection_policy()
11+
Membrane.HTTPAdaptiveStream.Source.variant_selection_policy(),
12+
Membrane.Time.t()
1213
) ::
1314
GenServer.on_start()
14-
def start_link(url, variant_selection_policy) do
15+
def start_link(url, variant_selection_policy, start_at_ms) do
1516
GenServer.start_link(__MODULE__,
1617
url: url,
17-
variant_selection_policy: variant_selection_policy
18+
variant_selection_policy: variant_selection_policy,
19+
start_at_ms: start_at_ms
1820
)
1921
end
2022

@@ -37,10 +39,11 @@ defmodule Membrane.HTTPAdaptiveStream.Source.ClientGenServer do
3739
end
3840

3941
@impl true
40-
def init(url: url, variant_selection_policy: variant_selection_policy) do
42+
def init(url: url, variant_selection_policy: variant_selection_policy, start_at_ms: start_at_ms) do
4143
state = %{
4244
url: url,
4345
variant_selection_policy: variant_selection_policy,
46+
start_at_ms: start_at_ms,
4447
client: nil
4548
}
4649

@@ -50,7 +53,7 @@ defmodule Membrane.HTTPAdaptiveStream.Source.ClientGenServer do
5053
@impl true
5154
def handle_continue(:setup, state) do
5255
state =
53-
%{state | client: Client.new(state.url)}
56+
%{state | client: Client.new(state.url, state.start_at_ms)}
5457
|> choose_variant()
5558

5659
{:noreply, state}

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ defmodule Membrane.HTTPAdaptiveStream.MixProject do
6969
{:membrane_aac_plugin, "~> 0.19.0"},
7070
{:membrane_h26x_plugin, "~> 0.10.0"},
7171
{:ex_hls,
72-
github: "membraneframework-labs/ex_hls", ref: "88847ba9a547366fd3f4868d49b72bd1e68ae412"},
72+
github: "membraneframework-labs/ex_hls", ref: "5b0227b898559678df25962424d1469f49f48810"},
7373
{:bunch, "~> 1.6"},
7474
{:qex, "~> 0.5"},
7575
{:membrane_hackney_plugin, "~> 0.11.0", only: :test},

mix.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"elixir_uuid": {:hex, :elixir_uuid, "1.2.1", "dce506597acb7e6b0daeaff52ff6a9043f5919a4c3315abb4143f0b00378c097", [:mix], [], "hexpm", "f7eba2ea6c3555cea09706492716b0d87397b88946e6380898c2889d68585752"},
1313
"erlex": {:hex, :erlex, "0.2.7", "810e8725f96ab74d17aac676e748627a07bc87eb950d2b83acd29dc047a30595", [:mix], [], "hexpm", "3ed95f79d1a844c3f6bf0cea61e0d5612a42ce56da9c03f01df538685365efb0"},
1414
"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"},
15-
"ex_hls": {:git, "https://github.com/membraneframework-labs/ex_hls.git", "88847ba9a547366fd3f4868d49b72bd1e68ae412", [ref: "88847ba9a547366fd3f4868d49b72bd1e68ae412"]},
15+
"ex_hls": {:git, "https://github.com/membraneframework-labs/ex_hls.git", "5b0227b898559678df25962424d1469f49f48810", [ref: "5b0227b898559678df25962424d1469f49f48810"]},
1616
"ex_m3u8": {:hex, :ex_m3u8, "0.15.3", "c10427f450b2ed7bfd85808d8dce21214f1fe9fa18927591cbbf96fea0a6a8aa", [:mix], [{:nimble_parsec, "~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}, {:typed_struct, "~> 0.3.0", [hex: :typed_struct, repo: "hexpm", optional: false]}], "hexpm", "99f20c0b44bab130dc6aca71fefe0d1a174413ae9ac2763220994b29bd310939"},
1717
"file_system": {:hex, :file_system, "1.1.0", "08d232062284546c6c34426997dd7ef6ec9f8bbd090eb91780283c9016840e8f", [:mix], [], "hexpm", "bfcf81244f416871f2a2e15c1b515287faa5db9c6bcf290222206d120b3d43f6"},
1818
"finch": {:hex, :finch, "0.20.0", "5330aefb6b010f424dcbbc4615d914e9e3deae40095e73ab0c1bb0968933cadf", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.6.2 or ~> 1.7", [hex: :mint, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.4 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 1.1", [hex: :nimble_pool, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "2658131a74d051aabfcba936093c903b8e89da9a1b63e430bee62045fa9b2ee2"},

test/membrane_http_adaptive_stream/integration_test/source_test.exs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,38 @@ defmodule Membrane.HTTPAdaptiveStream.Source.Test do
7070
assert_track(audio_result_file, @mpeg_ts_audio_ref_file, 40_000)
7171
assert_track(video_result_file, @mpeg_ts_video_ref_file, 70_000)
7272
end
73+
74+
@tag :tmp_dir
75+
@tag :sometag
76+
test "(MPEG-TS) with start_at option", %{tmp_dir: tmp_dir} do
77+
audio_result_file = Path.join(tmp_dir, "audio.aac")
78+
video_result_file = Path.join(tmp_dir, "video.h264")
79+
start_at = Membrane.Time.seconds(10)
80+
81+
spec =
82+
hls_to_file_pipeline_spec(
83+
@mpegts_url,
84+
%Membrane.Transcoder{
85+
assumed_input_stream_format: %Membrane.AAC{
86+
encapsulation: :ADTS
87+
},
88+
output_stream_format: Membrane.AAC
89+
},
90+
audio_result_file,
91+
video_result_file,
92+
start_at
93+
)
94+
95+
pipeline = Testing.Pipeline.start_link_supervised!(spec: spec)
96+
Process.sleep(10_000)
97+
Testing.Pipeline.terminate(pipeline)
98+
99+
# reference files created locally with a quite good internet connection have
100+
# - 78_732 bytes for audio
101+
# - 136_754 bytes for video
102+
assert_track(audio_result_file, @mpeg_ts_audio_ref_file, 40_000)
103+
assert_track(video_result_file, @mpeg_ts_video_ref_file, 70_000)
104+
end
73105
end
74106

75107
describe "Membrane.HTTPAdaptiveStream.Source sends :new_tracks notification" do
@@ -157,11 +189,12 @@ defmodule Membrane.HTTPAdaptiveStream.Source.Test do
157189
Testing.Pipeline.terminate(pipeline)
158190
end
159191

160-
defp hls_to_file_pipeline_spec(url, audio_transcoder, audio_result_file, video_result_file) do
192+
defp hls_to_file_pipeline_spec(url, audio_transcoder, audio_result_file, video_result_file, start_at \\ 0) do
161193
[
162194
child(:hls_source, %Membrane.HTTPAdaptiveStream.Source{
163195
url: url,
164-
variant_selection_policy: :lowest_resolution
196+
variant_selection_policy: :lowest_resolution,
197+
start_at: start_at
165198
})
166199
|> via_out(:video_output)
167200
|> child(%Membrane.Transcoder{

0 commit comments

Comments
 (0)