Remove old query functions. Ported old code.
[platform/upstream/gstreamer.git] / gst / gstelement.h
1 /* GStreamer
2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3  *               2000,2004 Wim Taymans <wim@fluendo.com>
4  *
5  * gstelement.h: Header for GstElement
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_ELEMENT_H__
25 #define __GST_ELEMENT_H__
26
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>
38
39 G_BEGIN_DECLS
40
41 typedef struct _GstElementDetails GstElementDetails;
42
43 /* FIXME: need translatable stuff in here (how handle in registry)? */
44 struct _GstElementDetails
45 {
46   /*< public > */
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? */
51
52   /*< private > */
53   gpointer _gst_reserved[GST_PADDING];
54 };
55
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))
61
62 #define GST_NUM_STATES 4
63
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.
66  */
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)
70
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)
79
80 GST_EXPORT GType _gst_element_type;
81
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))
89
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);
105 #endif
106
107 typedef enum
108 {
109   /* private flags that can be used by the scheduler */
110   GST_ELEMENT_SCHEDULER_PRIVATE1,
111   GST_ELEMENT_SCHEDULER_PRIVATE2,
112
113   /* ignore state changes from parent */
114   GST_ELEMENT_LOCKED_STATE,
115
116   /* use some padding for future expansion */
117   GST_ELEMENT_FLAG_LAST         = GST_OBJECT_FLAG_LAST + 16
118 } GstElementFlags;
119
120 #define GST_ELEMENT_IS_LOCKED_STATE(obj)        (GST_FLAG_IS_SET(obj,GST_ELEMENT_LOCKED_STATE))
121
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)
129
130 /**
131  * GST_ELEMENT_ERROR:
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)
137  *
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.
141  */
142 #define GST_ELEMENT_ERROR(el, domain, code, text, debug)                \
143 G_STMT_START {                                                          \
144   gchar *__txt = _gst_element_error_printf text;                        \
145   gchar *__dbg = _gst_element_error_printf debug;                       \
146   if (__txt)                                                            \
147     GST_ERROR_OBJECT (el, "%s", __txt);                                 \
148   if (__dbg)                                                            \
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__);                    \
153 } G_STMT_END
154
155 /* log a (non-fatal) warning message and post it on the bus */
156 #define GST_ELEMENT_WARNING(el, domain, code, text, debug)              \
157 G_STMT_START {                                                          \
158   gchar *__txt = _gst_element_error_printf text;                        \
159   gchar *__dbg = _gst_element_error_printf debug;                       \
160   if (__txt)                                                            \
161     GST_WARNING_OBJECT (el, "%s", __txt);                               \
162   if (__dbg)                                                            \
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__);                      \
167 } G_STMT_END
168
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),\
177                                                                 timeval)
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));
180
181 typedef struct _GstElementFactory GstElementFactory;
182 typedef struct _GstElementFactoryClass GstElementFactoryClass;
183
184 struct _GstElement
185 {
186   GstObject             object;
187
188   /*< public >*/ /* with STATE_LOCK */
189   /* element state */
190   GMutex               *state_lock;
191   GCond                *state_cond;
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;
199   GstBus       *bus;
200   GstScheduler         *scheduler;
201   /* private pointer for the scheduler */
202   gpointer              sched_private;
203
204   /* allocated clock */
205   GstClock             *clock;
206   GstClockTimeDiff      base_time; /* NULL/READY: 0 - PAUSED: current time - PLAYING: difference to clock */
207
208   /* element pads, these lists can only be iterated while holding
209    * the LOCK or checking the cookie after each LOCK. */
210   guint16               numpads;
211   GList                *pads;
212   guint16               numsrcpads;
213   GList                *srcpads;
214   guint16               numsinkpads;
215   GList                *sinkpads;
216   guint32               pads_cookie;
217
218   /*< private >*/
219   gpointer _gst_reserved[GST_PADDING];
220 };
221
222 struct _GstElementClass
223 {
224   GstObjectClass         parent_class;
225
226   /*< public >*/
227   /* the element details */
228   GstElementDetails      details;
229
230   /* factory that the element was created from */
231   GstElementFactory     *elementfactory;
232
233   /* templates for our pads */
234   GList                 *padtemplates;
235   gint                   numpadtemplates;
236   guint32                pad_templ_cookie;
237
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);
243
244   /*< protected >*/
245   /* vtable */
246
247   /* request/release pads */
248   GstPad*               (*request_new_pad)      (GstElement *element, GstPadTemplate *templ, const gchar* name);
249   void                  (*release_pad)          (GstElement *element, GstPad *pad);
250
251   /* state changes */
252   GstElementStateReturn (*get_state)            (GstElement * element, GstElementState * state,
253                                                  GstElementState * pending, GTimeVal * timeout);
254   GstElementStateReturn (*change_state)         (GstElement *element);
255
256   /* manager */
257   void                  (*set_manager)          (GstElement * element, GstPipeline * pipeline);
258   void                  (*set_bus)              (GstElement * element, GstBus * bus);
259   void                  (*set_scheduler)        (GstElement *element, GstScheduler *scheduler);
260
261   /* set/get clocks */
262   GstClock*             (*get_clock)            (GstElement *element);
263   void                  (*set_clock)            (GstElement *element, GstClock *clock);
264
265   /* index */
266   GstIndex*             (*get_index)            (GstElement *element);
267   void                  (*set_index)            (GstElement *element, GstIndex *index);
268
269   /* query functions */
270   gboolean              (*send_event)           (GstElement *element, GstEvent *event);
271
272   const GstQueryType*   (*get_query_types)      (GstElement *element);
273   gboolean              (*query)                (GstElement *element, GstQuery *query);
274
275   /*< private >*/
276   gpointer _gst_reserved[GST_PADDING];
277 };
278
279 /* element class pad templates */
280 void                    gst_element_class_add_pad_template      (GstElementClass *klass, GstPadTemplate *templ);
281 GstPadTemplate*         gst_element_class_get_pad_template      (GstElementClass *element_class, const gchar *name);
282 GList*                  gst_element_class_get_pad_template_list (GstElementClass *element_class);
283 void                    gst_element_class_set_details           (GstElementClass *klass,
284                                                                  const GstElementDetails *details);
285
286 /* element instance */
287 GType                   gst_element_get_type            (void);
288
289 /* basic name and parentage stuff from GstObject */
290 #define                 gst_element_get_name(elem)      gst_object_get_name(GST_OBJECT(elem))
291 #define                 gst_element_set_name(elem,name) gst_object_set_name(GST_OBJECT(elem),name)
292 #define                 gst_element_get_parent(elem)    gst_object_get_parent(GST_OBJECT(elem))
293 #define                 gst_element_set_parent(elem,parent)     gst_object_set_parent(GST_OBJECT(elem),parent)
294
295 /* clocking */
296 gboolean                gst_element_requires_clock      (GstElement *element);
297 gboolean                gst_element_provides_clock      (GstElement *element);
298 GstClock*               gst_element_get_clock           (GstElement *element);
299 void                    gst_element_set_clock           (GstElement *element, GstClock *clock);
300
301 /* indexes */
302 gboolean                gst_element_is_indexable        (GstElement *element);
303 void                    gst_element_set_index           (GstElement *element, GstIndex *index);
304 GstIndex*               gst_element_get_index           (GstElement *element);
305
306 /* manager and tasks */
307 void                    gst_element_set_manager         (GstElement * element, GstPipeline * pipeline);
308 GstPipeline *           gst_element_get_manager         (GstElement * element);
309 void                    gst_element_set_bus             (GstElement * element, GstBus * bus);
310 GstBus *                gst_element_get_bus             (GstElement * element);
311 void                    gst_element_set_scheduler       (GstElement *element, GstScheduler *sched);
312 GstScheduler*           gst_element_get_scheduler       (GstElement *element);
313
314 /* pad management */
315 gboolean                gst_element_add_pad             (GstElement *element, GstPad *pad);
316 gboolean                gst_element_remove_pad          (GstElement *element, GstPad *pad);
317 GstPad *                gst_element_add_ghost_pad       (GstElement *element, GstPad *pad, const gchar *name);
318 void                    gst_element_no_more_pads        (GstElement *element);
319
320 GstPad*                 gst_element_get_pad             (GstElement *element, const gchar *name);
321 GstPad*                 gst_element_get_static_pad      (GstElement *element, const gchar *name);
322 GstPad*                 gst_element_get_request_pad     (GstElement *element, const gchar *name);
323 void                    gst_element_release_request_pad (GstElement *element, GstPad *pad);
324
325 GstIterator *           gst_element_iterate_pads        (GstElement * element);
326
327 /* event/query/format stuff */
328 gboolean                gst_element_send_event          (GstElement *element, GstEvent *event);
329 gboolean                gst_element_seek                (GstElement *element, GstSeekType seek_type,
330                                                          guint64 offset);
331 G_CONST_RETURN GstQueryType*
332                         gst_element_get_query_types     (GstElement *element);
333 gboolean                gst_element_query               (GstElement *element, GstQuery *query);
334
335 /* messages */
336 gboolean                gst_element_post_message        (GstElement * element, GstMessage * message);
337
338 /* error handling */
339 gchar *                 _gst_element_error_printf       (const gchar *format, ...);
340 void                    gst_element_message_full        (GstElement * element, GstMessageType type,
341                                                          GQuark domain, gint code, gchar * text, 
342                                                          gchar * debug, const gchar * file,
343                                                          const gchar * function, gint line);
344
345 /* state management */
346 gboolean                gst_element_is_locked_state     (GstElement *element);
347 gboolean                gst_element_set_locked_state    (GstElement *element, gboolean locked_state);
348 gboolean                gst_element_sync_state_with_parent (GstElement *element);
349
350 GstElementStateReturn   gst_element_get_state           (GstElement * element, 
351                                                          GstElementState * state,
352                                                          GstElementState * pending, 
353                                                          GTimeVal * timeout);
354 GstElementStateReturn   gst_element_set_state           (GstElement *element, GstElementState state);
355
356 void                    gst_element_abort_state         (GstElement * element);
357 void                    gst_element_commit_state        (GstElement * element);
358 void                    gst_element_lost_state          (GstElement * element);
359
360 /* factory management */
361 GstElementFactory*      gst_element_get_factory         (GstElement *element);
362
363 /*
364  *
365  * factories stuff
366  *
367  **/
368
369 #define GST_TYPE_ELEMENT_FACTORY                (gst_element_factory_get_type())
370 #define GST_ELEMENT_FACTORY(obj)                (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_ELEMENT_FACTORY,\
371                                                  GstElementFactory))
372 #define GST_ELEMENT_FACTORY_CLASS(klass)        (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_ELEMENT_FACTORY,\
373                                                  GstElementFactoryClass))
374 #define GST_IS_ELEMENT_FACTORY(obj)             (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_ELEMENT_FACTORY))
375 #define GST_IS_ELEMENT_FACTORY_CLASS(klass)     (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_ELEMENT_FACTORY))
376
377 struct _GstElementFactory {
378   GstPluginFeature      parent;
379
380   GType                 type;                   /* unique GType of element or 0 if not loaded */
381
382   GstElementDetails     details;
383
384   GList *               staticpadtemplates;
385   guint                 numpadtemplates;
386
387   /* URI interface stuff */
388   guint                 uri_type;
389   gchar **              uri_protocols;
390   
391   GList *               interfaces;             /* interfaces this element implements */
392
393   gpointer _gst_reserved[GST_PADDING];
394 };
395
396 struct _GstElementFactoryClass {
397   GstPluginFeatureClass parent_class;
398
399   gpointer _gst_reserved[GST_PADDING];
400 };
401
402 GType                   gst_element_factory_get_type            (void);
403
404 gboolean                gst_element_register                    (GstPlugin *plugin,
405                                                                  const gchar *name,
406                                                                  guint rank,
407                                                                  GType type);
408
409 GstElementFactory *     gst_element_factory_find                (const gchar *name);
410 GType                   gst_element_factory_get_element_type    (GstElementFactory *factory);
411 G_CONST_RETURN gchar *  gst_element_factory_get_longname        (GstElementFactory *factory);
412 G_CONST_RETURN gchar *  gst_element_factory_get_klass           (GstElementFactory *factory);
413 G_CONST_RETURN gchar *  gst_element_factory_get_description     (GstElementFactory *factory);
414 G_CONST_RETURN gchar *  gst_element_factory_get_author          (GstElementFactory *factory);
415 guint                   gst_element_factory_get_num_pad_templates (GstElementFactory *factory);
416 G_CONST_RETURN GList *  gst_element_factory_get_static_pad_templates (GstElementFactory *factory);
417 guint                   gst_element_factory_get_uri_type        (GstElementFactory *factory);           
418 gchar **                gst_element_factory_get_uri_protocols   (GstElementFactory *factory);           
419
420 GstElement*             gst_element_factory_create              (GstElementFactory *factory,
421                                                                  const gchar *name);
422 GstElement*             gst_element_factory_make                (const gchar *factoryname, const gchar *name);
423
424 void                    __gst_element_factory_add_static_pad_template (GstElementFactory *elementfactory,
425                                                                  GstStaticPadTemplate *templ);
426 void                    __gst_element_factory_add_interface     (GstElementFactory *elementfactory,
427                                                                  const gchar *interfacename);
428
429 G_END_DECLS
430
431 #endif /* __GST_ELEMENT_H__ */