ed9bf64521c4f508db2b8bb188a45bd923996690
[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., 51 Franklin St, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  */
22
23
24 #ifndef __GST_ELEMENT_H__
25 #define __GST_ELEMENT_H__
26
27 #include <glib.h>
28
29 G_BEGIN_DECLS
30
31 /* gstelement.h and gstelementfactory.h include eachother */
32 typedef struct _GstElement GstElement;
33 typedef struct _GstElementClass GstElementClass;
34
35 /* gstmessage.h needs State */
36 /**
37  * GstState:
38  * @GST_STATE_VOID_PENDING: no pending state.
39  * @GST_STATE_NULL        : the NULL state or initial state of an element.
40  * @GST_STATE_READY       : the element is ready to go to PAUSED.
41  * @GST_STATE_PAUSED      : the element is PAUSED, it is ready to accept and
42  *                          process data. Sink elements however only accept one
43  *                          buffer and then block.
44  * @GST_STATE_PLAYING     : the element is PLAYING, the #GstClock is running and
45  *                          the data is flowing.
46  *
47  * The possible states an element can be in. States can be changed using
48  * gst_element_set_state() and checked using gst_element_get_state().
49  */
50 typedef enum {
51   GST_STATE_VOID_PENDING        = 0,
52   GST_STATE_NULL                = 1,
53   GST_STATE_READY               = 2,
54   GST_STATE_PAUSED              = 3,
55   GST_STATE_PLAYING             = 4
56 } GstState;
57
58 #define GST_TYPE_ELEMENT                (gst_element_get_type ())
59 #define GST_IS_ELEMENT(obj)             (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_ELEMENT))
60 #define GST_IS_ELEMENT_CLASS(klass)     (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_ELEMENT))
61 #define GST_ELEMENT_GET_CLASS(obj)      (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_ELEMENT, GstElementClass))
62 #define GST_ELEMENT(obj)                (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_ELEMENT, GstElement))
63 #define GST_ELEMENT_CLASS(klass)        (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_ELEMENT, GstElementClass))
64 #define GST_ELEMENT_CAST(obj)           ((GstElement*)(obj))
65
66 /**
67  * GstStateChangeReturn:
68  * @GST_STATE_CHANGE_FAILURE   : the state change failed
69  * @GST_STATE_CHANGE_SUCCESS   : the state change succeeded
70  * @GST_STATE_CHANGE_ASYNC     : the state change will happen asynchronously
71  * @GST_STATE_CHANGE_NO_PREROLL: the state change succeeded but the element
72  *                               cannot produce data in %GST_STATE_PAUSED.
73  *                               This typically happens with live sources.
74  *
75  * The possible return values from a state change function such as
76  * gst_element_set_state(). Only @GST_STATE_CHANGE_FAILURE is a real failure.
77  */
78 typedef enum {
79   GST_STATE_CHANGE_FAILURE             = 0,
80   GST_STATE_CHANGE_SUCCESS             = 1,
81   GST_STATE_CHANGE_ASYNC               = 2,
82   GST_STATE_CHANGE_NO_PREROLL          = 3
83 } GstStateChangeReturn;
84
85 #include <gst/gstconfig.h>
86 #include <gst/gstobject.h>
87 #include <gst/gstpad.h>
88 #include <gst/gstbus.h>
89 #include <gst/gstclock.h>
90 #include <gst/gstelementfactory.h>
91 #include <gst/gstplugin.h>
92 #include <gst/gstpluginfeature.h>
93 #include <gst/gstiterator.h>
94 #include <gst/gstmessage.h>
95 #include <gst/gstquery.h>
96 #include <gst/gsttaglist.h>
97 #include <gst/gstcontext.h>
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 #define GST_STATE_TARGET(elem)          (GST_ELEMENT_CAST(elem)->target_state)
134
135 /**
136  * GST_STATE_RETURN:
137  * @elem: a #GstElement to return the last state result for.
138  *
139  * This macro returns the last #GstStateChangeReturn value.
140  */
141 #define GST_STATE_RETURN(elem)          (GST_ELEMENT_CAST(elem)->last_return)
142
143 #define __GST_SIGN(val)                 ((val) < 0 ? -1 : ((val) > 0 ? 1 : 0))
144 /**
145  * GST_STATE_GET_NEXT:
146  * @cur: A starting #GstState
147  * @pending: A target #GstState
148  *
149  * Given a current state @cur and a target state @pending, calculate the next (intermediate)
150  * #GstState.
151  */
152 #define GST_STATE_GET_NEXT(cur,pending)         ((GstState)((cur) + __GST_SIGN ((gint)(pending) - (gint)(cur))))
153 /**
154  * GST_STATE_TRANSITION:
155  * @cur: A current state
156  * @next: A next state
157  *
158  * Given a current state @cur and a next state @next, calculate the associated
159  * #GstStateChange transition.
160  */
161 #define GST_STATE_TRANSITION(cur,next)          ((GstStateChange)(((cur)<<3)|(next)))
162 /**
163  * GST_STATE_TRANSITION_CURRENT:
164  * @trans: A #GstStateChange
165  *
166  * Given a state transition @trans, extract the current #GstState.
167  */
168 #define GST_STATE_TRANSITION_CURRENT(trans)     ((GstState)((trans)>>3))
169 /**
170  * GST_STATE_TRANSITION_NEXT:
171  * @trans: A #GstStateChange
172  *
173  * Given a state transition @trans, extract the next #GstState.
174  */
175 #define GST_STATE_TRANSITION_NEXT(trans)        ((GstState)((trans)&0x7))
176
177 /**
178  * GstStateChange:
179  * @GST_STATE_CHANGE_NULL_TO_READY    : state change from NULL to READY.
180  * <itemizedlist>
181  *   <listitem><para>
182  *     The element must check if the resources it needs are available. Device
183  *     sinks and -sources typically try to probe the device to constrain their
184  *     caps.
185  *   </para></listitem>
186  *   <listitem><para>
187  *     The element opens the device (in case feature need to be probed).
188  *   </para></listitem>
189  * </itemizedlist>
190  * @GST_STATE_CHANGE_READY_TO_PAUSED  : state change from READY to PAUSED.
191  * <itemizedlist>
192  *   <listitem><para>
193  *     The element pads are activated in order to receive data in PAUSED.
194  *     Streaming threads are started.
195  *   </para></listitem>
196  *   <listitem><para>
197  *     Some elements might need to return %GST_STATE_CHANGE_ASYNC and complete
198  *     the state change when they have enough information. It is a requirement
199  *     for sinks to return %GST_STATE_CHANGE_ASYNC and complete the state change
200  *     when they receive the first buffer or %GST_EVENT_EOS (preroll).
201  *     Sinks also block the dataflow when in PAUSED.
202  *   </para></listitem>
203  *   <listitem><para>
204  *     A pipeline resets the running_time to 0.
205  *   </para></listitem>
206  *   <listitem><para>
207  *     Live sources return %GST_STATE_CHANGE_NO_PREROLL and don't generate data.
208  *   </para></listitem>
209  * </itemizedlist>
210  * @GST_STATE_CHANGE_PAUSED_TO_PLAYING: state change from PAUSED to PLAYING.
211  * <itemizedlist>
212  *   <listitem><para>
213  *     Most elements ignore this state change.
214  *   </para></listitem>
215  *   <listitem><para>
216  *     The pipeline selects a #GstClock and distributes this to all the children
217  *     before setting them to PLAYING. This means that it is only allowed to
218  *     synchronize on the #GstClock in the PLAYING state.
219  *   </para></listitem>
220  *   <listitem><para>
221  *     The pipeline uses the #GstClock and the running_time to calculate the
222  *     base_time. The base_time is distributed to all children when performing
223  *     the state change.
224  *   </para></listitem>
225  *   <listitem><para>
226  *     Sink elements stop blocking on the preroll buffer or event and start
227  *     rendering the data.
228  *   </para></listitem>
229  *   <listitem><para>
230  *     Sinks can post %GST_MESSAGE_EOS in the PLAYING state. It is not allowed
231  *     to post %GST_MESSAGE_EOS when not in the PLAYING state.
232  *   </para></listitem>
233  *   <listitem><para>
234  *     While streaming in PAUSED or PLAYING elements can create and remove
235  *     sometimes pads.
236  *   </para></listitem>
237  *   <listitem><para>
238  *     Live sources start generating data and return %GST_STATE_CHANGE_SUCCESS.
239  *   </para></listitem>
240  * </itemizedlist>
241  * @GST_STATE_CHANGE_PLAYING_TO_PAUSED: state change from PLAYING to PAUSED.
242  * <itemizedlist>
243  *   <listitem><para>
244  *     Most elements ignore this state change.
245  *   </para></listitem>
246  *   <listitem><para>
247  *     The pipeline calculates the running_time based on the last selected
248  *     #GstClock and the base_time. It stores this information to continue
249  *     playback when going back to the PLAYING state.
250  *   </para></listitem>
251  *   <listitem><para>
252  *     Sinks unblock any #GstClock wait calls.
253  *   </para></listitem>
254  *   <listitem><para>
255  *     When a sink does not have a pending buffer to play, it returns
256  *     %GST_STATE_CHANGE_ASYNC from this state change and completes the state
257  *     change when it receives a new buffer or an %GST_EVENT_EOS.
258  *   </para></listitem>
259  *   <listitem><para>
260  *     Any queued %GST_MESSAGE_EOS items are removed since they will be reposted
261  *     when going back to the PLAYING state. The EOS messages are queued in
262  *     #GstBin containers.
263  *   </para></listitem>
264  *   <listitem><para>
265  *     Live sources stop generating data and return %GST_STATE_CHANGE_NO_PREROLL.
266  *   </para></listitem>
267  * </itemizedlist>
268  * @GST_STATE_CHANGE_PAUSED_TO_READY  : state change from PAUSED to READY.
269  * <itemizedlist>
270  *   <listitem><para>
271  *     Sinks unblock any waits in the preroll.
272  *   </para></listitem>
273  *   <listitem><para>
274  *     Elements unblock any waits on devices
275  *   </para></listitem>
276  *   <listitem><para>
277  *     Chain or get_range functions return %GST_FLOW_FLUSHING.
278  *   </para></listitem>
279  *   <listitem><para>
280  *     The element pads are deactivated so that streaming becomes impossible and
281  *     all streaming threads are stopped.
282  *   </para></listitem>
283  *   <listitem><para>
284  *     The sink forgets all negotiated formats
285  *   </para></listitem>
286  *   <listitem><para>
287  *     Elements remove all sometimes pads
288  *   </para></listitem>
289  * </itemizedlist>
290  * @GST_STATE_CHANGE_READY_TO_NULL    : state change from READY to NULL.
291  * <itemizedlist>
292  *   <listitem><para>
293  *     Elements close devices
294  *   </para></listitem>
295  *   <listitem><para>
296  *     Elements reset any internal state.
297  *   </para></listitem>
298  * </itemizedlist>
299  *
300  * These are the different state changes an element goes through.
301  * %GST_STATE_NULL &rArr; %GST_STATE_PLAYING is called an upwards state change
302  * and %GST_STATE_PLAYING &rArr; %GST_STATE_NULL a downwards state change.
303  */
304 typedef enum /*< flags=0 >*/
305 {
306   GST_STATE_CHANGE_NULL_TO_READY        = (GST_STATE_NULL<<3) | GST_STATE_READY,
307   GST_STATE_CHANGE_READY_TO_PAUSED      = (GST_STATE_READY<<3) | GST_STATE_PAUSED,
308   GST_STATE_CHANGE_PAUSED_TO_PLAYING    = (GST_STATE_PAUSED<<3) | GST_STATE_PLAYING,
309   GST_STATE_CHANGE_PLAYING_TO_PAUSED    = (GST_STATE_PLAYING<<3) | GST_STATE_PAUSED,
310   GST_STATE_CHANGE_PAUSED_TO_READY      = (GST_STATE_PAUSED<<3) | GST_STATE_READY,
311   GST_STATE_CHANGE_READY_TO_NULL        = (GST_STATE_READY<<3) | GST_STATE_NULL
312 } GstStateChange;
313
314 /**
315  * GstElementFlags:
316  * @GST_ELEMENT_FLAG_LOCKED_STATE: ignore state changes from parent
317  * @GST_ELEMENT_FLAG_SINK: the element is a sink
318  * @GST_ELEMENT_FLAG_SOURCE: the element is a source.
319  * @GST_ELEMENT_FLAG_PROVIDE_CLOCK: the element can provide a clock
320  * @GST_ELEMENT_FLAG_REQUIRE_CLOCK: the element requires a clock
321  * @GST_ELEMENT_FLAG_INDEXABLE: the element can use an index
322  * @GST_ELEMENT_FLAG_LAST: offset to define more flags
323  *
324  * The standard flags that an element may have.
325  */
326 typedef enum
327 {
328   GST_ELEMENT_FLAG_LOCKED_STATE   = (GST_OBJECT_FLAG_LAST << 0),
329   GST_ELEMENT_FLAG_SINK           = (GST_OBJECT_FLAG_LAST << 1),
330   GST_ELEMENT_FLAG_SOURCE         = (GST_OBJECT_FLAG_LAST << 2),
331   GST_ELEMENT_FLAG_PROVIDE_CLOCK  = (GST_OBJECT_FLAG_LAST << 3),
332   GST_ELEMENT_FLAG_REQUIRE_CLOCK  = (GST_OBJECT_FLAG_LAST << 4),
333   GST_ELEMENT_FLAG_INDEXABLE      = (GST_OBJECT_FLAG_LAST << 5),
334   /* padding */
335   GST_ELEMENT_FLAG_LAST           = (GST_OBJECT_FLAG_LAST << 10)
336 } GstElementFlags;
337
338 /**
339  * GST_ELEMENT_IS_LOCKED_STATE:
340  * @elem: A #GstElement to query
341  *
342  * Check if the element is in the locked state and therefore will ignore state
343  * changes from its parent object.
344  */
345 #define GST_ELEMENT_IS_LOCKED_STATE(elem)        (GST_OBJECT_FLAG_IS_SET(elem,GST_ELEMENT_FLAG_LOCKED_STATE))
346
347 /**
348  * GST_ELEMENT_NAME:
349  * @elem: A #GstElement to query
350  *
351  * Gets the name of this element. This is not thread-safe by default
352  * (i.e. you will have to make sure the object lock is taken yourself).
353  * If in doubt use gst_element_get_name() instead.
354  */
355 #define GST_ELEMENT_NAME(elem)                  (GST_OBJECT_NAME(elem))
356
357 /**
358  * GST_ELEMENT_PARENT:
359  * @elem: A #GstElement to query
360  *
361  * Get the parent object of this element. This is not thread-safe by default
362  * (i.e. you will have to make sure the object lock is taken yourself).
363  * If in doubt use gst_object_get_parent() instead.
364  */
365 #define GST_ELEMENT_PARENT(elem)                (GST_ELEMENT_CAST(GST_OBJECT_PARENT(elem)))
366
367 /**
368  * GST_ELEMENT_BUS:
369  * @elem: A #GstElement to query
370  *
371  * Get the message bus of this element. This is not thread-safe by default
372  * (i.e. you will have to make sure the object lock is taken yourself).
373  * If in doubt use gst_element_get_bus() instead.
374  */
375 #define GST_ELEMENT_BUS(elem)                   (GST_ELEMENT_CAST(elem)->bus)
376
377 /**
378  * GST_ELEMENT_CLOCK:
379  * @elem: A #GstElement to query
380  *
381  * Get the clock of this element.This is not thread-safe by default
382  * (i.e. you will have to make sure it is safe yourself).
383  * If in doubt use gst_element_get_clock() instead.
384  */
385 #define GST_ELEMENT_CLOCK(elem)                 (GST_ELEMENT_CAST(elem)->clock)
386
387 /**
388  * GST_ELEMENT_PADS:
389  * @elem: A #GstElement to query
390  *
391  * Get the pads of this elements.
392  */
393 #define GST_ELEMENT_PADS(elem)                  (GST_ELEMENT_CAST(elem)->pads)
394
395 /**
396  * GST_ELEMENT_START_TIME:
397  * @elem: a #GstElement to return the start time for.
398  *
399  * This macro returns the start_time of the @elem. The start_time is the
400  * running_time of the pipeline when the element went to PAUSED.
401  */
402 #define GST_ELEMENT_START_TIME(elem)            (GST_ELEMENT_CAST(elem)->start_time)
403
404 GstStructure *gst_make_element_message_details (const char *name, ...);
405 #define GST_ELEMENT_MESSAGE_MAKE_DETAILS(args) gst_make_element_message_details args
406
407 /**
408  * GST_ELEMENT_FLOW_ERROR:
409  * @el:           the element that generates the error
410  * @flow_return:  the GstFlowReturn leading to that ERROR message
411  *
412  * Utility function that elements can use in case they encountered a fatal
413  * data processing error due to wrong flow processing.
414  *
415  * Since: 1.10
416  */
417 #define GST_ELEMENT_FLOW_ERROR(el,flow_return)  \
418 G_STMT_START {                                                          \
419   GST_ELEMENT_ERROR_WITH_DETAILS (el, STREAM, FAILED, \
420       ("Internal data stream error."), \
421       ("streaming stopped, reason %s (%d)", gst_flow_get_name (flow_return), flow_return), \
422       ("flow-return", G_TYPE_INT, flow_return, NULL));\
423 } G_STMT_END
424
425 /**
426  * GST_ELEMENT_ERROR_WITH_DETAILS:
427  * @el:     the element that generates the error
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  * @args:   optional name, type, value triplets, which will be stored
435  *          in the associated GstStructure. NULL terminator required.
436  *          Must be enclosed within parentheses.
437  *
438  * Utility function that elements can use in case they encountered a fatal
439  * data processing error. The pipeline will post an error message and the
440  * application will be requested to stop further media processing.
441  *
442  * Since: 1.10
443  */
444 #define GST_ELEMENT_ERROR_WITH_DETAILS(el,domain,code,text,debug,args)  \
445 G_STMT_START {                                                          \
446   gchar *__txt = _gst_element_error_printf text;                        \
447   gchar *__dbg = _gst_element_error_printf debug;                       \
448   if (__txt)                                                            \
449     GST_WARNING_OBJECT (el, "error: %s", __txt);                        \
450   if (__dbg)                                                            \
451     GST_WARNING_OBJECT (el, "error: %s", __dbg);                        \
452   gst_element_message_full_with_details (GST_ELEMENT(el),               \
453     GST_MESSAGE_ERROR, GST_ ## domain ## _ERROR,                        \
454       GST_ ## domain ## _ERROR_ ## code, __txt, __dbg, __FILE__,        \
455       GST_FUNCTION, __LINE__, GST_ELEMENT_MESSAGE_MAKE_DETAILS(args));  \
456 } G_STMT_END
457
458 /**
459  * GST_ELEMENT_ERROR:
460  * @el:     the element that generates the error
461  * @domain: like CORE, LIBRARY, RESOURCE or STREAM (see #gstreamer-GstGError)
462  * @code:   error code defined for that domain (see #gstreamer-GstGError)
463  * @text:   the message to display (format string and args enclosed in
464             parentheses)
465  * @debug:  debugging information for the message (format string and args
466             enclosed in parentheses)
467  *
468  * Utility function that elements can use in case they encountered a fatal
469  * data processing error. The pipeline will post an error message and the
470  * application will be requested to stop further media processing.
471  */
472 #define GST_ELEMENT_ERROR(el,domain,code,text,debug)                    \
473 G_STMT_START {                                                          \
474   gchar *__txt = _gst_element_error_printf text;                        \
475   gchar *__dbg = _gst_element_error_printf debug;                       \
476   if (__txt)                                                            \
477     GST_WARNING_OBJECT (el, "error: %s", __txt);                        \
478   if (__dbg)                                                            \
479     GST_WARNING_OBJECT (el, "error: %s", __dbg);                        \
480   gst_element_message_full (GST_ELEMENT(el),                            \
481     GST_MESSAGE_ERROR, GST_ ## domain ## _ERROR,                        \
482       GST_ ## domain ## _ERROR_ ## code, __txt, __dbg, __FILE__,        \
483       GST_FUNCTION, __LINE__);                                          \
484 } G_STMT_END
485
486 /**
487  * GST_ELEMENT_WARNING_WITH_DETAILS:
488  * @el:     the element that generates the warning
489  * @domain: like CORE, LIBRARY, RESOURCE or STREAM (see #gstreamer-GstGError)
490  * @code:   error code defined for that domain (see #gstreamer-GstGError)
491  * @text:   the message to display (format string and args enclosed in
492             parentheses)
493  * @debug:  debugging information for the message (format string and args
494             enclosed in parentheses)
495  * @args:   optional name, type, value triplets, which will be stored
496  *          in the associated GstStructure. NULL terminator required.
497  *          Must be enclosed within parentheses.
498  *
499  * Utility function that elements can use in case they encountered a non-fatal
500  * data processing problem. The pipeline will post a warning message and the
501  * application will be informed.
502  *
503  * Since: 1.10
504  */
505 #define GST_ELEMENT_WARNING_WITH_DETAILS(el, domain, code, text, debug, args)\
506 G_STMT_START {                                                          \
507   gchar *__txt = _gst_element_error_printf text;                        \
508   gchar *__dbg = _gst_element_error_printf debug;                       \
509   if (__txt)                                                            \
510     GST_WARNING_OBJECT (el, "warning: %s", __txt);                      \
511   if (__dbg)                                                            \
512     GST_WARNING_OBJECT (el, "warning: %s", __dbg);                      \
513   gst_element_message_full_with_details (GST_ELEMENT(el),               \
514     GST_MESSAGE_WARNING, GST_ ## domain ## _ERROR,                      \
515     GST_ ## domain ## _ERROR_ ## code, __txt, __dbg, __FILE__,          \
516     GST_FUNCTION, __LINE__, GST_ELEMENT_MESSAGE_MAKE_DETAILS(args));    \
517 } G_STMT_END
518
519 /**
520  * GST_ELEMENT_WARNING:
521  * @el:     the element that generates the warning
522  * @domain: like CORE, LIBRARY, RESOURCE or STREAM (see #gstreamer-GstGError)
523  * @code:   error code defined for that domain (see #gstreamer-GstGError)
524  * @text:   the message to display (format string and args enclosed in
525             parentheses)
526  * @debug:  debugging information for the message (format string and args
527             enclosed in parentheses)
528  *
529  * Utility function that elements can use in case they encountered a non-fatal
530  * data processing problem. The pipeline will post a warning message and the
531  * application will be informed.
532  */
533 #define GST_ELEMENT_WARNING(el, domain, code, text, debug)              \
534 G_STMT_START {                                                          \
535   gchar *__txt = _gst_element_error_printf text;                        \
536   gchar *__dbg = _gst_element_error_printf debug;                       \
537   if (__txt)                                                            \
538     GST_WARNING_OBJECT (el, "warning: %s", __txt);                      \
539   if (__dbg)                                                            \
540     GST_WARNING_OBJECT (el, "warning: %s", __dbg);                      \
541   gst_element_message_full (GST_ELEMENT(el),                            \
542     GST_MESSAGE_WARNING, GST_ ## domain ## _ERROR,                      \
543     GST_ ## domain ## _ERROR_ ## code, __txt, __dbg, __FILE__,          \
544     GST_FUNCTION, __LINE__);                                            \
545 } G_STMT_END
546
547 /**
548  * GST_ELEMENT_INFO_WITH_DETAILS:
549  * @el:     the element that generates the information
550  * @domain: like CORE, LIBRARY, RESOURCE or STREAM (see #gstreamer-GstGError)
551  * @code:   error code defined for that domain (see #gstreamer-GstGError)
552  * @text:   the message to display (format string and args enclosed in
553             parentheses)
554  * @debug:  debugging information for the message (format string and args
555             enclosed in parentheses)
556  * @args:   optional name, type, value triplets, which will be stored
557  *          in the associated GstStructure. NULL terminator required.
558  *          Must be enclosed within parentheses.
559  *
560  * Utility function that elements can use in case they want to inform
561  * the application of something noteworthy that is not an error.
562  * The pipeline will post a info message and the
563  * application will be informed.
564  * Optional name, type, value triplets may be supplied, and will be stored
565  * in the associated GstStructure. NULL terminator required.
566  *
567  * Since: 1.10
568  */
569 #define GST_ELEMENT_INFO_WITH_DETAILS(el, domain, code, text, debug, args)   \
570 G_STMT_START {                                                          \
571   gchar *__txt = _gst_element_error_printf text;                        \
572   gchar *__dbg = _gst_element_error_printf debug;                       \
573   if (__txt)                                                            \
574     GST_INFO_OBJECT (el, "info: %s", __txt);                            \
575   if (__dbg)                                                            \
576     GST_INFO_OBJECT (el, "info: %s", __dbg);                            \
577   gst_element_message_full_with_details (GST_ELEMENT(el),               \
578     GST_MESSAGE_INFO, GST_ ## domain ## _ERROR,                         \
579     GST_ ## domain ## _ERROR_ ## code, __txt, __dbg, __FILE__,          \
580     GST_FUNCTION, __LINE__, GST_ELEMENT_MESSAGE_MAKE_DETAILS(args));    \
581 } G_STMT_END
582
583 /**
584  * GST_ELEMENT_INFO:
585  * @el:     the element that generates the information
586  * @domain: like CORE, LIBRARY, RESOURCE or STREAM (see #gstreamer-GstGError)
587  * @code:   error code defined for that domain (see #gstreamer-GstGError)
588  * @text:   the message to display (format string and args enclosed in
589             parentheses)
590  * @debug:  debugging information for the message (format string and args
591             enclosed in parentheses)
592  *
593  * Utility function that elements can use in case they want to inform
594  * the application of something noteworthy that is not an error.
595  * The pipeline will post a info message and the
596  * application will be informed.
597  */
598 #define GST_ELEMENT_INFO(el, domain, code, text, debug)                 \
599 G_STMT_START {                                                          \
600   gchar *__txt = _gst_element_error_printf text;                        \
601   gchar *__dbg = _gst_element_error_printf debug;                       \
602   if (__txt)                                                            \
603     GST_INFO_OBJECT (el, "info: %s", __txt);                            \
604   if (__dbg)                                                            \
605     GST_INFO_OBJECT (el, "info: %s", __dbg);                            \
606   gst_element_message_full (GST_ELEMENT(el),                            \
607     GST_MESSAGE_INFO, GST_ ## domain ## _ERROR,                         \
608     GST_ ## domain ## _ERROR_ ## code, __txt, __dbg, __FILE__,          \
609     GST_FUNCTION, __LINE__);                                            \
610 } G_STMT_END
611
612 /* the state change mutexes and conds */
613 /**
614  * GST_STATE_GET_LOCK:
615  * @elem:   a #GstElement
616  *
617  * Get a reference to the state lock of @elem.
618  * This lock is used by the core.  It is taken while getting or setting
619  * the state, during state changes, and while finalizing.
620  */
621 #define GST_STATE_GET_LOCK(elem)               (&(GST_ELEMENT_CAST(elem)->state_lock))
622 /**
623  * GST_STATE_GET_COND:
624  * @elem: a #GstElement
625  *
626  * Get the conditional used to signal the completion of a state change.
627  */
628 #define GST_STATE_GET_COND(elem)               (&GST_ELEMENT_CAST(elem)->state_cond)
629
630 #define GST_STATE_LOCK(elem)                   g_rec_mutex_lock(GST_STATE_GET_LOCK(elem))
631 #define GST_STATE_TRYLOCK(elem)                g_rec_mutex_trylock(GST_STATE_GET_LOCK(elem))
632 #define GST_STATE_UNLOCK(elem)                 g_rec_mutex_unlock(GST_STATE_GET_LOCK(elem))
633 #define GST_STATE_WAIT(elem)                   g_cond_wait (GST_STATE_GET_COND (elem), \
634                                                         GST_OBJECT_GET_LOCK (elem))
635 #define GST_STATE_WAIT_UNTIL(elem, end_time)   g_cond_wait_until (GST_STATE_GET_COND (elem), \
636                                                         GST_OBJECT_GET_LOCK (elem), end_time)
637 #define GST_STATE_SIGNAL(elem)                 g_cond_signal (GST_STATE_GET_COND (elem));
638 #define GST_STATE_BROADCAST(elem)              g_cond_broadcast (GST_STATE_GET_COND (elem));
639
640 /**
641  * GstElement:
642  * @state_lock: Used to serialize execution of gst_element_set_state()
643  * @state_cond: Used to signal completion of a state change
644  * @state_cookie: Used to detect concurrent execution of
645  * gst_element_set_state() and gst_element_get_state()
646  * @target_state: the target state of an element as set by the application
647  * @current_state: the current state of an element
648  * @next_state: the next state of an element, can be #GST_STATE_VOID_PENDING if
649  * the element is in the correct state.
650  * @pending_state: the final state the element should go to, can be
651  * #GST_STATE_VOID_PENDING if the element is in the correct state
652  * @last_return: the last return value of an element state change
653  * @bus: the bus of the element. This bus is provided to the element by the
654  * parent element or the application. A #GstPipeline has a bus of its own.
655  * @clock: the clock of the element. This clock is usually provided to the
656  * element by the toplevel #GstPipeline.
657  * @base_time: the time of the clock right before the element is set to
658  * PLAYING. Subtracting @base_time from the current clock time in the PLAYING
659  * state will yield the running_time against the clock.
660  * @start_time: the running_time of the last PAUSED state
661  * @numpads: number of pads of the element, includes both source and sink pads.
662  * @pads: (element-type Gst.Pad): list of pads
663  * @numsrcpads: number of source pads of the element.
664  * @srcpads: (element-type Gst.Pad): list of source pads
665  * @numsinkpads: number of sink pads of the element.
666  * @sinkpads: (element-type Gst.Pad): list of sink pads
667  * @pads_cookie: updated whenever the a pad is added or removed
668  * @contexts: (element-type Gst.Context): list of contexts
669  *
670  * GStreamer element abstract base class.
671  */
672 struct _GstElement
673 {
674   GstObject             object;
675
676   /*< public >*/ /* with LOCK */
677   GRecMutex             state_lock;
678
679   /* element state */
680   GCond                 state_cond;
681   guint32               state_cookie;
682   GstState              target_state;
683   GstState              current_state;
684   GstState              next_state;
685   GstState              pending_state;
686   GstStateChangeReturn  last_return;
687
688   GstBus               *bus;
689
690   /* allocated clock */
691   GstClock             *clock;
692   GstClockTimeDiff      base_time; /* NULL/READY: 0 - PAUSED: current time - PLAYING: difference to clock */
693   GstClockTime          start_time;
694
695   /* element pads, these lists can only be iterated while holding
696    * the LOCK or checking the cookie after each LOCK. */
697   guint16               numpads;
698   GList                *pads;
699   guint16               numsrcpads;
700   GList                *srcpads;
701   guint16               numsinkpads;
702   GList                *sinkpads;
703   guint32               pads_cookie;
704
705   /* with object LOCK */
706   GList                *contexts;
707
708   /*< private >*/
709   gpointer _gst_reserved[GST_PADDING-1];
710 };
711
712 /**
713  * GstElementClass:
714  * @parent_class: the parent class structure
715  * @metadata: metadata for elements of this class
716  * @elementfactory: the #GstElementFactory that creates these elements
717  * @padtemplates: a #GList of #GstPadTemplate
718  * @numpadtemplates: the number of padtemplates
719  * @pad_templ_cookie: changed whenever the padtemplates change
720  * @request_new_pad: called when a new pad is requested
721  * @release_pad: called when a request pad is to be released
722  * @get_state: get the state of the element
723  * @set_state: set a new state on the element
724  * @change_state: called by @set_state to perform an incremental state change
725  * @set_bus: set a #GstBus on the element
726  * @provide_clock: gets the #GstClock provided by the element
727  * @set_clock: set the #GstClock on the element
728  * @send_event: send a #GstEvent to the element
729  * @query: perform a #GstQuery on the element
730  * @state_changed: called immediately after a new state was set.
731  * @post_message: called when a message is posted on the element. Chain up to
732  *                the parent class' handler to have it posted on the bus.
733  * @set_context: set a #GstContext on the element
734  *
735  * GStreamer element class. Override the vmethods to implement the element
736  * functionality.
737  */
738 struct _GstElementClass
739 {
740   GstObjectClass         parent_class;
741
742   /*< public >*/
743   /* the element metadata */
744   gpointer               metadata;
745
746   /* factory that the element was created from */
747   GstElementFactory     *elementfactory;
748
749   /* templates for our pads */
750   GList                 *padtemplates;
751   gint                   numpadtemplates;
752   guint32                pad_templ_cookie;
753
754   /*< private >*/
755   /* signal callbacks */
756   void (*pad_added)     (GstElement *element, GstPad *pad);
757   void (*pad_removed)   (GstElement *element, GstPad *pad);
758   void (*no_more_pads)  (GstElement *element);
759
760   /*< public >*/
761   /* virtual methods for subclasses */
762
763   /* request/release pads */
764   /* FIXME 2.0 harmonize naming with gst_element_request_pad */
765   GstPad*               (*request_new_pad)      (GstElement *element, GstPadTemplate *templ,
766                                                  const gchar* name, const GstCaps *caps);
767
768   void                  (*release_pad)          (GstElement *element, GstPad *pad);
769
770   /* state changes */
771   GstStateChangeReturn (*get_state)             (GstElement * element, GstState * state,
772                                                  GstState * pending, GstClockTime timeout);
773   GstStateChangeReturn (*set_state)             (GstElement *element, GstState state);
774   GstStateChangeReturn (*change_state)          (GstElement *element, GstStateChange transition);
775   void                 (*state_changed)         (GstElement *element, GstState oldstate,
776                                                  GstState newstate, GstState pending);
777
778   /* bus */
779   void                  (*set_bus)              (GstElement * element, GstBus * bus);
780
781   /* set/get clocks */
782   GstClock*             (*provide_clock)        (GstElement *element);
783   gboolean              (*set_clock)            (GstElement *element, GstClock *clock);
784
785   /* query functions */
786   gboolean              (*send_event)           (GstElement *element, GstEvent *event);
787
788   gboolean              (*query)                (GstElement *element, GstQuery *query);
789
790   gboolean              (*post_message)         (GstElement *element, GstMessage *message);
791
792   void                  (*set_context)          (GstElement *element, GstContext *context);
793
794   /*< private >*/
795   gpointer _gst_reserved[GST_PADDING_LARGE-2];
796 };
797
798 /* element class pad templates */
799 void                    gst_element_class_add_pad_template      (GstElementClass *klass, GstPadTemplate *templ);
800
801 void                    gst_element_class_add_static_pad_template (GstElementClass *klass, GstStaticPadTemplate *static_templ);
802
803 GstPadTemplate*         gst_element_class_get_pad_template      (GstElementClass *element_class, const gchar *name);
804 GList*                  gst_element_class_get_pad_template_list (GstElementClass *element_class);
805
806 /* element class meta data */
807 void                    gst_element_class_set_metadata          (GstElementClass *klass,
808                                                                  const gchar     *longname,
809                                                                  const gchar     *classification,
810                                                                  const gchar     *description,
811                                                                  const gchar     *author);
812 void                    gst_element_class_set_static_metadata   (GstElementClass *klass,
813                                                                  const gchar     *longname,
814                                                                  const gchar     *classification,
815                                                                  const gchar     *description,
816                                                                  const gchar     *author);
817 void                    gst_element_class_add_metadata          (GstElementClass * klass,
818                                                                  const gchar * key, const gchar * value);
819 void                    gst_element_class_add_static_metadata   (GstElementClass * klass,
820                                                                  const gchar * key, const gchar * value);
821 const gchar *           gst_element_class_get_metadata          (GstElementClass * klass,
822                                                                  const gchar * key);
823
824
825 /* element instance */
826 GType                   gst_element_get_type            (void);
827
828 /* basic name and parentage stuff from GstObject */
829
830 /**
831  * gst_element_get_name:
832  * @elem: a #GstElement to get the name of @elem.
833  *
834  * Returns a copy of the name of @elem.
835  * Caller should g_free() the return value after usage.
836  * For a nameless element, this returns %NULL, which you can safely g_free()
837  * as well.
838  *
839  * Returns: (transfer full) (nullable): the name of @elem. g_free()
840  * after usage. MT safe.
841  *
842  */
843 #define                 gst_element_get_name(elem)      gst_object_get_name(GST_OBJECT_CAST(elem))
844
845 /**
846  * gst_element_set_name:
847  * @elem: a #GstElement to set the name of.
848  * @name: the new name
849  *
850  * Sets the name of the element, getting rid of the old name if there was one.
851  */
852 #define                 gst_element_set_name(elem,name) gst_object_set_name(GST_OBJECT_CAST(elem),name)
853
854 /**
855  * gst_element_get_parent:
856  * @elem: a #GstElement to get the parent of.
857  *
858  * Get the parent of an element.
859  *
860  * Returns: (transfer full): the parent of an element.
861  */
862 #define                 gst_element_get_parent(elem)    gst_object_get_parent(GST_OBJECT_CAST(elem))
863
864 /**
865  * gst_element_set_parent:
866  * @elem: a #GstElement to set the parent of.
867  * @parent: the new parent #GstObject of the element.
868  *
869  * Sets the parent of an element.
870  */
871 #define                 gst_element_set_parent(elem,parent)     gst_object_set_parent(GST_OBJECT_CAST(elem),parent)
872
873 /* clocking */
874 GstClock*               gst_element_provide_clock       (GstElement *element);
875 GstClock*               gst_element_get_clock           (GstElement *element);
876 gboolean                gst_element_set_clock           (GstElement *element, GstClock *clock);
877 void                    gst_element_set_base_time       (GstElement *element, GstClockTime time);
878 GstClockTime            gst_element_get_base_time       (GstElement *element);
879 void                    gst_element_set_start_time      (GstElement *element, GstClockTime time);
880 GstClockTime            gst_element_get_start_time      (GstElement *element);
881
882 /* bus */
883 void                    gst_element_set_bus             (GstElement * element, GstBus * bus);
884 GstBus *                gst_element_get_bus             (GstElement * element);
885
886 /* context */
887 void                    gst_element_set_context         (GstElement * element, GstContext * context);
888 GList *                 gst_element_get_contexts        (GstElement * element);
889 GstContext *            gst_element_get_context         (GstElement * element, const gchar * context_type);
890 GstContext *            gst_element_get_context_unlocked (GstElement * element, const gchar * context_type);
891
892 /* pad management */
893 gboolean                gst_element_add_pad             (GstElement *element, GstPad *pad);
894 gboolean                gst_element_remove_pad          (GstElement *element, GstPad *pad);
895 void                    gst_element_no_more_pads        (GstElement *element);
896
897 GstPad*                 gst_element_get_static_pad      (GstElement *element, const gchar *name);
898 GstPad*                 gst_element_get_request_pad     (GstElement *element, const gchar *name);
899 GstPad*                 gst_element_request_pad         (GstElement *element, GstPadTemplate *templ,
900                                                          const gchar * name, const GstCaps *caps);
901 void                    gst_element_release_request_pad (GstElement *element, GstPad *pad);
902
903 GstIterator *           gst_element_iterate_pads        (GstElement * element);
904 GstIterator *           gst_element_iterate_src_pads    (GstElement * element);
905 GstIterator *           gst_element_iterate_sink_pads   (GstElement * element);
906
907 /* event/query/format stuff */
908 gboolean                gst_element_send_event          (GstElement *element, GstEvent *event);
909 gboolean                gst_element_seek                (GstElement *element, gdouble rate,
910                                                          GstFormat format, GstSeekFlags flags,
911                                                          GstSeekType start_type, gint64 start,
912                                                          GstSeekType stop_type, gint64 stop);
913 gboolean                gst_element_query               (GstElement *element, GstQuery *query);
914
915 /* messages */
916 gboolean                gst_element_post_message        (GstElement * element, GstMessage * message);
917
918 /* error handling */
919 /* gcc versions < 3.3 warn about NULL being passed as format to printf */
920 #if (!defined(__GNUC__) || (__GNUC__ < 3) || (__GNUC__ == 3 && __GNUC_MINOR__ < 3))
921 gchar *                 _gst_element_error_printf       (const gchar *format, ...);
922 #else
923 gchar *                 _gst_element_error_printf       (const gchar *format, ...) G_GNUC_PRINTF (1, 2);
924 #endif
925 void                    gst_element_message_full        (GstElement * element, GstMessageType type,
926                                                          GQuark domain, gint code, gchar * text,
927                                                          gchar * debug, const gchar * file,
928                                                          const gchar * function, gint line);
929
930 void                    gst_element_message_full_with_details (GstElement * element, GstMessageType type,
931                                                          GQuark domain, gint code, gchar * text,
932                                                          gchar * debug, const gchar * file,
933                                                          const gchar * function, gint line,
934                                                          GstStructure * structure);
935
936 /* state management */
937 gboolean                gst_element_is_locked_state     (GstElement *element);
938 gboolean                gst_element_set_locked_state    (GstElement *element, gboolean locked_state);
939 gboolean                gst_element_sync_state_with_parent (GstElement *element);
940
941 GstStateChangeReturn    gst_element_get_state           (GstElement * element,
942                                                          GstState * state,
943                                                          GstState * pending,
944                                                          GstClockTime timeout);
945 GstStateChangeReturn    gst_element_set_state           (GstElement *element, GstState state);
946
947 void                    gst_element_abort_state         (GstElement * element);
948 GstStateChangeReturn    gst_element_change_state        (GstElement * element,
949                                                          GstStateChange transition);
950 GstStateChangeReturn    gst_element_continue_state      (GstElement * element,
951                                                          GstStateChangeReturn ret);
952 void                    gst_element_lost_state          (GstElement * element);
953
954 typedef void          (*GstElementCallAsyncFunc)        (GstElement * element,
955                                                          gpointer     user_data);
956
957 void                    gst_element_call_async          (GstElement * element,
958                                                          GstElementCallAsyncFunc func, gpointer user_data,
959                                                          GDestroyNotify destroy_notify);
960
961 /* factory management */
962 GstElementFactory*      gst_element_get_factory         (GstElement *element);
963
964 /* utility functions */
965 gulong                  gst_element_add_property_notify_watch (GstElement  * element,
966                                                                const gchar * property_name,
967                                                                gboolean      include_value);
968
969 gulong                  gst_element_add_property_deep_notify_watch (GstElement  * element,
970                                                                     const gchar * property_name,
971                                                                     gboolean      include_value);
972
973 void                    gst_element_remove_property_notify_watch (GstElement * element,
974                                                                   gulong       watch_id);
975
976 #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
977 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstElement, gst_object_unref)
978 #endif
979
980 G_END_DECLS
981
982 #endif /* __GST_ELEMENT_H__ */