2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
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 #include <gobject/gvaluecollector.h>
26 #include "gst_private.h"
28 #include "gstelement.h"
30 #include "gstscheduler.h"
35 /* Element signals and args */
52 extern void __gst_element_details_clear (GstElementDetails *dp);
53 extern void __gst_element_details_set (GstElementDetails *dest,
54 const GstElementDetails *src);
56 static void gst_element_class_init (GstElementClass *klass);
57 static void gst_element_init (GstElement *element);
58 static void gst_element_base_class_init (gpointer g_class);
59 static void gst_element_base_class_finalize (gpointer g_class);
61 static void gst_element_real_set_property (GObject *object, guint prop_id,
62 const GValue *value, GParamSpec *pspec);
63 static void gst_element_real_get_property (GObject *object, guint prop_id, GValue *value,
66 static void gst_element_dispose (GObject *object);
68 static GstElementStateReturn gst_element_change_state (GstElement *element);
69 static void gst_element_error_func (GstElement* element, GstElement *source, gchar *errormsg);
70 static void gst_element_found_tag_func (GstElement* element, GstElement *source, GstTagList *tag_list);
72 #ifndef GST_DISABLE_LOADSAVE
73 static xmlNodePtr gst_element_save_thyself (GstObject *object, xmlNodePtr parent);
74 static void gst_element_restore_thyself (GstObject *parent, xmlNodePtr self);
77 GType _gst_element_type = 0;
79 static GstObjectClass *parent_class = NULL;
80 static guint gst_element_signals[LAST_SIGNAL] = { 0 };
82 GType gst_element_get_type (void)
84 if (!_gst_element_type) {
85 static const GTypeInfo element_info = {
86 sizeof(GstElementClass),
87 gst_element_base_class_init,
88 gst_element_base_class_finalize,
89 (GClassInitFunc)gst_element_class_init,
94 (GInstanceInitFunc)gst_element_init,
97 _gst_element_type = g_type_register_static(GST_TYPE_OBJECT, "GstElement",
98 &element_info, G_TYPE_FLAG_ABSTRACT);
100 return _gst_element_type;
104 gst_element_class_init (GstElementClass *klass)
106 GObjectClass *gobject_class;
107 GstObjectClass *gstobject_class;
109 gobject_class = (GObjectClass*) klass;
110 gstobject_class = (GstObjectClass*) klass;
112 parent_class = g_type_class_ref(GST_TYPE_OBJECT);
114 gst_element_signals[STATE_CHANGE] =
115 g_signal_new ("state_change", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
116 G_STRUCT_OFFSET (GstElementClass, state_change), NULL, NULL,
117 gst_marshal_VOID__INT_INT, G_TYPE_NONE, 2,
118 G_TYPE_INT, G_TYPE_INT);
119 gst_element_signals[NEW_PAD] =
120 g_signal_new ("new_pad", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
121 G_STRUCT_OFFSET (GstElementClass, new_pad), NULL, NULL,
122 gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1,
124 gst_element_signals[PAD_REMOVED] =
125 g_signal_new ("pad_removed", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
126 G_STRUCT_OFFSET (GstElementClass, pad_removed), NULL, NULL,
127 gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1,
129 gst_element_signals[ERROR] =
130 g_signal_new ("error", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
131 G_STRUCT_OFFSET (GstElementClass, error), NULL, NULL,
132 gst_marshal_VOID__OBJECT_STRING, G_TYPE_NONE, 2,
133 GST_TYPE_ELEMENT, G_TYPE_STRING);
134 gst_element_signals[EOS] =
135 g_signal_new ("eos", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
136 G_STRUCT_OFFSET (GstElementClass, eos), NULL, NULL,
137 gst_marshal_VOID__VOID, G_TYPE_NONE, 0);
138 gst_element_signals[FOUND_TAG] =
139 g_signal_new ("found-tag", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
140 G_STRUCT_OFFSET (GstElementClass, found_tag), NULL, NULL,
141 gst_marshal_VOID__OBJECT_POINTER, G_TYPE_NONE, 2,
142 GST_TYPE_ELEMENT, G_TYPE_POINTER);
144 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_element_real_set_property);
145 gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_element_real_get_property);
147 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_element_dispose);
149 #ifndef GST_DISABLE_LOADSAVE
150 gstobject_class->save_thyself = GST_DEBUG_FUNCPTR (gst_element_save_thyself);
151 gstobject_class->restore_thyself = GST_DEBUG_FUNCPTR (gst_element_restore_thyself);
154 klass->change_state = GST_DEBUG_FUNCPTR (gst_element_change_state);
155 klass->error = GST_DEBUG_FUNCPTR (gst_element_error_func);
156 klass->found_tag = GST_DEBUG_FUNCPTR (gst_element_found_tag_func);
157 klass->padtemplates = NULL;
158 klass->numpadtemplates = 0;
160 klass->elementfactory = NULL;
164 gst_element_base_class_init (gpointer g_class)
166 GObjectClass *gobject_class = G_OBJECT_CLASS (g_class);
168 gobject_class->set_property = GST_DEBUG_FUNCPTR(gst_element_real_set_property);
169 gobject_class->get_property = GST_DEBUG_FUNCPTR(gst_element_real_get_property);
173 gst_element_base_class_finalize (gpointer g_class)
175 GstElementClass *klass = GST_ELEMENT_CLASS (klass);
177 g_list_foreach (klass->padtemplates, (GFunc) g_object_unref, NULL);
178 g_list_free (klass->padtemplates);
179 __gst_element_details_clear (&klass->details);
183 gst_element_init (GstElement *element)
185 element->current_state = GST_STATE_NULL;
186 element->pending_state = GST_STATE_VOID_PENDING;
187 element->numpads = 0;
188 element->numsrcpads = 0;
189 element->numsinkpads = 0;
190 element->pads = NULL;
191 element->loopfunc = NULL;
192 element->sched = NULL;
193 element->clock = NULL;
194 element->sched_private = NULL;
195 element->state_mutex = g_mutex_new ();
196 element->state_cond = g_cond_new ();
200 gst_element_real_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
202 GstElementClass *oclass = GST_ELEMENT_GET_CLASS (object);
204 if (oclass->set_property)
205 (oclass->set_property) (object, prop_id, value, pspec);
209 gst_element_real_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
211 GstElementClass *oclass = GST_ELEMENT_GET_CLASS (object);
213 if (oclass->get_property)
214 (oclass->get_property) (object, prop_id, value, pspec);
218 * gst_element_default_error:
219 * @object: a #GObject that signalled the error.
220 * @orig: the #GstObject that initiated the error.
221 * @error: the error message.
223 * Adds a default error signal callback to an
224 * element. The user data passed to the g_signal_connect is
226 * The default handler will simply print the error string
230 gst_element_default_error (GObject *object, GstObject *orig, gchar *error)
232 gchar *name = gst_object_get_path_string (orig);
233 g_print ("ERROR: %s: %s\n", name, error);
238 const GParamSpec *pspec;
243 element_set_property (GstElement *element, const GParamSpec *pspec, const GValue *value)
245 prop_value_t *prop_value = g_new0 (prop_value_t, 1);
247 prop_value->pspec = pspec;
248 prop_value->value = *value;
250 g_async_queue_push (element->prop_value_queue, prop_value);
254 element_get_property (GstElement *element, const GParamSpec *pspec, GValue *value)
256 g_mutex_lock (element->property_mutex);
257 g_object_get_property ((GObject*)element, pspec->name, value);
258 g_mutex_unlock (element->property_mutex);
262 gst_element_threadsafe_properties_pre_run (GstElement *element)
264 GST_DEBUG ("locking element %s", GST_OBJECT_NAME (element));
265 g_mutex_lock (element->property_mutex);
266 gst_element_set_pending_properties (element);
270 gst_element_threadsafe_properties_post_run (GstElement *element)
272 GST_DEBUG ("unlocking element %s", GST_OBJECT_NAME (element));
273 g_mutex_unlock (element->property_mutex);
277 * gst_element_enable_threadsafe_properties:
278 * @element: a #GstElement to enable threadsafe properties on.
280 * Installs an asynchronous queue, a mutex and pre- and post-run functions on
281 * this element so that properties on the element can be set in a
285 gst_element_enable_threadsafe_properties (GstElement *element)
287 g_return_if_fail (GST_IS_ELEMENT (element));
289 GST_FLAG_SET (element, GST_ELEMENT_USE_THREADSAFE_PROPERTIES);
290 element->pre_run_func = gst_element_threadsafe_properties_pre_run;
291 element->post_run_func = gst_element_threadsafe_properties_post_run;
292 if (!element->prop_value_queue)
293 element->prop_value_queue = g_async_queue_new ();
294 if (!element->property_mutex)
295 element->property_mutex = g_mutex_new ();
299 * gst_element_disable_threadsafe_properties:
300 * @element: a #GstElement to disable threadsafe properties on.
302 * Removes the threadsafe properties, post- and pre-run locks from
306 gst_element_disable_threadsafe_properties (GstElement *element)
308 g_return_if_fail (GST_IS_ELEMENT (element));
310 GST_FLAG_UNSET (element, GST_ELEMENT_USE_THREADSAFE_PROPERTIES);
311 element->pre_run_func = NULL;
312 element->post_run_func = NULL;
313 /* let's keep around that async queue */
317 * gst_element_set_pending_properties:
318 * @element: a #GstElement to set the pending properties on.
320 * Sets all pending properties on the threadsafe properties enabled
324 gst_element_set_pending_properties (GstElement *element)
326 prop_value_t *prop_value;
328 while ((prop_value = g_async_queue_try_pop (element->prop_value_queue))) {
329 g_object_set_property ((GObject*)element, prop_value->pspec->name, &prop_value->value);
330 g_value_unset (&prop_value->value);
335 /* following 6 functions taken mostly from gobject.c */
339 * @element: a #GstElement to set properties on.
340 * @first_property_name: the first property to set.
341 * @...: value of the first property, and more properties to set, ending
344 * Sets properties on an element. If the element uses threadsafe properties,
345 * they will be queued and set on the object when it is scheduled again.
348 gst_element_set (GstElement *element, const gchar *first_property_name, ...)
352 g_return_if_fail (GST_IS_ELEMENT (element));
354 va_start (var_args, first_property_name);
355 gst_element_set_valist (element, first_property_name, var_args);
361 * @element: a #GstElement to get properties of.
362 * @first_property_name: the first property to get.
363 * @...: pointer to a variable to store the first property in, as well as
364 * more properties to get, ending with NULL.
366 * Gets properties from an element. If the element uses threadsafe properties,
367 * the element will be locked before getting the given properties.
370 gst_element_get (GstElement *element, const gchar *first_property_name, ...)
374 g_return_if_fail (GST_IS_ELEMENT (element));
376 va_start (var_args, first_property_name);
377 gst_element_get_valist (element, first_property_name, var_args);
382 * gst_element_set_valist:
383 * @element: a #GstElement to set properties on.
384 * @first_property_name: the first property to set.
385 * @var_args: the var_args list of other properties to get.
387 * Sets properties on an element. If the element uses threadsafe properties,
388 * the property change will be put on the async queue.
391 gst_element_set_valist (GstElement *element, const gchar *first_property_name, va_list var_args)
396 g_return_if_fail (GST_IS_ELEMENT (element));
398 object = (GObject *) element;
400 GST_CAT_DEBUG (GST_CAT_PROPERTIES,
401 "setting valist of properties starting with %s on element %s",
402 first_property_name, gst_element_get_name (element));
404 if (!GST_FLAG_IS_SET (element, GST_ELEMENT_USE_THREADSAFE_PROPERTIES)) {
405 g_object_set_valist (object, first_property_name, var_args);
409 g_object_ref (object);
411 name = first_property_name;
415 GValue value = { 0, };
419 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (object), name);
423 g_warning ("%s: object class `%s' has no property named `%s'",
425 G_OBJECT_TYPE_NAME (object),
429 if (!(pspec->flags & G_PARAM_WRITABLE))
431 g_warning ("%s: property `%s' of object class `%s' is not writable",
434 G_OBJECT_TYPE_NAME (object));
438 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
440 G_VALUE_COLLECT (&value, var_args, 0, &error);
443 g_warning ("%s: %s", G_STRLOC, error);
446 /* we purposely leak the value here, it might not be
447 * in a sane state if an error condition occoured
452 element_set_property (element, pspec, &value);
453 g_value_unset (&value);
455 name = va_arg (var_args, gchar*);
458 g_object_unref (object);
462 * gst_element_get_valist:
463 * @element: a #GstElement to get properties of.
464 * @first_property_name: the first property to get.
465 * @var_args: the var_args list of other properties to get.
467 * Gets properties from an element. If the element uses threadsafe properties,
468 * the element will be locked before getting the given properties.
471 gst_element_get_valist (GstElement *element, const gchar *first_property_name, va_list var_args)
476 g_return_if_fail (GST_IS_ELEMENT (element));
478 object = (GObject*)element;
480 if (!GST_FLAG_IS_SET (element, GST_ELEMENT_USE_THREADSAFE_PROPERTIES)) {
481 g_object_get_valist (object, first_property_name, var_args);
485 g_object_ref (object);
487 name = first_property_name;
491 GValue value = { 0, };
495 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (object), name);
499 g_warning ("%s: object class `%s' has no property named `%s'",
501 G_OBJECT_TYPE_NAME (object),
505 if (!(pspec->flags & G_PARAM_READABLE))
507 g_warning ("%s: property `%s' of object class `%s' is not readable",
510 G_OBJECT_TYPE_NAME (object));
514 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
516 element_get_property (element, pspec, &value);
518 G_VALUE_LCOPY (&value, var_args, 0, &error);
521 g_warning ("%s: %s", G_STRLOC, error);
523 g_value_unset (&value);
527 g_value_unset (&value);
529 name = va_arg (var_args, gchar*);
532 g_object_unref (object);
536 * gst_element_set_property:
537 * @element: a #GstElement to set properties on.
538 * @property_name: the first property to get.
539 * @value: the #GValue that holds the value to set.
541 * Sets a property on an element. If the element uses threadsafe properties,
542 * the property will be put on the async queue.
545 gst_element_set_property (GstElement *element, const gchar *property_name,
551 g_return_if_fail (GST_IS_ELEMENT (element));
552 g_return_if_fail (property_name != NULL);
553 g_return_if_fail (G_IS_VALUE (value));
555 object = (GObject*) element;
557 GST_CAT_DEBUG (GST_CAT_PROPERTIES, "setting property %s on element %s",
558 property_name, gst_element_get_name (element));
559 if (!GST_FLAG_IS_SET (element, GST_ELEMENT_USE_THREADSAFE_PROPERTIES)) {
560 g_object_set_property (object, property_name, value);
564 g_object_ref (object);
566 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (object),
570 g_warning ("%s: object class `%s' has no property named `%s'",
572 G_OBJECT_TYPE_NAME (object),
575 element_set_property (element, pspec, value);
577 g_object_unref (object);
581 * gst_element_get_property:
582 * @element: a #GstElement to get properties of.
583 * @property_name: the first property to get.
584 * @value: the #GValue to store the property value in.
586 * Gets a property from an element. If the element uses threadsafe properties,
587 * the element will be locked before getting the given property.
590 gst_element_get_property (GstElement *element, const gchar *property_name, GValue *value)
595 g_return_if_fail (GST_IS_ELEMENT (element));
596 g_return_if_fail (property_name != NULL);
597 g_return_if_fail (G_IS_VALUE (value));
599 object = (GObject*)element;
601 if (!GST_FLAG_IS_SET (element, GST_ELEMENT_USE_THREADSAFE_PROPERTIES)) {
602 g_object_get_property (object, property_name, value);
606 g_object_ref (object);
608 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (object), property_name);
611 g_warning ("%s: object class `%s' has no property named `%s'",
613 G_OBJECT_TYPE_NAME (object),
617 GValue *prop_value, tmp_value = { 0, };
619 /* auto-conversion of the callers value type
621 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
623 g_value_reset (value);
626 else if (!g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
628 g_warning ("can't retrieve property `%s' of type `%s' as value of type `%s'",
630 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
631 G_VALUE_TYPE_NAME (value));
632 g_object_unref (object);
637 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
638 prop_value = &tmp_value;
640 element_get_property (element, pspec, prop_value);
641 if (prop_value != value)
643 g_value_transform (prop_value, value);
644 g_value_unset (&tmp_value);
648 g_object_unref (object);
652 gst_element_request_pad (GstElement *element, GstPadTemplate *templ, const gchar* name)
654 GstPad *newpad = NULL;
655 GstElementClass *oclass;
657 oclass = GST_ELEMENT_GET_CLASS (element);
659 if (oclass->request_new_pad)
660 newpad = (oclass->request_new_pad)(element, templ, name);
666 * gst_element_release_request_pad:
667 * @element: a #GstElement to release the request pad of.
668 * @pad: the #GstPad to release.
670 * Makes the element free the previously requested pad as obtained
671 * with gst_element_get_request_pad().
674 gst_element_release_request_pad (GstElement *element, GstPad *pad)
676 GstElementClass *oclass;
678 g_return_if_fail (GST_IS_ELEMENT (element));
679 g_return_if_fail (GST_IS_PAD (pad));
681 oclass = GST_ELEMENT_GET_CLASS (element);
683 if (oclass->release_pad)
684 (oclass->release_pad) (element, pad);
688 * gst_element_requires_clock:
689 * @element: a #GstElement to query
691 * Query if the element requiresd a clock
693 * Returns: TRUE if the element requires a clock
696 gst_element_requires_clock (GstElement *element)
698 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
700 return (GST_ELEMENT_GET_CLASS (element)->set_clock != NULL);
704 * gst_element_provides_clock:
705 * @element: a #GstElement to query
707 * Query if the element provides a clock
709 * Returns: TRUE if the element provides a clock
712 gst_element_provides_clock (GstElement *element)
714 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
716 return (GST_ELEMENT_GET_CLASS (element)->get_clock != NULL);
720 * gst_element_set_clock:
721 * @element: a #GstElement to set the clock for.
722 * @clock: the #GstClock to set for the element.
724 * Sets the clock for the element.
727 gst_element_set_clock (GstElement *element, GstClock *clock)
729 GstElementClass *oclass;
731 g_return_if_fail (GST_IS_ELEMENT (element));
733 oclass = GST_ELEMENT_GET_CLASS (element);
735 if (oclass->set_clock)
736 oclass->set_clock (element, clock);
738 gst_object_replace ((GstObject **)&element->clock, (GstObject *)clock);
742 * gst_element_get_clock:
743 * @element: a #GstElement to get the clock of.
745 * Gets the clock of the element.
747 * Returns: the #GstClock of the element.
750 gst_element_get_clock (GstElement *element)
752 GstElementClass *oclass;
754 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
756 oclass = GST_ELEMENT_GET_CLASS (element);
758 if (oclass->get_clock)
759 return oclass->get_clock (element);
765 * gst_element_clock_wait:
766 * @element: a #GstElement.
767 * @id: the #GstClock to use.
768 * @jitter: the difference between requested time and actual time.
770 * Waits for a specific time on the clock.
772 * Returns: the #GstClockReturn result of the wait operation.
775 gst_element_clock_wait (GstElement *element, GstClockID id, GstClockTimeDiff *jitter)
779 g_return_val_if_fail (GST_IS_ELEMENT (element), GST_CLOCK_ERROR);
781 if (GST_ELEMENT_SCHED (element)) {
782 GST_CAT_DEBUG (GST_CAT_CLOCK, "waiting on scheduler clock");
783 res = gst_scheduler_clock_wait (GST_ELEMENT_SCHED (element), element, id, jitter);
786 GST_CAT_DEBUG (GST_CAT_CLOCK, "no scheduler, returning GST_CLOCK_TIMEOUT");
787 res = GST_CLOCK_TIMEOUT;
793 #ifndef GST_DISABLE_INDEX
795 * gst_element_is_indexable:
796 * @element: a #GstElement.
798 * Queries if the element can be indexed/
800 * Returns: TRUE if the element can be indexed.
803 gst_element_is_indexable (GstElement *element)
805 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
807 return (GST_ELEMENT_GET_CLASS (element)->set_index != NULL);
811 * gst_element_set_index:
812 * @element: a #GstElement.
813 * @index: a #GstIndex.
815 * Set the specified GstIndex on the element.
818 gst_element_set_index (GstElement *element, GstIndex *index)
820 GstElementClass *oclass;
822 g_return_if_fail (GST_IS_ELEMENT (element));
823 g_return_if_fail (GST_IS_INDEX (index));
825 oclass = GST_ELEMENT_GET_CLASS (element);
827 if (oclass->set_index)
828 oclass->set_index (element, index);
832 * gst_element_get_index:
833 * @element: a #GstElement.
835 * Gets the index from the element.
837 * Returns: a #GstIndex or NULL when no index was set on the
841 gst_element_get_index (GstElement *element)
843 GstElementClass *oclass;
845 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
847 oclass = GST_ELEMENT_GET_CLASS (element);
849 if (oclass->get_index)
850 return oclass->get_index (element);
857 * gst_element_release_locks:
858 * @element: a #GstElement to release all locks on.
860 * Instruct the element to release all the locks it is holding, such as
861 * blocking reads, waiting for the clock, ...
863 * Returns: TRUE if the locks could be released.
866 gst_element_release_locks (GstElement *element)
868 GstElementClass *oclass;
870 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
872 oclass = GST_ELEMENT_GET_CLASS (element);
874 if (oclass->release_locks)
875 return oclass->release_locks (element);
881 * gst_element_add_pad:
882 * @element: a #GstElement to add the pad to.
883 * @pad: the #GstPad to add to the element.
885 * Add a pad (link point) to the element, setting the parent of the
886 * pad to the element (and thus adding a reference).
887 * Pads are automatically activated when the element is in state PLAYING.
890 gst_element_add_pad (GstElement *element, GstPad *pad)
892 g_return_if_fail (GST_IS_ELEMENT (element));
893 g_return_if_fail (GST_IS_PAD (pad));
895 /* first check to make sure the pad's parent is already set */
896 g_return_if_fail (GST_PAD_PARENT (pad) == NULL);
898 /* then check to see if there's already a pad by that name here */
899 g_return_if_fail (gst_object_check_uniqueness (element->pads, GST_PAD_NAME(pad)) == TRUE);
901 /* set the pad's parent */
902 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,"setting parent of pad '%s' to '%s'",
903 GST_PAD_NAME (pad), GST_STR_NULL (GST_ELEMENT_NAME (element)));
904 gst_object_set_parent (GST_OBJECT (pad), GST_OBJECT (element));
906 /* add it to the list */
907 element->pads = g_list_append (element->pads, pad);
909 if (gst_pad_get_direction (pad) == GST_PAD_SRC)
910 element->numsrcpads++;
912 element->numsinkpads++;
914 /* activate element when we are playing */
915 if (GST_STATE (element) == GST_STATE_PLAYING)
916 gst_pad_set_active (pad, TRUE);
918 /* emit the NEW_PAD signal */
919 g_signal_emit (G_OBJECT (element), gst_element_signals[NEW_PAD], 0, pad);
923 * gst_element_remove_pad:
924 * @element: a #GstElement to remove pad from.
925 * @pad: the #GstPad to remove from the element.
927 * Remove a pad (link point) from the element.
930 gst_element_remove_pad (GstElement *element, GstPad *pad)
932 g_return_if_fail (element != NULL);
933 g_return_if_fail (GST_IS_ELEMENT (element));
934 g_return_if_fail (pad != NULL);
935 g_return_if_fail (GST_IS_PAD (pad));
937 g_return_if_fail (GST_PAD_PARENT (pad) == element);
939 /* check to see if the pad is still linked */
940 /* FIXME: what if someone calls _remove_pad instead of
941 _remove_ghost_pad? */
942 if (GST_IS_REAL_PAD (pad)) {
943 if (GST_RPAD_PEER (pad) != NULL) {
944 gst_pad_unlink (pad, GST_PAD (GST_RPAD_PEER (pad)));
948 /* remove it from the list */
949 element->pads = g_list_remove (element->pads, pad);
951 if (gst_pad_get_direction (pad) == GST_PAD_SRC)
952 element->numsrcpads--;
954 element->numsinkpads--;
956 g_signal_emit (G_OBJECT (element), gst_element_signals[PAD_REMOVED], 0, pad);
958 gst_object_unparent (GST_OBJECT (pad));
962 * gst_element_add_ghost_pad:
963 * @element: a #GstElement to add the ghost pad to.
964 * @pad: the #GstPad from which the new ghost pad will be created.
965 * @name: the name of the new ghost pad.
967 * Creates a ghost pad from the given pad, and adds it to the list of pads
970 * Returns: the added ghost #GstPad, or NULL, if no ghost pad was created.
973 gst_element_add_ghost_pad (GstElement *element, GstPad *pad, const gchar *name)
977 g_return_val_if_fail (element != NULL, NULL);
978 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
979 g_return_val_if_fail (pad != NULL, NULL);
980 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
982 /* then check to see if there's already a pad by that name here */
983 g_return_val_if_fail (gst_object_check_uniqueness (element->pads, name) == TRUE, NULL);
985 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
986 "creating new ghost pad called %s, from pad %s:%s",
987 name, GST_DEBUG_PAD_NAME(pad));
988 ghostpad = gst_ghost_pad_new (name, pad);
990 /* add it to the list */
991 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,"adding ghost pad %s to element %s",
992 name, GST_ELEMENT_NAME (element));
993 element->pads = g_list_append (element->pads, ghostpad);
995 /* set the parent of the ghostpad */
996 gst_object_set_parent (GST_OBJECT (ghostpad), GST_OBJECT (element));
998 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,"added ghostpad %s:%s",GST_DEBUG_PAD_NAME(ghostpad));
1000 /* emit the NEW_GHOST_PAD signal */
1001 g_signal_emit (G_OBJECT (element), gst_element_signals[NEW_PAD], 0, ghostpad);
1007 * gst_element_remove_ghost_pad:
1008 * @element: a #GstElement to remove the ghost pad from.
1009 * @pad: ghost #GstPad to remove.
1011 * Removes a ghost pad from an element.
1014 gst_element_remove_ghost_pad (GstElement *element, GstPad *pad)
1016 g_return_if_fail (GST_IS_ELEMENT (element));
1017 g_return_if_fail (GST_IS_GHOST_PAD (pad));
1019 /* FIXME this is redundant?
1020 * wingo 10-july-2001: I don't think so, you have to actually remove the pad
1021 * from the element. gst_pad_remove_ghost_pad just removes the ghostpad from
1022 * the real pad's ghost pad list
1024 gst_object_ref (GST_OBJECT (pad));
1025 gst_element_remove_pad (element, pad);
1026 gst_pad_remove_ghost_pad (GST_PAD (GST_PAD_REALIZE (pad)), pad);
1027 gst_object_unref (GST_OBJECT (pad));
1032 * gst_element_get_pad:
1033 * @element: a #GstElement to find pad of.
1034 * @name: the name of the pad to retrieve.
1036 * Retrieves a pad from the element by name.
1038 * Returns: requested #GstPad if found, otherwise NULL.
1041 gst_element_get_pad (GstElement *element, const gchar *name)
1045 g_return_val_if_fail (element != NULL, NULL);
1046 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
1047 g_return_val_if_fail (name != NULL, NULL);
1049 pad = gst_element_get_static_pad (element, name);
1051 pad = gst_element_get_request_pad (element, name);
1057 * gst_element_get_static_pad:
1058 * @element: a #GstElement to find a static pad of.
1059 * @name: the name of the static #GstPad to retrieve.
1061 * Retrieves a pad from the element by name. This version only retrieves
1062 * already-existing (i.e. 'static') pads.
1064 * Returns: the requested #GstPad if found, otherwise NULL.
1067 gst_element_get_static_pad (GstElement *element, const gchar *name)
1071 g_return_val_if_fail (element != NULL, NULL);
1072 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
1073 g_return_val_if_fail (name != NULL, NULL);
1075 walk = element->pads;
1079 pad = GST_PAD(walk->data);
1080 if (strcmp (GST_PAD_NAME(pad), name) == 0) {
1081 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "found pad %s:%s", GST_DEBUG_PAD_NAME (pad));
1084 walk = g_list_next (walk);
1087 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "no such pad '%s' in element \"%s\"", name, GST_OBJECT_NAME (element));
1092 * gst_element_get_request_pad:
1093 * @element: a #GstElement to find a request pad of.
1094 * @name: the name of the request #GstPad to retrieve.
1096 * Retrieves a pad from the element by name. This version only retrieves
1099 * Returns: requested #GstPad if found, otherwise NULL.
1102 gst_element_get_request_pad (GstElement *element, const gchar *name)
1104 GstPadTemplate *templ = NULL;
1106 const gchar *req_name = NULL;
1107 gboolean templ_found = FALSE;
1111 gchar *str, *endptr = NULL;
1113 g_return_val_if_fail (element != NULL, NULL);
1114 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
1115 g_return_val_if_fail (name != NULL, NULL);
1117 if (strstr (name, "%")) {
1118 templ = gst_element_get_pad_template (element, name);
1123 list = gst_element_get_pad_template_list(element);
1124 while (!templ_found && list) {
1125 templ = (GstPadTemplate*) list->data;
1126 if (templ->presence == GST_PAD_REQUEST) {
1127 /* we know that %s and %d are the only possibilities because of sanity
1128 checks in gst_pad_template_new */
1129 GST_CAT_DEBUG (GST_CAT_PADS, "comparing %s to %s", name, templ->name_template);
1130 if ((str = strchr (templ->name_template, '%')) &&
1131 strncmp (templ->name_template, name, str - templ->name_template) == 0 &&
1132 strlen (name) > str - templ->name_template) {
1133 data = name + (str - templ->name_template);
1134 if (*(str+1) == 'd') {
1136 n = (gint) strtol (data, &endptr, 10);
1137 if (endptr && *endptr == '\0') {
1157 pad = gst_element_request_pad (element, templ, req_name);
1163 * gst_element_get_pad_list:
1164 * @element: a #GstElement to get pads of.
1166 * Retrieves a list of the pads associated with the element.
1168 * Returns: the #GList of pads.
1171 gst_element_get_pad_list (GstElement *element)
1173 g_return_val_if_fail (element != NULL, NULL);
1174 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
1176 /* return the list of pads */
1177 return element->pads;
1181 * gst_element_class_add_pad_template:
1182 * @klass: the #GstElementClass to add the pad template to.
1183 * @templ: a #GstPadTemplate to add to the element class.
1185 * Adds a padtemplate to an element class. This is mainly used in the _base_init
1186 * functions of classes.
1189 gst_element_class_add_pad_template (GstElementClass *klass,
1190 GstPadTemplate *templ)
1192 GstPadTemplate *templ_copy;
1194 g_return_if_fail (klass != NULL);
1195 g_return_if_fail (GST_IS_ELEMENT_CLASS (klass));
1196 g_return_if_fail (templ != NULL);
1197 g_return_if_fail (GST_IS_PAD_TEMPLATE (templ));
1198 /* avoid registering pad templates with the same name */
1199 g_return_if_fail (gst_element_class_get_pad_template (klass, templ->name_template) == NULL);
1201 templ_copy = g_memdup(templ, sizeof(GstPadTemplate));
1203 klass->padtemplates = g_list_append (klass->padtemplates, templ_copy);
1204 klass->numpadtemplates++;
1208 * gst_element_class_set_details:
1209 * @klass: class to set details for
1210 * @details: details to set
1212 * Sets the detailed information for a #GstElementClass.
1213 * <note>This function is for use in _base_init functions only.</note>
1216 gst_element_class_set_details (GstElementClass *klass, const GstElementDetails *details)
1218 g_return_if_fail (GST_IS_ELEMENT_CLASS (klass));
1219 g_return_if_fail (GST_IS_ELEMENT_DETAILS (details));
1221 __gst_element_details_set (&klass->details, details);
1225 * gst_element_class_get_pad_template_list:
1226 * @element: a #GstElementClass to get pad templates of.
1228 * Retrieves a list of the pad templates associated with the element.
1230 * Returns: the #GList of padtemplates.
1233 gst_element_class_get_pad_template_list (GstElementClass *element_class)
1235 g_return_val_if_fail (element_class != NULL, NULL);
1236 g_return_val_if_fail (GST_IS_ELEMENT_CLASS (element_class), NULL);
1238 return element_class->padtemplates;
1242 * gst_element_class_get_pad_template:
1243 * @element: a #GstElementClass to get the pad template of.
1244 * @name: the name of the #GstPadTemplate to get.
1246 * Retrieves a padtemplate from this element with the
1249 * Returns: the #GstPadTemplate with the given name, or NULL if none was found.
1250 * No unreferencing is necessary.
1253 gst_element_class_get_pad_template (GstElementClass *element_class, const gchar *name)
1257 g_return_val_if_fail (element_class != NULL, NULL);
1258 g_return_val_if_fail (GST_IS_ELEMENT_CLASS (element_class), NULL);
1259 g_return_val_if_fail (name != NULL, NULL);
1261 padlist = gst_element_class_get_pad_template_list (element_class);
1264 GstPadTemplate *padtempl = (GstPadTemplate*) padlist->data;
1266 if (strcmp (padtempl->name_template, name) == 0)
1269 padlist = g_list_next (padlist);
1276 * gst_element_get_pad_template_list:
1277 * @element: a #GstElement to get pad templates of.
1279 * Retrieves a list of the pad templates associated with the element.
1280 * (FIXME: Should be deprecated in favor of gst_element_class_get_pad_template_list).
1282 * Returns: the #GList of padtemplates.
1285 gst_element_get_pad_template_list (GstElement *element)
1287 g_return_val_if_fail (element != NULL, NULL);
1288 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
1290 return GST_ELEMENT_GET_CLASS (element)->padtemplates;
1294 * gst_element_get_pad_template:
1295 * @element: a #GstElement to get the pad template of.
1296 * @name: the name of the #GstPadTemplate to get.
1298 * Retrieves a padtemplate from this element with the
1300 * (FIXME: Should be deprecated in favor of gst_element_class_get_pad_template).
1302 * Returns: the #GstPadTemplate with the given name, or NULL if none was found.
1303 * No unreferencing is necessary.
1306 gst_element_get_pad_template (GstElement *element, const gchar *name)
1310 g_return_val_if_fail (element != NULL, NULL);
1311 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
1312 g_return_val_if_fail (name != NULL, NULL);
1314 padlist = gst_element_get_pad_template_list (element);
1317 GstPadTemplate *padtempl = (GstPadTemplate*) padlist->data;
1319 if (!strcmp (padtempl->name_template, name))
1322 padlist = g_list_next (padlist);
1329 * gst_element_get_compatible_pad_template:
1330 * @element: a #GstElement to get a compatible pad template for.
1331 * @compattempl: the #GstPadTemplate to find a compatible template for.
1333 * Generates a pad template for this element compatible with the given
1334 * template (meaning it is able to link with it).
1336 * Returns: the #GstPadTemplate of the element that is compatible with
1337 * the given GstPadTemplate, or NULL if none was found. No unreferencing
1341 gst_element_get_compatible_pad_template (GstElement *element,
1342 GstPadTemplate *compattempl)
1344 GstPadTemplate *newtempl = NULL;
1347 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "gst_element_get_compatible_pad_template()");
1349 g_return_val_if_fail (element != NULL, NULL);
1350 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
1351 g_return_val_if_fail (compattempl != NULL, NULL);
1353 padlist = gst_element_get_pad_template_list (element);
1356 GstPadTemplate *padtempl = (GstPadTemplate*) padlist->data;
1357 gboolean comp = FALSE;
1361 * Check direction (must be opposite)
1364 GST_CAT_DEBUG (GST_CAT_CAPS, "checking direction and caps");
1365 if (padtempl->direction == GST_PAD_SRC &&
1366 compattempl->direction == GST_PAD_SINK) {
1367 GST_CAT_DEBUG (GST_CAT_CAPS, "compatible direction: found src pad template");
1368 comp = gst_caps_is_always_compatible (GST_PAD_TEMPLATE_CAPS (compattempl),
1369 GST_PAD_TEMPLATE_CAPS (padtempl));
1370 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible", (comp ? "" : "not "));
1371 } else if (padtempl->direction == GST_PAD_SINK &&
1372 compattempl->direction == GST_PAD_SRC) {
1373 GST_CAT_DEBUG (GST_CAT_CAPS, "compatible direction: found sink pad template");
1374 comp = gst_caps_is_always_compatible (GST_PAD_TEMPLATE_CAPS (compattempl),
1375 GST_PAD_TEMPLATE_CAPS (padtempl));
1376 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible", (comp ? "" : "not "));
1380 newtempl = padtempl;
1384 padlist = g_list_next (padlist);
1391 * gst_element_request_compatible_pad:
1392 * @element: a #GstElement to request a new pad from.
1393 * @templ: the #GstPadTemplate to which the new pad should be able to link.
1395 * Requests a new pad from the element. The template will
1396 * be used to decide what type of pad to create. This function
1397 * is typically used for elements with a padtemplate with presence
1400 * Returns: the new #GstPad that was created, or NULL if none could be created.
1403 gst_element_request_compatible_pad (GstElement *element, GstPadTemplate *templ)
1405 GstPadTemplate *templ_new;
1408 g_return_val_if_fail (element != NULL, NULL);
1409 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
1410 g_return_val_if_fail (templ != NULL, NULL);
1412 templ_new = gst_element_get_compatible_pad_template (element, templ);
1413 if (templ_new != NULL)
1414 pad = gst_element_request_pad (element, templ_new, NULL);
1421 * gst_element_get_compatible_pad_filtered:
1422 * @element: a #GstElement in which the pad should be found.
1423 * @pad: the #GstPad to find a compatible one for.
1424 * @filtercaps: the #GstCaps to use as a filter.
1426 * Looks for an unlinked pad to which the given pad can link to.
1427 * It is not guaranteed that linking the pads will work, though
1428 * it should work in most cases.
1430 * Returns: the #GstPad to which a link can be made.
1433 gst_element_get_compatible_pad_filtered (GstElement *element, GstPad *pad,
1434 const GstCaps *filtercaps)
1437 GstPadTemplate *templ;
1439 GstPad *foundpad = NULL;
1442 g_return_val_if_fail (element != NULL, NULL);
1443 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
1444 g_return_val_if_fail (pad != NULL, NULL);
1445 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1447 GST_DEBUG ("finding pad in %s compatible with %s:%s",
1448 GST_ELEMENT_NAME (element), GST_DEBUG_PAD_NAME (pad));
1450 /* let's use the real pad */
1451 pad = (GstPad *) GST_PAD_REALIZE (pad);
1452 g_return_val_if_fail (pad != NULL, NULL);
1453 g_return_val_if_fail (GST_RPAD_PEER (pad) == NULL, NULL);
1455 /* try to get an existing unlinked pad */
1456 pads = gst_element_get_pad_list (element);
1458 GstPad *current = GST_PAD (pads->data);
1459 if ((GST_PAD_PEER (GST_PAD_REALIZE (current)) == NULL) &&
1460 gst_pad_can_link_filtered (pad, current, filtercaps)) {
1463 pads = g_list_next (pads);
1466 /* try to create a new one */
1467 /* requesting is a little crazy, we need a template. Let's create one */
1468 templcaps = gst_pad_get_caps (pad);
1469 if (filtercaps != NULL) {
1471 temp = gst_caps_intersect (filtercaps, templcaps);
1472 gst_caps_free (templcaps);
1476 templ = gst_pad_template_new ((gchar *) GST_PAD_NAME (pad),
1477 GST_RPAD_DIRECTION (pad), GST_PAD_ALWAYS, templcaps);
1478 foundpad = gst_element_request_compatible_pad (element, templ);
1479 gst_object_unref (GST_OBJECT (templ));
1481 if (foundpad) return foundpad;
1483 /* FIXME: this is broken, but it's in here so autoplugging elements
1484 * that don't have caps on their source padtemplates (spider) can
1486 //g_warning("got here");
1487 //if (filtercaps == NULL) {
1488 templ = gst_pad_template_new ((gchar *) GST_PAD_NAME (pad),
1489 GST_RPAD_DIRECTION (pad), GST_PAD_ALWAYS, gst_caps_new_any());
1490 foundpad = gst_element_request_compatible_pad (element, templ);
1491 gst_object_unref (GST_OBJECT (templ));
1493 if (foundpad) return foundpad;
1496 g_critical("could not find a compatible pad");
1502 * gst_element_get_compatible_pad:
1503 * @element: a #GstElement in which the pad should be found.
1504 * @pad: the #GstPad to find a compatible one for.
1506 * Looks for an unlinked pad to which the given pad can link to.
1507 * It is not guaranteed that linking the pads will work, though
1508 * it should work in most cases.
1510 * Returns: the #GstPad to which a link can be made, or NULL if none
1514 gst_element_get_compatible_pad (GstElement *element, GstPad *pad)
1516 return gst_element_get_compatible_pad_filtered (element, pad, NULL);
1520 * gst_element_link_pads_filtered:
1521 * @src: a #GstElement containing the source pad.
1522 * @srcpadname: the name of the #GstPad in source element or NULL for any pad.
1523 * @dest: the #GstElement containing the destination pad.
1524 * @destpadname: the name of the #GstPad in destination element or NULL for any pad.
1525 * @filtercaps: the #GstCaps to use as a filter.
1527 * Links the two named pads of the source and destination elements.
1528 * Side effect is that if one of the pads has no parent, it becomes a
1529 * child of the parent of the other element. If they have different
1530 * parents, the link fails.
1532 * Returns: TRUE if the pads could be linked.
1535 gst_element_link_pads_filtered (GstElement *src, const gchar *srcpadname,
1536 GstElement *dest, const gchar *destpadname,
1537 const GstCaps *filtercaps)
1539 const GList *srcpads, *destpads, *srctempls, *desttempls, *l;
1540 GstPad *srcpad, *destpad;
1541 GstPadTemplate *srctempl, *desttempl;
1544 g_return_val_if_fail (GST_IS_ELEMENT (src), FALSE);
1545 g_return_val_if_fail (GST_IS_ELEMENT (dest), FALSE);
1547 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "trying to link element %s:%s to element %s:%s",
1548 GST_ELEMENT_NAME (src), srcpadname ? srcpadname : "(any)",
1549 GST_ELEMENT_NAME (dest), destpadname ? destpadname : "(any)");
1551 /* now get the pads we're trying to link and a list of all remaining pads */
1553 srcpad = gst_element_get_pad (src, srcpadname);
1555 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no pad %s:%s", GST_ELEMENT_NAME (src), srcpadname);
1558 if (!(GST_RPAD_DIRECTION (srcpad) == GST_PAD_SRC)) {
1559 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "pad %s:%s is no src pad", GST_DEBUG_PAD_NAME (srcpad));
1562 if (GST_PAD_PEER (srcpad) != NULL) {
1563 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "pad %s:%s is already linked", GST_DEBUG_PAD_NAME (srcpad));
1569 srcpads = gst_element_get_pad_list (src);
1570 srcpad = srcpads ? (GstPad *) GST_PAD_REALIZE (srcpads->data) : NULL;
1573 destpad = gst_element_get_pad (dest, destpadname);
1575 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no pad %s:%s", GST_ELEMENT_NAME (dest), destpadname);
1578 if (!(GST_RPAD_DIRECTION (destpad) == GST_PAD_SINK)) {
1579 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "pad %s:%s is no sink pad", GST_DEBUG_PAD_NAME (destpad));
1582 if (GST_PAD_PEER (destpad) != NULL) {
1583 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "pad %s:%s is already linked", GST_DEBUG_PAD_NAME (destpad));
1589 destpads = gst_element_get_pad_list (dest);
1590 destpad = destpads ? (GstPad *) GST_PAD_REALIZE (destpads->data) : NULL;
1593 if (srcpadname && destpadname) {
1594 /* two explicitly specified pads */
1595 return gst_pad_link_filtered (srcpad, destpad, filtercaps);
1598 /* loop through the allowed pads in the source, trying to find a
1599 * compatible destination pad */
1600 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "looping through allowed src and dest pads");
1602 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "trying src pad %s:%s",
1603 GST_DEBUG_PAD_NAME (srcpad));
1604 if ((GST_RPAD_DIRECTION (srcpad) == GST_PAD_SRC) &&
1605 (GST_PAD_PEER (srcpad) == NULL)) {
1606 GstPad *temp = gst_element_get_compatible_pad_filtered (dest, srcpad,
1608 if (temp && gst_pad_link_filtered (srcpad, temp, filtercaps)) {
1609 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "linked pad %s:%s to pad %s:%s",
1610 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (temp));
1614 /* find a better way for this mess */
1616 srcpads = g_list_next (srcpads);
1618 srcpad = (GstPad *) GST_PAD_REALIZE (srcpads->data);
1623 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no link possible from %s:%s to %s",
1624 GST_DEBUG_PAD_NAME (srcpad), GST_ELEMENT_NAME (dest));
1628 /* loop through the existing pads in the destination */
1630 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "trying dest pad %s:%s",
1631 GST_DEBUG_PAD_NAME (destpad));
1632 if ((GST_RPAD_DIRECTION (destpad) == GST_PAD_SINK) &&
1633 (GST_PAD_PEER (destpad) == NULL)) {
1634 GstPad *temp = gst_element_get_compatible_pad_filtered (src, destpad,
1636 if (temp && gst_pad_link_filtered (temp, destpad, filtercaps)) {
1637 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "linked pad %s:%s to pad %s:%s",
1638 GST_DEBUG_PAD_NAME (temp), GST_DEBUG_PAD_NAME (destpad));
1643 destpads = g_list_next (destpads);
1645 destpad = (GstPad *) GST_PAD_REALIZE (destpads->data);
1650 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no link possible from %s to %s:%s",
1651 GST_ELEMENT_NAME (src), GST_DEBUG_PAD_NAME (destpad));
1655 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
1656 "we might have request pads on both sides, checking...");
1657 srctempls = gst_element_get_pad_template_list (src);
1658 desttempls = gst_element_get_pad_template_list (dest);
1660 if (srctempls && desttempls) {
1662 srctempl = (GstPadTemplate*) srctempls->data;
1663 if (srctempl->presence == GST_PAD_REQUEST) {
1664 for (l=desttempls; l; l=l->next) {
1665 desttempl = (GstPadTemplate*) l->data;
1666 if (desttempl->presence == GST_PAD_REQUEST &&
1667 desttempl->direction != srctempl->direction) {
1668 if (gst_caps_is_always_compatible (gst_pad_template_get_caps (srctempl),
1669 gst_pad_template_get_caps (desttempl))) {
1670 srcpad = gst_element_get_request_pad (src,
1671 srctempl->name_template);
1672 destpad = gst_element_get_request_pad (dest,
1673 desttempl->name_template);
1674 if (gst_pad_link_filtered (srcpad, destpad, filtercaps)) {
1675 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
1676 "linked pad %s:%s to pad %s:%s",
1677 GST_DEBUG_PAD_NAME (srcpad),
1678 GST_DEBUG_PAD_NAME (destpad));
1681 /* it failed, so we release the request pads */
1682 gst_element_release_request_pad (src, srcpad);
1683 gst_element_release_request_pad (dest, destpad);
1688 srctempls = srctempls->next;
1692 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "no link possible from %s to %s",
1693 GST_ELEMENT_NAME (src), GST_ELEMENT_NAME (dest));
1697 * gst_element_link_filtered:
1698 * @src: a #GstElement containing the source pad.
1699 * @dest: the #GstElement containing the destination pad.
1700 * @filtercaps: the #GstCaps to use as a filter.
1702 * Links the source to the destination element using the filtercaps.
1703 * The link must be from source to destination, the other
1704 * direction will not be tried.
1705 * The functions looks for existing pads that aren't linked yet.
1706 * It will use request pads if possible. But both pads will not be requested.
1707 * If multiple links are possible, only one is established.
1709 * Returns: TRUE if the elements could be linked.
1712 gst_element_link_filtered (GstElement *src, GstElement *dest,
1713 const GstCaps *filtercaps)
1715 return gst_element_link_pads_filtered (src, NULL, dest, NULL, filtercaps);
1719 * gst_element_link_many:
1720 * @element_1: the first #GstElement in the link chain.
1721 * @element_2: the second #GstElement in the link chain.
1722 * @...: the NULL-terminated list of elements to link in order.
1724 * Chain together a series of elements. Uses #gst_element_link.
1726 * Returns: TRUE on success, FALSE otherwise.
1729 gst_element_link_many (GstElement *element_1, GstElement *element_2, ...)
1733 g_return_val_if_fail (element_1 != NULL && element_2 != NULL, FALSE);
1734 g_return_val_if_fail (GST_IS_ELEMENT (element_1) &&
1735 GST_IS_ELEMENT (element_2), FALSE);
1737 va_start (args, element_2);
1740 if (!gst_element_link (element_1, element_2))
1743 element_1 = element_2;
1744 element_2 = va_arg (args, GstElement*);
1754 * @src: a #GstElement containing the source pad.
1755 * @dest: the #GstElement containing the destination pad.
1757 * Links the source to the destination element.
1758 * The link must be from source to destination, the other
1759 * direction will not be tried.
1760 * The functions looks for existing pads and request pads that aren't
1761 * linked yet. If multiple links are possible, only one is
1764 * Returns: TRUE if the elements could be linked.
1767 gst_element_link (GstElement *src, GstElement *dest)
1769 return gst_element_link_pads_filtered (src, NULL, dest, NULL, NULL);
1773 * gst_element_link_pads:
1774 * @src: a #GstElement containing the source pad.
1775 * @srcpadname: the name of the #GstPad in the source element.
1776 * @dest: the #GstElement containing the destination pad.
1777 * @destpadname: the name of the #GstPad in destination element.
1779 * Links the two named pads of the source and destination elements.
1780 * Side effect is that if one of the pads has no parent, it becomes a
1781 * child of the parent of the other element. If they have different
1782 * parents, the link fails.
1784 * Returns: TRUE if the pads could be linked.
1787 gst_element_link_pads (GstElement *src, const gchar *srcpadname,
1788 GstElement *dest, const gchar *destpadname)
1790 return gst_element_link_pads_filtered (src, srcpadname, dest, destpadname, NULL);
1794 * gst_element_unlink_pads:
1795 * @src: a #GstElement containing the source pad.
1796 * @srcpadname: the name of the #GstPad in source element.
1797 * @dest: a #GstElement containing the destination pad.
1798 * @destpadname: the name of the #GstPad in destination element.
1800 * Unlinks the two named pads of the source and destination elements.
1803 gst_element_unlink_pads (GstElement *src, const gchar *srcpadname,
1804 GstElement *dest, const gchar *destpadname)
1806 GstPad *srcpad,*destpad;
1808 g_return_if_fail (src != NULL);
1809 g_return_if_fail (GST_IS_ELEMENT(src));
1810 g_return_if_fail (srcpadname != NULL);
1811 g_return_if_fail (dest != NULL);
1812 g_return_if_fail (GST_IS_ELEMENT(dest));
1813 g_return_if_fail (destpadname != NULL);
1815 /* obtain the pads requested */
1816 srcpad = gst_element_get_pad (src, srcpadname);
1817 if (srcpad == NULL) {
1818 GST_WARNING_OBJECT (src, "source element has no pad \"%s\"", srcpadname);
1821 destpad = gst_element_get_pad (dest, destpadname);
1822 if (srcpad == NULL) {
1823 GST_WARNING_OBJECT (dest, "destination element has no pad \"%s\"", destpadname);
1827 /* we're satisified they can be unlinked, let's do it */
1828 gst_pad_unlink (srcpad,destpad);
1832 * gst_element_unlink_many:
1833 * @element_1: the first #GstElement in the link chain.
1834 * @element_2: the second #GstElement in the link chain.
1835 * @...: the NULL-terminated list of elements to unlink in order.
1837 * Unlinks a series of elements. Uses #gst_element_unlink.
1840 gst_element_unlink_many (GstElement *element_1, GstElement *element_2, ...)
1844 g_return_if_fail (element_1 != NULL && element_2 != NULL);
1845 g_return_if_fail (GST_IS_ELEMENT (element_1) && GST_IS_ELEMENT (element_2));
1847 va_start (args, element_2);
1850 gst_element_unlink (element_1, element_2);
1852 element_1 = element_2;
1853 element_2 = va_arg (args, GstElement*);
1860 * gst_element_unlink:
1861 * @src: the source #GstElement to unlink.
1862 * @dest: the sink #GstElement to unlink.
1864 * Unlinks all source pads of the source element with all sink pads
1865 * of the sink element to which they are linked.
1868 gst_element_unlink (GstElement *src, GstElement *dest)
1870 const GList *srcpads;
1873 g_return_if_fail (GST_IS_ELEMENT (src));
1874 g_return_if_fail (GST_IS_ELEMENT (dest));
1876 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "unlinking \"%s\" and \"%s\"",
1877 GST_ELEMENT_NAME (src), GST_ELEMENT_NAME (dest));
1879 srcpads = gst_element_get_pad_list (src);
1882 pad = GST_PAD (srcpads->data);
1884 /* we only care about real src pads */
1885 if (GST_IS_REAL_PAD (pad) && GST_PAD_IS_SRC (pad)) {
1886 GstPad *peerpad = GST_PAD_PEER (pad);
1888 /* see if the pad is connected and is really a pad
1891 (GST_OBJECT_PARENT (peerpad) == (GstObject*) dest))
1893 gst_pad_unlink (pad, peerpad);
1897 srcpads = g_list_next (srcpads);
1902 gst_element_error_func (GstElement* element, GstElement *source,
1905 /* tell the parent */
1906 if (GST_OBJECT_PARENT (element)) {
1907 GST_CAT_DEBUG (GST_CAT_EVENT, "forwarding error \"%s\" from %s to %s",
1908 errormsg, GST_ELEMENT_NAME (element),
1909 GST_OBJECT_NAME (GST_OBJECT_PARENT (element)));
1911 gst_object_ref (GST_OBJECT (element));
1912 g_signal_emit (G_OBJECT (GST_OBJECT_PARENT (element)),
1913 gst_element_signals[ERROR], 0, source, errormsg);
1914 gst_object_unref (GST_OBJECT (element));
1919 gst_element_get_random_pad (GstElement *element, GstPadDirection dir)
1921 GList *pads = element->pads;
1922 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "getting a random pad");
1924 GstPad *pad = GST_PAD (pads->data);
1926 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "checking pad %s:%s",
1927 GST_DEBUG_PAD_NAME (pad));
1929 if (GST_PAD_DIRECTION (pad) == dir) {
1930 if (GST_PAD_IS_LINKED (pad)) {
1934 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "pad %s:%s is not linked",
1935 GST_DEBUG_PAD_NAME (pad));
1939 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "pad %s:%s is in wrong direction",
1940 GST_DEBUG_PAD_NAME (pad));
1943 pads = g_list_next (pads);
1949 * gst_element_get_event_masks:
1950 * @element: a #GstElement to query
1952 * Get an array of event masks from the element.
1953 * If the element doesn't
1954 * implement an event masks function, the query will be forwarded
1955 * to a random linked sink pad.
1957 * Returns: An array of #GstEventMask elements.
1960 gst_element_get_event_masks (GstElement *element)
1962 GstElementClass *oclass;
1964 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
1966 oclass = GST_ELEMENT_GET_CLASS (element);
1968 if (oclass->get_event_masks)
1969 return oclass->get_event_masks (element);
1971 GstPad *pad = gst_element_get_random_pad (element, GST_PAD_SINK);
1973 return gst_pad_get_event_masks (GST_PAD_PEER (pad));
1980 * gst_element_send_event:
1981 * @element: a #GstElement to send the event to.
1982 * @event: the #GstEvent to send to the element.
1984 * Sends an event to an element. If the element doesn't
1985 * implement an event handler, the event will be forwarded
1986 * to a random sink pad.
1988 * Returns: TRUE if the event was handled.
1991 gst_element_send_event (GstElement *element, GstEvent *event)
1993 GstElementClass *oclass;
1995 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
1996 g_return_val_if_fail (event != NULL, FALSE);
1998 oclass = GST_ELEMENT_GET_CLASS (element);
2000 if (oclass->send_event)
2001 return oclass->send_event (element, event);
2003 GstPad *pad = gst_element_get_random_pad (element, GST_PAD_SINK);
2005 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "sending event to random pad %s:%s",
2006 GST_DEBUG_PAD_NAME (pad));
2007 return gst_pad_send_event (GST_PAD_PEER (pad), event);
2010 GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "can't send event on element %s",
2011 GST_ELEMENT_NAME (element));
2017 * @element: a #GstElement to send the event to.
2018 * @seek_type: the method to use for seeking.
2019 * @offset: the offset to seek to.
2021 * Sends a seek event to an element.
2023 * Returns: TRUE if the event was handled.
2026 gst_element_seek (GstElement *element,
2027 GstSeekType seek_type,
2030 GstEvent *event = gst_event_new_seek (seek_type, offset);
2032 return gst_element_send_event (element, event);
2036 * gst_element_get_query_types:
2037 * @element: a #GstElement to query
2039 * Get an array of query types from the element.
2040 * If the element doesn't
2041 * implement a query types function, the query will be forwarded
2042 * to a random sink pad.
2044 * Returns: An array of #GstQueryType elements.
2047 gst_element_get_query_types (GstElement *element)
2049 GstElementClass *oclass;
2051 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
2053 oclass = GST_ELEMENT_GET_CLASS (element);
2055 if (oclass->get_query_types)
2056 return oclass->get_query_types (element);
2058 GstPad *pad = gst_element_get_random_pad (element, GST_PAD_SINK);
2060 return gst_pad_get_query_types (GST_PAD_PEER (pad));
2067 * gst_element_query:
2068 * @element: a #GstElement to perform the query on.
2069 * @type: the #GstQueryType.
2070 * @format: the #GstFormat pointer to hold the format of the result.
2071 * @value: the pointer to the value of the result.
2073 * Performs a query on the given element. If the format is set
2074 * to GST_FORMAT_DEFAULT and this function returns TRUE, the
2075 * format pointer will hold the default format.
2076 * For element that don't implement a query handler, this function
2077 * forwards the query to a random usable sinkpad of this element.
2079 * Returns: TRUE if the query could be performed.
2082 gst_element_query (GstElement *element, GstQueryType type,
2083 GstFormat *format, gint64 *value)
2085 GstElementClass *oclass;
2087 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
2088 g_return_val_if_fail (format != NULL, FALSE);
2089 g_return_val_if_fail (value != NULL, FALSE);
2091 oclass = GST_ELEMENT_GET_CLASS (element);
2094 return oclass->query (element, type, format, value);
2096 GstPad *pad = gst_element_get_random_pad (element, GST_PAD_SRC);
2098 return gst_pad_query (pad, type, format, value);
2099 pad = gst_element_get_random_pad (element, GST_PAD_SINK);
2101 return gst_pad_query (GST_PAD_PEER (pad), type, format, value);
2108 * gst_element_get_formats:
2109 * @element: a #GstElement to query
2111 * Get an array of formst from the element.
2112 * If the element doesn't
2113 * implement a formats function, the query will be forwarded
2114 * to a random sink pad.
2116 * Returns: An array of #GstFormat elements.
2119 gst_element_get_formats (GstElement *element)
2121 GstElementClass *oclass;
2123 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
2125 oclass = GST_ELEMENT_GET_CLASS (element);
2127 if (oclass->get_formats)
2128 return oclass->get_formats (element);
2130 GstPad *pad = gst_element_get_random_pad (element, GST_PAD_SINK);
2132 return gst_pad_get_formats (GST_PAD_PEER (pad));
2139 * gst_element_convert:
2140 * @element: a #GstElement to invoke the converter on.
2141 * @src_format: the source #GstFormat.
2142 * @src_value: the source value.
2143 * @dest_format: a pointer to the destination #GstFormat.
2144 * @dest_value: a pointer to the destination value.
2146 * Invokes a conversion on the element.
2147 * If the element doesn't
2148 * implement a convert function, the query will be forwarded
2149 * to a random sink pad.
2151 * Returns: TRUE if the conversion could be performed.
2154 gst_element_convert (GstElement *element,
2155 GstFormat src_format, gint64 src_value,
2156 GstFormat *dest_format, gint64 *dest_value)
2158 GstElementClass *oclass;
2160 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
2161 g_return_val_if_fail (dest_format != NULL, FALSE);
2162 g_return_val_if_fail (dest_value != NULL, FALSE);
2164 if (src_format == *dest_format) {
2165 *dest_value = src_value;
2169 oclass = GST_ELEMENT_GET_CLASS (element);
2171 if (oclass->convert)
2172 return oclass->convert (element,
2173 src_format, src_value,
2174 dest_format, dest_value);
2176 GstPad *pad = gst_element_get_random_pad (element, GST_PAD_SINK);
2178 return gst_pad_convert (GST_PAD_PEER (pad),
2179 src_format, src_value,
2180 dest_format, dest_value);
2187 * gst_element_error:
2188 * @element: a #GstElement with the error.
2189 * @error: the printf-style string describing the error.
2190 * @...: the optional arguments for the string.
2192 * signals an error condition on an element.
2193 * This function is used internally by elements.
2194 * It results in the "error" signal.
2197 gst_element_error (GstElement *element, const gchar *error, ...)
2203 g_return_if_fail (GST_IS_ELEMENT (element));
2204 g_return_if_fail (error != NULL);
2206 /* create error message */
2207 va_start (var_args, error);
2208 string = g_strdup_vprintf (error, var_args);
2210 GST_CAT_INFO (GST_CAT_EVENT, "ERROR in %s: %s", GST_ELEMENT_NAME (element), string);
2212 /* if the element was already in error, stop now */
2213 if (GST_FLAG_IS_SET (element, GST_ELEMENT_ERROR)) {
2214 GST_CAT_INFO (GST_CAT_EVENT, "recursive ERROR detected in %s", GST_ELEMENT_NAME (element));
2219 GST_FLAG_SET (element, GST_ELEMENT_ERROR);
2221 /* emit the signal, make sure the element stays available */
2222 gst_object_ref (GST_OBJECT (element));
2223 g_signal_emit (G_OBJECT (element), gst_element_signals[ERROR], 0, element, string);
2225 /* tell the scheduler */
2226 if (element->sched) {
2227 gst_scheduler_error (element->sched, element);
2230 if (GST_STATE (element) == GST_STATE_PLAYING) {
2231 GstElementStateReturn ret;
2233 ret = gst_element_set_state (element, GST_STATE_PAUSED);
2234 if (ret != GST_STATE_SUCCESS) {
2235 g_warning ("could not PAUSE element \"%s\" after error, help!", GST_ELEMENT_NAME (element));
2239 GST_FLAG_UNSET (element, GST_ELEMENT_ERROR);
2242 gst_object_unref (GST_OBJECT (element));
2247 * gst_element_is_locked_state:
2248 * @element: a #GstElement.
2250 * Checks if the state of an element is locked.
2251 * If the state of an element is locked, state changes of the parent don't
2252 * affect the element.
2253 * This way you can leave currently unused elements inside bins. Just lock their
2254 * state before changing the state from #GST_STATE_NULL.
2256 * Returns: TRUE, if the element's state is locked.
2259 gst_element_is_locked_state (GstElement *element)
2261 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
2263 return GST_FLAG_IS_SET (element, GST_ELEMENT_LOCKED_STATE) ? TRUE : FALSE;
2266 * gst_element_set_locked_state:
2267 * @element: a #GstElement
2268 * @locked_state: TRUE to lock the element's state
2270 * Locks the state of an element, so state changes of the parent don't affect
2271 * this element anymore.
2274 gst_element_set_locked_state (GstElement *element, gboolean locked_state)
2278 g_return_if_fail (GST_IS_ELEMENT (element));
2280 old = GST_FLAG_IS_SET (element, GST_ELEMENT_LOCKED_STATE);
2282 if (old == locked_state)
2286 GST_CAT_DEBUG (GST_CAT_STATES, "locking state of element %s",
2287 GST_ELEMENT_NAME (element));
2288 GST_FLAG_SET (element, GST_ELEMENT_LOCKED_STATE);
2290 GST_CAT_DEBUG (GST_CAT_STATES, "unlocking state of element %s",
2291 GST_ELEMENT_NAME (element));
2292 GST_FLAG_UNSET (element, GST_ELEMENT_LOCKED_STATE);
2296 * gst_element_sync_state_with_parent:
2297 * @element: a #GstElement.
2299 * Tries to change the state of the element to the same as its parent.
2300 * If this function returns FALSE, the state of element is undefined.
2302 * Returns: TRUE, if the element's state could be synced to the parent's state.
2305 gst_element_sync_state_with_parent (GstElement *element)
2309 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
2310 parent = GST_ELEMENT (GST_ELEMENT_PARENT(element));
2311 g_return_val_if_fail (GST_IS_BIN (parent), FALSE);
2313 GST_CAT_DEBUG (GST_CAT_STATES, "syncing state of element %s (%s) to %s (%s)",
2314 GST_ELEMENT_NAME (element), gst_element_state_get_name (GST_STATE (element)),
2315 GST_ELEMENT_NAME (parent), gst_element_state_get_name (GST_STATE (parent)));
2316 if (gst_element_set_state (element, GST_STATE (parent)) == GST_STATE_FAILURE) {
2322 * gst_element_get_state:
2323 * @element: a #GstElement to get the state of.
2325 * Gets the state of the element.
2327 * Returns: the #GstElementState of the element.
2330 gst_element_get_state (GstElement *element)
2332 g_return_val_if_fail (GST_IS_ELEMENT (element), GST_STATE_VOID_PENDING);
2334 return GST_STATE (element);
2338 * gst_element_wait_state_change:
2339 * @element: a #GstElement to wait for a state change on.
2341 * Waits and blocks until the element changed its state.
2344 gst_element_wait_state_change (GstElement *element)
2346 g_mutex_lock (element->state_mutex);
2347 g_cond_wait (element->state_cond, element->state_mutex);
2348 g_mutex_unlock (element->state_mutex);
2352 * gst_element_set_state:
2353 * @element: a #GstElement to change state of.
2354 * @state: the element's new #GstElementState.
2356 * Sets the state of the element. This function will try to set the
2357 * requested state by going through all the intermediary states and calling
2358 * the class's state change function for each.
2360 * Returns: TRUE if the state was successfully set.
2361 * (using #GstElementStateReturn).
2363 GstElementStateReturn
2364 gst_element_set_state (GstElement *element, GstElementState state)
2366 GstElementClass *oclass;
2367 GstElementState curpending;
2368 GstElementStateReturn return_val = GST_STATE_SUCCESS;
2370 g_return_val_if_fail (GST_IS_ELEMENT (element), GST_STATE_FAILURE);
2372 /* start with the current state */
2373 curpending = GST_STATE(element);
2375 if (state == curpending)
2377 GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element,
2378 "element is already in requested state %s",
2379 gst_element_state_get_name (state));
2380 return (GST_STATE_SUCCESS);
2383 GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element, "setting state from %s to %s",
2384 gst_element_state_get_name (curpending),
2385 gst_element_state_get_name (state));
2387 /* loop until the final requested state is set */
2388 while (GST_STATE (element) != state
2389 && GST_STATE (element) != GST_STATE_VOID_PENDING) {
2390 /* move the curpending state in the correct direction */
2391 if (curpending < state)
2396 /* set the pending state variable */
2397 /* FIXME: should probably check to see that we don't already have one */
2398 GST_STATE_PENDING (element) = curpending;
2400 if (curpending != state) {
2401 GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element,
2402 "intermediate: setting state from %s to %s",
2403 gst_element_state_get_name (GST_STATE (element)),
2404 gst_element_state_get_name (curpending));
2407 /* call the state change function so it can set the state */
2408 oclass = GST_ELEMENT_GET_CLASS (element);
2409 if (oclass->change_state)
2410 return_val = (oclass->change_state) (element);
2412 switch (return_val) {
2413 case GST_STATE_FAILURE:
2414 GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element,
2415 "have failed change_state return");
2417 case GST_STATE_ASYNC:
2418 GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element,
2419 "element will change state async");
2421 case GST_STATE_SUCCESS:
2422 /* Last thing we do is verify that a successful state change really
2423 * did change the state... */
2424 /* if it did not, this is an error - fix the element that does this */
2425 if (GST_STATE (element) != curpending) {
2426 g_warning ("element %s claimed state-change success,"
2427 "but state didn't change to %s. State is %s (%s pending), fix the element",
2428 GST_ELEMENT_NAME (element),
2429 gst_element_state_get_name (curpending),
2430 gst_element_state_get_name (GST_STATE (element)),
2431 gst_element_state_get_name (GST_STATE_PENDING (element)));
2432 return_val = GST_STATE_FAILURE;
2437 /* somebody added a GST_STATE_ and forgot to do stuff here ! */
2438 g_assert_not_reached ();
2447 gst_element_negotiate_pads (GstElement *element)
2449 GList *pads = GST_ELEMENT_PADS (element);
2451 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, element, "negotiating pads");
2454 GstPad *pad = GST_PAD (pads->data);
2457 pads = g_list_next (pads);
2459 if (!GST_IS_REAL_PAD (pad))
2462 srcpad = GST_PAD_REALIZE (pad);
2464 /* if we have a link on this pad and it doesn't have caps
2465 * allready, try to negotiate */
2466 if (GST_PAD_IS_LINKED (srcpad) && !GST_PAD_CAPS (srcpad)) {
2467 GstRealPad *sinkpad;
2468 GstElementState otherstate;
2471 sinkpad = GST_RPAD_PEER (GST_PAD_REALIZE (srcpad));
2473 /* check the parent of the peer pad, if there is no parent do nothing */
2474 parent = GST_PAD_PARENT (sinkpad);
2478 /* skips pads that were already negotiating */
2479 if (GST_FLAG_IS_SET (sinkpad, GST_PAD_NEGOTIATING) ||
2480 GST_FLAG_IS_SET (srcpad, GST_PAD_NEGOTIATING))
2483 otherstate = GST_STATE (parent);
2485 /* swap pads if needed */
2486 if (!GST_PAD_IS_SRC (srcpad)) {
2494 /* only try to negotiate if the peer element is in PAUSED or higher too */
2495 if (otherstate >= GST_STATE_READY) {
2496 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, element,
2497 "perform negotiate for %s:%s and %s:%s",
2498 GST_DEBUG_PAD_NAME (srcpad),
2499 GST_DEBUG_PAD_NAME (sinkpad));
2500 if (!gst_pad_renegotiate (pad))
2504 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, element,
2505 "not negotiating %s:%s and %s:%s, not in READY yet",
2506 GST_DEBUG_PAD_NAME (srcpad),
2507 GST_DEBUG_PAD_NAME (sinkpad));
2516 gst_element_clear_pad_caps (GstElement *element)
2518 GList *pads = GST_ELEMENT_PADS (element);
2520 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, element, "clearing pad caps");
2523 GstPad *pad = GST_PAD (pads->data);
2525 gst_pad_unnegotiate (pad);
2527 pads = g_list_next (pads);
2532 gst_element_pads_activate (GstElement *element, gboolean active)
2534 GList *pads = element->pads;
2537 GstPad *pad = GST_PAD (pads->data);
2538 pads = g_list_next (pads);
2540 if (!GST_IS_REAL_PAD (pad))
2543 gst_pad_set_active (pad, active);
2547 static GstElementStateReturn
2548 gst_element_change_state (GstElement *element)
2550 GstElementState old_state;
2552 gint old_pending, old_transition;
2554 g_return_val_if_fail (GST_IS_ELEMENT (element), GST_STATE_FAILURE);
2556 old_state = GST_STATE (element);
2557 old_pending = GST_STATE_PENDING (element);
2558 old_transition = GST_STATE_TRANSITION (element);
2560 if (old_pending == GST_STATE_VOID_PENDING ||
2561 old_state == GST_STATE_PENDING (element)) {
2562 GST_CAT_INFO (GST_CAT_STATES,
2563 "no state change needed for element %s (VOID_PENDING)",
2564 GST_ELEMENT_NAME (element));
2565 return GST_STATE_SUCCESS;
2568 GST_CAT_INFO (GST_CAT_STATES, "%s default handler sets state from %s to %s %04x",
2569 GST_ELEMENT_NAME (element),
2570 gst_element_state_get_name (old_state),
2571 gst_element_state_get_name (old_pending),
2574 /* we set the state change early for the negotiation functions */
2575 GST_STATE (element) = old_pending;
2576 GST_STATE_PENDING (element) = GST_STATE_VOID_PENDING;
2578 switch (old_transition) {
2579 case GST_STATE_PLAYING_TO_PAUSED:
2580 gst_element_pads_activate (element, FALSE);
2582 case GST_STATE_PAUSED_TO_PLAYING:
2583 gst_element_pads_activate (element, TRUE);
2585 /* if we are going to paused, we try to negotiate the pads */
2586 case GST_STATE_READY_TO_PAUSED:
2587 if (!gst_element_negotiate_pads (element))
2590 /* going to the READY state clears all pad caps */
2591 /* FIXME: Why doesn't this happen on READY => NULL? -- Company */
2592 case GST_STATE_PAUSED_TO_READY:
2593 gst_element_clear_pad_caps (element);
2599 parent = GST_ELEMENT_PARENT (element);
2601 GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element,
2602 "signaling state change from %s to %s",
2603 gst_element_state_get_name (old_state),
2604 gst_element_state_get_name (GST_STATE (element)));
2606 /* tell the scheduler if we have one */
2607 if (element->sched) {
2608 if (gst_scheduler_state_transition (element->sched, element,
2609 old_transition) != GST_STATE_SUCCESS) {
2610 GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element,
2611 "scheduler could not change state");
2616 /* tell our parent about the state change */
2617 if (parent && GST_IS_BIN (parent)) {
2618 gst_bin_child_state_change (GST_BIN (parent), old_state,
2619 GST_STATE (element), element);
2621 /* at this point the state of the element could have changed again */
2623 g_signal_emit (G_OBJECT (element), gst_element_signals[STATE_CHANGE],
2624 0, old_state, GST_STATE (element));
2626 /* signal the state change in case somebody is waiting for us */
2627 g_mutex_lock (element->state_mutex);
2628 g_cond_signal (element->state_cond);
2629 g_mutex_unlock (element->state_mutex);
2631 return GST_STATE_SUCCESS;
2634 /* undo the state change */
2635 GST_STATE (element) = old_state;
2636 GST_STATE_PENDING (element) = old_pending;
2638 return GST_STATE_FAILURE;
2642 * gst_element_get_factory:
2643 * @element: a #GstElement to request the element factory of.
2645 * Retrieves the factory that was used to create this element.
2647 * Returns: the #GstElementFactory used for creating this element.
2650 gst_element_get_factory (GstElement *element)
2652 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
2654 return GST_ELEMENT_GET_CLASS (element)->elementfactory;
2658 gst_element_dispose (GObject *object)
2660 GstElement *element = GST_ELEMENT (object);
2664 GST_CAT_INFO_OBJECT (GST_CAT_REFCOUNTING, element, "dispose");
2666 gst_element_set_state (element, GST_STATE_NULL);
2668 /* first we break all our links with the ouside */
2669 if (element->pads) {
2671 orig = pads = g_list_copy (element->pads);
2673 pad = GST_PAD (pads->data);
2675 if (GST_PAD_PEER (pad)) {
2676 GST_CAT_DEBUG (GST_CAT_REFCOUNTING, "unlinking pad '%s'",
2677 GST_OBJECT_NAME (GST_OBJECT (GST_PAD (GST_PAD_PEER (pad)))));
2678 gst_pad_unlink (pad, GST_PAD (GST_PAD_PEER (pad)));
2680 gst_element_remove_pad (element, pad);
2682 pads = g_list_next (pads);
2685 g_list_free (element->pads);
2686 element->pads = NULL;
2689 element->numsrcpads = 0;
2690 element->numsinkpads = 0;
2691 element->numpads = 0;
2692 g_mutex_free (element->state_mutex);
2693 g_cond_free (element->state_cond);
2695 if (element->prop_value_queue)
2696 g_async_queue_unref (element->prop_value_queue);
2697 element->prop_value_queue = NULL;
2698 if (element->property_mutex)
2699 g_mutex_free (element->property_mutex);
2701 gst_object_replace ((GstObject **)&element->sched, NULL);
2702 gst_object_replace ((GstObject **)&element->clock, NULL);
2704 G_OBJECT_CLASS (parent_class)->dispose (object);
2707 #ifndef GST_DISABLE_LOADSAVE
2709 * gst_element_save_thyself:
2710 * @element: a #GstElement to save.
2711 * @parent: the xml parent node.
2713 * Saves the element as part of the given XML structure.
2715 * Returns: the new #xmlNodePtr.
2718 gst_element_save_thyself (GstObject *object,
2722 GstElementClass *oclass;
2723 GParamSpec **specs, *spec;
2725 GValue value = { 0, };
2726 GstElement *element;
2728 g_return_val_if_fail (GST_IS_ELEMENT (object), parent);
2730 element = GST_ELEMENT (object);
2732 oclass = GST_ELEMENT_GET_CLASS (element);
2734 xmlNewChild(parent, NULL, "name", GST_ELEMENT_NAME(element));
2736 if (oclass->elementfactory != NULL) {
2737 GstElementFactory *factory = (GstElementFactory *)oclass->elementfactory;
2739 xmlNewChild (parent, NULL, "type",
2740 GST_PLUGIN_FEATURE (factory)->name);
2743 /* FIXME: what is this? */
2744 /* if (element->manager) */
2745 /* xmlNewChild(parent, NULL, "manager", GST_ELEMENT_NAME(element->manager)); */
2748 specs = g_object_class_list_properties (G_OBJECT_GET_CLASS (object), &nspecs);
2750 for (i=0; i<nspecs; i++) {
2752 if (spec->flags & G_PARAM_READABLE) {
2756 g_value_init(&value, G_PARAM_SPEC_VALUE_TYPE (spec));
2758 g_object_get_property (G_OBJECT (element), spec->name, &value);
2759 param = xmlNewChild (parent, NULL, "param", NULL);
2760 xmlNewChild (param, NULL, "name", spec->name);
2762 if (G_IS_PARAM_SPEC_STRING (spec))
2763 contents = g_value_dup_string (&value);
2764 else if (G_IS_PARAM_SPEC_ENUM (spec))
2765 contents = g_strdup_printf ("%d", g_value_get_enum (&value));
2766 else if (G_IS_PARAM_SPEC_INT64 (spec))
2767 contents = g_strdup_printf ("%" G_GINT64_FORMAT,
2768 g_value_get_int64 (&value));
2770 contents = g_strdup_value_contents (&value);
2772 xmlNewChild (param, NULL, "value", contents);
2775 g_value_unset(&value);
2779 pads = GST_ELEMENT_PADS (element);
2782 GstPad *pad = GST_PAD (pads->data);
2783 /* figure out if it's a direct pad or a ghostpad */
2784 if (GST_ELEMENT (GST_OBJECT_PARENT (pad)) == element) {
2785 xmlNodePtr padtag = xmlNewChild (parent, NULL, "pad", NULL);
2786 gst_object_save_thyself (GST_OBJECT (pad), padtag);
2788 pads = g_list_next (pads);
2795 gst_element_restore_thyself (GstObject *object, xmlNodePtr self)
2797 xmlNodePtr children;
2798 GstElement *element;
2800 gchar *value = NULL;
2802 element = GST_ELEMENT (object);
2803 g_return_if_fail (element != NULL);
2806 children = self->xmlChildrenNode;
2808 if (!strcmp (children->name, "param")) {
2809 xmlNodePtr child = children->xmlChildrenNode;
2812 if (!strcmp (child->name, "name")) {
2813 name = xmlNodeGetContent (child);
2815 else if (!strcmp (child->name, "value")) {
2816 value = xmlNodeGetContent (child);
2818 child = child->next;
2820 /* FIXME: can this just be g_object_set ? */
2821 gst_util_set_object_arg (G_OBJECT (element), name, value);
2822 /* g_object_set (G_OBJECT (element), name, value, NULL); */
2824 children = children->next;
2828 children = self->xmlChildrenNode;
2830 if (!strcmp (children->name, "pad")) {
2831 gst_pad_load_and_link (children, GST_OBJECT (element));
2833 children = children->next;
2836 if (GST_OBJECT_CLASS (parent_class)->restore_thyself)
2837 (GST_OBJECT_CLASS (parent_class)->restore_thyself) (object, self);
2839 #endif /* GST_DISABLE_LOADSAVE */
2842 * gst_element_yield:
2843 * @element: a #GstElement to yield.
2845 * Requests a yield operation for the element. The scheduler will typically
2846 * give control to another element.
2849 gst_element_yield (GstElement *element)
2851 if (GST_ELEMENT_SCHED (element)) {
2852 gst_scheduler_yield (GST_ELEMENT_SCHED (element), element);
2857 * gst_element_interrupt:
2858 * @element: a #GstElement to interrupt.
2860 * Requests the scheduler of this element to interrupt the execution of
2861 * this element and scheduler another one.
2863 * Returns: TRUE if the element should exit its chain/loop/get
2864 * function ASAP, depending on the scheduler implementation.
2867 gst_element_interrupt (GstElement *element)
2869 if (GST_ELEMENT_SCHED (element)) {
2870 return gst_scheduler_interrupt (GST_ELEMENT_SCHED (element), element);
2877 * gst_element_set_scheduler:
2878 * @element: a #GstElement to set the scheduler of.
2879 * @sched: the #GstScheduler to set.
2881 * Sets the scheduler of the element. For internal use only, unless you're
2882 * writing a new bin subclass.
2885 gst_element_set_scheduler (GstElement *element,
2886 GstScheduler *sched)
2888 g_return_if_fail (GST_IS_ELEMENT (element));
2890 GST_CAT_INFO_OBJECT (GST_CAT_PARENTAGE, element, "setting scheduler to %p", sched);
2892 gst_object_replace ((GstObject **)&GST_ELEMENT_SCHED (element), GST_OBJECT (sched));
2896 * gst_element_get_scheduler:
2897 * @element: a #GstElement to get the scheduler of.
2899 * Returns the scheduler of the element.
2901 * Returns: the element's #GstScheduler.
2904 gst_element_get_scheduler (GstElement *element)
2906 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
2908 return GST_ELEMENT_SCHED (element);
2912 * gst_element_set_loop_function:
2913 * @element: a #GstElement to set the loop function of.
2914 * @loop: Pointer to #GstElementLoopFunction.
2916 * This sets the loop function for the element. The function pointed to
2917 * can deviate from the GstElementLoopFunction definition in type of
2920 * NOTE: in order for this to take effect, the current loop function *must*
2921 * exit. Assuming the loop function itself is the only one who will cause
2922 * a new loopfunc to be assigned, this should be no problem.
2925 gst_element_set_loop_function (GstElement *element,
2926 GstElementLoopFunction loop)
2928 gboolean need_notify = FALSE;
2930 g_return_if_fail (GST_IS_ELEMENT (element));
2932 /* if the element changed from loop based to chain/get based
2933 * or vice versa, we need to inform the scheduler about that */
2934 if ((element->loopfunc == NULL && loop != NULL) ||
2935 (element->loopfunc != NULL && loop == NULL))
2940 /* set the loop function */
2941 element->loopfunc = loop;
2944 /* set the NEW_LOOPFUNC flag so everyone knows to go try again */
2945 GST_FLAG_SET (element, GST_ELEMENT_NEW_LOOPFUNC);
2947 if (GST_ELEMENT_SCHED (element)) {
2948 gst_scheduler_scheduling_change (GST_ELEMENT_SCHED (element), element);
2953 gst_element_emit_found_tag (GstElement* element, GstElement *source, GstTagList *tag_list)
2955 gst_object_ref (GST_OBJECT (element));
2956 g_signal_emit (element, gst_element_signals[FOUND_TAG], 0, source, tag_list);
2957 gst_object_unref (GST_OBJECT (element));
2960 gst_element_found_tag_func (GstElement* element, GstElement *source, GstTagList *tag_list)
2962 /* tell the parent */
2963 if (GST_OBJECT_PARENT (element)) {
2964 GST_CAT_LOG_OBJECT (GST_CAT_EVENT, element, "forwarding tag event to %s",
2965 GST_OBJECT_NAME (GST_OBJECT_PARENT (element)));
2966 gst_element_emit_found_tag (GST_ELEMENT (GST_OBJECT_PARENT (element)), source, tag_list);
2970 * gst_element_found_tags:
2971 * @element: the element that found the tags
2972 * @tag_list: the found tags
2974 * This function emits the found_tags signal. This is a recursive signal, so
2975 * every parent will emit that signal, too, before this function returns.
2976 * Only emit this signal, when you extracted these tags out of the data stream,
2977 * not when you handle an event.
2980 gst_element_found_tags (GstElement *element, GstTagList *tag_list)
2982 gst_element_emit_found_tag (element, element, tag_list);
2985 * gst_element_found_tags_for_pad:
2986 * @element: element that found the tag
2987 * @pad: src pad the tags correspond to
2988 * @timestamp: time the tags were found
2989 * @list: the taglist
2991 * This is a convenience routine for tag finding. Most of the time you only
2992 * want to push the found tags down one pad, in that case this function is for
2993 * you. It takes ownership of the taglist, emits the found-tag signal and pushes
2994 * a tag event down the pad.
2997 gst_element_found_tags_for_pad (GstElement *element, GstPad *pad, GstClockTime timestamp,
3000 GstEvent *tag_event;
3002 g_return_if_fail (GST_IS_ELEMENT (element));
3003 g_return_if_fail (GST_IS_REAL_PAD (pad));
3004 g_return_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SRC);
3005 g_return_if_fail (element == GST_PAD_PARENT (pad));
3006 g_return_if_fail (list != NULL);
3008 tag_event = gst_event_new_tag (list);
3009 GST_EVENT_TIMESTAMP (tag_event) = timestamp;
3010 gst_element_found_tags (element, gst_event_tag_get_list (tag_event));
3011 if (GST_PAD_IS_USABLE (pad)) {
3012 gst_pad_push (pad, GST_DATA (tag_event));
3014 gst_data_unref (GST_DATA (tag_event));
3019 gst_element_set_eos_recursive (GstElement *element)
3021 /* this function is only called, when we were in PLAYING before. So every
3022 parent that's PAUSED was PLAYING before. That means it has reached EOS. */
3025 GST_CAT_DEBUG (GST_CAT_EVENT, "setting recursive EOS on %s",
3026 GST_OBJECT_NAME (element));
3027 g_signal_emit (G_OBJECT (element), gst_element_signals[EOS], 0);
3029 if (!GST_OBJECT_PARENT (element))
3032 parent = GST_ELEMENT (GST_OBJECT_PARENT (element));
3033 if (GST_STATE (parent) == GST_STATE_PAUSED)
3034 gst_element_set_eos_recursive (parent);
3037 * gst_element_set_eos:
3038 * @element: a #GstElement to set to the EOS state.
3040 * Perform the actions needed to bring the element in the EOS state.
3043 gst_element_set_eos (GstElement *element)
3045 g_return_if_fail (GST_IS_ELEMENT (element));
3047 GST_CAT_DEBUG (GST_CAT_EVENT, "setting EOS on element %s",
3048 GST_OBJECT_NAME (element));
3050 if (GST_STATE (element) == GST_STATE_PLAYING) {
3051 gst_element_set_state (element, GST_STATE_PAUSED);
3052 gst_element_set_eos_recursive (element);
3054 g_signal_emit (G_OBJECT (element), gst_element_signals[EOS], 0);
3060 * gst_element_state_get_name:
3061 * @state: a #GstElementState to get the name of.
3063 * Gets a string representing the given state.
3065 * Returns: a string with the name of the state.
3068 gst_element_state_get_name (GstElementState state)
3071 #ifdef GST_DEBUG_COLOR
3072 case GST_STATE_VOID_PENDING: return "NONE_PENDING";break;
3073 case GST_STATE_NULL: return "\033[01;34mNULL\033[00m";break;
3074 case GST_STATE_READY: return "\033[01;31mREADY\033[00m";break;
3075 case GST_STATE_PLAYING: return "\033[01;32mPLAYING\033[00m";break;
3076 case GST_STATE_PAUSED: return "\033[01;33mPAUSED\033[00m";break;
3078 /* This is a memory leak */
3079 return g_strdup_printf ("\033[01;35;41mUNKNOWN!\033[00m(%d)", state);
3081 case GST_STATE_VOID_PENDING: return "NONE_PENDING";break;
3082 case GST_STATE_NULL: return "NULL";break;
3083 case GST_STATE_READY: return "READY";break;
3084 case GST_STATE_PLAYING: return "PLAYING";break;
3085 case GST_STATE_PAUSED: return "PAUSED";break;
3086 default: return "UNKNOWN!";
3093 gst_element_populate_std_props (GObjectClass * klass, const gchar *prop_name,
3094 guint arg_id, GParamFlags flags)
3096 GQuark prop_id = g_quark_from_string (prop_name);
3099 static GQuark fd_id = 0;
3100 static GQuark blocksize_id;
3101 static GQuark bytesperread_id;
3102 static GQuark dump_id;
3103 static GQuark filesize_id;
3104 static GQuark mmapsize_id;
3105 static GQuark location_id;
3106 static GQuark offset_id;
3107 static GQuark silent_id;
3108 static GQuark touch_id;
3111 fd_id = g_quark_from_static_string ("fd");
3112 blocksize_id = g_quark_from_static_string ("blocksize");
3113 bytesperread_id = g_quark_from_static_string ("bytesperread");
3114 dump_id = g_quark_from_static_string ("dump");
3115 filesize_id = g_quark_from_static_string ("filesize");
3116 mmapsize_id = g_quark_from_static_string ("mmapsize");
3117 location_id = g_quark_from_static_string ("location");
3118 offset_id = g_quark_from_static_string ("offset");
3119 silent_id = g_quark_from_static_string ("silent");
3120 touch_id = g_quark_from_static_string ("touch");
3123 if (prop_id == fd_id) {
3124 pspec = g_param_spec_int ("fd", "File-descriptor",
3125 "File-descriptor for the file being read",
3126 0, G_MAXINT, 0, flags);
3128 else if (prop_id == blocksize_id) {
3129 pspec = g_param_spec_ulong ("blocksize", "Block Size",
3130 "Block size to read per buffer",
3131 0, G_MAXULONG, 4096, flags);
3134 else if (prop_id == bytesperread_id) {
3135 pspec = g_param_spec_int ("bytesperread", "Bytes per read",
3136 "Number of bytes to read per buffer",
3137 G_MININT, G_MAXINT, 0, flags);
3140 else if (prop_id == dump_id) {
3141 pspec = g_param_spec_boolean ("dump", "Dump",
3142 "Dump bytes to stdout",
3146 else if (prop_id == filesize_id) {
3147 pspec = g_param_spec_int64 ("filesize", "File Size",
3148 "Size of the file being read",
3149 0, G_MAXINT64, 0, flags);
3152 else if (prop_id == mmapsize_id) {
3153 pspec = g_param_spec_ulong ("mmapsize", "mmap() Block Size",
3154 "Size in bytes of mmap()d regions",
3155 0, G_MAXULONG, 4 * 1048576, flags);
3158 else if (prop_id == location_id) {
3159 pspec = g_param_spec_string ("location", "File Location",
3160 "Location of the file to read",
3164 else if (prop_id == offset_id) {
3165 pspec = g_param_spec_int64 ("offset", "File Offset",
3166 "Byte offset of current read pointer",
3167 0, G_MAXINT64, 0, flags);
3170 else if (prop_id == silent_id) {
3171 pspec = g_param_spec_boolean ("silent", "Silent", "Don't produce events",
3175 else if (prop_id == touch_id) {
3176 pspec = g_param_spec_boolean ("touch", "Touch read data",
3177 "Touch data to force disk read before "
3178 "push ()", TRUE, flags);
3181 g_warning ("Unknown - 'standard' property '%s' id %d from klass %s",
3182 prop_name, arg_id, g_type_name (G_OBJECT_CLASS_TYPE (klass)));
3187 g_object_class_install_property (klass, arg_id, pspec);
3192 * gst_element_class_install_std_props:
3193 * @klass: the #GstElementClass to add the properties to.
3194 * @first_name: the name of the first property.
3195 * in a NULL terminated
3196 * @...: the id and flags of the first property, followed by
3197 * further 'name', 'id', 'flags' triplets and terminated by NULL.
3199 * Adds a list of standardized properties with types to the @klass.
3200 * the id is for the property switch in your get_prop method, and
3201 * the flags determine readability / writeability.
3204 gst_element_class_install_std_props (GstElementClass * klass,
3205 const gchar *first_name, ...)
3211 g_return_if_fail (GST_IS_ELEMENT_CLASS (klass));
3213 va_start (args, first_name);
3218 int arg_id = va_arg (args, int);
3219 int flags = va_arg (args, int);
3221 gst_element_populate_std_props ((GObjectClass *) klass, name, arg_id, flags);
3223 name = va_arg (args, char *);
3230 * gst_element_get_managing_bin:
3231 * @element: a #GstElement to get the managing bin of.
3233 * Gets the managing bin (a pipeline or a thread, for example) of an element.
3235 * Returns: the #GstBin, or NULL on failure.
3238 gst_element_get_managing_bin (GstElement *element)
3242 g_return_val_if_fail (element != NULL, NULL);
3244 bin = GST_BIN (gst_object_get_parent (GST_OBJECT (element)));
3246 while (bin && !GST_FLAG_IS_SET (GST_OBJECT (bin), GST_BIN_FLAG_MANAGER))
3247 bin = GST_BIN (gst_object_get_parent (GST_OBJECT (bin)));