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 "../gststructure.h"
16 #include "../gsturi.h"
17 #include "../gstutils.h"
18 #include "../gstvalue.h"
19 #include "../gstchildproxy.h"
22 /* All error messages in this file are user-visible and need to be translated.
23 * Don't start the message with a capital, and don't end them with a period,
24 * as they will be presented inside a sentence/error.
27 #define YYERROR_VERBOSE 1
28 #define YYLEX_PARAM scanner
30 typedef void* yyscan_t;
32 int _gst_parse_yylex (void * yylval_param , yyscan_t yyscanner);
33 int _gst_parse_yylex_init (yyscan_t scanner);
34 int _gst_parse_yylex_destroy (yyscan_t scanner);
35 struct yy_buffer_state * _gst_parse_yy_scan_string (char* , yyscan_t);
36 void _gst_parse_yypush_buffer_state (void * new_buffer ,yyscan_t yyscanner );
37 void _gst_parse_yypop_buffer_state (yyscan_t yyscanner );
40 #ifdef __GST_PARSE_TRACE
41 static guint __strings;
43 static guint __chains;
45 __gst_parse_strdup (gchar *org)
50 /* g_print ("ALLOCATED STR (%3u): %p %s\n", __strings, ret, ret); */
54 __gst_parse_strfree (gchar *str)
57 /* g_print ("FREEING STR (%3u): %p %s\n", __strings - 1, str, str); */
59 g_return_if_fail (__strings > 0);
63 link_t *__gst_parse_link_new ()
67 ret = g_slice_new0 (link_t);
68 /* g_print ("ALLOCATED LINK (%3u): %p\n", __links, ret); */
72 __gst_parse_link_free (link_t *data)
75 /* g_print ("FREEING LINK (%3u): %p\n", __links - 1, data); */
76 g_slice_free (link_t, data);
77 g_return_if_fail (__links > 0);
82 __gst_parse_chain_new ()
86 ret = g_slice_new0 (chain_t);
87 /* g_print ("ALLOCATED CHAIN (%3u): %p\n", __chains, ret); */
91 __gst_parse_chain_free (chain_t *data)
93 /* g_print ("FREEING CHAIN (%3u): %p\n", __chains - 1, data); */
94 g_slice_free (chain_t, data);
95 g_return_if_fail (__chains > 0);
99 #endif /* __GST_PARSE_TRACE */
116 /*** define SET_ERROR and ERROR macros/functions */
118 #ifdef G_HAVE_ISO_VARARGS
120 # define SET_ERROR(error, type, ...) \
122 GST_CAT_ERROR (GST_CAT_PIPELINE, __VA_ARGS__); \
123 if ((error) && !*(error)) { \
124 g_set_error ((error), GST_PARSE_ERROR, (type), __VA_ARGS__); \
128 # define ERROR(type, ...) \
129 SET_ERROR (graph->error, (type), __VA_ARGS__ )
131 #elif defined(G_HAVE_GNUC_VARARGS)
133 # define SET_ERROR(error, type, args...) \
135 GST_CAT_ERROR (GST_CAT_PIPELINE, args ); \
136 if ((error) && !*(error)) { \
137 g_set_error ((error), GST_PARSE_ERROR, (type), args ); \
141 # define ERROR(type, args...) \
142 SET_ERROR (graph->error,(type) , args )
147 SET_ERROR (GError **error, gint type, const char *format, ...)
151 g_warning ("error while parsing");
156 va_start (varargs, format);
157 string = g_strdup_vprintf (format, varargs);
160 g_set_error (error, GST_PARSE_ERROR, type, string);
167 #endif /* G_HAVE_ISO_VARARGS */
169 /*** define YYPRINTF macro/function if we're debugging */
171 /* bison 1.35 calls this macro with side effects, we need to make sure the
172 side effects work - crappy bison */
174 #ifndef GST_DISABLE_GST_DEBUG
177 # ifdef G_HAVE_ISO_VARARGS
179 /* # define YYFPRINTF(a, ...) GST_CAT_DEBUG (GST_CAT_PIPELINE, __VA_ARGS__) */
180 # define YYFPRINTF(a, ...) \
182 GST_CAT_LOG (GST_CAT_PIPELINE, __VA_ARGS__); \
185 # elif defined(G_HAVE_GNUC_VARARGS)
187 # define YYFPRINTF(a, args...) \
189 GST_CAT_LOG (GST_CAT_PIPELINE, args); \
195 YYPRINTF(const char *format, ...)
200 va_start (varargs, format);
201 temp = g_strdup_vprintf (format, varargs);
202 GST_CAT_LOG (GST_CAT_PIPELINE, "%s", temp);
207 # endif /* G_HAVE_ISO_VARARGS */
209 #endif /* GST_DISABLE_GST_DEBUG */
211 #define ADD_MISSING_ELEMENT(graph,name) G_STMT_START { \
212 if ((graph)->ctx) { \
213 (graph)->ctx->missing_elements = \
214 g_list_append ((graph)->ctx->missing_elements, g_strdup (name)); \
217 #define GST_BIN_MAKE(res, type, chainval, assign, free_string) \
219 chain_t *chain = chainval; \
221 GstBin *bin = (GstBin *) gst_element_factory_make (type, NULL); \
223 SET_ERROR (graph->error, GST_PARSE_ERROR_EMPTY_BIN, \
224 _("specified empty bin \"%s\", not allowed"), type); \
225 g_slist_foreach (assign, (GFunc) gst_parse_strfree, NULL); \
226 g_slist_free (assign); \
227 gst_object_unref (bin); \
229 gst_parse_strfree (type); /* Need to clean up the string */ \
232 ADD_MISSING_ELEMENT(graph, type); \
233 SET_ERROR (graph->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT, \
234 _("no bin \"%s\", skipping"), type); \
235 g_slist_foreach (assign, (GFunc) gst_parse_strfree, NULL); \
236 g_slist_free (assign); \
239 for (walk = chain->elements; walk; walk = walk->next ) \
240 gst_bin_add (bin, GST_ELEMENT (walk->data)); \
241 g_slist_free (chain->elements); \
242 chain->elements = g_slist_prepend (NULL, bin); \
244 /* set the properties now */ \
245 for (walk = assign; walk; walk = walk->next) \
246 gst_parse_element_set ((gchar *) walk->data, GST_ELEMENT (bin), graph); \
247 g_slist_free (assign); \
251 #define MAKE_LINK(link, _src, _src_name, _src_pads, _sink, _sink_name, _sink_pads) \
253 link = gst_parse_link_new (); \
255 link->sink = _sink; \
256 link->src_name = _src_name; \
257 link->sink_name = _sink_name; \
258 link->src_pads = _src_pads; \
259 link->sink_pads = _sink_pads; \
263 #define MAKE_REF(link, _src, _pads) \
265 gchar *padname = _src; \
266 GSList *pads = _pads; \
268 while (*padname != '.') padname++; \
271 if (*padname != '\0') \
272 pads = g_slist_prepend (pads, gst_parse_strdup (padname)); \
274 MAKE_LINK (link, NULL, _src, pads, NULL, NULL, NULL); \
277 static void gst_parse_new_child(GstChildProxy *child_proxy, GObject *object,
280 DelayedSet *set = (DelayedSet *) data;
283 GstObject *target = NULL;
286 if (gst_child_proxy_lookup (GST_OBJECT (set->parent), set->name, &target, &pspec)) {
287 gboolean got_value = FALSE;
289 value_type = G_PARAM_SPEC_VALUE_TYPE (pspec);
291 GST_CAT_LOG (GST_CAT_PIPELINE, "parsing delayed property %s as a %s from %s", pspec->name,
292 g_type_name (value_type), set->value_str);
293 g_value_init (&v, value_type);
294 if (gst_value_deserialize (&v, set->value_str))
296 else if (g_type_is_a (value_type, GST_TYPE_ELEMENT)) {
299 bin = gst_parse_bin_from_description (set->value_str, TRUE, NULL);
301 g_value_set_object (&v, bin);
305 g_signal_handler_disconnect (child_proxy, set->signal_id);
307 g_free(set->value_str);
308 g_slice_free(DelayedSet, set);
311 g_object_set_property (G_OBJECT (target), pspec->name, &v);
318 gst_object_unref (target);
322 GST_CAT_ERROR (GST_CAT_PIPELINE, "could not set property \"%s\" in element \"%s\"",
323 pspec->name, GST_ELEMENT_NAME (target));
329 gst_parse_element_set (gchar *value, GstElement *element, graph_t *graph)
334 GstObject *target = NULL;
337 /* do nothing if assignment is for missing element */
341 /* parse the string, so the property name is null-terminated an pos points
342 to the beginning of the value */
343 while (!g_ascii_isspace (*pos) && (*pos != '=')) pos++;
349 while (g_ascii_isspace (*pos)) pos++;
352 while (g_ascii_isspace (*pos)) pos++;
355 pos[strlen (pos) - 1] = '\0';
357 gst_parse_unescape (pos);
359 if (gst_child_proxy_lookup (GST_OBJECT (element), value, &target, &pspec)) {
360 gboolean got_value = FALSE;
362 value_type = G_PARAM_SPEC_VALUE_TYPE (pspec);
364 GST_CAT_LOG (GST_CAT_PIPELINE, "parsing property %s as a %s", pspec->name,
365 g_type_name (value_type));
366 g_value_init (&v, value_type);
367 if (gst_value_deserialize (&v, pos))
369 else if (g_type_is_a (value_type, GST_TYPE_ELEMENT)) {
372 bin = gst_parse_bin_from_description (pos, TRUE, NULL);
374 g_value_set_object (&v, bin);
380 g_object_set_property (G_OBJECT (target), pspec->name, &v);
382 /* do a delayed set */
383 if (GST_IS_CHILD_PROXY (element)) {
384 DelayedSet *data = g_slice_new0 (DelayedSet);
386 data->parent = element;
387 data->name = g_strdup(value);
388 data->value_str = g_strdup(pos);
389 data->signal_id = g_signal_connect(element, "child-added", G_CALLBACK (gst_parse_new_child), data);
392 SET_ERROR (graph->error, GST_PARSE_ERROR_NO_SUCH_PROPERTY, \
393 _("no property \"%s\" in element \"%s\""), value, \
394 GST_ELEMENT_NAME (element));
399 gst_parse_strfree (value);
403 gst_object_unref (target);
407 SET_ERROR (graph->error, GST_PARSE_ERROR_COULD_NOT_SET_PROPERTY,
408 _("could not set property \"%s\" in element \"%s\" to \"%s\""),
409 value, GST_ELEMENT_NAME (element), pos);
413 gst_parse_free_link (link_t *link)
415 gst_parse_strfree (link->src_name);
416 gst_parse_strfree (link->sink_name);
417 g_slist_foreach (link->src_pads, (GFunc) gst_parse_strfree, NULL);
418 g_slist_foreach (link->sink_pads, (GFunc) gst_parse_strfree, NULL);
419 g_slist_free (link->src_pads);
420 g_slist_free (link->sink_pads);
421 if (link->caps) gst_caps_unref (link->caps);
422 gst_parse_link_free (link);
426 gst_parse_free_delayed_link (DelayedLink *link)
428 g_free (link->src_pad);
429 g_free (link->sink_pad);
430 if (link->caps) gst_caps_unref (link->caps);
431 g_slice_free (DelayedLink, link);
435 gst_parse_found_pad (GstElement *src, GstPad *pad, gpointer data)
437 DelayedLink *link = g_object_get_qdata (G_OBJECT (src),
438 g_quark_from_static_string ("GstParseDelayedLink"));
440 GST_CAT_INFO (GST_CAT_PIPELINE, "trying delayed linking %s:%s to %s:%s",
441 GST_STR_NULL (GST_ELEMENT_NAME (src)), GST_STR_NULL (link->src_pad),
442 GST_STR_NULL (GST_ELEMENT_NAME (link->sink)), GST_STR_NULL (link->sink_pad));
444 g_return_if_fail (link != NULL);
446 if (gst_element_link_pads_filtered (src, link->src_pad, link->sink,
447 link->sink_pad, link->caps)) {
448 /* do this here, we don't want to get any problems later on when
449 * unlocking states */
450 GST_CAT_DEBUG (GST_CAT_PIPELINE, "delayed linking %s:%s to %s:%s worked",
451 GST_STR_NULL (GST_ELEMENT_NAME (src)), GST_STR_NULL (link->src_pad),
452 GST_STR_NULL (GST_ELEMENT_NAME (link->sink)), GST_STR_NULL (link->sink_pad));
453 g_signal_handler_disconnect (src, link->signal_id);
454 g_object_set_qdata (G_OBJECT (src),
455 g_quark_from_static_string ("GstParseDelayedLink"), NULL);
458 /* both padnames and the caps may be NULL */
460 gst_parse_perform_delayed_link (GstElement *src, const gchar *src_pad,
461 GstElement *sink, const gchar *sink_pad,
464 GList *templs = gst_element_class_get_pad_template_list (
465 GST_ELEMENT_GET_CLASS (src));
467 for (; templs; templs = templs->next) {
468 GstPadTemplate *templ = (GstPadTemplate *) templs->data;
469 if ((GST_PAD_TEMPLATE_DIRECTION (templ) == GST_PAD_SRC) &&
470 (GST_PAD_TEMPLATE_PRESENCE(templ) == GST_PAD_SOMETIMES))
472 DelayedLink *data = g_slice_new (DelayedLink);
474 /* TODO: maybe we should check if src_pad matches this template's names */
476 GST_CAT_DEBUG (GST_CAT_PIPELINE, "trying delayed link %s:%s to %s:%s",
477 GST_STR_NULL (GST_ELEMENT_NAME (src)), GST_STR_NULL (src_pad),
478 GST_STR_NULL (GST_ELEMENT_NAME (sink)), GST_STR_NULL (sink_pad));
480 data->src_pad = g_strdup (src_pad);
482 data->sink_pad = g_strdup (sink_pad);
484 data->caps = gst_caps_copy (caps);
488 g_object_set_qdata_full (G_OBJECT (src),
489 g_quark_from_static_string ("GstParseDelayedLink"), data,
490 (GDestroyNotify)gst_parse_free_delayed_link);
491 data->signal_id = g_signal_connect (src, "pad-added",
492 G_CALLBACK (gst_parse_found_pad), NULL);
499 * performs a link and frees the struct. src and sink elements must be given
500 * return values 0 - link performed
505 gst_parse_perform_link (link_t *link, graph_t *graph)
507 GstElement *src = link->src;
508 GstElement *sink = link->sink;
509 GSList *srcs = link->src_pads;
510 GSList *sinks = link->sink_pads;
511 g_assert (GST_IS_ELEMENT (src));
512 g_assert (GST_IS_ELEMENT (sink));
514 GST_CAT_INFO (GST_CAT_PIPELINE,
515 "linking %s:%s to %s:%s (%u/%u) with caps \"%" GST_PTR_FORMAT "\"",
516 GST_ELEMENT_NAME (src), link->src_name ? link->src_name : "(any)",
517 GST_ELEMENT_NAME (sink), link->sink_name ? link->sink_name : "(any)",
518 g_slist_length (srcs), g_slist_length (sinks), link->caps);
520 if (!srcs || !sinks) {
521 if (gst_element_link_pads_filtered (src,
522 srcs ? (const gchar *) srcs->data : NULL, sink,
523 sinks ? (const gchar *) sinks->data : NULL, link->caps)) {
526 if (gst_parse_perform_delayed_link (src,
527 srcs ? (const gchar *) srcs->data : NULL,
528 sink, sinks ? (const gchar *) sinks->data : NULL, link->caps)) {
535 if (g_slist_length (link->src_pads) != g_slist_length (link->src_pads)) {
538 while (srcs && sinks) {
539 const gchar *src_pad = (const gchar *) srcs->data;
540 const gchar *sink_pad = (const gchar *) sinks->data;
541 srcs = g_slist_next (srcs);
542 sinks = g_slist_next (sinks);
543 if (gst_element_link_pads_filtered (src, src_pad, sink, sink_pad,
547 if (gst_parse_perform_delayed_link (src, src_pad,
558 gst_parse_free_link (link);
562 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK,
563 _("could not link %s to %s"), GST_ELEMENT_NAME (src),
564 GST_ELEMENT_NAME (sink));
565 gst_parse_free_link (link);
570 static int yyerror (void *scanner, graph_t *graph, const char *s);
583 %token <s> IDENTIFIER
584 %left <s> REF PADREF BINREF
585 %token <s> ASSIGNMENT
591 %type <l> linkpart link
594 %type <p> padlist pads assignments
601 %parse-param { void *scanner }
602 %parse-param { graph_t *graph }
608 element: IDENTIFIER { $$ = gst_element_factory_make ($1, NULL);
610 ADD_MISSING_ELEMENT (graph, $1);
611 SET_ERROR (graph->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT, _("no element \"%s\""), $1);
612 /* if FATAL_ERRORS flag is set, we don't have to worry about backwards
613 * compatibility and can continue parsing and check for other missing
615 if ((graph->flags & GST_PARSE_FLAG_FATAL_ERRORS) == 0) {
616 gst_parse_strfree ($1);
620 gst_parse_strfree ($1);
622 | element ASSIGNMENT { gst_parse_element_set ($2, $1, graph);
626 assignments: /* NOP */ { $$ = NULL; }
627 | assignments ASSIGNMENT { $$ = g_slist_prepend ($1, $2); }
629 bin: '(' assignments chain ')' { GST_BIN_MAKE ($$, "bin", $3, $2, FALSE); }
630 | BINREF assignments chain ')' { GST_BIN_MAKE ($$, $1, $3, $2, TRUE);
631 gst_parse_strfree ($1);
633 | BINREF assignments ')' { GST_BIN_MAKE ($$, $1, NULL, $2, TRUE);
634 gst_parse_strfree ($1);
636 | BINREF assignments error ')' { GST_BIN_MAKE ($$, $1, NULL, $2, TRUE);
637 gst_parse_strfree ($1);
641 pads: PADREF { $$ = g_slist_prepend (NULL, $1); }
642 | PADREF padlist { $$ = $2;
643 $$ = g_slist_prepend ($$, $1);
646 padlist: ',' IDENTIFIER { $$ = g_slist_prepend (NULL, $2); }
647 | ',' IDENTIFIER padlist { $$ = g_slist_prepend ($3, $2); }
650 reference: REF { MAKE_REF ($$, $1, NULL); }
651 | REF padlist { MAKE_REF ($$, $1, $2); }
654 linkpart: reference { $$ = $1; }
655 | pads { MAKE_REF ($$, NULL, $1); }
656 | /* NOP */ { MAKE_REF ($$, NULL, NULL); }
659 link: linkpart LINK linkpart { $$ = $1;
661 $$->caps = gst_caps_from_string ($2);
662 if ($$->caps == NULL)
663 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK, _("could not parse caps \"%s\""), $2);
664 gst_parse_strfree ($2);
666 $$->sink_name = $3->src_name;
667 $$->sink_pads = $3->src_pads;
668 gst_parse_link_free ($3);
672 linklist: link { $$ = g_slist_prepend (NULL, $1); }
673 | link linklist { $$ = g_slist_prepend ($2, $1); }
674 | linklist error { $$ = $1; }
677 chain: element { $$ = gst_parse_chain_new ();
678 $$->first = $$->last = $1;
679 $$->front = $$->back = NULL;
680 $$->elements = g_slist_prepend (NULL, $1);
683 | chain chain { if ($1->back && $2->front) {
684 if (!$1->back->sink_name) {
685 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK, _("link without source element"));
686 gst_parse_free_link ($1->back);
688 graph->links = g_slist_prepend (graph->links, $1->back);
690 if (!$2->front->src_name) {
691 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK, _("link without sink element"));
692 gst_parse_free_link ($2->front);
694 graph->links = g_slist_prepend (graph->links, $2->front);
697 } else if ($1->back) {
698 if (!$1->back->sink_name) {
699 $1->back->sink = $2->first;
701 } else if ($2->front) {
702 if (!$2->front->src_name) {
703 $2->front->src = $1->last;
705 $1->back = $2->front;
709 graph->links = g_slist_prepend (graph->links, $1->back);
713 $1->elements = g_slist_concat ($1->elements, $2->elements);
715 gst_parse_chain_free ($2);
718 | chain linklist { GSList *walk;
720 $2 = g_slist_prepend ($2, $1->back);
723 if (!((link_t *) $2->data)->src_name) {
724 ((link_t *) $2->data)->src = $1->last;
727 for (walk = $2; walk; walk = walk->next) {
728 link_t *link = (link_t *) walk->data;
729 if (!link->sink_name && walk->next) {
730 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK, _("link without sink element"));
731 gst_parse_free_link (link);
732 } else if (!link->src_name && !link->src) {
733 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK, _("link without source element"));
734 gst_parse_free_link (link);
737 graph->links = g_slist_prepend (graph->links, link);
746 | chain error { $$ = $1; }
747 | link chain { if ($2->front) {
748 if (!$2->front->src_name) {
749 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK, _("link without source element"));
750 gst_parse_free_link ($2->front);
752 graph->links = g_slist_prepend (graph->links, $2->front);
755 if (!$1->sink_name) {
756 $1->sink = $2->first;
761 | PARSE_URL chain { $$ = $2;
763 GstElement *element =
764 gst_element_make_from_uri (GST_URI_SRC, $1, NULL);
766 SET_ERROR (graph->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
767 _("no source element for URI \"%s\""), $1);
769 $$->front->src = element;
770 graph->links = g_slist_prepend (
771 graph->links, $$->front);
773 $$->elements = g_slist_prepend ($$->elements, element);
776 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK,
777 _("no element to link URI \"%s\" to"), $1);
781 | link PARSE_URL { GstElement *element =
782 gst_element_make_from_uri (GST_URI_SINK, $2, NULL);
784 SET_ERROR (graph->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
785 _("no sink element for URI \"%s\""), $2);
786 gst_parse_link_free ($1);
789 } else if ($1->sink_name || $1->sink_pads) {
790 gst_object_unref (element);
791 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK,
792 _("could not link sink element for URI \"%s\""), $2);
793 gst_parse_link_free ($1);
797 $$ = gst_parse_chain_new ();
798 $$->first = $$->last = element;
800 $$->front->sink = element;
801 $$->elements = g_slist_prepend (NULL, element);
806 graph: /* NOP */ { SET_ERROR (graph->error, GST_PARSE_ERROR_EMPTY, _("empty pipeline not allowed"));
809 | chain { $$ = graph;
811 if (!$1->front->src_name) {
812 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK, _("link without source element"));
813 gst_parse_free_link ($1->front);
815 $$->links = g_slist_prepend ($$->links, $1->front);
820 if (!$1->back->sink_name) {
821 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK, _("link without sink element"));
822 gst_parse_free_link ($1->back);
824 $$->links = g_slist_prepend ($$->links, $1->back);
836 yyerror (void *scanner, graph_t *graph, const char *s)
838 /* FIXME: This should go into the GError somehow, but how? */
839 GST_WARNING ("Error during parsing: %s", s);
845 _gst_parse_launch (const gchar *str, GError **error, GstParseContext *ctx,
855 g_return_val_if_fail (str != NULL, NULL);
856 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
864 #ifdef __GST_PARSE_TRACE
865 GST_CAT_DEBUG (GST_CAT_PIPELINE, "TRACE: tracing enabled");
866 __strings = __chains = __links = 0;
867 #endif /* __GST_PARSE_TRACE */
869 dstr = g_strdup (str);
870 _gst_parse_yylex_init (&scanner);
871 _gst_parse_yy_scan_string (dstr, scanner);
877 if (yyparse (scanner, &g) != 0) {
878 SET_ERROR (error, GST_PARSE_ERROR_SYNTAX,
879 "Unrecoverable syntax error while parsing pipeline %s", str);
881 _gst_parse_yylex_destroy (scanner);
886 _gst_parse_yylex_destroy (scanner);
889 GST_CAT_DEBUG (GST_CAT_PIPELINE, "got %u elements and %u links",
890 g.chain ? g_slist_length (g.chain->elements) : 0,
891 g_slist_length (g.links));
895 } else if (!g.chain->elements->next) {
896 /* only one toplevel element */
897 ret = (GstElement *) g.chain->elements->data;
898 g_slist_free (g.chain->elements);
899 if (GST_IS_BIN (ret))
901 gst_parse_chain_free (g.chain);
903 /* put all elements in our bin */
904 bin = GST_BIN (gst_element_factory_make ("pipeline", NULL));
907 for (walk = g.chain->elements; walk; walk = walk->next) {
908 if (walk->data != NULL)
909 gst_bin_add (bin, GST_ELEMENT (walk->data));
912 g_slist_free (g.chain->elements);
913 ret = GST_ELEMENT (bin);
914 gst_parse_chain_free (g.chain);
918 for (walk = g.links; walk; walk = walk->next) {
919 link_t *l = (link_t *) walk->data;
923 l->src = gst_bin_get_by_name_recurse_up (bin, l->src_name);
925 gst_object_unref (l->src);
927 l->src = strcmp (GST_ELEMENT_NAME (ret), l->src_name) == 0 ? ret : NULL;
932 SET_ERROR (error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
933 "No element named \"%s\" - omitting link", l->src_name);
935 /* probably a missing element which we've handled already */
937 gst_parse_free_link (l);
944 l->sink = gst_bin_get_by_name_recurse_up (bin, l->sink_name);
946 gst_object_unref (l->sink);
948 l->sink = strcmp (GST_ELEMENT_NAME (ret), l->sink_name) == 0 ? ret : NULL;
953 SET_ERROR (error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
954 "No element named \"%s\" - omitting link", l->sink_name);
956 /* probably a missing element which we've handled already */
958 gst_parse_free_link (l);
962 gst_parse_perform_link (l, &g);
964 g_slist_free (g.links);
967 #ifdef __GST_PARSE_TRACE
968 GST_CAT_DEBUG (GST_CAT_PIPELINE,
969 "TRACE: %u strings, %u chains and %u links left", __strings, __chains,
971 if (__strings || __chains || __links) {
972 g_warning ("TRACE: %u strings, %u chains and %u links left", __strings,
975 #endif /* __GST_PARSE_TRACE */
981 g_slist_foreach (g.chain->elements, (GFunc)gst_object_unref, NULL);
982 g_slist_free (g.chain->elements);
983 gst_parse_chain_free (g.chain);
986 g_slist_foreach (g.links, (GFunc)gst_parse_free_link, NULL);
987 g_slist_free (g.links);