API docs 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 typedef enum { 
83   GST_PAD_NEGOTIATE_FAIL,
84   GST_PAD_NEGOTIATE_AGREE,
85   GST_PAD_NEGOTIATE_TRY,
86 } GstPadNegotiateReturn;
87
88
89 /* this defines the functions used to chain buffers
90  * pad is the sink pad (so the same chain function can be used for N pads)
91  * buf is the buffer being passed */
92 typedef void (*GstPadChainFunction) (GstPad *pad,GstBuffer *buf);
93 typedef GstBuffer *(*GstPadGetFunction) (GstPad *pad);
94 typedef GstBuffer *(*GstPadGetRegionFunction) (GstPad *pad, GstRegionType type, guint64 offset, guint64 len);
95 typedef void (*GstPadQoSFunction) (GstPad *pad, glong qos_message);
96
97 typedef void (*GstPadPushFunction) (GstPad *pad, GstBuffer *buf);
98 typedef GstBuffer *(*GstPadPullFunction) (GstPad *pad);
99 typedef GstBuffer *(*GstPadPullRegionFunction) (GstPad *pad, GstRegionType type, guint64 offset, guint64 len);
100 typedef gboolean (*GstPadEOSFunction) (GstPad *pad);
101 typedef GstPadNegotiateReturn (*GstPadNegotiateFunction) (GstPad *pad, GstCaps **caps, gint count);
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   GstPadChainFunction chainfunc;
144   GstPadGetFunction getfunc;
145   GstPadGetRegionFunction getregionfunc;
146   GstPadQoSFunction qosfunc;
147   GstPadEOSFunction eosfunc;
148
149   GstPadPushFunction pushfunc;
150   GstPadPullFunction pullfunc;
151   GstPadPullRegionFunction pullregionfunc;
152
153   GstPadNegotiateFunction negotiatefunc;
154
155   GList *ghostpads;
156 };
157
158 struct _GstRealPadClass {
159   GstPadClass parent_class;
160
161   /* signal callbacks */
162   void (*set_active)    (GstPad *pad, gboolean active);
163   void (*caps_changed)  (GstPad *pad, GstCaps *newcaps);
164   void (*eos)           (GstPad *pad);
165 };
166
167 struct _GstGhostPad {
168   GstPad pad;
169
170   GstRealPad *realpad;
171 };
172
173 struct _GstGhostPadClass {
174   GstPadClass parent_class;
175 };
176
177
178 /***** helper macros *****/
179 /* GstPad */
180 #define GST_PAD_NAME(pad)               (GST_OBJECT_NAME(pad))
181 #define GST_PAD_PARENT(pad)             (GST_OBJECT_PARENT(pad))
182 #define GST_PAD_ELEMENT_PRIVATE(pad)    (((GstPad *)(pad))->element_private)
183 #define GST_PAD_PADTEMPLATE(pad)        (((GstPad *)(pad))->padtemplate)
184
185 /* GstRealPad */
186 #define GST_RPAD_DIRECTION(pad)         (((GstRealPad *)(pad))->direction)
187 #define GST_RPAD_CAPS(pad)              (((GstRealPad *)(pad))->caps)
188 #define GST_RPAD_PEER(pad)              (((GstRealPad *)(pad))->peer)
189 #define GST_RPAD_BUFPEN(pad)            (((GstRealPad *)(pad))->bufpen)
190 #define GST_RPAD_CHAINFUNC(pad)         (((GstRealPad *)(pad))->chainfunc)
191 #define GST_RPAD_GETFUNC(pad)           (((GstRealPad *)(pad))->getfunc)
192 #define GST_RPAD_GETREGIONFUNC(pad)     (((GstRealPad *)(pad))->getregionfunc)
193 #define GST_RPAD_PUSHFUNC(pad)          (((GstRealPad *)(pad))->pushfunc)
194 #define GST_RPAD_PULLFUNC(pad)          (((GstRealPad *)(pad))->pullfunc)
195 #define GST_RPAD_PULLREGIONFUNC(pad)    (((GstRealPad *)(pad))->pullregionfunc)
196 #define GST_RPAD_QOSFUNC(pad)           (((GstRealPad *)(pad))->qosfunc)
197 #define GST_RPAD_EOSFUNC(pad)           (((GstRealPad *)(pad))->eosfunc)
198 #define GST_RPAD_NEGOTIATEFUNC(pad)     (((GstRealPad *)(pad))->negotiatefunc)
199
200 #define GST_RPAD_REGIONTYPE(pad)        (((GstRealPad *)(pad))->regiontype)
201 #define GST_RPAD_OFFSET(pad)            (((GstRealPad *)(pad))->offset)
202 #define GST_RPAD_LEN(pad)               (((GstRealPad *)(pad))->len)
203
204 /* GstGhostPad */
205 #define GST_GPAD_REALPAD(pad)           (((GstGhostPad *)(pad))->realpad)
206
207 /* Generic */
208 #define GST_PAD_REALIZE(pad) (GST_IS_REAL_PAD(pad) ? ((GstRealPad *)(pad)) : GST_GPAD_REALPAD(pad))
209 #define GST_PAD_DIRECTION(pad)          GST_RPAD_DIRECTION(GST_PAD_REALIZE(pad))
210 #define GST_PAD_CAPS(pad)               GST_RPAD_CAPS(GST_PAD_REALIZE(pad))
211 #define GST_PAD_PEER(pad)               GST_RPAD_PEER(GST_PAD_REALIZE(pad))
212
213 /* Some check functions (unused?) */
214 #define GST_PAD_CONNECTED(pad)          (GST_PAD_PEER(pad) != NULL)
215 #define GST_PAD_CAN_PULL(pad)           (GST_IS_REAL_PAD(pad) && GST_REAL_PAD(pad)->pullfunc != NULL)
216
217
218 /***** PadTemplate *****/
219 #define GST_TYPE_PADTEMPLATE            (gst_padtemplate_get_type ())
220 #define GST_PADTEMPLATE(obj)            (GTK_CHECK_CAST ((obj), GST_TYPE_PADTEMPLATE,GstPad))
221 #define GST_PADTEMPLATE_CLASS(klass)    (GTK_CHECK_CLASS_CAST ((klass), GST_TYPE_PADTEMPLATE,GstPadClass))
222 #define GST_IS_PADTEMPLATE(obj)         (GTK_CHECK_TYPE ((obj), GST_TYPE_PADTEMPLATE))
223 #define GST_IS_PADTEMPLATE_CLASS(obj)   (GTK_CHECK_CLASS_TYPE ((klass), GST_TYPE_PADTEMPLATE))
224
225 typedef enum {
226   GST_PAD_ALWAYS,
227   GST_PAD_SOMETIMES,
228   GST_PAD_REQUEST,
229 } GstPadPresence;
230
231 #define GST_PADTEMPLATE_NAME_TEMPLATE(templ)    (((GstPadTemplate *)(templ))->name_template)
232 #define GST_PADTEMPLATE_DIRECTION(templ)        (((GstPadTemplate *)(templ))->direction)
233 #define GST_PADTEMPLATE_PRESENCE(templ)         (((GstPadTemplate *)(templ))->presence)
234 #define GST_PADTEMPLATE_CAPS(templ)             (((GstPadTemplate *)(templ))->caps)
235
236 struct _GstPadTemplate {
237   GstObject       object;
238
239   gchar           *name_template;
240   GstPadDirection direction;
241   GstPadPresence  presence;
242   GstCaps         *caps;
243 };
244
245 struct _GstPadTemplateClass {
246   GstObjectClass parent_class;
247
248   /* signal callbacks */
249   void (*pad_created)   (GstPadTemplate *templ, GstPad *pad);
250 };
251
252
253 /* factory */
254 typedef gpointer GstPadFactoryEntry;
255 typedef GstPadFactoryEntry GstPadFactory[];
256
257 #define GST_PAD_FACTORY_ALWAYS          GINT_TO_POINTER(GST_PAD_ALWAYS)
258 #define GST_PAD_FACTORY_SOMETIMES       GINT_TO_POINTER(GST_PAD_SOMETIMES)
259 #define GST_PAD_FACTORY_REQUEST         GINT_TO_POINTER(GST_PAD_REQUEST)
260
261 #define GST_PAD_FACTORY_SRC             GINT_TO_POINTER(GST_PAD_SRC)
262 #define GST_PAD_FACTORY_SINK            GINT_TO_POINTER(GST_PAD_SINK)
263
264 #define GST_PAD_FACTORY_CAPS_ID         1
265 #define GST_PAD_FACTORY_CAPS(a...)      GINT_TO_POINTER(GST_PAD_FACTORY_CAPS_ID),##a,NULL
266
267
268 GtkType                 gst_pad_get_type                (void);
269 GtkType                 gst_real_pad_get_type           (void);
270 GtkType                 gst_ghost_pad_get_type          (void);
271
272 GstPad*                 gst_pad_new                     (gchar *name, GstPadDirection direction);
273 #define                 gst_pad_destroy(pad)            gst_object_destroy (GST_OBJECT (pad))
274 GstPad*                 gst_pad_new_from_template       (GstPadTemplate *templ, gchar *name);
275
276 GstPadDirection         gst_pad_get_direction           (GstPad *pad);
277
278 void                    gst_pad_set_chain_function      (GstPad *pad, GstPadChainFunction chain);
279 void                    gst_pad_set_get_function        (GstPad *pad, GstPadGetFunction get);
280 void                    gst_pad_set_getregion_function  (GstPad *pad, GstPadGetRegionFunction getregion);
281 void                    gst_pad_set_qos_function        (GstPad *pad, GstPadQoSFunction qos);
282 void                    gst_pad_set_eos_function        (GstPad *pad, GstPadEOSFunction eos);
283 void                    gst_pad_set_negotiate_function  (GstPad *pad, GstPadNegotiateFunction nego);
284
285 gboolean                gst_pad_set_caps                (GstPad *pad, GstCaps *caps);
286 GstCaps*                gst_pad_get_caps                (GstPad *pad);
287 GstCaps*                gst_pad_get_padtemplate_caps    (GstPad *pad);
288 gboolean                gst_pad_check_compatibility     (GstPad *srcpad, GstPad *sinkpad);
289
290 void                    gst_pad_set_element_private     (GstPad *pad, gpointer priv);
291 gpointer                gst_pad_get_element_private     (GstPad *pad);
292
293 void                    gst_pad_set_name                (GstPad *pad, const gchar *name);
294 const gchar*            gst_pad_get_name                (GstPad *pad);
295
296 void                    gst_pad_set_parent              (GstPad *pad, GstObject *parent);
297 GstObject*              gst_pad_get_parent              (GstPad *pad);
298 GstObject*              gst_pad_get_real_parent         (GstPad *pad);
299
300 void                    gst_pad_add_ghost_pad           (GstPad *pad, GstPad *ghostpad);
301 void                    gst_pad_remove_ghost_pad        (GstPad *pad, GstPad *ghostpad);
302 GList*                  gst_pad_get_ghost_pad_list      (GstPad *pad);
303
304 GstPadTemplate*         gst_pad_get_padtemplate         (GstPad *pad);
305
306 GstPad*                 gst_pad_get_peer                (GstPad *pad);
307
308 gboolean                gst_pad_connect                 (GstPad *srcpad, GstPad *sinkpad);
309 void                    gst_pad_disconnect              (GstPad *srcpad, GstPad *sinkpad);
310
311 gboolean                gst_pad_renegotiate             (GstPad *pad);
312 GstPadNegotiateReturn   gst_pad_negotiate_proxy         (GstPad *srcpad, GstPad *destpad, GstCaps **caps, gint counter);
313
314 #if 1
315 void                    gst_pad_push                    (GstPad *pad, GstBuffer *buf);
316 #else
317 #define gst_pad_push(pad,buf) G_STMT_START{ \
318   if ((pad)->peer->pushfunc) ((pad)->peer->pushfunc)((pad)->peer,(buf)); \
319 }G_STMT_END
320 #endif
321 #if 1
322 GstBuffer*              gst_pad_pull                    (GstPad *pad);
323 GstBuffer*              gst_pad_pullregion              (GstPad *pad, GstRegionType type, guint64 offset, guint64 len);
324 #else
325 #define gst_pad_pull(pad) \
326   (((pad)->peer->pullfunc) ? ((pad)->peer->pullfunc)((pad)->peer) : NULL)
327 #define gst_pad_pullregion(pad,type,offset,len) \
328   (((pad)->peer->pullregionfunc) ? ((pad)->peer->pullregionfunc)((pad)->peer,(type),(offset),(len)) : NULL)
329 #endif
330
331 #define                 gst_pad_eos(pad)                (GST_RPAD_EOSFUNC(GST_RPAD_PEER(pad))(GST_PAD(GST_RPAD_PEER(pad))))
332 gboolean                gst_pad_set_eos                 (GstPad *pad);
333
334 void                    gst_pad_handle_qos              (GstPad *pad, glong qos_message);
335
336 void                    gst_pad_load_and_connect        (xmlNodePtr self, GstObject *parent);
337
338
339 /* ghostpads */
340 GstPad *                gst_ghost_pad_new               (gchar *name,GstPad *pad);
341
342
343
344 /* templates and factories */
345 GtkType                 gst_padtemplate_get_type        (void);
346
347 GstPadTemplate*         gst_padtemplate_new             (GstPadFactory *factory);
348 GstPadTemplate*         gst_padtemplate_create          (gchar *name_template,
349                                                          GstPadDirection direction, GstPadPresence presence,
350                                                          GstCaps *caps);
351
352 GstCaps*                gst_padtemplate_get_caps        (GstPadTemplate *templ);
353 GstCaps*                gst_padtemplate_get_caps_by_name        (GstPadTemplate *templ, const gchar *name);
354
355 xmlNodePtr              gst_padtemplate_save_thyself    (GstPadTemplate *templ, xmlNodePtr parent);
356 GstPadTemplate*         gst_padtemplate_load_thyself    (xmlNodePtr parent);
357
358 #ifdef __cplusplus
359 }
360 #endif /* __cplusplus */
361
362
363 #endif /* __GST_PAD_H__ */
364