2001-01-07 04:00:30 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* 2000 Wim Taymans <wtay@chello.be>
|
|
|
|
*
|
|
|
|
* :
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define DEBUG(format,args...)
|
|
|
|
#define DEBUG_NOPREFIX(format,args...)
|
|
|
|
#define VERBOSE(format,args...)
|
|
|
|
|
2001-06-15 19:13:45 +00:00
|
|
|
#define GST_PARSE_LISTPAD(list) ((GstPad*)(list->data))
|
|
|
|
|
2001-01-07 04:00:30 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2001-01-20 02:57:46 +00:00
|
|
|
#include "gst_private.h"
|
2001-01-07 04:00:30 +00:00
|
|
|
#include "gstparse.h"
|
2001-01-29 00:06:02 +00:00
|
|
|
#include "gstpipeline.h"
|
|
|
|
#include "gstthread.h"
|
2001-03-03 16:30:10 +00:00
|
|
|
#include "gstutils.h"
|
2001-01-07 04:00:30 +00:00
|
|
|
|
|
|
|
typedef struct _gst_parse_priv gst_parse_priv;
|
2001-12-12 13:04:05 +00:00
|
|
|
struct _gst_parse_priv
|
|
|
|
{
|
2001-01-07 04:00:30 +00:00
|
|
|
guint bincount;
|
|
|
|
guint threadcount;
|
|
|
|
gint binlevel;
|
|
|
|
GHashTable *elementcounts;
|
|
|
|
gboolean verbose;
|
|
|
|
gboolean debug;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct _gst_parse_delayed_pad gst_parse_delayed_pad;
|
2001-12-12 13:04:05 +00:00
|
|
|
struct _gst_parse_delayed_pad
|
|
|
|
{
|
2001-01-07 04:00:30 +00:00
|
|
|
gchar *name;
|
|
|
|
GstPad *peer;
|
|
|
|
};
|
|
|
|
|
2001-12-12 13:04:05 +00:00
|
|
|
typedef struct
|
2001-01-07 04:00:30 +00:00
|
|
|
{
|
2001-05-03 21:44:55 +00:00
|
|
|
gchar *srcpadname;
|
|
|
|
GstPad *target;
|
2001-12-09 14:44:48 +00:00
|
|
|
GstElement *pipeline;
|
2001-06-04 15:38:44 +00:00
|
|
|
}
|
2001-12-12 13:04:05 +00:00
|
|
|
dyn_connect;
|
2001-06-04 15:38:44 +00:00
|
|
|
|
2001-05-03 21:44:55 +00:00
|
|
|
static void
|
2001-12-12 13:04:05 +00:00
|
|
|
dynamic_connect (GstElement * element, GstPad * newpad, gpointer data)
|
2001-05-03 21:44:55 +00:00
|
|
|
{
|
2001-12-12 13:04:05 +00:00
|
|
|
dyn_connect *connect = (dyn_connect *) data;
|
2001-05-03 21:44:55 +00:00
|
|
|
|
|
|
|
if (!strcmp (gst_pad_get_name (newpad), connect->srcpadname)) {
|
2001-12-09 14:44:48 +00:00
|
|
|
gst_element_set_state (connect->pipeline, GST_STATE_PAUSED);
|
2001-05-03 21:44:55 +00:00
|
|
|
gst_pad_connect (newpad, connect->target);
|
2001-12-09 14:44:48 +00:00
|
|
|
gst_element_set_state (connect->pipeline, GST_STATE_PLAYING);
|
2001-05-03 21:44:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-21 23:20:46 +00:00
|
|
|
static gchar *
|
2001-12-12 13:04:05 +00:00
|
|
|
gst_parse_unique_name (gchar * type, gst_parse_priv * priv)
|
2001-01-07 04:00:30 +00:00
|
|
|
{
|
2001-09-14 22:16:47 +00:00
|
|
|
gpointer tmp;
|
2001-01-07 04:00:30 +00:00
|
|
|
gint count;
|
|
|
|
|
2001-12-12 13:04:05 +00:00
|
|
|
tmp = g_hash_table_lookup (priv->elementcounts, type);
|
2001-09-14 22:16:47 +00:00
|
|
|
count = GPOINTER_TO_INT (tmp);
|
2001-01-07 04:00:30 +00:00
|
|
|
count++;
|
2001-12-12 13:04:05 +00:00
|
|
|
g_hash_table_insert (priv->elementcounts, type, GINT_TO_POINTER (count));
|
2001-01-07 04:00:30 +00:00
|
|
|
|
2001-12-12 13:04:05 +00:00
|
|
|
return g_strdup_printf ("%s%d", type, count - 1);
|
2001-01-07 04:00:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static gint
|
2001-12-12 13:04:05 +00:00
|
|
|
gst_parse_launch_cmdline (int argc, char *argv[], GstBin * parent, gst_parse_priv * priv)
|
2001-01-07 04:00:30 +00:00
|
|
|
{
|
2001-06-10 11:57:39 +00:00
|
|
|
gint i = 0, j = 0;
|
2001-01-07 04:00:30 +00:00
|
|
|
gchar *arg;
|
|
|
|
GstElement *element = NULL, *previous = NULL, *prevelement = NULL;
|
|
|
|
gchar closingchar = '\0';
|
|
|
|
gint len;
|
|
|
|
gchar *ptr;
|
2001-06-10 11:57:39 +00:00
|
|
|
gchar *sinkpadname = NULL, *srcpadname = NULL, *tempname;
|
2001-06-09 11:43:58 +00:00
|
|
|
GstPad *temppad;
|
|
|
|
GSList *sinkpads = NULL, *srcpads = NULL;
|
2001-06-10 11:57:39 +00:00
|
|
|
gint numsrcpads = 0, numsinkpads = 0;
|
2001-01-07 04:00:30 +00:00
|
|
|
GList *pads;
|
|
|
|
gint elementcount = 0;
|
|
|
|
gint retval = 0;
|
2001-01-07 07:45:54 +00:00
|
|
|
|
2001-01-20 02:57:46 +00:00
|
|
|
priv->binlevel++;
|
2001-01-07 04:00:30 +00:00
|
|
|
|
2001-12-12 13:04:05 +00:00
|
|
|
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)));
|
2001-01-20 02:57:46 +00:00
|
|
|
|
2001-01-07 04:00:30 +00:00
|
|
|
while (i < argc) {
|
|
|
|
arg = argv[i];
|
|
|
|
// FIXME this is a lame solution for problems with the first parser
|
2001-12-12 13:04:05 +00:00
|
|
|
if (arg == NULL) {
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
len = strlen (arg);
|
2001-01-07 04:00:30 +00:00
|
|
|
element = NULL;
|
2001-12-12 13:04:05 +00:00
|
|
|
DEBUG ("** ARGUMENT is '%s'\n", arg);
|
2001-01-20 02:57:46 +00:00
|
|
|
|
2001-01-07 04:00:30 +00:00
|
|
|
// a null that slipped through the reconstruction
|
|
|
|
if (len == 0) {
|
2001-12-12 13:04:05 +00:00
|
|
|
DEBUG ("random arg, FIXME\n");
|
2001-01-07 04:00:30 +00:00
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
|
2001-12-12 13:04:05 +00:00
|
|
|
// end of the container
|
|
|
|
}
|
|
|
|
else if (arg[0] == closingchar) {
|
2001-01-07 04:00:30 +00:00
|
|
|
// time to finish off this bin
|
2001-12-12 13:04:05 +00:00
|
|
|
DEBUG ("exiting container %s\n", GST_ELEMENT_NAME (GST_ELEMENT (parent)));
|
|
|
|
retval = i + 1;
|
2001-01-07 04:00:30 +00:00
|
|
|
break;
|
2001-01-20 02:57:46 +00:00
|
|
|
|
2001-12-12 13:04:05 +00:00
|
|
|
// a pad connection
|
|
|
|
}
|
|
|
|
else if ((ptr = strchr (arg, '!'))) {
|
|
|
|
DEBUG ("attempting to connect pads together....\n");
|
2001-01-07 04:00:30 +00:00
|
|
|
|
|
|
|
// if it starts with the !
|
|
|
|
if (arg[0] == '!') {
|
2001-12-12 13:04:05 +00:00
|
|
|
srcpadname = NULL;
|
|
|
|
// if there's a sinkpad...
|
|
|
|
if (len > 1)
|
|
|
|
sinkpadname = &arg[1];
|
|
|
|
else
|
|
|
|
sinkpadname = NULL;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
srcpadname = g_strndup (arg, (ptr - arg));
|
|
|
|
// if there's a sinkpad
|
|
|
|
if (len > (ptr - arg) + 1)
|
|
|
|
sinkpadname = &ptr[1];
|
|
|
|
else
|
|
|
|
sinkpadname = NULL;
|
2001-01-07 04:00:30 +00:00
|
|
|
}
|
2001-01-20 02:57:46 +00:00
|
|
|
|
2001-12-12 13:04:05 +00:00
|
|
|
GST_DEBUG (0, "have srcpad %s, sinkpad %s\n", srcpadname, sinkpadname);
|
2001-01-20 02:57:46 +00:00
|
|
|
|
2001-12-12 13:04:05 +00:00
|
|
|
g_slist_free (srcpads);
|
2001-06-09 11:43:58 +00:00
|
|
|
srcpads = NULL;
|
2001-12-12 13:04:05 +00:00
|
|
|
numsrcpads = 0;
|
|
|
|
tempname = NULL;
|
2001-06-10 11:57:39 +00:00
|
|
|
|
|
|
|
// find src pads
|
|
|
|
if (srcpadname != NULL) {
|
2001-12-12 13:04:05 +00:00
|
|
|
while (1) {
|
|
|
|
// split name at commas
|
|
|
|
if ((ptr = strchr (srcpadname, ','))) {
|
|
|
|
tempname = g_strndup (srcpadname, (ptr - srcpadname));
|
|
|
|
srcpadname = &ptr[1];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tempname = srcpadname;
|
|
|
|
}
|
|
|
|
|
|
|
|
// look for pad with that name
|
|
|
|
if ((temppad = gst_element_get_pad (previous, tempname))) {
|
|
|
|
srcpads = g_slist_append (srcpads, temppad);
|
|
|
|
numsrcpads++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// try to create a pad using that padtemplate name
|
|
|
|
else if ((temppad = gst_element_request_pad_by_name (previous, tempname))) {
|
|
|
|
srcpads = g_slist_append (srcpads, temppad);
|
|
|
|
numsrcpads++;
|
|
|
|
}
|
|
|
|
if (!temppad) {
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
// if there is no more commas in srcpadname then we're done
|
|
|
|
if (tempname == srcpadname)
|
|
|
|
break;
|
|
|
|
g_free (tempname);
|
|
|
|
}
|
2001-06-10 11:57:39 +00:00
|
|
|
}
|
|
|
|
else {
|
2001-12-12 13:04:05 +00:00
|
|
|
// 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);
|
|
|
|
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_pad_get_direction (temppad) == GST_PAD_SRC) {
|
|
|
|
srcpads = g_slist_append (srcpads, temppad);
|
|
|
|
numsrcpads++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
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)));
|
2001-01-07 04:00:30 +00:00
|
|
|
}
|
|
|
|
|
2001-12-12 13:04:05 +00:00
|
|
|
// argument with = in it
|
|
|
|
}
|
|
|
|
else if (strstr (arg, "=")) {
|
|
|
|
gchar *argname;
|
|
|
|
gchar *argval;
|
|
|
|
gchar *pos = strstr (arg, "=");
|
|
|
|
|
2001-01-07 04:00:30 +00:00
|
|
|
// we have an argument
|
|
|
|
argname = arg;
|
|
|
|
pos[0] = '\0';
|
2001-12-12 13:04:05 +00:00
|
|
|
argval = pos + 1;
|
|
|
|
|
|
|
|
GST_DEBUG (0, "attempting to set argument '%s' to '%s' on element '%s'\n",
|
|
|
|
argname, argval, GST_ELEMENT_NAME (previous));
|
|
|
|
gst_util_set_object_arg (G_OBJECT (previous), argname, argval);
|
|
|
|
g_free (argname);
|
|
|
|
|
|
|
|
// element or argument, or beginning of bin or thread
|
|
|
|
}
|
|
|
|
else if (arg[0] == '[') {
|
2001-06-29 17:53:02 +00:00
|
|
|
// we have the start of a name of the preceding element.
|
|
|
|
// rename previous element to next arg.
|
|
|
|
if (arg[1] != '\0') {
|
2001-12-12 13:04:05 +00:00
|
|
|
fprintf (stderr, "error, unexpected junk after [\n");
|
|
|
|
return GST_PARSE_ERROR_SYNTAX;
|
2001-06-29 17:53:02 +00:00
|
|
|
}
|
|
|
|
i++;
|
|
|
|
if (i < argc) {
|
2001-12-12 13:04:05 +00:00
|
|
|
gst_element_set_name (previous, argv[i]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fprintf (stderr, "error, expected element name, found end of arguments\n");
|
|
|
|
return GST_PARSE_ERROR_SYNTAX;
|
2001-06-29 17:53:02 +00:00
|
|
|
}
|
|
|
|
i++;
|
|
|
|
if (i >= argc) {
|
2001-12-12 13:04:05 +00:00
|
|
|
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;
|
2001-06-29 17:53:02 +00:00
|
|
|
}
|
2001-12-12 13:04:05 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
DEBUG ("have element or bin/thread\n");
|
2001-01-07 04:00:30 +00:00
|
|
|
// if we have a bin or thread starting
|
2001-12-12 13:04:05 +00:00
|
|
|
if (strchr ("({", arg[0])) {
|
|
|
|
if (arg[0] == '(') {
|
|
|
|
// create a bin and add it to the current parent
|
|
|
|
element = gst_bin_new (g_strdup_printf ("bin%d", priv->bincount++));
|
|
|
|
if (!element) {
|
|
|
|
fprintf (stderr, "Couldn't create a bin!\n");
|
|
|
|
return GST_PARSE_ERROR_CREATING_ELEMENT;
|
|
|
|
}
|
|
|
|
GST_DEBUG (0, "CREATED bin %s\n", GST_ELEMENT_NAME (element));
|
|
|
|
}
|
|
|
|
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) {
|
|
|
|
fprintf (stderr, "Couldn't create a thread!\n");
|
|
|
|
return GST_PARSE_ERROR_CREATING_ELEMENT;
|
|
|
|
}
|
|
|
|
GST_DEBUG (0, "CREATED thread %s\n", GST_ELEMENT_NAME (element));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
DEBUG ("error in parser, unexpected symbol, FIXME\n");
|
2001-06-29 17:53:02 +00:00
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
2001-01-07 04:00:30 +00:00
|
|
|
|
2001-12-12 13:04:05 +00:00
|
|
|
j = gst_parse_launch_cmdline (argc - i, argv + i + 1, GST_BIN (element), priv);
|
|
|
|
//check for parse error
|
|
|
|
if (j < 0)
|
|
|
|
return j;
|
|
|
|
i += j;
|
|
|
|
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// we have an element
|
|
|
|
DEBUG ("attempting to create element '%s'\n", arg);
|
|
|
|
ptr = gst_parse_unique_name (arg, priv);
|
|
|
|
element = gst_elementfactory_make (arg, ptr);
|
|
|
|
g_free (ptr);
|
|
|
|
if (!element) {
|
2001-10-17 10:21:27 +00:00
|
|
|
#ifndef GST_DISABLE_REGISTRY
|
2001-12-12 13:04:05 +00:00
|
|
|
fprintf (stderr,
|
|
|
|
"Couldn't create a '%s', no such element or need to run gstreamer-register?\n",
|
|
|
|
arg);
|
2001-10-17 10:21:27 +00:00
|
|
|
#else
|
2001-12-12 13:04:05 +00:00
|
|
|
fprintf (stderr, "Couldn't create a '%s', no such element or need to load pluginn?\n",
|
|
|
|
arg);
|
2001-10-17 10:21:27 +00:00
|
|
|
#endif
|
2001-12-12 13:04:05 +00:00
|
|
|
return GST_PARSE_ERROR_NOSUCH_ELEMENT;
|
|
|
|
}
|
|
|
|
GST_DEBUG (0, "CREATED element %s\n", GST_ELEMENT_NAME (element));
|
2001-01-07 04:00:30 +00:00
|
|
|
}
|
2001-01-20 02:57:46 +00:00
|
|
|
|
2001-01-07 04:00:30 +00:00
|
|
|
gst_bin_add (GST_BIN (parent), element);
|
|
|
|
elementcount++;
|
2001-01-20 02:57:46 +00:00
|
|
|
|
2001-12-12 13:04:05 +00:00
|
|
|
g_slist_free (sinkpads);
|
2001-06-15 06:33:29 +00:00
|
|
|
sinkpads = NULL;
|
2001-12-12 13:04:05 +00:00
|
|
|
numsinkpads = 0;
|
|
|
|
tempname = NULL;
|
2001-06-15 06:33:29 +00:00
|
|
|
|
|
|
|
// find sink pads
|
|
|
|
if (sinkpadname != NULL) {
|
2001-12-12 13:04:05 +00:00
|
|
|
while (1) {
|
|
|
|
// split name at commas
|
|
|
|
if ((ptr = strchr (sinkpadname, ','))) {
|
|
|
|
tempname = g_strndup (sinkpadname, (ptr - sinkpadname));
|
|
|
|
sinkpadname = &ptr[1];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tempname = sinkpadname;
|
|
|
|
}
|
|
|
|
|
|
|
|
// look for pad with that name
|
|
|
|
if ((temppad = gst_element_get_pad (element, tempname))) {
|
|
|
|
sinkpads = g_slist_append (sinkpads, temppad);
|
|
|
|
numsinkpads++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// try to create a pad using that padtemplate name
|
|
|
|
else if ((temppad = gst_element_request_pad_by_name (element, tempname))) {
|
|
|
|
sinkpads = g_slist_append (sinkpads, temppad);
|
|
|
|
numsinkpads++;
|
|
|
|
}
|
|
|
|
if (!temppad) {
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
// if there is no more commas in sinkpadname then we're done
|
|
|
|
if (tempname == sinkpadname)
|
|
|
|
break;
|
|
|
|
g_free (tempname);
|
|
|
|
}
|
2001-06-15 06:33:29 +00:00
|
|
|
}
|
|
|
|
else {
|
2001-12-12 13:04:05 +00:00
|
|
|
// check through the list to find the first sink pad
|
|
|
|
pads = gst_element_get_pad_list (element);
|
|
|
|
while (pads) {
|
|
|
|
temppad = GST_PAD (pads->data);
|
|
|
|
pads = g_list_next (pads);
|
|
|
|
if (gst_pad_get_direction (temppad) == GST_PAD_SINK) {
|
|
|
|
sinkpads = g_slist_append (sinkpads, temppad);
|
|
|
|
numsinkpads++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2001-06-15 06:33:29 +00:00
|
|
|
}
|
2001-01-20 02:57:46 +00:00
|
|
|
|
2001-12-12 13:04:05 +00:00
|
|
|
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)));
|
2001-01-20 02:57:46 +00:00
|
|
|
|
2001-06-15 19:13:45 +00:00
|
|
|
if (!srcpads && sinkpads && previous) {
|
2001-12-12 13:04:05 +00:00
|
|
|
dyn_connect *connect = g_malloc (sizeof (dyn_connect));
|
2001-05-03 21:44:55 +00:00
|
|
|
|
2001-12-12 13:04:05 +00:00
|
|
|
connect->srcpadname = srcpadname;
|
|
|
|
connect->target = GST_PARSE_LISTPAD (sinkpads);
|
|
|
|
connect->pipeline = GST_ELEMENT (parent);
|
2001-05-03 21:44:55 +00:00
|
|
|
|
2001-12-12 13:04:05 +00:00
|
|
|
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)));
|
2001-05-03 21:44:55 +00:00
|
|
|
|
2001-12-12 13:04:05 +00:00
|
|
|
g_signal_connect (G_OBJECT (previous), "new_pad", G_CALLBACK (dynamic_connect), connect);
|
2001-06-15 06:33:29 +00:00
|
|
|
}
|
|
|
|
else {
|
2001-12-12 13:04:05 +00:00
|
|
|
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_PARSE_LISTPAD (g_slist_nth (sinkpads, j)));
|
|
|
|
}
|
2001-01-07 04:00:30 +00:00
|
|
|
}
|
2001-12-12 13:04:05 +00:00
|
|
|
|
|
|
|
g_slist_free (srcpads);
|
2001-06-15 06:33:29 +00:00
|
|
|
srcpads = NULL;
|
2001-01-20 02:57:46 +00:00
|
|
|
|
2001-12-12 13:04:05 +00:00
|
|
|
g_slist_free (sinkpads);
|
|
|
|
sinkpads = NULL;
|
2001-06-04 15:38:44 +00:00
|
|
|
|
2001-01-07 04:00:30 +00:00
|
|
|
// if we're the first element, ghost all the sinkpads
|
|
|
|
if (elementcount == 1) {
|
2001-12-12 13:04:05 +00:00
|
|
|
DEBUG ("first element, ghosting all of %s's sink pads to parent %s\n",
|
|
|
|
GST_ELEMENT_NAME (element), GST_ELEMENT_NAME (GST_ELEMENT (parent)));
|
|
|
|
pads = gst_element_get_pad_list (element);
|
|
|
|
while (pads) {
|
|
|
|
temppad = GST_PAD (pads->data);
|
|
|
|
pads = g_list_next (pads);
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|
2001-01-07 04:00:30 +00:00
|
|
|
}
|
|
|
|
|
2001-01-20 02:57:46 +00:00
|
|
|
previous = element;
|
2001-12-12 13:04:05 +00:00
|
|
|
if (!GST_IS_BIN (element))
|
|
|
|
prevelement = element;
|
2001-01-07 04:00:30 +00:00
|
|
|
}
|
2001-01-20 02:57:46 +00:00
|
|
|
|
2001-01-07 04:00:30 +00:00
|
|
|
i++;
|
|
|
|
}
|
2001-01-20 02:57:46 +00:00
|
|
|
|
2001-01-07 04:00:30 +00:00
|
|
|
// ghost all the src pads of the bin
|
|
|
|
if (prevelement != NULL) {
|
2001-12-12 13:04:05 +00:00
|
|
|
DEBUG ("last element, ghosting all of %s's src pads to parent %s\n",
|
|
|
|
GST_ELEMENT_NAME (prevelement), GST_ELEMENT_NAME (GST_ELEMENT (parent)));
|
2001-01-07 04:00:30 +00:00
|
|
|
pads = gst_element_get_pad_list (prevelement);
|
|
|
|
while (pads) {
|
2001-06-09 11:43:58 +00:00
|
|
|
temppad = GST_PAD (pads->data);
|
2001-01-07 04:00:30 +00:00
|
|
|
pads = g_list_next (pads);
|
2001-12-12 13:04:05 +00:00
|
|
|
if (!temppad)
|
|
|
|
DEBUG ("much oddness, pad doesn't seem to exist\n");
|
2001-06-09 11:43:58 +00:00
|
|
|
else if (gst_pad_get_direction (temppad) == GST_PAD_SRC) {
|
2001-12-12 13:04:05 +00:00
|
|
|
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 (parent), GST_PAD_NAME (temppad));
|
2001-01-07 04:00:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-01-20 02:57:46 +00:00
|
|
|
|
2001-01-07 04:00:30 +00:00
|
|
|
priv->binlevel--;
|
2001-01-20 02:57:46 +00:00
|
|
|
|
2001-12-12 13:04:05 +00:00
|
|
|
if (retval)
|
|
|
|
return retval;
|
2001-01-20 02:57:46 +00:00
|
|
|
|
2001-12-12 13:04:05 +00:00
|
|
|
DEBUG (closingchar != '\0' ? "returning IN THE WRONG PLACE\n" : "ending pipeline\n");
|
2001-09-14 22:16:47 +00:00
|
|
|
|
2001-12-12 13:04:05 +00:00
|
|
|
return i + 1;
|
2001-01-20 02:57:46 +00:00
|
|
|
}
|
2001-01-07 04:00:30 +00:00
|
|
|
|
2001-01-21 23:20:46 +00:00
|
|
|
/**
|
|
|
|
* gst_parse_launch:
|
|
|
|
* @cmdline: the command line describing the pipeline
|
|
|
|
* @parent: the parent bin for the resulting pipeline
|
|
|
|
*
|
|
|
|
* Create a new pipeline based on command line syntax.
|
|
|
|
*
|
|
|
|
* Returns: ?
|
|
|
|
*/
|
|
|
|
gint
|
2001-12-12 13:04:05 +00:00
|
|
|
gst_parse_launch (const gchar * cmdline, GstBin * parent)
|
2001-01-21 23:20:46 +00:00
|
|
|
{
|
2001-01-07 04:00:30 +00:00
|
|
|
gst_parse_priv priv;
|
|
|
|
gchar **argvn;
|
|
|
|
gint newargc;
|
2001-03-06 20:04:42 +00:00
|
|
|
gint i;
|
|
|
|
const gchar *cp, *start, *end;
|
2001-05-20 20:05:29 +00:00
|
|
|
gchar *temp;
|
2001-03-06 20:04:42 +00:00
|
|
|
GSList *string_list = NULL, *slist;
|
2001-01-07 04:00:30 +00:00
|
|
|
|
|
|
|
priv.bincount = 0;
|
|
|
|
priv.threadcount = 0;
|
|
|
|
priv.binlevel = 0;
|
|
|
|
priv.elementcounts = NULL;
|
|
|
|
priv.verbose = FALSE;
|
|
|
|
priv.debug = FALSE;
|
|
|
|
|
2001-12-12 13:04:05 +00:00
|
|
|
end = cmdline + strlen (cmdline);
|
2001-03-06 20:04:42 +00:00
|
|
|
newargc = 0;
|
|
|
|
|
2001-05-20 20:05:29 +00:00
|
|
|
temp = "";
|
|
|
|
|
2001-03-06 20:04:42 +00:00
|
|
|
// Extract the arguments to a gslist in reverse order
|
2001-12-12 13:04:05 +00:00
|
|
|
for (cp = cmdline; cp < end;) {
|
|
|
|
i = strcspn (cp, "([{}]) \"\\");
|
2001-03-06 20:04:42 +00:00
|
|
|
|
|
|
|
if (i > 0) {
|
2001-05-20 20:05:29 +00:00
|
|
|
temp = g_strconcat (temp, g_strndup (cp, i), NULL);
|
2001-12-12 13:04:05 +00:00
|
|
|
|
2001-05-20 20:05:29 +00:00
|
|
|
// see if we have an escape char
|
|
|
|
if (cp[i] != '\\') {
|
2001-12-12 13:04:05 +00:00
|
|
|
// normal argument - copy and add to the list
|
|
|
|
string_list = g_slist_prepend (string_list, temp);
|
|
|
|
newargc++;
|
2001-05-20 20:05:29 +00:00
|
|
|
temp = "";
|
|
|
|
}
|
|
|
|
else {
|
2001-12-12 13:04:05 +00:00
|
|
|
temp = g_strconcat (temp, g_strndup (&cp[++i], 1), NULL);
|
2001-05-20 20:05:29 +00:00
|
|
|
}
|
2001-03-06 20:04:42 +00:00
|
|
|
cp += i;
|
2001-01-07 04:00:30 +00:00
|
|
|
}
|
|
|
|
|
2001-03-06 20:04:42 +00:00
|
|
|
// skip spaces
|
2001-05-20 20:05:29 +00:00
|
|
|
while (cp < end && *cp == ' ') {
|
2001-03-06 20:04:42 +00:00
|
|
|
cp++;
|
2001-05-20 20:05:29 +00:00
|
|
|
}
|
2001-03-06 20:04:42 +00:00
|
|
|
|
|
|
|
// handle quoted arguments
|
|
|
|
if (*cp == '"') {
|
|
|
|
start = ++cp;
|
2001-01-07 04:00:30 +00:00
|
|
|
|
2001-03-06 20:04:42 +00:00
|
|
|
// find matching quote
|
|
|
|
while (cp < end && *cp != '"')
|
|
|
|
cp++;
|
|
|
|
|
|
|
|
// make sure we got it
|
|
|
|
if (cp == end) {
|
2001-12-12 13:04:05 +00:00
|
|
|
g_warning ("gst_parse_launch: Unbalanced quote in command line");
|
2001-03-06 20:04:42 +00:00
|
|
|
// FIXME: The list leaks here
|
|
|
|
return 0;
|
2001-01-07 04:00:30 +00:00
|
|
|
}
|
2001-03-06 20:04:42 +00:00
|
|
|
|
|
|
|
// copy the string sans quotes
|
2001-12-12 13:04:05 +00:00
|
|
|
string_list = g_slist_prepend (string_list, g_strndup (start, cp - start));
|
2001-03-06 20:04:42 +00:00
|
|
|
newargc++;
|
2001-12-12 13:04:05 +00:00
|
|
|
cp += 2; // skip the quote aswell
|
2001-03-06 20:04:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// brackets exist in a separate argument slot
|
2001-12-12 13:04:05 +00:00
|
|
|
if (*cp && strchr ("([{}])", *cp)) {
|
|
|
|
string_list = g_slist_prepend (string_list, g_strndup (cp, 1));
|
2001-03-06 20:04:42 +00:00
|
|
|
newargc++;
|
|
|
|
cp++;
|
2001-01-07 04:00:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-06 20:04:42 +00:00
|
|
|
// now allocate the new argv array
|
2001-12-12 13:04:05 +00:00
|
|
|
argvn = g_new0 (char *, newargc);
|
|
|
|
|
|
|
|
GST_DEBUG (0, "got %d args\n", newargc);
|
2001-03-06 20:04:42 +00:00
|
|
|
|
|
|
|
// reverse the list and put the strings in the new array
|
|
|
|
i = newargc;
|
|
|
|
|
|
|
|
for (slist = string_list; slist; slist = slist->next)
|
|
|
|
argvn[--i] = slist->data;
|
|
|
|
|
2001-12-12 13:04:05 +00:00
|
|
|
g_slist_free (string_list);
|
2001-03-06 20:04:42 +00:00
|
|
|
|
2001-01-07 04:00:30 +00:00
|
|
|
// print them out
|
2001-12-12 13:04:05 +00:00
|
|
|
for (i = 0; i < newargc; i++) {
|
|
|
|
GST_DEBUG (0, "arg %d is: %s\n", i, argvn[i]);
|
2001-01-07 04:00:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// set up the elementcounts hash
|
2001-12-12 13:04:05 +00:00
|
|
|
priv.elementcounts = g_hash_table_new (g_str_hash, g_str_equal);
|
2001-01-07 04:00:30 +00:00
|
|
|
|
2001-03-06 20:04:42 +00:00
|
|
|
// do it!
|
2001-12-12 13:04:05 +00:00
|
|
|
i = gst_parse_launch_cmdline (newargc, argvn, parent, &priv);
|
2001-03-06 20:04:42 +00:00
|
|
|
|
|
|
|
// GST_DEBUG(0, "Finished - freeing temporary argument array");
|
|
|
|
// g_strfreev(argvn);
|
|
|
|
|
|
|
|
return i;
|
2001-01-07 04:00:30 +00:00
|
|
|
}
|