Skip to content

Commit

Permalink
Spawn Membrane.Clock via subprocess supervisor in components (#594)
Browse files Browse the repository at this point in the history
  • Loading branch information
FelonEkonom authored Sep 5, 2023
1 parent 7c52631 commit 1658b76
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* Implement `Membrane.Debug.Filter` and `Membrane.Debug.Sink`. [#552](https://github.com/membraneframework/membrane_core/pull/552)
* Add `:pause_auto_demand` and `:resume_auto_demand` actions. [#586](https://github.com/membraneframework/membrane_core/pull/586)
* Send `:end_of_stream`, even if it is not preceded by `:start_of_stream`. [#557](https://github.com/membraneframework/membrane_core/pull/577)
* Fix process leak in starting clocks. [#594](https://github.com/membraneframework/membrane_core/pull/594)

## 0.11.0
* Separate element_name and pad arguments in handle_element_{start, end}_of_stream signature [#219](https://github.com/membraneframework/membrane_core/issues/219)
Expand Down
7 changes: 6 additions & 1 deletion lib/membrane/core/bin.ex
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,12 @@ defmodule Membrane.Core.Bin do
Membrane.Core.Stalker.register_component(options.stalker, observability_config)
SubprocessSupervisor.set_parent_component(options.subprocess_supervisor, observability_config)

clock_proxy = Membrane.Clock.start_link(proxy: true) ~> ({:ok, pid} -> pid)
{:ok, clock_proxy} =
SubprocessSupervisor.start_utility(
options.subprocess_supervisor,
{Membrane.Clock, proxy: true}
)

clock = if Bunch.Module.check_behaviour(module, :membrane_clock?), do: clock_proxy, else: nil
Message.send(options.parent, :clock, [name, clock])

Expand Down
6 changes: 4 additions & 2 deletions lib/membrane/core/element/lifecycle_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule Membrane.Core.Element.LifecycleController do
use Bunch

alias Membrane.{Clock, Element, Sync}
alias Membrane.Core.{CallbackHandler, Element, Message}
alias Membrane.Core.{CallbackHandler, Element, Message, SubprocessSupervisor}

alias Membrane.Core.Element.{
ActionHandler,
Expand All @@ -33,7 +33,9 @@ defmodule Membrane.Core.Element.LifecycleController do

clock =
if Bunch.Module.check_behaviour(module, :membrane_clock?) do
{:ok, clock} = Clock.start_link()
{:ok, clock} =
SubprocessSupervisor.start_utility(state.subprocess_supervisor, {Clock, []})

clock
else
nil
Expand Down
8 changes: 6 additions & 2 deletions lib/membrane/core/pipeline.ex
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,16 @@ defmodule Membrane.Core.Pipeline do
Telemetry.report_terminate(:pipeline)
end)

{:ok, clock} = Clock.start_link(proxy: true)
{:ok, clock_proxy} =
SubprocessSupervisor.start_utility(
params.subprocess_supervisor,
{Clock, proxy: true}
)

state = %State{
module: params.module,
synchronization: %{
clock_proxy: clock,
clock_proxy: clock_proxy,
clock_provider: %{clock: nil, provider: nil, choice: :auto},
timers: %{}
},
Expand Down

0 comments on commit 1658b76

Please sign in to comment.