Some code cleanups.

Original commit message from CVS:
Some code cleanups.
This commit is contained in:
Wim Taymans 2001-12-12 13:04:05 +00:00
parent f863316ce3
commit 946aace685

View file

@ -35,7 +35,8 @@
#include "gstutils.h" #include "gstutils.h"
typedef struct _gst_parse_priv gst_parse_priv; typedef struct _gst_parse_priv gst_parse_priv;
struct _gst_parse_priv { struct _gst_parse_priv
{
guint bincount; guint bincount;
guint threadcount; guint threadcount;
gint binlevel; gint binlevel;
@ -45,41 +46,24 @@ struct _gst_parse_priv {
}; };
typedef struct _gst_parse_delayed_pad gst_parse_delayed_pad; typedef struct _gst_parse_delayed_pad gst_parse_delayed_pad;
struct _gst_parse_delayed_pad { struct _gst_parse_delayed_pad
{
gchar *name; gchar *name;
GstPad *peer; GstPad *peer;
}; };
/* FIXME need to either revive this, or have pad->padtemplate connections in core typedef struct
static void
gst_parse_newpad(GstElement *element,GstPad *pad,launch_delayed_pad *peer)
{ {
gst_info("have NEW_PAD signal\n");
// if it matches, connect it
if (!strcmp(GST_PAD_NAME(pad),peer->name)) {
gst_pad_connect(pad,peer->peer);
gst_info("delayed connect of '%s' to '%s'\n",
GST_PAD_NAME(pad),GST_PAD_NAME(peer->peer));
}
}
*/
typedef struct {
gchar *srcpadname; gchar *srcpadname;
GstPad *target; GstPad *target;
GstElement *pipeline; GstElement *pipeline;
} dyn_connect;
static void have_eos (void)
{
DEBUG ("I have eos on the first element\n");
exit (0);
} }
dyn_connect;
static void static void
dynamic_connect (GstElement *element, GstPad *newpad, gpointer data) dynamic_connect (GstElement * element, GstPad * newpad, gpointer data)
{ {
dyn_connect *connect = (dyn_connect *)data; dyn_connect *connect = (dyn_connect *) data;
if (!strcmp (gst_pad_get_name (newpad), connect->srcpadname)) { if (!strcmp (gst_pad_get_name (newpad), connect->srcpadname)) {
gst_element_set_state (connect->pipeline, GST_STATE_PAUSED); gst_element_set_state (connect->pipeline, GST_STATE_PAUSED);
@ -89,23 +73,23 @@ dynamic_connect (GstElement *element, GstPad *newpad, gpointer data)
} }
static gchar * static gchar *
gst_parse_unique_name(gchar *type,gst_parse_priv *priv) gst_parse_unique_name (gchar * type, gst_parse_priv * priv)
{ {
gpointer tmp; gpointer tmp;
gint count; gint count;
tmp = g_hash_table_lookup (priv->elementcounts,type); tmp = g_hash_table_lookup (priv->elementcounts, type);
count = GPOINTER_TO_INT (tmp); count = GPOINTER_TO_INT (tmp);
count++; count++;
g_hash_table_insert(priv->elementcounts,type,GINT_TO_POINTER(count)); g_hash_table_insert (priv->elementcounts, type, GINT_TO_POINTER (count));
return g_strdup_printf("%s%d",type,count-1); return g_strdup_printf ("%s%d", type, count - 1);
} }
static gint static gint
gst_parse_launch_cmdline(int argc,char *argv[],GstBin *parent,gst_parse_priv *priv) gst_parse_launch_cmdline (int argc, char *argv[], GstBin * parent, gst_parse_priv * priv)
{ {
gint i = 0, j = 0; gint i = 0, j = 0;
gchar *arg; gchar *arg;
@ -123,35 +107,49 @@ gst_parse_launch_cmdline(int argc,char *argv[],GstBin *parent,gst_parse_priv *pr
priv->binlevel++; priv->binlevel++;
if (GST_IS_PIPELINE(parent)) { closingchar = '\0';DEBUG("in pipeline "); } if (GST_IS_PIPELINE (parent)) {
else if (GST_IS_THREAD(parent)) { closingchar = '}';DEBUG("in thread "); } closingchar = '\0';
else { closingchar = ')';DEBUG("in bin "); } DEBUG ("in pipeline ");
DEBUG_NOPREFIX("%s\n",GST_ELEMENT_NAME (GST_ELEMENT (parent))); }
else if (GST_IS_THREAD (parent)) {
closingchar = '}';
DEBUG ("in thread ");
}
else {
closingchar = ')';
DEBUG ("in bin ");
}
DEBUG_NOPREFIX ("%s\n", GST_ELEMENT_NAME (GST_ELEMENT (parent)));
while (i < argc) { while (i < argc) {
arg = argv[i]; arg = argv[i];
// FIXME this is a lame solution for problems with the first parser // FIXME this is a lame solution for problems with the first parser
if (arg == NULL) { i++;continue; } if (arg == NULL) {
len = strlen(arg); i++;
continue;
}
len = strlen (arg);
element = NULL; element = NULL;
DEBUG("** ARGUMENT is '%s'\n",arg); DEBUG ("** ARGUMENT is '%s'\n", arg);
// a null that slipped through the reconstruction // a null that slipped through the reconstruction
if (len == 0) { if (len == 0) {
DEBUG("random arg, FIXME\n"); DEBUG ("random arg, FIXME\n");
i++; i++;
continue; continue;
// end of the container // end of the container
} else if (arg[0] == closingchar) { }
else if (arg[0] == closingchar) {
// time to finish off this bin // time to finish off this bin
DEBUG("exiting container %s\n",GST_ELEMENT_NAME (GST_ELEMENT (parent))); DEBUG ("exiting container %s\n", GST_ELEMENT_NAME (GST_ELEMENT (parent)));
retval = i+1; retval = i + 1;
break; break;
// a pad connection // a pad connection
} else if ((ptr = strchr(arg,'!'))) { }
DEBUG("attempting to connect pads together....\n"); else if ((ptr = strchr (arg, '!'))) {
DEBUG ("attempting to connect pads together....\n");
// if it starts with the ! // if it starts with the !
if (arg[0] == '!') { if (arg[0] == '!') {
@ -161,276 +159,296 @@ gst_parse_launch_cmdline(int argc,char *argv[],GstBin *parent,gst_parse_priv *pr
sinkpadname = &arg[1]; sinkpadname = &arg[1];
else else
sinkpadname = NULL; sinkpadname = NULL;
} else { }
srcpadname = g_strndup(arg,(ptr-arg)); else {
srcpadname = g_strndup (arg, (ptr - arg));
// if there's a sinkpad // if there's a sinkpad
if (len > (ptr-arg)+1) if (len > (ptr - arg) + 1)
sinkpadname = &ptr[1]; sinkpadname = &ptr[1];
else else
sinkpadname = NULL; sinkpadname = NULL;
} }
GST_DEBUG(0,"have srcpad %s, sinkpad %s\n",srcpadname,sinkpadname); GST_DEBUG (0, "have srcpad %s, sinkpad %s\n", srcpadname, sinkpadname);
g_slist_free(srcpads); g_slist_free (srcpads);
srcpads = NULL; srcpads = NULL;
numsrcpads=0; numsrcpads = 0;
tempname=NULL; tempname = NULL;
// find src pads // find src pads
if (srcpadname != NULL) { if (srcpadname != NULL) {
while (1){ while (1) {
// split name at commas // split name at commas
if ((ptr = strchr(srcpadname,','))){ if ((ptr = strchr (srcpadname, ','))) {
tempname = g_strndup(srcpadname,(ptr-srcpadname)); tempname = g_strndup (srcpadname, (ptr - srcpadname));
srcpadname = &ptr[1]; srcpadname = &ptr[1];
} else { }
else {
tempname = srcpadname; tempname = srcpadname;
} }
// look for pad with that name // look for pad with that name
if ((temppad = gst_element_get_pad(previous,tempname))){ if ((temppad = gst_element_get_pad (previous, tempname))) {
srcpads = g_slist_append(srcpads,temppad); srcpads = g_slist_append (srcpads, temppad);
numsrcpads++; numsrcpads++;
} }
// try to create a pad using that padtemplate name // try to create a pad using that padtemplate name
else if ((temppad = gst_element_request_pad_by_name(previous,tempname))) { else if ((temppad = gst_element_request_pad_by_name (previous, tempname))) {
srcpads = g_slist_append(srcpads,temppad); srcpads = g_slist_append (srcpads, temppad);
numsrcpads++; numsrcpads++;
} }
if (!temppad) { if (!temppad) {
GST_DEBUG(0,"NO SUCH pad %s in element %s\n",tempname,GST_ELEMENT_NAME(previous)); GST_DEBUG (0, "NO SUCH pad %s in element %s\n", tempname, GST_ELEMENT_NAME (previous));
} else { }
GST_DEBUG(0,"have src pad %s:%s\n",GST_DEBUG_PAD_NAME(temppad)); else {
GST_DEBUG (0, "have src pad %s:%s\n", GST_DEBUG_PAD_NAME (temppad));
} }
// if there is no more commas in srcpadname then we're done // if there is no more commas in srcpadname then we're done
if (tempname == srcpadname) break; if (tempname == srcpadname)
g_free(tempname); break;
g_free (tempname);
} }
} }
else { else {
// check through the list to find the first sink pad // check through the list to find the first sink pad
GST_DEBUG(0,"CHECKING through element %s for pad named %s\n",GST_ELEMENT_NAME(previous),srcpadname); GST_DEBUG (0, "CHECKING through element %s for pad named %s\n", GST_ELEMENT_NAME (previous),
pads = gst_element_get_pad_list(previous); srcpadname);
pads = gst_element_get_pad_list (previous);
while (pads) { while (pads) {
temppad = GST_PARSE_LISTPAD(pads); temppad = GST_PARSE_LISTPAD (pads);
GST_DEBUG(0,"have pad %s:%s\n",GST_DEBUG_PAD_NAME(temppad)); GST_DEBUG (0, "have pad %s:%s\n", GST_DEBUG_PAD_NAME (temppad));
if (GST_IS_GHOST_PAD(temppad)) GST_DEBUG(0,"it's a ghost pad\n"); if (GST_IS_GHOST_PAD (temppad))
if (gst_pad_get_direction (temppad) == GST_PAD_SRC){ GST_DEBUG (0, "it's a ghost pad\n");
srcpads = g_slist_append(srcpads,temppad); if (gst_pad_get_direction (temppad) == GST_PAD_SRC) {
srcpads = g_slist_append (srcpads, temppad);
numsrcpads++; numsrcpads++;
break; break;
} }
pads = g_list_next (pads); pads = g_list_next (pads);
} }
if (!srcpads) GST_DEBUG(0,"error, can't find a src pad!!!\n"); if (!srcpads)
else GST_DEBUG(0,"have src pad %s:%s\n",GST_DEBUG_PAD_NAME(GST_PARSE_LISTPAD(srcpads))); GST_DEBUG (0, "error, can't find a src pad!!!\n");
else
GST_DEBUG (0, "have src pad %s:%s\n", GST_DEBUG_PAD_NAME (GST_PARSE_LISTPAD (srcpads)));
} }
// argument with = in it // argument with = in it
} else if (strstr(arg, "=")) { }
gchar * argname; else if (strstr (arg, "=")) {
gchar * argval; gchar *argname;
gchar * pos = strstr(arg, "="); gchar *argval;
gchar *pos = strstr (arg, "=");
// we have an argument // we have an argument
argname = arg; argname = arg;
pos[0] = '\0'; pos[0] = '\0';
argval = pos+1; argval = pos + 1;
GST_DEBUG(0,"attempting to set argument '%s' to '%s' on element '%s'\n", GST_DEBUG (0, "attempting to set argument '%s' to '%s' on element '%s'\n",
argname,argval,GST_ELEMENT_NAME(previous)); argname, argval, GST_ELEMENT_NAME (previous));
gst_util_set_object_arg (G_OBJECT(previous), argname, argval); gst_util_set_object_arg (G_OBJECT (previous), argname, argval);
g_free(argname); g_free (argname);
// element or argument, or beginning of bin or thread // element or argument, or beginning of bin or thread
} else if (arg[0] == '[') { }
else if (arg[0] == '[') {
// we have the start of a name of the preceding element. // we have the start of a name of the preceding element.
// rename previous element to next arg. // rename previous element to next arg.
if (arg[1] != '\0') { if (arg[1] != '\0') {
fprintf(stderr,"error, unexpected junk after [\n"); fprintf (stderr, "error, unexpected junk after [\n");
return GST_PARSE_ERROR_SYNTAX; return GST_PARSE_ERROR_SYNTAX;
} }
i++; i++;
if (i < argc) { if (i < argc) {
gst_element_set_name(previous, argv[i]); gst_element_set_name (previous, argv[i]);
} else { }
fprintf(stderr,"error, expected element name, found end of arguments\n"); else {
fprintf (stderr, "error, expected element name, found end of arguments\n");
return GST_PARSE_ERROR_SYNTAX; return GST_PARSE_ERROR_SYNTAX;
} }
i++; i++;
if (i >= argc) { if (i >= argc) {
fprintf(stderr,"error, expected ], found end of arguments\n"); fprintf (stderr, "error, expected ], found end of arguments\n");
return GST_PARSE_ERROR_SYNTAX;
} else if (strcmp(argv[i], "]") != 0) {
fprintf(stderr,"error, expected ], found '%s'\n", argv[i]);
return GST_PARSE_ERROR_SYNTAX; return GST_PARSE_ERROR_SYNTAX;
} }
} else { else if (strcmp (argv[i], "]") != 0) {
DEBUG("have element or bin/thread\n"); fprintf (stderr, "error, expected ], found '%s'\n", argv[i]);
return GST_PARSE_ERROR_SYNTAX;
}
}
else {
DEBUG ("have element or bin/thread\n");
// if we have a bin or thread starting // if we have a bin or thread starting
if (strchr("({",arg[0])) { if (strchr ("({", arg[0])) {
if (arg[0] == '(') { if (arg[0] == '(') {
// create a bin and add it to the current parent // create a bin and add it to the current parent
element = gst_bin_new(g_strdup_printf("bin%d",priv->bincount++)); element = gst_bin_new (g_strdup_printf ("bin%d", priv->bincount++));
if (!element) { if (!element) {
fprintf(stderr,"Couldn't create a bin!\n"); fprintf (stderr, "Couldn't create a bin!\n");
return GST_PARSE_ERROR_CREATING_ELEMENT; return GST_PARSE_ERROR_CREATING_ELEMENT;
} }
GST_DEBUG(0,"CREATED bin %s\n",GST_ELEMENT_NAME(element)); GST_DEBUG (0, "CREATED bin %s\n", GST_ELEMENT_NAME (element));
} else if (arg[0] == '{') { }
else if (arg[0] == '{') {
// create a thread and add it to the current parent // create a thread and add it to the current parent
element = gst_thread_new(g_strdup_printf("thread%d",priv->threadcount++)); element = gst_thread_new (g_strdup_printf ("thread%d", priv->threadcount++));
if (!element) { if (!element) {
fprintf(stderr,"Couldn't create a thread!\n"); fprintf (stderr, "Couldn't create a thread!\n");
return GST_PARSE_ERROR_CREATING_ELEMENT; return GST_PARSE_ERROR_CREATING_ELEMENT;
} }
GST_DEBUG(0,"CREATED thread %s\n",GST_ELEMENT_NAME(element)); GST_DEBUG (0, "CREATED thread %s\n", GST_ELEMENT_NAME (element));
} else { }
DEBUG("error in parser, unexpected symbol, FIXME\n"); else {
DEBUG ("error in parser, unexpected symbol, FIXME\n");
i++; i++;
continue; continue;
} }
j = gst_parse_launch_cmdline(argc - i, argv + i + 1, GST_BIN (element), priv); j = gst_parse_launch_cmdline (argc - i, argv + i + 1, GST_BIN (element), priv);
//check for parse error //check for parse error
if (j < 0) return j; if (j < 0)
return j;
i += j; i += j;
} else { }
else {
// we have an element // we have an element
DEBUG("attempting to create element '%s'\n",arg); DEBUG ("attempting to create element '%s'\n", arg);
ptr = gst_parse_unique_name(arg,priv); ptr = gst_parse_unique_name (arg, priv);
element = gst_elementfactory_make(arg,ptr); element = gst_elementfactory_make (arg, ptr);
g_free(ptr); g_free (ptr);
if (!element) { if (!element) {
#ifndef GST_DISABLE_REGISTRY #ifndef GST_DISABLE_REGISTRY
fprintf(stderr,"Couldn't create a '%s', no such element or need to run gstreamer-register?\n",arg); fprintf (stderr,
"Couldn't create a '%s', no such element or need to run gstreamer-register?\n",
arg);
#else #else
fprintf(stderr,"Couldn't create a '%s', no such element or need to load pluginn?\n",arg); fprintf (stderr, "Couldn't create a '%s', no such element or need to load pluginn?\n",
arg);
#endif #endif
return GST_PARSE_ERROR_NOSUCH_ELEMENT; return GST_PARSE_ERROR_NOSUCH_ELEMENT;
} }
GST_DEBUG(0,"CREATED element %s\n",GST_ELEMENT_NAME(element)); GST_DEBUG (0, "CREATED element %s\n", GST_ELEMENT_NAME (element));
} }
gst_bin_add (GST_BIN (parent), element); gst_bin_add (GST_BIN (parent), element);
elementcount++; elementcount++;
g_slist_free(sinkpads); g_slist_free (sinkpads);
sinkpads = NULL; sinkpads = NULL;
numsinkpads=0; numsinkpads = 0;
tempname=NULL; tempname = NULL;
// find sink pads // find sink pads
if (sinkpadname != NULL) { if (sinkpadname != NULL) {
while (1){ while (1) {
// split name at commas // split name at commas
if ((ptr = strchr(sinkpadname,','))){ if ((ptr = strchr (sinkpadname, ','))) {
tempname = g_strndup(sinkpadname,(ptr-sinkpadname)); tempname = g_strndup (sinkpadname, (ptr - sinkpadname));
sinkpadname = &ptr[1]; sinkpadname = &ptr[1];
} else { }
else {
tempname = sinkpadname; tempname = sinkpadname;
} }
// look for pad with that name // look for pad with that name
if ((temppad = gst_element_get_pad(element,tempname))){ if ((temppad = gst_element_get_pad (element, tempname))) {
sinkpads = g_slist_append(sinkpads,temppad); sinkpads = g_slist_append (sinkpads, temppad);
numsinkpads++; numsinkpads++;
} }
// try to create a pad using that padtemplate name // try to create a pad using that padtemplate name
else if ((temppad = gst_element_request_pad_by_name(element,tempname))) { else if ((temppad = gst_element_request_pad_by_name (element, tempname))) {
sinkpads = g_slist_append(sinkpads,temppad); sinkpads = g_slist_append (sinkpads, temppad);
numsinkpads++; numsinkpads++;
} }
if (!temppad) { if (!temppad) {
GST_DEBUG(0,"NO SUCH pad %s in element %s\n",tempname,GST_ELEMENT_NAME(element)); GST_DEBUG (0, "NO SUCH pad %s in element %s\n", tempname, GST_ELEMENT_NAME (element));
} else { }
GST_DEBUG(0,"have sink pad %s:%s\n",GST_DEBUG_PAD_NAME(temppad)); else {
GST_DEBUG (0, "have sink pad %s:%s\n", GST_DEBUG_PAD_NAME (temppad));
} }
// if there is no more commas in sinkpadname then we're done // if there is no more commas in sinkpadname then we're done
if (tempname == sinkpadname) break; if (tempname == sinkpadname)
g_free(tempname); break;
g_free (tempname);
} }
} }
else { else {
// check through the list to find the first sink pad // check through the list to find the first sink pad
pads = gst_element_get_pad_list(element); pads = gst_element_get_pad_list (element);
while (pads) { while (pads) {
temppad = GST_PAD(pads->data); temppad = GST_PAD (pads->data);
pads = g_list_next (pads); pads = g_list_next (pads);
if (gst_pad_get_direction (temppad) == GST_PAD_SINK){ if (gst_pad_get_direction (temppad) == GST_PAD_SINK) {
sinkpads = g_slist_append(sinkpads,temppad); sinkpads = g_slist_append (sinkpads, temppad);
numsinkpads++; numsinkpads++;
break; break;
} }
} }
} }
if (!sinkpads) GST_DEBUG(0,"can't find a sink pad for element\n"); if (!sinkpads)
else GST_DEBUG(0,"have sink pad %s:%s\n",GST_DEBUG_PAD_NAME(GST_PARSE_LISTPAD(sinkpads))); GST_DEBUG (0, "can't find a sink pad for element\n");
else
GST_DEBUG (0, "have sink pad %s:%s\n", GST_DEBUG_PAD_NAME (GST_PARSE_LISTPAD (sinkpads)));
if (!srcpads && sinkpads && previous) { if (!srcpads && sinkpads && previous) {
dyn_connect *connect = g_malloc (sizeof (dyn_connect)); dyn_connect *connect = g_malloc (sizeof (dyn_connect));
connect->srcpadname = srcpadname; connect->srcpadname = srcpadname;
connect->target = GST_PARSE_LISTPAD(sinkpads); connect->target = GST_PARSE_LISTPAD (sinkpads);
connect->pipeline = parent; connect->pipeline = GST_ELEMENT (parent);
GST_DEBUG(0,"SETTING UP dynamic connection %s:%s and %s:%s\n", GST_DEBUG (0, "SETTING UP dynamic connection %s:%s and %s:%s\n",
gst_element_get_name (previous), gst_element_get_name (previous),
srcpadname, srcpadname, GST_DEBUG_PAD_NAME (GST_PARSE_LISTPAD (sinkpads)));
GST_DEBUG_PAD_NAME(GST_PARSE_LISTPAD(sinkpads)));
g_signal_connect (G_OBJECT (previous), "new_pad", g_signal_connect (G_OBJECT (previous), "new_pad", G_CALLBACK (dynamic_connect), connect);
G_CALLBACK (dynamic_connect), connect);
} }
else { else {
for (j=0; (j<numsrcpads) && (j<numsinkpads); j++){ for (j = 0; (j < numsrcpads) && (j < numsinkpads); j++) {
GST_DEBUG(0,"CONNECTING %s:%s and %s:%s\n", GST_DEBUG (0, "CONNECTING %s:%s and %s:%s\n",
GST_DEBUG_PAD_NAME(GST_PARSE_LISTPAD(g_slist_nth(srcpads,j))), GST_DEBUG_PAD_NAME (GST_PARSE_LISTPAD (g_slist_nth (srcpads, j))),
GST_DEBUG_PAD_NAME(GST_PARSE_LISTPAD(g_slist_nth(sinkpads,j)))); GST_DEBUG_PAD_NAME (GST_PARSE_LISTPAD (g_slist_nth (sinkpads, j))));
gst_pad_connect( gst_pad_connect (GST_PARSE_LISTPAD (g_slist_nth (srcpads, j)),
GST_PARSE_LISTPAD(g_slist_nth(srcpads,j)), GST_PARSE_LISTPAD (g_slist_nth (sinkpads, j)));
GST_PARSE_LISTPAD(g_slist_nth(sinkpads,j)));
} }
} }
g_slist_free(srcpads); g_slist_free (srcpads);
srcpads = NULL; srcpads = NULL;
g_slist_free(sinkpads); g_slist_free (sinkpads);
sinkpads = NULL; sinkpads = NULL;
// thomas: if we're the first element, connect eos signal
if (elementcount == 1)
{
g_signal_connect (G_OBJECT (element), "eos", have_eos, NULL);
}
// if we're the first element, ghost all the sinkpads // if we're the first element, ghost all the sinkpads
if (elementcount == 1) { if (elementcount == 1) {
DEBUG("first element, ghosting all of %s's sink pads to parent %s\n", DEBUG ("first element, ghosting all of %s's sink pads to parent %s\n",
GST_ELEMENT_NAME(element),GST_ELEMENT_NAME(GST_ELEMENT(parent))); GST_ELEMENT_NAME (element), GST_ELEMENT_NAME (GST_ELEMENT (parent)));
pads = gst_element_get_pad_list (element); pads = gst_element_get_pad_list (element);
while (pads) { while (pads) {
temppad = GST_PAD (pads->data); temppad = GST_PAD (pads->data);
pads = g_list_next (pads); pads = g_list_next (pads);
if (!temppad) DEBUG("much oddness, pad doesn't seem to exist\n"); if (!temppad)
DEBUG ("much oddness, pad doesn't seem to exist\n");
else if (gst_pad_get_direction (temppad) == GST_PAD_SINK) { else if (gst_pad_get_direction (temppad) == GST_PAD_SINK) {
gst_element_add_ghost_pad (GST_ELEMENT (parent), temppad, gst_element_add_ghost_pad (GST_ELEMENT (parent), temppad,
g_strdup_printf("%s-ghost",GST_PAD_NAME(temppad))); g_strdup_printf ("%s-ghost", GST_PAD_NAME (temppad)));
GST_DEBUG(0,"GHOSTED %s:%s to %s as %s-ghost\n", GST_DEBUG (0, "GHOSTED %s:%s to %s as %s-ghost\n",
GST_DEBUG_PAD_NAME(temppad),GST_ELEMENT_NAME(GST_ELEMENT(parent)),GST_PAD_NAME(temppad)); GST_DEBUG_PAD_NAME (temppad), GST_ELEMENT_NAME (GST_ELEMENT (parent)),
GST_PAD_NAME (temppad));
} }
} }
} }
previous = element; previous = element;
if (!GST_IS_BIN(element)) prevelement = element; if (!GST_IS_BIN (element))
prevelement = element;
} }
i++; i++;
@ -438,31 +456,31 @@ g_strdup_printf("%s-ghost",GST_PAD_NAME(temppad)));
// ghost all the src pads of the bin // ghost all the src pads of the bin
if (prevelement != NULL) { if (prevelement != NULL) {
DEBUG("last element, ghosting all of %s's src pads to parent %s\n", DEBUG ("last element, ghosting all of %s's src pads to parent %s\n",
GST_ELEMENT_NAME(prevelement),GST_ELEMENT_NAME(GST_ELEMENT(parent))); GST_ELEMENT_NAME (prevelement), GST_ELEMENT_NAME (GST_ELEMENT (parent)));
pads = gst_element_get_pad_list (prevelement); pads = gst_element_get_pad_list (prevelement);
while (pads) { while (pads) {
temppad = GST_PAD (pads->data); temppad = GST_PAD (pads->data);
pads = g_list_next (pads); pads = g_list_next (pads);
if (!temppad) DEBUG("much oddness, pad doesn't seem to exist\n"); if (!temppad)
DEBUG ("much oddness, pad doesn't seem to exist\n");
else if (gst_pad_get_direction (temppad) == GST_PAD_SRC) { else if (gst_pad_get_direction (temppad) == GST_PAD_SRC) {
gst_element_add_ghost_pad (GST_ELEMENT (parent), temppad, gst_element_add_ghost_pad (GST_ELEMENT (parent), temppad,
g_strdup_printf("%s-ghost",GST_PAD_NAME(temppad))); g_strdup_printf ("%s-ghost", GST_PAD_NAME (temppad)));
GST_DEBUG(0,"GHOSTED %s:%s to %s as %s-ghost\n", GST_DEBUG (0, "GHOSTED %s:%s to %s as %s-ghost\n",
GST_DEBUG_PAD_NAME(temppad),GST_ELEMENT_NAME (parent),GST_PAD_NAME(temppad)); GST_DEBUG_PAD_NAME (temppad), GST_ELEMENT_NAME (parent), GST_PAD_NAME (temppad));
} }
} }
} }
priv->binlevel--; priv->binlevel--;
if (retval) return retval; if (retval)
return retval;
DEBUG (closingchar != '\0'? DEBUG (closingchar != '\0' ? "returning IN THE WRONG PLACE\n" : "ending pipeline\n");
"returning IN THE WRONG PLACE\n" :
"ending pipeline\n");
return i+1; return i + 1;
} }
/** /**
@ -475,7 +493,7 @@ GST_DEBUG_PAD_NAME(temppad),GST_ELEMENT_NAME (parent),GST_PAD_NAME(temppad));
* Returns: ? * Returns: ?
*/ */
gint gint
gst_parse_launch(const gchar *cmdline,GstBin *parent) gst_parse_launch (const gchar * cmdline, GstBin * parent)
{ {
gst_parse_priv priv; gst_parse_priv priv;
gchar **argvn; gchar **argvn;
@ -492,14 +510,14 @@ gst_parse_launch(const gchar *cmdline,GstBin *parent)
priv.verbose = FALSE; priv.verbose = FALSE;
priv.debug = FALSE; priv.debug = FALSE;
end = cmdline + strlen(cmdline); end = cmdline + strlen (cmdline);
newargc = 0; newargc = 0;
temp = ""; temp = "";
// Extract the arguments to a gslist in reverse order // Extract the arguments to a gslist in reverse order
for (cp = cmdline; cp < end; ) { for (cp = cmdline; cp < end;) {
i = strcspn(cp, "([{}]) \"\\"); i = strcspn (cp, "([{}]) \"\\");
if (i > 0) { if (i > 0) {
temp = g_strconcat (temp, g_strndup (cp, i), NULL); temp = g_strconcat (temp, g_strndup (cp, i), NULL);
@ -507,7 +525,7 @@ gst_parse_launch(const gchar *cmdline,GstBin *parent)
// see if we have an escape char // see if we have an escape char
if (cp[i] != '\\') { if (cp[i] != '\\') {
// normal argument - copy and add to the list // normal argument - copy and add to the list
string_list = g_slist_prepend(string_list, temp); string_list = g_slist_prepend (string_list, temp);
newargc++; newargc++;
temp = ""; temp = "";
} }
@ -532,28 +550,29 @@ gst_parse_launch(const gchar *cmdline,GstBin *parent)
// make sure we got it // make sure we got it
if (cp == end) { if (cp == end) {
g_warning("gst_parse_launch: Unbalanced quote in command line"); g_warning ("gst_parse_launch: Unbalanced quote in command line");
// FIXME: The list leaks here // FIXME: The list leaks here
return 0; return 0;
} }
// copy the string sans quotes // copy the string sans quotes
string_list = g_slist_prepend(string_list, g_strndup(start, cp - start)); string_list = g_slist_prepend (string_list, g_strndup (start, cp - start));
newargc++; newargc++;
cp += 2; // skip the quote aswell cp += 2; // skip the quote aswell
} }
// brackets exist in a separate argument slot // brackets exist in a separate argument slot
if (*cp && strchr("([{}])", *cp)) { if (*cp && strchr ("([{}])", *cp)) {
string_list = g_slist_prepend(string_list, g_strndup(cp, 1)); string_list = g_slist_prepend (string_list, g_strndup (cp, 1));
newargc++; newargc++;
cp++; cp++;
} }
} }
// now allocate the new argv array // now allocate the new argv array
argvn = g_new0(char *,newargc); argvn = g_new0 (char *, newargc);
GST_DEBUG(0,"got %d args\n",newargc);
GST_DEBUG (0, "got %d args\n", newargc);
// reverse the list and put the strings in the new array // reverse the list and put the strings in the new array
i = newargc; i = newargc;
@ -561,22 +580,21 @@ gst_parse_launch(const gchar *cmdline,GstBin *parent)
for (slist = string_list; slist; slist = slist->next) for (slist = string_list; slist; slist = slist->next)
argvn[--i] = slist->data; argvn[--i] = slist->data;
g_slist_free(string_list); g_slist_free (string_list);
// print them out // print them out
for (i=0;i<newargc;i++) { for (i = 0; i < newargc; i++) {
GST_DEBUG(0,"arg %d is: %s\n",i,argvn[i]); GST_DEBUG (0, "arg %d is: %s\n", i, argvn[i]);
} }
// set up the elementcounts hash // set up the elementcounts hash
priv.elementcounts = g_hash_table_new(g_str_hash,g_str_equal); priv.elementcounts = g_hash_table_new (g_str_hash, g_str_equal);
// do it! // do it!
i = gst_parse_launch_cmdline(newargc,argvn,parent,&priv); i = gst_parse_launch_cmdline (newargc, argvn, parent, &priv);
// GST_DEBUG(0, "Finished - freeing temporary argument array"); // GST_DEBUG(0, "Finished - freeing temporary argument array");
// g_strfreev(argvn); // g_strfreev(argvn);
return i; return i;
} }