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