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