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 #define YYENABLE_NLS 0
33 #ifndef YYLTYPE_IS_TRIVIAL
34 #define YYLTYPE_IS_TRIVIAL 0
37 typedef void* yyscan_t;
39 int priv_gst_parse_yylex (void * yylval_param , yyscan_t yyscanner);
40 int priv_gst_parse_yylex_init (yyscan_t scanner);
41 int priv_gst_parse_yylex_destroy (yyscan_t scanner);
42 struct yy_buffer_state * priv_gst_parse_yy_scan_string (char* , yyscan_t);
43 void _gst_parse_yypush_buffer_state (void * new_buffer ,yyscan_t yyscanner );
44 void _gst_parse_yypop_buffer_state (yyscan_t yyscanner );
46 #ifdef __GST_PARSE_TRACE
47 static guint __strings;
49 static guint __chains;
51 __gst_parse_strdup (gchar *org)
56 /* g_print ("ALLOCATED STR (%3u): %p %s\n", __strings, ret, ret); */
60 __gst_parse_strfree (gchar *str)
63 /* g_print ("FREEING STR (%3u): %p %s\n", __strings - 1, str, str); */
65 g_return_if_fail (__strings > 0);
69 link_t *__gst_parse_link_new ()
73 ret = g_slice_new0 (link_t);
74 /* g_print ("ALLOCATED LINK (%3u): %p\n", __links, ret); */
78 __gst_parse_link_free (link_t *data)
81 /* g_print ("FREEING LINK (%3u): %p\n", __links - 1, data); */
82 g_slice_free (link_t, data);
83 g_return_if_fail (__links > 0);
88 __gst_parse_chain_new ()
92 ret = g_slice_new0 (chain_t);
93 /* g_print ("ALLOCATED CHAIN (%3u): %p\n", __chains, ret); */
97 __gst_parse_chain_free (chain_t *data)
99 /* g_print ("FREEING CHAIN (%3u): %p\n", __chains - 1, data); */
100 g_slice_free (chain_t, data);
101 g_return_if_fail (__chains > 0);
105 #endif /* __GST_PARSE_TRACE */
121 /*** define SET_ERROR macro/function */
123 #ifdef G_HAVE_ISO_VARARGS
125 # define SET_ERROR(error, type, ...) \
127 GST_CAT_ERROR (GST_CAT_PIPELINE, __VA_ARGS__); \
128 if ((error) && !*(error)) { \
129 g_set_error ((error), GST_PARSE_ERROR, (type), __VA_ARGS__); \
133 #elif defined(G_HAVE_GNUC_VARARGS)
135 # define SET_ERROR(error, type, args...) \
137 GST_CAT_ERROR (GST_CAT_PIPELINE, args ); \
138 if ((error) && !*(error)) { \
139 g_set_error ((error), GST_PARSE_ERROR, (type), args ); \
146 SET_ERROR (GError **error, gint type, const char *format, ...)
150 g_warning ("error while parsing");
155 va_start (varargs, format);
156 string = g_strdup_vprintf (format, varargs);
159 g_set_error (error, GST_PARSE_ERROR, type, string);
166 #endif /* G_HAVE_ISO_VARARGS */
168 /*** define YYPRINTF macro/function if we're debugging */
170 /* bison 1.35 calls this macro with side effects, we need to make sure the
171 side effects work - crappy bison */
173 #ifndef GST_DISABLE_GST_DEBUG
176 # ifdef G_HAVE_ISO_VARARGS
178 /* # define YYFPRINTF(a, ...) GST_CAT_DEBUG (GST_CAT_PIPELINE, __VA_ARGS__) */
179 # define YYFPRINTF(a, ...) \
181 GST_CAT_LOG (GST_CAT_PIPELINE, __VA_ARGS__); \
184 # elif defined(G_HAVE_GNUC_VARARGS)
186 # define YYFPRINTF(a, args...) \
188 GST_CAT_LOG (GST_CAT_PIPELINE, args); \
194 YYPRINTF(const char *format, ...)
199 va_start (varargs, format);
200 temp = g_strdup_vprintf (format, varargs);
201 GST_CAT_LOG (GST_CAT_PIPELINE, "%s", temp);
206 # endif /* G_HAVE_ISO_VARARGS */
208 #endif /* GST_DISABLE_GST_DEBUG */
210 #define ADD_MISSING_ELEMENT(graph,name) G_STMT_START { \
211 if ((graph)->ctx) { \
212 (graph)->ctx->missing_elements = \
213 g_list_append ((graph)->ctx->missing_elements, g_strdup (name)); \
217 no_free (gconstpointer foo)
222 #define GST_BIN_MAKE(res, type, chainval, assign, type_string_free_func) \
224 chain_t *chain = chainval; \
226 GstBin *bin = (GstBin *) gst_element_factory_make (type, NULL); \
228 SET_ERROR (graph->error, GST_PARSE_ERROR_EMPTY_BIN, \
229 _("specified empty bin \"%s\", not allowed"), type); \
230 g_slist_foreach (assign, (GFunc) gst_parse_strfree, NULL); \
231 g_slist_free (assign); \
232 gst_object_unref (bin); \
233 type_string_free_func (type); /* Need to clean up the string */ \
236 ADD_MISSING_ELEMENT(graph, type); \
237 SET_ERROR (graph->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT, \
238 _("no bin \"%s\", skipping"), type); \
239 g_slist_foreach (assign, (GFunc) gst_parse_strfree, NULL); \
240 g_slist_free (assign); \
243 for (walk = chain->elements; walk; walk = walk->next ) \
244 gst_bin_add (bin, GST_ELEMENT (walk->data)); \
245 g_slist_free (chain->elements); \
246 chain->elements = g_slist_prepend (NULL, bin); \
248 /* set the properties now */ \
249 for (walk = assign; walk; walk = walk->next) \
250 gst_parse_element_set ((gchar *) walk->data, GST_ELEMENT (bin), graph); \
251 g_slist_free (assign); \
255 #define MAKE_LINK(link, _src, _src_name, _src_pads, _sink, _sink_name, _sink_pads) \
257 link = gst_parse_link_new (); \
259 link->sink = _sink; \
260 link->src_name = _src_name; \
261 link->sink_name = _sink_name; \
262 link->src_pads = _src_pads; \
263 link->sink_pads = _sink_pads; \
267 #define MAKE_REF(link, _src, _pads) \
269 gchar *padname = _src; \
270 GSList *pads = _pads; \
272 while (*padname != '.') padname++; \
275 if (*padname != '\0') \
276 pads = g_slist_prepend (pads, gst_parse_strdup (padname)); \
278 MAKE_LINK (link, NULL, _src, pads, NULL, NULL, NULL); \
282 gst_parse_free_delayed_set (DelayedSet *set)
285 g_free(set->value_str);
286 g_slice_free(DelayedSet, set);
289 static void gst_parse_new_child(GstChildProxy *child_proxy, GObject *object,
293 gst_parse_add_delayed_set (GstElement *element, gchar *name, gchar *value_str)
295 DelayedSet *data = g_slice_new0 (DelayedSet);
297 GST_CAT_LOG_OBJECT (GST_CAT_PIPELINE, element, "delaying property set %s to %s",
300 data->name = g_strdup(name);
301 data->value_str = g_strdup(value_str);
302 data->signal_id = g_signal_connect_data(element, "child-added",
303 G_CALLBACK (gst_parse_new_child), data, (GClosureNotify)
304 gst_parse_free_delayed_set, (GConnectFlags) 0);
306 /* FIXME: we would need to listen on all intermediate bins too */
307 if (GST_IS_BIN (element)) {
308 gchar **names, **current;
309 GstElement *parent, *child;
311 current = names = g_strsplit (name, "::", -1);
312 parent = gst_bin_get_by_name (GST_BIN_CAST (element), current[0]);
314 while (parent && current[0]) {
315 child = gst_bin_get_by_name (GST_BIN (parent), current[0]);
316 if (!child && current[1]) {
317 char *sub_name = g_strjoinv ("::", ¤t[0]);
319 gst_parse_add_delayed_set(parent, sub_name, value_str);
329 static void gst_parse_new_child(GstChildProxy *child_proxy, GObject *object,
332 DelayedSet *set = (DelayedSet *) data;
335 GObject *target = NULL;
338 GST_CAT_LOG_OBJECT (GST_CAT_PIPELINE, child_proxy, "new child %s, checking property %s",
339 GST_OBJECT_NAME(object), set->name);
341 if (gst_child_proxy_lookup (G_OBJECT (child_proxy), set->name, &target, &pspec)) {
342 gboolean got_value = FALSE;
344 value_type = pspec->value_type;
346 GST_CAT_LOG_OBJECT (GST_CAT_PIPELINE, child_proxy, "parsing delayed property %s as a %s from %s",
347 pspec->name, g_type_name (value_type), set->value_str);
348 g_value_init (&v, value_type);
349 if (gst_value_deserialize (&v, set->value_str))
351 else if (g_type_is_a (value_type, GST_TYPE_ELEMENT)) {
354 bin = gst_parse_bin_from_description (set->value_str, TRUE, NULL);
356 g_value_set_object (&v, bin);
360 g_signal_handler_disconnect (child_proxy, set->signal_id);
363 g_object_set_property (target, pspec->name, &v);
365 const gchar *obj_name = GST_OBJECT_NAME(object);
366 gint len = strlen (obj_name);
368 /* do a delayed set */
369 if ((strlen (set->name) > (len + 2)) && !strncmp (set->name, obj_name, len) && !strncmp (&set->name[len], "::", 2)) {
370 gst_parse_add_delayed_set (GST_ELEMENT(child_proxy), set->name, set->value_str);
378 g_object_unref (target);
382 GST_CAT_ERROR (GST_CAT_PIPELINE, "could not set property \"%s\" in "
383 GST_PTR_FORMAT, pspec->name, target);
388 gst_parse_element_set (gchar *value, GstElement *element, graph_t *graph)
393 GObject *target = NULL;
396 /* do nothing if assignment is for missing element */
400 /* parse the string, so the property name is null-terminated an pos points
401 to the beginning of the value */
402 while (!g_ascii_isspace (*pos) && (*pos != '=')) pos++;
408 while (g_ascii_isspace (*pos)) pos++;
411 while (g_ascii_isspace (*pos)) pos++;
414 pos[strlen (pos) - 1] = '\0';
416 gst_parse_unescape (pos);
418 if (gst_child_proxy_lookup (G_OBJECT (element), value, &target, &pspec)) {
419 gboolean got_value = FALSE;
421 value_type = pspec->value_type;
423 GST_CAT_LOG_OBJECT (GST_CAT_PIPELINE, element, "parsing property %s as a %s", pspec->name,
424 g_type_name (value_type));
425 g_value_init (&v, value_type);
426 if (gst_value_deserialize (&v, pos))
428 else if (g_type_is_a (value_type, GST_TYPE_ELEMENT)) {
431 bin = gst_parse_bin_from_description (pos, TRUE, NULL);
433 g_value_set_object (&v, bin);
439 g_object_set_property (target, pspec->name, &v);
441 /* do a delayed set */
442 if (GST_IS_CHILD_PROXY (element)) {
443 gst_parse_add_delayed_set (element, value, pos);
446 SET_ERROR (graph->error, GST_PARSE_ERROR_NO_SUCH_PROPERTY, \
447 _("no property \"%s\" in element \"%s\""), value, \
448 GST_ELEMENT_NAME (element));
453 gst_parse_strfree (value);
457 g_object_unref (target);
461 SET_ERROR (graph->error, GST_PARSE_ERROR_COULD_NOT_SET_PROPERTY,
462 _("could not set property \"%s\" in element \"%s\" to \"%s\""),
463 value, GST_ELEMENT_NAME (element), pos);
468 gst_parse_free_link (link_t *link)
470 gst_parse_strfree (link->src_name);
471 gst_parse_strfree (link->sink_name);
472 g_slist_foreach (link->src_pads, (GFunc) gst_parse_strfree, NULL);
473 g_slist_foreach (link->sink_pads, (GFunc) gst_parse_strfree, NULL);
474 g_slist_free (link->src_pads);
475 g_slist_free (link->sink_pads);
476 if (link->caps) gst_caps_unref (link->caps);
477 gst_parse_link_free (link);
481 gst_parse_free_delayed_link (DelayedLink *link)
483 g_free (link->src_pad);
484 g_free (link->sink_pad);
485 if (link->caps) gst_caps_unref (link->caps);
486 g_slice_free (DelayedLink, link);
490 gst_parse_found_pad (GstElement *src, GstPad *pad, gpointer data)
492 DelayedLink *link = data;
494 GST_CAT_INFO (GST_CAT_PIPELINE, "trying delayed linking %s:%s to %s:%s",
495 GST_STR_NULL (GST_ELEMENT_NAME (src)), GST_STR_NULL (link->src_pad),
496 GST_STR_NULL (GST_ELEMENT_NAME (link->sink)), GST_STR_NULL (link->sink_pad));
498 if (gst_element_link_pads_filtered (src, link->src_pad, link->sink,
499 link->sink_pad, link->caps)) {
500 /* do this here, we don't want to get any problems later on when
501 * unlocking states */
502 GST_CAT_DEBUG (GST_CAT_PIPELINE, "delayed linking %s:%s to %s:%s worked",
503 GST_STR_NULL (GST_ELEMENT_NAME (src)), GST_STR_NULL (link->src_pad),
504 GST_STR_NULL (GST_ELEMENT_NAME (link->sink)), GST_STR_NULL (link->sink_pad));
505 g_signal_handler_disconnect (src, link->signal_id);
509 /* both padnames and the caps may be NULL */
511 gst_parse_perform_delayed_link (GstElement *src, const gchar *src_pad,
512 GstElement *sink, const gchar *sink_pad,
515 GList *templs = gst_element_class_get_pad_template_list (
516 GST_ELEMENT_GET_CLASS (src));
518 for (; templs; templs = templs->next) {
519 GstPadTemplate *templ = (GstPadTemplate *) templs->data;
520 if ((GST_PAD_TEMPLATE_DIRECTION (templ) == GST_PAD_SRC) &&
521 (GST_PAD_TEMPLATE_PRESENCE(templ) == GST_PAD_SOMETIMES))
523 DelayedLink *data = g_slice_new (DelayedLink);
525 /* TODO: maybe we should check if src_pad matches this template's names */
527 GST_CAT_DEBUG (GST_CAT_PIPELINE, "trying delayed link %s:%s to %s:%s",
528 GST_STR_NULL (GST_ELEMENT_NAME (src)), GST_STR_NULL (src_pad),
529 GST_STR_NULL (GST_ELEMENT_NAME (sink)), GST_STR_NULL (sink_pad));
531 data->src_pad = g_strdup (src_pad);
533 data->sink_pad = g_strdup (sink_pad);
535 data->caps = gst_caps_copy (caps);
539 data->signal_id = g_signal_connect_data (src, "pad-added",
540 G_CALLBACK (gst_parse_found_pad), data,
541 (GClosureNotify) gst_parse_free_delayed_link, (GConnectFlags) 0);
549 * performs a link and frees the struct. src and sink elements must be given
550 * return values 0 - link performed
555 gst_parse_perform_link (link_t *link, graph_t *graph)
557 GstElement *src = link->src;
558 GstElement *sink = link->sink;
559 GSList *srcs = link->src_pads;
560 GSList *sinks = link->sink_pads;
561 g_assert (GST_IS_ELEMENT (src));
562 g_assert (GST_IS_ELEMENT (sink));
564 GST_CAT_INFO (GST_CAT_PIPELINE,
565 "linking %s:%s to %s:%s (%u/%u) with caps \"%" GST_PTR_FORMAT "\"",
566 GST_ELEMENT_NAME (src), link->src_name ? link->src_name : "(any)",
567 GST_ELEMENT_NAME (sink), link->sink_name ? link->sink_name : "(any)",
568 g_slist_length (srcs), g_slist_length (sinks), link->caps);
570 if (!srcs || !sinks) {
571 if (gst_element_link_pads_filtered (src,
572 srcs ? (const gchar *) srcs->data : NULL, sink,
573 sinks ? (const gchar *) sinks->data : NULL, link->caps)) {
576 if (gst_parse_perform_delayed_link (src,
577 srcs ? (const gchar *) srcs->data : NULL,
578 sink, sinks ? (const gchar *) sinks->data : NULL, link->caps)) {
585 if (g_slist_length (link->src_pads) != g_slist_length (link->sink_pads)) {
588 while (srcs && sinks) {
589 const gchar *src_pad = (const gchar *) srcs->data;
590 const gchar *sink_pad = (const gchar *) sinks->data;
591 srcs = g_slist_next (srcs);
592 sinks = g_slist_next (sinks);
593 if (gst_element_link_pads_filtered (src, src_pad, sink, sink_pad,
597 if (gst_parse_perform_delayed_link (src, src_pad,
608 gst_parse_free_link (link);
612 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK,
613 _("could not link %s to %s"), GST_ELEMENT_NAME (src),
614 GST_ELEMENT_NAME (sink));
615 gst_parse_free_link (link);
620 static int yyerror (void *scanner, graph_t *graph, const char *s);
633 %token <s> IDENTIFIER
634 %left <s> REF PADREF BINREF
635 %token <s> ASSIGNMENT
641 %type <l> linkpart link
644 %type <p> padlist pads assignments
651 %parse-param { void *scanner }
652 %parse-param { graph_t *graph }
658 element: IDENTIFIER { $$ = gst_element_factory_make ($1, NULL);
660 ADD_MISSING_ELEMENT (graph, $1);
661 SET_ERROR (graph->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT, _("no element \"%s\""), $1);
662 /* if FATAL_ERRORS flag is set, we don't have to worry about backwards
663 * compatibility and can continue parsing and check for other missing
665 if ((graph->flags & GST_PARSE_FLAG_FATAL_ERRORS) == 0) {
666 gst_parse_strfree ($1);
670 gst_parse_strfree ($1);
672 | element ASSIGNMENT { gst_parse_element_set ($2, $1, graph);
676 assignments: /* NOP */ { $$ = NULL; }
677 | assignments ASSIGNMENT { $$ = g_slist_prepend ($1, $2); }
679 bin: '(' assignments chain ')' { GST_BIN_MAKE ($$, "bin", $3, $2, no_free); }
680 | BINREF assignments chain ')' { GST_BIN_MAKE ($$, $1, $3, $2, gst_parse_strfree);
681 gst_parse_strfree ($1);
683 | BINREF assignments ')' { GST_BIN_MAKE ($$, $1, NULL, $2, gst_parse_strfree);
684 gst_parse_strfree ($1);
686 | BINREF assignments error ')' { GST_BIN_MAKE ($$, $1, NULL, $2, gst_parse_strfree);
687 gst_parse_strfree ($1);
691 pads: PADREF { $$ = g_slist_prepend (NULL, $1); }
692 | PADREF padlist { $$ = $2;
693 $$ = g_slist_prepend ($$, $1);
696 padlist: ',' IDENTIFIER { $$ = g_slist_prepend (NULL, $2); }
697 | ',' IDENTIFIER padlist { $$ = g_slist_prepend ($3, $2); }
700 reference: REF { MAKE_REF ($$, $1, NULL); }
701 | REF padlist { MAKE_REF ($$, $1, $2); }
704 linkpart: reference { $$ = $1; }
705 | pads { MAKE_REF ($$, NULL, $1); }
706 | /* NOP */ { MAKE_REF ($$, NULL, NULL); }
709 link: linkpart LINK linkpart { $$ = $1;
711 $$->caps = gst_caps_from_string ($2);
712 if ($$->caps == NULL)
713 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK, _("could not parse caps \"%s\""), $2);
714 gst_parse_strfree ($2);
716 $$->sink_name = $3->src_name;
717 $$->sink_pads = $3->src_pads;
718 gst_parse_link_free ($3);
722 linklist: link { $$ = g_slist_prepend (NULL, $1); }
723 | link linklist { $$ = g_slist_prepend ($2, $1); }
724 | linklist error { $$ = $1; }
727 chain: element { $$ = gst_parse_chain_new ();
728 $$->first = $$->last = $1;
729 $$->front = $$->back = NULL;
730 $$->elements = g_slist_prepend (NULL, $1);
733 | chain chain { if ($1->back && $2->front) {
734 if (!$1->back->sink_name) {
735 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK, _("link without source element"));
736 gst_parse_free_link ($1->back);
738 graph->links = g_slist_prepend (graph->links, $1->back);
740 if (!$2->front->src_name) {
741 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK, _("link without sink element"));
742 gst_parse_free_link ($2->front);
744 graph->links = g_slist_prepend (graph->links, $2->front);
747 } else if ($1->back) {
748 if (!$1->back->sink_name) {
749 $1->back->sink = $2->first;
751 } else if ($2->front) {
752 if (!$2->front->src_name) {
753 $2->front->src = $1->last;
755 $1->back = $2->front;
759 graph->links = g_slist_prepend (graph->links, $1->back);
763 $1->elements = g_slist_concat ($1->elements, $2->elements);
765 gst_parse_chain_free ($2);
768 | chain linklist { GSList *walk;
770 $2 = g_slist_prepend ($2, $1->back);
773 if (!((link_t *) $2->data)->src_name) {
774 ((link_t *) $2->data)->src = $1->last;
777 for (walk = $2; walk; walk = walk->next) {
778 link_t *link = (link_t *) walk->data;
779 if (!link->sink_name && walk->next) {
780 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK, _("link without sink element"));
781 gst_parse_free_link (link);
782 } else if (!link->src_name && !link->src) {
783 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK, _("link without source element"));
784 gst_parse_free_link (link);
787 graph->links = g_slist_prepend (graph->links, link);
796 | chain error { $$ = $1; }
797 | link chain { if ($2->front) {
798 if (!$2->front->src_name) {
799 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK, _("link without source element"));
800 gst_parse_free_link ($2->front);
802 graph->links = g_slist_prepend (graph->links, $2->front);
805 if (!$1->sink_name) {
806 $1->sink = $2->first;
811 | PARSE_URL chain { $$ = $2;
813 GstElement *element =
814 gst_element_make_from_uri (GST_URI_SRC, $1, NULL);
816 SET_ERROR (graph->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
817 _("no source element for URI \"%s\""), $1);
819 $$->front->src = element;
820 graph->links = g_slist_prepend (
821 graph->links, $$->front);
823 $$->elements = g_slist_prepend ($$->elements, element);
826 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK,
827 _("no element to link URI \"%s\" to"), $1);
831 | link PARSE_URL { GstElement *element =
832 gst_element_make_from_uri (GST_URI_SINK, $2, NULL);
834 SET_ERROR (graph->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
835 _("no sink element for URI \"%s\""), $2);
836 gst_parse_link_free ($1);
839 } else if ($1->sink_name || $1->sink_pads) {
840 gst_object_unref (element);
841 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK,
842 _("could not link sink element for URI \"%s\""), $2);
843 gst_parse_link_free ($1);
847 $$ = gst_parse_chain_new ();
848 $$->first = $$->last = element;
850 $$->front->sink = element;
851 $$->elements = g_slist_prepend (NULL, element);
856 graph: /* NOP */ { SET_ERROR (graph->error, GST_PARSE_ERROR_EMPTY, _("empty pipeline not allowed"));
859 | chain { $$ = graph;
861 if (!$1->front->src_name) {
862 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK, _("link without source element"));
863 gst_parse_free_link ($1->front);
865 $$->links = g_slist_prepend ($$->links, $1->front);
870 if (!$1->back->sink_name) {
871 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK, _("link without sink element"));
872 gst_parse_free_link ($1->back);
874 $$->links = g_slist_prepend ($$->links, $1->back);
886 yyerror (void *scanner, graph_t *graph, const char *s)
888 /* FIXME: This should go into the GError somehow, but how? */
889 GST_WARNING ("Error during parsing: %s", s);
895 priv_gst_parse_launch (const gchar *str, GError **error, GstParseContext *ctx,
905 g_return_val_if_fail (str != NULL, NULL);
906 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
914 #ifdef __GST_PARSE_TRACE
915 GST_CAT_DEBUG (GST_CAT_PIPELINE, "TRACE: tracing enabled");
916 __strings = __chains = __links = 0;
917 #endif /* __GST_PARSE_TRACE */
919 dstr = g_strdup (str);
920 priv_gst_parse_yylex_init (&scanner);
921 priv_gst_parse_yy_scan_string (dstr, scanner);
927 if (yyparse (scanner, &g) != 0) {
928 SET_ERROR (error, GST_PARSE_ERROR_SYNTAX,
929 "Unrecoverable syntax error while parsing pipeline %s", str);
931 priv_gst_parse_yylex_destroy (scanner);
936 priv_gst_parse_yylex_destroy (scanner);
939 GST_CAT_DEBUG (GST_CAT_PIPELINE, "got %u elements and %u links",
940 g.chain ? g_slist_length (g.chain->elements) : 0,
941 g_slist_length (g.links));
945 } else if (!g.chain->elements->next) {
946 /* only one toplevel element */
947 ret = (GstElement *) g.chain->elements->data;
948 g_slist_free (g.chain->elements);
949 if (GST_IS_BIN (ret))
951 gst_parse_chain_free (g.chain);
953 /* put all elements in our bin */
954 bin = GST_BIN (gst_element_factory_make ("pipeline", NULL));
957 for (walk = g.chain->elements; walk; walk = walk->next) {
958 if (walk->data != NULL)
959 gst_bin_add (bin, GST_ELEMENT (walk->data));
962 g_slist_free (g.chain->elements);
963 ret = GST_ELEMENT (bin);
964 gst_parse_chain_free (g.chain);
968 for (walk = g.links; walk; walk = walk->next) {
969 link_t *l = (link_t *) walk->data;
973 l->src = gst_bin_get_by_name_recurse_up (bin, l->src_name);
975 gst_object_unref (l->src);
977 l->src = strcmp (GST_ELEMENT_NAME (ret), l->src_name) == 0 ? ret : NULL;
982 SET_ERROR (error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
983 "No element named \"%s\" - omitting link", l->src_name);
985 /* probably a missing element which we've handled already */
987 gst_parse_free_link (l);
994 l->sink = gst_bin_get_by_name_recurse_up (bin, l->sink_name);
996 gst_object_unref (l->sink);
998 l->sink = strcmp (GST_ELEMENT_NAME (ret), l->sink_name) == 0 ? ret : NULL;
1003 SET_ERROR (error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
1004 "No element named \"%s\" - omitting link", l->sink_name);
1006 /* probably a missing element which we've handled already */
1008 gst_parse_free_link (l);
1012 gst_parse_perform_link (l, &g);
1014 g_slist_free (g.links);
1017 #ifdef __GST_PARSE_TRACE
1018 GST_CAT_DEBUG (GST_CAT_PIPELINE,
1019 "TRACE: %u strings, %u chains and %u links left", __strings, __chains,
1021 if (__strings || __chains || __links) {
1022 g_warning ("TRACE: %u strings, %u chains and %u links left", __strings,
1025 #endif /* __GST_PARSE_TRACE */
1031 g_slist_foreach (g.chain->elements, (GFunc)gst_object_unref, NULL);
1032 g_slist_free (g.chain->elements);
1033 gst_parse_chain_free (g.chain);
1036 g_slist_foreach (g.links, (GFunc)gst_parse_free_link, NULL);
1037 g_slist_free (g.links);