1 <chapter id="cha-pads">
4 As we have seen in <xref linkend="cha-elements"/>, the pads are the element's
5 interface to the outside world.
8 The specific type of media that the element can handle will be exposed by the pads.
9 The description of this media type is done with capabilities(see
10 <xref linkend="sec-caps"/>)
14 Pads are either source or sink pads. The terminology is defined from the
15 view of the element itself: elements accept data on their sink pads, and
16 send data out on their source pads. Sink pads are drawn on the left,
17 while source pads are drawn on the right of an element. In general,
18 data flows from left to right in the graph.<footnote>
20 In reality, there is no objection to data flowing from a
21 source pad to the sink pad of an element upstream. Data will, however,
22 always flow from a source pad of one element to the sink pad of
27 <sect1 id="sec-pads-get">
28 <title>Getting pads from an element</title>
30 Once you have created an element, you can get one of its pads with:
35 srcpad = gst_element_get_pad (element, "src");
39 This function will get the pad named "src" from the given element.
42 Alternatively, you can request a GList of pads from the element. The
43 following code example will print the names of all the pads of an
49 pads = gst_element_get_pad_list (element);
51 GstPad *pad = GST_PAD (pads->data);
53 g_print ("pad name %s\n", gst_pad_get_name (pad));
55 pads = g_list_next (pads);
59 <sect2 id="sec-pads-functions">
60 <title>Useful pad functions</title>
62 You can get the name of a pad with gst_pad_get_name () and set its name with
66 gst_pad_get_direction (GstPad *pad) can be used to query if the pad
67 is a sink or a source pad. Remember that a source pad is a pad that
68 can output data and a sink pad is one that accepts data.
71 You can get the parent of the pad, this is the element that this pad belongs to,
72 with get_pad_get_parent(GstPad *pad). This function will return a pointer to a
78 <sect1 id="sec-pads-type">
79 <title>Types of pads</title>
81 <sect2 id="sec-pads-dynamic">
82 <title>Dynamic pads</title>
84 Some elements might not have all of their pads when the element is
86 can happen, for example, with an MPEG system demultiplexer. The
87 demultiplexer will create its pads at runtime when it detects the
88 different elementary streams in the MPEG system stream.
91 Running <application>gst-inspect mpegdemux</application> will show that
92 the element has only one pad: a sink pad called 'sink'. The other pads are
93 "dormant". You can see this in the pad template because there is
94 an 'Exists: Sometimes'
95 property. Depending on the type of MPEG file you play, the pads will
97 will see that this is very important when you are going to create dynamic
98 pipelines later on in this manual.
101 You can attach a signal to an element to inform you when the element has created
102 a new pad from one of its padtemplates. The following piece of code is an example
107 pad_link_func (GstElement *parser, GstPad *pad, GstElement *pipeline)
109 g_print("***** a new pad %s was created\n", gst_pad_get_name(pad));
111 gst_element_set_state (pipeline, GST_STATE_PAUSED);
113 if (strncmp (gst_pad_get_name (pad), "private_stream_1.0", 18) == 0) {
114 // set up an AC3 decoder pipeline
116 // link pad to the AC3 decoder pipeline
119 gst_element_set_state (GST_ELEMENT (audio_thread), GST_STATE_READY);
123 main(int argc, char *argv[])
125 GstElement *pipeline;
126 GstElement *mpeg2parser;
128 // create pipeline and do something useful
131 mpeg2parser = gst_element_factory_make ("mpegdemux", "mpegdemux");
132 g_signal_connect (G_OBJECT (mpeg2parser), "new_pad", pad_link_func, pipeline);
135 // start the pipeline
136 gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
142 A pipeline cannot be changed in the PLAYING state.
146 <sect2 id="sec-pads-request">
147 <title>Request pads</title>
149 An element can also have request pads. These pads are not created
150 automatically but are only created on demand. This is very useful
151 for multiplexers, aggregators and tee elements.
154 The tee element, for example, has one input pad and a request padtemplate for the
155 output pads. Whenever an element wants to get an output pad from the tee element, it
156 has to request the pad.
159 The following piece of code can be used to get a pad from the tee element. After
160 the pad has been requested, it can be used to link another element to it.
166 element = gst_element_factory_make ("tee", "element");
168 pad = gst_element_get_request_pad (element, "src%d");
169 g_print ("new pad %s\n", gst_pad_get_name (pad));
173 The gst_element_get_request_pad method can be used to get a pad
174 from the element based on the name_template of the padtemplate.
177 It is also possible to request a pad that is compatible with another
178 pad template. This is very useful if you want to link an element
179 to a multiplexer element and you need to request a pad that is
180 compatible. The gst_element_get_compatible_pad is used to request
181 a compatible pad, as is shown in the next example.
185 GstPadTemplate *templ;
188 element = gst_element_factory_make ("tee", "element");
189 mad = gst_element_factory_make ("mad", "mad");
191 templ = gst_element_get_pad_template_by_name (mad, "sink");
193 pad = gst_element_get_compatible_pad (element, templ);
194 g_print ("new pad %s\n", gst_pad_get_name (pad));
201 <sect1 id="sec-caps">
202 <title>Capabilities of a pad</title>
204 Since the pads play a very important role in how the element is viewed by the
205 outside world, a mechanism is implemented to describe the data that can
206 flow through the pad by using capabilities.
209 We will briefly describe what capabilities are, enough for you to get a basic understanding
210 of the concepts. You will find more information on how to create capabilities in the
211 Plugin Writer's Guide.
214 <sect2 id="sec-pads-caps">
215 <title>What are capabilities ?</title>
217 Capabilities are attached to a pad in order to describe
218 what type of media the pad can handle.
221 Capabilities is shorthand for "capability chain". A capability chain
222 is a chain of one capability or more.
225 The basic entity is a capability, and is defined by a name, a MIME
226 type and a set of properties. A capability can be chained to
227 another capability, which is why we commonly refer to a chain of
228 capability entities as "capabilities".<footnote>
230 It is important to understand that the term "capabilities" refers
231 to a chain of one capability or more. This will be clearer when
232 you see the structure definition of a <classname>GstCaps</classname>
241 gchar *name; /* the name of this caps */
242 guint16 id; /* type id (major type) */
244 guint refcount; /* caps are refcounted */
246 GstProps *properties; /* properties for this capability */
248 GstCaps *next; /* caps can be chained together */
252 Below is a dump of the capabilities of the element mad, as shown by
253 <command>gst-inspect</command>.
254 You can see two pads: sink and src. Both pads have capability information attached to them.
257 The sink pad (input pad) is called 'sink' and takes data of MIME type 'audio/mp3'. It also has
258 three properties: layer, bitrate and framed.
261 The source pad (output pad) is called 'src' and outputs data of
262 MIME type 'audio/raw'. It also has four properties: format, depth,
267 SINK template: 'sink'
271 MIME type: 'audio/mp3':
277 MIME type: 'audio/raw':
279 endianness: Integer: 1234
282 channels: Integer range: 1 - 2
284 signed: Boolean: TRUE
285 rate: Integer range: 11025 - 48000
288 <sect2 id="sec-pads-props">
289 <title>What are properties ?</title>
291 Properties are used to describe extra information for
292 capabilities. A property consists of a key (a string) and
293 a value. There are different possible value types that can be used:
304 an integer value: the property has this exact value.
309 a boolean value: the property is either TRUE or FALSE.
314 a fourcc value: this is a value that is commonly used to
315 describe an encoding for video,
316 as used for example by the AVI specification.
318 fourcc values consist of four bytes.
319 <ulink url="http://www.fourcc.org" type="http">The FOURCC
320 Definition List</ulink> is the most complete resource
321 on the allowed fourcc values.
327 a float value: the property has this exact floating point value.
345 an integer range value: the property denotes a range of
346 possible integer. For example, the wavparse element has
347 a source pad where the "rate" property can go from 8000 to
353 a float range value: the property denotes a range of possible
354 floating point values.
361 a list value: the property can take any value from a list of
362 basic value types or range types.
368 <sect2 id="sec-pads-caps-use">
369 <title>What capabilities are used for</title>
371 Capabilities describe in great detail the type of media that is handled by the pads.
372 They are mostly used for:
377 Autoplugging: automatically finding plugins for a set of capabilities
382 Compatibility detection: when two pads are linked, <application>GStreamer</application>
383 can verify if the two pads are talking about the same media types.
384 The process of linking two pads and checking if they are compatible
385 is called "caps negotiation".
390 <sect2 id="sec-pads-caps-get">
391 <title>Getting the capabilities of a pad</title>
393 A pad can have a chain of capabilities attached to it. You can get the capabilities chain
399 caps = gst_pad_get_caps (pad);
401 g_print ("pad name %s\n", gst_pad_get_name (pad));
404 g_print (" Capability name %s, MIME type %s\n",
405 gst_caps_get_name (cap),
406 gst_caps_get_mime (cap));
408 caps = caps->next;
413 <sect2 id="sec-pads-caps-create">
414 <title>Creating capability structures</title>
416 While capabilities are mainly used inside a plugin to describe the
417 media type of the pads, the application programmer also has to have
418 basic understanding of capabilities in order to interface with the
419 plugins, specially when using the autopluggers.
422 As we said, a capability has a name, a mime-type and some
423 properties. The signature of the function to create a new
424 <classname>GstCaps</classname> structure is:
427 GstCaps* gst_caps_new (const gchar *name, const gchar *mime, GstProps *props);
431 You can therefore create a new capability with no properties like this:
435 newcaps = gst_caps_new ("my_caps", "audio/wav", NULL);
439 <classname>GstProps</classname> basically consist of a set of key-value pairs
440 and are created with a function with this signature:
442 GstProps* gst_props_new (const gchar *firstname, ...);
446 The keys are given as strings and the values are given with a set of macros:
450 GST_PROPS_INT(a): An integer value
455 GST_PROPS_FLOAT(a): A floating point value
460 GST_PROPS_FOURCC(a): A fourcc value
465 GST_PROPS_BOOLEAN(a): A boolean value
470 GST_PROPS_STRING(a): A string value
474 The values can also be specified as ranges with:
478 GST_PROPS_INT_RANGE(a,b): An integer range from a to b
483 GST_PROPS_FLOAT_RANGE(a,b): A float ragne from a to b
487 All of the above values can be given with a list too, using:
491 GST_PROPS_LIST(a,...): A list of property values.
497 A more complex capability with properties is created like this:
501 newcaps = gst_caps_new ("my_caps",
504 "bitrate", GST_PROPS_INT_RANGE (11025,22050),
505 "depth", GST_PROPS_INT (16),
506 "signed", GST_PROPS_LIST (
507 GST_PROPS_BOOLEAN (TRUE),
508 GST_PROPS_BOOLEAN (FALSE)
513 Optionally, the convenient shortcut macro can be used. The above complex
514 capability can be created with:
518 newcaps = GST_CAPS_NEW ("my_caps",
520 "bitrate", GST_PROPS_INT_RANGE (11025,22050),
521 "depth", GST_PROPS_INT (16),
522 "signed", GST_PROPS_LIST (
523 GST_PROPS_BOOLEAN (TRUE),
524 GST_PROPS_BOOLEAN (FALSE)