Merge branch 'master' into 0.11
[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 /* gstelement.h and gstelementfactory.h include eachother */
28 typedef struct _GstElement GstElement;
29 typedef struct _GstElementClass GstElementClass;
30
31 /* gstmessage.h needs State */
32 /**
33  * GstState:
34  * @GST_STATE_VOID_PENDING: no pending state.
35  * @GST_STATE_NULL        : the NULL state or initial state of an element.
36  * @GST_STATE_READY       : the element is ready to go to PAUSED.
37  * @GST_STATE_PAUSED      : the element is PAUSED, it is ready to accept and
38  *                          process data. Sink elements however only accept one
39  *                          buffer and then block.
40  * @GST_STATE_PLAYING     : the element is PLAYING, the #GstClock is running and
41  *                          the data is flowing.
42  *
43  * The possible states an element can be in. States can be changed using
44  * gst_element_set_state() and checked using gst_element_get_state().
45  */
46 typedef enum {
47   GST_STATE_VOID_PENDING        = 0,
48   GST_STATE_NULL                = 1,
49   GST_STATE_READY               = 2,
50   GST_STATE_PAUSED              = 3,
51   GST_STATE_PLAYING             = 4
52 } GstState;
53
54
55 #include <gst/gstconfig.h>
56 #include <gst/gstobject.h>
57 #include <gst/gstpad.h>
58 #include <gst/gstbus.h>
59 #include <gst/gstclock.h>
60 #include <gst/gstelementfactory.h>
61 #include <gst/gstplugin.h>
62 #include <gst/gstpluginfeature.h>
63 #include <gst/gstindex.h>
64 #include <gst/gstindexfactory.h>
65 #include <gst/gstiterator.h>
66 #include <gst/gstmessage.h>
67 #include <gst/gstquery.h>
68 #include <gst/gsttaglist.h>
69
70 G_BEGIN_DECLS
71
72 #define GST_TYPE_ELEMENT                (gst_element_get_type ())
73 #define GST_IS_ELEMENT(obj)             (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_ELEMENT))
74 #define GST_IS_ELEMENT_CLASS(klass)     (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_ELEMENT))
75 #define GST_ELEMENT_GET_CLASS(obj)      (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_ELEMENT, GstElementClass))
76 #define GST_ELEMENT(obj)                (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_ELEMENT, GstElement))
77 #define GST_ELEMENT_CLASS(klass)        (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_ELEMENT, GstElementClass))
78 #define GST_ELEMENT_CAST(obj)           ((GstElement*)(obj))
79
80 /**
81  * GstStateChangeReturn:
82  * @GST_STATE_CHANGE_FAILURE   : the state change failed
83  * @GST_STATE_CHANGE_SUCCESS   : the state change succeeded
84  * @GST_STATE_CHANGE_ASYNC     : the state change will happen asynchronously
85  * @GST_STATE_CHANGE_NO_PREROLL: the state change succeeded but the element
86  *                               cannot produce data in %GST_STATE_PAUSED.
87  *                               This typically happens with live sources.
88  *
89  * The possible return values from a state change function such as 
90  * gst_element_set_state(). Only @GST_STATE_CHANGE_FAILURE is a real failure.
91  */
92 typedef enum {
93   GST_STATE_CHANGE_FAILURE             = 0,
94   GST_STATE_CHANGE_SUCCESS             = 1,
95   GST_STATE_CHANGE_ASYNC               = 2,
96   GST_STATE_CHANGE_NO_PREROLL          = 3
97 } GstStateChangeReturn;
98
99 /* NOTE: this probably should be done with an #ifdef to decide
100  * whether to safe-cast or to just do the non-checking cast.
101  */
102
103 /**
104  * GST_STATE:
105  * @elem: a #GstElement to return state for.
106  *
107  * This macro returns the current #GstState of the element.
108  */
109 #define GST_STATE(elem)                 (GST_ELEMENT_CAST(elem)->current_state)
110
111 /**
112  * GST_STATE_NEXT:
113  * @elem: a #GstElement to return the next state for.
114  *
115  * This macro returns the next #GstState of the element.
116  */
117 #define GST_STATE_NEXT(elem)            (GST_ELEMENT_CAST(elem)->next_state)
118
119 /**
120  * GST_STATE_PENDING:
121  * @elem: a #GstElement to return the pending state for.
122  *
123  * This macro returns the currently pending #GstState of the element.
124  */
125 #define GST_STATE_PENDING(elem)         (GST_ELEMENT_CAST(elem)->pending_state)
126
127 /**
128  * GST_STATE_TARGET:
129  * @elem: a #GstElement to return the target state for.
130  *
131  * This macro returns the target #GstState of the element.
132  *
133  * Since: 0.10.13
134  */
135 #define GST_STATE_TARGET(elem)          (GST_ELEMENT_CAST(elem)->target_state)
136
137 /**
138  * GST_STATE_RETURN:
139  * @elem: a #GstElement to return the last state result for.
140  *
141  * This macro returns the last #GstStateChangeReturn value.
142  */
143 #define GST_STATE_RETURN(elem)          (GST_ELEMENT_CAST(elem)->last_return)
144
145 #define __GST_SIGN(val)                 ((val) < 0 ? -1 : ((val) > 0 ? 1 : 0))
146 /**
147  * GST_STATE_GET_NEXT:
148  * @cur: A starting #GstState
149  * @pending: A target #GstState
150  *
151  * Given a current state @cur and a target state @pending, calculate the next (intermediate)
152  * #GstState.
153  */
154 #define GST_STATE_GET_NEXT(cur,pending)         ((GstState)((cur) + __GST_SIGN ((gint)(pending) - (gint)(cur))))
155 /**
156  * GST_STATE_TRANSITION:
157  * @cur: A current state
158  * @next: A next state
159  *
160  * Given a current state @cur and a next state @next, calculate the associated
161  * #GstStateChange transition.
162  */
163 #define GST_STATE_TRANSITION(cur,next)          ((GstStateChange)(((cur)<<3)|(next)))
164 /**
165  * GST_STATE_TRANSITION_CURRENT:
166  * @trans: A #GstStateChange
167  *
168  * Given a state transition @trans, extract the current #GstState.
169  */
170 #define GST_STATE_TRANSITION_CURRENT(trans)     ((GstState)((trans)>>3))
171 /**
172  * GST_STATE_TRANSITION_NEXT:
173  * @trans: A #GstStateChange
174  *
175  * Given a state transition @trans, extract the next #GstState.
176  */
177 #define GST_STATE_TRANSITION_NEXT(trans)        ((GstState)((trans)&0x7))
178
179 /**
180  * GstStateChange:
181  * @GST_STATE_CHANGE_NULL_TO_READY    : state change from NULL to READY.
182  * <itemizedlist>
183  *   <listitem><para>
184  *     The element must check if the resources it needs are available. Device
185  *     sinks and -sources typically try to probe the device to constrain their
186  *     caps.
187  *   </para></listitem>
188  *   <listitem><para>
189  *     The element opens the device (in case feature need to be probed).
190  *   </para></listitem>
191  * </itemizedlist>
192  * @GST_STATE_CHANGE_READY_TO_PAUSED  : state change from READY to PAUSED.
193  * <itemizedlist>
194  *   <listitem><para>
195  *     The element pads are activated in order to receive data in PAUSED.
196  *     Streaming threads are started.
197  *   </para></listitem>
198  *   <listitem><para>
199  *     Some elements might need to return %GST_STATE_CHANGE_ASYNC and complete
200  *     the state change when they have enough information. It is a requirement
201  *     for sinks to return %GST_STATE_CHANGE_ASYNC and complete the state change
202  *     when they receive the first buffer or %GST_EVENT_EOS (preroll).
203  *     Sinks also block the dataflow when in PAUSED.
204  *   </para></listitem>
205  *   <listitem><para>
206  *     A pipeline resets the running_time to 0.
207  *   </para></listitem>
208  *   <listitem><para>
209  *     Live sources return %GST_STATE_CHANGE_NO_PREROLL and don't generate data.
210  *   </para></listitem>
211  * </itemizedlist>
212  * @GST_STATE_CHANGE_PAUSED_TO_PLAYING: state change from PAUSED to PLAYING.
213  * <itemizedlist>
214  *   <listitem><para>
215  *     Most elements ignore this state change.
216  *   </para></listitem>
217  *   <listitem><para>
218  *     The pipeline selects a #GstClock and distributes this to all the children
219  *     before setting them to PLAYING. This means that it is only alowed to
220  *     synchronize on the #GstClock in the PLAYING state.
221  *   </para></listitem>
222  *   <listitem><para>
223  *     The pipeline uses the #GstClock and the running_time to calculate the
224  *     base_time. The base_time is distributed to all children when performing
225  *     the state change.
226  *   </para></listitem>
227  *   <listitem><para>
228  *     Sink elements stop blocking on the preroll buffer or event and start
229  *     rendering the data.
230  *   </para></listitem>
231  *   <listitem><para>
232  *     Sinks can post %GST_MESSAGE_EOS in the PLAYING state. It is not allowed
233  *     to post %GST_MESSAGE_EOS when not in the PLAYING state.
234  *   </para></listitem>
235  *   <listitem><para>
236  *     While streaming in PAUSED or PLAYING elements can create and remove
237  *     sometimes pads.
238  *   </para></listitem>
239  *   <listitem><para>
240  *     Live sources start generating data and return %GST_STATE_CHANGE_SUCCESS.
241  *   </para></listitem>
242  * </itemizedlist>
243  * @GST_STATE_CHANGE_PLAYING_TO_PAUSED: state change from PLAYING to PAUSED.
244  * <itemizedlist>
245  *   <listitem><para>
246  *     Most elements ignore this state change.
247  *   </para></listitem>
248  *   <listitem><para>
249  *     The pipeline calculates the running_time based on the last selected
250  *     #GstClock and the base_time. It stores this information to continue
251  *     playback when going back to the PLAYING state.
252  *   </para></listitem>
253  *   <listitem><para>
254  *     Sinks unblock any #GstClock wait calls.
255  *   </para></listitem>
256  *   <listitem><para>
257  *     When a sink does not have a pending buffer to play, it returns 
258  *     %GST_STATE_CHANGE_ASYNC from this state change and completes the state
259  *     change when it receives a new buffer or an %GST_EVENT_EOS.
260  *   </para></listitem>
261  *   <listitem><para>
262  *     Any queued %GST_MESSAGE_EOS items are removed since they will be reposted
263  *     when going back to the PLAYING state. The EOS messages are queued in
264  *     #GstBin containers.
265  *   </para></listitem>
266  *   <listitem><para>
267  *     Live sources stop generating data and return %GST_STATE_CHANGE_NO_PREROLL.
268  *   </para></listitem>
269  * </itemizedlist>
270  * @GST_STATE_CHANGE_PAUSED_TO_READY  : state change from PAUSED to READY.
271  * <itemizedlist>
272  *   <listitem><para>
273  *     Sinks unblock any waits in the preroll.
274  *   </para></listitem>
275  *   <listitem><para>
276  *     Elements unblock any waits on devices
277  *   </para></listitem>
278  *   <listitem><para>
279  *     Chain or get_range functions return %GST_FLOW_WRONG_STATE.
280  *   </para></listitem>
281  *   <listitem><para>
282  *     The element pads are deactivated so that streaming becomes impossible and
283  *     all streaming threads are stopped.
284  *   </para></listitem>
285  *   <listitem><para>
286  *     The sink forgets all negotiated formats
287  *   </para></listitem>
288  *   <listitem><para>
289  *     Elements remove all sometimes pads
290  *   </para></listitem>
291  * </itemizedlist>
292  * @GST_STATE_CHANGE_READY_TO_NULL    : state change from READY to NULL.
293  * <itemizedlist>
294  *   <listitem><para>
295  *     Elements close devices
296  *   </para></listitem>
297  *   <listitem><para>
298  *     Elements reset any internal state.
299  *   </para></listitem>
300  * </itemizedlist>
301  *
302  * These are the different state changes an element goes through.
303  * %GST_STATE_NULL &rArr; %GST_STATE_PLAYING is called an upwards state change
304  * and %GST_STATE_PLAYING &rArr; %GST_STATE_NULL a downwards state change.
305  */
306 typedef enum /*< flags=0 >*/
307 {
308   GST_STATE_CHANGE_NULL_TO_READY        = (GST_STATE_NULL<<3) | GST_STATE_READY,
309   GST_STATE_CHANGE_READY_TO_PAUSED      = (GST_STATE_READY<<3) | GST_STATE_PAUSED,
310   GST_STATE_CHANGE_PAUSED_TO_PLAYING    = (GST_STATE_PAUSED<<3) | GST_STATE_PLAYING,
311   GST_STATE_CHANGE_PLAYING_TO_PAUSED    = (GST_STATE_PLAYING<<3) | GST_STATE_PAUSED,
312   GST_STATE_CHANGE_PAUSED_TO_READY      = (GST_STATE_PAUSED<<3) | GST_STATE_READY,
313   GST_STATE_CHANGE_READY_TO_NULL        = (GST_STATE_READY<<3) | GST_STATE_NULL
314 } GstStateChange;
315
316 /**
317  * GstElementFlags:
318  * @GST_ELEMENT_LOCKED_STATE: ignore state changes from parent
319  * @GST_ELEMENT_IS_SINK: the element is a sink
320  * @GST_ELEMENT_UNPARENTING: Child is being removed from the parent bin.
321  *  gst_bin_remove() on a child already being removed immediately returns FALSE
322  * @GST_ELEMENT_IS_SOURCE: the element is a source. Since 0.10.31
323  * @GST_ELEMENT_FLAG_LAST: offset to define more flags
324  *
325  * The standard flags that an element may have.
326  */
327 typedef enum
328 {
329   GST_ELEMENT_LOCKED_STATE      = (GST_OBJECT_FLAG_LAST << 0),
330   GST_ELEMENT_IS_SINK           = (GST_OBJECT_FLAG_LAST << 1),
331   GST_ELEMENT_UNPARENTING       = (GST_OBJECT_FLAG_LAST << 2),
332   GST_ELEMENT_IS_SOURCE         = (GST_OBJECT_FLAG_LAST << 3),
333   /* padding */
334   GST_ELEMENT_FLAG_LAST         = (GST_OBJECT_FLAG_LAST << 16)
335 } GstElementFlags;
336
337 /**
338  * GST_ELEMENT_IS_LOCKED_STATE:
339  * @elem: A #GstElement to query
340  *
341  * Check if the element is in the locked state and therefore will ignore state
342  * changes from its parent object.
343  */
344 #define GST_ELEMENT_IS_LOCKED_STATE(elem)        (GST_OBJECT_FLAG_IS_SET(elem,GST_ELEMENT_LOCKED_STATE))
345
346 /**
347  * GST_ELEMENT_NAME:
348  * @elem: A #GstElement to query
349  *
350  * Gets the name of this element. Use only in core as this is not
351  * ABI-compatible. Others use gst_element_get_name()
352  */
353 #define GST_ELEMENT_NAME(elem)                  (GST_OBJECT_NAME(elem))
354
355 /**
356  * GST_ELEMENT_PARENT:
357  * @elem: A #GstElement to query
358  *
359  * Get the parent object of this element.
360  */
361 #define GST_ELEMENT_PARENT(elem)                (GST_ELEMENT_CAST(GST_OBJECT_PARENT(elem)))
362
363 /**
364  * GST_ELEMENT_BUS:
365  * @elem: A #GstElement to query
366  *
367  * Get the message bus of this element.
368  */
369 #define GST_ELEMENT_BUS(elem)                   (GST_ELEMENT_CAST(elem)->bus)
370
371 /**
372  * GST_ELEMENT_CLOCK:
373  * @elem: A #GstElement to query
374  *
375  * Get the clock of this element
376  */
377 #define GST_ELEMENT_CLOCK(elem)                 (GST_ELEMENT_CAST(elem)->clock)
378
379 /**
380  * GST_ELEMENT_PADS:
381  * @elem: A #GstElement to query
382  *
383  * Get the pads of this elements.
384  */
385 #define GST_ELEMENT_PADS(elem)                  (GST_ELEMENT_CAST(elem)->pads)
386
387 /**
388  * GST_ELEMENT_START_TIME:
389  * @elem: a #GstElement to return the start time for.
390  *
391  * This macro returns the start_time of the @elem. The start_time is the
392  * running_time of the pipeline when the element went to PAUSED.
393  *
394  * Since: 0.10.24
395  */
396 #define GST_ELEMENT_START_TIME(elem)            (GST_ELEMENT_CAST(elem)->start_time)
397
398 /**
399  * GST_ELEMENT_ERROR:
400  * @el:     the element that generates the error
401  * @domain: like CORE, LIBRARY, RESOURCE or STREAM (see #gstreamer-GstGError)
402  * @code:   error code defined for that domain (see #gstreamer-GstGError)
403  * @text:   the message to display (format string and args enclosed in
404             parentheses)
405  * @debug:  debugging information for the message (format string and args
406             enclosed in parentheses)
407  *
408  * Utility function that elements can use in case they encountered a fatal
409  * data processing error. The pipeline will post an error message and the
410  * application will be requested to stop further media processing.
411  */
412 #define GST_ELEMENT_ERROR(el, domain, code, text, debug)                \
413 G_STMT_START {                                                          \
414   gchar *__txt = _gst_element_error_printf text;                        \
415   gchar *__dbg = _gst_element_error_printf debug;                       \
416   if (__txt)                                                            \
417     GST_WARNING_OBJECT (el, "error: %s", __txt);                        \
418   if (__dbg)                                                            \
419     GST_WARNING_OBJECT (el, "error: %s", __dbg);                        \
420   gst_element_message_full (GST_ELEMENT(el), GST_MESSAGE_ERROR,         \
421     GST_ ## domain ## _ERROR, GST_ ## domain ## _ERROR_ ## code,        \
422     __txt, __dbg, __FILE__, GST_FUNCTION, __LINE__);                    \
423 } G_STMT_END
424
425 /**
426  * GST_ELEMENT_WARNING:
427  * @el:     the element that generates the warning
428  * @domain: like CORE, LIBRARY, RESOURCE or STREAM (see #gstreamer-GstGError)
429  * @code:   error code defined for that domain (see #gstreamer-GstGError)
430  * @text:   the message to display (format string and args enclosed in
431             parentheses)
432  * @debug:  debugging information for the message (format string and args
433             enclosed in parentheses)
434  *
435  * Utility function that elements can use in case they encountered a non-fatal
436  * data processing problem. The pipeline will post a warning message and the
437  * application will be informed.
438  */
439 #define GST_ELEMENT_WARNING(el, domain, code, text, debug)              \
440 G_STMT_START {                                                          \
441   gchar *__txt = _gst_element_error_printf text;                        \
442   gchar *__dbg = _gst_element_error_printf debug;                       \
443   if (__txt)                                                            \
444     GST_WARNING_OBJECT (el, "warning: %s", __txt);                      \
445   if (__dbg)                                                            \
446     GST_WARNING_OBJECT (el, "warning: %s", __dbg);                      \
447   gst_element_message_full (GST_ELEMENT(el), GST_MESSAGE_WARNING,       \
448     GST_ ## domain ## _ERROR, GST_ ## domain ## _ERROR_ ## code,        \
449   __txt, __dbg, __FILE__, GST_FUNCTION, __LINE__);                      \
450 } G_STMT_END
451
452 /**
453  * GST_ELEMENT_INFO:
454  * @el:     the element that generates the information
455  * @domain: like CORE, LIBRARY, RESOURCE or STREAM (see #gstreamer-GstGError)
456  * @code:   error code defined for that domain (see #gstreamer-GstGError)
457  * @text:   the message to display (format string and args enclosed in
458             parentheses)
459  * @debug:  debugging information for the message (format string and args
460             enclosed in parentheses)
461  *
462  * Utility function that elements can use in case they want to inform
463  * the application of something noteworthy that is not an error.
464  * The pipeline will post a info message and the
465  * application will be informed.
466  *
467  * Since: 0.10.12
468  */
469 #define GST_ELEMENT_INFO(el, domain, code, text, debug)                 \
470 G_STMT_START {                                                          \
471   gchar *__txt = _gst_element_error_printf text;                        \
472   gchar *__dbg = _gst_element_error_printf debug;                       \
473   if (__txt)                                                            \
474     GST_INFO_OBJECT (el, "info: %s", __txt);                            \
475   if (__dbg)                                                            \
476     GST_INFO_OBJECT (el, "info: %s", __dbg);                            \
477   gst_element_message_full (GST_ELEMENT(el), GST_MESSAGE_INFO,          \
478     GST_ ## domain ## _ERROR, GST_ ## domain ## _ERROR_ ## code,        \
479   __txt, __dbg, __FILE__, GST_FUNCTION, __LINE__);                      \
480 } G_STMT_END
481
482 /* the state change mutexes and conds */
483 /**
484  * GST_STATE_GET_LOCK:
485  * @elem:   a #GstElement
486  *
487  * Get a reference to the state lock of @elem.
488  * This lock is used by the core.  It is taken while getting or setting
489  * the state, during state changes, and while finalizing.
490  */
491 #define GST_STATE_GET_LOCK(elem)               (&(GST_ELEMENT_CAST(elem)->state_lock))
492 /**
493  * GST_STATE_GET_COND:
494  * @elem: a #GstElement
495  *
496  * Get the conditional used to signal the completion of a state change.
497  */
498 #define GST_STATE_GET_COND(elem)               (GST_ELEMENT_CAST(elem)->state_cond)
499
500 #define GST_STATE_LOCK(elem)                   g_static_rec_mutex_lock(GST_STATE_GET_LOCK(elem))
501 #define GST_STATE_TRYLOCK(elem)                g_static_rec_mutex_trylock(GST_STATE_GET_LOCK(elem))
502 #define GST_STATE_UNLOCK(elem)                 g_static_rec_mutex_unlock(GST_STATE_GET_LOCK(elem))
503 #define GST_STATE_UNLOCK_FULL(elem)            g_static_rec_mutex_unlock_full(GST_STATE_GET_LOCK(elem))
504 #define GST_STATE_LOCK_FULL(elem,t)            g_static_rec_mutex_lock_full(GST_STATE_GET_LOCK(elem), t)
505 #define GST_STATE_WAIT(elem)                   g_cond_wait (GST_STATE_GET_COND (elem), \
506                                                         GST_OBJECT_GET_LOCK (elem))
507 #define GST_STATE_TIMED_WAIT(elem, timeval)    g_cond_timed_wait (GST_STATE_GET_COND (elem), \
508                                                         GST_OBJECT_GET_LOCK (elem), timeval)
509 #define GST_STATE_SIGNAL(elem)                 g_cond_signal (GST_STATE_GET_COND (elem));
510 #define GST_STATE_BROADCAST(elem)              g_cond_broadcast (GST_STATE_GET_COND (elem));
511
512 /**
513  * GstElement:
514  * @state_lock: Used to serialize execution of gst_element_set_state()
515  * @state_cond: Used to signal completion of a state change
516  * @state_cookie: Used to detect concurrent execution of
517  * gst_element_set_state() and gst_element_get_state()
518  * @target_state: the target state of an element as set by the application
519  * @current_state: the current state of an element
520  * @next_state: the next state of an element, can be #GST_STATE_VOID_PENDING if
521  * the element is in the correct state.
522  * @pending_state: the final state the element should go to, can be
523  * #GST_STATE_VOID_PENDING if the element is in the correct state
524  * @last_return: the last return value of an element state change
525  * @bus: the bus of the element. This bus is provided to the element by the
526  * parent element or the application. A #GstPipeline has a bus of its own.
527  * @clock: the clock of the element. This clock is usually provided to the
528  * element by the toplevel #GstPipeline.
529  * @base_time: the time of the clock right before the element is set to
530  * PLAYING. Subtracting @base_time from the current clock time in the PLAYING
531  * state will yield the running_time against the clock.
532  * @start_time: the running_time of the last PAUSED state
533  * @numpads: number of pads of the element, includes both source and sink pads.
534  * @pads: list of pads
535  * @numsrcpads: number of source pads of the element.
536  * @srcpads: list of source pads
537  * @numsinkpads: number of sink pads of the element.
538  * @sinkpads: list of sink pads
539  * @pads_cookie: updated whenever the a pad is added or removed
540  *
541  * GStreamer element abstract base class.
542  */
543 struct _GstElement
544 {
545   GstObject             object;
546
547   /*< public >*/ /* with LOCK */
548   GStaticRecMutex       state_lock;
549
550   /* element state */
551   GCond                *state_cond;
552   guint32               state_cookie;
553   GstState              target_state;
554   GstState              current_state;
555   GstState              next_state;
556   GstState              pending_state;
557   GstStateChangeReturn  last_return;
558
559   GstBus               *bus;
560
561   /* allocated clock */
562   GstClock             *clock;
563   GstClockTimeDiff      base_time; /* NULL/READY: 0 - PAUSED: current time - PLAYING: difference to clock */
564   GstClockTime          start_time;
565
566   /* element pads, these lists can only be iterated while holding
567    * the LOCK or checking the cookie after each LOCK. */
568   guint16               numpads;
569   GList                *pads;
570   guint16               numsrcpads;
571   GList                *srcpads;
572   guint16               numsinkpads;
573   GList                *sinkpads;
574   guint32               pads_cookie;
575
576   /*< private >*/
577   gpointer _gst_reserved[GST_PADDING];
578 };
579
580 /**
581  * GstElementClass:
582  * @parent_class: the parent class structure
583  * @metadata: metadata for elements of this class
584  * @elementfactory: the #GstElementFactory that creates these elements
585  * @padtemplates: a #GList of #GstPadTemplate
586  * @numpadtemplates: the number of padtemplates
587  * @pad_templ_cookie: changed whenever the padtemplates change
588  * @request_new_pad: called when a new pad is requested
589  * @release_pad: called when a request pad is to be released
590  * @get_state: get the state of the element
591  * @set_state: set a new state on the element
592  * @change_state: called by @set_state to perform an incremental state change
593  * @set_bus: set a #GstBus on the element
594  * @provide_clock: gets the #GstClock provided by the element
595  * @set_clock: set the #GstClock on the element
596  * @get_index: set a #GstIndex on the element
597  * @set_index: get the #GstIndex of an element
598  * @send_event: send a #GstEvent to the element
599  * @get_query_types: get the supported #GstQueryType of this element
600  * @query: perform a #GstQuery on the element
601  * @state_changed: called immediately after a new state was set.
602  *
603  * GStreamer element class. Override the vmethods to implement the element
604  * functionality.
605  */
606 struct _GstElementClass
607 {
608   GstObjectClass         parent_class;
609
610   /*< public >*/
611   /* the element metadata */
612   gpointer               metadata;
613
614   /* factory that the element was created from */
615   GstElementFactory     *elementfactory;
616
617   /* templates for our pads */
618   GList                 *padtemplates;
619   gint                   numpadtemplates;
620   guint32                pad_templ_cookie;
621
622   /*< private >*/
623   /* signal callbacks */
624   void (*pad_added)     (GstElement *element, GstPad *pad);
625   void (*pad_removed)   (GstElement *element, GstPad *pad);
626   void (*no_more_pads)  (GstElement *element);
627
628   /*< public >*/
629   /* virtual methods for subclasses */
630
631   /* request/release pads */
632   GstPad*               (*request_new_pad)      (GstElement *element, GstPadTemplate *templ,
633                                                  const gchar* name, const GstCaps *caps);
634   void                  (*release_pad)          (GstElement *element, GstPad *pad);
635
636   /* state changes */
637   GstStateChangeReturn (*get_state)             (GstElement * element, GstState * state,
638                                                  GstState * pending, GstClockTime timeout);
639   GstStateChangeReturn (*set_state)             (GstElement *element, GstState state);
640   GstStateChangeReturn (*change_state)          (GstElement *element, GstStateChange transition);
641   void                 (*state_changed)         (GstElement *element, GstState oldstate,
642                                                  GstState newstate, GstState pending);
643
644   /* bus */
645   void                  (*set_bus)              (GstElement * element, GstBus * bus);
646
647   /* set/get clocks */
648   GstClock*             (*provide_clock)        (GstElement *element);
649   gboolean              (*set_clock)            (GstElement *element, GstClock *clock);
650
651   /* index */
652   GstIndex*             (*get_index)            (GstElement *element);
653   void                  (*set_index)            (GstElement *element, GstIndex *index);
654
655   /* query functions */
656   gboolean              (*send_event)           (GstElement *element, GstEvent *event);
657
658   const GstQueryType*   (*get_query_types)      (GstElement *element);
659   gboolean              (*query)                (GstElement *element, GstQuery *query);
660
661   /*< private >*/
662   gpointer _gst_reserved[GST_PADDING];
663 };
664
665 /* element class pad templates */
666 void                    gst_element_class_add_pad_template      (GstElementClass *klass, GstPadTemplate *templ);
667 GstPadTemplate*         gst_element_class_get_pad_template      (GstElementClass *element_class, const gchar *name);
668 GList*                  gst_element_class_get_pad_template_list (GstElementClass *element_class);
669
670 /* element class meta data */
671 void                    gst_element_class_set_metadata          (GstElementClass *klass,
672                                                                  const gchar     *longname,
673                                                                  const gchar     *classification,
674                                                                  const gchar     *description,
675                                                                  const gchar     *author);
676 void                    gst_element_class_add_metadata          (GstElementClass * klass,
677                                                                  const gchar * key, const gchar * value);
678 const gchar          *  gst_element_class_get_metadata          (GstElementClass * klass,
679                                                                  const gchar * key);
680
681
682 /* element instance */
683 GType                   gst_element_get_type            (void);
684
685 /* basic name and parentage stuff from GstObject */
686
687 /**
688  * gst_element_get_name:
689  * @elem: a #GstElement to get the name of @elem.
690  *
691  * Returns a copy of the name of @elem.
692  * Caller should g_free() the return value after usage.
693  * For a nameless element, this returns NULL, which you can safely g_free()
694  * as well.
695  *
696  * Returns: (transfer full): the name of @elem. g_free() after usage. MT safe.
697  *
698  */
699 #define                 gst_element_get_name(elem)      gst_object_get_name(GST_OBJECT_CAST(elem))
700
701 /**
702  * gst_element_set_name:
703  * @elem: a #GstElement to set the name of.
704  * @name: the new name
705  *
706  * Sets the name of the element, getting rid of the old name if there was one.
707  */
708 #define                 gst_element_set_name(elem,name) gst_object_set_name(GST_OBJECT_CAST(elem),name)
709
710 /**
711  * gst_element_get_parent:
712  * @elem: a #GstElement to get the parent of.
713  *
714  * Get the parent of an element.
715  *
716  * Returns: (transfer full): the parent of an element.
717  */
718 #define                 gst_element_get_parent(elem)    gst_object_get_parent(GST_OBJECT_CAST(elem))
719
720 /**
721  * gst_element_set_parent:
722  * @elem: a #GstElement to set the parent of.
723  * @parent: the new parent #GstObject of the element.
724  *
725  * Sets the parent of an element.
726  */
727 #define                 gst_element_set_parent(elem,parent)     gst_object_set_parent(GST_OBJECT_CAST(elem),parent)
728
729 /* clocking */
730 gboolean                gst_element_requires_clock      (GstElement *element);
731 gboolean                gst_element_provides_clock      (GstElement *element);
732 GstClock*               gst_element_provide_clock       (GstElement *element);
733 GstClock*               gst_element_get_clock           (GstElement *element);
734 gboolean                gst_element_set_clock           (GstElement *element, GstClock *clock);
735 void                    gst_element_set_base_time       (GstElement *element, GstClockTime time);
736 GstClockTime            gst_element_get_base_time       (GstElement *element);
737 void                    gst_element_set_start_time      (GstElement *element, GstClockTime time);
738 GstClockTime            gst_element_get_start_time      (GstElement *element);
739
740 /* indexes */
741 gboolean                gst_element_is_indexable        (GstElement *element);
742 void                    gst_element_set_index           (GstElement *element, GstIndex *index);
743 GstIndex*               gst_element_get_index           (GstElement *element);
744
745 /* bus */
746 void                    gst_element_set_bus             (GstElement * element, GstBus * bus);
747 GstBus *                gst_element_get_bus             (GstElement * element);
748
749 /* pad management */
750 gboolean                gst_element_add_pad             (GstElement *element, GstPad *pad);
751 gboolean                gst_element_remove_pad          (GstElement *element, GstPad *pad);
752 void                    gst_element_no_more_pads        (GstElement *element);
753
754 GstPad*                 gst_element_get_static_pad      (GstElement *element, const gchar *name);
755 GstPad*                 gst_element_get_request_pad     (GstElement *element, const gchar *name);
756 GstPad*                 gst_element_request_pad         (GstElement *element, GstPadTemplate *templ,
757                                                          const gchar * name, const GstCaps *caps);
758 void                    gst_element_release_request_pad (GstElement *element, GstPad *pad);
759
760 GstIterator *           gst_element_iterate_pads        (GstElement * element);
761 GstIterator *           gst_element_iterate_src_pads    (GstElement * element);
762 GstIterator *           gst_element_iterate_sink_pads   (GstElement * element);
763
764 /* event/query/format stuff */
765 gboolean                gst_element_send_event          (GstElement *element, GstEvent *event);
766 gboolean                gst_element_seek                (GstElement *element, gdouble rate,
767                                                          GstFormat format, GstSeekFlags flags,
768                                                          GstSeekType cur_type, gint64 cur,
769                                                          GstSeekType stop_type, gint64 stop);
770 gboolean                gst_element_query               (GstElement *element, GstQuery *query);
771
772 /* messages */
773 gboolean                gst_element_post_message        (GstElement * element, GstMessage * message);
774
775 /* error handling */
776 /* gcc versions < 3.3 warn about NULL being passed as format to printf */
777 #if (defined(GST_USING_PRINTF_EXTENSION) || !defined(__GNUC__) || (__GNUC__ < 3) || (__GNUC__ == 3 && __GNUC_MINOR__ < 3))
778 gchar *                 _gst_element_error_printf       (const gchar *format, ...);
779 #else
780 gchar *                 _gst_element_error_printf       (const gchar *format, ...) G_GNUC_PRINTF (1, 2);
781 #endif
782 void                    gst_element_message_full        (GstElement * element, GstMessageType type,
783                                                          GQuark domain, gint code, gchar * text,
784                                                          gchar * debug, const gchar * file,
785                                                          const gchar * function, gint line);
786
787 /* state management */
788 gboolean                gst_element_is_locked_state     (GstElement *element);
789 gboolean                gst_element_set_locked_state    (GstElement *element, gboolean locked_state);
790 gboolean                gst_element_sync_state_with_parent (GstElement *element);
791
792 GstStateChangeReturn    gst_element_get_state           (GstElement * element,
793                                                          GstState * state,
794                                                          GstState * pending,
795                                                          GstClockTime timeout);
796 GstStateChangeReturn    gst_element_set_state           (GstElement *element, GstState state);
797
798 void                    gst_element_abort_state         (GstElement * element);
799 GstStateChangeReturn    gst_element_change_state        (GstElement * element,
800                                                          GstStateChange transition);
801 GstStateChangeReturn    gst_element_continue_state      (GstElement * element,
802                                                          GstStateChangeReturn ret);
803 void                    gst_element_lost_state          (GstElement * element);
804
805 /* factory management */
806 GstElementFactory*      gst_element_get_factory         (GstElement *element);
807
808 G_END_DECLS
809
810 #endif /* __GST_ELEMENT_H__ */