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