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)
79 /* g_print ("FREEING CHAIN (%3u): %p\n", __chains - 1, data); */
81 g_return_if_fail (__chains > 0);
85 #endif /* __GST_PARSE_TRACE */
93 /* FIXME: need to connect to "disposed" signal to clean up, but there is no such signal */
96 #ifdef G_HAVE_ISO_VARARGS
97 #define SET_ERROR(error, type, ...) G_STMT_START{ \
100 g_warning (__VA_ARGS__); \
102 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{ \
125 g_warning ( args ); \
127 g_set_error ((error), GST_PARSE_ERROR, (type), args ); \
131 #define ERROR(type, args...) SET_ERROR (((graph_t *) graph)->error, (type) , args )
132 #ifndef GST_DISABLE_GST_DEBUG
134 /* bison 1.35 calls this macro with side effects, we need to make sure the
135 side effects work - crappy bison
136 # define YYFPRINTF(a, args...) GST_CAT_DEBUG (GST_CAT_PIPELINE, args )
138 # define YYFPRINTF(a, args...) G_STMT_START{ \
139 gchar *temp = g_strdup_printf ( args ); \
140 GST_CAT_LOG (GST_CAT_PIPELINE, temp); \
147 #define SET_ERROR(error, type, ...) G_STMT_START{ \
150 g_warning ("error while parsing"); \
152 g_set_error ((error), GST_PARSE_ERROR, (type), "error while parsing"); \
156 #define ERROR(type, ...) SET_ERROR (((graph_t *) graph)->error, (type), "error while parsing")
157 #ifndef GST_DISABLE_GST_DEBUG
161 #endif /* G_HAVE_ISO_VARARGS */
163 #define GST_BIN_MAKE(res, type, chainval, assign) G_STMT_START{ \
164 chain_t *chain = chainval; \
166 GstBin *bin = (GstBin *) gst_element_factory_make (type, NULL); \
168 ERROR (GST_PARSE_ERROR_EMPTY_BIN, _("specified empty bin \"%s\", not allowed"), type); \
169 g_slist_foreach (assign, (GFunc) gst_parse_strfree, NULL); \
170 g_slist_free (assign); \
173 ERROR (GST_PARSE_ERROR_NO_SUCH_ELEMENT, _("no bin \"%s\", skipping"), type); \
174 g_slist_foreach (assign, (GFunc) gst_parse_strfree, NULL); \
175 g_slist_free (assign); \
178 for (walk = chain->elements; walk; walk = walk->next ) \
179 gst_bin_add (bin, GST_ELEMENT (walk->data)); \
180 g_slist_free (chain->elements); \
181 chain->elements = g_slist_prepend (NULL, bin); \
183 /* set the properties now */ \
184 for (walk = assign; walk; walk = walk->next) \
185 gst_parse_element_set ((gchar *) walk->data, GST_ELEMENT (bin), graph); \
186 g_slist_free (assign); \
190 #define MAKE_LINK(link, _src, _src_name, _src_pads, _sink, _sink_name, _sink_pads) G_STMT_START{ \
191 link = gst_parse_link_new (); \
193 link->sink = _sink; \
194 link->src_name = _src_name; \
195 link->sink_name = _sink_name; \
196 link->src_pads = _src_pads; \
197 link->sink_pads = _sink_pads; \
201 #define MAKE_REF(link, _src, _pads) G_STMT_START{ \
202 gchar *padname = _src; \
203 GSList *pads = _pads; \
205 while (*padname != '.') padname++; \
208 if (*padname != '\0') \
209 pads = g_slist_prepend (pads, gst_parse_strdup (padname)); \
211 MAKE_LINK (link, NULL, _src, pads, NULL, NULL, NULL); \
215 gst_parse_element_set (gchar *value, GstElement *element, graph_t *graph)
221 /* parse the string, so the property name is null-terminated an pos points
222 to the beginning of the value */
223 while (!g_ascii_isspace (*pos) && (*pos != '=')) pos++;
229 while (g_ascii_isspace (*pos)) pos++;
232 while (g_ascii_isspace (*pos)) pos++;
235 pos[strlen (pos) - 1] = '\0';
237 gst_parse_unescape (pos);
238 if ((pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (element), value))) {
239 g_value_init (&v, G_PARAM_SPEC_VALUE_TYPE(pspec));
240 switch (G_TYPE_FUNDAMENTAL (G_PARAM_SPEC_VALUE_TYPE (pspec))) {
242 g_value_set_string (&v, pos);
245 if (g_ascii_strcasecmp (pos, "true") && g_ascii_strcasecmp (pos, "yes") && g_ascii_strcasecmp (pos, "1")) {
246 g_value_set_boolean (&v, FALSE);
248 g_value_set_boolean (&v, TRUE);
253 gchar *endptr = NULL;
254 GEnumClass *klass = (GEnumClass *) g_type_class_peek (G_PARAM_SPEC_VALUE_TYPE (pspec));
255 if (klass == NULL) goto error;
256 if (!(en = g_enum_get_value_by_name (klass, pos))) {
257 if (!(en = g_enum_get_value_by_nick (klass, pos))) {
258 gint i = strtol (pos, &endptr, 0);
259 if (endptr && *endptr == '\0') {
260 en = g_enum_get_value (klass, i);
266 g_value_set_enum (&v, en->value);
274 g_value_init (&v2, G_TYPE_LONG);
275 l = strtol (pos, &endptr, 0);
276 if (*endptr != '\0') goto error_conversion;
277 g_value_set_long (&v2, l);
278 if (!g_value_transform (&v2, &v)) goto error_conversion;
283 case G_TYPE_UINT64: {
286 g_value_init (&v2, G_TYPE_ULONG);
287 ul = strtoul (pos, &endptr, 0);
288 if (*endptr != '\0') goto error_conversion;
289 g_value_set_ulong (&v2, ul);
290 if (!g_value_transform (&v2, &v)) goto error_conversion;
294 case G_TYPE_DOUBLE: {
297 g_value_init (&v2, G_TYPE_DOUBLE);
298 d = g_ascii_strtod (pos, &endptr);
299 if (*endptr != '\0') goto error_conversion;
300 g_value_set_double (&v2, d);
301 if (!g_value_transform (&v2, &v)) goto error_conversion;
306 g_warning ("property \"%s\" in element %s cannot be set", value, GST_ELEMENT_NAME (element));
309 g_object_set_property (G_OBJECT (element), value, &v);
311 ERROR (GST_PARSE_ERROR_NO_SUCH_PROPERTY, _("no property \"%s\" in element \"%s\""), value, GST_ELEMENT_NAME (element));
315 gst_parse_strfree (value);
318 if (G_IS_VALUE (&v2))
323 ERROR (GST_PARSE_ERROR_COULD_NOT_SET_PROPERTY,
324 _("could not set property \"%s\" in element \"%s\" to \"%s\""),
325 value, GST_ELEMENT_NAME (element), pos);
328 ERROR (GST_PARSE_ERROR_COULD_NOT_SET_PROPERTY,
329 _("could not convert \"%s\" so that it fits property \"%s\" in element \"%s\""),
330 pos, value, GST_ELEMENT_NAME (element));
334 gst_parse_free_link (link_t *link)
336 gst_parse_strfree (link->src_name);
337 gst_parse_strfree (link->sink_name);
338 g_slist_foreach (link->src_pads, (GFunc) gst_parse_strfree, NULL);
339 g_slist_foreach (link->sink_pads, (GFunc) gst_parse_strfree, NULL);
340 g_slist_free (link->src_pads);
341 g_slist_free (link->sink_pads);
342 if (link->caps) gst_caps_free (link->caps);
343 gst_parse_link_free (link);
346 gst_parse_element_lock (GstElement *element, gboolean lock)
349 GList *walk = (GList *) gst_element_get_pad_list (element);
350 gboolean unlocked_peer = FALSE;
352 if (gst_element_is_locked_state (element) == lock)
354 /* check if we have an unlocked peer */
355 for (; walk; walk = walk->next) {
356 pad = (GstPad *) GST_PAD_REALIZE (walk->data);
357 if (GST_PAD_IS_SINK (pad) && GST_PAD_PEER (pad) &&
358 !gst_element_is_locked_state (GST_PAD_PARENT (GST_PAD_PEER (pad)))) {
359 unlocked_peer = TRUE;
364 if (!(lock && unlocked_peer)) {
365 GST_CAT_DEBUG (GST_CAT_PIPELINE, "setting locked state on element");
366 gst_element_set_locked_state (element, lock);
369 /* try to sync state with parent */
370 GST_CAT_DEBUG (GST_CAT_PIPELINE, "trying to sync state of element with parent");
371 /* FIXME: it would be nice if we can figure out why it failed
372 (e.g. caps nego) and give an error about that instead. */
373 if (!gst_element_sync_state_with_parent (element))
374 GST_ELEMENT_ERROR (element, CORE, STATE_CHANGE, (NULL), (NULL));
380 /* check if there are other pads to (un)lock */
381 walk = (GList *) gst_element_get_pad_list (element);
382 for (; walk; walk = walk->next) {
383 pad = (GstPad *) GST_PAD_REALIZE (walk->data);
384 if (GST_PAD_IS_SRC (pad) && GST_PAD_PEER (pad)) {
385 GstElement *next = GST_ELEMENT (GST_OBJECT_PARENT (GST_PAD_PEER (pad)));
386 if (gst_element_is_locked_state (next) != lock)
387 gst_parse_element_lock (next, lock);
392 gst_parse_found_pad (GstElement *src, GstPad *pad, gpointer data)
394 DelayedLink *link = (DelayedLink *) data;
396 GST_CAT_INFO (GST_CAT_PIPELINE, "trying delayed linking %s:%s to %s:%s",
397 GST_ELEMENT_NAME (src), link->src_pad,
398 GST_ELEMENT_NAME (link->sink), link->sink_pad);
400 if (gst_element_link_pads_filtered (src, link->src_pad, link->sink, link->sink_pad, link->caps)) {
401 /* do this here, we don't want to get any problems later on when unlocking states */
402 GST_CAT_DEBUG (GST_CAT_PIPELINE, "delayed linking %s:%s to %s:%s worked",
403 GST_ELEMENT_NAME (src), link->src_pad,
404 GST_ELEMENT_NAME (link->sink), link->sink_pad);
405 g_signal_handler_disconnect (src, link->signal_id);
406 g_free (link->src_pad);
407 g_free (link->sink_pad);
408 if (link->caps) gst_caps_free (link->caps);
409 if (!gst_element_is_locked_state (src))
410 gst_parse_element_lock (link->sink, FALSE);
414 /* both padnames and the caps may be NULL */
416 gst_parse_perform_delayed_link (GstElement *src, const gchar *src_pad,
417 GstElement *sink, const gchar *sink_pad, GstCaps *caps)
419 GList *templs = gst_element_get_pad_template_list (src);
421 for (; templs; templs = templs->next) {
422 GstPadTemplate *templ = (GstPadTemplate *) templs->data;
423 if ((GST_PAD_TEMPLATE_DIRECTION (templ) == GST_PAD_SRC) && (GST_PAD_TEMPLATE_PRESENCE(templ) == GST_PAD_SOMETIMES))
425 DelayedLink *data = g_new (DelayedLink, 1);
427 /* TODO: maybe we should check if src_pad matches this template's names */
429 GST_CAT_DEBUG (GST_CAT_PIPELINE, "trying delayed link %s:%s to %s:%s",
430 GST_ELEMENT_NAME (src), src_pad, GST_ELEMENT_NAME (sink), sink_pad);
432 data->src_pad = g_strdup (src_pad);
434 data->sink_pad = g_strdup (sink_pad);
436 data->caps = gst_caps_copy (caps);
440 data->signal_id = g_signal_connect (G_OBJECT (src), "new_pad",
441 G_CALLBACK (gst_parse_found_pad), data);
448 * performs a link and frees the struct. src and sink elements must be given
449 * return values 0 - link performed
454 gst_parse_perform_link (link_t *link, graph_t *graph)
456 GstElement *src = link->src;
457 GstElement *sink = link->sink;
458 GSList *srcs = link->src_pads;
459 GSList *sinks = link->sink_pads;
460 g_assert (GST_IS_ELEMENT (src));
461 g_assert (GST_IS_ELEMENT (sink));
463 GST_CAT_INFO (GST_CAT_PIPELINE, "linking %s:%s to %s:%s (%u/%u) with caps \"%" GST_PTR_FORMAT "\"",
464 GST_ELEMENT_NAME (src), link->src_name ? link->src_name : "(any)",
465 GST_ELEMENT_NAME (sink), link->sink_name ? link->sink_name : "(any)",
466 g_slist_length (srcs), g_slist_length (sinks),
469 if (!srcs || !sinks) {
470 if (gst_element_link_pads_filtered (src, srcs ? (const gchar *) srcs->data : NULL,
471 sink, sinks ? (const gchar *) sinks->data : NULL,
473 gst_parse_element_lock (sink, gst_element_is_locked_state (src));
476 if (gst_parse_perform_delayed_link (src, srcs ? (const gchar *) srcs->data : NULL,
477 sink, sinks ? (const gchar *) sinks->data : NULL,
479 gst_parse_element_lock (sink, TRUE);
486 if (g_slist_length (link->src_pads) != g_slist_length (link->src_pads)) {
489 while (srcs && sinks) {
490 const gchar *src_pad = (const gchar *) srcs->data;
491 const gchar *sink_pad = (const gchar *) sinks->data;
492 srcs = g_slist_next (srcs);
493 sinks = g_slist_next (sinks);
494 if (gst_element_link_pads_filtered (src, src_pad, sink, sink_pad, link->caps)) {
495 gst_parse_element_lock (sink, gst_element_is_locked_state (src));
498 if (gst_parse_perform_delayed_link (src, src_pad,
501 gst_parse_element_lock (sink, TRUE);
510 gst_parse_free_link (link);
514 ERROR (GST_PARSE_ERROR_LINK, _("could not link %s to %s"), GST_ELEMENT_NAME (src), GST_ELEMENT_NAME (sink));
515 gst_parse_free_link (link);
520 static int yylex (void *lvalp);
521 static int yyerror (const char *s);
534 %token <s> IDENTIFIER
535 %left <s> REF PADREF BINREF
536 %token <s> ASSIGNMENT
542 %type <l> linkpart link
545 %type <p> padlist pads assignments
547 %left '{' '}' '(' ')'
557 element: IDENTIFIER { $$ = gst_element_factory_make ($1, NULL);
559 ERROR (GST_PARSE_ERROR_NO_SUCH_ELEMENT, _("no element \"%s\""), $1);
560 gst_parse_strfree ($1);
564 | element ASSIGNMENT { gst_parse_element_set ($2, $1, graph);
568 assignments: /* NOP */ { $$ = NULL; }
569 | assignments ASSIGNMENT { $$ = g_slist_prepend ($1, $2); }
571 bin: '{' assignments chain '}' { GST_BIN_MAKE ($$, "thread", $3, $2); }
572 | '(' assignments chain ')' { GST_BIN_MAKE ($$, "bin", $3, $2); }
573 | BINREF assignments chain ')' { GST_BIN_MAKE ($$, $1, $3, $2);
574 gst_parse_strfree ($1);
576 | '{' assignments '}' { GST_BIN_MAKE ($$, "thread", NULL, $2); }
577 | '(' assignments '}' { GST_BIN_MAKE ($$, "thread", NULL, $2); }
578 | BINREF assignments ')' { GST_BIN_MAKE ($$, $1, NULL, $2);
579 gst_parse_strfree ($1);
581 | '{' assignments error '}' { GST_BIN_MAKE ($$, "thread", NULL, $2); }
582 | '(' assignments error '}' { GST_BIN_MAKE ($$, "thread", NULL, $2); }
583 | BINREF assignments error ')' { GST_BIN_MAKE ($$, $1, NULL, $2);
584 gst_parse_strfree ($1);
588 pads: PADREF { $$ = g_slist_prepend (NULL, $1); }
589 | PADREF padlist { $$ = $2;
590 $$ = g_slist_prepend ($$, $1);
593 padlist: ',' IDENTIFIER { $$ = g_slist_prepend (NULL, $2); }
594 | ',' IDENTIFIER padlist { $$ = g_slist_prepend ($3, $2); }
597 reference: REF { MAKE_REF ($$, $1, NULL); }
598 | REF padlist { MAKE_REF ($$, $1, $2); }
601 linkpart: reference { $$ = $1; }
602 | pads { MAKE_REF ($$, NULL, $1); }
603 | /* NOP */ { MAKE_REF ($$, NULL, NULL); }
606 link: linkpart LINK linkpart { $$ = $1;
608 $$->caps = gst_caps_from_string ($2);
610 ERROR (GST_PARSE_ERROR_LINK, _("could not parse caps \"%s\""), $2);
611 gst_parse_strfree ($2);
613 $$->sink_name = $3->src_name;
614 $$->sink_pads = $3->src_pads;
615 gst_parse_link_free ($3);
619 linklist: link { $$ = g_slist_prepend (NULL, $1); }
620 | link linklist { $$ = g_slist_prepend ($2, $1); }
621 | linklist error { $$ = $1; }
624 chain: element { $$ = gst_parse_chain_new ();
625 $$->first = $$->last = $1;
626 $$->front = $$->back = NULL;
627 $$->elements = g_slist_prepend (NULL, $1);
630 | chain chain { if ($1->back && $2->front) {
631 if (!$1->back->sink_name) {
632 ERROR (GST_PARSE_ERROR_LINK, _("link without source element"));
633 gst_parse_free_link ($1->back);
635 ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, $1->back);
637 if (!$2->front->src_name) {
638 ERROR (GST_PARSE_ERROR_LINK, _("link without sink element"));
639 gst_parse_free_link ($2->front);
641 ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, $2->front);
644 } else if ($1->back) {
645 if (!$1->back->sink_name) {
646 $1->back->sink = $2->first;
648 } else if ($2->front) {
649 if (!$2->front->src_name) {
650 $2->front->src = $1->last;
652 $1->back = $2->front;
656 if (!$1->back->sink || !$1->back->src) {
657 ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, $1->back);
660 gst_parse_perform_link ($1->back, (graph_t *) graph);
665 $1->elements = g_slist_concat ($1->elements, $2->elements);
667 gst_parse_chain_free ($2);
670 | chain linklist { GSList *walk;
672 $2 = g_slist_prepend ($2, $1->back);
675 if (!((link_t *) $2->data)->src_name) {
676 ((link_t *) $2->data)->src = $1->last;
679 for (walk = $2; walk; walk = walk->next) {
680 link_t *link = (link_t *) walk->data;
681 if (!link->sink_name && walk->next) {
682 ERROR (GST_PARSE_ERROR_LINK, _("link without sink element"));
683 gst_parse_free_link (link);
684 } else if (!link->src_name && !link->src) {
685 ERROR (GST_PARSE_ERROR_LINK, _("link without source element"));
686 gst_parse_free_link (link);
689 ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, link);
698 | chain error { $$ = $1; }
699 | link chain { if ($2->front) {
700 if (!$2->front->src_name) {
701 ERROR (GST_PARSE_ERROR_LINK, _("link without source element"));
702 gst_parse_free_link ($2->front);
704 ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, $2->front);
707 if (!$1->sink_name) {
708 $1->sink = $2->first;
713 | PARSE_URL chain { $$ = $2;
715 GstElement *element =
716 gst_element_make_from_uri (GST_URI_SRC, $1, NULL);
718 ERROR (GST_PARSE_ERROR_NO_SUCH_ELEMENT,
719 _("no source element for URI \"%s\""), $1);
721 $$->front->src = element;
722 ((graph_t *) graph)->links = g_slist_prepend (
723 ((graph_t *) graph)->links, $$->front);
725 $$->elements = g_slist_prepend ($$->elements, element);
728 ERROR (GST_PARSE_ERROR_LINK,
729 _("no element to link URI \"%s\" to"), $1);
733 | link PARSE_URL { GstElement *element =
734 gst_element_make_from_uri (GST_URI_SINK, $2, NULL);
736 ERROR (GST_PARSE_ERROR_NO_SUCH_ELEMENT,
737 _("no sink element for URI \"%s\""), $2);
739 } else if ($1->sink_name || $1->sink_pads) {
740 ERROR (GST_PARSE_ERROR_LINK,
741 _("could not link sink element for URI \"%s\""), $2);
744 $$ = gst_parse_chain_new ();
745 $$->first = $$->last = element;
747 $$->front->sink = element;
748 $$->elements = g_slist_prepend (NULL, element);
753 graph: /* NOP */ { ERROR (GST_PARSE_ERROR_EMPTY, _("empty pipeline not allowed"));
754 $$ = (graph_t *) graph;
756 | chain { $$ = (graph_t *) graph;
758 if (!$1->front->src_name) {
759 ERROR (GST_PARSE_ERROR_LINK, _("link without source element"));
760 gst_parse_free_link ($1->front);
762 $$->links = g_slist_prepend ($$->links, $1->front);
767 if (!$1->back->sink_name) {
768 ERROR (GST_PARSE_ERROR_LINK, _("link without sink element"));
769 gst_parse_free_link ($1->back);
771 $$->links = g_slist_prepend ($$->links, $1->back);
781 extern FILE *_gst_parse_yyin;
782 int _gst_parse_yylex (YYSTYPE *lvalp);
784 static int yylex (void *lvalp) {
785 return _gst_parse_yylex ((YYSTYPE*) lvalp);
789 yyerror (const char *s)
791 /* FIXME: This should go into the GError somehow, but how? */
792 g_warning ("error: %s", s);
796 int _gst_parse_yy_scan_string (char*);
798 _gst_parse_launch (const gchar *str, GError **error)
806 g_return_val_if_fail (str != NULL, NULL);
812 #ifdef __GST_PARSE_TRACE
813 GST_CAT_DEBUG (GST_CAT_PIPELINE, "TRACE: tracing enabled");
814 __strings = __chains = __links = 0;
815 #endif /* __GST_PARSE_TRACE */
817 dstr = g_strdup (str);
818 _gst_parse_yy_scan_string (dstr);
820 #ifndef GST_DISABLE_GST_DEBUG
824 if (yyparse (&g) != 0) {
825 SET_ERROR (error, GST_PARSE_ERROR_SYNTAX, "Unrecoverable syntax error while parsing pipeline");
831 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));
835 } else if (!(((chain_t *) g.chain)->elements->next)) {
836 /* only one toplevel element */
837 ret = (GstElement *) ((chain_t *) g.chain)->elements->data;
838 g_slist_free (((chain_t *) g.chain)->elements);
839 if (GST_IS_BIN (ret))
841 gst_parse_chain_free (g.chain);
843 /* put all elements in our bin */
844 bin = GST_BIN (gst_element_factory_make ("pipeline", NULL));
847 for (walk = g.chain->elements; walk; walk = walk->next)
848 gst_bin_add (bin, GST_ELEMENT (walk->data));
850 g_slist_free (g.chain->elements);
851 ret = GST_ELEMENT (bin);
852 gst_parse_chain_free (g.chain);
856 for (walk = g.links; walk; walk = walk->next) {
857 link_t *l = (link_t *) walk->data;
861 l->src = gst_bin_get_by_name_recurse_up (bin, l->src_name);
863 l->src = strcmp (GST_ELEMENT_NAME (ret), l->src_name) == 0 ? ret : NULL;
867 SET_ERROR (error, GST_PARSE_ERROR_NO_SUCH_ELEMENT, "No element named \"%s\" - omitting link", l->src_name);
868 gst_parse_free_link (l);
875 l->sink = gst_bin_get_by_name_recurse_up (bin, l->sink_name);
877 l->sink = strcmp (GST_ELEMENT_NAME (ret), l->sink_name) == 0 ? ret : NULL;
881 SET_ERROR (error, GST_PARSE_ERROR_NO_SUCH_ELEMENT, "No element named \"%s\" - omitting link", l->sink_name);
882 gst_parse_free_link (l);
886 gst_parse_perform_link (l, &g);
888 g_slist_free (g.links);
891 #ifdef __GST_PARSE_TRACE
892 GST_CAT_DEBUG (GST_CAT_PIPELINE, "TRACE: %u strings, %u chains and %u links left", __strings, __chains, __links);
893 if (__strings || __chains || __links) {
894 g_warning ("TRACE: %u strings, %u chains and %u links left", __strings, __chains, __links);
896 #endif /* __GST_PARSE_TRACE */
904 g_slist_foreach (g.chain->elements, (GFunc)gst_object_unref, NULL);
905 g_slist_free (g.chain->elements);
906 gst_parse_chain_free (g.chain);
909 g_slist_foreach (g.links, (GFunc)gst_parse_free_link, NULL);
910 g_slist_free (g.links);