gst/: Simplify pad activation.
[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/gstprobe.h>
34 #include <gst/gstquery.h>
35 #include <gst/gsttask.h>
36
37
38 G_BEGIN_DECLS
39
40 GST_EXPORT GType _gst_pad_type;
41 GST_EXPORT GType _gst_real_pad_type;
42 GST_EXPORT GType _gst_ghost_pad_type;
43
44 /*
45  * Pad base class
46  */
47 #define GST_TYPE_PAD                    (_gst_pad_type)
48 #define GST_IS_PAD(obj)                 (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_PAD))
49 #define GST_IS_PAD_FAST(obj)            (G_OBJECT_TYPE(obj) == GST_TYPE_REAL_PAD || \
50                                          G_OBJECT_TYPE(obj) == GST_TYPE_GHOST_PAD)
51 #define GST_IS_PAD_CLASS(klass)         (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_PAD))
52 #define GST_PAD(obj)                    (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_PAD, GstPad))
53 #define GST_PAD_CLASS(klass)            (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_PAD, GstPadClass))
54 #define GST_PAD_CAST(obj)               ((GstPad*)(obj))
55
56 /* 
57  * Real Pads
58  */
59 #define GST_TYPE_REAL_PAD               (_gst_real_pad_type)
60 #define GST_IS_REAL_PAD(obj)            (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_REAL_PAD))
61 #define GST_IS_REAL_PAD_FAST(obj)       (G_OBJECT_TYPE(obj) == GST_TYPE_REAL_PAD)
62 #define GST_IS_REAL_PAD_CLASS(klass)    (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_REAL_PAD))
63 #define GST_REAL_PAD(obj)               (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_REAL_PAD, GstRealPad))
64 #define GST_REAL_PAD_CLASS(klass)       (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_REAL_PAD, GstRealPadClass))
65 #define GST_REAL_PAD_CAST(obj)          ((GstRealPad*)(obj))
66
67 /*
68  * Ghost Pads
69  */
70 #define GST_TYPE_GHOST_PAD              (_gst_ghost_pad_type)
71 #define GST_IS_GHOST_PAD(obj)           (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_GHOST_PAD))
72 #define GST_IS_GHOST_PAD_FAST(obj)      (G_OBJECT_TYPE(obj) == GST_TYPE_GHOST_PAD)
73 #define GST_IS_GHOST_PAD_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_GHOST_PAD))
74 #define GST_GHOST_PAD(obj)              (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_GHOST_PAD, GstGhostPad))
75 #define GST_GHOST_PAD_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_GHOST_PAD, GstGhostPadClass))
76 #define GST_GHOST_PAD_CAST(obj)         ((GstGhostPad*)(obj))
77
78
79 /*typedef struct _GstPad GstPad; */
80 /*typedef struct _GstPadClass GstPadClass;*/
81 typedef struct _GstRealPad GstRealPad;
82 typedef struct _GstRealPadClass GstRealPadClass;
83 typedef struct _GstGhostPad GstGhostPad;
84 typedef struct _GstGhostPadClass GstGhostPadClass;
85 /*typedef struct _GstPadTemplate GstPadTemplate;*/
86 /*typedef struct _GstPadTemplateClass GstPadTemplateClass;*/
87 typedef struct _GstStaticPadTemplate GstStaticPadTemplate;
88 typedef struct _GstPadLink GstPadLink;
89
90 typedef enum {
91   GST_PAD_LINK_NOSCHED          = -5,   /* pads cannot cooperate in scheduling */
92   GST_PAD_LINK_NOFORMAT         = -4,   /* pads do not have common format */
93   GST_PAD_LINK_REFUSED          = -3,   /* refused for some reason */
94   GST_PAD_LINK_WRONG_DIRECTION  = -2,   /* pads have wrong direction */
95   GST_PAD_LINK_WAS_LINKED       = -1,   /* pad was already linked */
96   GST_PAD_LINK_OK               =  0,   /* link ok */
97 } GstPadLinkReturn;
98
99 #define GST_PAD_LINK_FAILED(ret) ((ret) < GST_PAD_LINK_OK)
100 #define GST_PAD_LINK_SUCCESSFUL(ret) ((ret) >= GST_PAD_LINK_OK)
101
102 typedef enum {
103   GST_FLOW_OK             =  0,         /* data passing was ok */
104   GST_FLOW_RESEND         =  1,         /* resend buffer, possibly with new caps */
105   GST_FLOW_ERROR          = -1,         /* some (fatal) error occured */
106   GST_FLOW_NOT_CONNECTED  = -2,         /* pad is not connected */
107   GST_FLOW_NOT_NEGOTIATED = -3,         /* pad is not negotiated */
108   GST_FLOW_WRONG_STATE    = -4,         /* pad is in wrong state */
109   GST_FLOW_UNEXPECTED     = -5,         /* did not expect anything, this is not fatal */
110   GST_FLOW_NOT_SUPPORTED  = -6          /* function not supported */
111 } GstFlowReturn;
112
113 typedef enum {
114   GST_ACTIVATE_NONE,
115   GST_ACTIVATE_PUSH,
116   GST_ACTIVATE_PULL,
117 } GstActivateMode;
118
119 #define GST_PAD_MODE_ACTIVATE(mode) ((mode) != GST_ACTIVATE_NONE)
120
121 /* convenience functions */
122 #ifdef G_HAVE_ISO_VARARGS
123 #define GST_PAD_QUERY_TYPE_FUNCTION(functionname, ...)  GST_QUERY_TYPE_FUNCTION (GstPad *, functionname, __VA_ARGS__);
124 #define GST_PAD_FORMATS_FUNCTION(functionname, ...)     GST_FORMATS_FUNCTION (GstPad *, functionname, __VA_ARGS__);
125 #define GST_PAD_EVENT_MASK_FUNCTION(functionname, ...)  GST_EVENT_MASK_FUNCTION (GstPad *, functionname, __VA_ARGS__);
126 #elif defined(G_HAVE_GNUC_VARARGS)
127 #define GST_PAD_QUERY_TYPE_FUNCTION(functionname, a...) GST_QUERY_TYPE_FUNCTION (GstPad *, functionname, a);
128 #define GST_PAD_FORMATS_FUNCTION(functionname, a...)    GST_FORMATS_FUNCTION (GstPad *, functionname, a);
129 #define GST_PAD_EVENT_MASK_FUNCTION(functionname, a...) GST_EVENT_MASK_FUNCTION (GstPad *, functionname, a);
130 #endif
131
132  
133 /* pad states */
134 typedef gboolean                (*GstPadActivateFunction)       (GstPad *pad, GstActivateMode mode);
135
136 /* data passing */
137 typedef void                    (*GstPadLoopFunction)           (GstPad *pad);
138 typedef GstFlowReturn           (*GstPadChainFunction)          (GstPad *pad, GstBuffer *buffer);
139 typedef GstFlowReturn           (*GstPadGetRangeFunction)       (GstPad *pad, guint64 offset, 
140                                                                  guint length, GstBuffer **buffer);
141 typedef gboolean                (*GstPadCheckGetRangeFunction)  (GstPad *pad); 
142 typedef gboolean                (*GstPadEventFunction)          (GstPad *pad, GstEvent *event);
143
144 /* convert/query/format functions */
145 typedef gboolean                (*GstPadConvertFunction)        (GstPad *pad,
146                                                                  GstFormat src_format,  gint64  src_value,
147                                                                  GstFormat *dest_format, gint64 *dest_value);
148 typedef gboolean                (*GstPadQueryFunction)          (GstPad *pad, GstQueryType type,
149                                                                  GstFormat *format, gint64  *value);
150 typedef GList*                  (*GstPadIntLinkFunction)        (GstPad *pad);
151 typedef const GstFormat*        (*GstPadFormatsFunction)        (GstPad *pad);
152 typedef const GstEventMask*     (*GstPadEventMaskFunction)      (GstPad *pad);
153 typedef const GstQueryType*     (*GstPadQueryTypeFunction)      (GstPad *pad);
154
155 /* linking */
156 typedef GstPadLinkReturn        (*GstPadLinkFunction)           (GstPad *pad, GstPad *peer);
157 typedef void                    (*GstPadUnlinkFunction)         (GstPad *pad);
158
159 /* caps nego */
160 typedef GstCaps*                (*GstPadGetCapsFunction)        (GstPad *pad);
161 typedef gboolean                (*GstPadSetCapsFunction)        (GstPad *pad, GstCaps *caps);
162 typedef gboolean                (*GstPadAcceptCapsFunction)     (GstPad *pad, GstCaps *caps);
163 typedef GstCaps*                (*GstPadFixateCapsFunction)     (GstPad *pad, GstCaps *caps);
164 typedef GstBuffer*              (*GstPadBufferAllocFunction)    (GstPad *pad, guint64 offset, guint size,
165                                                                  GstCaps *caps);
166 /* misc */
167 typedef gboolean                (*GstPadDispatcherFunction)     (GstPad *pad, gpointer data);
168
169 typedef void                    (*GstPadBlockCallback)          (GstPad *pad, gboolean blocked, gpointer user_data);
170
171 typedef enum {
172   GST_PAD_UNKNOWN,
173   GST_PAD_SRC,
174   GST_PAD_SINK
175 } GstPadDirection;
176
177 typedef enum {
178   GST_PAD_ACTIVE                = GST_OBJECT_FLAG_LAST,
179   GST_PAD_BLOCKED,
180   GST_PAD_FLUSHING,
181   GST_PAD_IN_GETCAPS,
182   GST_PAD_IN_SETCAPS,
183
184   GST_PAD_FLAG_LAST             = GST_OBJECT_FLAG_LAST + 8
185 } GstPadFlags;
186
187 struct _GstPad {
188   GstObject             object;
189
190   gpointer              element_private;
191
192   GstPadTemplate        *padtemplate;   /* the template for this pad */
193
194   gpointer _gst_reserved[GST_PADDING];
195 };
196
197 struct _GstPadClass {
198   GstObjectClass parent_class;
199
200   gpointer _gst_reserved[GST_PADDING];
201 };
202
203 struct _GstRealPad {
204   GstPad                         pad;
205
206   /* direction cannot change after creating the pad */
207   GstPadDirection                direction;
208
209   /*< public >*/ /* with STREAM_LOCK */
210   /* streaming rec_lock */
211   GStaticRecMutex               *stream_rec_lock;
212   GstTask                       *task;
213   /*< public >*/ /* with PREROLL_LOCK */
214   GMutex                        *preroll_lock;
215   GCond                         *preroll_cond;
216
217   /*< public >*/ /* with LOCK */
218   /* block cond, mutex is from the object */
219   GCond                         *block_cond;
220   GstPadBlockCallback            block_callback;
221   gpointer                       block_data;
222
223   /* the pad capabilities */
224   GstCaps                       *caps;
225   GstCaps                       *appfilter;
226   GstPadGetCapsFunction          getcapsfunc;
227   GstPadSetCapsFunction          setcapsfunc;
228   GstPadAcceptCapsFunction       acceptcapsfunc;
229   GstPadFixateCapsFunction       fixatecapsfunc;
230
231   GstPadActivateFunction         activatefunc;
232
233   /* pad link */
234   GstPadLinkFunction             linkfunc;
235   GstPadUnlinkFunction           unlinkfunc;
236   GstRealPad                    *peer;
237
238   gpointer                       sched_private;
239
240   /* data transport functions */
241   GstPadLoopFunction             loopfunc;
242   GstPadChainFunction            chainfunc;
243   GstPadCheckGetRangeFunction    checkgetrangefunc;
244   GstPadGetRangeFunction         getrangefunc;
245   GstPadEventFunction            eventfunc;
246
247   GstPadEventMaskFunction        eventmaskfunc;
248
249   /* ghostpads */
250   GList                         *ghostpads;
251   guint32                        ghostpads_cookie;
252
253   /* query/convert/formats functions */
254   GstPadConvertFunction          convertfunc;
255   GstPadQueryFunction            queryfunc;
256   GstPadFormatsFunction          formatsfunc;
257   GstPadQueryTypeFunction        querytypefunc;
258   GstPadIntLinkFunction          intlinkfunc;
259
260   GstPadBufferAllocFunction      bufferallocfunc;
261
262   GstProbeDispatcher             probedisp;
263
264   /*< private >*/
265   gpointer _gst_reserved[GST_PADDING];
266 };
267
268 struct _GstRealPadClass {
269   GstPadClass   parent_class;
270
271   /* signal callbacks */
272   void          (*linked)               (GstPad *pad, GstPad *peer);
273   void          (*unlinked)             (GstPad *pad, GstPad *peer);
274   void          (*request_link)         (GstPad *pad);
275
276   /*< private >*/
277   gpointer _gst_reserved[GST_PADDING];
278 };
279
280 struct _GstGhostPad {
281   GstPad pad;
282
283   GstRealPad *realpad;
284
285   gpointer _gst_reserved[GST_PADDING];
286 };
287
288 struct _GstGhostPadClass {
289   GstPadClass parent_class;
290
291   gpointer _gst_reserved[GST_PADDING];
292 };
293
294
295 /***** helper macros *****/
296 /* GstPad */
297 #define GST_PAD_NAME(pad)               (GST_OBJECT_NAME(pad))
298 #define GST_PAD_PARENT(pad)             (GST_ELEMENT_CAST(GST_OBJECT_PARENT(pad)))
299 #define GST_PAD_ELEMENT_PRIVATE(pad)    (GST_PAD_CAST(pad)->element_private)
300 #define GST_PAD_PAD_TEMPLATE(pad)       (GST_PAD_CAST(pad)->padtemplate)
301
302 /* GstRealPad */
303 #define GST_RPAD_DIRECTION(pad)         (GST_REAL_PAD_CAST(pad)->direction)
304 #define GST_RPAD_TASK(pad)              (GST_REAL_PAD_CAST(pad)->task)
305 #define GST_RPAD_ACTIVATEFUNC(pad)      (GST_REAL_PAD_CAST(pad)->activatefunc)
306 #define GST_RPAD_LOOPFUNC(pad)          (GST_REAL_PAD_CAST(pad)->loopfunc)
307 #define GST_RPAD_CHAINFUNC(pad)         (GST_REAL_PAD_CAST(pad)->chainfunc)
308 #define GST_RPAD_CHECKGETRANGEFUNC(pad) (GST_REAL_PAD_CAST(pad)->checkgetrangefunc)
309 #define GST_RPAD_GETRANGEFUNC(pad)      (GST_REAL_PAD_CAST(pad)->getrangefunc)
310 #define GST_RPAD_EVENTFUNC(pad)         (GST_REAL_PAD_CAST(pad)->eventfunc)
311 #define GST_RPAD_CONVERTFUNC(pad)       (GST_REAL_PAD_CAST(pad)->convertfunc)
312 #define GST_RPAD_QUERYFUNC(pad)         (GST_REAL_PAD_CAST(pad)->queryfunc)
313 #define GST_RPAD_INTLINKFUNC(pad)       (GST_REAL_PAD_CAST(pad)->intlinkfunc)
314 #define GST_RPAD_FORMATSFUNC(pad)       (GST_REAL_PAD_CAST(pad)->formatsfunc)
315 #define GST_RPAD_QUERYTYPEFUNC(pad)     (GST_REAL_PAD_CAST(pad)->querytypefunc)
316 #define GST_RPAD_EVENTMASKFUNC(pad)     (GST_REAL_PAD_CAST(pad)->eventmaskfunc)
317
318 #define GST_RPAD_PEER(pad)              (GST_REAL_PAD_CAST(pad)->peer)
319 #define GST_RPAD_LINKFUNC(pad)          (GST_REAL_PAD_CAST(pad)->linkfunc)
320 #define GST_RPAD_UNLINKFUNC(pad)        (GST_REAL_PAD_CAST(pad)->unlinkfunc)
321
322 #define GST_RPAD_CAPS(pad)              (GST_REAL_PAD_CAST(pad)->caps)
323 #define GST_RPAD_APPFILTER(pad)         (GST_REAL_PAD_CAST(pad)->appfilter)
324 #define GST_RPAD_GETCAPSFUNC(pad)       (GST_REAL_PAD_CAST(pad)->getcapsfunc)
325 #define GST_RPAD_SETCAPSFUNC(pad)       (GST_REAL_PAD_CAST(pad)->setcapsfunc)
326 #define GST_RPAD_ACCEPTCAPSFUNC(pad)    (GST_REAL_PAD_CAST(pad)->acceptcapsfunc)
327 #define GST_RPAD_FIXATECAPSFUNC(pad)    (GST_REAL_PAD_CAST(pad)->fixatecapsfunc)
328
329 #define GST_RPAD_BUFFERALLOCFUNC(pad)   (GST_REAL_PAD_CAST(pad)->bufferallocfunc)
330
331 #define GST_RPAD_IS_LINKED(pad)         (GST_RPAD_PEER(pad) != NULL)
332 #define GST_RPAD_IS_ACTIVE(pad)         (GST_FLAG_IS_SET (pad, GST_PAD_ACTIVE))
333 #define GST_RPAD_IS_BLOCKED(pad)        (GST_FLAG_IS_SET (pad, GST_PAD_BLOCKED))
334 #define GST_RPAD_IS_FLUSHING(pad)       (GST_FLAG_IS_SET (pad, GST_PAD_FLUSHING))
335 #define GST_RPAD_IS_IN_GETCAPS(pad)     (GST_FLAG_IS_SET (pad, GST_PAD_IN_GETCAPS))
336 #define GST_RPAD_IS_IN_SETCAPS(pad)     (GST_FLAG_IS_SET (pad, GST_PAD_IN_SETCAPS))
337 #define GST_RPAD_IS_USABLE(pad)         (GST_RPAD_IS_LINKED (pad) && \
338                                          GST_RPAD_IS_ACTIVE(pad) && GST_RPAD_IS_ACTIVE(GST_RPAD_PEER (pad)))
339 #define GST_RPAD_IS_SRC(pad)            (GST_RPAD_DIRECTION(pad) == GST_PAD_SRC)
340 #define GST_RPAD_IS_SINK(pad)           (GST_RPAD_DIRECTION(pad) == GST_PAD_SINK)
341
342 #define GST_STREAM_GET_LOCK(pad)        (GST_PAD_REALIZE(pad)->stream_rec_lock)
343 #define GST_STREAM_LOCK(pad)            (g_static_rec_mutex_lock(GST_STREAM_GET_LOCK(pad)))
344 #define GST_STREAM_TRYLOCK(pad)         (g_static_rec_mutex_trylock(GST_STREAM_GET_LOCK(pad)))
345 #define GST_STREAM_UNLOCK(pad)          (g_static_rec_mutex_unlock(GST_STREAM_GET_LOCK(pad)))
346
347 #define GST_PREROLL_GET_LOCK(pad)       (GST_PAD_REALIZE(pad)->preroll_lock)
348 #define GST_PREROLL_LOCK(pad)           (g_mutex_lock(GST_PREROLL_GET_LOCK(pad)))
349 #define GST_PREROLL_TRYLOCK(pad)        (g_mutex_trylock(GST_PREROLL_GET_LOCK(pad)))
350 #define GST_PREROLL_UNLOCK(pad)         (g_mutex_unlock(GST_PREROLL_GET_LOCK(pad)))
351 #define GST_PREROLL_GET_COND(pad)       (GST_PAD_REALIZE(pad)->preroll_cond)
352 #define GST_PREROLL_WAIT(pad)           g_cond_wait (GST_PREROLL_GET_COND (pad), GST_PREROLL_GET_LOCK (pad))
353 #define GST_PREROLL_TIMED_WAIT(pad, timeval) g_cond_timed_wait (GST_PREROLL_GET_COND (pad), GST_PREROLL_GET_LOCK (pad),\
354                                              timeval)
355 #define GST_PREROLL_SIGNAL(pad)         g_cond_signal (GST_PREROLL_GET_COND (pad));
356 #define GST_PREROLL_BROADCAST(pad)      g_cond_broadcast (GST_PREROLL_GET_COND (pad));
357
358 #define GST_PAD_BLOCK_GET_COND(pad)     (GST_PAD_REALIZE(pad)->block_cond)
359 #define GST_PAD_BLOCK_WAIT(pad)         (g_cond_wait(GST_PAD_BLOCK_GET_COND (pad), GST_GET_LOCK (pad)))
360 #define GST_PAD_BLOCK_SIGNAL(pad)       (g_cond_signal(GST_PAD_BLOCK_GET_COND (pad)))
361
362 /* GstGhostPad */
363 #define GST_GPAD_REALPAD(pad)           (((GstGhostPad *)(pad))->realpad)
364
365 /* Generic, be VERY carefull with these macros as the ghostpad could be lost */
366 #define GST_PAD_REALIZE(pad)            (GST_IS_REAL_PAD(pad) ? ((GstRealPad *)(pad)) : GST_GPAD_REALPAD(pad))
367 #define GST_PAD_DIRECTION(pad)          GST_RPAD_DIRECTION(GST_PAD_REALIZE(pad))
368 #define GST_PAD_CAPS(pad)               GST_RPAD_CAPS(GST_PAD_REALIZE (pad))
369 #define GST_PAD_APPFILTER(pad)          GST_RPAD_APPFILTER(GST_PAD_REALIZE (pad))
370 #define GST_PAD_PEER(pad)               GST_PAD_CAST(GST_RPAD_PEER(GST_PAD_REALIZE(pad)))
371
372 /* Some check functions (unused?) */
373 #define GST_PAD_IS_LINKED(pad)          (GST_RPAD_IS_LINKED(GST_PAD_REALIZE(pad)))
374 #define GST_PAD_IS_ACTIVE(pad)          (GST_RPAD_IS_ACTIVE(GST_PAD_REALIZE(pad)))
375 #define GST_PAD_IS_BLOCKED(pad)         (GST_RPAD_IS_BLOCKED(GST_PAD_REALIZE(pad)))
376 #define GST_PAD_IS_NEGOTIATING(pad)     (GST_RPAD_IS_NEGOTIATING(GST_PAD_REALIZE(pad)))
377 #define GST_PAD_IS_IN_GETCAPS(pad)      (GST_RPAD_IS_IN_GETCAPS(GST_PAD_REALIZE(pad)))
378 #define GST_PAD_IS_IN_SETCAPS(pad)      (GST_RPAD_IS_IN_SETCAPS(GST_PAD_REALIZE(pad)))
379 #define GST_PAD_IS_USABLE(pad)          (GST_RPAD_IS_USABLE(GST_PAD_REALIZE(pad)))
380 #define GST_PAD_CAN_PULL(pad)           (GST_RPAD_CAN_PULL(GST_PAD_REALIZE(pad)))
381 #define GST_PAD_IS_SRC(pad)             (GST_RPAD_IS_SRC(GST_PAD_REALIZE(pad)))
382 #define GST_PAD_IS_SINK(pad)            (GST_RPAD_IS_SINK(GST_PAD_REALIZE(pad)))
383
384 /***** PadTemplate *****/
385 #define GST_TYPE_PAD_TEMPLATE           (gst_pad_template_get_type ())
386 #define GST_PAD_TEMPLATE(obj)           (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_PAD_TEMPLATE,GstPadTemplate))
387 #define GST_PAD_TEMPLATE_CLASS(klass)   (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_PAD_TEMPLATE,GstPadTemplateClass))
388 #define GST_IS_PAD_TEMPLATE(obj)        (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_PAD_TEMPLATE))
389 #define GST_IS_PAD_TEMPLATE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_PAD_TEMPLATE))
390
391 typedef enum {
392   GST_PAD_ALWAYS,
393   GST_PAD_SOMETIMES,
394   GST_PAD_REQUEST
395 } GstPadPresence;
396
397 #define GST_PAD_TEMPLATE_NAME_TEMPLATE(templ)   (((GstPadTemplate *)(templ))->name_template)
398 #define GST_PAD_TEMPLATE_DIRECTION(templ)       (((GstPadTemplate *)(templ))->direction)
399 #define GST_PAD_TEMPLATE_PRESENCE(templ)        (((GstPadTemplate *)(templ))->presence)
400 #define GST_PAD_TEMPLATE_CAPS(templ)            (((GstPadTemplate *)(templ))->caps)
401
402 typedef enum {
403   GST_PAD_TEMPLATE_FIXED        = GST_OBJECT_FLAG_LAST,
404
405   GST_PAD_TEMPLATE_FLAG_LAST    = GST_OBJECT_FLAG_LAST + 4
406 } GstPadTemplateFlags;
407
408 #define GST_PAD_TEMPLATE_IS_FIXED(templ)        (GST_FLAG_IS_SET(templ, GST_PAD_TEMPLATE_FIXED))
409
410 struct _GstPadTemplate {
411   GstObject        object;
412
413   gchar           *name_template;
414   GstPadDirection  direction;
415   GstPadPresence   presence;
416   GstCaps         *caps;
417
418   gpointer _gst_reserved[GST_PADDING];
419 };
420
421 struct _GstPadTemplateClass {
422   GstObjectClass   parent_class;
423
424   /* signal callbacks */
425   void (*pad_created)   (GstPadTemplate *templ, GstPad *pad);
426
427   gpointer _gst_reserved[GST_PADDING];
428 };
429
430 struct _GstStaticPadTemplate {
431   gchar           *name_template;
432   GstPadDirection  direction;
433   GstPadPresence   presence;
434   GstStaticCaps   static_caps;
435 };
436
437 #define GST_STATIC_PAD_TEMPLATE(padname, dir, pres, caps) \
438   { \
439   /* name_template */    padname, \
440   /* direction */        dir, \
441   /* presence */         pres, \
442   /* caps */             caps \
443   }
444
445
446 GType                   gst_pad_get_type                        (void);
447 GType                   gst_real_pad_get_type                   (void);
448 GType                   gst_ghost_pad_get_type                  (void);
449
450 /* creating pads */
451 GstPad*                 gst_pad_new                             (const gchar *name, GstPadDirection direction);
452 GstPad*                 gst_pad_new_from_template               (GstPadTemplate *templ, const gchar *name);
453 GstPad*                 gst_pad_custom_new                      (GType type, const gchar *name, GstPadDirection direction);
454 GstPad*                 gst_pad_custom_new_from_template        (GType type, GstPadTemplate *templ, const gchar *name);
455
456 #define                 gst_pad_get_name(pad)                   gst_object_get_name(GST_OBJECT(pad))
457 #define                 gst_pad_set_name(pad,name)              gst_object_set_name(GST_OBJECT(pad),name)
458 #define                 gst_pad_get_parent(pad)                 GST_ELEMENT(gst_object_get_parent(GST_OBJECT(pad)))
459 #define                 gst_pad_set_parent(pad,parent)          gst_object_set_parent(GST_OBJECT(pad),parent)
460 GstElement*             gst_pad_get_real_parent                 (GstPad *pad);
461
462
463 GstPadDirection         gst_pad_get_direction                   (GstPad *pad);
464
465 gboolean                gst_pad_set_active                      (GstPad *pad, GstActivateMode mode);
466 gboolean                gst_pad_peer_set_active                 (GstPad *pad, GstActivateMode mode);
467 gboolean                gst_pad_is_active                       (GstPad *pad);
468 gboolean                gst_pad_set_blocked                     (GstPad *pad, gboolean blocked);
469 gboolean                gst_pad_set_blocked_async               (GstPad *pad, gboolean blocked,
470                                                                  GstPadBlockCallback callback, gpointer user_data);
471 gboolean                gst_pad_is_blocked                      (GstPad *pad);
472
473 void                    gst_pad_set_element_private             (GstPad *pad, gpointer priv);
474 gpointer                gst_pad_get_element_private             (GstPad *pad);
475
476 GstPadTemplate*         gst_pad_get_pad_template                (GstPad *pad);
477
478 void                    gst_pad_set_bufferalloc_function        (GstPad *pad, GstPadBufferAllocFunction bufalloc);
479 GstBuffer*              gst_pad_alloc_buffer                    (GstPad *pad, guint64 offset, gint size, 
480                                                                  GstCaps *caps);
481
482 /* data passing setup functions */
483 void                    gst_pad_set_activate_function           (GstPad *pad, GstPadActivateFunction activate);
484 void                    gst_pad_set_loop_function               (GstPad *pad, GstPadLoopFunction loop);
485 void                    gst_pad_set_chain_function              (GstPad *pad, GstPadChainFunction chain);
486 void                    gst_pad_set_getrange_function           (GstPad *pad, GstPadGetRangeFunction get);
487 void                    gst_pad_set_event_function              (GstPad *pad, GstPadEventFunction event);
488 void                    gst_pad_set_event_mask_function         (GstPad *pad, GstPadEventMaskFunction mask_func);
489 G_CONST_RETURN GstEventMask*
490                         gst_pad_get_event_masks                 (GstPad *pad);
491 G_CONST_RETURN GstEventMask*
492                         gst_pad_get_event_masks_default         (GstPad *pad);
493
494 /* pad links */
495 void                    gst_pad_set_link_function               (GstPad *pad, GstPadLinkFunction link);
496 void                    gst_pad_set_unlink_function             (GstPad *pad, GstPadUnlinkFunction unlink);
497
498 GstPadLinkReturn        gst_pad_link                            (GstPad *srcpad, GstPad *sinkpad);
499 GstPadLinkReturn        gst_pad_link_filtered                   (GstPad *srcpad, GstPad *sinkpad, 
500                                                                  const GstCaps *filtercaps);
501 GstPadLinkReturn        gst_pad_relink_filtered                 (GstPad *srcpad, GstPad *sinkpad, 
502                                                                  const GstCaps *filtercaps);
503 gboolean                gst_pad_unlink                          (GstPad *srcpad, GstPad *sinkpad);
504 gboolean                gst_pad_is_linked                       (GstPad *pad);
505
506 GstPad*                 gst_pad_get_peer                        (GstPad *pad);
507 GstPad*                 gst_pad_realize                         (GstPad *pad);
508
509 /* capsnego functions */
510 void                    gst_pad_set_getcaps_function            (GstPad *pad, GstPadGetCapsFunction getcaps);
511 void                    gst_pad_set_acceptcaps_function         (GstPad *pad, GstPadAcceptCapsFunction acceptcaps);
512 void                    gst_pad_set_fixatecaps_function         (GstPad *pad, GstPadFixateCapsFunction fixatecaps);
513 void                    gst_pad_set_setcaps_function            (GstPad *pad, GstPadSetCapsFunction setcaps);
514
515 G_CONST_RETURN GstCaps* gst_pad_get_pad_template_caps           (GstPad *pad);
516
517 /* capsnego function for connected/unconnected pads */
518 GstCaps *               gst_pad_get_caps                        (GstPad * pad);
519 GstCaps*                gst_pad_fixate_caps                     (GstPad * pad, GstCaps *caps);
520 gboolean                gst_pad_accept_caps                     (GstPad * pad, GstCaps *caps);
521 gboolean                gst_pad_set_caps                        (GstPad * pad, GstCaps *caps);
522
523 GstCaps *               gst_pad_peer_get_caps                   (GstPad * pad);
524 gboolean                gst_pad_peer_accept_caps                (GstPad * pad, GstCaps *caps);
525
526 /* capsnego for connected pads */
527 GstCaps *               gst_pad_get_allowed_caps                (GstPad * srcpad);
528 GstCaps *               gst_pad_get_negotiated_caps             (GstPad * pad);
529 GstCaps *               gst_pad_get_filter_caps                 (GstPad * pad);
530
531 /* data passing functions */
532 GstFlowReturn           gst_pad_push                            (GstPad *pad, GstBuffer *buffer);
533 gboolean                gst_pad_check_pull_range                (GstPad *pad);
534 GstFlowReturn           gst_pad_pull_range                      (GstPad *pad, guint64 offset, guint size,
535                                                                  GstBuffer **buffer);
536 gboolean                gst_pad_push_event                      (GstPad *pad, GstEvent *event);
537 gboolean                gst_pad_send_event                      (GstPad *pad, GstEvent *event);
538 gboolean                gst_pad_event_default                   (GstPad *pad, GstEvent *event);
539
540 /* pad tasks */
541 gboolean                gst_pad_start_task                      (GstPad *pad);
542 gboolean                gst_pad_pause_task                      (GstPad *pad);
543 gboolean                gst_pad_stop_task                       (GstPad *pad);
544
545 /* convert/query/format functions */
546 void                    gst_pad_set_formats_function            (GstPad *pad,
547                                                                  GstPadFormatsFunction formats);
548 G_CONST_RETURN GstFormat*
549                         gst_pad_get_formats                     (GstPad *pad);
550 G_CONST_RETURN GstFormat*
551                         gst_pad_get_formats_default             (GstPad *pad);
552
553 void                    gst_pad_set_convert_function            (GstPad *pad, GstPadConvertFunction convert);
554 gboolean                gst_pad_convert                         (GstPad *pad,
555                                                                  GstFormat src_format,  gint64  src_value,
556                                                                  GstFormat *dest_format, gint64 *dest_value);
557 gboolean                gst_pad_convert_default                 (GstPad *pad,
558                                                                  GstFormat src_format,  gint64  src_value,
559                                                                  GstFormat *dest_format, gint64 *dest_value);
560
561 void                    gst_pad_set_query_function              (GstPad *pad, GstPadQueryFunction query);
562 void                    gst_pad_set_query_type_function         (GstPad *pad, GstPadQueryTypeFunction type_func);
563 G_CONST_RETURN GstQueryType*
564                         gst_pad_get_query_types                 (GstPad *pad);
565 G_CONST_RETURN GstQueryType*
566                         gst_pad_get_query_types_default         (GstPad *pad);
567 gboolean                gst_pad_query                           (GstPad *pad, GstQueryType type,
568                                                                  GstFormat *format, gint64 *value);
569 gboolean                gst_pad_query_default                   (GstPad *pad, GstQueryType type,
570                                                                  GstFormat *format, gint64 *value);
571
572 void                    gst_pad_set_internal_link_function      (GstPad *pad, GstPadIntLinkFunction intlink);
573 GList*                  gst_pad_get_internal_links              (GstPad *pad);
574 GList*                  gst_pad_get_internal_links_default      (GstPad *pad);
575
576 /* misc helper functions */
577 gboolean                gst_pad_dispatcher                      (GstPad *pad, GstPadDispatcherFunction dispatch,
578                                                                  gpointer data);
579
580 /* probes */
581 #define                 gst_pad_add_probe(pad, probe) \
582                         (gst_probe_dispatcher_add_probe (&(GST_PAD_REALIZE (pad)->probedisp), probe))
583 #define                 gst_pad_remove_probe(pad, probe) \
584                         (gst_probe_dispatcher_remove_probe (&(GST_PAD_REALIZE (pad)->probedisp), probe))
585
586 #ifndef GST_DISABLE_LOADSAVE
587 void                    gst_pad_load_and_link                   (xmlNodePtr self, GstObject *parent);
588 #endif
589
590
591 /* ghostpads */
592 GstPad*                 gst_ghost_pad_new                       (const gchar *name, GstPad *pad);
593
594
595 /* templates and factories */
596 GType                   gst_pad_template_get_type               (void);
597
598 GstPadTemplate*         gst_pad_template_new                    (const gchar *name_template,
599                                                                  GstPadDirection direction, GstPadPresence presence,
600                                                                  GstCaps *caps);
601
602 GstPadTemplate *        gst_static_pad_template_get             (GstStaticPadTemplate *pad_template);
603 GstCaps*                gst_pad_template_get_caps               (GstPadTemplate *templ);
604
605 #ifndef GST_DISABLE_LOADSAVE
606 xmlNodePtr              gst_ghost_pad_save_thyself              (GstPad *pad,
607                                                                  xmlNodePtr parent);
608 #endif
609
610
611 G_END_DECLS
612
613 #endif /* __GST_PAD_H__ */