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); \
139 #elif defined(G_HAVE_ISO_VARARGS)
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
155 SET_ERROR (GError **error, gint type, const char *format, ...)
159 g_warning ("error while parsing");
164 va_start (varargs, format);
165 string = g_strdup_vprintf (format, varargs);
168 g_set_error (error, GST_PARSE_ERROR, type, string);
175 #ifndef GST_DISABLE_GST_DEBUG
178 YYPRINTF(const char *format, ...)
183 va_start (varargs, format);
184 temp = g_strdup_vprintf ( format, varargs );
185 GST_CAT_LOG (GST_CAT_PIPELINE, "%s", temp);
193 #define GST_BIN_MAKE(res, type, chainval, assign) G_STMT_START{ \
194 chain_t *chain = chainval; \
196 GstBin *bin = (GstBin *) gst_element_factory_make (type, NULL); \
198 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_EMPTY_BIN, _("specified empty bin \"%s\", not allowed"), type); \
199 g_slist_foreach (assign, (GFunc) gst_parse_strfree, NULL); \
200 g_slist_free (assign); \
203 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT, _("no bin \"%s\", skipping"), type); \
204 g_slist_foreach (assign, (GFunc) gst_parse_strfree, NULL); \
205 g_slist_free (assign); \
208 for (walk = chain->elements; walk; walk = walk->next ) \
209 gst_bin_add (bin, GST_ELEMENT (walk->data)); \
210 g_slist_free (chain->elements); \
211 chain->elements = g_slist_prepend (NULL, bin); \
213 /* set the properties now */ \
214 for (walk = assign; walk; walk = walk->next) \
215 gst_parse_element_set ((gchar *) walk->data, GST_ELEMENT (bin), graph); \
216 g_slist_free (assign); \
220 #define MAKE_LINK(link, _src, _src_name, _src_pads, _sink, _sink_name, _sink_pads) G_STMT_START{ \
221 link = gst_parse_link_new (); \
223 link->sink = _sink; \
224 link->src_name = _src_name; \
225 link->sink_name = _sink_name; \
226 link->src_pads = _src_pads; \
227 link->sink_pads = _sink_pads; \
231 #define MAKE_REF(link, _src, _pads) G_STMT_START{ \
232 gchar *padname = _src; \
233 GSList *pads = _pads; \
235 while (*padname != '.') padname++; \
238 if (*padname != '\0') \
239 pads = g_slist_prepend (pads, gst_parse_strdup (padname)); \
241 MAKE_LINK (link, NULL, _src, pads, NULL, NULL, NULL); \
245 gst_parse_element_set (gchar *value, GstElement *element, graph_t *graph)
251 /* parse the string, so the property name is null-terminated an pos points
252 to the beginning of the value */
253 while (!g_ascii_isspace (*pos) && (*pos != '=')) pos++;
259 while (g_ascii_isspace (*pos)) pos++;
262 while (g_ascii_isspace (*pos)) pos++;
265 pos[strlen (pos) - 1] = '\0';
267 gst_parse_unescape (pos);
268 if ((pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (element), value))) {
269 g_value_init (&v, G_PARAM_SPEC_VALUE_TYPE(pspec));
270 switch (G_TYPE_FUNDAMENTAL (G_PARAM_SPEC_VALUE_TYPE (pspec))) {
272 g_value_set_string (&v, pos);
275 if (g_ascii_strcasecmp (pos, "true") && g_ascii_strcasecmp (pos, "yes") && g_ascii_strcasecmp (pos, "1")) {
276 g_value_set_boolean (&v, FALSE);
278 g_value_set_boolean (&v, TRUE);
283 gchar *endptr = NULL;
284 GEnumClass *klass = (GEnumClass *) g_type_class_peek (G_PARAM_SPEC_VALUE_TYPE (pspec));
285 if (klass == NULL) goto error;
286 if (!(en = g_enum_get_value_by_name (klass, pos))) {
287 if (!(en = g_enum_get_value_by_nick (klass, pos))) {
288 gint i = strtol (pos, &endptr, 0);
289 if (endptr && *endptr == '\0') {
290 en = g_enum_get_value (klass, i);
296 g_value_set_enum (&v, en->value);
304 g_value_init (&v2, G_TYPE_LONG);
305 l = strtol (pos, &endptr, 0);
306 if (*endptr != '\0') goto error_conversion;
307 g_value_set_long (&v2, l);
308 if (!g_value_transform (&v2, &v)) goto error_conversion;
313 case G_TYPE_UINT64: {
316 g_value_init (&v2, G_TYPE_ULONG);
317 ul = strtoul (pos, &endptr, 0);
318 if (*endptr != '\0') goto error_conversion;
319 g_value_set_ulong (&v2, ul);
320 if (!g_value_transform (&v2, &v)) goto error_conversion;
324 case G_TYPE_DOUBLE: {
327 g_value_init (&v2, G_TYPE_DOUBLE);
328 d = g_ascii_strtod (pos, &endptr);
329 if (*endptr != '\0') goto error_conversion;
330 g_value_set_double (&v2, d);
331 if (!g_value_transform (&v2, &v)) goto error_conversion;
336 g_warning ("property \"%s\" in element %s cannot be set", value, GST_ELEMENT_NAME (element));
339 g_object_set_property (G_OBJECT (element), value, &v);
341 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_NO_SUCH_PROPERTY, _("no property \"%s\" in element \"%s\""), value, GST_ELEMENT_NAME (element));
345 gst_parse_strfree (value);
348 if (G_IS_VALUE (&v2))
353 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_COULD_NOT_SET_PROPERTY,
354 _("could not set property \"%s\" in element \"%s\" to \"%s\""),
355 value, GST_ELEMENT_NAME (element), pos);
358 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_COULD_NOT_SET_PROPERTY,
359 _("could not convert \"%s\" so that it fits property \"%s\" in element \"%s\""),
360 pos, value, GST_ELEMENT_NAME (element));
364 gst_parse_free_link (link_t *link)
366 gst_parse_strfree (link->src_name);
367 gst_parse_strfree (link->sink_name);
368 g_slist_foreach (link->src_pads, (GFunc) gst_parse_strfree, NULL);
369 g_slist_foreach (link->sink_pads, (GFunc) gst_parse_strfree, NULL);
370 g_slist_free (link->src_pads);
371 g_slist_free (link->sink_pads);
372 if (link->caps) gst_caps_free (link->caps);
373 gst_parse_link_free (link);
376 gst_parse_element_lock (GstElement *element, gboolean lock)
379 GList *walk = (GList *) gst_element_get_pad_list (element);
380 gboolean unlocked_peer = FALSE;
382 if (gst_element_is_locked_state (element) == lock)
384 /* check if we have an unlocked peer */
385 for (; walk; walk = walk->next) {
386 pad = (GstPad *) GST_PAD_REALIZE (walk->data);
387 if (GST_PAD_IS_SINK (pad) && GST_PAD_PEER (pad) &&
388 !gst_element_is_locked_state (GST_PAD_PARENT (GST_PAD_PEER (pad)))) {
389 unlocked_peer = TRUE;
394 if (!(lock && unlocked_peer)) {
395 GST_CAT_DEBUG (GST_CAT_PIPELINE, "setting locked state on element");
396 gst_element_set_locked_state (element, lock);
399 /* try to sync state with parent */
400 GST_CAT_DEBUG (GST_CAT_PIPELINE, "trying to sync state of element with parent");
401 /* FIXME: it would be nice if we can figure out why it failed
402 (e.g. caps nego) and give an error about that instead. */
403 if (!gst_element_sync_state_with_parent (element))
404 GST_ELEMENT_ERROR (element, CORE, STATE_CHANGE, (NULL), (NULL));
410 /* check if there are other pads to (un)lock */
411 walk = (GList *) gst_element_get_pad_list (element);
412 for (; walk; walk = walk->next) {
413 pad = (GstPad *) GST_PAD_REALIZE (walk->data);
414 if (GST_PAD_IS_SRC (pad) && GST_PAD_PEER (pad)) {
415 GstElement *next = GST_ELEMENT (GST_OBJECT_PARENT (GST_PAD_PEER (pad)));
416 if (gst_element_is_locked_state (next) != lock)
417 gst_parse_element_lock (next, lock);
422 gst_parse_found_pad (GstElement *src, GstPad *pad, gpointer data)
424 DelayedLink *link = (DelayedLink *) data;
426 GST_CAT_INFO (GST_CAT_PIPELINE, "trying delayed linking %s:%s to %s:%s",
427 GST_ELEMENT_NAME (src), link->src_pad,
428 GST_ELEMENT_NAME (link->sink), link->sink_pad);
430 if (gst_element_link_pads_filtered (src, link->src_pad, link->sink, link->sink_pad, link->caps)) {
431 /* do this here, we don't want to get any problems later on when unlocking states */
432 GST_CAT_DEBUG (GST_CAT_PIPELINE, "delayed linking %s:%s to %s:%s worked",
433 GST_ELEMENT_NAME (src), link->src_pad,
434 GST_ELEMENT_NAME (link->sink), link->sink_pad);
435 g_signal_handler_disconnect (src, link->signal_id);
436 g_free (link->src_pad);
437 g_free (link->sink_pad);
438 if (link->caps) gst_caps_free (link->caps);
439 if (!gst_element_is_locked_state (src))
440 gst_parse_element_lock (link->sink, FALSE);
444 /* both padnames and the caps may be NULL */
446 gst_parse_perform_delayed_link (GstElement *src, const gchar *src_pad,
447 GstElement *sink, const gchar *sink_pad, GstCaps *caps)
449 GList *templs = gst_element_get_pad_template_list (src);
451 for (; templs; templs = templs->next) {
452 GstPadTemplate *templ = (GstPadTemplate *) templs->data;
453 if ((GST_PAD_TEMPLATE_DIRECTION (templ) == GST_PAD_SRC) && (GST_PAD_TEMPLATE_PRESENCE(templ) == GST_PAD_SOMETIMES))
455 DelayedLink *data = g_new (DelayedLink, 1);
457 /* TODO: maybe we should check if src_pad matches this template's names */
459 GST_CAT_DEBUG (GST_CAT_PIPELINE, "trying delayed link %s:%s to %s:%s",
460 GST_ELEMENT_NAME (src), src_pad, GST_ELEMENT_NAME (sink), sink_pad);
462 data->src_pad = g_strdup (src_pad);
464 data->sink_pad = g_strdup (sink_pad);
466 data->caps = gst_caps_copy (caps);
470 data->signal_id = g_signal_connect (G_OBJECT (src), "new_pad",
471 G_CALLBACK (gst_parse_found_pad), data);
478 * performs a link and frees the struct. src and sink elements must be given
479 * return values 0 - link performed
484 gst_parse_perform_link (link_t *link, graph_t *graph)
486 GstElement *src = link->src;
487 GstElement *sink = link->sink;
488 GSList *srcs = link->src_pads;
489 GSList *sinks = link->sink_pads;
490 g_assert (GST_IS_ELEMENT (src));
491 g_assert (GST_IS_ELEMENT (sink));
493 GST_CAT_INFO (GST_CAT_PIPELINE, "linking %s:%s to %s:%s (%u/%u) with caps \"%" GST_PTR_FORMAT "\"",
494 GST_ELEMENT_NAME (src), link->src_name ? link->src_name : "(any)",
495 GST_ELEMENT_NAME (sink), link->sink_name ? link->sink_name : "(any)",
496 g_slist_length (srcs), g_slist_length (sinks),
499 if (!srcs || !sinks) {
500 if (gst_element_link_pads_filtered (src, srcs ? (const gchar *) srcs->data : NULL,
501 sink, sinks ? (const gchar *) sinks->data : NULL,
503 gst_parse_element_lock (sink, gst_element_is_locked_state (src));
506 if (gst_parse_perform_delayed_link (src, srcs ? (const gchar *) srcs->data : NULL,
507 sink, sinks ? (const gchar *) sinks->data : NULL,
509 gst_parse_element_lock (sink, TRUE);
516 if (g_slist_length (link->src_pads) != g_slist_length (link->src_pads)) {
519 while (srcs && sinks) {
520 const gchar *src_pad = (const gchar *) srcs->data;
521 const gchar *sink_pad = (const gchar *) sinks->data;
522 srcs = g_slist_next (srcs);
523 sinks = g_slist_next (sinks);
524 if (gst_element_link_pads_filtered (src, src_pad, sink, sink_pad, link->caps)) {
525 gst_parse_element_lock (sink, gst_element_is_locked_state (src));
528 if (gst_parse_perform_delayed_link (src, src_pad,
531 gst_parse_element_lock (sink, TRUE);
540 gst_parse_free_link (link);
544 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("could not link %s to %s"), GST_ELEMENT_NAME (src), GST_ELEMENT_NAME (sink));
545 gst_parse_free_link (link);
550 static int yylex (void *lvalp);
551 static int yyerror (const char *s);
564 %token <s> IDENTIFIER
565 %left <s> REF PADREF BINREF
566 %token <s> ASSIGNMENT
572 %type <l> linkpart link
575 %type <p> padlist pads assignments
577 %left '{' '}' '(' ')'
587 element: IDENTIFIER { $$ = gst_element_factory_make ($1, NULL);
589 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT, _("no element \"%s\""), $1);
590 gst_parse_strfree ($1);
594 | element ASSIGNMENT { gst_parse_element_set ($2, $1, graph);
598 assignments: /* NOP */ { $$ = NULL; }
599 | assignments ASSIGNMENT { $$ = g_slist_prepend ($1, $2); }
601 bin: '{' assignments chain '}' { GST_BIN_MAKE ($$, "thread", $3, $2); }
602 | '(' assignments chain ')' { GST_BIN_MAKE ($$, "bin", $3, $2); }
603 | BINREF assignments chain ')' { GST_BIN_MAKE ($$, $1, $3, $2);
604 gst_parse_strfree ($1);
606 | '{' assignments '}' { GST_BIN_MAKE ($$, "thread", NULL, $2); }
607 | '(' assignments '}' { GST_BIN_MAKE ($$, "thread", NULL, $2); }
608 | BINREF assignments ')' { GST_BIN_MAKE ($$, $1, NULL, $2);
609 gst_parse_strfree ($1);
611 | '{' assignments error '}' { GST_BIN_MAKE ($$, "thread", NULL, $2); }
612 | '(' assignments error '}' { GST_BIN_MAKE ($$, "thread", NULL, $2); }
613 | BINREF assignments error ')' { GST_BIN_MAKE ($$, $1, NULL, $2);
614 gst_parse_strfree ($1);
618 pads: PADREF { $$ = g_slist_prepend (NULL, $1); }
619 | PADREF padlist { $$ = $2;
620 $$ = g_slist_prepend ($$, $1);
623 padlist: ',' IDENTIFIER { $$ = g_slist_prepend (NULL, $2); }
624 | ',' IDENTIFIER padlist { $$ = g_slist_prepend ($3, $2); }
627 reference: REF { MAKE_REF ($$, $1, NULL); }
628 | REF padlist { MAKE_REF ($$, $1, $2); }
631 linkpart: reference { $$ = $1; }
632 | pads { MAKE_REF ($$, NULL, $1); }
633 | /* NOP */ { MAKE_REF ($$, NULL, NULL); }
636 link: linkpart LINK linkpart { $$ = $1;
638 $$->caps = gst_caps_from_string ($2);
640 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("could not parse caps \"%s\""), $2);
641 gst_parse_strfree ($2);
643 $$->sink_name = $3->src_name;
644 $$->sink_pads = $3->src_pads;
645 gst_parse_link_free ($3);
649 linklist: link { $$ = g_slist_prepend (NULL, $1); }
650 | link linklist { $$ = g_slist_prepend ($2, $1); }
651 | linklist error { $$ = $1; }
654 chain: element { $$ = gst_parse_chain_new ();
655 $$->first = $$->last = $1;
656 $$->front = $$->back = NULL;
657 $$->elements = g_slist_prepend (NULL, $1);
660 | chain chain { if ($1->back && $2->front) {
661 if (!$1->back->sink_name) {
662 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("link without source element"));
663 gst_parse_free_link ($1->back);
665 ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, $1->back);
667 if (!$2->front->src_name) {
668 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("link without sink element"));
669 gst_parse_free_link ($2->front);
671 ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, $2->front);
674 } else if ($1->back) {
675 if (!$1->back->sink_name) {
676 $1->back->sink = $2->first;
678 } else if ($2->front) {
679 if (!$2->front->src_name) {
680 $2->front->src = $1->last;
682 $1->back = $2->front;
686 if (!$1->back->sink || !$1->back->src) {
687 ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, $1->back);
690 gst_parse_perform_link ($1->back, (graph_t *) graph);
695 $1->elements = g_slist_concat ($1->elements, $2->elements);
697 gst_parse_chain_free ($2);
700 | chain linklist { GSList *walk;
702 $2 = g_slist_prepend ($2, $1->back);
705 if (!((link_t *) $2->data)->src_name) {
706 ((link_t *) $2->data)->src = $1->last;
709 for (walk = $2; walk; walk = walk->next) {
710 link_t *link = (link_t *) walk->data;
711 if (!link->sink_name && walk->next) {
712 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("link without sink element"));
713 gst_parse_free_link (link);
714 } else if (!link->src_name && !link->src) {
715 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("link without source element"));
716 gst_parse_free_link (link);
719 ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, link);
728 | chain error { $$ = $1; }
729 | link chain { if ($2->front) {
730 if (!$2->front->src_name) {
731 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("link without source element"));
732 gst_parse_free_link ($2->front);
734 ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, $2->front);
737 if (!$1->sink_name) {
738 $1->sink = $2->first;
743 | PARSE_URL chain { $$ = $2;
745 GstElement *element =
746 gst_element_make_from_uri (GST_URI_SRC, $1, NULL);
748 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
749 _("no source element for URI \"%s\""), $1);
751 $$->front->src = element;
752 ((graph_t *) graph)->links = g_slist_prepend (
753 ((graph_t *) graph)->links, $$->front);
755 $$->elements = g_slist_prepend ($$->elements, element);
758 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK,
759 _("no element to link URI \"%s\" to"), $1);
763 | link PARSE_URL { GstElement *element =
764 gst_element_make_from_uri (GST_URI_SINK, $2, NULL);
766 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
767 _("no sink element for URI \"%s\""), $2);
769 } else if ($1->sink_name || $1->sink_pads) {
770 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK,
771 _("could not link sink element for URI \"%s\""), $2);
774 $$ = gst_parse_chain_new ();
775 $$->first = $$->last = element;
777 $$->front->sink = element;
778 $$->elements = g_slist_prepend (NULL, element);
783 graph: /* NOP */ { SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_EMPTY, _("empty pipeline not allowed"));
784 $$ = (graph_t *) graph;
786 | chain { $$ = (graph_t *) graph;
788 if (!$1->front->src_name) {
789 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("link without source element"));
790 gst_parse_free_link ($1->front);
792 $$->links = g_slist_prepend ($$->links, $1->front);
797 if (!$1->back->sink_name) {
798 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("link without sink element"));
799 gst_parse_free_link ($1->back);
801 $$->links = g_slist_prepend ($$->links, $1->back);
811 extern FILE *_gst_parse_yyin;
812 int _gst_parse_yylex (YYSTYPE *lvalp);
814 static int yylex (void *lvalp) {
815 return _gst_parse_yylex ((YYSTYPE*) lvalp);
819 yyerror (const char *s)
821 /* FIXME: This should go into the GError somehow, but how? */
822 g_warning ("error: %s", s);
826 struct yy_buffer_state * _gst_parse_yy_scan_string (char*);
827 void _gst_parse_yy_delete_buffer (struct yy_buffer_state *);
829 _gst_parse_launch (const gchar *str, GError **error)
836 struct yy_buffer_state *buf;
838 g_return_val_if_fail (str != NULL, NULL);
844 #ifdef __GST_PARSE_TRACE
845 GST_CAT_DEBUG (GST_CAT_PIPELINE, "TRACE: tracing enabled");
846 __strings = __chains = __links = 0;
847 #endif /* __GST_PARSE_TRACE */
849 dstr = g_strdup (str);
850 buf = _gst_parse_yy_scan_string (dstr);
852 #ifndef GST_DISABLE_GST_DEBUG
856 if (yyparse (&g) != 0) {
857 SET_ERROR (error, GST_PARSE_ERROR_SYNTAX, "Unrecoverable syntax error while parsing pipeline %s", str);
862 _gst_parse_yy_delete_buffer (buf);
864 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));
868 } else if (!(((chain_t *) g.chain)->elements->next)) {
869 /* only one toplevel element */
870 ret = (GstElement *) ((chain_t *) g.chain)->elements->data;
871 g_slist_free (((chain_t *) g.chain)->elements);
872 if (GST_IS_BIN (ret))
874 gst_parse_chain_free (g.chain);
876 /* put all elements in our bin */
877 bin = GST_BIN (gst_element_factory_make ("pipeline", NULL));
880 for (walk = g.chain->elements; walk; walk = walk->next)
881 gst_bin_add (bin, GST_ELEMENT (walk->data));
883 g_slist_free (g.chain->elements);
884 ret = GST_ELEMENT (bin);
885 gst_parse_chain_free (g.chain);
889 for (walk = g.links; walk; walk = walk->next) {
890 link_t *l = (link_t *) walk->data;
894 l->src = gst_bin_get_by_name_recurse_up (bin, l->src_name);
896 l->src = strcmp (GST_ELEMENT_NAME (ret), l->src_name) == 0 ? ret : NULL;
900 SET_ERROR (error, GST_PARSE_ERROR_NO_SUCH_ELEMENT, "No element named \"%s\" - omitting link", l->src_name);
901 gst_parse_free_link (l);
908 l->sink = gst_bin_get_by_name_recurse_up (bin, l->sink_name);
910 l->sink = strcmp (GST_ELEMENT_NAME (ret), l->sink_name) == 0 ? ret : NULL;
914 SET_ERROR (error, GST_PARSE_ERROR_NO_SUCH_ELEMENT, "No element named \"%s\" - omitting link", l->sink_name);
915 gst_parse_free_link (l);
919 gst_parse_perform_link (l, &g);
921 g_slist_free (g.links);
924 #ifdef __GST_PARSE_TRACE
925 GST_CAT_DEBUG (GST_CAT_PIPELINE, "TRACE: %u strings, %u chains and %u links left", __strings, __chains, __links);
926 if (__strings || __chains || __links) {
927 g_warning ("TRACE: %u strings, %u chains and %u links left", __strings, __chains, __links);
929 #endif /* __GST_PARSE_TRACE */
937 g_slist_foreach (g.chain->elements, (GFunc)gst_object_unref, NULL);
938 g_slist_free (g.chain->elements);
939 gst_parse_chain_free (g.chain);
942 g_slist_foreach (g.links, (GFunc)gst_parse_free_link, NULL);
943 g_slist_free (g.links);