gst/: Remove comma at end of enumerator list.
[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/gstcaps.h>
32 #include <gst/gstevent.h>
33 #include <gst/gstquery.h>
34 #include <gst/gsttask.h>
35
36 G_BEGIN_DECLS
37
38 /*
39  * Pad base class
40  */
41 #define GST_TYPE_PAD                    (gst_pad_get_type ())
42 #define GST_IS_PAD(obj)                 (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_PAD))
43 #define GST_IS_PAD_CLASS(klass)         (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_PAD))
44 #define GST_PAD(obj)                    (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_PAD, GstPad))
45 #define GST_PAD_CLASS(klass)            (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_PAD, GstPadClass))
46 #define GST_PAD_CAST(obj)               ((GstPad*)(obj))
47
48
49 typedef struct _GstPad GstPad;
50 typedef struct _GstPadClass GstPadClass;
51
52 /**
53  * GstPadLinkReturn:
54  * @GST_PAD_LINK_OK             : link succeeded
55  * @GST_PAD_LINK_WRONG_HIERARCHY: pads have no common grandparent
56  * @GST_PAD_LINK_WAS_LINKED     : pad was already linked
57  * @GST_PAD_LINK_WRONG_DIRECTION: pads have wrong direction
58  * @GST_PAD_LINK_NOFORMAT       : pads do not have common format
59  * @GST_PAD_LINK_NOSCHED        : pads cannot cooperate in scheduling
60  * @GST_PAD_LINK_REFUSED        : refused for some reason
61  *
62  * Result values from gst_pad_link and friends.
63  */
64 typedef enum {
65   GST_PAD_LINK_OK               =  0,
66   GST_PAD_LINK_WRONG_HIERARCHY  = -1,
67   GST_PAD_LINK_WAS_LINKED       = -2,
68   GST_PAD_LINK_WRONG_DIRECTION  = -3,
69   GST_PAD_LINK_NOFORMAT         = -4,
70   GST_PAD_LINK_NOSCHED          = -5,
71   GST_PAD_LINK_REFUSED          = -6
72 } GstPadLinkReturn;
73
74 /**
75  * GST_PAD_LINK_FAILED:
76  * @ret: the #GstPadLinkReturn value
77  *
78  * Macro to test if the given #GstPadLinkReturn value indicates a failed
79  * link step.
80  */
81 #define GST_PAD_LINK_FAILED(ret) ((ret) < GST_PAD_LINK_OK)
82
83 /**
84  * GST_PAD_LINK_SUCCESSFUL:
85  * @ret: the #GstPadLinkReturn value
86  *
87  * Macro to test if the given #GstPadLinkReturn value indicates a successful
88  * link step.
89  */
90 #define GST_PAD_LINK_SUCCESSFUL(ret) ((ret) >= GST_PAD_LINK_OK)
91
92 /**
93  * GstFlowReturn:
94  * @GST_FLOW_CUSTOM_SUCCESS:     Elements can use values starting from
95  *                               this to define custom success codes. 
96  *                               Since 0.10.7.
97  * @GST_FLOW_RESEND:             Resend buffer, possibly with new caps.
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_ERROR:       Elements can use values starting from
108  *                               this to define custom error codes. Since 0.10.7.
109  *
110  * The result of passing data to a pad. 
111  *
112  * Note that the custom return values should not be exposed outside of the 
113  * element scope and are available since 0.10.7.
114  */
115 typedef enum {
116   /* custom success starts here */ 
117   GST_FLOW_CUSTOM_SUCCESS = 100,
118
119   /* core predefined */ 
120   GST_FLOW_RESEND         =  1,
121   GST_FLOW_OK             =  0,
122   /* expected failures */
123   GST_FLOW_NOT_LINKED     = -1,
124   GST_FLOW_WRONG_STATE    = -2,
125   /* error cases */
126   GST_FLOW_UNEXPECTED     = -3,
127   GST_FLOW_NOT_NEGOTIATED = -4,
128   GST_FLOW_ERROR          = -5,
129   GST_FLOW_NOT_SUPPORTED  = -6,
130
131   /* custom error starts here */ 
132   GST_FLOW_CUSTOM_ERROR   = -100
133 } GstFlowReturn;
134
135 /**
136  * GST_FLOW_IS_FATAL:
137  * @ret: a #GstFlowReturn value
138  *
139  * Macro to test if the given #GstFlowReturn value indicates a fatal
140  * error. This macro is mainly used in elements to decide when an error
141  * message should be posted on the bus.
142  */
143 #define GST_FLOW_IS_FATAL(ret) ((ret) <= GST_FLOW_UNEXPECTED)
144
145 /**
146  * GST_FLOW_IS_SUCCESS:
147  * @ret: a #GstFlowReturn value
148  *
149  * Macro to test if the given #GstFlowReturn value indicates a 
150  * successfull result
151  * This macro is mainly used in elements to decide if the processing
152  * of a buffer was successfull.
153  *
154  * Since: 0.10.7
155  */
156 #define GST_FLOW_IS_SUCCESS(ret) ((ret) >= GST_FLOW_OK)
157
158 G_CONST_RETURN gchar*   gst_flow_get_name       (GstFlowReturn ret);
159 GQuark                  gst_flow_to_quark       (GstFlowReturn ret);
160
161 /**
162  * GstActivateMode:
163  * @GST_ACTIVATE_NONE:           Pad will not handle dataflow
164  * @GST_ACTIVATE_PUSH:           Pad handles dataflow in downstream push mode
165  * @GST_ACTIVATE_PULL:           Pad handles dataflow in upstream pull mode
166  *
167  * The status of a GstPad. After activating a pad, which usually happens when the
168  * parent element goes from READY to PAUSED, the GstActivateMode defines if the
169  * pad operates in push or pull mode.
170  */
171 typedef enum {
172   GST_ACTIVATE_NONE,
173   GST_ACTIVATE_PUSH,
174   GST_ACTIVATE_PULL
175 } GstActivateMode;
176
177 /**
178  * GST_PAD_MODE_ACTIVATE:
179  * @mode: a #GstActivateMode
180  *
181  * Macro to test if the given #GstActivateMode value indicates that datapassing
182  * is possible or not.
183  */
184 #define GST_PAD_MODE_ACTIVATE(mode) ((mode) != GST_ACTIVATE_NONE)
185
186 /* pad states */
187 /**
188  * GstPadActivateFunction:
189  * @pad: a #GstPad
190  *
191  * This function is called when the pad is activated during the element
192  * READY to PAUSED state change. By default this function will call the
193  * activate function that puts the pad in push mode but elements can
194  * override this function to activate the pad in pull mode if they wish.
195  *
196  * Returns: TRUE if the pad could be activated.
197  */
198 typedef gboolean                (*GstPadActivateFunction)       (GstPad *pad);
199 /**
200  * GstPadActivateModeFunction:
201  * @pad: a #GstPad
202  * @active: activate or deactivate the pad.
203  *
204  * The prototype of the push and pull activate functions. 
205  *
206  * Returns: TRUE if the pad could be activated or deactivated.
207  */
208 typedef gboolean                (*GstPadActivateModeFunction)   (GstPad *pad, gboolean active);
209
210
211 /* data passing */
212 /**
213  * GstPadChainFunction:
214  * @pad: the #GstPad that performed the chain.
215  * @buffer: the #GstBuffer that is chained.
216  *
217  * A function that will be called on sinkpads when chaining buffers.
218  *
219  * Returns: GST_FLOW_OK for success
220  */
221 typedef GstFlowReturn           (*GstPadChainFunction)          (GstPad *pad, GstBuffer *buffer);
222 /**
223  * GstPadGetRangeFunction:
224  * @pad: the #GstPad to perform the getrange on.
225  * @offset: the offset of the range
226  * @length: the length of the range
227  * @buffer: a memory location to hold the result buffer
228  *
229  * This function will be called on sourcepads when a peer element
230  * request a buffer at the specified offset and length. If this function
231  * returns GST_FLOW_OK, the result buffer will be stored in @buffer. The 
232  * contents of @buffer is invalid for any other return value.
233  *
234  * Returns: GST_FLOW_OK for success
235  */
236 typedef GstFlowReturn           (*GstPadGetRangeFunction)       (GstPad *pad, guint64 offset,
237                                                                  guint length, GstBuffer **buffer);
238
239 /**
240  * GstPadEventFunction:
241  * @pad: the #GstPad to handle the event.
242  * @event: the #GstEvent to handle.
243  *
244  * Function signature to handle an event for the pad.
245  *
246  * Returns: TRUE if the pad could handle the event.
247  */
248 typedef gboolean                (*GstPadEventFunction)          (GstPad *pad, GstEvent *event);
249
250
251 /* FIXME: 0.11: deprecate me, check range should use seeking query */
252 /**
253  * GstPadCheckGetRangeFunction:
254  * @pad: a #GstPad
255  *
256  * Check if @pad can be activated in pull mode.
257  *
258  * This function will be deprecated after 0.10; use the seeking query to check
259  * if a pad can support random access.
260  *
261  * Returns: TRUE if the pad can operate in pull mode.
262  */
263 typedef gboolean                (*GstPadCheckGetRangeFunction)  (GstPad *pad);
264
265 /* internal links */
266 /**
267  * GstPadIntLinkFunction:
268  * @pad: The #GstPad to query.
269  *
270  * The signature of the internal pad link function.
271  *
272  * Returns: a newly allocated #GList of pads that are linked to the given pad on
273  *  the inside of the parent element.
274  *  The caller must call g_list_free() on it after use.
275  */
276 typedef GList*                  (*GstPadIntLinkFunction)        (GstPad *pad);
277
278
279 /* generic query function */
280 /**
281  * GstPadQueryTypeFunction:
282  * @pad: a #GstPad to query
283  *
284  * The signature of the query types function.
285  *
286  * Returns: a constant array of query types
287  */
288 typedef const GstQueryType*     (*GstPadQueryTypeFunction)      (GstPad *pad);
289
290 /**
291  * GstPadQueryFunction:
292  * @pad: the #GstPad to query.
293  * @query: the #GstQuery object to execute
294  *
295  * The signature of the query function.
296  *
297  * Returns: TRUE if the query could be performed.
298  */
299 typedef gboolean                (*GstPadQueryFunction)          (GstPad *pad, GstQuery *query);
300
301
302 /* linking */
303 /**
304  * GstPadLinkFunction
305  * @pad: the #GstPad that is linked.
306  * @peer: the peer #GstPad of the link
307  *
308  * Function signature to handle a new link on the pad.
309  *
310  * Returns: the result of the link with the specified peer.
311  */
312 typedef GstPadLinkReturn        (*GstPadLinkFunction)           (GstPad *pad, GstPad *peer);
313 /**
314  * GstPadUnlinkFunction
315  * @pad: the #GstPad that is linked.
316  *
317  * Function signature to handle a unlinking the pad prom its peer.
318  */
319 typedef void                    (*GstPadUnlinkFunction)         (GstPad *pad);
320
321
322 /* caps nego */
323 /**
324  * GstPadGetCapsFunction:
325  * @pad: the #GstPad to get the capabilities of.
326  *
327  * Returns a copy of the capabilities of the specified pad. By default this
328  * function will return the pad template capabilities, but can optionally
329  * be overridden by elements.
330  *
331  * Returns: a newly allocated copy #GstCaps of the pad.
332  */
333 typedef GstCaps*                (*GstPadGetCapsFunction)        (GstPad *pad);
334
335 /**
336  * GstPadSetCapsFunction:
337  * @pad: the #GstPad to set the capabilities of.
338  * @caps: the #GstCaps to set
339  *
340  * Set @caps on @pad. By default this function updates the caps of the
341  * pad but the function can be overriden by elements to perform extra 
342  * actions or verifications.
343  *
344  * Returns: TRUE if the caps could be set on the pad.
345  */
346 typedef gboolean                (*GstPadSetCapsFunction)        (GstPad *pad, GstCaps *caps);
347 /**
348  * GstPadAcceptCapsFunction:
349  * @pad: the #GstPad to check
350  * @caps: the #GstCaps to check
351  *
352  * Check if @pad can accept @caps. By default this function will see if @caps
353  * intersect with the result from gst_pad_get_caps() by can be overridden to
354  * perform extra checks.
355  *
356  * Returns: TRUE if the caps can be accepted by the pad.
357  */
358 typedef gboolean                (*GstPadAcceptCapsFunction)     (GstPad *pad, GstCaps *caps);
359 /**
360  * GstPadFixateCapsFunction:
361  * @pad: a #GstPad  
362  * @caps: the #GstCaps to fixate
363  *
364  * Given possibly unfixed caps @caps, let @pad use its default prefered 
365  * format to make a fixed caps. @caps should be writable. By default this
366  * function will pick the first value of any ranges or lists in the caps but
367  * elements can override this function to perform other behaviour.
368  */
369 typedef void                    (*GstPadFixateCapsFunction)     (GstPad *pad, GstCaps *caps);
370 /**
371  * GstPadBufferAllocFunction:
372  * @pad: a sink #GstPad  
373  * @offset: the desired offset of the buffer
374  * @size: the desired size of the buffer
375  * @caps: the desired caps of the buffer
376  * @buf: pointer to hold the allocated buffer.
377  *
378  * Ask the sinkpad @pad to allocate a buffer with @offset, @size and @caps.
379  * The result will be stored in @buf.
380  *
381  * The purpose of this function is to allocate a buffer that is optimal to
382  * be processed by @pad. The function is mostly overridden by elements that can
383  * provide a hardware buffer in order to avoid additional memcpy operations.
384  *
385  * The function can return a buffer that does not have @caps, in which case the
386  * upstream element requests a format change. 
387  *
388  * When this function returns anything else than GST_FLOW_OK, the buffer allocation
389  * failed and @buf does not contain valid data.
390  *
391  * By default this function returns a new buffer of @size and with @caps containing
392  * purely malloced data.
393  *
394  * Returns: GST_FLOW_OK if @buf contains a valid buffer, any other return
395  *  value means @buf does not hold a valid buffer.
396  */
397 typedef GstFlowReturn           (*GstPadBufferAllocFunction)    (GstPad *pad, guint64 offset, guint size,
398                                                                  GstCaps *caps, GstBuffer **buf);
399
400 /* misc */
401 /**
402  * GstPadDispatcherFunction:
403  * @pad: the #GstPad that is dispatched.
404  * @data: the gpointer to optional user data.
405  *
406  * A dispatcher function is called for all internally linked pads, see
407  * gst_pad_dispatcher().
408  *
409  * Returns: TRUE if the dispatching procedure has to be stopped.
410  */
411 typedef gboolean                (*GstPadDispatcherFunction)     (GstPad *pad, gpointer data);
412
413 /**
414  * GstPadBlockCallback:
415  * @pad: the #GstPad that is blockend or unblocked.
416  * @blocked: blocking state for the pad
417  * @user_data: the gpointer to optional user data.
418  *
419  * Callback used by gst_pad_set_blocked_async(). Gets called when the blocking
420  * operation succeeds.
421  */
422 typedef void                    (*GstPadBlockCallback)          (GstPad *pad, gboolean blocked, gpointer user_data);
423
424 /**
425  * GstPadDirection:
426  * @GST_PAD_UNKNOWN: direction is unknown.
427  * @GST_PAD_SRC: the pad is a source pad.
428  * @GST_PAD_SINK: the pad is a sink pad.
429  *
430  * The direction of a pad.
431  */
432 typedef enum {
433   GST_PAD_UNKNOWN,
434   GST_PAD_SRC,
435   GST_PAD_SINK
436 } GstPadDirection;
437
438 /**
439  * GstPadFlags:
440  * @GST_PAD_BLOCKED: is dataflow on a pad blocked
441  * @GST_PAD_FLUSHING: is pad refusing buffers
442  * @GST_PAD_IN_GETCAPS: GstPadGetCapsFunction() is running now
443  * @GST_PAD_IN_SETCAPS: GstPadSetCapsFunction() is running now
444  * @GST_PAD_FLAG_LAST: offset to define more flags
445  *
446  * Pad state flags
447  */
448 typedef enum {
449   GST_PAD_BLOCKED       = (GST_OBJECT_FLAG_LAST << 0),
450   GST_PAD_FLUSHING      = (GST_OBJECT_FLAG_LAST << 1),
451   GST_PAD_IN_GETCAPS    = (GST_OBJECT_FLAG_LAST << 2),
452   GST_PAD_IN_SETCAPS    = (GST_OBJECT_FLAG_LAST << 3),
453   /* padding */
454   GST_PAD_FLAG_LAST     = (GST_OBJECT_FLAG_LAST << 8)
455 } GstPadFlags;
456
457 /* FIXME: this awful circular dependency need to be resolved properly (see padtemplate.h) */
458 typedef struct _GstPadTemplate GstPadTemplate;
459
460 /**
461  * GstPad:
462  * @element_private: private data owned by the parent element
463  * @padtemplate: padtemplate for this pad
464  * @direction: the direction of the pad, cannot change after creating
465  *             the pad.
466  * @stream_rec_lock: recursive stream lock of the pad, used to protect
467  *                   the data used in streaming.
468  * @task: task for this pad if the pad is actively driving dataflow.
469  * @preroll_lock: lock used when prerolling
470  * @preroll_cond: conf to signal preroll
471  * @block_cond: conditional to signal pad block
472  * @block_callback: callback for the pad block if any
473  * @block_data: user data for @block_callback
474  * @caps: the current caps of the pad
475  * @getcapsfunc: function to get caps of the pad
476  * @setcapsfunc: function to set caps on the pad
477  * @acceptcapsfunc: function to check if pad can accept caps
478  * @fixatecapsfunc: function to fixate caps
479  * @activatefunc: pad activation function
480  * @activatepushfunc: function to activate/deactivate pad in push mode
481  * @activatepullfunc: function to activate/deactivate pad in pull mode
482  * @linkfunc: function called when pad is linked
483  * @unlinkfunc: function called when pad is unlinked
484  * @peer: the pad this pad is linked to
485  * @sched_private: private storage for the scheduler
486  * @chainfunc: function to chain data to pad
487  * @checkgetrangefunc: function to check if pad can operate in pull mode
488  * @getrangefunc: function to get a range of data from a pad
489  * @eventfunc: function to send an event to a pad
490  * @mode: current activation mode of the pad
491  * @querytypefunc: get list of supported queries
492  * @queryfunc: perform a query on the pad
493  * @intlinkfunc: get the internal links of this pad
494  * @bufferallocfunc: function to allocate a buffer for this pad
495  * @do_buffer_signals: counter counting installed buffer signals
496  * @do_event_signals: counter counting installed event signals
497  * 
498  * The #GstPad structure. Use the functions to update the variables.
499  */
500 struct _GstPad {
501   GstObject                     object;
502
503   /*< public >*/
504   gpointer                      element_private;
505
506   GstPadTemplate                *padtemplate;
507
508   GstPadDirection                direction;
509
510   /*< public >*/ /* with STREAM_LOCK */
511   /* streaming rec_lock */
512   GStaticRecMutex               *stream_rec_lock;
513   GstTask                       *task;
514   /*< public >*/ /* with PREROLL_LOCK */
515   GMutex                        *preroll_lock;
516   GCond                         *preroll_cond;
517
518   /*< public >*/ /* with LOCK */
519   /* block cond, mutex is from the object */
520   GCond                         *block_cond;
521   GstPadBlockCallback            block_callback;
522   gpointer                       block_data;
523
524   /* the pad capabilities */
525   GstCaps                       *caps;
526   GstPadGetCapsFunction         getcapsfunc;
527   GstPadSetCapsFunction         setcapsfunc;
528   GstPadAcceptCapsFunction       acceptcapsfunc;
529   GstPadFixateCapsFunction       fixatecapsfunc;
530
531   GstPadActivateFunction         activatefunc;
532   GstPadActivateModeFunction     activatepushfunc;
533   GstPadActivateModeFunction     activatepullfunc;
534
535   /* pad link */
536   GstPadLinkFunction             linkfunc;
537   GstPadUnlinkFunction           unlinkfunc;
538   GstPad                        *peer;
539
540   gpointer                       sched_private;
541
542   /* data transport functions */
543   GstPadChainFunction            chainfunc;
544   GstPadCheckGetRangeFunction    checkgetrangefunc;
545   GstPadGetRangeFunction         getrangefunc;
546   GstPadEventFunction            eventfunc;
547
548   GstActivateMode                mode;
549
550   /* generic query method */
551   GstPadQueryTypeFunction        querytypefunc;
552   GstPadQueryFunction            queryfunc;
553
554   /* internal links */
555   GstPadIntLinkFunction          intlinkfunc;
556
557   GstPadBufferAllocFunction      bufferallocfunc;
558
559   /* whether to emit signals for have-data. counts number
560    * of handlers attached. */
561   gint                           do_buffer_signals;
562   gint                           do_event_signals;
563
564   /*< private >*/
565   gpointer _gst_reserved[GST_PADDING];
566 };
567
568 struct _GstPadClass {
569   GstObjectClass        parent_class;
570
571   /* signal callbacks */
572   void          (*linked)               (GstPad *pad, GstPad *peer);
573   void          (*unlinked)             (GstPad *pad, GstPad *peer);
574   void          (*request_link)         (GstPad *pad);
575   gboolean      (*have_data)            (GstPad *pad, GstMiniObject *data);
576
577   /*< private >*/
578   gpointer _gst_reserved[GST_PADDING];
579 };
580
581
582 /***** helper macros *****/
583 /* GstPad */
584 #define GST_PAD_NAME(pad)               (GST_OBJECT_NAME(pad))
585 #define GST_PAD_PARENT(pad)             (GST_ELEMENT_CAST(GST_OBJECT_PARENT(pad)))
586 #define GST_PAD_ELEMENT_PRIVATE(pad)    (GST_PAD_CAST(pad)->element_private)
587 #define GST_PAD_PAD_TEMPLATE(pad)       (GST_PAD_CAST(pad)->padtemplate)
588 #define GST_PAD_DIRECTION(pad)          (GST_PAD_CAST(pad)->direction)
589 #define GST_PAD_TASK(pad)               (GST_PAD_CAST(pad)->task)
590 #define GST_PAD_ACTIVATE_MODE(pad)      (GST_PAD_CAST(pad)->mode)
591
592 #define GST_PAD_ACTIVATEFUNC(pad)       (GST_PAD_CAST(pad)->activatefunc)
593 #define GST_PAD_ACTIVATEPUSHFUNC(pad)   (GST_PAD_CAST(pad)->activatepushfunc)
594 #define GST_PAD_ACTIVATEPULLFUNC(pad)   (GST_PAD_CAST(pad)->activatepullfunc)
595 #define GST_PAD_CHAINFUNC(pad)          (GST_PAD_CAST(pad)->chainfunc)
596 #define GST_PAD_CHECKGETRANGEFUNC(pad)  (GST_PAD_CAST(pad)->checkgetrangefunc)
597 #define GST_PAD_GETRANGEFUNC(pad)       (GST_PAD_CAST(pad)->getrangefunc)
598 #define GST_PAD_EVENTFUNC(pad)          (GST_PAD_CAST(pad)->eventfunc)
599 #define GST_PAD_QUERYTYPEFUNC(pad)      (GST_PAD_CAST(pad)->querytypefunc)
600 #define GST_PAD_QUERYFUNC(pad)          (GST_PAD_CAST(pad)->queryfunc)
601 #define GST_PAD_INTLINKFUNC(pad)        (GST_PAD_CAST(pad)->intlinkfunc)
602
603 #define GST_PAD_PEER(pad)               (GST_PAD_CAST(pad)->peer)
604 #define GST_PAD_LINKFUNC(pad)           (GST_PAD_CAST(pad)->linkfunc)
605 #define GST_PAD_UNLINKFUNC(pad)         (GST_PAD_CAST(pad)->unlinkfunc)
606
607 #define GST_PAD_CAPS(pad)               (GST_PAD_CAST(pad)->caps)
608 #define GST_PAD_GETCAPSFUNC(pad)        (GST_PAD_CAST(pad)->getcapsfunc)
609 #define GST_PAD_SETCAPSFUNC(pad)        (GST_PAD_CAST(pad)->setcapsfunc)
610 #define GST_PAD_ACCEPTCAPSFUNC(pad)     (GST_PAD_CAST(pad)->acceptcapsfunc)
611 #define GST_PAD_FIXATECAPSFUNC(pad)     (GST_PAD_CAST(pad)->fixatecapsfunc)
612
613 #define GST_PAD_BUFFERALLOCFUNC(pad)    (GST_PAD_CAST(pad)->bufferallocfunc)
614
615 #define GST_PAD_DO_BUFFER_SIGNALS(pad)  (GST_PAD_CAST(pad)->do_buffer_signals)
616 #define GST_PAD_DO_EVENT_SIGNALS(pad)   (GST_PAD_CAST(pad)->do_event_signals)
617
618 #define GST_PAD_IS_LINKED(pad)          (GST_PAD_PEER(pad) != NULL)
619 #define GST_PAD_IS_BLOCKED(pad)         (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_BLOCKED))
620 #define GST_PAD_IS_FLUSHING(pad)        (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLUSHING))
621 #define GST_PAD_IS_IN_GETCAPS(pad)      (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_IN_GETCAPS))
622 #define GST_PAD_IS_IN_SETCAPS(pad)      (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_IN_SETCAPS))
623 #define GST_PAD_IS_SRC(pad)             (GST_PAD_DIRECTION(pad) == GST_PAD_SRC)
624 #define GST_PAD_IS_SINK(pad)            (GST_PAD_DIRECTION(pad) == GST_PAD_SINK)
625
626 #define GST_PAD_SET_FLUSHING(pad)       (GST_OBJECT_FLAG_SET (pad, GST_PAD_FLUSHING))
627 #define GST_PAD_UNSET_FLUSHING(pad)     (GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLUSHING))
628
629 /**
630  * GST_PAD_GET_STREAM_LOCK:
631  * @pad: a #GstPad
632  *
633  * Get the stream lock of @pad. The stream lock is protecting the
634  * resources used in the data processing functions of @pad.
635  */
636 #define GST_PAD_GET_STREAM_LOCK(pad)    (GST_PAD_CAST(pad)->stream_rec_lock)
637 /**
638  * GST_PAD_STREAM_LOCK:
639  * @pad: a #GstPad
640  *
641  * Lock the stream lock of @pad.
642  */
643 #define GST_PAD_STREAM_LOCK(pad)        (g_static_rec_mutex_lock(GST_PAD_GET_STREAM_LOCK(pad)))
644 /**
645  * GST_PAD_STREAM_LOCK_FULL:
646  * @pad: a #GstPad
647  * @t: the number of times to recursively lock
648  *
649  * Lock the stream lock of @pad @t times.
650  */
651 #define GST_PAD_STREAM_LOCK_FULL(pad,t) (g_static_rec_mutex_lock_full(GST_PAD_GET_STREAM_LOCK(pad), t))
652 /**
653  * GST_PAD_STREAM_TRYLOCK:
654  * @pad: a #GstPad
655  *
656  * Try to Lock the stream lock of the pad, return TRUE if the lock could be
657  * taken.
658  */
659 #define GST_PAD_STREAM_TRYLOCK(pad)     (g_static_rec_mutex_trylock(GST_PAD_GET_STREAM_LOCK(pad)))
660 /**
661  * GST_PAD_STREAM_UNLOCK:
662  * @pad: a #GstPad
663  *
664  * Unlock the stream lock of @pad.
665  */
666 #define GST_PAD_STREAM_UNLOCK(pad)      (g_static_rec_mutex_unlock(GST_PAD_GET_STREAM_LOCK(pad)))
667 /**
668  * GST_PAD_STREAM_UNLOCK_FULL:
669  * @pad: a #GstPad
670  *
671  * Fully unlock the recursive stream lock of @pad, return the number of times
672  * @pad was locked.
673  */
674 #define GST_PAD_STREAM_UNLOCK_FULL(pad) (g_static_rec_mutex_unlock_full(GST_PAD_GET_STREAM_LOCK(pad)))
675
676 #define GST_PAD_GET_PREROLL_LOCK(pad)   (GST_PAD_CAST(pad)->preroll_lock)
677 #define GST_PAD_PREROLL_LOCK(pad)       (g_mutex_lock(GST_PAD_GET_PREROLL_LOCK(pad)))
678 #define GST_PAD_PREROLL_TRYLOCK(pad)    (g_mutex_trylock(GST_PAD_GET_PREROLL_LOCK(pad)))
679 #define GST_PAD_PREROLL_UNLOCK(pad)     (g_mutex_unlock(GST_PAD_GET_PREROLL_LOCK(pad)))
680
681 #define GST_PAD_GET_PREROLL_COND(pad)   (GST_PAD_CAST(pad)->preroll_cond)
682 #define GST_PAD_PREROLL_WAIT(pad)       \
683     g_cond_wait (GST_PAD_GET_PREROLL_COND (pad), GST_PAD_GET_PREROLL_LOCK (pad))
684 #define GST_PAD_PREROLL_TIMED_WAIT(pad, timeval) \
685     g_cond_timed_wait (GST_PAD_GET_PREROLL_COND (pad), GST_PAD_GET_PREROLL_LOCK (pad), timeval)
686 #define GST_PAD_PREROLL_SIGNAL(pad)     g_cond_signal (GST_PAD_GET_PREROLL_COND (pad));
687 #define GST_PAD_PREROLL_BROADCAST(pad)  g_cond_broadcast (GST_PAD_GET_PREROLL_COND (pad));
688
689 #define GST_PAD_BLOCK_GET_COND(pad)     (GST_PAD_CAST(pad)->block_cond)
690 #define GST_PAD_BLOCK_WAIT(pad)         (g_cond_wait(GST_PAD_BLOCK_GET_COND (pad), GST_OBJECT_GET_LOCK (pad)))
691 #define GST_PAD_BLOCK_SIGNAL(pad)       (g_cond_signal(GST_PAD_BLOCK_GET_COND (pad)))
692
693 /* FIXME: this awful circular dependency need to be resolved properly (see padtemplate.h) */
694 #include <gst/gstpadtemplate.h>
695
696 GType                   gst_pad_get_type                        (void);
697
698 /* creating pads */
699 GstPad*                 gst_pad_new                             (const gchar *name, GstPadDirection direction);
700 GstPad*                 gst_pad_new_from_template               (GstPadTemplate *templ, const gchar *name);
701 GstPad*                 gst_pad_new_from_static_template        (GstStaticPadTemplate *templ, const gchar *name);
702
703
704 /**
705  * gst_pad_get_name:
706  * @pad: the pad to get the name from
707  *
708  * Get a copy of the name of the pad. g_free() after usage.
709  *
710  * MT safe.
711  */
712 #define gst_pad_get_name(pad) gst_object_get_name (GST_OBJECT_CAST (pad))
713 /**
714  * gst_pad_get_parent:
715  * @pad: the pad to get the parent of
716  *
717  * Get the parent of @pad. This function increases the refcount
718  * of the parent object so you should gst_object_unref() it after usage.
719  * Can return NULL if the pad did not have a parent.
720  *
721  * MT safe.
722  */
723 #define gst_pad_get_parent(pad) gst_object_get_parent (GST_OBJECT_CAST (pad))
724
725 GstPadDirection         gst_pad_get_direction                   (GstPad *pad);
726
727 gboolean                gst_pad_set_active                      (GstPad *pad, gboolean active);
728 gboolean                gst_pad_is_active                       (GstPad *pad);
729 gboolean                gst_pad_activate_pull                   (GstPad *pad, gboolean active);
730 gboolean                gst_pad_activate_push                   (GstPad *pad, gboolean active);
731
732 gboolean                gst_pad_set_blocked                     (GstPad *pad, gboolean blocked);
733 gboolean                gst_pad_set_blocked_async               (GstPad *pad, gboolean blocked,
734                                                                  GstPadBlockCallback callback, gpointer user_data);
735 gboolean                gst_pad_is_blocked                      (GstPad *pad);
736
737 void                    gst_pad_set_element_private             (GstPad *pad, gpointer priv);
738 gpointer                gst_pad_get_element_private             (GstPad *pad);
739
740 GstPadTemplate*         gst_pad_get_pad_template                (GstPad *pad);
741
742 void                    gst_pad_set_bufferalloc_function        (GstPad *pad, GstPadBufferAllocFunction bufalloc);
743 GstFlowReturn           gst_pad_alloc_buffer                    (GstPad *pad, guint64 offset, gint size,
744                                                                  GstCaps *caps, GstBuffer **buf);
745 GstFlowReturn           gst_pad_alloc_buffer_and_set_caps       (GstPad *pad, guint64 offset, gint size,
746                                                                  GstCaps *caps, GstBuffer **buf);
747
748 /* data passing setup functions */
749 void                    gst_pad_set_activate_function           (GstPad *pad, GstPadActivateFunction activate);
750 void                    gst_pad_set_activatepull_function       (GstPad *pad, GstPadActivateModeFunction activatepull);
751 void                    gst_pad_set_activatepush_function       (GstPad *pad, GstPadActivateModeFunction activatepush);
752 void                    gst_pad_set_chain_function              (GstPad *pad, GstPadChainFunction chain);
753 void                    gst_pad_set_getrange_function           (GstPad *pad, GstPadGetRangeFunction get);
754 void                    gst_pad_set_checkgetrange_function      (GstPad *pad, GstPadCheckGetRangeFunction check);
755 void                    gst_pad_set_event_function              (GstPad *pad, GstPadEventFunction event);
756
757 /* pad links */
758 void                    gst_pad_set_link_function               (GstPad *pad, GstPadLinkFunction link);
759 void                    gst_pad_set_unlink_function             (GstPad *pad, GstPadUnlinkFunction unlink);
760
761 GstPadLinkReturn        gst_pad_link                            (GstPad *srcpad, GstPad *sinkpad);
762 gboolean                gst_pad_unlink                          (GstPad *srcpad, GstPad *sinkpad);
763 gboolean                gst_pad_is_linked                       (GstPad *pad);
764
765 GstPad*                 gst_pad_get_peer                        (GstPad *pad);
766
767 /* capsnego functions */
768 void                    gst_pad_set_getcaps_function            (GstPad *pad, GstPadGetCapsFunction getcaps);
769 void                    gst_pad_set_acceptcaps_function         (GstPad *pad, GstPadAcceptCapsFunction acceptcaps);
770 void                    gst_pad_set_fixatecaps_function         (GstPad *pad, GstPadFixateCapsFunction fixatecaps);
771 void                    gst_pad_set_setcaps_function            (GstPad *pad, GstPadSetCapsFunction setcaps);
772
773 G_CONST_RETURN GstCaps* gst_pad_get_pad_template_caps           (GstPad *pad);
774
775 /* capsnego function for connected/unconnected pads */
776 GstCaps *               gst_pad_get_caps                        (GstPad * pad);
777 void                    gst_pad_fixate_caps                     (GstPad * pad, GstCaps *caps);
778 gboolean                gst_pad_accept_caps                     (GstPad * pad, GstCaps *caps);
779 gboolean                gst_pad_set_caps                        (GstPad * pad, GstCaps *caps);
780
781 GstCaps *               gst_pad_peer_get_caps                   (GstPad * pad);
782 gboolean                gst_pad_peer_accept_caps                (GstPad * pad, GstCaps *caps);
783
784 /* capsnego for connected pads */
785 GstCaps *               gst_pad_get_allowed_caps                (GstPad * srcpad);
786 GstCaps *               gst_pad_get_negotiated_caps             (GstPad * pad);
787
788 /* data passing functions to peer */
789 GstFlowReturn           gst_pad_push                            (GstPad *pad, GstBuffer *buffer);
790 gboolean                gst_pad_check_pull_range                (GstPad *pad);
791 GstFlowReturn           gst_pad_pull_range                      (GstPad *pad, guint64 offset, guint size,
792                                                                  GstBuffer **buffer);
793 gboolean                gst_pad_push_event                      (GstPad *pad, GstEvent *event);
794 gboolean                gst_pad_event_default                   (GstPad *pad, GstEvent *event);
795
796 /* data passing functions on pad */
797 GstFlowReturn           gst_pad_chain                           (GstPad *pad, GstBuffer *buffer);
798 GstFlowReturn           gst_pad_get_range                       (GstPad *pad, guint64 offset, guint size,
799                                                                  GstBuffer **buffer);
800 gboolean                gst_pad_send_event                      (GstPad *pad, GstEvent *event);
801
802 /* pad tasks */
803 gboolean                gst_pad_start_task                      (GstPad *pad, GstTaskFunction func,
804                                                                  gpointer data);
805 gboolean                gst_pad_pause_task                      (GstPad *pad);
806 gboolean                gst_pad_stop_task                       (GstPad *pad);
807
808 /* internal links */
809 void                    gst_pad_set_internal_link_function      (GstPad *pad, GstPadIntLinkFunction intlink);
810 GList*                  gst_pad_get_internal_links              (GstPad *pad);
811 GList*                  gst_pad_get_internal_links_default      (GstPad *pad);
812
813 /* generic query function */
814 void                    gst_pad_set_query_type_function         (GstPad *pad, GstPadQueryTypeFunction type_func);
815 G_CONST_RETURN GstQueryType*
816                         gst_pad_get_query_types                 (GstPad *pad);
817 G_CONST_RETURN GstQueryType*
818                         gst_pad_get_query_types_default         (GstPad *pad);
819
820 gboolean                gst_pad_query                           (GstPad *pad, GstQuery *query);
821 void                    gst_pad_set_query_function              (GstPad *pad, GstPadQueryFunction query);
822 gboolean                gst_pad_query_default                   (GstPad *pad, GstQuery *query);
823
824 /* misc helper functions */
825 gboolean                gst_pad_dispatcher                      (GstPad *pad, GstPadDispatcherFunction dispatch,
826                                                                  gpointer data);
827
828 #ifndef GST_DISABLE_LOADSAVE
829 void                    gst_pad_load_and_link                   (xmlNodePtr self, GstObject *parent);
830 #endif
831
832 G_END_DECLS
833
834 #endif /* __GST_PAD_H__ */