GstPad: Add new pad linking method with configurable checks.
[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 /**
153  * GST_FLOW_IS_FATAL:
154  * @ret: a #GstFlowReturn value
155  *
156  * Macro to test if the given #GstFlowReturn value indicates a fatal
157  * error. This macro is mainly used in elements driving the pipeline to decide
158  * whether an error message should be posted on the bus. Note that such
159  * elements may also need to post an error message in the #GST_FLOW_NOT_LINKED
160  * case which is not caught by this macro.
161  */
162 #define GST_FLOW_IS_FATAL(ret) ((ret) <= GST_FLOW_UNEXPECTED)
163
164 /**
165  * GST_FLOW_IS_SUCCESS:
166  * @ret: a #GstFlowReturn value
167  *
168  * Macro to test if the given #GstFlowReturn value indicates a
169  * successfull result
170  * This macro is mainly used in elements to decide if the processing
171  * of a buffer was successfull.
172  *
173  * Since: 0.10.7
174  */
175 #define GST_FLOW_IS_SUCCESS(ret) ((ret) >= GST_FLOW_OK)
176
177 G_CONST_RETURN gchar*   gst_flow_get_name       (GstFlowReturn ret);
178 GQuark                  gst_flow_to_quark       (GstFlowReturn ret);
179
180 /**
181  * GstPadLinkCheck:
182  * @GST_PAD_LINK_CHECK_NOTHING: Don't check hierarchy or compatibily
183  * @GST_PAD_LINK_CHECK_HIERARCHY: Check the pads have same parents/grandparents
184  * @GST_PAD_LINK_CHECK_TEMPLATE_CAPS: Check if the pads are compatible by using their
185  * template caps.
186  * @GST_PAD_LINK_CHECK_CAPS: Check if the pads are compatible by checking their full caps
187  *
188  * The amount of check to be done when linking pads.
189  *
190  * Since: 0.10.30
191  */
192
193 typedef enum {
194   GST_PAD_LINK_CHECK_NOTHING       = 1 << 0,
195   GST_PAD_LINK_CHECK_HIERARCHY     = 1 << 1,
196   GST_PAD_LINK_CHECK_TEMPLATE_CAPS = 1 << 2,
197   GST_PAD_LINK_CHECK_CAPS          = 1 << 3,
198 } GstPadLinkCheck;
199
200 /**
201  * GST_PAD_LINK_CHECK_DEFAULT:
202  *
203  * The default checks done when linking pads (i.e. the ones used by #gst_pad_link.
204  *
205  * Since: 0.10.30
206  */
207 #define GST_PAD_LINK_CHECK_DEFAULT (GST_PAD_LINK_CHECK_HIERARCHY | GST_PAD_LINK_CHECK_CAPS)
208
209 /**
210  * GstActivateMode:
211  * @GST_ACTIVATE_NONE:           Pad will not handle dataflow
212  * @GST_ACTIVATE_PUSH:           Pad handles dataflow in downstream push mode
213  * @GST_ACTIVATE_PULL:           Pad handles dataflow in upstream pull mode
214  *
215  * The status of a GstPad. After activating a pad, which usually happens when the
216  * parent element goes from READY to PAUSED, the GstActivateMode defines if the
217  * pad operates in push or pull mode.
218  */
219 typedef enum {
220   GST_ACTIVATE_NONE,
221   GST_ACTIVATE_PUSH,
222   GST_ACTIVATE_PULL
223 } GstActivateMode;
224
225 /**
226  * GST_PAD_MODE_ACTIVATE:
227  * @mode: a #GstActivateMode
228  *
229  * Macro to test if the given #GstActivateMode value indicates that datapassing
230  * is possible or not.
231  */
232 #define GST_PAD_MODE_ACTIVATE(mode) ((mode) != GST_ACTIVATE_NONE)
233
234 /* pad states */
235 /**
236  * GstPadActivateFunction:
237  * @pad: a #GstPad
238  *
239  * This function is called when the pad is activated during the element
240  * READY to PAUSED state change. By default this function will call the
241  * activate function that puts the pad in push mode but elements can
242  * override this function to activate the pad in pull mode if they wish.
243  *
244  * Returns: TRUE if the pad could be activated.
245  */
246 typedef gboolean                (*GstPadActivateFunction)       (GstPad *pad);
247 /**
248  * GstPadActivateModeFunction:
249  * @pad: a #GstPad
250  * @active: activate or deactivate the pad.
251  *
252  * The prototype of the push and pull activate functions.
253  *
254  * Returns: TRUE if the pad could be activated or deactivated.
255  */
256 typedef gboolean                (*GstPadActivateModeFunction)   (GstPad *pad, gboolean active);
257
258
259 /* data passing */
260 /**
261  * GstPadChainFunction:
262  * @pad: the sink #GstPad that performed the chain.
263  * @buffer: the #GstBuffer that is chained, not %NULL.
264  *
265  * A function that will be called on sinkpads when chaining buffers.
266  * The function typically processes the data contained in the buffer and
267  * either consumes the data or passes it on to the internally linked pad(s).
268  *
269  * The implementer of this function receives a refcount to @buffer and should
270  * gst_buffer_unref() when the buffer is no longer needed.
271  *
272  * When a chain function detects an error in the data stream, it must post an
273  * error on the bus and return an appropriate #GstFlowReturn value.
274  *
275  * Returns: #GST_FLOW_OK for success
276  */
277 typedef GstFlowReturn           (*GstPadChainFunction)          (GstPad *pad, GstBuffer *buffer);
278
279 /**
280  * GstPadChainListFunction:
281  * @pad: the sink #GstPad that performed the chain.
282  * @list: 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, GstBufferList *list);
297
298 /**
299  * GstPadGetRangeFunction:
300  * @pad: the src #GstPad to perform the getrange on.
301  * @offset: the offset of the range
302  * @length: the length of the range
303  * @buffer: a memory location to hold the result buffer, cannot be NULL.
304  *
305  * This function will be called on source pads when a peer element
306  * request a buffer at the specified @offset and @length. If this function
307  * returns #GST_FLOW_OK, the result buffer will be stored in @buffer. The
308  * contents of @buffer is invalid for any other return value.
309  *
310  * This function is installed on a source pad with
311  * gst_pad_set_getrange_function() and can only be called on source pads after
312  * they are successfully activated with gst_pad_activate_pull().
313  *
314  * @offset and @length are always given in byte units. @offset must normally be a value
315  * between 0 and the length in bytes of the data available on @pad. The
316  * length (duration in bytes) can be retrieved with a #GST_QUERY_DURATION or with a
317  * #GST_QUERY_SEEKING.
318  *
319  * Any @offset larger or equal than the length will make the function return
320  * #GST_FLOW_UNEXPECTED, which corresponds to EOS. In this case @buffer does not
321  * contain a valid buffer.
322  *
323  * The buffer size of @buffer will only be smaller than @length when @offset is
324  * near the end of the stream. In all other cases, the size of @buffer must be
325  * exactly the requested size.
326  *
327  * It is allowed to call this function with a 0 @length and valid @offset, in
328  * which case @buffer will contain a 0-sized buffer and the function returns
329  * #GST_FLOW_OK.
330  *
331  * When this function is called with a -1 @offset, the sequentially next buffer
332  * of length @length in the stream is returned.
333  *
334  * When this function is called with a -1 @length, a buffer with a default
335  * optimal length is returned in @buffer. The length might depend on the value
336  * of @offset.
337  *
338  * Returns: #GST_FLOW_OK for success and a valid buffer in @buffer. Any other
339  * return value leaves @buffer undefined.
340  */
341 typedef GstFlowReturn           (*GstPadGetRangeFunction)       (GstPad *pad, guint64 offset,
342                                                                  guint length, GstBuffer **buffer);
343
344 /**
345  * GstPadEventFunction:
346  * @pad: the #GstPad to handle the event.
347  * @event: the #GstEvent to handle.
348  *
349  * Function signature to handle an event for the pad.
350  *
351  * Returns: TRUE if the pad could handle the event.
352  */
353 typedef gboolean                (*GstPadEventFunction)          (GstPad *pad, GstEvent *event);
354
355
356 /* FIXME: 0.11: deprecate me, check range should use seeking query */
357 /**
358  * GstPadCheckGetRangeFunction:
359  * @pad: a #GstPad
360  *
361  * Check if @pad can be activated in pull mode.
362  *
363  * This function will be deprecated after 0.10; use the seeking query to check
364  * if a pad can support random access.
365  *
366  * Returns: TRUE if the pad can operate in pull mode.
367  */
368 typedef gboolean                (*GstPadCheckGetRangeFunction)  (GstPad *pad);
369
370 /* internal links */
371 /**
372  * GstPadIntLinkFunction:
373  * @pad: The #GstPad to query.
374  *
375  * The signature of the internal pad link function.
376  *
377  * Returns: (element-type Gst.Pad) (transfer container): a newly allocated #GList of pads that are linked to the given pad on
378  * the inside of the parent element.
379  *
380  * The caller must call g_list_free() on it after use.
381  *
382  * Deprecated: use the threadsafe #GstPadIterIntLinkFunction instead.
383  */
384 typedef GList*                  (*GstPadIntLinkFunction)        (GstPad *pad);
385
386 /**
387  * GstPadIterIntLinkFunction:
388  * @pad: The #GstPad to query.
389  *
390  * The signature of the internal pad link iterator function.
391  *
392  * Returns: a new #GstIterator that will iterate over all pads that are
393  * linked to the given pad on the inside of the parent element.
394  *
395  * the caller must call gst_iterator_free() after usage.
396  *
397  * Since 0.10.21
398  */
399 typedef GstIterator*           (*GstPadIterIntLinkFunction)    (GstPad *pad);
400
401 /* generic query function */
402 /**
403  * GstPadQueryTypeFunction:
404  * @pad: a #GstPad to query
405  *
406  * The signature of the query types function.
407  *
408  * Returns: a constant array of query types
409  */
410 typedef const GstQueryType*     (*GstPadQueryTypeFunction)      (GstPad *pad);
411
412 /**
413  * GstPadQueryFunction:
414  * @pad: the #GstPad to query.
415  * @query: the #GstQuery object to execute
416  *
417  * The signature of the query function.
418  *
419  * Returns: TRUE if the query could be performed.
420  */
421 typedef gboolean                (*GstPadQueryFunction)          (GstPad *pad, GstQuery *query);
422
423
424 /* linking */
425 /**
426  * GstPadLinkFunction
427  * @pad: the #GstPad that is linked.
428  * @peer: the peer #GstPad of the link
429  *
430  * Function signature to handle a new link on the pad.
431  *
432  * Returns: the result of the link with the specified peer.
433  */
434 typedef GstPadLinkReturn        (*GstPadLinkFunction)           (GstPad *pad, GstPad *peer);
435 /**
436  * GstPadUnlinkFunction
437  * @pad: the #GstPad that is linked.
438  *
439  * Function signature to handle a unlinking the pad prom its peer.
440  */
441 typedef void                    (*GstPadUnlinkFunction)         (GstPad *pad);
442
443
444 /* caps nego */
445 /**
446  * GstPadGetCapsFunction:
447  * @pad: the #GstPad to get the capabilities of.
448  *
449  * Returns a copy of the capabilities of the specified pad. By default this
450  * function will return the pad template capabilities, but can optionally
451  * be overridden by elements.
452  *
453  * Returns: a newly allocated copy #GstCaps of the pad.
454  */
455 typedef GstCaps*                (*GstPadGetCapsFunction)        (GstPad *pad);
456
457 /**
458  * GstPadSetCapsFunction:
459  * @pad: the #GstPad to set the capabilities of.
460  * @caps: the #GstCaps to set
461  *
462  * Set @caps on @pad. By default this function updates the caps of the
463  * pad but the function can be overriden by elements to perform extra
464  * actions or verifications.
465  *
466  * Returns: TRUE if the caps could be set on the pad.
467  */
468 typedef gboolean                (*GstPadSetCapsFunction)        (GstPad *pad, GstCaps *caps);
469 /**
470  * GstPadAcceptCapsFunction:
471  * @pad: the #GstPad to check
472  * @caps: the #GstCaps to check
473  *
474  * Check if @pad can accept @caps. By default this function will see if @caps
475  * intersect with the result from gst_pad_get_caps() by can be overridden to
476  * perform extra checks.
477  *
478  * Returns: TRUE if the caps can be accepted by the pad.
479  */
480 typedef gboolean                (*GstPadAcceptCapsFunction)     (GstPad *pad, GstCaps *caps);
481 /**
482  * GstPadFixateCapsFunction:
483  * @pad: a #GstPad
484  * @caps: the #GstCaps to fixate
485  *
486  * Given possibly unfixed caps @caps, let @pad use its default prefered
487  * format to make a fixed caps. @caps should be writable. By default this
488  * function will pick the first value of any ranges or lists in the caps but
489  * elements can override this function to perform other behaviour.
490  */
491 typedef void                    (*GstPadFixateCapsFunction)     (GstPad *pad, GstCaps *caps);
492 /**
493  * GstPadBufferAllocFunction:
494  * @pad: a sink #GstPad
495  * @offset: the desired offset of the buffer
496  * @size: the desired size of the buffer
497  * @caps: the desired caps of the buffer
498  * @buf: pointer to hold the allocated buffer.
499  *
500  * Ask the sinkpad @pad to allocate a buffer with @offset, @size and @caps.
501  * The result will be stored in @buf.
502  *
503  * The purpose of this function is to allocate a buffer that is optimal to
504  * be processed by @pad. The function is mostly overridden by elements that can
505  * provide a hardware buffer in order to avoid additional memcpy operations.
506  *
507  * The function can return a buffer that has caps different from the requested
508  * @caps, in which case the upstream element requests a format change to this
509  * new caps.
510  * If a format change was requested, the returned buffer will be one to hold
511  * the data of said new caps, so its size might be different from the requested
512  * @size.
513  *
514  * When this function returns anything else than #GST_FLOW_OK, the buffer allocation
515  * failed and @buf does not contain valid data. If the function returns #GST_FLOW_OK and
516  * the @buf is NULL, a #GstBuffer will be created with @caps, @offset and @size.
517  *
518  * By default this function returns a new buffer of @size and with @caps containing
519  * purely malloced data. The buffer should be freed with gst_buffer_unref()
520  * after usage.
521  *
522  * Returns: #GST_FLOW_OK if @buf contains a valid buffer, any other return
523  *  value means @buf does not hold a valid buffer.
524  */
525 typedef GstFlowReturn           (*GstPadBufferAllocFunction)    (GstPad *pad, guint64 offset, guint size,
526                                                                  GstCaps *caps, GstBuffer **buf);
527
528 /* misc */
529 /**
530  * GstPadDispatcherFunction:
531  * @pad: the #GstPad that is dispatched.
532  * @data: the gpointer to optional user data.
533  *
534  * A dispatcher function is called for all internally linked pads, see
535  * gst_pad_dispatcher().
536  *
537  * Returns: TRUE if the dispatching procedure has to be stopped.
538  */
539 typedef gboolean                (*GstPadDispatcherFunction)     (GstPad *pad, gpointer data);
540
541 /**
542  * GstPadBlockCallback:
543  * @pad: the #GstPad that is blockend or unblocked.
544  * @blocked: blocking state for the pad
545  * @user_data: the gpointer to optional user data.
546  *
547  * Callback used by gst_pad_set_blocked_async(). Gets called when the blocking
548  * operation succeeds.
549  */
550 typedef void                    (*GstPadBlockCallback)          (GstPad *pad, gboolean blocked, gpointer user_data);
551
552 /**
553  * GstPadDirection:
554  * @GST_PAD_UNKNOWN: direction is unknown.
555  * @GST_PAD_SRC: the pad is a source pad.
556  * @GST_PAD_SINK: the pad is a sink pad.
557  *
558  * The direction of a pad.
559  */
560 typedef enum {
561   GST_PAD_UNKNOWN,
562   GST_PAD_SRC,
563   GST_PAD_SINK
564 } GstPadDirection;
565
566 /**
567  * GstPadFlags:
568  * @GST_PAD_BLOCKED: is dataflow on a pad blocked
569  * @GST_PAD_FLUSHING: is pad refusing buffers
570  * @GST_PAD_IN_GETCAPS: GstPadGetCapsFunction() is running now
571  * @GST_PAD_IN_SETCAPS: GstPadSetCapsFunction() is running now
572  * @GST_PAD_BLOCKING: is pad currently blocking on a buffer or event
573  * @GST_PAD_FLAG_LAST: offset to define more flags
574  *
575  * Pad state flags
576  */
577 typedef enum {
578   GST_PAD_BLOCKED       = (GST_OBJECT_FLAG_LAST << 0),
579   GST_PAD_FLUSHING      = (GST_OBJECT_FLAG_LAST << 1),
580   GST_PAD_IN_GETCAPS    = (GST_OBJECT_FLAG_LAST << 2),
581   GST_PAD_IN_SETCAPS    = (GST_OBJECT_FLAG_LAST << 3),
582   GST_PAD_BLOCKING      = (GST_OBJECT_FLAG_LAST << 4),
583   /* padding */
584   GST_PAD_FLAG_LAST     = (GST_OBJECT_FLAG_LAST << 8)
585 } GstPadFlags;
586
587 /* FIXME: this awful circular dependency need to be resolved properly (see padtemplate.h) */
588 typedef struct _GstPadTemplate GstPadTemplate;
589
590 /**
591  * GstPad:
592  * @element_private: private data owned by the parent element
593  * @padtemplate: padtemplate for this pad
594  * @direction: the direction of the pad, cannot change after creating
595  *             the pad.
596  * @stream_rec_lock: recursive stream lock of the pad, used to protect
597  *                   the data used in streaming.
598  * @task: task for this pad if the pad is actively driving dataflow.
599  * @preroll_lock: lock used when prerolling
600  * @preroll_cond: conf to signal preroll
601  * @block_cond: conditional to signal pad block
602  * @block_callback: callback for the pad block if any
603  * @block_data: user data for @block_callback
604  * @caps: the current caps of the pad
605  * @getcapsfunc: function to get caps of the pad
606  * @setcapsfunc: function to set caps on the pad
607  * @acceptcapsfunc: function to check if pad can accept caps
608  * @fixatecapsfunc: function to fixate caps
609  * @activatefunc: pad activation function
610  * @activatepushfunc: function to activate/deactivate pad in push mode
611  * @activatepullfunc: function to activate/deactivate pad in pull mode
612  * @linkfunc: function called when pad is linked
613  * @unlinkfunc: function called when pad is unlinked
614  * @peer: the pad this pad is linked to
615  * @sched_private: private storage for the scheduler
616  * @chainfunc: function to chain buffer to pad
617  * @checkgetrangefunc: function to check if pad can operate in pull mode
618  * @getrangefunc: function to get a range of data from a pad
619  * @eventfunc: function to send an event to a pad
620  * @mode: current activation mode of the pad
621  * @querytypefunc: get list of supported queries
622  * @queryfunc: perform a query on the pad
623  * @intlinkfunc: get the internal links of this pad
624  * @bufferallocfunc: function to allocate a buffer for this pad
625  * @do_buffer_signals: counter counting installed buffer signals
626  * @do_event_signals: counter counting installed event signals
627  * @iterintlinkfunc: get the internal links iterator of this pad
628  * @block_destroy_data: notify function for gst_pad_set_blocked_async_full()
629  *
630  * The #GstPad structure. Use the functions to update the variables.
631  */
632 struct _GstPad {
633   GstObject                     object;
634
635   /*< public >*/
636   gpointer                      element_private;
637
638   GstPadTemplate                *padtemplate;
639
640   GstPadDirection                direction;
641
642   /*< public >*/ /* with STREAM_LOCK */
643   /* streaming rec_lock */
644   GStaticRecMutex               *stream_rec_lock;
645   GstTask                       *task;
646   /*< public >*/ /* with PREROLL_LOCK */
647   GMutex                        *preroll_lock;
648   GCond                         *preroll_cond;
649
650   /*< public >*/ /* with LOCK */
651   /* block cond, mutex is from the object */
652   GCond                         *block_cond;
653   GstPadBlockCallback            block_callback;
654   gpointer                       block_data;
655
656   /* the pad capabilities */
657   GstCaps                       *caps;
658   GstPadGetCapsFunction         getcapsfunc;
659   GstPadSetCapsFunction         setcapsfunc;
660   GstPadAcceptCapsFunction       acceptcapsfunc;
661   GstPadFixateCapsFunction       fixatecapsfunc;
662
663   GstPadActivateFunction         activatefunc;
664   GstPadActivateModeFunction     activatepushfunc;
665   GstPadActivateModeFunction     activatepullfunc;
666
667   /* pad link */
668   GstPadLinkFunction             linkfunc;
669   GstPadUnlinkFunction           unlinkfunc;
670   GstPad                        *peer;
671
672   gpointer                       sched_private;
673
674   /* data transport functions */
675   GstPadChainFunction            chainfunc;
676   GstPadCheckGetRangeFunction    checkgetrangefunc;
677   GstPadGetRangeFunction         getrangefunc;
678   GstPadEventFunction            eventfunc;
679
680   GstActivateMode                mode;
681
682   /* generic query method */
683   GstPadQueryTypeFunction        querytypefunc;
684   GstPadQueryFunction            queryfunc;
685
686   /* internal links */
687   GstPadIntLinkFunction          intlinkfunc;
688
689   GstPadBufferAllocFunction      bufferallocfunc;
690
691   /* whether to emit signals for have-data. counts number
692    * of handlers attached. */
693   gint                           do_buffer_signals;
694   gint                           do_event_signals;
695
696   /* ABI added */
697   /* iterate internal links */
698   GstPadIterIntLinkFunction     iterintlinkfunc;
699
700   /* free block_data */
701   GDestroyNotify block_destroy_data;
702
703   /*< private >*/
704   union {
705     struct {
706       gboolean                      block_callback_called;
707       GstPadPrivate                *priv;
708     } ABI;
709     gpointer _gst_reserved[GST_PADDING - 2];
710   } abidata;
711 };
712
713 struct _GstPadClass {
714   GstObjectClass        parent_class;
715
716   /* signal callbacks */
717   void          (*linked)               (GstPad *pad, GstPad *peer);
718   void          (*unlinked)             (GstPad *pad, GstPad *peer);
719   void          (*request_link)         (GstPad *pad);
720   gboolean      (*have_data)            (GstPad *pad, GstMiniObject *data);
721
722   /*< private >*/
723   gpointer _gst_reserved[GST_PADDING];
724 };
725
726
727 /***** helper macros *****/
728 /* GstPad */
729 #define GST_PAD_NAME(pad)               (GST_OBJECT_NAME(pad))
730 #define GST_PAD_PARENT(pad)             (GST_ELEMENT_CAST(GST_OBJECT_PARENT(pad)))
731 #define GST_PAD_ELEMENT_PRIVATE(pad)    (GST_PAD_CAST(pad)->element_private)
732 #define GST_PAD_PAD_TEMPLATE(pad)       (GST_PAD_CAST(pad)->padtemplate)
733 #define GST_PAD_DIRECTION(pad)          (GST_PAD_CAST(pad)->direction)
734 #define GST_PAD_TASK(pad)               (GST_PAD_CAST(pad)->task)
735 #define GST_PAD_ACTIVATE_MODE(pad)      (GST_PAD_CAST(pad)->mode)
736
737 #define GST_PAD_ACTIVATEFUNC(pad)       (GST_PAD_CAST(pad)->activatefunc)
738 #define GST_PAD_ACTIVATEPUSHFUNC(pad)   (GST_PAD_CAST(pad)->activatepushfunc)
739 #define GST_PAD_ACTIVATEPULLFUNC(pad)   (GST_PAD_CAST(pad)->activatepullfunc)
740 #define GST_PAD_CHAINFUNC(pad)          (GST_PAD_CAST(pad)->chainfunc)
741 #define GST_PAD_CHECKGETRANGEFUNC(pad)  (GST_PAD_CAST(pad)->checkgetrangefunc)
742 #define GST_PAD_GETRANGEFUNC(pad)       (GST_PAD_CAST(pad)->getrangefunc)
743 #define GST_PAD_EVENTFUNC(pad)          (GST_PAD_CAST(pad)->eventfunc)
744 #define GST_PAD_QUERYTYPEFUNC(pad)      (GST_PAD_CAST(pad)->querytypefunc)
745 #define GST_PAD_QUERYFUNC(pad)          (GST_PAD_CAST(pad)->queryfunc)
746 #ifndef GST_DISABLE_DEPRECATED
747 #define GST_PAD_INTLINKFUNC(pad)        (GST_PAD_CAST(pad)->intlinkfunc)
748 #endif
749 #define GST_PAD_ITERINTLINKFUNC(pad)    (GST_PAD_CAST(pad)->iterintlinkfunc)
750
751 #define GST_PAD_PEER(pad)               (GST_PAD_CAST(pad)->peer)
752 #define GST_PAD_LINKFUNC(pad)           (GST_PAD_CAST(pad)->linkfunc)
753 #define GST_PAD_UNLINKFUNC(pad)         (GST_PAD_CAST(pad)->unlinkfunc)
754
755 /**
756  * GST_PAD_CAPS:
757  * @pad: a #GstPad.
758  *
759  * The caps for this pad.
760  */
761 #define GST_PAD_CAPS(pad)               (GST_PAD_CAST(pad)->caps)
762 #define GST_PAD_GETCAPSFUNC(pad)        (GST_PAD_CAST(pad)->getcapsfunc)
763 #define GST_PAD_SETCAPSFUNC(pad)        (GST_PAD_CAST(pad)->setcapsfunc)
764 #define GST_PAD_ACCEPTCAPSFUNC(pad)     (GST_PAD_CAST(pad)->acceptcapsfunc)
765 #define GST_PAD_FIXATECAPSFUNC(pad)     (GST_PAD_CAST(pad)->fixatecapsfunc)
766
767 #define GST_PAD_BUFFERALLOCFUNC(pad)    (GST_PAD_CAST(pad)->bufferallocfunc)
768
769 #define GST_PAD_DO_BUFFER_SIGNALS(pad)  (GST_PAD_CAST(pad)->do_buffer_signals)
770 #define GST_PAD_DO_EVENT_SIGNALS(pad)   (GST_PAD_CAST(pad)->do_event_signals)
771
772 #define GST_PAD_IS_LINKED(pad)          (GST_PAD_PEER(pad) != NULL)
773 #define GST_PAD_IS_BLOCKED(pad)         (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_BLOCKED))
774 #define GST_PAD_IS_BLOCKING(pad)        (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_BLOCKING))
775 #define GST_PAD_IS_FLUSHING(pad)        (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLUSHING))
776 #define GST_PAD_IS_IN_GETCAPS(pad)      (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_IN_GETCAPS))
777 #define GST_PAD_IS_IN_SETCAPS(pad)      (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_IN_SETCAPS))
778 #define GST_PAD_IS_SRC(pad)             (GST_PAD_DIRECTION(pad) == GST_PAD_SRC)
779 #define GST_PAD_IS_SINK(pad)            (GST_PAD_DIRECTION(pad) == GST_PAD_SINK)
780
781 #define GST_PAD_SET_FLUSHING(pad)       (GST_OBJECT_FLAG_SET (pad, GST_PAD_FLUSHING))
782 #define GST_PAD_UNSET_FLUSHING(pad)     (GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLUSHING))
783
784 /**
785  * GST_PAD_GET_STREAM_LOCK:
786  * @pad: a #GstPad
787  *
788  * Get the stream lock of @pad. The stream lock is protecting the
789  * resources used in the data processing functions of @pad.
790  */
791 #define GST_PAD_GET_STREAM_LOCK(pad)    (GST_PAD_CAST(pad)->stream_rec_lock)
792 /**
793  * GST_PAD_STREAM_LOCK:
794  * @pad: a #GstPad
795  *
796  * Lock the stream lock of @pad.
797  */
798 #define GST_PAD_STREAM_LOCK(pad)        (g_static_rec_mutex_lock(GST_PAD_GET_STREAM_LOCK(pad)))
799 /**
800  * GST_PAD_STREAM_LOCK_FULL:
801  * @pad: a #GstPad
802  * @t: the number of times to recursively lock
803  *
804  * Lock the stream lock of @pad @t times.
805  */
806 #define GST_PAD_STREAM_LOCK_FULL(pad,t) (g_static_rec_mutex_lock_full(GST_PAD_GET_STREAM_LOCK(pad), t))
807 /**
808  * GST_PAD_STREAM_TRYLOCK:
809  * @pad: a #GstPad
810  *
811  * Try to Lock the stream lock of the pad, return TRUE if the lock could be
812  * taken.
813  */
814 #define GST_PAD_STREAM_TRYLOCK(pad)     (g_static_rec_mutex_trylock(GST_PAD_GET_STREAM_LOCK(pad)))
815 /**
816  * GST_PAD_STREAM_UNLOCK:
817  * @pad: a #GstPad
818  *
819  * Unlock the stream lock of @pad.
820  */
821 #define GST_PAD_STREAM_UNLOCK(pad)      (g_static_rec_mutex_unlock(GST_PAD_GET_STREAM_LOCK(pad)))
822 /**
823  * GST_PAD_STREAM_UNLOCK_FULL:
824  * @pad: a #GstPad
825  *
826  * Fully unlock the recursive stream lock of @pad, return the number of times
827  * @pad was locked.
828  */
829 #define GST_PAD_STREAM_UNLOCK_FULL(pad) (g_static_rec_mutex_unlock_full(GST_PAD_GET_STREAM_LOCK(pad)))
830
831 #define GST_PAD_GET_PREROLL_LOCK(pad)   (GST_PAD_CAST(pad)->preroll_lock)
832 #define GST_PAD_PREROLL_LOCK(pad)       (g_mutex_lock(GST_PAD_GET_PREROLL_LOCK(pad)))
833 #define GST_PAD_PREROLL_TRYLOCK(pad)    (g_mutex_trylock(GST_PAD_GET_PREROLL_LOCK(pad)))
834 #define GST_PAD_PREROLL_UNLOCK(pad)     (g_mutex_unlock(GST_PAD_GET_PREROLL_LOCK(pad)))
835
836 #define GST_PAD_GET_PREROLL_COND(pad)   (GST_PAD_CAST(pad)->preroll_cond)
837 #define GST_PAD_PREROLL_WAIT(pad)       \
838     g_cond_wait (GST_PAD_GET_PREROLL_COND (pad), GST_PAD_GET_PREROLL_LOCK (pad))
839 #define GST_PAD_PREROLL_TIMED_WAIT(pad, timeval) \
840     g_cond_timed_wait (GST_PAD_GET_PREROLL_COND (pad), GST_PAD_GET_PREROLL_LOCK (pad), timeval)
841 #define GST_PAD_PREROLL_SIGNAL(pad)     g_cond_signal (GST_PAD_GET_PREROLL_COND (pad));
842 #define GST_PAD_PREROLL_BROADCAST(pad)  g_cond_broadcast (GST_PAD_GET_PREROLL_COND (pad));
843
844 #define GST_PAD_BLOCK_GET_COND(pad)     (GST_PAD_CAST(pad)->block_cond)
845 #define GST_PAD_BLOCK_WAIT(pad)         (g_cond_wait(GST_PAD_BLOCK_GET_COND (pad), GST_OBJECT_GET_LOCK (pad)))
846 #define GST_PAD_BLOCK_SIGNAL(pad)       (g_cond_signal(GST_PAD_BLOCK_GET_COND (pad)))
847 #define GST_PAD_BLOCK_BROADCAST(pad)    (g_cond_broadcast(GST_PAD_BLOCK_GET_COND (pad)))
848
849 /* FIXME: this awful circular dependency need to be resolved properly (see padtemplate.h) */
850 #include <gst/gstpadtemplate.h>
851
852 GType                   gst_pad_get_type                        (void);
853
854 /* creating pads */
855 GstPad*                 gst_pad_new                             (const gchar *name, GstPadDirection direction);
856 GstPad*                 gst_pad_new_from_template               (GstPadTemplate *templ, const gchar *name);
857 GstPad*                 gst_pad_new_from_static_template        (GstStaticPadTemplate *templ, const gchar *name);
858
859
860 /**
861  * gst_pad_get_name:
862  * @pad: the pad to get the name from
863  *
864  * Get a copy of the name of the pad. g_free() after usage.
865  *
866  * MT safe.
867  */
868 #define gst_pad_get_name(pad) gst_object_get_name (GST_OBJECT_CAST (pad))
869 /**
870  * gst_pad_get_parent:
871  * @pad: the pad to get the parent of
872  *
873  * Get the parent of @pad. This function increases the refcount
874  * of the parent object so you should gst_object_unref() it after usage.
875  * Can return NULL if the pad did not have a parent.
876  *
877  * MT safe.
878  */
879 #define gst_pad_get_parent(pad) gst_object_get_parent (GST_OBJECT_CAST (pad))
880
881 GstPadDirection         gst_pad_get_direction                   (GstPad *pad);
882
883 gboolean                gst_pad_set_active                      (GstPad *pad, gboolean active);
884 gboolean                gst_pad_is_active                       (GstPad *pad);
885 gboolean                gst_pad_activate_pull                   (GstPad *pad, gboolean active);
886 gboolean                gst_pad_activate_push                   (GstPad *pad, gboolean active);
887
888 gboolean                gst_pad_set_blocked                     (GstPad *pad, gboolean blocked);
889 gboolean                gst_pad_set_blocked_async               (GstPad *pad, gboolean blocked,
890                                                                  GstPadBlockCallback callback, gpointer user_data);
891 gboolean                gst_pad_set_blocked_async_full          (GstPad *pad, gboolean blocked,
892                                                                  GstPadBlockCallback callback, gpointer user_data,
893                                                                  GDestroyNotify destroy_data);
894 gboolean                gst_pad_is_blocked                      (GstPad *pad);
895 gboolean                gst_pad_is_blocking                     (GstPad *pad);
896
897 void                    gst_pad_set_element_private             (GstPad *pad, gpointer priv);
898 gpointer                gst_pad_get_element_private             (GstPad *pad);
899
900 GstPadTemplate*         gst_pad_get_pad_template                (GstPad *pad);
901
902 void                    gst_pad_set_bufferalloc_function        (GstPad *pad, GstPadBufferAllocFunction bufalloc);
903 GstFlowReturn           gst_pad_alloc_buffer                    (GstPad *pad, guint64 offset, gint size,
904                                                                  GstCaps *caps, GstBuffer **buf);
905 GstFlowReturn           gst_pad_alloc_buffer_and_set_caps       (GstPad *pad, guint64 offset, gint size,
906                                                                  GstCaps *caps, GstBuffer **buf);
907
908 /* data passing setup functions */
909 void                    gst_pad_set_activate_function           (GstPad *pad, GstPadActivateFunction activate);
910 void                    gst_pad_set_activatepull_function       (GstPad *pad, GstPadActivateModeFunction activatepull);
911 void                    gst_pad_set_activatepush_function       (GstPad *pad, GstPadActivateModeFunction activatepush);
912 void                    gst_pad_set_chain_function              (GstPad *pad, GstPadChainFunction chain);
913 void                    gst_pad_set_chain_list_function (GstPad *pad, GstPadChainListFunction chainlist);
914 void                    gst_pad_set_getrange_function           (GstPad *pad, GstPadGetRangeFunction get);
915 void                    gst_pad_set_checkgetrange_function      (GstPad *pad, GstPadCheckGetRangeFunction check);
916 void                    gst_pad_set_event_function              (GstPad *pad, GstPadEventFunction event);
917
918 /* pad links */
919 void                    gst_pad_set_link_function               (GstPad *pad, GstPadLinkFunction link);
920 void                    gst_pad_set_unlink_function             (GstPad *pad, GstPadUnlinkFunction unlink);
921
922 gboolean                gst_pad_can_link                        (GstPad *srcpad, GstPad *sinkpad);
923 GstPadLinkReturn        gst_pad_link                            (GstPad *srcpad, GstPad *sinkpad);
924 GstPadLinkReturn        gst_pad_link_full                       (GstPad *srcpad, GstPad *sinkpad, GstPadLinkCheck flags);
925 gboolean                gst_pad_unlink                          (GstPad *srcpad, GstPad *sinkpad);
926 gboolean                gst_pad_is_linked                       (GstPad *pad);
927
928 GstPad*                 gst_pad_get_peer                        (GstPad *pad);
929
930 /* capsnego functions */
931 void                    gst_pad_set_getcaps_function            (GstPad *pad, GstPadGetCapsFunction getcaps);
932 void                    gst_pad_set_acceptcaps_function         (GstPad *pad, GstPadAcceptCapsFunction acceptcaps);
933 void                    gst_pad_set_fixatecaps_function         (GstPad *pad, GstPadFixateCapsFunction fixatecaps);
934 void                    gst_pad_set_setcaps_function            (GstPad *pad, GstPadSetCapsFunction setcaps);
935
936 G_CONST_RETURN GstCaps* gst_pad_get_pad_template_caps           (GstPad *pad);
937
938 /* capsnego function for linked/unlinked pads */
939 GstCaps *               gst_pad_get_caps_reffed                 (GstPad * pad);
940 GstCaps *               gst_pad_get_caps                        (GstPad * pad);
941 void                    gst_pad_fixate_caps                     (GstPad * pad, GstCaps *caps);
942 gboolean                gst_pad_accept_caps                     (GstPad * pad, GstCaps *caps);
943 gboolean                gst_pad_set_caps                        (GstPad * pad, GstCaps *caps);
944
945 GstCaps *               gst_pad_peer_get_caps_reffed            (GstPad * pad);
946 GstCaps *               gst_pad_peer_get_caps                   (GstPad * pad);
947 gboolean                gst_pad_peer_accept_caps                (GstPad * pad, GstCaps *caps);
948
949 /* capsnego for linked pads */
950 GstCaps *               gst_pad_get_allowed_caps                (GstPad * pad);
951 GstCaps *               gst_pad_get_negotiated_caps             (GstPad * pad);
952
953 /* data passing functions to peer */
954 GstFlowReturn           gst_pad_push                            (GstPad *pad, GstBuffer *buffer);
955 GstFlowReturn           gst_pad_push_list                       (GstPad *pad, GstBufferList *list);
956 gboolean                gst_pad_check_pull_range                (GstPad *pad);
957 GstFlowReturn           gst_pad_pull_range                      (GstPad *pad, guint64 offset, guint size,
958                                                                  GstBuffer **buffer);
959 gboolean                gst_pad_push_event                      (GstPad *pad, GstEvent *event);
960 gboolean                gst_pad_event_default                   (GstPad *pad, GstEvent *event);
961
962 /* data passing functions on pad */
963 GstFlowReturn           gst_pad_chain                           (GstPad *pad, GstBuffer *buffer);
964 GstFlowReturn           gst_pad_chain_list                      (GstPad *pad, GstBufferList *list);
965 GstFlowReturn           gst_pad_get_range                       (GstPad *pad, guint64 offset, guint size,
966                                                                  GstBuffer **buffer);
967 gboolean                gst_pad_send_event                      (GstPad *pad, GstEvent *event);
968
969 /* pad tasks */
970 gboolean                gst_pad_start_task                      (GstPad *pad, GstTaskFunction func,
971                                                                  gpointer data);
972 gboolean                gst_pad_pause_task                      (GstPad *pad);
973 gboolean                gst_pad_stop_task                       (GstPad *pad);
974
975 /* internal links */
976 #ifndef GST_DISABLE_DEPRECATED
977 void                    gst_pad_set_internal_link_function      (GstPad *pad, GstPadIntLinkFunction intlink);
978 GList*                  gst_pad_get_internal_links              (GstPad *pad);
979 GList*                  gst_pad_get_internal_links_default      (GstPad *pad);
980 #endif
981
982 void                    gst_pad_set_iterate_internal_links_function (GstPad * pad,
983                                                                  GstPadIterIntLinkFunction iterintlink);
984 GstIterator *           gst_pad_iterate_internal_links          (GstPad * pad);
985 GstIterator *           gst_pad_iterate_internal_links_default  (GstPad * pad);
986
987
988 /* generic query function */
989 void                    gst_pad_set_query_type_function         (GstPad *pad, GstPadQueryTypeFunction type_func);
990 G_CONST_RETURN GstQueryType*
991                         gst_pad_get_query_types                 (GstPad *pad);
992 G_CONST_RETURN GstQueryType*
993                         gst_pad_get_query_types_default         (GstPad *pad);
994
995 gboolean                gst_pad_query                           (GstPad *pad, GstQuery *query);
996 gboolean                gst_pad_peer_query                      (GstPad *pad, GstQuery *query);
997 void                    gst_pad_set_query_function              (GstPad *pad, GstPadQueryFunction query);
998 gboolean                gst_pad_query_default                   (GstPad *pad, GstQuery *query);
999
1000 /* misc helper functions */
1001 gboolean                gst_pad_dispatcher                      (GstPad *pad, GstPadDispatcherFunction dispatch,
1002                                                                  gpointer data);
1003
1004 #ifndef GST_DISABLE_LOADSAVE
1005 void                    gst_pad_load_and_link                   (xmlNodePtr self, GstObject *parent);
1006 #endif
1007
1008 G_END_DECLS
1009
1010 #endif /* __GST_PAD_H__ */