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
30 #define YYENABLE_NLS 0
32 #ifndef YYLTYPE_IS_TRIVIAL
33 #define YYLTYPE_IS_TRIVIAL 0
36 /*******************************************************************************************
37 *** Tracing memory leaks
38 *******************************************************************************************/
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 (void)
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 (void)
86 ret = g_slice_new0 (chain_t);
87 /* g_print ("@%p: ALLOCATED CHAIN (%3u):\n", ret, __chains); */
91 __gst_parse_chain_free (chain_t *data)
93 /* g_print ("@%p: FREEING CHAIN (%3u):\n", data, __chains - 1); */
94 g_slice_free (chain_t, data);
95 g_return_if_fail (__chains > 0);
99 #endif /* __GST_PARSE_TRACE */
101 /*******************************************************************************************
102 *** define SET_ERROR macro/function
103 *******************************************************************************************/
104 #ifdef G_HAVE_ISO_VARARGS
106 # define SET_ERROR(error, type, ...) \
108 GST_CAT_ERROR (GST_CAT_PIPELINE, __VA_ARGS__); \
109 if ((error) && !*(error)) { \
110 g_set_error ((error), GST_PARSE_ERROR, (type), __VA_ARGS__); \
114 #elif defined(G_HAVE_GNUC_VARARGS)
116 # define SET_ERROR(error, type, args...) \
118 GST_CAT_ERROR (GST_CAT_PIPELINE, args ); \
119 if ((error) && !*(error)) { \
120 g_set_error ((error), GST_PARSE_ERROR, (type), args ); \
127 SET_ERROR (GError **error, gint type, const char *format, ...)
131 g_warning ("error while parsing");
136 va_start (varargs, format);
137 string = g_strdup_vprintf (format, varargs);
140 g_set_error (error, GST_PARSE_ERROR, type, string);
147 #endif /* G_HAVE_ISO_VARARGS */
149 /*** define YYPRINTF macro/function if we're debugging */
151 /* bison 1.35 calls this macro with side effects, we need to make sure the
152 side effects work - crappy bison */
154 #ifndef GST_DISABLE_GST_DEBUG
157 # ifdef G_HAVE_ISO_VARARGS
159 /* # define YYFPRINTF(a, ...) GST_CAT_DEBUG (GST_CAT_PIPELINE, __VA_ARGS__) */
160 # define YYFPRINTF(a, ...) \
162 GST_CAT_LOG (GST_CAT_PIPELINE, __VA_ARGS__); \
165 # elif defined(G_HAVE_GNUC_VARARGS)
167 # define YYFPRINTF(a, args...) \
169 GST_CAT_LOG (GST_CAT_PIPELINE, args); \
175 YYPRINTF(const char *format, ...)
180 va_start (varargs, format);
181 temp = g_strdup_vprintf (format, varargs);
182 GST_CAT_LOG (GST_CAT_PIPELINE, "%s", temp);
187 # endif /* G_HAVE_ISO_VARARGS */
189 #endif /* GST_DISABLE_GST_DEBUG */
193 * include headers generated by bison & flex, after defining (or not defining) YYDEBUG
195 #include "grammar.tab.h"
196 #include "parse_lex.h"
198 /*******************************************************************************************
199 *** report missing elements/bins/..
200 *******************************************************************************************/
203 static void add_missing_element(graph_t *graph,gchar *name){
205 (graph)->ctx->missing_elements = g_list_append ((graph)->ctx->missing_elements, g_strdup (name));
210 /*******************************************************************************************
211 *** helpers for pipeline-setup
212 *******************************************************************************************/
214 #define TRY_SETUP_LINK(l) G_STMT_START { \
215 if( (!(l)->src.element) && (!(l)->src.name) ){ \
216 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK, _("link has no source [sink=%s@%p]"), \
217 (l)->sink.name ? (l)->sink.name : _(""), \
218 (l)->sink.element); \
219 gst_parse_free_link (l); \
220 }else if( (!(l)->sink.element) && (!(l)->sink.name) ){ \
221 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK, _("link has no sink [source=%s@%p]"), \
222 (l)->src.name ? (l)->src.name :_(""), \
224 gst_parse_free_link (l); \
226 graph->links = g_slist_prepend (graph->links, l ); \
244 static int gst_resolve_reference(reference_t *rr, GstElement *pipeline){
247 if(rr->element) return 0; /* already resolved! */
248 if(!rr->name) return -2; /* no chance! */
250 if (GST_IS_BIN (pipeline)){
251 bin = GST_BIN (pipeline);
252 rr->element = gst_bin_get_by_name_recurse_up (bin, rr->name);
254 rr->element = strcmp (GST_ELEMENT_NAME (pipeline), rr->name) == 0 ?
255 gst_object_ref(pipeline) : NULL;
257 if(rr->element) return 0; /* resolved */
258 else return -1; /* not found */
261 static void gst_parse_free_delayed_set (DelayedSet *set)
264 g_free(set->value_str);
265 g_slice_free(DelayedSet, set);
268 static void gst_parse_new_child(GstChildProxy *child_proxy, GObject *object,
269 const gchar * name, gpointer data);
271 static void gst_parse_add_delayed_set (GstElement *element, gchar *name, gchar *value_str)
273 DelayedSet *data = g_slice_new0 (DelayedSet);
275 GST_CAT_LOG_OBJECT (GST_CAT_PIPELINE, element, "delaying property set %s to %s",
278 data->name = g_strdup(name);
279 data->value_str = g_strdup(value_str);
280 data->signal_id = g_signal_connect_data(element, "child-added",
281 G_CALLBACK (gst_parse_new_child), data, (GClosureNotify)
282 gst_parse_free_delayed_set, (GConnectFlags) 0);
284 /* FIXME: we would need to listen on all intermediate bins too */
285 if (GST_IS_BIN (element)) {
286 gchar **names, **current;
287 GstElement *parent, *child;
289 current = names = g_strsplit (name, "::", -1);
290 parent = gst_bin_get_by_name (GST_BIN_CAST (element), current[0]);
292 while (parent && current[0]) {
293 child = gst_bin_get_by_name (GST_BIN (parent), current[0]);
294 if (!child && current[1]) {
295 char *sub_name = g_strjoinv ("::", ¤t[0]);
297 gst_parse_add_delayed_set(parent, sub_name, value_str);
307 static void gst_parse_new_child(GstChildProxy *child_proxy, GObject *object,
308 const gchar * name, gpointer data)
310 DelayedSet *set = (DelayedSet *) data;
313 GObject *target = NULL;
316 GST_CAT_LOG_OBJECT (GST_CAT_PIPELINE, child_proxy, "new child %s, checking property %s",
319 if (gst_child_proxy_lookup (child_proxy, set->name, &target, &pspec)) {
320 gboolean got_value = FALSE;
322 value_type = pspec->value_type;
324 GST_CAT_LOG_OBJECT (GST_CAT_PIPELINE, child_proxy, "parsing delayed property %s as a %s from %s",
325 pspec->name, g_type_name (value_type), set->value_str);
326 g_value_init (&v, value_type);
327 if (gst_value_deserialize (&v, set->value_str))
329 else if (g_type_is_a (value_type, GST_TYPE_ELEMENT)) {
332 bin = gst_parse_bin_from_description_full (set->value_str, TRUE, NULL,
333 GST_PARSE_FLAG_NO_SINGLE_ELEMENT_BINS, NULL);
335 g_value_set_object (&v, bin);
339 g_signal_handler_disconnect (child_proxy, set->signal_id);
342 g_object_set_property (target, pspec->name, &v);
344 const gchar *obj_name = GST_OBJECT_NAME(object);
345 gint len = strlen (obj_name);
347 /* do a delayed set */
348 if ((strlen (set->name) > (len + 2)) && !strncmp (set->name, obj_name, len) && !strncmp (&set->name[len], "::", 2)) {
349 gst_parse_add_delayed_set (GST_ELEMENT(child_proxy), set->name, set->value_str);
357 g_object_unref (target);
361 GST_CAT_ERROR (GST_CAT_PIPELINE, "could not set property \"%s\" in %"
362 GST_PTR_FORMAT, pspec->name, target);
366 static void gst_parse_element_set (gchar *value, GstElement *element, graph_t *graph)
368 GParamSpec *pspec = NULL;
371 GObject *target = NULL;
374 /* do nothing if assignment is for missing element */
378 /* parse the string, so the property name is null-terminated and pos points
379 to the beginning of the value */
380 while (!g_ascii_isspace (*pos) && (*pos != '=')) pos++;
386 while (g_ascii_isspace (*pos)) pos++;
389 while (g_ascii_isspace (*pos)) pos++;
392 pos[strlen (pos) - 1] = '\0';
394 gst_parse_unescape (pos);
396 if (GST_IS_CHILD_PROXY (element)) {
397 if (!gst_child_proxy_lookup (GST_CHILD_PROXY (element), value, &target, &pspec)) {
398 /* do a delayed set */
399 gst_parse_add_delayed_set (element, value, pos);
402 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (element), value);
404 target = g_object_ref (element);
405 GST_CAT_LOG_OBJECT (GST_CAT_PIPELINE, target, "found %s property", value);
407 SET_ERROR (graph->error, GST_PARSE_ERROR_NO_SUCH_PROPERTY, \
408 _("no property \"%s\" in element \"%s\""), value, \
409 GST_ELEMENT_NAME (element));
413 if (pspec != NULL && target != NULL) {
414 gboolean got_value = FALSE;
416 value_type = pspec->value_type;
418 GST_CAT_LOG_OBJECT (GST_CAT_PIPELINE, element, "parsing property %s as a %s",
419 pspec->name, g_type_name (value_type));
421 g_value_init (&v, value_type);
422 if (gst_value_deserialize (&v, pos))
424 else if (g_type_is_a (value_type, GST_TYPE_ELEMENT)) {
427 bin = gst_parse_bin_from_description_full (pos, TRUE, NULL,
428 GST_PARSE_FLAG_NO_SINGLE_ELEMENT_BINS, NULL);
430 g_value_set_object (&v, bin);
436 g_object_set_property (target, pspec->name, &v);
440 gst_parse_strfree (value);
444 g_object_unref (target);
448 SET_ERROR (graph->error, GST_PARSE_ERROR_COULD_NOT_SET_PROPERTY,
449 _("could not set property \"%s\" in element \"%s\" to \"%s\""),
450 value, GST_ELEMENT_NAME (element), pos);
454 static void gst_parse_free_reference (reference_t *rr)
456 if(rr->element) gst_object_unref(rr->element);
457 gst_parse_strfree (rr->name);
458 g_slist_foreach (rr->pads, (GFunc) gst_parse_strfree, NULL);
459 g_slist_free (rr->pads);
462 static void gst_parse_free_link (link_t *link)
464 gst_parse_free_reference (&(link->src));
465 gst_parse_free_reference (&(link->sink));
466 if (link->caps) gst_caps_unref (link->caps);
467 gst_parse_link_free (link);
470 static void gst_parse_free_chain (chain_t *ch)
473 gst_parse_free_reference (&(ch->first));
474 gst_parse_free_reference (&(ch->last));
475 for(walk=ch->elements;walk;walk=walk->next)
476 gst_object_unref (walk->data);
477 g_slist_free (ch->elements);
478 gst_parse_chain_free (ch);
481 static void 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);
489 static void gst_parse_found_pad (GstElement *src, GstPad *pad, gpointer data)
491 DelayedLink *link = data;
493 GST_CAT_INFO (GST_CAT_PIPELINE, "trying delayed linking %s:%s to %s:%s",
494 GST_STR_NULL (GST_ELEMENT_NAME (src)), GST_STR_NULL (link->src_pad),
495 GST_STR_NULL (GST_ELEMENT_NAME (link->sink)), GST_STR_NULL (link->sink_pad));
497 if (gst_element_link_pads_filtered (src, link->src_pad, link->sink,
498 link->sink_pad, link->caps)) {
499 /* do this here, we don't want to get any problems later on when
500 * unlocking states */
501 GST_CAT_DEBUG (GST_CAT_PIPELINE, "delayed linking %s:%s to %s:%s worked",
502 GST_STR_NULL (GST_ELEMENT_NAME (src)), GST_STR_NULL (link->src_pad),
503 GST_STR_NULL (GST_ELEMENT_NAME (link->sink)), GST_STR_NULL (link->sink_pad));
504 g_signal_handler_disconnect (src, link->signal_id);
508 /* both padnames and the caps may be NULL */
510 gst_parse_perform_delayed_link (GstElement *src, const gchar *src_pad,
511 GstElement *sink, const gchar *sink_pad,
514 GList *templs = gst_element_class_get_pad_template_list (
515 GST_ELEMENT_GET_CLASS (src));
517 for (; templs; templs = templs->next) {
518 GstPadTemplate *templ = (GstPadTemplate *) templs->data;
519 if ((GST_PAD_TEMPLATE_DIRECTION (templ) == GST_PAD_SRC) &&
520 (GST_PAD_TEMPLATE_PRESENCE(templ) == GST_PAD_SOMETIMES))
522 DelayedLink *data = g_slice_new (DelayedLink);
524 /* TODO: maybe we should check if src_pad matches this template's names */
526 GST_CAT_DEBUG (GST_CAT_PIPELINE, "trying delayed link %s:%s to %s:%s",
527 GST_STR_NULL (GST_ELEMENT_NAME (src)), GST_STR_NULL (src_pad),
528 GST_STR_NULL (GST_ELEMENT_NAME (sink)), GST_STR_NULL (sink_pad));
530 data->src_pad = g_strdup (src_pad);
532 data->sink_pad = g_strdup (sink_pad);
534 data->caps = gst_caps_copy (caps);
538 data->signal_id = g_signal_connect_data (src, "pad-added",
539 G_CALLBACK (gst_parse_found_pad), data,
540 (GClosureNotify) gst_parse_free_delayed_link, (GConnectFlags) 0);
548 * performs a link and frees the struct. src and sink elements must be given
549 * return values 0 - link performed
554 gst_parse_perform_link (link_t *link, graph_t *graph)
556 GstElement *src = link->src.element;
557 GstElement *sink = link->sink.element;
558 GSList *srcs = link->src.pads;
559 GSList *sinks = link->sink.pads;
560 g_assert (GST_IS_ELEMENT (src));
561 g_assert (GST_IS_ELEMENT (sink));
563 GST_CAT_INFO (GST_CAT_PIPELINE,
564 "linking %s:%s to %s:%s (%u/%u) with caps \"%" GST_PTR_FORMAT "\"",
565 GST_ELEMENT_NAME (src), link->src.name ? link->src.name : "(any)",
566 GST_ELEMENT_NAME (sink), link->sink.name ? link->sink.name : "(any)",
567 g_slist_length (srcs), g_slist_length (sinks), link->caps);
569 if (!srcs || !sinks) {
570 if (gst_element_link_pads_filtered (src,
571 srcs ? (const gchar *) srcs->data : NULL, sink,
572 sinks ? (const gchar *) sinks->data : NULL, link->caps)) {
575 if (gst_parse_perform_delayed_link (src,
576 srcs ? (const gchar *) srcs->data : NULL,
577 sink, sinks ? (const gchar *) sinks->data : NULL, link->caps)) {
584 if (g_slist_length (link->src.pads) != g_slist_length (link->sink.pads)) {
587 while (srcs && sinks) {
588 const gchar *src_pad = (const gchar *) srcs->data;
589 const gchar *sink_pad = (const gchar *) sinks->data;
590 srcs = g_slist_next (srcs);
591 sinks = g_slist_next (sinks);
592 if (gst_element_link_pads_filtered (src, src_pad, sink, sink_pad,
596 if (gst_parse_perform_delayed_link (src, src_pad,
607 gst_parse_free_link (link);
611 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK,
612 _("could not link %s to %s"), GST_ELEMENT_NAME (src),
613 GST_ELEMENT_NAME (sink));
614 gst_parse_free_link (link);
619 static int yyerror (void *scanner, graph_t *graph, const char *s);
632 %token <ss> PARSE_URL
633 %token <ss> IDENTIFIER
634 %left <ss> REF PADREF BINREF
635 %token <ss> ASSIGNMENT
640 %type <cc> chain bin chainlist openchain elementary
644 %type <pp> morepads pads assignments
646 %destructor { gst_parse_strfree ($$); } <ss>
647 %destructor { gst_parse_free_chain($$); } <cc>
648 %destructor { gst_parse_free_link ($$); } <ll>
649 %destructor { gst_parse_free_reference(&($$));} <rr>
650 %destructor { gst_object_unref ($$); } <ee>
651 %destructor { GSList *walk;
652 for(walk=$$;walk;walk=walk->next)
653 gst_parse_strfree (walk->data);
654 g_slist_free ($$); } <pp>
663 %lex-param { void *scanner }
664 %parse-param { void *scanner }
665 %parse-param { graph_t *graph }
671 /*************************************************************
672 * Grammar explanation:
673 * _element_s are specified by an identifier of their type.
674 * a name can be give in the optional property-assignments
677 * identity silence=false name=frodo
679 **************************************************************/
680 element: IDENTIFIER { $$ = gst_element_factory_make ($1, NULL);
682 add_missing_element(graph, $1);
683 SET_ERROR (graph->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT, _("no element \"%s\""), $1);
685 gst_parse_strfree ($1);
687 | element ASSIGNMENT { gst_parse_element_set ($2, $1, graph);
692 /*************************************************************
693 * Grammar explanation: (cont'd)
694 * a graph has (pure) _element_s, _bin_s and _link_s.
695 * since bins are special elements, bins and elements can
696 * be generalized as _elementary_.
697 * The construction of _bin_s will be discussed later.
700 **************************************************************/
702 element { $$ = gst_parse_chain_new ();
703 /* g_print ("@%p: CHAINing elementary\n", $$); */
704 $$->first.element = $1? gst_object_ref($1) : NULL;
705 $$->last.element = $1? gst_object_ref($1) : NULL;
706 $$->first.name = $$->last.name = NULL;
707 $$->first.pads = $$->last.pads = NULL;
708 $$->elements = $1 ? g_slist_prepend (NULL, $1) : NULL;
713 /*************************************************************
714 * Grammar explanation: (cont'd)
715 * a _chain_ is a list of _elementary_s that have _link_s inbetween
716 * which are represented through infix-notation.
718 * fakesrc ! sometransformation ! fakesink
720 * every _link_ can be augmented with _pads_.
722 * coffeesrc .sound ! speakersink
723 * multisrc .movie,ads ! .projector,smallscreen multisink
725 * and every _link_ can be setup to filter media-types
726 * mediasrc ! audio/x-raw, signed=TRUE ! stereosink
729 * if the lexer does not recognize your media-type it
730 * will make it an element name. that results in errors
732 * NO SUCH ELEMENT: no element audio7x-raw
733 * '7' vs. '/' in https://en.wikipedia.org/wiki/QWERTZ
736 * in the parser we need to differ between chains that can
737 * be extended by more elementaries (_openchain_) and others
738 * that are syntactically closed (handled later in this file).
739 * (e.g. fakesrc ! sinkreferencename.padname)
740 **************************************************************/
741 chain: openchain { $$=$1;
743 SET_ERROR (graph->error, GST_PARSE_ERROR_SYNTAX,
744 _("unexpected reference \"%s\" - ignoring"), $$->last.name);
745 gst_parse_strfree($$->last.name);
749 SET_ERROR (graph->error, GST_PARSE_ERROR_SYNTAX,
750 _("unexpected pad-reference \"%s\" - ignoring"), (gchar*)$$->last.pads->data);
751 g_slist_foreach ($$->last.pads, (GFunc) gst_parse_strfree, NULL);
752 g_slist_free ($$->last.pads);
759 elementary pads { $$=$1;
760 $$->last.pads = g_slist_concat ($$->last.pads, $2);
761 /* g_print ("@%p@%p: FKI elementary pads\n", $1, $$->last.pads); */
763 | openchain link pads elementary pads
766 $2->sink = $4->first;
767 $2->sink.pads = g_slist_concat ($3, $2->sink.pads);
769 $4->first = $1->first;
770 $4->elements = g_slist_concat ($1->elements, $4->elements);
771 gst_parse_chain_free($1);
773 $$->last.pads = g_slist_concat ($$->last.pads, $5);
778 link: LINK { $$ = gst_parse_link_new ();
779 $$->src.element = NULL;
780 $$->sink.element = NULL;
782 $$->sink.name = NULL;
784 $$->sink.pads = NULL;
787 $$->caps = gst_caps_from_string ($1);
788 if ($$->caps == NULL)
789 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK, _("could not parse caps \"%s\""), $1);
790 gst_parse_strfree ($1);
794 pads: /* NOP */ { $$ = NULL; }
795 | PADREF morepads { $$ = $2;
796 $$ = g_slist_prepend ($$, $1);
799 morepads: /* NOP */ { $$ = NULL; }
800 | ',' IDENTIFIER morepads { $$ = g_slist_prepend ($3, $2); }
803 /*************************************************************
804 * Grammar explanation: (cont'd)
805 * the first and last elements of a _chain_ can be give
806 * as URL. This creates special elements that fit the URL.
808 * fakesrc ! http://fake-sink.org
809 * http://somesource.org ! fakesink
810 **************************************************************/
812 chain: openchain link PARSE_URL { GstElement *element =
813 gst_element_make_from_uri (GST_URI_SINK, $3, NULL, NULL);
814 /* FIXME: get and parse error properly */
816 SET_ERROR (graph->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
817 _("no sink element for URI \"%s\""), $3);
820 $2->sink.element = element?gst_object_ref(element):NULL;
823 $$->last.element = NULL;
824 $$->last.name = NULL;
825 $$->last.pads = NULL;
826 if(element) $$->elements = g_slist_append ($$->elements, element);
831 PARSE_URL { GstElement *element =
832 gst_element_make_from_uri (GST_URI_SRC, $1, NULL, NULL);
833 /* FIXME: get and parse error properly */
835 SET_ERROR (graph->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
836 _("no source element for URI \"%s\""), $1);
838 $$ = gst_parse_chain_new ();
839 /* g_print ("@%p: CHAINing srcURL\n", $$); */
840 $$->first.element = NULL;
841 $$->first.name = NULL;
842 $$->first.pads = NULL;
843 $$->last.element = element ? gst_object_ref(element):NULL;
844 $$->last.name = NULL;
845 $$->last.pads = NULL;
846 $$->elements = element ? g_slist_prepend (NULL, element) : NULL;
852 /*************************************************************
853 * Grammar explanation: (cont'd)
854 * the first and last elements of a _chain_ can be linked
855 * to a named _reference_ (with optional pads).
857 * fakesrc ! nameOfSinkElement.
858 * fakesrc ! nameOfSinkElement.Padname
859 * fakesrc ! nameOfSinkElement.Padname, anotherPad
860 * nameOfSource.Padname ! fakesink
861 **************************************************************/
863 chain: openchain link reference { $$ = $1;
867 $$->last.element = NULL;
868 $$->last.name = NULL;
869 $$->last.pads = NULL;
875 reference { $$ = gst_parse_chain_new ();
877 $$->first.element = NULL;
878 $$->first.name = NULL;
879 $$->first.pads = NULL;
883 reference: REF morepads {
887 while (*padname != '.') padname++;
890 if (*padname != '\0')
891 pads = g_slist_prepend (pads, gst_parse_strdup (padname));
900 /*************************************************************
901 * Grammar explanation: (cont'd)
902 * a _chainlist_ is just a list of _chain_s.
904 * You can specify _link_s with named
905 * _reference_ on each side. That
906 * works already after the explanations above.
907 * someSourceName.Pad ! someSinkName.
908 * someSourceName.Pad,anotherPad ! someSinkName.Apad,Bpad
910 * If a syntax error occurs, the already finished _chain_s
911 * and _links_ are kept intact.
912 *************************************************************/
914 chainlist: /* NOP */ { $$ = NULL; }
915 | chainlist chain { if ($1){
916 gst_parse_free_reference(&($1->last));
917 gst_parse_free_reference(&($2->first));
918 $2->first = $1->first;
919 $2->elements = g_slist_concat ($1->elements, $2->elements);
920 gst_parse_chain_free ($1);
924 | chainlist error { $$=$1;
925 GST_CAT_DEBUG (GST_CAT_PIPELINE,"trying to recover from syntax error");
926 SET_ERROR (graph->error, GST_PARSE_ERROR_SYNTAX, _("syntax error"));
930 /*************************************************************
931 * Grammar explanation: (cont'd)
933 *************************************************************/
936 assignments: /* NOP */ { $$ = NULL; }
937 | assignments ASSIGNMENT { $$ = g_slist_prepend ($1, $2); }
940 binopener: '(' { $$ = gst_parse_strdup(_("bin")); }
941 | BINREF { $$ = $1; }
943 bin: binopener assignments chainlist ')' {
946 GstBin *bin = (GstBin *) gst_element_factory_make ($1, NULL);
948 SET_ERROR (graph->error, GST_PARSE_ERROR_EMPTY_BIN,
949 _("specified empty bin \"%s\", not allowed"), $1);
950 chain = gst_parse_chain_new ();
951 chain->first.element = chain->last.element = NULL;
952 chain->first.name = chain->last.name = NULL;
953 chain->first.pads = chain->last.pads = NULL;
954 chain->elements = NULL;
957 add_missing_element(graph, $1);
958 SET_ERROR (graph->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
959 _("no bin \"%s\", unpacking elements"), $1);
960 /* clear property-list */
961 g_slist_foreach ($2, (GFunc) gst_parse_strfree, NULL);
965 for (walk = chain->elements; walk; walk = walk->next )
966 gst_bin_add (bin, GST_ELEMENT (walk->data));
967 g_slist_free (chain->elements);
968 chain->elements = g_slist_prepend (NULL, bin);
971 /* set the properties now
972 * HINT: property-list cleared above, if bin==NULL
974 for (walk = $2; walk; walk = walk->next)
975 gst_parse_element_set ((gchar *) walk->data,
976 GST_ELEMENT (bin), graph);
978 gst_parse_strfree ($1);
982 /*************************************************************
983 * Grammar explanation: (cont'd)
985 *************************************************************/
987 graph: chainlist { $$ = graph;
990 SET_ERROR (graph->error, GST_PARSE_ERROR_EMPTY, _("empty pipeline not allowed"));
999 yyerror (void *scanner, graph_t *graph, const char *s)
1001 /* FIXME: This should go into the GError somehow, but how? */
1002 GST_WARNING ("Error during parsing: %s", s);
1008 priv_gst_parse_launch (const gchar *str, GError **error, GstParseContext *ctx,
1009 GstParseFlags flags)
1018 g_return_val_if_fail (str != NULL, NULL);
1019 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
1027 #ifdef __GST_PARSE_TRACE
1028 GST_CAT_DEBUG (GST_CAT_PIPELINE, "TRACE: tracing enabled");
1029 __strings = __chains = __links = 0;
1030 #endif /* __GST_PARSE_TRACE */
1032 /* g_print("Now scanning: %s\n", str); */
1034 dstr = g_strdup (str);
1035 priv_gst_parse_yylex_init (&scanner);
1036 priv_gst_parse_yy_scan_string (dstr, scanner);
1042 if (yyparse (scanner, &g) != 0) {
1043 SET_ERROR (error, GST_PARSE_ERROR_SYNTAX,
1044 "Unrecoverable syntax error while parsing pipeline %s", str);
1046 priv_gst_parse_yylex_destroy (scanner);
1051 priv_gst_parse_yylex_destroy (scanner);
1054 GST_CAT_DEBUG (GST_CAT_PIPELINE, "got %u elements and %u links",
1055 g.chain ? g_slist_length (g.chain->elements) : 0,
1056 g_slist_length (g.links));
1058 /* ensure chain is not NULL */
1060 g.chain=gst_parse_chain_new ();
1061 g.chain->elements=NULL;
1062 g.chain->first.element=NULL;
1063 g.chain->first.name=NULL;
1064 g.chain->first.pads=NULL;
1065 g.chain->last.element=NULL;
1066 g.chain->last.name=NULL;
1067 g.chain->last.pads=NULL;
1070 /* ensure elements is not empty */
1071 if(!g.chain->elements){
1072 g.chain->elements= g_slist_prepend (NULL, NULL);
1075 /* put all elements in our bin if necessary */
1076 if(g.chain->elements->next){
1077 bin = GST_BIN (gst_element_factory_make ("pipeline", NULL));
1080 for (walk = g.chain->elements; walk; walk = walk->next) {
1081 if (walk->data != NULL)
1082 gst_bin_add (bin, GST_ELEMENT (walk->data));
1084 g_slist_free (g.chain->elements);
1085 g.chain->elements = g_slist_prepend (NULL, bin);
1088 ret = (GstElement *) g.chain->elements->data;
1089 g_slist_free (g.chain->elements);
1090 g.chain->elements=NULL;
1091 if (GST_IS_BIN (ret))
1092 bin = GST_BIN (ret);
1093 gst_parse_free_chain (g.chain);
1097 /* resolve and perform links */
1098 for (walk = g.links; walk; walk = walk->next) {
1099 link_t *l = (link_t *) walk->data;
1101 err=gst_resolve_reference( &(l->src), ret);
1104 SET_ERROR (error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
1105 "No src-element named \"%s\" - omitting link", l->src.name);
1107 /* probably a missing element which we've handled already */
1108 SET_ERROR (error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
1109 "No src-element found - omitting link");
1111 gst_parse_free_link (l);
1115 err=gst_resolve_reference( &(l->sink), ret);
1118 SET_ERROR (error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
1119 "No sink-element named \"%s\" - omitting link", l->src.name);
1121 /* probably a missing element which we've handled already */
1122 SET_ERROR (error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
1123 "No sink-element found - omitting link");
1125 gst_parse_free_link (l);
1128 gst_parse_perform_link (l, &g);
1130 g_slist_free (g.links);
1133 #ifdef __GST_PARSE_TRACE
1134 GST_CAT_DEBUG (GST_CAT_PIPELINE,
1135 "TRACE: %u strings, %u chains and %u links left", __strings, __chains,
1137 if (__strings || __chains || __links) {
1138 g_warning ("TRACE: %u strings, %u chains and %u links left", __strings,
1141 #endif /* __GST_PARSE_TRACE */
1147 g_slist_foreach (g.chain->elements, (GFunc)gst_object_unref, NULL);
1148 g_slist_free (g.chain->elements);
1149 gst_parse_free_chain (g.chain);
1152 g_slist_foreach (g.links, (GFunc)gst_parse_free_link, NULL);
1153 g_slist_free (g.links);