-
Notifications
You must be signed in to change notification settings - Fork 6
Add how_much_to_skip option to the Source element
#116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 14 commits
6e2ac5c
96802e6
1082157
e3564c4
ed56df9
e51af45
b52f503
006f5c1
d5438f9
3640c66
7de6a75
e4d8b73
56ab986
d4adbb8
525ebf8
0db178f
076d41c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,13 +8,15 @@ defmodule Membrane.HTTPAdaptiveStream.Source.ClientGenServer do | |
|
|
||
| @spec start_link( | ||
| String.t(), | ||
| Membrane.HTTPAdaptiveStream.Source.variant_selection_policy() | ||
| Membrane.HTTPAdaptiveStream.Source.variant_selection_policy(), | ||
| Membrane.Time.t() | ||
| ) :: | ||
| GenServer.on_start() | ||
| def start_link(url, variant_selection_policy) do | ||
| def start_link(url, variant_selection_policy, how_much_to_skip) do | ||
| GenServer.start_link(__MODULE__, | ||
| url: url, | ||
| variant_selection_policy: variant_selection_policy | ||
| variant_selection_policy: variant_selection_policy, | ||
| how_much_to_skip: how_much_to_skip | ||
| ) | ||
| end | ||
|
|
||
|
|
@@ -36,21 +38,34 @@ defmodule Membrane.HTTPAdaptiveStream.Source.ClientGenServer do | |
| GenServer.call(client_genserver, :get_tracks_info) | ||
| end | ||
|
|
||
| @spec how_much_skipped(pid()) :: Membrane.Time.t() | ||
| def how_much_skipped(client_genserver) do | ||
|
||
| GenServer.call(client_genserver, :how_much_skipped) | ||
| end | ||
|
|
||
| @impl true | ||
| def init(url: url, variant_selection_policy: variant_selection_policy) do | ||
| def init( | ||
| url: url, | ||
| variant_selection_policy: variant_selection_policy, | ||
| how_much_to_skip: how_much_to_skip | ||
| ) do | ||
| state = %{ | ||
| url: url, | ||
| variant_selection_policy: variant_selection_policy, | ||
| client: nil | ||
| how_much_to_skip: how_much_to_skip, | ||
| client: nil, | ||
| how_much_skipped: nil | ||
| } | ||
|
|
||
| {:ok, state, {:continue, :setup}} | ||
| end | ||
|
|
||
| @impl true | ||
| def handle_continue(:setup, state) do | ||
| how_much_to_skip_ms = Membrane.Time.as_milliseconds(state.how_much_to_skip, :round) | ||
|
|
||
| state = | ||
| %{state | client: Client.new(state.url)} | ||
| %{state | client: Client.new(state.url, how_much_to_skip_ms)} | ||
| |> choose_variant() | ||
|
|
||
| {:noreply, state} | ||
|
|
@@ -91,13 +106,27 @@ defmodule Membrane.HTTPAdaptiveStream.Source.ClientGenServer do | |
| @impl true | ||
| def handle_cast({:request_audio_chunk, pid}, state) do | ||
| {chunk, client} = Client.read_audio_chunk(state.client) | ||
|
|
||
| state = | ||
| put_in( | ||
| state.how_much_skipped, | ||
| state.client.base_timestamp_ms |> round() |> Membrane.Time.milliseconds() | ||
|
||
| ) | ||
|
|
||
| send(pid, {:audio_chunk, chunk}) | ||
| {:noreply, %{state | client: client}} | ||
| end | ||
|
|
||
| @impl true | ||
| def handle_cast({:request_video_chunk, pid}, state) do | ||
| {chunk, client} = Client.read_video_chunk(state.client) | ||
|
|
||
| state = | ||
| put_in( | ||
| state.how_much_skipped, | ||
| state.client.base_timestamp_ms |> round() |> Membrane.Time.milliseconds() | ||
| ) | ||
|
|
||
| send(pid, {:video_chunk, chunk}) | ||
| {:noreply, %{state | client: client}} | ||
| end | ||
|
|
@@ -107,4 +136,9 @@ defmodule Membrane.HTTPAdaptiveStream.Source.ClientGenServer do | |
| {:ok, tracks_info, client} = Client.get_tracks_info(state.client) | ||
| {:reply, tracks_info, %{state | client: client}} | ||
| end | ||
|
|
||
| @impl true | ||
| def handle_call(:how_much_skipped, _from, state) do | ||
| {:reply, state.how_much_skipped, state} | ||
| end | ||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
discontinuity events are supposed to be sent up to once on every pad, am I right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's right