Merge branch 'master' into 0.11
[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 /* FIXME: 0.11: deprecate me, check range should use seeking query */
346 /**
347  * GstPadCheckGetRangeFunction:
348  * @pad: a #GstPad
349  *
350  * Check if @pad can be activated in pull mode.
351  *
352  * This function will be deprecated after 0.10; use the seeking query to check
353  * if a pad can support random access.
354  *
355  * Returns: TRUE if the pad can operate in pull mode.
356  */
357 typedef gboolean                (*GstPadCheckGetRangeFunction)  (GstPad *pad);
358
359 /* internal links */
360 /**
361  * GstPadIterIntLinkFunction:
362  * @pad: The #GstPad to query.
363  *
364  * The signature of the internal pad link iterator function.
365  *
366  * Returns: a new #GstIterator that will iterate over all pads that are
367  * linked to the given pad on the inside of the parent element.
368  *
369  * the caller must call gst_iterator_free() after usage.
370  *
371  * Since 0.10.21
372  */
373 typedef GstIterator*           (*GstPadIterIntLinkFunction)    (GstPad *pad);
374
375 /* generic query function */
376 /**
377  * GstPadQueryTypeFunction:
378  * @pad: a #GstPad to query
379  *
380  * The signature of the query types function.
381  *
382  * Returns: a constant array of query types
383  */
384 typedef const GstQueryType*     (*GstPadQueryTypeFunction)      (GstPad *pad);
385
386 /**
387  * GstPadQueryFunction:
388  * @pad: the #GstPad to query.
389  * @query: the #GstQuery object to execute
390  *
391  * The signature of the query function.
392  *
393  * Returns: TRUE if the query could be performed.
394  */
395 typedef gboolean                (*GstPadQueryFunction)          (GstPad *pad, GstQuery *query);
396
397
398 /* linking */
399 /**
400  * GstPadLinkFunction
401  * @pad: the #GstPad that is linked.
402  * @peer: the peer #GstPad of the link
403  *
404  * Function signature to handle a new link on the pad.
405  *
406  * Returns: the result of the link with the specified peer.
407  */
408 typedef GstPadLinkReturn        (*GstPadLinkFunction)           (GstPad *pad, GstPad *peer);
409 /**
410  * GstPadUnlinkFunction
411  * @pad: the #GstPad that is linked.
412  *
413  * Function signature to handle a unlinking the pad prom its peer.
414  */
415 typedef void                    (*GstPadUnlinkFunction)         (GstPad *pad);
416
417
418 /* caps nego */
419 /**
420  * GstPadGetCapsFunction:
421  * @pad: the #GstPad to get the capabilities of.
422  *
423  * Returns a copy of the capabilities of the specified pad. By default this
424  * function will return the pad template capabilities, but can optionally
425  * be overridden by elements.
426  *
427  * Returns: a newly allocated copy #GstCaps of the pad.
428  */
429 typedef GstCaps*                (*GstPadGetCapsFunction)        (GstPad *pad);
430
431 /**
432  * GstPadSetCapsFunction:
433  * @pad: the #GstPad to set the capabilities of.
434  * @caps: the #GstCaps to set
435  *
436  * Set @caps on @pad. By default this function updates the caps of the
437  * pad but the function can be overriden by elements to perform extra
438  * actions or verifications.
439  *
440  * Returns: TRUE if the caps could be set on the pad.
441  */
442 typedef gboolean                (*GstPadSetCapsFunction)        (GstPad *pad, GstCaps *caps);
443 /**
444  * GstPadAcceptCapsFunction:
445  * @pad: the #GstPad to check
446  * @caps: the #GstCaps to check
447  *
448  * Check if @pad can accept @caps. By default this function will see if @caps
449  * intersect with the result from gst_pad_get_caps() by can be overridden to
450  * perform extra checks.
451  *
452  * Returns: TRUE if the caps can be accepted by the pad.
453  */
454 typedef gboolean                (*GstPadAcceptCapsFunction)     (GstPad *pad, GstCaps *caps);
455 /**
456  * GstPadFixateCapsFunction:
457  * @pad: a #GstPad
458  * @caps: the #GstCaps to fixate
459  *
460  * Given possibly unfixed caps @caps, let @pad use its default prefered
461  * format to make a fixed caps. @caps should be writable. By default this
462  * function will pick the first value of any ranges or lists in the caps but
463  * elements can override this function to perform other behaviour.
464  */
465 typedef void                    (*GstPadFixateCapsFunction)     (GstPad *pad, GstCaps *caps);
466 /**
467  * GstPadBufferAllocFunction:
468  * @pad: a sink #GstPad
469  * @offset: the desired offset of the buffer
470  * @size: the desired size of the buffer
471  * @caps: the desired caps of the buffer
472  * @buf: pointer to hold the allocated buffer.
473  *
474  * Ask the sinkpad @pad to allocate a buffer with @offset, @size and @caps.
475  * The result will be stored in @buf.
476  *
477  * The purpose of this function is to allocate a buffer that is optimal to
478  * be processed by @pad. The function is mostly overridden by elements that can
479  * provide a hardware buffer in order to avoid additional memcpy operations.
480  *
481  * The function can return a buffer that has caps different from the requested
482  * @caps, in which case the upstream element requests a format change to this
483  * new caps.
484  * If a format change was requested, the returned buffer will be one to hold
485  * the data of said new caps, so its size might be different from the requested
486  * @size.
487  *
488  * When this function returns anything else than #GST_FLOW_OK, the buffer allocation
489  * failed and @buf does not contain valid data. If the function returns #GST_FLOW_OK and
490  * the @buf is NULL, a #GstBuffer will be created with @caps, @offset and @size.
491  *
492  * By default this function returns a new buffer of @size and with @caps containing
493  * purely malloced data. The buffer should be freed with gst_buffer_unref()
494  * after usage.
495  *
496  * Returns: #GST_FLOW_OK if @buf contains a valid buffer, any other return
497  *  value means @buf does not hold a valid buffer.
498  */
499 typedef GstFlowReturn           (*GstPadBufferAllocFunction)    (GstPad *pad, guint64 offset, guint size,
500                                                                  GstCaps *caps, GstBuffer **buf);
501
502 /* misc */
503 /**
504  * GstPadDispatcherFunction:
505  * @pad: the #GstPad that is dispatched.
506  * @data: the gpointer to optional user data.
507  *
508  * A dispatcher function is called for all internally linked pads, see
509  * gst_pad_dispatcher().
510  *
511  * Returns: TRUE if the dispatching procedure has to be stopped.
512  */
513 typedef gboolean                (*GstPadDispatcherFunction)     (GstPad *pad, gpointer data);
514
515 /**
516  * GstPadBlockCallback:
517  * @pad: the #GstPad that is blockend or unblocked.
518  * @blocked: blocking state for the pad
519  * @user_data: the gpointer to optional user data.
520  *
521  * Callback used by gst_pad_set_blocked_async(). Gets called when the blocking
522  * operation succeeds.
523  */
524 typedef void                    (*GstPadBlockCallback)          (GstPad *pad, gboolean blocked, gpointer user_data);
525
526 /**
527  * GstPadDirection:
528  * @GST_PAD_UNKNOWN: direction is unknown.
529  * @GST_PAD_SRC: the pad is a source pad.
530  * @GST_PAD_SINK: the pad is a sink pad.
531  *
532  * The direction of a pad.
533  */
534 typedef enum {
535   GST_PAD_UNKNOWN,
536   GST_PAD_SRC,
537   GST_PAD_SINK
538 } GstPadDirection;
539
540 /**
541  * GstPadFlags:
542  * @GST_PAD_BLOCKED: is dataflow on a pad blocked
543  * @GST_PAD_FLUSHING: is pad refusing buffers
544  * @GST_PAD_IN_GETCAPS: GstPadGetCapsFunction() is running now
545  * @GST_PAD_IN_SETCAPS: GstPadSetCapsFunction() is running now
546  * @GST_PAD_BLOCKING: is pad currently blocking on a buffer or event
547  * @GST_PAD_FLAG_LAST: offset to define more flags
548  *
549  * Pad state flags
550  */
551 typedef enum {
552   GST_PAD_BLOCKED       = (GST_OBJECT_FLAG_LAST << 0),
553   GST_PAD_FLUSHING      = (GST_OBJECT_FLAG_LAST << 1),
554   GST_PAD_IN_GETCAPS    = (GST_OBJECT_FLAG_LAST << 2),
555   GST_PAD_IN_SETCAPS    = (GST_OBJECT_FLAG_LAST << 3),
556   GST_PAD_BLOCKING      = (GST_OBJECT_FLAG_LAST << 4),
557   /* padding */
558   GST_PAD_FLAG_LAST     = (GST_OBJECT_FLAG_LAST << 8)
559 } GstPadFlags;
560
561 /* FIXME: this awful circular dependency need to be resolved properly (see padtemplate.h) */
562 typedef struct _GstPadTemplate GstPadTemplate;
563
564 /**
565  * GstPad:
566  * @element_private: private data owned by the parent element
567  * @padtemplate: padtemplate for this pad
568  * @direction: the direction of the pad, cannot change after creating
569  *             the pad.
570  * @stream_rec_lock: recursive stream lock of the pad, used to protect
571  *                   the data used in streaming.
572  * @task: task for this pad if the pad is actively driving dataflow.
573  * @preroll_lock: lock used when prerolling
574  * @preroll_cond: conf to signal preroll
575  * @block_cond: conditional to signal pad block
576  * @block_callback: callback for the pad block if any
577  * @block_data: user data for @block_callback
578  * @caps: the current caps of the pad
579  * @getcapsfunc: function to get caps of the pad
580  * @setcapsfunc: function to set caps on the pad
581  * @acceptcapsfunc: function to check if pad can accept caps
582  * @fixatecapsfunc: function to fixate caps
583  * @activatefunc: pad activation function
584  * @activatepushfunc: function to activate/deactivate pad in push mode
585  * @activatepullfunc: function to activate/deactivate pad in pull mode
586  * @linkfunc: function called when pad is linked
587  * @unlinkfunc: function called when pad is unlinked
588  * @peer: the pad this pad is linked to
589  * @sched_private: private storage for the scheduler
590  * @chainfunc: function to chain buffer to pad
591  * @checkgetrangefunc: function to check if pad can operate in pull mode
592  * @getrangefunc: function to get a range of data from a pad
593  * @eventfunc: function to send an event to a pad
594  * @mode: current activation mode of the pad
595  * @querytypefunc: get list of supported queries
596  * @queryfunc: perform a query on the pad
597  * @intlinkfunc: get the internal links of this pad
598  * @bufferallocfunc: function to allocate a buffer for this pad
599  * @do_buffer_signals: counter counting installed buffer signals
600  * @do_event_signals: counter counting installed event signals
601  * @iterintlinkfunc: get the internal links iterator of this pad
602  * @block_destroy_data: notify function for gst_pad_set_blocked_async_full()
603  *
604  * The #GstPad structure. Use the functions to update the variables.
605  */
606 struct _GstPad {
607   GstObject                     object;
608
609   /*< public >*/
610   gpointer                      element_private;
611
612   GstPadTemplate                *padtemplate;
613
614   GstPadDirection                direction;
615
616   /*< public >*/ /* with STREAM_LOCK */
617   /* streaming rec_lock */
618   GStaticRecMutex               *stream_rec_lock;
619   GstTask                       *task;
620
621   /*< public >*/ /* with LOCK */
622   /* block cond, mutex is from the object */
623   GCond                         *block_cond;
624   GstPadBlockCallback            block_callback;
625   gpointer                       block_data;
626   GDestroyNotify                 block_destroy_data;
627   gboolean                       block_callback_called;
628
629   /* the pad capabilities */
630   GstCaps                       *caps;
631   GstPadGetCapsFunction         getcapsfunc;
632   GstPadSetCapsFunction         setcapsfunc;
633   GstPadAcceptCapsFunction       acceptcapsfunc;
634   GstPadFixateCapsFunction       fixatecapsfunc;
635
636   GstPadActivateFunction         activatefunc;
637   GstPadActivateModeFunction     activatepushfunc;
638   GstPadActivateModeFunction     activatepullfunc;
639
640   /* pad link */
641   GstPadLinkFunction             linkfunc;
642   GstPadUnlinkFunction           unlinkfunc;
643   GstPad                        *peer;
644
645   gpointer                       sched_private;
646
647   /* data transport functions */
648   GstPadChainFunction            chainfunc;
649   GstPadChainListFunction        chainlistfunc;
650   GstPadCheckGetRangeFunction    checkgetrangefunc;
651   GstPadGetRangeFunction         getrangefunc;
652   GstPadEventFunction            eventfunc;
653
654   GstActivateMode                mode;
655
656   /* generic query method */
657   GstPadQueryTypeFunction        querytypefunc;
658   GstPadQueryFunction            queryfunc;
659
660   /* internal links */
661   GstPadIterIntLinkFunction      iterintlinkfunc;
662
663   GstPadBufferAllocFunction      bufferallocfunc;
664
665   /* whether to emit signals for have-data. counts number
666    * of handlers attached. */
667   gint                           do_buffer_signals;
668   gint                           do_event_signals;
669
670   /*< private >*/
671   GstPadPrivate                 *priv;
672
673   gpointer _gst_reserved[GST_PADDING];
674 };
675
676 struct _GstPadClass {
677   GstObjectClass        parent_class;
678
679   /* signal callbacks */
680   void          (*linked)               (GstPad *pad, GstPad *peer);
681   void          (*unlinked)             (GstPad *pad, GstPad *peer);
682   void          (*request_link)         (GstPad *pad);
683   gboolean      (*have_data)            (GstPad *pad, GstMiniObject *data);
684
685   /*< private >*/
686   gpointer _gst_reserved[GST_PADDING];
687 };
688
689
690 /***** helper macros *****/
691 /* GstPad */
692 #define GST_PAD_NAME(pad)               (GST_OBJECT_NAME(pad))
693 #define GST_PAD_PARENT(pad)             (GST_ELEMENT_CAST(GST_OBJECT_PARENT(pad)))
694 #define GST_PAD_ELEMENT_PRIVATE(pad)    (GST_PAD_CAST(pad)->element_private)
695 #define GST_PAD_PAD_TEMPLATE(pad)       (GST_PAD_CAST(pad)->padtemplate)
696 #define GST_PAD_DIRECTION(pad)          (GST_PAD_CAST(pad)->direction)
697 #define GST_PAD_TASK(pad)               (GST_PAD_CAST(pad)->task)
698 #define GST_PAD_ACTIVATE_MODE(pad)      (GST_PAD_CAST(pad)->mode)
699
700 #define GST_PAD_ACTIVATEFUNC(pad)       (GST_PAD_CAST(pad)->activatefunc)
701 #define GST_PAD_ACTIVATEPUSHFUNC(pad)   (GST_PAD_CAST(pad)->activatepushfunc)
702 #define GST_PAD_ACTIVATEPULLFUNC(pad)   (GST_PAD_CAST(pad)->activatepullfunc)
703 #define GST_PAD_CHAINFUNC(pad)          (GST_PAD_CAST(pad)->chainfunc)
704 #define GST_PAD_CHAINLISTFUNC(pad)      (GST_PAD_CAST(pad)->chainlistfunc)
705 #define GST_PAD_CHECKGETRANGEFUNC(pad)  (GST_PAD_CAST(pad)->checkgetrangefunc)
706 #define GST_PAD_GETRANGEFUNC(pad)       (GST_PAD_CAST(pad)->getrangefunc)
707 #define GST_PAD_EVENTFUNC(pad)          (GST_PAD_CAST(pad)->eventfunc)
708 #define GST_PAD_QUERYTYPEFUNC(pad)      (GST_PAD_CAST(pad)->querytypefunc)
709 #define GST_PAD_QUERYFUNC(pad)          (GST_PAD_CAST(pad)->queryfunc)
710 #define GST_PAD_ITERINTLINKFUNC(pad)    (GST_PAD_CAST(pad)->iterintlinkfunc)
711
712 #define GST_PAD_PEER(pad)               (GST_PAD_CAST(pad)->peer)
713 #define GST_PAD_LINKFUNC(pad)           (GST_PAD_CAST(pad)->linkfunc)
714 #define GST_PAD_UNLINKFUNC(pad)         (GST_PAD_CAST(pad)->unlinkfunc)
715
716 /**
717  * GST_PAD_CAPS:
718  * @pad: a #GstPad.
719  *
720  * The caps for this pad.
721  */
722 #define GST_PAD_CAPS(pad)               (GST_PAD_CAST(pad)->caps)
723 #define GST_PAD_GETCAPSFUNC(pad)        (GST_PAD_CAST(pad)->getcapsfunc)
724 #define GST_PAD_SETCAPSFUNC(pad)        (GST_PAD_CAST(pad)->setcapsfunc)
725 #define GST_PAD_ACCEPTCAPSFUNC(pad)     (GST_PAD_CAST(pad)->acceptcapsfunc)
726 #define GST_PAD_FIXATECAPSFUNC(pad)     (GST_PAD_CAST(pad)->fixatecapsfunc)
727
728 #define GST_PAD_BUFFERALLOCFUNC(pad)    (GST_PAD_CAST(pad)->bufferallocfunc)
729
730 #define GST_PAD_DO_BUFFER_SIGNALS(pad)  (GST_PAD_CAST(pad)->do_buffer_signals)
731 #define GST_PAD_DO_EVENT_SIGNALS(pad)   (GST_PAD_CAST(pad)->do_event_signals)
732
733 #define GST_PAD_IS_LINKED(pad)          (GST_PAD_PEER(pad) != NULL)
734 #define GST_PAD_IS_BLOCKED(pad)         (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_BLOCKED))
735 #define GST_PAD_IS_BLOCKING(pad)        (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_BLOCKING))
736 #define GST_PAD_IS_FLUSHING(pad)        (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLUSHING))
737 #define GST_PAD_IS_IN_GETCAPS(pad)      (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_IN_GETCAPS))
738 #define GST_PAD_IS_IN_SETCAPS(pad)      (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_IN_SETCAPS))
739 #define GST_PAD_IS_SRC(pad)             (GST_PAD_DIRECTION(pad) == GST_PAD_SRC)
740 #define GST_PAD_IS_SINK(pad)            (GST_PAD_DIRECTION(pad) == GST_PAD_SINK)
741
742 #define GST_PAD_SET_FLUSHING(pad)       (GST_OBJECT_FLAG_SET (pad, GST_PAD_FLUSHING))
743 #define GST_PAD_UNSET_FLUSHING(pad)     (GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLUSHING))
744
745 /**
746  * GST_PAD_GET_STREAM_LOCK:
747  * @pad: a #GstPad
748  *
749  * Get the stream lock of @pad. The stream lock is protecting the
750  * resources used in the data processing functions of @pad.
751  */
752 #define GST_PAD_GET_STREAM_LOCK(pad)    (GST_PAD_CAST(pad)->stream_rec_lock)
753 /**
754  * GST_PAD_STREAM_LOCK:
755  * @pad: a #GstPad
756  *
757  * Lock the stream lock of @pad.
758  */
759 #define GST_PAD_STREAM_LOCK(pad)        (g_static_rec_mutex_lock(GST_PAD_GET_STREAM_LOCK(pad)))
760 /**
761  * GST_PAD_STREAM_LOCK_FULL:
762  * @pad: a #GstPad
763  * @t: the number of times to recursively lock
764  *
765  * Lock the stream lock of @pad @t times.
766  */
767 #define GST_PAD_STREAM_LOCK_FULL(pad,t) (g_static_rec_mutex_lock_full(GST_PAD_GET_STREAM_LOCK(pad), t))
768 /**
769  * GST_PAD_STREAM_TRYLOCK:
770  * @pad: a #GstPad
771  *
772  * Try to Lock the stream lock of the pad, return TRUE if the lock could be
773  * taken.
774  */
775 #define GST_PAD_STREAM_TRYLOCK(pad)     (g_static_rec_mutex_trylock(GST_PAD_GET_STREAM_LOCK(pad)))
776 /**
777  * GST_PAD_STREAM_UNLOCK:
778  * @pad: a #GstPad
779  *
780  * Unlock the stream lock of @pad.
781  */
782 #define GST_PAD_STREAM_UNLOCK(pad)      (g_static_rec_mutex_unlock(GST_PAD_GET_STREAM_LOCK(pad)))
783 /**
784  * GST_PAD_STREAM_UNLOCK_FULL:
785  * @pad: a #GstPad
786  *
787  * Fully unlock the recursive stream lock of @pad, return the number of times
788  * @pad was locked.
789  */
790 #define GST_PAD_STREAM_UNLOCK_FULL(pad) (g_static_rec_mutex_unlock_full(GST_PAD_GET_STREAM_LOCK(pad)))
791
792 #define GST_PAD_BLOCK_GET_COND(pad)     (GST_PAD_CAST(pad)->block_cond)
793 #define GST_PAD_BLOCK_WAIT(pad)         (g_cond_wait(GST_PAD_BLOCK_GET_COND (pad), GST_OBJECT_GET_LOCK (pad)))
794 #define GST_PAD_BLOCK_SIGNAL(pad)       (g_cond_signal(GST_PAD_BLOCK_GET_COND (pad)))
795 #define GST_PAD_BLOCK_BROADCAST(pad)    (g_cond_broadcast(GST_PAD_BLOCK_GET_COND (pad)))
796
797 /* FIXME: this awful circular dependency need to be resolved properly (see padtemplate.h) */
798 #include <gst/gstpadtemplate.h>
799
800 GType                   gst_pad_get_type                        (void);
801
802 /* creating pads */
803 GstPad*                 gst_pad_new                             (const gchar *name, GstPadDirection direction);
804 GstPad*                 gst_pad_new_from_template               (GstPadTemplate *templ, const gchar *name);
805 GstPad*                 gst_pad_new_from_static_template        (GstStaticPadTemplate *templ, const gchar *name);
806
807
808 /**
809  * gst_pad_get_name:
810  * @pad: the pad to get the name from
811  *
812  * Get a copy of the name of the pad. g_free() after usage.
813  *
814  * MT safe.
815  */
816 #define gst_pad_get_name(pad) gst_object_get_name (GST_OBJECT_CAST (pad))
817 /**
818  * gst_pad_get_parent:
819  * @pad: the pad to get the parent of
820  *
821  * Get the parent of @pad. This function increases the refcount
822  * of the parent object so you should gst_object_unref() it after usage.
823  * Can return NULL if the pad did not have a parent.
824  *
825  * MT safe.
826  */
827 #define gst_pad_get_parent(pad) gst_object_get_parent (GST_OBJECT_CAST (pad))
828
829 GstPadDirection         gst_pad_get_direction                   (GstPad *pad);
830
831 gboolean                gst_pad_set_active                      (GstPad *pad, gboolean active);
832 gboolean                gst_pad_is_active                       (GstPad *pad);
833 gboolean                gst_pad_activate_pull                   (GstPad *pad, gboolean active);
834 gboolean                gst_pad_activate_push                   (GstPad *pad, gboolean active);
835
836 gboolean                gst_pad_set_blocked                     (GstPad *pad, gboolean blocked);
837 gboolean                gst_pad_set_blocked_async               (GstPad *pad, gboolean blocked,
838                                                                  GstPadBlockCallback callback, gpointer user_data);
839 gboolean                gst_pad_set_blocked_async_full          (GstPad *pad, gboolean blocked,
840                                                                  GstPadBlockCallback callback, gpointer user_data,
841                                                                  GDestroyNotify destroy_data);
842 gboolean                gst_pad_is_blocked                      (GstPad *pad);
843 gboolean                gst_pad_is_blocking                     (GstPad *pad);
844
845 void                    gst_pad_set_element_private             (GstPad *pad, gpointer priv);
846 gpointer                gst_pad_get_element_private             (GstPad *pad);
847
848 GstPadTemplate*         gst_pad_get_pad_template                (GstPad *pad);
849
850 void                    gst_pad_set_bufferalloc_function        (GstPad *pad, GstPadBufferAllocFunction bufalloc);
851 GstFlowReturn           gst_pad_alloc_buffer                    (GstPad *pad, guint64 offset, gint size,
852                                                                  GstCaps *caps, GstBuffer **buf);
853 GstFlowReturn           gst_pad_alloc_buffer_and_set_caps       (GstPad *pad, guint64 offset, gint size,
854                                                                  GstCaps *caps, GstBuffer **buf);
855
856 /* data passing setup functions */
857 void                    gst_pad_set_activate_function           (GstPad *pad, GstPadActivateFunction activate);
858 void                    gst_pad_set_activatepull_function       (GstPad *pad, GstPadActivateModeFunction activatepull);
859 void                    gst_pad_set_activatepush_function       (GstPad *pad, GstPadActivateModeFunction activatepush);
860 void                    gst_pad_set_chain_function              (GstPad *pad, GstPadChainFunction chain);
861 void                    gst_pad_set_chain_list_function (GstPad *pad, GstPadChainListFunction chainlist);
862 void                    gst_pad_set_getrange_function           (GstPad *pad, GstPadGetRangeFunction get);
863 void                    gst_pad_set_checkgetrange_function      (GstPad *pad, GstPadCheckGetRangeFunction check);
864 void                    gst_pad_set_event_function              (GstPad *pad, GstPadEventFunction event);
865
866 /* pad links */
867 void                    gst_pad_set_link_function               (GstPad *pad, GstPadLinkFunction link);
868 void                    gst_pad_set_unlink_function             (GstPad *pad, GstPadUnlinkFunction unlink);
869
870 gboolean                gst_pad_can_link                        (GstPad *srcpad, GstPad *sinkpad);
871 GstPadLinkReturn        gst_pad_link                            (GstPad *srcpad, GstPad *sinkpad);
872 GstPadLinkReturn        gst_pad_link_full                       (GstPad *srcpad, GstPad *sinkpad, GstPadLinkCheck flags);
873 gboolean                gst_pad_unlink                          (GstPad *srcpad, GstPad *sinkpad);
874 gboolean                gst_pad_is_linked                       (GstPad *pad);
875
876 GstPad*                 gst_pad_get_peer                        (GstPad *pad);
877
878 /* capsnego functions */
879 void                    gst_pad_set_getcaps_function            (GstPad *pad, GstPadGetCapsFunction getcaps);
880 void                    gst_pad_set_acceptcaps_function         (GstPad *pad, GstPadAcceptCapsFunction acceptcaps);
881 void                    gst_pad_set_fixatecaps_function         (GstPad *pad, GstPadFixateCapsFunction fixatecaps);
882 void                    gst_pad_set_setcaps_function            (GstPad *pad, GstPadSetCapsFunction setcaps);
883
884 G_CONST_RETURN GstCaps* gst_pad_get_pad_template_caps           (GstPad *pad);
885
886 /* capsnego function for linked/unlinked pads */
887 GstCaps *               gst_pad_get_caps                        (GstPad * pad);
888 void                    gst_pad_fixate_caps                     (GstPad * pad, GstCaps *caps);
889 gboolean                gst_pad_accept_caps                     (GstPad * pad, GstCaps *caps);
890 gboolean                gst_pad_set_caps                        (GstPad * pad, GstCaps *caps);
891
892 GstCaps *               gst_pad_peer_get_caps                   (GstPad * pad);
893 gboolean                gst_pad_peer_accept_caps                (GstPad * pad, GstCaps *caps);
894
895 /* capsnego for linked pads */
896 GstCaps *               gst_pad_get_allowed_caps                (GstPad * pad);
897 GstCaps *               gst_pad_get_negotiated_caps             (GstPad * pad);
898
899 /* data passing functions to peer */
900 GstFlowReturn           gst_pad_push                            (GstPad *pad, GstBuffer *buffer);
901 GstFlowReturn           gst_pad_push_list                       (GstPad *pad, GstBufferList *list);
902 gboolean                gst_pad_check_pull_range                (GstPad *pad);
903 GstFlowReturn           gst_pad_pull_range                      (GstPad *pad, guint64 offset, guint size,
904                                                                  GstBuffer **buffer);
905 gboolean                gst_pad_push_event                      (GstPad *pad, GstEvent *event);
906 gboolean                gst_pad_event_default                   (GstPad *pad, GstEvent *event);
907
908 /* data passing functions on pad */
909 GstFlowReturn           gst_pad_chain                           (GstPad *pad, GstBuffer *buffer);
910 GstFlowReturn           gst_pad_chain_list                      (GstPad *pad, GstBufferList *list);
911 GstFlowReturn           gst_pad_get_range                       (GstPad *pad, guint64 offset, guint size,
912                                                                  GstBuffer **buffer);
913 gboolean                gst_pad_send_event                      (GstPad *pad, GstEvent *event);
914
915 /* pad tasks */
916 gboolean                gst_pad_start_task                      (GstPad *pad, GstTaskFunction func,
917                                                                  gpointer data);
918 gboolean                gst_pad_pause_task                      (GstPad *pad);
919 gboolean                gst_pad_stop_task                       (GstPad *pad);
920
921 /* internal links */
922 void                    gst_pad_set_iterate_internal_links_function (GstPad * pad,
923                                                                  GstPadIterIntLinkFunction iterintlink);
924 GstIterator *           gst_pad_iterate_internal_links          (GstPad * pad);
925 GstIterator *           gst_pad_iterate_internal_links_default  (GstPad * pad);
926
927
928 /* generic query function */
929 void                    gst_pad_set_query_type_function         (GstPad *pad, GstPadQueryTypeFunction type_func);
930 G_CONST_RETURN GstQueryType*
931                         gst_pad_get_query_types                 (GstPad *pad);
932 G_CONST_RETURN GstQueryType*
933                         gst_pad_get_query_types_default         (GstPad *pad);
934
935 gboolean                gst_pad_query                           (GstPad *pad, GstQuery *query);
936 gboolean                gst_pad_peer_query                      (GstPad *pad, GstQuery *query);
937 void                    gst_pad_set_query_function              (GstPad *pad, GstPadQueryFunction query);
938 gboolean                gst_pad_query_default                   (GstPad *pad, GstQuery *query);
939
940 /* misc helper functions */
941 gboolean                gst_pad_dispatcher                      (GstPad *pad, GstPadDispatcherFunction dispatch,
942                                                                  gpointer data);
943
944 G_END_DECLS
945
946 #endif /* __GST_PAD_H__ */