Skip to content

Commit 3f71657

Browse files
author
kidp330
committed
Further fixes to 03-04
1 parent 9c01303 commit 3f71657

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

basic_pipeline/03_Source.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ As you can see, we are returning an optional list of [actions](https://hexdocs.p
1212
the updated state (which later on will be passed to the next invoked callback).
1313
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.
1414

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.
1616

1717
## What makes our module a Membrane Framework's element?
1818

1919
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:
2020

21-
**_`lib/elements/Source.ex`_**
21+
**_`lib/elements/source.ex`_**
2222

2323
```elixir
2424
defmodule Basic.Elements.Source do
@@ -33,7 +33,7 @@ end
3333

3434
Later on, we will make use of [macros](https://elixir-lang.org/getting-started/meta/macros.html) defined in the `Membrane.Source` module:
3535

36-
**_`lib/elements/Source.ex`_**
36+
**_`lib/elements/source.ex`_**
3737

3838
```elixir
3939
defmodule Basic.Elements.Source do
@@ -67,7 +67,7 @@ You can read more on pad specification [here](https://hexdocs.pm/membrane_core/M
6767

6868
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?
6969

70-
**_`lib/elements/Source.ex`_**
70+
**_`lib/elements/source.ex`_**
7171

7272
```elixir
7373
defmodule Basic.Elements.Source do
@@ -97,7 +97,7 @@ All we need to do there is to initialize the state - our state will be in a form
9797
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.
9898
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`.
9999

100-
**_`lib/elements/Source.ex`_**
100+
**_`lib/elements/source.ex`_**
101101

102102
```elixir
103103
defmodule Basic.Elements.Source do
@@ -117,7 +117,7 @@ end
117117

118118
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`:
119119

120-
**_`lib/elements/Source.ex`_**
120+
**_`lib/elements/source.ex`_**
121121

122122
```elixir
123123
defmodule Basic.Elements.Source do
@@ -137,28 +137,28 @@ The `:stream_format` action means that we want to transmit the information about
137137
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.
138138
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:
139139

140-
**_`lib/elements/Source.ex`_**
140+
**_`lib/elements/source.ex`_**
141141

142142
```elixir
143143
defmodule Basic.Elements.Source do
144144
...
145145

146-
@impl true
147-
def handle_demand(:output, _size, :buffers, _ctx, state) do
148-
if state.content == [] do
149-
{ [end_of_stream: :output], state}
150-
else
151-
[first_packet | rest] = state.content
152-
new_state = %{state | content: rest}
153-
154-
actions = [
155-
buffer: {:output, %Buffer{payload: first_packet}},
156-
redemand: :output
157-
]
158-
159-
{actions, new_state}
146+
@impl true
147+
def handle_demand(:output, _size, :buffers, _context, state) do
148+
if state.content == [] do
149+
{[end_of_stream: :output], state}
150+
else
151+
[first_packet | rest] = state.content
152+
new_state = %{state | content: rest}
153+
154+
actions = [
155+
buffer: {:output, %Buffer{payload: first_packet}},
156+
redemand: :output
157+
]
158+
159+
{actions, new_state}
160+
end
160161
end
161-
end
162162
...
163163
end
164164
```

basic_pipeline/04_StreamFormat.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ defmodule Source do
9393
]
9494
)
9595
...
96-
def handle_playing(_ctx, state) do
96+
def handle_playing(_context, state) do
9797
...
9898
{ {[stream_format: {:output, %Formats.Raw{pixel_format: I420, framerate: 45, width: 720, height: 300} }]}, state}
9999
end

0 commit comments

Comments
 (0)