mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-26 19:51:11 +00:00
Some code cleanups.
Original commit message from CVS: Some code cleanups.
This commit is contained in:
parent
f863316ce3
commit
946aace685
1 changed files with 309 additions and 291 deletions
166
gst/gstparse.c
166
gst/gstparse.c
|
@ -35,7 +35,8 @@
|
|||
#include "gstutils.h"
|
||||
|
||||
typedef struct _gst_parse_priv gst_parse_priv;
|
||||
struct _gst_parse_priv {
|
||||
struct _gst_parse_priv
|
||||
{
|
||||
guint bincount;
|
||||
guint threadcount;
|
||||
gint binlevel;
|
||||
|
@ -45,36 +46,19 @@ struct _gst_parse_priv {
|
|||
};
|
||||
|
||||
typedef struct _gst_parse_delayed_pad gst_parse_delayed_pad;
|
||||
struct _gst_parse_delayed_pad {
|
||||
struct _gst_parse_delayed_pad
|
||||
{
|
||||
gchar *name;
|
||||
GstPad *peer;
|
||||
};
|
||||
|
||||
/* FIXME need to either revive this, or have pad->padtemplate connections in core
|
||||
static void
|
||||
gst_parse_newpad(GstElement *element,GstPad *pad,launch_delayed_pad *peer)
|
||||
typedef struct
|
||||
{
|
||||
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;
|
||||
GstPad *target;
|
||||
GstElement *pipeline;
|
||||
} dyn_connect;
|
||||
|
||||
static void have_eos (void)
|
||||
{
|
||||
DEBUG ("I have eos on the first element\n");
|
||||
exit (0);
|
||||
}
|
||||
dyn_connect;
|
||||
|
||||
static void
|
||||
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++;
|
||||
|
||||
if (GST_IS_PIPELINE(parent)) { closingchar = '\0';DEBUG("in pipeline "); }
|
||||
else if (GST_IS_THREAD(parent)) { closingchar = '}';DEBUG("in thread "); }
|
||||
else { closingchar = ')';DEBUG("in bin "); }
|
||||
if (GST_IS_PIPELINE (parent)) {
|
||||
closingchar = '\0';
|
||||
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)));
|
||||
|
||||
while (i < argc) {
|
||||
arg = argv[i];
|
||||
// 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);
|
||||
element = NULL;
|
||||
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;
|
||||
|
||||
// end of the container
|
||||
} else if (arg[0] == closingchar) {
|
||||
}
|
||||
else if (arg[0] == closingchar) {
|
||||
// time to finish off this bin
|
||||
DEBUG ("exiting container %s\n", GST_ELEMENT_NAME (GST_ELEMENT (parent)));
|
||||
retval = i + 1;
|
||||
break;
|
||||
|
||||
// a pad connection
|
||||
} else if ((ptr = strchr(arg,'!'))) {
|
||||
}
|
||||
else if ((ptr = strchr (arg, '!'))) {
|
||||
DEBUG ("attempting to connect pads together....\n");
|
||||
|
||||
// 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];
|
||||
else
|
||||
sinkpadname = NULL;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
srcpadname = g_strndup (arg, (ptr - arg));
|
||||
// if there's a sinkpad
|
||||
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, ','))) {
|
||||
tempname = g_strndup (srcpadname, (ptr - srcpadname));
|
||||
srcpadname = &ptr[1];
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
tempname = srcpadname;
|
||||
}
|
||||
|
||||
|
@ -201,23 +201,27 @@ gst_parse_launch_cmdline(int argc,char *argv[],GstBin *parent,gst_parse_priv *pr
|
|||
}
|
||||
if (!temppad) {
|
||||
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));
|
||||
}
|
||||
|
||||
// if there is no more commas in srcpadname then we're done
|
||||
if (tempname == srcpadname) break;
|
||||
if (tempname == srcpadname)
|
||||
break;
|
||||
g_free (tempname);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// 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);
|
||||
while (pads) {
|
||||
temppad = GST_PARSE_LISTPAD (pads);
|
||||
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) {
|
||||
srcpads = g_slist_append (srcpads, temppad);
|
||||
numsrcpads++;
|
||||
|
@ -225,15 +229,19 @@ gst_parse_launch_cmdline(int argc,char *argv[],GstBin *parent,gst_parse_priv *pr
|
|||
}
|
||||
pads = g_list_next (pads);
|
||||
}
|
||||
if (!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)));
|
||||
if (!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
|
||||
} else if (strstr(arg, "=")) {
|
||||
}
|
||||
else if (strstr (arg, "=")) {
|
||||
gchar *argname;
|
||||
gchar *argval;
|
||||
gchar *pos = strstr (arg, "=");
|
||||
|
||||
// we have an argument
|
||||
argname = arg;
|
||||
pos[0] = '\0';
|
||||
|
@ -245,7 +253,8 @@ gst_parse_launch_cmdline(int argc,char *argv[],GstBin *parent,gst_parse_priv *pr
|
|||
g_free (argname);
|
||||
|
||||
// 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.
|
||||
// rename previous element to next arg.
|
||||
if (arg[1] != '\0') {
|
||||
|
@ -255,7 +264,8 @@ gst_parse_launch_cmdline(int argc,char *argv[],GstBin *parent,gst_parse_priv *pr
|
|||
i++;
|
||||
if (i < argc) {
|
||||
gst_element_set_name (previous, argv[i]);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
fprintf (stderr, "error, expected element name, found end of arguments\n");
|
||||
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) {
|
||||
fprintf (stderr, "error, expected ], found end of arguments\n");
|
||||
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]);
|
||||
return GST_PARSE_ERROR_SYNTAX;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
DEBUG ("have element or bin/thread\n");
|
||||
// if we have a bin or thread starting
|
||||
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;
|
||||
}
|
||||
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
|
||||
element = gst_thread_new (g_strdup_printf ("thread%d", priv->threadcount++));
|
||||
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;
|
||||
}
|
||||
GST_DEBUG (0, "CREATED thread %s\n", GST_ELEMENT_NAME (element));
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
DEBUG ("error in parser, unexpected symbol, FIXME\n");
|
||||
i++;
|
||||
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);
|
||||
//check for parse error
|
||||
if (j < 0) return j;
|
||||
if (j < 0)
|
||||
return j;
|
||||
i += j;
|
||||
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// we have an element
|
||||
DEBUG ("attempting to create element '%s'\n", arg);
|
||||
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);
|
||||
if (!element) {
|
||||
#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
|
||||
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
|
||||
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, ','))) {
|
||||
tempname = g_strndup (sinkpadname, (ptr - sinkpadname));
|
||||
sinkpadname = &ptr[1];
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
tempname = sinkpadname;
|
||||
}
|
||||
|
||||
|
@ -347,12 +367,14 @@ gst_parse_launch_cmdline(int argc,char *argv[],GstBin *parent,gst_parse_priv *pr
|
|||
}
|
||||
if (!temppad) {
|
||||
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));
|
||||
}
|
||||
|
||||
// if there is no more commas in sinkpadname then we're done
|
||||
if (tempname == sinkpadname) break;
|
||||
if (tempname == sinkpadname)
|
||||
break;
|
||||
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");
|
||||
else GST_DEBUG(0,"have sink pad %s:%s\n",GST_DEBUG_PAD_NAME(GST_PARSE_LISTPAD(sinkpads)));
|
||||
if (!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) {
|
||||
dyn_connect *connect = g_malloc (sizeof (dyn_connect));
|
||||
|
||||
connect->srcpadname = srcpadname;
|
||||
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_element_get_name (previous),
|
||||
srcpadname,
|
||||
GST_DEBUG_PAD_NAME(GST_PARSE_LISTPAD(sinkpads)));
|
||||
srcpadname, GST_DEBUG_PAD_NAME (GST_PARSE_LISTPAD (sinkpads)));
|
||||
|
||||
g_signal_connect (G_OBJECT (previous), "new_pad",
|
||||
G_CALLBACK (dynamic_connect), connect);
|
||||
g_signal_connect (G_OBJECT (previous), "new_pad", G_CALLBACK (dynamic_connect), connect);
|
||||
}
|
||||
else {
|
||||
for (j = 0; (j < numsrcpads) && (j < numsinkpads); j++) {
|
||||
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 (sinkpads, j))));
|
||||
gst_pad_connect(
|
||||
GST_PARSE_LISTPAD(g_slist_nth(srcpads,j)),
|
||||
gst_pad_connect (GST_PARSE_LISTPAD (g_slist_nth (srcpads, 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);
|
||||
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 (elementcount == 1) {
|
||||
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) {
|
||||
temppad = GST_PAD (pads->data);
|
||||
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) {
|
||||
gst_element_add_ghost_pad (GST_ELEMENT (parent), temppad,
|
||||
g_strdup_printf ("%s-ghost", GST_PAD_NAME (temppad)));
|
||||
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;
|
||||
if (!GST_IS_BIN(element)) prevelement = element;
|
||||
if (!GST_IS_BIN (element))
|
||||
prevelement = element;
|
||||
}
|
||||
|
||||
i++;
|
||||
|
@ -444,7 +462,8 @@ g_strdup_printf("%s-ghost",GST_PAD_NAME(temppad)));
|
|||
while (pads) {
|
||||
temppad = GST_PAD (pads->data);
|
||||
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) {
|
||||
gst_element_add_ghost_pad (GST_ELEMENT (parent), 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--;
|
||||
|
||||
if (retval) return retval;
|
||||
if (retval)
|
||||
return retval;
|
||||
|
||||
DEBUG (closingchar != '\0'?
|
||||
"returning IN THE WRONG PLACE\n" :
|
||||
"ending pipeline\n");
|
||||
DEBUG (closingchar != '\0' ? "returning IN THE WRONG PLACE\n" : "ending pipeline\n");
|
||||
|
||||
return i + 1;
|
||||
}
|
||||
|
@ -553,6 +571,7 @@ gst_parse_launch(const gchar *cmdline,GstBin *parent)
|
|||
|
||||
// now allocate the new argv array
|
||||
argvn = g_new0 (char *, newargc);
|
||||
|
||||
GST_DEBUG (0, "got %d args\n", newargc);
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue