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,36 +46,19 @@ 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)
@ -123,15 +107,27 @@ 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 ");
}
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))); 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) {
i++;
continue;
}
len = strlen (arg); len = strlen (arg);
element = NULL; element = NULL;
DEBUG ("** ARGUMENT is '%s'\n", arg); DEBUG ("** ARGUMENT is '%s'\n", arg);
@ -143,14 +139,16 @@ gst_parse_launch_cmdline(int argc,char *argv[],GstBin *parent,gst_parse_priv *pr
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,'!'))) { }
else if ((ptr = strchr (arg, '!'))) {
DEBUG ("attempting to connect pads together....\n"); DEBUG ("attempting to connect pads together....\n");
// if it starts with the ! // if it starts with the !
@ -161,7 +159,8 @@ 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 { }
else {
srcpadname = g_strndup (arg, (ptr - arg)); 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)
@ -184,7 +183,8 @@ gst_parse_launch_cmdline(int argc,char *argv[],GstBin *parent,gst_parse_priv *pr
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;
} }
@ -201,23 +201,27 @@ gst_parse_launch_cmdline(int argc,char *argv[],GstBin *parent,gst_parse_priv *pr
} }
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 { }
else {
GST_DEBUG (0, "have src pad %s:%s\n", GST_DEBUG_PAD_NAME (temppad)); 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)
break;
g_free (tempname); 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),
srcpadname);
pads = gst_element_get_pad_list (previous); 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))
GST_DEBUG (0, "it's a ghost pad\n");
if (gst_pad_get_direction (temppad) == GST_PAD_SRC) { if (gst_pad_get_direction (temppad) == GST_PAD_SRC) {
srcpads = g_slist_append (srcpads, temppad); srcpads = g_slist_append (srcpads, temppad);
numsrcpads++; numsrcpads++;
@ -225,15 +229,19 @@ gst_parse_launch_cmdline(int argc,char *argv[],GstBin *parent,gst_parse_priv *pr
} }
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, "=")) { }
else if (strstr (arg, "=")) {
gchar *argname; gchar *argname;
gchar *argval; gchar *argval;
gchar *pos = strstr (arg, "="); gchar *pos = strstr (arg, "=");
// we have an argument // we have an argument
argname = arg; argname = arg;
pos[0] = '\0'; pos[0] = '\0';
@ -245,7 +253,8 @@ gst_parse_launch_cmdline(int argc,char *argv[],GstBin *parent,gst_parse_priv *pr
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') {
@ -255,7 +264,8 @@ gst_parse_launch_cmdline(int argc,char *argv[],GstBin *parent,gst_parse_priv *pr
i++; i++;
if (i < argc) { if (i < argc) {
gst_element_set_name (previous, argv[i]); gst_element_set_name (previous, argv[i]);
} else { }
else {
fprintf (stderr, "error, expected element name, found end of arguments\n"); fprintf (stderr, "error, expected element name, found end of arguments\n");
return GST_PARSE_ERROR_SYNTAX; return GST_PARSE_ERROR_SYNTAX;
} }
@ -263,11 +273,13 @@ gst_parse_launch_cmdline(int argc,char *argv[],GstBin *parent,gst_parse_priv *pr
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; return GST_PARSE_ERROR_SYNTAX;
} else if (strcmp(argv[i], "]") != 0) { }
else if (strcmp (argv[i], "]") != 0) {
fprintf (stderr, "error, expected ], found '%s'\n", argv[i]); fprintf (stderr, "error, expected ], found '%s'\n", argv[i]);
return GST_PARSE_ERROR_SYNTAX; return GST_PARSE_ERROR_SYNTAX;
} }
} else { }
else {
DEBUG ("have element or bin/thread\n"); 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])) {
@ -279,7 +291,8 @@ gst_parse_launch_cmdline(int argc,char *argv[],GstBin *parent,gst_parse_priv *pr
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) {
@ -287,7 +300,8 @@ gst_parse_launch_cmdline(int argc,char *argv[],GstBin *parent,gst_parse_priv *pr
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 { }
else {
DEBUG ("error in parser, unexpected symbol, FIXME\n"); DEBUG ("error in parser, unexpected symbol, FIXME\n");
i++; i++;
continue; continue;
@ -295,10 +309,12 @@ gst_parse_launch_cmdline(int argc,char *argv[],GstBin *parent,gst_parse_priv *pr
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);
@ -306,9 +322,12 @@ gst_parse_launch_cmdline(int argc,char *argv[],GstBin *parent,gst_parse_priv *pr
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;
} }
@ -330,7 +349,8 @@ gst_parse_launch_cmdline(int argc,char *argv[],GstBin *parent,gst_parse_priv *pr
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;
} }
@ -347,12 +367,14 @@ gst_parse_launch_cmdline(int argc,char *argv[],GstBin *parent,gst_parse_priv *pr
} }
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 { }
else {
GST_DEBUG (0, "have sink pad %s:%s\n", GST_DEBUG_PAD_NAME (temppad)); 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)
break;
g_free (tempname); g_free (tempname);
} }
} }
@ -370,31 +392,30 @@ gst_parse_launch_cmdline(int argc,char *argv[],GstBin *parent,gst_parse_priv *pr
} }
} }
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)));
} }
} }
@ -405,12 +426,6 @@ gst_parse_launch_cmdline(int argc,char *argv[],GstBin *parent,gst_parse_priv *pr
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",
@ -419,18 +434,21 @@ gst_parse_launch_cmdline(int argc,char *argv[],GstBin *parent,gst_parse_priv *pr
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++;
@ -444,7 +462,8 @@ g_strdup_printf("%s-ghost",GST_PAD_NAME(temppad)));
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)));
@ -456,11 +475,10 @@ 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;
} }
@ -553,6 +571,7 @@ gst_parse_launch(const gchar *cmdline,GstBin *parent)
// 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
@ -579,4 +598,3 @@ gst_parse_launch(const gchar *cmdline,GstBin *parent)
return i; return i;
} }