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