parse: Add GST_FLAG_NO_SINGLE_ELEMENT_BINS
authorBrendan Long <b.long@cablelabs.com>
Mon, 1 Jul 2013 20:04:46 +0000 (14:04 -0600)
committerSebastian Dröge <slomo@circular-chaos.org>
Mon, 19 Aug 2013 09:30:15 +0000 (11:30 +0200)
This makes gst_parse_bin_from_description() return an element instead of
a bin if there's only one element. Also changed gstparse.c to use this,
so gst-launch won't create superfluous bins.

https://bugzilla.gnome.org/show_bug.cgi?id=703405

gst/gstparse.h
gst/gstutils.c
gst/parse/grammar.y

index 09013d9..de437b1 100644 (file)
@@ -64,13 +64,16 @@ typedef enum
  * @GST_PARSE_FLAG_FATAL_ERRORS: Always return NULL when an error occurs
  *     (default behaviour is to return partially constructed bins or elements
  *      in some cases)
+ * @GST_PARSE_FLAG_NO_SINGLE_ELEMENT_BINS: If a bin only has a single element,
+ *     just return the element.
  *
  * Parsing options.
  */
 typedef enum
 {
   GST_PARSE_FLAG_NONE = 0,
-  GST_PARSE_FLAG_FATAL_ERRORS = (1 << 0)
+  GST_PARSE_FLAG_FATAL_ERRORS = (1 << 0),
+  GST_PARSE_FLAG_NO_SINGLE_ELEMENT_BINS = (1 << 1)
 } GstParseFlags;
 
 #define GST_TYPE_PARSE_CONTEXT (gst_parse_context_get_type())
index fe982bf..09cd786 100644 (file)
@@ -3030,8 +3030,9 @@ gst_parse_bin_from_description (const gchar * bin_description,
  * and want them all ghosted, you will have to create the ghost pads
  * yourself).
  *
- * Returns: (transfer full) (type Gst.Bin): a newly-created bin, or
- *   %NULL if an error occurred.
+ * Returns: (transfer full) (type Gst.Element): a newly-created element, which
+ *   is guaranteed to be a bin unless GST_FLAG_NO_SINGLE_ELEMENT_BINS was
+ *   passed, or %NULL if an error occurred.
  */
 GstElement *
 gst_parse_bin_from_description_full (const gchar * bin_description,
@@ -3040,6 +3041,7 @@ gst_parse_bin_from_description_full (const gchar * bin_description,
 {
 #ifndef GST_DISABLE_PARSE
   GstPad *pad = NULL;
+  GstElement *element;
   GstBin *bin;
   gchar *desc;
 
@@ -3049,16 +3051,26 @@ gst_parse_bin_from_description_full (const gchar * bin_description,
   GST_DEBUG ("Making bin from description '%s'", bin_description);
 
   /* parse the pipeline to a bin */
-  desc = g_strdup_printf ("bin.( %s )", bin_description);
-  bin = (GstBin *) gst_parse_launch_full (desc, context, flags, err);
-  g_free (desc);
+  if (flags & GST_PARSE_FLAG_NO_SINGLE_ELEMENT_BINS) {
+    element = gst_parse_launch_full (bin_description, context, flags, err);
+  } else {
+    desc = g_strdup_printf ("bin.( %s )", bin_description);
+    element = gst_parse_launch_full (desc, context, flags, err);
+    g_free (desc);
+  }
 
-  if (bin == NULL || (err && *err != NULL)) {
-    if (bin)
-      gst_object_unref (bin);
+  if (element == NULL || (err && *err != NULL)) {
+    if (element)
+      gst_object_unref (element);
     return NULL;
   }
 
+  if (GST_IS_BIN (element)) {
+    bin = GST_BIN (element);
+  } else {
+    return element;
+  }
+
   /* find pads and ghost them if necessary */
   if (ghost_unlinked_pads) {
     if ((pad = gst_bin_find_unlinked_pad (bin, GST_PAD_SRC))) {
index cd26a2a..8a9019c 100644 (file)
@@ -352,7 +352,8 @@ gst_parse_new_child(GstChildProxy *child_proxy, GObject *object,
     else if (g_type_is_a (value_type, GST_TYPE_ELEMENT)) {
        GstElement *bin;
 
-       bin = gst_parse_bin_from_description (set->value_str, TRUE, NULL);
+       bin = gst_parse_bin_from_description_full (set->value_str, TRUE, NULL,
+           GST_PARSE_FLAG_NO_SINGLE_ELEMENT_BINS, NULL);
        if (bin) {
          g_value_set_object (&v, bin);
          got_value = TRUE;
@@ -447,7 +448,8 @@ gst_parse_element_set (gchar *value, GstElement *element, graph_t *graph)
     else if (g_type_is_a (value_type, GST_TYPE_ELEMENT)) {
        GstElement *bin;
 
-       bin = gst_parse_bin_from_description (pos, TRUE, NULL);
+       bin = gst_parse_bin_from_description_full (pos, TRUE, NULL,
+           GST_PARSE_FLAG_NO_SINGLE_ELEMENT_BINS, NULL);
        if (bin) {
          g_value_set_object (&v, bin);
          got_value = TRUE;