Skip to content
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

Auto push full impl #537

Merged
merged 71 commits into from
May 22, 2023
Merged

Auto push full impl #537

merged 71 commits into from
May 22, 2023

Conversation

FelonEkonom
Copy link
Member

@FelonEkonom FelonEkonom commented Mar 13, 2023

@FelonEkonom FelonEkonom force-pushed the auto-push-full-impl branch from 17ac82e to 4af3609 Compare March 15, 2023 11:07
@FelonEkonom FelonEkonom force-pushed the auto-push-full-impl branch from 4af3609 to 70f1842 Compare March 15, 2023 11:13
@FelonEkonom FelonEkonom added the no-changelog This label has to be added if changes from the PR are not meant to be placed in the CHANGELOG.md label Mar 15, 2023
@FelonEkonom FelonEkonom force-pushed the auto-push-full-impl branch from 8d7e3d9 to e819388 Compare March 15, 2023 12:30
@FelonEkonom FelonEkonom marked this pull request as ready for review March 15, 2023 12:32
@FelonEkonom FelonEkonom requested a review from mat-hek as a code owner March 15, 2023 12:32
@FelonEkonom FelonEkonom requested a review from varsill March 15, 2023 12:33
@FelonEkonom FelonEkonom mentioned this pull request Mar 15, 2023
@FelonEkonom FelonEkonom force-pushed the auto-push-full-impl branch from 436a9be to 38ff2a7 Compare March 17, 2023 13:46
@FelonEkonom FelonEkonom marked this pull request as draft March 20, 2023 12:28
@FelonEkonom FelonEkonom requested a review from mat-hek May 16, 2023 11:14
Comment on lines 1 to 9
defmodule Membrane.Core.Element.DemandCounter.DistributedFlowMode do
@moduledoc false

alias Membrane.Core.Element.DemandCounter.DistributedAtomic
alias Membrane.Core.Element.EffectiveFlowController

@type t :: DistributedAtomic.t()
@type flow_mode_value ::
EffectiveFlowController.effective_flow_control() | :to_be_resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
defmodule Membrane.Core.Element.DemandCounter.DistributedFlowMode do
@moduledoc false
alias Membrane.Core.Element.DemandCounter.DistributedAtomic
alias Membrane.Core.Element.EffectiveFlowController
@type t :: DistributedAtomic.t()
@type flow_mode_value ::
EffectiveFlowController.effective_flow_control() | :to_be_resolved
defmodule Membrane.Core.Element.DemandCounter.DistributedFlowStatus do
@moduledoc false
alias Membrane.Core.Element.DemandCounter.DistributedAtomic
alias Membrane.Core.Element.EffectiveFlowController
@type t :: DistributedAtomic.t()
@type flow_control_status ::
{:resolved, EffectiveFlowController.effective_flow_control()} | :to_be_resolved

receiver_demand_unit: Membrane.Buffer.Metric.unit()
}

@type flow_mode :: DistributedFlowMode.flow_mode_value()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@type flow_mode :: DistributedFlowMode.flow_mode_value()

@@ -91,7 +89,9 @@ defmodule Membrane.Core.Element.DemandController do
@spec decrease_demand_by_outgoing_buffers(Pad.ref(), [Buffer.t()], State.t()) :: State.t()
def decrease_demand_by_outgoing_buffers(pad_ref, buffers, state) do
pad_data = PadModel.get_data!(state, pad_ref)
buffers_size = Buffer.Metric.from_unit(pad_data.other_demand_unit).buffers_size(buffers)

demand_unit = pad_data.demand_unit || pad_data.other_demand_unit || :buffers
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

demand unit should be resolved when the pad is linked

Copy link
Member Author

@FelonEkonom FelonEkonom May 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but this alternative matters when output pad has :push flow control

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So maybe we should calculate the demand unit no matter the flow control (since the demand counter is always there)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it does not look good to have non-nil demand_unit when flow_control is :push. I have changed this line to make it explicit, that we take other_demand_unit into account only when flow_control is :push and pad_data.demand_unit when flow_control is :pull or :auto

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it does not look good to have non-nil demand_unit when flow_control is :push.

IMO it looks even worse to have demand_counter and not have demand_unit there 🤔 And I see no point in resolving it each time when we can do it once.

Maybe the field should be buffer_size_unit, not demand_unit :D

lib/membrane/core/element/demand_counter.ex Outdated Show resolved Hide resolved
lib/membrane/element/pad_data.ex Outdated Show resolved Hide resolved
@@ -241,6 +244,18 @@ defmodule Membrane.Core.Element.PadController do
end
end

@spec handle_input_pad_added(Pad.ref(), State.t()) :: State.t()
def handle_input_pad_added(pad_ref, state) do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's only called once, in the same module. Remove it and put the contents where it's called

@FelonEkonom FelonEkonom requested a review from mat-hek May 18, 2023 13:05
@FelonEkonom FelonEkonom force-pushed the auto-push-full-impl branch from 27c0b66 to 1a1957a Compare May 18, 2023 13:06
@@ -19,7 +19,7 @@ defmodule Membrane.Core.Element.DemandCounter.DistributedAtomic do
@spec new(integer() | nil) :: t
def new(initial_value \\ nil) do
atomic_ref = :atomics.new(1, [])
{:ok, worker} = Worker.start_link()
{:ok, worker} = Worker.start_link(self())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's start it under the supervisor

%{effective_flow_control: effective_flow_control} = state
),
do: state

defp set_effective_flow_control(new_effective_flow_control, state) do
defp set_effective_flow_control(new_effective_flow_control, last_changed_pad, state) do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
defp set_effective_flow_control(new_effective_flow_control, last_changed_pad, state) do
defp set_effective_flow_control(new_effective_flow_control, triggerer_pad, state) do

[pad_data.other_ref, new_effective_flow_control]
)

state

{pad_ref, %{direction: :input} = pad_data}, state when last_changed_pad != nil ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{pad_ref, %{direction: :input} = pad_data}, state when last_changed_pad != nil ->
{pad_ref, %{direction: :input} = pad_data}, state ->

lib/membrane/core/element/demand_counter.ex Outdated Show resolved Hide resolved
lib/membrane/core/element/demand_counter.ex Outdated Show resolved Hide resolved
lib/membrane/core/element/demand_handler.ex Outdated Show resolved Hide resolved
lib/membrane/core/element/effective_flow_controller.ex Outdated Show resolved Hide resolved
@FelonEkonom FelonEkonom requested review from varsill and mat-hek May 22, 2023 11:51
Copy link
Member

@mat-hek mat-hek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@FelonEkonom
Copy link
Member Author

🎉

awesome

Copy link
Contributor

@varsill varsill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is one small comment concerning the docs, but generally speaking:
LGTM 🥇

@@ -1,7 +1,7 @@
defmodule Membrane.Core.Element.DemandController do
@moduledoc false

# Module handling changes in values of output pads demand counters
# Module handling changes in values of output pads demand atomics
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Module handling changes in values of output pads demand atomics
# Module handling changes in values of output pads atomic demand

To be fair, I believe it should be written that way, but I don't find it anyhow crucial :D

@FelonEkonom FelonEkonom merged commit 0328b57 into master May 22, 2023
@FelonEkonom FelonEkonom deleted the auto-push-full-impl branch May 22, 2023 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-changelog This label has to be added if changes from the PR are not meant to be placed in the CHANGELOG.md
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants