2 #include "../gst_private.h"
4 #include <glib-object.h>
10 #include "../gst-i18n-lib.h"
12 #include "../gstconfig.h"
13 #include "../gstparse.h"
14 #include "../gstinfo.h"
15 #include "../gsterror.h"
16 #include "../gststructure.h"
17 #include "../gsturi.h"
18 #include "../gstutils.h"
19 #include "../gstvalue.h"
20 #include "../gstchildproxy.h"
23 /* All error messages in this file are user-visible and need to be translated.
24 * Don't start the message with a capital, and don't end them with a period,
25 * as they will be presented inside a sentence/error.
28 #define YYERROR_VERBOSE 1
29 #define YYLEX_PARAM scanner
31 typedef void* yyscan_t;
33 int _gst_parse_yylex (void * yylval_param , yyscan_t yyscanner);
34 int _gst_parse_yylex_init (yyscan_t scanner);
35 int _gst_parse_yylex_destroy (yyscan_t scanner);
36 struct yy_buffer_state * _gst_parse_yy_scan_string (char* , yyscan_t);
37 void _gst_parse_yypush_buffer_state (void * new_buffer ,yyscan_t yyscanner );
38 void _gst_parse_yypop_buffer_state (yyscan_t yyscanner );
41 #ifdef __GST_PARSE_TRACE
42 static guint __strings;
44 static guint __chains;
46 __gst_parse_strdup (gchar *org)
51 /* g_print ("ALLOCATED STR (%3u): %p %s\n", __strings, ret, ret); */
55 __gst_parse_strfree (gchar *str)
58 /* g_print ("FREEING STR (%3u): %p %s\n", __strings - 1, str, str); */
60 g_return_if_fail (__strings > 0);
64 link_t *__gst_parse_link_new ()
68 ret = g_slice_new0 (link_t);
69 /* g_print ("ALLOCATED LINK (%3u): %p\n", __links, ret); */
73 __gst_parse_link_free (link_t *data)
76 /* g_print ("FREEING LINK (%3u): %p\n", __links - 1, data); */
77 g_slice_free (link_t, data);
78 g_return_if_fail (__links > 0);
83 __gst_parse_chain_new ()
87 ret = g_slice_new0 (chain_t);
88 /* g_print ("ALLOCATED CHAIN (%3u): %p\n", __chains, ret); */
92 __gst_parse_chain_free (chain_t *data)
94 /* g_print ("FREEING CHAIN (%3u): %p\n", __chains - 1, data); */
95 g_slice_free (chain_t, data);
96 g_return_if_fail (__chains > 0);
100 #endif /* __GST_PARSE_TRACE */
117 /*** define SET_ERROR macro/function */
119 #ifdef G_HAVE_ISO_VARARGS
121 # define SET_ERROR(error, type, ...) \
123 GST_CAT_ERROR (GST_CAT_PIPELINE, __VA_ARGS__); \
124 if ((error) && !*(error)) { \
125 g_set_error ((error), GST_PARSE_ERROR, (type), __VA_ARGS__); \
129 #elif defined(G_HAVE_GNUC_VARARGS)
131 # define SET_ERROR(error, type, args...) \
133 GST_CAT_ERROR (GST_CAT_PIPELINE, args ); \
134 if ((error) && !*(error)) { \
135 g_set_error ((error), GST_PARSE_ERROR, (type), args ); \
142 SET_ERROR (GError **error, gint type, const char *format, ...)
146 g_warning ("error while parsing");
151 va_start (varargs, format);
152 string = g_strdup_vprintf (format, varargs);
155 g_set_error (error, GST_PARSE_ERROR, type, string);
162 #endif /* G_HAVE_ISO_VARARGS */
164 /*** define YYPRINTF macro/function if we're debugging */
166 /* bison 1.35 calls this macro with side effects, we need to make sure the
167 side effects work - crappy bison */
169 #ifndef GST_DISABLE_GST_DEBUG
172 # ifdef G_HAVE_ISO_VARARGS
174 /* # define YYFPRINTF(a, ...) GST_CAT_DEBUG (GST_CAT_PIPELINE, __VA_ARGS__) */
175 # define YYFPRINTF(a, ...) \
177 GST_CAT_LOG (GST_CAT_PIPELINE, __VA_ARGS__); \
180 # elif defined(G_HAVE_GNUC_VARARGS)
182 # define YYFPRINTF(a, args...) \
184 GST_CAT_LOG (GST_CAT_PIPELINE, args); \
190 YYPRINTF(const char *format, ...)
195 va_start (varargs, format);
196 temp = g_strdup_vprintf (format, varargs);
197 GST_CAT_LOG (GST_CAT_PIPELINE, "%s", temp);
202 # endif /* G_HAVE_ISO_VARARGS */
204 #endif /* GST_DISABLE_GST_DEBUG */
206 #define ADD_MISSING_ELEMENT(graph,name) G_STMT_START { \
207 if ((graph)->ctx) { \
208 (graph)->ctx->missing_elements = \
209 g_list_append ((graph)->ctx->missing_elements, g_strdup (name)); \
212 #define GST_BIN_MAKE(res, type, chainval, assign, free_string) \
214 chain_t *chain = chainval; \
216 GstBin *bin = (GstBin *) gst_element_factory_make (type, NULL); \
218 SET_ERROR (graph->error, GST_PARSE_ERROR_EMPTY_BIN, \
219 _("specified empty bin \"%s\", not allowed"), type); \
220 g_slist_foreach (assign, (GFunc) gst_parse_strfree, NULL); \
221 g_slist_free (assign); \
222 gst_object_unref (bin); \
224 gst_parse_strfree (type); /* Need to clean up the string */ \
227 ADD_MISSING_ELEMENT(graph, type); \
228 SET_ERROR (graph->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT, \
229 _("no bin \"%s\", skipping"), type); \
230 g_slist_foreach (assign, (GFunc) gst_parse_strfree, NULL); \
231 g_slist_free (assign); \
234 for (walk = chain->elements; walk; walk = walk->next ) \
235 gst_bin_add (bin, GST_ELEMENT (walk->data)); \
236 g_slist_free (chain->elements); \
237 chain->elements = g_slist_prepend (NULL, bin); \
239 /* set the properties now */ \
240 for (walk = assign; walk; walk = walk->next) \
241 gst_parse_element_set ((gchar *) walk->data, GST_ELEMENT (bin), graph); \
242 g_slist_free (assign); \
246 #define MAKE_LINK(link, _src, _src_name, _src_pads, _sink, _sink_name, _sink_pads) \
248 link = gst_parse_link_new (); \
250 link->sink = _sink; \
251 link->src_name = _src_name; \
252 link->sink_name = _sink_name; \
253 link->src_pads = _src_pads; \
254 link->sink_pads = _sink_pads; \
258 #define MAKE_REF(link, _src, _pads) \
260 gchar *padname = _src; \
261 GSList *pads = _pads; \
263 while (*padname != '.') padname++; \
266 if (*padname != '\0') \
267 pads = g_slist_prepend (pads, gst_parse_strdup (padname)); \
269 MAKE_LINK (link, NULL, _src, pads, NULL, NULL, NULL); \
272 static void gst_parse_new_child(GstChildProxy *child_proxy, GObject *object,
275 DelayedSet *set = (DelayedSet *) data;
278 GstObject *target = NULL;
281 if (gst_child_proxy_lookup (GST_OBJECT (set->parent), set->name, &target, &pspec)) {
282 gboolean got_value = FALSE;
284 value_type = G_PARAM_SPEC_VALUE_TYPE (pspec);
286 GST_CAT_LOG (GST_CAT_PIPELINE, "parsing delayed property %s as a %s from %s", pspec->name,
287 g_type_name (value_type), set->value_str);
288 g_value_init (&v, value_type);
289 if (gst_value_deserialize (&v, set->value_str))
291 else if (g_type_is_a (value_type, GST_TYPE_ELEMENT)) {
294 bin = gst_parse_bin_from_description (set->value_str, TRUE, NULL);
296 g_value_set_object (&v, bin);
300 g_signal_handler_disconnect (child_proxy, set->signal_id);
303 g_object_set_property (G_OBJECT (target), pspec->name, &v);
310 gst_object_unref (target);
314 GST_CAT_ERROR (GST_CAT_PIPELINE, "could not set property \"%s\" in element \"%s\"",
315 pspec->name, GST_ELEMENT_NAME (target));
320 gst_parse_free_delayed_set (DelayedSet *set) {
322 g_free(set->value_str);
323 g_slice_free(DelayedSet, set);
327 gst_parse_element_set (gchar *value, GstElement *element, graph_t *graph)
332 GstObject *target = NULL;
335 /* do nothing if assignment is for missing element */
339 /* parse the string, so the property name is null-terminated an pos points
340 to the beginning of the value */
341 while (!g_ascii_isspace (*pos) && (*pos != '=')) pos++;
347 while (g_ascii_isspace (*pos)) pos++;
350 while (g_ascii_isspace (*pos)) pos++;
353 pos[strlen (pos) - 1] = '\0';
355 gst_parse_unescape (pos);
357 if (gst_child_proxy_lookup (GST_OBJECT (element), value, &target, &pspec)) {
358 gboolean got_value = FALSE;
360 value_type = G_PARAM_SPEC_VALUE_TYPE (pspec);
362 GST_CAT_LOG (GST_CAT_PIPELINE, "parsing property %s as a %s", pspec->name,
363 g_type_name (value_type));
364 g_value_init (&v, value_type);
365 if (gst_value_deserialize (&v, pos))
367 else if (g_type_is_a (value_type, GST_TYPE_ELEMENT)) {
370 bin = gst_parse_bin_from_description (pos, TRUE, NULL);
372 g_value_set_object (&v, bin);
378 g_object_set_property (G_OBJECT (target), pspec->name, &v);
380 /* do a delayed set */
381 if (GST_IS_CHILD_PROXY (element)) {
382 DelayedSet *data = g_slice_new0 (DelayedSet);
384 data->parent = element;
385 data->name = g_strdup(value);
386 data->value_str = g_strdup(pos);
387 data->signal_id = g_signal_connect_data(element, "child-added",
388 G_CALLBACK (gst_parse_new_child), data, (GClosureNotify)
389 gst_parse_free_delayed_set, (GConnectFlags) 0);
392 SET_ERROR (graph->error, GST_PARSE_ERROR_NO_SUCH_PROPERTY, \
393 _("no property \"%s\" in element \"%s\""), value, \
394 GST_ELEMENT_NAME (element));
399 gst_parse_strfree (value);
403 gst_object_unref (target);
407 SET_ERROR (graph->error, GST_PARSE_ERROR_COULD_NOT_SET_PROPERTY,
408 _("could not set property \"%s\" in element \"%s\" to \"%s\""),
409 value, GST_ELEMENT_NAME (element), pos);
413 gst_parse_free_link (link_t *link)
415 gst_parse_strfree (link->src_name);
416 gst_parse_strfree (link->sink_name);
417 g_slist_foreach (link->src_pads, (GFunc) gst_parse_strfree, NULL);
418 g_slist_foreach (link->sink_pads, (GFunc) gst_parse_strfree, NULL);
419 g_slist_free (link->src_pads);
420 g_slist_free (link->sink_pads);
421 if (link->caps) gst_caps_unref (link->caps);
422 gst_parse_link_free (link);
426 gst_parse_free_delayed_link (DelayedLink *link)
428 g_free (link->src_pad);
429 g_free (link->sink_pad);
430 if (link->caps) gst_caps_unref (link->caps);
431 g_slice_free (DelayedLink, link);
435 gst_parse_found_pad (GstElement *src, GstPad *pad, gpointer data)
437 DelayedLink *link = data;
439 GST_CAT_INFO (GST_CAT_PIPELINE, "trying delayed linking %s:%s to %s:%s",
440 GST_STR_NULL (GST_ELEMENT_NAME (src)), GST_STR_NULL (link->src_pad),
441 GST_STR_NULL (GST_ELEMENT_NAME (link->sink)), GST_STR_NULL (link->sink_pad));
443 if (gst_element_link_pads_filtered (src, link->src_pad, link->sink,
444 link->sink_pad, link->caps)) {
445 /* do this here, we don't want to get any problems later on when
446 * unlocking states */
447 GST_CAT_DEBUG (GST_CAT_PIPELINE, "delayed linking %s:%s to %s:%s worked",
448 GST_STR_NULL (GST_ELEMENT_NAME (src)), GST_STR_NULL (link->src_pad),
449 GST_STR_NULL (GST_ELEMENT_NAME (link->sink)), GST_STR_NULL (link->sink_pad));
450 g_signal_handler_disconnect (src, link->signal_id);
453 /* both padnames and the caps may be NULL */
455 gst_parse_perform_delayed_link (GstElement *src, const gchar *src_pad,
456 GstElement *sink, const gchar *sink_pad,
459 GList *templs = gst_element_class_get_pad_template_list (
460 GST_ELEMENT_GET_CLASS (src));
462 for (; templs; templs = templs->next) {
463 GstPadTemplate *templ = (GstPadTemplate *) templs->data;
464 if ((GST_PAD_TEMPLATE_DIRECTION (templ) == GST_PAD_SRC) &&
465 (GST_PAD_TEMPLATE_PRESENCE(templ) == GST_PAD_SOMETIMES))
467 DelayedLink *data = g_slice_new (DelayedLink);
469 /* TODO: maybe we should check if src_pad matches this template's names */
471 GST_CAT_DEBUG (GST_CAT_PIPELINE, "trying delayed link %s:%s to %s:%s",
472 GST_STR_NULL (GST_ELEMENT_NAME (src)), GST_STR_NULL (src_pad),
473 GST_STR_NULL (GST_ELEMENT_NAME (sink)), GST_STR_NULL (sink_pad));
475 data->src_pad = g_strdup (src_pad);
477 data->sink_pad = g_strdup (sink_pad);
479 data->caps = gst_caps_copy (caps);
483 data->signal_id = g_signal_connect_data (src, "pad-added",
484 G_CALLBACK (gst_parse_found_pad), data,
485 (GClosureNotify) gst_parse_free_delayed_link, (GConnectFlags) 0);
492 * performs a link and frees the struct. src and sink elements must be given
493 * return values 0 - link performed
498 gst_parse_perform_link (link_t *link, graph_t *graph)
500 GstElement *src = link->src;
501 GstElement *sink = link->sink;
502 GSList *srcs = link->src_pads;
503 GSList *sinks = link->sink_pads;
504 g_assert (GST_IS_ELEMENT (src));
505 g_assert (GST_IS_ELEMENT (sink));
507 GST_CAT_INFO (GST_CAT_PIPELINE,
508 "linking %s:%s to %s:%s (%u/%u) with caps \"%" GST_PTR_FORMAT "\"",
509 GST_ELEMENT_NAME (src), link->src_name ? link->src_name : "(any)",
510 GST_ELEMENT_NAME (sink), link->sink_name ? link->sink_name : "(any)",
511 g_slist_length (srcs), g_slist_length (sinks), link->caps);
513 if (!srcs || !sinks) {
514 if (gst_element_link_pads_filtered (src,
515 srcs ? (const gchar *) srcs->data : NULL, sink,
516 sinks ? (const gchar *) sinks->data : NULL, link->caps)) {
519 if (gst_parse_perform_delayed_link (src,
520 srcs ? (const gchar *) srcs->data : NULL,
521 sink, sinks ? (const gchar *) sinks->data : NULL, link->caps)) {
528 if (g_slist_length (link->src_pads) != g_slist_length (link->src_pads)) {
531 while (srcs && sinks) {
532 const gchar *src_pad = (const gchar *) srcs->data;
533 const gchar *sink_pad = (const gchar *) sinks->data;
534 srcs = g_slist_next (srcs);
535 sinks = g_slist_next (sinks);
536 if (gst_element_link_pads_filtered (src, src_pad, sink, sink_pad,
540 if (gst_parse_perform_delayed_link (src, src_pad,
551 gst_parse_free_link (link);
555 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK,
556 _("could not link %s to %s"), GST_ELEMENT_NAME (src),
557 GST_ELEMENT_NAME (sink));
558 gst_parse_free_link (link);
563 static int yyerror (void *scanner, graph_t *graph, const char *s);
576 %token <s> IDENTIFIER
577 %left <s> REF PADREF BINREF
578 %token <s> ASSIGNMENT
584 %type <l> linkpart link
587 %type <p> padlist pads assignments
594 %parse-param { void *scanner }
595 %parse-param { graph_t *graph }
601 element: IDENTIFIER { $$ = gst_element_factory_make ($1, NULL);
603 ADD_MISSING_ELEMENT (graph, $1);
604 SET_ERROR (graph->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT, _("no element \"%s\""), $1);
605 /* if FATAL_ERRORS flag is set, we don't have to worry about backwards
606 * compatibility and can continue parsing and check for other missing
608 if ((graph->flags & GST_PARSE_FLAG_FATAL_ERRORS) == 0) {
609 gst_parse_strfree ($1);
613 gst_parse_strfree ($1);
615 | element ASSIGNMENT { gst_parse_element_set ($2, $1, graph);
619 assignments: /* NOP */ { $$ = NULL; }
620 | assignments ASSIGNMENT { $$ = g_slist_prepend ($1, $2); }
622 bin: '(' assignments chain ')' { GST_BIN_MAKE ($$, "bin", $3, $2, FALSE); }
623 | BINREF assignments chain ')' { GST_BIN_MAKE ($$, $1, $3, $2, TRUE);
624 gst_parse_strfree ($1);
626 | BINREF assignments ')' { GST_BIN_MAKE ($$, $1, NULL, $2, TRUE);
627 gst_parse_strfree ($1);
629 | BINREF assignments error ')' { GST_BIN_MAKE ($$, $1, NULL, $2, TRUE);
630 gst_parse_strfree ($1);
634 pads: PADREF { $$ = g_slist_prepend (NULL, $1); }
635 | PADREF padlist { $$ = $2;
636 $$ = g_slist_prepend ($$, $1);
639 padlist: ',' IDENTIFIER { $$ = g_slist_prepend (NULL, $2); }
640 | ',' IDENTIFIER padlist { $$ = g_slist_prepend ($3, $2); }
643 reference: REF { MAKE_REF ($$, $1, NULL); }
644 | REF padlist { MAKE_REF ($$, $1, $2); }
647 linkpart: reference { $$ = $1; }
648 | pads { MAKE_REF ($$, NULL, $1); }
649 | /* NOP */ { MAKE_REF ($$, NULL, NULL); }
652 link: linkpart LINK linkpart { $$ = $1;
654 $$->caps = gst_caps_from_string ($2);
655 if ($$->caps == NULL)
656 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK, _("could not parse caps \"%s\""), $2);
657 gst_parse_strfree ($2);
659 $$->sink_name = $3->src_name;
660 $$->sink_pads = $3->src_pads;
661 gst_parse_link_free ($3);
665 linklist: link { $$ = g_slist_prepend (NULL, $1); }
666 | link linklist { $$ = g_slist_prepend ($2, $1); }
667 | linklist error { $$ = $1; }
670 chain: element { $$ = gst_parse_chain_new ();
671 $$->first = $$->last = $1;
672 $$->front = $$->back = NULL;
673 $$->elements = g_slist_prepend (NULL, $1);
676 | chain chain { if ($1->back && $2->front) {
677 if (!$1->back->sink_name) {
678 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK, _("link without source element"));
679 gst_parse_free_link ($1->back);
681 graph->links = g_slist_prepend (graph->links, $1->back);
683 if (!$2->front->src_name) {
684 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK, _("link without sink element"));
685 gst_parse_free_link ($2->front);
687 graph->links = g_slist_prepend (graph->links, $2->front);
690 } else if ($1->back) {
691 if (!$1->back->sink_name) {
692 $1->back->sink = $2->first;
694 } else if ($2->front) {
695 if (!$2->front->src_name) {
696 $2->front->src = $1->last;
698 $1->back = $2->front;
702 graph->links = g_slist_prepend (graph->links, $1->back);
706 $1->elements = g_slist_concat ($1->elements, $2->elements);
708 gst_parse_chain_free ($2);
711 | chain linklist { GSList *walk;
713 $2 = g_slist_prepend ($2, $1->back);
716 if (!((link_t *) $2->data)->src_name) {
717 ((link_t *) $2->data)->src = $1->last;
720 for (walk = $2; walk; walk = walk->next) {
721 link_t *link = (link_t *) walk->data;
722 if (!link->sink_name && walk->next) {
723 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK, _("link without sink element"));
724 gst_parse_free_link (link);
725 } else if (!link->src_name && !link->src) {
726 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK, _("link without source element"));
727 gst_parse_free_link (link);
730 graph->links = g_slist_prepend (graph->links, link);
739 | chain error { $$ = $1; }
740 | link chain { if ($2->front) {
741 if (!$2->front->src_name) {
742 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK, _("link without source element"));
743 gst_parse_free_link ($2->front);
745 graph->links = g_slist_prepend (graph->links, $2->front);
748 if (!$1->sink_name) {
749 $1->sink = $2->first;
754 | PARSE_URL chain { $$ = $2;
756 GstElement *element =
757 gst_element_make_from_uri (GST_URI_SRC, $1, NULL);
759 SET_ERROR (graph->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
760 _("no source element for URI \"%s\""), $1);
762 $$->front->src = element;
763 graph->links = g_slist_prepend (
764 graph->links, $$->front);
766 $$->elements = g_slist_prepend ($$->elements, element);
769 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK,
770 _("no element to link URI \"%s\" to"), $1);
774 | link PARSE_URL { GstElement *element =
775 gst_element_make_from_uri (GST_URI_SINK, $2, NULL);
777 SET_ERROR (graph->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
778 _("no sink element for URI \"%s\""), $2);
779 gst_parse_link_free ($1);
782 } else if ($1->sink_name || $1->sink_pads) {
783 gst_object_unref (element);
784 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK,
785 _("could not link sink element for URI \"%s\""), $2);
786 gst_parse_link_free ($1);
790 $$ = gst_parse_chain_new ();
791 $$->first = $$->last = element;
793 $$->front->sink = element;
794 $$->elements = g_slist_prepend (NULL, element);
799 graph: /* NOP */ { SET_ERROR (graph->error, GST_PARSE_ERROR_EMPTY, _("empty pipeline not allowed"));
802 | chain { $$ = graph;
804 if (!$1->front->src_name) {
805 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK, _("link without source element"));
806 gst_parse_free_link ($1->front);
808 $$->links = g_slist_prepend ($$->links, $1->front);
813 if (!$1->back->sink_name) {
814 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK, _("link without sink element"));
815 gst_parse_free_link ($1->back);
817 $$->links = g_slist_prepend ($$->links, $1->back);
829 yyerror (void *scanner, graph_t *graph, const char *s)
831 /* FIXME: This should go into the GError somehow, but how? */
832 GST_WARNING ("Error during parsing: %s", s);
838 _gst_parse_launch (const gchar *str, GError **error, GstParseContext *ctx,
848 g_return_val_if_fail (str != NULL, NULL);
849 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
857 #ifdef __GST_PARSE_TRACE
858 GST_CAT_DEBUG (GST_CAT_PIPELINE, "TRACE: tracing enabled");
859 __strings = __chains = __links = 0;
860 #endif /* __GST_PARSE_TRACE */
862 dstr = g_strdup (str);
863 _gst_parse_yylex_init (&scanner);
864 _gst_parse_yy_scan_string (dstr, scanner);
870 if (yyparse (scanner, &g) != 0) {
871 SET_ERROR (error, GST_PARSE_ERROR_SYNTAX,
872 "Unrecoverable syntax error while parsing pipeline %s", str);
874 _gst_parse_yylex_destroy (scanner);
879 _gst_parse_yylex_destroy (scanner);
882 GST_CAT_DEBUG (GST_CAT_PIPELINE, "got %u elements and %u links",
883 g.chain ? g_slist_length (g.chain->elements) : 0,
884 g_slist_length (g.links));
888 } else if (!g.chain->elements->next) {
889 /* only one toplevel element */
890 ret = (GstElement *) g.chain->elements->data;
891 g_slist_free (g.chain->elements);
892 if (GST_IS_BIN (ret))
894 gst_parse_chain_free (g.chain);
896 /* put all elements in our bin */
897 bin = GST_BIN (gst_element_factory_make ("pipeline", NULL));
900 for (walk = g.chain->elements; walk; walk = walk->next) {
901 if (walk->data != NULL)
902 gst_bin_add (bin, GST_ELEMENT (walk->data));
905 g_slist_free (g.chain->elements);
906 ret = GST_ELEMENT (bin);
907 gst_parse_chain_free (g.chain);
911 for (walk = g.links; walk; walk = walk->next) {
912 link_t *l = (link_t *) walk->data;
916 l->src = gst_bin_get_by_name_recurse_up (bin, l->src_name);
918 gst_object_unref (l->src);
920 l->src = strcmp (GST_ELEMENT_NAME (ret), l->src_name) == 0 ? ret : NULL;
925 SET_ERROR (error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
926 "No element named \"%s\" - omitting link", l->src_name);
928 /* probably a missing element which we've handled already */
930 gst_parse_free_link (l);
937 l->sink = gst_bin_get_by_name_recurse_up (bin, l->sink_name);
939 gst_object_unref (l->sink);
941 l->sink = strcmp (GST_ELEMENT_NAME (ret), l->sink_name) == 0 ? ret : NULL;
946 SET_ERROR (error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
947 "No element named \"%s\" - omitting link", l->sink_name);
949 /* probably a missing element which we've handled already */
951 gst_parse_free_link (l);
955 gst_parse_perform_link (l, &g);
957 g_slist_free (g.links);
960 #ifdef __GST_PARSE_TRACE
961 GST_CAT_DEBUG (GST_CAT_PIPELINE,
962 "TRACE: %u strings, %u chains and %u links left", __strings, __chains,
964 if (__strings || __chains || __links) {
965 g_warning ("TRACE: %u strings, %u chains and %u links left", __strings,
968 #endif /* __GST_PARSE_TRACE */
974 g_slist_foreach (g.chain->elements, (GFunc)gst_object_unref, NULL);
975 g_slist_free (g.chain->elements);
976 gst_parse_chain_free (g.chain);
979 g_slist_foreach (g.links, (GFunc)gst_parse_free_link, NULL);
980 g_slist_free (g.links);