2000-01-30 09:03:00 +00:00
|
|
|
/* Gnome-Streamer
|
|
|
|
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2000-08-21 21:20:38 +00:00
|
|
|
//#define DEBUG_ENABLED
|
2000-01-30 09:03:00 +00:00
|
|
|
#include <gst/gst.h>
|
|
|
|
|
2000-08-18 20:35:48 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2000-08-21 21:20:38 +00:00
|
|
|
|
2000-01-30 09:03:00 +00:00
|
|
|
GstElementDetails gst_bin_details = {
|
|
|
|
"Generic bin",
|
|
|
|
"Bin",
|
|
|
|
"Simple container object",
|
|
|
|
VERSION,
|
|
|
|
"Erik Walthinsen <omega@cse.ogi.edu>",
|
|
|
|
"(C) 1999",
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2000-11-04 18:54:07 +00:00
|
|
|
static void gst_bin_real_destroy (GtkObject *object);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-11-04 18:54:07 +00:00
|
|
|
static GstElementStateReturn gst_bin_change_state (GstElement *element);
|
|
|
|
static GstElementStateReturn gst_bin_change_state_norecurse (GstBin *bin);
|
|
|
|
static gboolean gst_bin_change_state_type (GstBin *bin,
|
|
|
|
GstElementState state,
|
|
|
|
GtkType type);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-11-04 18:54:07 +00:00
|
|
|
static void gst_bin_create_plan_func (GstBin *bin);
|
|
|
|
static void gst_bin_iterate_func (GstBin *bin);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-11-04 18:54:07 +00:00
|
|
|
static xmlNodePtr gst_bin_save_thyself (GstElement *element, xmlNodePtr parent);
|
|
|
|
static void gst_bin_restore_thyself (GstElement *element, xmlNodePtr parent,
|
|
|
|
GHashTable *elements);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
|
|
|
/* Bin signals and args */
|
|
|
|
enum {
|
|
|
|
OBJECT_ADDED,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
ARG_0,
|
|
|
|
/* FILL ME */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2000-11-04 18:54:07 +00:00
|
|
|
static void gst_bin_class_init (GstBinClass *klass);
|
|
|
|
static void gst_bin_init (GstBin *bin);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
static GstElementClass *parent_class = NULL;
|
|
|
|
static guint gst_bin_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
|
|
|
GtkType
|
2000-11-04 18:54:07 +00:00
|
|
|
gst_bin_get_type (void)
|
|
|
|
{
|
2000-01-30 09:03:00 +00:00
|
|
|
static GtkType bin_type = 0;
|
|
|
|
|
|
|
|
if (!bin_type) {
|
|
|
|
static const GtkTypeInfo bin_info = {
|
|
|
|
"GstBin",
|
|
|
|
sizeof(GstBin),
|
|
|
|
sizeof(GstBinClass),
|
|
|
|
(GtkClassInitFunc)gst_bin_class_init,
|
|
|
|
(GtkObjectInitFunc)gst_bin_init,
|
|
|
|
(GtkArgSetFunc)NULL,
|
|
|
|
(GtkArgGetFunc)NULL,
|
|
|
|
(GtkClassInitFunc)NULL,
|
|
|
|
};
|
2000-11-04 18:54:07 +00:00
|
|
|
bin_type = gtk_type_unique (GST_TYPE_ELEMENT, &bin_info);
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
return bin_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-11-04 18:54:07 +00:00
|
|
|
gst_bin_class_init (GstBinClass *klass)
|
|
|
|
{
|
2000-01-30 09:03:00 +00:00
|
|
|
GtkObjectClass *gtkobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
|
|
|
gtkobject_class = (GtkObjectClass*)klass;
|
|
|
|
gstelement_class = (GstElementClass*)klass;
|
|
|
|
|
2000-11-04 18:54:07 +00:00
|
|
|
parent_class = gtk_type_class (GST_TYPE_ELEMENT);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
|
|
|
gst_bin_signals[OBJECT_ADDED] =
|
2000-11-04 18:54:07 +00:00
|
|
|
gtk_signal_new ("object_added", GTK_RUN_FIRST, gtkobject_class->type,
|
|
|
|
GTK_SIGNAL_OFFSET (GstBinClass, object_added),
|
|
|
|
gtk_marshal_NONE__POINTER, GTK_TYPE_NONE, 1,
|
|
|
|
GST_TYPE_ELEMENT);
|
|
|
|
gtk_object_class_add_signals (gtkobject_class, gst_bin_signals, LAST_SIGNAL);
|
|
|
|
|
|
|
|
klass->change_state_type = gst_bin_change_state_type;
|
|
|
|
klass->create_plan = gst_bin_create_plan_func;
|
|
|
|
klass->iterate = gst_bin_iterate_func;
|
|
|
|
|
|
|
|
gstelement_class->change_state = gst_bin_change_state;
|
|
|
|
gstelement_class->save_thyself = gst_bin_save_thyself;
|
|
|
|
gstelement_class->restore_thyself = gst_bin_restore_thyself;
|
|
|
|
gstelement_class->elementfactory = gst_elementfactory_find("bin");
|
|
|
|
|
|
|
|
gtkobject_class->destroy = gst_bin_real_destroy;
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
|
2000-11-04 18:54:07 +00:00
|
|
|
static void
|
|
|
|
gst_bin_init (GstBin *bin)
|
|
|
|
{
|
2000-01-30 09:03:00 +00:00
|
|
|
bin->numchildren = 0;
|
|
|
|
bin->children = NULL;
|
2000-08-14 10:55:35 +00:00
|
|
|
bin->use_cothreads = TRUE;
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_bin_new:
|
|
|
|
* @name: name of new bin
|
|
|
|
*
|
|
|
|
* Create a new bin with given name.
|
|
|
|
*
|
|
|
|
* Returns: new bin
|
|
|
|
*/
|
2000-11-04 18:54:07 +00:00
|
|
|
GstElement*
|
|
|
|
gst_bin_new (gchar *name)
|
|
|
|
{
|
|
|
|
GstElement *bin = GST_ELEMENT (gtk_type_new (GST_TYPE_BIN));
|
|
|
|
gst_element_set_name (GST_ELEMENT (bin), name);
|
2000-01-30 09:03:00 +00:00
|
|
|
return bin;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_bin_add:
|
|
|
|
* @bin: #GstBin to add element to
|
|
|
|
* @element: #GstElement to add to bin
|
|
|
|
*
|
|
|
|
* Add the given element to the bin. Set the elements parent, and thus
|
|
|
|
* add a reference.
|
|
|
|
*/
|
2000-11-04 18:54:07 +00:00
|
|
|
void
|
|
|
|
gst_bin_add (GstBin *bin,
|
|
|
|
GstElement *element)
|
|
|
|
{
|
|
|
|
g_return_if_fail (bin != NULL);
|
|
|
|
g_return_if_fail (GST_IS_BIN (bin));
|
|
|
|
g_return_if_fail (element != NULL);
|
|
|
|
g_return_if_fail (GST_IS_ELEMENT (element));
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-07-17 17:14:15 +00:00
|
|
|
// must be NULL or PAUSED state in order to modify bin
|
2000-11-04 18:54:07 +00:00
|
|
|
g_return_if_fail ((GST_STATE (bin) == GST_STATE_NULL) ||
|
|
|
|
(GST_STATE (bin) == GST_STATE_PAUSED));
|
2000-07-17 17:14:15 +00:00
|
|
|
|
2000-11-04 18:54:07 +00:00
|
|
|
bin->children = g_list_append (bin->children, element);
|
2000-01-30 09:03:00 +00:00
|
|
|
bin->numchildren++;
|
2000-11-04 18:54:07 +00:00
|
|
|
gst_object_set_parent (GST_OBJECT (element), GST_OBJECT (bin));
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-07-17 17:14:15 +00:00
|
|
|
/* we know we have at least one child, we just added one... */
|
|
|
|
// if (GST_STATE(element) < GST_STATE_READY)
|
|
|
|
// gst_bin_change_state_norecurse(bin,GST_STATE_READY);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-11-04 18:54:07 +00:00
|
|
|
gtk_signal_emit (GTK_OBJECT (bin), gst_bin_signals[OBJECT_ADDED], element);
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_bin_remove:
|
2000-07-17 17:14:15 +00:00
|
|
|
* @bin: #GstBin to remove element from
|
2000-01-30 09:03:00 +00:00
|
|
|
* @element: #GstElement to remove
|
|
|
|
*
|
|
|
|
* Remove the element from its associated bin, unparenting as well.
|
|
|
|
*/
|
2000-11-04 18:54:07 +00:00
|
|
|
void
|
|
|
|
gst_bin_remove (GstBin *bin,
|
|
|
|
GstElement *element)
|
|
|
|
{
|
|
|
|
g_return_if_fail (bin != NULL);
|
|
|
|
g_return_if_fail (GST_IS_BIN (bin));
|
|
|
|
g_return_if_fail (element != NULL);
|
|
|
|
g_return_if_fail (GST_IS_ELEMENT (element));
|
|
|
|
g_return_if_fail (bin->children != NULL);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-07-17 17:14:15 +00:00
|
|
|
// must be NULL or PAUSED state in order to modify bin
|
2000-11-04 18:54:07 +00:00
|
|
|
g_return_if_fail ((GST_STATE (bin) == GST_STATE_NULL) ||
|
|
|
|
(GST_STATE (bin) == GST_STATE_PAUSED));
|
2000-07-17 17:14:15 +00:00
|
|
|
|
2000-11-04 18:54:07 +00:00
|
|
|
gst_object_unparent (GST_OBJECT (element));
|
|
|
|
bin->children = g_list_remove (bin->children, element);
|
2000-01-30 09:03:00 +00:00
|
|
|
bin->numchildren--;
|
2000-07-17 17:14:15 +00:00
|
|
|
|
|
|
|
/* if we're down to zero children, force state to NULL */
|
|
|
|
if (bin->numchildren == 0)
|
2000-11-04 18:54:07 +00:00
|
|
|
gst_element_set_state (GST_ELEMENT (bin), GST_STATE_NULL);
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-11-04 18:54:07 +00:00
|
|
|
static GstElementStateReturn
|
|
|
|
gst_bin_change_state (GstElement *element)
|
|
|
|
{
|
2000-01-30 09:03:00 +00:00
|
|
|
GstBin *bin;
|
|
|
|
GList *children;
|
|
|
|
GstElement *child;
|
|
|
|
|
2000-11-04 18:54:07 +00:00
|
|
|
g_return_val_if_fail (GST_IS_BIN (element), GST_STATE_FAILURE);
|
|
|
|
|
|
|
|
bin = GST_BIN (element);
|
2000-07-17 17:14:15 +00:00
|
|
|
|
|
|
|
g_print("gst_bin_change_state(\"%s\"): currently %d(%s), %d(%s) pending\n",
|
2000-11-04 18:54:07 +00:00
|
|
|
gst_element_get_name (element), GST_STATE (element),
|
|
|
|
_gst_print_statename (GST_STATE (element)), GST_STATE_PENDING (element),
|
|
|
|
_gst_print_statename (GST_STATE_PENDING (element)));
|
2000-07-17 17:14:15 +00:00
|
|
|
|
|
|
|
// g_return_val_if_fail(bin->numchildren != 0, GST_STATE_FAILURE);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
|
|
|
// g_print("-->\n");
|
|
|
|
children = bin->children;
|
|
|
|
while (children) {
|
2000-11-04 18:54:07 +00:00
|
|
|
child = GST_ELEMENT (children->data);
|
2000-07-17 17:14:15 +00:00
|
|
|
g_print("gst_bin_change_state: setting state on '%s'\n",
|
2000-11-04 18:54:07 +00:00
|
|
|
gst_element_get_name (child));
|
|
|
|
switch (gst_element_set_state (child, GST_STATE_PENDING (element))) {
|
2000-07-17 17:14:15 +00:00
|
|
|
case GST_STATE_FAILURE:
|
2000-11-04 18:54:07 +00:00
|
|
|
GST_STATE_PENDING (element) = GST_STATE_NONE_PENDING;
|
|
|
|
g_print("gstbin: child '%s' failed to go to state %d(%s)\n", gst_element_get_name (child),
|
|
|
|
GST_STATE_PENDING (element), _gst_print_statename (GST_STATE_PENDING (element)));
|
2000-07-17 17:14:15 +00:00
|
|
|
return GST_STATE_FAILURE;
|
|
|
|
break;
|
|
|
|
case GST_STATE_ASYNC:
|
2000-11-04 18:54:07 +00:00
|
|
|
g_print("gstbin: child '%s' is changing state asynchronously\n", gst_element_get_name (child));
|
2000-07-17 17:14:15 +00:00
|
|
|
break;
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
// g_print("\n");
|
2000-11-04 18:54:07 +00:00
|
|
|
children = g_list_next (children);
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
// g_print("<-- \"%s\"\n",gst_object_get_name(GST_OBJECT(bin)));
|
|
|
|
|
2000-11-23 08:13:43 +00:00
|
|
|
if (GST_STATE_PENDING (element) == GST_STATE_READY) {
|
|
|
|
GstObject *parent;
|
|
|
|
|
|
|
|
parent = gst_object_get_parent (GST_OBJECT (element));
|
|
|
|
|
|
|
|
if (!parent || !GST_IS_BIN (parent))
|
|
|
|
gst_bin_create_plan (bin);
|
|
|
|
}
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-11-04 18:54:07 +00:00
|
|
|
return gst_bin_change_state_norecurse (bin);
|
2000-07-17 17:14:15 +00:00
|
|
|
}
|
2000-01-30 09:03:00 +00:00
|
|
|
|
|
|
|
|
2000-11-04 18:54:07 +00:00
|
|
|
static GstElementStateReturn
|
|
|
|
gst_bin_change_state_norecurse (GstBin *bin)
|
|
|
|
{
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-11-04 18:54:07 +00:00
|
|
|
if (GST_ELEMENT_CLASS (parent_class)->change_state)
|
|
|
|
return GST_ELEMENT_CLASS (parent_class)->change_state (GST_ELEMENT (bin));
|
2000-07-17 17:14:15 +00:00
|
|
|
else
|
|
|
|
return GST_STATE_FAILURE;
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
|
2000-11-04 18:54:07 +00:00
|
|
|
static gboolean
|
|
|
|
gst_bin_change_state_type(GstBin *bin,
|
|
|
|
GstElementState state,
|
|
|
|
GtkType type)
|
|
|
|
{
|
2000-01-30 09:03:00 +00:00
|
|
|
GList *children;
|
|
|
|
GstElement *child;
|
|
|
|
|
|
|
|
// g_print("gst_bin_change_state_type(\"%s\",%d,%d);\n",
|
|
|
|
// gst_object_get_name(GST_OBJECT(bin)),state,type);
|
|
|
|
|
2000-11-04 18:54:07 +00:00
|
|
|
g_return_val_if_fail (GST_IS_BIN (bin), FALSE);
|
|
|
|
g_return_val_if_fail (bin->numchildren != 0, FALSE);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
|
|
|
// g_print("-->\n");
|
|
|
|
children = bin->children;
|
|
|
|
while (children) {
|
2000-11-04 18:54:07 +00:00
|
|
|
child = GST_ELEMENT (children->data);
|
|
|
|
if (GST_IS_BIN (child)) {
|
|
|
|
if (!gst_bin_set_state_type (GST_BIN (child), state,type))
|
2000-01-30 09:03:00 +00:00
|
|
|
return FALSE;
|
2000-11-04 18:54:07 +00:00
|
|
|
} else if (GTK_CHECK_TYPE (child,type)) {
|
|
|
|
if (!gst_element_set_state (child,state))
|
2000-01-30 09:03:00 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
// g_print("\n");
|
2000-11-04 18:54:07 +00:00
|
|
|
children = g_list_next (children);
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
if (type == GST_TYPE_BIN)
|
2000-11-04 18:54:07 +00:00
|
|
|
gst_element_set_state (GST_ELEMENT (bin),state);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2000-09-14 20:31:03 +00:00
|
|
|
/**
|
|
|
|
* gst_bin_set_state_type:
|
|
|
|
* @bin: #GstBin to set the state
|
|
|
|
* @state: the new state to set the elements to
|
|
|
|
* @type: the type of elements to change
|
|
|
|
*
|
|
|
|
* Sets the state of only those objects of the given type.
|
|
|
|
*
|
|
|
|
* Returns: indication if the state change was successfull
|
|
|
|
*/
|
2000-11-04 18:54:07 +00:00
|
|
|
gboolean
|
|
|
|
gst_bin_set_state_type (GstBin *bin,
|
|
|
|
GstElementState state,
|
|
|
|
GtkType type)
|
|
|
|
{
|
2000-01-30 09:03:00 +00:00
|
|
|
GstBinClass *oclass;
|
|
|
|
|
2000-09-22 23:35:14 +00:00
|
|
|
DEBUG("gst_bin_set_state_type(\"%s\",%d,%d)\n",
|
2000-11-04 18:54:07 +00:00
|
|
|
gst_element_get_name (GST_ELEMENT (bin)), state,type);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-11-04 18:54:07 +00:00
|
|
|
g_return_val_if_fail (bin != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (GST_IS_BIN (bin), FALSE);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-11-04 18:54:07 +00:00
|
|
|
oclass = GST_BIN_CLASS (GTK_OBJECT (bin)->klass);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
|
|
|
if (oclass->change_state_type)
|
2000-11-04 18:54:07 +00:00
|
|
|
(oclass->change_state_type) (bin,state,type);
|
2000-09-24 14:29:49 +00:00
|
|
|
return TRUE;
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
|
2000-11-04 18:54:07 +00:00
|
|
|
static void
|
|
|
|
gst_bin_real_destroy (GtkObject *object)
|
|
|
|
{
|
|
|
|
GstBin *bin = GST_BIN (object);
|
2000-01-30 09:03:00 +00:00
|
|
|
GList *children;
|
|
|
|
GstElement *child;
|
|
|
|
|
2000-09-22 23:35:14 +00:00
|
|
|
DEBUG("in gst_bin_real_destroy()\n");
|
2000-01-30 09:03:00 +00:00
|
|
|
|
|
|
|
children = bin->children;
|
|
|
|
while (children) {
|
2000-11-04 18:54:07 +00:00
|
|
|
child = GST_ELEMENT (children->data);
|
|
|
|
gst_element_destroy (child);
|
|
|
|
children = g_list_next (children);
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
|
2000-11-04 18:54:07 +00:00
|
|
|
g_list_free (bin->children);
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
|
2000-03-27 19:53:43 +00:00
|
|
|
/**
|
|
|
|
* gst_bin_get_by_name:
|
|
|
|
* @bin: #Gstbin to search
|
|
|
|
* @name: the element name to search for
|
|
|
|
*
|
|
|
|
* get the element with the given name from this bin
|
|
|
|
*
|
|
|
|
* Returns: the element with the given name
|
|
|
|
*/
|
2000-11-04 18:54:07 +00:00
|
|
|
GstElement*
|
|
|
|
gst_bin_get_by_name (GstBin *bin,
|
|
|
|
gchar *name)
|
|
|
|
{
|
2000-01-30 09:03:00 +00:00
|
|
|
GList *children;
|
|
|
|
GstElement *child;
|
|
|
|
|
2000-11-04 18:54:07 +00:00
|
|
|
g_return_val_if_fail (bin != NULL, NULL);
|
|
|
|
g_return_val_if_fail (GST_IS_BIN (bin), NULL);
|
|
|
|
g_return_val_if_fail (name != NULL, NULL);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-11-04 18:54:07 +00:00
|
|
|
g_print("gstbin: lookup element \"%s\" in \"%s\"\n", name,
|
|
|
|
gst_element_get_name (GST_ELEMENT (bin)));
|
|
|
|
|
2000-01-30 09:03:00 +00:00
|
|
|
children = bin->children;
|
|
|
|
while (children) {
|
2000-11-04 18:54:07 +00:00
|
|
|
child = GST_ELEMENT (children->data);
|
|
|
|
if (!strcmp (child->name,name))
|
2000-01-30 09:03:00 +00:00
|
|
|
return child;
|
2000-11-04 18:54:07 +00:00
|
|
|
if (GST_IS_BIN (child)) {
|
|
|
|
GstElement *res = gst_bin_get_by_name (GST_BIN (child), name);
|
2000-09-27 19:33:10 +00:00
|
|
|
if (res)
|
|
|
|
return res;
|
|
|
|
}
|
2000-11-04 18:54:07 +00:00
|
|
|
children = g_list_next (children);
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2000-03-27 19:53:43 +00:00
|
|
|
/**
|
|
|
|
* gst_bin_get_list:
|
|
|
|
* @bin: #Gstbin to get the list from
|
|
|
|
*
|
|
|
|
* get the list of elements in this bin
|
|
|
|
*
|
|
|
|
* Returns: a GList of elements
|
|
|
|
*/
|
2000-11-04 18:54:07 +00:00
|
|
|
GList*
|
|
|
|
gst_bin_get_list (GstBin *bin)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (bin != NULL, NULL);
|
|
|
|
g_return_val_if_fail (GST_IS_BIN (bin), NULL);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
|
|
|
return bin->children;
|
|
|
|
}
|
|
|
|
|
2000-11-04 18:54:07 +00:00
|
|
|
static xmlNodePtr
|
|
|
|
gst_bin_save_thyself (GstElement *element,
|
|
|
|
xmlNodePtr parent)
|
|
|
|
{
|
|
|
|
GstBin *bin = GST_BIN (element);
|
2000-01-30 09:03:00 +00:00
|
|
|
xmlNodePtr childlist;
|
|
|
|
GList *children;
|
|
|
|
GstElement *child;
|
|
|
|
|
2000-11-04 18:54:07 +00:00
|
|
|
if (GST_ELEMENT_CLASS (parent_class)->save_thyself)
|
|
|
|
GST_ELEMENT_CLASS (parent_class)->save_thyself (GST_ELEMENT (bin), parent);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-11-04 18:54:07 +00:00
|
|
|
childlist = xmlNewChild (parent,NULL,"children",NULL);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
|
|
|
children = bin->children;
|
|
|
|
while (children) {
|
2000-11-04 18:54:07 +00:00
|
|
|
child = GST_ELEMENT (children->data);
|
|
|
|
gst_element_save_thyself (child, childlist);
|
|
|
|
children = g_list_next (children);
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
2000-09-27 19:33:10 +00:00
|
|
|
return childlist;
|
|
|
|
}
|
|
|
|
|
2000-11-04 18:54:07 +00:00
|
|
|
static void
|
|
|
|
gst_bin_restore_thyself (GstElement *element,
|
|
|
|
xmlNodePtr parent,
|
|
|
|
GHashTable *elements)
|
|
|
|
{
|
|
|
|
GstBin *bin = GST_BIN (element);
|
2000-09-27 19:33:10 +00:00
|
|
|
xmlNodePtr field = parent->childs;
|
|
|
|
xmlNodePtr childlist;
|
|
|
|
|
2000-11-04 18:54:07 +00:00
|
|
|
g_print("gstbin: restore \"%s\"\n", gst_element_get_name (element));
|
2000-09-27 19:33:10 +00:00
|
|
|
|
|
|
|
while (field) {
|
2000-11-04 18:54:07 +00:00
|
|
|
if (!strcmp (field->name, "children")) {
|
2000-09-27 19:33:10 +00:00
|
|
|
childlist = field->childs;
|
|
|
|
while (childlist) {
|
2000-11-04 18:54:07 +00:00
|
|
|
if (!strcmp (childlist->name, "element")) {
|
|
|
|
GstElement *element = gst_element_load_thyself (childlist, elements);
|
2000-09-27 19:33:10 +00:00
|
|
|
|
2000-11-04 18:54:07 +00:00
|
|
|
gst_bin_add (bin, element);
|
2000-09-27 19:33:10 +00:00
|
|
|
}
|
|
|
|
childlist = childlist->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
field = field->next;
|
|
|
|
}
|
|
|
|
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
|
2000-11-04 18:54:07 +00:00
|
|
|
void
|
|
|
|
gst_bin_use_cothreads (GstBin *bin,
|
|
|
|
gboolean enabled)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GST_IS_BIN (bin));
|
2000-08-14 10:55:35 +00:00
|
|
|
|
|
|
|
bin->use_cothreads = enabled;
|
|
|
|
}
|
|
|
|
|
2000-03-27 19:53:43 +00:00
|
|
|
/**
|
|
|
|
* gst_bin_iterate:
|
|
|
|
* @bin: #Gstbin to iterate
|
|
|
|
*
|
|
|
|
* iterates over the elements in this bin
|
|
|
|
*/
|
2000-11-04 18:54:07 +00:00
|
|
|
void
|
|
|
|
gst_bin_iterate (GstBin *bin)
|
|
|
|
{
|
2000-01-30 09:03:00 +00:00
|
|
|
GstBinClass *oclass;
|
|
|
|
|
2000-11-04 18:54:07 +00:00
|
|
|
oclass = GST_BIN_CLASS (GTK_OBJECT (bin)->klass);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-08-14 10:55:35 +00:00
|
|
|
DEBUG("gst_bin_iterate()\n");
|
2000-11-04 18:54:07 +00:00
|
|
|
|
2000-01-30 09:03:00 +00:00
|
|
|
if (oclass->iterate)
|
2000-11-04 18:54:07 +00:00
|
|
|
(oclass->iterate) (bin);
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
|
2000-09-14 20:31:03 +00:00
|
|
|
/**
|
|
|
|
* gst_bin_create_plan:
|
|
|
|
* @bin: #Gstbin to create the plan for
|
|
|
|
*
|
|
|
|
* let the bin figure out how to handle the plugins in it.
|
|
|
|
*/
|
2000-11-04 18:54:07 +00:00
|
|
|
void
|
|
|
|
gst_bin_create_plan (GstBin *bin)
|
|
|
|
{
|
2000-01-30 09:03:00 +00:00
|
|
|
GstBinClass *oclass;
|
|
|
|
|
2000-11-04 18:54:07 +00:00
|
|
|
oclass = GST_BIN_CLASS (GTK_OBJECT (bin)->klass);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
|
|
|
if (oclass->create_plan)
|
2000-11-04 18:54:07 +00:00
|
|
|
(oclass->create_plan) (bin);
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
|
2000-11-06 00:15:51 +00:00
|
|
|
typedef struct {
|
|
|
|
gulong offset;
|
|
|
|
gulong size;
|
|
|
|
} region_struct;
|
|
|
|
|
2000-11-04 18:54:07 +00:00
|
|
|
static int
|
|
|
|
gst_bin_loopfunc_wrapper (int argc,char *argv[])
|
|
|
|
{
|
|
|
|
GstElement *element = GST_ELEMENT (argv);
|
2000-07-17 17:14:15 +00:00
|
|
|
GList *pads;
|
|
|
|
GstPad *pad;
|
|
|
|
GstBuffer *buf;
|
2000-11-11 15:13:50 +00:00
|
|
|
G_GNUC_UNUSED const gchar *name = gst_element_get_name (element);
|
2000-07-17 17:14:15 +00:00
|
|
|
|
2000-09-22 23:35:14 +00:00
|
|
|
DEBUG("** gst_bin_loopfunc_wrapper(%d,\"%s\")\n",
|
2000-11-04 18:54:07 +00:00
|
|
|
argc,gst_element_get_name (element));
|
2000-07-17 17:14:15 +00:00
|
|
|
|
|
|
|
if (element->loopfunc != NULL) {
|
|
|
|
while (1) {
|
2000-09-22 23:35:14 +00:00
|
|
|
DEBUG("** gst_bin_loopfunc_wrapper(): element %s has loop function, calling it\n", name);
|
2000-11-04 18:54:07 +00:00
|
|
|
(element->loopfunc) (element);
|
2000-09-22 23:35:14 +00:00
|
|
|
DEBUG("** gst_bin_loopfunc_wrapper(): element %s ended loop function\n", name);
|
2000-07-17 17:14:15 +00:00
|
|
|
}
|
|
|
|
} else {
|
2000-09-22 23:35:14 +00:00
|
|
|
DEBUG("** gst_bin_loopfunc_wrapper(): element %s is chain-based, calling in infinite loop\n", name);
|
2000-11-04 18:54:07 +00:00
|
|
|
if (GST_IS_SRC (element)) {
|
2000-11-06 00:15:51 +00:00
|
|
|
region_struct *region = cothread_get_data (element->threadstate, "region");
|
|
|
|
if (region) {
|
|
|
|
gst_src_push_region (GST_SRC (element), region->offset, region->size);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
DEBUG("** gst_bin_loopfunc_wrapper(): calling push function of source %s\n", name);
|
|
|
|
gst_src_push (GST_SRC (element));
|
|
|
|
DEBUG("** gst_bin_loopfunc_wrapper(): calling push function of source %s done\n", name);
|
|
|
|
}
|
2000-11-04 18:54:07 +00:00
|
|
|
} else if (GST_IS_CONNECTION (element) && argc == 1) {
|
2000-09-22 23:35:14 +00:00
|
|
|
while (1) {
|
|
|
|
DEBUG("** gst_bin_loopfunc_wrapper(): calling push function of connection %s\n", name);
|
2000-11-04 18:54:07 +00:00
|
|
|
gst_connection_push (GST_CONNECTION (element));
|
2000-09-22 23:35:14 +00:00
|
|
|
DEBUG("** gst_bin_loopfunc_wrapper(): calling push function of connection %s done\n", name);
|
|
|
|
}
|
2000-07-17 17:14:15 +00:00
|
|
|
} else {
|
|
|
|
while (1) {
|
|
|
|
pads = element->pads;
|
|
|
|
while (pads) {
|
2000-11-04 18:54:07 +00:00
|
|
|
pad = GST_PAD (pads->data);
|
2000-07-17 17:14:15 +00:00
|
|
|
if (pad->direction == GST_PAD_SINK) {
|
2000-11-04 18:54:07 +00:00
|
|
|
DEBUG("** gst_bin_loopfunc_wrapper(): pulling a buffer from %s:%s\n", name, gst_pad_get_name (pad));
|
|
|
|
buf = gst_pad_pull (pad);
|
|
|
|
DEBUG("** gst_bin_loopfunc_wrapper(): calling chain function of %s:%s\n", name, gst_pad_get_name (pad));
|
|
|
|
(pad->chainfunc) (pad,buf);
|
|
|
|
DEBUG("** gst_bin_loopfunc_wrapper(): calling chain function of %s:%s done\n", name, gst_pad_get_name (pad));
|
2000-07-17 17:14:15 +00:00
|
|
|
}
|
2000-11-04 18:54:07 +00:00
|
|
|
pads = g_list_next (pads);
|
2000-07-17 17:14:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-09-16 10:58:23 +00:00
|
|
|
return 0;
|
2000-07-17 17:14:15 +00:00
|
|
|
}
|
|
|
|
|
2000-11-04 18:54:07 +00:00
|
|
|
static void
|
|
|
|
gst_bin_pullfunc_wrapper (GstPad *pad)
|
|
|
|
{
|
2000-09-16 10:58:23 +00:00
|
|
|
DEBUG("** in gst_bin_pullfunc_wrapper()============================= %s\n",
|
2000-11-04 18:54:07 +00:00
|
|
|
gst_element_get_name (GST_ELEMENT (pad->parent)));
|
|
|
|
cothread_switch (GST_ELEMENT (pad->parent)->threadstate);
|
2000-09-16 10:58:23 +00:00
|
|
|
DEBUG("** out gst_bin_pullfunc_wrapper()============================= %s\n",
|
2000-11-04 18:54:07 +00:00
|
|
|
gst_element_get_name (GST_ELEMENT (pad->parent)));
|
2000-07-17 17:14:15 +00:00
|
|
|
}
|
|
|
|
|
2000-11-06 00:15:51 +00:00
|
|
|
static void
|
|
|
|
gst_bin_pullregionfunc_wrapper (GstPad *pad,
|
|
|
|
gulong offset,
|
|
|
|
gulong size)
|
|
|
|
{
|
|
|
|
region_struct region;
|
|
|
|
|
|
|
|
region.offset = offset;
|
|
|
|
region.size = size;
|
|
|
|
|
|
|
|
DEBUG("** in gst_bin_pullregionfunc_wrapper()============================= %s\n",
|
|
|
|
gst_element_get_name (GST_ELEMENT (pad->parent)));
|
|
|
|
cothread_set_data (GST_ELEMENT (pad->parent)->threadstate, "region", ®ion);
|
|
|
|
cothread_switch (GST_ELEMENT (pad->parent)->threadstate);
|
|
|
|
cothread_set_data (GST_ELEMENT (pad->parent)->threadstate, "region", NULL);
|
|
|
|
DEBUG("** out gst_bin_pullregionfunc_wrapper()============================= %s\n",
|
|
|
|
gst_element_get_name (GST_ELEMENT (pad->parent)));
|
|
|
|
}
|
|
|
|
|
2000-11-04 18:54:07 +00:00
|
|
|
static void
|
|
|
|
gst_bin_pushfunc_wrapper (GstPad *pad)
|
|
|
|
{
|
2000-09-16 10:58:23 +00:00
|
|
|
DEBUG("** in gst_bin_pushfunc_wrapper()============================= %s\n",
|
2000-11-04 18:54:07 +00:00
|
|
|
gst_element_get_name (GST_ELEMENT (pad->parent)));
|
|
|
|
cothread_switch (GST_ELEMENT (pad->parent)->threadstate);
|
2000-09-16 10:58:23 +00:00
|
|
|
DEBUG("** out gst_bin_pushfunc_wrapper()============================= %s\n",
|
2000-11-04 18:54:07 +00:00
|
|
|
gst_element_get_name (GST_ELEMENT (pad->parent)));
|
2000-07-17 17:14:15 +00:00
|
|
|
}
|
|
|
|
|
2000-11-04 18:54:07 +00:00
|
|
|
static void
|
|
|
|
gst_bin_create_plan_func (GstBin *bin)
|
|
|
|
{
|
2000-07-17 17:14:15 +00:00
|
|
|
GList *elements;
|
|
|
|
GstElement *element;
|
|
|
|
int sink_pads;
|
|
|
|
GList *pads;
|
2000-09-22 23:35:14 +00:00
|
|
|
GstPad *pad, *opad, *peer;
|
2000-07-17 17:14:15 +00:00
|
|
|
GstElement *outside;
|
|
|
|
|
2000-11-04 18:54:07 +00:00
|
|
|
g_print("gstbin: creating plan for bin \"%s\"\n", gst_element_get_name (GST_ELEMENT (bin)));
|
2000-07-17 17:14:15 +00:00
|
|
|
|
|
|
|
// first loop through all children to see if we need cothreads
|
|
|
|
// we break immediately when we find we need to, why keep searching?
|
|
|
|
elements = bin->children;
|
|
|
|
while (elements) {
|
2000-11-04 18:54:07 +00:00
|
|
|
element = GST_ELEMENT (elements->data);
|
|
|
|
|
|
|
|
g_print("gstbin: found element \"%s\" in bin \"%s\"\n",
|
|
|
|
gst_element_get_name (element),
|
|
|
|
gst_element_get_name (GST_ELEMENT (bin)));
|
|
|
|
|
2000-07-17 17:14:15 +00:00
|
|
|
// if it's a loop-based element, use cothreads
|
|
|
|
if (element->loopfunc != NULL) {
|
2000-11-04 18:54:07 +00:00
|
|
|
g_print("gstbin: loop based element \"%s\" in bin \"%s\"\n",
|
|
|
|
gst_element_get_name (element),
|
|
|
|
gst_element_get_name (GST_ELEMENT (bin)));
|
|
|
|
|
2000-07-17 17:14:15 +00:00
|
|
|
bin->need_cothreads = TRUE;
|
2000-09-24 14:29:49 +00:00
|
|
|
break;
|
2000-07-17 17:14:15 +00:00
|
|
|
}
|
|
|
|
// if it's a complex element, use cothreads
|
2000-11-04 18:54:07 +00:00
|
|
|
else if (GST_ELEMENT_IS_MULTI_IN (element)) {
|
|
|
|
g_print("gstbin: complex element \"%s\" in bin \"%s\"\n",
|
|
|
|
gst_element_get_name (element),
|
|
|
|
gst_element_get_name (GST_ELEMENT (bin)));
|
|
|
|
|
2000-07-17 17:14:15 +00:00
|
|
|
bin->need_cothreads = TRUE;
|
2000-09-24 14:29:49 +00:00
|
|
|
break;
|
2000-07-17 17:14:15 +00:00
|
|
|
}
|
|
|
|
// if it has more than one input pad, use cothreads
|
|
|
|
sink_pads = 0;
|
2000-11-04 18:54:07 +00:00
|
|
|
pads = gst_element_get_pad_list (element);
|
2000-07-17 17:14:15 +00:00
|
|
|
while (pads) {
|
2000-11-04 18:54:07 +00:00
|
|
|
pad = GST_PAD (pads->data);
|
2000-07-17 17:14:15 +00:00
|
|
|
if (pad->direction == GST_PAD_SINK)
|
|
|
|
sink_pads++;
|
2000-11-04 18:54:07 +00:00
|
|
|
pads = g_list_next (pads);
|
2000-07-17 17:14:15 +00:00
|
|
|
}
|
|
|
|
if (sink_pads > 1) {
|
2000-11-04 18:54:07 +00:00
|
|
|
g_print("gstbin: more than 1 sinkpad for element \"%s\" in bin \"%s\"\n",
|
|
|
|
gst_element_get_name (element),
|
|
|
|
gst_element_get_name (GST_ELEMENT (bin)));
|
|
|
|
|
2000-07-17 17:14:15 +00:00
|
|
|
bin->need_cothreads = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2000-11-04 18:54:07 +00:00
|
|
|
elements = g_list_next (elements);
|
2000-07-17 17:14:15 +00:00
|
|
|
}
|
|
|
|
|
2000-08-14 10:55:35 +00:00
|
|
|
// FIXME
|
|
|
|
bin->need_cothreads &= bin->use_cothreads;
|
|
|
|
|
2000-09-22 23:35:14 +00:00
|
|
|
// clear previous plan state
|
2000-11-04 18:54:07 +00:00
|
|
|
g_list_free (bin->entries);
|
2000-09-22 23:35:14 +00:00
|
|
|
bin->entries = NULL;
|
|
|
|
bin->numentries = 0;
|
|
|
|
|
2000-07-17 17:14:15 +00:00
|
|
|
if (bin->need_cothreads) {
|
2000-08-14 10:55:35 +00:00
|
|
|
g_print("gstbin: need cothreads\n");
|
2000-07-17 17:14:15 +00:00
|
|
|
|
|
|
|
// first create thread context
|
|
|
|
if (bin->threadcontext == NULL) {
|
2000-11-04 18:54:07 +00:00
|
|
|
bin->threadcontext = cothread_init ();
|
2000-08-14 10:55:35 +00:00
|
|
|
g_print("gstbin: initialized cothread context\n");
|
2000-07-17 17:14:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// walk through all the children
|
|
|
|
elements = bin->children;
|
|
|
|
while (elements) {
|
2000-11-04 18:54:07 +00:00
|
|
|
element = GST_ELEMENT (elements->data);
|
2000-07-17 17:14:15 +00:00
|
|
|
|
|
|
|
// start by creating thread state for the element
|
|
|
|
if (element->threadstate == NULL) {
|
2000-11-04 18:54:07 +00:00
|
|
|
element->threadstate = cothread_create (bin->threadcontext);
|
|
|
|
cothread_setfunc (element->threadstate, gst_bin_loopfunc_wrapper,
|
|
|
|
0, (char **)element);
|
2000-07-17 17:14:15 +00:00
|
|
|
}
|
2000-11-04 18:54:07 +00:00
|
|
|
if (GST_IS_BIN (element)) {
|
|
|
|
gst_bin_create_plan (GST_BIN (element));
|
2000-11-01 22:11:48 +00:00
|
|
|
}
|
|
|
|
|
2000-11-04 18:54:07 +00:00
|
|
|
if (GST_IS_SRC (element)) {
|
|
|
|
g_print("gstbin: adding '%s' as entry point\n",gst_element_get_name (element));
|
|
|
|
bin->entries = g_list_prepend (bin->entries,element);
|
2000-09-24 14:29:49 +00:00
|
|
|
bin->numentries++;
|
|
|
|
}
|
2000-07-17 17:14:15 +00:00
|
|
|
|
2000-11-04 18:54:07 +00:00
|
|
|
pads = gst_element_get_pad_list (element);
|
2000-07-17 17:14:15 +00:00
|
|
|
while (pads) {
|
|
|
|
pad = GST_PAD(pads->data);
|
2000-09-22 23:35:14 +00:00
|
|
|
g_print("gstbin: setting push&pull handlers for %s:%s\n",
|
2000-11-04 18:54:07 +00:00
|
|
|
gst_element_get_name (element), gst_pad_get_name (pad));
|
2000-09-22 23:35:14 +00:00
|
|
|
|
|
|
|
// an internal connection will push outside this bin.
|
2000-11-04 18:54:07 +00:00
|
|
|
if (!GST_IS_CONNECTION (element)) {
|
2000-07-17 17:14:15 +00:00
|
|
|
pad->pushfunc = gst_bin_pushfunc_wrapper;
|
2000-09-22 23:35:14 +00:00
|
|
|
}
|
|
|
|
pad->pullfunc = gst_bin_pullfunc_wrapper;
|
2000-11-06 00:15:51 +00:00
|
|
|
pad->pullregionfunc = gst_bin_pullregionfunc_wrapper;
|
2000-09-22 23:35:14 +00:00
|
|
|
|
|
|
|
/* we only worry about sink pads */
|
2000-11-04 18:54:07 +00:00
|
|
|
if (gst_pad_get_direction (pad) == GST_PAD_SINK) {
|
2000-09-22 23:35:14 +00:00
|
|
|
/* get the pad's peer */
|
2000-11-04 18:54:07 +00:00
|
|
|
peer = gst_pad_get_peer (pad);
|
2000-09-22 23:35:14 +00:00
|
|
|
if (!peer) break;
|
|
|
|
/* get the parent of the peer of the pad */
|
2000-11-04 18:54:07 +00:00
|
|
|
outside = GST_ELEMENT (gst_pad_get_parent (peer));
|
2000-09-22 23:35:14 +00:00
|
|
|
if (!outside) break;
|
|
|
|
/* if it's a connection and it's not ours... */
|
2000-11-04 18:54:07 +00:00
|
|
|
if (GST_IS_CONNECTION (outside) &&
|
|
|
|
(gst_object_get_parent (GST_OBJECT (outside)) != GST_OBJECT (bin))) {
|
|
|
|
GList *connection_pads = gst_element_get_pad_list (outside);
|
2000-09-22 23:35:14 +00:00
|
|
|
while (connection_pads) {
|
2000-11-04 18:54:07 +00:00
|
|
|
opad = GST_PAD (connection_pads->data);
|
|
|
|
if (gst_pad_get_direction (opad) == GST_PAD_SRC) {
|
2000-09-24 14:29:49 +00:00
|
|
|
g_print("gstbin: setting push&pull handlers for %s:%s SRC connection %p %p\n",
|
2000-11-04 18:54:07 +00:00
|
|
|
gst_element_get_name (outside),gst_pad_get_name (opad), opad, opad->pullfunc);
|
2000-09-24 14:29:49 +00:00
|
|
|
|
2000-09-22 23:35:14 +00:00
|
|
|
opad->pushfunc = gst_bin_pushfunc_wrapper;
|
|
|
|
opad->pullfunc = gst_bin_pullfunc_wrapper;
|
2000-11-06 00:15:51 +00:00
|
|
|
opad->pullregionfunc = gst_bin_pullregionfunc_wrapper;
|
2000-09-24 14:29:49 +00:00
|
|
|
|
2000-09-22 23:35:14 +00:00
|
|
|
if (outside->threadstate == NULL) {
|
2000-11-04 18:54:07 +00:00
|
|
|
outside->threadstate = cothread_create (bin->threadcontext);
|
|
|
|
cothread_setfunc (outside->threadstate, gst_bin_loopfunc_wrapper,
|
|
|
|
1, (char **)outside);
|
2000-09-22 23:35:14 +00:00
|
|
|
}
|
|
|
|
}
|
2000-11-04 18:54:07 +00:00
|
|
|
connection_pads = g_list_next (connection_pads);
|
2000-09-22 23:35:14 +00:00
|
|
|
}
|
|
|
|
gst_info("gstbin: element \"%s\" is the external source Connection "
|
|
|
|
"for internal element \"%s\"\n",
|
2000-11-04 18:54:07 +00:00
|
|
|
gst_element_get_name (GST_ELEMENT (outside)),
|
|
|
|
gst_element_get_name (GST_ELEMENT (element)));
|
|
|
|
bin->entries = g_list_prepend (bin->entries,outside);
|
2000-09-22 23:35:14 +00:00
|
|
|
bin->numentries++;
|
|
|
|
}
|
|
|
|
}
|
2000-11-04 18:54:07 +00:00
|
|
|
pads = g_list_next (pads);
|
2000-07-17 17:14:15 +00:00
|
|
|
}
|
2000-11-04 18:54:07 +00:00
|
|
|
elements = g_list_next (elements);
|
2000-07-17 17:14:15 +00:00
|
|
|
}
|
|
|
|
} else {
|
2000-08-14 10:55:35 +00:00
|
|
|
g_print("gstbin: don't need cothreads, looking for entry points\n");
|
2000-07-17 17:14:15 +00:00
|
|
|
// we have to find which elements will drive an iteration
|
|
|
|
elements = bin->children;
|
|
|
|
while (elements) {
|
2000-11-04 18:54:07 +00:00
|
|
|
element = GST_ELEMENT (elements->data);
|
|
|
|
g_print("gstbin: found element \"%s\"\n", gst_element_get_name (element));
|
|
|
|
if (GST_IS_BIN (element)) {
|
|
|
|
gst_bin_create_plan (GST_BIN (element));
|
2000-11-01 22:11:48 +00:00
|
|
|
}
|
2000-11-04 18:54:07 +00:00
|
|
|
if (GST_IS_SRC (element)) {
|
|
|
|
g_print("gstbin: adding '%s' as entry point\n",gst_element_get_name (element));
|
|
|
|
bin->entries = g_list_prepend (bin->entries, element);
|
2000-07-17 17:14:15 +00:00
|
|
|
bin->numentries++;
|
2000-08-14 10:55:35 +00:00
|
|
|
} else {
|
|
|
|
/* go through the list of pads to see if there's a Connection */
|
2000-11-04 18:54:07 +00:00
|
|
|
pads = gst_element_get_pad_list (element);
|
2000-08-14 10:55:35 +00:00
|
|
|
while (pads) {
|
2000-11-04 18:54:07 +00:00
|
|
|
pad = GST_PAD (pads->data);
|
2000-08-14 10:55:35 +00:00
|
|
|
/* we only worry about sink pads */
|
2000-11-04 18:54:07 +00:00
|
|
|
if (gst_pad_get_direction (pad) == GST_PAD_SINK) {
|
|
|
|
g_print("gstbin: found SINK pad %s\n", gst_pad_get_name (pad));
|
2000-08-14 10:55:35 +00:00
|
|
|
/* get the pad's peer */
|
2000-11-04 18:54:07 +00:00
|
|
|
peer = gst_pad_get_peer (pad);
|
2000-09-24 14:29:49 +00:00
|
|
|
if (!peer) {
|
2000-11-04 18:54:07 +00:00
|
|
|
g_print("gstbin: found SINK pad %s has no peer\n", gst_pad_get_name (pad));
|
2000-09-24 14:29:49 +00:00
|
|
|
break;
|
|
|
|
}
|
2000-08-14 10:55:35 +00:00
|
|
|
/* get the parent of the peer of the pad */
|
2000-11-04 18:54:07 +00:00
|
|
|
outside = GST_ELEMENT (gst_pad_get_parent (peer));
|
2000-08-14 10:55:35 +00:00
|
|
|
if (!outside) break;
|
|
|
|
/* if it's a connection and it's not ours... */
|
2000-11-04 18:54:07 +00:00
|
|
|
if (GST_IS_CONNECTION (outside) &&
|
|
|
|
(gst_object_get_parent (GST_OBJECT (outside)) != GST_OBJECT (bin))) {
|
2000-09-22 23:35:14 +00:00
|
|
|
gst_info("gstbin: element \"%s\" is the external source Connection "
|
|
|
|
"for internal element \"%s\"\n",
|
2000-11-04 18:54:07 +00:00
|
|
|
gst_element_get_name (GST_ELEMENT (outside)),
|
|
|
|
gst_element_get_name (GST_ELEMENT (element)));
|
|
|
|
bin->entries = g_list_prepend (bin->entries, outside);
|
2000-08-14 10:55:35 +00:00
|
|
|
bin->numentries++;
|
|
|
|
}
|
|
|
|
}
|
2000-09-24 14:29:49 +00:00
|
|
|
else {
|
2000-11-04 18:54:07 +00:00
|
|
|
g_print("gstbin: found pad %s\n", gst_pad_get_name (pad));
|
2000-09-24 14:29:49 +00:00
|
|
|
}
|
2000-11-04 18:54:07 +00:00
|
|
|
pads = g_list_next (pads);
|
2000-08-14 10:55:35 +00:00
|
|
|
}
|
2000-07-17 17:14:15 +00:00
|
|
|
}
|
2000-11-04 18:54:07 +00:00
|
|
|
elements = g_list_next (elements);
|
2000-07-17 17:14:15 +00:00
|
|
|
}
|
|
|
|
}
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
|
2000-11-04 18:54:07 +00:00
|
|
|
void
|
|
|
|
gst_bin_iterate_func (GstBin *bin)
|
|
|
|
{
|
2000-01-30 09:03:00 +00:00
|
|
|
GList *entries;
|
|
|
|
GstElement *entry;
|
2000-07-17 17:14:15 +00:00
|
|
|
|
2000-11-04 18:54:07 +00:00
|
|
|
DEBUG("gst_bin_iterate_func() in \"%s\"\n", gst_element_get_name (GST_ELEMENT (bin)));
|
2000-07-17 17:14:15 +00:00
|
|
|
|
2000-11-04 18:54:07 +00:00
|
|
|
g_return_if_fail (bin != NULL);
|
|
|
|
g_return_if_fail (GST_IS_BIN (bin));
|
|
|
|
g_return_if_fail (GST_STATE (bin) == GST_STATE_PLAYING);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-08-14 10:55:35 +00:00
|
|
|
DEBUG("GstBin: iterating\n");
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-07-17 17:14:15 +00:00
|
|
|
if (bin->need_cothreads) {
|
|
|
|
// all we really have to do is switch to the first child
|
|
|
|
// FIXME this should be lots more intelligent about where to start
|
2000-09-22 23:35:14 +00:00
|
|
|
DEBUG("** in gst_bin_iterate_func()==================================%s\n",
|
2000-11-04 18:54:07 +00:00
|
|
|
gst_element_get_name (GST_ELEMENT (bin->children->data)));
|
|
|
|
|
|
|
|
cothread_switch (GST_ELEMENT (bin->children->data)->threadstate);
|
|
|
|
|
2000-10-21 12:04:40 +00:00
|
|
|
DEBUG("** out gst_bin_iterate_func()==================================%s\n",
|
2000-11-04 18:54:07 +00:00
|
|
|
gst_element_get_name (GST_ELEMENT (bin->children->data)));
|
|
|
|
|
2000-07-17 17:14:15 +00:00
|
|
|
} else {
|
2000-09-22 23:35:14 +00:00
|
|
|
if (bin->numentries <= 0) {
|
2000-10-30 21:02:08 +00:00
|
|
|
//printf("gstbin: no entries in bin \"%s\" trying children...\n", gst_element_get_name(GST_ELEMENT(bin)));
|
2000-09-24 14:29:49 +00:00
|
|
|
// we will try loop over the elements then...
|
2000-09-22 23:35:14 +00:00
|
|
|
entries = bin->children;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
entries = bin->entries;
|
|
|
|
}
|
2000-07-17 17:14:15 +00:00
|
|
|
|
2000-09-27 19:33:10 +00:00
|
|
|
g_assert(entries != NULL);
|
|
|
|
|
2000-07-17 17:14:15 +00:00
|
|
|
while (entries) {
|
2000-11-04 18:54:07 +00:00
|
|
|
entry = GST_ELEMENT (entries->data);
|
|
|
|
if (GST_IS_SRC (entry))
|
|
|
|
gst_src_push (GST_SRC (entry));
|
|
|
|
else if (GST_IS_CONNECTION (entry))
|
|
|
|
gst_connection_push (GST_CONNECTION (entry));
|
|
|
|
else if (GST_IS_BIN (entry))
|
|
|
|
gst_bin_iterate (GST_BIN (entry));
|
2000-07-17 17:14:15 +00:00
|
|
|
else
|
2000-11-04 18:54:07 +00:00
|
|
|
g_assert_not_reached ();
|
|
|
|
entries = g_list_next (entries);
|
2000-07-17 17:14:15 +00:00
|
|
|
}
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
}
|