2 #include <glib-object.h>
8 #include "../gst_private.h"
9 #include "../gst-i18n-lib.h"
11 #include "../gstconfig.h"
12 #include "../gstparse.h"
13 #include "../gstinfo.h"
14 #include "../gsterror.h"
15 #include "../gsturi.h"
16 #include "../gstutils.h"
17 #include "../gstvalue.h"
18 #include "../gstchildproxy.h"
21 /* All error messages in this file are user-visible and need to be translated.
22 * Don't start the message with a capital, and don't end them with a period,
23 * as they will be presented inside a sentence/error.
26 #define YYERROR_VERBOSE 1
27 #define YYPARSE_PARAM graph
29 #ifdef __GST_PARSE_TRACE
30 static guint __strings;
32 static guint __chains;
34 __gst_parse_strdup (gchar *org)
39 /* g_print ("ALLOCATED STR (%3u): %p %s\n", __strings, ret, ret); */
43 __gst_parse_strfree (gchar *str)
46 /* g_print ("FREEING STR (%3u): %p %s\n", __strings - 1, str, str); */
48 g_return_if_fail (__strings > 0);
52 link_t *__gst_parse_link_new ()
56 ret = g_new0 (link_t, 1);
57 /* g_print ("ALLOCATED LINK (%3u): %p\n", __links, ret); */
61 __gst_parse_link_free (link_t *data)
64 /* g_print ("FREEING LINK (%3u): %p\n", __links - 1, data); */
66 g_return_if_fail (__links > 0);
71 __gst_parse_chain_new ()
75 ret = g_new0 (chain_t, 1);
76 /* g_print ("ALLOCATED CHAIN (%3u): %p\n", __chains, ret); */
80 __gst_parse_chain_free (chain_t *data)
82 /* g_print ("FREEING CHAIN (%3u): %p\n", __chains - 1, data); */
84 g_return_if_fail (__chains > 0);
88 #endif /* __GST_PARSE_TRACE */
96 /* FIXME: need to connect to "disposed" signal to clean up, but there is no such signal */
99 #ifdef G_HAVE_ISO_VARARGS
100 #define SET_ERROR(error, type, ...) G_STMT_START{ \
101 GST_CAT_ERROR (GST_CAT_PIPELINE, __VA_ARGS__); \
102 if ((error) && !*(error)) { \
103 g_set_error ((error), GST_PARSE_ERROR, (type), __VA_ARGS__); \
106 #define ERROR(type, ...) SET_ERROR (((graph_t *) graph)->error, (type), __VA_ARGS__ )
107 #ifndef GST_DISABLE_GST_DEBUG
109 /* bison 1.35 calls this macro with side effects, we need to make sure the
110 side effects work - crappy bison
111 # define YYFPRINTF(a, ...) GST_CAT_DEBUG (GST_CAT_PIPELINE, __VA_ARGS__)
113 # define YYFPRINTF(a, ...) G_STMT_START{ \
114 gchar *temp = g_strdup_printf (__VA_ARGS__); \
115 GST_CAT_LOG (GST_CAT_PIPELINE, temp); \
120 #elif defined(G_HAVE_GNUC_VARARGS)
122 #define SET_ERROR(error, type, args...) G_STMT_START{ \
123 GST_CAT_ERROR (GST_CAT_PIPELINE, args ); \
124 if ((error) && !*(error)) { \
125 g_set_error ((error), GST_PARSE_ERROR, (type), args ); \
128 #define ERROR(type, args...) SET_ERROR (((graph_t *) graph)->error, (type) , args )
129 #ifndef GST_DISABLE_GST_DEBUG
131 /* bison 1.35 calls this macro with side effects, we need to make sure the
132 side effects work - crappy bison
133 # define YYFPRINTF(a, args...) GST_CAT_DEBUG (GST_CAT_PIPELINE, args )
135 # define YYFPRINTF(a, args...) G_STMT_START{ \
136 gchar *temp = g_strdup_printf ( args ); \
137 GST_CAT_LOG (GST_CAT_PIPELINE, temp); \
145 SET_ERROR (GError **error, gint type, const char *format, ...)
149 g_warning ("error while parsing");
154 va_start (varargs, format);
155 string = g_strdup_vprintf (format, varargs);
158 g_set_error (error, GST_PARSE_ERROR, type, string);
165 #ifndef GST_DISABLE_GST_DEBUG
168 YYPRINTF(const char *format, ...)
173 va_start (varargs, format);
174 temp = g_strdup_vprintf ( format, varargs );
175 GST_CAT_LOG (GST_CAT_PIPELINE, "%s", temp);
183 #define GST_BIN_MAKE(res, type, chainval, assign) G_STMT_START{ \
184 chain_t *chain = chainval; \
186 GstBin *bin = (GstBin *) gst_element_factory_make (type, NULL); \
188 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_EMPTY_BIN, _("specified empty bin \"%s\", not allowed"), type); \
189 g_slist_foreach (assign, (GFunc) gst_parse_strfree, NULL); \
190 g_slist_free (assign); \
193 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT, _("no bin \"%s\", skipping"), type); \
194 g_slist_foreach (assign, (GFunc) gst_parse_strfree, NULL); \
195 g_slist_free (assign); \
198 for (walk = chain->elements; walk; walk = walk->next ) \
199 gst_bin_add (bin, GST_ELEMENT (walk->data)); \
200 g_slist_free (chain->elements); \
201 chain->elements = g_slist_prepend (NULL, bin); \
203 /* set the properties now */ \
204 for (walk = assign; walk; walk = walk->next) \
205 gst_parse_element_set ((gchar *) walk->data, GST_ELEMENT (bin), graph); \
206 g_slist_free (assign); \
210 #define MAKE_LINK(link, _src, _src_name, _src_pads, _sink, _sink_name, _sink_pads) G_STMT_START{ \
211 link = gst_parse_link_new (); \
213 link->sink = _sink; \
214 link->src_name = _src_name; \
215 link->sink_name = _sink_name; \
216 link->src_pads = _src_pads; \
217 link->sink_pads = _sink_pads; \
221 #define MAKE_REF(link, _src, _pads) G_STMT_START{ \
222 gchar *padname = _src; \
223 GSList *pads = _pads; \
225 while (*padname != '.') padname++; \
228 if (*padname != '\0') \
229 pads = g_slist_prepend (pads, gst_parse_strdup (padname)); \
231 MAKE_LINK (link, NULL, _src, pads, NULL, NULL, NULL); \
235 gst_parse_element_set (gchar *value, GstElement *element, graph_t *graph)
244 /* parse the string, so the property name is null-terminated an pos points
245 to the beginning of the value */
246 while (!g_ascii_isspace (*pos) && (*pos != '=')) pos++;
252 while (g_ascii_isspace (*pos)) pos++;
255 while (g_ascii_isspace (*pos)) pos++;
258 pos[strlen (pos) - 1] = '\0';
260 gst_parse_unescape (pos);
262 if (gst_child_proxy_lookup (GST_OBJECT (element), value, &target, &pspec)) {
263 value_type = G_PARAM_SPEC_VALUE_TYPE (pspec);
264 GST_LOG ("parsing property %s as a %s", pspec->name,
265 g_type_name (value_type));
266 g_value_init (&v, value_type);
267 if (!gst_value_deserialize (&v, pos))
269 g_object_set_property (G_OBJECT (target), pspec->name, &v);
270 gst_object_unref (target);
272 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_NO_SUCH_PROPERTY, _("no property \"%s\" in element \"%s\""), value, GST_ELEMENT_NAME (element));
276 gst_parse_strfree (value);
279 if (G_IS_VALUE (&v2))
284 gst_object_unref (target);
285 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_COULD_NOT_SET_PROPERTY,
286 _("could not set property \"%s\" in element \"%s\" to \"%s\""),
287 value, GST_ELEMENT_NAME (element), pos);
291 gst_parse_free_link (link_t *link)
293 gst_parse_strfree (link->src_name);
294 gst_parse_strfree (link->sink_name);
295 g_slist_foreach (link->src_pads, (GFunc) gst_parse_strfree, NULL);
296 g_slist_foreach (link->sink_pads, (GFunc) gst_parse_strfree, NULL);
297 g_slist_free (link->src_pads);
298 g_slist_free (link->sink_pads);
299 if (link->caps) gst_caps_unref (link->caps);
300 gst_parse_link_free (link);
304 gst_parse_element_lock (GstElement *element, gboolean lock)
308 gboolean unlocked_peer = FALSE;
309 gboolean done = FALSE;
312 if (gst_element_is_locked_state (element) == lock)
317 /* check if we have an unlocked peer */
318 pads = gst_element_iterate_pads (element);
321 switch (gst_iterator_next (pads, &data)) {
322 case GST_ITERATOR_OK:
324 GstPad *pad = GST_PAD_CAST (data);
326 if (GST_PAD_IS_SINK (pad) && GST_PAD_PEER (pad) &&
327 !gst_element_is_locked_state (GST_PAD_PARENT (GST_PAD_PEER (pad)))) {
328 unlocked_peer = TRUE;
331 gst_object_unref (GST_OBJECT (pad));
334 case GST_ITERATOR_RESYNC:
335 unlocked_peer = FALSE;
336 gst_iterator_resync (pads);
338 case GST_ITERATOR_DONE:
342 g_assert_not_reached ();
346 gst_iterator_free (pads);
348 if (!(lock && unlocked_peer)) {
349 GST_CAT_DEBUG (GST_CAT_PIPELINE, "setting locked state on element");
350 gst_element_set_locked_state (element, lock);
353 /* try to sync state with parent */
354 GST_CAT_DEBUG (GST_CAT_PIPELINE, "trying to sync state of element with parent");
355 /* FIXME: it would be nice if we can figure out why it failed
356 (e.g. caps nego) and give an error about that instead. */
357 if (gst_element_set_state (element, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
358 GST_ELEMENT_ERROR (element, CORE, STATE_CHANGE, (NULL), (NULL));
364 /* check if there are other pads to (un)lock */
365 walk = (GList *) element->pads;
366 for (; walk; walk = walk->next) {
367 pad = GST_PAD_CAST (walk->data);
368 if (GST_PAD_IS_SRC (pad) && GST_PAD_PEER (pad)) {
369 GstElement *next = GST_ELEMENT (GST_OBJECT_PARENT (GST_PAD_PEER (pad)));
370 if (gst_element_is_locked_state (next) != lock)
371 gst_parse_element_lock (next, lock);
376 gst_parse_found_pad (GstElement *src, GstPad *pad, gpointer data)
378 DelayedLink *link = (DelayedLink *) data;
380 GST_CAT_INFO (GST_CAT_PIPELINE, "trying delayed linking %s:%s to %s:%s",
381 GST_ELEMENT_NAME (src), link->src_pad,
382 GST_ELEMENT_NAME (link->sink), link->sink_pad);
384 if (gst_element_link_pads_filtered (src, link->src_pad, link->sink, link->sink_pad, link->caps)) {
385 /* do this here, we don't want to get any problems later on when unlocking states */
386 GST_CAT_DEBUG (GST_CAT_PIPELINE, "delayed linking %s:%s to %s:%s worked",
387 GST_ELEMENT_NAME (src), link->src_pad,
388 GST_ELEMENT_NAME (link->sink), link->sink_pad);
389 g_signal_handler_disconnect (src, link->signal_id);
390 g_free (link->src_pad);
391 g_free (link->sink_pad);
392 if (link->caps) gst_caps_unref (link->caps);
393 if (!gst_element_is_locked_state (src))
394 gst_parse_element_lock (link->sink, FALSE);
398 /* both padnames and the caps may be NULL */
400 gst_parse_perform_delayed_link (GstElement *src, const gchar *src_pad,
401 GstElement *sink, const gchar *sink_pad, GstCaps *caps)
403 GList *templs = gst_element_class_get_pad_template_list (GST_ELEMENT_GET_CLASS (src));
405 for (; templs; templs = templs->next) {
406 GstPadTemplate *templ = (GstPadTemplate *) templs->data;
407 if ((GST_PAD_TEMPLATE_DIRECTION (templ) == GST_PAD_SRC) && (GST_PAD_TEMPLATE_PRESENCE(templ) == GST_PAD_SOMETIMES))
409 DelayedLink *data = g_new (DelayedLink, 1);
411 /* TODO: maybe we should check if src_pad matches this template's names */
413 GST_CAT_DEBUG (GST_CAT_PIPELINE, "trying delayed link %s:%s to %s:%s",
414 GST_ELEMENT_NAME (src), src_pad, GST_ELEMENT_NAME (sink), sink_pad);
416 data->src_pad = g_strdup (src_pad);
418 data->sink_pad = g_strdup (sink_pad);
420 data->caps = gst_caps_copy (caps);
424 data->signal_id = g_signal_connect (G_OBJECT (src), "pad-added",
425 G_CALLBACK (gst_parse_found_pad), data);
432 * performs a link and frees the struct. src and sink elements must be given
433 * return values 0 - link performed
438 gst_parse_perform_link (link_t *link, graph_t *graph)
440 GstElement *src = link->src;
441 GstElement *sink = link->sink;
442 GSList *srcs = link->src_pads;
443 GSList *sinks = link->sink_pads;
444 g_assert (GST_IS_ELEMENT (src));
445 g_assert (GST_IS_ELEMENT (sink));
447 GST_CAT_INFO (GST_CAT_PIPELINE, "linking %s:%s to %s:%s (%u/%u) with caps \"%" GST_PTR_FORMAT "\"",
448 GST_ELEMENT_NAME (src), link->src_name ? link->src_name : "(any)",
449 GST_ELEMENT_NAME (sink), link->sink_name ? link->sink_name : "(any)",
450 g_slist_length (srcs), g_slist_length (sinks),
453 if (!srcs || !sinks) {
454 if (gst_element_link_pads_filtered (src, srcs ? (const gchar *) srcs->data : NULL,
455 sink, sinks ? (const gchar *) sinks->data : NULL,
457 gst_parse_element_lock (sink, gst_element_is_locked_state (src));
460 if (gst_parse_perform_delayed_link (src, srcs ? (const gchar *) srcs->data : NULL,
461 sink, sinks ? (const gchar *) sinks->data : NULL,
463 gst_parse_element_lock (sink, TRUE);
470 if (g_slist_length (link->src_pads) != g_slist_length (link->src_pads)) {
473 while (srcs && sinks) {
474 const gchar *src_pad = (const gchar *) srcs->data;
475 const gchar *sink_pad = (const gchar *) sinks->data;
476 srcs = g_slist_next (srcs);
477 sinks = g_slist_next (sinks);
478 if (gst_element_link_pads_filtered (src, src_pad, sink, sink_pad, link->caps)) {
479 gst_parse_element_lock (sink, gst_element_is_locked_state (src));
482 if (gst_parse_perform_delayed_link (src, src_pad,
485 gst_parse_element_lock (sink, TRUE);
494 gst_parse_free_link (link);
498 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("could not link %s to %s"), GST_ELEMENT_NAME (src), GST_ELEMENT_NAME (sink));
499 gst_parse_free_link (link);
504 static int yylex (void *lvalp);
505 static int yyerror (const char *s);
518 %token <s> IDENTIFIER
519 %left <s> REF PADREF BINREF
520 %token <s> ASSIGNMENT
526 %type <l> linkpart link
529 %type <p> padlist pads assignments
531 %left '{' '}' '(' ')'
541 element: IDENTIFIER { $$ = gst_element_factory_make ($1, NULL);
543 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT, _("no element \"%s\""), $1);
544 gst_parse_strfree ($1);
548 | element ASSIGNMENT { gst_parse_element_set ($2, $1, graph);
552 assignments: /* NOP */ { $$ = NULL; }
553 | assignments ASSIGNMENT { $$ = g_slist_prepend ($1, $2); }
555 bin: '{' assignments chain '}' { GST_BIN_MAKE ($$, "thread", $3, $2); }
556 | '(' assignments chain ')' { GST_BIN_MAKE ($$, "bin", $3, $2); }
557 | BINREF assignments chain ')' { GST_BIN_MAKE ($$, $1, $3, $2);
558 gst_parse_strfree ($1);
560 | '{' assignments '}' { GST_BIN_MAKE ($$, "thread", NULL, $2); }
561 | '(' assignments '}' { GST_BIN_MAKE ($$, "thread", NULL, $2); }
562 | BINREF assignments ')' { GST_BIN_MAKE ($$, $1, NULL, $2);
563 gst_parse_strfree ($1);
565 | '{' assignments error '}' { GST_BIN_MAKE ($$, "thread", NULL, $2); }
566 | '(' assignments error '}' { GST_BIN_MAKE ($$, "thread", NULL, $2); }
567 | BINREF assignments error ')' { GST_BIN_MAKE ($$, $1, NULL, $2);
568 gst_parse_strfree ($1);
572 pads: PADREF { $$ = g_slist_prepend (NULL, $1); }
573 | PADREF padlist { $$ = $2;
574 $$ = g_slist_prepend ($$, $1);
577 padlist: ',' IDENTIFIER { $$ = g_slist_prepend (NULL, $2); }
578 | ',' IDENTIFIER padlist { $$ = g_slist_prepend ($3, $2); }
581 reference: REF { MAKE_REF ($$, $1, NULL); }
582 | REF padlist { MAKE_REF ($$, $1, $2); }
585 linkpart: reference { $$ = $1; }
586 | pads { MAKE_REF ($$, NULL, $1); }
587 | /* NOP */ { MAKE_REF ($$, NULL, NULL); }
590 link: linkpart LINK linkpart { $$ = $1;
592 $$->caps = gst_caps_from_string ($2);
594 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("could not parse caps \"%s\""), $2);
595 gst_parse_strfree ($2);
597 $$->sink_name = $3->src_name;
598 $$->sink_pads = $3->src_pads;
599 gst_parse_link_free ($3);
603 linklist: link { $$ = g_slist_prepend (NULL, $1); }
604 | link linklist { $$ = g_slist_prepend ($2, $1); }
605 | linklist error { $$ = $1; }
608 chain: element { $$ = gst_parse_chain_new ();
609 $$->first = $$->last = $1;
610 $$->front = $$->back = NULL;
611 $$->elements = g_slist_prepend (NULL, $1);
614 | chain chain { if ($1->back && $2->front) {
615 if (!$1->back->sink_name) {
616 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("link without source element"));
617 gst_parse_free_link ($1->back);
619 ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, $1->back);
621 if (!$2->front->src_name) {
622 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("link without sink element"));
623 gst_parse_free_link ($2->front);
625 ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, $2->front);
628 } else if ($1->back) {
629 if (!$1->back->sink_name) {
630 $1->back->sink = $2->first;
632 } else if ($2->front) {
633 if (!$2->front->src_name) {
634 $2->front->src = $1->last;
636 $1->back = $2->front;
640 ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, $1->back);
644 $1->elements = g_slist_concat ($1->elements, $2->elements);
646 gst_parse_chain_free ($2);
649 | chain linklist { GSList *walk;
651 $2 = g_slist_prepend ($2, $1->back);
654 if (!((link_t *) $2->data)->src_name) {
655 ((link_t *) $2->data)->src = $1->last;
658 for (walk = $2; walk; walk = walk->next) {
659 link_t *link = (link_t *) walk->data;
660 if (!link->sink_name && walk->next) {
661 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("link without sink element"));
662 gst_parse_free_link (link);
663 } else if (!link->src_name && !link->src) {
664 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("link without source element"));
665 gst_parse_free_link (link);
668 ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, link);
677 | chain error { $$ = $1; }
678 | link chain { if ($2->front) {
679 if (!$2->front->src_name) {
680 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("link without source element"));
681 gst_parse_free_link ($2->front);
683 ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, $2->front);
686 if (!$1->sink_name) {
687 $1->sink = $2->first;
692 | PARSE_URL chain { $$ = $2;
694 GstElement *element =
695 gst_element_make_from_uri (GST_URI_SRC, $1, NULL);
697 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
698 _("no source element for URI \"%s\""), $1);
700 $$->front->src = element;
701 ((graph_t *) graph)->links = g_slist_prepend (
702 ((graph_t *) graph)->links, $$->front);
704 $$->elements = g_slist_prepend ($$->elements, element);
707 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK,
708 _("no element to link URI \"%s\" to"), $1);
712 | link PARSE_URL { GstElement *element =
713 gst_element_make_from_uri (GST_URI_SINK, $2, NULL);
715 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
716 _("no sink element for URI \"%s\""), $2);
718 } else if ($1->sink_name || $1->sink_pads) {
719 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK,
720 _("could not link sink element for URI \"%s\""), $2);
723 $$ = gst_parse_chain_new ();
724 $$->first = $$->last = element;
726 $$->front->sink = element;
727 $$->elements = g_slist_prepend (NULL, element);
732 graph: /* NOP */ { SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_EMPTY, _("empty pipeline not allowed"));
733 $$ = (graph_t *) graph;
735 | chain { $$ = (graph_t *) graph;
737 if (!$1->front->src_name) {
738 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("link without source element"));
739 gst_parse_free_link ($1->front);
741 $$->links = g_slist_prepend ($$->links, $1->front);
746 if (!$1->back->sink_name) {
747 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("link without sink element"));
748 gst_parse_free_link ($1->back);
750 $$->links = g_slist_prepend ($$->links, $1->back);
760 extern FILE *_gst_parse_yyin;
761 int _gst_parse_yylex (YYSTYPE *lvalp);
763 static int yylex (void *lvalp) {
764 return _gst_parse_yylex ((YYSTYPE*) lvalp);
768 yyerror (const char *s)
770 /* FIXME: This should go into the GError somehow, but how? */
771 g_warning ("error: %s", s);
775 struct yy_buffer_state * _gst_parse_yy_scan_string (char*);
776 void _gst_parse_yy_delete_buffer (struct yy_buffer_state *);
778 _gst_parse_launch (const gchar *str, GError **error)
785 struct yy_buffer_state *buf;
787 g_return_val_if_fail (str != NULL, NULL);
793 #ifdef __GST_PARSE_TRACE
794 GST_CAT_DEBUG (GST_CAT_PIPELINE, "TRACE: tracing enabled");
795 __strings = __chains = __links = 0;
796 #endif /* __GST_PARSE_TRACE */
798 dstr = g_strdup (str);
799 buf = _gst_parse_yy_scan_string (dstr);
801 #ifndef GST_DISABLE_GST_DEBUG
805 if (yyparse (&g) != 0) {
806 SET_ERROR (error, GST_PARSE_ERROR_SYNTAX, "Unrecoverable syntax error while parsing pipeline %s", str);
811 _gst_parse_yy_delete_buffer (buf);
813 GST_CAT_DEBUG (GST_CAT_PIPELINE, "got %u elements and %u links", g.chain ? g_slist_length (g.chain->elements) : 0, g_slist_length (g.links));
817 } else if (!(((chain_t *) g.chain)->elements->next)) {
818 /* only one toplevel element */
819 ret = (GstElement *) ((chain_t *) g.chain)->elements->data;
820 g_slist_free (((chain_t *) g.chain)->elements);
821 if (GST_IS_BIN (ret))
823 gst_parse_chain_free (g.chain);
825 /* put all elements in our bin */
826 bin = GST_BIN (gst_element_factory_make ("pipeline", NULL));
829 for (walk = g.chain->elements; walk; walk = walk->next)
830 gst_bin_add (bin, GST_ELEMENT (walk->data));
832 g_slist_free (g.chain->elements);
833 ret = GST_ELEMENT (bin);
834 gst_parse_chain_free (g.chain);
838 for (walk = g.links; walk; walk = walk->next) {
839 link_t *l = (link_t *) walk->data;
843 l->src = gst_bin_get_by_name_recurse_up (bin, l->src_name);
845 l->src = strcmp (GST_ELEMENT_NAME (ret), l->src_name) == 0 ? ret : NULL;
849 SET_ERROR (error, GST_PARSE_ERROR_NO_SUCH_ELEMENT, "No element named \"%s\" - omitting link", l->src_name);
850 gst_parse_free_link (l);
857 l->sink = gst_bin_get_by_name_recurse_up (bin, l->sink_name);
859 l->sink = strcmp (GST_ELEMENT_NAME (ret), l->sink_name) == 0 ? ret : NULL;
863 SET_ERROR (error, GST_PARSE_ERROR_NO_SUCH_ELEMENT, "No element named \"%s\" - omitting link", l->sink_name);
864 gst_parse_free_link (l);
868 gst_parse_perform_link (l, &g);
870 g_slist_free (g.links);
873 #ifdef __GST_PARSE_TRACE
874 GST_CAT_DEBUG (GST_CAT_PIPELINE, "TRACE: %u strings, %u chains and %u links left", __strings, __chains, __links);
875 if (__strings || __chains || __links) {
876 g_warning ("TRACE: %u strings, %u chains and %u links left", __strings, __chains, __links);
878 #endif /* __GST_PARSE_TRACE */
886 g_slist_foreach (g.chain->elements, (GFunc)gst_object_unref, NULL);
887 g_slist_free (g.chain->elements);
888 gst_parse_chain_free (g.chain);
891 g_slist_foreach (g.links, (GFunc)gst_parse_free_link, NULL);
892 g_slist_free (g.links);