updated .h files with // 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/cothreads.h>
32 #include <gst/gstcaps.h>
33 #include <gst/gstevent.h>
34
35
36 #ifdef __cplusplus
37 extern "C" {
38 #endif /* __cplusplus */
39
40 extern GType _gst_pad_type;
41 extern GType _gst_real_pad_type;
42 extern GType _gst_ghost_pad_type;
43
44 /*#define GST_TYPE_PARANOID */
45
46 /* 
47  * Pad base class
48  */
49 #define GST_TYPE_PAD                    (_gst_pad_type)
50
51 #define GST_PAD_FAST(obj)               ((GstPad*)(obj))
52 #define GST_PAD_CLASS_FAST(klass)       ((GstPadClass*)(klass))
53 #define GST_IS_PAD(obj)                 (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_PAD))
54 #define GST_IS_PAD_FAST(obj)            (G_OBJECT_TYPE(obj) == GST_TYPE_REAL_PAD || \
55                                          G_OBJECT_TYPE(obj) == GST_TYPE_GHOST_PAD)
56 #define GST_IS_PAD_CLASS(obj)           (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_PAD))
57
58 #ifdef GST_TYPE_PARANOID
59 # define GST_PAD(obj)                   (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_PAD, GstPad))
60 # define GST_PAD_CLASS(klass)           (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_PAD, GstPadClass))
61 #else
62 # define GST_PAD                        GST_PAD_FAST
63 # define GST_PAD_CLASS                  GST_PAD_CLASS_FAST
64 #endif
65
66 /* 
67  * Real Pads
68  */
69 #define GST_TYPE_REAL_PAD               (_gst_real_pad_type)
70
71 #define GST_REAL_PAD_FAST(obj)          ((GstRealPad*)(obj))
72 #define GST_REAL_PAD_CLASS_FAST(klass)  ((GstRealPadClass*)(klass))
73 #define GST_IS_REAL_PAD(obj)            (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_REAL_PAD))
74 #define GST_IS_REAL_PAD_FAST(obj)       (G_OBJECT_TYPE(obj) == GST_TYPE_REAL_PAD)
75 #define GST_IS_REAL_PAD_CLASS(obj)      (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_REAL_PAD))
76
77 #ifdef GST_TYPE_PARANOID
78 # define GST_REAL_PAD(obj)              (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_REAL_PAD, GstRealPad))
79 # define GST_REAL_PAD_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_REAL_PAD, GstRealPadClass))
80 #else
81 # define GST_REAL_PAD                   GST_REAL_PAD_FAST
82 # define GST_REAL_PAD_CLASS             GST_REAL_PAD_CLASS_FAST
83 #endif
84
85 /* 
86  * Ghost Pads
87  */
88 #define GST_TYPE_GHOST_PAD              (_gst_ghost_pad_type)
89
90 #define GST_GHOST_PAD_FAST(obj)         ((GstGhostPad*)(obj))
91 #define GST_GHOST_PAD_CLASS_FAST(klass) ((GstGhostPadClass*)(klass))
92 #define GST_IS_GHOST_PAD(obj)           (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_GHOST_PAD))
93 #define GST_IS_GHOST_PAD_FAST(obj)      (G_OBJECT_TYPE(obj) == GST_TYPE_GHOST_PAD)
94 #define GST_IS_GHOST_PAD_CLASS(obj)     (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_GHOST_PAD))
95
96 #ifdef GST_TYPE_PARANOID
97 # define GST_GHOST_PAD(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_GHOST_PAD, GstGhostPad))
98 # define GST_GHOST_PAD_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_GHOST_PAD, GstGhostPadClass))
99 #else
100 # define GST_GHOST_PAD                  GST_GHOST_PAD_FAST
101 # define GST_GHOST_PAD_CLASS            GST_GHOST_PAD_CLASS_FAST
102 #endif
103
104
105 /*typedef struct _GstPad GstPad; */
106 /*typedef struct _GstPadClass GstPadClass;*/
107 typedef struct _GstRealPad GstRealPad;
108 typedef struct _GstRealPadClass GstRealPadClass;
109 typedef struct _GstGhostPad GstGhostPad;
110 typedef struct _GstGhostPadClass GstGhostPadClass;
111 /*typedef struct _GstPadTemplate GstPadTemplate;*/
112 /*typedef struct _GstPadTemplateClass GstPadTemplateClass;*/
113
114
115 typedef enum {
116   GST_REGION_VOID,
117   GST_REGION_OFFSET_LEN,
118   GST_REGION_TIME_LEN,
119 } GstRegionType;
120
121 typedef enum { 
122   GST_PAD_NEGOTIATE_FAIL,
123   GST_PAD_NEGOTIATE_AGREE,
124   GST_PAD_NEGOTIATE_TRY,
125 } GstPadNegotiateReturn;
126
127
128 /* this defines the functions used to chain buffers
129  * pad is the sink pad (so the same chain function can be used for N pads)
130  * buf is the buffer being passed */
131 typedef void            (*GstPadChainFunction)          (GstPad *pad,GstBuffer *buf);
132 typedef GstBuffer*      (*GstPadGetFunction)            (GstPad *pad);
133 typedef gboolean        (*GstPadEventFunction)          (GstPad *pad, GstEvent *event);
134
135 typedef GstBuffer*      (*GstPadGetRegionFunction)      (GstPad *pad, GstRegionType type, guint64 offset, guint64 len);
136 typedef GstBuffer*      (*GstPadPullRegionFunction)     (GstPad *pad, GstRegionType type, guint64 offset, guint64 len);
137 typedef GstPadNegotiateReturn (*GstPadNegotiateFunction)        (GstPad *pad, GstCaps **caps, gpointer *data);
138 typedef void            (*GstPadNewCapsFunction)        (GstPad *pad, GstCaps *caps);
139 typedef GstBufferPool*  (*GstPadBufferPoolFunction)     (GstPad *pad);
140
141 typedef enum {
142   GST_PAD_UNKNOWN,
143   GST_PAD_SRC,
144   GST_PAD_SINK,
145 } GstPadDirection;
146
147 typedef enum {
148   GST_PAD_DISABLED              = GST_OBJECT_FLAG_LAST,
149   GST_PAD_EOS,
150
151   GST_PAD_FLAG_LAST             = GST_OBJECT_FLAG_LAST + 4,
152 } GstPadFlags;
153
154 struct _GstPad {
155   GstObject             object;
156
157   gpointer              element_private;
158
159   GstPadTemplate        *padtemplate;   /* the template for this pad */
160 };
161
162 struct _GstPadClass {
163   GstObjectClass parent_class;
164 };
165
166 struct _GstRealPad {
167   GstPad                        pad;
168
169   GstCaps                       *caps;
170   GstPadDirection               direction;
171
172   cothread_state                *threadstate;
173
174   GstRealPad                    *peer;
175
176   GstBuffer                     *bufpen;
177   GstRegionType                 regiontype;
178   guint64                       offset;
179   guint64                       len;
180
181   GstScheduler                  *sched;
182
183   GstPadChainFunction           chainfunc;
184   GstPadChainFunction           chainhandler;
185   GstPadGetFunction             getfunc;
186   GstPadGetFunction             gethandler;
187
188   GstPadEventFunction           eventfunc;
189   GstPadEventFunction           eventhandler;
190
191   GstPadGetRegionFunction       getregionfunc;
192   GstPadPullRegionFunction      pullregionfunc;
193
194   GstPadNegotiateFunction       negotiatefunc;
195   GstPadNewCapsFunction         newcapsfunc;
196   GstPadBufferPoolFunction      bufferpoolfunc;
197
198   GList *ghostpads;
199 };
200
201 struct _GstRealPadClass {
202   GstPadClass parent_class;
203
204   /* signal callbacks */
205   void (*set_active)            (GstPad *pad, gboolean active);
206   void (*caps_changed)          (GstPad *pad, GstCaps *newcaps);
207   void (*caps_nego_failed)      (GstPad *pad);
208   void (*connected)             (GstPad *pad, GstPad *peer);
209   void (*disconnected)          (GstPad *pad, GstPad *peer);
210
211   void (*eos)                   (GstPad *pad);
212 };
213
214 struct _GstGhostPad {
215   GstPad pad;
216
217   GstRealPad *realpad;
218 };
219
220 struct _GstGhostPadClass {
221   GstPadClass parent_class;
222 };
223
224
225 /***** helper macros *****/
226 /* GstPad */
227 #define GST_PAD_NAME(pad)               (GST_OBJECT_NAME(pad))
228 #define GST_PAD_PARENT(pad)             ((GstElement *)(GST_OBJECT_PARENT(pad)))
229 #define GST_PAD_ELEMENT_PRIVATE(pad)    (((GstPad *)(pad))->element_private)
230 #define GST_PAD_PADTEMPLATE(pad)        (((GstPad *)(pad))->padtemplate)
231
232 /* GstRealPad */
233 #define GST_RPAD_DIRECTION(pad)         (((GstRealPad *)(pad))->direction)
234 #define GST_RPAD_CAPS(pad)              (((GstRealPad *)(pad))->caps)
235 #define GST_RPAD_PEER(pad)              (((GstRealPad *)(pad))->peer)
236 #define GST_RPAD_BUFPEN(pad)            (((GstRealPad *)(pad))->bufpen)
237 #define GST_RPAD_SCHED(pad)             (((GstRealPad *)(pad))->sched)
238 #define GST_RPAD_CHAINFUNC(pad)         (((GstRealPad *)(pad))->chainfunc)
239 #define GST_RPAD_CHAINHANDLER(pad)      (((GstRealPad *)(pad))->chainhandler)
240 #define GST_RPAD_GETFUNC(pad)           (((GstRealPad *)(pad))->getfunc)
241 #define GST_RPAD_GETHANDLER(pad)        (((GstRealPad *)(pad))->gethandler)
242 #define GST_RPAD_EVENTFUNC(pad)         (((GstRealPad *)(pad))->eventfunc)
243 #define GST_RPAD_EVENTHANDLER(pad)      (((GstRealPad *)(pad))->eventhandler)
244
245 #define GST_RPAD_GETREGIONFUNC(pad)     (((GstRealPad *)(pad))->getregionfunc)
246 #define GST_RPAD_PULLREGIONFUNC(pad)    (((GstRealPad *)(pad))->pullregionfunc)
247
248 #define GST_RPAD_NEGOTIATEFUNC(pad)     (((GstRealPad *)(pad))->negotiatefunc)
249 #define GST_RPAD_NEWCAPSFUNC(pad)       (((GstRealPad *)(pad))->newcapsfunc)
250 #define GST_RPAD_BUFFERPOOLFUNC(pad)    (((GstRealPad *)(pad))->bufferpoolfunc)
251
252 #define GST_RPAD_REGIONTYPE(pad)        (((GstRealPad *)(pad))->regiontype)
253 #define GST_RPAD_OFFSET(pad)            (((GstRealPad *)(pad))->offset)
254 #define GST_RPAD_LEN(pad)               (((GstRealPad *)(pad))->len)
255
256 /* GstGhostPad */
257 #define GST_GPAD_REALPAD(pad)           (((GstGhostPad *)(pad))->realpad)
258
259 /* Generic */
260 #define GST_PAD_REALIZE(pad)    (GST_IS_REAL_PAD(pad) ? ((GstRealPad *)(pad)) : GST_GPAD_REALPAD(pad))
261 #define GST_PAD_DIRECTION(pad)          GST_RPAD_DIRECTION(GST_PAD_REALIZE(pad))
262 #define GST_PAD_CAPS(pad)               GST_RPAD_CAPS(GST_PAD_REALIZE(pad))
263 #define GST_PAD_PEER(pad)               GST_RPAD_PEER(GST_PAD_REALIZE(pad))
264
265 /* Some check functions (unused?) */
266 #define GST_PAD_CONNECTED(pad)          (GST_PAD_PEER(pad) != NULL)
267 #define GST_PAD_CAN_PULL(pad)           (GST_IS_REAL_PAD(pad) && GST_REAL_PAD(pad)->gethandler != NULL)
268
269
270 /***** PadTemplate *****/
271 #define GST_TYPE_PADTEMPLATE            (gst_padtemplate_get_type ())
272 #define GST_PADTEMPLATE(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_PADTEMPLATE,GstPadTemplate))
273 #define GST_PADTEMPLATE_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_PADTEMPLATE,GstPadTemplateClass))
274 #define GST_IS_PADTEMPLATE(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_PADTEMPLATE))
275 #define GST_IS_PADTEMPLATE_CLASS(obj)   (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_PADTEMPLATE))
276
277 typedef enum {
278   GST_PAD_ALWAYS,
279   GST_PAD_SOMETIMES,
280   GST_PAD_REQUEST,
281 } GstPadPresence;
282
283 #define GST_PADTEMPLATE_NAME_TEMPLATE(templ)    (((GstPadTemplate *)(templ))->name_template)
284 #define GST_PADTEMPLATE_DIRECTION(templ)        (((GstPadTemplate *)(templ))->direction)
285 #define GST_PADTEMPLATE_PRESENCE(templ)         (((GstPadTemplate *)(templ))->presence)
286 #define GST_PADTEMPLATE_CAPS(templ)             (((GstPadTemplate *)(templ))->caps)
287
288 struct _GstPadTemplate {
289   GstObject       object;
290
291   gchar           *name_template;
292   GstPadDirection direction;
293   GstPadPresence  presence;
294   GstCaps         *caps;
295 };
296
297 struct _GstPadTemplateClass {
298   GstObjectClass parent_class;
299
300   /* signal callbacks */
301   void (*pad_created)   (GstPadTemplate *templ, GstPad *pad);
302 };
303
304 #define GST_PADTEMPLATE_NEW(padname, dir, pres, a...) \
305   gst_padtemplate_new (                         \
306     padname,                                    \
307     dir,                                        \
308     pres,                                       \
309     a ,                                         \
310     NULL)
311
312 #define GST_PADTEMPLATE_FACTORY(name, padname, dir, pres, a...)         \
313 static GstPadTemplate*                          \
314 name (void)                                     \
315 {                                               \
316   static GstPadTemplate *templ = NULL;          \
317   if (!templ) {                                 \
318     templ = GST_PADTEMPLATE_NEW (               \
319       padname,                                  \
320       dir,                                      \
321       pres,                                     \
322       a );                                     \
323   }                                             \
324   return templ;                                 \
325 }
326
327 #define GST_PADTEMPLATE_GET(fact) (fact)()
328
329 GType                   gst_pad_get_type                (void);
330 GType                   gst_real_pad_get_type           (void);
331 GType                   gst_ghost_pad_get_type          (void);
332
333 GstPad*                 gst_pad_new                     (gchar *name, GstPadDirection direction);
334 #define                 gst_pad_destroy(pad)            gst_object_destroy (GST_OBJECT (pad))
335 GstPad*                 gst_pad_new_from_template       (GstPadTemplate *templ, gchar *name);
336
337 GstPadDirection         gst_pad_get_direction           (GstPad *pad);
338
339 void                    gst_pad_set_chain_function      (GstPad *pad, GstPadChainFunction chain);
340 void                    gst_pad_set_get_function        (GstPad *pad, GstPadGetFunction get);
341 void                    gst_pad_set_event_function      (GstPad *pad, GstPadEventFunction event);
342
343 void                    gst_pad_set_getregion_function  (GstPad *pad, GstPadGetRegionFunction getregion);
344
345 void                    gst_pad_set_negotiate_function  (GstPad *pad, GstPadNegotiateFunction nego);
346 void                    gst_pad_set_newcaps_function    (GstPad *pad, GstPadNewCapsFunction newcaps);
347 void                    gst_pad_set_bufferpool_function (GstPad *pad, GstPadBufferPoolFunction bufpool);
348
349 gboolean                gst_pad_set_caps                (GstPad *pad, GstCaps *caps);
350 GstCaps*                gst_pad_get_caps                (GstPad *pad);
351 GstCaps*                gst_pad_get_padtemplate_caps    (GstPad *pad);
352 gboolean                gst_pad_check_compatibility     (GstPad *srcpad, GstPad *sinkpad);
353
354 void                    gst_pad_set_element_private     (GstPad *pad, gpointer priv);
355 gpointer                gst_pad_get_element_private     (GstPad *pad);
356
357 void                    gst_pad_set_name                (GstPad *pad, const gchar *name);
358 const gchar*            gst_pad_get_name                (GstPad *pad);
359
360 void                    gst_pad_set_parent              (GstPad *pad, GstObject *parent);
361 GstElement*             gst_pad_get_parent              (GstPad *pad);
362 GstElement*             gst_pad_get_real_parent         (GstPad *pad);
363
364 void                    gst_pad_set_sched               (GstPad *pad, GstScheduler *sched);
365 GstScheduler*           gst_pad_get_sched               (GstPad *pad);
366
367 void                    gst_pad_add_ghost_pad           (GstPad *pad, GstPad *ghostpad);
368 void                    gst_pad_remove_ghost_pad        (GstPad *pad, GstPad *ghostpad);
369 GList*                  gst_pad_get_ghost_pad_list      (GstPad *pad);
370
371 GstPadTemplate*         gst_pad_get_padtemplate         (GstPad *pad);
372
373 GstPad*                 gst_pad_get_peer                (GstPad *pad);
374
375 GstBufferPool*          gst_pad_get_bufferpool          (GstPad *pad);
376
377 gboolean                gst_pad_try_connect             (GstPad *srcpad, GstPad *sinkpad);
378 void                    gst_pad_connect                 (GstPad *srcpad, GstPad *sinkpad);
379 void                    gst_pad_disconnect              (GstPad *srcpad, GstPad *sinkpad);
380
381 gboolean                gst_pad_renegotiate             (GstPad *pad);
382 GstPadNegotiateReturn   gst_pad_negotiate_proxy         (GstPad *srcpad, GstPad *destpad, GstCaps **caps);
383
384 #if 1
385 void                    gst_pad_push                    (GstPad *pad, GstBuffer *buf);
386 #else
387 #define gst_pad_push(pad,buf) G_STMT_START{ \
388   if (((GstRealPad *)(pad))->peer->chainhandler) \
389     (((GstRealPad *)(pad))->peer->chainhandler)((GstPad *)(((GstRealPad *)(pad))->peer),(buf)); \
390 }G_STMT_END
391 #endif
392 #if 1
393 GstBuffer*              gst_pad_pull                    (GstPad *pad);
394 GstBuffer*              gst_pad_pullregion              (GstPad *pad, GstRegionType type, guint64 offset, guint64 len);
395 #else
396 #define gst_pad_pull(pad) \
397   ( (((GstRealPad *)(pad))->peer->gethandler) ? \
398 (((GstRealPad *)(pad))->peer->gethandler)((GstPad *)(((GstRealPad *)(pad))->peer)) : \
399 NULL )
400 #define gst_pad_pullregion(pad,type,offset,len) \
401   ( (((GstRealPad *)(pad))->peer->pullregionfunc) ? \
402 (((GstRealPad *)(pad))->peer->pullregionfunc)((GstPad *)(((GstRealPad *)(pad))->peer),(type),(offset),(len)) : \
403 NULL )
404 #endif
405
406 gboolean                gst_pad_send_event              (GstPad *pad, GstEvent *event);
407 void                    gst_pad_event_default           (GstPad *pad, GstEvent *event);
408
409
410
411 GstBuffer*              gst_pad_peek                    (GstPad *pad);
412 GstPad*                 gst_pad_select                  (GList *padlist);
413 GstPad*                 gst_pad_selectv                 (GstPad *pad, ...);
414
415 #ifndef GST_DISABLE_LOADSAVE
416 void                    gst_pad_load_and_connect        (xmlNodePtr self, GstObject *parent);
417 #endif
418
419
420 /* ghostpads */
421 GstPad*                 gst_ghost_pad_new               (gchar *name,GstPad *pad);
422
423
424 /* templates and factories */
425 GType                   gst_padtemplate_get_type        (void);
426
427 GstPadTemplate*         gst_padtemplate_new             (gchar *name_template,
428                                                          GstPadDirection direction, GstPadPresence presence,
429                                                          GstCaps *caps, ...);
430
431 GstCaps*                gst_padtemplate_get_caps        (GstPadTemplate *templ);
432 GstCaps*                gst_padtemplate_get_caps_by_name        (GstPadTemplate *templ, const gchar *name);
433
434 #ifndef GST_DISABLE_LOADSAVE
435 xmlNodePtr              gst_padtemplate_save_thyself    (GstPadTemplate *templ, xmlNodePtr parent);
436 GstPadTemplate*         gst_padtemplate_load_thyself    (xmlNodePtr parent);
437 #endif
438
439 xmlNodePtr              gst_pad_ghost_save_thyself   (GstPad *pad,
440                                                       GstElement *bin,
441                                                       xmlNodePtr parent);
442
443 #ifdef __cplusplus
444 }
445 #endif /* __cplusplus */
446
447
448 #endif /* __GST_PAD_H__ */
449