* @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())
* 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,
{
#ifndef GST_DISABLE_PARSE
GstPad *pad = NULL;
+ GstElement *element;
GstBin *bin;
gchar *desc;
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))) {
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;
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;