[gst-devel] Patch to allow spaces in options for gstreamer-launch
Dominic Ludlam
dom at recoil.org
Sat Mar 3 17:54:27 CET 2001
Hi,
I got gstreamer from CVS after seeing it mentioned on slashdot and was very
impressed. I have a few comments though:
I couldn't play many of my mp3s using the example mp3play tool because most
of them have spaces in the filenames. I've appended a simple patch that
allows you to quote the options in gst_parse_launch.
The argvn argument list it creates never gets freed - I put in a g_strfreev
at the end of the function but the program core dumped, implying that some of
the strings in that array are referenced instead of copied in
gst_parse_launch_cmdline. I'll look at that soon.
Also, I have two audio devices, a sound card and the microphone in my webcam.
The webcam is /dev/dsp and the soundcard is /dev/dsp1. This meant that by
default the audiosink plugin output sound to my webcam which just ate
everything passed to it. I wasn't sure of the best way to fix this
properly - maybe a GtkArg that enumerates all the available audio devices?
Dom.
Index: examples/launch/mp3play
===================================================================
RCS file: /cvsroot/gstreamer/gstreamer/examples/launch/mp3play,v
retrieving revision 1.6
diff -u -r1.6 mp3play
--- examples/launch/mp3play 2001/01/22 23:39:23 1.6
+++ examples/launch/mp3play 2001/03/03 00:41:28
@@ -1,4 +1,4 @@
#! /bin/sh
for loc in "$@"; do
-gstreamer-launch disksrc "location=$loc" ! mp3parse ! mpg123 ! audiosink
+gstreamer-launch disksrc \""location=$loc"\" ! mp3parse ! mpg123 ! audiosink
done
Index: gst/gstparse.c
===================================================================
RCS file: /cvsroot/gstreamer/gstreamer/gst/gstparse.c,v
retrieving revision 1.5
diff -u -r1.5 gstparse.c
--- gst/gstparse.c 2001/01/29 00:06:00 1.5
+++ gst/gstparse.c 2001/03/03 00:41:28
@@ -321,8 +321,9 @@
gst_parse_priv priv;
gchar **argvn;
gint newargc;
- gint len;
- int i,j,k;
+ gint i;
+ const gchar *cp, *start, *end;
+ GSList *string_list = NULL, *slist;
priv.bincount = 0;
priv.threadcount = 0;
@@ -331,46 +332,64 @@
priv.verbose = FALSE;
priv.debug = FALSE;
- // 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++;
+ end = cmdline + strlen(cmdline);
+ newargc = 0;
+
+ // Extract the arguments to a gslist in reverse order
+ for (cp = cmdline; cp < end; ) {
+ i = strcspn(cp, "([{}]) \"");
+
+ if (i > 0) {
+ // normal argument - copy and add to the list
+ string_list = g_slist_prepend(string_list, g_strndup(cp, i));
+ newargc++;
+ cp += i;
+ }
+
+ // skip spaces
+ while (cp < end && *cp == ' ')
+ cp++;
+
+ // handle quoted arguments
+ if (*cp == '"') {
+ start = ++cp;
+
+ // find matching quote
+ while (cp < end && *cp != '"')
+ cp++;
+
+ // make sure we got it
+ if (cp == end) {
+ g_warning("gst_parse_launch: Unbalanced quote in command line");
+ // FIXME: The list leaks here
+ return 0;
+ }
+
+ // copy the string sans quotes
+ string_list = g_slist_prepend(string_list, g_strndup(start, cp - start));
+ newargc++;
+ cp += 2; // skip the quote aswell
+ }
+
+ // brackets exist in a separate argument slot
+ if (*cp && strchr("([{}])", *cp)) {
+ string_list = g_slist_prepend(string_list, g_strndup(cp, 1));
+ newargc++;
+ cp++;
}
}
// now allocate the new argv array
- argvn = g_new0(char *,newargc+1);
- GST_DEBUG(0,"supposed to have %d args\n",newargc);
+ argvn = g_new0(char *,newargc);
+ GST_DEBUG(0,"got %d args\n",newargc);
- // 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);
+ // reverse the list and put the strings in the new array
+ i = newargc;
- // catch misparses
- if (strlen(argvn[j]) > 0) j++;
- }
- k = i;
+ for (slist = string_list; slist; slist = slist->next)
+ argvn[--i] = slist->data;
- // if this is a bracket, construct a word
- if ((cmdline[i] != ' ') && (cmdline[i] != '\0')) {
- argvn[j++] = g_strdup_printf("%c",cmdline[i]);
- k++;
- }
- }
- }
+ g_slist_free(string_list);
// print them out
for (i=0;i<newargc;i++) {
@@ -379,6 +398,12 @@
// set up the elementcounts hash
priv.elementcounts = g_hash_table_new(g_str_hash,g_str_equal);
+
+ // do it!
+ i = gst_parse_launch_cmdline(newargc,argvn,parent,&priv);
+
+// GST_DEBUG(0, "Finished - freeing temporary argument array");
+// g_strfreev(argvn);
- return gst_parse_launch_cmdline(newargc,argvn,parent,&priv);
+ return i;
}
More information about the gstreamer-devel
mailing list