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{ \
98 GST_CAT_ERROR (GST_CAT_PIPELINE, __VA_ARGS__); \
99 if ((error) && !*(error)) { \
100 g_set_error ((error), GST_PARSE_ERROR, (type), __VA_ARGS__); \
103 #define ERROR(type, ...) SET_ERROR (((graph_t *) graph)->error, (type), __VA_ARGS__ )
104 #ifndef GST_DISABLE_GST_DEBUG
106 /* bison 1.35 calls this macro with side effects, we need to make sure the
107 side effects work - crappy bison
108 # define YYFPRINTF(a, ...) GST_CAT_DEBUG (GST_CAT_PIPELINE, __VA_ARGS__)
110 # define YYFPRINTF(a, ...) G_STMT_START{ \
111 gchar *temp = g_strdup_printf (__VA_ARGS__); \
112 GST_CAT_LOG (GST_CAT_PIPELINE, temp); \
117 #elif defined(G_HAVE_GNUC_VARARGS)
119 #define SET_ERROR(error, type, args...) G_STMT_START{ \
120 GST_CAT_ERROR (GST_CAT_PIPELINE, args ); \
121 if ((error) && !*(error)) { \
122 g_set_error ((error), GST_PARSE_ERROR, (type), args ); \
125 #define ERROR(type, args...) SET_ERROR (((graph_t *) graph)->error, (type) , args )
126 #ifndef GST_DISABLE_GST_DEBUG
128 /* bison 1.35 calls this macro with side effects, we need to make sure the
129 side effects work - crappy bison
130 # define YYFPRINTF(a, args...) GST_CAT_DEBUG (GST_CAT_PIPELINE, args )
132 # define YYFPRINTF(a, args...) G_STMT_START{ \
133 gchar *temp = g_strdup_printf ( args ); \
134 GST_CAT_LOG (GST_CAT_PIPELINE, temp); \
141 #define SET_ERROR(error, type, ...) G_STMT_START{ \
142 GST_CAT_ERROR (GST_CAT_PIPELINE, "error while parsing" ); \
143 if ((error) && !*(error)) { \
144 g_set_error ((error), GST_PARSE_ERROR, (type), "error while parsing"); \
147 #define ERROR(type, ...) SET_ERROR (((graph_t *) graph)->error, (type), "error while parsing")
148 #ifndef GST_DISABLE_GST_DEBUG
152 #endif /* G_HAVE_ISO_VARARGS */
154 #define GST_BIN_MAKE(res, type, chainval, assign) G_STMT_START{ \
155 chain_t *chain = chainval; \
157 GstBin *bin = (GstBin *) gst_element_factory_make (type, NULL); \
159 ERROR (GST_PARSE_ERROR_EMPTY_BIN, _("specified empty bin \"%s\", not allowed"), type); \
160 g_slist_foreach (assign, (GFunc) gst_parse_strfree, NULL); \
161 g_slist_free (assign); \
164 ERROR (GST_PARSE_ERROR_NO_SUCH_ELEMENT, _("no bin \"%s\", skipping"), type); \
165 g_slist_foreach (assign, (GFunc) gst_parse_strfree, NULL); \
166 g_slist_free (assign); \
169 for (walk = chain->elements; walk; walk = walk->next ) \
170 gst_bin_add (bin, GST_ELEMENT (walk->data)); \
171 g_slist_free (chain->elements); \
172 chain->elements = g_slist_prepend (NULL, bin); \
174 /* set the properties now */ \
175 for (walk = assign; walk; walk = walk->next) \
176 gst_parse_element_set ((gchar *) walk->data, GST_ELEMENT (bin), graph); \
177 g_slist_free (assign); \
181 #define MAKE_LINK(link, _src, _src_name, _src_pads, _sink, _sink_name, _sink_pads) G_STMT_START{ \
182 link = gst_parse_link_new (); \
184 link->sink = _sink; \
185 link->src_name = _src_name; \
186 link->sink_name = _sink_name; \
187 link->src_pads = _src_pads; \
188 link->sink_pads = _sink_pads; \
192 #define MAKE_REF(link, _src, _pads) G_STMT_START{ \
193 gchar *padname = _src; \
194 GSList *pads = _pads; \
196 while (*padname != '.') padname++; \
199 if (*padname != '\0') \
200 pads = g_slist_prepend (pads, gst_parse_strdup (padname)); \
202 MAKE_LINK (link, NULL, _src, pads, NULL, NULL, NULL); \
206 gst_parse_element_set (gchar *value, GstElement *element, graph_t *graph)
212 /* parse the string, so the property name is null-terminated an pos points
213 to the beginning of the value */
214 while (!g_ascii_isspace (*pos) && (*pos != '=')) pos++;
220 while (g_ascii_isspace (*pos)) pos++;
223 while (g_ascii_isspace (*pos)) pos++;
226 pos[strlen (pos) - 1] = '\0';
228 gst_parse_unescape (pos);
229 if ((pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (element), value))) {
230 g_value_init (&v, G_PARAM_SPEC_VALUE_TYPE(pspec));
231 switch (G_TYPE_FUNDAMENTAL (G_PARAM_SPEC_VALUE_TYPE (pspec))) {
233 g_value_set_string (&v, pos);
236 if (g_ascii_strcasecmp (pos, "true") && g_ascii_strcasecmp (pos, "yes") && g_ascii_strcasecmp (pos, "1")) {
237 g_value_set_boolean (&v, FALSE);
239 g_value_set_boolean (&v, TRUE);
244 gchar *endptr = NULL;
245 GEnumClass *klass = (GEnumClass *) g_type_class_peek (G_PARAM_SPEC_VALUE_TYPE (pspec));
246 if (klass == NULL) goto error;
247 if (!(en = g_enum_get_value_by_name (klass, pos))) {
248 if (!(en = g_enum_get_value_by_nick (klass, pos))) {
249 gint i = strtol (pos, &endptr, 0);
250 if (endptr && *endptr == '\0') {
251 en = g_enum_get_value (klass, i);
257 g_value_set_enum (&v, en->value);
265 g_value_init (&v2, G_TYPE_LONG);
266 l = strtol (pos, &endptr, 0);
267 if (*endptr != '\0') goto error_conversion;
268 g_value_set_long (&v2, l);
269 if (!g_value_transform (&v2, &v)) goto error_conversion;
274 case G_TYPE_UINT64: {
277 g_value_init (&v2, G_TYPE_ULONG);
278 ul = strtoul (pos, &endptr, 0);
279 if (*endptr != '\0') goto error_conversion;
280 g_value_set_ulong (&v2, ul);
281 if (!g_value_transform (&v2, &v)) goto error_conversion;
285 case G_TYPE_DOUBLE: {
288 g_value_init (&v2, G_TYPE_DOUBLE);
289 d = g_ascii_strtod (pos, &endptr);
290 if (*endptr != '\0') goto error_conversion;
291 g_value_set_double (&v2, d);
292 if (!g_value_transform (&v2, &v)) goto error_conversion;
297 g_warning ("property \"%s\" in element %s cannot be set", value, GST_ELEMENT_NAME (element));
300 g_object_set_property (G_OBJECT (element), value, &v);
302 ERROR (GST_PARSE_ERROR_NO_SUCH_PROPERTY, _("no property \"%s\" in element \"%s\""), value, GST_ELEMENT_NAME (element));
306 gst_parse_strfree (value);
309 if (G_IS_VALUE (&v2))
314 ERROR (GST_PARSE_ERROR_COULD_NOT_SET_PROPERTY,
315 _("could not set property \"%s\" in element \"%s\" to \"%s\""),
316 value, GST_ELEMENT_NAME (element), pos);
319 ERROR (GST_PARSE_ERROR_COULD_NOT_SET_PROPERTY,
320 _("could not convert \"%s\" so that it fits property \"%s\" in element \"%s\""),
321 pos, value, GST_ELEMENT_NAME (element));
325 gst_parse_free_link (link_t *link)
327 gst_parse_strfree (link->src_name);
328 gst_parse_strfree (link->sink_name);
329 g_slist_foreach (link->src_pads, (GFunc) gst_parse_strfree, NULL);
330 g_slist_foreach (link->sink_pads, (GFunc) gst_parse_strfree, NULL);
331 g_slist_free (link->src_pads);
332 g_slist_free (link->sink_pads);
333 if (link->caps) gst_caps_free (link->caps);
334 gst_parse_link_free (link);
337 gst_parse_element_lock (GstElement *element, gboolean lock)
340 GList *walk = (GList *) gst_element_get_pad_list (element);
341 gboolean unlocked_peer = FALSE;
343 if (gst_element_is_locked_state (element) == lock)
345 /* check if we have an unlocked peer */
346 for (; walk; walk = walk->next) {
347 pad = (GstPad *) GST_PAD_REALIZE (walk->data);
348 if (GST_PAD_IS_SINK (pad) && GST_PAD_PEER (pad) &&
349 !gst_element_is_locked_state (GST_PAD_PARENT (GST_PAD_PEER (pad)))) {
350 unlocked_peer = TRUE;
355 if (!(lock && unlocked_peer)) {
356 GST_CAT_DEBUG (GST_CAT_PIPELINE, "setting locked state on element");
357 gst_element_set_locked_state (element, lock);
360 /* try to sync state with parent */
361 GST_CAT_DEBUG (GST_CAT_PIPELINE, "trying to sync state of element with parent");
362 /* FIXME: it would be nice if we can figure out why it failed
363 (e.g. caps nego) and give an error about that instead. */
364 if (!gst_element_sync_state_with_parent (element))
365 GST_ELEMENT_ERROR (element, CORE, STATE_CHANGE, (NULL), (NULL));
371 /* check if there are other pads to (un)lock */
372 walk = (GList *) gst_element_get_pad_list (element);
373 for (; walk; walk = walk->next) {
374 pad = (GstPad *) GST_PAD_REALIZE (walk->data);
375 if (GST_PAD_IS_SRC (pad) && GST_PAD_PEER (pad)) {
376 GstElement *next = GST_ELEMENT (GST_OBJECT_PARENT (GST_PAD_PEER (pad)));
377 if (gst_element_is_locked_state (next) != lock)
378 gst_parse_element_lock (next, lock);
383 gst_parse_found_pad (GstElement *src, GstPad *pad, gpointer data)
385 DelayedLink *link = (DelayedLink *) data;
387 GST_CAT_INFO (GST_CAT_PIPELINE, "trying delayed linking %s:%s to %s:%s",
388 GST_ELEMENT_NAME (src), link->src_pad,
389 GST_ELEMENT_NAME (link->sink), link->sink_pad);
391 if (gst_element_link_pads_filtered (src, link->src_pad, link->sink, link->sink_pad, link->caps)) {
392 /* do this here, we don't want to get any problems later on when unlocking states */
393 GST_CAT_DEBUG (GST_CAT_PIPELINE, "delayed linking %s:%s to %s:%s worked",
394 GST_ELEMENT_NAME (src), link->src_pad,
395 GST_ELEMENT_NAME (link->sink), link->sink_pad);
396 g_signal_handler_disconnect (src, link->signal_id);
397 g_free (link->src_pad);
398 g_free (link->sink_pad);
399 if (link->caps) gst_caps_free (link->caps);
400 if (!gst_element_is_locked_state (src))
401 gst_parse_element_lock (link->sink, FALSE);
405 /* both padnames and the caps may be NULL */
407 gst_parse_perform_delayed_link (GstElement *src, const gchar *src_pad,
408 GstElement *sink, const gchar *sink_pad, GstCaps *caps)
410 GList *templs = gst_element_get_pad_template_list (src);
412 for (; templs; templs = templs->next) {
413 GstPadTemplate *templ = (GstPadTemplate *) templs->data;
414 if ((GST_PAD_TEMPLATE_DIRECTION (templ) == GST_PAD_SRC) && (GST_PAD_TEMPLATE_PRESENCE(templ) == GST_PAD_SOMETIMES))
416 DelayedLink *data = g_new (DelayedLink, 1);
418 /* TODO: maybe we should check if src_pad matches this template's names */
420 GST_CAT_DEBUG (GST_CAT_PIPELINE, "trying delayed link %s:%s to %s:%s",
421 GST_ELEMENT_NAME (src), src_pad, GST_ELEMENT_NAME (sink), sink_pad);
423 data->src_pad = g_strdup (src_pad);
425 data->sink_pad = g_strdup (sink_pad);
427 data->caps = gst_caps_copy (caps);
431 data->signal_id = g_signal_connect (G_OBJECT (src), "new_pad",
432 G_CALLBACK (gst_parse_found_pad), data);
439 * performs a link and frees the struct. src and sink elements must be given
440 * return values 0 - link performed
445 gst_parse_perform_link (link_t *link, graph_t *graph)
447 GstElement *src = link->src;
448 GstElement *sink = link->sink;
449 GSList *srcs = link->src_pads;
450 GSList *sinks = link->sink_pads;
451 g_assert (GST_IS_ELEMENT (src));
452 g_assert (GST_IS_ELEMENT (sink));
454 GST_CAT_INFO (GST_CAT_PIPELINE, "linking %s:%s to %s:%s (%u/%u) with caps \"%" GST_PTR_FORMAT "\"",
455 GST_ELEMENT_NAME (src), link->src_name ? link->src_name : "(any)",
456 GST_ELEMENT_NAME (sink), link->sink_name ? link->sink_name : "(any)",
457 g_slist_length (srcs), g_slist_length (sinks),
460 if (!srcs || !sinks) {
461 if (gst_element_link_pads_filtered (src, srcs ? (const gchar *) srcs->data : NULL,
462 sink, sinks ? (const gchar *) sinks->data : NULL,
464 gst_parse_element_lock (sink, gst_element_is_locked_state (src));
467 if (gst_parse_perform_delayed_link (src, srcs ? (const gchar *) srcs->data : NULL,
468 sink, sinks ? (const gchar *) sinks->data : NULL,
470 gst_parse_element_lock (sink, TRUE);
477 if (g_slist_length (link->src_pads) != g_slist_length (link->src_pads)) {
480 while (srcs && sinks) {
481 const gchar *src_pad = (const gchar *) srcs->data;
482 const gchar *sink_pad = (const gchar *) sinks->data;
483 srcs = g_slist_next (srcs);
484 sinks = g_slist_next (sinks);
485 if (gst_element_link_pads_filtered (src, src_pad, sink, sink_pad, link->caps)) {
486 gst_parse_element_lock (sink, gst_element_is_locked_state (src));
489 if (gst_parse_perform_delayed_link (src, src_pad,
492 gst_parse_element_lock (sink, TRUE);
501 gst_parse_free_link (link);
505 ERROR (GST_PARSE_ERROR_LINK, _("could not link %s to %s"), GST_ELEMENT_NAME (src), GST_ELEMENT_NAME (sink));
506 gst_parse_free_link (link);
511 static int yylex (void *lvalp);
512 static int yyerror (const char *s);
525 %token <s> IDENTIFIER
526 %left <s> REF PADREF BINREF
527 %token <s> ASSIGNMENT
533 %type <l> linkpart link
536 %type <p> padlist pads assignments
538 %left '{' '}' '(' ')'
548 element: IDENTIFIER { $$ = gst_element_factory_make ($1, NULL);
550 ERROR (GST_PARSE_ERROR_NO_SUCH_ELEMENT, _("no element \"%s\""), $1);
551 gst_parse_strfree ($1);
555 | element ASSIGNMENT { gst_parse_element_set ($2, $1, graph);
559 assignments: /* NOP */ { $$ = NULL; }
560 | assignments ASSIGNMENT { $$ = g_slist_prepend ($1, $2); }
562 bin: '{' assignments chain '}' { GST_BIN_MAKE ($$, "thread", $3, $2); }
563 | '(' assignments chain ')' { GST_BIN_MAKE ($$, "bin", $3, $2); }
564 | BINREF assignments chain ')' { GST_BIN_MAKE ($$, $1, $3, $2);
565 gst_parse_strfree ($1);
567 | '{' assignments '}' { GST_BIN_MAKE ($$, "thread", NULL, $2); }
568 | '(' assignments '}' { GST_BIN_MAKE ($$, "thread", NULL, $2); }
569 | BINREF assignments ')' { GST_BIN_MAKE ($$, $1, NULL, $2);
570 gst_parse_strfree ($1);
572 | '{' assignments error '}' { GST_BIN_MAKE ($$, "thread", NULL, $2); }
573 | '(' assignments error '}' { GST_BIN_MAKE ($$, "thread", NULL, $2); }
574 | BINREF assignments error ')' { GST_BIN_MAKE ($$, $1, NULL, $2);
575 gst_parse_strfree ($1);
579 pads: PADREF { $$ = g_slist_prepend (NULL, $1); }
580 | PADREF padlist { $$ = $2;
581 $$ = g_slist_prepend ($$, $1);
584 padlist: ',' IDENTIFIER { $$ = g_slist_prepend (NULL, $2); }
585 | ',' IDENTIFIER padlist { $$ = g_slist_prepend ($3, $2); }
588 reference: REF { MAKE_REF ($$, $1, NULL); }
589 | REF padlist { MAKE_REF ($$, $1, $2); }
592 linkpart: reference { $$ = $1; }
593 | pads { MAKE_REF ($$, NULL, $1); }
594 | /* NOP */ { MAKE_REF ($$, NULL, NULL); }
597 link: linkpart LINK linkpart { $$ = $1;
599 $$->caps = gst_caps_from_string ($2);
601 ERROR (GST_PARSE_ERROR_LINK, _("could not parse caps \"%s\""), $2);
602 gst_parse_strfree ($2);
604 $$->sink_name = $3->src_name;
605 $$->sink_pads = $3->src_pads;
606 gst_parse_link_free ($3);
610 linklist: link { $$ = g_slist_prepend (NULL, $1); }
611 | link linklist { $$ = g_slist_prepend ($2, $1); }
612 | linklist error { $$ = $1; }
615 chain: element { $$ = gst_parse_chain_new ();
616 $$->first = $$->last = $1;
617 $$->front = $$->back = NULL;
618 $$->elements = g_slist_prepend (NULL, $1);
621 | chain chain { if ($1->back && $2->front) {
622 if (!$1->back->sink_name) {
623 ERROR (GST_PARSE_ERROR_LINK, _("link without source element"));
624 gst_parse_free_link ($1->back);
626 ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, $1->back);
628 if (!$2->front->src_name) {
629 ERROR (GST_PARSE_ERROR_LINK, _("link without sink element"));
630 gst_parse_free_link ($2->front);
632 ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, $2->front);
635 } else if ($1->back) {
636 if (!$1->back->sink_name) {
637 $1->back->sink = $2->first;
639 } else if ($2->front) {
640 if (!$2->front->src_name) {
641 $2->front->src = $1->last;
643 $1->back = $2->front;
647 if (!$1->back->sink || !$1->back->src) {
648 ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, $1->back);
651 gst_parse_perform_link ($1->back, (graph_t *) graph);
656 $1->elements = g_slist_concat ($1->elements, $2->elements);
658 gst_parse_chain_free ($2);
661 | chain linklist { GSList *walk;
663 $2 = g_slist_prepend ($2, $1->back);
666 if (!((link_t *) $2->data)->src_name) {
667 ((link_t *) $2->data)->src = $1->last;
670 for (walk = $2; walk; walk = walk->next) {
671 link_t *link = (link_t *) walk->data;
672 if (!link->sink_name && walk->next) {
673 ERROR (GST_PARSE_ERROR_LINK, _("link without sink element"));
674 gst_parse_free_link (link);
675 } else if (!link->src_name && !link->src) {
676 ERROR (GST_PARSE_ERROR_LINK, _("link without source element"));
677 gst_parse_free_link (link);
680 ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, link);
689 | chain error { $$ = $1; }
690 | link chain { if ($2->front) {
691 if (!$2->front->src_name) {
692 ERROR (GST_PARSE_ERROR_LINK, _("link without source element"));
693 gst_parse_free_link ($2->front);
695 ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, $2->front);
698 if (!$1->sink_name) {
699 $1->sink = $2->first;
704 | PARSE_URL chain { $$ = $2;
706 GstElement *element =
707 gst_element_make_from_uri (GST_URI_SRC, $1, NULL);
709 ERROR (GST_PARSE_ERROR_NO_SUCH_ELEMENT,
710 _("no source element for URI \"%s\""), $1);
712 $$->front->src = element;
713 ((graph_t *) graph)->links = g_slist_prepend (
714 ((graph_t *) graph)->links, $$->front);
716 $$->elements = g_slist_prepend ($$->elements, element);
719 ERROR (GST_PARSE_ERROR_LINK,
720 _("no element to link URI \"%s\" to"), $1);
724 | link PARSE_URL { GstElement *element =
725 gst_element_make_from_uri (GST_URI_SINK, $2, NULL);
727 ERROR (GST_PARSE_ERROR_NO_SUCH_ELEMENT,
728 _("no sink element for URI \"%s\""), $2);
730 } else if ($1->sink_name || $1->sink_pads) {
731 ERROR (GST_PARSE_ERROR_LINK,
732 _("could not link sink element for URI \"%s\""), $2);
735 $$ = gst_parse_chain_new ();
736 $$->first = $$->last = element;
738 $$->front->sink = element;
739 $$->elements = g_slist_prepend (NULL, element);
744 graph: /* NOP */ { ERROR (GST_PARSE_ERROR_EMPTY, _("empty pipeline not allowed"));
745 $$ = (graph_t *) graph;
747 | chain { $$ = (graph_t *) graph;
749 if (!$1->front->src_name) {
750 ERROR (GST_PARSE_ERROR_LINK, _("link without source element"));
751 gst_parse_free_link ($1->front);
753 $$->links = g_slist_prepend ($$->links, $1->front);
758 if (!$1->back->sink_name) {
759 ERROR (GST_PARSE_ERROR_LINK, _("link without sink element"));
760 gst_parse_free_link ($1->back);
762 $$->links = g_slist_prepend ($$->links, $1->back);
772 extern FILE *_gst_parse_yyin;
773 int _gst_parse_yylex (YYSTYPE *lvalp);
775 static int yylex (void *lvalp) {
776 return _gst_parse_yylex ((YYSTYPE*) lvalp);
780 yyerror (const char *s)
782 /* FIXME: This should go into the GError somehow, but how? */
783 g_warning ("error: %s", s);
787 struct yy_buffer_state * _gst_parse_yy_scan_string (char*);
788 void _gst_parse_yy_delete_buffer (struct yy_buffer_state *);
790 _gst_parse_launch (const gchar *str, GError **error)
797 struct yy_buffer_state *buf;
799 g_return_val_if_fail (str != NULL, NULL);
805 #ifdef __GST_PARSE_TRACE
806 GST_CAT_DEBUG (GST_CAT_PIPELINE, "TRACE: tracing enabled");
807 __strings = __chains = __links = 0;
808 #endif /* __GST_PARSE_TRACE */
810 dstr = g_strdup (str);
811 buf = _gst_parse_yy_scan_string (dstr);
813 #ifndef GST_DISABLE_GST_DEBUG
817 if (yyparse (&g) != 0) {
818 SET_ERROR (error, GST_PARSE_ERROR_SYNTAX, "Unrecoverable syntax error while parsing pipeline %s", str);
823 _gst_parse_yy_delete_buffer (buf);
825 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));
829 } else if (!(((chain_t *) g.chain)->elements->next)) {
830 /* only one toplevel element */
831 ret = (GstElement *) ((chain_t *) g.chain)->elements->data;
832 g_slist_free (((chain_t *) g.chain)->elements);
833 if (GST_IS_BIN (ret))
835 gst_parse_chain_free (g.chain);
837 /* put all elements in our bin */
838 bin = GST_BIN (gst_element_factory_make ("pipeline", NULL));
841 for (walk = g.chain->elements; walk; walk = walk->next)
842 gst_bin_add (bin, GST_ELEMENT (walk->data));
844 g_slist_free (g.chain->elements);
845 ret = GST_ELEMENT (bin);
846 gst_parse_chain_free (g.chain);
850 for (walk = g.links; walk; walk = walk->next) {
851 link_t *l = (link_t *) walk->data;
855 l->src = gst_bin_get_by_name_recurse_up (bin, l->src_name);
857 l->src = strcmp (GST_ELEMENT_NAME (ret), l->src_name) == 0 ? ret : NULL;
861 SET_ERROR (error, GST_PARSE_ERROR_NO_SUCH_ELEMENT, "No element named \"%s\" - omitting link", l->src_name);
862 gst_parse_free_link (l);
869 l->sink = gst_bin_get_by_name_recurse_up (bin, l->sink_name);
871 l->sink = strcmp (GST_ELEMENT_NAME (ret), l->sink_name) == 0 ? ret : NULL;
875 SET_ERROR (error, GST_PARSE_ERROR_NO_SUCH_ELEMENT, "No element named \"%s\" - omitting link", l->sink_name);
876 gst_parse_free_link (l);
880 gst_parse_perform_link (l, &g);
882 g_slist_free (g.links);
885 #ifdef __GST_PARSE_TRACE
886 GST_CAT_DEBUG (GST_CAT_PIPELINE, "TRACE: %u strings, %u chains and %u links left", __strings, __chains, __links);
887 if (__strings || __chains || __links) {
888 g_warning ("TRACE: %u strings, %u chains and %u links left", __strings, __chains, __links);
890 #endif /* __GST_PARSE_TRACE */
898 g_slist_foreach (g.chain->elements, (GFunc)gst_object_unref, NULL);
899 g_slist_free (g.chain->elements);
900 gst_parse_chain_free (g.chain);
903 g_slist_foreach (g.links, (GFunc)gst_parse_free_link, NULL);
904 g_slist_free (g.links);