pad: add parent to other functions
[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_EOS:                Pad is 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_EOS            = -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_query_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 ((GstPadLinkCheck) (GST_PAD_LINK_CHECK_HIERARCHY | GST_PAD_LINK_CHECK_CAPS))
213
214 /**
215  * GstPadActivateMode:
216  * @GST_PAD_ACTIVATE_NONE: Pad will not handle dataflow
217  * @GST_PAD_ACTIVATE_PUSH: Pad handles dataflow in downstream push mode
218  * @GST_PAD_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 GstPadActivateMode defines if the
222  * pad operates in push or pull mode.
223  */
224 typedef enum {
225   GST_PAD_ACTIVATE_NONE,
226   GST_PAD_ACTIVATE_PUSH,
227   GST_PAD_ACTIVATE_PULL
228 } GstPadActivateMode;
229
230 /* pad states */
231 /**
232  * GstPadActivateFunction:
233  * @pad: a #GstPad
234  *
235  * This function is called when the pad is activated during the element
236  * READY to PAUSED state change. By default this function will call the
237  * activate function that puts the pad in push mode but elements can
238  * override this function to activate the pad in pull mode if they wish.
239  *
240  * Returns: TRUE if the pad could be activated.
241  */
242 typedef gboolean                (*GstPadActivateFunction)       (GstPad *pad);
243 /**
244  * GstPadActivateModeFunction:
245  * @pad: a #GstPad
246  * @active: activate or deactivate the pad.
247  *
248  * The prototype of the push and pull activate functions.
249  *
250  * Returns: TRUE if the pad could be activated or deactivated.
251  */
252 typedef gboolean                (*GstPadActivateModeFunction)   (GstPad *pad, gboolean active);
253
254
255 /* data passing */
256 /**
257  * GstPadChainFunction:
258  * @pad: the sink #GstPad that performed the chain.
259  * @parent: the parent of @pad. If the #GST_PAD_FLAG_NEED_PARENT flag is set,
260  *          @parent is guaranteed to be not-NULL and remain valid during the
261  *          execution of this function.
262  * @buffer: the #GstBuffer that is chained, not %NULL.
263  *
264  * A function that will be called on sinkpads when chaining buffers.
265  * The function typically processes the data contained in the buffer and
266  * either consumes the data or passes it on to the internally linked pad(s).
267  *
268  * The implementer of this function receives a refcount to @buffer and should
269  * gst_buffer_unref() when the buffer is no longer needed.
270  *
271  * When a chain function detects an error in the data stream, it must post an
272  * error on the bus and return an appropriate #GstFlowReturn value.
273  *
274  * Returns: #GST_FLOW_OK for success
275  */
276 typedef GstFlowReturn           (*GstPadChainFunction)          (GstPad *pad, GstObject *parent,
277                                                                  GstBuffer *buffer);
278
279 /**
280  * GstPadChainListFunction:
281  * @pad: the sink #GstPad that performed the chain.
282  * @parent: the parent of @pad. If the #GST_PAD_FLAG_NEED_PARENT flag is set,
283  *          @parent is guaranteed to be not-NULL and remain valid during the
284  *          execution of this function.
285  * @list: the #GstBufferList that is chained, not %NULL.
286  *
287  * A function that will be called on sinkpads when chaining buffer lists.
288  * The function typically processes the data contained in the buffer list and
289  * either consumes the data or passes it on to the internally linked pad(s).
290  *
291  * The implementer of this function receives a refcount to @list and
292  * should gst_buffer_list_unref() when the list is no longer needed.
293  *
294  * When a chainlist function detects an error in the data stream, it must
295  * post an error on the bus and return an appropriate #GstFlowReturn value.
296  *
297  * Returns: #GST_FLOW_OK for success
298  */
299 typedef GstFlowReturn           (*GstPadChainListFunction)      (GstPad *pad, GstObject *parent,
300                                                                  GstBufferList *list);
301
302 /**
303  * GstPadGetRangeFunction:
304  * @pad: the src #GstPad to perform the getrange on.
305  * @parent: the parent of @pad. If the #GST_PAD_FLAG_NEED_PARENT flag is set,
306  *          @parent is guaranteed to be not-NULL and remain valid during the
307  *          execution of this function.
308  * @offset: the offset of the range
309  * @length: the length of the range
310  * @buffer: a memory location to hold the result buffer, cannot be NULL.
311  *
312  * This function will be called on source pads when a peer element
313  * request a buffer at the specified @offset and @length. If this function
314  * returns #GST_FLOW_OK, the result buffer will be stored in @buffer. The
315  * contents of @buffer is invalid for any other return value.
316  *
317  * This function is installed on a source pad with
318  * gst_pad_set_getrange_function() and can only be called on source pads after
319  * they are successfully activated with gst_pad_activate_pull().
320  *
321  * @offset and @length are always given in byte units. @offset must normally be a value
322  * between 0 and the length in bytes of the data available on @pad. The
323  * length (duration in bytes) can be retrieved with a #GST_QUERY_DURATION or with a
324  * #GST_QUERY_SEEKING.
325  *
326  * Any @offset larger or equal than the length will make the function return
327  * #GST_FLOW_UNEXPECTED, which corresponds to EOS. In this case @buffer does not
328  * contain a valid buffer.
329  *
330  * The buffer size of @buffer will only be smaller than @length when @offset is
331  * near the end of the stream. In all other cases, the size of @buffer must be
332  * exactly the requested size.
333  *
334  * It is allowed to call this function with a 0 @length and valid @offset, in
335  * which case @buffer will contain a 0-sized buffer and the function returns
336  * #GST_FLOW_OK.
337  *
338  * When this function is called with a -1 @offset, the sequentially next buffer
339  * of length @length in the stream is returned.
340  *
341  * When this function is called with a -1 @length, a buffer with a default
342  * optimal length is returned in @buffer. The length might depend on the value
343  * of @offset.
344  *
345  * Returns: #GST_FLOW_OK for success and a valid buffer in @buffer. Any other
346  * return value leaves @buffer undefined.
347  */
348 typedef GstFlowReturn           (*GstPadGetRangeFunction)       (GstPad *pad, GstObject *parent,
349                                                                  guint64 offset, guint length,
350                                                                  GstBuffer **buffer);
351
352 /**
353  * GstPadEventFunction:
354  * @pad: the #GstPad to handle the event.
355  * @parent: the parent of @pad. If the #GST_PAD_FLAG_NEED_PARENT flag is set,
356  *          @parent is guaranteed to be not-NULL and remain valid during the
357  *          execution of this function.
358  * @event: the #GstEvent to handle.
359  *
360  * Function signature to handle an event for the pad.
361  *
362  * Returns: TRUE if the pad could handle the event.
363  */
364 typedef gboolean                (*GstPadEventFunction)          (GstPad *pad, GstObject *parent,
365                                                                  GstEvent *event);
366
367
368 /* internal links */
369 /**
370  * GstPadIterIntLinkFunction:
371  * @pad: The #GstPad to query.
372  * @parent: the parent of @pad. If the #GST_PAD_FLAG_NEED_PARENT flag is set,
373  *          @parent is guaranteed to be not-NULL and remain valid during the
374  *          execution of this function.
375  *
376  * The signature of the internal pad link iterator function.
377  *
378  * Returns: a new #GstIterator that will iterate over all pads that are
379  * linked to the given pad on the inside of the parent element.
380  *
381  * the caller must call gst_iterator_free() after usage.
382  *
383  * Since 0.10.21
384  */
385 typedef GstIterator*           (*GstPadIterIntLinkFunction)    (GstPad *pad, GstObject *parent);
386
387 /* generic query function */
388 /**
389  * GstPadQueryFunction:
390  * @pad: the #GstPad to query.
391  * @parent: the parent of @pad. If the #GST_PAD_FLAG_NEED_PARENT flag is set,
392  *          @parent is guaranteed to be not-NULL and remain valid during the
393  *          execution of this function.
394  * @query: the #GstQuery object to execute
395  *
396  * The signature of the query function.
397  *
398  * Returns: TRUE if the query could be performed.
399  */
400 typedef gboolean                (*GstPadQueryFunction)          (GstPad *pad, GstObject *parent,
401                                                                  GstQuery *query);
402
403
404 /* linking */
405 /**
406  * GstPadLinkFunction
407  * @pad: the #GstPad that is linked.
408  * @peer: the peer #GstPad of the link
409  *
410  * Function signature to handle a new link on the pad.
411  *
412  * Returns: the result of the link with the specified peer.
413  */
414 typedef GstPadLinkReturn        (*GstPadLinkFunction)           (GstPad *pad, GstPad *peer);
415 /**
416  * GstPadUnlinkFunction
417  * @pad: the #GstPad that is linked.
418  *
419  * Function signature to handle a unlinking the pad prom its peer.
420  */
421 typedef void                    (*GstPadUnlinkFunction)         (GstPad *pad);
422
423
424 /* misc */
425 /**
426  * GstPadForwardFunction:
427  * @pad: the #GstPad that is forwarded.
428  * @user_data: the gpointer to optional user data.
429  *
430  * A forward function is called for all internally linked pads, see
431  * gst_pad_forward().
432  *
433  * Returns: TRUE if the dispatching procedure has to be stopped.
434  */
435 typedef gboolean                (*GstPadForwardFunction)        (GstPad *pad, gpointer user_data);
436
437 /**
438  * GstPadProbeType:
439  * @GST_PAD_PROBE_TYPE_INVALID: invalid probe type
440  * @GST_PAD_PROBE_TYPE_IDLE: probe idle pads and block
441  * @GST_PAD_PROBE_TYPE_BLOCK: probe and block pads
442  * @GST_PAD_PROBE_TYPE_BUFFER: probe buffers
443  * @GST_PAD_PROBE_TYPE_BUFFER_LIST: probe buffer lists
444  * @GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM: probe downstream events
445  * @GST_PAD_PROBE_TYPE_EVENT_UPSTREAM: probe upstream events
446  * @GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM: probe downstream queries
447  * @GST_PAD_PROBE_TYPE_QUERY_UPSTREAM: probe upstream queries
448  * @GST_PAD_PROBE_TYPE_PUSH: probe push
449  * @GST_PAD_PROBE_TYPE_PULL: probe pull
450  *
451  * The different probing types that can occur. When either one of
452  * @GST_PAD_PROBE_TYPE_IDLE or @GST_PAD_PROBE_TYPE_BLOCK is used, the probe will be a
453  * blocking probe.
454  */
455 typedef enum
456 {
457   GST_PAD_PROBE_TYPE_INVALID          = 0,
458   /* flags to control blocking */
459   GST_PAD_PROBE_TYPE_IDLE             = (1 << 0),
460   GST_PAD_PROBE_TYPE_BLOCK            = (1 << 1),
461   /* flags to select datatypes */
462   GST_PAD_PROBE_TYPE_BUFFER           = (1 << 4),
463   GST_PAD_PROBE_TYPE_BUFFER_LIST      = (1 << 5),
464   GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM = (1 << 6),
465   GST_PAD_PROBE_TYPE_EVENT_UPSTREAM   = (1 << 7),
466   GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM = (1 << 8),
467   GST_PAD_PROBE_TYPE_QUERY_UPSTREAM   = (1 << 9),
468   /* flags to select scheduling mode */
469   GST_PAD_PROBE_TYPE_PUSH             = (1 << 12),
470   GST_PAD_PROBE_TYPE_PULL             = (1 << 13),
471 } GstPadProbeType;
472
473 #define GST_PAD_PROBE_TYPE_BLOCKING         (GST_PAD_PROBE_TYPE_IDLE | GST_PAD_PROBE_TYPE_BLOCK)
474 #define GST_PAD_PROBE_TYPE_BLOCK_DOWNSTREAM (GST_PAD_PROBE_TYPE_BLOCK | GST_PAD_PROBE_TYPE_DATA_DOWNSTREAM)
475 #define GST_PAD_PROBE_TYPE_BLOCK_UPSTREAM   (GST_PAD_PROBE_TYPE_BLOCK | GST_PAD_PROBE_TYPE_DATA_UPSTREAM)
476 #define GST_PAD_PROBE_TYPE_DATA_DOWNSTREAM  (GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_BUFFER_LIST | \
477                                              GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM)
478 #define GST_PAD_PROBE_TYPE_DATA_UPSTREAM    (GST_PAD_PROBE_TYPE_EVENT_UPSTREAM)
479 #define GST_PAD_PROBE_TYPE_DATA_BOTH        (GST_PAD_PROBE_TYPE_DATA_DOWNSTREAM | \
480                                              GST_PAD_PROBE_TYPE_DATA_UPSTREAM)
481 #define GST_PAD_PROBE_TYPE_EVENT_BOTH       (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM | \
482                                              GST_PAD_PROBE_TYPE_EVENT_UPSTREAM)
483 #define GST_PAD_PROBE_TYPE_QUERY_BOTH       (GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM | \
484                                              GST_PAD_PROBE_TYPE_QUERY_UPSTREAM)
485 #define GST_PAD_PROBE_TYPE_ALL_BOTH         (GST_PAD_PROBE_TYPE_DATA_BOTH | \
486                                              GST_PAD_PROBE_TYPE_QUERY_BOTH)
487 #define GST_PAD_PROBE_TYPE_SCHEDULING       (GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_PULL)
488
489 /**
490  * GstPadProbeReturn:
491  * @GST_PAD_PROBE_OK: normal probe return value
492  * @GST_PAD_PROBE_DROP: drop data in data probes
493  * @GST_PAD_PROBE_REMOVE: remove probe
494  * @GST_PAD_PROBE_PASS: pass the data item in the block probe and block on
495  *                         the next item
496  *
497  * Different return values for the #GstPadProbeCallback.
498  */
499 typedef enum
500 {
501   GST_PAD_PROBE_DROP,
502   GST_PAD_PROBE_OK,
503   GST_PAD_PROBE_REMOVE,
504   GST_PAD_PROBE_PASS,
505 } GstPadProbeReturn;
506
507
508 /**
509  * GstPadProbeInfo:
510  * @type: the current probe type
511  * @data: type specific data, check the @type field to know the datatype.
512  *    This field can be NULL.
513  * @offset: offset of pull probe, this field is valid when @type contains
514  *    #GST_PAD_PROBE_TYPE_PULL
515  * @size: size of pull probe, this field is valid when @type contains
516  *    #GST_PAD_PROBE_TYPE_PULL
517  *
518  * Info passed in the #GstPadProbeCallback.
519  */
520 typedef struct
521 {
522   GstPadProbeType type;
523   gpointer data;
524   guint64 offset;
525   guint size;
526
527   gpointer _gst_reserved[GST_PADDING];
528 } GstPadProbeInfo;
529
530 #define GST_PAD_PROBE_INFO_TYPE(d)         ((d)->type)
531 #define GST_PAD_PROBE_INFO_DATA(d)         ((d)->data)
532
533 #define GST_PAD_PROBE_INFO_BUFFER(d)       GST_BUFFER_CAST(GST_PAD_PROBE_INFO_DATA(d))
534 #define GST_PAD_PROBE_INFO_BUFFER_LIST(d)  GST_BUFFER_LIST_CAST(GST_PAD_PROBE_INFO_DATA(d))
535 #define GST_PAD_PROBE_INFO_EVENT(d)        GST_EVENT_CAST(GST_PAD_PROBE_INFO_DATA(d))
536 #define GST_PAD_PROBE_INFO_QUERY(d)        GST_QUERY_CAST(GST_PAD_PROBE_INFO_DATA(d))
537
538 #define GST_PAD_PROBE_INFO_OFFSET(d)       ((d)->offset)
539 #define GST_PAD_PROBE_INFO_SIZE(d)         ((d)->size)
540
541 /**
542  * GstPadProbeCallback
543  * @pad: the #GstPad that is blocked
544  * @info: #GstPadProbeInfo
545  * @user_data: the gpointer to optional user data.
546  *
547  * Callback used by gst_pad_add_probe(). Gets called to notify about the current
548  * blocking type.
549  *
550  * The callback is allowed to modify the data pointer in @info.
551  */
552 typedef GstPadProbeReturn   (*GstPadProbeCallback)   (GstPad *pad, GstPadProbeInfo *info,
553                                                       gpointer user_data);
554
555 /**
556  * GstPadStickyEventsForeachFunction:
557  * @pad: the #GstPad.
558  * @event: the sticky #GstEvent.
559  * @user_data: the #gpointer to optional user data.
560  *
561  * Callback used by gst_pad_sticky_events_foreach().
562  *
563  * Returns: GST_FLOW_OK if the iteration should continue
564  */
565 typedef GstFlowReturn  (*GstPadStickyEventsForeachFunction) (GstPad *pad, GstEvent *event,
566                                                              gpointer user_data);
567
568 /**
569  * GstPadFlags:
570  * @GST_PAD_FLAG_BLOCKED: is dataflow on a pad blocked
571  * @GST_PAD_FLAG_FLUSHING: is pad refusing buffers
572  * @GST_PAD_FLAG_BLOCKING: is pad currently blocking on a buffer or event
573  * @GST_PAD_FLAG_NEED_RECONFIGURE: the pad should be reconfigured/renegotiated.
574  *                            The flag has to be unset manually after
575  *                            reconfiguration happened.
576  *                            Since: 0.10.34.
577  * @GST_PAD_FLAG_NEED_EVENTS: the pad has pending events
578  * @GST_PAD_FLAG_FIXED_CAPS: the pad is using fixed caps this means that once the
579  *                      caps are set on the pad, the caps query function only
580  *                      returns those caps.
581  * @GST_PAD_FLAG_PROXY_CAPS: the default event and query handler will forward
582  *                      all events and queries to the internally linked pads
583  *                      instead of discarding them.
584  * @GST_PAD_FLAG_NEED_PARENT: ensure that there is a parent object before calling
585  *                       into the pad callbacks.
586  * @GST_PAD_FLAG_LAST: offset to define more flags
587  *
588  * Pad state flags
589  */
590 typedef enum {
591   GST_PAD_FLAG_BLOCKED          = (GST_OBJECT_FLAG_LAST << 0),
592   GST_PAD_FLAG_FLUSHING         = (GST_OBJECT_FLAG_LAST << 1),
593   GST_PAD_FLAG_BLOCKING         = (GST_OBJECT_FLAG_LAST << 2),
594   GST_PAD_FLAG_NEED_RECONFIGURE = (GST_OBJECT_FLAG_LAST << 3),
595   GST_PAD_FLAG_NEED_EVENTS      = (GST_OBJECT_FLAG_LAST << 4),
596   GST_PAD_FLAG_FIXED_CAPS       = (GST_OBJECT_FLAG_LAST << 5),
597   GST_PAD_FLAG_PROXY_CAPS       = (GST_OBJECT_FLAG_LAST << 6),
598   GST_PAD_FLAG_NEED_PARENT      = (GST_OBJECT_FLAG_LAST << 7),
599   /* padding */
600   GST_PAD_FLAG_LAST        = (GST_OBJECT_FLAG_LAST << 16)
601 } GstPadFlags;
602
603 /**
604  * GstPad:
605  * @element_private: private data owned by the parent element
606  * @padtemplate: padtemplate for this pad
607  * @direction: the direction of the pad, cannot change after creating
608  *             the pad.
609  * @stream_rec_lock: recursive stream lock of the pad, used to protect
610  *                   the data used in streaming.
611  * @task: task for this pad if the pad is actively driving dataflow.
612  * @block_cond: conditional to signal pad block
613  * @probes: installed probes
614  * @mode: current activation mode of the pad
615  * @activatefunc: pad activation function
616  * @activatepushfunc: function to activate/deactivate pad in push mode
617  * @activatepullfunc: function to activate/deactivate pad in pull mode
618  * @peer: the pad this pad is linked to
619  * @linkfunc: function called when pad is linked
620  * @unlinkfunc: function called when pad is unlinked
621  * @chainfunc: function to chain buffer to pad
622  * @chainlistfunc: function to chain a list of buffers to pad
623  * @getrangefunc: function to get a range of data from a pad
624  * @eventfunc: function to send an event to a pad
625  * @offset: the pad offset
626  * @queryfunc: perform a query on the pad
627  * @iterintlinkfunc: get the internal links iterator of this pad
628  *
629  * The #GstPad structure. Use the functions to update the variables.
630  */
631 struct _GstPad {
632   GstObject                      object;
633
634   /*< public >*/
635   gpointer                       element_private;
636
637   GstPadTemplate                *padtemplate;
638
639   GstPadDirection                direction;
640
641   /*< public >*/ /* with STREAM_LOCK */
642   /* streaming rec_lock */
643   GStaticRecMutex                stream_rec_lock;
644   GstTask                       *task;
645
646   /*< public >*/ /* with LOCK */
647   /* block cond, mutex is from the object */
648   GCond                         *block_cond;
649   GHookList                      probes;
650
651   GstPadActivateMode             mode;
652   GstPadActivateFunction         activatefunc;
653   GstPadActivateModeFunction     activatepushfunc;
654   GstPadActivateModeFunction     activatepullfunc;
655
656   /* pad link */
657   GstPad                        *peer;
658   GstPadLinkFunction             linkfunc;
659   GstPadUnlinkFunction           unlinkfunc;
660
661   /* data transport functions */
662   GstPadChainFunction            chainfunc;
663   GstPadChainListFunction        chainlistfunc;
664   GstPadGetRangeFunction         getrangefunc;
665   GstPadEventFunction            eventfunc;
666
667   /* pad offset */
668   gint64                         offset;
669
670   /* generic query method */
671   GstPadQueryFunction            queryfunc;
672
673   /* internal links */
674   GstPadIterIntLinkFunction      iterintlinkfunc;
675
676   /*< private >*/
677   /* counts number of probes attached. */
678   gint                           num_probes;
679   gint                           num_blocked;
680
681   GstPadPrivate                 *priv;
682
683   gpointer _gst_reserved[GST_PADDING];
684 };
685
686 struct _GstPadClass {
687   GstObjectClass        parent_class;
688
689   /* signal callbacks */
690   void          (*linked)               (GstPad *pad, GstPad *peer);
691   void          (*unlinked)             (GstPad *pad, GstPad *peer);
692
693   /*< private >*/
694   gpointer _gst_reserved[GST_PADDING];
695 };
696
697
698 /***** helper macros *****/
699 /* GstPad */
700 #define GST_PAD_NAME(pad)               (GST_OBJECT_NAME(pad))
701 #define GST_PAD_PARENT(pad)             (GST_ELEMENT_CAST(GST_OBJECT_PARENT(pad)))
702 #define GST_PAD_ELEMENT_PRIVATE(pad)    (GST_PAD_CAST(pad)->element_private)
703 #define GST_PAD_PAD_TEMPLATE(pad)       (GST_PAD_CAST(pad)->padtemplate)
704 #define GST_PAD_DIRECTION(pad)          (GST_PAD_CAST(pad)->direction)
705 #define GST_PAD_TASK(pad)               (GST_PAD_CAST(pad)->task)
706 #define GST_PAD_ACTIVATE_MODE(pad)      (GST_PAD_CAST(pad)->mode)
707
708 #define GST_PAD_ACTIVATEFUNC(pad)       (GST_PAD_CAST(pad)->activatefunc)
709 #define GST_PAD_ACTIVATEPUSHFUNC(pad)   (GST_PAD_CAST(pad)->activatepushfunc)
710 #define GST_PAD_ACTIVATEPULLFUNC(pad)   (GST_PAD_CAST(pad)->activatepullfunc)
711 #define GST_PAD_CHAINFUNC(pad)          (GST_PAD_CAST(pad)->chainfunc)
712 #define GST_PAD_CHAINLISTFUNC(pad)      (GST_PAD_CAST(pad)->chainlistfunc)
713 #define GST_PAD_GETRANGEFUNC(pad)       (GST_PAD_CAST(pad)->getrangefunc)
714 #define GST_PAD_EVENTFUNC(pad)          (GST_PAD_CAST(pad)->eventfunc)
715 #define GST_PAD_QUERYFUNC(pad)          (GST_PAD_CAST(pad)->queryfunc)
716 #define GST_PAD_ITERINTLINKFUNC(pad)    (GST_PAD_CAST(pad)->iterintlinkfunc)
717
718 #define GST_PAD_PEER(pad)               (GST_PAD_CAST(pad)->peer)
719 #define GST_PAD_LINKFUNC(pad)           (GST_PAD_CAST(pad)->linkfunc)
720 #define GST_PAD_UNLINKFUNC(pad)         (GST_PAD_CAST(pad)->unlinkfunc)
721
722 #define GST_PAD_IS_SRC(pad)             (GST_PAD_DIRECTION(pad) == GST_PAD_SRC)
723 #define GST_PAD_IS_SINK(pad)            (GST_PAD_DIRECTION(pad) == GST_PAD_SINK)
724
725 #define GST_PAD_IS_LINKED(pad)          (GST_PAD_PEER(pad) != NULL)
726
727 #define GST_PAD_IS_ACTIVE(pad)          (GST_PAD_ACTIVATE_MODE(pad) != GST_PAD_ACTIVATE_NONE)
728
729 #define GST_PAD_IS_BLOCKED(pad)         (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_BLOCKED))
730 #define GST_PAD_IS_BLOCKING(pad)        (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_BLOCKING))
731
732 #define GST_PAD_IS_FLUSHING(pad)        (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_FLUSHING))
733 #define GST_PAD_SET_FLUSHING(pad)       (GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_FLUSHING))
734 #define GST_PAD_UNSET_FLUSHING(pad)     (GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_FLUSHING))
735
736 #define GST_PAD_NEEDS_RECONFIGURE(pad)  (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE))
737 #define GST_PAD_NEEDS_EVENTS(pad)       (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_NEED_EVENTS))
738 #define GST_PAD_IS_FIXED_CAPS(pad)      (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_FIXED_CAPS))
739 #define GST_PAD_NEEDS_PARENT(pad)       (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_NEED_PARENT))
740
741 #define GST_PAD_IS_PROXY_CAPS(pad)      (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_PROXY_CAPS))
742 #define GST_PAD_SET_PROXY_CAPS(pad)     (GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PROXY_CAPS))
743 #define GST_PAD_UNSET_PROXY_CAPS(pad)   (GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PROXY_CAPS))
744
745 /**
746  * GST_PAD_GET_STREAM_LOCK:
747  * @pad: a #GstPad
748  *
749  * Get the stream lock of @pad. The stream lock is protecting the
750  * resources used in the data processing functions of @pad.
751  */
752 #define GST_PAD_GET_STREAM_LOCK(pad)    (&(GST_PAD_CAST(pad)->stream_rec_lock))
753 /**
754  * GST_PAD_STREAM_LOCK:
755  * @pad: a #GstPad
756  *
757  * Lock the stream lock of @pad.
758  */
759 #define GST_PAD_STREAM_LOCK(pad)        (g_static_rec_mutex_lock(GST_PAD_GET_STREAM_LOCK(pad)))
760 /**
761  * GST_PAD_STREAM_TRYLOCK:
762  * @pad: a #GstPad
763  *
764  * Try to Lock the stream lock of the pad, return TRUE if the lock could be
765  * taken.
766  */
767 #define GST_PAD_STREAM_TRYLOCK(pad)     (g_static_rec_mutex_trylock(GST_PAD_GET_STREAM_LOCK(pad)))
768 /**
769  * GST_PAD_STREAM_UNLOCK:
770  * @pad: a #GstPad
771  *
772  * Unlock the stream lock of @pad.
773  */
774 #define GST_PAD_STREAM_UNLOCK(pad)      (g_static_rec_mutex_unlock(GST_PAD_GET_STREAM_LOCK(pad)))
775
776 #define GST_PAD_BLOCK_GET_COND(pad)     (GST_PAD_CAST(pad)->block_cond)
777 #define GST_PAD_BLOCK_WAIT(pad)         (g_cond_wait(GST_PAD_BLOCK_GET_COND (pad), GST_OBJECT_GET_LOCK (pad)))
778 #define GST_PAD_BLOCK_SIGNAL(pad)       (g_cond_signal(GST_PAD_BLOCK_GET_COND (pad)))
779 #define GST_PAD_BLOCK_BROADCAST(pad)    (g_cond_broadcast(GST_PAD_BLOCK_GET_COND (pad)))
780
781 GType                   gst_pad_get_type                        (void);
782
783 /* creating pads */
784 GstPad*                 gst_pad_new                             (const gchar *name, GstPadDirection direction);
785 GstPad*                 gst_pad_new_from_template               (GstPadTemplate *templ, const gchar *name);
786 GstPad*                 gst_pad_new_from_static_template        (GstStaticPadTemplate *templ, const gchar *name);
787
788
789 /**
790  * gst_pad_get_name:
791  * @pad: the pad to get the name from
792  *
793  * Get a copy of the name of the pad. g_free() after usage.
794  *
795  * MT safe.
796  */
797 #define gst_pad_get_name(pad) gst_object_get_name (GST_OBJECT_CAST (pad))
798 /**
799  * gst_pad_get_parent:
800  * @pad: the pad to get the parent of
801  *
802  * Get the parent of @pad. This function increases the refcount
803  * of the parent object so you should gst_object_unref() it after usage.
804  * Can return NULL if the pad did not have a parent.
805  *
806  * MT safe.
807  */
808 #define gst_pad_get_parent(pad) gst_object_get_parent (GST_OBJECT_CAST (pad))
809
810 GstPadDirection         gst_pad_get_direction                   (GstPad *pad);
811
812 gboolean                gst_pad_set_active                      (GstPad *pad, gboolean active);
813 gboolean                gst_pad_is_active                       (GstPad *pad);
814 gboolean                gst_pad_activate_pull                   (GstPad *pad, gboolean active);
815 gboolean                gst_pad_activate_push                   (GstPad *pad, gboolean active);
816
817 gulong                  gst_pad_add_probe                       (GstPad *pad,
818                                                                  GstPadProbeType mask,
819                                                                  GstPadProbeCallback callback,
820                                                                  gpointer user_data,
821                                                                  GDestroyNotify destroy_data);
822 void                    gst_pad_remove_probe                    (GstPad *pad, gulong id);
823
824 gboolean                gst_pad_is_blocked                      (GstPad *pad);
825 gboolean                gst_pad_is_blocking                     (GstPad *pad);
826
827 void                    gst_pad_mark_reconfigure                (GstPad *pad);
828 gboolean                gst_pad_check_reconfigure               (GstPad *pad);
829
830 void                    gst_pad_set_element_private             (GstPad *pad, gpointer priv);
831 gpointer                gst_pad_get_element_private             (GstPad *pad);
832
833 GstPadTemplate*         gst_pad_get_pad_template                (GstPad *pad);
834
835 GstEvent*               gst_pad_get_sticky_event                (GstPad *pad, GstEventType event_type);
836 GstFlowReturn           gst_pad_sticky_events_foreach           (GstPad *pad, GstPadStickyEventsForeachFunction foreach_func, gpointer user_data);
837
838 /* data passing setup functions */
839 void                    gst_pad_set_activate_function           (GstPad *pad, GstPadActivateFunction activate);
840 void                    gst_pad_set_activatepull_function       (GstPad *pad, GstPadActivateModeFunction activatepull);
841 void                    gst_pad_set_activatepush_function       (GstPad *pad, GstPadActivateModeFunction activatepush);
842 void                    gst_pad_set_chain_function              (GstPad *pad, GstPadChainFunction chain);
843 void                    gst_pad_set_chain_list_function         (GstPad *pad, GstPadChainListFunction chainlist);
844 void                    gst_pad_set_getrange_function           (GstPad *pad, GstPadGetRangeFunction get);
845 void                    gst_pad_set_event_function              (GstPad *pad, GstPadEventFunction event);
846
847 /* pad links */
848 void                    gst_pad_set_link_function               (GstPad *pad, GstPadLinkFunction link);
849 void                    gst_pad_set_unlink_function             (GstPad *pad, GstPadUnlinkFunction unlink);
850
851 gboolean                gst_pad_can_link                        (GstPad *srcpad, GstPad *sinkpad);
852 GstPadLinkReturn        gst_pad_link                            (GstPad *srcpad, GstPad *sinkpad);
853 GstPadLinkReturn        gst_pad_link_full                       (GstPad *srcpad, GstPad *sinkpad, GstPadLinkCheck flags);
854 gboolean                gst_pad_unlink                          (GstPad *srcpad, GstPad *sinkpad);
855 gboolean                gst_pad_is_linked                       (GstPad *pad);
856
857 GstPad*                 gst_pad_get_peer                        (GstPad *pad);
858
859 GstCaps*                gst_pad_get_pad_template_caps           (GstPad *pad);
860
861 /* capsnego function for linked/unlinked pads */
862 GstCaps *               gst_pad_get_current_caps                (GstPad * pad);
863 gboolean                gst_pad_has_current_caps                (GstPad * pad);
864 gboolean                gst_pad_set_caps                        (GstPad * pad, GstCaps *caps);
865
866 /* capsnego for linked pads */
867 GstCaps *               gst_pad_get_allowed_caps                (GstPad * pad);
868
869 /* pad offsets */
870 gint64                  gst_pad_get_offset                      (GstPad *pad);
871 void                    gst_pad_set_offset                      (GstPad *pad, gint64 offset);
872
873 /* data passing functions to peer */
874 GstFlowReturn           gst_pad_push                            (GstPad *pad, GstBuffer *buffer);
875 GstFlowReturn           gst_pad_push_list                       (GstPad *pad, GstBufferList *list);
876 GstFlowReturn           gst_pad_pull_range                      (GstPad *pad, guint64 offset, guint size,
877                                                                  GstBuffer **buffer);
878 gboolean                gst_pad_push_event                      (GstPad *pad, GstEvent *event);
879 gboolean                gst_pad_event_default                   (GstPad *pad, GstObject *parent,
880                                                                  GstEvent *event);
881
882 /* data passing functions on pad */
883 GstFlowReturn           gst_pad_chain                           (GstPad *pad, GstBuffer *buffer);
884 GstFlowReturn           gst_pad_chain_list                      (GstPad *pad, GstBufferList *list);
885 GstFlowReturn           gst_pad_get_range                       (GstPad *pad, guint64 offset, guint size,
886                                                                  GstBuffer **buffer);
887 gboolean                gst_pad_send_event                      (GstPad *pad, GstEvent *event);
888
889 /* pad tasks */
890 gboolean                gst_pad_start_task                      (GstPad *pad, GstTaskFunction func,
891                                                                  gpointer data);
892 gboolean                gst_pad_pause_task                      (GstPad *pad);
893 gboolean                gst_pad_stop_task                       (GstPad *pad);
894
895 /* internal links */
896 void                    gst_pad_set_iterate_internal_links_function (GstPad * pad,
897                                                                  GstPadIterIntLinkFunction iterintlink);
898 GstIterator *           gst_pad_iterate_internal_links          (GstPad * pad);
899 GstIterator *           gst_pad_iterate_internal_links_default  (GstPad * pad, GstObject *parent);
900
901
902 /* generic query function */
903 gboolean                gst_pad_query                           (GstPad *pad, GstQuery *query);
904 gboolean                gst_pad_peer_query                      (GstPad *pad, GstQuery *query);
905 void                    gst_pad_set_query_function              (GstPad *pad, GstPadQueryFunction query);
906 gboolean                gst_pad_query_default                   (GstPad *pad, GstObject *parent,
907                                                                  GstQuery *query);
908
909 /* misc helper functions */
910 gboolean                gst_pad_forward                         (GstPad *pad, GstPadForwardFunction forward,
911                                                                  gpointer user_data);
912
913 G_END_DECLS
914
915 #endif /* __GST_PAD_H__ */