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