? gst-launch.c.diff
Index: gst-launch.c
===================================================================
RCS file: /cvs/gstreamer/gstreamer/tools/gst-launch.c,v
retrieving revision 1.109
diff -u -3 -p -b -B -d -r1.109 gst-launch.c
--- gst-launch.c	13 May 2006 17:50:11 -0000	1.109
+++ gst-launch.c	30 Jun 2006 06:28:03 -0000
@@ -496,6 +496,39 @@ event_loop (GstElement * pipeline, gbool
   return TRUE;
 }
 
+typedef struct {
+  GList *list;
+  GstStateChangeReturn ret;
+} SelectStreamsForeachData;
+
+static void
+select_streams_foreach (gpointer data, gpointer user_data)
+{
+  SelectStreamsForeachData *ssfd = (SelectStreamsForeachData *) user_data;
+  GList *p = ssfd->list;
+  GstElement *e = GST_ELEMENT (data);
+
+  while (p && (ssfd->ret == GST_STATE_CHANGE_SUCCESS)) {
+    if (!strcmp (p->data, GST_OBJECT_NAME (e))) {
+      g_free (p->data);
+      ssfd->list = g_list_remove_link (ssfd->list, p);
+      ssfd->ret = gst_element_set_state (e, GST_STATE_PLAYING);
+      break;
+    }
+    p = p->next;
+  }
+}
+
+static void
+list_streams_foreach (gpointer data, gpointer user_data)
+{
+  guint *n = (guint *) user_data;
+
+  (*n)++;
+  g_print ("%3i: %s (of type %s)\n", *n,
+      GST_OBJECT_NAME (data), G_OBJECT_TYPE_NAME (data));
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -505,7 +538,9 @@ main (int argc, char *argv[])
   gboolean verbose = FALSE;
   gboolean no_fault = FALSE;
   gboolean trace = FALSE;
+  gboolean list_streams = FALSE;
   gchar *savefile = NULL;
+  gchar *select_streams = NULL;
   gchar *exclude_args = NULL;
   GOptionEntry options[] = {
     {"tags", 't', 0, G_OPTION_ARG_NONE, &tags,
@@ -524,6 +559,10 @@ main (int argc, char *argv[])
         N_("Do not install a fault handler"), NULL},
     {"trace", 'T', 0, G_OPTION_ARG_NONE, &trace,
         N_("Print alloc trace (if enabled at compile time)"), NULL},
+    {"list-streams", 'l', 0, G_OPTION_ARG_NONE, &list_streams,
+        N_("List streams"), NULL},
+    {"select-streams", 's', 0, G_OPTION_ARG_STRING, &select_streams,
+        N_("Play only streams STREAMS"), N_("STREAMS")},
     GST_TOOLS_GOPTION_VERSION,
     {NULL}
   };
@@ -677,10 +716,47 @@ main (int argc, char *argv[])
     } else {
       GTimeVal tfthen, tfnow;
       GstClockTimeDiff diff;
+      GstStateChangeReturn sret = GST_STATE_CHANGE_SUCCESS;
+      GstIterator *it;
+
+      if (list_streams) {
+        guint n = 0;
+
+        g_print ("Available sinks:\n");
+        it = gst_bin_iterate_sinks (GST_BIN (pipeline));
+        gst_iterator_foreach (it, list_streams_foreach, &n);
+        gst_iterator_free (it);
+        if (!n)
+          g_print ("(none)\n");
+        goto end;
+      }
+
+      if (select_streams) {
+        SelectStreamsForeachData data;
+        gchar *t;
 
+        fprintf (stderr, _("Setting selected element to PLAYING ...\n"));
+        it = gst_bin_iterate_sinks (GST_BIN (pipeline));
+        data.ret = GST_STATE_CHANGE_SUCCESS;
+        data.list = NULL;
+        for (t = strtok (select_streams, ","); t != NULL;
+            t = strtok (NULL, ","))
+          data.list = g_list_append (data.list, g_strdup (t));
+        gst_iterator_foreach (it, select_streams_foreach, &data);
+        gst_iterator_free (it);
+        if (data.list) {
+          fprintf (stderr, _("ERROR: could not find stream '%s'.\n"),
+              (gchar *) data.list->data);
+          g_list_foreach (data.list, (GFunc) g_free, NULL);
+          res = -1;
+          goto end;
+        }
+        sret = data.ret;
+      } else {
       fprintf (stderr, _("Setting pipeline to PLAYING ...\n"));
-      if (gst_element_set_state (pipeline,
-              GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE) {
+        sret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
+      }
+      if (sret == GST_STATE_CHANGE_FAILURE) {
         fprintf (stderr, _("ERROR: pipeline doesn't want to play.\n"));
         res = -1;
         goto end;
