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.
|
|
|
|
*/
|
|
|
|
|
2002-01-14 04:09:56 +00:00
|
|
|
/* #define DEBUG(format,args...) g_print (format, ##args) */
|
2001-01-07 04:00:30 +00:00
|
|
|
#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;
|
|
|
|
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);
|
2002-01-18 22:44:19 +00:00
|
|
|
if (!gst_pad_connect (newpad, connect->target))
|
|
|
|
g_warning ("could not connect %s:%s to %s:%s", GST_DEBUG_PAD_NAME (newpad),
|
|
|
|
GST_DEBUG_PAD_NAME (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-07 04:00:30 +00:00
|
|
|
static gint
|
2002-01-14 04:09:56 +00:00
|
|
|
gst_parse_launchv_recurse (const gchar **argv, GstBin * parent, gst_parse_priv * priv)
|
2001-01-07 04:00:30 +00:00
|
|
|
{
|
2002-01-14 04:09:56 +00:00
|
|
|
gint i = -1, j = 0;
|
|
|
|
const gchar *arg;
|
2001-01-07 04:00:30 +00:00
|
|
|
GstElement *element = NULL, *previous = NULL, *prevelement = NULL;
|
|
|
|
gchar closingchar = '\0';
|
|
|
|
gint len;
|
2002-01-14 04:09:56 +00:00
|
|
|
const gchar *cptr;
|
2001-01-07 04:00:30 +00:00
|
|
|
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-12-22 21:18:17 +00:00
|
|
|
gboolean backref = FALSE;
|
2001-01-07 07:45:54 +00:00
|
|
|
|
2002-01-14 04:09:56 +00:00
|
|
|
if (!priv) {
|
|
|
|
priv = g_new0 (gst_parse_priv, 1);
|
|
|
|
}
|
|
|
|
|
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 ");
|
2002-01-14 04:09:56 +00:00
|
|
|
} else if (GST_IS_THREAD (parent)) {
|
2001-12-12 13:04:05 +00:00
|
|
|
closingchar = '}';
|
|
|
|
DEBUG ("in thread ");
|
2002-01-14 04:09:56 +00:00
|
|
|
} else {
|
2001-12-12 13:04:05 +00:00
|
|
|
closingchar = ')';
|
|
|
|
DEBUG ("in bin ");
|
|
|
|
}
|
|
|
|
DEBUG_NOPREFIX ("%s\n", GST_ELEMENT_NAME (GST_ELEMENT (parent)));
|
2001-01-20 02:57:46 +00:00
|
|
|
|
2002-01-14 04:09:56 +00:00
|
|
|
while ((arg = argv[++i])) {
|
2001-12-12 13:04:05 +00:00
|
|
|
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
|
|
|
if (len == 0) {
|
2001-12-12 13:04:05 +00:00
|
|
|
DEBUG ("random arg, FIXME\n");
|
2001-01-07 04:00:30 +00:00
|
|
|
|
2002-01-14 04:09:56 +00:00
|
|
|
continue;
|
|
|
|
} else if (arg[0] == closingchar) {
|
2001-12-12 13:04:05 +00:00
|
|
|
DEBUG ("exiting container %s\n", GST_ELEMENT_NAME (GST_ELEMENT (parent)));
|
2002-01-14 04:09:56 +00:00
|
|
|
|
2001-12-12 13:04:05 +00:00
|
|
|
retval = i + 1;
|
2001-01-07 04:00:30 +00:00
|
|
|
break;
|
2002-01-14 04:09:56 +00:00
|
|
|
} else if ((cptr = strchr (arg, '!'))) {
|
2001-12-12 13:04:05 +00:00
|
|
|
DEBUG ("attempting to connect pads together....\n");
|
2001-01-07 04:00:30 +00:00
|
|
|
|
2001-12-14 22:59:21 +00:00
|
|
|
/* if it starts with the ! */
|
2001-01-07 04:00:30 +00:00
|
|
|
if (arg[0] == '!') {
|
2001-12-12 13:04:05 +00:00
|
|
|
srcpadname = NULL;
|
2001-12-14 22:59:21 +00:00
|
|
|
/* if there's a sinkpad... */
|
2001-12-12 13:04:05 +00:00
|
|
|
if (len > 1)
|
2002-01-14 04:09:56 +00:00
|
|
|
sinkpadname = g_strdup (&arg[1]);
|
2001-12-12 13:04:05 +00:00
|
|
|
else
|
|
|
|
sinkpadname = NULL;
|
2002-01-14 04:09:56 +00:00
|
|
|
} else {
|
|
|
|
srcpadname = g_strndup (arg, (cptr - arg));
|
2001-12-14 22:59:21 +00:00
|
|
|
/* if there's a sinkpad */
|
2002-01-14 04:09:56 +00:00
|
|
|
if (len > (cptr - arg) + 1)
|
|
|
|
sinkpadname = g_strdup(&cptr[1]);
|
2001-12-12 13:04:05 +00:00
|
|
|
else
|
|
|
|
sinkpadname = NULL;
|
2001-01-07 04:00:30 +00:00
|
|
|
}
|
2001-01-20 02:57:46 +00:00
|
|
|
|
2001-12-17 14:18:03 +00:00
|
|
|
if (srcpadname && (ptr = strchr (srcpadname, '.'))) {
|
2002-01-14 04:09:56 +00:00
|
|
|
gchar *element_name = srcpadname;
|
2001-12-17 14:18:03 +00:00
|
|
|
GstElement *new;
|
|
|
|
|
2002-01-14 04:09:56 +00:00
|
|
|
*ptr = '\0'; /* it was a '.' before */
|
|
|
|
|
2001-12-17 14:18:03 +00:00
|
|
|
GST_DEBUG (0, "have pad for element %s\n", element_name);
|
2001-12-22 21:18:17 +00:00
|
|
|
new = gst_bin_get_by_name_recurse_up (parent, element_name);
|
2001-12-17 14:18:03 +00:00
|
|
|
if (!new) {
|
2002-01-14 04:09:56 +00:00
|
|
|
GST_DEBUG (0, "element %s does not exist! trying to continue\n", element_name);
|
|
|
|
} else {
|
|
|
|
previous = new;
|
2001-12-17 14:18:03 +00:00
|
|
|
srcpadname = ptr + 1;
|
2001-12-22 21:18:17 +00:00
|
|
|
backref = TRUE;
|
2001-12-17 14:18:03 +00:00
|
|
|
}
|
|
|
|
}
|
2002-01-14 04:09:56 +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
|
|
|
|
2001-12-14 22:59:21 +00:00
|
|
|
/* find src pads */
|
2001-06-10 11:57:39 +00:00
|
|
|
if (srcpadname != NULL) {
|
2001-12-12 13:04:05 +00:00
|
|
|
while (1) {
|
2001-12-14 22:59:21 +00:00
|
|
|
/* split name at commas */
|
2001-12-12 13:04:05 +00:00
|
|
|
if ((ptr = strchr (srcpadname, ','))) {
|
2002-01-14 04:09:56 +00:00
|
|
|
tempname = srcpadname;
|
2001-12-12 13:04:05 +00:00
|
|
|
srcpadname = &ptr[1];
|
2002-01-14 04:09:56 +00:00
|
|
|
*ptr = '\0';
|
|
|
|
} else {
|
2001-12-12 13:04:05 +00:00
|
|
|
tempname = srcpadname;
|
|
|
|
}
|
|
|
|
|
2001-12-14 22:59:21 +00:00
|
|
|
/* look for pad with that name */
|
2001-12-12 13:04:05 +00:00
|
|
|
if ((temppad = gst_element_get_pad (previous, tempname))) {
|
|
|
|
srcpads = g_slist_append (srcpads, temppad);
|
|
|
|
numsrcpads++;
|
|
|
|
}
|
|
|
|
|
2001-12-14 22:59:21 +00:00
|
|
|
/* try to create a pad using that padtemplate name */
|
2001-12-12 13:04:05 +00:00
|
|
|
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));
|
2002-01-14 04:09:56 +00:00
|
|
|
} else {
|
2001-12-12 13:04:05 +00:00
|
|
|
GST_DEBUG (0, "have src pad %s:%s\n", GST_DEBUG_PAD_NAME (temppad));
|
|
|
|
}
|
|
|
|
|
2001-12-14 22:59:21 +00:00
|
|
|
/* if there is no more commas in srcpadname then we're done */
|
2001-12-12 13:04:05 +00:00
|
|
|
if (tempname == srcpadname)
|
|
|
|
break;
|
|
|
|
g_free (tempname);
|
|
|
|
}
|
2002-01-14 04:09:56 +00:00
|
|
|
} else {
|
|
|
|
/* check through the list to find the first src pad */
|
|
|
|
GST_DEBUG (0, "CHECKING element %s for pad named %s\n", GST_ELEMENT_NAME (previous),
|
2001-12-12 13:04:05 +00:00
|
|
|
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
|
|
|
}
|
2002-01-14 04:09:56 +00:00
|
|
|
} else if (strchr (arg, '=')) {
|
|
|
|
gchar *propname;
|
|
|
|
gchar *propval;
|
|
|
|
gchar *pos;
|
|
|
|
|
|
|
|
DEBUG ("have a property\n");
|
|
|
|
|
|
|
|
/* we have a property */
|
|
|
|
propname = g_strdup (arg);
|
|
|
|
pos = strchr (propname, '=');
|
|
|
|
*pos = '\0';
|
|
|
|
propval = pos + 1;
|
|
|
|
|
|
|
|
/* use g_object_set in the future when gst_util_{set|get} go away */
|
|
|
|
GST_DEBUG (0, "attempting to set property '%s' to '%s' on element '%s'\n",
|
|
|
|
propname, propval, GST_ELEMENT_NAME (previous));
|
|
|
|
gst_util_set_object_arg (G_OBJECT (previous), propname, propval);
|
|
|
|
g_free (propname);
|
|
|
|
} else if (arg[0] == '[') {
|
|
|
|
DEBUG ("have element name\n");
|
|
|
|
|
2001-06-29 17:53:02 +00:00
|
|
|
if (arg[1] != '\0') {
|
2002-01-14 04:09:56 +00:00
|
|
|
fprintf (stderr, "error, unexpected junk after [\n");
|
|
|
|
return GST_PARSE_ERROR_SYNTAX;
|
2001-12-12 13:04:05 +00:00
|
|
|
}
|
2002-01-14 04:09:56 +00:00
|
|
|
|
|
|
|
if ((arg = argv[++i])) {
|
|
|
|
if (!previous) {
|
|
|
|
g_critical("parser error, please report");
|
|
|
|
return GST_PARSE_ERROR_INTERNAL;
|
|
|
|
}
|
|
|
|
gst_element_set_name (previous, arg);
|
|
|
|
} else {
|
|
|
|
fprintf (stderr, "error, expected element name, found end of arguments\n");
|
|
|
|
return GST_PARSE_ERROR_SYNTAX;
|
2001-12-12 13:04:05 +00:00
|
|
|
}
|
2002-01-14 04:09:56 +00:00
|
|
|
|
|
|
|
if ((arg = argv[++i])) {
|
|
|
|
if (strcmp (arg, "]") != 0) {
|
|
|
|
fprintf (stderr, "error, expected ], found '%s'\n", arg);
|
|
|
|
return GST_PARSE_ERROR_SYNTAX;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fprintf (stderr, "error, expected ], found end of arguments\n");
|
|
|
|
return GST_PARSE_ERROR_SYNTAX;
|
2001-06-29 17:53:02 +00:00
|
|
|
}
|
2002-01-14 04:09:56 +00:00
|
|
|
} else {
|
|
|
|
/* we have an element, a bin, or a thread. we treat these together because
|
|
|
|
* once we rech them we have to resolve any dangling connections from
|
|
|
|
* previous array arguments. */
|
|
|
|
|
2001-12-12 13:04:05 +00:00
|
|
|
if (strchr ("({", arg[0])) {
|
2002-01-14 04:09:56 +00:00
|
|
|
DEBUG ("have bin or thread\n");
|
|
|
|
|
|
|
|
if (arg[0] == '(') {
|
|
|
|
/* create a bin and add it to the current parent */
|
2002-02-20 21:31:16 +00:00
|
|
|
priv->bincount++;
|
|
|
|
element = gst_elementfactory_make ("bin", NULL);
|
2002-01-14 04:09:56 +00:00
|
|
|
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 */
|
2002-02-20 21:31:16 +00:00
|
|
|
priv->threadcount++;
|
|
|
|
element = gst_elementfactory_make ("thread", NULL);
|
2002-01-14 04:09:56 +00:00
|
|
|
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 {
|
|
|
|
fprintf (stderr, "Illegal argument: %s\n", arg);
|
|
|
|
return GST_PARSE_ERROR_CREATING_ELEMENT;
|
|
|
|
}
|
|
|
|
|
2001-12-22 21:18:17 +00:00
|
|
|
gst_bin_add (GST_BIN (parent), element);
|
2002-01-14 04:09:56 +00:00
|
|
|
|
|
|
|
j = gst_parse_launchv_recurse (argv + i + 1, GST_BIN (element), priv);
|
|
|
|
/* check for parse error */
|
|
|
|
if (j < 0)
|
|
|
|
return j;
|
|
|
|
|
|
|
|
/* we will get autoincremented at the while */
|
|
|
|
i += j;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
/* we have an element */
|
|
|
|
DEBUG ("attempting to create element '%s'\n", arg);
|
|
|
|
|
2002-02-20 21:31:16 +00:00
|
|
|
element = gst_elementfactory_make (arg, NULL);
|
2002-01-14 04:09:56 +00:00
|
|
|
if (!element) {
|
2001-10-17 10:21:27 +00:00
|
|
|
#ifndef GST_DISABLE_REGISTRY
|
2002-01-14 04:09:56 +00:00
|
|
|
fprintf (stderr,
|
|
|
|
"Couldn't create a '%s', no such element or need to run gst-register?\n", arg);
|
2001-10-17 10:21:27 +00:00
|
|
|
#else
|
2002-01-14 04:09:56 +00:00
|
|
|
fprintf (stderr, "Couldn't create a '%s', no such element or need to load plugin?\n",
|
|
|
|
arg);
|
2001-10-17 10:21:27 +00:00
|
|
|
#endif
|
2002-01-14 04:09:56 +00:00
|
|
|
return GST_PARSE_ERROR_NOSUCH_ELEMENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_DEBUG (0, "CREATED element %s\n", GST_ELEMENT_NAME (element));
|
2001-12-22 21:18:17 +00:00
|
|
|
gst_bin_add (GST_BIN (parent), element);
|
2001-01-07 04:00:30 +00:00
|
|
|
}
|
2002-01-14 04:09:56 +00:00
|
|
|
|
2001-01-07 04:00:30 +00:00
|
|
|
elementcount++;
|
2002-01-14 04:09:56 +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;
|
2002-01-14 04:09:56 +00:00
|
|
|
|
2001-12-15 01:01:57 +00:00
|
|
|
/* find sink pads */
|
2001-06-15 06:33:29 +00:00
|
|
|
if (sinkpadname != NULL) {
|
2002-01-14 04:09:56 +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);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* 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) {
|
2001-12-12 13:04:05 +00:00
|
|
|
sinkpads = g_slist_append (sinkpads, temppad);
|
|
|
|
numsinkpads++;
|
|
|
|
break;
|
2002-01-14 04:09:56 +00:00
|
|
|
}
|
|
|
|
}
|
2001-06-15 06:33:29 +00:00
|
|
|
}
|
2002-01-14 04:09:56 +00:00
|
|
|
|
2001-12-12 13:04:05 +00:00
|
|
|
if (!sinkpads)
|
2002-01-14 04:09:56 +00:00
|
|
|
GST_DEBUG (0, "can't find a sink pad for element\n");
|
2001-12-12 13:04:05 +00:00
|
|
|
else
|
2002-01-14 04:09:56 +00:00
|
|
|
GST_DEBUG (0, "have sink pad %s:%s\n", GST_DEBUG_PAD_NAME (GST_PARSE_LISTPAD (sinkpads)));
|
|
|
|
|
2001-12-22 21:18:17 +00:00
|
|
|
if (!srcpads && sinkpads && previous && srcpadname) {
|
2002-01-14 04:09:56 +00:00
|
|
|
dyn_connect *connect = g_malloc (sizeof (dyn_connect));
|
|
|
|
|
|
|
|
connect->srcpadname = srcpadname;
|
|
|
|
connect->target = GST_PARSE_LISTPAD (sinkpads);
|
|
|
|
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)));
|
|
|
|
|
|
|
|
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))));
|
2002-01-18 22:44:19 +00:00
|
|
|
if (!gst_pad_connect (GST_PARSE_LISTPAD (g_slist_nth (srcpads, j)),
|
|
|
|
GST_PARSE_LISTPAD (g_slist_nth (sinkpads, j)))) {
|
|
|
|
g_warning ("could not connect %s:%s to %s:%s",
|
|
|
|
GST_DEBUG_PAD_NAME (GST_PARSE_LISTPAD (g_slist_nth (srcpads, j))),
|
|
|
|
GST_DEBUG_PAD_NAME (GST_PARSE_LISTPAD (g_slist_nth (sinkpads, j))));
|
|
|
|
return GST_PARSE_ERROR_CONNECT;
|
|
|
|
}
|
2002-01-14 04:09:56 +00:00
|
|
|
}
|
2001-01-07 04:00:30 +00:00
|
|
|
}
|
2002-01-14 04:09:56 +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-12-17 14:18:03 +00:00
|
|
|
|
2001-12-12 13:04:05 +00:00
|
|
|
g_slist_free (sinkpads);
|
|
|
|
sinkpads = NULL;
|
2002-01-14 04:09:56 +00:00
|
|
|
|
2001-12-14 22:59:21 +00:00
|
|
|
/* if we're the first element, ghost all the sinkpads */
|
2001-12-22 21:18:17 +00:00
|
|
|
if (elementcount == 1 && !backref) {
|
2002-01-14 04:09:56 +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
|
|
|
}
|
2002-01-14 04:09:56 +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))
|
2002-01-14 04:09:56 +00:00
|
|
|
prevelement = element;
|
2001-01-07 04:00:30 +00:00
|
|
|
}
|
|
|
|
}
|
2002-01-14 04:09:56 +00:00
|
|
|
|
2001-12-14 22:59:21 +00:00
|
|
|
/* ghost all the src pads of the bin */
|
2001-01-07 04:00:30 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-01-14 04:09:56 +00:00
|
|
|
|
2001-01-07 04:00:30 +00:00
|
|
|
priv->binlevel--;
|
2002-01-14 04:09:56 +00:00
|
|
|
|
2001-12-12 13:04:05 +00:00
|
|
|
if (retval)
|
|
|
|
return retval;
|
2002-01-14 04:09:56 +00:00
|
|
|
|
2001-12-12 13:04:05 +00:00
|
|
|
DEBUG (closingchar != '\0' ? "returning IN THE WRONG PLACE\n" : "ending pipeline\n");
|
2002-01-14 04:09:56 +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
|
|
|
|
2002-01-14 04:09:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_parse_launchv:
|
|
|
|
* @argv: null-terminated array of arguments
|
|
|
|
*
|
|
|
|
* Create a new pipeline based on command line syntax.
|
|
|
|
*
|
|
|
|
* Returns: a new pipeline on success, NULL on failure
|
|
|
|
*/
|
|
|
|
GstPipeline *
|
|
|
|
gst_parse_launchv (const gchar **argv)
|
|
|
|
{
|
|
|
|
GstPipeline *pipeline;
|
|
|
|
gint ret;
|
|
|
|
|
|
|
|
/* defer error detection to the _recurse function */
|
|
|
|
|
|
|
|
pipeline = (GstPipeline*) gst_pipeline_new ("launch");
|
|
|
|
|
|
|
|
ret = gst_parse_launchv_recurse (argv, GST_BIN (pipeline), NULL);
|
|
|
|
|
|
|
|
if (ret <= 0) {
|
|
|
|
// print an error
|
|
|
|
gst_object_unref (GST_OBJECT (pipeline));
|
|
|
|
return NULL;
|
|
|
|
} else {
|
|
|
|
return pipeline;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-21 23:20:46 +00:00
|
|
|
/**
|
|
|
|
* gst_parse_launch:
|
2002-01-14 04:09:56 +00:00
|
|
|
* @pipeline_description: the command line describing the pipeline
|
2001-01-21 23:20:46 +00:00
|
|
|
*
|
|
|
|
* Create a new pipeline based on command line syntax.
|
|
|
|
*
|
2002-01-14 04:09:56 +00:00
|
|
|
* Returns: a new GstPipeline (cast to a Bin) on success, NULL on failure
|
2001-01-21 23:20:46 +00:00
|
|
|
*/
|
2002-01-14 04:09:56 +00:00
|
|
|
GstPipeline *
|
|
|
|
gst_parse_launch (const gchar * pipeline_description)
|
2001-01-21 23:20:46 +00:00
|
|
|
{
|
2001-01-07 04:00:30 +00:00
|
|
|
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;
|
2002-01-14 04:09:56 +00:00
|
|
|
GstPipeline *pipeline;
|
2001-01-07 04:00:30 +00:00
|
|
|
|
2002-01-14 04:09:56 +00:00
|
|
|
end = pipeline_description + strlen (pipeline_description);
|
2001-03-06 20:04:42 +00:00
|
|
|
newargc = 0;
|
|
|
|
|
2001-05-20 20:05:29 +00:00
|
|
|
temp = "";
|
|
|
|
|
2001-12-14 22:59:21 +00:00
|
|
|
/* Extract the arguments to a gslist in reverse order */
|
2002-01-14 04:09:56 +00:00
|
|
|
for (cp = pipeline_description; cp < end;) {
|
2001-12-12 13:04:05 +00:00
|
|
|
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-12-14 22:59:21 +00:00
|
|
|
/* see if we have an escape char */
|
2001-05-20 20:05:29 +00:00
|
|
|
if (cp[i] != '\\') {
|
2001-12-14 22:59:21 +00:00
|
|
|
/* normal argument - copy and add to the list */
|
2001-12-12 13:04:05 +00:00
|
|
|
string_list = g_slist_prepend (string_list, temp);
|
|
|
|
newargc++;
|
2001-05-20 20:05:29 +00:00
|
|
|
temp = "";
|
2002-01-14 04:09:56 +00:00
|
|
|
} 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-12-14 22:59:21 +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
|
|
|
|
2001-12-14 22:59:21 +00:00
|
|
|
/* handle quoted arguments */
|
2001-03-06 20:04:42 +00:00
|
|
|
if (*cp == '"') {
|
|
|
|
start = ++cp;
|
2001-01-07 04:00:30 +00:00
|
|
|
|
2001-12-14 22:59:21 +00:00
|
|
|
/* find matching quote */
|
2001-03-06 20:04:42 +00:00
|
|
|
while (cp < end && *cp != '"')
|
|
|
|
cp++;
|
|
|
|
|
2001-12-14 22:59:21 +00:00
|
|
|
/* make sure we got it */
|
2001-03-06 20:04:42 +00:00
|
|
|
if (cp == end) {
|
2001-12-12 13:04:05 +00:00
|
|
|
g_warning ("gst_parse_launch: Unbalanced quote in command line");
|
2001-12-14 22:59:21 +00:00
|
|
|
/* FIXME: The list leaks here */
|
2001-03-06 20:04:42 +00:00
|
|
|
return 0;
|
2001-01-07 04:00:30 +00:00
|
|
|
}
|
2001-03-06 20:04:42 +00:00
|
|
|
|
2001-12-14 22:59:21 +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-14 22:59:21 +00:00
|
|
|
cp += 2; /* skip the quote aswell */
|
2001-03-06 20:04:42 +00:00
|
|
|
}
|
|
|
|
|
2001-12-14 22:59:21 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-14 04:09:56 +00:00
|
|
|
/* now allocate the new argv array, with room for NULL termination */
|
|
|
|
argvn = g_new0 (char *, newargc + 1);
|
2001-12-12 13:04:05 +00:00
|
|
|
|
|
|
|
GST_DEBUG (0, "got %d args\n", newargc);
|
2001-03-06 20:04:42 +00:00
|
|
|
|
2001-12-14 22:59:21 +00:00
|
|
|
/* reverse the list and put the strings in the new array */
|
2001-03-06 20:04:42 +00:00
|
|
|
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-12-14 22:59:21 +00:00
|
|
|
/* print them out */
|
2002-03-04 05:37:26 +00:00
|
|
|
while (argvn[i++]) {
|
|
|
|
GST_DEBUG (0, "arg %d is: %s\n", i-1, argvn[i-1]);
|
2001-01-07 04:00:30 +00:00
|
|
|
}
|
|
|
|
|
2001-12-14 22:59:21 +00:00
|
|
|
/* do it! */
|
2002-02-02 13:34:44 +00:00
|
|
|
pipeline = gst_parse_launchv ((const char**) argvn);
|
2001-03-06 20:04:42 +00:00
|
|
|
|
2002-01-14 04:09:56 +00:00
|
|
|
GST_DEBUG(0, "Finished - freeing temporary argument array");
|
|
|
|
g_strfreev(argvn);
|
2001-03-06 20:04:42 +00:00
|
|
|
|
2002-01-14 04:09:56 +00:00
|
|
|
return pipeline;
|
2001-01-07 04:00:30 +00:00
|
|
|
}
|