2 #include "../gst_private.h"
4 #include <glib-object.h>
10 #include "../gst-i18n-lib.h"
12 #include "../gstconfig.h"
13 #include "../gstparse.h"
14 #include "../gstinfo.h"
15 #include "../gsterror.h"
16 #include "../gststructure.h"
17 #include "../gsturi.h"
18 #include "../gstutils.h"
19 #include "../gstvalue.h"
20 #include "../gstchildproxy.h"
23 /* All error messages in this file are user-visible and need to be translated.
24 * Don't start the message with a capital, and don't end them with a period,
25 * as they will be presented inside a sentence/error.
28 #define YYERROR_VERBOSE 1
29 #define YYLEX_PARAM scanner
31 typedef void* yyscan_t;
33 int _gst_parse_yylex (void * yylval_param , yyscan_t yyscanner);
34 int _gst_parse_yylex_init (yyscan_t scanner);
35 int _gst_parse_yylex_destroy (yyscan_t scanner);
36 struct yy_buffer_state * _gst_parse_yy_scan_string (char* , yyscan_t);
37 void _gst_parse_yypush_buffer_state (void * new_buffer ,yyscan_t yyscanner );
38 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 */
115 /*** define SET_ERROR macro/function */
117 #ifdef G_HAVE_ISO_VARARGS
119 # define SET_ERROR(error, type, ...) \
121 GST_CAT_ERROR (GST_CAT_PIPELINE, __VA_ARGS__); \
122 if ((error) && !*(error)) { \
123 g_set_error ((error), GST_PARSE_ERROR, (type), __VA_ARGS__); \
127 #elif defined(G_HAVE_GNUC_VARARGS)
129 # define SET_ERROR(error, type, args...) \
131 GST_CAT_ERROR (GST_CAT_PIPELINE, args ); \
132 if ((error) && !*(error)) { \
133 g_set_error ((error), GST_PARSE_ERROR, (type), args ); \
140 SET_ERROR (GError **error, gint type, const char *format, ...)
144 g_warning ("error while parsing");
149 va_start (varargs, format);
150 string = g_strdup_vprintf (format, varargs);
153 g_set_error (error, GST_PARSE_ERROR, type, string);
160 #endif /* G_HAVE_ISO_VARARGS */
162 /*** define YYPRINTF macro/function if we're debugging */
164 /* bison 1.35 calls this macro with side effects, we need to make sure the
165 side effects work - crappy bison */
167 #ifndef GST_DISABLE_GST_DEBUG
170 # ifdef G_HAVE_ISO_VARARGS
172 /* # define YYFPRINTF(a, ...) GST_CAT_DEBUG (GST_CAT_PIPELINE, __VA_ARGS__) */
173 # define YYFPRINTF(a, ...) \
175 GST_CAT_LOG (GST_CAT_PIPELINE, __VA_ARGS__); \
178 # elif defined(G_HAVE_GNUC_VARARGS)
180 # define YYFPRINTF(a, args...) \
182 GST_CAT_LOG (GST_CAT_PIPELINE, args); \
188 YYPRINTF(const char *format, ...)
193 va_start (varargs, format);
194 temp = g_strdup_vprintf (format, varargs);
195 GST_CAT_LOG (GST_CAT_PIPELINE, "%s", temp);
200 # endif /* G_HAVE_ISO_VARARGS */
202 #endif /* GST_DISABLE_GST_DEBUG */
204 #define ADD_MISSING_ELEMENT(graph,name) G_STMT_START { \
205 if ((graph)->ctx) { \
206 (graph)->ctx->missing_elements = \
207 g_list_append ((graph)->ctx->missing_elements, g_strdup (name)); \
210 #define GST_BIN_MAKE(res, type, chainval, assign, free_string) \
212 chain_t *chain = chainval; \
214 GstBin *bin = (GstBin *) gst_element_factory_make (type, NULL); \
216 SET_ERROR (graph->error, GST_PARSE_ERROR_EMPTY_BIN, \
217 _("specified empty bin \"%s\", not allowed"), type); \
218 g_slist_foreach (assign, (GFunc) gst_parse_strfree, NULL); \
219 g_slist_free (assign); \
220 gst_object_unref (bin); \
222 gst_parse_strfree (type); /* Need to clean up the string */ \
225 ADD_MISSING_ELEMENT(graph, type); \
226 SET_ERROR (graph->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT, \
227 _("no bin \"%s\", skipping"), type); \
228 g_slist_foreach (assign, (GFunc) gst_parse_strfree, NULL); \
229 g_slist_free (assign); \
232 for (walk = chain->elements; walk; walk = walk->next ) \
233 gst_bin_add (bin, GST_ELEMENT (walk->data)); \
234 g_slist_free (chain->elements); \
235 chain->elements = g_slist_prepend (NULL, bin); \
237 /* set the properties now */ \
238 for (walk = assign; walk; walk = walk->next) \
239 gst_parse_element_set ((gchar *) walk->data, GST_ELEMENT (bin), graph); \
240 g_slist_free (assign); \
244 #define MAKE_LINK(link, _src, _src_name, _src_pads, _sink, _sink_name, _sink_pads) \
246 link = gst_parse_link_new (); \
248 link->sink = _sink; \
249 link->src_name = _src_name; \
250 link->sink_name = _sink_name; \
251 link->src_pads = _src_pads; \
252 link->sink_pads = _sink_pads; \
256 #define MAKE_REF(link, _src, _pads) \
258 gchar *padname = _src; \
259 GSList *pads = _pads; \
261 while (*padname != '.') padname++; \
264 if (*padname != '\0') \
265 pads = g_slist_prepend (pads, gst_parse_strdup (padname)); \
267 MAKE_LINK (link, NULL, _src, pads, NULL, NULL, NULL); \
271 gst_parse_free_delayed_set (DelayedSet *set)
274 g_free(set->value_str);
275 g_slice_free(DelayedSet, set);
278 static void gst_parse_new_child(GstChildProxy *child_proxy, GObject *object,
282 gst_parse_add_delayed_set (GstElement *element, gchar *name, gchar *value_str)
284 DelayedSet *data = g_slice_new0 (DelayedSet);
286 GST_CAT_LOG_OBJECT (GST_CAT_PIPELINE, element, "delaying property set %s to %s",
289 data->name = g_strdup(name);
290 data->value_str = g_strdup(value_str);
291 data->signal_id = g_signal_connect_data(element, "child-added",
292 G_CALLBACK (gst_parse_new_child), data, (GClosureNotify)
293 gst_parse_free_delayed_set, (GConnectFlags) 0);
295 /* FIXME: we would need to listen on all intermediate bins too */
296 if (GST_IS_BIN (element)) {
297 gchar **names, **current;
298 GstElement *parent, *child;
300 current = names = g_strsplit (name, "::", -1);
301 parent = gst_bin_get_by_name (GST_BIN_CAST (element), current[0]);
303 while (parent && current[0]) {
304 child = gst_bin_get_by_name (GST_BIN (parent), current[0]);
305 if (!child && current[1]) {
306 char *sub_name = g_strjoinv ("::", ¤t[0]);
308 gst_parse_add_delayed_set(parent, sub_name, value_str);
318 static void gst_parse_new_child(GstChildProxy *child_proxy, GObject *object,
321 DelayedSet *set = (DelayedSet *) data;
324 GstObject *target = NULL;
327 GST_CAT_LOG_OBJECT (GST_CAT_PIPELINE, child_proxy, "new child %s, checking property %s",
328 GST_OBJECT_NAME(object), set->name);
330 if (gst_child_proxy_lookup (GST_OBJECT (child_proxy), set->name, &target, &pspec)) {
331 gboolean got_value = FALSE;
333 value_type = pspec->value_type;
335 GST_CAT_LOG_OBJECT (GST_CAT_PIPELINE, child_proxy, "parsing delayed property %s as a %s from %s",
336 pspec->name, g_type_name (value_type), set->value_str);
337 g_value_init (&v, value_type);
338 if (gst_value_deserialize (&v, set->value_str))
340 else if (g_type_is_a (value_type, GST_TYPE_ELEMENT)) {
343 bin = gst_parse_bin_from_description (set->value_str, TRUE, NULL);
345 g_value_set_object (&v, bin);
349 g_signal_handler_disconnect (child_proxy, set->signal_id);
352 g_object_set_property (G_OBJECT (target), pspec->name, &v);
354 const gchar *obj_name = GST_OBJECT_NAME(object);
355 gint len = strlen (obj_name);
357 /* do a delayed set */
358 if ((strlen (set->name) > (len + 2)) && !strncmp (set->name, obj_name, len) && !strncmp (&set->name[len], "::", 2)) {
359 gst_parse_add_delayed_set (GST_ELEMENT(child_proxy), set->name, set->value_str);
367 gst_object_unref (target);
371 GST_CAT_ERROR (GST_CAT_PIPELINE, "could not set property \"%s\" in element \"%s\"",
372 pspec->name, GST_ELEMENT_NAME (target));
377 gst_parse_element_set (gchar *value, GstElement *element, graph_t *graph)
382 GstObject *target = NULL;
385 /* do nothing if assignment is for missing element */
389 /* parse the string, so the property name is null-terminated an pos points
390 to the beginning of the value */
391 while (!g_ascii_isspace (*pos) && (*pos != '=')) pos++;
397 while (g_ascii_isspace (*pos)) pos++;
400 while (g_ascii_isspace (*pos)) pos++;
403 pos[strlen (pos) - 1] = '\0';
405 gst_parse_unescape (pos);
407 if (gst_child_proxy_lookup (GST_OBJECT (element), value, &target, &pspec)) {
408 gboolean got_value = FALSE;
410 value_type = pspec->value_type;
412 GST_CAT_LOG_OBJECT (GST_CAT_PIPELINE, element, "parsing property %s as a %s", pspec->name,
413 g_type_name (value_type));
414 g_value_init (&v, value_type);
415 if (gst_value_deserialize (&v, pos))
417 else if (g_type_is_a (value_type, GST_TYPE_ELEMENT)) {
420 bin = gst_parse_bin_from_description (pos, TRUE, NULL);
422 g_value_set_object (&v, bin);
428 g_object_set_property (G_OBJECT (target), pspec->name, &v);
430 /* do a delayed set */
431 if (GST_IS_CHILD_PROXY (element)) {
432 gst_parse_add_delayed_set (element, value, pos);
435 SET_ERROR (graph->error, GST_PARSE_ERROR_NO_SUCH_PROPERTY, \
436 _("no property \"%s\" in element \"%s\""), value, \
437 GST_ELEMENT_NAME (element));
442 gst_parse_strfree (value);
446 gst_object_unref (target);
450 SET_ERROR (graph->error, GST_PARSE_ERROR_COULD_NOT_SET_PROPERTY,
451 _("could not set property \"%s\" in element \"%s\" to \"%s\""),
452 value, GST_ELEMENT_NAME (element), pos);
457 gst_parse_free_link (link_t *link)
459 gst_parse_strfree (link->src_name);
460 gst_parse_strfree (link->sink_name);
461 g_slist_foreach (link->src_pads, (GFunc) gst_parse_strfree, NULL);
462 g_slist_foreach (link->sink_pads, (GFunc) gst_parse_strfree, NULL);
463 g_slist_free (link->src_pads);
464 g_slist_free (link->sink_pads);
465 if (link->caps) gst_caps_unref (link->caps);
466 gst_parse_link_free (link);
470 gst_parse_free_delayed_link (DelayedLink *link)
472 g_free (link->src_pad);
473 g_free (link->sink_pad);
474 if (link->caps) gst_caps_unref (link->caps);
475 g_slice_free (DelayedLink, link);
479 gst_parse_found_pad (GstElement *src, GstPad *pad, gpointer data)
481 DelayedLink *link = data;
483 GST_CAT_INFO (GST_CAT_PIPELINE, "trying delayed linking %s:%s to %s:%s",
484 GST_STR_NULL (GST_ELEMENT_NAME (src)), GST_STR_NULL (link->src_pad),
485 GST_STR_NULL (GST_ELEMENT_NAME (link->sink)), GST_STR_NULL (link->sink_pad));
487 if (gst_element_link_pads_filtered (src, link->src_pad, link->sink,
488 link->sink_pad, link->caps)) {
489 /* do this here, we don't want to get any problems later on when
490 * unlocking states */
491 GST_CAT_DEBUG (GST_CAT_PIPELINE, "delayed linking %s:%s to %s:%s worked",
492 GST_STR_NULL (GST_ELEMENT_NAME (src)), GST_STR_NULL (link->src_pad),
493 GST_STR_NULL (GST_ELEMENT_NAME (link->sink)), GST_STR_NULL (link->sink_pad));
494 g_signal_handler_disconnect (src, link->signal_id);
498 /* both padnames and the caps may be NULL */
500 gst_parse_perform_delayed_link (GstElement *src, const gchar *src_pad,
501 GstElement *sink, const gchar *sink_pad,
504 GList *templs = gst_element_class_get_pad_template_list (
505 GST_ELEMENT_GET_CLASS (src));
507 for (; templs; templs = templs->next) {
508 GstPadTemplate *templ = (GstPadTemplate *) templs->data;
509 if ((GST_PAD_TEMPLATE_DIRECTION (templ) == GST_PAD_SRC) &&
510 (GST_PAD_TEMPLATE_PRESENCE(templ) == GST_PAD_SOMETIMES))
512 DelayedLink *data = g_slice_new (DelayedLink);
514 /* TODO: maybe we should check if src_pad matches this template's names */
516 GST_CAT_DEBUG (GST_CAT_PIPELINE, "trying delayed link %s:%s to %s:%s",
517 GST_STR_NULL (GST_ELEMENT_NAME (src)), GST_STR_NULL (src_pad),
518 GST_STR_NULL (GST_ELEMENT_NAME (sink)), GST_STR_NULL (sink_pad));
520 data->src_pad = g_strdup (src_pad);
522 data->sink_pad = g_strdup (sink_pad);
524 data->caps = gst_caps_copy (caps);
528 data->signal_id = g_signal_connect_data (src, "pad-added",
529 G_CALLBACK (gst_parse_found_pad), data,
530 (GClosureNotify) gst_parse_free_delayed_link, (GConnectFlags) 0);
538 * performs a link and frees the struct. src and sink elements must be given
539 * return values 0 - link performed
544 gst_parse_perform_link (link_t *link, graph_t *graph)
546 GstElement *src = link->src;
547 GstElement *sink = link->sink;
548 GSList *srcs = link->src_pads;
549 GSList *sinks = link->sink_pads;
550 g_assert (GST_IS_ELEMENT (src));
551 g_assert (GST_IS_ELEMENT (sink));
553 GST_CAT_INFO (GST_CAT_PIPELINE,
554 "linking %s:%s to %s:%s (%u/%u) with caps \"%" GST_PTR_FORMAT "\"",
555 GST_ELEMENT_NAME (src), link->src_name ? link->src_name : "(any)",
556 GST_ELEMENT_NAME (sink), link->sink_name ? link->sink_name : "(any)",
557 g_slist_length (srcs), g_slist_length (sinks), link->caps);
559 if (!srcs || !sinks) {
560 if (gst_element_link_pads_filtered (src,
561 srcs ? (const gchar *) srcs->data : NULL, sink,
562 sinks ? (const gchar *) sinks->data : NULL, link->caps)) {
565 if (gst_parse_perform_delayed_link (src,
566 srcs ? (const gchar *) srcs->data : NULL,
567 sink, sinks ? (const gchar *) sinks->data : NULL, link->caps)) {
574 if (g_slist_length (link->src_pads) != g_slist_length (link->src_pads)) {
577 while (srcs && sinks) {
578 const gchar *src_pad = (const gchar *) srcs->data;
579 const gchar *sink_pad = (const gchar *) sinks->data;
580 srcs = g_slist_next (srcs);
581 sinks = g_slist_next (sinks);
582 if (gst_element_link_pads_filtered (src, src_pad, sink, sink_pad,
586 if (gst_parse_perform_delayed_link (src, src_pad,
597 gst_parse_free_link (link);
601 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK,
602 _("could not link %s to %s"), GST_ELEMENT_NAME (src),
603 GST_ELEMENT_NAME (sink));
604 gst_parse_free_link (link);
609 static int yyerror (void *scanner, graph_t *graph, const char *s);
622 %token <s> IDENTIFIER
623 %left <s> REF PADREF BINREF
624 %token <s> ASSIGNMENT
630 %type <l> linkpart link
633 %type <p> padlist pads assignments
640 %parse-param { void *scanner }
641 %parse-param { graph_t *graph }
647 element: IDENTIFIER { $$ = gst_element_factory_make ($1, NULL);
649 ADD_MISSING_ELEMENT (graph, $1);
650 SET_ERROR (graph->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT, _("no element \"%s\""), $1);
651 /* if FATAL_ERRORS flag is set, we don't have to worry about backwards
652 * compatibility and can continue parsing and check for other missing
654 if ((graph->flags & GST_PARSE_FLAG_FATAL_ERRORS) == 0) {
655 gst_parse_strfree ($1);
659 gst_parse_strfree ($1);
661 | element ASSIGNMENT { gst_parse_element_set ($2, $1, graph);
665 assignments: /* NOP */ { $$ = NULL; }
666 | assignments ASSIGNMENT { $$ = g_slist_prepend ($1, $2); }
668 bin: '(' assignments chain ')' { GST_BIN_MAKE ($$, "bin", $3, $2, FALSE); }
669 | BINREF assignments chain ')' { GST_BIN_MAKE ($$, $1, $3, $2, TRUE);
670 gst_parse_strfree ($1);
672 | BINREF assignments ')' { GST_BIN_MAKE ($$, $1, NULL, $2, TRUE);
673 gst_parse_strfree ($1);
675 | BINREF assignments error ')' { GST_BIN_MAKE ($$, $1, NULL, $2, TRUE);
676 gst_parse_strfree ($1);
680 pads: PADREF { $$ = g_slist_prepend (NULL, $1); }
681 | PADREF padlist { $$ = $2;
682 $$ = g_slist_prepend ($$, $1);
685 padlist: ',' IDENTIFIER { $$ = g_slist_prepend (NULL, $2); }
686 | ',' IDENTIFIER padlist { $$ = g_slist_prepend ($3, $2); }
689 reference: REF { MAKE_REF ($$, $1, NULL); }
690 | REF padlist { MAKE_REF ($$, $1, $2); }
693 linkpart: reference { $$ = $1; }
694 | pads { MAKE_REF ($$, NULL, $1); }
695 | /* NOP */ { MAKE_REF ($$, NULL, NULL); }
698 link: linkpart LINK linkpart { $$ = $1;
700 $$->caps = gst_caps_from_string ($2);
701 if ($$->caps == NULL)
702 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK, _("could not parse caps \"%s\""), $2);
703 gst_parse_strfree ($2);
705 $$->sink_name = $3->src_name;
706 $$->sink_pads = $3->src_pads;
707 gst_parse_link_free ($3);
711 linklist: link { $$ = g_slist_prepend (NULL, $1); }
712 | link linklist { $$ = g_slist_prepend ($2, $1); }
713 | linklist error { $$ = $1; }
716 chain: element { $$ = gst_parse_chain_new ();
717 $$->first = $$->last = $1;
718 $$->front = $$->back = NULL;
719 $$->elements = g_slist_prepend (NULL, $1);
722 | chain chain { if ($1->back && $2->front) {
723 if (!$1->back->sink_name) {
724 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK, _("link without source element"));
725 gst_parse_free_link ($1->back);
727 graph->links = g_slist_prepend (graph->links, $1->back);
729 if (!$2->front->src_name) {
730 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK, _("link without sink element"));
731 gst_parse_free_link ($2->front);
733 graph->links = g_slist_prepend (graph->links, $2->front);
736 } else if ($1->back) {
737 if (!$1->back->sink_name) {
738 $1->back->sink = $2->first;
740 } else if ($2->front) {
741 if (!$2->front->src_name) {
742 $2->front->src = $1->last;
744 $1->back = $2->front;
748 graph->links = g_slist_prepend (graph->links, $1->back);
752 $1->elements = g_slist_concat ($1->elements, $2->elements);
754 gst_parse_chain_free ($2);
757 | chain linklist { GSList *walk;
759 $2 = g_slist_prepend ($2, $1->back);
762 if (!((link_t *) $2->data)->src_name) {
763 ((link_t *) $2->data)->src = $1->last;
766 for (walk = $2; walk; walk = walk->next) {
767 link_t *link = (link_t *) walk->data;
768 if (!link->sink_name && walk->next) {
769 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK, _("link without sink element"));
770 gst_parse_free_link (link);
771 } else if (!link->src_name && !link->src) {
772 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK, _("link without source element"));
773 gst_parse_free_link (link);
776 graph->links = g_slist_prepend (graph->links, link);
785 | chain error { $$ = $1; }
786 | link chain { if ($2->front) {
787 if (!$2->front->src_name) {
788 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK, _("link without source element"));
789 gst_parse_free_link ($2->front);
791 graph->links = g_slist_prepend (graph->links, $2->front);
794 if (!$1->sink_name) {
795 $1->sink = $2->first;
800 | PARSE_URL chain { $$ = $2;
802 GstElement *element =
803 gst_element_make_from_uri (GST_URI_SRC, $1, NULL);
805 SET_ERROR (graph->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
806 _("no source element for URI \"%s\""), $1);
808 $$->front->src = element;
809 graph->links = g_slist_prepend (
810 graph->links, $$->front);
812 $$->elements = g_slist_prepend ($$->elements, element);
815 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK,
816 _("no element to link URI \"%s\" to"), $1);
820 | link PARSE_URL { GstElement *element =
821 gst_element_make_from_uri (GST_URI_SINK, $2, NULL);
823 SET_ERROR (graph->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
824 _("no sink element for URI \"%s\""), $2);
825 gst_parse_link_free ($1);
828 } else if ($1->sink_name || $1->sink_pads) {
829 gst_object_unref (element);
830 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK,
831 _("could not link sink element for URI \"%s\""), $2);
832 gst_parse_link_free ($1);
836 $$ = gst_parse_chain_new ();
837 $$->first = $$->last = element;
839 $$->front->sink = element;
840 $$->elements = g_slist_prepend (NULL, element);
845 graph: /* NOP */ { SET_ERROR (graph->error, GST_PARSE_ERROR_EMPTY, _("empty pipeline not allowed"));
848 | chain { $$ = graph;
850 if (!$1->front->src_name) {
851 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK, _("link without source element"));
852 gst_parse_free_link ($1->front);
854 $$->links = g_slist_prepend ($$->links, $1->front);
859 if (!$1->back->sink_name) {
860 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK, _("link without sink element"));
861 gst_parse_free_link ($1->back);
863 $$->links = g_slist_prepend ($$->links, $1->back);
875 yyerror (void *scanner, graph_t *graph, const char *s)
877 /* FIXME: This should go into the GError somehow, but how? */
878 GST_WARNING ("Error during parsing: %s", s);
884 _gst_parse_launch (const gchar *str, GError **error, GstParseContext *ctx,
894 g_return_val_if_fail (str != NULL, NULL);
895 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
903 #ifdef __GST_PARSE_TRACE
904 GST_CAT_DEBUG (GST_CAT_PIPELINE, "TRACE: tracing enabled");
905 __strings = __chains = __links = 0;
906 #endif /* __GST_PARSE_TRACE */
908 dstr = g_strdup (str);
909 _gst_parse_yylex_init (&scanner);
910 _gst_parse_yy_scan_string (dstr, scanner);
916 if (yyparse (scanner, &g) != 0) {
917 SET_ERROR (error, GST_PARSE_ERROR_SYNTAX,
918 "Unrecoverable syntax error while parsing pipeline %s", str);
920 _gst_parse_yylex_destroy (scanner);
925 _gst_parse_yylex_destroy (scanner);
928 GST_CAT_DEBUG (GST_CAT_PIPELINE, "got %u elements and %u links",
929 g.chain ? g_slist_length (g.chain->elements) : 0,
930 g_slist_length (g.links));
934 } else if (!g.chain->elements->next) {
935 /* only one toplevel element */
936 ret = (GstElement *) g.chain->elements->data;
937 g_slist_free (g.chain->elements);
938 if (GST_IS_BIN (ret))
940 gst_parse_chain_free (g.chain);
942 /* put all elements in our bin */
943 bin = GST_BIN (gst_element_factory_make ("pipeline", NULL));
946 for (walk = g.chain->elements; walk; walk = walk->next) {
947 if (walk->data != NULL)
948 gst_bin_add (bin, GST_ELEMENT (walk->data));
951 g_slist_free (g.chain->elements);
952 ret = GST_ELEMENT (bin);
953 gst_parse_chain_free (g.chain);
957 for (walk = g.links; walk; walk = walk->next) {
958 link_t *l = (link_t *) walk->data;
962 l->src = gst_bin_get_by_name_recurse_up (bin, l->src_name);
964 gst_object_unref (l->src);
966 l->src = strcmp (GST_ELEMENT_NAME (ret), l->src_name) == 0 ? ret : NULL;
971 SET_ERROR (error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
972 "No element named \"%s\" - omitting link", l->src_name);
974 /* probably a missing element which we've handled already */
976 gst_parse_free_link (l);
983 l->sink = gst_bin_get_by_name_recurse_up (bin, l->sink_name);
985 gst_object_unref (l->sink);
987 l->sink = strcmp (GST_ELEMENT_NAME (ret), l->sink_name) == 0 ? ret : NULL;
992 SET_ERROR (error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
993 "No element named \"%s\" - omitting link", l->sink_name);
995 /* probably a missing element which we've handled already */
997 gst_parse_free_link (l);
1001 gst_parse_perform_link (l, &g);
1003 g_slist_free (g.links);
1006 #ifdef __GST_PARSE_TRACE
1007 GST_CAT_DEBUG (GST_CAT_PIPELINE,
1008 "TRACE: %u strings, %u chains and %u links left", __strings, __chains,
1010 if (__strings || __chains || __links) {
1011 g_warning ("TRACE: %u strings, %u chains and %u links left", __strings,
1014 #endif /* __GST_PARSE_TRACE */
1020 g_slist_foreach (g.chain->elements, (GFunc)gst_object_unref, NULL);
1021 g_slist_free (g.chain->elements);
1022 gst_parse_chain_free (g.chain);
1025 g_slist_foreach (g.links, (GFunc)gst_parse_free_link, NULL);
1026 g_slist_free (g.links);