More doc updates
[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
41
42 #ifdef __cplusplus
43 extern "C" {
44 #endif /* __cplusplus */
45
46
47 #define GST_TYPE_PAD                    (gst_pad_get_type ())
48 #define GST_PAD(obj)                    (GTK_CHECK_CAST ((obj), GST_TYPE_PAD,GstPad))
49 #define GST_PAD_CLASS(klass)            (GTK_CHECK_CLASS_CAST ((klass), GST_TYPE_PAD,GstPadClass))
50 #define GST_IS_PAD(obj)                 (GTK_CHECK_TYPE ((obj), GST_TYPE_PAD))
51 #define GST_IS_PAD_CLASS(obj)           (GTK_CHECK_CLASS_TYPE ((klass), GST_TYPE_PAD))
52
53 #define GST_TYPE_REAL_PAD               (gst_real_pad_get_type ())
54 #define GST_REAL_PAD(obj)               (GTK_CHECK_CAST ((obj), GST_TYPE_REAL_PAD,GstRealPad))
55 #define GST_REAL_PAD_CLASS(klass)       (GTK_CHECK_CLASS_CAST ((klass), GST_TYPE_REAL_PAD,GstRealPadClass))
56 #define GST_IS_REAL_PAD(obj)            (GTK_CHECK_TYPE ((obj), GST_TYPE_REAL_PAD))
57 #define GST_IS_REAL_PAD_CLASS(obj)      (GTK_CHECK_CLASS_TYPE ((klass), GST_TYPE_REAL_PAD))
58
59 #define GST_TYPE_GHOST_PAD              (gst_ghost_pad_get_type ())
60 #define GST_GHOST_PAD(obj)              (GTK_CHECK_CAST ((obj), GST_TYPE_GHOST_PAD,GstGhostPad))
61 #define GST_GHOST_PAD_CLASS(klass)      (GTK_CHECK_CLASS_CAST ((klass), GST_TYPE_GHOST_PAD,GstGhostPadClass))
62 #define GST_IS_GHOST_PAD(obj)           (GTK_CHECK_TYPE ((obj), GST_TYPE_GHOST_PAD))
63 #define GST_IS_GHOST_PAD_CLASS(obj)     (GTK_CHECK_CLASS_TYPE ((klass), GST_TYPE_GHOST_PAD))
64
65
66 typedef struct _GstPad GstPad;
67 typedef struct _GstPadClass GstPadClass;
68 typedef struct _GstRealPad GstRealPad;
69 typedef struct _GstRealPadClass GstRealPadClass;
70 typedef struct _GstGhostPad GstGhostPad;
71 typedef struct _GstGhostPadClass GstGhostPadClass;
72 typedef struct _GstPadTemplate GstPadTemplate;
73 typedef struct _GstPadTemplateClass GstPadTemplateClass;
74
75
76 typedef enum {
77   GST_REGION_NONE,
78   GST_REGION_OFFSET_LEN,
79   GST_REGION_TIME_LEN,
80 } GstRegionType;
81
82
83 /* this defines the functions used to chain buffers
84  * pad is the sink pad (so the same chain function can be used for N pads)
85  * buf is the buffer being passed */
86 typedef void (*GstPadChainFunction) (GstPad *pad,GstBuffer *buf);
87 typedef GstBuffer *(*GstPadGetFunction) (GstPad *pad);
88 typedef GstBuffer *(*GstPadGetRegionFunction) (GstPad *pad, GstRegionType type, guint64 offset, guint64 len);
89 typedef void (*GstPadQoSFunction) (GstPad *pad, glong qos_message);
90
91 typedef void (*GstPadPushFunction) (GstPad *pad, GstBuffer *buf);
92 typedef GstBuffer *(*GstPadPullFunction) (GstPad *pad);
93 typedef GstBuffer *(*GstPadPullRegionFunction) (GstPad *pad, GstRegionType type, guint64 offset, guint64 len);
94 typedef gboolean (*GstPadEOSFunction) (GstPad *pad);
95
96 typedef enum {
97   GST_PAD_UNKNOWN,
98   GST_PAD_SRC,
99   GST_PAD_SINK,
100 } GstPadDirection;
101
102 typedef enum {
103   GST_PAD_DISABLED              = GST_OBJECT_FLAG_LAST,
104   GST_PAD_EOS,
105
106   GST_PAD_FLAG_LAST             = GST_OBJECT_FLAG_LAST + 4,
107 } GstPadFlags;
108
109 struct _GstPad {
110   GstObject object;
111
112   gpointer element_private;
113
114   GstPadTemplate *padtemplate;  /* the template for this pad */
115 };
116
117 struct _GstPadClass {
118   GstObjectClass parent_class;
119 };
120
121 struct _GstRealPad {
122   GstPad pad;
123
124   GList *caps;
125   GstPadDirection direction;
126
127   cothread_state *threadstate;
128
129   GstRealPad *peer;
130
131   GstBuffer *bufpen;
132   GstRegionType regiontype;
133   guint64 offset;
134   guint64 len;
135
136   GstPadChainFunction chainfunc;
137   GstPadGetFunction getfunc;
138   GstPadGetRegionFunction getregionfunc;
139   GstPadQoSFunction qosfunc;
140   GstPadEOSFunction eosfunc;
141
142   GstPadPushFunction pushfunc;
143   GstPadPullFunction pullfunc;
144   GstPadPullRegionFunction pullregionfunc;
145
146   GList *ghostpads;
147 };
148
149 struct _GstRealPadClass {
150   GstPadClass parent_class;
151
152   /* signal callbacks */
153   void (*set_active)    (GstPad *pad, gboolean active);
154   void (*caps_changed)  (GstPad *pad, GstCaps *newcaps);
155   void (*eos)           (GstPad *pad);
156 };
157
158 struct _GstGhostPad {
159   GstPad pad;
160
161   GstRealPad *realpad;
162 };
163
164 struct _GstGhostPadClass {
165   GstPadClass parent_class;
166 };
167
168
169 /***** helper macros *****/
170 /* GstPad */
171 #define GST_PAD_NAME(pad)               (GST_OBJECT_NAME(pad))
172 #define GST_PAD_PARENT(pad)             (GST_OBJECT_PARENT(pad))
173 #define GST_PAD_ELEMENT_PRIVATE(pad)    (((GstPad *)(pad))->element_private)
174 #define GST_PAD_PADTEMPLATE(pad)        (((GstPad *)(pad))->padtemplate)
175
176 /* GstRealPad */
177 #define GST_RPAD_DIRECTION(pad)         (((GstRealPad *)(pad))->direction)
178 #define GST_RPAD_CAPS(pad)              (((GstRealPad *)(pad))->caps)
179 #define GST_RPAD_PEER(pad)              (((GstRealPad *)(pad))->peer)
180 #define GST_RPAD_BUFPEN(pad)            (((GstRealPad *)(pad))->bufpen)
181 #define GST_RPAD_CHAINFUNC(pad)         (((GstRealPad *)(pad))->chainfunc)
182 #define GST_RPAD_GETFUNC(pad)           (((GstRealPad *)(pad))->getfunc)
183 #define GST_RPAD_GETREGIONFUNC(pad)     (((GstRealPad *)(pad))->getregionfunc)
184 #define GST_RPAD_PUSHFUNC(pad)          (((GstRealPad *)(pad))->pushfunc)
185 #define GST_RPAD_PULLFUNC(pad)          (((GstRealPad *)(pad))->pullfunc)
186 #define GST_RPAD_PULLREGIONFUNC(pad)    (((GstRealPad *)(pad))->pullregionfunc)
187 #define GST_RPAD_QOSFUNC(pad)           (((GstRealPad *)(pad))->qosfunc)
188 #define GST_RPAD_EOSFUNC(pad)           (((GstRealPad *)(pad))->eosfunc)
189
190 #define GST_RPAD_REGIONTYPE(pad)        (((GstRealPad *)(pad))->regiontype)
191 #define GST_RPAD_OFFSET(pad)            (((GstRealPad *)(pad))->offset)
192 #define GST_RPAD_LEN(pad)               (((GstRealPad *)(pad))->len)
193
194 /* GstGhostPad */
195 #define GST_GPAD_REALPAD(pad)           (((GstGhostPad *)(pad))->realpad)
196
197 /* Generic */
198 #define GST_PAD_REALIZE(pad) (GST_IS_REAL_PAD(pad) ? ((GstRealPad *)(pad)) : GST_GPAD_REALPAD(pad))
199 #define GST_PAD_DIRECTION(pad)          GST_RPAD_DIRECTION(GST_PAD_REALIZE(pad))
200 #define GST_PAD_CAPS(pad)               GST_RPAD_CAPS(GST_PAD_REALIZE(pad))
201 #define GST_PAD_PEER(pad)               GST_RPAD_PEER(GST_PAD_REALIZE(pad))
202
203 /* Some check functions (unused?) */
204 #define GST_PAD_CONNECTED(pad)          (GST_IS_REAL_PAD(pad) && GST_REAL_PAD(pad)->peer != NULL)
205 #define GST_PAD_CAN_PULL(pad)           (GST_IS_REAL_PAD(pad) && GST_REAL_PAD(pad)->pullfunc != NULL)
206
207
208 /***** PadTemplate *****/
209 #define GST_TYPE_PADTEMPLATE            (gst_padtemplate_get_type ())
210 #define GST_PADTEMPLATE(obj)            (GTK_CHECK_CAST ((obj), GST_TYPE_PADTEMPLATE,GstPad))
211 #define GST_PADTEMPLATE_CLASS(klass)    (GTK_CHECK_CLASS_CAST ((klass), GST_TYPE_PADTEMPLATE,GstPadClass))
212 #define GST_IS_PADTEMPLATE(obj)         (GTK_CHECK_TYPE ((obj), GST_TYPE_PADTEMPLATE))
213 #define GST_IS_PADTEMPLATE_CLASS(obj)   (GTK_CHECK_CLASS_TYPE ((klass), GST_TYPE_PADTEMPLATE))
214
215 typedef enum {
216   GST_PAD_ALWAYS,
217   GST_PAD_SOMETIMES,
218   GST_PAD_REQUEST,
219 } GstPadPresence;
220
221 struct _GstPadTemplate {
222   GstObject       object;
223
224   gchar           *name_template;
225   GstPadDirection direction;
226   GstPadPresence  presence;
227   GList           *caps;
228 };
229
230 struct _GstPadTemplateClass {
231   GstObjectClass parent_class;
232
233   /* signal callbacks */
234   void (*pad_created)   (GstPadTemplate *templ, GstPad *pad);
235 };
236
237
238 /* factory */
239 typedef gpointer GstPadFactoryEntry;
240 typedef GstPadFactoryEntry GstPadFactory[];
241
242 #define GST_PAD_FACTORY_ALWAYS          GINT_TO_POINTER(GST_PAD_ALWAYS)
243 #define GST_PAD_FACTORY_SOMETIMES       GINT_TO_POINTER(GST_PAD_SOMETIMES)
244 #define GST_PAD_FACTORY_REQUEST         GINT_TO_POINTER(GST_PAD_REQUEST)
245
246 #define GST_PAD_FACTORY_SRC             GINT_TO_POINTER(GST_PAD_SRC)
247 #define GST_PAD_FACTORY_SINK            GINT_TO_POINTER(GST_PAD_SINK)
248
249 #define GST_PAD_FACTORY_CAPS(a...)      GINT_TO_POINTER(1),##a,NULL
250
251
252 GtkType                 gst_pad_get_type                (void);
253 GtkType                 gst_real_pad_get_type           (void);
254 GtkType                 gst_ghost_pad_get_type          (void);
255
256 GstPad*                 gst_pad_new                     (gchar *name, GstPadDirection direction);
257 #define                 gst_pad_destroy(pad)            gst_object_destroy (GST_OBJECT (pad))
258 GstPad*                 gst_pad_new_from_template       (GstPadTemplate *templ, gchar *name);
259
260 GstPadDirection         gst_pad_get_direction           (GstPad *pad);
261
262 void                    gst_pad_set_chain_function      (GstPad *pad, GstPadChainFunction chain);
263 void                    gst_pad_set_get_function        (GstPad *pad, GstPadGetFunction get);
264 void                    gst_pad_set_getregion_function  (GstPad *pad, GstPadGetRegionFunction getregion);
265 void                    gst_pad_set_qos_function        (GstPad *pad, GstPadQoSFunction qos);
266 void                    gst_pad_set_eos_function        (GstPad *pad, GstPadEOSFunction eos);
267
268 void                    gst_pad_set_caps_list           (GstPad *pad, GList *caps);
269 GList*                  gst_pad_get_caps_list           (GstPad *pad);
270 GstCaps*                gst_pad_get_caps_by_name        (GstPad *pad, gchar *name);
271 gboolean                gst_pad_check_compatibility     (GstPad *srcpad, GstPad *sinkpad);
272
273 void                    gst_pad_set_element_private     (GstPad *pad, gpointer priv);
274 gpointer                gst_pad_get_element_private     (GstPad *pad);
275
276 void                    gst_pad_set_name                (GstPad *pad, const gchar *name);
277 const gchar*            gst_pad_get_name                (GstPad *pad);
278
279 void                    gst_pad_set_parent              (GstPad *pad, GstObject *parent);
280 GstObject*              gst_pad_get_parent              (GstPad *pad);
281
282 void                    gst_pad_add_ghost_pad           (GstPad *pad, GstPad *ghostpad);
283 void                    gst_pad_remove_ghost_pad        (GstPad *pad, GstPad *ghostpad);
284 GList*                  gst_pad_get_ghost_pad_list      (GstPad *pad);
285
286 GstPad*                 gst_pad_get_peer                (GstPad *pad);
287
288 void                    gst_pad_connect                 (GstPad *srcpad, GstPad *sinkpad);
289 void                    gst_pad_disconnect              (GstPad *srcpad, GstPad *sinkpad);
290
291 #if 1
292 void                    gst_pad_push                    (GstPad *pad, GstBuffer *buf);
293 #else
294 #define gst_pad_push(pad,buf) G_STMT_START{ \
295   if ((pad)->peer->pushfunc) ((pad)->peer->pushfunc)((pad)->peer,(buf)); \
296 }G_STMT_END
297 #endif
298 #if 1
299 GstBuffer*              gst_pad_pull                    (GstPad *pad);
300 GstBuffer*              gst_pad_pullregion              (GstPad *pad, GstRegionType type, guint64 offset, guint64 len);
301 #else
302 #define gst_pad_pull(pad) \
303   (((pad)->peer->pullfunc) ? ((pad)->peer->pullfunc)((pad)->peer) : NULL)
304 #define gst_pad_pullregion(pad,type,offset,len) \
305   (((pad)->peer->pullregionfunc) ? ((pad)->peer->pullregionfunc)((pad)->peer,(type),(offset),(len)) : NULL)
306 #endif
307
308 #define                 gst_pad_eos(pad)                (GST_RPAD_EOSFUNC(GST_RPAD_PEER(pad))(GST_PAD(GST_RPAD_PEER(pad))))
309 gboolean                gst_pad_set_eos                 (GstPad *pad);
310
311 void                    gst_pad_handle_qos              (GstPad *pad, glong qos_message);
312
313 void                    gst_pad_load_and_connect        (xmlNodePtr self, GstObject *parent);
314
315
316 /* ghostpads */
317 GstPad *                gst_ghost_pad_new               (gchar *name,GstPad *pad);
318
319
320
321 /* templates and factories */
322 GtkType                 gst_padtemplate_get_type        (void);
323
324 GstPadTemplate*         gst_padtemplate_new             (GstPadFactory *factory);
325 GstPadTemplate*         gst_padtemplate_create          (gchar *name_template,
326                                                          GstPadDirection direction, GstPadPresence presence,
327                                                          GList *caps);
328
329 xmlNodePtr              gst_padtemplate_save_thyself    (GstPadTemplate *templ, xmlNodePtr parent);
330 GstPadTemplate*         gst_padtemplate_load_thyself    (xmlNodePtr parent);
331
332 #ifdef __cplusplus
333 }
334 #endif /* __cplusplus */
335
336
337 #endif /* __GST_PAD_H__ */
338