From 48319d4be2365559d785a55c5569ff9a629e9575 Mon Sep 17 00:00:00 2001 From: Brendan Long Date: Mon, 1 Jul 2013 14:04:46 -0600 Subject: [PATCH] parse: Add GST_FLAG_NO_SINGLE_ELEMENT_BINS 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 | 5 ++++- gst/gstutils.c | 28 ++++++++++++++++++++-------- gst/parse/grammar.y | 6 ++++-- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/gst/gstparse.h b/gst/gstparse.h index 09013d9..de437b1 100644 --- a/gst/gstparse.h +++ b/gst/gstparse.h @@ -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()) diff --git a/gst/gstutils.c b/gst/gstutils.c index fe982bf..09cd786 100644 --- a/gst/gstutils.c +++ b/gst/gstutils.c @@ -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))) { diff --git a/gst/parse/grammar.y b/gst/parse/grammar.y index cd26a2a..8a9019c2 100644 --- a/gst/parse/grammar.y +++ b/gst/parse/grammar.y @@ -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; -- 2.7.4