2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wim.taymans@chello.be>
5 * gstpad.h: Header for GstPad object
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.
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.
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.
27 #include <gst/gstconfig.h>
29 #include <gst/gstobject.h>
30 #include <gst/gstbuffer.h>
31 #include <gst/gstcaps.h>
32 #include <gst/gstevent.h>
37 extern GType _gst_pad_type;
38 extern GType _gst_real_pad_type;
39 extern GType _gst_ghost_pad_type;
41 #define GST_TYPE_PARANOID
46 #define GST_TYPE_PAD (_gst_pad_type)
48 #define GST_PAD_CAST(obj) ((GstPad*)(obj))
49 #define GST_PAD_CLASS_CAST(klass) ((GstPadClass*)(klass))
50 #define GST_IS_PAD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_PAD))
51 #define GST_IS_PAD_FAST(obj) (G_OBJECT_TYPE(obj) == GST_TYPE_REAL_PAD || \
52 G_OBJECT_TYPE(obj) == GST_TYPE_GHOST_PAD)
53 #define GST_IS_PAD_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_PAD))
55 #ifdef GST_TYPE_PARANOID
56 # define GST_PAD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_PAD, GstPad))
57 # define GST_PAD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_PAD, GstPadClass))
59 # define GST_PAD GST_PAD_CAST
60 # define GST_PAD_CLASS GST_PAD_CLASS_CAST
66 #define GST_TYPE_REAL_PAD (_gst_real_pad_type)
68 #define GST_REAL_PAD_CAST(obj) ((GstRealPad*)(obj))
69 #define GST_REAL_PAD_CLASS_CAST(klass) ((GstRealPadClass*)(klass))
70 #define GST_IS_REAL_PAD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_REAL_PAD))
71 #define GST_IS_REAL_PAD_FAST(obj) (G_OBJECT_TYPE(obj) == GST_TYPE_REAL_PAD)
72 #define GST_IS_REAL_PAD_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_REAL_PAD))
74 #ifdef GST_TYPE_PARANOID
75 # define GST_REAL_PAD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_REAL_PAD, GstRealPad))
76 # define GST_REAL_PAD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_REAL_PAD, GstRealPadClass))
78 # define GST_REAL_PAD GST_REAL_PAD_CAST
79 # define GST_REAL_PAD_CLASS GST_REAL_PAD_CLASS_CAST
85 #define GST_TYPE_GHOST_PAD (_gst_ghost_pad_type)
87 #define GST_GHOST_PAD_CAST(obj) ((GstGhostPad*)(obj))
88 #define GST_GHOST_PAD_CLASS_CAST(klass) ((GstGhostPadClass*)(klass))
89 #define GST_IS_GHOST_PAD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_GHOST_PAD))
90 #define GST_IS_GHOST_PAD_FAST(obj) (G_OBJECT_TYPE(obj) == GST_TYPE_GHOST_PAD)
91 #define GST_IS_GHOST_PAD_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_GHOST_PAD))
93 #ifdef GST_TYPE_PARANOID
94 # define GST_GHOST_PAD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_GHOST_PAD, GstGhostPad))
95 # define GST_GHOST_PAD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_GHOST_PAD, GstGhostPadClass))
97 # define GST_GHOST_PAD GST_GHOST_PAD_CAST
98 # define GST_GHOST_PAD_CLASS GST_GHOST_PAD_CLASS_CAST
102 /*typedef struct _GstPad GstPad; */
103 /*typedef struct _GstPadClass GstPadClass;*/
104 typedef struct _GstRealPad GstRealPad;
105 typedef struct _GstRealPadClass GstRealPadClass;
106 typedef struct _GstGhostPad GstGhostPad;
107 typedef struct _GstGhostPadClass GstGhostPadClass;
108 /*typedef struct _GstPadTemplate GstPadTemplate;*/
109 /*typedef struct _GstPadTemplateClass GstPadTemplateClass;*/
113 GST_PAD_CONNECT_REFUSED = -1,
114 GST_PAD_CONNECT_DELAYED = 0,
115 GST_PAD_CONNECT_OK = 1,
116 GST_PAD_CONNECT_DONE = 2
117 } GstPadConnectReturn;
120 GST_PAD_QUERY_NONE = 0,
122 GST_PAD_QUERY_POSITION,
123 GST_PAD_QUERY_LATENCY,
124 GST_PAD_QUERY_JITTER,
126 GST_PAD_QUERY_SEGMENT_END,
130 #define GST_PAD_QUERY_TYPE_FUNCTION(functionname, a...) \
131 static const GstPadQueryType* \
132 functionname (GstPad *pad) \
134 static const GstPadQueryType types[] = { \
142 /* this defines the functions used to chain buffers
143 * pad is the sink pad (so the same chain function can be used for N pads)
144 * buf is the buffer being passed */
145 typedef void (*GstPadChainFunction) (GstPad *pad,GstBuffer *buf);
146 typedef GstBuffer* (*GstPadGetFunction) (GstPad *pad);
147 typedef gboolean (*GstPadEventFunction) (GstPad *pad, GstEvent *event);
148 typedef gboolean (*GstPadConvertFunction) (GstPad *pad,
149 GstFormat src_format, gint64 src_value,
150 GstFormat *dest_format, gint64 *dest_value);
151 typedef gboolean (*GstPadQueryFunction) (GstPad *pad, GstPadQueryType type,
152 GstFormat *format, gint64 *value);
153 typedef GList* (*GstPadIntConnFunction) (GstPad *pad);
154 typedef const GstFormat* (*GstPadFormatsFunction) (GstPad *pad);
155 typedef const GstEventMask* (*GstPadEventMaskFunction) (GstPad *pad);
156 typedef const GstPadQueryType* (*GstPadQueryTypeFunction) (GstPad *pad);
158 typedef GstPadConnectReturn (*GstPadConnectFunction) (GstPad *pad, GstCaps *caps);
159 typedef GstCaps* (*GstPadGetCapsFunction) (GstPad *pad, GstCaps *caps);
160 typedef GstBufferPool* (*GstPadBufferPoolFunction) (GstPad *pad);
162 typedef gboolean (*GstPadDispatcherFunction) (GstPad *pad, gpointer data);
171 GST_PAD_DISABLED = GST_OBJECT_FLAG_LAST,
174 GST_PAD_FLAG_LAST = GST_OBJECT_FLAG_LAST + 4
180 gpointer element_private;
182 GstPadTemplate *padtemplate; /* the template for this pad */
185 struct _GstPadClass {
186 GstObjectClass parent_class;
192 /* the pad capabilities */
196 GstPadGetCapsFunction getcapsfunc;
198 GstPadDirection direction;
200 GstPadConnectFunction connectfunc;
203 gpointer sched_private;
205 /* data transport functions */
206 GstPadChainFunction chainfunc;
207 GstPadChainFunction chainhandler;
208 GstPadGetFunction getfunc;
209 GstPadGetFunction gethandler;
210 GstPadEventFunction eventfunc;
211 GstPadEventFunction eventhandler;
212 GstPadEventMaskFunction eventmaskfunc;
216 /* query/convert/formats functions */
217 GstPadConvertFunction convertfunc;
218 GstPadQueryFunction queryfunc;
219 GstPadFormatsFunction formatsfunc;
220 GstPadQueryTypeFunction querytypefunc;
221 GstPadIntConnFunction intconnfunc;
223 GstPadBufferPoolFunction bufferpoolfunc;
226 struct _GstRealPadClass {
227 GstPadClass parent_class;
229 /* signal callbacks */
230 void (*set_active) (GstPad *pad, gboolean active);
231 void (*caps_changed) (GstPad *pad, GstCaps *newcaps);
232 void (*caps_nego_failed) (GstPad *pad);
233 void (*connected) (GstPad *pad, GstPad *peer);
234 void (*disconnected) (GstPad *pad, GstPad *peer);
235 void (*event_received) (GstPad *pad, GstEvent *event);
237 void (*eos) (GstPad *pad);
240 struct _GstGhostPad {
246 struct _GstGhostPadClass {
247 GstPadClass parent_class;
251 /***** helper macros *****/
253 #define GST_PAD_NAME(pad) (GST_OBJECT_NAME(pad))
254 #define GST_PAD_PARENT(pad) ((GstElement *)(GST_OBJECT_PARENT(pad)))
255 #define GST_PAD_ELEMENT_PRIVATE(pad) (((GstPad *)(pad))->element_private)
256 #define GST_PAD_PAD_TEMPLATE(pad) (((GstPad *)(pad))->padtemplate)
259 #define GST_RPAD_DIRECTION(pad) (((GstRealPad *)(pad))->direction)
260 #define GST_RPAD_CAPS(pad) (((GstRealPad *)(pad))->caps)
261 #define GST_RPAD_FILTER(pad) (((GstRealPad *)(pad))->filter)
262 #define GST_RPAD_APPFILTER(pad) (((GstRealPad *)(pad))->appfilter)
263 #define GST_RPAD_PEER(pad) (((GstRealPad *)(pad))->peer)
264 #define GST_RPAD_CHAINFUNC(pad) (((GstRealPad *)(pad))->chainfunc)
265 #define GST_RPAD_CHAINHANDLER(pad) (((GstRealPad *)(pad))->chainhandler)
266 #define GST_RPAD_GETFUNC(pad) (((GstRealPad *)(pad))->getfunc)
267 #define GST_RPAD_GETHANDLER(pad) (((GstRealPad *)(pad))->gethandler)
268 #define GST_RPAD_EVENTFUNC(pad) (((GstRealPad *)(pad))->eventfunc)
269 #define GST_RPAD_EVENTHANDLER(pad) (((GstRealPad *)(pad))->eventhandler)
270 #define GST_RPAD_CONVERTFUNC(pad) (((GstRealPad *)(pad))->convertfunc)
271 #define GST_RPAD_QUERYFUNC(pad) (((GstRealPad *)(pad))->queryfunc)
272 #define GST_RPAD_INTCONNFUNC(pad) (((GstRealPad *)(pad))->intconnfunc)
273 #define GST_RPAD_FORMATSFUNC(pad) (((GstRealPad *)(pad))->formatsfunc)
274 #define GST_RPAD_QUERYTYPEFUNC(pad) (((GstRealPad *)(pad))->querytypefunc)
275 #define GST_RPAD_EVENTMASKFUNC(pad) (((GstRealPad *)(pad))->eventmaskfunc)
277 #define GST_RPAD_EVENT_MASKS(pad) (((GstRealPad *)(pad))->event_masks)
278 #define GST_RPAD_QUERY_TYPES(pad) (((GstRealPad *)(pad))->query_types)
280 #define GST_RPAD_CONNECTFUNC(pad) (((GstRealPad *)(pad))->connectfunc)
281 #define GST_RPAD_GETCAPSFUNC(pad) (((GstRealPad *)(pad))->getcapsfunc)
282 #define GST_RPAD_BUFFERPOOLFUNC(pad) (((GstRealPad *)(pad))->bufferpoolfunc)
285 #define GST_GPAD_REALPAD(pad) (((GstGhostPad *)(pad))->realpad)
288 #define GST_PAD_REALIZE(pad) (GST_IS_REAL_PAD(pad) ? ((GstRealPad *)(pad)) : GST_GPAD_REALPAD(pad))
289 #define GST_PAD_DIRECTION(pad) GST_RPAD_DIRECTION(GST_PAD_REALIZE(pad))
290 #define GST_PAD_CAPS(pad) GST_RPAD_CAPS(GST_PAD_REALIZE(pad))
291 #define GST_PAD_PEER(pad) GST_PAD_CAST(GST_RPAD_PEER(GST_PAD_REALIZE(pad)))
293 /* Some check functions (unused?) */
294 #define GST_PAD_IS_CONNECTED(pad) (GST_PAD_PEER(pad) != NULL)
295 #define GST_PAD_IS_ACTIVE(pad) (!GST_FLAG_IS_SET(pad, GST_PAD_DISABLED))
296 #define GST_PAD_IS_USABLE(pad) (GST_PAD_IS_CONNECTED (pad) && \
297 GST_PAD_IS_ACTIVE(pad) && GST_PAD_IS_ACTIVE(GST_PAD_PEER (pad)))
298 #define GST_PAD_CAN_PULL(pad) (GST_IS_REAL_PAD(pad) && GST_REAL_PAD(pad)->gethandler != NULL)
299 #define GST_PAD_IS_SRC(pad) (GST_PAD_DIRECTION(pad) == GST_PAD_SRC)
300 #define GST_PAD_IS_SINK(pad) (GST_PAD_DIRECTION(pad) == GST_PAD_SINK)
302 /***** PadTemplate *****/
303 #define GST_TYPE_PAD_TEMPLATE (gst_pad_template_get_type ())
304 #define GST_PAD_TEMPLATE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_PAD_TEMPLATE,GstPadTemplate))
305 #define GST_PAD_TEMPLATE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_PAD_TEMPLATE,GstPadTemplateClass))
306 #define GST_IS_PAD_TEMPLATE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_PAD_TEMPLATE))
307 #define GST_IS_PAD_TEMPLATE_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_PAD_TEMPLATE))
315 #define GST_PAD_TEMPLATE_NAME_TEMPLATE(templ) (((GstPadTemplate *)(templ))->name_template)
316 #define GST_PAD_TEMPLATE_DIRECTION(templ) (((GstPadTemplate *)(templ))->direction)
317 #define GST_PAD_TEMPLATE_PRESENCE(templ) (((GstPadTemplate *)(templ))->presence)
318 #define GST_PAD_TEMPLATE_CAPS(templ) (((GstPadTemplate *)(templ))->caps)
319 #define GST_PAD_TEMPLATE_FIXED(templ) (((GstPadTemplate *)(templ))->fixed)
321 #define GST_PAD_TEMPLATE_IS_FIXED(templ) (GST_PAD_TEMPLATE_FIXED(templ) == TRUE)
323 struct _GstPadTemplate {
326 gchar *name_template;
327 GstPadDirection direction;
328 GstPadPresence presence;
333 struct _GstPadTemplateClass {
334 GstObjectClass parent_class;
336 /* signal callbacks */
337 void (*pad_created) (GstPadTemplate *templ, GstPad *pad);
340 /* CR1: the space after 'a' is necessary because of preprocessing in gcc */
341 #define GST_PAD_TEMPLATE_NEW(padname, dir, pres, a...) \
342 gst_pad_template_new ( \
349 #define GST_PAD_TEMPLATE_FACTORY(name, padname, dir, pres, a...) \
350 static GstPadTemplate* \
353 static GstPadTemplate *templ = NULL; \
355 templ = GST_PAD_TEMPLATE_NEW ( \
364 #define GST_PAD_TEMPLATE_GET(fact) (fact)()
366 GType gst_pad_get_type (void);
367 GType gst_real_pad_get_type (void);
368 GType gst_ghost_pad_get_type (void);
371 GstPad* gst_pad_new (const gchar *name, GstPadDirection direction);
372 #define gst_pad_destroy(pad) gst_object_destroy (GST_OBJECT (pad))
373 GstPad* gst_pad_new_from_template (GstPadTemplate *templ, const gchar *name);
374 GstPad* gst_pad_custom_new (GType type, const gchar *name, GstPadDirection direction);
375 GstPad* gst_pad_custom_new_from_template (GType type, GstPadTemplate *templ, const gchar *name);
377 void gst_pad_set_name (GstPad *pad, const gchar *name);
378 const gchar* gst_pad_get_name (GstPad *pad);
380 GstPadDirection gst_pad_get_direction (GstPad *pad);
382 void gst_pad_set_active (GstPad *pad, gboolean active);
383 gboolean gst_pad_is_active (GstPad *pad);
385 void gst_pad_set_element_private (GstPad *pad, gpointer priv);
386 gpointer gst_pad_get_element_private (GstPad *pad);
388 void gst_pad_set_parent (GstPad *pad, GstElement *parent);
389 GstElement* gst_pad_get_parent (GstPad *pad);
390 GstElement* gst_pad_get_real_parent (GstPad *pad);
392 GstScheduler* gst_pad_get_scheduler (GstPad *pad);
394 void gst_pad_add_ghost_pad (GstPad *pad, GstPad *ghostpad);
395 void gst_pad_remove_ghost_pad (GstPad *pad, GstPad *ghostpad);
396 GList* gst_pad_get_ghost_pad_list (GstPad *pad);
398 GstPadTemplate* gst_pad_get_pad_template (GstPad *pad);
400 void gst_pad_set_bufferpool_function (GstPad *pad, GstPadBufferPoolFunction bufpool);
401 GstBufferPool* gst_pad_get_bufferpool (GstPad *pad);
403 /* data passing setup functions */
404 void gst_pad_set_chain_function (GstPad *pad, GstPadChainFunction chain);
405 void gst_pad_set_get_function (GstPad *pad, GstPadGetFunction get);
406 void gst_pad_set_event_function (GstPad *pad, GstPadEventFunction event);
407 void gst_pad_set_event_mask_function (GstPad *pad, GstPadEventMaskFunction mask_func);
408 const GstEventMask* gst_pad_get_event_masks (GstPad *pad);
409 const GstEventMask* gst_pad_get_event_masks_default (GstPad *pad);
410 gboolean gst_pad_handles_event (GstPad *pad, GstEventMask *mask);
412 /* pad connections */
413 void gst_pad_set_connect_function (GstPad *pad, GstPadConnectFunction connect);
414 gboolean gst_pad_can_connect (GstPad *srcpad, GstPad *sinkpad);
415 gboolean gst_pad_can_connect_filtered (GstPad *srcpad, GstPad *sinkpad, GstCaps *filtercaps);
417 gboolean gst_pad_connect (GstPad *srcpad, GstPad *sinkpad);
418 gboolean gst_pad_connect_filtered (GstPad *srcpad, GstPad *sinkpad, GstCaps *filtercaps);
419 void gst_pad_disconnect (GstPad *srcpad, GstPad *sinkpad);
421 GstPad* gst_pad_get_peer (GstPad *pad);
423 /* capsnego functions */
424 GstCaps* gst_pad_get_caps (GstPad *pad);
425 GstCaps* gst_pad_get_pad_template_caps (GstPad *pad);
426 GstPadConnectReturn gst_pad_try_set_caps (GstPad *pad, GstCaps *caps);
427 gboolean gst_pad_check_compatibility (GstPad *srcpad, GstPad *sinkpad);
429 void gst_pad_set_getcaps_function (GstPad *pad, GstPadGetCapsFunction getcaps);
430 GstPadConnectReturn gst_pad_proxy_connect (GstPad *pad, GstCaps *caps);
431 gboolean gst_pad_reconnect_filtered (GstPad *srcpad, GstPad *sinkpad, GstCaps *filtercaps);
432 gboolean gst_pad_perform_negotiate (GstPad *srcpad, GstPad *sinkpad);
433 gboolean gst_pad_try_reconnect_filtered (GstPad *srcpad, GstPad *sinkpad, GstCaps *filtercaps);
434 GstCaps* gst_pad_get_allowed_caps (GstPad *pad);
435 gboolean gst_pad_recalc_allowed_caps (GstPad *pad);
437 /* data passing functions */
438 void gst_pad_push (GstPad *pad, GstBuffer *buf);
439 GstBuffer* gst_pad_pull (GstPad *pad);
440 gboolean gst_pad_send_event (GstPad *pad, GstEvent *event);
441 gboolean gst_pad_event_default (GstPad *pad, GstEvent *event);
442 GstPad* gst_pad_select (GList *padlist);
443 GstPad* gst_pad_selectv (GstPad *pad, ...);
446 /* convert/query/format functions */
447 void gst_pad_set_formats_function (GstPad *pad, GstPadFormatsFunction format);
448 gboolean gst_pad_handles_format (GstPad *pad, GstFormat format);
449 const GstFormat* gst_pad_get_formats (GstPad *pad);
450 const GstFormat* gst_pad_get_formats_default (GstPad *pad);
452 void gst_pad_set_convert_function (GstPad *pad, GstPadConvertFunction convert);
453 gboolean gst_pad_convert (GstPad *pad,
454 GstFormat src_format, gint64 src_value,
455 GstFormat *dest_format, gint64 *dest_value);
456 gboolean gst_pad_convert_default (GstPad *pad,
457 GstFormat src_format, gint64 src_value,
458 GstFormat *dest_format, gint64 *dest_value);
460 void gst_pad_set_query_function (GstPad *pad, GstPadQueryFunction query);
461 void gst_pad_set_query_type_function (GstPad *pad, GstPadQueryTypeFunction type_function);
462 const GstPadQueryType* gst_pad_get_query_types (GstPad *pad);
463 const GstPadQueryType* gst_pad_get_query_types_default (GstPad *pad);
464 gboolean gst_pad_query (GstPad *pad, GstPadQueryType type,
465 GstFormat *format, gint64 *value);
466 gboolean gst_pad_query_default (GstPad *pad, GstPadQueryType type,
467 GstFormat *format, gint64 *value);
469 void gst_pad_set_internal_connection_function(GstPad *pad, GstPadIntConnFunction intconn);
470 GList* gst_pad_get_internal_connections (GstPad *pad);
471 GList* gst_pad_get_internal_connections_default (GstPad *pad);
473 /* misc helper functions */
474 gboolean gst_pad_dispatcher (GstPad *pad, GstPadDispatcherFunction dispatch,
478 #ifndef GST_DISABLE_LOADSAVE
479 void gst_pad_load_and_connect (xmlNodePtr self, GstObject *parent);
484 GstPad* gst_ghost_pad_new (const gchar *name, GstPad *pad);
487 /* templates and factories */
488 GType gst_pad_template_get_type (void);
490 GstPadTemplate* gst_pad_template_new (const gchar *name_template,
491 GstPadDirection direction, GstPadPresence presence,
494 GstCaps* gst_pad_template_get_caps (GstPadTemplate *templ);
495 GstCaps* gst_pad_template_get_caps_by_name (GstPadTemplate *templ, const gchar *name);
497 xmlNodePtr gst_ghost_pad_save_thyself (GstPad *pad,
503 #endif /* __GST_PAD_H__ */