doc: Fix some doctsing making GI happy
[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 GstStructure *gst_make_element_message_details (const char *name, ...);
339 #define GST_ELEMENT_MESSAGE_MAKE_DETAILS(args) gst_make_element_message_details args
340
341 /**
342  * GST_ELEMENT_FLOW_ERROR:
343  * @el:           the element that generates the error
344  * @flow_return:  the GstFlowReturn leading to that ERROR message
345  *
346  * Utility function that elements can use in case they encountered a fatal
347  * data processing error due to wrong flow processing.
348  *
349  * Since: 1.10
350  */
351 #define GST_ELEMENT_FLOW_ERROR(el,flow_return)  \
352 G_STMT_START {                                                          \
353   GST_ELEMENT_ERROR_WITH_DETAILS (el, STREAM, FAILED, \
354       ("Internal data stream error."), \
355       ("streaming stopped, reason %s (%d)", gst_flow_get_name (flow_return), flow_return), \
356       ("flow-return", G_TYPE_INT, flow_return, NULL));\
357 } G_STMT_END
358
359 /**
360  * GST_ELEMENT_ERROR_WITH_DETAILS:
361  * @el:     the element that generates the error
362  * @domain: like CORE, LIBRARY, RESOURCE or STREAM (see #gstreamer-GstGError)
363  * @code:   error code defined for that domain (see #gstreamer-GstGError)
364  * @text:   the message to display (format string and args enclosed in
365             parentheses)
366  * @debug:  debugging information for the message (format string and args
367             enclosed in parentheses)
368  * @args:   optional name, type, value triplets, which will be stored
369  *          in the associated GstStructure. NULL terminator required.
370  *          Must be enclosed within parentheses.
371  *
372  * Utility function that elements can use in case they encountered a fatal
373  * data processing error. The pipeline will post an error message and the
374  * application will be requested to stop further media processing.
375  *
376  * Since: 1.10
377  */
378 #define GST_ELEMENT_ERROR_WITH_DETAILS(el,domain,code,text,debug,args)  \
379 G_STMT_START {                                                          \
380   gchar *__txt = _gst_element_error_printf text;                        \
381   gchar *__dbg = _gst_element_error_printf debug;                       \
382   if (__txt)                                                            \
383     GST_WARNING_OBJECT (el, "error: %s", __txt);                        \
384   if (__dbg)                                                            \
385     GST_WARNING_OBJECT (el, "error: %s", __dbg);                        \
386   gst_element_message_full_with_details (GST_ELEMENT(el),               \
387     GST_MESSAGE_ERROR, GST_ ## domain ## _ERROR,                        \
388       GST_ ## domain ## _ERROR_ ## code, __txt, __dbg, __FILE__,        \
389       GST_FUNCTION, __LINE__, GST_ELEMENT_MESSAGE_MAKE_DETAILS(args));  \
390 } G_STMT_END
391
392 /**
393  * GST_ELEMENT_ERROR:
394  * @el:     the element that generates the error
395  * @domain: like CORE, LIBRARY, RESOURCE or STREAM (see #gstreamer-GstGError)
396  * @code:   error code defined for that domain (see #gstreamer-GstGError)
397  * @text:   the message to display (format string and args enclosed in
398             parentheses)
399  * @debug:  debugging information for the message (format string and args
400             enclosed in parentheses)
401  *
402  * Utility function that elements can use in case they encountered a fatal
403  * data processing error. The pipeline will post an error message and the
404  * application will be requested to stop further media processing.
405  */
406 #define GST_ELEMENT_ERROR(el,domain,code,text,debug)                    \
407 G_STMT_START {                                                          \
408   gchar *__txt = _gst_element_error_printf text;                        \
409   gchar *__dbg = _gst_element_error_printf debug;                       \
410   if (__txt)                                                            \
411     GST_WARNING_OBJECT (el, "error: %s", __txt);                        \
412   if (__dbg)                                                            \
413     GST_WARNING_OBJECT (el, "error: %s", __dbg);                        \
414   gst_element_message_full (GST_ELEMENT(el),                            \
415     GST_MESSAGE_ERROR, GST_ ## domain ## _ERROR,                        \
416       GST_ ## domain ## _ERROR_ ## code, __txt, __dbg, __FILE__,        \
417       GST_FUNCTION, __LINE__);                                          \
418 } G_STMT_END
419
420 /**
421  * GST_ELEMENT_WARNING_WITH_DETAILS:
422  * @el:     the element that generates the warning
423  * @domain: like CORE, LIBRARY, RESOURCE or STREAM (see #gstreamer-GstGError)
424  * @code:   error code defined for that domain (see #gstreamer-GstGError)
425  * @text:   the message to display (format string and args enclosed in
426             parentheses)
427  * @debug:  debugging information for the message (format string and args
428             enclosed in parentheses)
429  * @args:   optional name, type, value triplets, which will be stored
430  *          in the associated GstStructure. NULL terminator required.
431  *          Must be enclosed within parentheses.
432  *
433  * Utility function that elements can use in case they encountered a non-fatal
434  * data processing problem. The pipeline will post a warning message and the
435  * application will be informed.
436  *
437  * Since: 1.10
438  */
439 #define GST_ELEMENT_WARNING_WITH_DETAILS(el, domain, code, text, debug, args)\
440 G_STMT_START {                                                          \
441   gchar *__txt = _gst_element_error_printf text;                        \
442   gchar *__dbg = _gst_element_error_printf debug;                       \
443   if (__txt)                                                            \
444     GST_WARNING_OBJECT (el, "warning: %s", __txt);                      \
445   if (__dbg)                                                            \
446     GST_WARNING_OBJECT (el, "warning: %s", __dbg);                      \
447   gst_element_message_full_with_details (GST_ELEMENT(el),               \
448     GST_MESSAGE_WARNING, GST_ ## domain ## _ERROR,                      \
449     GST_ ## domain ## _ERROR_ ## code, __txt, __dbg, __FILE__,          \
450     GST_FUNCTION, __LINE__, GST_ELEMENT_MESSAGE_MAKE_DETAILS(args));    \
451 } G_STMT_END
452
453 /**
454  * GST_ELEMENT_WARNING:
455  * @el:     the element that generates the warning
456  * @domain: like CORE, LIBRARY, RESOURCE or STREAM (see #gstreamer-GstGError)
457  * @code:   error code defined for that domain (see #gstreamer-GstGError)
458  * @text:   the message to display (format string and args enclosed in
459             parentheses)
460  * @debug:  debugging information for the message (format string and args
461             enclosed in parentheses)
462  *
463  * Utility function that elements can use in case they encountered a non-fatal
464  * data processing problem. The pipeline will post a warning message and the
465  * application will be informed.
466  */
467 #define GST_ELEMENT_WARNING(el, domain, code, text, debug)              \
468 G_STMT_START {                                                          \
469   gchar *__txt = _gst_element_error_printf text;                        \
470   gchar *__dbg = _gst_element_error_printf debug;                       \
471   if (__txt)                                                            \
472     GST_WARNING_OBJECT (el, "warning: %s", __txt);                      \
473   if (__dbg)                                                            \
474     GST_WARNING_OBJECT (el, "warning: %s", __dbg);                      \
475   gst_element_message_full (GST_ELEMENT(el),                            \
476     GST_MESSAGE_WARNING, GST_ ## domain ## _ERROR,                      \
477     GST_ ## domain ## _ERROR_ ## code, __txt, __dbg, __FILE__,          \
478     GST_FUNCTION, __LINE__);                                            \
479 } G_STMT_END
480
481 /**
482  * GST_ELEMENT_INFO_WITH_DETAILS:
483  * @el:     the element that generates the information
484  * @domain: like CORE, LIBRARY, RESOURCE or STREAM (see #gstreamer-GstGError)
485  * @code:   error code defined for that domain (see #gstreamer-GstGError)
486  * @text:   the message to display (format string and args enclosed in
487             parentheses)
488  * @debug:  debugging information for the message (format string and args
489             enclosed in parentheses)
490  * @args:   optional name, type, value triplets, which will be stored
491  *          in the associated GstStructure. NULL terminator required.
492  *          Must be enclosed within parentheses.
493  *
494  * Utility function that elements can use in case they want to inform
495  * the application of something noteworthy that is not an error.
496  * The pipeline will post a info message and the
497  * application will be informed.
498  * Optional name, type, value triplets may be supplied, and will be stored
499  * in the associated GstStructure. NULL terminator required.
500  *
501  * Since: 1.10
502  */
503 #define GST_ELEMENT_INFO_WITH_DETAILS(el, domain, code, text, debug, args)   \
504 G_STMT_START {                                                          \
505   gchar *__txt = _gst_element_error_printf text;                        \
506   gchar *__dbg = _gst_element_error_printf debug;                       \
507   if (__txt)                                                            \
508     GST_INFO_OBJECT (el, "info: %s", __txt);                            \
509   if (__dbg)                                                            \
510     GST_INFO_OBJECT (el, "info: %s", __dbg);                            \
511   gst_element_message_full_with_details (GST_ELEMENT(el),               \
512     GST_MESSAGE_INFO, GST_ ## domain ## _ERROR,                         \
513     GST_ ## domain ## _ERROR_ ## code, __txt, __dbg, __FILE__,          \
514     GST_FUNCTION, __LINE__, GST_ELEMENT_MESSAGE_MAKE_DETAILS(args));    \
515 } G_STMT_END
516
517 /**
518  * GST_ELEMENT_INFO:
519  * @el:     the element that generates the information
520  * @domain: like CORE, LIBRARY, RESOURCE or STREAM (see #gstreamer-GstGError)
521  * @code:   error code defined for that domain (see #gstreamer-GstGError)
522  * @text:   the message to display (format string and args enclosed in
523             parentheses)
524  * @debug:  debugging information for the message (format string and args
525             enclosed in parentheses)
526  *
527  * Utility function that elements can use in case they want to inform
528  * the application of something noteworthy that is not an error.
529  * The pipeline will post a info message and the
530  * application will be informed.
531  */
532 #define GST_ELEMENT_INFO(el, domain, code, text, debug)                 \
533 G_STMT_START {                                                          \
534   gchar *__txt = _gst_element_error_printf text;                        \
535   gchar *__dbg = _gst_element_error_printf debug;                       \
536   if (__txt)                                                            \
537     GST_INFO_OBJECT (el, "info: %s", __txt);                            \
538   if (__dbg)                                                            \
539     GST_INFO_OBJECT (el, "info: %s", __dbg);                            \
540   gst_element_message_full (GST_ELEMENT(el),                            \
541     GST_MESSAGE_INFO, GST_ ## domain ## _ERROR,                         \
542     GST_ ## domain ## _ERROR_ ## code, __txt, __dbg, __FILE__,          \
543     GST_FUNCTION, __LINE__);                                            \
544 } G_STMT_END
545
546 /* the state change mutexes and conds */
547 /**
548  * GST_STATE_GET_LOCK:
549  * @elem:   a #GstElement
550  *
551  * Get a reference to the state lock of @elem.
552  * This lock is used by the core.  It is taken while getting or setting
553  * the state, during state changes, and while finalizing.
554  */
555 #define GST_STATE_GET_LOCK(elem)               (&(GST_ELEMENT_CAST(elem)->state_lock))
556 /**
557  * GST_STATE_GET_COND:
558  * @elem: a #GstElement
559  *
560  * Get the conditional used to signal the completion of a state change.
561  */
562 #define GST_STATE_GET_COND(elem)               (&GST_ELEMENT_CAST(elem)->state_cond)
563
564 #define GST_STATE_LOCK(elem)                   g_rec_mutex_lock(GST_STATE_GET_LOCK(elem))
565 #define GST_STATE_TRYLOCK(elem)                g_rec_mutex_trylock(GST_STATE_GET_LOCK(elem))
566 #define GST_STATE_UNLOCK(elem)                 g_rec_mutex_unlock(GST_STATE_GET_LOCK(elem))
567 #define GST_STATE_WAIT(elem)                   g_cond_wait (GST_STATE_GET_COND (elem), \
568                                                         GST_OBJECT_GET_LOCK (elem))
569 #define GST_STATE_WAIT_UNTIL(elem, end_time)   g_cond_wait_until (GST_STATE_GET_COND (elem), \
570                                                         GST_OBJECT_GET_LOCK (elem), end_time)
571 #define GST_STATE_SIGNAL(elem)                 g_cond_signal (GST_STATE_GET_COND (elem));
572 #define GST_STATE_BROADCAST(elem)              g_cond_broadcast (GST_STATE_GET_COND (elem));
573
574 /**
575  * GstElement:
576  * @state_lock: Used to serialize execution of gst_element_set_state()
577  * @state_cond: Used to signal completion of a state change
578  * @state_cookie: Used to detect concurrent execution of
579  * gst_element_set_state() and gst_element_get_state()
580  * @target_state: the target state of an element as set by the application
581  * @current_state: the current state of an element
582  * @next_state: the next state of an element, can be #GST_STATE_VOID_PENDING if
583  * the element is in the correct state.
584  * @pending_state: the final state the element should go to, can be
585  * #GST_STATE_VOID_PENDING if the element is in the correct state
586  * @last_return: the last return value of an element state change
587  * @bus: the bus of the element. This bus is provided to the element by the
588  * parent element or the application. A #GstPipeline has a bus of its own.
589  * @clock: the clock of the element. This clock is usually provided to the
590  * element by the toplevel #GstPipeline.
591  * @base_time: the time of the clock right before the element is set to
592  * PLAYING. Subtracting @base_time from the current clock time in the PLAYING
593  * state will yield the running_time against the clock.
594  * @start_time: the running_time of the last PAUSED state
595  * @numpads: number of pads of the element, includes both source and sink pads.
596  * @pads: (element-type Gst.Pad): list of pads
597  * @numsrcpads: number of source pads of the element.
598  * @srcpads: (element-type Gst.Pad): list of source pads
599  * @numsinkpads: number of sink pads of the element.
600  * @sinkpads: (element-type Gst.Pad): list of sink pads
601  * @pads_cookie: updated whenever the a pad is added or removed
602  * @contexts: (element-type Gst.Context): list of contexts
603  *
604  * GStreamer element abstract base class.
605  */
606 struct _GstElement
607 {
608   GstObject             object;
609
610   /*< public >*/ /* with LOCK */
611   GRecMutex             state_lock;
612
613   /* element state */
614   GCond                 state_cond;
615   guint32               state_cookie;
616   GstState              target_state;
617   GstState              current_state;
618   GstState              next_state;
619   GstState              pending_state;
620   GstStateChangeReturn  last_return;
621
622   GstBus               *bus;
623
624   /* allocated clock */
625   GstClock             *clock;
626   GstClockTimeDiff      base_time; /* NULL/READY: 0 - PAUSED: current time - PLAYING: difference to clock */
627   GstClockTime          start_time;
628
629   /* element pads, these lists can only be iterated while holding
630    * the LOCK or checking the cookie after each LOCK. */
631   guint16               numpads;
632   GList                *pads;
633   guint16               numsrcpads;
634   GList                *srcpads;
635   guint16               numsinkpads;
636   GList                *sinkpads;
637   guint32               pads_cookie;
638
639   /* with object LOCK */
640   GList                *contexts;
641
642   /*< private >*/
643   gpointer _gst_reserved[GST_PADDING-1];
644 };
645
646 /**
647  * GstElementClass:
648  * @parent_class: the parent class structure
649  * @metadata: metadata for elements of this class
650  * @elementfactory: the #GstElementFactory that creates these elements
651  * @padtemplates: a #GList of #GstPadTemplate
652  * @numpadtemplates: the number of padtemplates
653  * @pad_templ_cookie: changed whenever the padtemplates change
654  * @request_new_pad: called when a new pad is requested
655  * @release_pad: called when a request pad is to be released
656  * @get_state: get the state of the element
657  * @set_state: set a new state on the element
658  * @change_state: called by @set_state to perform an incremental state change
659  * @set_bus: set a #GstBus on the element
660  * @provide_clock: gets the #GstClock provided by the element
661  * @set_clock: set the #GstClock on the element
662  * @send_event: send a #GstEvent to the element
663  * @query: perform a #GstQuery on the element
664  * @state_changed: called immediately after a new state was set.
665  * @post_message: called when a message is posted on the element. Chain up to
666  *                the parent class' handler to have it posted on the bus.
667  * @set_context: set a #GstContext on the element
668  *
669  * GStreamer element class. Override the vmethods to implement the element
670  * functionality.
671  */
672 struct _GstElementClass
673 {
674   GstObjectClass         parent_class;
675
676   /*< public >*/
677   /* the element metadata */
678   gpointer               metadata;
679
680   /* factory that the element was created from */
681   GstElementFactory     *elementfactory;
682
683   /* templates for our pads */
684   GList                 *padtemplates;
685   gint                   numpadtemplates;
686   guint32                pad_templ_cookie;
687
688   /*< private >*/
689   /* signal callbacks */
690   void (*pad_added)     (GstElement *element, GstPad *pad);
691   void (*pad_removed)   (GstElement *element, GstPad *pad);
692   void (*no_more_pads)  (GstElement *element);
693
694   /*< public >*/
695   /* virtual methods for subclasses */
696
697   /* request/release pads */
698   /* FIXME 2.0 harmonize naming with gst_element_request_pad */
699   GstPad*               (*request_new_pad)      (GstElement *element, GstPadTemplate *templ,
700                                                  const gchar* name, const GstCaps *caps);
701
702   void                  (*release_pad)          (GstElement *element, GstPad *pad);
703
704   /* state changes */
705   GstStateChangeReturn (*get_state)             (GstElement * element, GstState * state,
706                                                  GstState * pending, GstClockTime timeout);
707   GstStateChangeReturn (*set_state)             (GstElement *element, GstState state);
708   GstStateChangeReturn (*change_state)          (GstElement *element, GstStateChange transition);
709   void                 (*state_changed)         (GstElement *element, GstState oldstate,
710                                                  GstState newstate, GstState pending);
711
712   /* bus */
713   void                  (*set_bus)              (GstElement * element, GstBus * bus);
714
715   /* set/get clocks */
716   GstClock*             (*provide_clock)        (GstElement *element);
717   gboolean              (*set_clock)            (GstElement *element, GstClock *clock);
718
719   /* query functions */
720   gboolean              (*send_event)           (GstElement *element, GstEvent *event);
721
722   gboolean              (*query)                (GstElement *element, GstQuery *query);
723
724   gboolean              (*post_message)         (GstElement *element, GstMessage *message);
725
726   void                  (*set_context)          (GstElement *element, GstContext *context);
727
728   /*< private >*/
729   gpointer _gst_reserved[GST_PADDING_LARGE-2];
730 };
731
732 /* element class pad templates */
733 void                    gst_element_class_add_pad_template      (GstElementClass *klass, GstPadTemplate *templ);
734
735 void                    gst_element_class_add_static_pad_template (GstElementClass *klass, GstStaticPadTemplate *static_templ);
736
737 GstPadTemplate*         gst_element_class_get_pad_template      (GstElementClass *element_class, const gchar *name);
738 GList*                  gst_element_class_get_pad_template_list (GstElementClass *element_class);
739
740 /* element class meta data */
741 void                    gst_element_class_set_metadata          (GstElementClass *klass,
742                                                                  const gchar     *longname,
743                                                                  const gchar     *classification,
744                                                                  const gchar     *description,
745                                                                  const gchar     *author);
746 void                    gst_element_class_set_static_metadata   (GstElementClass *klass,
747                                                                  const gchar     *longname,
748                                                                  const gchar     *classification,
749                                                                  const gchar     *description,
750                                                                  const gchar     *author);
751 void                    gst_element_class_add_metadata          (GstElementClass * klass,
752                                                                  const gchar * key, const gchar * value);
753 void                    gst_element_class_add_static_metadata   (GstElementClass * klass,
754                                                                  const gchar * key, const gchar * value);
755 const gchar *           gst_element_class_get_metadata          (GstElementClass * klass,
756                                                                  const gchar * key);
757
758
759 /* element instance */
760 GType                   gst_element_get_type            (void);
761
762 /* basic name and parentage stuff from GstObject */
763
764 /**
765  * gst_element_get_name:
766  * @elem: a #GstElement to get the name of @elem.
767  *
768  * Returns a copy of the name of @elem.
769  * Caller should g_free() the return value after usage.
770  * For a nameless element, this returns %NULL, which you can safely g_free()
771  * as well.
772  *
773  * Returns: (transfer full) (nullable): the name of @elem. g_free()
774  * after usage. MT safe.
775  *
776  */
777 #define                 gst_element_get_name(elem)      gst_object_get_name(GST_OBJECT_CAST(elem))
778
779 /**
780  * gst_element_set_name:
781  * @elem: a #GstElement to set the name of.
782  * @name: the new name
783  *
784  * Sets the name of the element, getting rid of the old name if there was one.
785  */
786 #define                 gst_element_set_name(elem,name) gst_object_set_name(GST_OBJECT_CAST(elem),name)
787
788 /**
789  * gst_element_get_parent:
790  * @elem: a #GstElement to get the parent of.
791  *
792  * Get the parent of an element.
793  *
794  * Returns: (transfer full): the parent of an element.
795  */
796 #define                 gst_element_get_parent(elem)    gst_object_get_parent(GST_OBJECT_CAST(elem))
797
798 /**
799  * gst_element_set_parent:
800  * @elem: a #GstElement to set the parent of.
801  * @parent: the new parent #GstObject of the element.
802  *
803  * Sets the parent of an element.
804  */
805 #define                 gst_element_set_parent(elem,parent)     gst_object_set_parent(GST_OBJECT_CAST(elem),parent)
806
807 /* clocking */
808 GstClock*               gst_element_provide_clock       (GstElement *element);
809 GstClock*               gst_element_get_clock           (GstElement *element);
810 gboolean                gst_element_set_clock           (GstElement *element, GstClock *clock);
811 void                    gst_element_set_base_time       (GstElement *element, GstClockTime time);
812 GstClockTime            gst_element_get_base_time       (GstElement *element);
813 void                    gst_element_set_start_time      (GstElement *element, GstClockTime time);
814 GstClockTime            gst_element_get_start_time      (GstElement *element);
815
816 /* bus */
817 void                    gst_element_set_bus             (GstElement * element, GstBus * bus);
818 GstBus *                gst_element_get_bus             (GstElement * element);
819
820 /* context */
821 void                    gst_element_set_context         (GstElement * element, GstContext * context);
822 GList *                 gst_element_get_contexts        (GstElement * element);
823 GstContext *            gst_element_get_context         (GstElement * element, const gchar * context_type);
824 GstContext *            gst_element_get_context_unlocked (GstElement * element, const gchar * context_type);
825
826 /* pad management */
827 gboolean                gst_element_add_pad             (GstElement *element, GstPad *pad);
828 gboolean                gst_element_remove_pad          (GstElement *element, GstPad *pad);
829 void                    gst_element_no_more_pads        (GstElement *element);
830
831 GstPad*                 gst_element_get_static_pad      (GstElement *element, const gchar *name);
832 GstPad*                 gst_element_get_request_pad     (GstElement *element, const gchar *name);
833 GstPad*                 gst_element_request_pad         (GstElement *element, GstPadTemplate *templ,
834                                                          const gchar * name, const GstCaps *caps);
835 void                    gst_element_release_request_pad (GstElement *element, GstPad *pad);
836
837 GstIterator *           gst_element_iterate_pads        (GstElement * element);
838 GstIterator *           gst_element_iterate_src_pads    (GstElement * element);
839 GstIterator *           gst_element_iterate_sink_pads   (GstElement * element);
840
841 /* event/query/format stuff */
842 gboolean                gst_element_send_event          (GstElement *element, GstEvent *event);
843 gboolean                gst_element_seek                (GstElement *element, gdouble rate,
844                                                          GstFormat format, GstSeekFlags flags,
845                                                          GstSeekType start_type, gint64 start,
846                                                          GstSeekType stop_type, gint64 stop);
847 gboolean                gst_element_query               (GstElement *element, GstQuery *query);
848
849 /* messages */
850 gboolean                gst_element_post_message        (GstElement * element, GstMessage * message);
851
852 /* error handling */
853 /* gcc versions < 3.3 warn about NULL being passed as format to printf */
854 #if (!defined(__GNUC__) || (__GNUC__ < 3) || (__GNUC__ == 3 && __GNUC_MINOR__ < 3))
855 gchar *                 _gst_element_error_printf       (const gchar *format, ...);
856 #else
857 gchar *                 _gst_element_error_printf       (const gchar *format, ...) G_GNUC_PRINTF (1, 2);
858 #endif
859 void                    gst_element_message_full        (GstElement * element, GstMessageType type,
860                                                          GQuark domain, gint code, gchar * text,
861                                                          gchar * debug, const gchar * file,
862                                                          const gchar * function, gint line);
863
864 void                    gst_element_message_full_with_details (GstElement * element, GstMessageType type,
865                                                          GQuark domain, gint code, gchar * text,
866                                                          gchar * debug, const gchar * file,
867                                                          const gchar * function, gint line,
868                                                          GstStructure * structure);
869
870 /* state management */
871 gboolean                gst_element_is_locked_state     (GstElement *element);
872 gboolean                gst_element_set_locked_state    (GstElement *element, gboolean locked_state);
873 gboolean                gst_element_sync_state_with_parent (GstElement *element);
874
875 GstStateChangeReturn    gst_element_get_state           (GstElement * element,
876                                                          GstState * state,
877                                                          GstState * pending,
878                                                          GstClockTime timeout);
879 GstStateChangeReturn    gst_element_set_state           (GstElement *element, GstState state);
880
881 void                    gst_element_abort_state         (GstElement * element);
882 GstStateChangeReturn    gst_element_change_state        (GstElement * element,
883                                                          GstStateChange transition);
884 GstStateChangeReturn    gst_element_continue_state      (GstElement * element,
885                                                          GstStateChangeReturn ret);
886 void                    gst_element_lost_state          (GstElement * element);
887
888 typedef void          (*GstElementCallAsyncFunc)        (GstElement * element,
889                                                          gpointer     user_data);
890
891 void                    gst_element_call_async          (GstElement * element,
892                                                          GstElementCallAsyncFunc func, gpointer user_data,
893                                                          GDestroyNotify destroy_notify);
894
895 /* factory management */
896 GstElementFactory*      gst_element_get_factory         (GstElement *element);
897
898 /* utility functions */
899 gulong                  gst_element_add_property_notify_watch (GstElement  * element,
900                                                                const gchar * property_name,
901                                                                gboolean      include_value);
902
903 gulong                  gst_element_add_property_deep_notify_watch (GstElement  * element,
904                                                                     const gchar * property_name,
905                                                                     gboolean      include_value);
906
907 void                    gst_element_remove_property_notify_watch (GstElement * element,
908                                                                   gulong       watch_id);
909
910 #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
911 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstElement, gst_object_unref)
912 #endif
913
914 G_END_DECLS
915
916 #endif /* __GST_ELEMENT_H__ */