2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2004 Wim Taymans <wim@fluendo.com>
5 * gstelement.c: The base element, all elements derive from this
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.
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.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
25 * @short_description: Abstract base class for all pipeline elements
26 * @see_also: #GstElementFactory, #GstPad
28 * GstElement is the base class needed to construct an element that can be
29 * used in a GStreamer pipeline. As such, it is not a functional entity, and
30 * cannot do anything when placed in a pipeline.
32 * The name of a #GstElement can be get with gst_element_get_name() and set with
33 * gst_element_set_name(). For speed, GST_ELEMENT_NAME() can be used in the
34 * core when using the appropriate locking. Do not use this in plug-ins or
35 * applications in order to retain ABI compatibility.
37 * All elements have pads (of the type #GstPad). These pads link to pads on
38 * other elements. #GstBuffer flow between these linked pads.
39 * A #GstElement has a #GList of #GstPad structures for all their input (or sink)
40 * and output (or source) pads.
41 * Core and plug-in writers can add and remove pads with gst_element_add_pad()
42 * and gst_element_remove_pad().
44 * A pad of an element can be retrieved by name with gst_element_get_pad().
45 * An iterator of all pads can be retrieved with gst_element_iterate_pads().
47 * Elements can be linked through their pads.
48 * If the link is straightforward, use the gst_element_link()
49 * convenience function to link two elements, or gst_element_link_many()
50 * for more elements in a row.
51 * Use gst_element_link_filtered() to link two elements constrained by
52 * a specified set of #GstCaps.
53 * For finer control, use gst_element_link_pads() and
54 * gst_element_link_pads_filtered() to specify the pads to link on
55 * each element by name.
57 * Each element has a state (see #GstState). You can get and set the state
58 * of an element with gst_element_get_state() and gst_element_set_state().
59 * To get a string representation of a #GstState, use
60 * gst_element_state_get_name().
62 * You can get and set a #GstClock on an element using gst_element_get_clock()
63 * and gst_element_set_clock().
64 * Some elements can provide a clock for the pipeline if
65 * gst_element_provides_clock() returns TRUE. With the gst_element_provide_clock()
66 * method one can retrieve the clock provided by such an element.
67 * Not all elements require a clock to operate correctly. If
68 * gst_element_requires_clock() returns TRUE, a clock should be set on the
69 * element with gst_element_set_clock().
71 * Note that clock slection and distribution is normally handled by the
72 * toplevel #GstPipeline so the clock functions are only to be used in very
73 * specific situations.
75 * Last reviewed on 2005-11-23 (0.9.5)
78 #include "gst_private.h"
81 #include <gobject/gvaluecollector.h>
83 #include "gstelement.h"
85 #include "gstmarshal.h"
90 #include "gst-i18n-lib.h"
92 /* Element signals and args */
108 extern void __gst_element_details_clear (GstElementDetails * dp);
109 extern void __gst_element_details_copy (GstElementDetails * dest,
110 const GstElementDetails * src);
112 static void gst_element_class_init (GstElementClass * klass);
113 static void gst_element_init (GstElement * element);
114 static void gst_element_base_class_init (gpointer g_class);
115 static void gst_element_base_class_finalize (gpointer g_class);
117 static void gst_element_dispose (GObject * object);
118 static void gst_element_finalize (GObject * object);
120 static GstStateChangeReturn gst_element_change_state (GstElement * element,
121 GstStateChange transition);
122 static GstStateChangeReturn gst_element_change_state_func (GstElement * element,
123 GstStateChange transition);
124 static GstStateChangeReturn gst_element_get_state_func (GstElement * element,
125 GstState * state, GstState * pending, GstClockTime timeout);
126 static GstStateChangeReturn gst_element_set_state_func (GstElement * element,
128 static void gst_element_set_bus_func (GstElement * element, GstBus * bus);
130 #ifndef GST_DISABLE_LOADSAVE
131 static xmlNodePtr gst_element_save_thyself (GstObject * object,
133 static void gst_element_restore_thyself (GstObject * parent, xmlNodePtr self);
136 static GstObjectClass *parent_class = NULL;
137 static guint gst_element_signals[LAST_SIGNAL] = { 0 };
140 gst_element_get_type (void)
142 static GType gst_element_type = 0;
144 if (!gst_element_type) {
145 static const GTypeInfo element_info = {
146 sizeof (GstElementClass),
147 gst_element_base_class_init,
148 gst_element_base_class_finalize,
149 (GClassInitFunc) gst_element_class_init,
154 (GInstanceInitFunc) gst_element_init,
158 gst_element_type = g_type_register_static (GST_TYPE_OBJECT, "GstElement",
159 &element_info, G_TYPE_FLAG_ABSTRACT);
161 return gst_element_type;
165 gst_element_class_init (GstElementClass * klass)
167 GObjectClass *gobject_class;
168 GstObjectClass *gstobject_class;
170 gobject_class = (GObjectClass *) klass;
171 gstobject_class = (GstObjectClass *) klass;
173 parent_class = g_type_class_ref (GST_TYPE_OBJECT);
176 * GstElement::pad-added:
177 * @gstelement: the object which received the signal
178 * @new_pad: the pad that has been added
180 * a new #GstPad has been added to the element.
182 gst_element_signals[NEW_PAD] =
183 g_signal_new ("pad-added", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
184 G_STRUCT_OFFSET (GstElementClass, pad_added), NULL, NULL,
185 gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, G_TYPE_OBJECT);
187 * GstElement::pad-removed:
188 * @gstelement: the object which received the signal
189 * @old_pad: the pad that has been removed
191 * a #GstPad has been removed from the element
193 gst_element_signals[PAD_REMOVED] =
194 g_signal_new ("pad-removed", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
195 G_STRUCT_OFFSET (GstElementClass, pad_removed), NULL, NULL,
196 gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, G_TYPE_OBJECT);
198 * GstElement::no-more-pads:
199 * @gstelement: the object which received the signal
201 * This signals that the element will not generate more dynamic pads.
203 gst_element_signals[NO_MORE_PADS] =
204 g_signal_new ("no-more-pads", G_TYPE_FROM_CLASS (klass),
205 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstElementClass, no_more_pads), NULL,
206 NULL, gst_marshal_VOID__VOID, G_TYPE_NONE, 0);
208 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_element_dispose);
209 gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_element_finalize);
211 #ifndef GST_DISABLE_LOADSAVE
212 gstobject_class->save_thyself = GST_DEBUG_FUNCPTR (gst_element_save_thyself);
213 gstobject_class->restore_thyself =
214 GST_DEBUG_FUNCPTR (gst_element_restore_thyself);
217 klass->change_state = GST_DEBUG_FUNCPTR (gst_element_change_state_func);
218 klass->set_state = GST_DEBUG_FUNCPTR (gst_element_set_state_func);
219 klass->get_state = GST_DEBUG_FUNCPTR (gst_element_get_state_func);
220 klass->set_bus = GST_DEBUG_FUNCPTR (gst_element_set_bus_func);
221 klass->numpadtemplates = 0;
223 klass->elementfactory = NULL;
227 gst_element_base_class_init (gpointer g_class)
229 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
231 memset (&element_class->details, 0, sizeof (GstElementDetails));
232 element_class->padtemplates = NULL;
236 gst_element_base_class_finalize (gpointer g_class)
238 GstElementClass *klass = GST_ELEMENT_CLASS (g_class);
240 g_list_foreach (klass->padtemplates, (GFunc) gst_object_unref, NULL);
241 g_list_free (klass->padtemplates);
242 __gst_element_details_clear (&klass->details);
246 gst_element_init (GstElement * element)
248 GST_STATE (element) = GST_STATE_NULL;
249 GST_STATE_NEXT (element) = GST_STATE_VOID_PENDING;
250 GST_STATE_PENDING (element) = GST_STATE_VOID_PENDING;
251 GST_STATE_RETURN (element) = GST_STATE_CHANGE_SUCCESS;
253 element->state_lock = g_new0 (GStaticRecMutex, 1);
254 g_static_rec_mutex_init (element->state_lock);
255 element->state_cond = g_cond_new ();
259 * gst_element_default_error:
260 * @object: a #GObject that signalled the error.
261 * @orig: the #GstObject that initiated the error.
262 * @error: the GError.
263 * @debug: an additional debug information string, or NULL.
265 * A default error signal callback to attach to an element.
266 * The user data passed to the g_signal_connect is ignored.
268 * The default handler will simply print the error string using g_print.
273 gst_element_default_error (GObject * object, GstObject * source, GError * error,
276 gchar *name = gst_object_get_path_string (source);
278 g_print (_("ERROR: from element %s: %s\n"), name, error->message);
280 g_print (_("Additional debug info:\n%s\n"), debug);
286 * gst_element_release_request_pad:
287 * @element: a #GstElement to release the request pad of.
288 * @pad: the #GstPad to release.
290 * Makes the element free the previously requested pad as obtained
291 * with gst_element_get_request_pad().
296 gst_element_release_request_pad (GstElement * element, GstPad * pad)
298 GstElementClass *oclass;
300 g_return_if_fail (GST_IS_ELEMENT (element));
301 g_return_if_fail (GST_IS_PAD (pad));
303 oclass = GST_ELEMENT_GET_CLASS (element);
305 if (oclass->release_pad)
306 (oclass->release_pad) (element, pad);
308 gst_element_remove_pad (element, pad);
312 * gst_element_requires_clock:
313 * @element: a #GstElement to query
315 * Query if the element requires a clock.
317 * Returns: TRUE if the element requires a clock
322 gst_element_requires_clock (GstElement * element)
326 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
328 result = (GST_ELEMENT_GET_CLASS (element)->set_clock != NULL);
334 * gst_element_provides_clock:
335 * @element: a #GstElement to query
337 * Query if the element provides a clock. A #GstClock provided by an
338 * element can be used as the global #GstClock for the pipeline.
340 * Returns: TRUE if the element provides a clock
345 gst_element_provides_clock (GstElement * element)
349 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
351 result = (GST_ELEMENT_GET_CLASS (element)->provide_clock != NULL);
357 * gst_element_provide_clock:
358 * @element: a #GstElement to query
360 * Get the clock provided by the given element.
362 * Returns: the GstClock provided by the element or NULL
363 * if no clock could be provided. Unref after usage.
368 gst_element_provide_clock (GstElement * element)
370 GstClock *result = NULL;
371 GstElementClass *oclass;
373 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
375 oclass = GST_ELEMENT_GET_CLASS (element);
377 if (oclass->provide_clock)
378 result = oclass->provide_clock (element);
384 * gst_element_set_clock:
385 * @element: a #GstElement to set the clock for.
386 * @clock: the #GstClock to set for the element.
388 * Sets the clock for the element. This function increases the
389 * refcount on the clock. Any previously set clock on the object
392 * Returns: TRUE if the element accepted the clock.
397 gst_element_set_clock (GstElement * element, GstClock * clock)
399 GstElementClass *oclass;
402 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
404 oclass = GST_ELEMENT_GET_CLASS (element);
406 GST_DEBUG_OBJECT (element, "setting clock %p", clock);
408 if (oclass->set_clock)
409 res = oclass->set_clock (element, clock);
412 GST_OBJECT_LOCK (element);
413 gst_object_replace ((GstObject **) & element->clock, (GstObject *) clock);
414 GST_OBJECT_UNLOCK (element);
420 * gst_element_get_clock:
421 * @element: a #GstElement to get the clock of.
423 * Gets the currently configured clock of the element.
425 * Returns: the #GstClock of the element. unref after usage.
430 gst_element_get_clock (GstElement * element)
434 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
436 GST_OBJECT_LOCK (element);
437 if ((result = element->clock))
438 gst_object_ref (result);
439 GST_OBJECT_UNLOCK (element);
445 * gst_element_set_base_time:
446 * @element: a #GstElement.
447 * @time: the base time to set.
449 * Set the base time of an element. See gst_element_get_base_time().
454 gst_element_set_base_time (GstElement * element, GstClockTime time)
456 g_return_if_fail (GST_IS_ELEMENT (element));
458 GST_OBJECT_LOCK (element);
459 element->base_time = time;
460 GST_OBJECT_UNLOCK (element);
462 GST_DEBUG_OBJECT (element, "set base_time=%" GST_TIME_FORMAT,
463 GST_TIME_ARGS (time));
467 * gst_element_get_base_time:
468 * @element: a #GstElement.
470 * Returns the base time of the element. The base time is the
471 * absolute time of the clock when this element was last put to
472 * PLAYING. Substracting the base time from the clock time gives
473 * the stream time of the element.
475 * Returns: the base time of the element.
480 gst_element_get_base_time (GstElement * element)
484 g_return_val_if_fail (GST_IS_ELEMENT (element), GST_CLOCK_TIME_NONE);
486 GST_OBJECT_LOCK (element);
487 result = element->base_time;
488 GST_OBJECT_UNLOCK (element);
493 #ifndef GST_DISABLE_INDEX
495 * gst_element_is_indexable:
496 * @element: a #GstElement.
498 * Queries if the element can be indexed.
500 * Returns: TRUE if the element can be indexed.
505 gst_element_is_indexable (GstElement * element)
509 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
511 result = (GST_ELEMENT_GET_CLASS (element)->set_index != NULL);
517 * gst_element_set_index:
518 * @element: a #GstElement.
519 * @index: a #GstIndex.
521 * Set @index on the element. The refcount of the index
522 * will be increased, any previously set index is unreffed.
527 gst_element_set_index (GstElement * element, GstIndex * index)
529 GstElementClass *oclass;
531 g_return_if_fail (GST_IS_ELEMENT (element));
532 g_return_if_fail (GST_IS_INDEX (index));
534 oclass = GST_ELEMENT_GET_CLASS (element);
536 if (oclass->set_index)
537 oclass->set_index (element, index);
541 * gst_element_get_index:
542 * @element: a #GstElement.
544 * Gets the index from the element.
546 * Returns: a #GstIndex or NULL when no index was set on the
547 * element. unref after usage.
552 gst_element_get_index (GstElement * element)
554 GstElementClass *oclass;
556 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
558 oclass = GST_ELEMENT_GET_CLASS (element);
560 if (oclass->get_index)
561 return oclass->get_index (element);
568 * gst_element_add_pad:
569 * @element: a #GstElement to add the pad to.
570 * @pad: the #GstPad to add to the element.
572 * Adds a pad (link point) to @element. @pad's parent will be set to @element;
573 * see gst_object_set_parent() for refcounting information.
575 * Pads are not automatically activated so elements should perform the needed
576 * steps to activate the pad in case this pad is added in the PAUSED or PLAYING
579 * The pad and the element should be unlocked when calling this function.
581 * Returns: TRUE if the pad could be added. This function can fail when
582 * a pad with the same name already existed or the pad already had another
588 gst_element_add_pad (GstElement * element, GstPad * pad)
592 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
593 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
595 /* locking pad to look at the name */
596 GST_OBJECT_LOCK (pad);
597 pad_name = g_strdup (GST_PAD_NAME (pad));
598 GST_CAT_INFO_OBJECT (GST_CAT_ELEMENT_PADS, element, "adding pad '%s'",
599 GST_STR_NULL (pad_name));
600 GST_OBJECT_UNLOCK (pad);
602 /* then check to see if there's already a pad by that name here */
603 GST_OBJECT_LOCK (element);
604 if (G_UNLIKELY (!gst_object_check_uniqueness (element->pads, pad_name)))
607 /* try to set the pad's parent */
608 if (G_UNLIKELY (!gst_object_set_parent (GST_OBJECT_CAST (pad),
609 GST_OBJECT_CAST (element))))
614 /* add it to the list */
615 switch (gst_pad_get_direction (pad)) {
617 element->srcpads = g_list_prepend (element->srcpads, pad);
618 element->numsrcpads++;
621 element->sinkpads = g_list_prepend (element->sinkpads, pad);
622 element->numsinkpads++;
627 element->pads = g_list_prepend (element->pads, pad);
629 element->pads_cookie++;
630 GST_OBJECT_UNLOCK (element);
632 /* emit the NEW_PAD signal */
633 g_signal_emit (G_OBJECT (element), gst_element_signals[NEW_PAD], 0, pad);
640 g_critical ("Padname %s is not unique in element %s, not adding",
641 pad_name, GST_ELEMENT_NAME (element));
642 GST_OBJECT_UNLOCK (element);
649 ("Pad %s already has parent when trying to add to element %s",
650 pad_name, GST_ELEMENT_NAME (element));
651 GST_OBJECT_UNLOCK (element);
657 GST_OBJECT_LOCK (pad);
659 ("Trying to add pad %s to element %s, but it has no direction",
660 GST_OBJECT_NAME (pad), GST_ELEMENT_NAME (element));
661 GST_OBJECT_UNLOCK (pad);
662 GST_OBJECT_UNLOCK (element);
668 * gst_element_remove_pad:
669 * @element: a #GstElement to remove pad from.
670 * @pad: the #GstPad to remove from the element.
672 * Removes @pad from @element. @pad will be destroyed if it has not been
673 * referenced elsewhere.
675 * Returns: TRUE if the pad could be removed. Can return FALSE if the
676 * pad is not belonging to the provided element.
681 gst_element_remove_pad (GstElement * element, GstPad * pad)
685 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
686 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
688 /* locking pad to look at the name and parent */
689 GST_OBJECT_LOCK (pad);
690 GST_CAT_INFO_OBJECT (GST_CAT_ELEMENT_PADS, element, "removing pad '%s'",
691 GST_STR_NULL (GST_PAD_NAME (pad)));
693 if (G_UNLIKELY (GST_PAD_PARENT (pad) != element))
695 GST_OBJECT_UNLOCK (pad);
698 if ((peer = gst_pad_get_peer (pad))) {
699 /* window for MT unsafeness, someone else could unlink here
700 * and then we call unlink with wrong pads. The unlink
701 * function would catch this and safely return failed. */
702 if (GST_PAD_IS_SRC (pad))
703 gst_pad_unlink (pad, peer);
705 gst_pad_unlink (peer, pad);
707 gst_object_unref (peer);
710 GST_OBJECT_LOCK (element);
711 /* remove it from the list */
712 switch (gst_pad_get_direction (pad)) {
714 element->srcpads = g_list_remove (element->srcpads, pad);
715 element->numsrcpads--;
718 element->sinkpads = g_list_remove (element->sinkpads, pad);
719 element->numsinkpads--;
722 g_critical ("Removing pad without direction???");
725 element->pads = g_list_remove (element->pads, pad);
727 element->pads_cookie++;
728 GST_OBJECT_UNLOCK (element);
730 g_signal_emit (G_OBJECT (element), gst_element_signals[PAD_REMOVED], 0, pad);
732 gst_object_unparent (GST_OBJECT (pad));
738 /* FIXME, locking order? */
739 GST_OBJECT_LOCK (element);
740 g_critical ("Padname %s:%s does not belong to element %s when removing",
741 GST_ELEMENT_NAME (GST_PAD_PARENT (pad)), GST_PAD_NAME (pad),
742 GST_ELEMENT_NAME (element));
743 GST_OBJECT_UNLOCK (element);
744 GST_OBJECT_UNLOCK (pad);
750 * gst_element_no_more_pads:
751 * @element: a #GstElement
753 * Use this function to signal that the element does not expect any more pads
754 * to show up in the current pipeline. This function should be called whenever
755 * pads have been added by the element itself. Elements with #GST_PAD_SOMETIMES
756 * pad templates use this in combination with autopluggers to figure out that
757 * the element is done initializing its pads.
762 gst_element_no_more_pads (GstElement * element)
764 g_return_if_fail (GST_IS_ELEMENT (element));
766 g_signal_emit (element, gst_element_signals[NO_MORE_PADS], 0);
770 pad_compare_name (GstPad * pad1, const gchar * name)
774 GST_OBJECT_LOCK (pad1);
775 result = strcmp (GST_PAD_NAME (pad1), name);
776 GST_OBJECT_UNLOCK (pad1);
782 * gst_element_get_static_pad:
783 * @element: a #GstElement to find a static pad of.
784 * @name: the name of the static #GstPad to retrieve.
786 * Retrieves a pad from @element by name. This version only retrieves
787 * already-existing (i.e. 'static') pads.
789 * Returns: the requested #GstPad if found, otherwise NULL. unref after
795 gst_element_get_static_pad (GstElement * element, const gchar * name)
798 GstPad *result = NULL;
800 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
801 g_return_val_if_fail (name != NULL, NULL);
803 GST_OBJECT_LOCK (element);
805 g_list_find_custom (element->pads, name, (GCompareFunc) pad_compare_name);
807 result = GST_PAD_CAST (find->data);
808 gst_object_ref (result);
811 if (result == NULL) {
812 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "no such pad '%s' in element \"%s\"",
813 name, GST_ELEMENT_NAME (element));
815 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "found pad %s:%s",
816 GST_ELEMENT_NAME (element), name);
818 GST_OBJECT_UNLOCK (element);
824 gst_element_request_pad (GstElement * element, GstPadTemplate * templ,
827 GstPad *newpad = NULL;
828 GstElementClass *oclass;
830 oclass = GST_ELEMENT_GET_CLASS (element);
832 if (oclass->request_new_pad)
833 newpad = (oclass->request_new_pad) (element, templ, name);
836 gst_object_ref (newpad);
842 * gst_element_get_request_pad:
843 * @element: a #GstElement to find a request pad of.
844 * @name: the name of the request #GstPad to retrieve.
846 * Retrieves a pad from the element by name. This version only retrieves
849 * Returns: requested #GstPad if found, otherwise NULL. Unref after usage.
852 gst_element_get_request_pad (GstElement * element, const gchar * name)
854 GstPadTemplate *templ = NULL;
856 const gchar *req_name = NULL;
857 gboolean templ_found = FALSE;
861 gchar *str, *endptr = NULL;
862 GstElementClass *class;
864 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
865 g_return_val_if_fail (name != NULL, NULL);
867 class = GST_ELEMENT_GET_CLASS (element);
869 if (strstr (name, "%")) {
870 templ = gst_element_class_get_pad_template (class, name);
875 list = gst_element_class_get_pad_template_list (class);
876 while (!templ_found && list) {
877 templ = (GstPadTemplate *) list->data;
878 if (templ->presence == GST_PAD_REQUEST) {
879 /* Because of sanity checks in gst_pad_template_new(), we know that %s
880 and %d, occurring at the end of the name_template, are the only
882 GST_CAT_DEBUG (GST_CAT_PADS, "comparing %s to %s", name,
883 templ->name_template);
884 if ((str = strchr (templ->name_template, '%'))
885 && strncmp (templ->name_template, name,
886 str - templ->name_template) == 0
887 && strlen (name) > str - templ->name_template) {
888 data = name + (str - templ->name_template);
889 if (*(str + 1) == 'd') {
891 n = (gint) strtol (data, &endptr, 10);
892 if (endptr && *endptr == '\0') {
912 pad = gst_element_request_pad (element, templ, req_name);
918 * gst_element_get_pad:
919 * @element: a #GstElement.
920 * @name: the name of the pad to retrieve.
922 * Retrieves a pad from @element by name. Tries gst_element_get_static_pad()
923 * first, then gst_element_get_request_pad().
925 * Returns: the #GstPad if found, otherwise %NULL. Unref after usage.
928 gst_element_get_pad (GstElement * element, const gchar * name)
932 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
933 g_return_val_if_fail (name != NULL, NULL);
935 pad = gst_element_get_static_pad (element, name);
937 pad = gst_element_get_request_pad (element, name);
942 static GstIteratorItem
943 iterate_pad (GstIterator * it, GstPad * pad)
945 gst_object_ref (pad);
946 return GST_ITERATOR_ITEM_PASS;
950 gst_element_iterate_pad_list (GstElement * element, GList ** padlist)
954 GST_OBJECT_LOCK (element);
955 gst_object_ref (element);
956 result = gst_iterator_new_list (GST_TYPE_PAD,
957 GST_OBJECT_GET_LOCK (element),
958 &element->pads_cookie,
961 (GstIteratorItemFunction) iterate_pad,
962 (GstIteratorDisposeFunction) gst_object_unref);
963 GST_OBJECT_UNLOCK (element);
969 * gst_element_iterate_pads:
970 * @element: a #GstElement to iterate pads of.
972 * Retrieves an iterattor of @element's pads. The iterator should
973 * be freed after usage.
975 * Returns: the #GstIterator of #GstPad. Unref each pad after use.
980 gst_element_iterate_pads (GstElement * element)
982 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
984 return gst_element_iterate_pad_list (element, &element->pads);
988 * gst_element_iterate_src_pads:
989 * @element: a #GstElement.
991 * Retrieves an iterator of @element's source pads.
993 * Returns: the #GstIterator of #GstPad. Unref each pad after use.
998 gst_element_iterate_src_pads (GstElement * element)
1000 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
1002 return gst_element_iterate_pad_list (element, &element->srcpads);
1006 * gst_element_iterate_sink_pads:
1007 * @element: a #GstElement.
1009 * Retrieves an iterator of @element's sink pads.
1011 * Returns: the #GstIterator of #GstPad. Unref each pad after use.
1016 gst_element_iterate_sink_pads (GstElement * element)
1018 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
1020 return gst_element_iterate_pad_list (element, &element->sinkpads);
1024 * gst_element_class_add_pad_template:
1025 * @klass: the #GstElementClass to add the pad template to.
1026 * @templ: a #GstPadTemplate to add to the element class.
1028 * Adds a padtemplate to an element class. This is mainly used in the _base_init
1029 * functions of classes.
1032 gst_element_class_add_pad_template (GstElementClass * klass,
1033 GstPadTemplate * templ)
1035 g_return_if_fail (GST_IS_ELEMENT_CLASS (klass));
1036 g_return_if_fail (GST_IS_PAD_TEMPLATE (templ));
1038 /* avoid registering pad templates with the same name */
1039 g_return_if_fail (gst_element_class_get_pad_template (klass,
1040 templ->name_template) == NULL);
1042 klass->padtemplates = g_list_append (klass->padtemplates,
1043 gst_object_ref (templ));
1044 klass->numpadtemplates++;
1048 * gst_element_class_set_details:
1049 * @klass: class to set details for
1050 * @details: details to set
1052 * Sets the detailed information for a #GstElementClass.
1053 * <note>This function is for use in _base_init functions only.</note>
1056 gst_element_class_set_details (GstElementClass * klass,
1057 const GstElementDetails * details)
1059 g_return_if_fail (GST_IS_ELEMENT_CLASS (klass));
1060 g_return_if_fail (GST_IS_ELEMENT_DETAILS (details));
1062 __gst_element_details_copy (&klass->details, details);
1066 * gst_element_class_get_pad_template_list:
1067 * @element_class: a #GstElementClass to get pad templates of.
1069 * Retrieves a list of the pad templates associated with @element_class. The
1070 * list must not be modified by the calling code.
1071 * <note>If you use this function in the #GInstanceInitFunc of an object class
1072 * that has subclasses, make sure to pass the g_class parameter of the
1073 * #GInstanceInitFunc here.</note>
1075 * Returns: the #GList of padtemplates.
1078 gst_element_class_get_pad_template_list (GstElementClass * element_class)
1080 g_return_val_if_fail (GST_IS_ELEMENT_CLASS (element_class), NULL);
1082 return element_class->padtemplates;
1086 * gst_element_class_get_pad_template:
1087 * @element_class: a #GstElementClass to get the pad template of.
1088 * @name: the name of the #GstPadTemplate to get.
1090 * Retrieves a padtemplate from @element_class with the given name.
1091 * <note>If you use this function in the #GInstanceInitFunc of an object class
1092 * that has subclasses, make sure to pass the g_class parameter of the
1093 * #GInstanceInitFunc here.</note>
1095 * Returns: the #GstPadTemplate with the given name, or NULL if none was found.
1096 * No unreferencing is necessary.
1099 gst_element_class_get_pad_template (GstElementClass * element_class,
1104 g_return_val_if_fail (GST_IS_ELEMENT_CLASS (element_class), NULL);
1105 g_return_val_if_fail (name != NULL, NULL);
1107 padlist = gst_element_class_get_pad_template_list (element_class);
1110 GstPadTemplate *padtempl = (GstPadTemplate *) padlist->data;
1112 if (strcmp (padtempl->name_template, name) == 0)
1115 padlist = g_list_next (padlist);
1122 gst_element_get_random_pad (GstElement * element, GstPadDirection dir)
1124 GstPad *result = NULL;
1127 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "getting a random pad");
1131 GST_OBJECT_LOCK (element);
1132 pads = element->srcpads;
1135 GST_OBJECT_LOCK (element);
1136 pads = element->sinkpads;
1139 goto wrong_direction;
1141 for (; pads; pads = g_list_next (pads)) {
1142 GstPad *pad = GST_PAD (pads->data);
1144 GST_OBJECT_LOCK (pad);
1145 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "checking pad %s:%s",
1146 GST_DEBUG_PAD_NAME (pad));
1148 if (GST_PAD_IS_LINKED (pad)) {
1149 GST_OBJECT_UNLOCK (pad);
1153 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "pad %s:%s is not linked",
1154 GST_DEBUG_PAD_NAME (pad));
1156 GST_OBJECT_UNLOCK (pad);
1159 gst_object_ref (result);
1161 GST_OBJECT_UNLOCK (element);
1165 /* ERROR handling */
1168 g_warning ("unknown pad direction %d", dir);
1174 * gst_element_send_event:
1175 * @element: a #GstElement to send the event to.
1176 * @event: the #GstEvent to send to the element.
1178 * Sends an event to an element. If the element doesn't
1179 * implement an event handler, the event will be forwarded
1180 * to a random sink pad. This function takes owership of the
1181 * provided event so you should gst_event_ref() it if you want to reuse
1182 * the event after this call.
1184 * Returns: TRUE if the event was handled.
1189 gst_element_send_event (GstElement * element, GstEvent * event)
1191 GstElementClass *oclass;
1192 gboolean result = FALSE;
1194 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
1195 g_return_val_if_fail (event != NULL, FALSE);
1197 oclass = GST_ELEMENT_GET_CLASS (element);
1199 if (oclass->send_event) {
1200 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "send %s event on element %s",
1201 GST_EVENT_TYPE_NAME (event), GST_ELEMENT_NAME (element));
1202 result = oclass->send_event (element, event);
1204 GstPad *pad = GST_EVENT_IS_DOWNSTREAM (event) ?
1205 gst_element_get_random_pad (element, GST_PAD_SRC) :
1206 gst_element_get_random_pad (element, GST_PAD_SINK);
1209 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
1210 "pushing %s event to random %s pad %s:%s",
1211 GST_EVENT_TYPE_NAME (event),
1212 (GST_PAD_DIRECTION (pad) == GST_PAD_SRC ? "src" : "sink"),
1213 GST_DEBUG_PAD_NAME (pad));
1215 result = gst_pad_push_event (pad, event);
1216 gst_object_unref (pad);
1218 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "can't send %s event on element %s",
1219 GST_EVENT_TYPE_NAME (event), GST_ELEMENT_NAME (element));
1227 * @element: a #GstElement to send the event to.
1228 * @rate: The new playback rate
1229 * @format: The format of the seek values
1230 * @flags: The optional seek flags.
1231 * @cur_type: The type and flags for the new current position
1232 * @cur: The value of the new current position
1233 * @stop_type: The type and flags for the new stop position
1234 * @stop: The value of the new stop position
1236 * Sends a seek event to an element.
1238 * Returns: %TRUE if the event was handled.
1243 gst_element_seek (GstElement * element, gdouble rate, GstFormat format,
1244 GstSeekFlags flags, GstSeekType cur_type, gint64 cur,
1245 GstSeekType stop_type, gint64 stop)
1250 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
1253 gst_event_new_seek (rate, format, flags, cur_type, cur, stop_type, stop);
1254 result = gst_element_send_event (element, event);
1260 * gst_element_get_query_types:
1261 * @element: a #GstElement to query
1263 * Get an array of query types from the element.
1264 * If the element doesn't implement a query types function,
1265 * the query will be forwarded to a random sink pad.
1267 * Returns: An array of #GstQueryType elements that should not
1268 * be freed or modified.
1272 const GstQueryType *
1273 gst_element_get_query_types (GstElement * element)
1275 GstElementClass *oclass;
1276 const GstQueryType *result = NULL;
1278 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
1280 oclass = GST_ELEMENT_GET_CLASS (element);
1282 if (oclass->get_query_types) {
1283 result = oclass->get_query_types (element);
1285 GstPad *pad = gst_element_get_random_pad (element, GST_PAD_SINK);
1288 GstPad *peer = gst_pad_get_peer (pad);
1291 result = gst_pad_get_query_types (peer);
1293 gst_object_unref (peer);
1295 gst_object_unref (pad);
1302 * gst_element_query:
1303 * @element: a #GstElement to perform the query on.
1304 * @query: the #GstQuery.
1306 * Performs a query on the given element. If the format is set
1307 * to #GST_FORMAT_DEFAULT and this function returns TRUE, the
1308 * format pointer will hold the default format.
1309 * For element that don't implement a query handler, this function
1310 * forwards the query to a random usable sinkpad of this element.
1312 * Returns: TRUE if the query could be performed.
1317 gst_element_query (GstElement * element, GstQuery * query)
1319 GstElementClass *oclass;
1320 gboolean result = FALSE;
1322 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
1323 g_return_val_if_fail (query != NULL, FALSE);
1325 oclass = GST_ELEMENT_GET_CLASS (element);
1327 if (oclass->query) {
1328 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "send query on element %s",
1329 GST_ELEMENT_NAME (element));
1330 result = oclass->query (element, query);
1332 GstPad *pad = gst_element_get_random_pad (element, GST_PAD_SRC);
1335 result = gst_pad_query (pad, query);
1337 gst_object_unref (pad);
1339 pad = gst_element_get_random_pad (element, GST_PAD_SINK);
1341 GstPad *peer = gst_pad_get_peer (pad);
1344 result = gst_pad_query (peer, query);
1346 gst_object_unref (peer);
1348 gst_object_unref (pad);
1356 * gst_element_post_message:
1357 * @element: a #GstElement posting the message
1358 * @message: a #GstMessage to post
1360 * Post a message on the element's #GstBus. This function takes ownership of the
1361 * message; if you want to access the message after this call, you should add an
1362 * additional reference before calling.
1364 * Returns: TRUE if the message was successfully posted.
1369 gst_element_post_message (GstElement * element, GstMessage * message)
1372 gboolean result = FALSE;
1374 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
1375 g_return_val_if_fail (message != NULL, FALSE);
1377 GST_OBJECT_LOCK (element);
1380 if (G_UNLIKELY (bus == NULL))
1383 gst_object_ref (bus);
1384 GST_OBJECT_UNLOCK (element);
1386 result = gst_bus_post (bus, message);
1387 gst_object_unref (bus);
1393 GST_DEBUG ("not posting message %p: no bus", message);
1394 GST_OBJECT_UNLOCK (element);
1395 gst_message_unref (message);
1401 * _gst_element_error_printf:
1402 * @format: the printf-like format to use, or NULL
1404 * This function is only used internally by the #gst_element_error macro.
1406 * Returns: a newly allocated string, or NULL if the format was NULL or ""
1411 _gst_element_error_printf (const gchar * format, ...)
1421 va_start (args, format);
1422 buffer = g_strdup_vprintf (format, args);
1428 * gst_element_message_full:
1429 * @element: a #GstElement to send message from
1430 * @type: the #GstMessageType
1431 * @domain: the GStreamer GError domain this message belongs to
1432 * @code: the GError code belonging to the domain
1433 * @text: an allocated text string to be used as a replacement for the
1434 * default message connected to code, or NULL
1435 * @debug: an allocated debug message to be used as a replacement for the
1436 * default debugging information, or NULL
1437 * @file: the source code file where the error was generated
1438 * @function: the source code function where the error was generated
1439 * @line: the source code line where the error was generated
1441 * Post an error or warning message on the bus from inside an element.
1445 void gst_element_message_full
1446 (GstElement * element, GstMessageType type,
1447 GQuark domain, gint code, gchar * text,
1448 gchar * debug, const gchar * file, const gchar * function, gint line)
1450 GError *gerror = NULL;
1454 GstMessage *message = NULL;
1457 GST_DEBUG ("start");
1458 g_return_if_fail (GST_IS_ELEMENT (element));
1459 g_return_if_fail ((type == GST_MESSAGE_ERROR) ||
1460 (type == GST_MESSAGE_WARNING));
1462 /* check if we send the given text or the default error text */
1463 if ((text == NULL) || (text[0] == 0)) {
1464 /* text could have come from g_strdup_printf (""); */
1466 sent_text = gst_error_get_message (domain, code);
1470 /* construct a sent_debug with extra information from source */
1471 if ((debug == NULL) || (debug[0] == 0)) {
1472 /* debug could have come from g_strdup_printf (""); */
1475 name = gst_object_get_path_string (GST_OBJECT (element));
1476 sent_debug = g_strdup_printf ("%s(%d): %s: %s:\n%s",
1477 file, line, function, name, debug ? debug : "");
1482 /* create gerror and post message */
1483 GST_CAT_INFO_OBJECT (GST_CAT_ERROR_SYSTEM, element, "posting message: %s",
1485 gerror = g_error_new_literal (domain, code, sent_text);
1487 if (type == GST_MESSAGE_ERROR) {
1488 message = gst_message_new_error (GST_OBJECT (element), gerror, sent_debug);
1489 } else if (type == GST_MESSAGE_WARNING) {
1490 message = gst_message_new_warning (GST_OBJECT (element), gerror,
1493 g_assert_not_reached ();
1495 gst_element_post_message (element, message);
1497 GST_CAT_INFO_OBJECT (GST_CAT_ERROR_SYSTEM, element, "posted message: %s",
1501 g_error_free (gerror);
1502 g_free (sent_debug);
1507 * gst_element_is_locked_state:
1508 * @element: a #GstElement.
1510 * Checks if the state of an element is locked.
1511 * If the state of an element is locked, state changes of the parent don't
1512 * affect the element.
1513 * This way you can leave currently unused elements inside bins. Just lock their
1514 * state before changing the state from #GST_STATE_NULL.
1518 * Returns: TRUE, if the element's state is locked.
1521 gst_element_is_locked_state (GstElement * element)
1525 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
1527 GST_OBJECT_LOCK (element);
1528 result = GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_LOCKED_STATE);
1529 GST_OBJECT_UNLOCK (element);
1535 * gst_element_set_locked_state:
1536 * @element: a #GstElement
1537 * @locked_state: TRUE to lock the element's state
1539 * Locks the state of an element, so state changes of the parent don't affect
1540 * this element anymore.
1544 * Returns: TRUE if the state was changed, FALSE if bad parameterss were given
1545 * or the elements state-locking needed no change.
1548 gst_element_set_locked_state (GstElement * element, gboolean locked_state)
1552 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
1554 GST_OBJECT_LOCK (element);
1555 old = GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_LOCKED_STATE);
1557 if (G_UNLIKELY (old == locked_state))
1561 GST_CAT_DEBUG (GST_CAT_STATES, "locking state of element %s",
1562 GST_ELEMENT_NAME (element));
1563 GST_OBJECT_FLAG_SET (element, GST_ELEMENT_LOCKED_STATE);
1565 GST_CAT_DEBUG (GST_CAT_STATES, "unlocking state of element %s",
1566 GST_ELEMENT_NAME (element));
1567 GST_OBJECT_FLAG_UNSET (element, GST_ELEMENT_LOCKED_STATE);
1569 GST_OBJECT_UNLOCK (element);
1574 GST_OBJECT_UNLOCK (element);
1580 * gst_element_sync_state_with_parent:
1581 * @element: a #GstElement.
1583 * Tries to change the state of the element to the same as its parent.
1584 * If this function returns FALSE, the state of element is undefined.
1586 * Returns: TRUE, if the element's state could be synced to the parent's state.
1591 gst_element_sync_state_with_parent (GstElement * element)
1595 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
1597 if ((parent = GST_ELEMENT_CAST (gst_element_get_parent (element)))) {
1598 GstState parent_current, parent_pending;
1599 GstStateChangeReturn ret;
1601 GST_OBJECT_LOCK (parent);
1602 parent_current = GST_STATE (parent);
1603 parent_pending = GST_STATE_PENDING (parent);
1604 GST_OBJECT_UNLOCK (parent);
1606 GST_CAT_DEBUG (GST_CAT_STATES,
1607 "syncing state of element %s (%s) to %s (%s, %s)",
1608 GST_ELEMENT_NAME (element),
1609 gst_element_state_get_name (GST_STATE (element)),
1610 GST_ELEMENT_NAME (parent), gst_element_state_get_name (parent_current),
1611 gst_element_state_get_name (parent_pending));
1613 ret = gst_element_set_state (element, parent_current);
1614 if (ret == GST_STATE_CHANGE_FAILURE)
1617 gst_object_unref (parent);
1631 static GstStateChangeReturn
1632 gst_element_get_state_func (GstElement * element,
1633 GstState * state, GstState * pending, GstClockTime timeout)
1635 GstStateChangeReturn ret = GST_STATE_CHANGE_FAILURE;
1636 GstState old_pending;
1638 GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element, "getting state");
1640 GST_OBJECT_LOCK (element);
1641 ret = GST_STATE_RETURN (element);
1643 /* we got an error, report immediatly */
1644 if (ret == GST_STATE_CHANGE_FAILURE)
1647 /* we got no_preroll, report immediatly */
1648 if (ret == GST_STATE_CHANGE_NO_PREROLL)
1651 /* no need to wait async if we are not async */
1652 if (ret != GST_STATE_CHANGE_ASYNC)
1655 old_pending = GST_STATE_PENDING (element);
1656 if (old_pending != GST_STATE_VOID_PENDING) {
1657 GTimeVal *timeval, abstimeout;
1660 if (timeout != GST_CLOCK_TIME_NONE) {
1661 glong add = timeout / 1000;
1666 /* make timeout absolute */
1667 g_get_current_time (&abstimeout);
1668 g_time_val_add (&abstimeout, add);
1669 timeval = &abstimeout;
1673 /* get cookie to dected state change during waiting */
1674 cookie = element->state_cookie;
1676 GST_CAT_INFO_OBJECT (GST_CAT_STATES, element,
1677 "waiting for element to commit state");
1679 /* we have a pending state change, wait for it to complete */
1680 if (!GST_STATE_TIMED_WAIT (element, timeval)) {
1681 GST_CAT_INFO_OBJECT (GST_CAT_STATES, element, "timed out");
1682 /* timeout triggered */
1683 ret = GST_STATE_CHANGE_ASYNC;
1685 if (cookie != element->state_cookie)
1688 /* could be success or failure */
1689 if (old_pending == GST_STATE (element)) {
1690 GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element, "got success");
1691 ret = GST_STATE_CHANGE_SUCCESS;
1693 GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element, "got failure");
1694 ret = GST_STATE_CHANGE_FAILURE;
1698 /* if nothing is pending anymore we can return SUCCESS */
1699 if (GST_STATE_PENDING (element) == GST_STATE_VOID_PENDING) {
1700 GST_CAT_LOG_OBJECT (GST_CAT_STATES, element, "nothing pending");
1701 ret = GST_STATE_CHANGE_SUCCESS;
1706 *state = GST_STATE (element);
1708 *pending = GST_STATE_PENDING (element);
1710 GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element,
1711 "state current: %s, pending: %s, result: %d",
1712 gst_element_state_get_name (GST_STATE (element)),
1713 gst_element_state_get_name (GST_STATE_PENDING (element)), ret);
1714 GST_OBJECT_UNLOCK (element);
1721 *state = GST_STATE_VOID_PENDING;
1723 *pending = GST_STATE_VOID_PENDING;
1725 GST_CAT_INFO_OBJECT (GST_CAT_STATES, element, "get_state() interruped");
1727 GST_OBJECT_UNLOCK (element);
1729 return GST_STATE_CHANGE_FAILURE;
1734 * gst_element_get_state:
1735 * @element: a #GstElement to get the state of.
1736 * @state: a pointer to #GstState to hold the state. Can be NULL.
1737 * @pending: a pointer to #GstState to hold the pending state.
1739 * @timeout: a #GstClockTime to specify the timeout for an async
1740 * state change or GST_CLOCK_TIME_NONE for infinite timeout.
1742 * Gets the state of the element.
1744 * For elements that performed an ASYNC state change, as reported by
1745 * #gst_element_set_state(), this function will block up to the
1746 * specified timeout value for the state change to complete.
1747 * If the element completes the state change or goes into
1748 * an error, this function returns immediately with a return value of
1749 * #GST_STATE_CHANGE_SUCCESS or #GST_STATE_CHANGE_FAILURE respectively.
1751 * For elements that did not return #GST_STATE_CHANGE_ASYNC, this function
1752 * returns the current and pending state immediately.
1754 * This function returns #GST_STATE_CHANGE_NO_PREROLL if the element
1755 * successfully changed its state but is not able to provide data yet.
1757 * happens for live sources that only produce data in the PLAYING state.
1758 * While the state change return is equivalent to #GST_STATE_CHANGE_SUCCESS, it
1759 * is returned to the application to signal that some sink elements might not
1760 * be able to complete their state change because an element is not producing
1761 * data to complete the preroll. When setting the element to playing,
1762 * the preroll will complete and playback will start.
1764 * Returns: #GST_STATE_CHANGE_SUCCESS if the element has no more pending state
1765 * and the last state change succeeded, #GST_STATE_CHANGE_ASYNC if the
1766 * element is still performing a state change or
1767 * #GST_STATE_CHANGE_FAILURE if the last state change failed.
1771 GstStateChangeReturn
1772 gst_element_get_state (GstElement * element,
1773 GstState * state, GstState * pending, GstClockTime timeout)
1775 GstElementClass *oclass;
1776 GstStateChangeReturn result = GST_STATE_CHANGE_FAILURE;
1778 g_return_val_if_fail (GST_IS_ELEMENT (element), GST_STATE_CHANGE_FAILURE);
1780 oclass = GST_ELEMENT_GET_CLASS (element);
1782 if (oclass->get_state)
1783 result = (oclass->get_state) (element, state, pending, timeout);
1789 * gst_element_abort_state:
1790 * @element: a #GstElement to abort the state of.
1792 * Abort the state change of the element. This function is used
1793 * by elements that do asynchronous state changes and find out
1794 * something is wrong.
1796 * This function should be called with the STATE_LOCK held.
1801 gst_element_abort_state (GstElement * element)
1805 #ifndef GST_DISABLE_GST_DEBUG
1809 g_return_if_fail (GST_IS_ELEMENT (element));
1811 GST_OBJECT_LOCK (element);
1812 pending = GST_STATE_PENDING (element);
1814 if (pending == GST_STATE_VOID_PENDING ||
1815 GST_STATE_RETURN (element) == GST_STATE_CHANGE_FAILURE)
1816 goto nothing_aborted;
1818 #ifndef GST_DISABLE_GST_DEBUG
1819 old_state = GST_STATE (element);
1821 GST_CAT_INFO_OBJECT (GST_CAT_STATES, element,
1822 "aborting state from %s to %s", gst_element_state_get_name (old_state),
1823 gst_element_state_get_name (pending));
1827 GST_STATE_RETURN (element) = GST_STATE_CHANGE_FAILURE;
1829 GST_STATE_BROADCAST (element);
1830 GST_OBJECT_UNLOCK (element);
1836 GST_OBJECT_UNLOCK (element);
1842 * gst_element_continue_state:
1843 * @element: a #GstElement to continue the state change of.
1844 * @ret: The previous state return value
1846 * Commit the state change of the element and proceed to the next
1847 * pending state if any. This function is used
1848 * by elements that do asynchronous state changes.
1849 * The core will normally call this method automatically when an
1850 * element returned SUCCESS from the state change function.
1851 * Elements that return ASYNC from the change_state function should
1852 * eventually call this method from the streaming thread to signal
1853 * successfull state change completion.
1855 * If after calling this method the element still has not reached
1856 * the pending state, the next state change is performed.
1858 * Returns: The result of the commit state change.
1862 GstStateChangeReturn
1863 gst_element_continue_state (GstElement * element, GstStateChangeReturn ret)
1866 GstState old_ret, old_state, old_next;
1867 GstState current, next;
1868 GstMessage *message;
1869 GstStateChange transition;
1871 GST_OBJECT_LOCK (element);
1872 old_ret = GST_STATE_RETURN (element);
1873 GST_STATE_RETURN (element) = ret;
1874 pending = GST_STATE_PENDING (element);
1876 /* check if there is something to commit */
1877 if (pending == GST_STATE_VOID_PENDING)
1878 goto nothing_pending;
1880 old_state = GST_STATE (element);
1881 /* this is the state we should go to next */
1882 old_next = GST_STATE_NEXT (element);
1883 /* update current state */
1884 current = GST_STATE (element) = old_next;
1886 /* see if we reached the final state */
1887 if (pending == current)
1890 next = GST_STATE_GET_NEXT (current, pending);
1891 transition = GST_STATE_TRANSITION (current, next);
1893 GST_STATE_NEXT (element) = next;
1894 GST_OBJECT_UNLOCK (element);
1896 GST_CAT_INFO_OBJECT (GST_CAT_STATES, element,
1897 "committing state from %s to %s, pending %s",
1898 gst_element_state_get_name (old_state),
1899 gst_element_state_get_name (old_next),
1900 gst_element_state_get_name (pending));
1902 message = gst_message_new_state_changed (GST_OBJECT (element),
1903 old_state, old_next, pending);
1904 gst_element_post_message (element, message);
1906 GST_CAT_INFO_OBJECT (GST_CAT_STATES, element,
1907 "continue state change %s to %s, final %s",
1908 gst_element_state_get_name (current),
1909 gst_element_state_get_name (next), gst_element_state_get_name (pending));
1911 ret = gst_element_change_state (element, transition);
1917 GST_CAT_INFO_OBJECT (GST_CAT_STATES, element, "nothing pending");
1918 GST_OBJECT_UNLOCK (element);
1923 GST_STATE_PENDING (element) = GST_STATE_VOID_PENDING;
1924 GST_STATE_NEXT (element) = GST_STATE_VOID_PENDING;
1926 GST_CAT_INFO_OBJECT (GST_CAT_STATES, element, "completed state change");
1927 GST_OBJECT_UNLOCK (element);
1929 /* don't post silly messages with the same state. This can happen
1930 * when an element state is changed to what it already was. For bins
1931 * this can be the result of a lost state, which we check with the
1932 * previous return value.
1933 * We do signal the cond though as a _get_state() might be blocking
1935 if (old_state != old_next || old_ret == GST_STATE_CHANGE_ASYNC) {
1936 message = gst_message_new_state_changed (GST_OBJECT (element),
1937 old_state, old_next, GST_STATE_VOID_PENDING);
1938 gst_element_post_message (element, message);
1941 GST_STATE_BROADCAST (element);
1948 * gst_element_lost_state:
1949 * @element: a #GstElement the state is lost of
1951 * Brings the element to the lost state. The current state of the
1952 * element is copied to the pending state so that any call to
1953 * #gst_element_get_state() will return ASYNC.
1955 * This is mostly used for elements that lost their preroll buffer
1956 * in the PAUSED state after a flush, they become PAUSED again
1957 * if a new preroll buffer is queued.
1958 * This function can only be called when the element is currently
1959 * not in error or an async state change.
1961 * This function can only be called with the STATE_LOCK held.
1966 gst_element_lost_state (GstElement * element)
1968 GstState current_state;
1969 GstMessage *message;
1971 g_return_if_fail (GST_IS_ELEMENT (element));
1973 GST_OBJECT_LOCK (element);
1974 if (GST_STATE_PENDING (element) != GST_STATE_VOID_PENDING ||
1975 GST_STATE_RETURN (element) == GST_STATE_CHANGE_FAILURE)
1978 current_state = GST_STATE (element);
1980 GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element,
1981 "lost state of %s", gst_element_state_get_name (current_state));
1983 GST_STATE_NEXT (element) = current_state;
1984 GST_STATE_PENDING (element) = current_state;
1985 GST_STATE_RETURN (element) = GST_STATE_CHANGE_ASYNC;
1986 GST_OBJECT_UNLOCK (element);
1988 message = gst_message_new_state_changed (GST_OBJECT (element),
1989 current_state, current_state, current_state);
1990 gst_element_post_message (element, message);
1992 /* and mark us dirty */
1993 message = gst_message_new_state_dirty (GST_OBJECT (element));
1994 gst_element_post_message (element, message);
2000 GST_OBJECT_UNLOCK (element);
2006 * gst_element_set_state:
2007 * @element: a #GstElement to change state of.
2008 * @state: the element's new #GstState.
2010 * Sets the state of the element. This function will try to set the
2011 * requested state by going through all the intermediary states and calling
2012 * the class's state change function for each.
2014 * This function can return #GST_STATE_CHANGE_ASYNC, in which case the
2015 * element will perform the remainder of the state change asynchronously in
2017 * An application can use gst_element_get_state() to wait for the completion
2018 * of the state change or it can wait for a state change message on the bus.
2020 * Returns: Result of the state change using #GstStateChangeReturn.
2024 GstStateChangeReturn
2025 gst_element_set_state (GstElement * element, GstState state)
2027 GstElementClass *oclass;
2028 GstStateChangeReturn result = GST_STATE_CHANGE_FAILURE;
2030 g_return_val_if_fail (GST_IS_ELEMENT (element), GST_STATE_CHANGE_FAILURE);
2032 oclass = GST_ELEMENT_GET_CLASS (element);
2034 if (oclass->set_state)
2035 result = (oclass->set_state) (element, state);
2041 * default set state function, calculates the next state based
2042 * on current state and calls the change_state function
2044 static GstStateChangeReturn
2045 gst_element_set_state_func (GstElement * element, GstState state)
2047 GstState current, next, old_pending;
2048 GstStateChangeReturn ret;
2049 GstStateChange transition;
2050 GstStateChangeReturn old_ret;
2052 g_return_val_if_fail (GST_IS_ELEMENT (element), GST_STATE_CHANGE_FAILURE);
2054 GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element, "set_state to %s",
2055 gst_element_state_get_name (state));
2057 /* state lock is taken to protect the set_state() and get_state()
2058 * procedures, it does not lock any variables. */
2059 GST_STATE_LOCK (element);
2061 /* now calculate how to get to the new state */
2062 GST_OBJECT_LOCK (element);
2063 old_ret = GST_STATE_RETURN (element);
2064 /* previous state change returned an error, remove all pending
2065 * and next states */
2066 if (old_ret == GST_STATE_CHANGE_FAILURE) {
2067 GST_STATE_NEXT (element) = GST_STATE_VOID_PENDING;
2068 GST_STATE_PENDING (element) = GST_STATE_VOID_PENDING;
2069 GST_STATE_RETURN (element) = GST_STATE_CHANGE_SUCCESS;
2072 current = GST_STATE (element);
2073 next = GST_STATE_NEXT (element);
2074 old_pending = GST_STATE_PENDING (element);
2075 element->state_cookie++;
2077 /* this is the (new) state we should go to */
2078 GST_STATE_PENDING (element) = state;
2080 GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element,
2081 "current %s, old_pending %s, next %s, old return %d",
2082 gst_element_state_get_name (current),
2083 gst_element_state_get_name (old_pending),
2084 gst_element_state_get_name (next), old_ret);
2086 /* if the element was busy doing a state change, we just update the
2087 * target state, it'll get to it async then. */
2088 if (old_pending != GST_STATE_VOID_PENDING) {
2089 /* upwards state change will happen ASYNC */
2090 if (old_pending <= state)
2092 /* element is going to this state already */
2093 else if (next == state)
2095 /* element was performing an ASYNC upward state change and
2096 * we request to go downward again. Start from the next pending
2098 else if (next > state
2099 && GST_STATE_RETURN (element) == GST_STATE_CHANGE_ASYNC) {
2103 next = GST_STATE_GET_NEXT (current, state);
2104 /* now we store the next state */
2105 GST_STATE_NEXT (element) = next;
2106 transition = GST_STATE_TRANSITION (current, next);
2108 GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element,
2109 "%s: setting state from %s to %s",
2110 (next != state ? "intermediate" : "final"),
2111 gst_element_state_get_name (current), gst_element_state_get_name (next));
2113 /* now signal any waiters, they will error since the cookie was increased */
2114 GST_STATE_BROADCAST (element);
2116 GST_OBJECT_UNLOCK (element);
2118 ret = gst_element_change_state (element, transition);
2120 GST_STATE_UNLOCK (element);
2122 GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element, "returned %d", ret);
2128 GST_STATE_RETURN (element) = GST_STATE_CHANGE_ASYNC;
2129 GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element,
2130 "element was busy with async state change");
2131 GST_OBJECT_UNLOCK (element);
2133 GST_STATE_UNLOCK (element);
2135 return GST_STATE_CHANGE_ASYNC;
2139 /* with STATE_LOCK */
2140 static GstStateChangeReturn
2141 gst_element_change_state (GstElement * element, GstStateChange transition)
2143 GstElementClass *oclass;
2144 GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
2148 oclass = GST_ELEMENT_GET_CLASS (element);
2150 /* start with the current state. */
2151 current = GST_STATE_TRANSITION_CURRENT (transition);
2152 next = GST_STATE_TRANSITION_NEXT (transition);
2154 /* call the state change function so it can set the state */
2155 if (oclass->change_state)
2156 ret = (oclass->change_state) (element, transition);
2158 ret = GST_STATE_CHANGE_FAILURE;
2161 case GST_STATE_CHANGE_FAILURE:
2162 GST_CAT_INFO_OBJECT (GST_CAT_STATES, element,
2163 "have FAILURE change_state return");
2164 /* state change failure */
2165 gst_element_abort_state (element);
2167 case GST_STATE_CHANGE_ASYNC:
2168 GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element,
2169 "element will change state ASYNC");
2171 /* if we go upwards, we give the app a change to wait for
2176 /* else we just continue the state change downwards */
2177 GST_CAT_INFO_OBJECT (GST_CAT_STATES, element,
2178 "forcing commit state %s < %s",
2179 gst_element_state_get_name (current),
2180 gst_element_state_get_name (next));
2182 ret = gst_element_continue_state (element, GST_STATE_CHANGE_SUCCESS);
2184 case GST_STATE_CHANGE_SUCCESS:
2185 GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element,
2186 "element changed state SUCCESS");
2187 /* we can commit the state now which will proceeed to
2189 ret = gst_element_continue_state (element, ret);
2191 case GST_STATE_CHANGE_NO_PREROLL:
2192 GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element,
2193 "element changed state NO_PREROLL");
2194 /* we can commit the state now which will proceeed to
2196 ret = gst_element_continue_state (element, ret);
2199 goto invalid_return;
2202 GST_CAT_LOG_OBJECT (GST_CAT_STATES, element, "exit state change %d", ret);
2207 GST_OBJECT_LOCK (element);
2208 GST_STATE_RETURN (element) = ret;
2209 GST_CAT_LOG_OBJECT (GST_CAT_STATES, element, "exit async state change %d",
2211 GST_OBJECT_UNLOCK (element);
2218 GST_OBJECT_LOCK (element);
2219 /* somebody added a GST_STATE_ and forgot to do stuff here ! */
2220 g_critical ("%s: unknown return value %d from a state change function",
2221 GST_ELEMENT_NAME (element), ret);
2223 ret = GST_STATE_CHANGE_FAILURE;
2224 GST_STATE_RETURN (element) = ret;
2225 GST_OBJECT_UNLOCK (element);
2231 /* gst_iterator_fold functions for pads_activate */
2234 activate_pads (GstPad * pad, GValue * ret, gboolean * active)
2236 if (!gst_pad_set_active (pad, *active))
2237 g_value_set_boolean (ret, FALSE);
2239 gst_pad_set_caps (pad, NULL);
2241 gst_object_unref (pad);
2245 /* returns false on error or early cutout of the fold, true otherwise */
2247 iterator_fold_with_resync (GstIterator * iter, GstIteratorFoldFunction func,
2248 GValue * ret, gpointer user_data)
2250 GstIteratorResult ires;
2251 gboolean res = TRUE;
2254 ires = gst_iterator_fold (iter, func, ret, user_data);
2257 case GST_ITERATOR_RESYNC:
2258 gst_iterator_resync (iter);
2260 case GST_ITERATOR_DONE:
2273 /* is called with STATE_LOCK
2276 gst_element_pads_activate (GstElement * element, gboolean active)
2278 GValue ret = { 0, };
2282 GST_DEBUG_OBJECT (element, "pads_activate with active %d", active);
2283 /* no need to unset this later, it's just a boolean */
2284 g_value_init (&ret, G_TYPE_BOOLEAN);
2285 g_value_set_boolean (&ret, TRUE);
2288 iter = gst_element_iterate_src_pads (element);
2290 iter = gst_element_iterate_sink_pads (element);
2291 fold_ok = iterator_fold_with_resync
2292 (iter, (GstIteratorFoldFunction) activate_pads, &ret, &active);
2293 gst_iterator_free (iter);
2294 if (!fold_ok || !g_value_get_boolean (&ret)) {
2295 GST_DEBUG_OBJECT (element, "pads_activate failed");
2300 iter = gst_element_iterate_sink_pads (element);
2302 iter = gst_element_iterate_src_pads (element);
2303 fold_ok = iterator_fold_with_resync
2304 (iter, (GstIteratorFoldFunction) activate_pads, &ret, &active);
2305 gst_iterator_free (iter);
2306 if (!fold_ok || !g_value_get_boolean (&ret)) {
2307 GST_DEBUG_OBJECT (element, "pads_activate failed");
2311 GST_DEBUG_OBJECT (element, "pads_activate successful");
2315 /* is called with STATE_LOCK */
2316 static GstStateChangeReturn
2317 gst_element_change_state_func (GstElement * element, GstStateChange transition)
2319 GstState state, next;
2320 GstStateChangeReturn result = GST_STATE_CHANGE_SUCCESS;
2322 g_return_val_if_fail (GST_IS_ELEMENT (element), GST_STATE_CHANGE_FAILURE);
2324 state = GST_STATE_TRANSITION_CURRENT (transition);
2325 next = GST_STATE_TRANSITION_NEXT (transition);
2327 /* if the element already is in the given state, we just return success */
2328 if (next == GST_STATE_VOID_PENDING || state == next)
2331 GST_CAT_LOG_OBJECT (GST_CAT_STATES, element,
2332 "default handler tries setting state from %s to %s (%04x)",
2333 gst_element_state_get_name (state),
2334 gst_element_state_get_name (next), transition);
2336 switch (transition) {
2337 case GST_STATE_CHANGE_NULL_TO_READY:
2339 case GST_STATE_CHANGE_READY_TO_PAUSED:
2340 if (!gst_element_pads_activate (element, TRUE)) {
2341 result = GST_STATE_CHANGE_FAILURE;
2344 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
2346 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
2348 case GST_STATE_CHANGE_PAUSED_TO_READY:
2349 case GST_STATE_CHANGE_READY_TO_NULL:
2350 /* deactivate pads in both cases, since they are activated on
2351 ready->paused but the element might not have made it to paused */
2352 if (!gst_element_pads_activate (element, FALSE)) {
2353 result = GST_STATE_CHANGE_FAILURE;
2355 gst_element_set_base_time (element, 0);
2359 /* this will catch real but unhandled state changes;
2360 * can only be caused by:
2361 * - a new state was added
2362 * - somehow the element was asked to jump across an intermediate state
2364 g_warning ("Unhandled state change from %s to %s",
2365 gst_element_state_get_name (state),
2366 gst_element_state_get_name (next));
2373 GST_OBJECT_LOCK (element);
2374 result = GST_STATE_RETURN (element);
2375 GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element,
2376 "element is already in the %s state",
2377 gst_element_state_get_name (state));
2378 GST_OBJECT_UNLOCK (element);
2385 * gst_element_get_factory:
2386 * @element: a #GstElement to request the element factory of.
2388 * Retrieves the factory that was used to create this element.
2390 * Returns: the #GstElementFactory used for creating this element.
2391 * no refcounting is needed.
2394 gst_element_get_factory (GstElement * element)
2396 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
2398 return GST_ELEMENT_GET_CLASS (element)->elementfactory;
2402 gst_element_dispose (GObject * object)
2404 GstElement *element = GST_ELEMENT (object);
2406 GST_CAT_INFO_OBJECT (GST_CAT_REFCOUNTING, element, "dispose");
2408 if (GST_STATE (element) != GST_STATE_NULL) {
2410 ("\nTrying to dispose element %s, but it is not in the NULL state.\n"
2411 "You need to explicitly set elements to the NULL state before\n"
2412 "dropping the final reference, to allow them to clean up.\n",
2413 GST_OBJECT_NAME (element));
2416 g_return_if_fail (GST_STATE_PENDING (element) == GST_STATE_VOID_PENDING);
2418 GST_DEBUG ("removing %d pads", g_list_length (element->pads));
2419 /* first we break all our links with the outside */
2420 while (element->pads && element->pads->data) {
2421 /* don't call _remove_pad with NULL */
2422 gst_element_remove_pad (element, GST_PAD_CAST (element->pads->data));
2424 if (G_UNLIKELY (element->pads != 0)) {
2425 g_critical ("could not remove pads from element %s",
2426 GST_STR_NULL (GST_OBJECT_NAME (object)));
2429 GST_OBJECT_LOCK (element);
2430 gst_object_replace ((GstObject **) & element->clock, NULL);
2431 gst_object_replace ((GstObject **) & element->bus, NULL);
2432 GST_OBJECT_UNLOCK (element);
2434 GST_CAT_INFO_OBJECT (GST_CAT_REFCOUNTING, element, "parent class dispose");
2436 G_OBJECT_CLASS (parent_class)->dispose (object);
2440 gst_element_finalize (GObject * object)
2442 GstElement *element = GST_ELEMENT (object);
2444 GST_CAT_INFO_OBJECT (GST_CAT_REFCOUNTING, element, "finalize");
2446 GST_STATE_LOCK (element);
2447 if (element->state_cond)
2448 g_cond_free (element->state_cond);
2449 element->state_cond = NULL;
2450 GST_STATE_UNLOCK (element);
2451 g_static_rec_mutex_free (element->state_lock);
2452 g_free (element->state_lock);
2453 element->state_lock = NULL;
2455 GST_CAT_INFO_OBJECT (GST_CAT_REFCOUNTING, element, "finalize parent");
2457 G_OBJECT_CLASS (parent_class)->finalize (object);
2460 #ifndef GST_DISABLE_LOADSAVE
2462 * gst_element_save_thyself:
2463 * @element: a #GstElement to save.
2464 * @parent: the xml parent node.
2466 * Saves the element as part of the given XML structure.
2468 * Returns: the new #xmlNodePtr.
2471 gst_element_save_thyself (GstObject * object, xmlNodePtr parent)
2474 GstElementClass *oclass;
2475 GParamSpec **specs, *spec;
2478 GValue value = { 0, };
2479 GstElement *element;
2481 g_return_val_if_fail (GST_IS_ELEMENT (object), parent);
2483 element = GST_ELEMENT (object);
2485 oclass = GST_ELEMENT_GET_CLASS (element);
2487 xmlNewChild (parent, NULL, (xmlChar *) "name",
2488 (xmlChar *) GST_ELEMENT_NAME (element));
2490 if (oclass->elementfactory != NULL) {
2491 GstElementFactory *factory = (GstElementFactory *) oclass->elementfactory;
2493 xmlNewChild (parent, NULL, (xmlChar *) "type",
2494 (xmlChar *) GST_PLUGIN_FEATURE (factory)->name);
2498 specs = g_object_class_list_properties (G_OBJECT_GET_CLASS (object), &nspecs);
2500 for (i = 0; i < nspecs; i++) {
2502 if (spec->flags & G_PARAM_READABLE) {
2506 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (spec));
2508 g_object_get_property (G_OBJECT (element), spec->name, &value);
2509 param = xmlNewChild (parent, NULL, (xmlChar *) "param", NULL);
2510 xmlNewChild (param, NULL, (xmlChar *) "name", (xmlChar *) spec->name);
2512 if (G_IS_PARAM_SPEC_STRING (spec))
2513 contents = g_value_dup_string (&value);
2514 else if (G_IS_PARAM_SPEC_ENUM (spec))
2515 contents = g_strdup_printf ("%d", g_value_get_enum (&value));
2516 else if (G_IS_PARAM_SPEC_INT64 (spec))
2517 contents = g_strdup_printf ("%" G_GINT64_FORMAT,
2518 g_value_get_int64 (&value));
2520 contents = g_strdup_value_contents (&value);
2522 xmlNewChild (param, NULL, (xmlChar *) "value", (xmlChar *) contents);
2525 g_value_unset (&value);
2531 pads = GST_ELEMENT_PADS (element);
2534 GstPad *pad = GST_PAD (pads->data);
2536 /* figure out if it's a direct pad or a ghostpad */
2537 if (GST_ELEMENT (GST_OBJECT_PARENT (pad)) == element) {
2538 xmlNodePtr padtag = xmlNewChild (parent, NULL, (xmlChar *) "pad", NULL);
2540 gst_object_save_thyself (GST_OBJECT (pad), padtag);
2542 pads = g_list_next (pads);
2549 gst_element_restore_thyself (GstObject * object, xmlNodePtr self)
2551 xmlNodePtr children;
2552 GstElement *element;
2554 gchar *value = NULL;
2556 element = GST_ELEMENT (object);
2557 g_return_if_fail (element != NULL);
2560 children = self->xmlChildrenNode;
2562 if (!strcmp ((char *) children->name, "param")) {
2563 xmlNodePtr child = children->xmlChildrenNode;
2566 if (!strcmp ((char *) child->name, "name")) {
2567 name = (gchar *) xmlNodeGetContent (child);
2568 } else if (!strcmp ((char *) child->name, "value")) {
2569 value = (gchar *) xmlNodeGetContent (child);
2571 child = child->next;
2573 /* FIXME: can this just be g_object_set ? */
2574 gst_util_set_object_arg (G_OBJECT (element), name, value);
2575 /* g_object_set (G_OBJECT (element), name, value, NULL); */
2579 children = children->next;
2583 children = self->xmlChildrenNode;
2585 if (!strcmp ((char *) children->name, "pad")) {
2586 gst_pad_load_and_link (children, GST_OBJECT (element));
2588 children = children->next;
2591 if (GST_OBJECT_CLASS (parent_class)->restore_thyself)
2592 (GST_OBJECT_CLASS (parent_class)->restore_thyself) (object, self);
2594 #endif /* GST_DISABLE_LOADSAVE */
2597 gst_element_set_bus_func (GstElement * element, GstBus * bus)
2599 g_return_if_fail (GST_IS_ELEMENT (element));
2601 GST_CAT_DEBUG_OBJECT (GST_CAT_PARENTAGE, element, "setting bus to %p", bus);
2603 GST_OBJECT_LOCK (element);
2604 gst_object_replace ((GstObject **) & GST_ELEMENT_BUS (element),
2605 GST_OBJECT_CAST (bus));
2606 GST_OBJECT_UNLOCK (element);
2610 * gst_element_set_bus:
2611 * @element: a #GstElement to set the bus of.
2612 * @bus: the #GstBus to set.
2614 * Sets the bus of the element. For internal use only, unless you're
2620 gst_element_set_bus (GstElement * element, GstBus * bus)
2622 GstElementClass *oclass;
2624 g_return_if_fail (GST_IS_ELEMENT (element));
2626 oclass = GST_ELEMENT_GET_CLASS (element);
2628 if (oclass->set_bus)
2629 oclass->set_bus (element, bus);
2633 * gst_element_get_bus:
2634 * @element: a #GstElement to get the bus of.
2636 * Returns the bus of the element.
2638 * Returns: the element's #GstBus. unref after usage.
2643 gst_element_get_bus (GstElement * element)
2645 GstBus *result = NULL;
2647 g_return_val_if_fail (GST_IS_ELEMENT (element), result);
2649 GST_OBJECT_LOCK (element);
2650 result = GST_ELEMENT_BUS (element);
2651 gst_object_ref (result);
2652 GST_OBJECT_UNLOCK (element);
2654 GST_DEBUG_OBJECT (element, "got bus %" GST_PTR_FORMAT, result);