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 event on element %s",
1201 GST_ELEMENT_NAME (element));
1202 result = oclass->send_event (element, event);
1204 GstPad *pad = gst_element_get_random_pad (element, GST_PAD_SINK);
1207 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
1208 "pushing event to random pad %s:%s", GST_DEBUG_PAD_NAME (pad));
1210 result = gst_pad_push_event (pad, event);
1211 gst_object_unref (pad);
1213 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "can't send event on element %s",
1214 GST_ELEMENT_NAME (element));
1222 * @element: a #GstElement to send the event to.
1223 * @rate: The new playback rate
1224 * @format: The format of the seek values
1225 * @flags: The optional seek flags.
1226 * @cur_type: The type and flags for the new current position
1227 * @cur: The value of the new current position
1228 * @stop_type: The type and flags for the new stop position
1229 * @stop: The value of the new stop position
1231 * Sends a seek event to an element.
1233 * Returns: %TRUE if the event was handled.
1238 gst_element_seek (GstElement * element, gdouble rate, GstFormat format,
1239 GstSeekFlags flags, GstSeekType cur_type, gint64 cur,
1240 GstSeekType stop_type, gint64 stop)
1245 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
1248 gst_event_new_seek (rate, format, flags, cur_type, cur, stop_type, stop);
1249 result = gst_element_send_event (element, event);
1255 * gst_element_get_query_types:
1256 * @element: a #GstElement to query
1258 * Get an array of query types from the element.
1259 * If the element doesn't implement a query types function,
1260 * the query will be forwarded to a random sink pad.
1262 * Returns: An array of #GstQueryType elements that should not
1263 * be freed or modified.
1267 const GstQueryType *
1268 gst_element_get_query_types (GstElement * element)
1270 GstElementClass *oclass;
1271 const GstQueryType *result = NULL;
1273 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
1275 oclass = GST_ELEMENT_GET_CLASS (element);
1277 if (oclass->get_query_types) {
1278 result = oclass->get_query_types (element);
1280 GstPad *pad = gst_element_get_random_pad (element, GST_PAD_SINK);
1283 GstPad *peer = gst_pad_get_peer (pad);
1286 result = gst_pad_get_query_types (peer);
1288 gst_object_unref (peer);
1290 gst_object_unref (pad);
1297 * gst_element_query:
1298 * @element: a #GstElement to perform the query on.
1299 * @query: the #GstQuery.
1301 * Performs a query on the given element. If the format is set
1302 * to #GST_FORMAT_DEFAULT and this function returns TRUE, the
1303 * format pointer will hold the default format.
1304 * For element that don't implement a query handler, this function
1305 * forwards the query to a random usable sinkpad of this element.
1307 * Returns: TRUE if the query could be performed.
1312 gst_element_query (GstElement * element, GstQuery * query)
1314 GstElementClass *oclass;
1315 gboolean result = FALSE;
1317 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
1318 g_return_val_if_fail (query != NULL, FALSE);
1320 oclass = GST_ELEMENT_GET_CLASS (element);
1322 if (oclass->query) {
1323 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "send query on element %s",
1324 GST_ELEMENT_NAME (element));
1325 result = oclass->query (element, query);
1327 GstPad *pad = gst_element_get_random_pad (element, GST_PAD_SRC);
1330 result = gst_pad_query (pad, query);
1332 gst_object_unref (pad);
1334 pad = gst_element_get_random_pad (element, GST_PAD_SINK);
1336 GstPad *peer = gst_pad_get_peer (pad);
1339 result = gst_pad_query (peer, query);
1341 gst_object_unref (peer);
1343 gst_object_unref (pad);
1351 * gst_element_post_message:
1352 * @element: a #GstElement posting the message
1353 * @message: a #GstMessage to post
1355 * Post a message on the element's #GstBus. This function takes ownership of the
1356 * message; if you want to access the message after this call, you should add an
1357 * additional reference before calling.
1359 * Returns: TRUE if the message was successfully posted.
1364 gst_element_post_message (GstElement * element, GstMessage * message)
1367 gboolean result = FALSE;
1369 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
1370 g_return_val_if_fail (message != NULL, FALSE);
1372 GST_OBJECT_LOCK (element);
1375 if (G_UNLIKELY (bus == NULL))
1378 gst_object_ref (bus);
1379 GST_OBJECT_UNLOCK (element);
1381 result = gst_bus_post (bus, message);
1382 gst_object_unref (bus);
1388 GST_DEBUG ("not posting message %p: no bus", message);
1389 GST_OBJECT_UNLOCK (element);
1390 gst_message_unref (message);
1396 * _gst_element_error_printf:
1397 * @format: the printf-like format to use, or NULL
1399 * This function is only used internally by the #gst_element_error macro.
1401 * Returns: a newly allocated string, or NULL if the format was NULL or ""
1406 _gst_element_error_printf (const gchar * format, ...)
1416 va_start (args, format);
1417 buffer = g_strdup_vprintf (format, args);
1423 * gst_element_message_full:
1424 * @element: a #GstElement to send message from
1425 * @type: the #GstMessageType
1426 * @domain: the GStreamer GError domain this message belongs to
1427 * @code: the GError code belonging to the domain
1428 * @text: an allocated text string to be used as a replacement for the
1429 * default message connected to code, or NULL
1430 * @debug: an allocated debug message to be used as a replacement for the
1431 * default debugging information, or NULL
1432 * @file: the source code file where the error was generated
1433 * @function: the source code function where the error was generated
1434 * @line: the source code line where the error was generated
1436 * Post an error or warning message on the bus from inside an element.
1440 void gst_element_message_full
1441 (GstElement * element, GstMessageType type,
1442 GQuark domain, gint code, gchar * text,
1443 gchar * debug, const gchar * file, const gchar * function, gint line)
1445 GError *gerror = NULL;
1449 GstMessage *message = NULL;
1452 GST_DEBUG ("start");
1453 g_return_if_fail (GST_IS_ELEMENT (element));
1454 g_return_if_fail ((type == GST_MESSAGE_ERROR) ||
1455 (type == GST_MESSAGE_WARNING));
1457 /* check if we send the given text or the default error text */
1458 if ((text == NULL) || (text[0] == 0)) {
1459 /* text could have come from g_strdup_printf (""); */
1461 sent_text = gst_error_get_message (domain, code);
1465 /* construct a sent_debug with extra information from source */
1466 if ((debug == NULL) || (debug[0] == 0)) {
1467 /* debug could have come from g_strdup_printf (""); */
1470 name = gst_object_get_path_string (GST_OBJECT (element));
1471 sent_debug = g_strdup_printf ("%s(%d): %s: %s:\n%s",
1472 file, line, function, name, debug ? debug : "");
1477 /* create gerror and post message */
1478 GST_CAT_INFO_OBJECT (GST_CAT_ERROR_SYSTEM, element, "posting message: %s",
1480 gerror = g_error_new_literal (domain, code, sent_text);
1482 if (type == GST_MESSAGE_ERROR) {
1483 message = gst_message_new_error (GST_OBJECT (element), gerror, sent_debug);
1484 } else if (type == GST_MESSAGE_WARNING) {
1485 message = gst_message_new_warning (GST_OBJECT (element), gerror,
1488 g_assert_not_reached ();
1490 gst_element_post_message (element, message);
1492 GST_CAT_INFO_OBJECT (GST_CAT_ERROR_SYSTEM, element, "posted message: %s",
1496 g_error_free (gerror);
1497 g_free (sent_debug);
1502 * gst_element_is_locked_state:
1503 * @element: a #GstElement.
1505 * Checks if the state of an element is locked.
1506 * If the state of an element is locked, state changes of the parent don't
1507 * affect the element.
1508 * This way you can leave currently unused elements inside bins. Just lock their
1509 * state before changing the state from #GST_STATE_NULL.
1513 * Returns: TRUE, if the element's state is locked.
1516 gst_element_is_locked_state (GstElement * element)
1520 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
1522 GST_OBJECT_LOCK (element);
1523 result = GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_LOCKED_STATE);
1524 GST_OBJECT_UNLOCK (element);
1530 * gst_element_set_locked_state:
1531 * @element: a #GstElement
1532 * @locked_state: TRUE to lock the element's state
1534 * Locks the state of an element, so state changes of the parent don't affect
1535 * this element anymore.
1539 * Returns: TRUE if the state was changed, FALSE if bad parameterss were given
1540 * or the elements state-locking needed no change.
1543 gst_element_set_locked_state (GstElement * element, gboolean locked_state)
1547 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
1549 GST_OBJECT_LOCK (element);
1550 old = GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_LOCKED_STATE);
1552 if (G_UNLIKELY (old == locked_state))
1556 GST_CAT_DEBUG (GST_CAT_STATES, "locking state of element %s",
1557 GST_ELEMENT_NAME (element));
1558 GST_OBJECT_FLAG_SET (element, GST_ELEMENT_LOCKED_STATE);
1560 GST_CAT_DEBUG (GST_CAT_STATES, "unlocking state of element %s",
1561 GST_ELEMENT_NAME (element));
1562 GST_OBJECT_FLAG_UNSET (element, GST_ELEMENT_LOCKED_STATE);
1564 GST_OBJECT_UNLOCK (element);
1569 GST_OBJECT_UNLOCK (element);
1575 * gst_element_sync_state_with_parent:
1576 * @element: a #GstElement.
1578 * Tries to change the state of the element to the same as its parent.
1579 * If this function returns FALSE, the state of element is undefined.
1581 * Returns: TRUE, if the element's state could be synced to the parent's state.
1586 gst_element_sync_state_with_parent (GstElement * element)
1590 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
1592 if ((parent = GST_ELEMENT_CAST (gst_element_get_parent (element)))) {
1593 GstState parent_current, parent_pending;
1594 GstStateChangeReturn ret;
1596 GST_OBJECT_LOCK (parent);
1597 parent_current = GST_STATE (parent);
1598 parent_pending = GST_STATE_PENDING (parent);
1599 GST_OBJECT_UNLOCK (parent);
1601 GST_CAT_DEBUG (GST_CAT_STATES,
1602 "syncing state of element %s (%s) to %s (%s, %s)",
1603 GST_ELEMENT_NAME (element),
1604 gst_element_state_get_name (GST_STATE (element)),
1605 GST_ELEMENT_NAME (parent), gst_element_state_get_name (parent_current),
1606 gst_element_state_get_name (parent_pending));
1608 ret = gst_element_set_state (element, parent_current);
1609 if (ret == GST_STATE_CHANGE_FAILURE)
1612 gst_object_unref (parent);
1626 static GstStateChangeReturn
1627 gst_element_get_state_func (GstElement * element,
1628 GstState * state, GstState * pending, GstClockTime timeout)
1630 GstStateChangeReturn ret = GST_STATE_CHANGE_FAILURE;
1631 GstState old_pending;
1633 GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element, "getting state");
1635 GST_OBJECT_LOCK (element);
1636 ret = GST_STATE_RETURN (element);
1638 /* we got an error, report immediatly */
1639 if (ret == GST_STATE_CHANGE_FAILURE)
1642 /* we got no_preroll, report immediatly */
1643 if (ret == GST_STATE_CHANGE_NO_PREROLL)
1646 /* no need to wait async if we are not async */
1647 if (ret != GST_STATE_CHANGE_ASYNC)
1650 old_pending = GST_STATE_PENDING (element);
1651 if (old_pending != GST_STATE_VOID_PENDING) {
1652 GTimeVal *timeval, abstimeout;
1655 if (timeout != GST_CLOCK_TIME_NONE) {
1656 glong add = timeout / 1000;
1661 /* make timeout absolute */
1662 g_get_current_time (&abstimeout);
1663 g_time_val_add (&abstimeout, add);
1664 timeval = &abstimeout;
1668 /* get cookie to dected state change during waiting */
1669 cookie = element->state_cookie;
1671 GST_CAT_INFO_OBJECT (GST_CAT_STATES, element,
1672 "waiting for element to commit state");
1674 /* we have a pending state change, wait for it to complete */
1675 if (!GST_STATE_TIMED_WAIT (element, timeval)) {
1676 GST_CAT_INFO_OBJECT (GST_CAT_STATES, element, "timed out");
1677 /* timeout triggered */
1678 ret = GST_STATE_CHANGE_ASYNC;
1680 if (cookie != element->state_cookie)
1683 /* could be success or failure */
1684 if (old_pending == GST_STATE (element)) {
1685 GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element, "got success");
1686 ret = GST_STATE_CHANGE_SUCCESS;
1688 GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element, "got failure");
1689 ret = GST_STATE_CHANGE_FAILURE;
1693 /* if nothing is pending anymore we can return SUCCESS */
1694 if (GST_STATE_PENDING (element) == GST_STATE_VOID_PENDING) {
1695 GST_CAT_LOG_OBJECT (GST_CAT_STATES, element, "nothing pending");
1696 ret = GST_STATE_CHANGE_SUCCESS;
1701 *state = GST_STATE (element);
1703 *pending = GST_STATE_PENDING (element);
1705 GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element,
1706 "state current: %s, pending: %s, result: %d",
1707 gst_element_state_get_name (GST_STATE (element)),
1708 gst_element_state_get_name (GST_STATE_PENDING (element)), ret);
1709 GST_OBJECT_UNLOCK (element);
1716 *state = GST_STATE_VOID_PENDING;
1718 *pending = GST_STATE_VOID_PENDING;
1720 GST_CAT_INFO_OBJECT (GST_CAT_STATES, element, "get_state() interruped");
1722 GST_OBJECT_UNLOCK (element);
1724 return GST_STATE_CHANGE_FAILURE;
1729 * gst_element_get_state:
1730 * @element: a #GstElement to get the state of.
1731 * @state: a pointer to #GstState to hold the state. Can be NULL.
1732 * @pending: a pointer to #GstState to hold the pending state.
1734 * @timeout: a #GstClockTime to specify the timeout for an async
1735 * state change or GST_CLOCK_TIME_NONE for infinite timeout.
1737 * Gets the state of the element.
1739 * For elements that performed an ASYNC state change, as reported by
1740 * #gst_element_set_state(), this function will block up to the
1741 * specified timeout value for the state change to complete.
1742 * If the element completes the state change or goes into
1743 * an error, this function returns immediatly with a return value of
1744 * #GST_STATE_CHANGE_SUCCESS or #GST_STATE_CHANGE_FAILURE respectively.
1746 * For elements that did not return #GST_STATE_CHANGE_ASYNC, this function
1747 * returns the current and pending state immediatly.
1749 * This function returns #GST_STATE_CHANGE_NO_PREROLL if the element
1750 * successfully changed its state but is not able to provide data yet. This mostly
1751 * happens for live sources that only produce data in the PLAYING state.
1752 * While the state change return is equivalent to #GST_STATE_CHANGE_SUCCESS, it
1753 * is returned to the application to signal that some sink elements might not
1754 * be able to complete their state change because an element is not producing
1755 * data to complete the preroll. When setting the element to playing, the preroll
1756 * will complete and playback will start.
1758 * Returns: #GST_STATE_CHANGE_SUCCESS if the element has no more pending state and
1759 * the last state change succeeded, #GST_STATE_CHANGE_ASYNC
1760 * if the element is still performing a state change or
1761 * #GST_STATE_CHANGE_FAILURE if the last state change failed.
1765 GstStateChangeReturn
1766 gst_element_get_state (GstElement * element,
1767 GstState * state, GstState * pending, GstClockTime timeout)
1769 GstElementClass *oclass;
1770 GstStateChangeReturn result = GST_STATE_CHANGE_FAILURE;
1772 g_return_val_if_fail (GST_IS_ELEMENT (element), GST_STATE_CHANGE_FAILURE);
1774 oclass = GST_ELEMENT_GET_CLASS (element);
1776 if (oclass->get_state)
1777 result = (oclass->get_state) (element, state, pending, timeout);
1783 * gst_element_abort_state:
1784 * @element: a #GstElement to abort the state of.
1786 * Abort the state change of the element. This function is used
1787 * by elements that do asynchronous state changes and find out
1788 * something is wrong.
1790 * This function should be called with the STATE_LOCK held.
1795 gst_element_abort_state (GstElement * element)
1799 #ifndef GST_DISABLE_GST_DEBUG
1803 g_return_if_fail (GST_IS_ELEMENT (element));
1805 GST_OBJECT_LOCK (element);
1806 pending = GST_STATE_PENDING (element);
1808 if (pending == GST_STATE_VOID_PENDING ||
1809 GST_STATE_RETURN (element) == GST_STATE_CHANGE_FAILURE)
1810 goto nothing_aborted;
1812 #ifndef GST_DISABLE_GST_DEBUG
1813 old_state = GST_STATE (element);
1815 GST_CAT_INFO_OBJECT (GST_CAT_STATES, element,
1816 "aborting state from %s to %s", gst_element_state_get_name (old_state),
1817 gst_element_state_get_name (pending));
1821 GST_STATE_RETURN (element) = GST_STATE_CHANGE_FAILURE;
1823 GST_STATE_BROADCAST (element);
1824 GST_OBJECT_UNLOCK (element);
1830 GST_OBJECT_UNLOCK (element);
1836 * gst_element_continue_state:
1837 * @element: a #GstElement to continue the state change of.
1838 * @ret: The previous state return value
1840 * Commit the state change of the element and proceed to the next
1841 * pending state if any. This function is used
1842 * by elements that do asynchronous state changes.
1843 * The core will normally call this method automatically when an
1844 * element returned SUCCESS from the state change function.
1845 * Elements that return ASYNC from the change_state function should
1846 * eventually call this method from the streaming thread to signal
1847 * successfull state change completion.
1849 * If after calling this method the element still has not reached
1850 * the pending state, the next state change is performed.
1852 * Returns: The result of the commit state change.
1856 GstStateChangeReturn
1857 gst_element_continue_state (GstElement * element, GstStateChangeReturn ret)
1860 GstState old_ret, old_state, old_next;
1861 GstState current, next;
1862 GstMessage *message;
1863 GstStateChange transition;
1865 GST_OBJECT_LOCK (element);
1866 old_ret = GST_STATE_RETURN (element);
1867 GST_STATE_RETURN (element) = ret;
1868 pending = GST_STATE_PENDING (element);
1870 /* check if there is something to commit */
1871 if (pending == GST_STATE_VOID_PENDING)
1872 goto nothing_pending;
1874 old_state = GST_STATE (element);
1875 /* this is the state we should go to next */
1876 old_next = GST_STATE_NEXT (element);
1877 /* update current state */
1878 current = GST_STATE (element) = old_next;
1880 /* see if we reached the final state */
1881 if (pending == current)
1884 next = GST_STATE_GET_NEXT (current, pending);
1885 transition = GST_STATE_TRANSITION (current, next);
1887 GST_STATE_NEXT (element) = next;
1888 GST_OBJECT_UNLOCK (element);
1890 GST_CAT_INFO_OBJECT (GST_CAT_STATES, element,
1891 "committing state from %s to %s, pending %s",
1892 gst_element_state_get_name (old_state),
1893 gst_element_state_get_name (old_next),
1894 gst_element_state_get_name (pending));
1896 message = gst_message_new_state_changed (GST_OBJECT (element),
1897 old_state, old_next, pending);
1898 gst_element_post_message (element, message);
1900 GST_CAT_INFO_OBJECT (GST_CAT_STATES, element,
1901 "continue state change %s to %s, final %s",
1902 gst_element_state_get_name (current),
1903 gst_element_state_get_name (next), gst_element_state_get_name (pending));
1905 ret = gst_element_change_state (element, transition);
1911 GST_CAT_INFO_OBJECT (GST_CAT_STATES, element, "nothing pending");
1912 GST_OBJECT_UNLOCK (element);
1917 GST_STATE_PENDING (element) = GST_STATE_VOID_PENDING;
1918 GST_STATE_NEXT (element) = GST_STATE_VOID_PENDING;
1920 GST_CAT_INFO_OBJECT (GST_CAT_STATES, element, "completed state change");
1921 GST_OBJECT_UNLOCK (element);
1923 /* don't post silly messages with the same state. This can happen
1924 * when an element state is changed to what it already was. For bins
1925 * this can be the result of a lost state, which we check with the
1926 * previous return value.
1927 * We do signal the cond though as a _get_state() might be blocking
1929 if (old_state != old_next || old_ret == GST_STATE_CHANGE_ASYNC) {
1930 message = gst_message_new_state_changed (GST_OBJECT (element),
1931 old_state, old_next, GST_STATE_VOID_PENDING);
1932 gst_element_post_message (element, message);
1935 GST_STATE_BROADCAST (element);
1942 * gst_element_lost_state:
1943 * @element: a #GstElement the state is lost of
1945 * Brings the element to the lost state. The current state of the
1946 * element is copied to the pending state so that any call to
1947 * #gst_element_get_state() will return ASYNC.
1949 * This is mostly used for elements that lost their preroll buffer
1950 * in the PAUSED state after a flush, they become PAUSED again
1951 * if a new preroll buffer is queued.
1952 * This function can only be called when the element is currently
1953 * not in error or an async state change.
1955 * This function can only be called with the STATE_LOCK held.
1960 gst_element_lost_state (GstElement * element)
1962 GstState current_state;
1963 GstMessage *message;
1965 g_return_if_fail (GST_IS_ELEMENT (element));
1967 GST_OBJECT_LOCK (element);
1968 if (GST_STATE_PENDING (element) != GST_STATE_VOID_PENDING ||
1969 GST_STATE_RETURN (element) == GST_STATE_CHANGE_FAILURE)
1972 current_state = GST_STATE (element);
1974 GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element,
1975 "lost state of %s", gst_element_state_get_name (current_state));
1977 GST_STATE_NEXT (element) = current_state;
1978 GST_STATE_PENDING (element) = current_state;
1979 GST_STATE_RETURN (element) = GST_STATE_CHANGE_ASYNC;
1980 GST_OBJECT_UNLOCK (element);
1982 message = gst_message_new_state_changed (GST_OBJECT (element),
1983 current_state, current_state, current_state);
1984 gst_element_post_message (element, message);
1986 /* and mark us dirty */
1987 message = gst_message_new_state_dirty (GST_OBJECT (element));
1988 gst_element_post_message (element, message);
1994 GST_OBJECT_UNLOCK (element);
2000 * gst_element_set_state:
2001 * @element: a #GstElement to change state of.
2002 * @state: the element's new #GstState.
2004 * Sets the state of the element. This function will try to set the
2005 * requested state by going through all the intermediary states and calling
2006 * the class's state change function for each.
2008 * This function can return #GST_STATE_CHANGE_ASYNC, in which case the
2009 * element will perform the remainder of the state change asynchronously in
2011 * An application can use gst_element_get_state() to wait for the completion
2012 * of the state change or it can wait for a state change message on the bus.
2014 * Returns: Result of the state change using #GstStateChangeReturn.
2018 GstStateChangeReturn
2019 gst_element_set_state (GstElement * element, GstState state)
2021 GstElementClass *oclass;
2022 GstStateChangeReturn result = GST_STATE_CHANGE_FAILURE;
2024 g_return_val_if_fail (GST_IS_ELEMENT (element), GST_STATE_CHANGE_FAILURE);
2026 oclass = GST_ELEMENT_GET_CLASS (element);
2028 if (oclass->set_state)
2029 result = (oclass->set_state) (element, state);
2035 * default set state function, calculates the next state based
2036 * on current state and calls the change_state function
2038 static GstStateChangeReturn
2039 gst_element_set_state_func (GstElement * element, GstState state)
2041 GstState current, next, old_pending;
2042 GstStateChangeReturn ret;
2043 GstStateChange transition;
2044 GstStateChangeReturn old_ret;
2046 g_return_val_if_fail (GST_IS_ELEMENT (element), GST_STATE_CHANGE_FAILURE);
2048 GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element, "set_state to %s",
2049 gst_element_state_get_name (state));
2051 /* state lock is taken to protect the set_state() and get_state()
2052 * procedures, it does not lock any variables. */
2053 GST_STATE_LOCK (element);
2055 /* now calculate how to get to the new state */
2056 GST_OBJECT_LOCK (element);
2057 old_ret = GST_STATE_RETURN (element);
2058 /* previous state change returned an error, remove all pending
2059 * and next states */
2060 if (old_ret == GST_STATE_CHANGE_FAILURE) {
2061 GST_STATE_NEXT (element) = GST_STATE_VOID_PENDING;
2062 GST_STATE_PENDING (element) = GST_STATE_VOID_PENDING;
2063 GST_STATE_RETURN (element) = GST_STATE_CHANGE_SUCCESS;
2066 current = GST_STATE (element);
2067 next = GST_STATE_NEXT (element);
2068 old_pending = GST_STATE_PENDING (element);
2069 element->state_cookie++;
2071 /* this is the (new) state we should go to */
2072 GST_STATE_PENDING (element) = state;
2074 GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element,
2075 "current %s, old_pending %s, next %s, old return %d",
2076 gst_element_state_get_name (current),
2077 gst_element_state_get_name (old_pending),
2078 gst_element_state_get_name (next), old_ret);
2080 /* if the element was busy doing a state change, we just update the
2081 * target state, it'll get to it async then. */
2082 if (old_pending != GST_STATE_VOID_PENDING) {
2083 /* upwards state change will happen ASYNC */
2084 if (old_pending <= state)
2086 /* element is going to this state already */
2087 else if (next == state)
2089 /* element was performing an ASYNC upward state change and
2090 * we request to go downward again. Start from the next pending
2092 else if (next > state
2093 && GST_STATE_RETURN (element) == GST_STATE_CHANGE_ASYNC) {
2097 next = GST_STATE_GET_NEXT (current, state);
2098 /* now we store the next state */
2099 GST_STATE_NEXT (element) = next;
2100 transition = GST_STATE_TRANSITION (current, next);
2102 GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element,
2103 "%s: setting state from %s to %s",
2104 (next != state ? "intermediate" : "final"),
2105 gst_element_state_get_name (current), gst_element_state_get_name (next));
2107 /* now signal any waiters, they will error since the cookie was increased */
2108 GST_STATE_BROADCAST (element);
2110 GST_OBJECT_UNLOCK (element);
2112 ret = gst_element_change_state (element, transition);
2114 GST_STATE_UNLOCK (element);
2116 GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element, "returned %d", ret);
2122 GST_STATE_RETURN (element) = GST_STATE_CHANGE_ASYNC;
2123 GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element,
2124 "element was busy with async state change");
2125 GST_OBJECT_UNLOCK (element);
2127 GST_STATE_UNLOCK (element);
2129 return GST_STATE_CHANGE_ASYNC;
2133 /* with STATE_LOCK */
2134 static GstStateChangeReturn
2135 gst_element_change_state (GstElement * element, GstStateChange transition)
2137 GstElementClass *oclass;
2138 GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
2142 oclass = GST_ELEMENT_GET_CLASS (element);
2144 /* start with the current state. */
2145 current = GST_STATE_TRANSITION_CURRENT (transition);
2146 next = GST_STATE_TRANSITION_NEXT (transition);
2148 /* call the state change function so it can set the state */
2149 if (oclass->change_state)
2150 ret = (oclass->change_state) (element, transition);
2152 ret = GST_STATE_CHANGE_FAILURE;
2155 case GST_STATE_CHANGE_FAILURE:
2156 GST_CAT_INFO_OBJECT (GST_CAT_STATES, element,
2157 "have FAILURE change_state return");
2158 /* state change failure */
2159 gst_element_abort_state (element);
2161 case GST_STATE_CHANGE_ASYNC:
2162 GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element,
2163 "element will change state ASYNC");
2165 /* if we go upwards, we give the app a change to wait for
2170 /* else we just continue the state change downwards */
2171 GST_CAT_INFO_OBJECT (GST_CAT_STATES, element,
2172 "forcing commit state %s < %s",
2173 gst_element_state_get_name (current),
2174 gst_element_state_get_name (next));
2176 ret = gst_element_continue_state (element, GST_STATE_CHANGE_SUCCESS);
2178 case GST_STATE_CHANGE_SUCCESS:
2179 GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element,
2180 "element changed state SUCCESS");
2181 /* we can commit the state now which will proceeed to
2183 ret = gst_element_continue_state (element, ret);
2185 case GST_STATE_CHANGE_NO_PREROLL:
2186 GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element,
2187 "element changed state NO_PREROLL");
2188 /* we can commit the state now which will proceeed to
2190 ret = gst_element_continue_state (element, ret);
2193 goto invalid_return;
2196 GST_CAT_LOG_OBJECT (GST_CAT_STATES, element, "exit state change %d", ret);
2201 GST_OBJECT_LOCK (element);
2202 GST_STATE_RETURN (element) = ret;
2203 GST_CAT_LOG_OBJECT (GST_CAT_STATES, element, "exit async state change %d",
2205 GST_OBJECT_UNLOCK (element);
2212 GST_OBJECT_LOCK (element);
2213 /* somebody added a GST_STATE_ and forgot to do stuff here ! */
2214 g_critical ("%s: unknown return value %d from a state change function",
2215 GST_ELEMENT_NAME (element), ret);
2217 ret = GST_STATE_CHANGE_FAILURE;
2218 GST_STATE_RETURN (element) = ret;
2219 GST_OBJECT_UNLOCK (element);
2225 /* gst_iterator_fold functions for pads_activate */
2228 activate_pads (GstPad * pad, GValue * ret, gboolean * active)
2230 if (!gst_pad_set_active (pad, *active))
2231 g_value_set_boolean (ret, FALSE);
2233 gst_pad_set_caps (pad, NULL);
2235 gst_object_unref (pad);
2239 /* returns false on error or early cutout of the fold, true otherwise */
2241 iterator_fold_with_resync (GstIterator * iter, GstIteratorFoldFunction func,
2242 GValue * ret, gpointer user_data)
2244 GstIteratorResult ires;
2245 gboolean res = TRUE;
2248 ires = gst_iterator_fold (iter, func, ret, user_data);
2251 case GST_ITERATOR_RESYNC:
2252 gst_iterator_resync (iter);
2254 case GST_ITERATOR_DONE:
2267 /* is called with STATE_LOCK
2270 gst_element_pads_activate (GstElement * element, gboolean active)
2272 GValue ret = { 0, };
2276 GST_DEBUG_OBJECT (element, "pads_activate with active %d", active);
2277 /* no need to unset this later, it's just a boolean */
2278 g_value_init (&ret, G_TYPE_BOOLEAN);
2279 g_value_set_boolean (&ret, TRUE);
2281 iter = gst_element_iterate_src_pads (element);
2282 fold_ok = iterator_fold_with_resync
2283 (iter, (GstIteratorFoldFunction) activate_pads, &ret, &active);
2284 gst_iterator_free (iter);
2285 if (!fold_ok || !g_value_get_boolean (&ret)) {
2286 GST_DEBUG_OBJECT (element, "pads_activate failed");
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");
2299 GST_DEBUG_OBJECT (element, "pads_activate successful");
2303 /* is called with STATE_LOCK */
2304 static GstStateChangeReturn
2305 gst_element_change_state_func (GstElement * element, GstStateChange transition)
2307 GstState state, next;
2308 GstStateChangeReturn result = GST_STATE_CHANGE_SUCCESS;
2310 g_return_val_if_fail (GST_IS_ELEMENT (element), GST_STATE_CHANGE_FAILURE);
2312 state = GST_STATE_TRANSITION_CURRENT (transition);
2313 next = GST_STATE_TRANSITION_NEXT (transition);
2315 /* if the element already is in the given state, we just return success */
2316 if (next == GST_STATE_VOID_PENDING || state == next)
2319 GST_CAT_LOG_OBJECT (GST_CAT_STATES, element,
2320 "default handler tries setting state from %s to %s (%04x)",
2321 gst_element_state_get_name (state),
2322 gst_element_state_get_name (next), transition);
2324 switch (transition) {
2325 case GST_STATE_CHANGE_NULL_TO_READY:
2327 case GST_STATE_CHANGE_READY_TO_PAUSED:
2328 if (!gst_element_pads_activate (element, TRUE)) {
2329 result = GST_STATE_CHANGE_FAILURE;
2332 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
2334 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
2336 case GST_STATE_CHANGE_PAUSED_TO_READY:
2337 case GST_STATE_CHANGE_READY_TO_NULL:
2338 /* deactivate pads in both cases, since they are activated on
2339 ready->paused but the element might not have made it to paused */
2340 if (!gst_element_pads_activate (element, FALSE)) {
2341 result = GST_STATE_CHANGE_FAILURE;
2343 gst_element_set_base_time (element, 0);
2347 /* this will catch real but unhandled state changes;
2348 * can only be caused by:
2349 * - a new state was added
2350 * - somehow the element was asked to jump across an intermediate state
2352 g_warning ("Unhandled state change from %s to %s",
2353 gst_element_state_get_name (state),
2354 gst_element_state_get_name (next));
2361 GST_OBJECT_LOCK (element);
2362 result = GST_STATE_RETURN (element);
2363 GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element,
2364 "element is already in the %s state",
2365 gst_element_state_get_name (state));
2366 GST_OBJECT_UNLOCK (element);
2373 * gst_element_get_factory:
2374 * @element: a #GstElement to request the element factory of.
2376 * Retrieves the factory that was used to create this element.
2378 * Returns: the #GstElementFactory used for creating this element.
2379 * no refcounting is needed.
2382 gst_element_get_factory (GstElement * element)
2384 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
2386 return GST_ELEMENT_GET_CLASS (element)->elementfactory;
2390 gst_element_dispose (GObject * object)
2392 GstElement *element = GST_ELEMENT (object);
2394 GST_CAT_INFO_OBJECT (GST_CAT_REFCOUNTING, element, "dispose");
2396 if (GST_STATE (element) != GST_STATE_NULL) {
2398 ("\nTrying to dispose element %s, but it is not in the NULL state.\n"
2399 "You need to explicitly set elements to the NULL state before\n"
2400 "dropping the final reference, to allow them to clean up.\n",
2401 GST_OBJECT_NAME (element));
2404 g_return_if_fail (GST_STATE_PENDING (element) == GST_STATE_VOID_PENDING);
2406 GST_DEBUG ("removing %d pads", g_list_length (element->pads));
2407 /* first we break all our links with the outside */
2408 while (element->pads && element->pads->data) {
2409 /* don't call _remove_pad with NULL */
2410 gst_element_remove_pad (element, GST_PAD_CAST (element->pads->data));
2412 if (G_UNLIKELY (element->pads != 0)) {
2413 g_critical ("could not remove pads from element %s",
2414 GST_STR_NULL (GST_OBJECT_NAME (object)));
2417 GST_OBJECT_LOCK (element);
2418 gst_object_replace ((GstObject **) & element->clock, NULL);
2419 gst_object_replace ((GstObject **) & element->bus, NULL);
2420 GST_OBJECT_UNLOCK (element);
2422 GST_CAT_INFO_OBJECT (GST_CAT_REFCOUNTING, element, "parent class dispose");
2424 G_OBJECT_CLASS (parent_class)->dispose (object);
2428 gst_element_finalize (GObject * object)
2430 GstElement *element = GST_ELEMENT (object);
2432 GST_CAT_INFO_OBJECT (GST_CAT_REFCOUNTING, element, "finalize");
2434 GST_STATE_LOCK (element);
2435 if (element->state_cond)
2436 g_cond_free (element->state_cond);
2437 element->state_cond = NULL;
2438 GST_STATE_UNLOCK (element);
2439 g_static_rec_mutex_free (element->state_lock);
2440 g_free (element->state_lock);
2441 element->state_lock = NULL;
2443 GST_CAT_INFO_OBJECT (GST_CAT_REFCOUNTING, element, "finalize parent");
2445 G_OBJECT_CLASS (parent_class)->finalize (object);
2448 #ifndef GST_DISABLE_LOADSAVE
2450 * gst_element_save_thyself:
2451 * @element: a #GstElement to save.
2452 * @parent: the xml parent node.
2454 * Saves the element as part of the given XML structure.
2456 * Returns: the new #xmlNodePtr.
2459 gst_element_save_thyself (GstObject * object, xmlNodePtr parent)
2462 GstElementClass *oclass;
2463 GParamSpec **specs, *spec;
2466 GValue value = { 0, };
2467 GstElement *element;
2469 g_return_val_if_fail (GST_IS_ELEMENT (object), parent);
2471 element = GST_ELEMENT (object);
2473 oclass = GST_ELEMENT_GET_CLASS (element);
2475 xmlNewChild (parent, NULL, (xmlChar *) "name",
2476 (xmlChar *) GST_ELEMENT_NAME (element));
2478 if (oclass->elementfactory != NULL) {
2479 GstElementFactory *factory = (GstElementFactory *) oclass->elementfactory;
2481 xmlNewChild (parent, NULL, (xmlChar *) "type",
2482 (xmlChar *) GST_PLUGIN_FEATURE (factory)->name);
2486 specs = g_object_class_list_properties (G_OBJECT_GET_CLASS (object), &nspecs);
2488 for (i = 0; i < nspecs; i++) {
2490 if (spec->flags & G_PARAM_READABLE) {
2494 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (spec));
2496 g_object_get_property (G_OBJECT (element), spec->name, &value);
2497 param = xmlNewChild (parent, NULL, (xmlChar *) "param", NULL);
2498 xmlNewChild (param, NULL, (xmlChar *) "name", (xmlChar *) spec->name);
2500 if (G_IS_PARAM_SPEC_STRING (spec))
2501 contents = g_value_dup_string (&value);
2502 else if (G_IS_PARAM_SPEC_ENUM (spec))
2503 contents = g_strdup_printf ("%d", g_value_get_enum (&value));
2504 else if (G_IS_PARAM_SPEC_INT64 (spec))
2505 contents = g_strdup_printf ("%" G_GINT64_FORMAT,
2506 g_value_get_int64 (&value));
2508 contents = g_strdup_value_contents (&value);
2510 xmlNewChild (param, NULL, (xmlChar *) "value", (xmlChar *) contents);
2513 g_value_unset (&value);
2519 pads = GST_ELEMENT_PADS (element);
2522 GstPad *pad = GST_PAD (pads->data);
2524 /* figure out if it's a direct pad or a ghostpad */
2525 if (GST_ELEMENT (GST_OBJECT_PARENT (pad)) == element) {
2526 xmlNodePtr padtag = xmlNewChild (parent, NULL, (xmlChar *) "pad", NULL);
2528 gst_object_save_thyself (GST_OBJECT (pad), padtag);
2530 pads = g_list_next (pads);
2537 gst_element_restore_thyself (GstObject * object, xmlNodePtr self)
2539 xmlNodePtr children;
2540 GstElement *element;
2542 gchar *value = NULL;
2544 element = GST_ELEMENT (object);
2545 g_return_if_fail (element != NULL);
2548 children = self->xmlChildrenNode;
2550 if (!strcmp ((char *) children->name, "param")) {
2551 xmlNodePtr child = children->xmlChildrenNode;
2554 if (!strcmp ((char *) child->name, "name")) {
2555 name = (gchar *) xmlNodeGetContent (child);
2556 } else if (!strcmp ((char *) child->name, "value")) {
2557 value = (gchar *) xmlNodeGetContent (child);
2559 child = child->next;
2561 /* FIXME: can this just be g_object_set ? */
2562 gst_util_set_object_arg (G_OBJECT (element), name, value);
2563 /* g_object_set (G_OBJECT (element), name, value, NULL); */
2567 children = children->next;
2571 children = self->xmlChildrenNode;
2573 if (!strcmp ((char *) children->name, "pad")) {
2574 gst_pad_load_and_link (children, GST_OBJECT (element));
2576 children = children->next;
2579 if (GST_OBJECT_CLASS (parent_class)->restore_thyself)
2580 (GST_OBJECT_CLASS (parent_class)->restore_thyself) (object, self);
2582 #endif /* GST_DISABLE_LOADSAVE */
2585 gst_element_set_bus_func (GstElement * element, GstBus * bus)
2587 g_return_if_fail (GST_IS_ELEMENT (element));
2589 GST_CAT_DEBUG_OBJECT (GST_CAT_PARENTAGE, element, "setting bus to %p", bus);
2591 GST_OBJECT_LOCK (element);
2592 gst_object_replace ((GstObject **) & GST_ELEMENT_BUS (element),
2593 GST_OBJECT_CAST (bus));
2594 GST_OBJECT_UNLOCK (element);
2598 * gst_element_set_bus:
2599 * @element: a #GstElement to set the bus of.
2600 * @bus: the #GstBus to set.
2602 * Sets the bus of the element. For internal use only, unless you're
2608 gst_element_set_bus (GstElement * element, GstBus * bus)
2610 GstElementClass *oclass;
2612 g_return_if_fail (GST_IS_ELEMENT (element));
2614 oclass = GST_ELEMENT_GET_CLASS (element);
2616 if (oclass->set_bus)
2617 oclass->set_bus (element, bus);
2621 * gst_element_get_bus:
2622 * @element: a #GstElement to get the bus of.
2624 * Returns the bus of the element.
2626 * Returns: the element's #GstBus. unref after usage.
2631 gst_element_get_bus (GstElement * element)
2633 GstBus *result = NULL;
2635 g_return_val_if_fail (GST_IS_ELEMENT (element), result);
2637 GST_OBJECT_LOCK (element);
2638 result = GST_ELEMENT_BUS (element);
2639 gst_object_ref (result);
2640 GST_OBJECT_UNLOCK (element);
2642 GST_DEBUG_OBJECT (element, "got bus %" GST_PTR_FORMAT, result);