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.
23 /* #define GST_DEBUG_ENABLED */
26 #include "gst_private.h"
28 #include "gstelement.h"
29 #include "gstextratypes.h"
31 #include "gstscheduler.h"
35 /* Element signals and args */
50 #define CLASS(element) GST_ELEMENT_CLASS (G_OBJECT_GET_CLASS (element))
52 static void gst_element_class_init (GstElementClass *klass);
53 static void gst_element_init (GstElement *element);
54 static void gst_element_base_class_init (GstElementClass *klass);
56 static void gst_element_set_property (GObject *object, guint prop_id,
57 const GValue *value, GParamSpec *pspec);
58 static void gst_element_get_property (GObject *object, guint prop_id, GValue *value,
61 static void gst_element_dispose (GObject *object);
63 static GstElementStateReturn gst_element_change_state (GstElement *element);
64 static void gst_element_error_func (GstElement* element, GstElement *source, gchar *errormsg);
66 #ifndef GST_DISABLE_LOADSAVE
67 static xmlNodePtr gst_element_save_thyself (GstObject *object, xmlNodePtr parent);
68 static void gst_element_restore_thyself (GstObject *parent, xmlNodePtr self);
71 GType _gst_element_type = 0;
73 static GstObjectClass *parent_class = NULL;
74 static guint gst_element_signals[LAST_SIGNAL] = { 0 };
76 GType gst_element_get_type (void)
78 if (!_gst_element_type) {
79 static const GTypeInfo element_info = {
80 sizeof(GstElementClass),
81 (GBaseInitFunc)gst_element_base_class_init,
83 (GClassInitFunc)gst_element_class_init,
88 (GInstanceInitFunc)gst_element_init,
91 _gst_element_type = g_type_register_static(GST_TYPE_OBJECT, "GstElement", &element_info, G_TYPE_FLAG_ABSTRACT);
93 return _gst_element_type;
97 gst_element_class_init (GstElementClass *klass)
99 GObjectClass *gobject_class;
100 GstObjectClass *gstobject_class;
102 gobject_class = (GObjectClass*) klass;
103 gstobject_class = (GstObjectClass*) klass;
105 parent_class = g_type_class_ref(GST_TYPE_OBJECT);
107 gst_element_signals[STATE_CHANGE] =
108 g_signal_new ("state_change", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
109 G_STRUCT_OFFSET (GstElementClass, state_change), NULL, NULL,
110 gst_marshal_VOID__INT_INT, G_TYPE_NONE, 2,
111 G_TYPE_INT, G_TYPE_INT);
112 gst_element_signals[NEW_PAD] =
113 g_signal_new ("new_pad", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
114 G_STRUCT_OFFSET (GstElementClass, new_pad), NULL, NULL,
115 gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1,
117 gst_element_signals[PAD_REMOVED] =
118 g_signal_new ("pad_removed", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
119 G_STRUCT_OFFSET (GstElementClass, pad_removed), NULL, NULL,
120 gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1,
122 gst_element_signals[ERROR] =
123 g_signal_new ("error", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
124 G_STRUCT_OFFSET (GstElementClass, error), NULL, NULL,
125 gst_marshal_VOID__OBJECT_STRING, G_TYPE_NONE, 2,
126 G_TYPE_OBJECT, G_TYPE_STRING);
127 gst_element_signals[EOS] =
128 g_signal_new ("eos", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
129 G_STRUCT_OFFSET (GstElementClass,eos), NULL, NULL,
130 gst_marshal_VOID__VOID, G_TYPE_NONE, 0);
134 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_element_set_property);
135 gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_element_get_property);
136 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_element_dispose);
138 #ifndef GST_DISABLE_LOADSAVE
139 gstobject_class->save_thyself = GST_DEBUG_FUNCPTR (gst_element_save_thyself);
140 gstobject_class->restore_thyself = GST_DEBUG_FUNCPTR (gst_element_restore_thyself);
143 klass->change_state = GST_DEBUG_FUNCPTR (gst_element_change_state);
144 klass->error = GST_DEBUG_FUNCPTR (gst_element_error_func);
145 klass->elementfactory = NULL;
146 klass->padtemplates = NULL;
147 klass->numpadtemplates = 0;
151 gst_element_base_class_init (GstElementClass *klass)
153 GObjectClass *gobject_class;
155 gobject_class = (GObjectClass*) klass;
157 gobject_class->set_property = GST_DEBUG_FUNCPTR(gst_element_set_property);
158 gobject_class->get_property = GST_DEBUG_FUNCPTR(gst_element_get_property);
162 gst_element_init (GstElement *element)
164 element->current_state = GST_STATE_NULL;
165 element->pending_state = GST_STATE_VOID_PENDING;
166 element->numpads = 0;
167 element->numsrcpads = 0;
168 element->numsinkpads = 0;
169 element->pads = NULL;
170 element->loopfunc = NULL;
171 element->sched = NULL;
172 element->sched_private = NULL;
173 element->state_mutex = g_mutex_new ();
174 element->state_cond = g_cond_new ();
179 gst_element_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
181 GstElementClass *oclass = CLASS (object);
183 if (oclass->set_property)
184 (oclass->set_property) (object, prop_id, value, pspec);
189 gst_element_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
191 GstElementClass *oclass = CLASS (object);
193 if (oclass->get_property)
194 (oclass->get_property) (object, prop_id, value, pspec);
199 * gst_element_set_name:
200 * @element: GstElement to set name of
201 * @name: new name of element
203 * Set the name of the element, getting rid of the old name if there was
207 gst_element_set_name (GstElement *element, const gchar *name)
209 g_return_if_fail (element != NULL);
210 g_return_if_fail (GST_IS_ELEMENT (element));
212 gst_object_set_name (GST_OBJECT (element), name);
216 * gst_element_get_name:
217 * @element: GstElement to get name of
219 * Get the name of the element.
221 * Returns: name of the element
224 gst_element_get_name (GstElement *element)
226 g_return_val_if_fail (element != NULL, NULL);
227 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
229 return GST_OBJECT_NAME (element);
233 * gst_element_set_parent:
234 * @element: GstElement to set parent of
235 * @parent: new parent of the object
237 * Set the parent of the element.
240 gst_element_set_parent (GstElement *element, GstObject *parent)
242 g_return_if_fail (element != NULL);
243 g_return_if_fail (GST_IS_ELEMENT (element));
244 g_return_if_fail (GST_OBJECT_PARENT (element) == NULL);
245 g_return_if_fail (parent != NULL);
246 g_return_if_fail (GST_IS_OBJECT (parent));
247 g_return_if_fail ((gpointer)element != (gpointer)parent);
249 gst_object_set_parent (GST_OBJECT (element), parent);
253 * gst_element_get_parent:
254 * @element: GstElement to get the parent of
256 * Get the parent of the element.
258 * Returns: parent of the element
261 gst_element_get_parent (GstElement *element)
263 g_return_val_if_fail (element != NULL, NULL);
264 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
266 return GST_OBJECT_PARENT (element);
270 * gst_element_set_clock:
271 * @element: GstElement to set the clock to
272 * @clock: the clock to set for the element
274 * Set the clock for the element
277 gst_element_set_clock (GstElement *element, GstClock *clock)
279 g_return_if_fail (element != NULL);
280 g_return_if_fail (GST_IS_ELEMENT (element));
282 if (element->setclockfunc)
283 element->setclockfunc (element, clock);
287 * gst_element_get_clock:
288 * @element: GstElement to get the clock of
290 * Get the clock of the element
292 * Returns: the clock of the element.
295 gst_element_get_clock (GstElement *element)
297 g_return_val_if_fail (element != NULL, NULL);
298 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
300 if (element->getclockfunc)
301 return element->getclockfunc (element);
307 * gst_element_clock_wait:
308 * @element: GstElement to wait for the clock
309 * @clock: the clock to wait for
310 * @time: the time to wait for
312 * Wait for a specific time on the clock
314 * Returns: the result of the wait operation
317 gst_element_clock_wait (GstElement *element, GstClock *clock, GstClockTime time)
319 g_return_val_if_fail (element != NULL, GST_CLOCK_ERROR);
320 g_return_val_if_fail (GST_IS_ELEMENT (element), GST_CLOCK_ERROR);
322 if (GST_ELEMENT_SCHED (element)) {
323 return gst_scheduler_clock_wait (GST_ELEMENT_SCHED (element), element, clock, time);
326 return GST_CLOCK_TIMEOUT;
330 * gst_element_add_pad:
331 * @element: element to add pad to
334 * Add a pad (connection point) to the element, setting the parent of the
335 * pad to the element (and thus adding a reference).
338 gst_element_add_pad (GstElement *element, GstPad *pad)
340 g_return_if_fail (element != NULL);
341 g_return_if_fail (GST_IS_ELEMENT (element));
342 g_return_if_fail (pad != NULL);
343 g_return_if_fail (GST_IS_PAD (pad));
345 /* first check to make sure the pad's parent is already set */
346 g_return_if_fail (GST_PAD_PARENT (pad) == NULL);
348 /* then check to see if there's already a pad by that name here */
349 g_return_if_fail (gst_object_check_uniqueness (element->pads, GST_PAD_NAME(pad)) == TRUE);
351 /* set the pad's parent */
352 GST_DEBUG (GST_CAT_ELEMENT_PADS,"setting parent of pad '%s' to '%s'",
353 GST_PAD_NAME (pad), GST_ELEMENT_NAME (element));
354 gst_object_set_parent (GST_OBJECT (pad), GST_OBJECT (element));
356 /* add it to the list */
357 element->pads = g_list_append (element->pads, pad);
359 if (gst_pad_get_direction (pad) == GST_PAD_SRC)
360 element->numsrcpads++;
362 element->numsinkpads++;
364 /* emit the NEW_PAD signal */
365 g_signal_emit (G_OBJECT (element), gst_element_signals[NEW_PAD], 0, pad);
369 * gst_element_remove_pad:
370 * @element: element to remove pad from
371 * @pad: pad to remove
373 * Remove a pad (connection point) from the element,
376 gst_element_remove_pad (GstElement *element, GstPad *pad)
378 g_return_if_fail (element != NULL);
379 g_return_if_fail (GST_IS_ELEMENT (element));
380 g_return_if_fail (pad != NULL);
381 g_return_if_fail (GST_IS_PAD (pad));
383 g_return_if_fail (GST_PAD_PARENT (pad) == element);
385 /* check to see if the pad is still connected */
386 /* FIXME: what if someone calls _remove_pad instead of
387 _remove_ghost_pad? */
388 if (GST_IS_REAL_PAD (pad)) {
389 g_return_if_fail (GST_RPAD_PEER (pad) == NULL);
392 /* remove it from the list */
393 element->pads = g_list_remove (element->pads, pad);
395 if (gst_pad_get_direction (pad) == GST_PAD_SRC)
396 element->numsrcpads--;
398 element->numsinkpads--;
400 g_signal_emit (G_OBJECT (element), gst_element_signals[PAD_REMOVED], 0, pad);
402 gst_object_unparent (GST_OBJECT (pad));
406 * gst_element_add_ghost_pad:
407 * @element: element to add ghost pad to
408 * @pad: pad from which the new ghost pad will be created
409 * @name: name of the new ghost pad
411 * Create a ghost pad from the given pad, and add it to the list of pads
414 * Returns: the added ghost pad or NULL, if no ghost pad was created.
417 gst_element_add_ghost_pad (GstElement *element, GstPad *pad, gchar *name)
421 g_return_val_if_fail (element != NULL, NULL);
422 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
423 g_return_val_if_fail (pad != NULL, NULL);
424 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
426 /* then check to see if there's already a pad by that name here */
427 g_return_val_if_fail (gst_object_check_uniqueness (element->pads, name) == TRUE, NULL);
429 GST_DEBUG(GST_CAT_ELEMENT_PADS,"creating new ghost pad called %s, from pad %s:%s",
430 name,GST_DEBUG_PAD_NAME(pad));
431 ghostpad = gst_ghost_pad_new (name, pad);
433 /* add it to the list */
434 GST_DEBUG(GST_CAT_ELEMENT_PADS,"adding ghost pad %s to element %s",
435 name, GST_ELEMENT_NAME (element));
436 element->pads = g_list_append (element->pads, ghostpad);
438 /* set the parent of the ghostpad */
439 gst_object_set_parent (GST_OBJECT (ghostpad), GST_OBJECT (element));
441 GST_DEBUG(GST_CAT_ELEMENT_PADS,"added ghostpad %s:%s",GST_DEBUG_PAD_NAME(ghostpad));
443 /* emit the NEW_GHOST_PAD signal */
444 g_signal_emit (G_OBJECT (element), gst_element_signals[NEW_PAD], 0, ghostpad);
450 * gst_element_remove_ghost_pad:
451 * @element: element to remove the ghost pad from
452 * @pad: ghost pad to remove
454 * removes a ghost pad from an element
457 gst_element_remove_ghost_pad (GstElement *element, GstPad *pad)
459 g_return_if_fail (element != NULL);
460 g_return_if_fail (GST_IS_ELEMENT (element));
461 g_return_if_fail (pad != NULL);
462 g_return_if_fail (GST_IS_GHOST_PAD (pad));
464 /* FIXME this is redundant?
465 * wingo 10-july-2001: I don't think so, you have to actually remove the pad
466 * from the element. gst_pad_remove_ghost_pad just removes the ghostpad from
467 * the real pad's ghost pad list
469 gst_pad_remove_ghost_pad (GST_PAD (GST_PAD_REALIZE (pad)), pad);
470 gst_element_remove_pad (element, pad);
475 * gst_element_get_pad:
476 * @element: element to find pad of
477 * @name: name of pad to retrieve
479 * Retrieve a pad from the element by name.
481 * Returns: requested pad if found, otherwise NULL.
484 gst_element_get_pad (GstElement *element, const gchar *name)
488 g_return_val_if_fail (element != NULL, NULL);
489 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
490 g_return_val_if_fail (name != NULL, NULL);
492 /* if there aren't any pads, well, we're not likely to find one */
493 if (!element->numpads)
496 /* look through the list, matching by name */
497 walk = element->pads;
501 pad = GST_PAD(walk->data);
502 if (!strcmp (GST_PAD_NAME(pad), name)) {
503 GST_INFO(GST_CAT_ELEMENT_PADS,"found pad %s:%s",GST_DEBUG_PAD_NAME(pad));
506 walk = g_list_next (walk);
509 GST_INFO(GST_CAT_ELEMENT_PADS,"no such pad '%s' in element \"%s\"",name,GST_ELEMENT_NAME(element));
514 * gst_element_get_pad_list:
515 * @element: element to get pads of
517 * Retrieve a list of the pads associated with the element.
519 * Returns: GList of pads
522 gst_element_get_pad_list (GstElement *element)
524 g_return_val_if_fail (element != NULL, NULL);
525 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
527 /* return the list of pads */
528 return element->pads;
532 * gst_element_class_add_padtemplate:
533 * @klass: element class to add padtemplate to
534 * @templ: padtemplate to add
536 * Add a padtemplate to an element class. This is useful if you have derived a custom
537 * bin and wish to provide an on-request pad at runtime. Plugin writers should use
538 * gst_elementfactory_add_padtemplate instead.
541 gst_element_class_add_padtemplate (GstElementClass *klass, GstPadTemplate *templ)
543 g_return_if_fail (klass != NULL);
544 g_return_if_fail (GST_IS_ELEMENT_CLASS (klass));
545 g_return_if_fail (templ != NULL);
546 g_return_if_fail (GST_IS_PADTEMPLATE (templ));
548 klass->padtemplates = g_list_append (klass->padtemplates, templ);
549 klass->numpadtemplates++;
553 * gst_element_get_padtemplate_list:
554 * @element: element to get padtemplates of
556 * Retrieve a list of the padtemplates associated with the element.
558 * Returns: GList of padtemplates
561 gst_element_get_padtemplate_list (GstElement *element)
563 g_return_val_if_fail (element != NULL, NULL);
564 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
566 return CLASS (element)->padtemplates;
570 * gst_element_get_padtemplate_by_name:
571 * @element: element to get padtemplate of
572 * @name: the name of the padtemplate to get.
574 * Retrieve a padtemplate from this element with the
577 * Returns: the padtemplate with the given name
580 gst_element_get_padtemplate_by_name (GstElement *element, const guchar *name)
584 g_return_val_if_fail (element != NULL, NULL);
585 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
586 g_return_val_if_fail (name != NULL, NULL);
588 padlist = gst_element_get_padtemplate_list (element);
591 GstPadTemplate *padtempl = (GstPadTemplate*) padlist->data;
593 if (!strcmp (padtempl->name_template, name))
596 padlist = g_list_next (padlist);
603 * gst_element_get_padtemplate_by_compatible:
604 * @element: element to get padtemplate of
605 * @templ: a template to find a compatible template for
607 * Generate a padtemplate for this element compatible with the given
608 * template, ie able to link to it.
610 * Returns: the padtemplate
612 static GstPadTemplate*
613 gst_element_get_padtemplate_by_compatible (GstElement *element, GstPadTemplate *compattempl)
615 GstPadTemplate *newtempl = NULL;
618 GST_DEBUG(GST_CAT_ELEMENT_PADS,"gst_element_get_padtemplate_by_compatible()");
620 g_return_val_if_fail (element != NULL, NULL);
621 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
622 g_return_val_if_fail (compattempl != NULL, NULL);
624 padlist = gst_element_get_padtemplate_list (element);
627 GstPadTemplate *padtempl = (GstPadTemplate*) padlist->data;
628 gboolean compat = FALSE;
632 * Check direction (must be opposite)
635 GST_DEBUG(GST_CAT_CAPS,"checking direction and caps");
636 if (padtempl->direction == GST_PAD_SRC &&
637 compattempl->direction == GST_PAD_SINK) {
638 GST_DEBUG(GST_CAT_CAPS,"compatible direction: found src pad template");
639 compat = gst_caps_check_compatibility(GST_PADTEMPLATE_CAPS (padtempl),
640 GST_PADTEMPLATE_CAPS (compattempl));
641 GST_DEBUG(GST_CAT_CAPS,"caps are %scompatible", (compat?"":"not "));
642 } else if (padtempl->direction == GST_PAD_SINK &&
643 compattempl->direction == GST_PAD_SRC) {
644 GST_DEBUG(GST_CAT_CAPS,"compatible direction: found sink pad template");
645 compat = gst_caps_check_compatibility(GST_PADTEMPLATE_CAPS (compattempl),
646 GST_PADTEMPLATE_CAPS (padtempl));
647 GST_DEBUG(GST_CAT_CAPS,"caps are %scompatible", (compat?"":"not "));
655 padlist = g_list_next (padlist);
662 gst_element_request_pad (GstElement *element, GstPadTemplate *templ, const gchar* name)
664 GstPad *newpad = NULL;
665 GstElementClass *oclass;
667 oclass = CLASS (element);
668 if (oclass->request_new_pad)
669 newpad = (oclass->request_new_pad)(element, templ, name);
675 * gst_element_request_compatible_pad:
676 * @element: element to request a new pad from
677 * @templ: a pad template to which the new pad should be able to connect
679 * Request a new pad from the element. The template will
680 * be used to decide what type of pad to create. This function
681 * is typically used for elements with a padtemplate with presence
684 * Returns: the new pad that was created.
687 gst_element_request_compatible_pad (GstElement *element, GstPadTemplate *templ)
689 GstPadTemplate *templ_new;
692 g_return_val_if_fail (element != NULL, NULL);
693 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
694 g_return_val_if_fail (templ != NULL, NULL);
696 templ_new = gst_element_get_padtemplate_by_compatible (element, templ);
697 if (templ_new != NULL)
698 pad = gst_element_request_pad (element, templ_new, NULL);
704 * gst_element_request_pad_by_name:
705 * @element: element to request a new pad from
706 * @name: the name of the padtemplate to use.
708 * Request a new pad from the element. The name argument will
709 * be used to decide what padtemplate to use. This function
710 * is typically used for elements with a padtemplate with presence
713 * Returns: the new pad that was created.
716 gst_element_request_pad_by_name (GstElement *element, const gchar *name)
718 GstPadTemplate *templ = NULL;
720 const gchar *req_name = NULL;
721 gboolean templ_found = FALSE;
727 g_return_val_if_fail (element != NULL, NULL);
728 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
729 g_return_val_if_fail (name != NULL, NULL);
732 if (strstr (name, "%")) {
733 templ = gst_element_get_padtemplate_by_name (element, name);
738 list = gst_element_get_padtemplate_list(element);
739 while (!templ_found && list) {
740 templ = (GstPadTemplate*) list->data;
741 if (templ->presence == GST_PAD_REQUEST) {
742 /* we know that %s and %d are the only possibilities because of sanity
743 checks in gst_padtemplate_new */
744 if ((str = strchr (templ->name_template, '%')) &&
745 strncmp (templ->name_template, name, str - templ->name_template) == 0 &&
746 strlen (name) > str - templ->name_template) {
747 data = name + (str - templ->name_template);
748 if (*(str+1) == 'd') {
750 n = (gint) strtol (data, &endptr, 10);
751 if (endptr == NULL) {
771 pad = gst_element_request_pad (element, templ, req_name);
777 * gst_element_get_compatible_pad_filtered:
778 * @element: the element in which the pad should be found
779 * @pad: the pad to find a compatible one for
780 * @filtercaps: the caps to use as a filter
782 * Looks for an unconnected pad to which the given pad can connect to.
783 * It is not guaranteed that connecting the pads will work, though
784 * it should work in most cases.
786 * Returns: the pad to which a connection can be made
789 gst_element_get_compatible_pad_filtered (GstElement *element, GstPad *pad, GstCaps *filtercaps)
792 GstPadTemplate *templ;
794 GstPad *foundpad = NULL;
797 g_return_val_if_fail (element != NULL, NULL);
798 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
799 g_return_val_if_fail (pad != NULL, NULL);
800 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
802 /* let's use the real pad */
803 pad = (GstPad *) GST_PAD_REALIZE (pad);
804 g_return_val_if_fail (pad != NULL, NULL);
805 g_return_val_if_fail (GST_RPAD_PEER (pad) == NULL, NULL);
807 /* try to get an existing unconnected pad */
808 pads = gst_element_get_pad_list (element);
810 GstPad *current = GST_PAD (pads->data);
811 if ((GST_PAD_PEER (GST_PAD_REALIZE (current)) == NULL) &&
812 gst_pad_can_connect_filtered (pad, current, filtercaps)) {
815 pads = g_list_next (pads);
818 /* try to create a new one */
819 /* requesting is a little crazy, we need a template. Let's create one */
820 if (filtercaps != NULL) {
821 templcaps = gst_caps_intersect (filtercaps, (GstCaps *) GST_RPAD_CAPS (pad));
822 if (templcaps == NULL)
825 templcaps = gst_caps_copy (gst_pad_get_caps (pad));
828 templ = gst_padtemplate_new ((gchar *) GST_PAD_NAME (pad), GST_RPAD_DIRECTION (pad),
829 GST_PAD_ALWAYS, templcaps, NULL);
830 foundpad = gst_element_request_compatible_pad (element, templ);
831 gst_object_unref (GST_OBJECT (templ)); /* this will take care of the caps too */
833 /* FIXME: this is broken, but it's in here so autoplugging elements that don't
834 have caps on their source padtemplates (spider) can connect... */
835 if (!foundpad && !filtercaps) {
836 templ = gst_padtemplate_new ((gchar *) GST_PAD_NAME (pad), GST_RPAD_DIRECTION (pad),
837 GST_PAD_ALWAYS, NULL, NULL);
838 foundpad = gst_element_request_compatible_pad (element, templ);
839 gst_object_unref (GST_OBJECT (templ));
846 * gst_element_get_compatible_pad:
847 * @element: the element in which the pad should be found
848 * @pad: the pad to find a compatible one for
850 * Looks for an unconnected pad to which the given pad can connect to.
851 * It is not guaranteed that connecting the pads will work, though
852 * it should work in most cases.
854 * Returns: the pad to which a connection can be made
857 gst_element_get_compatible_pad (GstElement *element, GstPad *pad)
859 return gst_element_get_compatible_pad_filtered (element, pad, NULL);
863 * gst_element_connect_elements_filtered:
864 * @src: the element containing source pad
865 * @dest: the element containing destination pad
866 * @filtercaps: the caps to use as filter
868 * Connect the source to the destination element using the filtercaps.
869 * The connection must be from source to destination, the other
870 * direction will not be tried.
871 * The functions looks for existing pads that aren't connected yet.
872 + It will use request pads if possible. But both pads will not be requested.
873 * If multiple connections are possible, only one is established.
875 * Returns: TRUE if the elements could be connected.
878 gst_element_connect_elements_filtered (GstElement *src, GstElement *dest,
881 GList *srcpads, *destpads, *srctempls, *desttempls, *l;
882 GstPad *srcpad, *destpad;
883 GstPadTemplate *srctempl, *desttempl;
886 g_return_val_if_fail (src != NULL, FALSE);
887 g_return_val_if_fail (GST_IS_ELEMENT(src), FALSE);
888 g_return_val_if_fail (dest != NULL, FALSE);
889 g_return_val_if_fail (GST_IS_ELEMENT(dest), FALSE);
891 GST_DEBUG (GST_CAT_ELEMENT_PADS, "attempting to connect element %s to element %s", GST_ELEMENT_NAME (src), GST_ELEMENT_NAME (dest));
893 /* loop through the existing pads in the source */
894 srcpads = gst_element_get_pad_list (src);
895 destpads = gst_element_get_pad_list (dest);
897 if (srcpads || destpads) {
899 srcpad = (GstPad *) GST_PAD_REALIZE (srcpads->data);
900 if ((GST_RPAD_DIRECTION (srcpad) == GST_PAD_SRC) &&
901 (GST_PAD_PEER (srcpad) == NULL)) {
902 destpad = gst_element_get_compatible_pad_filtered (dest, srcpad, filtercaps);
903 if (destpad && gst_pad_connect_filtered (srcpad, destpad, filtercaps)) {
904 GST_DEBUG (GST_CAT_ELEMENT_PADS, "connected pad %s:%s to pad %s:%s", GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (destpad));
908 srcpads = g_list_next (srcpads);
911 /* loop through the existing pads in the destination */
913 destpad = (GstPad *) GST_PAD_REALIZE (destpads->data);
914 if ((GST_RPAD_DIRECTION (destpad) == GST_PAD_SINK) &&
915 (GST_PAD_PEER (destpad) == NULL)) {
916 srcpad = gst_element_get_compatible_pad_filtered (src, destpad, filtercaps);
917 if (srcpad && gst_pad_connect_filtered (srcpad, destpad, filtercaps)) {
918 GST_DEBUG (GST_CAT_ELEMENT_PADS, "connected pad %s:%s to pad %s:%s", GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (destpad));
922 destpads = g_list_next (destpads);
926 GST_DEBUG (GST_CAT_ELEMENT_PADS, "we might have request pads on both sides, checking...");
927 srctempls = gst_element_get_padtemplate_list (src);
928 desttempls = gst_element_get_padtemplate_list (dest);
930 if (srctempls && desttempls) {
932 srctempl = (GstPadTemplate*) srctempls->data;
933 if (srctempl->presence == GST_PAD_REQUEST) {
934 for (l=desttempls; l; l=l->next) {
935 desttempl = (GstPadTemplate*) desttempls->data;
936 if (desttempl->presence == GST_PAD_REQUEST && desttempl->direction != srctempl->direction) {
937 if (gst_caps_check_compatibility (gst_padtemplate_get_caps (srctempl),
938 gst_padtemplate_get_caps (desttempl))) {
939 srcpad = gst_element_request_pad_by_name (src, srctempl->name_template);
940 destpad = gst_element_request_pad_by_name (dest, desttempl->name_template);
941 if (gst_pad_connect_filtered (srcpad, destpad, filtercaps)) {
942 GST_DEBUG (GST_CAT_ELEMENT_PADS, "connected pad %s:%s to pad %s:%s",
943 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (destpad));
946 /* FIXME: we have extraneous request pads lying around */
951 srctempls = srctempls->next;
955 GST_DEBUG (GST_CAT_ELEMENT_PADS, "no connection possible from %s to %s", GST_ELEMENT_NAME (src), GST_ELEMENT_NAME (dest));
960 * gst_element_connect_elements_many:
961 * @element_1: the first element in the connection chain
962 * @element_2: the second element in the connection chain
963 * @...: NULL-terminated list of elements to connect in order
965 * Chain together a series of elements. Uses #gst_element_connect_elements.
967 * Returns: TRUE on success, FALSE otherwise.
969 /* API FIXME: this should be called gst_element_connect_many, and connect_elements
970 * should just be connect */
972 gst_element_connect_elements_many (GstElement *element_1, GstElement *element_2, ...)
976 g_return_val_if_fail (element_1 != NULL && element_2 != NULL, FALSE);
977 g_return_val_if_fail (GST_IS_ELEMENT (element_1) && GST_IS_ELEMENT (element_2), FALSE);
979 va_start (args, element_2);
982 if (!gst_element_connect_elements (element_1, element_2))
985 element_1 = element_2;
986 element_2 = va_arg (args, GstElement*);
995 * gst_element_connect_elements:
996 * @src: element containing source pad
997 * @dest: element containing destination pad
999 * Connect the source to the destination element.
1000 * The connection must be from source to destination, the other
1001 * direction will not be tried.
1002 * The functions looks for existing pads and request pads that aren't
1003 * connected yet. If multiple connections are possible, only one is
1006 * Returns: TRUE if the elements could be connected.
1009 gst_element_connect_elements (GstElement *src, GstElement *dest)
1011 return gst_element_connect_elements_filtered (src, dest, NULL);
1015 * gst_element_connect_filtered:
1016 * @src: element containing source pad
1017 * @srcpadname: name of pad in source element
1018 * @dest: element containing destination pad
1019 * @destpadname: name of pad in destination element
1020 * @filtercaps: the caps to use as a filter
1022 * Connect the two named pads of the source and destination elements.
1023 * Side effect is that if one of the pads has no parent, it becomes a
1024 * child of the parent of the other element. If they have different
1025 * parents, the connection fails.
1027 * Returns: TRUE if the pads could be connected.
1030 gst_element_connect_filtered (GstElement *src, const gchar *srcpadname,
1031 GstElement *dest, const gchar *destpadname,
1032 GstCaps *filtercaps)
1034 GstPad *srcpad,*destpad;
1036 g_return_val_if_fail (src != NULL, FALSE);
1037 g_return_val_if_fail (GST_IS_ELEMENT(src), FALSE);
1038 g_return_val_if_fail (srcpadname != NULL, FALSE);
1039 g_return_val_if_fail (dest != NULL, FALSE);
1040 g_return_val_if_fail (GST_IS_ELEMENT(dest), FALSE);
1041 g_return_val_if_fail (destpadname != NULL, FALSE);
1043 /* obtain the pads requested */
1044 srcpad = gst_element_get_pad (src, srcpadname);
1045 if (srcpad == NULL) {
1046 GST_ERROR (src, "source element has no pad \"%s\"", srcpadname);
1049 destpad = gst_element_get_pad (dest, destpadname);
1050 if (srcpad == NULL) {
1051 GST_ERROR (dest, "destination element has no pad \"%s\"", destpadname);
1055 /* we're satisified they can be connected, let's do it */
1056 return gst_pad_connect_filtered (srcpad, destpad, filtercaps);
1060 * gst_element_connect:
1061 * @src: element containing source pad
1062 * @srcpadname: name of pad in source element
1063 * @dest: element containing destination pad
1064 * @destpadname: name of pad in destination element
1066 * Connect the two named pads of the source and destination elements.
1067 * Side effect is that if one of the pads has no parent, it becomes a
1068 * child of the parent of the other element. If they have different
1069 * parents, the connection fails.
1071 * Returns: TRUE if the pads could be connected.
1074 gst_element_connect (GstElement *src, const gchar *srcpadname,
1075 GstElement *dest, const gchar *destpadname)
1077 return gst_element_connect_filtered (src, srcpadname, dest, destpadname, NULL);
1081 * gst_element_disconnect:
1082 * @src: element containing source pad
1083 * @srcpadname: name of pad in source element
1084 * @dest: element containing destination pad
1085 * @destpadname: name of pad in destination element
1087 * Disconnect the two named pads of the source and destination elements.
1090 gst_element_disconnect (GstElement *src, const gchar *srcpadname,
1091 GstElement *dest, const gchar *destpadname)
1093 GstPad *srcpad,*destpad;
1095 g_return_if_fail (src != NULL);
1096 g_return_if_fail (GST_IS_ELEMENT(src));
1097 g_return_if_fail (srcpadname != NULL);
1098 g_return_if_fail (dest != NULL);
1099 g_return_if_fail (GST_IS_ELEMENT(dest));
1100 g_return_if_fail (destpadname != NULL);
1102 /* obtain the pads requested */
1103 srcpad = gst_element_get_pad (src, srcpadname);
1104 if (srcpad == NULL) {
1105 GST_ERROR(src,"source element has no pad \"%s\"",srcpadname);
1108 destpad = gst_element_get_pad (dest, destpadname);
1109 if (srcpad == NULL) {
1110 GST_ERROR(dest,"destination element has no pad \"%s\"",destpadname);
1114 /* we're satisified they can be disconnected, let's do it */
1115 gst_pad_disconnect(srcpad,destpad);
1119 * gst_element_disconnect_elements:
1120 * @src: source element
1121 * @dest: sink element
1123 * Disconnect all pads connecting the two elements in the direction src -> dest.
1126 gst_element_disconnect_elements (GstElement *src, GstElement *dest)
1131 g_return_if_fail (GST_IS_ELEMENT(src));
1132 g_return_if_fail (GST_IS_ELEMENT(dest));
1134 srcpads = gst_element_get_pad_list (src);
1137 pad = GST_PAD (srcpads->data);
1139 if (GST_PAD_DIRECTION (pad) == GST_PAD_SRC)
1140 if (GST_OBJECT_PARENT (GST_PAD_PEER (pad)) == (GstObject*) dest)
1141 gst_pad_disconnect (pad, GST_PAD_PEER (pad));
1143 srcpads = g_list_next (srcpads);
1148 gst_element_error_func (GstElement* element, GstElement *source, gchar *errormsg)
1150 /* tell the parent */
1151 if (GST_OBJECT_PARENT (element)) {
1152 GST_DEBUG (GST_CAT_EVENT, "forwarding error \"%s\" from %s to %s", errormsg,
1153 GST_ELEMENT_NAME (element), GST_OBJECT_NAME (GST_OBJECT_PARENT (element)));
1155 gst_object_ref (GST_OBJECT (element));
1156 g_signal_emit (G_OBJECT (GST_OBJECT_PARENT (element)), gst_element_signals[ERROR], 0, source, errormsg);
1157 gst_object_unref (GST_OBJECT (element));
1161 * gst_element_error:
1162 * @element: Element with the error
1163 * @error: A printf-like string describing the error
1164 * @...: optional arguments for the string
1166 * This function is used internally by elements to signal an error
1167 * condition. It results in the "error" signal.
1170 gst_element_error (GstElement *element, const gchar *error, ...)
1176 g_return_if_fail (GST_IS_ELEMENT (element));
1177 g_return_if_fail (element != NULL);
1178 g_return_if_fail (error != NULL);
1180 /* create error message */
1181 va_start (var_args, error);
1182 string = g_strdup_vprintf (error, var_args);
1184 GST_INFO (GST_CAT_EVENT, "ERROR in %s: %s", GST_ELEMENT_NAME (element), string);
1186 /* emit the signal, make sure the element stays available */
1187 gst_object_ref (GST_OBJECT (element));
1188 g_signal_emit (G_OBJECT (element), gst_element_signals[ERROR], 0, element, string);
1190 /* tell the scheduler */
1191 if (element->sched) {
1192 gst_scheduler_error (element->sched, element);
1196 gst_object_unref (GST_OBJECT (element));
1201 * gst_element_get_state:
1202 * @element: element to get state of
1204 * Gets the state of the element.
1206 * Returns: The element state
1209 gst_element_get_state (GstElement *element)
1211 g_return_val_if_fail (GST_IS_ELEMENT (element), GST_STATE_VOID_PENDING);
1213 return GST_STATE (element);
1217 * gst_element_wait_state_change:
1218 * @element: element wait for
1220 * Wait and block until the element changed its state.
1223 gst_element_wait_state_change (GstElement *element)
1225 g_mutex_lock (element->state_mutex);
1226 g_cond_wait (element->state_cond, element->state_mutex);
1227 g_mutex_unlock (element->state_mutex);
1230 * gst_element_set_state:
1231 * @element: element to change state of
1232 * @state: new element state
1234 * Sets the state of the element. This function will only set
1235 * the elements pending state.
1237 * Returns: whether or not the state was successfully set.
1240 gst_element_set_state (GstElement *element, GstElementState state)
1242 GstElementClass *oclass;
1243 GstElementState curpending;
1244 GstElementStateReturn return_val = GST_STATE_SUCCESS;
1246 g_return_val_if_fail (GST_IS_ELEMENT (element), GST_STATE_FAILURE);
1248 /* start with the current state */
1249 curpending = GST_STATE(element);
1251 GST_DEBUG_ELEMENT (GST_CAT_STATES, element, "setting state from %s to %s\n",
1252 gst_element_statename (curpending),
1253 gst_element_statename (state));
1255 /* loop until the final requested state is set */
1256 while (GST_STATE (element) != state && GST_STATE (element) != GST_STATE_VOID_PENDING) {
1257 /* move the curpending state in the correct direction */
1258 if (curpending < state)
1263 /* set the pending state variable */
1264 /* FIXME: should probably check to see that we don't already have one */
1265 GST_STATE_PENDING (element) = curpending;
1267 if (curpending != state) {
1268 GST_DEBUG_ELEMENT (GST_CAT_STATES, element, "intermediate: setting state to %s\n",
1269 gst_element_statename (curpending));
1272 /* call the state change function so it can set the state */
1273 oclass = CLASS (element);
1274 if (oclass->change_state)
1275 return_val = (oclass->change_state) (element);
1277 switch (return_val) {
1278 case GST_STATE_FAILURE:
1279 GST_DEBUG_ELEMENT (GST_CAT_STATES, element, "have failed change_state return\n");
1281 case GST_STATE_ASYNC:
1282 GST_DEBUG_ELEMENT (GST_CAT_STATES, element, "element will change state async\n");
1285 /* Last thing we do is verify that a successful state change really
1286 * did change the state... */
1287 if (GST_STATE (element) != curpending) {
1288 GST_DEBUG_ELEMENT (GST_CAT_STATES, element,
1289 "element claimed state-change success, but state didn't change %s, %s <-> %s\n",
1290 gst_element_statename (GST_STATE (element)),
1291 gst_element_statename (GST_STATE_PENDING (element)),
1292 gst_element_statename (curpending));
1293 return GST_STATE_FAILURE;
1303 gst_element_negotiate_pads (GstElement *element)
1305 GList *pads = GST_ELEMENT_PADS (element);
1307 GST_DEBUG_ELEMENT (GST_CAT_CAPS, element, "negotiating pads\n");
1310 GstPad *pad = GST_PAD (pads->data);
1313 pads = g_list_next (pads);
1315 if (!GST_IS_REAL_PAD (pad))
1318 srcpad = GST_PAD_REALIZE (pad);
1320 /* if we have a connection on this pad and it doesn't have caps
1321 * allready, try to negotiate */
1322 if (GST_PAD_IS_CONNECTED (srcpad) && !GST_PAD_CAPS (srcpad)) {
1323 GstRealPad *sinkpad;
1324 GstElementState otherstate;
1327 sinkpad = GST_RPAD_PEER (GST_PAD_REALIZE (srcpad));
1329 /* check the parent of the peer pad, if there is no parent do nothing */
1330 parent = GST_PAD_PARENT (sinkpad);
1334 otherstate = GST_STATE (parent);
1336 /* swap pads if needed */
1337 if (!GST_PAD_IS_SRC (srcpad)) {
1345 /* only try to negotiate if the peer element is in PAUSED or higher too */
1346 if (otherstate >= GST_STATE_READY) {
1347 GST_DEBUG_ELEMENT (GST_CAT_CAPS, element, "perform negotiate for %s:%s and %s:%s\n",
1348 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1349 if (!gst_pad_perform_negotiate (GST_PAD (srcpad), GST_PAD (sinkpad)))
1353 GST_DEBUG_ELEMENT (GST_CAT_CAPS, element, "not negotiatiating %s:%s and %s:%s, not in READY yet\n",
1354 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1363 gst_element_clear_pad_caps (GstElement *element)
1365 GList *pads = GST_ELEMENT_PADS (element);
1367 GST_DEBUG_ELEMENT (GST_CAT_CAPS, element, "clearing pad caps\n");
1370 GstRealPad *pad = GST_PAD_REALIZE (pads->data);
1372 if (GST_PAD_CAPS (pad)) {
1373 GST_PAD_CAPS (pad) = NULL;
1375 pads = g_list_next (pads);
1379 static GstElementStateReturn
1380 gst_element_change_state (GstElement *element)
1382 GstElementState old_state;
1384 gint old_pending, old_transition;
1386 g_return_val_if_fail (GST_IS_ELEMENT (element), GST_STATE_FAILURE);
1388 old_state = GST_STATE (element);
1389 old_pending = GST_STATE_PENDING (element);
1390 old_transition = GST_STATE_TRANSITION (element);
1392 if (old_pending == GST_STATE_VOID_PENDING || old_state == GST_STATE_PENDING (element)) {
1393 GST_INFO (GST_CAT_STATES, "no state change needed for element %s (VOID_PENDING)", GST_ELEMENT_NAME (element));
1394 return GST_STATE_SUCCESS;
1397 GST_INFO (GST_CAT_STATES, "%s default handler sets state from %s to %s %d", GST_ELEMENT_NAME (element),
1398 gst_element_statename (old_state),
1399 gst_element_statename (old_pending),
1400 GST_STATE_TRANSITION (element));
1402 /* we set the state change early for the negotiation functions */
1403 GST_STATE (element) = old_pending;
1404 GST_STATE_PENDING (element) = GST_STATE_VOID_PENDING;
1406 /* if we are going to paused, we try to negotiate the pads */
1407 if (old_transition == GST_STATE_NULL_TO_READY) {
1408 if (!gst_element_negotiate_pads (element))
1411 /* going to the READY state clears all pad caps */
1412 else if (old_transition == GST_STATE_READY_TO_NULL) {
1413 gst_element_clear_pad_caps (element);
1416 /* tell the scheduler if we have one */
1417 if (element->sched) {
1418 if (gst_scheduler_state_transition (element->sched, element, old_transition)
1419 != GST_STATE_SUCCESS) {
1424 parent = GST_ELEMENT_PARENT (element);
1426 /* tell our parent about the state change */
1427 if (parent && GST_IS_BIN (parent)) {
1428 gst_bin_child_state_change (GST_BIN (parent), old_state, GST_STATE (element), element);
1431 g_signal_emit (G_OBJECT (element), gst_element_signals[STATE_CHANGE],
1432 0, old_state, GST_STATE (element));
1434 /* signal the state change in case somebody is waiting for us */
1435 g_mutex_lock (element->state_mutex);
1436 g_cond_signal (element->state_cond);
1437 g_mutex_unlock (element->state_mutex);
1439 return GST_STATE_SUCCESS;
1442 /* undo the state change */
1443 GST_STATE (element) = old_state;
1444 GST_STATE_PENDING (element) = old_pending;
1446 return GST_STATE_FAILURE;
1450 * gst_element_get_factory:
1451 * @element: element to request the factory
1453 * Retrieves the factory that was used to create this element
1455 * Returns: the factory used for creating this element
1458 gst_element_get_factory (GstElement *element)
1460 GstElementClass *oclass;
1462 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
1464 oclass = CLASS (element);
1466 return oclass->elementfactory;
1470 gst_element_dispose (GObject *object)
1472 GstElement *element = GST_ELEMENT (object);
1476 GST_DEBUG_ELEMENT (GST_CAT_REFCOUNTING, element, "dispose\n");
1478 gst_element_set_state (element, GST_STATE_NULL);
1480 /* first we break all our connections with the ouside */
1481 if (element->pads) {
1483 orig = pads = g_list_copy (element->pads);
1485 pad = GST_PAD (pads->data);
1487 if (GST_PAD_PEER (pad)) {
1488 GST_DEBUG (GST_CAT_REFCOUNTING, "disconnecting pad '%s'",
1489 GST_OBJECT_NAME (GST_OBJECT (GST_PAD (GST_PAD_PEER (pad)))));
1490 gst_pad_disconnect (pad, GST_PAD (GST_PAD_PEER (pad)));
1492 gst_element_remove_pad (element, pad);
1494 pads = g_list_next (pads);
1497 g_list_free (element->pads);
1498 element->pads = NULL;
1501 element->numsrcpads = 0;
1502 element->numsinkpads = 0;
1503 element->numpads = 0;
1504 g_mutex_free (element->state_mutex);
1505 g_cond_free (element->state_cond);
1507 G_OBJECT_CLASS (parent_class)->dispose (object);
1510 #ifndef GST_DISABLE_LOADSAVE
1512 * gst_element_save_thyself:
1513 * @element: GstElement to save
1514 * @parent: the xml parent node
1516 * Saves the element as part of the given XML structure
1518 * Returns: the new xml node
1521 gst_element_save_thyself (GstObject *object,
1525 GstElementClass *oclass;
1526 GParamSpec **specs, *spec;
1528 GValue value = { 0, };
1529 GstElement *element;
1531 g_return_val_if_fail (GST_IS_ELEMENT (object), parent);
1533 element = GST_ELEMENT (object);
1535 oclass = CLASS (element);
1537 xmlNewChild(parent, NULL, "name", GST_ELEMENT_NAME(element));
1539 if (oclass->elementfactory != NULL) {
1540 GstElementFactory *factory = (GstElementFactory *)oclass->elementfactory;
1542 xmlNewChild (parent, NULL, "type", GST_OBJECT_NAME (factory));
1543 xmlNewChild (parent, NULL, "version", factory->details->version);
1546 /* FIXME: what is this? */
1547 /* if (element->manager) */
1548 /* xmlNewChild(parent, NULL, "manager", GST_ELEMENT_NAME(element->manager)); */
1551 specs = g_object_class_list_properties (G_OBJECT_GET_CLASS (object), &nspecs);
1553 for (i=0; i<nspecs; i++) {
1555 if (spec->flags & G_PARAM_READABLE) {
1558 g_value_init(&value, G_PARAM_SPEC_VALUE_TYPE (spec));
1560 g_object_get_property (G_OBJECT (element), spec->name, &value);
1561 param = xmlNewChild (parent, NULL, "param", NULL);
1562 xmlNewChild (param, NULL, "name", spec->name);
1564 if (G_IS_PARAM_SPEC_STRING (spec))
1565 xmlNewChild (param, NULL, "value", g_value_dup_string (&value));
1566 else if (G_IS_PARAM_SPEC_ENUM (spec))
1567 xmlNewChild (param, NULL, "value", g_strdup_printf ("%d", g_value_get_enum (&value)));
1568 else if (G_IS_PARAM_SPEC_INT64 (spec))
1569 xmlNewChild (param, NULL, "value", g_strdup_printf ("%lld", g_value_get_int64 (&value)));
1571 xmlNewChild (param, NULL, "value", g_strdup_value_contents (&value));
1573 g_value_unset(&value);
1577 pads = GST_ELEMENT_PADS (element);
1580 GstPad *pad = GST_PAD (pads->data);
1581 /* figure out if it's a direct pad or a ghostpad */
1582 if (GST_ELEMENT (GST_OBJECT_PARENT (pad)) == element) {
1583 xmlNodePtr padtag = xmlNewChild (parent, NULL, "pad", NULL);
1584 gst_object_save_thyself (GST_OBJECT (pad), padtag);
1586 pads = g_list_next (pads);
1593 gst_element_restore_thyself (GstObject *object, xmlNodePtr self)
1595 xmlNodePtr children;
1596 GstElement *element;
1597 guchar *name = NULL;
1598 guchar *value = NULL;
1600 element = GST_ELEMENT (object);
1601 g_return_if_fail (element != NULL);
1604 children = self->xmlChildrenNode;
1606 if (!strcmp (children->name, "param")) {
1607 xmlNodePtr child = children->xmlChildrenNode;
1610 if (!strcmp (child->name, "name")) {
1611 name = xmlNodeGetContent (child);
1613 else if (!strcmp (child->name, "value")) {
1614 value = xmlNodeGetContent (child);
1616 child = child->next;
1618 /* FIXME: can this just be g_object_set ? */
1619 gst_util_set_object_arg ((GObject *)G_OBJECT (element), name, value);
1621 children = children->next;
1625 children = self->xmlChildrenNode;
1627 if (!strcmp (children->name, "pad")) {
1628 gst_pad_load_and_connect (children, GST_OBJECT (element));
1630 children = children->next;
1633 if (GST_OBJECT_CLASS(parent_class)->restore_thyself)
1634 (GST_OBJECT_CLASS(parent_class)->restore_thyself) (object, self);
1636 #endif /* GST_DISABLE_LOADSAVE */
1639 * gst_element_yield:
1640 * @element: Element to yield
1642 * Request a yield operation for the child. The scheduler will typically
1643 * give control to another element.
1646 gst_element_yield (GstElement *element)
1648 if (GST_ELEMENT_SCHED (element)) {
1649 gst_scheduler_yield (GST_ELEMENT_SCHED (element), element);
1654 * gst_element_interrupt:
1655 * @element: Element to interrupt
1657 * Request the scheduler of this element to interrupt the execution of
1658 * this element and scheduler another one.
1660 * Returns: a boolean indicating that the child should exit its chain/loop/get
1661 * function ASAP, depending on the scheduler implementation.
1664 gst_element_interrupt (GstElement *element)
1666 if (GST_ELEMENT_SCHED (element)) {
1667 return gst_scheduler_interrupt (GST_ELEMENT_SCHED (element), element);
1674 * gst_element_set_sched:
1675 * @element: Element to set manager of.
1676 * @sched: @GstScheduler to set.
1678 * Sets the scheduler of the element. For internal use only, unless you're
1679 * writing a new bin subclass.
1682 gst_element_set_sched (GstElement *element,
1683 GstScheduler *sched)
1685 g_return_if_fail (GST_IS_ELEMENT (element));
1687 GST_INFO_ELEMENT (GST_CAT_PARENTAGE, element, "setting scheduler to %p", sched);
1689 element->sched = sched;
1693 * gst_element_get_sched:
1694 * @element: Element to get manager of.
1696 * Returns the scheduler of the element.
1698 * Returns: Element's scheduler
1701 gst_element_get_sched (GstElement *element)
1703 g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
1705 return element->sched;
1709 * gst_element_set_loop_function:
1710 * @element: Element to set loop function of.
1711 * @loop: Pointer to loop function.
1713 * This sets the loop function for the element. The function pointed to
1714 * can deviate from the GstElementLoopFunction definition in type of
1717 * NOTE: in order for this to take effect, the current loop function *must*
1718 * exit. Assuming the loop function itself is the only one who will cause
1719 * a new loopfunc to be assigned, this should be no problem.
1722 gst_element_set_loop_function (GstElement *element,
1723 GstElementLoopFunction loop)
1725 g_return_if_fail (GST_IS_ELEMENT (element));
1727 /* set the loop function */
1728 element->loopfunc = loop;
1730 /* set the NEW_LOOPFUNC flag so everyone knows to go try again */
1731 GST_FLAG_SET (element, GST_ELEMENT_NEW_LOOPFUNC);
1735 * gst_element_set_eos:
1736 * @element: element to set to the EOS state
1738 * Perform the actions needed to bring the element in the EOS state.
1741 gst_element_set_eos (GstElement *element)
1743 g_return_if_fail (GST_IS_ELEMENT (element));
1745 GST_DEBUG (GST_CAT_EVENT, "setting EOS on element %s", GST_OBJECT_NAME (element));
1747 gst_element_set_state (element, GST_STATE_PAUSED);
1749 g_signal_emit (G_OBJECT (element), gst_element_signals[EOS], 0);
1754 * gst_element_statename:
1755 * @state: The state to get the name of
1757 * Gets a string representing the given state.
1759 * Returns: a string with the statename.
1762 gst_element_statename (GstElementState state)
1765 #ifdef GST_DEBUG_COLOR
1766 case GST_STATE_VOID_PENDING: return "NONE_PENDING";break;
1767 case GST_STATE_NULL: return "\033[01;37mNULL\033[00m";break;
1768 case GST_STATE_READY: return "\033[01;31mREADY\033[00m";break;
1769 case GST_STATE_PLAYING: return "\033[01;32mPLAYING\033[00m";break;
1770 case GST_STATE_PAUSED: return "\033[01;33mPAUSED\033[00m";break;
1771 default: return g_strdup_printf ("\033[01;37;41mUNKNOWN!\033[00m(%d)", state);
1773 case GST_STATE_VOID_PENDING: return "NONE_PENDING";break;
1774 case GST_STATE_NULL: return "NULL";break;
1775 case GST_STATE_READY: return "READY";break;
1776 case GST_STATE_PLAYING: return "PLAYING";break;
1777 case GST_STATE_PAUSED: return "PAUSED";break;
1778 default: return "UNKNOWN!";
1785 gst_element_populate_std_props (GObjectClass * klass,
1786 const char *prop_name, guint arg_id, GParamFlags flags)
1788 GQuark prop_id = g_quark_from_string (prop_name);
1791 static GQuark fd_id = 0;
1792 static GQuark blocksize_id;
1793 static GQuark bytesperread_id;
1794 static GQuark dump_id;
1795 static GQuark filesize_id;
1796 static GQuark mmapsize_id;
1797 static GQuark location_id;
1798 static GQuark offset_id;
1799 static GQuark silent_id;
1800 static GQuark touch_id;
1803 fd_id = g_quark_from_static_string ("fd");
1804 blocksize_id = g_quark_from_static_string ("blocksize");
1805 bytesperread_id = g_quark_from_static_string ("bytesperread");
1806 dump_id = g_quark_from_static_string ("dump");
1807 filesize_id = g_quark_from_static_string ("filesize");
1808 mmapsize_id = g_quark_from_static_string ("mmapsize");
1809 location_id = g_quark_from_static_string ("location");
1810 offset_id = g_quark_from_static_string ("offset");
1811 silent_id = g_quark_from_static_string ("silent");
1812 touch_id = g_quark_from_static_string ("touch");
1815 if (prop_id == fd_id) {
1816 pspec = g_param_spec_int ("fd", "File-descriptor",
1817 "File-descriptor for the file being read",
1818 0, G_MAXINT, 0, flags);
1820 else if (prop_id == blocksize_id) {
1821 pspec = g_param_spec_ulong ("blocksize", "Block Size",
1822 "Block size to read per buffer",
1823 0, G_MAXULONG, 4096, flags);
1826 else if (prop_id == bytesperread_id) {
1827 pspec = g_param_spec_int ("bytesperread", "bytesperread",
1829 G_MININT, G_MAXINT, 0, flags);
1832 else if (prop_id == dump_id) {
1833 pspec = g_param_spec_boolean ("dump", "dump", "dump", FALSE, flags);
1836 else if (prop_id == filesize_id) {
1837 pspec = g_param_spec_int64 ("filesize", "File Size",
1838 "Size of the file being read",
1839 0, G_MAXINT64, 0, flags);
1842 else if (prop_id == mmapsize_id) {
1843 pspec = g_param_spec_ulong ("mmapsize", "mmap() Block Size",
1844 "Size in bytes of mmap()d regions",
1845 0, G_MAXULONG, 4 * 1048576, flags);
1848 else if (prop_id == location_id) {
1849 pspec = g_param_spec_string ("location", "File Location",
1850 "Location of the file to read",
1854 else if (prop_id == offset_id) {
1855 pspec = g_param_spec_int64 ("offset", "File Offset",
1856 "Byte offset of current read pointer",
1857 0, G_MAXINT64, 0, flags);
1860 else if (prop_id == silent_id) {
1861 pspec = g_param_spec_boolean ("silent", "silent", "silent",
1865 else if (prop_id == touch_id) {
1866 pspec = g_param_spec_boolean ("touch", "Touch read data",
1867 "Touch data to force disk read before "
1868 "push ()", TRUE, flags);
1871 g_warning ("Unknown - 'standard' property '%s' id %d from klass %s",
1872 prop_name, arg_id, g_type_name (G_OBJECT_CLASS_TYPE (klass)));
1877 g_object_class_install_property (klass, arg_id, pspec);
1882 * gst_element_class_install_std_props:
1883 * @klass: the class to add the properties to
1884 * @first_name: the first in a NULL terminated
1885 * 'name', 'id', 'flags' triplet list.
1886 * @...: the triplet list
1888 * Add a list of standardized properties with types to the @klass.
1889 * the id is for the property switch in your get_prop method, and
1890 * the flags determine readability / writeability.
1893 gst_element_class_install_std_props (GstElementClass * klass, const char *first_name, ...)
1899 g_return_if_fail (GST_IS_ELEMENT_CLASS (klass));
1901 va_start (args, first_name);
1906 int arg_id = va_arg (args, int);
1907 int flags = va_arg (args, int);
1909 gst_element_populate_std_props ((GObjectClass *) klass, name, arg_id, flags);
1911 name = va_arg (args, char *);
1918 * gst_element_get_managing_bin:
1919 * @element: the element in question
1921 * Get the managing bin (a pipeline or a thread, for example) of an element.
1923 * Returns: the bin, or NULL on failure
1926 gst_element_get_managing_bin (GstElement *element)
1930 g_return_val_if_fail (element != NULL, NULL);
1932 bin = GST_BIN (gst_object_get_parent (GST_OBJECT_CAST (element)));
1934 while (bin && !GST_FLAG_IS_SET (GST_OBJECT_CAST (bin), GST_BIN_FLAG_MANAGER))
1935 bin = GST_BIN (gst_object_get_parent (GST_OBJECT_CAST (bin)));