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);
271 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_NO_SUCH_PROPERTY, _("no property \"%s\" in element \"%s\""), value, GST_ELEMENT_NAME (element));
275 gst_parse_strfree (value);
278 if (G_IS_VALUE (&v2))
283 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_COULD_NOT_SET_PROPERTY,
284 _("could not set property \"%s\" in element \"%s\" to \"%s\""),
285 value, GST_ELEMENT_NAME (element), pos);
289 gst_parse_free_link (link_t *link)
291 gst_parse_strfree (link->src_name);
292 gst_parse_strfree (link->sink_name);
293 g_slist_foreach (link->src_pads, (GFunc) gst_parse_strfree, NULL);
294 g_slist_foreach (link->sink_pads, (GFunc) gst_parse_strfree, NULL);
295 g_slist_free (link->src_pads);
296 g_slist_free (link->sink_pads);
297 if (link->caps) gst_caps_unref (link->caps);
298 gst_parse_link_free (link);
302 gst_parse_element_lock (GstElement *element, gboolean lock)
306 gboolean unlocked_peer = FALSE;
307 gboolean done = FALSE;
310 if (gst_element_is_locked_state (element) == lock)
315 /* check if we have an unlocked peer */
316 pads = gst_element_iterate_pads (element);
319 switch (gst_iterator_next (pads, &data)) {
320 case GST_ITERATOR_OK:
322 GstPad *pad = GST_PAD_CAST (data);
324 if (GST_PAD_IS_SINK (pad) && GST_PAD_PEER (pad) &&
325 !gst_element_is_locked_state (GST_PAD_PARENT (GST_PAD_PEER (pad)))) {
326 unlocked_peer = TRUE;
329 gst_object_unref (GST_OBJECT (pad));
332 case GST_ITERATOR_RESYNC:
333 unlocked_peer = FALSE;
334 gst_iterator_resync (pads);
336 case GST_ITERATOR_DONE:
340 g_assert_not_reached ();
344 gst_iterator_free (pads);
346 if (!(lock && unlocked_peer)) {
347 GST_CAT_DEBUG (GST_CAT_PIPELINE, "setting locked state on element");
348 gst_element_set_locked_state (element, lock);
351 /* try to sync state with parent */
352 GST_CAT_DEBUG (GST_CAT_PIPELINE, "trying to sync state of element with parent");
353 /* FIXME: it would be nice if we can figure out why it failed
354 (e.g. caps nego) and give an error about that instead. */
355 if (gst_element_set_state (element, GST_STATE_PLAYING) == GST_STATE_FAILURE)
356 GST_ELEMENT_ERROR (element, CORE, STATE_CHANGE, (NULL), (NULL));
362 /* check if there are other pads to (un)lock */
363 walk = (GList *) element->pads;
364 for (; walk; walk = walk->next) {
365 pad = GST_PAD_CAST (walk->data);
366 if (GST_PAD_IS_SRC (pad) && GST_PAD_PEER (pad)) {
367 GstElement *next = GST_ELEMENT (GST_OBJECT_PARENT (GST_PAD_PEER (pad)));
368 if (gst_element_is_locked_state (next) != lock)
369 gst_parse_element_lock (next, lock);
374 gst_parse_found_pad (GstElement *src, GstPad *pad, gpointer data)
376 DelayedLink *link = (DelayedLink *) data;
378 GST_CAT_INFO (GST_CAT_PIPELINE, "trying delayed linking %s:%s to %s:%s",
379 GST_ELEMENT_NAME (src), link->src_pad,
380 GST_ELEMENT_NAME (link->sink), link->sink_pad);
382 if (gst_element_link_pads_filtered (src, link->src_pad, link->sink, link->sink_pad, link->caps)) {
383 /* do this here, we don't want to get any problems later on when unlocking states */
384 GST_CAT_DEBUG (GST_CAT_PIPELINE, "delayed linking %s:%s to %s:%s worked",
385 GST_ELEMENT_NAME (src), link->src_pad,
386 GST_ELEMENT_NAME (link->sink), link->sink_pad);
387 g_signal_handler_disconnect (src, link->signal_id);
388 g_free (link->src_pad);
389 g_free (link->sink_pad);
390 if (link->caps) gst_caps_unref (link->caps);
391 if (!gst_element_is_locked_state (src))
392 gst_parse_element_lock (link->sink, FALSE);
396 /* both padnames and the caps may be NULL */
398 gst_parse_perform_delayed_link (GstElement *src, const gchar *src_pad,
399 GstElement *sink, const gchar *sink_pad, GstCaps *caps)
401 GList *templs = gst_element_class_get_pad_template_list (GST_ELEMENT_GET_CLASS (src));
403 for (; templs; templs = templs->next) {
404 GstPadTemplate *templ = (GstPadTemplate *) templs->data;
405 if ((GST_PAD_TEMPLATE_DIRECTION (templ) == GST_PAD_SRC) && (GST_PAD_TEMPLATE_PRESENCE(templ) == GST_PAD_SOMETIMES))
407 DelayedLink *data = g_new (DelayedLink, 1);
409 /* TODO: maybe we should check if src_pad matches this template's names */
411 GST_CAT_DEBUG (GST_CAT_PIPELINE, "trying delayed link %s:%s to %s:%s",
412 GST_ELEMENT_NAME (src), src_pad, GST_ELEMENT_NAME (sink), sink_pad);
414 data->src_pad = g_strdup (src_pad);
416 data->sink_pad = g_strdup (sink_pad);
418 data->caps = gst_caps_copy (caps);
422 data->signal_id = g_signal_connect (G_OBJECT (src), "pad-added",
423 G_CALLBACK (gst_parse_found_pad), data);
430 * performs a link and frees the struct. src and sink elements must be given
431 * return values 0 - link performed
436 gst_parse_perform_link (link_t *link, graph_t *graph)
438 GstElement *src = link->src;
439 GstElement *sink = link->sink;
440 GSList *srcs = link->src_pads;
441 GSList *sinks = link->sink_pads;
442 g_assert (GST_IS_ELEMENT (src));
443 g_assert (GST_IS_ELEMENT (sink));
445 GST_CAT_INFO (GST_CAT_PIPELINE, "linking %s:%s to %s:%s (%u/%u) with caps \"%" GST_PTR_FORMAT "\"",
446 GST_ELEMENT_NAME (src), link->src_name ? link->src_name : "(any)",
447 GST_ELEMENT_NAME (sink), link->sink_name ? link->sink_name : "(any)",
448 g_slist_length (srcs), g_slist_length (sinks),
451 if (!srcs || !sinks) {
452 if (gst_element_link_pads_filtered (src, srcs ? (const gchar *) srcs->data : NULL,
453 sink, sinks ? (const gchar *) sinks->data : NULL,
455 gst_parse_element_lock (sink, gst_element_is_locked_state (src));
458 if (gst_parse_perform_delayed_link (src, srcs ? (const gchar *) srcs->data : NULL,
459 sink, sinks ? (const gchar *) sinks->data : NULL,
461 gst_parse_element_lock (sink, TRUE);
468 if (g_slist_length (link->src_pads) != g_slist_length (link->src_pads)) {
471 while (srcs && sinks) {
472 const gchar *src_pad = (const gchar *) srcs->data;
473 const gchar *sink_pad = (const gchar *) sinks->data;
474 srcs = g_slist_next (srcs);
475 sinks = g_slist_next (sinks);
476 if (gst_element_link_pads_filtered (src, src_pad, sink, sink_pad, link->caps)) {
477 gst_parse_element_lock (sink, gst_element_is_locked_state (src));
480 if (gst_parse_perform_delayed_link (src, src_pad,
483 gst_parse_element_lock (sink, TRUE);
492 gst_parse_free_link (link);
496 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("could not link %s to %s"), GST_ELEMENT_NAME (src), GST_ELEMENT_NAME (sink));
497 gst_parse_free_link (link);
502 static int yylex (void *lvalp);
503 static int yyerror (const char *s);
516 %token <s> IDENTIFIER
517 %left <s> REF PADREF BINREF
518 %token <s> ASSIGNMENT
524 %type <l> linkpart link
527 %type <p> padlist pads assignments
529 %left '{' '}' '(' ')'
539 element: IDENTIFIER { $$ = gst_element_factory_make ($1, NULL);
541 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT, _("no element \"%s\""), $1);
542 gst_parse_strfree ($1);
546 | element ASSIGNMENT { gst_parse_element_set ($2, $1, graph);
550 assignments: /* NOP */ { $$ = NULL; }
551 | assignments ASSIGNMENT { $$ = g_slist_prepend ($1, $2); }
553 bin: '{' assignments chain '}' { GST_BIN_MAKE ($$, "thread", $3, $2); }
554 | '(' assignments chain ')' { GST_BIN_MAKE ($$, "bin", $3, $2); }
555 | BINREF assignments chain ')' { GST_BIN_MAKE ($$, $1, $3, $2);
556 gst_parse_strfree ($1);
558 | '{' assignments '}' { GST_BIN_MAKE ($$, "thread", NULL, $2); }
559 | '(' assignments '}' { GST_BIN_MAKE ($$, "thread", NULL, $2); }
560 | BINREF assignments ')' { GST_BIN_MAKE ($$, $1, NULL, $2);
561 gst_parse_strfree ($1);
563 | '{' assignments error '}' { GST_BIN_MAKE ($$, "thread", NULL, $2); }
564 | '(' assignments error '}' { GST_BIN_MAKE ($$, "thread", NULL, $2); }
565 | BINREF assignments error ')' { GST_BIN_MAKE ($$, $1, NULL, $2);
566 gst_parse_strfree ($1);
570 pads: PADREF { $$ = g_slist_prepend (NULL, $1); }
571 | PADREF padlist { $$ = $2;
572 $$ = g_slist_prepend ($$, $1);
575 padlist: ',' IDENTIFIER { $$ = g_slist_prepend (NULL, $2); }
576 | ',' IDENTIFIER padlist { $$ = g_slist_prepend ($3, $2); }
579 reference: REF { MAKE_REF ($$, $1, NULL); }
580 | REF padlist { MAKE_REF ($$, $1, $2); }
583 linkpart: reference { $$ = $1; }
584 | pads { MAKE_REF ($$, NULL, $1); }
585 | /* NOP */ { MAKE_REF ($$, NULL, NULL); }
588 link: linkpart LINK linkpart { $$ = $1;
590 $$->caps = gst_caps_from_string ($2);
592 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("could not parse caps \"%s\""), $2);
593 gst_parse_strfree ($2);
595 $$->sink_name = $3->src_name;
596 $$->sink_pads = $3->src_pads;
597 gst_parse_link_free ($3);
601 linklist: link { $$ = g_slist_prepend (NULL, $1); }
602 | link linklist { $$ = g_slist_prepend ($2, $1); }
603 | linklist error { $$ = $1; }
606 chain: element { $$ = gst_parse_chain_new ();
607 $$->first = $$->last = $1;
608 $$->front = $$->back = NULL;
609 $$->elements = g_slist_prepend (NULL, $1);
612 | chain chain { if ($1->back && $2->front) {
613 if (!$1->back->sink_name) {
614 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("link without source element"));
615 gst_parse_free_link ($1->back);
617 ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, $1->back);
619 if (!$2->front->src_name) {
620 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("link without sink element"));
621 gst_parse_free_link ($2->front);
623 ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, $2->front);
626 } else if ($1->back) {
627 if (!$1->back->sink_name) {
628 $1->back->sink = $2->first;
630 } else if ($2->front) {
631 if (!$2->front->src_name) {
632 $2->front->src = $1->last;
634 $1->back = $2->front;
638 ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, $1->back);
642 $1->elements = g_slist_concat ($1->elements, $2->elements);
644 gst_parse_chain_free ($2);
647 | chain linklist { GSList *walk;
649 $2 = g_slist_prepend ($2, $1->back);
652 if (!((link_t *) $2->data)->src_name) {
653 ((link_t *) $2->data)->src = $1->last;
656 for (walk = $2; walk; walk = walk->next) {
657 link_t *link = (link_t *) walk->data;
658 if (!link->sink_name && walk->next) {
659 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("link without sink element"));
660 gst_parse_free_link (link);
661 } else if (!link->src_name && !link->src) {
662 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("link without source element"));
663 gst_parse_free_link (link);
666 ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, link);
675 | chain error { $$ = $1; }
676 | link chain { if ($2->front) {
677 if (!$2->front->src_name) {
678 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("link without source element"));
679 gst_parse_free_link ($2->front);
681 ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, $2->front);
684 if (!$1->sink_name) {
685 $1->sink = $2->first;
690 | PARSE_URL chain { $$ = $2;
692 GstElement *element =
693 gst_element_make_from_uri (GST_URI_SRC, $1, NULL);
695 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
696 _("no source element for URI \"%s\""), $1);
698 $$->front->src = element;
699 ((graph_t *) graph)->links = g_slist_prepend (
700 ((graph_t *) graph)->links, $$->front);
702 $$->elements = g_slist_prepend ($$->elements, element);
705 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK,
706 _("no element to link URI \"%s\" to"), $1);
710 | link PARSE_URL { GstElement *element =
711 gst_element_make_from_uri (GST_URI_SINK, $2, NULL);
713 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
714 _("no sink element for URI \"%s\""), $2);
716 } else if ($1->sink_name || $1->sink_pads) {
717 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK,
718 _("could not link sink element for URI \"%s\""), $2);
721 $$ = gst_parse_chain_new ();
722 $$->first = $$->last = element;
724 $$->front->sink = element;
725 $$->elements = g_slist_prepend (NULL, element);
730 graph: /* NOP */ { SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_EMPTY, _("empty pipeline not allowed"));
731 $$ = (graph_t *) graph;
733 | chain { $$ = (graph_t *) graph;
735 if (!$1->front->src_name) {
736 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("link without source element"));
737 gst_parse_free_link ($1->front);
739 $$->links = g_slist_prepend ($$->links, $1->front);
744 if (!$1->back->sink_name) {
745 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("link without sink element"));
746 gst_parse_free_link ($1->back);
748 $$->links = g_slist_prepend ($$->links, $1->back);
758 extern FILE *_gst_parse_yyin;
759 int _gst_parse_yylex (YYSTYPE *lvalp);
761 static int yylex (void *lvalp) {
762 return _gst_parse_yylex ((YYSTYPE*) lvalp);
766 yyerror (const char *s)
768 /* FIXME: This should go into the GError somehow, but how? */
769 g_warning ("error: %s", s);
773 struct yy_buffer_state * _gst_parse_yy_scan_string (char*);
774 void _gst_parse_yy_delete_buffer (struct yy_buffer_state *);
776 _gst_parse_launch (const gchar *str, GError **error)
783 struct yy_buffer_state *buf;
785 g_return_val_if_fail (str != NULL, NULL);
791 #ifdef __GST_PARSE_TRACE
792 GST_CAT_DEBUG (GST_CAT_PIPELINE, "TRACE: tracing enabled");
793 __strings = __chains = __links = 0;
794 #endif /* __GST_PARSE_TRACE */
796 dstr = g_strdup (str);
797 buf = _gst_parse_yy_scan_string (dstr);
799 #ifndef GST_DISABLE_GST_DEBUG
803 if (yyparse (&g) != 0) {
804 SET_ERROR (error, GST_PARSE_ERROR_SYNTAX, "Unrecoverable syntax error while parsing pipeline %s", str);
809 _gst_parse_yy_delete_buffer (buf);
811 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));
815 } else if (!(((chain_t *) g.chain)->elements->next)) {
816 /* only one toplevel element */
817 ret = (GstElement *) ((chain_t *) g.chain)->elements->data;
818 g_slist_free (((chain_t *) g.chain)->elements);
819 if (GST_IS_BIN (ret))
821 gst_parse_chain_free (g.chain);
823 /* put all elements in our bin */
824 bin = GST_BIN (gst_element_factory_make ("pipeline", NULL));
827 for (walk = g.chain->elements; walk; walk = walk->next)
828 gst_bin_add (bin, GST_ELEMENT (walk->data));
830 g_slist_free (g.chain->elements);
831 ret = GST_ELEMENT (bin);
832 gst_parse_chain_free (g.chain);
836 for (walk = g.links; walk; walk = walk->next) {
837 link_t *l = (link_t *) walk->data;
841 l->src = gst_bin_get_by_name_recurse_up (bin, l->src_name);
843 l->src = strcmp (GST_ELEMENT_NAME (ret), l->src_name) == 0 ? ret : NULL;
847 SET_ERROR (error, GST_PARSE_ERROR_NO_SUCH_ELEMENT, "No element named \"%s\" - omitting link", l->src_name);
848 gst_parse_free_link (l);
855 l->sink = gst_bin_get_by_name_recurse_up (bin, l->sink_name);
857 l->sink = strcmp (GST_ELEMENT_NAME (ret), l->sink_name) == 0 ? ret : NULL;
861 SET_ERROR (error, GST_PARSE_ERROR_NO_SUCH_ELEMENT, "No element named \"%s\" - omitting link", l->sink_name);
862 gst_parse_free_link (l);
866 gst_parse_perform_link (l, &g);
868 g_slist_free (g.links);
871 #ifdef __GST_PARSE_TRACE
872 GST_CAT_DEBUG (GST_CAT_PIPELINE, "TRACE: %u strings, %u chains and %u links left", __strings, __chains, __links);
873 if (__strings || __chains || __links) {
874 g_warning ("TRACE: %u strings, %u chains and %u links left", __strings, __chains, __links);
876 #endif /* __GST_PARSE_TRACE */
884 g_slist_foreach (g.chain->elements, (GFunc)gst_object_unref, NULL);
885 g_slist_free (g.chain->elements);
886 gst_parse_chain_free (g.chain);
889 g_slist_foreach (g.links, (GFunc)gst_parse_free_link, NULL);
890 g_slist_free (g.links);