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,
97 * but there is no such signal */
100 /*** define SET_ERROR and ERROR macros/functions */
102 #ifdef G_HAVE_ISO_VARARGS
104 # define SET_ERROR(error, type, ...) \
106 GST_CAT_ERROR (GST_CAT_PIPELINE, __VA_ARGS__); \
107 if ((error) && !*(error)) { \
108 g_set_error ((error), GST_PARSE_ERROR, (type), __VA_ARGS__); \
112 # define ERROR(type, ...) \
113 SET_ERROR (((graph_t *) graph)->error, (type), __VA_ARGS__ )
115 #elif defined(G_HAVE_GNUC_VARARGS)
117 # define SET_ERROR(error, type, args...) \
119 GST_CAT_ERROR (GST_CAT_PIPELINE, args ); \
120 if ((error) && !*(error)) { \
121 g_set_error ((error), GST_PARSE_ERROR, (type), args ); \
125 # define ERROR(type, args...) \
126 SET_ERROR (((graph_t *) graph)->error,(type) , args )
131 SET_ERROR (GError **error, gint type, const char *format, ...)
135 g_warning ("error while parsing");
140 va_start (varargs, format);
141 string = g_strdup_vprintf (format, varargs);
144 g_set_error (error, GST_PARSE_ERROR, type, string);
151 #endif /* G_HAVE_ISO_VARARGS */
153 /*** define YYPRINTF macro/function if we're debugging */
155 /* bison 1.35 calls this macro with side effects, we need to make sure the
156 side effects work - crappy bison */
158 #ifndef GST_DISABLE_GST_DEBUG
161 # ifdef G_HAVE_ISO_VARARGS
163 /* # define YYFPRINTF(a, ...) GST_CAT_DEBUG (GST_CAT_PIPELINE, __VA_ARGS__) */
164 # define YYFPRINTF(a, ...) \
166 gchar *temp = g_strdup_printf (__VA_ARGS__); \
167 GST_CAT_LOG (GST_CAT_PIPELINE, temp); \
171 # elif defined(G_HAVE_GNUC_VARARGS)
173 # define YYFPRINTF(a, args...) \
175 gchar *temp = g_strdup_printf ( args ); \
176 GST_CAT_LOG (GST_CAT_PIPELINE, temp); \
183 YYPRINTF(const char *format, ...)
188 va_start (varargs, format);
189 temp = g_strdup_vprintf ( format, varargs );
190 GST_CAT_LOG (GST_CAT_PIPELINE, "%s", temp);
195 # endif /* G_HAVE_ISO_VARARGS */
197 #endif /* GST_DISABLE_GST_DEBUG */
199 #define GST_BIN_MAKE(res, type, chainval, assign) \
201 chain_t *chain = chainval; \
203 GstBin *bin = (GstBin *) gst_element_factory_make (type, NULL); \
205 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_EMPTY_BIN, \
206 _("specified empty bin \"%s\", not allowed"), type); \
207 g_slist_foreach (assign, (GFunc) gst_parse_strfree, NULL); \
208 g_slist_free (assign); \
211 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT, \
212 _("no bin \"%s\", skipping"), type); \
213 g_slist_foreach (assign, (GFunc) gst_parse_strfree, NULL); \
214 g_slist_free (assign); \
217 for (walk = chain->elements; walk; walk = walk->next ) \
218 gst_bin_add (bin, GST_ELEMENT (walk->data)); \
219 g_slist_free (chain->elements); \
220 chain->elements = g_slist_prepend (NULL, bin); \
222 /* set the properties now */ \
223 for (walk = assign; walk; walk = walk->next) \
224 gst_parse_element_set ((gchar *) walk->data, GST_ELEMENT (bin), graph); \
225 g_slist_free (assign); \
229 #define MAKE_LINK(link, _src, _src_name, _src_pads, _sink, _sink_name, _sink_pads) \
231 link = gst_parse_link_new (); \
233 link->sink = _sink; \
234 link->src_name = _src_name; \
235 link->sink_name = _sink_name; \
236 link->src_pads = _src_pads; \
237 link->sink_pads = _sink_pads; \
241 #define MAKE_REF(link, _src, _pads) \
243 gchar *padname = _src; \
244 GSList *pads = _pads; \
246 while (*padname != '.') padname++; \
249 if (*padname != '\0') \
250 pads = g_slist_prepend (pads, gst_parse_strdup (padname)); \
252 MAKE_LINK (link, NULL, _src, pads, NULL, NULL, NULL); \
256 gst_parse_element_set (gchar *value, GstElement *element, graph_t *graph)
265 /* parse the string, so the property name is null-terminated an pos points
266 to the beginning of the value */
267 while (!g_ascii_isspace (*pos) && (*pos != '=')) pos++;
273 while (g_ascii_isspace (*pos)) pos++;
276 while (g_ascii_isspace (*pos)) pos++;
279 pos[strlen (pos) - 1] = '\0';
281 gst_parse_unescape (pos);
283 if (gst_child_proxy_lookup (GST_OBJECT (element), value, &target, &pspec)) {
284 value_type = G_PARAM_SPEC_VALUE_TYPE (pspec);
285 GST_LOG ("parsing property %s as a %s", pspec->name,
286 g_type_name (value_type));
287 g_value_init (&v, value_type);
288 if (!gst_value_deserialize (&v, pos))
290 g_object_set_property (G_OBJECT (target), pspec->name, &v);
291 gst_object_unref (target);
293 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_NO_SUCH_PROPERTY, \
294 _("no property \"%s\" in element \"%s\""), value, \
295 GST_ELEMENT_NAME (element));
299 gst_parse_strfree (value);
302 if (G_IS_VALUE (&v2))
307 gst_object_unref (target);
308 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_COULD_NOT_SET_PROPERTY,
309 _("could not set property \"%s\" in element \"%s\" to \"%s\""),
310 value, GST_ELEMENT_NAME (element), pos);
314 gst_parse_free_link (link_t *link)
316 gst_parse_strfree (link->src_name);
317 gst_parse_strfree (link->sink_name);
318 g_slist_foreach (link->src_pads, (GFunc) gst_parse_strfree, NULL);
319 g_slist_foreach (link->sink_pads, (GFunc) gst_parse_strfree, NULL);
320 g_slist_free (link->src_pads);
321 g_slist_free (link->sink_pads);
322 if (link->caps) gst_caps_unref (link->caps);
323 gst_parse_link_free (link);
327 gst_parse_element_lock (GstElement *element, gboolean lock)
331 gboolean unlocked_peer = FALSE;
332 gboolean done = FALSE;
335 if (gst_element_is_locked_state (element) == lock)
340 /* check if we have an unlocked peer */
341 pads = gst_element_iterate_pads (element);
344 switch (gst_iterator_next (pads, &data)) {
345 case GST_ITERATOR_OK:
347 GstPad *pad = GST_PAD_CAST (data);
349 if (GST_PAD_IS_SINK (pad) && GST_PAD_PEER (pad) &&
350 !gst_element_is_locked_state (
351 GST_PAD_PARENT (GST_PAD_PEER (pad)))) {
352 unlocked_peer = TRUE;
355 gst_object_unref (GST_OBJECT (pad));
358 case GST_ITERATOR_RESYNC:
359 unlocked_peer = FALSE;
360 gst_iterator_resync (pads);
362 case GST_ITERATOR_DONE:
366 g_assert_not_reached ();
370 gst_iterator_free (pads);
372 if (!(lock && unlocked_peer)) {
373 GST_CAT_DEBUG (GST_CAT_PIPELINE, "setting locked state on element");
374 gst_element_set_locked_state (element, lock);
377 /* try to sync state with parent */
378 GST_CAT_DEBUG (GST_CAT_PIPELINE,
379 "trying to sync state of element with parent");
380 /* FIXME: it would be nice if we can figure out why it failed
381 (e.g. caps nego) and give an error about that instead. */
382 if (gst_element_set_state (element, GST_STATE_PLAYING)
383 == GST_STATE_CHANGE_FAILURE)
384 GST_ELEMENT_ERROR (element, CORE, STATE_CHANGE, (NULL), (NULL));
390 /* check if there are other pads to (un)lock */
391 walk = (GList *) element->pads;
392 for (; walk; walk = walk->next) {
393 pad = GST_PAD_CAST (walk->data);
394 if (GST_PAD_IS_SRC (pad) && GST_PAD_PEER (pad)) {
395 GstElement *next = GST_ELEMENT (GST_OBJECT_PARENT (GST_PAD_PEER (pad)));
396 if (gst_element_is_locked_state (next) != lock)
397 gst_parse_element_lock (next, lock);
402 gst_parse_found_pad (GstElement *src, GstPad *pad, gpointer data)
404 DelayedLink *link = (DelayedLink *) data;
406 GST_CAT_INFO (GST_CAT_PIPELINE, "trying delayed linking %s:%s to %s:%s",
407 GST_ELEMENT_NAME (src), link->src_pad,
408 GST_ELEMENT_NAME (link->sink), link->sink_pad);
410 if (gst_element_link_pads_filtered (src, link->src_pad, link->sink,
411 link->sink_pad, link->caps)) {
412 /* do this here, we don't want to get any problems later on when
413 * unlocking states */
414 GST_CAT_DEBUG (GST_CAT_PIPELINE, "delayed linking %s:%s to %s:%s worked",
415 GST_ELEMENT_NAME (src), link->src_pad,
416 GST_ELEMENT_NAME (link->sink), link->sink_pad);
417 g_signal_handler_disconnect (src, link->signal_id);
418 g_free (link->src_pad);
419 g_free (link->sink_pad);
420 if (link->caps) gst_caps_unref (link->caps);
421 if (!gst_element_is_locked_state (src))
422 gst_parse_element_lock (link->sink, FALSE);
426 /* both padnames and the caps may be NULL */
428 gst_parse_perform_delayed_link (GstElement *src, const gchar *src_pad,
429 GstElement *sink, const gchar *sink_pad,
432 GList *templs = gst_element_class_get_pad_template_list (
433 GST_ELEMENT_GET_CLASS (src));
435 for (; templs; templs = templs->next) {
436 GstPadTemplate *templ = (GstPadTemplate *) templs->data;
437 if ((GST_PAD_TEMPLATE_DIRECTION (templ) == GST_PAD_SRC) &&
438 (GST_PAD_TEMPLATE_PRESENCE(templ) == GST_PAD_SOMETIMES))
440 DelayedLink *data = g_new (DelayedLink, 1);
442 /* TODO: maybe we should check if src_pad matches this template's names */
444 GST_CAT_DEBUG (GST_CAT_PIPELINE, "trying delayed link %s:%s to %s:%s",
445 GST_ELEMENT_NAME (src), src_pad,
446 GST_ELEMENT_NAME (sink), sink_pad);
448 data->src_pad = g_strdup (src_pad);
450 data->sink_pad = g_strdup (sink_pad);
452 data->caps = gst_caps_copy (caps);
456 data->signal_id = g_signal_connect (G_OBJECT (src), "pad-added",
457 G_CALLBACK (gst_parse_found_pad), data);
464 * performs a link and frees the struct. src and sink elements must be given
465 * return values 0 - link performed
470 gst_parse_perform_link (link_t *link, graph_t *graph)
472 GstElement *src = link->src;
473 GstElement *sink = link->sink;
474 GSList *srcs = link->src_pads;
475 GSList *sinks = link->sink_pads;
476 g_assert (GST_IS_ELEMENT (src));
477 g_assert (GST_IS_ELEMENT (sink));
479 GST_CAT_INFO (GST_CAT_PIPELINE,
480 "linking %s:%s to %s:%s (%u/%u) with caps \"%" GST_PTR_FORMAT "\"",
481 GST_ELEMENT_NAME (src), link->src_name ? link->src_name : "(any)",
482 GST_ELEMENT_NAME (sink), link->sink_name ? link->sink_name : "(any)",
483 g_slist_length (srcs), g_slist_length (sinks), link->caps);
485 if (!srcs || !sinks) {
486 if (gst_element_link_pads_filtered (src,
487 srcs ? (const gchar *) srcs->data : NULL, sink,
488 sinks ? (const gchar *) sinks->data : NULL, link->caps)) {
489 gst_parse_element_lock (sink, gst_element_is_locked_state (src));
492 if (gst_parse_perform_delayed_link (src,
493 srcs ? (const gchar *) srcs->data : NULL,
494 sink, sinks ? (const gchar *) sinks->data : NULL, link->caps)) {
495 gst_parse_element_lock (sink, TRUE);
502 if (g_slist_length (link->src_pads) != g_slist_length (link->src_pads)) {
505 while (srcs && sinks) {
506 const gchar *src_pad = (const gchar *) srcs->data;
507 const gchar *sink_pad = (const gchar *) sinks->data;
508 srcs = g_slist_next (srcs);
509 sinks = g_slist_next (sinks);
510 if (gst_element_link_pads_filtered (src, src_pad, sink, sink_pad,
512 gst_parse_element_lock (sink, gst_element_is_locked_state (src));
515 if (gst_parse_perform_delayed_link (src, src_pad,
518 gst_parse_element_lock (sink, TRUE);
527 gst_parse_free_link (link);
531 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK,
532 _("could not link %s to %s"), GST_ELEMENT_NAME (src),
533 GST_ELEMENT_NAME (sink));
534 gst_parse_free_link (link);
539 static int yylex (void *lvalp);
540 static int yyerror (const char *s);
553 %token <s> IDENTIFIER
554 %left <s> REF PADREF BINREF
555 %token <s> ASSIGNMENT
561 %type <l> linkpart link
564 %type <p> padlist pads assignments
566 %left '{' '}' '(' ')'
576 element: IDENTIFIER { $$ = gst_element_factory_make ($1, NULL);
578 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT, _("no element \"%s\""), $1);
579 gst_parse_strfree ($1);
583 | element ASSIGNMENT { gst_parse_element_set ($2, $1, graph);
587 assignments: /* NOP */ { $$ = NULL; }
588 | assignments ASSIGNMENT { $$ = g_slist_prepend ($1, $2); }
590 bin: '{' assignments chain '}' { GST_BIN_MAKE ($$, "thread", $3, $2); }
591 | '(' assignments chain ')' { GST_BIN_MAKE ($$, "bin", $3, $2); }
592 | BINREF assignments chain ')' { GST_BIN_MAKE ($$, $1, $3, $2);
593 gst_parse_strfree ($1);
595 | '{' assignments '}' { GST_BIN_MAKE ($$, "thread", NULL, $2); }
596 | '(' assignments '}' { GST_BIN_MAKE ($$, "thread", NULL, $2); }
597 | BINREF assignments ')' { GST_BIN_MAKE ($$, $1, NULL, $2);
598 gst_parse_strfree ($1);
600 | '{' assignments error '}' { GST_BIN_MAKE ($$, "thread", NULL, $2); }
601 | '(' assignments error '}' { GST_BIN_MAKE ($$, "thread", NULL, $2); }
602 | BINREF assignments error ')' { GST_BIN_MAKE ($$, $1, NULL, $2);
603 gst_parse_strfree ($1);
607 pads: PADREF { $$ = g_slist_prepend (NULL, $1); }
608 | PADREF padlist { $$ = $2;
609 $$ = g_slist_prepend ($$, $1);
612 padlist: ',' IDENTIFIER { $$ = g_slist_prepend (NULL, $2); }
613 | ',' IDENTIFIER padlist { $$ = g_slist_prepend ($3, $2); }
616 reference: REF { MAKE_REF ($$, $1, NULL); }
617 | REF padlist { MAKE_REF ($$, $1, $2); }
620 linkpart: reference { $$ = $1; }
621 | pads { MAKE_REF ($$, NULL, $1); }
622 | /* NOP */ { MAKE_REF ($$, NULL, NULL); }
625 link: linkpart LINK linkpart { $$ = $1;
627 $$->caps = gst_caps_from_string ($2);
629 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("could not parse caps \"%s\""), $2);
630 gst_parse_strfree ($2);
632 $$->sink_name = $3->src_name;
633 $$->sink_pads = $3->src_pads;
634 gst_parse_link_free ($3);
638 linklist: link { $$ = g_slist_prepend (NULL, $1); }
639 | link linklist { $$ = g_slist_prepend ($2, $1); }
640 | linklist error { $$ = $1; }
643 chain: element { $$ = gst_parse_chain_new ();
644 $$->first = $$->last = $1;
645 $$->front = $$->back = NULL;
646 $$->elements = g_slist_prepend (NULL, $1);
649 | chain chain { if ($1->back && $2->front) {
650 if (!$1->back->sink_name) {
651 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("link without source element"));
652 gst_parse_free_link ($1->back);
654 ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, $1->back);
656 if (!$2->front->src_name) {
657 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("link without sink element"));
658 gst_parse_free_link ($2->front);
660 ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, $2->front);
663 } else if ($1->back) {
664 if (!$1->back->sink_name) {
665 $1->back->sink = $2->first;
667 } else if ($2->front) {
668 if (!$2->front->src_name) {
669 $2->front->src = $1->last;
671 $1->back = $2->front;
675 ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, $1->back);
679 $1->elements = g_slist_concat ($1->elements, $2->elements);
681 gst_parse_chain_free ($2);
684 | chain linklist { GSList *walk;
686 $2 = g_slist_prepend ($2, $1->back);
689 if (!((link_t *) $2->data)->src_name) {
690 ((link_t *) $2->data)->src = $1->last;
693 for (walk = $2; walk; walk = walk->next) {
694 link_t *link = (link_t *) walk->data;
695 if (!link->sink_name && walk->next) {
696 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("link without sink element"));
697 gst_parse_free_link (link);
698 } else if (!link->src_name && !link->src) {
699 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("link without source element"));
700 gst_parse_free_link (link);
703 ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, link);
712 | chain error { $$ = $1; }
713 | link chain { if ($2->front) {
714 if (!$2->front->src_name) {
715 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("link without source element"));
716 gst_parse_free_link ($2->front);
718 ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, $2->front);
721 if (!$1->sink_name) {
722 $1->sink = $2->first;
727 | PARSE_URL chain { $$ = $2;
729 GstElement *element =
730 gst_element_make_from_uri (GST_URI_SRC, $1, NULL);
732 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
733 _("no source element for URI \"%s\""), $1);
735 $$->front->src = element;
736 ((graph_t *) graph)->links = g_slist_prepend (
737 ((graph_t *) graph)->links, $$->front);
739 $$->elements = g_slist_prepend ($$->elements, element);
742 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK,
743 _("no element to link URI \"%s\" to"), $1);
747 | link PARSE_URL { GstElement *element =
748 gst_element_make_from_uri (GST_URI_SINK, $2, NULL);
750 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
751 _("no sink element for URI \"%s\""), $2);
753 } else if ($1->sink_name || $1->sink_pads) {
754 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK,
755 _("could not link sink element for URI \"%s\""), $2);
758 $$ = gst_parse_chain_new ();
759 $$->first = $$->last = element;
761 $$->front->sink = element;
762 $$->elements = g_slist_prepend (NULL, element);
767 graph: /* NOP */ { SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_EMPTY, _("empty pipeline not allowed"));
768 $$ = (graph_t *) graph;
770 | chain { $$ = (graph_t *) graph;
772 if (!$1->front->src_name) {
773 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("link without source element"));
774 gst_parse_free_link ($1->front);
776 $$->links = g_slist_prepend ($$->links, $1->front);
781 if (!$1->back->sink_name) {
782 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("link without sink element"));
783 gst_parse_free_link ($1->back);
785 $$->links = g_slist_prepend ($$->links, $1->back);
795 extern FILE *_gst_parse_yyin;
796 int _gst_parse_yylex (YYSTYPE *lvalp);
798 static int yylex (void *lvalp) {
799 return _gst_parse_yylex ((YYSTYPE*) lvalp);
803 yyerror (const char *s)
805 /* FIXME: This should go into the GError somehow, but how? */
806 g_warning ("error: %s", s);
810 struct yy_buffer_state * _gst_parse_yy_scan_string (char*);
811 void _gst_parse_yy_delete_buffer (struct yy_buffer_state *);
813 _gst_parse_launch (const gchar *str, GError **error)
820 struct yy_buffer_state *buf;
822 g_return_val_if_fail (str != NULL, NULL);
828 #ifdef __GST_PARSE_TRACE
829 GST_CAT_DEBUG (GST_CAT_PIPELINE, "TRACE: tracing enabled");
830 __strings = __chains = __links = 0;
831 #endif /* __GST_PARSE_TRACE */
833 dstr = g_strdup (str);
834 buf = _gst_parse_yy_scan_string (dstr);
836 #ifndef GST_DISABLE_GST_DEBUG
840 if (yyparse (&g) != 0) {
841 SET_ERROR (error, GST_PARSE_ERROR_SYNTAX,
842 "Unrecoverable syntax error while parsing pipeline %s", str);
847 _gst_parse_yy_delete_buffer (buf);
849 GST_CAT_DEBUG (GST_CAT_PIPELINE, "got %u elements and %u links",
850 g.chain ? g_slist_length (g.chain->elements) : 0,
851 g_slist_length (g.links));
855 } else if (!(((chain_t *) g.chain)->elements->next)) {
856 /* only one toplevel element */
857 ret = (GstElement *) ((chain_t *) g.chain)->elements->data;
858 g_slist_free (((chain_t *) g.chain)->elements);
859 if (GST_IS_BIN (ret))
861 gst_parse_chain_free (g.chain);
863 /* put all elements in our bin */
864 bin = GST_BIN (gst_element_factory_make ("pipeline", NULL));
867 for (walk = g.chain->elements; walk; walk = walk->next)
868 gst_bin_add (bin, GST_ELEMENT (walk->data));
870 g_slist_free (g.chain->elements);
871 ret = GST_ELEMENT (bin);
872 gst_parse_chain_free (g.chain);
876 for (walk = g.links; walk; walk = walk->next) {
877 link_t *l = (link_t *) walk->data;
881 l->src = gst_bin_get_by_name_recurse_up (bin, l->src_name);
883 l->src = strcmp (GST_ELEMENT_NAME (ret), l->src_name) == 0 ? ret : NULL;
887 SET_ERROR (error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
888 "No element named \"%s\" - omitting link", l->src_name);
889 gst_parse_free_link (l);
896 l->sink = gst_bin_get_by_name_recurse_up (bin, l->sink_name);
898 l->sink = strcmp (GST_ELEMENT_NAME (ret), l->sink_name) == 0 ? ret : NULL;
902 SET_ERROR (error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
903 "No element named \"%s\" - omitting link", l->sink_name);
904 gst_parse_free_link (l);
908 gst_parse_perform_link (l, &g);
910 g_slist_free (g.links);
913 #ifdef __GST_PARSE_TRACE
914 GST_CAT_DEBUG (GST_CAT_PIPELINE,
915 "TRACE: %u strings, %u chains and %u links left", __strings, __chains,
917 if (__strings || __chains || __links) {
918 g_warning ("TRACE: %u strings, %u chains and %u links left", __strings,
921 #endif /* __GST_PARSE_TRACE */
929 g_slist_foreach (g.chain->elements, (GFunc)gst_object_unref, NULL);
930 g_slist_free (g.chain->elements);
931 gst_parse_chain_free (g.chain);
934 g_slist_foreach (g.links, (GFunc)gst_parse_free_link, NULL);
935 g_slist_free (g.links);