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"
18 /* All error messages in this file are user-visible and need to be translated.
19 * Don't start the message with a capital, and don't end them with a period,
20 * as they will be presented inside a sentence/error.
23 #define YYERROR_VERBOSE 1
24 #define YYPARSE_PARAM graph
26 #ifdef __GST_PARSE_TRACE
27 static guint __strings;
29 static guint __chains;
31 __gst_parse_strdup (gchar *org)
36 /* g_print ("ALLOCATED STR (%3u): %p %s\n", __strings, ret, ret); */
40 __gst_parse_strfree (gchar *str)
43 /* g_print ("FREEING STR (%3u): %p %s\n", __strings - 1, str, str); */
45 g_return_if_fail (__strings > 0);
49 link_t *__gst_parse_link_new ()
53 ret = g_new0 (link_t, 1);
54 /* g_print ("ALLOCATED LINK (%3u): %p\n", __links, ret); */
58 __gst_parse_link_free (link_t *data)
61 /* g_print ("FREEING LINK (%3u): %p\n", __links - 1, data); */
63 g_return_if_fail (__links > 0);
68 __gst_parse_chain_new ()
72 ret = g_new0 (chain_t, 1);
73 /* g_print ("ALLOCATED CHAIN (%3u): %p\n", __chains, ret); */
77 __gst_parse_chain_free (chain_t *data)
80 /* g_print ("FREEING CHAIN (%3u): %p\n", __chains - 1, data); */
82 g_return_if_fail (__chains > 0);
87 #endif /* __GST_PARSE_TRACE */
95 /* FIXME: need to connect to "disposed" signal to clean up, but there is no such signal */
98 #ifdef G_HAVE_ISO_VARARGS
99 #define SET_ERROR(error, type, ...) G_STMT_START{ \
102 g_warning (__VA_ARGS__); \
104 g_set_error ((error), GST_PARSE_ERROR, (type), __VA_ARGS__); \
108 #define ERROR(type, ...) SET_ERROR (((graph_t *) graph)->error, (type), __VA_ARGS__ )
109 #ifndef GST_DISABLE_GST_DEBUG
111 /* bison 1.35 calls this macro with side effects, we need to make sure the
112 side effects work - crappy bison
113 # define YYFPRINTF(a, ...) GST_CAT_DEBUG (GST_CAT_PIPELINE, __VA_ARGS__)
115 # define YYFPRINTF(a, ...) G_STMT_START{ \
116 gchar *temp = g_strdup_printf (__VA_ARGS__); \
117 GST_CAT_LOG (GST_CAT_PIPELINE, temp); \
122 #elif defined(G_HAVE_GNUC_VARARGS)
124 #define SET_ERROR(error, type, args...) G_STMT_START{ \
127 g_warning ( args ); \
129 g_set_error ((error), GST_PARSE_ERROR, (type), args ); \
133 #define ERROR(type, args...) SET_ERROR (((graph_t *) graph)->error, (type) , args )
134 #ifndef GST_DISABLE_GST_DEBUG
136 /* bison 1.35 calls this macro with side effects, we need to make sure the
137 side effects work - crappy bison
138 # define YYFPRINTF(a, args...) GST_CAT_DEBUG (GST_CAT_PIPELINE, args )
140 # define YYFPRINTF(a, args...) G_STMT_START{ \
141 gchar *temp = g_strdup_printf ( args ); \
142 GST_CAT_LOG (GST_CAT_PIPELINE, temp); \
149 #define SET_ERROR(error, type, ...) G_STMT_START{ \
152 g_warning ("error while parsing"); \
154 g_set_error ((error), GST_PARSE_ERROR, (type), "error while parsing"); \
158 #define ERROR(type, ...) SET_ERROR (((graph_t *) graph)->error, (type), "error while parsing")
159 #ifndef GST_DISABLE_GST_DEBUG
163 #endif /* G_HAVE_ISO_VARARGS */
165 #define GST_BIN_MAKE(res, type, chainval, assign) G_STMT_START{ \
166 chain_t *chain = chainval; \
168 GstBin *bin = (GstBin *) gst_element_factory_make (type, NULL); \
170 ERROR (GST_PARSE_ERROR_EMPTY_BIN, _("specified empty bin \"%s\", not allowed"), type); \
171 g_slist_foreach (assign, (GFunc) gst_parse_strfree, NULL); \
172 g_slist_free (assign); \
175 ERROR (GST_PARSE_ERROR_NO_SUCH_ELEMENT, _("no bin \"%s\", skipping"), type); \
176 g_slist_foreach (assign, (GFunc) gst_parse_strfree, NULL); \
177 g_slist_free (assign); \
180 walk = chain->elements; \
182 gst_bin_add (bin, GST_ELEMENT (walk->data)); \
185 g_slist_free (chain->elements); \
186 chain->elements = g_slist_prepend (NULL, bin); \
188 /* set the properties now */ \
191 gst_parse_element_set ((gchar *) walk->data, GST_ELEMENT (bin), graph); \
192 walk = g_slist_next (walk); \
194 g_slist_free (assign); \
198 #define MAKE_LINK(link, _src, _src_name, _src_pads, _sink, _sink_name, _sink_pads) G_STMT_START{ \
199 link = gst_parse_link_new (); \
201 link->sink = _sink; \
202 link->src_name = _src_name; \
203 link->sink_name = _sink_name; \
204 link->src_pads = _src_pads; \
205 link->sink_pads = _sink_pads; \
209 #define MAKE_REF(link, _src, _pads) G_STMT_START{ \
210 gchar *padname = _src; \
211 GSList *pads = _pads; \
213 while (*padname != '.') padname++; \
216 if (*padname != '\0') \
217 pads = g_slist_prepend (pads, gst_parse_strdup (padname)); \
219 MAKE_LINK (link, NULL, _src, pads, NULL, NULL, NULL); \
223 gst_parse_element_set (gchar *value, GstElement *element, graph_t *graph)
229 /* parse the string, so the property name is null-terminated an pos points
230 to the beginning of the value */
231 while (!g_ascii_isspace (*pos) && (*pos != '=')) pos++;
237 while (g_ascii_isspace (*pos)) pos++;
240 while (g_ascii_isspace (*pos)) pos++;
243 pos[strlen (pos) - 1] = '\0';
245 gst_parse_unescape (pos);
246 if ((pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (element), value))) {
247 g_value_init (&v, G_PARAM_SPEC_VALUE_TYPE(pspec));
248 switch (G_TYPE_FUNDAMENTAL (G_PARAM_SPEC_VALUE_TYPE (pspec))) {
250 g_value_set_string (&v, pos);
253 if (g_ascii_strcasecmp (pos, "true") && g_ascii_strcasecmp (pos, "yes") && g_ascii_strcasecmp (pos, "1")) {
254 g_value_set_boolean (&v, FALSE);
256 g_value_set_boolean (&v, TRUE);
261 gchar *endptr = NULL;
262 GEnumClass *klass = (GEnumClass *) g_type_class_peek (G_PARAM_SPEC_VALUE_TYPE (pspec));
263 if (klass == NULL) goto error;
264 if (!(en = g_enum_get_value_by_name (klass, pos))) {
265 if (!(en = g_enum_get_value_by_nick (klass, pos))) {
266 gint i = strtol (pos, &endptr, 0);
267 if (endptr && *endptr == '\0') {
268 en = g_enum_get_value (klass, i);
274 g_value_set_enum (&v, en->value);
282 g_value_init (&v2, G_TYPE_LONG);
283 l = strtol (pos, &endptr, 0);
284 if (*endptr != '\0') goto error_conversion;
285 g_value_set_long (&v2, l);
286 if (!g_value_transform (&v2, &v)) goto error_conversion;
291 case G_TYPE_UINT64: {
294 g_value_init (&v2, G_TYPE_ULONG);
295 ul = strtoul (pos, &endptr, 0);
296 if (*endptr != '\0') goto error_conversion;
297 g_value_set_ulong (&v2, ul);
298 if (!g_value_transform (&v2, &v)) goto error_conversion;
302 case G_TYPE_DOUBLE: {
305 g_value_init (&v2, G_TYPE_DOUBLE);
306 d = g_ascii_strtod (pos, &endptr);
307 if (*endptr != '\0') goto error_conversion;
308 g_value_set_double (&v2, d);
309 if (!g_value_transform (&v2, &v)) goto error_conversion;
314 g_warning ("property \"%s\" in element %s cannot be set", value, GST_ELEMENT_NAME (element));
317 g_object_set_property (G_OBJECT (element), value, &v);
319 ERROR (GST_PARSE_ERROR_NO_SUCH_PROPERTY, _("no property \"%s\" in element \"%s\""), value, GST_ELEMENT_NAME (element));
323 gst_parse_strfree (value);
326 if (G_IS_VALUE (&v2))
331 ERROR (GST_PARSE_ERROR_COULD_NOT_SET_PROPERTY,
332 _("could not set property \"%s\" in element \"%s\" to \"%s\""),
333 value, GST_ELEMENT_NAME (element), pos);
336 ERROR (GST_PARSE_ERROR_COULD_NOT_SET_PROPERTY,
337 _("could not convert \"%s\" so that it fits property \"%s\" in element \"%s\""),
338 pos, value, GST_ELEMENT_NAME (element));
342 gst_parse_free_link (link_t *link)
344 gst_parse_strfree (link->src_name);
345 gst_parse_strfree (link->sink_name);
346 g_slist_foreach (link->src_pads, (GFunc) gst_parse_strfree, NULL);
347 g_slist_foreach (link->sink_pads, (GFunc) gst_parse_strfree, NULL);
348 g_slist_free (link->src_pads);
349 g_slist_free (link->sink_pads);
350 if (link->caps) gst_caps_free (link->caps);
351 gst_parse_link_free (link);
354 gst_parse_element_lock (GstElement *element, gboolean lock)
357 GList *walk = (GList *) gst_element_get_pad_list (element);
358 gboolean unlocked_peer = FALSE;
360 if (gst_element_is_locked_state (element) == lock)
362 /* check if we have an unlocked peer */
364 pad = (GstPad *) GST_PAD_REALIZE (walk->data);
366 if (GST_PAD_IS_SINK (pad) && GST_PAD_PEER (pad) &&
367 !gst_element_is_locked_state (GST_PAD_PARENT (GST_PAD_PEER (pad)))) {
368 unlocked_peer = TRUE;
373 if (!(lock && unlocked_peer)) {
374 GST_CAT_DEBUG (GST_CAT_PIPELINE, "setting locked state on element");
375 gst_element_set_locked_state (element, lock);
378 /* try to sync state with parent */
379 GST_CAT_DEBUG (GST_CAT_PIPELINE, "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_sync_state_with_parent (element))
383 GST_ELEMENT_ERROR (element, CORE, STATE_CHANGE, (NULL), (NULL));
389 /* check if there are other pads to (un)lock */
390 walk = (GList *) gst_element_get_pad_list (element);
392 pad = (GstPad *) GST_PAD_REALIZE (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, link->sink_pad, link->caps)) {
411 /* do this here, we don't want to get any problems later on when unlocking states */
412 GST_CAT_DEBUG (GST_CAT_PIPELINE, "delayed linking %s:%s to %s:%s worked",
413 GST_ELEMENT_NAME (src), link->src_pad,
414 GST_ELEMENT_NAME (link->sink), link->sink_pad);
415 g_signal_handler_disconnect (src, link->signal_id);
416 g_free (link->src_pad);
417 g_free (link->sink_pad);
418 if (link->caps) gst_caps_free (link->caps);
419 if (!gst_element_is_locked_state (src))
420 gst_parse_element_lock (link->sink, FALSE);
424 /* both padnames and the caps may be NULL */
426 gst_parse_perform_delayed_link (GstElement *src, const gchar *src_pad,
427 GstElement *sink, const gchar *sink_pad, GstCaps *caps)
429 GList *templs = gst_element_get_pad_template_list (src);
432 GstPadTemplate *templ = (GstPadTemplate *) templs->data;
433 if ((GST_PAD_TEMPLATE_DIRECTION (templ) == GST_PAD_SRC) && (GST_PAD_TEMPLATE_PRESENCE(templ) == GST_PAD_SOMETIMES))
435 DelayedLink *data = g_new (DelayedLink, 1);
437 /* TODO: maybe we should check if src_pad matches this template's names */
439 GST_CAT_DEBUG (GST_CAT_PIPELINE, "trying delayed link %s:%s to %s:%s",
440 GST_ELEMENT_NAME (src), src_pad, GST_ELEMENT_NAME (sink), sink_pad);
442 data->src_pad = g_strdup (src_pad);
444 data->sink_pad = g_strdup (sink_pad);
446 data->caps = gst_caps_copy (caps);
450 data->signal_id = g_signal_connect (G_OBJECT (src), "new_pad",
451 G_CALLBACK (gst_parse_found_pad), data);
454 templs = g_list_next (templs);
459 * performs a link and frees the struct. src and sink elements must be given
460 * return values 0 - link performed
465 gst_parse_perform_link (link_t *link, graph_t *graph)
467 GstElement *src = link->src;
468 GstElement *sink = link->sink;
469 GSList *srcs = link->src_pads;
470 GSList *sinks = link->sink_pads;
471 g_assert (GST_IS_ELEMENT (src));
472 g_assert (GST_IS_ELEMENT (sink));
474 GST_CAT_INFO (GST_CAT_PIPELINE, "linking %s:%s to %s:%s (%u/%u) with caps \"%" GST_PTR_FORMAT "\"",
475 GST_ELEMENT_NAME (src), link->src_name ? link->src_name : "(any)",
476 GST_ELEMENT_NAME (sink), link->sink_name ? link->sink_name : "(any)",
477 g_slist_length (srcs), g_slist_length (sinks),
480 if (!srcs || !sinks) {
481 if (gst_element_link_pads_filtered (src, srcs ? (const gchar *) srcs->data : NULL,
482 sink, sinks ? (const gchar *) sinks->data : NULL,
484 gst_parse_element_lock (sink, gst_element_is_locked_state (src));
487 if (gst_parse_perform_delayed_link (src, srcs ? (const gchar *) srcs->data : NULL,
488 sink, sinks ? (const gchar *) sinks->data : NULL,
490 gst_parse_element_lock (sink, TRUE);
497 if (g_slist_length (link->src_pads) != g_slist_length (link->src_pads)) {
500 while (srcs && sinks) {
501 const gchar *src_pad = (const gchar *) srcs->data;
502 const gchar *sink_pad = (const gchar *) sinks->data;
503 srcs = g_slist_next (srcs);
504 sinks = g_slist_next (sinks);
505 if (gst_element_link_pads_filtered (src, src_pad, sink, sink_pad, link->caps)) {
506 gst_parse_element_lock (sink, gst_element_is_locked_state (src));
509 if (gst_parse_perform_delayed_link (src, src_pad,
512 gst_parse_element_lock (sink, TRUE);
521 gst_parse_free_link (link);
525 ERROR (GST_PARSE_ERROR_LINK, _("could not link %s to %s"), GST_ELEMENT_NAME (src), GST_ELEMENT_NAME (sink));
526 gst_parse_free_link (link);
531 static int yylex (void *lvalp);
532 static int yyerror (const char *s);
545 %token <s> IDENTIFIER
546 %left <s> REF PADREF BINREF
547 %token <s> ASSIGNMENT
553 %type <l> linkpart link
556 %type <p> padlist pads assignments
558 %left '{' '}' '(' ')'
568 element: IDENTIFIER { $$ = gst_element_factory_make ($1, NULL);
570 ERROR (GST_PARSE_ERROR_NO_SUCH_ELEMENT, _("no element \"%s\""), $1);
571 gst_parse_strfree ($1);
575 | element ASSIGNMENT { gst_parse_element_set ($2, $1, graph);
579 assignments: /* NOP */ { $$ = NULL; }
580 | assignments ASSIGNMENT { $$ = g_slist_prepend ($1, $2); }
582 bin: '{' assignments chain '}' { GST_BIN_MAKE ($$, "thread", $3, $2); }
583 | '(' assignments chain ')' { GST_BIN_MAKE ($$, "bin", $3, $2); }
584 | BINREF assignments chain ')' { GST_BIN_MAKE ($$, $1, $3, $2);
585 gst_parse_strfree ($1);
587 | '{' assignments '}' { GST_BIN_MAKE ($$, "thread", NULL, $2); }
588 | '(' assignments '}' { GST_BIN_MAKE ($$, "thread", NULL, $2); }
589 | BINREF assignments ')' { GST_BIN_MAKE ($$, $1, NULL, $2);
590 gst_parse_strfree ($1);
592 | '{' assignments error '}' { GST_BIN_MAKE ($$, "thread", NULL, $2); }
593 | '(' assignments error '}' { GST_BIN_MAKE ($$, "thread", NULL, $2); }
594 | BINREF assignments error ')' { GST_BIN_MAKE ($$, $1, NULL, $2);
595 gst_parse_strfree ($1);
599 pads: PADREF { $$ = g_slist_prepend (NULL, $1); }
600 | PADREF padlist { $$ = $2;
601 $$ = g_slist_prepend ($$, $1);
604 padlist: ',' IDENTIFIER { $$ = g_slist_prepend (NULL, $2); }
605 | ',' IDENTIFIER padlist { $$ = g_slist_prepend ($3, $2); }
608 reference: REF { MAKE_REF ($$, $1, NULL); }
609 | REF padlist { MAKE_REF ($$, $1, $2); }
612 linkpart: reference { $$ = $1; }
613 | pads { MAKE_REF ($$, NULL, $1); }
614 | /* NOP */ { MAKE_REF ($$, NULL, NULL); }
617 link: linkpart LINK linkpart { $$ = $1;
619 $$->caps = gst_caps_from_string ($2);
621 ERROR (GST_PARSE_ERROR_LINK, _("could not parse caps \"%s\""), $2);
622 gst_parse_strfree ($2);
624 $$->sink_name = $3->src_name;
625 $$->sink_pads = $3->src_pads;
626 gst_parse_link_free ($3);
630 linklist: link { $$ = g_slist_prepend (NULL, $1); }
631 | link linklist { $$ = g_slist_prepend ($2, $1); }
632 | linklist error { $$ = $1; }
635 chain: element { $$ = gst_parse_chain_new ();
636 $$->first = $$->last = $1;
637 $$->front = $$->back = NULL;
638 $$->elements = g_slist_prepend (NULL, $1);
641 | chain chain { if ($1->back && $2->front) {
642 if (!$1->back->sink_name) {
643 ERROR (GST_PARSE_ERROR_LINK, _("link without source element"));
644 gst_parse_free_link ($1->back);
646 ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, $1->back);
648 if (!$2->front->src_name) {
649 ERROR (GST_PARSE_ERROR_LINK, _("link without sink element"));
650 gst_parse_free_link ($2->front);
652 ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, $2->front);
655 } else if ($1->back) {
656 if (!$1->back->sink_name) {
657 $1->back->sink = $2->first;
659 } else if ($2->front) {
660 if (!$2->front->src_name) {
661 $2->front->src = $1->last;
663 $1->back = $2->front;
667 if (!$1->back->sink || !$1->back->src) {
668 ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, $1->back);
671 gst_parse_perform_link ($1->back, (graph_t *) graph);
676 $1->elements = g_slist_concat ($1->elements, $2->elements);
677 gst_parse_chain_free ($2);
680 | chain linklist { GSList *walk;
682 $2 = g_slist_prepend ($2, $1->back);
685 if (!((link_t *) $2->data)->src_name) {
686 ((link_t *) $2->data)->src = $1->last;
691 link_t *link = (link_t *) walk->data;
693 if (!link->sink_name && walk) {
694 ERROR (GST_PARSE_ERROR_LINK, _("link without sink element"));
695 gst_parse_free_link (link);
696 } else if (!link->src_name && !link->src) {
697 ERROR (GST_PARSE_ERROR_LINK, _("link without source element"));
698 gst_parse_free_link (link);
701 ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, link);
710 | chain error { $$ = $1; }
711 | link chain { if ($2->front) {
712 if (!$2->front->src_name) {
713 ERROR (GST_PARSE_ERROR_LINK, _("link without source element"));
714 gst_parse_free_link ($2->front);
716 ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, $2->front);
719 if (!$1->sink_name) {
720 $1->sink = $2->first;
725 | PARSE_URL chain { $$ = $2;
727 GstElement *element =
728 gst_element_make_from_uri (GST_URI_SRC, $1, NULL);
730 ERROR (GST_PARSE_ERROR_NO_SUCH_ELEMENT,
731 _("no source element for URI \"%s\""), $1);
733 $$->front->src = element;
734 ((graph_t *) graph)->links = g_slist_prepend (
735 ((graph_t *) graph)->links, $$->front);
737 $$->elements = g_slist_prepend ($$->elements, element);
740 ERROR (GST_PARSE_ERROR_LINK,
741 _("no element to link URI \"%s\" to"), $1);
745 | link PARSE_URL { GstElement *element =
746 gst_element_make_from_uri (GST_URI_SINK, $2, NULL);
748 ERROR (GST_PARSE_ERROR_NO_SUCH_ELEMENT,
749 _("no sink element for URI \"%s\""), $2);
751 } else if ($1->sink_name || $1->sink_pads) {
752 ERROR (GST_PARSE_ERROR_LINK,
753 _("could not link sink element for URI \"%s\""), $2);
756 $$ = gst_parse_chain_new ();
757 $$->first = $$->last = element;
759 $$->front->sink = element;
760 $$->elements = g_slist_prepend (NULL, element);
765 graph: /* NOP */ { ERROR (GST_PARSE_ERROR_EMPTY, _("empty pipeline not allowed"));
766 $$ = (graph_t *) graph;
768 | chain { $$ = (graph_t *) graph;
770 if (!$1->front->src_name) {
771 ERROR (GST_PARSE_ERROR_LINK, _("link without source element"));
772 gst_parse_free_link ($1->front);
774 $$->links = g_slist_prepend ($$->links, $1->front);
779 if (!$1->back->sink_name) {
780 ERROR (GST_PARSE_ERROR_LINK, _("link without sink element"));
781 gst_parse_free_link ($1->back);
783 $$->links = g_slist_prepend ($$->links, $1->back);
793 extern FILE *_gst_parse_yyin;
794 int _gst_parse_yylex (YYSTYPE *lvalp);
796 static int yylex (void *lvalp) {
797 return _gst_parse_yylex ((YYSTYPE*) lvalp);
801 yyerror (const char *s)
803 /* FIXME: This should go into the GError somehow, but how? */
804 g_warning ("error: %s", s);
808 int _gst_parse_yy_scan_string (char*);
810 _gst_parse_launch (const gchar *str, GError **error)
818 g_return_val_if_fail (str != NULL, NULL);
824 #ifdef __GST_PARSE_TRACE
825 GST_CAT_DEBUG (GST_CAT_PIPELINE, "TRACE: tracing enabled");
826 __strings = __chains = __links = 0;
827 #endif /* __GST_PARSE_TRACE */
829 dstr = g_strdup (str);
830 _gst_parse_yy_scan_string (dstr);
832 #ifndef GST_DISABLE_GST_DEBUG
836 if (yyparse (&g) != 0) {
837 SET_ERROR (error, GST_PARSE_ERROR_SYNTAX, "Unrecoverable syntax error while parsing pipeline");
843 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));
847 } else if (!(((chain_t *) g.chain)->elements->next)) {
848 /* only one toplevel element */
849 ret = (GstElement *) ((chain_t *) g.chain)->elements->data;
850 g_slist_free (((chain_t *) g.chain)->elements);
851 if (GST_IS_BIN (ret))
854 /* put all elements in our bin */
855 bin = GST_BIN (gst_element_factory_make ("pipeline", NULL));
857 walk = g.chain->elements;
859 gst_bin_add (bin, GST_ELEMENT (walk->data));
860 walk = g_slist_next (walk);
862 g_slist_free (g.chain->elements);
863 ret = GST_ELEMENT (bin);
865 gst_parse_chain_free (g.chain);
870 link_t *l = (link_t *) walk->data;
872 walk = g_slist_next (walk);
876 l->src = gst_bin_get_by_name_recurse_up (bin, l->src_name);
878 l->src = strcmp (GST_ELEMENT_NAME (ret), l->src_name) == 0 ? ret : NULL;
882 SET_ERROR (error, GST_PARSE_ERROR_NO_SUCH_ELEMENT, "No element named \"%s\" - omitting link", l->src_name);
883 gst_parse_free_link (l);
890 l->sink = gst_bin_get_by_name_recurse_up (bin, l->sink_name);
892 l->sink = strcmp (GST_ELEMENT_NAME (ret), l->sink_name) == 0 ? ret : NULL;
896 SET_ERROR (error, GST_PARSE_ERROR_NO_SUCH_ELEMENT, "No element named \"%s\" - omitting link", l->sink_name);
897 gst_parse_free_link (l);
902 gst_parse_perform_link (l, &g);
904 g_slist_free (g.links);
907 #ifdef __GST_PARSE_TRACE
908 GST_CAT_DEBUG (GST_CAT_PIPELINE, "TRACE: %u strings, %u chains and %u links left", __strings, __chains, __links);
909 if (__strings || __chains || __links) {
910 g_warning ("TRACE: %u strings, %u chains and %u links left", __strings, __chains, __links);
912 #endif /* __GST_PARSE_TRACE */
920 walk = g.chain->elements;
922 gst_object_unref (GST_OBJECT (walk->data));
925 g_slist_free (g.chain->elements);
927 gst_parse_chain_free (g.chain);
931 gst_parse_free_link ((link_t *) walk->data);
934 g_slist_free (g.links);