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"
16 #include "../gstutils.h"
17 #include "../gstvalue.h"
18 #include "../gstchildproxy.h"
21 /* All error messages in this file are user-visible and need to be translated.
22 * Don't start the message with a capital, and don't end them with a period,
23 * as they will be presented inside a sentence/error.
26 #define YYERROR_VERBOSE 1
27 #define YYLEX_PARAM scanner
29 typedef void* yyscan_t;
31 int _gst_parse_yylex (void * yylval_param , yyscan_t yyscanner);
32 int _gst_parse_yylex_init (yyscan_t scanner);
33 int _gst_parse_yylex_destroy (yyscan_t scanner);
34 struct yy_buffer_state * _gst_parse_yy_scan_string (char* , yyscan_t);
35 void _gst_parse_yypush_buffer_state (void * new_buffer ,yyscan_t yyscanner );
36 void _gst_parse_yypop_buffer_state (yyscan_t yyscanner );
39 #ifdef __GST_PARSE_TRACE
40 static guint __strings;
42 static guint __chains;
44 __gst_parse_strdup (gchar *org)
49 /* g_print ("ALLOCATED STR (%3u): %p %s\n", __strings, ret, ret); */
53 __gst_parse_strfree (gchar *str)
56 /* g_print ("FREEING STR (%3u): %p %s\n", __strings - 1, str, str); */
58 g_return_if_fail (__strings > 0);
62 link_t *__gst_parse_link_new ()
66 ret = g_new0 (link_t, 1);
67 /* g_print ("ALLOCATED LINK (%3u): %p\n", __links, ret); */
71 __gst_parse_link_free (link_t *data)
74 /* g_print ("FREEING LINK (%3u): %p\n", __links - 1, data); */
76 g_return_if_fail (__links > 0);
81 __gst_parse_chain_new ()
85 ret = g_new0 (chain_t, 1);
86 /* g_print ("ALLOCATED CHAIN (%3u): %p\n", __chains, ret); */
90 __gst_parse_chain_free (chain_t *data)
92 /* g_print ("FREEING CHAIN (%3u): %p\n", __chains - 1, data); */
94 g_return_if_fail (__chains > 0);
98 #endif /* __GST_PARSE_TRACE */
106 /* FIXME: need to connect to "disposed" signal to clean up,
107 * but there is no such signal */
110 /*** define SET_ERROR and ERROR macros/functions */
112 #ifdef G_HAVE_ISO_VARARGS
114 # define SET_ERROR(error, type, ...) \
116 GST_CAT_ERROR (GST_CAT_PIPELINE, __VA_ARGS__); \
117 if ((error) && !*(error)) { \
118 g_set_error ((error), GST_PARSE_ERROR, (type), __VA_ARGS__); \
122 # define ERROR(type, ...) \
123 SET_ERROR (((graph_t *) graph)->error, (type), __VA_ARGS__ )
125 #elif defined(G_HAVE_GNUC_VARARGS)
127 # define SET_ERROR(error, type, args...) \
129 GST_CAT_ERROR (GST_CAT_PIPELINE, args ); \
130 if ((error) && !*(error)) { \
131 g_set_error ((error), GST_PARSE_ERROR, (type), args ); \
135 # define ERROR(type, args...) \
136 SET_ERROR (((graph_t *) graph)->error,(type) , args )
141 SET_ERROR (GError **error, gint type, const char *format, ...)
145 g_warning ("error while parsing");
150 va_start (varargs, format);
151 string = g_strdup_vprintf (format, varargs);
154 g_set_error (error, GST_PARSE_ERROR, type, string);
161 #endif /* G_HAVE_ISO_VARARGS */
163 /*** define YYPRINTF macro/function if we're debugging */
165 /* bison 1.35 calls this macro with side effects, we need to make sure the
166 side effects work - crappy bison */
168 #ifndef GST_DISABLE_GST_DEBUG
171 # ifdef G_HAVE_ISO_VARARGS
173 /* # define YYFPRINTF(a, ...) GST_CAT_DEBUG (GST_CAT_PIPELINE, __VA_ARGS__) */
174 # define YYFPRINTF(a, ...) \
176 gchar *temp = g_strdup_printf (__VA_ARGS__); \
177 GST_CAT_LOG (GST_CAT_PIPELINE, temp); \
181 # elif defined(G_HAVE_GNUC_VARARGS)
183 # define YYFPRINTF(a, args...) \
185 gchar *temp = g_strdup_printf ( args ); \
186 GST_CAT_LOG (GST_CAT_PIPELINE, temp); \
193 YYPRINTF(const char *format, ...)
198 va_start (varargs, format);
199 temp = g_strdup_vprintf (format, varargs);
200 GST_CAT_LOG (GST_CAT_PIPELINE, "%s", temp);
205 # endif /* G_HAVE_ISO_VARARGS */
207 #endif /* GST_DISABLE_GST_DEBUG */
209 #define GST_BIN_MAKE(res, type, chainval, assign) \
211 chain_t *chain = chainval; \
213 GstBin *bin = (GstBin *) gst_element_factory_make (type, NULL); \
215 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_EMPTY_BIN, \
216 _("specified empty bin \"%s\", not allowed"), type); \
217 g_slist_foreach (assign, (GFunc) gst_parse_strfree, NULL); \
218 g_slist_free (assign); \
221 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT, \
222 _("no bin \"%s\", skipping"), type); \
223 g_slist_foreach (assign, (GFunc) gst_parse_strfree, NULL); \
224 g_slist_free (assign); \
227 for (walk = chain->elements; walk; walk = walk->next ) \
228 gst_bin_add (bin, GST_ELEMENT (walk->data)); \
229 g_slist_free (chain->elements); \
230 chain->elements = g_slist_prepend (NULL, bin); \
232 /* set the properties now */ \
233 for (walk = assign; walk; walk = walk->next) \
234 gst_parse_element_set ((gchar *) walk->data, GST_ELEMENT (bin), graph); \
235 g_slist_free (assign); \
239 #define MAKE_LINK(link, _src, _src_name, _src_pads, _sink, _sink_name, _sink_pads) \
241 link = gst_parse_link_new (); \
243 link->sink = _sink; \
244 link->src_name = _src_name; \
245 link->sink_name = _sink_name; \
246 link->src_pads = _src_pads; \
247 link->sink_pads = _sink_pads; \
251 #define MAKE_REF(link, _src, _pads) \
253 gchar *padname = _src; \
254 GSList *pads = _pads; \
256 while (*padname != '.') padname++; \
259 if (*padname != '\0') \
260 pads = g_slist_prepend (pads, gst_parse_strdup (padname)); \
262 MAKE_LINK (link, NULL, _src, pads, NULL, NULL, NULL); \
266 gst_parse_element_set (gchar *value, GstElement *element, graph_t *graph)
274 /* parse the string, so the property name is null-terminated an pos points
275 to the beginning of the value */
276 while (!g_ascii_isspace (*pos) && (*pos != '=')) pos++;
282 while (g_ascii_isspace (*pos)) pos++;
285 while (g_ascii_isspace (*pos)) pos++;
288 pos[strlen (pos) - 1] = '\0';
290 gst_parse_unescape (pos);
292 if (gst_child_proxy_lookup (GST_OBJECT (element), value, &target, &pspec)) {
293 value_type = G_PARAM_SPEC_VALUE_TYPE (pspec);
294 GST_LOG ("parsing property %s as a %s", pspec->name,
295 g_type_name (value_type));
296 g_value_init (&v, value_type);
297 if (!gst_value_deserialize (&v, pos))
299 g_object_set_property (G_OBJECT (target), pspec->name, &v);
300 gst_object_unref (target);
302 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_NO_SUCH_PROPERTY, \
303 _("no property \"%s\" in element \"%s\""), value, \
304 GST_ELEMENT_NAME (element));
308 gst_parse_strfree (value);
314 gst_object_unref (target);
315 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_COULD_NOT_SET_PROPERTY,
316 _("could not set property \"%s\" in element \"%s\" to \"%s\""),
317 value, GST_ELEMENT_NAME (element), pos);
321 gst_parse_free_link (link_t *link)
323 gst_parse_strfree (link->src_name);
324 gst_parse_strfree (link->sink_name);
325 g_slist_foreach (link->src_pads, (GFunc) gst_parse_strfree, NULL);
326 g_slist_foreach (link->sink_pads, (GFunc) gst_parse_strfree, NULL);
327 g_slist_free (link->src_pads);
328 g_slist_free (link->sink_pads);
329 if (link->caps) gst_caps_unref (link->caps);
330 gst_parse_link_free (link);
334 gst_parse_element_lock (GstElement *element, gboolean lock)
338 gboolean unlocked_peer = FALSE;
339 gboolean done = FALSE;
342 if (gst_element_is_locked_state (element) == lock)
347 /* check if we have an unlocked peer */
348 pads = gst_element_iterate_pads (element);
351 switch (gst_iterator_next (pads, &data)) {
352 case GST_ITERATOR_OK:
354 GstPad *pad = GST_PAD_CAST (data);
356 if (GST_PAD_IS_SINK (pad) && GST_PAD_PEER (pad) &&
357 !gst_element_is_locked_state (
358 GST_PAD_PARENT (GST_PAD_PEER (pad)))) {
359 unlocked_peer = TRUE;
362 gst_object_unref (GST_OBJECT (pad));
365 case GST_ITERATOR_RESYNC:
366 unlocked_peer = FALSE;
367 gst_iterator_resync (pads);
369 case GST_ITERATOR_DONE:
373 g_assert_not_reached ();
377 gst_iterator_free (pads);
379 if (!(lock && unlocked_peer)) {
380 GST_CAT_DEBUG (GST_CAT_PIPELINE, "setting locked state on element");
381 gst_element_set_locked_state (element, lock);
384 /* try to sync state with parent */
385 GST_CAT_DEBUG (GST_CAT_PIPELINE,
386 "trying to sync state of element with parent");
387 /* FIXME: it would be nice if we can figure out why it failed
388 (e.g. caps nego) and give an error about that instead. */
389 if (gst_element_set_state (element, GST_STATE_PLAYING)
390 == GST_STATE_CHANGE_FAILURE)
391 GST_ELEMENT_ERROR (element, CORE, STATE_CHANGE, (NULL), (NULL));
397 /* check if there are other pads to (un)lock */
398 walk = (GList *) element->pads;
399 for (; walk; walk = walk->next) {
400 pad = GST_PAD_CAST (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_STR_NULL (GST_ELEMENT_NAME (src)), GST_STR_NULL (link->src_pad),
415 GST_STR_NULL (GST_ELEMENT_NAME (link->sink)), GST_STR_NULL (link->sink_pad));
417 if (gst_element_link_pads_filtered (src, link->src_pad, link->sink,
418 link->sink_pad, link->caps)) {
419 /* do this here, we don't want to get any problems later on when
420 * unlocking states */
421 GST_CAT_DEBUG (GST_CAT_PIPELINE, "delayed linking %s:%s to %s:%s worked",
422 GST_STR_NULL (GST_ELEMENT_NAME (src)), GST_STR_NULL (link->src_pad),
423 GST_STR_NULL (GST_ELEMENT_NAME (link->sink)), GST_STR_NULL (link->sink_pad));
424 g_signal_handler_disconnect (src, link->signal_id);
425 g_free (link->src_pad);
426 g_free (link->sink_pad);
427 if (link->caps) gst_caps_unref (link->caps);
428 if (!gst_element_is_locked_state (src))
429 gst_parse_element_lock (link->sink, FALSE);
433 /* both padnames and the caps may be NULL */
435 gst_parse_perform_delayed_link (GstElement *src, const gchar *src_pad,
436 GstElement *sink, const gchar *sink_pad,
439 GList *templs = gst_element_class_get_pad_template_list (
440 GST_ELEMENT_GET_CLASS (src));
442 for (; templs; templs = templs->next) {
443 GstPadTemplate *templ = (GstPadTemplate *) templs->data;
444 if ((GST_PAD_TEMPLATE_DIRECTION (templ) == GST_PAD_SRC) &&
445 (GST_PAD_TEMPLATE_PRESENCE(templ) == GST_PAD_SOMETIMES))
447 DelayedLink *data = g_new (DelayedLink, 1);
449 /* TODO: maybe we should check if src_pad matches this template's names */
451 GST_CAT_DEBUG (GST_CAT_PIPELINE, "trying delayed link %s:%s to %s:%s",
452 GST_STR_NULL (GST_ELEMENT_NAME (src)), GST_STR_NULL (src_pad),
453 GST_STR_NULL (GST_ELEMENT_NAME (sink)), GST_STR_NULL (sink_pad));
455 data->src_pad = g_strdup (src_pad);
457 data->sink_pad = g_strdup (sink_pad);
459 data->caps = gst_caps_copy (caps);
463 data->signal_id = g_signal_connect (G_OBJECT (src), "pad-added",
464 G_CALLBACK (gst_parse_found_pad), data);
471 * performs a link and frees the struct. src and sink elements must be given
472 * return values 0 - link performed
477 gst_parse_perform_link (link_t *link, graph_t *graph)
479 GstElement *src = link->src;
480 GstElement *sink = link->sink;
481 GSList *srcs = link->src_pads;
482 GSList *sinks = link->sink_pads;
483 g_assert (GST_IS_ELEMENT (src));
484 g_assert (GST_IS_ELEMENT (sink));
486 GST_CAT_INFO (GST_CAT_PIPELINE,
487 "linking %s:%s to %s:%s (%u/%u) with caps \"%" GST_PTR_FORMAT "\"",
488 GST_ELEMENT_NAME (src), link->src_name ? link->src_name : "(any)",
489 GST_ELEMENT_NAME (sink), link->sink_name ? link->sink_name : "(any)",
490 g_slist_length (srcs), g_slist_length (sinks), link->caps);
492 if (!srcs || !sinks) {
493 if (gst_element_link_pads_filtered (src,
494 srcs ? (const gchar *) srcs->data : NULL, sink,
495 sinks ? (const gchar *) sinks->data : NULL, link->caps)) {
496 gst_parse_element_lock (sink, gst_element_is_locked_state (src));
499 if (gst_parse_perform_delayed_link (src,
500 srcs ? (const gchar *) srcs->data : NULL,
501 sink, sinks ? (const gchar *) sinks->data : NULL, link->caps)) {
502 gst_parse_element_lock (sink, TRUE);
509 if (g_slist_length (link->src_pads) != g_slist_length (link->src_pads)) {
512 while (srcs && sinks) {
513 const gchar *src_pad = (const gchar *) srcs->data;
514 const gchar *sink_pad = (const gchar *) sinks->data;
515 srcs = g_slist_next (srcs);
516 sinks = g_slist_next (sinks);
517 if (gst_element_link_pads_filtered (src, src_pad, sink, sink_pad,
519 gst_parse_element_lock (sink, gst_element_is_locked_state (src));
522 if (gst_parse_perform_delayed_link (src, src_pad,
525 gst_parse_element_lock (sink, TRUE);
534 gst_parse_free_link (link);
538 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK,
539 _("could not link %s to %s"), GST_ELEMENT_NAME (src),
540 GST_ELEMENT_NAME (sink));
541 gst_parse_free_link (link);
546 static int yyerror (graph_t *graph, const char *s);
559 %token <s> IDENTIFIER
560 %left <s> REF PADREF BINREF
561 %token <s> ASSIGNMENT
567 %type <l> linkpart link
570 %type <p> padlist pads assignments
577 %parse-param { void *scanner, graph_t *graph }
583 element: IDENTIFIER { $$ = gst_element_factory_make ($1, NULL);
585 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT, _("no element \"%s\""), $1);
586 gst_parse_strfree ($1);
589 gst_parse_strfree ($1);
591 | element ASSIGNMENT { gst_parse_element_set ($2, $1, graph);
595 assignments: /* NOP */ { $$ = NULL; }
596 | assignments ASSIGNMENT { $$ = g_slist_prepend ($1, $2); }
598 bin: '(' assignments chain ')' { GST_BIN_MAKE ($$, "bin", $3, $2); }
599 | BINREF assignments chain ')' { GST_BIN_MAKE ($$, $1, $3, $2);
600 gst_parse_strfree ($1);
602 | BINREF assignments ')' { GST_BIN_MAKE ($$, $1, NULL, $2);
603 gst_parse_strfree ($1);
605 | BINREF assignments error ')' { GST_BIN_MAKE ($$, $1, NULL, $2);
606 gst_parse_strfree ($1);
610 pads: PADREF { $$ = g_slist_prepend (NULL, $1); }
611 | PADREF padlist { $$ = $2;
612 $$ = g_slist_prepend ($$, $1);
615 padlist: ',' IDENTIFIER { $$ = g_slist_prepend (NULL, $2); }
616 | ',' IDENTIFIER padlist { $$ = g_slist_prepend ($3, $2); }
619 reference: REF { MAKE_REF ($$, $1, NULL); }
620 | REF padlist { MAKE_REF ($$, $1, $2); }
623 linkpart: reference { $$ = $1; }
624 | pads { MAKE_REF ($$, NULL, $1); }
625 | /* NOP */ { MAKE_REF ($$, NULL, NULL); }
628 link: linkpart LINK linkpart { $$ = $1;
630 $$->caps = gst_caps_from_string ($2);
631 if ($$->caps == NULL)
632 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("could not parse caps \"%s\""), $2);
633 gst_parse_strfree ($2);
635 $$->sink_name = $3->src_name;
636 $$->sink_pads = $3->src_pads;
637 gst_parse_link_free ($3);
641 linklist: link { $$ = g_slist_prepend (NULL, $1); }
642 | link linklist { $$ = g_slist_prepend ($2, $1); }
643 | linklist error { $$ = $1; }
646 chain: element { $$ = gst_parse_chain_new ();
647 $$->first = $$->last = $1;
648 $$->front = $$->back = NULL;
649 $$->elements = g_slist_prepend (NULL, $1);
652 | chain chain { if ($1->back && $2->front) {
653 if (!$1->back->sink_name) {
654 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("link without source element"));
655 gst_parse_free_link ($1->back);
657 ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, $1->back);
659 if (!$2->front->src_name) {
660 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("link without sink element"));
661 gst_parse_free_link ($2->front);
663 ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, $2->front);
666 } else if ($1->back) {
667 if (!$1->back->sink_name) {
668 $1->back->sink = $2->first;
670 } else if ($2->front) {
671 if (!$2->front->src_name) {
672 $2->front->src = $1->last;
674 $1->back = $2->front;
678 ((graph_t *) graph)->links = g_slist_prepend (((graph_t *) graph)->links, $1->back);
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);
755 gst_parse_link_free ($1);
758 } else if ($1->sink_name || $1->sink_pads) {
759 gst_object_unref (element);
760 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK,
761 _("could not link sink element for URI \"%s\""), $2);
762 gst_parse_link_free ($1);
766 $$ = gst_parse_chain_new ();
767 $$->first = $$->last = element;
769 $$->front->sink = element;
770 $$->elements = g_slist_prepend (NULL, element);
775 graph: /* NOP */ { SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_EMPTY, _("empty pipeline not allowed"));
776 $$ = (graph_t *) graph;
778 | chain { $$ = (graph_t *) graph;
780 if (!$1->front->src_name) {
781 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("link without source element"));
782 gst_parse_free_link ($1->front);
784 $$->links = g_slist_prepend ($$->links, $1->front);
789 if (!$1->back->sink_name) {
790 SET_ERROR (((graph_t *) graph)->error, GST_PARSE_ERROR_LINK, _("link without sink element"));
791 gst_parse_free_link ($1->back);
793 $$->links = g_slist_prepend ($$->links, $1->back);
805 yyerror (graph_t *graph, const char *s)
807 /* FIXME: This should go into the GError somehow, but how? */
808 GST_WARNING ("Error during parsing: %s", s);
814 _gst_parse_launch (const gchar *str, GError **error)
823 g_return_val_if_fail (str != NULL, NULL);
829 #ifdef __GST_PARSE_TRACE
830 GST_CAT_DEBUG (GST_CAT_PIPELINE, "TRACE: tracing enabled");
831 __strings = __chains = __links = 0;
832 #endif /* __GST_PARSE_TRACE */
834 dstr = g_strdup (str);
835 _gst_parse_yylex_init( &scanner );
836 _gst_parse_yy_scan_string (dstr, scanner);
842 if (yyparse (scanner, &g) != 0) {
843 SET_ERROR (error, GST_PARSE_ERROR_SYNTAX,
844 "Unrecoverable syntax error while parsing pipeline %s", str);
848 _gst_parse_yylex_destroy( scanner );
851 GST_CAT_DEBUG (GST_CAT_PIPELINE, "got %u elements and %u links",
852 g.chain ? g_slist_length (g.chain->elements) : 0,
853 g_slist_length (g.links));
857 } else if (!(((chain_t *) g.chain)->elements->next)) {
858 /* only one toplevel element */
859 ret = (GstElement *) ((chain_t *) g.chain)->elements->data;
860 g_slist_free (((chain_t *) g.chain)->elements);
861 if (GST_IS_BIN (ret))
863 gst_parse_chain_free (g.chain);
865 /* put all elements in our bin */
866 bin = GST_BIN (gst_element_factory_make ("pipeline", NULL));
869 for (walk = g.chain->elements; walk; walk = walk->next) {
870 if (walk->data != NULL)
871 gst_bin_add (bin, GST_ELEMENT (walk->data));
874 g_slist_free (g.chain->elements);
875 ret = GST_ELEMENT (bin);
876 gst_parse_chain_free (g.chain);
880 for (walk = g.links; walk; walk = walk->next) {
881 link_t *l = (link_t *) walk->data;
885 l->src = gst_bin_get_by_name_recurse_up (bin, l->src_name);
887 gst_object_unref (l->src);
889 l->src = strcmp (GST_ELEMENT_NAME (ret), l->src_name) == 0 ? ret : NULL;
893 SET_ERROR (error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
894 "No element named \"%s\" - omitting link", l->src_name);
895 gst_parse_free_link (l);
902 l->sink = gst_bin_get_by_name_recurse_up (bin, l->sink_name);
904 gst_object_unref (l->sink);
906 l->sink = strcmp (GST_ELEMENT_NAME (ret), l->sink_name) == 0 ? ret : NULL;
910 SET_ERROR (error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
911 "No element named \"%s\" - omitting link", l->sink_name);
912 gst_parse_free_link (l);
916 gst_parse_perform_link (l, &g);
918 g_slist_free (g.links);
921 #ifdef __GST_PARSE_TRACE
922 GST_CAT_DEBUG (GST_CAT_PIPELINE,
923 "TRACE: %u strings, %u chains and %u links left", __strings, __chains,
925 if (__strings || __chains || __links) {
926 g_warning ("TRACE: %u strings, %u chains and %u links left", __strings,
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);