generated from membraneframework/membrane_template_plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from membraneframework/release
Release v0.1.0
- Loading branch information
Showing
8 changed files
with
168 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,62 @@ | ||
# Membrane Multimedia Framework: Template Plugin | ||
# Membrane Funnel plugin | ||
|
||
[![Hex.pm](https://img.shields.io/hexpm/v/membrane_template_plugin.svg)](https://hex.pm/packages/membrane_template_plugin) | ||
[![CircleCI](https://circleci.com/gh/membraneframework/membrane_template_plugin.svg?style=svg)](https://circleci.com/gh/membraneframework/membrane_template_plugin) | ||
[![Hex.pm](https://img.shields.io/hexpm/v/membrane_template_plugin.svg)](https://hex.pm/packages/membrane_funnel_plugin) | ||
[![API Docs](https://img.shields.io/badge/api-docs-yellow.svg?style=flat)](https://hexdocs.pm/membrane_funnel_plugin/) | ||
[![CircleCI](https://circleci.com/gh/membraneframework/membrane_template_plugin.svg?style=svg)](https://circleci.com/gh/membraneframework/membrane_funnel_plugin) | ||
|
||
This repository contains a template for new elements. | ||
Membrane plugin for funneling. | ||
|
||
Check out different branches for other flavours of template. | ||
It can be used for collecting data from multiple inputs and sending it through one output. | ||
|
||
It is part of [Membrane Multimedia Framework](https://membraneframework.org). | ||
|
||
## Installation | ||
|
||
The package can be installed by adding `membrane_template_plugin` to your list of dependencies in `mix.exs`: | ||
The package can be installed by adding `membrane_funnel_plugin` to your list of dependencies in `mix.exs`: | ||
|
||
```elixir | ||
def deps do | ||
[ | ||
{:membrane_template_plugin, "~> 0.1.0"} | ||
{:membrane_funnel_plugin, "~> 0.1.0"} | ||
] | ||
end | ||
``` | ||
|
||
## Usage | ||
Playing this pipeline should merge two files `a.txt` and `b.txt` into file `c.txt` | ||
|
||
TODO | ||
```elixir | ||
defmodule FunnelDemo do | ||
use Membrane.Pipeline | ||
|
||
def handle_init(_) do | ||
children = [ | ||
a_source: %Membrane.File.Source{location: "a.txt"}, | ||
b_source: %Membrane.File.Source{location: "b.txt"}, | ||
funnel: Membrane.Funnel, | ||
sink: %Membrane.File.Sink{location: "c.txt"} | ||
] | ||
|
||
links = [ | ||
link(:a_source) |> to(:funnel), | ||
link(:b_source) |> to(:funnel), | ||
link(:funnel) |> to(:sink) | ||
] | ||
|
||
spec = %ParentSpec{children: children, links: links} | ||
{{:ok, spec: spec}, %{}} | ||
end | ||
end | ||
``` | ||
|
||
For more examples please refer to our [echo demo](https://github.com/membraneframework/membrane_demo/tree/echo/webrtc/echo) | ||
where we use funnel plugin to send two RTP streams using the same connection, or our integration | ||
tests. | ||
|
||
## Copyright and License | ||
|
||
Copyright 2020, [Software Mansion](https://swmansion.com/?utm_source=git&utm_medium=readme&utm_campaign=membrane_template_plugin) | ||
Copyright 2020, [Software Mansion](https://swmansion.com/?utm_source=git&utm_medium=readme&utm_campaign=membrane_funnel_plugin) | ||
|
||
[![Software Mansion](https://logo.swmansion.com/logo?color=white&variant=desktop&width=200&tag=membrane-github)](https://swmansion.com/?utm_source=git&utm_medium=readme&utm_campaign=membrane_template_plugin) | ||
[![Software Mansion](https://logo.swmansion.com/logo?color=white&variant=desktop&width=200&tag=membrane-github)](https://swmansion.com/?utm_source=git&utm_medium=readme&utm_campaign=membrane_funnel_plugin) | ||
|
||
Licensed under the [Apache License, Version 2.0](LICENSE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
defmodule Membrane.Funnel.NewInputEvent do | ||
@moduledoc """ | ||
Event sent each time new element is linked (via funnel input pad) after playing pipeline. | ||
""" | ||
@derive Membrane.EventProtocol | ||
|
||
@type t :: %__MODULE__{} | ||
defstruct [] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
defmodule Membrane.Funnel do | ||
@moduledoc """ | ||
Element that can be used for collecting data from multiple inputs and sending it through one | ||
output. | ||
""" | ||
use Membrane.Filter | ||
|
||
alias Membrane.Funnel | ||
|
||
def_input_pad :input, demand_unit: :buffers, caps: :any, availability: :on_request | ||
def_output_pad :output, caps: :any | ||
|
||
def_options end_of_stream: [spec: :on_last_pad | :never, default: :on_last_pad] | ||
|
||
@impl true | ||
def handle_init(opts) do | ||
{:ok, Map.from_struct(opts)} | ||
end | ||
|
||
@impl true | ||
def handle_demand(:output, _size, :buffers, ctx, state) do | ||
demands = ctx |> inputs_data() |> Enum.map(&{:demand, {&1.ref, 1}}) | ||
{{:ok, demands}, state} | ||
end | ||
|
||
@impl true | ||
def handle_process(Pad.ref(:input, _id), buffer, _ctx, state) do | ||
{{:ok, buffer: {:output, buffer}, redemand: :output}, state} | ||
end | ||
|
||
@impl true | ||
def handle_pad_added(Pad.ref(:input, _id) = pad, %{playback_state: :playing}, state) do | ||
{{:ok, [demand: {pad, 1}, event: {:output, %Funnel.NewInputEvent{}}]}, state} | ||
end | ||
|
||
@impl true | ||
def handle_pad_added(Pad.ref(:input, _id), _ctx, state) do | ||
{:ok, state} | ||
end | ||
|
||
@impl true | ||
def handle_end_of_stream(Pad.ref(:input, _id), _ctx, %{end_of_stream: :never} = state) do | ||
{:ok, state} | ||
end | ||
|
||
@impl true | ||
def handle_end_of_stream(Pad.ref(:input, _id), ctx, %{end_of_stream: :on_last_pad} = state) do | ||
if ctx |> inputs_data() |> Enum.all?(& &1.end_of_stream?) do | ||
{{:ok, end_of_stream: :output}, state} | ||
else | ||
{:ok, state} | ||
end | ||
end | ||
|
||
defp inputs_data(ctx) do | ||
Enum.flat_map(ctx.pads, fn | ||
{_ref, %{direction: :input} = data} -> [data] | ||
_output -> [] | ||
end) | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
defmodule Membrane.FunnelTest do | ||
use ExUnit.Case | ||
|
||
import Membrane.Testing.Assertions | ||
|
||
alias Membrane.{Buffer, Funnel, Testing} | ||
|
||
test "Collects multiple inputs" do | ||
import Membrane.ParentSpec | ||
data = 1..10 | ||
|
||
{:ok, pipeline} = | ||
%Testing.Pipeline.Options{ | ||
elements: [ | ||
src1: %Testing.Source{output: data}, | ||
src2: %Testing.Source{output: data}, | ||
funnel: Funnel, | ||
sink: Testing.Sink | ||
], | ||
links: [ | ||
link(:src1) |> to(:funnel), | ||
link(:src2) |> to(:funnel), | ||
link(:funnel) |> to(:sink) | ||
] | ||
} | ||
|> Testing.Pipeline.start_link() | ||
|
||
:ok = Testing.Pipeline.play(pipeline) | ||
|
||
data | ||
|> Enum.flat_map(&[&1, &1]) | ||
|> Enum.each(fn payload -> | ||
assert_sink_buffer(pipeline, :sink, %Buffer{payload: ^payload}) | ||
end) | ||
|
||
assert_end_of_stream(pipeline, :sink) | ||
refute_sink_buffer(pipeline, :sink, _buffer, 0) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
ExUnit.start() | ||
ExUnit.start(capture_log: true) |