2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000,2004 Wim Taymans <wim@fluendo.com>
5 * gstelement.h: Header for GstElement
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.
24 #ifndef __GST_ELEMENT_H__
25 #define __GST_ELEMENT_H__
27 #include <gst/gstconfig.h>
28 #include <gst/gsttypes.h>
29 #include <gst/gstobject.h>
30 #include <gst/gstpad.h>
31 #include <gst/gstclock.h>
32 #include <gst/gstplugin.h>
33 #include <gst/gstpluginfeature.h>
34 #include <gst/gstindex.h>
35 #include <gst/gstiterator.h>
36 #include <gst/gstmessage.h>
37 #include <gst/gsttag.h>
41 typedef struct _GstElementDetails GstElementDetails;
43 /* FIXME: need translatable stuff in here (how handle in registry)? */
44 struct _GstElementDetails
47 gchar *longname; /* long, english name */
48 gchar *klass; /* type of element, as hierarchy */
49 gchar *description; /* insights of one form or another */
50 gchar *author; /* who wrote this thing? */
53 gpointer _gst_reserved[GST_PADDING];
56 #define GST_ELEMENT_DETAILS(longname,klass,description,author) \
57 { longname, klass, description, author, GST_PADDING_INIT }
58 #define GST_IS_ELEMENT_DETAILS(details) ( \
59 (details) && ((details)->longname != NULL) && ((details)->klass != NULL) \
60 && ((details)->description != NULL) && ((details)->author != NULL))
62 #define GST_NUM_STATES 4
64 /* NOTE: this probably should be done with an #ifdef to decide
65 * whether to safe-cast or to just do the non-checking cast.
67 #define GST_STATE(obj) (GST_ELEMENT(obj)->current_state)
68 #define GST_STATE_PENDING(obj) (GST_ELEMENT(obj)->pending_state)
69 #define GST_STATE_ERROR(obj) (GST_ELEMENT(obj)->state_error)
71 /* Note: using 8 bit shift mostly "just because", it leaves us enough room to grow <g> */
72 #define GST_STATE_TRANSITION(obj) ((GST_STATE(obj)<<8) | GST_STATE_PENDING(obj))
73 #define GST_STATE_NULL_TO_READY ((GST_STATE_NULL<<8) | GST_STATE_READY)
74 #define GST_STATE_READY_TO_PAUSED ((GST_STATE_READY<<8) | GST_STATE_PAUSED)
75 #define GST_STATE_PAUSED_TO_PLAYING ((GST_STATE_PAUSED<<8) | GST_STATE_PLAYING)
76 #define GST_STATE_PLAYING_TO_PAUSED ((GST_STATE_PLAYING<<8) | GST_STATE_PAUSED)
77 #define GST_STATE_PAUSED_TO_READY ((GST_STATE_PAUSED<<8) | GST_STATE_READY)
78 #define GST_STATE_READY_TO_NULL ((GST_STATE_READY<<8) | GST_STATE_NULL)
80 GST_EXPORT GType _gst_element_type;
82 #define GST_TYPE_ELEMENT (_gst_element_type)
83 #define GST_IS_ELEMENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_ELEMENT))
84 #define GST_IS_ELEMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_ELEMENT))
85 #define GST_ELEMENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_ELEMENT, GstElementClass))
86 #define GST_ELEMENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_ELEMENT, GstElement))
87 #define GST_ELEMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_ELEMENT, GstElementClass))
88 #define GST_ELEMENT_CAST(obj) ((GstElement*)(obj))
90 /* convenience functions */
91 #ifdef G_HAVE_ISO_VARARGS
92 #define GST_ELEMENT_QUERY_TYPE_FUNCTION(functionname, ...) \
93 GST_QUERY_TYPE_FUNCTION (GstElement*, functionname, __VA_ARGS__);
94 #define GST_ELEMENT_FORMATS_FUNCTION(functionname, ...) \
95 GST_FORMATS_FUNCTION (GstElement*, functionname, __VA_ARGS__);
96 #define GST_ELEMENT_EVENT_MASK_FUNCTION(functionname, ...) \
97 GST_EVENT_MASK_FUNCTION (GstElement*, functionname, __VA_ARGS__);
98 #elif defined(G_HAVE_GNUC_VARARGS)
99 #define GST_ELEMENT_QUERY_TYPE_FUNCTION(functionname, a...) \
100 GST_QUERY_TYPE_FUNCTION (GstElement*, functionname, a);
101 #define GST_ELEMENT_FORMATS_FUNCTION(functionname, a...) \
102 GST_FORMATS_FUNCTION (GstElement*, functionname, a);
103 #define GST_ELEMENT_EVENT_MASK_FUNCTION(functionname, a...) \
104 GST_EVENT_MASK_FUNCTION (GstElement*, functionname, a);
109 /* private flags that can be used by the scheduler */
110 GST_ELEMENT_SCHEDULER_PRIVATE1,
111 GST_ELEMENT_SCHEDULER_PRIVATE2,
113 /* ignore state changes from parent */
114 GST_ELEMENT_LOCKED_STATE,
116 /* use some padding for future expansion */
117 GST_ELEMENT_FLAG_LAST = GST_OBJECT_FLAG_LAST + 16
120 #define GST_ELEMENT_IS_LOCKED_STATE(obj) (GST_FLAG_IS_SET(obj,GST_ELEMENT_LOCKED_STATE))
122 #define GST_ELEMENT_NAME(obj) (GST_OBJECT_NAME(obj))
123 #define GST_ELEMENT_PARENT(obj) (GST_ELEMENT_CAST(GST_OBJECT_PARENT(obj)))
124 #define GST_ELEMENT_MANAGER(obj) (GST_ELEMENT_CAST(obj)->manager)
125 #define GST_ELEMENT_BUS(obj) (GST_ELEMENT_CAST(obj)->bus)
126 #define GST_ELEMENT_SCHEDULER(obj) (GST_ELEMENT_CAST(obj)->scheduler)
127 #define GST_ELEMENT_CLOCK(obj) (GST_ELEMENT_CAST(obj)->clock)
128 #define GST_ELEMENT_PADS(obj) (GST_ELEMENT_CAST(obj)->pads)
132 * @el: the element that throws the error
133 * @domain: like CORE, LIBRARY, RESOURCE or STREAM (see #GstError)
134 * @code: error code defined for that domain (see #GstError)
135 * @message: the message to display (format string and args enclosed in round brackets)
136 * @debug: debugging information for the message (format string and args enclosed in round brackets)
138 * Utility function that elements can use in case they encountered a fatal
139 * data processing error. The pipeline will throw an error signal and the
140 * application will be requested to stop further media processing.
142 #define GST_ELEMENT_ERROR(el, domain, code, text, debug) \
144 gchar *__txt = _gst_element_error_printf text; \
145 gchar *__dbg = _gst_element_error_printf debug; \
147 GST_ERROR_OBJECT (el, "%s", __txt); \
149 GST_ERROR_OBJECT (el, "%s", __dbg); \
150 gst_element_message_full (GST_ELEMENT(el), GST_MESSAGE_ERROR, \
151 GST_ ## domain ## _ERROR, GST_ ## domain ## _ERROR_ ## code, \
152 __txt, __dbg, __FILE__, GST_FUNCTION, __LINE__); \
155 /* log a (non-fatal) warning message and post it on the bus */
156 #define GST_ELEMENT_WARNING(el, domain, code, text, debug) \
158 gchar *__txt = _gst_element_error_printf text; \
159 gchar *__dbg = _gst_element_error_printf debug; \
161 GST_WARNING_OBJECT (el, "%s", __txt); \
163 GST_WARNING_OBJECT (el, "%s", __dbg); \
164 gst_element_message_full (GST_ELEMENT(el), GST_MESSAGE_WARNING, \
165 GST_ ## domain ## _ERROR, GST_ ## domain ## _ERROR_ ## code, \
166 __txt, __dbg, __FILE__, GST_FUNCTION, __LINE__); \
169 /* the state change mutexes and conds */
170 #define GST_STATE_GET_LOCK(elem) (GST_ELEMENT_CAST(elem)->state_lock)
171 #define GST_STATE_LOCK(elem) g_mutex_lock(GST_STATE_GET_LOCK(elem))
172 #define GST_STATE_TRYLOCK(elem) g_mutex_trylock(GST_STATE_GET_LOCK(elem))
173 #define GST_STATE_UNLOCK(elem) g_mutex_unlock(GST_STATE_GET_LOCK(elem))
174 #define GST_STATE_GET_COND(elem) (GST_ELEMENT_CAST(elem)->state_cond)
175 #define GST_STATE_WAIT(elem) g_cond_wait (GST_STATE_GET_COND (elem), GST_STATE_GET_LOCK (elem))
176 #define GST_STATE_TIMED_WAIT(elem, timeval) g_cond_timed_wait (GST_STATE_GET_COND (elem), GST_STATE_GET_LOCK (elem),\
178 #define GST_STATE_SIGNAL(elem) g_cond_signal (GST_STATE_GET_COND (elem));
179 #define GST_STATE_BROADCAST(elem) g_cond_broadcast (GST_STATE_GET_COND (elem));
181 typedef struct _GstElementFactory GstElementFactory;
182 typedef struct _GstElementFactoryClass GstElementFactoryClass;
188 /*< public >*/ /* with STATE_LOCK */
192 guint8 current_state;
193 guint8 pending_state;
194 gboolean state_error; /* flag is set when the element has an error in the last state
195 change. it is cleared when doing another state change. */
196 /*< public >*/ /* with LOCK */
197 /* element manager */
198 GstPipeline *manager;
200 GstScheduler *scheduler;
201 /* private pointer for the scheduler */
202 gpointer sched_private;
204 /* allocated clock */
206 GstClockTimeDiff base_time; /* NULL/READY: 0 - PAUSED: current time - PLAYING: difference to clock */
208 /* element pads, these lists can only be iterated while holding
209 * the LOCK or checking the cookie after each LOCK. */
219 gpointer _gst_reserved[GST_PADDING];
222 struct _GstElementClass
224 GstObjectClass parent_class;
227 /* the element details */
228 GstElementDetails details;
230 /* factory that the element was created from */
231 GstElementFactory *elementfactory;
233 /* templates for our pads */
235 gint numpadtemplates;
236 guint32 pad_templ_cookie;
238 /* signal callbacks */
239 void (*state_change) (GstElement *element, GstElementState old, GstElementState state);
240 void (*new_pad) (GstElement *element, GstPad *pad);
241 void (*pad_removed) (GstElement *element, GstPad *pad);
242 void (*no_more_pads) (GstElement *element);
247 /* request/release pads */
248 GstPad* (*request_new_pad) (GstElement *element, GstPadTemplate *templ, const gchar* name);
249 void (*release_pad) (GstElement *element, GstPad *pad);
252 GstElementStateReturn (*get_state) (GstElement * element, GstElementState * state,
253 GstElementState * pending, GTimeVal * timeout);
254 GstElementStateReturn (*change_state) (GstElement *element);
257 void (*set_manager) (GstElement * element, GstPipeline * pipeline);
258 void (*set_bus) (GstElement * element, GstBus * bus);
259 void (*set_scheduler) (GstElement *element, GstScheduler *scheduler);
262 GstClock* (*get_clock) (GstElement *element);
263 void (*set_clock) (GstElement *element, GstClock *clock);
266 GstIndex* (*get_index) (GstElement *element);
267 void (*set_index) (GstElement *element, GstIndex *index);
269 /* query/convert/events functions */
270 const GstEventMask* (*get_event_masks) (GstElement *element);
271 gboolean (*send_event) (GstElement *element, GstEvent *event);
272 const GstFormat* (*get_formats) (GstElement *element);
273 gboolean (*convert) (GstElement *element,
274 GstFormat src_format, gint64 src_value,
275 GstFormat *dest_format, gint64 *dest_value);
276 const GstQueryType* (*get_query_types) (GstElement *element);
277 gboolean (*query) (GstElement *element, GstQueryType type,
278 GstFormat *format, gint64 *value);
281 gpointer _gst_reserved[GST_PADDING];
284 /* element class pad templates */
285 void gst_element_class_add_pad_template (GstElementClass *klass, GstPadTemplate *templ);
286 GstPadTemplate* gst_element_class_get_pad_template (GstElementClass *element_class, const gchar *name);
287 GList* gst_element_class_get_pad_template_list (GstElementClass *element_class);
288 void gst_element_class_set_details (GstElementClass *klass,
289 const GstElementDetails *details);
291 /* element instance */
292 GType gst_element_get_type (void);
294 /* basic name and parentage stuff from GstObject */
295 #define gst_element_get_name(elem) gst_object_get_name(GST_OBJECT(elem))
296 #define gst_element_set_name(elem,name) gst_object_set_name(GST_OBJECT(elem),name)
297 #define gst_element_get_parent(elem) gst_object_get_parent(GST_OBJECT(elem))
298 #define gst_element_set_parent(elem,parent) gst_object_set_parent(GST_OBJECT(elem),parent)
301 gboolean gst_element_requires_clock (GstElement *element);
302 gboolean gst_element_provides_clock (GstElement *element);
303 GstClock* gst_element_get_clock (GstElement *element);
304 void gst_element_set_clock (GstElement *element, GstClock *clock);
307 gboolean gst_element_is_indexable (GstElement *element);
308 void gst_element_set_index (GstElement *element, GstIndex *index);
309 GstIndex* gst_element_get_index (GstElement *element);
311 /* manager and tasks */
312 void gst_element_set_manager (GstElement * element, GstPipeline * pipeline);
313 GstPipeline *gst_element_get_manager (GstElement * element);
314 void gst_element_set_bus (GstElement * element, GstBus * bus);
315 GstBus *gst_element_get_bus (GstElement * element);
316 void gst_element_set_scheduler (GstElement *element, GstScheduler *sched);
317 GstScheduler* gst_element_get_scheduler (GstElement *element);
320 gboolean gst_element_add_pad (GstElement *element, GstPad *pad);
321 gboolean gst_element_remove_pad (GstElement *element, GstPad *pad);
322 GstPad * gst_element_add_ghost_pad (GstElement *element, GstPad *pad, const gchar *name);
323 void gst_element_no_more_pads (GstElement *element);
325 GstPad* gst_element_get_pad (GstElement *element, const gchar *name);
326 GstPad* gst_element_get_static_pad (GstElement *element, const gchar *name);
327 GstPad* gst_element_get_request_pad (GstElement *element, const gchar *name);
328 void gst_element_release_request_pad (GstElement *element, GstPad *pad);
330 GstIterator * gst_element_iterate_pads (GstElement * element);
332 /* event/query/format stuff */
333 G_CONST_RETURN GstEventMask*
334 gst_element_get_event_masks (GstElement *element);
335 gboolean gst_element_send_event (GstElement *element, GstEvent *event);
336 gboolean gst_element_seek (GstElement *element, GstSeekType seek_type,
338 G_CONST_RETURN GstQueryType*
339 gst_element_get_query_types (GstElement *element);
340 gboolean gst_element_query (GstElement *element, GstQueryType type,
341 GstFormat *format, gint64 *value);
342 G_CONST_RETURN GstFormat*
343 gst_element_get_formats (GstElement *element);
344 gboolean gst_element_convert (GstElement *element,
345 GstFormat src_format, gint64 src_value,
346 GstFormat *dest_format, gint64 *dest_value);
349 gboolean gst_element_post_message (GstElement * element, GstMessage * message);
352 gchar * _gst_element_error_printf (const gchar *format, ...);
353 void gst_element_message_full (GstElement * element, GstMessageType type,
354 GQuark domain, gint code, gchar * text, gchar * debug, const gchar * file,
355 const gchar * function, gint line);
357 /* state management */
358 gboolean gst_element_is_locked_state (GstElement *element);
359 gboolean gst_element_set_locked_state (GstElement *element, gboolean locked_state);
360 gboolean gst_element_sync_state_with_parent (GstElement *element);
362 GstElementStateReturn gst_element_get_state (GstElement * element,
363 GstElementState * state,
364 GstElementState * pending,
366 GstElementStateReturn gst_element_set_state (GstElement *element, GstElementState state);
368 void gst_element_abort_state (GstElement * element);
369 void gst_element_commit_state (GstElement * element);
370 void gst_element_lost_state (GstElement * element);
372 /* factory management */
373 GstElementFactory* gst_element_get_factory (GstElement *element);
381 #define GST_TYPE_ELEMENT_FACTORY (gst_element_factory_get_type())
382 #define GST_ELEMENT_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_ELEMENT_FACTORY,\
384 #define GST_ELEMENT_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_ELEMENT_FACTORY,\
385 GstElementFactoryClass))
386 #define GST_IS_ELEMENT_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_ELEMENT_FACTORY))
387 #define GST_IS_ELEMENT_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_ELEMENT_FACTORY))
389 struct _GstElementFactory {
390 GstPluginFeature parent;
392 GType type; /* unique GType of element or 0 if not loaded */
394 GstElementDetails details;
396 GList * staticpadtemplates;
397 guint numpadtemplates;
399 /* URI interface stuff */
401 gchar ** uri_protocols;
403 GList * interfaces; /* interfaces this element implements */
405 gpointer _gst_reserved[GST_PADDING];
408 struct _GstElementFactoryClass {
409 GstPluginFeatureClass parent_class;
411 gpointer _gst_reserved[GST_PADDING];
414 GType gst_element_factory_get_type (void);
416 gboolean gst_element_register (GstPlugin *plugin,
421 GstElementFactory * gst_element_factory_find (const gchar *name);
422 GType gst_element_factory_get_element_type (GstElementFactory *factory);
423 G_CONST_RETURN gchar * gst_element_factory_get_longname (GstElementFactory *factory);
424 G_CONST_RETURN gchar * gst_element_factory_get_klass (GstElementFactory *factory);
425 G_CONST_RETURN gchar * gst_element_factory_get_description (GstElementFactory *factory);
426 G_CONST_RETURN gchar * gst_element_factory_get_author (GstElementFactory *factory);
427 guint gst_element_factory_get_num_pad_templates (GstElementFactory *factory);
428 G_CONST_RETURN GList * gst_element_factory_get_static_pad_templates (GstElementFactory *factory);
429 guint gst_element_factory_get_uri_type (GstElementFactory *factory);
430 gchar ** gst_element_factory_get_uri_protocols (GstElementFactory *factory);
432 GstElement* gst_element_factory_create (GstElementFactory *factory,
434 GstElement* gst_element_factory_make (const gchar *factoryname, const gchar *name);
436 void __gst_element_factory_add_static_pad_template (GstElementFactory *elementfactory,
437 GstStaticPadTemplate *templ);
438 void __gst_element_factory_add_interface (GstElementFactory *elementfactory,
439 const gchar *interfacename);
443 #endif /* __GST_ELEMENT_H__ */