4 The scheduling in GStreamer is based on pads actively pushing (producing) data or
5 pad pulling in data (consuming) from other pads.
10 A pad can produce data and push it to the next pad. A pad that behaves this way
11 exposes a loop function that will be called repeatedly until it returns false.
12 The loop function is allowed to block whenever it wants. When the pad is deactivated
13 the loop function should unblock though.
15 A pad operating in the push mode can only produce data to a pad that exposes a
16 chain function. This chain function will be called with the buffer produced by
19 This method of producing data is called the streaming mode since the producer
20 produces a constant stream of data.
25 Pads that operate in pulling mode can only pull data from a pad that exposes the
26 pull_range function. In this case, the sink pad exposes a loop function that will be
27 called repeatedly until the task is stopped.
29 After pulling data from the peer pad, the loop function will typically call the
30 push function to push the result to the peer sinkpad.
33 Deciding the scheduling mode
34 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
36 When a pad is activated, the _activate() function is called. The pad can then
37 choose to activate itself in push or pull mode depending on upstream
40 The GStreamer core will by default activate pads in push mode when there is no
41 activate function for the pad.
46 The chain function will be called when a upstream element performs a _push() on the pad.
47 The upstream element can be another chain based element or a pushing source.
52 The getrange function is called when a peer pad performs a _pull_range() on the pad. This
53 downstream pad can be a pulling element or another _pull_range() based element.
59 A sinkpad can ask the upstream srcpad for its scheduling attributes. It does
60 this with the SCHEDULING query.
63 (out) "modes", G_TYPE_ARRAY (default NULL)
64 - an array of GST_TYPE_PAD_MODE enums. Contains all the supported
67 (out) "flags", GST_TYPE_SCHEDULING_FLAGS (default 0)
70 GST_SCHEDULING_FLAG_SEEKABLE = (1 << 0),
71 GST_SCHEDULING_FLAG_SEQUENTIAL = (1 << 1)
75 - the offset of a pull operation can be specified, if this flag is false,
76 the offset should be -1,
79 - suggest sequential access to the data. If _SEEKABLE is specified,
80 seeks are allowed but should be avoided. This is common for network
83 (out) "minsize", G_TYPE_INT (default 1)
84 - the suggested minimum size of pull requests
86 (out) "maxsize", G_TYPE_INT (default -1, unlimited)
87 - the suggested maximum size of pull requests
89 (out) "align", G_TYPE_INT (default 0)
90 - the suggested alignment for the pull requests.
100 Elements with multiple sinks can either expose a loop function on each of the pads to
101 actively pull_range data or they can expose a chain function on each pad.
103 Implementing a chain function is usually easy and allows for all possible scheduling
109 If the chain based sink wants to wait for one of the pads to receive a buffer, just
110 implement the action to perform in the chain function. Be aware that the action could
111 be performed in different threads and possibly simultaneously so grab the STREAM_LOCK.
116 If the chain based sink pads all require one buffer before the element can operate on
117 the data, collect all the buffers in the chain function and perform the action when
118 all chainpads received the buffer.
120 In this case you probably also don't want to accept more data on a pad that has a buffer
121 queued. This can easily be done with the following code snippet:
123 static GstFlowReturn _chain (GstPad *pad, GstBuffer *buffer)
126 while (pad->store != NULL) {
127 WAIT (mycond, mylock);
136 static void _pull (GstPad *pad, GstBuffer **buffer)
139 while (pad->store == NULL) {
140 WAIT (mycond, mylock);
142 **buffer = pad->store;
152 Inside the braces below the pads is stated what function the
155 l: exposes a loop function, so it can act as a pushing source.
156 g: exposes a getrange function
157 c: exposes a chain function
159 following scheduling decisions are made based on the scheduling
160 methods exposed by the pads:
162 (g) - (l): sinkpad will pull data from src
163 (l) - (c): srcpad actively pushes data to sinkpad
164 () - (c): srcpad will push data to sinkpad.
166 () - () : not schedulable.
167 () - (l): not schedulable.
168 (g) - () : not schedulable.
169 (g) - (c): not schedulable.
170 (l) - () : not schedulable.
171 (l) - (l): not schedulable
174 (g) - (g): impossible.
175 (l) - (g): impossible
176 (c) - () : impossible
177 (c) - (g): impossible
178 (c) - (l): impossible
179 (c) - (c): impossible
181 +---------+ +------------+ +-----------+
182 | filesrc | | mp3decoder | | audiosink |
183 | src--sink src--sink |
184 +---------+ +------------+ +-----------+
187 When activating the pads:
189 * audiosink has a chain function and the peer pad has no
190 loop function, no scheduling is done.
191 * mp3decoder and filesrc expose an (l) - (c) connection,
192 a thread is created to call the srcpad loop function.
194 +---------+ +------------+ +----------+
195 | filesrc | | avidemuxer | | fakesink |
196 | src--sink src--sink |
197 +---------+ +------------+ +----------+
200 * fakesink has a chain function and the peer pad has no
201 loop function, no scheduling is done.
202 * avidemuxer and filesrc expose an (g) - (l) connection,
203 a thread is created to call the sinkpad loop function.
205 +---------+ +----------+ +------------+ +----------+
206 | filesrc | | identity | | avidemuxer | | fakesink |
207 | src--sink src--sink src--sink |
208 +---------+ +----------+ +------------+ +----------+
209 (l-g) (c) () (l) () (c)
211 * fakesink has a chain function and the peer pad has no
212 loop function, no scheduling is done.
213 * avidemuxer and identity expose no schedulable connection so
214 this pipeline is not schedulable.
216 +---------+ +----------+ +------------+ +----------+
217 | filesrc | | identity | | avidemuxer | | fakesink |
218 | src--sink src--sink src--sink |
219 +---------+ +----------+ +------------+ +----------+
220 (l-g) (c-l) (g) (l) () (c)
222 * fakesink has a chain function and the peer pad has no
223 loop function, no scheduling is done.
224 * avidemuxer and identity expose an (g) - (l) connection,
225 a thread is created to call the sinkpad loop function.
226 * identity knows the srcpad is getrange based and uses the
227 thread from avidemux to getrange data from filesrc.
229 +---------+ +----------+ +------------+ +----------+
230 | filesrc | | identity | | oggdemuxer | | fakesink |
231 | src--sink src--sink src--sink |
232 +---------+ +----------+ +------------+ +----------+
233 (l-g) (c) () (l-c) () (c)
235 * fakesink has a chain function and the peer pad has no
236 loop function, no scheduling is done.
237 * oggdemuxer and identity expose an () - (l-c) connection,
238 oggdemux has to operate in chain mode.
239 * identity chan only work chain based and so filesrc creates
240 a thread to push data to identity.