Skip to content

Commit c81c07d

Browse files
committed
Add new type, refactor error message
1 parent d324bc3 commit c81c07d

File tree

1 file changed

+34
-10
lines changed

1 file changed

+34
-10
lines changed

lib/membrane_http_adaptive_stream/source.ex

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,23 @@ defmodule Membrane.HTTPAdaptiveStream.Source do
6262
| (variants_map :: %{integer() => ExHLS.Client.variant_description()} ->
6363
variant_id :: integer())
6464

65+
@typedoc """
66+
Notification sent by #{inspect(__MODULE__)} to its parent when the element figures out what
67+
tracks are present in the HLS stream.
68+
69+
Contains pads that should be linked to the element and stream formats that will be sent via
70+
those pads.
71+
72+
If pads are linked before the element enters the `:playing` playback, the notification will
73+
not be sent, but the pads will have to match the tracks in the HLS stream.
74+
"""
75+
@type new_tracks_notification() ::
76+
{:new_tracks,
77+
[
78+
{:audio_output, RemoteStream.t() | AAC.t()}
79+
| {:video_output, RemoteStream.t() | H264.t()}
80+
]}
81+
6582
def_options url: [
6683
spec: String.t(),
6784
description: "URL of the HLS playlist manifest"
@@ -132,23 +149,30 @@ defmodule Membrane.HTTPAdaptiveStream.Source do
132149
{[], state}
133150
end
134151

135-
# todo: refactor error messages in handle_pad_added/3
136-
137152
@impl true
138153
def handle_pad_added(Pad.ref(pad_name, _id) = pad_ref, ctx, state)
139-
when ctx.playback == :playing do
140-
case state.status do
141-
:waiting_on_pads -> :ok
142-
:running -> raise "dupa"
143-
end
144-
154+
when ctx.playback == :playing and state.status == :waiting_on_pads do
145155
state = state |> put_in([pad_name, :ref], pad_ref)
146156

147157
if map_size(ctx.pads) == length(state.new_tracks_notification),
148158
do: state |> start_running(),
149159
else: {[], state}
150160
end
151161

162+
@impl true
163+
def handle_pad_added(Pad.ref(pad_name, _id), ctx, state)
164+
when ctx.playback == :playing and state.status == :running do
165+
raise """
166+
Tried to link pad #{inspect(pad_name)}, but all pads are already linked.
167+
168+
You must follow one of two scenarios:
169+
1. Link all pads before an element enters the `:playing` playback.
170+
2. Don't link any pads before an element enters the `:playing` playback,
171+
wait until it generates `{:new_tracks, tracks}` parent notification
172+
and then link pads accodrding to the notification.
173+
"""
174+
end
175+
152176
@impl true
153177
def handle_playing(_ctx, state) do
154178
if state.audio_output.ref != nil or state.video_output.ref != nil do
@@ -247,7 +271,7 @@ defmodule Membrane.HTTPAdaptiveStream.Source do
247271
#{pad_name_to_media_type(pad_name)} stream format.
248272
249273
Pads: #{get_pads(state) |> inspect()}
250-
Stream formats: #{inspect(stream_formats)}
274+
Stream formats of tracks in HLS playlist: #{inspect(stream_formats)}
251275
"""
252276
end
253277

@@ -258,7 +282,7 @@ defmodule Membrane.HTTPAdaptiveStream.Source do
258282
#{pad_name_to_media_type(pad_name)} stream format.
259283
260284
Pads: #{get_pads(state) |> inspect()}
261-
Stream formats: #{inspect(stream_formats)}
285+
Stream formats of tracks in HLS playlist: #{inspect(stream_formats)}
262286
"""
263287
end
264288

0 commit comments

Comments
 (0)