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