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
This commit is contained in:
Brendan Long 2013-07-01 14:04:46 -06:00 committed by Sebastian Dröge
parent 9819e48b92
commit 48319d4be2
3 changed files with 28 additions and 11 deletions

View 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())

View 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))) {

View 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;