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); \
142 SET_ERROR (GError **error, gint type, const char *format, ...)
146 g_warning ("error while parsing");
151 va_start (varargs, format);
152 string = g_strdup_vprintf (format, varargs);
155 g_set_error (error, GST_PARSE_ERROR, type, string);
162 #ifndef GST_DISABLE_GST_DEBUG
165 YYPRINTF(const char *format, ...)
170 va_start (varargs, format);
171 temp = g_strdup_vprintf ( format, varargs );
172 GST_CAT_LOG (GST_CAT_PIPELINE, "%s", temp);
180 #define GST_BIN_MAKE(res, type, chainval, assign) G_STMT_START{ \
181 chain_t *chain = chainval; \
183 GstBin *bin = (GstBin *) gst_element_factory_make (type, NULL); \
185 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_EMPTY_BIN, _("specified empty bin \"%s\", not allowed"), type); \
186 g_slist_foreach (assign, (GFunc) gst_parse_strfree, NULL); \
187 g_slist_free (assign); \
190 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT, _("no bin \"%s\", skipping"), type); \
191 g_slist_foreach (assign, (GFunc) gst_parse_strfree, NULL); \
192 g_slist_free (assign); \
195 for (walk = chain->elements; walk; walk = walk->next ) \
196 gst_bin_add (bin, GST_ELEMENT (walk->data)); \
197 g_slist_free (chain->elements); \
198 chain->elements = g_slist_prepend (NULL, bin); \
200 /* set the properties now */ \
201 for (walk = assign; walk; walk = walk->next) \
202 gst_parse_element_set ((gchar *) walk->data, GST_ELEMENT (bin), graph); \
203 g_slist_free (assign); \
207 #define MAKE_LINK(link, _src, _src_name, _src_pads, _sink, _sink_name, _sink_pads) G_STMT_START{ \
208 link = gst_parse_link_new (); \
210 link->sink = _sink; \
211 link->src_name = _src_name; \
212 link->sink_name = _sink_name; \
213 link->src_pads = _src_pads; \
214 link->sink_pads = _sink_pads; \
218 #define MAKE_REF(link, _src, _pads) G_STMT_START{ \
219 gchar *padname = _src; \
220 GSList *pads = _pads; \
222 while (*padname != '.') padname++; \
225 if (*padname != '\0') \
226 pads = g_slist_prepend (pads, gst_parse_strdup (padname)); \
228 MAKE_LINK (link, NULL, _src, pads, NULL, NULL, NULL); \
232 gst_parse_element_set (gchar *value, GstElement *element, graph_t *graph)
238 /* parse the string, so the property name is null-terminated an pos points
239 to the beginning of the value */
240 while (!g_ascii_isspace (*pos) && (*pos != '=')) pos++;
246 while (g_ascii_isspace (*pos)) pos++;
249 while (g_ascii_isspace (*pos)) pos++;
252 pos[strlen (pos) - 1] = '\0';
254 gst_parse_unescape (pos);
255 if ((pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (element), value))) {
256 g_value_init (&v, G_PARAM_SPEC_VALUE_TYPE(pspec));
257 switch (G_TYPE_FUNDAMENTAL (G_PARAM_SPEC_VALUE_TYPE (pspec))) {
259 g_value_set_string (&v, pos);
262 if (g_ascii_strcasecmp (pos, "true") && g_ascii_strcasecmp (pos, "yes") && g_ascii_strcasecmp (pos, "1")) {
263 g_value_set_boolean (&v, FALSE);
265 g_value_set_boolean (&v, TRUE);
270 gchar *endptr = NULL;
271 GEnumClass *klass = (GEnumClass *) g_type_class_peek (G_PARAM_SPEC_VALUE_TYPE (pspec));
272 if (klass == NULL) goto error;
273 if (!(en = g_enum_get_value_by_name (klass, pos))) {
274 if (!(en = g_enum_get_value_by_nick (klass, pos))) {
275 gint i = strtol (pos, &endptr, 0);
276 if (endptr && *endptr == '\0') {
277 en = g_enum_get_value (klass, i);
283 g_value_set_enum (&v, en->value);
291 g_value_init (&v2, G_TYPE_LONG);
292 l = strtol (pos, &endptr, 0);
293 if (*endptr != '\0') goto error_conversion;
294 g_value_set_long (&v2, l);
295 if (!g_value_transform (&v2, &v)) goto error_conversion;
300 case G_TYPE_UINT64: {
303 g_value_init (&v2, G_TYPE_ULONG);
304 ul = strtoul (pos, &endptr, 0);
305 if (*endptr != '\0') goto error_conversion;
306 g_value_set_ulong (&v2, ul);
307 if (!g_value_transform (&v2, &v)) goto error_conversion;
311 case G_TYPE_DOUBLE: {
314 g_value_init (&v2, G_TYPE_DOUBLE);
315 d = g_ascii_strtod (pos, &endptr);
316 if (*endptr != '\0') goto error_conversion;
317 g_value_set_double (&v2, d);
318 if (!g_value_transform (&v2, &v)) goto error_conversion;
323 g_warning ("property \"%s\" in element %s cannot be set", value, GST_ELEMENT_NAME (element));
326 g_object_set_property (G_OBJECT (element), value, &v);
328 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_NO_SUCH_PROPERTY, _("no property \"%s\" in element \"%s\""), value, GST_ELEMENT_NAME (element));
332 gst_parse_strfree (value);
335 if (G_IS_VALUE (&v2))
340 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_COULD_NOT_SET_PROPERTY,
341 _("could not set property \"%s\" in element \"%s\" to \"%s\""),
342 value, GST_ELEMENT_NAME (element), pos);
345 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_COULD_NOT_SET_PROPERTY,
346 _("could not convert \"%s\" so that it fits property \"%s\" in element \"%s\""),
347 pos, value, GST_ELEMENT_NAME (element));
351 gst_parse_free_link (link_t *link)
353 gst_parse_strfree (link->src_name);
354 gst_parse_strfree (link->sink_name);
355 g_slist_foreach (link->src_pads, (GFunc) gst_parse_strfree, NULL);
356 g_slist_foreach (link->sink_pads, (GFunc) gst_parse_strfree, NULL);
357 g_slist_free (link->src_pads);
358 g_slist_free (link->sink_pads);
359 if (link->caps) gst_caps_free (link->caps);
360 gst_parse_link_free (link);
363 gst_parse_element_lock (GstElement *element, gboolean lock)
366 GList *walk = (GList *) gst_element_get_pad_list (element);
367 gboolean unlocked_peer = FALSE;
369 if (gst_element_is_locked_state (element) == lock)
371 /* check if we have an unlocked peer */
372 for (; walk; walk = walk->next) {
373 pad = (GstPad *) GST_PAD_REALIZE (walk->data);
374 if (GST_PAD_IS_SINK (pad) && GST_PAD_PEER (pad) &&
375 !gst_element_is_locked_state (GST_PAD_PARENT (GST_PAD_PEER (pad)))) {
376 unlocked_peer = TRUE;
381 if (!(lock && unlocked_peer)) {
382 GST_CAT_DEBUG (GST_CAT_PIPELINE, "setting locked state on element");
383 gst_element_set_locked_state (element, lock);
386 /* try to sync state with parent */
387 GST_CAT_DEBUG (GST_CAT_PIPELINE, "trying to sync state of element with parent");
388 /* FIXME: it would be nice if we can figure out why it failed
389 (e.g. caps nego) and give an error about that instead. */
390 if (!gst_element_sync_state_with_parent (element))
391 GST_ELEMENT_ERROR (element, CORE, STATE_CHANGE, (NULL), (NULL));
397 /* check if there are other pads to (un)lock */
398 walk = (GList *) gst_element_get_pad_list (element);
399 for (; walk; walk = walk->next) {
400 pad = (GstPad *) GST_PAD_REALIZE (walk->data);
401 if (GST_PAD_IS_SRC (pad) && GST_PAD_PEER (pad)) {
402 GstElement *next = GST_ELEMENT (GST_OBJECT_PARENT (GST_PAD_PEER (pad)));
403 if (gst_element_is_locked_state (next) != lock)
404 gst_parse_element_lock (next, lock);
409 gst_parse_found_pad (GstElement *src, GstPad *pad, gpointer data)
411 DelayedLink *link = (DelayedLink *) data;
413 GST_CAT_INFO (GST_CAT_PIPELINE, "trying delayed linking %s:%s to %s:%s",
414 GST_ELEMENT_NAME (src), link->src_pad,
415 GST_ELEMENT_NAME (link->sink), link->sink_pad);
417 if (gst_element_link_pads_filtered (src, link->src_pad, link->sink, link->sink_pad, link->caps)) {
418 /* do this here, we don't want to get any problems later on when unlocking states */
419 GST_CAT_DEBUG (GST_CAT_PIPELINE, "delayed linking %s:%s to %s:%s worked",
420 GST_ELEMENT_NAME (src), link->src_pad,
421 GST_ELEMENT_NAME (link->sink), link->sink_pad);
422 g_signal_handler_disconnect (src, link->signal_id);
423 g_free (link->src_pad);
424 g_free (link->sink_pad);
425 if (link->caps) gst_caps_free (link->caps);
426 if (!gst_element_is_locked_state (src))
427 gst_parse_element_lock (link->sink, FALSE);
431 /* both padnames and the caps may be NULL */
433 gst_parse_perform_delayed_link (GstElement *src, const gchar *src_pad,
434 GstElement *sink, const gchar *sink_pad, GstCaps *caps)
436 GList *templs = gst_element_get_pad_template_list (src);
438 for (; templs; templs = templs->next) {
439 GstPadTemplate *templ = (GstPadTemplate *) templs->data;
440 if ((GST_PAD_TEMPLATE_DIRECTION (templ) == GST_PAD_SRC) && (GST_PAD_TEMPLATE_PRESENCE(templ) == GST_PAD_SOMETIMES))
442 DelayedLink *data = g_new (DelayedLink, 1);
444 /* TODO: maybe we should check if src_pad matches this template's names */
446 GST_CAT_DEBUG (GST_CAT_PIPELINE, "trying delayed link %s:%s to %s:%s",
447 GST_ELEMENT_NAME (src), src_pad, GST_ELEMENT_NAME (sink), sink_pad);
449 data->src_pad = g_strdup (src_pad);
451 data->sink_pad = g_strdup (sink_pad);
453 data->caps = gst_caps_copy (caps);
457 data->signal_id = g_signal_connect (G_OBJECT (src), "new_pad",
458 G_CALLBACK (gst_parse_found_pad), data);
465 * performs a link and frees the struct. src and sink elements must be given
466 * return values 0 - link performed
471 gst_parse_perform_link (link_t *link, graph_t *graph)
473 GstElement *src = link->src;
474 GstElement *sink = link->sink;
475 GSList *srcs = link->src_pads;
476 GSList *sinks = link->sink_pads;
477 g_assert (GST_IS_ELEMENT (src));
478 g_assert (GST_IS_ELEMENT (sink));
480 GST_CAT_INFO (GST_CAT_PIPELINE, "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),
486 if (!srcs || !sinks) {
487 if (gst_element_link_pads_filtered (src, srcs ? (const gchar *) srcs->data : NULL,
488 sink, sinks ? (const gchar *) sinks->data : NULL,
490 gst_parse_element_lock (sink, gst_element_is_locked_state (src));
493 if (gst_parse_perform_delayed_link (src, srcs ? (const gchar *) srcs->data : NULL,
494 sink, sinks ? (const gchar *) sinks->data : NULL,
496 gst_parse_element_lock (sink, TRUE);
503 if (g_slist_length (link->src_pads) != g_slist_length (link->src_pads)) {
506 while (srcs && sinks) {
507 const gchar *src_pad = (const gchar *) srcs->data;
508 const gchar *sink_pad = (const gchar *) sinks->data;
509 srcs = g_slist_next (srcs);
510 sinks = g_slist_next (sinks);
511 if (gst_element_link_pads_filtered (src, src_pad, sink, sink_pad, link->caps)) {
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, _("could not link %s to %s"), GST_ELEMENT_NAME (src), GST_ELEMENT_NAME (sink));
532 gst_parse_free_link (link);
537 static int yylex (void *lvalp);
538 static int yyerror (const char *s);
551 %token <s> IDENTIFIER
552 %left <s> REF PADREF BINREF
553 %token <s> ASSIGNMENT
559 %type <l> linkpart link
562 %type <p> padlist pads assignments
564 %left '{' '}' '(' ')'
574 element: IDENTIFIER { $$ = gst_element_factory_make ($1, NULL);
576 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT, _("no element \"%s\""), $1);
577 gst_parse_strfree ($1);
581 | element ASSIGNMENT { gst_parse_element_set ($2, $1, graph);
585 assignments: /* NOP */ { $$ = NULL; }
586 | assignments ASSIGNMENT { $$ = g_slist_prepend ($1, $2); }
588 bin: '{' assignments chain '}' { GST_BIN_MAKE ($$, "thread", $3, $2); }
589 | '(' assignments chain ')' { GST_BIN_MAKE ($$, "bin", $3, $2); }
590 | BINREF assignments chain ')' { GST_BIN_MAKE ($$, $1, $3, $2);
591 gst_parse_strfree ($1);
593 | '{' assignments '}' { GST_BIN_MAKE ($$, "thread", NULL, $2); }
594 | '(' assignments '}' { GST_BIN_MAKE ($$, "thread", NULL, $2); }
595 | BINREF assignments ')' { GST_BIN_MAKE ($$, $1, NULL, $2);
596 gst_parse_strfree ($1);
598 | '{' assignments error '}' { GST_BIN_MAKE ($$, "thread", NULL, $2); }
599 | '(' assignments error '}' { GST_BIN_MAKE ($$, "thread", NULL, $2); }
600 | BINREF assignments error ')' { GST_BIN_MAKE ($$, $1, NULL, $2);
601 gst_parse_strfree ($1);
605 pads: PADREF { $$ = g_slist_prepend (NULL, $1); }
606 | PADREF padlist { $$ = $2;
607 $$ = g_slist_prepend ($$, $1);
610 padlist: ',' IDENTIFIER { $$ = g_slist_prepend (NULL, $2); }
611 | ',' IDENTIFIER padlist { $$ = g_slist_prepend ($3, $2); }
614 reference: REF { MAKE_REF ($$, $1, NULL); }
615 | REF padlist { MAKE_REF ($$, $1, $2); }
618 linkpart: reference { $$ = $1; }
619 | pads { MAKE_REF ($$, NULL, $1); }
620 | /* NOP */ { MAKE_REF ($$, NULL, NULL); }
623 link: linkpart LINK linkpart { $$ = $1;
625 $$->caps = gst_caps_from_string ($2);
627 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("could not parse caps \"%s\""), $2);
628 gst_parse_strfree ($2);
630 $$->sink_name = $3->src_name;
631 $$->sink_pads = $3->src_pads;
632 gst_parse_link_free ($3);
636 linklist: link { $$ = g_slist_prepend (NULL, $1); }
637 | link linklist { $$ = g_slist_prepend ($2, $1); }
638 | linklist error { $$ = $1; }
641 chain: element { $$ = gst_parse_chain_new ();
642 $$->first = $$->last = $1;
643 $$->front = $$->back = NULL;
644 $$->elements = g_slist_prepend (NULL, $1);
647 | chain chain { if ($1->back && $2->front) {
648 if (!$1->back->sink_name) {
649 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("link without source element"));
650 gst_parse_free_link ($1->back);
652 ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, $1->back);
654 if (!$2->front->src_name) {
655 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("link without sink element"));
656 gst_parse_free_link ($2->front);
658 ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, $2->front);
661 } else if ($1->back) {
662 if (!$1->back->sink_name) {
663 $1->back->sink = $2->first;
665 } else if ($2->front) {
666 if (!$2->front->src_name) {
667 $2->front->src = $1->last;
669 $1->back = $2->front;
673 if (!$1->back->sink || !$1->back->src) {
674 ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, $1->back);
677 gst_parse_perform_link ($1->back, (graph_t *) graph);
682 $1->elements = g_slist_concat ($1->elements, $2->elements);
684 gst_parse_chain_free ($2);
687 | chain linklist { GSList *walk;
689 $2 = g_slist_prepend ($2, $1->back);
692 if (!((link_t *) $2->data)->src_name) {
693 ((link_t *) $2->data)->src = $1->last;
696 for (walk = $2; walk; walk = walk->next) {
697 link_t *link = (link_t *) walk->data;
698 if (!link->sink_name && walk->next) {
699 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("link without sink element"));
700 gst_parse_free_link (link);
701 } else if (!link->src_name && !link->src) {
702 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("link without source element"));
703 gst_parse_free_link (link);
706 ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, link);
715 | chain error { $$ = $1; }
716 | link chain { if ($2->front) {
717 if (!$2->front->src_name) {
718 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("link without source element"));
719 gst_parse_free_link ($2->front);
721 ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, $2->front);
724 if (!$1->sink_name) {
725 $1->sink = $2->first;
730 | PARSE_URL chain { $$ = $2;
732 GstElement *element =
733 gst_element_make_from_uri (GST_URI_SRC, $1, NULL);
735 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
736 _("no source element for URI \"%s\""), $1);
738 $$->front->src = element;
739 ((graph_t *) graph)->links = g_slist_prepend (
740 ((graph_t *) graph)->links, $$->front);
742 $$->elements = g_slist_prepend ($$->elements, element);
745 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK,
746 _("no element to link URI \"%s\" to"), $1);
750 | link PARSE_URL { GstElement *element =
751 gst_element_make_from_uri (GST_URI_SINK, $2, NULL);
753 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
754 _("no sink element for URI \"%s\""), $2);
756 } else if ($1->sink_name || $1->sink_pads) {
757 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK,
758 _("could not link sink element for URI \"%s\""), $2);
761 $$ = gst_parse_chain_new ();
762 $$->first = $$->last = element;
764 $$->front->sink = element;
765 $$->elements = g_slist_prepend (NULL, element);
770 graph: /* NOP */ { SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_EMPTY, _("empty pipeline not allowed"));
771 $$ = (graph_t *) graph;
773 | chain { $$ = (graph_t *) graph;
775 if (!$1->front->src_name) {
776 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("link without source element"));
777 gst_parse_free_link ($1->front);
779 $$->links = g_slist_prepend ($$->links, $1->front);
784 if (!$1->back->sink_name) {
785 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("link without sink element"));
786 gst_parse_free_link ($1->back);
788 $$->links = g_slist_prepend ($$->links, $1->back);
798 extern FILE *_gst_parse_yyin;
799 int _gst_parse_yylex (YYSTYPE *lvalp);
801 static int yylex (void *lvalp) {
802 return _gst_parse_yylex ((YYSTYPE*) lvalp);
806 yyerror (const char *s)
808 /* FIXME: This should go into the GError somehow, but how? */
809 g_warning ("error: %s", s);
813 struct yy_buffer_state * _gst_parse_yy_scan_string (char*);
814 void _gst_parse_yy_delete_buffer (struct yy_buffer_state *);
816 _gst_parse_launch (const gchar *str, GError **error)
823 struct yy_buffer_state *buf;
825 g_return_val_if_fail (str != NULL, NULL);
831 #ifdef __GST_PARSE_TRACE
832 GST_CAT_DEBUG (GST_CAT_PIPELINE, "TRACE: tracing enabled");
833 __strings = __chains = __links = 0;
834 #endif /* __GST_PARSE_TRACE */
836 dstr = g_strdup (str);
837 buf = _gst_parse_yy_scan_string (dstr);
839 #ifndef GST_DISABLE_GST_DEBUG
843 if (yyparse (&g) != 0) {
844 SET_ERROR (error, GST_PARSE_ERROR_SYNTAX, "Unrecoverable syntax error while parsing pipeline %s", str);
849 _gst_parse_yy_delete_buffer (buf);
851 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));
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, "No element named \"%s\" - omitting link", l->src_name);
888 gst_parse_free_link (l);
895 l->sink = gst_bin_get_by_name_recurse_up (bin, l->sink_name);
897 l->sink = strcmp (GST_ELEMENT_NAME (ret), l->sink_name) == 0 ? ret : NULL;
901 SET_ERROR (error, GST_PARSE_ERROR_NO_SUCH_ELEMENT, "No element named \"%s\" - omitting link", l->sink_name);
902 gst_parse_free_link (l);
906 gst_parse_perform_link (l, &g);
908 g_slist_free (g.links);
911 #ifdef __GST_PARSE_TRACE
912 GST_CAT_DEBUG (GST_CAT_PIPELINE, "TRACE: %u strings, %u chains and %u links left", __strings, __chains, __links);
913 if (__strings || __chains || __links) {
914 g_warning ("TRACE: %u strings, %u chains and %u links left", __strings, __chains, __links);
916 #endif /* __GST_PARSE_TRACE */
924 g_slist_foreach (g.chain->elements, (GFunc)gst_object_unref, NULL);
925 g_slist_free (g.chain->elements);
926 gst_parse_chain_free (g.chain);
929 g_slist_foreach (g.links, (GFunc)gst_parse_free_link, NULL);
930 g_slist_free (g.links);