2000-01-30 10:44:33 +00:00
|
|
|
#include <glib.h>
|
|
|
|
#include <gst/gst.h>
|
2000-08-28 20:20:55 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2000-01-30 10:44:33 +00:00
|
|
|
|
2001-01-03 07:38:45 +00:00
|
|
|
guint bincount = 0;
|
|
|
|
guint threadcount = 0;
|
|
|
|
gint binlevel = 0;
|
|
|
|
GHashTable *elementcounts;
|
|
|
|
gboolean verbose = FALSE;
|
|
|
|
gboolean debug = FALSE;
|
|
|
|
|
|
|
|
#define DEBUG(format,args...) G_STMT_START{ \
|
|
|
|
if (debug) { \
|
|
|
|
int ___i; \
|
|
|
|
for (___i=0;___i<binlevel*2;___i++) fprintf(stderr," "); \
|
|
|
|
fprintf(stderr, format , ## args ); \
|
|
|
|
} \
|
|
|
|
}G_STMT_END
|
|
|
|
#define DEBUG_NOPREFIX(format,args...) G_STMT_START{ if (debug) fprintf(stderr, format , ## args ); }G_STMT_END
|
|
|
|
#define VERBOSE(format,args...) G_STMT_START{ \
|
|
|
|
if (verbose) { \
|
|
|
|
int ___i; \
|
|
|
|
for (___i=0;___i<binlevel*2;___i++) fprintf(stderr," "); \
|
|
|
|
fprintf(stderr, format , ## args ); \
|
|
|
|
} \
|
|
|
|
}G_STMT_END
|
|
|
|
|
2000-01-30 10:44:33 +00:00
|
|
|
typedef struct _launch_delayed_pad launch_delayed_pad;
|
|
|
|
struct _launch_delayed_pad {
|
|
|
|
gchar *name;
|
|
|
|
GstPad *peer;
|
|
|
|
};
|
|
|
|
|
|
|
|
void launch_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_get_name(pad),peer->name)) {
|
|
|
|
gst_pad_connect(pad,peer->peer);
|
|
|
|
gst_info("delayed connect of '%s' to '%s'\n",
|
|
|
|
gst_pad_get_name(pad),gst_pad_get_name(peer->peer));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-12-31 10:46:16 +00:00
|
|
|
gchar *unique_name(gchar *type) {
|
|
|
|
gint count;
|
|
|
|
|
|
|
|
count = GPOINTER_TO_INT(g_hash_table_lookup(elementcounts,type));
|
|
|
|
count++;
|
|
|
|
g_hash_table_insert(elementcounts,type,GINT_TO_POINTER(count));
|
|
|
|
|
|
|
|
return g_strdup_printf("%s%d",type,count-1);
|
|
|
|
}
|
|
|
|
|
2001-01-03 07:38:45 +00:00
|
|
|
// element ! [ element ! (element ! element )] ! element
|
|
|
|
// 0 1 2 3 4 5 6 7 8 9 10 11
|
|
|
|
// 0 1 2 3 4 5 8
|
|
|
|
// 0 1 2 3 6
|
|
|
|
|
2000-12-31 10:46:16 +00:00
|
|
|
gint parse_cmdline(int argc,char *argv[],GstBin *parent) {
|
|
|
|
gint i = 0;
|
|
|
|
gchar *arg;
|
2001-01-03 07:38:45 +00:00
|
|
|
GstElement *element = NULL, *previous = NULL, *prevelement = NULL;
|
2000-12-31 10:46:16 +00:00
|
|
|
gchar closingchar;
|
2000-01-30 10:44:33 +00:00
|
|
|
gint len;
|
2000-12-31 10:46:16 +00:00
|
|
|
gchar *ptr;
|
|
|
|
gchar *sinkpadname = NULL, *srcpadname = NULL;
|
|
|
|
GstPad *sinkpad = NULL, *srcpad = NULL;
|
|
|
|
GList *pads;
|
|
|
|
gint elementcount = 0;
|
|
|
|
gint retval = 0;
|
2000-01-30 10:44:33 +00:00
|
|
|
|
2001-01-03 07:38:45 +00:00
|
|
|
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 ");
|
|
|
|
DEBUG_NOPREFIX("%s\n",gst_element_get_name (GST_ELEMENT (parent)));
|
2000-01-30 10:44:33 +00:00
|
|
|
|
|
|
|
while (i < argc) {
|
2000-12-31 10:46:16 +00:00
|
|
|
arg = argv[i];
|
|
|
|
len = strlen(arg);
|
|
|
|
element = NULL;
|
2001-01-03 07:38:45 +00:00
|
|
|
DEBUG("** ARGUMENT is '%s'\n",arg);
|
2000-12-31 10:46:16 +00:00
|
|
|
|
|
|
|
// a null that slipped through the reconstruction
|
|
|
|
if (len == 0) {
|
2001-01-03 07:38:45 +00:00
|
|
|
DEBUG("random arg, FIXME\n");
|
2000-12-31 10:46:16 +00:00
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// end of the container
|
|
|
|
} else if (arg[0] == closingchar) {
|
|
|
|
// time to finish off this bin
|
2001-01-03 07:38:45 +00:00
|
|
|
DEBUG("exiting container %s\n",gst_element_get_name (GST_ELEMENT (parent)));
|
2000-12-31 10:46:16 +00:00
|
|
|
retval = i+1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
// a pad connection
|
|
|
|
} else if ((ptr = strchr(arg,'!'))) {
|
2001-01-03 07:38:45 +00:00
|
|
|
DEBUG("attempting to connect pads together....\n");
|
2000-12-31 10:46:16 +00:00
|
|
|
|
|
|
|
// if it starts with the !
|
|
|
|
if (arg[0] == '!') {
|
|
|
|
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;
|
2000-01-30 10:44:33 +00:00
|
|
|
}
|
2000-12-31 10:46:16 +00:00
|
|
|
|
2001-01-03 07:38:45 +00:00
|
|
|
DEBUG("have sinkpad %s, srcpad %s\n",sinkpadname,srcpadname);
|
2000-12-31 10:46:16 +00:00
|
|
|
|
|
|
|
srcpad = NULL;
|
|
|
|
|
|
|
|
// if the srcpadname doesn't have any commas in it, find an actual pad
|
|
|
|
if (!srcpadname || !strchr(srcpadname,',')) {
|
2001-01-03 07:38:45 +00:00
|
|
|
if (srcpadname != NULL) {
|
|
|
|
srcpad = gst_element_get_pad(previous,srcpadname);
|
|
|
|
if (!srcpad)
|
|
|
|
VERBOSE("NO SUCH pad %s in element %s\n",srcpadname,gst_element_get_name(previous));
|
|
|
|
}
|
2000-12-31 10:46:16 +00:00
|
|
|
|
2001-01-03 07:38:45 +00:00
|
|
|
if (srcpad == NULL) {
|
2000-12-31 10:46:16 +00:00
|
|
|
// check through the list to find the first sink pad
|
2001-01-03 07:38:45 +00:00
|
|
|
pads = gst_element_get_pad_list(previous);
|
2000-12-31 10:46:16 +00:00
|
|
|
while (pads) {
|
|
|
|
srcpad = GST_PAD(pads->data);
|
|
|
|
pads = g_list_next (pads);
|
|
|
|
if (gst_pad_get_direction (srcpad) == GST_PAD_SRC) break;
|
|
|
|
srcpad = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-03 07:38:45 +00:00
|
|
|
if (!srcpad) DEBUG("error, can't find a src pad!!!\n");
|
|
|
|
else DEBUG("have src pad %s:%s\n",GST_DEBUG_PAD_NAME(srcpad));
|
2000-01-30 10:44:33 +00:00
|
|
|
}
|
2000-12-31 10:46:16 +00:00
|
|
|
|
2001-01-04 10:47:39 +00:00
|
|
|
// argument with = in it
|
|
|
|
} else if (strstr(arg, "=")) {
|
|
|
|
gchar * argname;
|
|
|
|
gchar * argval;
|
|
|
|
gchar * pos = strstr(arg, "=");
|
|
|
|
// we have an argument
|
|
|
|
argname = g_strndup(arg, pos - arg);
|
|
|
|
argval = pos+1;
|
|
|
|
DEBUG("attempting to set argument '%s'\n", arg);
|
|
|
|
gtk_object_set(GTK_OBJECT(previous),argname,argval,NULL);
|
|
|
|
g_free(argname);
|
|
|
|
|
2001-01-04 00:15:13 +00:00
|
|
|
// element or argument, or beginning of bin or thread
|
2000-12-31 10:46:16 +00:00
|
|
|
} else {
|
2001-01-03 07:38:45 +00:00
|
|
|
DEBUG("have element or bin/thread\n");
|
2000-12-31 10:46:16 +00:00
|
|
|
// if we have a bin or thread starting
|
|
|
|
if (strchr("({",arg[0])) {
|
2001-01-03 07:38:45 +00:00
|
|
|
if (arg[0] == '(') {
|
2000-12-31 10:46:16 +00:00
|
|
|
// create a bin and add it to the current parent
|
|
|
|
element = gst_bin_new(g_strdup_printf("bin%d",bincount++));
|
2001-01-03 07:38:45 +00:00
|
|
|
VERBOSE("CREATED bin %s\n",gst_element_get_name(element));
|
|
|
|
} else if (arg[0] == '{') {
|
2000-12-31 10:46:16 +00:00
|
|
|
// create a thread and add it to the current parent
|
|
|
|
element = gst_thread_new(g_strdup_printf("thread%d",threadcount++));
|
2001-01-03 07:38:45 +00:00
|
|
|
VERBOSE("CREATED thread %s\n",gst_element_get_name(element));
|
|
|
|
}
|
2000-12-31 10:46:16 +00:00
|
|
|
|
|
|
|
i += parse_cmdline(argc - i, argv + i + 1, GST_BIN (element));
|
|
|
|
|
2000-01-30 10:44:33 +00:00
|
|
|
} else {
|
2001-01-04 00:15:13 +00:00
|
|
|
// we have an element
|
2001-01-03 07:38:45 +00:00
|
|
|
DEBUG("attempting to create element '%s'\n",arg);
|
2000-12-31 10:46:16 +00:00
|
|
|
element = gst_elementfactory_make(arg,unique_name(arg));
|
2001-01-03 07:38:45 +00:00
|
|
|
VERBOSE("CREATED element %s\n",gst_element_get_name(element));
|
|
|
|
DEBUG("created element %s\n",gst_element_get_name(element));
|
2000-01-30 10:44:33 +00:00
|
|
|
}
|
2000-12-31 10:46:16 +00:00
|
|
|
|
|
|
|
gst_bin_add (GST_BIN (parent), element);
|
|
|
|
elementcount++;
|
|
|
|
|
|
|
|
if (srcpad != NULL) {
|
2001-01-03 07:38:45 +00:00
|
|
|
DEBUG("need to connect to sinkpad %s:%s\n",GST_DEBUG_PAD_NAME(srcpad));
|
2000-12-31 10:46:16 +00:00
|
|
|
|
|
|
|
sinkpad = NULL;
|
|
|
|
|
|
|
|
if (sinkpadname != NULL)
|
2001-01-03 07:38:45 +00:00
|
|
|
sinkpad = gst_element_get_pad(previous,sinkpadname);
|
2000-12-31 10:46:16 +00:00
|
|
|
|
|
|
|
if (!sinkpad) {
|
|
|
|
// check through the list to find the first sink pad
|
|
|
|
pads = gst_element_get_pad_list(element);
|
|
|
|
while (pads) {
|
|
|
|
sinkpad = GST_PAD(pads->data);
|
|
|
|
pads = g_list_next (pads);
|
|
|
|
if (gst_pad_get_direction (sinkpad) == GST_PAD_SINK) break;
|
|
|
|
sinkpad = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-03 07:38:45 +00:00
|
|
|
if (!sinkpad) DEBUG("error, can't find a sink pad!!!\n");
|
|
|
|
else DEBUG("have sink pad %s:%s\n",GST_DEBUG_PAD_NAME(sinkpad));
|
2000-12-31 10:46:16 +00:00
|
|
|
|
2001-01-03 07:38:45 +00:00
|
|
|
VERBOSE("CONNECTING %s:%s and %s:%s\n",GST_DEBUG_PAD_NAME(srcpad),GST_DEBUG_PAD_NAME(sinkpad));
|
2000-12-31 10:46:16 +00:00
|
|
|
gst_pad_connect(srcpad,sinkpad);
|
|
|
|
|
|
|
|
sinkpad = NULL;
|
|
|
|
srcpad = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we're the first element, ghost all the sinkpads
|
|
|
|
if (elementcount == 1) {
|
2001-01-03 07:38:45 +00:00
|
|
|
DEBUG("first element, ghosting all of %s's sink pads to parent %s\n",
|
|
|
|
gst_element_get_name(element),gst_element_get_name(GST_ELEMENT(parent)));
|
2000-12-31 10:46:16 +00:00
|
|
|
pads = gst_element_get_pad_list (element);
|
|
|
|
while (pads) {
|
|
|
|
sinkpad = GST_PAD (pads->data);
|
|
|
|
pads = g_list_next (pads);
|
2001-01-03 07:38:45 +00:00
|
|
|
if (!sinkpad) DEBUG("much oddness, pad doesn't seem to exist\n");
|
2000-12-31 10:46:16 +00:00
|
|
|
else if (gst_pad_get_direction (sinkpad) == GST_PAD_SINK) {
|
|
|
|
gst_element_add_ghost_pad (GST_ELEMENT (parent), sinkpad);
|
2001-01-03 07:38:45 +00:00
|
|
|
DEBUG("ghosted %s:%s\n",GST_DEBUG_PAD_NAME(sinkpad));
|
2000-12-31 10:46:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
i++;
|
2001-01-03 07:38:45 +00:00
|
|
|
previous = element;
|
|
|
|
if (!GST_IS_BIN(element)) prevelement = element;
|
2000-12-31 10:46:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ghost all the src pads of the bin
|
|
|
|
if (prevelement != NULL) {
|
2001-01-03 07:38:45 +00:00
|
|
|
DEBUG("last element, ghosting all of %s's src pads to parent %s\n",
|
|
|
|
gst_element_get_name(prevelement),gst_element_get_name(GST_ELEMENT(parent)));
|
2000-12-31 10:46:16 +00:00
|
|
|
pads = gst_element_get_pad_list (prevelement);
|
|
|
|
while (pads) {
|
|
|
|
srcpad = GST_PAD (pads->data);
|
|
|
|
pads = g_list_next (pads);
|
2001-01-03 07:38:45 +00:00
|
|
|
if (!srcpad) DEBUG("much oddness, pad doesn't seem to exist\n");
|
2000-12-31 10:46:16 +00:00
|
|
|
else if (gst_pad_get_direction (srcpad) == GST_PAD_SRC) {
|
|
|
|
gst_element_add_ghost_pad (GST_ELEMENT (parent), srcpad);
|
2001-01-03 07:38:45 +00:00
|
|
|
DEBUG("ghosted %s:%s\n",GST_DEBUG_PAD_NAME(srcpad));
|
2000-12-31 10:46:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-03 07:38:45 +00:00
|
|
|
binlevel--;
|
|
|
|
|
2000-12-31 10:46:16 +00:00
|
|
|
if (retval) return retval;
|
|
|
|
|
|
|
|
if (closingchar != '\0')
|
2001-01-03 07:38:45 +00:00
|
|
|
DEBUG("returning IN THE WRONG PLACE\n");
|
|
|
|
else DEBUG("ending pipeline\n");
|
2000-12-31 10:46:16 +00:00
|
|
|
return i+1;
|
|
|
|
}
|
|
|
|
|
|
|
|
gint parse(int argc,char *argv[],GstBin *parent) {
|
|
|
|
char **argvn;
|
|
|
|
gchar *cmdline;
|
|
|
|
gint newargc;
|
|
|
|
gint len;
|
|
|
|
int i,j,k;
|
|
|
|
|
|
|
|
// make a null-terminated version of argv
|
|
|
|
argvn = g_new0(char *,argc+1);
|
|
|
|
memcpy(argvn,argv,sizeof(char*)*argc);
|
|
|
|
// join the argvs together
|
|
|
|
cmdline = g_strjoinv(" ",argvn);
|
|
|
|
// free the null-terminated argv
|
|
|
|
g_free(argvn);
|
|
|
|
|
|
|
|
// first walk through quickly and see how many more slots we need
|
|
|
|
len = strlen(cmdline);
|
|
|
|
newargc = 1;
|
|
|
|
for (i=0;i<len;i++) {
|
|
|
|
// if it's a space, it denotes a new arg
|
|
|
|
if (cmdline[i] == ' ') newargc++;
|
|
|
|
// if it's a brace and isn't followed by a space, give it an arg
|
|
|
|
if (strchr("([{}])",cmdline[i])) {
|
|
|
|
// not followed by space, gets one
|
|
|
|
if (cmdline[i+1] != ' ') newargc++;
|
2000-01-30 10:44:33 +00:00
|
|
|
}
|
|
|
|
}
|
2000-12-31 10:46:16 +00:00
|
|
|
|
|
|
|
// now allocate the new argv array
|
|
|
|
argvn = g_new0(char *,newargc+1);
|
2001-01-03 07:38:45 +00:00
|
|
|
DEBUG("supposed to have %d args\n",newargc);
|
2000-12-31 10:46:16 +00:00
|
|
|
|
|
|
|
// now attempt to construct the new arg list
|
|
|
|
j = 0;k = 0;
|
|
|
|
for (i=0;i<len+1;i++) {
|
|
|
|
// if it's a delimiter
|
|
|
|
if (strchr("([{}]) ",cmdline[i]) || (cmdline[i] == '\0')) {
|
|
|
|
// extract the previous arg
|
|
|
|
if (i-k > 0) {
|
|
|
|
if (cmdline[k] == ' ') k++;
|
|
|
|
argvn[j] = g_new0(char,(i-k)+1);
|
|
|
|
memcpy(argvn[j],&cmdline[k],i-k);
|
2001-01-03 07:38:45 +00:00
|
|
|
|
|
|
|
// catch misparses
|
|
|
|
if (strlen(argvn[j]) > 0) j++;
|
2000-12-31 10:46:16 +00:00
|
|
|
}
|
|
|
|
k = i;
|
|
|
|
|
|
|
|
// if this is a bracket, construct a word
|
|
|
|
if ((cmdline[i] != ' ') && (cmdline[i] != '\0')) {
|
|
|
|
argvn[j++] = g_strdup_printf("%c",cmdline[i]);
|
|
|
|
k++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// print them out
|
|
|
|
for (i=0;i<newargc;i++) {
|
2001-01-03 07:38:45 +00:00
|
|
|
DEBUG("arg %d is: %s\n",i,argvn[i]);
|
2000-12-31 10:46:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// set up the elementcounts hash
|
|
|
|
elementcounts = g_hash_table_new(g_str_hash,g_str_equal);
|
|
|
|
|
|
|
|
return parse_cmdline(newargc,argvn,parent);
|
2000-01-30 10:44:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc,char *argv[]) {
|
|
|
|
GstElement *pipeline;
|
2001-01-03 07:38:45 +00:00
|
|
|
int firstarg;
|
2001-01-04 07:19:11 +00:00
|
|
|
guint i;
|
2000-01-30 10:44:33 +00:00
|
|
|
|
|
|
|
gst_init(&argc,&argv);
|
|
|
|
|
2001-01-03 07:38:45 +00:00
|
|
|
firstarg = 1;
|
|
|
|
while ((argv[firstarg][0] == '-') && (argv[firstarg][1] == '-')) {
|
|
|
|
if (strcmp(&argv[firstarg][2],"verbose") == 0)
|
|
|
|
verbose = TRUE;
|
|
|
|
else if (strcmp(&argv[firstarg][2],"debug") == 0)
|
|
|
|
debug = TRUE;
|
|
|
|
firstarg++;
|
|
|
|
}
|
|
|
|
|
2000-12-31 10:46:16 +00:00
|
|
|
pipeline = gst_pipeline_new("launch");
|
2000-01-30 10:44:33 +00:00
|
|
|
|
2001-01-03 07:38:45 +00:00
|
|
|
VERBOSE("CREATED pipeline %s\n",gst_element_get_name(pipeline));
|
|
|
|
parse(argc - firstarg,argv + firstarg,GST_BIN (pipeline));
|
2000-01-30 10:44:33 +00:00
|
|
|
|
2001-01-03 07:38:45 +00:00
|
|
|
VERBOSE("RUNNING pipeline\n");
|
2000-01-30 10:44:33 +00:00
|
|
|
gst_element_set_state(pipeline,GST_STATE_PLAYING);
|
2001-01-04 10:47:39 +00:00
|
|
|
|
|
|
|
while(1)
|
2001-01-04 07:19:11 +00:00
|
|
|
gst_bin_iterate (GST_BIN (pipeline));
|
2000-08-28 20:20:55 +00:00
|
|
|
|
2001-01-03 07:38:45 +00:00
|
|
|
fprintf(stderr,"\n");
|
|
|
|
|
2000-09-09 16:36:10 +00:00
|
|
|
return 0;
|
2000-01-30 10:44:33 +00:00
|
|
|
}
|