Skip to content

Commit

Permalink
Merge pull request #14 from membraneframework/core-0.11
Browse files Browse the repository at this point in the history
Update to Core 0.11, bump plugin version
  • Loading branch information
balins authored Jan 2, 2023
2 parents 6b48835 + 9b973e5 commit b5bb07d
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 67 deletions.
25 changes: 22 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,25 @@ workflows:
version: 2
build:
jobs:
- elixir/build_test
- elixir/test
- elixir/lint
- elixir/build_test:
filters: &filters
tags:
only: /v.*/
- elixir/test:
filters:
<<: *filters
- elixir/lint:
filters:
<<: *filters
- elixir/hex_publish:
requires:
- elixir/build_test
- elixir/test
- elixir/lint
context:
- Deployment
filters:
branches:
ignore: /.*/
tags:
only: /v.*/
53 changes: 22 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

Membrane plugin for limiting playback speed to realtime, according to buffers' timestamps.

It is part of [Membrane Multimedia Framework](https://membraneframework.org).
It is a part of [Membrane Multimedia Framework](https://membraneframework.org).

## Installation

Expand All @@ -15,7 +15,7 @@ The package can be installed by adding `membrane_realtimer_plugin` to your list
```elixir
def deps do
[
{:membrane_realtimer_plugin, "~> 0.5.0"}
{:membrane_realtimer_plugin, "~> 0.6.0"}
]
end
```
Expand All @@ -29,36 +29,27 @@ It requires [RTP plugin](https://github.com/membraneframework/membrane_rtp_plugi
defmodule Example.Pipeline do
use Membrane.Pipeline

@ssrc 1234

@impl true
def handle_init(_opts) do
ssrc = 1234

spec = %ParentSpec{
children: [
source: %Membrane.Hackney.Source{
location: "https://membraneframework.github.io/static/samples/ffmpeg-testsrc.h264",
hackney_opts: [follow_redirect: true]
},
parser: %Membrane.H264.FFmpeg.Parser{framerate: {30, 1}, alignment: :nal},
rtp: Membrane.RTP.SessionBin,
realtimer: Membrane.Realtimer,
sink: %Membrane.UDP.Sink{
destination_port_no: 5000,
destination_address: {127, 0, 0, 1}
}
],
links: [
link(:source)
|> to(:parser)
|> via_in(Pad.ref(:input, ssrc), options: [payloader: Membrane.RTP.H264.Payloader])
|> to(:rtp)
|> via_out(Pad.ref(:rtp_output, ssrc), options: [encoding: :H264])
|> to(:realtimer)
|> to(:sink)
]
}

{{:ok, spec: spec, playback: :playing}, %{}}
def handle_init(_ctx, _opts) do
structure = [
child(:source, %Membrane.Hackney.Source{
location: "https://membraneframework.github.io/static/samples/ffmpeg-testsrc.h264",
hackney_opts: [follow_redirect: true]
})
|> child(:parser, %Membrane.H264.FFmpeg.Parser{framerate: {30, 1}, alignment: :nal})
|> via_in(Pad.ref(:input, @ssrc), options: [payloader: Membrane.RTP.H264.Payloader])
|> child(:rtp, Membrane.RTP.SessionBin)
|> via_out(Pad.ref(:rtp_output, @ssrc), options: [encoding: :H264])
|> child(:realtimer, Membrane.Realtimer)
|> child(:sink, %Membrane.UDP.Sink{
destination_port_no: 5000,
destination_address: {127, 0, 0, 1}
})
]

{[spec: structure, playback: :playing], %{}}
end
end
```
Expand Down
38 changes: 20 additions & 18 deletions lib/membrane/realtimer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,21 @@ defmodule Membrane.Realtimer do

alias Membrane.Buffer

def_input_pad :input, caps: :any, demand_unit: :buffers
def_output_pad :output, caps: :any, mode: :push
def_input_pad :input, accepted_format: _any, demand_unit: :buffers
def_output_pad :output, accepted_format: _any, mode: :push

@impl true
def handle_init(_opts) do
{:ok, %{previous_timestamp: 0, tick_actions: []}}
def handle_init(_ctx, _opts) do
{[], %{previous_timestamp: 0, tick_actions: []}}
end

@impl true
def handle_prepared_to_playing(_ctx, state) do
{{:ok, start_timer: {:timer, :no_interval}, demand: {:input, 1}}, state}
def handle_playing(_ctx, state) do
{[start_timer: {:timer, :no_interval}, demand: {:input, 1}], state}
end

# TODO: remove when https://github.com/membraneframework/membrane_core/pull/502 is merged and released
@dialyzer {:no_behaviours, {:handle_process, 4}}
@impl true
def handle_process(:input, buffer, _ctx, state) do
use Ratio
Expand All @@ -32,38 +34,38 @@ defmodule Membrane.Realtimer do
tick_actions: [buffer: {:output, buffer}] ++ state.tick_actions
}

{{:ok, timer_interval: {:timer, interval}}, state}
{[timer_interval: {:timer, interval}], state}
end

@impl true
def handle_event(pad, event, _ctx, %{tick_actions: tick_actions} = state)
when pad == :output or tick_actions == [] do
{{:ok, forward: event}, state}
{[forward: event], state}
end

@impl true
def handle_event(:input, event, _ctx, state) do
{:ok, %{state | tick_actions: [event: {:output, event}] ++ state.tick_actions}}
{[], %{state | tick_actions: [event: {:output, event}] ++ state.tick_actions}}
end

@impl true
def handle_caps(:input, caps, _ctx, %{tick_actions: []} = state) do
{{:ok, forward: caps}, state}
def handle_stream_format(:input, stream_format, _ctx, %{tick_actions: []} = state) do
{[forward: stream_format], state}
end

@impl true
def handle_caps(:input, caps, _ctx, state) do
{:ok, %{state | tick_actions: [caps: {:output, caps}] ++ state.tick_actions}}
def handle_stream_format(:input, stream_format, _ctx, state) do
{[], %{state | tick_actions: [stream_format: {:output, stream_format}] ++ state.tick_actions}}
end

@impl true
def handle_end_of_stream(:input, _ctx, %{tick_actions: []} = state) do
{{:ok, end_of_stream: :output}, state}
{[end_of_stream: :output], state}
end

@impl true
def handle_end_of_stream(:input, _ctx, state) do
{:ok, %{state | tick_actions: [end_of_stream: :output] ++ state.tick_actions}}
{[], %{state | tick_actions: [end_of_stream: :output] ++ state.tick_actions}}
end

@impl true
Expand All @@ -72,11 +74,11 @@ defmodule Membrane.Realtimer do
[timer_interval: {:timer, :no_interval}] ++
Enum.reverse(state.tick_actions) ++ [demand: {:input, 1}]

{{:ok, actions}, %{state | tick_actions: []}}
{actions, %{state | tick_actions: []}}
end

@impl true
def handle_playing_to_prepared(_ctx, state) do
{{:ok, stop_timer: :timer}, %{state | previous_timestamp: 0}}
def handle_terminate_request(_ctx, state) do
{[stop_timer: :timer], %{state | previous_timestamp: 0}}
end
end
7 changes: 4 additions & 3 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Membrane.Realtimer.Plugin.Mixfile do
use Mix.Project

@version "0.5.0"
@version "0.6.0"
@github_url "https://github.com/membraneframework/membrane_realtimer_plugin"

def project do
Expand Down Expand Up @@ -37,7 +37,7 @@ defmodule Membrane.Realtimer.Plugin.Mixfile do

defp deps do
[
{:membrane_core, "~> 0.10"},
{:membrane_core, "~> 0.11"},
{:ex_doc, "~> 0.28", only: :dev, runtime: false},
{:dialyxir, "~> 1.1", only: :dev, runtime: false},
{:credo, "~> 1.6", only: :dev, runtime: false}
Expand Down Expand Up @@ -73,7 +73,8 @@ defmodule Membrane.Realtimer.Plugin.Mixfile do
main: "readme",
extras: ["README.md", "LICENSE"],
formatters: ["html"],
source_ref: "v#{@version}"
source_ref: "v#{@version}",
nest_modules_by_prefix: [Membrane.Realtimer]
]
end
end
8 changes: 4 additions & 4 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
%{
"bunch": {:hex, :bunch, "1.3.2", "9a3647e8bf8859482206c554d907b13d60aa8e40a3b82057a34bf71c0e23a0ae", [:mix], [], "hexpm", "dd89f2df6e6284c06cf9c44be5aae622f2a5a0804098167a0cb5370542c8c22b"},
"bunch": {:hex, :bunch, "1.6.0", "4775f8cdf5e801c06beed3913b0bd53fceec9d63380cdcccbda6be125a6cfd54", [:mix], [], "hexpm", "ef4e9abf83f0299d599daed3764d19e8eac5d27a5237e5e4d5e2c129cfeb9a22"},
"bunt": {:hex, :bunt, "0.2.1", "e2d4792f7bc0ced7583ab54922808919518d0e57ee162901a16a1b6664ef3b14", [:mix], [], "hexpm", "a330bfb4245239787b15005e66ae6845c9cd524a288f0d141c148b02603777a5"},
"coerce": {:hex, :coerce, "1.0.1", "211c27386315dc2894ac11bc1f413a0e38505d808153367bd5c6e75a4003d096", [:mix], [], "hexpm", "b44a691700f7a1a15b4b7e2ff1fa30bebd669929ac8aa43cffe9e2f8bf051cf1"},
"credo": {:hex, :credo, "1.6.7", "323f5734350fd23a456f2688b9430e7d517afb313fbd38671b8a4449798a7854", [:mix], [{:bunt, "~> 0.2.1", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "41e110bfb007f7eda7f897c10bf019ceab9a0b269ce79f015d54b0dcf4fc7dd3"},
"dialyxir": {:hex, :dialyxir, "1.2.0", "58344b3e87c2e7095304c81a9ae65cb68b613e28340690dfe1a5597fd08dec37", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "61072136427a851674cab81762be4dbeae7679f85b1272b6d25c3a839aff8463"},
"earmark_parser": {:hex, :earmark_parser, "1.4.26", "f4291134583f373c7d8755566122908eb9662df4c4b63caa66a0eabe06569b0a", [:mix], [], "hexpm", "48d460899f8a0c52c5470676611c01f64f3337bad0b26ddab43648428d94aabc"},
"earmark_parser": {:hex, :earmark_parser, "1.4.29", "149d50dcb3a93d9f3d6f3ecf18c918fb5a2d3c001b5d3305c926cddfbd33355b", [:mix], [], "hexpm", "4902af1b3eb139016aed210888748db8070b8125c2342ce3dcae4f38dcc63503"},
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
"ex_doc": {:hex, :ex_doc, "0.28.5", "3e52a6d2130ce74d096859e477b97080c156d0926701c13870a4e1f752363279", [:mix], [{:earmark_parser, "~> 1.4.19", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "d2c4b07133113e9aa3e9ba27efb9088ba900e9e51caa383919676afdf09ab181"},
"ex_doc": {:hex, :ex_doc, "0.29.1", "b1c652fa5f92ee9cf15c75271168027f92039b3877094290a75abcaac82a9f77", [:mix], [{:earmark_parser, "~> 1.4.19", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "b7745fa6374a36daf484e2a2012274950e084815b936b1319aeebcf7809574f6"},
"file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"},
"jason": {:hex, :jason, "1.4.0", "e855647bc964a44e2f67df589ccf49105ae039d4179db7f6271dfd3843dc27e6", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "79a3791085b2a0f743ca04cec0f7be26443738779d09302e01318f97bdb82121"},
"makeup": {:hex, :makeup, "1.1.0", "6b67c8bc2882a6b6a445859952a602afc1a41c2e08379ca057c0f525366fc3ca", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "0a45ed501f4a8897f580eabf99a2e5234ea3e75a4373c8a52824f6e873be57a6"},
"makeup_elixir": {:hex, :makeup_elixir, "0.16.0", "f8c570a0d33f8039513fbccaf7108c5d750f47d8defd44088371191b76492b0b", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "28b2cbdc13960a46ae9a8858c4bebdec3c9a6d7b4b9e7f4ed1502f8159f338e7"},
"makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"},
"membrane_core": {:hex, :membrane_core, "0.10.2", "d2d17039f6df746e4a3c47da32f51867fbafe528272cdd9b226d16b1032bc337", [:mix], [{:bunch, "~> 1.3", [hex: :bunch, repo: "hexpm", optional: false]}, {:qex, "~> 0.3", [hex: :qex, repo: "hexpm", optional: false]}, {:ratio, "~> 2.0", [hex: :ratio, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "6a4f290f919ada66c772807d64d5830be2962b7c13a2f2bc9ace416a1cd19ee1"},
"membrane_core": {:hex, :membrane_core, "0.11.2", "c8a257bea90c53e0fe99453630a07e4711e4d8ba25e647b3ba346b994aa4f7ab", [:mix], [{:bunch, "~> 1.5", [hex: :bunch, repo: "hexpm", optional: false]}, {:qex, "~> 0.3", [hex: :qex, repo: "hexpm", optional: false]}, {:ratio, "~> 2.0", [hex: :ratio, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7e2566c9b6d1c22fbb832c22e5f9dbbf7c6cba1c72eeea53bd2f2b73efed58b3"},
"nimble_parsec": {:hex, :nimble_parsec, "1.2.3", "244836e6e3f1200c7f30cb56733fd808744eca61fd182f731eac4af635cc6d0b", [:mix], [], "hexpm", "c8d789e39b9131acf7b99291e93dae60ab48ef14a7ee9d58c6964f59efb570b0"},
"numbers": {:hex, :numbers, "5.2.4", "f123d5bb7f6acc366f8f445e10a32bd403c8469bdbce8ce049e1f0972b607080", [:mix], [{:coerce, "~> 1.0", [hex: :coerce, repo: "hexpm", optional: false]}, {:decimal, "~> 1.9 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "eeccf5c61d5f4922198395bf87a465b6f980b8b862dd22d28198c5e6fab38582"},
"qex": {:hex, :qex, "0.5.1", "0d82c0f008551d24fffb99d97f8299afcb8ea9cf99582b770bd004ed5af63fd6", [:mix], [], "hexpm", "935a39fdaf2445834b95951456559e9dc2063d0a055742c558a99987b38d6bab"},
Expand Down
17 changes: 9 additions & 8 deletions test/membrane_realtimer_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@ defmodule Membrane.RealtimerTest do
alias Membrane.{Buffer, Realtimer, Testing, Time}

test "Limits playback speed to realtime" do
import Membrane.ChildrenSpec

buffers = [
%Buffer{pts: 0, payload: 0},
%Buffer{pts: Time.milliseconds(100), payload: 1}
]

{:ok, pipeline} =
[
src1: %Testing.Source{output: Testing.Source.output_from_buffers(buffers)},
realtimer: Realtimer,
sink: Testing.Sink
]
|> Membrane.ParentSpec.link_linear()
|> then(&Testing.Pipeline.start_link(links: &1))
structure = [
child(:src, %Testing.Source{output: Testing.Source.output_from_buffers(buffers)})
|> child(:realtimer, Realtimer)
|> child(:sink, Testing.Sink)
]

pipeline = Testing.Pipeline.start_link_supervised!(structure: structure)

assert_sink_buffer(pipeline, :sink, %Buffer{payload: 0})
refute_sink_buffer(pipeline, :sink, _buffer, 90)
Expand Down

0 comments on commit b5bb07d

Please sign in to comment.