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_append (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);
300 gst_object_unref (parent);
305 gst_object_unref (parent);
310 static void gst_parse_new_child(GstChildProxy *child_proxy, GObject *object,
311 const gchar * name, gpointer data)
313 DelayedSet *set = (DelayedSet *) data;
316 GObject *target = NULL;
319 GST_CAT_LOG_OBJECT (GST_CAT_PIPELINE, child_proxy, "new child %s, checking property %s",
322 if (gst_child_proxy_lookup (child_proxy, set->name, &target, &pspec)) {
323 gboolean got_value = FALSE;
325 value_type = pspec->value_type;
327 GST_CAT_LOG_OBJECT (GST_CAT_PIPELINE, child_proxy, "parsing delayed property %s as a %s from %s",
328 pspec->name, g_type_name (value_type), set->value_str);
329 g_value_init (&v, value_type);
330 if (gst_value_deserialize (&v, set->value_str))
332 else if (g_type_is_a (value_type, GST_TYPE_ELEMENT)) {
335 bin = gst_parse_bin_from_description_full (set->value_str, TRUE, NULL,
336 GST_PARSE_FLAG_NO_SINGLE_ELEMENT_BINS, NULL);
338 g_value_set_object (&v, bin);
342 g_signal_handler_disconnect (child_proxy, set->signal_id);
345 g_object_set_property (target, pspec->name, &v);
347 const gchar *obj_name = GST_OBJECT_NAME(object);
348 gint len = strlen (obj_name);
350 /* do a delayed set */
351 if ((strlen (set->name) > (len + 2)) && !strncmp (set->name, obj_name, len) && !strncmp (&set->name[len], "::", 2)) {
352 gst_parse_add_delayed_set (GST_ELEMENT(child_proxy), set->name, set->value_str);
360 g_object_unref (target);
364 GST_CAT_ERROR (GST_CAT_PIPELINE, "could not set property \"%s\" in %"
365 GST_PTR_FORMAT, pspec->name, target);
369 static void gst_parse_element_set (gchar *value, GstElement *element, graph_t *graph)
371 GParamSpec *pspec = NULL;
374 GObject *target = NULL;
377 /* do nothing if assignment is for missing element */
381 /* parse the string, so the property name is null-terminated and pos points
382 to the beginning of the value */
383 while (!g_ascii_isspace (*pos) && (*pos != '=')) pos++;
389 while (g_ascii_isspace (*pos)) pos++;
392 while (g_ascii_isspace (*pos)) pos++;
395 pos[strlen (pos) - 1] = '\0';
397 gst_parse_unescape (pos);
399 if (GST_IS_CHILD_PROXY (element)) {
400 if (!gst_child_proxy_lookup (GST_CHILD_PROXY (element), value, &target, &pspec)) {
401 /* do a delayed set */
402 gst_parse_add_delayed_set (element, value, pos);
405 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (element), value);
407 target = g_object_ref (element);
408 GST_CAT_LOG_OBJECT (GST_CAT_PIPELINE, target, "found %s property", value);
410 SET_ERROR (graph->error, GST_PARSE_ERROR_NO_SUCH_PROPERTY, \
411 _("no property \"%s\" in element \"%s\""), value, \
412 GST_ELEMENT_NAME (element));
416 if (pspec != NULL && target != NULL) {
417 gboolean got_value = FALSE;
419 value_type = pspec->value_type;
421 GST_CAT_LOG_OBJECT (GST_CAT_PIPELINE, element, "parsing property %s as a %s",
422 pspec->name, g_type_name (value_type));
424 g_value_init (&v, value_type);
425 if (gst_value_deserialize (&v, pos))
427 else if (g_type_is_a (value_type, GST_TYPE_ELEMENT)) {
430 bin = gst_parse_bin_from_description_full (pos, TRUE, NULL,
431 GST_PARSE_FLAG_NO_SINGLE_ELEMENT_BINS, NULL);
433 g_value_set_object (&v, bin);
439 g_object_set_property (target, pspec->name, &v);
443 gst_parse_strfree (value);
447 g_object_unref (target);
451 SET_ERROR (graph->error, GST_PARSE_ERROR_COULD_NOT_SET_PROPERTY,
452 _("could not set property \"%s\" in element \"%s\" to \"%s\""),
453 value, GST_ELEMENT_NAME (element), pos);
457 static void gst_parse_free_reference (reference_t *rr)
459 if(rr->element) gst_object_unref(rr->element);
460 gst_parse_strfree (rr->name);
461 g_slist_foreach (rr->pads, (GFunc) gst_parse_strfree, NULL);
462 g_slist_free (rr->pads);
465 static void gst_parse_free_link (link_t *link)
467 gst_parse_free_reference (&(link->src));
468 gst_parse_free_reference (&(link->sink));
469 if (link->caps) gst_caps_unref (link->caps);
470 gst_parse_link_free (link);
473 static void gst_parse_free_chain (chain_t *ch)
476 gst_parse_free_reference (&(ch->first));
477 gst_parse_free_reference (&(ch->last));
478 for(walk=ch->elements;walk;walk=walk->next)
479 gst_object_unref (walk->data);
480 g_slist_free (ch->elements);
481 gst_parse_chain_free (ch);
484 static void gst_parse_free_delayed_link (DelayedLink *link)
486 g_free (link->src_pad);
487 g_free (link->sink_pad);
488 if (link->caps) gst_caps_unref (link->caps);
489 g_slice_free (DelayedLink, link);
492 static void gst_parse_found_pad (GstElement *src, GstPad *pad, gpointer data)
494 DelayedLink *link = data;
496 GST_CAT_INFO (GST_CAT_PIPELINE, "trying delayed linking %s:%s to %s:%s",
497 GST_STR_NULL (GST_ELEMENT_NAME (src)), GST_STR_NULL (link->src_pad),
498 GST_STR_NULL (GST_ELEMENT_NAME (link->sink)), GST_STR_NULL (link->sink_pad));
500 if (gst_element_link_pads_filtered (src, link->src_pad, link->sink,
501 link->sink_pad, link->caps)) {
502 /* do this here, we don't want to get any problems later on when
503 * unlocking states */
504 GST_CAT_DEBUG (GST_CAT_PIPELINE, "delayed linking %s:%s to %s:%s worked",
505 GST_STR_NULL (GST_ELEMENT_NAME (src)), GST_STR_NULL (link->src_pad),
506 GST_STR_NULL (GST_ELEMENT_NAME (link->sink)), GST_STR_NULL (link->sink_pad));
507 g_signal_handler_disconnect (src, link->signal_id);
511 /* both padnames and the caps may be NULL */
513 gst_parse_perform_delayed_link (GstElement *src, const gchar *src_pad,
514 GstElement *sink, const gchar *sink_pad,
517 GList *templs = gst_element_class_get_pad_template_list (
518 GST_ELEMENT_GET_CLASS (src));
520 for (; templs; templs = templs->next) {
521 GstPadTemplate *templ = (GstPadTemplate *) templs->data;
522 if ((GST_PAD_TEMPLATE_DIRECTION (templ) == GST_PAD_SRC) &&
523 (GST_PAD_TEMPLATE_PRESENCE(templ) == GST_PAD_SOMETIMES))
525 DelayedLink *data = g_slice_new (DelayedLink);
527 /* TODO: maybe we should check if src_pad matches this template's names */
529 GST_CAT_DEBUG (GST_CAT_PIPELINE, "trying delayed link %s:%s to %s:%s",
530 GST_STR_NULL (GST_ELEMENT_NAME (src)), GST_STR_NULL (src_pad),
531 GST_STR_NULL (GST_ELEMENT_NAME (sink)), GST_STR_NULL (sink_pad));
533 data->src_pad = g_strdup (src_pad);
535 data->sink_pad = g_strdup (sink_pad);
537 data->caps = gst_caps_copy (caps);
541 data->signal_id = g_signal_connect_data (src, "pad-added",
542 G_CALLBACK (gst_parse_found_pad), data,
543 (GClosureNotify) gst_parse_free_delayed_link, (GConnectFlags) 0);
551 * performs a link and frees the struct. src and sink elements must be given
552 * return values 0 - link performed
557 gst_parse_perform_link (link_t *link, graph_t *graph)
559 GstElement *src = link->src.element;
560 GstElement *sink = link->sink.element;
561 GSList *srcs = link->src.pads;
562 GSList *sinks = link->sink.pads;
563 g_assert (GST_IS_ELEMENT (src));
564 g_assert (GST_IS_ELEMENT (sink));
566 GST_CAT_INFO (GST_CAT_PIPELINE,
567 "linking %s:%s to %s:%s (%u/%u) with caps \"%" GST_PTR_FORMAT "\"",
568 GST_ELEMENT_NAME (src), link->src.name ? link->src.name : "(any)",
569 GST_ELEMENT_NAME (sink), link->sink.name ? link->sink.name : "(any)",
570 g_slist_length (srcs), g_slist_length (sinks), link->caps);
572 if (!srcs || !sinks) {
573 if (gst_element_link_pads_filtered (src,
574 srcs ? (const gchar *) srcs->data : NULL, sink,
575 sinks ? (const gchar *) sinks->data : NULL, link->caps)) {
578 if (gst_parse_perform_delayed_link (src,
579 srcs ? (const gchar *) srcs->data : NULL,
580 sink, sinks ? (const gchar *) sinks->data : NULL, link->caps)) {
587 if (g_slist_length (link->src.pads) != g_slist_length (link->sink.pads)) {
590 while (srcs && sinks) {
591 const gchar *src_pad = (const gchar *) srcs->data;
592 const gchar *sink_pad = (const gchar *) sinks->data;
593 srcs = g_slist_next (srcs);
594 sinks = g_slist_next (sinks);
595 if (gst_element_link_pads_filtered (src, src_pad, sink, sink_pad,
599 if (gst_parse_perform_delayed_link (src, src_pad,
610 gst_parse_free_link (link);
614 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK,
615 _("could not link %s to %s"), GST_ELEMENT_NAME (src),
616 GST_ELEMENT_NAME (sink));
617 gst_parse_free_link (link);
622 static int yyerror (void *scanner, graph_t *graph, const char *s);
635 /* No grammar ambiguities expected, FAIL otherwise */
638 %token <ss> PARSE_URL
639 %token <ss> IDENTIFIER
640 %left <ss> REF PADREF BINREF
641 %token <ss> ASSIGNMENT
646 %type <cc> chain bin chainlist openchain elementary
650 %type <pp> morepads pads assignments
652 %destructor { gst_parse_strfree ($$); } <ss>
654 gst_parse_free_chain($$); } <cc>
655 %destructor { gst_parse_free_link ($$); } <ll>
656 %destructor { gst_parse_free_reference(&($$));} <rr>
657 %destructor { gst_object_unref ($$); } <ee>
658 %destructor { GSList *walk;
659 for(walk=$$;walk;walk=walk->next)
660 gst_parse_strfree (walk->data);
661 g_slist_free ($$); } <pp>
670 %lex-param { void *scanner }
671 %parse-param { void *scanner }
672 %parse-param { graph_t *graph }
678 /*************************************************************
679 * Grammar explanation:
680 * _element_s are specified by an identifier of their type.
681 * a name can be give in the optional property-assignments
684 * identity silence=false name=frodo
686 **************************************************************/
687 element: IDENTIFIER { $$ = gst_element_factory_make ($1, NULL);
689 add_missing_element(graph, $1);
690 SET_ERROR (graph->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT, _("no element \"%s\""), $1);
692 gst_parse_strfree ($1);
694 | element ASSIGNMENT { gst_parse_element_set ($2, $1, graph);
699 /*************************************************************
700 * Grammar explanation: (cont'd)
701 * a graph has (pure) _element_s, _bin_s and _link_s.
702 * since bins are special elements, bins and elements can
703 * be generalized as _elementary_.
704 * The construction of _bin_s will be discussed later.
707 **************************************************************/
709 element { $$ = gst_parse_chain_new ();
710 /* g_print ("@%p: CHAINing elementary\n", $$); */
711 $$->first.element = $1? gst_object_ref($1) : NULL;
712 $$->last.element = $1? gst_object_ref($1) : NULL;
713 $$->first.name = $$->last.name = NULL;
714 $$->first.pads = $$->last.pads = NULL;
715 $$->elements = $1 ? g_slist_prepend (NULL, $1) : NULL;
720 /*************************************************************
721 * Grammar explanation: (cont'd)
722 * a _chain_ is a list of _elementary_s that have _link_s inbetween
723 * which are represented through infix-notation.
725 * fakesrc ! sometransformation ! fakesink
727 * every _link_ can be augmented with _pads_.
729 * coffeesrc .sound ! speakersink
730 * multisrc .movie,ads ! .projector,smallscreen multisink
732 * and every _link_ can be setup to filter media-types
733 * mediasrc ! audio/x-raw, signed=TRUE ! stereosink
736 * if the lexer does not recognize your media-type it
737 * will make it an element name. that results in errors
739 * NO SUCH ELEMENT: no element audio7x-raw
740 * '7' vs. '/' in https://en.wikipedia.org/wiki/QWERTZ
743 * in the parser we need to differ between chains that can
744 * be extended by more elementaries (_openchain_) and others
745 * that are syntactically closed (handled later in this file).
746 * (e.g. fakesrc ! sinkreferencename.padname)
747 **************************************************************/
748 chain: openchain { $$=$1;
750 SET_ERROR (graph->error, GST_PARSE_ERROR_SYNTAX,
751 _("unexpected reference \"%s\" - ignoring"), $$->last.name);
752 gst_parse_strfree($$->last.name);
756 SET_ERROR (graph->error, GST_PARSE_ERROR_SYNTAX,
757 _("unexpected pad-reference \"%s\" - ignoring"), (gchar*)$$->last.pads->data);
758 g_slist_foreach ($$->last.pads, (GFunc) gst_parse_strfree, NULL);
759 g_slist_free ($$->last.pads);
766 elementary pads { $$=$1;
767 $$->last.pads = g_slist_concat ($$->last.pads, $2);
768 /* g_print ("@%p@%p: FKI elementary pads\n", $1, $$->last.pads); */
770 | openchain link pads elementary pads
773 $2->sink = $4->first;
774 $2->sink.pads = g_slist_concat ($3, $2->sink.pads);
776 $4->first = $1->first;
777 $4->elements = g_slist_concat ($1->elements, $4->elements);
778 gst_parse_chain_free($1);
780 $$->last.pads = g_slist_concat ($$->last.pads, $5);
785 link: LINK { $$ = gst_parse_link_new ();
786 $$->src.element = NULL;
787 $$->sink.element = NULL;
789 $$->sink.name = NULL;
791 $$->sink.pads = NULL;
794 $$->caps = gst_caps_from_string ($1);
795 if ($$->caps == NULL)
796 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK, _("could not parse caps \"%s\""), $1);
797 gst_parse_strfree ($1);
801 pads: /* NOP */ { $$ = NULL; }
802 | PADREF morepads { $$ = $2;
803 $$ = g_slist_prepend ($$, $1);
806 morepads: /* NOP */ { $$ = NULL; }
807 | ',' IDENTIFIER morepads { $$ = g_slist_prepend ($3, $2); }
810 /*************************************************************
811 * Grammar explanation: (cont'd)
812 * the first and last elements of a _chain_ can be give
813 * as URL. This creates special elements that fit the URL.
815 * fakesrc ! http://fake-sink.org
816 * http://somesource.org ! fakesink
817 **************************************************************/
819 chain: openchain link PARSE_URL { GstElement *element =
820 gst_element_make_from_uri (GST_URI_SINK, $3, NULL, NULL);
821 /* FIXME: get and parse error properly */
823 SET_ERROR (graph->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
824 _("no sink element for URI \"%s\""), $3);
827 $2->sink.element = element?gst_object_ref(element):NULL;
830 $$->last.element = NULL;
831 $$->last.name = NULL;
832 $$->last.pads = NULL;
833 if(element) $$->elements = g_slist_append ($$->elements, element);
838 PARSE_URL { GstElement *element =
839 gst_element_make_from_uri (GST_URI_SRC, $1, NULL, NULL);
840 /* FIXME: get and parse error properly */
842 SET_ERROR (graph->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
843 _("no source element for URI \"%s\""), $1);
845 $$ = gst_parse_chain_new ();
846 /* g_print ("@%p: CHAINing srcURL\n", $$); */
847 $$->first.element = NULL;
848 $$->first.name = NULL;
849 $$->first.pads = NULL;
850 $$->last.element = element ? gst_object_ref(element):NULL;
851 $$->last.name = NULL;
852 $$->last.pads = NULL;
853 $$->elements = element ? g_slist_prepend (NULL, element) : NULL;
859 /*************************************************************
860 * Grammar explanation: (cont'd)
861 * the first and last elements of a _chain_ can be linked
862 * to a named _reference_ (with optional pads).
864 * fakesrc ! nameOfSinkElement.
865 * fakesrc ! nameOfSinkElement.Padname
866 * fakesrc ! nameOfSinkElement.Padname, anotherPad
867 * nameOfSource.Padname ! fakesink
868 **************************************************************/
870 chain: openchain link reference { $$ = $1;
874 $$->last.element = NULL;
875 $$->last.name = NULL;
876 $$->last.pads = NULL;
882 reference { $$ = gst_parse_chain_new ();
884 $$->first.element = NULL;
885 $$->first.name = NULL;
886 $$->first.pads = NULL;
890 reference: REF morepads {
894 while (*padname != '.') padname++;
897 if (*padname != '\0')
898 pads = g_slist_prepend (pads, gst_parse_strdup (padname));
907 /*************************************************************
908 * Grammar explanation: (cont'd)
909 * a _chainlist_ is just a list of _chain_s.
911 * You can specify _link_s with named
912 * _reference_ on each side. That
913 * works already after the explanations above.
914 * someSourceName.Pad ! someSinkName.
915 * someSourceName.Pad,anotherPad ! someSinkName.Apad,Bpad
917 * If a syntax error occurs, the already finished _chain_s
918 * and _links_ are kept intact.
919 *************************************************************/
921 chainlist: /* NOP */ { $$ = NULL; }
922 | chainlist chain { if ($1){
923 gst_parse_free_reference(&($1->last));
924 gst_parse_free_reference(&($2->first));
925 $2->first = $1->first;
926 $2->elements = g_slist_concat ($1->elements, $2->elements);
927 gst_parse_chain_free ($1);
931 | chainlist error { $$=$1;
932 GST_CAT_DEBUG (GST_CAT_PIPELINE,"trying to recover from syntax error");
933 SET_ERROR (graph->error, GST_PARSE_ERROR_SYNTAX, _("syntax error"));
937 /*************************************************************
938 * Grammar explanation: (cont'd)
940 *************************************************************/
943 assignments: /* NOP */ { $$ = NULL; }
944 | ASSIGNMENT assignments { $$ = g_slist_prepend ($2, $1); }
947 binopener: '(' { $$ = gst_parse_strdup(_("bin")); }
948 | BINREF { $$ = $1; }
950 bin: binopener assignments chainlist ')' {
953 GstBin *bin = (GstBin *) gst_element_factory_make ($1, NULL);
955 SET_ERROR (graph->error, GST_PARSE_ERROR_EMPTY_BIN,
956 _("specified empty bin \"%s\", not allowed"), $1);
957 chain = gst_parse_chain_new ();
958 chain->first.element = chain->last.element = NULL;
959 chain->first.name = chain->last.name = NULL;
960 chain->first.pads = chain->last.pads = NULL;
961 chain->elements = NULL;
964 add_missing_element(graph, $1);
965 SET_ERROR (graph->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
966 _("no bin \"%s\", unpacking elements"), $1);
967 /* clear property-list */
968 g_slist_foreach ($2, (GFunc) gst_parse_strfree, NULL);
972 for (walk = chain->elements; walk; walk = walk->next )
973 gst_bin_add (bin, GST_ELEMENT (walk->data));
974 g_slist_free (chain->elements);
975 chain->elements = g_slist_prepend (NULL, bin);
978 /* set the properties now
979 * HINT: property-list cleared above, if bin==NULL
981 for (walk = $2; walk; walk = walk->next)
982 gst_parse_element_set ((gchar *) walk->data,
983 GST_ELEMENT (bin), graph);
985 gst_parse_strfree ($1);
989 /*************************************************************
990 * Grammar explanation: (cont'd)
992 *************************************************************/
994 graph: chainlist { $$ = graph;
997 SET_ERROR (graph->error, GST_PARSE_ERROR_EMPTY, _("empty pipeline not allowed"));
1006 yyerror (void *scanner, graph_t *graph, const char *s)
1008 /* FIXME: This should go into the GError somehow, but how? */
1009 GST_WARNING ("Error during parsing: %s", s);
1015 priv_gst_parse_launch (const gchar *str, GError **error, GstParseContext *ctx,
1016 GstParseFlags flags)
1025 g_return_val_if_fail (str != NULL, NULL);
1026 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
1034 #ifdef __GST_PARSE_TRACE
1035 GST_CAT_DEBUG (GST_CAT_PIPELINE, "TRACE: tracing enabled");
1036 __strings = __chains = __links = 0;
1037 #endif /* __GST_PARSE_TRACE */
1039 /* g_print("Now scanning: %s\n", str); */
1041 dstr = g_strdup (str);
1042 priv_gst_parse_yylex_init (&scanner);
1043 priv_gst_parse_yy_scan_string (dstr, scanner);
1049 if (yyparse (scanner, &g) != 0) {
1050 SET_ERROR (error, GST_PARSE_ERROR_SYNTAX,
1051 "Unrecoverable syntax error while parsing pipeline %s", str);
1053 priv_gst_parse_yylex_destroy (scanner);
1058 priv_gst_parse_yylex_destroy (scanner);
1061 GST_CAT_DEBUG (GST_CAT_PIPELINE, "got %u elements and %u links",
1062 g.chain ? g_slist_length (g.chain->elements) : 0,
1063 g_slist_length (g.links));
1065 /* ensure chain is not NULL */
1067 g.chain=gst_parse_chain_new ();
1068 g.chain->elements=NULL;
1069 g.chain->first.element=NULL;
1070 g.chain->first.name=NULL;
1071 g.chain->first.pads=NULL;
1072 g.chain->last.element=NULL;
1073 g.chain->last.name=NULL;
1074 g.chain->last.pads=NULL;
1077 /* ensure elements is not empty */
1078 if(!g.chain->elements){
1079 g.chain->elements= g_slist_prepend (NULL, NULL);
1082 /* put all elements in our bin if necessary */
1083 if(g.chain->elements->next){
1084 bin = GST_BIN (gst_element_factory_make ("pipeline", NULL));
1087 for (walk = g.chain->elements; walk; walk = walk->next) {
1088 if (walk->data != NULL)
1089 gst_bin_add (bin, GST_ELEMENT (walk->data));
1091 g_slist_free (g.chain->elements);
1092 g.chain->elements = g_slist_prepend (NULL, bin);
1095 ret = (GstElement *) g.chain->elements->data;
1096 g_slist_free (g.chain->elements);
1097 g.chain->elements=NULL;
1098 if (GST_IS_BIN (ret))
1099 bin = GST_BIN (ret);
1100 gst_parse_free_chain (g.chain);
1104 /* resolve and perform links */
1105 for (walk = g.links; walk; walk = walk->next) {
1106 link_t *l = (link_t *) walk->data;
1108 err=gst_resolve_reference( &(l->src), ret);
1111 SET_ERROR (error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
1112 "No src-element named \"%s\" - omitting link", l->src.name);
1114 /* probably a missing element which we've handled already */
1115 SET_ERROR (error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
1116 "No src-element found - omitting link");
1118 gst_parse_free_link (l);
1122 err=gst_resolve_reference( &(l->sink), ret);
1125 SET_ERROR (error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
1126 "No sink-element named \"%s\" - omitting link", l->src.name);
1128 /* probably a missing element which we've handled already */
1129 SET_ERROR (error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
1130 "No sink-element found - omitting link");
1132 gst_parse_free_link (l);
1135 gst_parse_perform_link (l, &g);
1137 g_slist_free (g.links);
1140 #ifdef __GST_PARSE_TRACE
1141 GST_CAT_DEBUG (GST_CAT_PIPELINE,
1142 "TRACE: %u strings, %u chains and %u links left", __strings, __chains,
1144 if (__strings || __chains || __links) {
1145 g_warning ("TRACE: %u strings, %u chains and %u links left", __strings,
1148 #endif /* __GST_PARSE_TRACE */
1154 gst_parse_free_chain (g.chain);
1158 g_slist_foreach (g.links, (GFunc)gst_parse_free_link, NULL);
1159 g_slist_free (g.links);