b22bfad23d9ca63d02e9adb02b9efb4425e2756a
[platform/upstream/gstreamer.git] / gst / gstpad.h
1 /* GStreamer
2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3  *                    2000 Wim Taymans <wim.taymans@chello.be>
4  *
5  * gstpad.h: Header for GstPad object
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23
24 #ifndef __GST_PAD_H__
25 #define __GST_PAD_H__
26
27 #include <gst/gstconfig.h>
28
29 typedef struct _GstPad GstPad;
30 typedef struct _GstPadPrivate GstPadPrivate;
31 typedef struct _GstPadClass GstPadClass;
32
33 /**
34  * GstPadDirection:
35  * @GST_PAD_UNKNOWN: direction is unknown.
36  * @GST_PAD_SRC: the pad is a source pad.
37  * @GST_PAD_SINK: the pad is a sink pad.
38  *
39  * The direction of a pad.
40  */
41 typedef enum {
42   GST_PAD_UNKNOWN,
43   GST_PAD_SRC,
44   GST_PAD_SINK
45 } GstPadDirection;
46
47 #include <gst/gstobject.h>
48 #include <gst/gstbuffer.h>
49 #include <gst/gstbufferlist.h>
50 #include <gst/gstcaps.h>
51 #include <gst/gstpadtemplate.h>
52 #include <gst/gstevent.h>
53 #include <gst/gstquery.h>
54 #include <gst/gsttask.h>
55
56 G_BEGIN_DECLS
57
58 /*
59  * Pad base class
60  */
61 #define GST_TYPE_PAD                    (gst_pad_get_type ())
62 #define GST_IS_PAD(obj)                 (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_PAD))
63 #define GST_IS_PAD_CLASS(klass)         (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_PAD))
64 #define GST_PAD(obj)                    (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_PAD, GstPad))
65 #define GST_PAD_CLASS(klass)            (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_PAD, GstPadClass))
66 #define GST_PAD_CAST(obj)               ((GstPad*)(obj))
67
68
69
70 /**
71  * GstPadLinkReturn:
72  * @GST_PAD_LINK_OK             : link succeeded
73  * @GST_PAD_LINK_WRONG_HIERARCHY: pads have no common grandparent
74  * @GST_PAD_LINK_WAS_LINKED     : pad was already linked
75  * @GST_PAD_LINK_WRONG_DIRECTION: pads have wrong direction
76  * @GST_PAD_LINK_NOFORMAT       : pads do not have common format
77  * @GST_PAD_LINK_NOSCHED        : pads cannot cooperate in scheduling
78  * @GST_PAD_LINK_REFUSED        : refused for some reason
79  *
80  * Result values from gst_pad_link and friends.
81  */
82 typedef enum {
83   GST_PAD_LINK_OK               =  0,
84   GST_PAD_LINK_WRONG_HIERARCHY  = -1,
85   GST_PAD_LINK_WAS_LINKED       = -2,
86   GST_PAD_LINK_WRONG_DIRECTION  = -3,
87   GST_PAD_LINK_NOFORMAT         = -4,
88   GST_PAD_LINK_NOSCHED          = -5,
89   GST_PAD_LINK_REFUSED          = -6
90 } GstPadLinkReturn;
91
92 /**
93  * GST_PAD_LINK_FAILED:
94  * @ret: the #GstPadLinkReturn value
95  *
96  * Macro to test if the given #GstPadLinkReturn value indicates a failed
97  * link step.
98  */
99 #define GST_PAD_LINK_FAILED(ret) ((ret) < GST_PAD_LINK_OK)
100
101 /**
102  * GST_PAD_LINK_SUCCESSFUL:
103  * @ret: the #GstPadLinkReturn value
104  *
105  * Macro to test if the given #GstPadLinkReturn value indicates a successful
106  * link step.
107  */
108 #define GST_PAD_LINK_SUCCESSFUL(ret) ((ret) >= GST_PAD_LINK_OK)
109
110 /**
111  * GstFlowReturn:
112  * @GST_FLOW_RESEND:             Resend buffer, possibly with new caps (not
113  *                                 sent yet) (unused/unimplemented).
114  * @GST_FLOW_OK:                 Data passing was ok.
115  * @GST_FLOW_NOT_LINKED:         Pad is not linked.
116  * @GST_FLOW_WRONG_STATE:        Pad is in wrong state.
117  * @GST_FLOW_UNEXPECTED:         Did not expect anything, like after EOS.
118  * @GST_FLOW_NOT_NEGOTIATED:     Pad is not negotiated.
119  * @GST_FLOW_ERROR:              Some (fatal) error occured. Element generating
120  *                               this error should post an error message with more
121  *                               details.
122  * @GST_FLOW_NOT_SUPPORTED:      This operation is not supported.
123  * @GST_FLOW_CUSTOM_SUCCESS:     Elements can use values starting from
124  *                               this (and higher) to define custom success
125  *                               codes. Since 0.10.7.
126  * @GST_FLOW_CUSTOM_SUCCESS_1:   Pre-defined custom success code (define your
127  *                               custom success code to this to avoid compiler
128  *                               warnings). Since 0.10.29.
129  * @GST_FLOW_CUSTOM_SUCCESS_2:   Pre-defined custom success code. Since 0.10.29.
130  * @GST_FLOW_CUSTOM_ERROR:       Elements can use values starting from
131  *                               this (and lower) to define custom error codes.
132  *                               Since 0.10.7.
133  * @GST_FLOW_CUSTOM_ERROR_1:     Pre-defined custom error code (define your
134  *                               custom error code to this to avoid compiler
135  *                               warnings). Since 0.10.29.
136  * @GST_FLOW_CUSTOM_ERROR_2:     Pre-defined custom error code. Since 0.10.29.
137  *
138  * The result of passing data to a pad.
139  *
140  * Note that the custom return values should not be exposed outside of the
141  * element scope and are available since 0.10.7.
142  */
143 /* FIXME 0.11: remove custom flow returns */
144 typedef enum {
145   /* custom success starts here */
146   GST_FLOW_CUSTOM_SUCCESS_2 = 102,
147   GST_FLOW_CUSTOM_SUCCESS_1 = 101,
148   GST_FLOW_CUSTOM_SUCCESS = 100,
149
150   /* core predefined */
151   GST_FLOW_RESEND         =  1,
152   GST_FLOW_OK             =  0,
153   /* expected failures */
154   GST_FLOW_NOT_LINKED     = -1,
155   GST_FLOW_WRONG_STATE    = -2,
156   /* error cases */
157   GST_FLOW_UNEXPECTED     = -3,
158   GST_FLOW_NOT_NEGOTIATED = -4,
159   GST_FLOW_ERROR          = -5,
160   GST_FLOW_NOT_SUPPORTED  = -6,
161
162   /* custom error starts here */
163   GST_FLOW_CUSTOM_ERROR   = -100,
164   GST_FLOW_CUSTOM_ERROR_1 = -101,
165   GST_FLOW_CUSTOM_ERROR_2 = -102
166 } GstFlowReturn;
167
168 const gchar*            gst_flow_get_name       (GstFlowReturn ret);
169 GQuark                  gst_flow_to_quark       (GstFlowReturn ret);
170
171 /**
172  * GstPadLinkCheck:
173  * @GST_PAD_LINK_CHECK_NOTHING: Don't check hierarchy or caps compatibility.
174  * @GST_PAD_LINK_CHECK_HIERARCHY: Check the pads have same parents/grandparents.
175  *   Could be omitted if it is already known that the two elements that own the
176  *   pads are in the same bin.
177  * @GST_PAD_LINK_CHECK_TEMPLATE_CAPS: Check if the pads are compatible by using
178  *   their template caps. This is much faster than @GST_PAD_LINK_CHECK_CAPS, but
179  *   would be unsafe e.g. if one pad has %GST_CAPS_ANY.
180  * @GST_PAD_LINK_CHECK_CAPS: Check if the pads are compatible by comparing the
181  *   caps returned by gst_pad_get_caps().
182  *
183  * The amount of checking to be done when linking pads. @GST_PAD_LINK_CHECK_CAPS
184  * and @GST_PAD_LINK_CHECK_TEMPLATE_CAPS are mutually exclusive. If both are
185  * specified, expensive but safe @GST_PAD_LINK_CHECK_CAPS are performed.
186  *
187  * <warning><para>
188  * Only disable some of the checks if you are 100% certain you know the link
189  * will not fail because of hierarchy/caps compatibility failures. If uncertain,
190  * use the default checks (%GST_PAD_LINK_CHECK_DEFAULT) or the regular methods
191  * for linking the pads.
192  * </para></warning>
193  *
194  * Since: 0.10.30
195  */
196
197 typedef enum {
198   GST_PAD_LINK_CHECK_NOTHING       = 0,
199   GST_PAD_LINK_CHECK_HIERARCHY     = 1 << 0,
200   GST_PAD_LINK_CHECK_TEMPLATE_CAPS = 1 << 1,
201   GST_PAD_LINK_CHECK_CAPS          = 1 << 2
202 } GstPadLinkCheck;
203
204 /**
205  * GST_PAD_LINK_CHECK_DEFAULT:
206  *
207  * The default checks done when linking pads (i.e. the ones used by
208  * gst_pad_link()).
209  *
210  * Since: 0.10.30
211  */
212 #define GST_PAD_LINK_CHECK_DEFAULT (GST_PAD_LINK_CHECK_HIERARCHY | GST_PAD_LINK_CHECK_CAPS)
213
214 /**
215  * GstActivateMode:
216  * @GST_ACTIVATE_NONE:           Pad will not handle dataflow
217  * @GST_ACTIVATE_PUSH:           Pad handles dataflow in downstream push mode
218  * @GST_ACTIVATE_PULL:           Pad handles dataflow in upstream pull mode
219  *
220  * The status of a GstPad. After activating a pad, which usually happens when the
221  * parent element goes from READY to PAUSED, the GstActivateMode defines if the
222  * pad operates in push or pull mode.
223  */
224 typedef enum {
225   GST_ACTIVATE_NONE,
226   GST_ACTIVATE_PUSH,
227   GST_ACTIVATE_PULL
228 } GstActivateMode;
229
230 /**
231  * GST_PAD_MODE_ACTIVATE:
232  * @mode: a #GstActivateMode
233  *
234  * Macro to test if the given #GstActivateMode value indicates that datapassing
235  * is possible or not.
236  */
237 #define GST_PAD_MODE_ACTIVATE(mode) ((mode) != GST_ACTIVATE_NONE)
238
239 /* pad states */
240 /**
241  * GstPadActivateFunction:
242  * @pad: a #GstPad
243  *
244  * This function is called when the pad is activated during the element
245  * READY to PAUSED state change. By default this function will call the
246  * activate function that puts the pad in push mode but elements can
247  * override this function to activate the pad in pull mode if they wish.
248  *
249  * Returns: TRUE if the pad could be activated.
250  */
251 typedef gboolean                (*GstPadActivateFunction)       (GstPad *pad);
252 /**
253  * GstPadActivateModeFunction:
254  * @pad: a #GstPad
255  * @active: activate or deactivate the pad.
256  *
257  * The prototype of the push and pull activate functions.
258  *
259  * Returns: TRUE if the pad could be activated or deactivated.
260  */
261 typedef gboolean                (*GstPadActivateModeFunction)   (GstPad *pad, gboolean active);
262
263
264 /* data passing */
265 /**
266  * GstPadChainFunction:
267  * @pad: the sink #GstPad that performed the chain.
268  * @buffer: the #GstBuffer that is chained, not %NULL.
269  *
270  * A function that will be called on sinkpads when chaining buffers.
271  * The function typically processes the data contained in the buffer and
272  * either consumes the data or passes it on to the internally linked pad(s).
273  *
274  * The implementer of this function receives a refcount to @buffer and should
275  * gst_buffer_unref() when the buffer is no longer needed.
276  *
277  * When a chain function detects an error in the data stream, it must post an
278  * error on the bus and return an appropriate #GstFlowReturn value.
279  *
280  * Returns: #GST_FLOW_OK for success
281  */
282 typedef GstFlowReturn           (*GstPadChainFunction)          (GstPad *pad, GstBuffer *buffer);
283
284 /**
285  * GstPadChainListFunction:
286  * @pad: the sink #GstPad that performed the chain.
287  * @list: the #GstBufferList that is chained, not %NULL.
288  *
289  * A function that will be called on sinkpads when chaining buffer lists.
290  * The function typically processes the data contained in the buffer list and
291  * either consumes the data or passes it on to the internally linked pad(s).
292  *
293  * The implementer of this function receives a refcount to @list and
294  * should gst_buffer_list_unref() when the list is no longer needed.
295  *
296  * When a chainlist function detects an error in the data stream, it must
297  * post an error on the bus and return an appropriate #GstFlowReturn value.
298  *
299  * Returns: #GST_FLOW_OK for success
300  */
301 typedef GstFlowReturn           (*GstPadChainListFunction)      (GstPad *pad, GstBufferList *list);
302
303 /**
304  * GstPadGetRangeFunction:
305  * @pad: the src #GstPad to perform the getrange on.
306  * @offset: the offset of the range
307  * @length: the length of the range
308  * @buffer: a memory location to hold the result buffer, cannot be NULL.
309  *
310  * This function will be called on source pads when a peer element
311  * request a buffer at the specified @offset and @length. If this function
312  * returns #GST_FLOW_OK, the result buffer will be stored in @buffer. The
313  * contents of @buffer is invalid for any other return value.
314  *
315  * This function is installed on a source pad with
316  * gst_pad_set_getrange_function() and can only be called on source pads after
317  * they are successfully activated with gst_pad_activate_pull().
318  *
319  * @offset and @length are always given in byte units. @offset must normally be a value
320  * between 0 and the length in bytes of the data available on @pad. The
321  * length (duration in bytes) can be retrieved with a #GST_QUERY_DURATION or with a
322  * #GST_QUERY_SEEKING.
323  *
324  * Any @offset larger or equal than the length will make the function return
325  * #GST_FLOW_UNEXPECTED, which corresponds to EOS. In this case @buffer does not
326  * contain a valid buffer.
327  *
328  * The buffer size of @buffer will only be smaller than @length when @offset is
329  * near the end of the stream. In all other cases, the size of @buffer must be
330  * exactly the requested size.
331  *
332  * It is allowed to call this function with a 0 @length and valid @offset, in
333  * which case @buffer will contain a 0-sized buffer and the function returns
334  * #GST_FLOW_OK.
335  *
336  * When this function is called with a -1 @offset, the sequentially next buffer
337  * of length @length in the stream is returned.
338  *
339  * When this function is called with a -1 @length, a buffer with a default
340  * optimal length is returned in @buffer. The length might depend on the value
341  * of @offset.
342  *
343  * Returns: #GST_FLOW_OK for success and a valid buffer in @buffer. Any other
344  * return value leaves @buffer undefined.
345  */
346 typedef GstFlowReturn           (*GstPadGetRangeFunction)       (GstPad *pad, guint64 offset,
347                                                                  guint length, GstBuffer **buffer);
348
349 /**
350  * GstPadEventFunction:
351  * @pad: the #GstPad to handle the event.
352  * @event: the #GstEvent to handle.
353  *
354  * Function signature to handle an event for the pad.
355  *
356  * Returns: TRUE if the pad could handle the event.
357  */
358 typedef gboolean                (*GstPadEventFunction)          (GstPad *pad, GstEvent *event);
359
360
361 /* internal links */
362 /**
363  * GstPadIterIntLinkFunction:
364  * @pad: The #GstPad to query.
365  *
366  * The signature of the internal pad link iterator function.
367  *
368  * Returns: a new #GstIterator that will iterate over all pads that are
369  * linked to the given pad on the inside of the parent element.
370  *
371  * the caller must call gst_iterator_free() after usage.
372  *
373  * Since 0.10.21
374  */
375 typedef GstIterator*           (*GstPadIterIntLinkFunction)    (GstPad *pad);
376
377 /* generic query function */
378 /**
379  * GstPadQueryTypeFunction:
380  * @pad: a #GstPad to query
381  *
382  * The signature of the query types function.
383  *
384  * Returns: a constant array of query types
385  */
386 typedef const GstQueryType*     (*GstPadQueryTypeFunction)      (GstPad *pad);
387
388 /**
389  * GstPadQueryFunction:
390  * @pad: the #GstPad to query.
391  * @query: the #GstQuery object to execute
392  *
393  * The signature of the query function.
394  *
395  * Returns: TRUE if the query could be performed.
396  */
397 typedef gboolean                (*GstPadQueryFunction)          (GstPad *pad, GstQuery *query);
398
399
400 /* linking */
401 /**
402  * GstPadLinkFunction
403  * @pad: the #GstPad that is linked.
404  * @peer: the peer #GstPad of the link
405  *
406  * Function signature to handle a new link on the pad.
407  *
408  * Returns: the result of the link with the specified peer.
409  */
410 typedef GstPadLinkReturn        (*GstPadLinkFunction)           (GstPad *pad, GstPad *peer);
411 /**
412  * GstPadUnlinkFunction
413  * @pad: the #GstPad that is linked.
414  *
415  * Function signature to handle a unlinking the pad prom its peer.
416  */
417 typedef void                    (*GstPadUnlinkFunction)         (GstPad *pad);
418
419
420 /* caps nego */
421 /**
422  * GstPadGetCapsFunction:
423  * @pad: the #GstPad to get the capabilities of.
424  * @filter: filter #GstCaps.
425  *
426  * When called on sinkpads @filter contains the caps that
427  * upstream could produce in the order preferred by upstream. When
428  * called on srcpads @filter contains the caps accepted by
429  * downstream in the preffered order. @filter might be %NULL but if
430  * it is not %NULL only a subset of @filter must be returned.
431  *
432  * Returns a copy of the capabilities of the specified pad. By default this
433  * function will return the pad template capabilities, but can optionally
434  * be overridden by elements.
435  *
436  * Returns: a newly allocated copy #GstCaps of the pad.
437  */
438 typedef GstCaps*                (*GstPadGetCapsFunction)        (GstPad *pad, GstCaps *filter);
439
440 /**
441  * GstPadAcceptCapsFunction:
442  * @pad: the #GstPad to check
443  * @caps: the #GstCaps to check
444  *
445  * Check if @pad can accept @caps. By default this function will see if @caps
446  * intersect with the result from gst_pad_get_caps() by can be overridden to
447  * perform extra checks.
448  *
449  * Returns: TRUE if the caps can be accepted by the pad.
450  */
451 typedef gboolean                (*GstPadAcceptCapsFunction)     (GstPad *pad, GstCaps *caps);
452 /**
453  * GstPadFixateCapsFunction:
454  * @pad: a #GstPad
455  * @caps: the #GstCaps to fixate
456  *
457  * Given possibly unfixed caps @caps, let @pad use its default prefered
458  * format to make a fixed caps. @caps should be writable. By default this
459  * function will pick the first value of any ranges or lists in the caps but
460  * elements can override this function to perform other behaviour.
461  */
462 typedef void                    (*GstPadFixateCapsFunction)     (GstPad *pad, GstCaps *caps);
463
464 /* misc */
465 /**
466  * GstPadForwardFunction:
467  * @pad: the #GstPad that is forwarded.
468  * @user_data: the gpointer to optional user data.
469  *
470  * A forward function is called for all internally linked pads, see
471  * gst_pad_forward().
472  *
473  * Returns: TRUE if the dispatching procedure has to be stopped.
474  */
475 typedef gboolean                (*GstPadForwardFunction)        (GstPad *pad, gpointer user_data);
476
477 /**
478  * GstProbeType:
479  * @GST_PROBE_TYPE_INVALID: invalid probe type
480  * @GST_PROBE_TYPE_IDLE: probe idle pads and block
481  * @GST_PROBE_TYPE_BLOCK: probe and block pads
482  * @GST_PROBE_TYPE_BUFFER: probe buffers
483  * @GST_PROBE_TYPE_BUFFER_LIST: probe buffer lists
484  * @GST_PROBE_TYPE_EVENT: probe events
485  * @GST_PROBE_TYPE_PUSH: probe push
486  * @GST_PROBE_TYPE_PULL: probe pull
487  *
488  * The different probing types that can occur. When either one of
489  * @GST_PROBE_TYPE_IDLE or @GST_PROBE_TYPE_BLOCK is used, the probe will be a
490  * blocking probe.
491  */
492 typedef enum
493 {
494   GST_PROBE_TYPE_INVALID      = 0,
495   /* flags to control blocking */
496   GST_PROBE_TYPE_IDLE         = (1 << 0),
497   GST_PROBE_TYPE_BLOCK        = (1 << 1),
498   /* flags to select datatypes */
499   GST_PROBE_TYPE_BUFFER       = (1 << 2),
500   GST_PROBE_TYPE_BUFFER_LIST  = (1 << 3),
501   GST_PROBE_TYPE_EVENT        = (1 << 4),
502   /* flags to select scheduling mode */
503   GST_PROBE_TYPE_PUSH         = (1 << 5),
504   GST_PROBE_TYPE_PULL         = (1 << 6),
505 } GstProbeType;
506
507 #define GST_PROBE_TYPE_BLOCKING   (GST_PROBE_TYPE_IDLE | GST_PROBE_TYPE_BLOCK)
508 #define GST_PROBE_TYPE_DATA       (GST_PROBE_TYPE_BUFFER | GST_PROBE_TYPE_EVENT | \
509                                    GST_PROBE_TYPE_BUFFER_LIST)
510 #define GST_PROBE_TYPE_SCHEDULING (GST_PROBE_TYPE_PUSH | GST_PROBE_TYPE_PULL)
511
512 /**
513  * GstProbeReturn:
514  * @GST_PROBE_OK: normal probe return value
515  * @GST_PROBE_DROP: drop data in data probes
516  * @GST_PROBE_REMOVE: remove probe
517  * @GST_PROBE_PASS: pass the data item in the block probe and block on
518  *                         the next item
519  *
520  * Different return values for the #GstPadProbeCallback.
521  */
522 typedef enum
523 {
524   GST_PROBE_DROP,
525   GST_PROBE_OK,
526   GST_PROBE_REMOVE,
527   GST_PROBE_PASS,
528 } GstProbeReturn;
529
530 /**
531  * GstPadProbeCallback
532  * @pad: the #GstPad that is blocked
533  * @type: the current probe type
534  * @type_data: type specific data
535  * @user_data: the gpointer to optional user data.
536  *
537  * Callback used by gst_pad_add_probe(). Gets called to notify about the current
538  * blocking type.
539  */
540 typedef GstProbeReturn      (*GstPadProbeCallback)              (GstPad *pad, GstProbeType type,
541                                                                  gpointer type_data, gpointer user_data);
542
543 /**
544  * GstPadStickyEventsForeachFunction:
545  * @pad: the #GstPad.
546  * @event: the sticky #GstEvent.
547  * @user_data: the #gpointer to optional user data.
548  *
549  * Callback used by gst_pad_sticky_events_foreach().
550  *
551  * Returns: GST_FLOW_OK if the iteration should continue
552  */
553 typedef GstFlowReturn           (*GstPadStickyEventsForeachFunction) (GstPad *pad, GstEvent *event, gpointer user_data);
554
555 /**
556  * GstPadFlags:
557  * @GST_PAD_BLOCKED: is dataflow on a pad blocked
558  * @GST_PAD_FLUSHING: is pad refusing buffers
559  * @GST_PAD_IN_GETCAPS: GstPadGetCapsFunction() is running now
560  * @GST_PAD_BLOCKING: is pad currently blocking on a buffer or event
561  * @GST_PAD_NEED_RECONFIGURE: the pad should be reconfigured/renegotiated.
562  *                            The flag has to be unset manually after
563  *                            reconfiguration happened.
564  *                            Since: 0.10.34.
565  * @GST_PAD_NEED_EVENTS: the pad has pending events
566  * @GST_PAD_FIXED_CAPS: the pad is using fixed caps this means that once the
567  *                      caps are set on the pad, the getcaps function only
568  *                      returns those caps.
569  * @GST_PAD_FLAG_LAST: offset to define more flags
570  *
571  * Pad state flags
572  */
573 typedef enum {
574   GST_PAD_BLOCKED          = (GST_OBJECT_FLAG_LAST << 0),
575   GST_PAD_FLUSHING         = (GST_OBJECT_FLAG_LAST << 1),
576   GST_PAD_IN_GETCAPS       = (GST_OBJECT_FLAG_LAST << 2),
577   GST_PAD_BLOCKING         = (GST_OBJECT_FLAG_LAST << 4),
578   GST_PAD_NEED_RECONFIGURE = (GST_OBJECT_FLAG_LAST << 5),
579   GST_PAD_NEED_EVENTS      = (GST_OBJECT_FLAG_LAST << 6),
580   GST_PAD_FIXED_CAPS       = (GST_OBJECT_FLAG_LAST << 7),
581   /* padding */
582   GST_PAD_FLAG_LAST        = (GST_OBJECT_FLAG_LAST << 16)
583 } GstPadFlags;
584
585 /**
586  * GstPad:
587  * @element_private: private data owned by the parent element
588  * @padtemplate: padtemplate for this pad
589  * @direction: the direction of the pad, cannot change after creating
590  *             the pad.
591  * @stream_rec_lock: recursive stream lock of the pad, used to protect
592  *                   the data used in streaming.
593  * @task: task for this pad if the pad is actively driving dataflow.
594  * @block_cond: conditional to signal pad block
595  * @getcapsfunc: function to get caps of the pad
596  * @acceptcapsfunc: function to check if pad can accept caps
597  * @fixatecapsfunc: function to fixate caps
598  * @activatefunc: pad activation function
599  * @activatepushfunc: function to activate/deactivate pad in push mode
600  * @activatepullfunc: function to activate/deactivate pad in pull mode
601  * @linkfunc: function called when pad is linked
602  * @unlinkfunc: function called when pad is unlinked
603  * @peer: the pad this pad is linked to
604  * @chainfunc: function to chain buffer to pad
605  * @getrangefunc: function to get a range of data from a pad
606  * @eventfunc: function to send an event to a pad
607  * @mode: current activation mode of the pad
608  * @querytypefunc: get list of supported queries
609  * @queryfunc: perform a query on the pad
610  * @iterintlinkfunc: get the internal links iterator of this pad
611  *
612  * The #GstPad structure. Use the functions to update the variables.
613  */
614 struct _GstPad {
615   GstObject                      object;
616
617   /*< public >*/
618   gpointer                       element_private;
619
620   GstPadTemplate                *padtemplate;
621
622   GstPadDirection                direction;
623
624   /*< public >*/ /* with STREAM_LOCK */
625   /* streaming rec_lock */
626   GStaticRecMutex                stream_rec_lock;
627   GstTask                       *task;
628
629   /*< public >*/ /* with LOCK */
630   /* block cond, mutex is from the object */
631   GCond                         *block_cond;
632   GHookList                      probes;
633
634   /* the pad capabilities */
635   GstPadGetCapsFunction         getcapsfunc;
636   GstPadAcceptCapsFunction       acceptcapsfunc;
637   GstPadFixateCapsFunction       fixatecapsfunc;
638
639   GstActivateMode                mode;
640   GstPadActivateFunction         activatefunc;
641   GstPadActivateModeFunction     activatepushfunc;
642   GstPadActivateModeFunction     activatepullfunc;
643
644   /* pad link */
645   GstPad                        *peer;
646   GstPadLinkFunction             linkfunc;
647   GstPadUnlinkFunction           unlinkfunc;
648
649   /* data transport functions */
650   GstPadChainFunction            chainfunc;
651   GstPadChainListFunction        chainlistfunc;
652   GstPadGetRangeFunction         getrangefunc;
653   GstPadEventFunction            eventfunc;
654
655   /* pad offset */
656   gint64                         offset;
657
658   /* generic query method */
659   GstPadQueryTypeFunction        querytypefunc;
660   GstPadQueryFunction            queryfunc;
661
662   /* internal links */
663   GstPadIterIntLinkFunction      iterintlinkfunc;
664
665   /* counts number of probes attached. */
666   gint                           num_probes;
667   gint                           num_blocked;
668
669   /*< private >*/
670   GstPadPrivate                 *priv;
671
672   gpointer _gst_reserved[GST_PADDING];
673 };
674
675 struct _GstPadClass {
676   GstObjectClass        parent_class;
677
678   /* signal callbacks */
679   void          (*linked)               (GstPad *pad, GstPad *peer);
680   void          (*unlinked)             (GstPad *pad, GstPad *peer);
681
682   /*< private >*/
683   gpointer _gst_reserved[GST_PADDING];
684 };
685
686
687 /***** helper macros *****/
688 /* GstPad */
689 #define GST_PAD_NAME(pad)               (GST_OBJECT_NAME(pad))
690 #define GST_PAD_PARENT(pad)             (GST_ELEMENT_CAST(GST_OBJECT_PARENT(pad)))
691 #define GST_PAD_ELEMENT_PRIVATE(pad)    (GST_PAD_CAST(pad)->element_private)
692 #define GST_PAD_PAD_TEMPLATE(pad)       (GST_PAD_CAST(pad)->padtemplate)
693 #define GST_PAD_DIRECTION(pad)          (GST_PAD_CAST(pad)->direction)
694 #define GST_PAD_TASK(pad)               (GST_PAD_CAST(pad)->task)
695 #define GST_PAD_ACTIVATE_MODE(pad)      (GST_PAD_CAST(pad)->mode)
696
697 #define GST_PAD_ACTIVATEFUNC(pad)       (GST_PAD_CAST(pad)->activatefunc)
698 #define GST_PAD_ACTIVATEPUSHFUNC(pad)   (GST_PAD_CAST(pad)->activatepushfunc)
699 #define GST_PAD_ACTIVATEPULLFUNC(pad)   (GST_PAD_CAST(pad)->activatepullfunc)
700 #define GST_PAD_CHAINFUNC(pad)          (GST_PAD_CAST(pad)->chainfunc)
701 #define GST_PAD_CHAINLISTFUNC(pad)      (GST_PAD_CAST(pad)->chainlistfunc)
702 #define GST_PAD_GETRANGEFUNC(pad)       (GST_PAD_CAST(pad)->getrangefunc)
703 #define GST_PAD_EVENTFUNC(pad)          (GST_PAD_CAST(pad)->eventfunc)
704 #define GST_PAD_QUERYTYPEFUNC(pad)      (GST_PAD_CAST(pad)->querytypefunc)
705 #define GST_PAD_QUERYFUNC(pad)          (GST_PAD_CAST(pad)->queryfunc)
706 #define GST_PAD_ITERINTLINKFUNC(pad)    (GST_PAD_CAST(pad)->iterintlinkfunc)
707
708 #define GST_PAD_PEER(pad)               (GST_PAD_CAST(pad)->peer)
709 #define GST_PAD_LINKFUNC(pad)           (GST_PAD_CAST(pad)->linkfunc)
710 #define GST_PAD_UNLINKFUNC(pad)         (GST_PAD_CAST(pad)->unlinkfunc)
711
712 #define GST_PAD_GETCAPSFUNC(pad)        (GST_PAD_CAST(pad)->getcapsfunc)
713 #define GST_PAD_ACCEPTCAPSFUNC(pad)     (GST_PAD_CAST(pad)->acceptcapsfunc)
714 #define GST_PAD_FIXATECAPSFUNC(pad)     (GST_PAD_CAST(pad)->fixatecapsfunc)
715
716 #define GST_PAD_IS_SRC(pad)             (GST_PAD_DIRECTION(pad) == GST_PAD_SRC)
717 #define GST_PAD_IS_SINK(pad)            (GST_PAD_DIRECTION(pad) == GST_PAD_SINK)
718
719 #define GST_PAD_IS_LINKED(pad)          (GST_PAD_PEER(pad) != NULL)
720
721 #define GST_PAD_IS_BLOCKED(pad)         (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_BLOCKED))
722 #define GST_PAD_IS_BLOCKING(pad)        (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_BLOCKING))
723 #define GST_PAD_IS_FLUSHING(pad)        (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLUSHING))
724 #define GST_PAD_IS_IN_GETCAPS(pad)      (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_IN_GETCAPS))
725 #define GST_PAD_NEEDS_RECONFIGURE(pad)  (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_NEED_RECONFIGURE))
726 #define GST_PAD_NEEDS_EVENTS(pad)       (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_NEED_EVENTS))
727 #define GST_PAD_IS_FIXED_CAPS(pad)      (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FIXED_CAPS))
728
729 #define GST_PAD_SET_FLUSHING(pad)       (GST_OBJECT_FLAG_SET (pad, GST_PAD_FLUSHING))
730 #define GST_PAD_UNSET_FLUSHING(pad)     (GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLUSHING))
731
732 /**
733  * GST_PAD_GET_STREAM_LOCK:
734  * @pad: a #GstPad
735  *
736  * Get the stream lock of @pad. The stream lock is protecting the
737  * resources used in the data processing functions of @pad.
738  */
739 #define GST_PAD_GET_STREAM_LOCK(pad)    (&(GST_PAD_CAST(pad)->stream_rec_lock))
740 /**
741  * GST_PAD_STREAM_LOCK:
742  * @pad: a #GstPad
743  *
744  * Lock the stream lock of @pad.
745  */
746 #define GST_PAD_STREAM_LOCK(pad)        (g_static_rec_mutex_lock(GST_PAD_GET_STREAM_LOCK(pad)))
747 /**
748  * GST_PAD_STREAM_LOCK_FULL:
749  * @pad: a #GstPad
750  * @t: the number of times to recursively lock
751  *
752  * Lock the stream lock of @pad @t times.
753  */
754 #define GST_PAD_STREAM_LOCK_FULL(pad,t) (g_static_rec_mutex_lock_full(GST_PAD_GET_STREAM_LOCK(pad), t))
755 /**
756  * GST_PAD_STREAM_TRYLOCK:
757  * @pad: a #GstPad
758  *
759  * Try to Lock the stream lock of the pad, return TRUE if the lock could be
760  * taken.
761  */
762 #define GST_PAD_STREAM_TRYLOCK(pad)     (g_static_rec_mutex_trylock(GST_PAD_GET_STREAM_LOCK(pad)))
763 /**
764  * GST_PAD_STREAM_UNLOCK:
765  * @pad: a #GstPad
766  *
767  * Unlock the stream lock of @pad.
768  */
769 #define GST_PAD_STREAM_UNLOCK(pad)      (g_static_rec_mutex_unlock(GST_PAD_GET_STREAM_LOCK(pad)))
770 /**
771  * GST_PAD_STREAM_UNLOCK_FULL:
772  * @pad: a #GstPad
773  *
774  * Fully unlock the recursive stream lock of @pad, return the number of times
775  * @pad was locked.
776  */
777 #define GST_PAD_STREAM_UNLOCK_FULL(pad) (g_static_rec_mutex_unlock_full(GST_PAD_GET_STREAM_LOCK(pad)))
778
779 #define GST_PAD_BLOCK_GET_COND(pad)     (GST_PAD_CAST(pad)->block_cond)
780 #define GST_PAD_BLOCK_WAIT(pad)         (g_cond_wait(GST_PAD_BLOCK_GET_COND (pad), GST_OBJECT_GET_LOCK (pad)))
781 #define GST_PAD_BLOCK_SIGNAL(pad)       (g_cond_signal(GST_PAD_BLOCK_GET_COND (pad)))
782 #define GST_PAD_BLOCK_BROADCAST(pad)    (g_cond_broadcast(GST_PAD_BLOCK_GET_COND (pad)))
783
784 GType                   gst_pad_get_type                        (void);
785
786 /* creating pads */
787 GstPad*                 gst_pad_new                             (const gchar *name, GstPadDirection direction);
788 GstPad*                 gst_pad_new_from_template               (GstPadTemplate *templ, const gchar *name);
789 GstPad*                 gst_pad_new_from_static_template        (GstStaticPadTemplate *templ, const gchar *name);
790
791
792 /**
793  * gst_pad_get_name:
794  * @pad: the pad to get the name from
795  *
796  * Get a copy of the name of the pad. g_free() after usage.
797  *
798  * MT safe.
799  */
800 #define gst_pad_get_name(pad) gst_object_get_name (GST_OBJECT_CAST (pad))
801 /**
802  * gst_pad_get_parent:
803  * @pad: the pad to get the parent of
804  *
805  * Get the parent of @pad. This function increases the refcount
806  * of the parent object so you should gst_object_unref() it after usage.
807  * Can return NULL if the pad did not have a parent.
808  *
809  * MT safe.
810  */
811 #define gst_pad_get_parent(pad) gst_object_get_parent (GST_OBJECT_CAST (pad))
812
813 GstPadDirection         gst_pad_get_direction                   (GstPad *pad);
814
815 gboolean                gst_pad_set_active                      (GstPad *pad, gboolean active);
816 gboolean                gst_pad_is_active                       (GstPad *pad);
817 gboolean                gst_pad_activate_pull                   (GstPad *pad, gboolean active);
818 gboolean                gst_pad_activate_push                   (GstPad *pad, gboolean active);
819
820 gulong                  gst_pad_add_probe                       (GstPad *pad,
821                                                                  GstProbeType mask,
822                                                                  GstPadProbeCallback callback,
823                                                                  gpointer user_data,
824                                                                  GDestroyNotify destroy_data);
825 void                    gst_pad_remove_probe                    (GstPad *pad, gulong id);
826
827 gboolean                gst_pad_is_blocked                      (GstPad *pad);
828 gboolean                gst_pad_is_blocking                     (GstPad *pad);
829
830 gboolean                gst_pad_check_reconfigure               (GstPad *pad);
831
832 void                    gst_pad_set_element_private             (GstPad *pad, gpointer priv);
833 gpointer                gst_pad_get_element_private             (GstPad *pad);
834
835 GstPadTemplate*         gst_pad_get_pad_template                (GstPad *pad);
836
837 GstEvent*               gst_pad_get_sticky_event                (GstPad *pad, GstEventType event_type);
838 GstFlowReturn           gst_pad_sticky_events_foreach           (GstPad *pad, GstPadStickyEventsForeachFunction foreach_func, gpointer user_data);
839
840 /* data passing setup functions */
841 void                    gst_pad_set_activate_function           (GstPad *pad, GstPadActivateFunction activate);
842 void                    gst_pad_set_activatepull_function       (GstPad *pad, GstPadActivateModeFunction activatepull);
843 void                    gst_pad_set_activatepush_function       (GstPad *pad, GstPadActivateModeFunction activatepush);
844 void                    gst_pad_set_chain_function              (GstPad *pad, GstPadChainFunction chain);
845 void                    gst_pad_set_chain_list_function         (GstPad *pad, GstPadChainListFunction chainlist);
846 void                    gst_pad_set_getrange_function           (GstPad *pad, GstPadGetRangeFunction get);
847 void                    gst_pad_set_event_function              (GstPad *pad, GstPadEventFunction event);
848
849 /* pad links */
850 void                    gst_pad_set_link_function               (GstPad *pad, GstPadLinkFunction link);
851 void                    gst_pad_set_unlink_function             (GstPad *pad, GstPadUnlinkFunction unlink);
852
853 gboolean                gst_pad_can_link                        (GstPad *srcpad, GstPad *sinkpad);
854 GstPadLinkReturn        gst_pad_link                            (GstPad *srcpad, GstPad *sinkpad);
855 GstPadLinkReturn        gst_pad_link_full                       (GstPad *srcpad, GstPad *sinkpad, GstPadLinkCheck flags);
856 gboolean                gst_pad_unlink                          (GstPad *srcpad, GstPad *sinkpad);
857 gboolean                gst_pad_is_linked                       (GstPad *pad);
858
859 GstPad*                 gst_pad_get_peer                        (GstPad *pad);
860
861 /* capsnego functions */
862 void                    gst_pad_set_getcaps_function            (GstPad *pad, GstPadGetCapsFunction getcaps);
863 void                    gst_pad_set_acceptcaps_function         (GstPad *pad, GstPadAcceptCapsFunction acceptcaps);
864 void                    gst_pad_set_fixatecaps_function         (GstPad *pad, GstPadFixateCapsFunction fixatecaps);
865
866 GstCaps*                gst_pad_get_pad_template_caps           (GstPad *pad);
867
868 /* capsnego function for linked/unlinked pads */
869 GstCaps *               gst_pad_get_current_caps                (GstPad * pad);
870 gboolean                gst_pad_has_current_caps                (GstPad * pad);
871 GstCaps *               gst_pad_get_caps                        (GstPad * pad, GstCaps *filter);
872 void                    gst_pad_fixate_caps                     (GstPad * pad, GstCaps *caps);
873 gboolean                gst_pad_accept_caps                     (GstPad * pad, GstCaps *caps);
874 gboolean                gst_pad_set_caps                        (GstPad * pad, GstCaps *caps);
875
876 GstCaps *               gst_pad_peer_get_caps                   (GstPad * pad, GstCaps *filter);
877 gboolean                gst_pad_peer_accept_caps                (GstPad * pad, GstCaps *caps);
878
879 /* capsnego for linked pads */
880 GstCaps *               gst_pad_get_allowed_caps                (GstPad * pad);
881 GstCaps *               gst_pad_get_negotiated_caps             (GstPad * pad);
882
883 /* pad offsets */
884 gint64                  gst_pad_get_offset                      (GstPad *pad);
885 void                    gst_pad_set_offset                      (GstPad *pad, gint64 offset);
886
887 /* data passing functions to peer */
888 GstFlowReturn           gst_pad_push                            (GstPad *pad, GstBuffer *buffer);
889 GstFlowReturn           gst_pad_push_list                       (GstPad *pad, GstBufferList *list);
890 GstFlowReturn           gst_pad_pull_range                      (GstPad *pad, guint64 offset, guint size,
891                                                                  GstBuffer **buffer);
892 gboolean                gst_pad_push_event                      (GstPad *pad, GstEvent *event);
893 gboolean                gst_pad_event_default                   (GstPad *pad, GstEvent *event);
894
895 /* data passing functions on pad */
896 GstFlowReturn           gst_pad_chain                           (GstPad *pad, GstBuffer *buffer);
897 GstFlowReturn           gst_pad_chain_list                      (GstPad *pad, GstBufferList *list);
898 GstFlowReturn           gst_pad_get_range                       (GstPad *pad, guint64 offset, guint size,
899                                                                  GstBuffer **buffer);
900 gboolean                gst_pad_send_event                      (GstPad *pad, GstEvent *event);
901
902 /* pad tasks */
903 gboolean                gst_pad_start_task                      (GstPad *pad, GstTaskFunction func,
904                                                                  gpointer data);
905 gboolean                gst_pad_pause_task                      (GstPad *pad);
906 gboolean                gst_pad_stop_task                       (GstPad *pad);
907
908 /* internal links */
909 void                    gst_pad_set_iterate_internal_links_function (GstPad * pad,
910                                                                  GstPadIterIntLinkFunction iterintlink);
911 GstIterator *           gst_pad_iterate_internal_links          (GstPad * pad);
912 GstIterator *           gst_pad_iterate_internal_links_default  (GstPad * pad);
913
914
915 /* generic query function */
916 void                    gst_pad_set_query_type_function         (GstPad *pad, GstPadQueryTypeFunction type_func);
917 const GstQueryType*     gst_pad_get_query_types                 (GstPad *pad);
918 const GstQueryType*     gst_pad_get_query_types_default         (GstPad *pad);
919
920 gboolean                gst_pad_query                           (GstPad *pad, GstQuery *query);
921 gboolean                gst_pad_peer_query                      (GstPad *pad, GstQuery *query);
922 void                    gst_pad_set_query_function              (GstPad *pad, GstPadQueryFunction query);
923 gboolean                gst_pad_query_default                   (GstPad *pad, GstQuery *query);
924
925 /* misc helper functions */
926 gboolean                gst_pad_forward                         (GstPad *pad, GstPadForwardFunction forward,
927                                                                  gpointer user_data);
928
929 G_END_DECLS
930
931 #endif /* __GST_PAD_H__ */