You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: basic_pipeline/03_Source.md
+22-22Lines changed: 22 additions & 22 deletions
Original file line number
Diff line number
Diff line change
@@ -12,13 +12,13 @@ As you can see, we are returning an optional list of [actions](https://hexdocs.p
12
12
the updated state (which later on will be passed to the next invoked callback).
13
13
Take your time and read about the possible actions which can be requested to be performed while returning from the callback. Their usage is crucial for the pipeline to work.
14
14
15
-
As you can judge based on the structure of the project, all the elements will be put in the `lib/elements` directory. Therefore there is a place where `Source.ex` with the `Basic.Elements.Source` module's definition should be placed.
15
+
As you can judge based on the structure of the project, all the elements will be put in the `lib/elements` directory. Therefore there is a place where `source.ex` with the `Basic.Elements.Source` module's definition should be placed.
16
16
17
17
## What makes our module a Membrane Framework's element?
18
18
19
19
Let's start with specifying that our module will implement the `Membrane.Source` behavior as well as alias the modules which will be used later in the module's code:
20
20
21
-
**_`lib/elements/Source.ex`_**
21
+
**_`lib/elements/source.ex`_**
22
22
23
23
```elixir
24
24
defmoduleBasic.Elements.Sourcedo
@@ -33,7 +33,7 @@ end
33
33
34
34
Later on, we will make use of [macros](https://elixir-lang.org/getting-started/meta/macros.html) defined in the `Membrane.Source` module:
35
35
36
-
**_`lib/elements/Source.ex`_**
36
+
**_`lib/elements/source.ex`_**
37
37
38
38
```elixir
39
39
defmoduleBasic.Elements.Sourcedo
@@ -67,7 +67,7 @@ You can read more on pad specification [here](https://hexdocs.pm/membrane_core/M
67
67
68
68
Let's define our first callback! Why not start with [`handle_init/2`](https://hexdocs.pm/membrane_core/Membrane.Element.Base.html#c:handle_init/2), which gets called once the element is created?
69
69
70
-
**_`lib/elements/Source.ex`_**
70
+
**_`lib/elements/source.ex`_**
71
71
72
72
```elixir
73
73
defmoduleBasic.Elements.Sourcedo
@@ -97,7 +97,7 @@ All we need to do there is to initialize the state - our state will be in a form
97
97
When an element requires more time to initialise, you should delegate complex tasks to `handle_setup/2`. This callback runs after `handle_init/2` if it returns the `setup: :incomplete` action.
98
98
In our example, we'd like to open, read and save the contents of the input file. We then save it in our state as `content`.
99
99
100
-
**_`lib/elements/Source.ex`_**
100
+
**_`lib/elements/source.ex`_**
101
101
102
102
```elixir
103
103
defmoduleBasic.Elements.Sourcedo
@@ -117,7 +117,7 @@ end
117
117
118
118
When the setup is complete, the element goes into `playing` state. It can then demand buffers from previous elements and send its `:stream_format` to receiving elements. Since we are implementing a sink we do not have anything to demand from, but we can specify the format. We can do this, for example, in `handle_playing/2`:
119
119
120
-
**_`lib/elements/Source.ex`_**
120
+
**_`lib/elements/source.ex`_**
121
121
122
122
```elixir
123
123
defmoduleBasic.Elements.Sourcedo
@@ -137,28 +137,28 @@ The `:stream_format` action means that we want to transmit the information about
137
137
Before going any further let's stop for a moment and talk about the demands. Do you remember, that the `:output` pad is working in `:manual` mode? That means that the succeeding element has to ask the Source element for the data to be sent and our element has to take care of keeping that data in some kind of buffer until it is requested.
138
138
Once the succeeding element requests for the data, the `handle_demand/4` callback will be invoked - therefore it would be good for us to define it:
139
139
140
-
**_`lib/elements/Source.ex`_**
140
+
**_`lib/elements/source.ex`_**
141
141
142
142
```elixir
143
143
defmoduleBasic.Elements.Sourcedo
144
144
...
145
145
146
-
@impltrue
147
-
defhandle_demand(:output, _size, :buffers, _ctx, state) do
0 commit comments