pad: add GST_PAD_FLAG_ACCEPT_TEMPLATE
[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., 51 Franklin St, Fifth Floor,
20  * Boston, MA 02110-1301, 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 typedef struct _GstPadProbeInfo GstPadProbeInfo;
33
34 /**
35  * GstPadDirection:
36  * @GST_PAD_UNKNOWN: direction is unknown.
37  * @GST_PAD_SRC: the pad is a source pad.
38  * @GST_PAD_SINK: the pad is a sink pad.
39  *
40  * The direction of a pad.
41  */
42 typedef enum {
43   GST_PAD_UNKNOWN,
44   GST_PAD_SRC,
45   GST_PAD_SINK
46 } GstPadDirection;
47
48 /**
49  * GstPadMode:
50  * @GST_PAD_MODE_NONE: Pad will not handle dataflow
51  * @GST_PAD_MODE_PUSH: Pad handles dataflow in downstream push mode
52  * @GST_PAD_MODE_PULL: Pad handles dataflow in upstream pull mode
53  *
54  * The status of a GstPad. After activating a pad, which usually happens when the
55  * parent element goes from READY to PAUSED, the GstPadMode defines if the
56  * pad operates in push or pull mode.
57  */
58 typedef enum {
59   GST_PAD_MODE_NONE,
60   GST_PAD_MODE_PUSH,
61   GST_PAD_MODE_PULL
62 } GstPadMode;
63
64 const gchar   * gst_pad_mode_get_name (GstPadMode mode);
65
66 #include <gst/gstobject.h>
67 #include <gst/gstbuffer.h>
68 #include <gst/gstbufferlist.h>
69 #include <gst/gstcaps.h>
70 #include <gst/gstpadtemplate.h>
71 #include <gst/gstevent.h>
72 #include <gst/gstquery.h>
73 #include <gst/gsttask.h>
74
75 G_BEGIN_DECLS
76
77 /*
78  * Pad base class
79  */
80 #define GST_TYPE_PAD                    (gst_pad_get_type ())
81 #define GST_IS_PAD(obj)                 (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_PAD))
82 #define GST_IS_PAD_CLASS(klass)         (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_PAD))
83 #define GST_PAD(obj)                    (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_PAD, GstPad))
84 #define GST_PAD_CLASS(klass)            (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_PAD, GstPadClass))
85 #define GST_PAD_CAST(obj)               ((GstPad*)(obj))
86
87
88
89 /**
90  * GstPadLinkReturn:
91  * @GST_PAD_LINK_OK             : link succeeded
92  * @GST_PAD_LINK_WRONG_HIERARCHY: pads have no common grandparent
93  * @GST_PAD_LINK_WAS_LINKED     : pad was already linked
94  * @GST_PAD_LINK_WRONG_DIRECTION: pads have wrong direction
95  * @GST_PAD_LINK_NOFORMAT       : pads do not have common format
96  * @GST_PAD_LINK_NOSCHED        : pads cannot cooperate in scheduling
97  * @GST_PAD_LINK_REFUSED        : refused for some reason
98  *
99  * Result values from gst_pad_link and friends.
100  */
101 typedef enum {
102   GST_PAD_LINK_OK               =  0,
103   GST_PAD_LINK_WRONG_HIERARCHY  = -1,
104   GST_PAD_LINK_WAS_LINKED       = -2,
105   GST_PAD_LINK_WRONG_DIRECTION  = -3,
106   GST_PAD_LINK_NOFORMAT         = -4,
107   GST_PAD_LINK_NOSCHED          = -5,
108   GST_PAD_LINK_REFUSED          = -6
109 } GstPadLinkReturn;
110
111 /**
112  * GST_PAD_LINK_FAILED:
113  * @ret: the #GstPadLinkReturn value
114  *
115  * Macro to test if the given #GstPadLinkReturn value indicates a failed
116  * link step.
117  */
118 #define GST_PAD_LINK_FAILED(ret) ((ret) < GST_PAD_LINK_OK)
119
120 /**
121  * GST_PAD_LINK_SUCCESSFUL:
122  * @ret: the #GstPadLinkReturn value
123  *
124  * Macro to test if the given #GstPadLinkReturn value indicates a successful
125  * link step.
126  */
127 #define GST_PAD_LINK_SUCCESSFUL(ret) ((ret) >= GST_PAD_LINK_OK)
128
129 /**
130  * GstFlowReturn:
131  * @GST_FLOW_OK:                 Data passing was ok.
132  * @GST_FLOW_NOT_LINKED:         Pad is not linked.
133  * @GST_FLOW_FLUSHING:           Pad is flushing.
134  * @GST_FLOW_EOS:                Pad is EOS.
135  * @GST_FLOW_NOT_NEGOTIATED:     Pad is not negotiated.
136  * @GST_FLOW_ERROR:              Some (fatal) error occurred. Element generating
137  *                               this error should post an error message with more
138  *                               details.
139  * @GST_FLOW_NOT_SUPPORTED:      This operation is not supported.
140  * @GST_FLOW_CUSTOM_SUCCESS:     Elements can use values starting from
141  *                               this (and higher) to define custom success
142  *                               codes.
143  * @GST_FLOW_CUSTOM_SUCCESS_1:   Pre-defined custom success code (define your
144  *                               custom success code to this to avoid compiler
145  *                               warnings).
146  * @GST_FLOW_CUSTOM_SUCCESS_2:   Pre-defined custom success code.
147  * @GST_FLOW_CUSTOM_ERROR:       Elements can use values starting from
148  *                               this (and lower) to define custom error codes.
149  * @GST_FLOW_CUSTOM_ERROR_1:     Pre-defined custom error code (define your
150  *                               custom error code to this to avoid compiler
151  *                               warnings).
152  * @GST_FLOW_CUSTOM_ERROR_2:     Pre-defined custom error code.
153  *
154  * The result of passing data to a pad.
155  *
156  * Note that the custom return values should not be exposed outside of the
157  * element scope.
158  */
159 typedef enum {
160   /* custom success starts here */
161   GST_FLOW_CUSTOM_SUCCESS_2 = 102,
162   GST_FLOW_CUSTOM_SUCCESS_1 = 101,
163   GST_FLOW_CUSTOM_SUCCESS = 100,
164
165   /* core predefined */
166   GST_FLOW_OK             =  0,
167   /* expected failures */
168   GST_FLOW_NOT_LINKED     = -1,
169   GST_FLOW_FLUSHING       = -2,
170   /* error cases */
171   GST_FLOW_EOS            = -3,
172   GST_FLOW_NOT_NEGOTIATED = -4,
173   GST_FLOW_ERROR          = -5,
174   GST_FLOW_NOT_SUPPORTED  = -6,
175
176   /* custom error starts here */
177   GST_FLOW_CUSTOM_ERROR   = -100,
178   GST_FLOW_CUSTOM_ERROR_1 = -101,
179   GST_FLOW_CUSTOM_ERROR_2 = -102
180 } GstFlowReturn;
181
182 const gchar*            gst_flow_get_name (GstFlowReturn ret);
183 GQuark                            gst_flow_to_quark (GstFlowReturn ret);
184 const gchar*          gst_pad_link_get_name (GstPadLinkReturn ret);
185
186 /**
187  * GstPadLinkCheck:
188  * @GST_PAD_LINK_CHECK_NOTHING: Don't check hierarchy or caps compatibility.
189  * @GST_PAD_LINK_CHECK_HIERARCHY: Check the pads have same parents/grandparents.
190  *   Could be omitted if it is already known that the two elements that own the
191  *   pads are in the same bin.
192  * @GST_PAD_LINK_CHECK_TEMPLATE_CAPS: Check if the pads are compatible by using
193  *   their template caps. This is much faster than @GST_PAD_LINK_CHECK_CAPS, but
194  *   would be unsafe e.g. if one pad has %GST_CAPS_ANY.
195  * @GST_PAD_LINK_CHECK_CAPS: Check if the pads are compatible by comparing the
196  *   caps returned by gst_pad_query_caps().
197  * @GST_PAD_LINK_CHECK_DEFAULT: The default checks done when linking
198  *   pads (i.e. the ones used by gst_pad_link()).
199  *
200  * The amount of checking to be done when linking pads. @GST_PAD_LINK_CHECK_CAPS
201  * and @GST_PAD_LINK_CHECK_TEMPLATE_CAPS are mutually exclusive. If both are
202  * specified, expensive but safe @GST_PAD_LINK_CHECK_CAPS are performed.
203  *
204  * <warning><para>
205  * Only disable some of the checks if you are 100% certain you know the link
206  * will not fail because of hierarchy/caps compatibility failures. If uncertain,
207  * use the default checks (%GST_PAD_LINK_CHECK_DEFAULT) or the regular methods
208  * for linking the pads.
209  * </para></warning>
210  */
211
212 typedef enum {
213   GST_PAD_LINK_CHECK_NOTHING       = 0,
214   GST_PAD_LINK_CHECK_HIERARCHY     = 1 << 0,
215   GST_PAD_LINK_CHECK_TEMPLATE_CAPS = 1 << 1,
216   GST_PAD_LINK_CHECK_CAPS          = 1 << 2,
217
218   GST_PAD_LINK_CHECK_DEFAULT       = GST_PAD_LINK_CHECK_HIERARCHY | GST_PAD_LINK_CHECK_CAPS
219 } GstPadLinkCheck;
220
221 /* pad states */
222 /**
223  * GstPadActivateFunction:
224  * @pad: a #GstPad
225  * @parent: the parent of @pad
226  *
227  * This function is called when the pad is activated during the element
228  * READY to PAUSED state change. By default this function will call the
229  * activate function that puts the pad in push mode but elements can
230  * override this function to activate the pad in pull mode if they wish.
231  *
232  * Returns: %TRUE if the pad could be activated.
233  */
234 typedef gboolean                (*GstPadActivateFunction)       (GstPad *pad, GstObject *parent);
235 /**
236  * GstPadActivateModeFunction:
237  * @pad: a #GstPad
238  * @parent: the parent of @pad
239  * @mode: the requested activation mode of @pad
240  * @active: activate or deactivate the pad.
241  *
242  * The prototype of the push and pull activate functions.
243  *
244  * Returns: %TRUE if the pad could be activated or deactivated.
245  */
246 typedef gboolean                (*GstPadActivateModeFunction)   (GstPad *pad, GstObject *parent,
247                                                                  GstPadMode mode, gboolean active);
248
249
250 /* data passing */
251 /**
252  * GstPadChainFunction:
253  * @pad: the sink #GstPad that performed the chain.
254  * @parent: (allow-none): the parent of @pad. If the #GST_PAD_FLAG_NEED_PARENT
255  *          flag is set, @parent is guaranteed to be not-%NULL and remain valid
256  *          during the execution of this function.
257  * @buffer: (transfer full): the #GstBuffer that is chained, not %NULL.
258  *
259  * A function that will be called on sinkpads when chaining buffers.
260  * The function typically processes the data contained in the buffer and
261  * either consumes the data or passes it on to the internally linked pad(s).
262  *
263  * The implementer of this function receives a refcount to @buffer and should
264  * gst_buffer_unref() when the buffer is no longer needed.
265  *
266  * When a chain function detects an error in the data stream, it must post an
267  * error on the bus and return an appropriate #GstFlowReturn value.
268  *
269  * Returns: #GST_FLOW_OK for success
270  */
271 typedef GstFlowReturn           (*GstPadChainFunction)          (GstPad *pad, GstObject *parent,
272                                                                  GstBuffer *buffer);
273
274 /**
275  * GstPadChainListFunction:
276  * @pad: the sink #GstPad that performed the chain.
277  * @parent: (allow-none): the parent of @pad. If the #GST_PAD_FLAG_NEED_PARENT
278  *          flag is set, @parent is guaranteed to be not-%NULL and remain valid
279  *          during the execution of this function.
280  * @list: (transfer full): the #GstBufferList that is chained, not %NULL.
281  *
282  * A function that will be called on sinkpads when chaining buffer lists.
283  * The function typically processes the data contained in the buffer list and
284  * either consumes the data or passes it on to the internally linked pad(s).
285  *
286  * The implementer of this function receives a refcount to @list and
287  * should gst_buffer_list_unref() when the list is no longer needed.
288  *
289  * When a chainlist function detects an error in the data stream, it must
290  * post an error on the bus and return an appropriate #GstFlowReturn value.
291  *
292  * Returns: #GST_FLOW_OK for success
293  */
294 typedef GstFlowReturn           (*GstPadChainListFunction)      (GstPad *pad, GstObject *parent,
295                                                                  GstBufferList *list);
296
297 /**
298  * GstPadGetRangeFunction:
299  * @pad: the src #GstPad to perform the getrange on.
300  * @parent: (allow-none): the parent of @pad. If the #GST_PAD_FLAG_NEED_PARENT
301  *          flag is set, @parent is guaranteed to be not-%NULL and remain valid
302  *          during the execution of this function.
303  * @offset: the offset of the range
304  * @length: the length of the range
305  * @buffer: a memory location to hold the result buffer, cannot be %NULL.
306  *
307  * This function will be called on source pads when a peer element
308  * request a buffer at the specified @offset and @length. If this function
309  * returns #GST_FLOW_OK, the result buffer will be stored in @buffer. The
310  * contents of @buffer is invalid for any other return value.
311  *
312  * This function is installed on a source pad with
313  * gst_pad_set_getrange_function() and can only be called on source pads after
314  * they are successfully activated with gst_pad_activate_mode() with the
315  * #GST_PAD_MODE_PULL.
316  *
317  * @offset and @length are always given in byte units. @offset must normally be a value
318  * between 0 and the length in bytes of the data available on @pad. The
319  * length (duration in bytes) can be retrieved with a #GST_QUERY_DURATION or with a
320  * #GST_QUERY_SEEKING.
321  *
322  * Any @offset larger or equal than the length will make the function return
323  * #GST_FLOW_EOS, which corresponds to EOS. In this case @buffer does not
324  * contain a valid buffer.
325  *
326  * The buffer size of @buffer will only be smaller than @length when @offset is
327  * near the end of the stream. In all other cases, the size of @buffer must be
328  * exactly the requested size.
329  *
330  * It is allowed to call this function with a 0 @length and valid @offset, in
331  * which case @buffer will contain a 0-sized buffer and the function returns
332  * #GST_FLOW_OK.
333  *
334  * When this function is called with a -1 @offset, the sequentially next buffer
335  * of length @length in the stream is returned.
336  *
337  * When this function is called with a -1 @length, a buffer with a default
338  * optimal length is returned in @buffer. The length might depend on the value
339  * of @offset.
340  *
341  * Returns: #GST_FLOW_OK for success and a valid buffer in @buffer. Any other
342  * return value leaves @buffer undefined.
343  */
344 typedef GstFlowReturn           (*GstPadGetRangeFunction)       (GstPad *pad, GstObject *parent,
345                                                                  guint64 offset, guint length,
346                                                                  GstBuffer **buffer);
347
348 /**
349  * GstPadEventFunction:
350  * @pad: the #GstPad to handle the event.
351  * @parent: (allow-none): the parent of @pad. If the #GST_PAD_FLAG_NEED_PARENT
352  *          flag is set, @parent is guaranteed to be not-%NULL and remain valid
353  *          during the execution of this function.
354  * @event: (transfer full): the #GstEvent to handle.
355  *
356  * Function signature to handle an event for the pad.
357  *
358  * Returns: %TRUE if the pad could handle the event.
359  */
360 typedef gboolean                (*GstPadEventFunction)          (GstPad *pad, GstObject *parent,
361                                                                  GstEvent *event);
362
363
364 /* internal links */
365 /**
366  * GstPadIterIntLinkFunction:
367  * @pad: The #GstPad to query.
368  * @parent: (allow-none): the parent of @pad. If the #GST_PAD_FLAG_NEED_PARENT
369  *          flag is set, @parent is guaranteed to be not-%NULL and remain valid
370  *          during the execution of this function.
371  *
372  * The signature of the internal pad link iterator function.
373  *
374  * Returns: a new #GstIterator that will iterate over all pads that are
375  * linked to the given pad on the inside of the parent element.
376  *
377  * the caller must call gst_iterator_free() after usage.
378  */
379 typedef GstIterator*           (*GstPadIterIntLinkFunction)    (GstPad *pad, GstObject *parent);
380
381 /* generic query function */
382 /**
383  * GstPadQueryFunction:
384  * @pad: the #GstPad to query.
385  * @parent: (allow-none): the parent of @pad. If the #GST_PAD_FLAG_NEED_PARENT
386  *          flag is set, @parent is guaranteed to be not-%NULL and remain valid
387  *          during the execution of this function.
388  * @query: the #GstQuery object to execute
389  *
390  * The signature of the query function.
391  *
392  * Returns: %TRUE if the query could be performed.
393  */
394 typedef gboolean                (*GstPadQueryFunction)          (GstPad *pad, GstObject *parent,
395                                                                  GstQuery *query);
396
397
398 /* linking */
399 /**
400  * GstPadLinkFunction:
401  * @pad: the #GstPad that is linked.
402  * @parent: (allow-none): the parent of @pad. If the #GST_PAD_FLAG_NEED_PARENT
403  *          flag is set, @parent is guaranteed to be not-%NULL and remain valid
404  *          during the execution of this function.
405  * @peer: the peer #GstPad of the link
406  *
407  * Function signature to handle a new link on the pad.
408  *
409  * Returns: the result of the link with the specified peer.
410  */
411 typedef GstPadLinkReturn        (*GstPadLinkFunction)           (GstPad *pad, GstObject *parent, GstPad *peer);
412 /**
413  * GstPadUnlinkFunction:
414  * @pad: the #GstPad that is linked.
415  * @parent: (allow-none): the parent of @pad. If the #GST_PAD_FLAG_NEED_PARENT
416  *          flag is set, @parent is guaranteed to be not-%NULL and remain valid
417  *          during the execution of this function.
418  *
419  * Function signature to handle a unlinking the pad prom its peer.
420  */
421 typedef void                    (*GstPadUnlinkFunction)         (GstPad *pad, GstObject *parent);
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_EVENT_FLUSH: probe flush events. This probe has to be
447  *     explicitly enabled and is not included in the
448  *     @@GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM or
449  *     @@GST_PAD_PROBE_TYPE_EVENT_UPSTREAM probe types.
450  * @GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM: probe downstream queries
451  * @GST_PAD_PROBE_TYPE_QUERY_UPSTREAM: probe upstream queries
452  * @GST_PAD_PROBE_TYPE_PUSH: probe push
453  * @GST_PAD_PROBE_TYPE_PULL: probe pull
454  * @GST_PAD_PROBE_TYPE_BLOCKING: probe and block at the next opportunity, at data flow or when idle
455  * @GST_PAD_PROBE_TYPE_DATA_DOWNSTREAM: probe downstream data (buffers, buffer lists, and events)
456  * @GST_PAD_PROBE_TYPE_DATA_UPSTREAM: probe upstream data (events)
457  * @GST_PAD_PROBE_TYPE_DATA_BOTH: probe upstream and downstream data (buffers, buffer lists, and events)
458  * @GST_PAD_PROBE_TYPE_BLOCK_DOWNSTREAM: probe and block downstream data (buffers, buffer lists, and events)
459  * @GST_PAD_PROBE_TYPE_BLOCK_UPSTREAM: probe and block upstream data (events)
460  * @GST_PAD_PROBE_TYPE_EVENT_BOTH: probe upstream and downstream events
461  * @GST_PAD_PROBE_TYPE_QUERY_BOTH: probe upstream and downstream queries
462  * @GST_PAD_PROBE_TYPE_ALL_BOTH: probe upstream events and queries and downstream buffers, buffer lists, events and queries
463  * @GST_PAD_PROBE_TYPE_SCHEDULING: probe push and pull
464  *
465  * The different probing types that can occur. When either one of
466  * @GST_PAD_PROBE_TYPE_IDLE or @GST_PAD_PROBE_TYPE_BLOCK is used, the probe will be a
467  * blocking probe.
468  */
469 typedef enum
470 {
471   GST_PAD_PROBE_TYPE_INVALID          = 0,
472   /* flags to control blocking */
473   GST_PAD_PROBE_TYPE_IDLE             = (1 << 0),
474   GST_PAD_PROBE_TYPE_BLOCK            = (1 << 1),
475   /* flags to select datatypes */
476   GST_PAD_PROBE_TYPE_BUFFER           = (1 << 4),
477   GST_PAD_PROBE_TYPE_BUFFER_LIST      = (1 << 5),
478   GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM = (1 << 6),
479   GST_PAD_PROBE_TYPE_EVENT_UPSTREAM   = (1 << 7),
480   GST_PAD_PROBE_TYPE_EVENT_FLUSH      = (1 << 8),
481   GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM = (1 << 9),
482   GST_PAD_PROBE_TYPE_QUERY_UPSTREAM   = (1 << 10),
483   /* flags to select scheduling mode */
484   GST_PAD_PROBE_TYPE_PUSH             = (1 << 12),
485   GST_PAD_PROBE_TYPE_PULL             = (1 << 13),
486
487   /* flag combinations */
488   GST_PAD_PROBE_TYPE_BLOCKING         = GST_PAD_PROBE_TYPE_IDLE | GST_PAD_PROBE_TYPE_BLOCK,
489   GST_PAD_PROBE_TYPE_DATA_DOWNSTREAM  = GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM,
490   GST_PAD_PROBE_TYPE_DATA_UPSTREAM    = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM,
491   GST_PAD_PROBE_TYPE_DATA_BOTH        = GST_PAD_PROBE_TYPE_DATA_DOWNSTREAM | GST_PAD_PROBE_TYPE_DATA_UPSTREAM,
492   GST_PAD_PROBE_TYPE_BLOCK_DOWNSTREAM = GST_PAD_PROBE_TYPE_BLOCK | GST_PAD_PROBE_TYPE_DATA_DOWNSTREAM,
493   GST_PAD_PROBE_TYPE_BLOCK_UPSTREAM   = GST_PAD_PROBE_TYPE_BLOCK | GST_PAD_PROBE_TYPE_DATA_UPSTREAM,
494   GST_PAD_PROBE_TYPE_EVENT_BOTH       = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM | GST_PAD_PROBE_TYPE_EVENT_UPSTREAM,
495   GST_PAD_PROBE_TYPE_QUERY_BOTH       = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM | GST_PAD_PROBE_TYPE_QUERY_UPSTREAM,
496   GST_PAD_PROBE_TYPE_ALL_BOTH         = GST_PAD_PROBE_TYPE_DATA_BOTH | GST_PAD_PROBE_TYPE_QUERY_BOTH,
497   GST_PAD_PROBE_TYPE_SCHEDULING       = GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_PULL
498 } GstPadProbeType;
499
500
501 /**
502  * GstPadProbeReturn:
503  * @GST_PAD_PROBE_OK: normal probe return value. This leaves the probe in
504  *        place, and defers decisions about dropping or passing data to other
505  *        probes, if any. If there are no other probes, the default behaviour
506  *        for the probe type applies (block for blocking probes, and pass for
507  *        non-blocking probes).
508  * @GST_PAD_PROBE_DROP: drop data in data probes. For push mode this means that
509  *        the data item is not sent downstream. For pull mode, it means that
510  *        the data item is not passed upstream. In both cases, no more probes
511  *        are called and #GST_FLOW_OK or %TRUE is returned to the caller.
512  * @GST_PAD_PROBE_REMOVE: remove this probe.
513  * @GST_PAD_PROBE_PASS: pass the data item in the block probe and block on the
514  *        next item.
515  *
516  * Different return values for the #GstPadProbeCallback.
517  */
518 typedef enum
519 {
520   GST_PAD_PROBE_DROP,
521   GST_PAD_PROBE_OK,
522   GST_PAD_PROBE_REMOVE,
523   GST_PAD_PROBE_PASS,
524 } GstPadProbeReturn;
525
526
527 /**
528  * GstPadProbeInfo:
529  * @type: the current probe type
530  * @id: the id of the probe
531  * @data: (allow-none): type specific data, check the @type field to know the
532  *    datatype.  This field can be %NULL.
533  * @offset: offset of pull probe, this field is valid when @type contains
534  *    #GST_PAD_PROBE_TYPE_PULL
535  * @size: size of pull probe, this field is valid when @type contains
536  *    #GST_PAD_PROBE_TYPE_PULL
537  *
538  * Info passed in the #GstPadProbeCallback.
539  */
540 struct _GstPadProbeInfo
541 {
542   GstPadProbeType type;
543   gulong id;
544   gpointer data;
545   guint64 offset;
546   guint size;
547
548   /*< private >*/
549   gpointer _gst_reserved[GST_PADDING];
550 };
551
552 #define GST_PAD_PROBE_INFO_TYPE(d)         ((d)->type)
553 #define GST_PAD_PROBE_INFO_ID(d)           ((d)->id)
554 #define GST_PAD_PROBE_INFO_DATA(d)         ((d)->data)
555
556 #define GST_PAD_PROBE_INFO_BUFFER(d)       GST_BUFFER_CAST(GST_PAD_PROBE_INFO_DATA(d))
557 #define GST_PAD_PROBE_INFO_BUFFER_LIST(d)  GST_BUFFER_LIST_CAST(GST_PAD_PROBE_INFO_DATA(d))
558 #define GST_PAD_PROBE_INFO_EVENT(d)        GST_EVENT_CAST(GST_PAD_PROBE_INFO_DATA(d))
559 #define GST_PAD_PROBE_INFO_QUERY(d)        GST_QUERY_CAST(GST_PAD_PROBE_INFO_DATA(d))
560
561 #define GST_PAD_PROBE_INFO_OFFSET(d)       ((d)->offset)
562 #define GST_PAD_PROBE_INFO_SIZE(d)         ((d)->size)
563
564 GstEvent*      gst_pad_probe_info_get_event       (GstPadProbeInfo * info);
565 GstQuery*      gst_pad_probe_info_get_query       (GstPadProbeInfo * info);
566 GstBuffer*     gst_pad_probe_info_get_buffer      (GstPadProbeInfo * info);
567 GstBufferList* gst_pad_probe_info_get_buffer_list (GstPadProbeInfo * info);
568
569 /**
570  * GstPadProbeCallback:
571  * @pad: the #GstPad that is blocked
572  * @info: #GstPadProbeInfo
573  * @user_data: the gpointer to optional user data.
574  *
575  * Callback used by gst_pad_add_probe(). Gets called to notify about the current
576  * blocking type.
577  *
578  * The callback is allowed to modify the data pointer in @info.
579  *
580  * Returns: a #GstPadProbeReturn
581  */
582 typedef GstPadProbeReturn   (*GstPadProbeCallback)   (GstPad *pad, GstPadProbeInfo *info,
583                                                       gpointer user_data);
584
585 /**
586  * GstPadStickyEventsForeachFunction:
587  * @pad: the #GstPad.
588  * @event: (allow-none): a sticky #GstEvent.
589  * @user_data: the #gpointer to optional user data.
590  *
591  * Callback used by gst_pad_sticky_events_foreach().
592  *
593  * When this function returns %TRUE, the next event will be
594  * returned. When %FALSE is returned, gst_pad_sticky_events_foreach() will return.
595  *
596  * When @event is set to %NULL, the item will be removed from the list of sticky events.
597  * @event can be replaced by assigning a new reference to it.
598  * This function is responsible for unreffing the old event when
599  * removing or modifying.
600  *
601  * Returns: %TRUE if the iteration should continue
602  */
603 typedef gboolean  (*GstPadStickyEventsForeachFunction) (GstPad *pad, GstEvent **event,
604                                                         gpointer user_data);
605
606 /**
607  * GstPadFlags:
608  * @GST_PAD_FLAG_BLOCKED: is dataflow on a pad blocked
609  * @GST_PAD_FLAG_FLUSHING: is pad flushing
610  * @GST_PAD_FLAG_EOS: is pad in EOS state
611  * @GST_PAD_FLAG_BLOCKING: is pad currently blocking on a buffer or event
612  * @GST_PAD_FLAG_NEED_PARENT: ensure that there is a parent object before calling
613  *                       into the pad callbacks.
614  * @GST_PAD_FLAG_NEED_RECONFIGURE: the pad should be reconfigured/renegotiated.
615  *                            The flag has to be unset manually after
616  *                            reconfiguration happened.
617  * @GST_PAD_FLAG_PENDING_EVENTS: the pad has pending events
618  * @GST_PAD_FLAG_FIXED_CAPS: the pad is using fixed caps. This means that
619  *     once the caps are set on the pad, the default caps query function
620  *     will only return those caps.
621  * @GST_PAD_FLAG_PROXY_CAPS: the default event and query handler will forward
622  *                      all events and queries to the internally linked pads
623  *                      instead of discarding them.
624  * @GST_PAD_FLAG_PROXY_ALLOCATION: the default query handler will forward
625  *                      allocation queries to the internally linked pads
626  *                      instead of discarding them.
627  * @GST_PAD_FLAG_PROXY_SCHEDULING: the default query handler will forward
628  *                      scheduling queries to the internally linked pads
629  *                      instead of discarding them.
630  * @GST_PAD_FLAG_ACCEPT_INTERSECT: the default accept-caps handler will check
631  *                      it the caps intersect the query-caps result instead
632  *                      of checking for a subset. This is interesting for
633  *                      parsers that can accept incompletely specified caps.
634  * @GST_PAD_FLAG_ACCEPT_TEMPLATE: the default accept-caps handler will use
635  *                      the template pad caps instead of query caps to
636  *                      compare with the accept caps. Use this in combination
637  *                      with %GST_PAD_FLAG_ACCEPT_INTERSECT. (Since 1.6)
638  * @GST_PAD_FLAG_LAST: offset to define more flags
639  *
640  * Pad state flags
641  */
642 typedef enum {
643   GST_PAD_FLAG_BLOCKED          = (GST_OBJECT_FLAG_LAST << 0),
644   GST_PAD_FLAG_FLUSHING         = (GST_OBJECT_FLAG_LAST << 1),
645   GST_PAD_FLAG_EOS              = (GST_OBJECT_FLAG_LAST << 2),
646   GST_PAD_FLAG_BLOCKING         = (GST_OBJECT_FLAG_LAST << 3),
647   GST_PAD_FLAG_NEED_PARENT      = (GST_OBJECT_FLAG_LAST << 4),
648   GST_PAD_FLAG_NEED_RECONFIGURE = (GST_OBJECT_FLAG_LAST << 5),
649   GST_PAD_FLAG_PENDING_EVENTS   = (GST_OBJECT_FLAG_LAST << 6),
650   GST_PAD_FLAG_FIXED_CAPS       = (GST_OBJECT_FLAG_LAST << 7),
651   GST_PAD_FLAG_PROXY_CAPS       = (GST_OBJECT_FLAG_LAST << 8),
652   GST_PAD_FLAG_PROXY_ALLOCATION = (GST_OBJECT_FLAG_LAST << 9),
653   GST_PAD_FLAG_PROXY_SCHEDULING = (GST_OBJECT_FLAG_LAST << 10),
654   GST_PAD_FLAG_ACCEPT_INTERSECT = (GST_OBJECT_FLAG_LAST << 11),
655   GST_PAD_FLAG_ACCEPT_TEMPLATE  = (GST_OBJECT_FLAG_LAST << 12),
656   /* padding */
657   GST_PAD_FLAG_LAST        = (GST_OBJECT_FLAG_LAST << 16)
658 } GstPadFlags;
659
660 /**
661  * GstPad:
662  * @element_private: private data owned by the parent element
663  * @padtemplate: padtemplate for this pad
664  * @direction: the direction of the pad, cannot change after creating
665  *             the pad.
666  *
667  * The #GstPad structure. Use the functions to update the variables.
668  */
669 struct _GstPad {
670   GstObject                      object;
671
672   /*< public >*/
673   gpointer                       element_private;
674
675   GstPadTemplate                *padtemplate;
676
677   GstPadDirection                direction;
678
679   /*< private >*/
680   /* streaming rec_lock */
681   GRecMutex                      stream_rec_lock;
682   GstTask                       *task;
683
684   /* block cond, mutex is from the object */
685   GCond                          block_cond;
686   GHookList                      probes;
687
688   GstPadMode                     mode;
689   GstPadActivateFunction         activatefunc;
690   gpointer                       activatedata;
691   GDestroyNotify                 activatenotify;
692   GstPadActivateModeFunction     activatemodefunc;
693   gpointer                       activatemodedata;
694   GDestroyNotify                 activatemodenotify;
695
696   /* pad link */
697   GstPad                        *peer;
698   GstPadLinkFunction             linkfunc;
699   gpointer                       linkdata;
700   GDestroyNotify                 linknotify;
701   GstPadUnlinkFunction           unlinkfunc;
702   gpointer                       unlinkdata;
703   GDestroyNotify                 unlinknotify;
704
705   /* data transport functions */
706   GstPadChainFunction            chainfunc;
707   gpointer                       chaindata;
708   GDestroyNotify                 chainnotify;
709   GstPadChainListFunction        chainlistfunc;
710   gpointer                       chainlistdata;
711   GDestroyNotify                 chainlistnotify;
712   GstPadGetRangeFunction         getrangefunc;
713   gpointer                       getrangedata;
714   GDestroyNotify                 getrangenotify;
715   GstPadEventFunction            eventfunc;
716   gpointer                       eventdata;
717   GDestroyNotify                 eventnotify;
718
719   /* pad offset */
720   gint64                         offset;
721
722   /* generic query method */
723   GstPadQueryFunction            queryfunc;
724   gpointer                       querydata;
725   GDestroyNotify                 querynotify;
726
727   /* internal links */
728   GstPadIterIntLinkFunction      iterintlinkfunc;
729   gpointer                       iterintlinkdata;
730   GDestroyNotify                 iterintlinknotify;
731
732   /* counts number of probes attached. */
733   gint                           num_probes;
734   gint                           num_blocked;
735
736   GstPadPrivate                 *priv;
737
738   union {
739     gpointer _gst_reserved[GST_PADDING];
740     struct {
741       GstFlowReturn last_flowret;
742     } abi;
743   } ABI;
744 };
745
746 struct _GstPadClass {
747   GstObjectClass        parent_class;
748
749   /* signal callbacks */
750   void          (*linked)               (GstPad *pad, GstPad *peer);
751   void          (*unlinked)             (GstPad *pad, GstPad *peer);
752
753   /*< private >*/
754   gpointer _gst_reserved[GST_PADDING];
755 };
756
757
758 /***** helper macros *****/
759 /* GstPad */
760
761 /**
762  * GST_PAD_NAME:
763  * @pad: a #GstPad
764  *
765  * Get name of the given pad.
766  * No locking is performed in this function, use gst_pad_get_name() instead.
767  */
768 #define GST_PAD_NAME(pad)               (GST_OBJECT_NAME(pad))
769 /**
770  * GST_PAD_PARENT:
771  * @pad: a #GstPad
772  *
773  * Get the @pad parent.
774  * No locking is performed in this function, use gst_pad_get_parent() instead.
775  */
776 #define GST_PAD_PARENT(pad)             (GST_ELEMENT_CAST(GST_OBJECT_PARENT(pad)))
777 /**
778  * GST_PAD_ELEMENT_PRIVATE:
779  * @pad: a #GstPad
780  *
781  * Get the private data of @pad, which is usually some pad- or stream-specific
782  * structure created by the element and set on the pad when creating it.
783  * No locking is performed in this function.
784  */
785 #define GST_PAD_ELEMENT_PRIVATE(pad)    (GST_PAD_CAST(pad)->element_private)
786 /**
787  * GST_PAD_PAD_TEMPLATE:
788  * @pad: a #GstPad
789  *
790  * Get the @pad #GstPadTemplate. It describes the possible media types
791  * a @pad or an element factory can handle.
792  */
793 #define GST_PAD_PAD_TEMPLATE(pad)       (GST_PAD_CAST(pad)->padtemplate)
794 /**
795  * GST_PAD_DIRECTION:
796  * @pad: a #GstPad
797  *
798  * Get the #GstPadDirection of the given @pad. Accessor macro, use
799  * gst_pad_get_direction() instead.
800  */
801 #define GST_PAD_DIRECTION(pad)          (GST_PAD_CAST(pad)->direction)
802 /**
803  * GST_PAD_TASK:
804  * @pad: a #GstPad
805  *
806  * Get the #GstTask of @pad. Accessor macro used by GStreamer. Use the
807  * gst_pad_start_task(), gst_pad_stop_task() and gst_pad_pause_task()
808  * functions instead.
809  */
810 #define GST_PAD_TASK(pad)               (GST_PAD_CAST(pad)->task)
811 /**
812  * GST_PAD_MODE:
813  * @pad: a #GstPad
814  *
815  * Get the #GstPadMode of pad, which will be GST_PAD_MODE_NONE if the pad
816  * has not been activated yet, and otherwise either GST_PAD_MODE_PUSH or
817  * GST_PAD_MODE_PULL depending on which mode the pad was activated in.
818  */
819 #define GST_PAD_MODE(pad)               (GST_PAD_CAST(pad)->mode)
820 /**
821  * GST_PAD_ACTIVATEFUNC:
822  * @pad: a #GstPad
823  *
824  * Get the #GstPadActivateFunction from @pad.
825  */
826 #define GST_PAD_ACTIVATEFUNC(pad)       (GST_PAD_CAST(pad)->activatefunc)
827 /**
828  * GST_PAD_ACTIVATEMODEFUNC:
829  * @pad: a #GstPad
830  *
831  * Get the #GstPadActivateModeFunction from the given @pad.
832  */
833 #define GST_PAD_ACTIVATEMODEFUNC(pad)   (GST_PAD_CAST(pad)->activatemodefunc)
834 /**
835  * GST_PAD_CHAINFUNC:
836  * @pad: a #GstPad
837  *
838  * Get the #GstPadChainFunction from the given @pad.
839  */
840 #define GST_PAD_CHAINFUNC(pad)          (GST_PAD_CAST(pad)->chainfunc)
841 /**
842  * GST_PAD_CHAINLISTFUNC:
843  * @pad: a #GstPad
844  *
845  * Get the #GstPadChainListFunction from the given @pad.
846  */
847 #define GST_PAD_CHAINLISTFUNC(pad)      (GST_PAD_CAST(pad)->chainlistfunc)
848 /**
849  * GST_PAD_GETRANGEFUNC:
850  * @pad: a #GstPad
851  *
852  * Get the #GstPadGetRangeFunction from the given @pad.
853  */
854 #define GST_PAD_GETRANGEFUNC(pad)       (GST_PAD_CAST(pad)->getrangefunc)
855 /**
856  * GST_PAD_EVENTFUNC:
857  * @pad: a #GstPad
858  *
859  * Get the #GstPadEventFunction from the given @pad, which
860  * is the function that handles events on the pad. You can
861  * use this to set your own event handling function on a pad
862  * after you create it.  If your element derives from a base
863  * class, use the base class's virtual functions instead.
864  */
865 #define GST_PAD_EVENTFUNC(pad)          (GST_PAD_CAST(pad)->eventfunc)
866 /**
867  * GST_PAD_QUERYFUNC:
868  * @pad: a #GstPad
869  *
870  * Get the #GstPadQueryFunction from @pad, which is the function
871  * that handles queries on the pad. You can  use this to set your
872  * own query handling function on a pad after you create it. If your
873  * element derives from a base class, use the base class's virtual
874  * functions instead.
875  */
876 #define GST_PAD_QUERYFUNC(pad)          (GST_PAD_CAST(pad)->queryfunc)
877 /**
878  * GST_PAD_ITERINTLINKFUNC:
879  * @pad: a #GstPad
880  *
881  * Get the #GstPadIterIntLinkFunction from the given @pad.
882  */
883 #define GST_PAD_ITERINTLINKFUNC(pad)    (GST_PAD_CAST(pad)->iterintlinkfunc)
884 /**
885  * GST_PAD_PEER:
886  * @pad: a #GstPad
887  *
888  * Return the pad's peer member. This member is a pointer to the linked @pad.
889  * No locking is performed in this function, use gst_pad_get_peer() instead.
890  */
891 #define GST_PAD_PEER(pad)               (GST_PAD_CAST(pad)->peer)
892 /**
893  * GST_PAD_LINKFUNC:
894  * @pad: a #GstPad
895  *
896  * Get the #GstPadLinkFunction for the given @pad.
897  */
898 #define GST_PAD_LINKFUNC(pad)           (GST_PAD_CAST(pad)->linkfunc)
899 /**
900  * GST_PAD_UNLINKFUNC:
901  * @pad: a #GstPad
902  *
903  * Get the #GstPadUnlinkFunction from the given @pad.
904  */
905 #define GST_PAD_UNLINKFUNC(pad)         (GST_PAD_CAST(pad)->unlinkfunc)
906 /**
907  * GST_PAD_IS_SRC:
908  * @pad: a #GstPad
909  *
910  * Returns: %TRUE if the pad is a source pad (i.e. produces data).
911  */
912 #define GST_PAD_IS_SRC(pad)             (GST_PAD_DIRECTION(pad) == GST_PAD_SRC)
913 /**
914  * GST_PAD_IS_SINK:
915  * @pad: a #GstPad
916  *
917  * Returns: %TRUE if the pad is a sink pad (i.e. consumes data).
918  */
919 #define GST_PAD_IS_SINK(pad)            (GST_PAD_DIRECTION(pad) == GST_PAD_SINK)
920 /**
921  * GST_PAD_IS_LINKED:
922  * @pad: a #GstPad
923  *
924  * Returns: %TRUE if the pad is linked to another pad. Use gst_pad_is_linked()
925  * instead.
926  */
927 #define GST_PAD_IS_LINKED(pad)          (GST_PAD_PEER(pad) != NULL)
928 /**
929  * GST_PAD_IS_ACTIVE:
930  * @pad: a #GstPad
931  *
932  * Returns: %TRUE if the pad has been activated.
933  */
934 #define GST_PAD_IS_ACTIVE(pad)          (GST_PAD_MODE(pad) != GST_PAD_MODE_NONE)
935 /**
936  * GST_PAD_IS_BLOCKED:
937  * @pad: a #GstPad
938  *
939  * Check if the dataflow on a @pad is blocked. Use gst_pad_is_blocked() instead.
940  */
941 #define GST_PAD_IS_BLOCKED(pad)         (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_BLOCKED))
942 /**
943  * GST_PAD_IS_BLOCKING:
944  * @pad: a #GstPad
945  *
946  * Check if the @pad is currently blocking on a buffer or event. Use
947  * gst_pad_is_blocking() instead.
948  */
949 #define GST_PAD_IS_BLOCKING(pad)        (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_BLOCKING))
950 /**
951  * GST_PAD_IS_FLUSHING:
952  * @pad: a #GstPad
953  *
954  * Check if the given @pad is flushing.
955  */
956 #define GST_PAD_IS_FLUSHING(pad)        (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_FLUSHING))
957 /**
958  * GST_PAD_SET_FLUSHING:
959  * @pad: a #GstPad
960  *
961  * Set the given @pad to flushing state, which means it will not accept any
962  * more events, queries or buffers, and return GST_FLOW_FLUSHING if any buffers
963  * are pushed on it. This usually happens when the pad is shut down or when
964  * a flushing seek happens. This is used inside GStreamer when flush start/stop
965  * events pass through pads, or when an element state is changed and pads are
966  * activated or deactivated.
967  */
968 #define GST_PAD_SET_FLUSHING(pad)       (GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_FLUSHING))
969 /**
970  * GST_PAD_UNSET_FLUSHING:
971  * @pad: a #GstPad
972  *
973  * Unset the flushing flag.
974  */
975 #define GST_PAD_UNSET_FLUSHING(pad)     (GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_FLUSHING))
976 /**
977  * GST_PAD_IS_EOS:
978  * @pad: a #GstPad
979  *
980  * Check if the @pad is in EOS state.
981  */
982 #define GST_PAD_IS_EOS(pad)             (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_EOS))
983 /**
984  * GST_PAD_NEEDS_RECONFIGURE:
985  * @pad: a #GstPad
986  *
987  * Check if the @pad should be reconfigured/renegotiated.
988  * The flag has to be unset manually after reconfiguration happened.
989  * Use gst_pad_needs_reconfigure() or gst_pad_check_reconfigure() instead.
990  */
991 #define GST_PAD_NEEDS_RECONFIGURE(pad)  (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE))
992 /**
993  * GST_PAD_HAS_PENDING_EVENTS:
994  * @pad: a #GstPad
995  *
996  * Check if the given @pad has pending events. This is used internally by
997  * GStreamer.
998  */
999 #define GST_PAD_HAS_PENDING_EVENTS(pad) (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_PENDING_EVENTS))
1000 /**
1001  * GST_PAD_IS_FIXED_CAPS:
1002  * @pad: a #GstPad
1003  *
1004  * Check if the given @pad is using fixed caps, which means that
1005  * once the caps are set on the @pad, the caps query function will
1006  * only return those caps. See gst_pad_use_fixed_caps().
1007  */
1008 #define GST_PAD_IS_FIXED_CAPS(pad)      (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_FIXED_CAPS))
1009 /**
1010  * GST_PAD_NEEDS_PARENT:
1011  * @pad: a #GstPad
1012  *
1013  * Check if there is a parent object before calling into the @pad callbacks.
1014  * This is used internally by GStreamer.
1015  */
1016 #define GST_PAD_NEEDS_PARENT(pad)       (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_NEED_PARENT))
1017 /**
1018  * GST_PAD_IS_PROXY_CAPS:
1019  * @pad: a #GstPad
1020  *
1021  * Check if the given @pad is set to proxy caps. This means that the default
1022  * event and query handler will forward all events and queries to the
1023  * internally linked @pads instead of discarding them.
1024  */
1025 #define GST_PAD_IS_PROXY_CAPS(pad)      (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_PROXY_CAPS))
1026 /**
1027  * GST_PAD_SET_PROXY_CAPS:
1028  * @pad: a #GstPad
1029  *
1030  * Set @pad to proxy caps, so that all caps-related events and queries are
1031  * proxied down- or upstream to the other side of the element automatically.
1032  * Set this if the element always outputs data in the exact same format as it
1033  * receives as input. This is just for convenience to avoid implementing some
1034  * standard event and query handling code in an element.
1035  */
1036 #define GST_PAD_SET_PROXY_CAPS(pad)     (GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PROXY_CAPS))
1037 /**
1038  * GST_PAD_UNSET_PROXY_CAPS:
1039  * @pad: a #GstPad
1040  *
1041  * Unset proxy caps flag.
1042  */
1043 #define GST_PAD_UNSET_PROXY_CAPS(pad)   (GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PROXY_CAPS))
1044 /**
1045  * GST_PAD_IS_PROXY_ALLOCATION:
1046  * @pad: a #GstPad
1047  *
1048  * Check if the given @pad is set as proxy allocation which means
1049  * that the default query handler will forward allocation queries to the
1050  * internally linked @pads instead of discarding them.
1051  */
1052 #define GST_PAD_IS_PROXY_ALLOCATION(pad)    (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_PROXY_ALLOCATION))
1053 /**
1054  * GST_PAD_SET_PROXY_ALLOCATION:
1055  * @pad: a #GstPad
1056  *
1057  * Set @pad to proxy allocation queries, which means that the default query
1058  * handler will forward allocation queries to the internally linked @pads
1059  * instead of discarding them.
1060  * Set this if the element always outputs data in the exact same format as it
1061  * receives as input. This is just for convenience to avoid implementing some
1062  * standard query handling code in an element.
1063  */
1064 #define GST_PAD_SET_PROXY_ALLOCATION(pad)   (GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PROXY_ALLOCATION))
1065 /**
1066  * GST_PAD_UNSET_PROXY_ALLOCATION:
1067  * @pad: a #GstPad
1068  *
1069  * Unset proxy allocation flag.
1070  */
1071 #define GST_PAD_UNSET_PROXY_ALLOCATION(pad) (GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PROXY_ALLOCATION))
1072 /**
1073  * GST_PAD_IS_PROXY_SCHEDULING:
1074  * @pad: a #GstPad
1075  *
1076  * Check if the given @pad is set to proxy scheduling queries, which means that
1077  * the default query handler will forward scheduling queries to the internally
1078  * linked @pads instead of discarding them.
1079  */
1080 #define GST_PAD_IS_PROXY_SCHEDULING(pad)    (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_PROXY_SCHEDULING))
1081 /**
1082  * GST_PAD_SET_PROXY_SCHEDULING:
1083  * @pad: a #GstPad
1084  *
1085  * Set @pad to proxy scheduling queries, which means that the default query
1086  * handler will forward scheduling queries to the internally linked @pads
1087  * instead of discarding them. You will usually want to handle scheduling
1088  * queries explicitly if your element supports multiple scheduling modes.
1089  */
1090 #define GST_PAD_SET_PROXY_SCHEDULING(pad)   (GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PROXY_SCHEDULING))
1091 /**
1092  * GST_PAD_UNSET_PROXY_SCHEDULING:
1093  * @pad: a #GstPad
1094  *
1095  * Unset proxy scheduling flag.
1096  */
1097 #define GST_PAD_UNSET_PROXY_SCHEDULING(pad) (GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PROXY_SCHEDULING))
1098 /**
1099  * GST_PAD_IS_ACCEPT_INTERSECT:
1100  * @pad: a #GstPad
1101  *
1102  * Check if the pad's accept intersect flag is set. The default accept-caps
1103  * handler will check it the caps intersect the query-caps result instead of
1104  * checking for a subset. This is interesting for parser elements that can
1105  * accept incompletely specified caps.
1106  */
1107 #define GST_PAD_IS_ACCEPT_INTERSECT(pad)    (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_ACCEPT_INTERSECT))
1108 /**
1109  * GST_PAD_SET_ACCEPT_INTERSECT:
1110  * @pad: a #GstPad
1111  *
1112  * Set @pad to by default accept caps by intersecting the result instead of
1113  * checking for a subset. This is interesting for parser elements that can
1114  * accept incompletely specified caps.
1115  */
1116 #define GST_PAD_SET_ACCEPT_INTERSECT(pad)   (GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_ACCEPT_INTERSECT))
1117 /**
1118  * GST_PAD_UNSET_ACCEPT_INTERSECT:
1119  * @pad: a #GstPad
1120  *
1121  * Unset accept intersect flag.
1122  */
1123 #define GST_PAD_UNSET_ACCEPT_INTERSECT(pad) (GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_ACCEPT_INTERSECT))
1124 /**
1125  * GST_PAD_IS_ACCEPT_TEMPLATE:
1126  * @pad: a #GstPad
1127  *
1128  * Check if the pad's accept caps operation will use the pad template caps.
1129  * The default accept-caps will do a query caps to get the caps, which might
1130  * be querying downstream causing unnecessary overhead. It is recommended to
1131  * implement a proper accept-caps query handler or to use this flag to prevent
1132  * recursive accept-caps handling.
1133  *
1134  * Since: 1.6
1135  */
1136 #define GST_PAD_IS_ACCEPT_TEMPLATE(pad)    (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_ACCEPT_TEMPLATE))
1137 /**
1138  * GST_PAD_SET_ACCEPT_TEMPLATE:
1139  * @pad: a #GstPad
1140  *
1141  * Set @pad to by default use the pad template caps to compare with
1142  * the accept caps instead of using a caps query result.
1143  *
1144  * Since: 1.6
1145  */
1146 #define GST_PAD_SET_ACCEPT_TEMPLATE(pad)   (GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_ACCEPT_TEMPLATE))
1147 /**
1148  * GST_PAD_UNSET_ACCEPT_TEMPLATE:
1149  * @pad: a #GstPad
1150  *
1151  * Unset accept template flag.
1152  *
1153  * Since: 1.6
1154  */
1155 #define GST_PAD_UNSET_ACCEPT_TEMPLATE(pad) (GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_ACCEPT_TEMPLATE))
1156 /**
1157  * GST_PAD_GET_STREAM_LOCK:
1158  * @pad: a #GstPad
1159  *
1160  * Get the stream lock of @pad. The stream lock is protecting the
1161  * resources used in the data processing functions of @pad. Accessor
1162  * macro, use GST_PAD_STREAM_LOCK() and GST_PAD_STREAM_UNLOCK() instead
1163  * to take/release the pad's stream lock.
1164  */
1165 #define GST_PAD_GET_STREAM_LOCK(pad)    (&(GST_PAD_CAST(pad)->stream_rec_lock))
1166 /**
1167  * GST_PAD_STREAM_LOCK:
1168  * @pad: a #GstPad
1169  *
1170  * Take the pad's stream lock. The stream lock is recursive and will be taken
1171  * when buffers or serialized downstream events are pushed on a pad.
1172  */
1173 #define GST_PAD_STREAM_LOCK(pad)        g_rec_mutex_lock(GST_PAD_GET_STREAM_LOCK(pad))
1174 /**
1175  * GST_PAD_STREAM_TRYLOCK:
1176  * @pad: a #GstPad
1177  *
1178  * Try to take the pad's stream lock, and return %TRUE if the lock could be
1179  * taken, and otherwise %FALSE.
1180  */
1181 #define GST_PAD_STREAM_TRYLOCK(pad)     g_rec_mutex_trylock(GST_PAD_GET_STREAM_LOCK(pad))
1182 /**
1183  * GST_PAD_STREAM_UNLOCK:
1184  * @pad: a #GstPad
1185  *
1186  * Release the pad's stream lock.
1187  */
1188 #define GST_PAD_STREAM_UNLOCK(pad)      g_rec_mutex_unlock(GST_PAD_GET_STREAM_LOCK(pad))
1189 /**
1190  * GST_PAD_LAST_FLOW_RETURN:
1191  * @pad: a #GstPad
1192  *
1193  * Gets the last flow return on this pad
1194  *
1195  * Since: 1.4
1196  */
1197 #define GST_PAD_LAST_FLOW_RETURN(pad)   (GST_PAD_CAST(pad)->ABI.abi.last_flowret)
1198
1199 #define GST_PAD_BLOCK_GET_COND(pad)     (&GST_PAD_CAST(pad)->block_cond)
1200 #define GST_PAD_BLOCK_WAIT(pad)         (g_cond_wait(GST_PAD_BLOCK_GET_COND (pad), GST_OBJECT_GET_LOCK (pad)))
1201 #define GST_PAD_BLOCK_SIGNAL(pad)       (g_cond_signal(GST_PAD_BLOCK_GET_COND (pad)))
1202 #define GST_PAD_BLOCK_BROADCAST(pad)    (g_cond_broadcast(GST_PAD_BLOCK_GET_COND (pad)))
1203
1204 GType                   gst_pad_get_type                        (void);
1205
1206 /* creating pads */
1207 GstPad*                 gst_pad_new                             (const gchar *name, GstPadDirection direction);
1208 GstPad*                 gst_pad_new_from_template               (GstPadTemplate *templ, const gchar *name);
1209 GstPad*                 gst_pad_new_from_static_template        (GstStaticPadTemplate *templ, const gchar *name);
1210
1211
1212 /**
1213  * gst_pad_get_name:
1214  * @pad: the pad to get the name from
1215  *
1216  * Get a copy of the name of the pad. g_free() after usage.
1217  *
1218  * MT safe.
1219  */
1220 #define gst_pad_get_name(pad) gst_object_get_name (GST_OBJECT_CAST (pad))
1221 /**
1222  * gst_pad_get_parent:
1223  * @pad: the pad to get the parent of
1224  *
1225  * Get the parent of @pad. This function increases the refcount
1226  * of the parent object so you should gst_object_unref() it after usage.
1227  * Can return %NULL if the pad did not have a parent.
1228  *
1229  * MT safe.
1230  *
1231  * Returns: (nullable): the parent
1232  */
1233 #define gst_pad_get_parent(pad) gst_object_get_parent (GST_OBJECT_CAST (pad))
1234
1235 GstPadDirection         gst_pad_get_direction                   (GstPad *pad);
1236
1237 gboolean                gst_pad_set_active                      (GstPad *pad, gboolean active);
1238 gboolean                gst_pad_is_active                       (GstPad *pad);
1239 gboolean                gst_pad_activate_mode                   (GstPad *pad, GstPadMode mode,
1240                                                                  gboolean active);
1241
1242 gulong                  gst_pad_add_probe                       (GstPad *pad,
1243                                                                  GstPadProbeType mask,
1244                                                                  GstPadProbeCallback callback,
1245                                                                  gpointer user_data,
1246                                                                  GDestroyNotify destroy_data);
1247 void                    gst_pad_remove_probe                    (GstPad *pad, gulong id);
1248
1249 gboolean                gst_pad_is_blocked                      (GstPad *pad);
1250 gboolean                gst_pad_is_blocking                     (GstPad *pad);
1251
1252 void                    gst_pad_mark_reconfigure                (GstPad *pad);
1253 gboolean                gst_pad_needs_reconfigure               (GstPad *pad);
1254 gboolean                gst_pad_check_reconfigure               (GstPad *pad);
1255
1256 void                    gst_pad_set_element_private             (GstPad *pad, gpointer priv);
1257 gpointer                gst_pad_get_element_private             (GstPad *pad);
1258
1259 GstPadTemplate*         gst_pad_get_pad_template                (GstPad *pad);
1260
1261 GstFlowReturn           gst_pad_store_sticky_event              (GstPad *pad, GstEvent *event);
1262 GstEvent*               gst_pad_get_sticky_event                (GstPad *pad, GstEventType event_type,
1263                                                                  guint idx);
1264 void                    gst_pad_sticky_events_foreach           (GstPad *pad, GstPadStickyEventsForeachFunction foreach_func, gpointer user_data);
1265
1266 /* data passing setup functions */
1267 void                    gst_pad_set_activate_function_full      (GstPad *pad,
1268                                                                  GstPadActivateFunction activate,
1269                                                                  gpointer user_data,
1270                                                                  GDestroyNotify notify);
1271 void                    gst_pad_set_activatemode_function_full  (GstPad *pad,
1272                                                                  GstPadActivateModeFunction activatemode,
1273                                                                  gpointer user_data,
1274                                                                  GDestroyNotify notify);
1275 /* data passing functions */
1276 void                    gst_pad_set_chain_function_full         (GstPad *pad,
1277                                                                  GstPadChainFunction chain,
1278                                                                  gpointer user_data,
1279                                                                  GDestroyNotify notify);
1280 void                    gst_pad_set_chain_list_function_full    (GstPad *pad,
1281                                                                  GstPadChainListFunction chainlist,
1282                                                                  gpointer user_data,
1283                                                                  GDestroyNotify notify);
1284 void                    gst_pad_set_getrange_function_full      (GstPad *pad,
1285                                                                  GstPadGetRangeFunction get,
1286                                                                  gpointer user_data,
1287                                                                  GDestroyNotify notify);
1288 void                    gst_pad_set_event_function_full         (GstPad *pad,
1289                                                                  GstPadEventFunction event,
1290                                                                  gpointer user_data,
1291                                                                  GDestroyNotify notify);
1292
1293 #define gst_pad_set_activate_function(p,f)      gst_pad_set_activate_function_full((p),(f),NULL,NULL)
1294 #define gst_pad_set_activatemode_function(p,f)  gst_pad_set_activatemode_function_full((p),(f),NULL,NULL)
1295 #define gst_pad_set_chain_function(p,f)         gst_pad_set_chain_function_full((p),(f),NULL,NULL)
1296 #define gst_pad_set_chain_list_function(p,f)    gst_pad_set_chain_list_function_full((p),(f),NULL,NULL)
1297 #define gst_pad_set_getrange_function(p,f)      gst_pad_set_getrange_function_full((p),(f),NULL,NULL)
1298 #define gst_pad_set_event_function(p,f)         gst_pad_set_event_function_full((p),(f),NULL,NULL)
1299
1300 /* pad links */
1301 void                    gst_pad_set_link_function_full          (GstPad *pad,
1302                                                                  GstPadLinkFunction link,
1303                                                                  gpointer user_data,
1304                                                                  GDestroyNotify notify);
1305 void                    gst_pad_set_unlink_function_full        (GstPad *pad,
1306                                                                  GstPadUnlinkFunction unlink,
1307                                                                  gpointer user_data,
1308                                                                  GDestroyNotify notify);
1309
1310 #define gst_pad_set_link_function(p,f)          gst_pad_set_link_function_full((p),(f),NULL,NULL)
1311 #define gst_pad_set_unlink_function(p,f)        gst_pad_set_unlink_function_full((p),(f),NULL,NULL)
1312
1313 gboolean                gst_pad_can_link                        (GstPad *srcpad, GstPad *sinkpad);
1314 GstPadLinkReturn        gst_pad_link                            (GstPad *srcpad, GstPad *sinkpad);
1315 GstPadLinkReturn        gst_pad_link_full                       (GstPad *srcpad, GstPad *sinkpad, GstPadLinkCheck flags);
1316 gboolean                gst_pad_unlink                          (GstPad *srcpad, GstPad *sinkpad);
1317 gboolean                gst_pad_is_linked                       (GstPad *pad);
1318
1319 GstPad*                 gst_pad_get_peer                        (GstPad *pad);
1320
1321 GstCaps*                gst_pad_get_pad_template_caps           (GstPad *pad);
1322
1323 /* capsnego function for linked/unlinked pads */
1324 GstCaps *               gst_pad_get_current_caps                (GstPad * pad);
1325 gboolean                gst_pad_has_current_caps                (GstPad * pad);
1326
1327 /* capsnego for linked pads */
1328 GstCaps *               gst_pad_get_allowed_caps                (GstPad * pad);
1329
1330 /* pad offsets */
1331 gint64                  gst_pad_get_offset                      (GstPad *pad);
1332 void                    gst_pad_set_offset                      (GstPad *pad, gint64 offset);
1333
1334 /* data passing functions to peer */
1335 GstFlowReturn           gst_pad_push                            (GstPad *pad, GstBuffer *buffer);
1336 GstFlowReturn           gst_pad_push_list                       (GstPad *pad, GstBufferList *list);
1337 GstFlowReturn           gst_pad_pull_range                      (GstPad *pad, guint64 offset, guint size,
1338                                                                  GstBuffer **buffer);
1339 gboolean                gst_pad_push_event                      (GstPad *pad, GstEvent *event);
1340 gboolean                gst_pad_event_default                   (GstPad *pad, GstObject *parent,
1341                                                                  GstEvent *event);
1342 GstFlowReturn           gst_pad_get_last_flow_return            (GstPad *pad);
1343
1344 /* data passing functions on pad */
1345 GstFlowReturn           gst_pad_chain                           (GstPad *pad, GstBuffer *buffer);
1346 GstFlowReturn           gst_pad_chain_list                      (GstPad *pad, GstBufferList *list);
1347 GstFlowReturn           gst_pad_get_range                       (GstPad *pad, guint64 offset, guint size,
1348                                                                  GstBuffer **buffer);
1349 gboolean                gst_pad_send_event                      (GstPad *pad, GstEvent *event);
1350
1351 /* pad tasks */
1352 gboolean                gst_pad_start_task                      (GstPad *pad, GstTaskFunction func,
1353                                                                  gpointer user_data, GDestroyNotify notify);
1354 gboolean                gst_pad_pause_task                      (GstPad *pad);
1355 gboolean                gst_pad_stop_task                       (GstPad *pad);
1356
1357 /* internal links */
1358 void                    gst_pad_set_iterate_internal_links_function_full (GstPad * pad,
1359                                                                  GstPadIterIntLinkFunction iterintlink,
1360                                                                  gpointer user_data,
1361                                                                  GDestroyNotify notify);
1362 GstIterator *           gst_pad_iterate_internal_links          (GstPad * pad);
1363 GstIterator *           gst_pad_iterate_internal_links_default  (GstPad * pad, GstObject *parent);
1364
1365 #define gst_pad_set_iterate_internal_links_function(p,f) gst_pad_set_iterate_internal_links_function_full((p),(f),NULL,NULL)
1366
1367 /* generic query function */
1368 gboolean                gst_pad_query                           (GstPad *pad, GstQuery *query);
1369 gboolean                gst_pad_peer_query                      (GstPad *pad, GstQuery *query);
1370 void                    gst_pad_set_query_function_full         (GstPad *pad, GstPadQueryFunction query,
1371                                                                  gpointer user_data,
1372                                                                  GDestroyNotify notify);
1373 gboolean                gst_pad_query_default                   (GstPad *pad, GstObject *parent,
1374                                                                  GstQuery *query);
1375
1376 #define gst_pad_set_query_function(p,f)   gst_pad_set_query_function_full((p),(f),NULL,NULL)
1377
1378 /* misc helper functions */
1379 gboolean                gst_pad_forward                         (GstPad *pad, GstPadForwardFunction forward,
1380                                                                  gpointer user_data);
1381
1382 G_END_DECLS
1383
1384 #endif /* __GST_PAD_H__ */