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