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