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 ); \
235 gulong pad_added_signal_id, no_more_pads_signal_id;
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 | GST_PARSE_FLAG_PLACE_IN_BIN, 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++;
393 /* truncate a string if it is delimited with double quotes */
394 if (*pos == '"' && pos[strlen (pos) - 1] == '"') {
396 pos[strlen (pos) - 1] = '\0';
398 gst_parse_unescape (pos);
400 if (GST_IS_CHILD_PROXY (element)) {
401 if (!gst_child_proxy_lookup (GST_CHILD_PROXY (element), value, &target, &pspec)) {
402 /* do a delayed set */
403 gst_parse_add_delayed_set (element, value, pos);
406 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (element), value);
408 target = g_object_ref (element);
409 GST_CAT_LOG_OBJECT (GST_CAT_PIPELINE, target, "found %s property", value);
411 SET_ERROR (graph->error, GST_PARSE_ERROR_NO_SUCH_PROPERTY, \
412 _("no property \"%s\" in element \"%s\""), value, \
413 GST_ELEMENT_NAME (element));
417 if (pspec != NULL && target != NULL) {
418 gboolean got_value = FALSE;
420 value_type = pspec->value_type;
422 GST_CAT_LOG_OBJECT (GST_CAT_PIPELINE, element, "parsing property %s as a %s",
423 pspec->name, 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_full (pos, TRUE, NULL,
432 GST_PARSE_FLAG_NO_SINGLE_ELEMENT_BINS | GST_PARSE_FLAG_PLACE_IN_BIN, NULL);
434 g_value_set_object (&v, bin);
440 g_object_set_property (target, pspec->name, &v);
444 gst_parse_strfree (value);
448 g_object_unref (target);
452 SET_ERROR (graph->error, GST_PARSE_ERROR_COULD_NOT_SET_PROPERTY,
453 _("could not set property \"%s\" in element \"%s\" to \"%s\""),
454 value, GST_ELEMENT_NAME (element), pos);
458 static void gst_parse_free_reference (reference_t *rr)
460 if(rr->element) gst_object_unref(rr->element);
461 gst_parse_strfree (rr->name);
462 g_slist_foreach (rr->pads, (GFunc) gst_parse_strfree, NULL);
463 g_slist_free (rr->pads);
466 static void gst_parse_free_link (link_t *link)
468 gst_parse_free_reference (&(link->src));
469 gst_parse_free_reference (&(link->sink));
470 if (link->caps) gst_caps_unref (link->caps);
471 gst_parse_link_free (link);
474 static void gst_parse_free_chain (chain_t *ch)
477 gst_parse_free_reference (&(ch->first));
478 gst_parse_free_reference (&(ch->last));
479 for(walk=ch->elements;walk;walk=walk->next)
480 gst_object_unref (walk->data);
481 g_slist_free (ch->elements);
482 gst_parse_chain_free (ch);
485 static void gst_parse_free_delayed_link (DelayedLink *link)
487 g_free (link->src_pad);
488 g_free (link->sink_pad);
489 if (link->caps) gst_caps_unref (link->caps);
490 g_slice_free (DelayedLink, link);
493 #define PRETTY_PAD_NAME_FMT "%s %s of %s named %s"
494 #define PRETTY_PAD_NAME_ARGS(elem, pad_name) \
495 (pad_name ? "pad " : "some"), (pad_name ? pad_name : "pad"), \
496 G_OBJECT_TYPE_NAME(elem), GST_STR_NULL (GST_ELEMENT_NAME (elem))
498 static void gst_parse_no_more_pads (GstElement *src, gpointer data)
500 DelayedLink *link = data;
502 GST_ELEMENT_WARNING(src, PARSE, DELAYED_LINK,
503 (_("Delayed linking failed.")),
504 ("failed delayed linking " PRETTY_PAD_NAME_FMT " to " PRETTY_PAD_NAME_FMT,
505 PRETTY_PAD_NAME_ARGS (src, link->src_pad),
506 PRETTY_PAD_NAME_ARGS (link->sink, link->sink_pad)));
507 /* we keep the handlers connected, so that in case an element still adds a pad
508 * despite no-more-pads, we will consider it for pending delayed links */
511 static void gst_parse_found_pad (GstElement *src, GstPad *pad, gpointer data)
513 DelayedLink *link = data;
515 GST_CAT_INFO (GST_CAT_PIPELINE,
516 "trying delayed linking " PRETTY_PAD_NAME_FMT " to " PRETTY_PAD_NAME_FMT,
517 PRETTY_PAD_NAME_ARGS (src, link->src_pad),
518 PRETTY_PAD_NAME_ARGS (link->sink, link->sink_pad));
520 if (gst_element_link_pads_filtered (src, link->src_pad, link->sink,
521 link->sink_pad, link->caps)) {
522 /* do this here, we don't want to get any problems later on when
523 * unlocking states */
524 GST_CAT_DEBUG (GST_CAT_PIPELINE,
525 "delayed linking " PRETTY_PAD_NAME_FMT " to " PRETTY_PAD_NAME_FMT " worked",
526 PRETTY_PAD_NAME_ARGS (src, link->src_pad),
527 PRETTY_PAD_NAME_ARGS (link->sink, link->sink_pad));
528 g_signal_handler_disconnect (src, link->no_more_pads_signal_id);
529 /* releases 'link' */
530 g_signal_handler_disconnect (src, link->pad_added_signal_id);
534 /* both padnames and the caps may be NULL */
536 gst_parse_perform_delayed_link (GstElement *src, const gchar *src_pad,
537 GstElement *sink, const gchar *sink_pad,
540 GList *templs = gst_element_class_get_pad_template_list (
541 GST_ELEMENT_GET_CLASS (src));
543 for (; templs; templs = templs->next) {
544 GstPadTemplate *templ = (GstPadTemplate *) templs->data;
545 if ((GST_PAD_TEMPLATE_DIRECTION (templ) == GST_PAD_SRC) &&
546 (GST_PAD_TEMPLATE_PRESENCE(templ) == GST_PAD_SOMETIMES))
548 DelayedLink *data = g_slice_new (DelayedLink);
550 /* TODO: maybe we should check if src_pad matches this template's names */
552 GST_CAT_DEBUG (GST_CAT_PIPELINE,
553 "trying delayed link " PRETTY_PAD_NAME_FMT " to " PRETTY_PAD_NAME_FMT,
554 PRETTY_PAD_NAME_ARGS (src, src_pad),
555 PRETTY_PAD_NAME_ARGS (sink, sink_pad));
557 data->src_pad = g_strdup (src_pad);
559 data->sink_pad = g_strdup (sink_pad);
561 data->caps = gst_caps_copy (caps);
565 data->pad_added_signal_id = g_signal_connect_data (src, "pad-added",
566 G_CALLBACK (gst_parse_found_pad), data,
567 (GClosureNotify) gst_parse_free_delayed_link, (GConnectFlags) 0);
568 data->no_more_pads_signal_id = g_signal_connect (src, "no-more-pads",
569 G_CALLBACK (gst_parse_no_more_pads), data);
577 * performs a link and frees the struct. src and sink elements must be given
578 * return values 0 - link performed
583 gst_parse_perform_link (link_t *link, graph_t *graph)
585 GstElement *src = link->src.element;
586 GstElement *sink = link->sink.element;
587 GSList *srcs = link->src.pads;
588 GSList *sinks = link->sink.pads;
589 g_assert (GST_IS_ELEMENT (src));
590 g_assert (GST_IS_ELEMENT (sink));
592 GST_CAT_INFO (GST_CAT_PIPELINE,
593 "linking " PRETTY_PAD_NAME_FMT " to " PRETTY_PAD_NAME_FMT " (%u/%u) with caps \"%" GST_PTR_FORMAT "\"",
594 PRETTY_PAD_NAME_ARGS (src, link->src.name),
595 PRETTY_PAD_NAME_ARGS (sink, link->sink.name),
596 g_slist_length (srcs), g_slist_length (sinks), link->caps);
598 if (!srcs || !sinks) {
599 if (gst_element_link_pads_filtered (src,
600 srcs ? (const gchar *) srcs->data : NULL, sink,
601 sinks ? (const gchar *) sinks->data : NULL, link->caps)) {
604 if (gst_parse_perform_delayed_link (src,
605 srcs ? (const gchar *) srcs->data : NULL,
606 sink, sinks ? (const gchar *) sinks->data : NULL, link->caps)) {
613 if (g_slist_length (link->src.pads) != g_slist_length (link->sink.pads)) {
616 while (srcs && sinks) {
617 const gchar *src_pad = (const gchar *) srcs->data;
618 const gchar *sink_pad = (const gchar *) sinks->data;
619 srcs = g_slist_next (srcs);
620 sinks = g_slist_next (sinks);
621 if (gst_element_link_pads_filtered (src, src_pad, sink, sink_pad,
625 if (gst_parse_perform_delayed_link (src, src_pad,
636 gst_parse_free_link (link);
640 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK,
641 _("could not link %s to %s"), GST_ELEMENT_NAME (src),
642 GST_ELEMENT_NAME (sink));
643 gst_parse_free_link (link);
648 static int yyerror (void *scanner, graph_t *graph, const char *s);
661 /* No grammar ambiguities expected, FAIL otherwise */
664 %token <ss> PARSE_URL
665 %token <ss> IDENTIFIER
666 %left <ss> REF PADREF BINREF
667 %token <ss> ASSIGNMENT
672 %type <cc> chain bin chainlist openchain elementary
676 %type <pp> morepads pads assignments
678 %destructor { gst_parse_strfree ($$); } <ss>
680 gst_parse_free_chain($$); } <cc>
681 %destructor { gst_parse_free_link ($$); } <ll>
682 %destructor { gst_parse_free_reference(&($$));} <rr>
683 %destructor { gst_object_unref ($$); } <ee>
684 %destructor { GSList *walk;
685 for(walk=$$;walk;walk=walk->next)
686 gst_parse_strfree (walk->data);
687 g_slist_free ($$); } <pp>
696 %lex-param { void *scanner }
697 %parse-param { void *scanner }
698 %parse-param { graph_t *graph }
704 /*************************************************************
705 * Grammar explanation:
706 * _element_s are specified by an identifier of their type.
707 * a name can be give in the optional property-assignments
710 * identity silence=false name=frodo
712 **************************************************************/
713 element: IDENTIFIER { $$ = gst_element_factory_make ($1, NULL);
715 add_missing_element(graph, $1);
716 SET_ERROR (graph->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT, _("no element \"%s\""), $1);
718 gst_parse_strfree ($1);
720 | element ASSIGNMENT { gst_parse_element_set ($2, $1, graph);
725 /*************************************************************
726 * Grammar explanation: (cont'd)
727 * a graph has (pure) _element_s, _bin_s and _link_s.
728 * since bins are special elements, bins and elements can
729 * be generalized as _elementary_.
730 * The construction of _bin_s will be discussed later.
733 **************************************************************/
735 element { $$ = gst_parse_chain_new ();
736 /* g_print ("@%p: CHAINing elementary\n", $$); */
737 $$->first.element = $1? gst_object_ref($1) : NULL;
738 $$->last.element = $1? gst_object_ref($1) : NULL;
739 $$->first.name = $$->last.name = NULL;
740 $$->first.pads = $$->last.pads = NULL;
741 $$->elements = $1 ? g_slist_prepend (NULL, $1) : NULL;
746 /*************************************************************
747 * Grammar explanation: (cont'd)
748 * a _chain_ is a list of _elementary_s that have _link_s inbetween
749 * which are represented through infix-notation.
751 * fakesrc ! sometransformation ! fakesink
753 * every _link_ can be augmented with _pads_.
755 * coffeesrc .sound ! speakersink
756 * multisrc .movie,ads ! .projector,smallscreen multisink
758 * and every _link_ can be setup to filter media-types
759 * mediasrc ! audio/x-raw, signed=TRUE ! stereosink
762 * if the lexer does not recognize your media-type it
763 * will make it an element name. that results in errors
765 * NO SUCH ELEMENT: no element audio7x-raw
766 * '7' vs. '/' in https://en.wikipedia.org/wiki/QWERTZ
769 * in the parser we need to differ between chains that can
770 * be extended by more elementaries (_openchain_) and others
771 * that are syntactically closed (handled later in this file).
772 * (e.g. fakesrc ! sinkreferencename.padname)
773 **************************************************************/
774 chain: openchain { $$=$1;
776 SET_ERROR (graph->error, GST_PARSE_ERROR_SYNTAX,
777 _("unexpected reference \"%s\" - ignoring"), $$->last.name);
778 gst_parse_strfree($$->last.name);
782 SET_ERROR (graph->error, GST_PARSE_ERROR_SYNTAX,
783 _("unexpected pad-reference \"%s\" - ignoring"), (gchar*)$$->last.pads->data);
784 g_slist_foreach ($$->last.pads, (GFunc) gst_parse_strfree, NULL);
785 g_slist_free ($$->last.pads);
792 elementary pads { $$=$1;
793 $$->last.pads = g_slist_concat ($$->last.pads, $2);
794 /* g_print ("@%p@%p: FKI elementary pads\n", $1, $$->last.pads); */
796 | openchain link pads elementary pads
799 $2->sink = $4->first;
800 $2->sink.pads = g_slist_concat ($3, $2->sink.pads);
802 $4->first = $1->first;
803 $4->elements = g_slist_concat ($1->elements, $4->elements);
804 gst_parse_chain_free($1);
806 $$->last.pads = g_slist_concat ($$->last.pads, $5);
811 link: LINK { $$ = gst_parse_link_new ();
812 $$->src.element = NULL;
813 $$->sink.element = NULL;
815 $$->sink.name = NULL;
817 $$->sink.pads = NULL;
820 $$->caps = gst_caps_from_string ($1);
821 if ($$->caps == NULL)
822 SET_ERROR (graph->error, GST_PARSE_ERROR_LINK, _("could not parse caps \"%s\""), $1);
823 gst_parse_strfree ($1);
827 pads: /* NOP */ { $$ = NULL; }
828 | PADREF morepads { $$ = $2;
829 $$ = g_slist_prepend ($$, $1);
832 morepads: /* NOP */ { $$ = NULL; }
833 | ',' IDENTIFIER morepads { $$ = g_slist_prepend ($3, $2); }
836 /*************************************************************
837 * Grammar explanation: (cont'd)
838 * the first and last elements of a _chain_ can be give
839 * as URL. This creates special elements that fit the URL.
841 * fakesrc ! http://fake-sink.org
842 * http://somesource.org ! fakesink
843 **************************************************************/
845 chain: openchain link PARSE_URL { GstElement *element =
846 gst_element_make_from_uri (GST_URI_SINK, $3, NULL, NULL);
847 /* FIXME: get and parse error properly */
849 SET_ERROR (graph->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
850 _("no sink element for URI \"%s\""), $3);
853 $2->sink.element = element?gst_object_ref(element):NULL;
856 $$->last.element = NULL;
857 $$->last.name = NULL;
858 $$->last.pads = NULL;
859 if(element) $$->elements = g_slist_append ($$->elements, element);
864 PARSE_URL { GstElement *element =
865 gst_element_make_from_uri (GST_URI_SRC, $1, NULL, NULL);
866 /* FIXME: get and parse error properly */
868 SET_ERROR (graph->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
869 _("no source element for URI \"%s\""), $1);
871 $$ = gst_parse_chain_new ();
872 /* g_print ("@%p: CHAINing srcURL\n", $$); */
873 $$->first.element = NULL;
874 $$->first.name = NULL;
875 $$->first.pads = NULL;
876 $$->last.element = element ? gst_object_ref(element):NULL;
877 $$->last.name = NULL;
878 $$->last.pads = NULL;
879 $$->elements = element ? g_slist_prepend (NULL, element) : NULL;
885 /*************************************************************
886 * Grammar explanation: (cont'd)
887 * the first and last elements of a _chain_ can be linked
888 * to a named _reference_ (with optional pads).
890 * fakesrc ! nameOfSinkElement.
891 * fakesrc ! nameOfSinkElement.Padname
892 * fakesrc ! nameOfSinkElement.Padname, anotherPad
893 * nameOfSource.Padname ! fakesink
894 **************************************************************/
896 chain: openchain link reference { $$ = $1;
900 $$->last.element = NULL;
901 $$->last.name = NULL;
902 $$->last.pads = NULL;
908 reference { $$ = gst_parse_chain_new ();
910 $$->first.element = NULL;
911 $$->first.name = NULL;
912 $$->first.pads = NULL;
916 reference: REF morepads {
920 while (*padname != '.') padname++;
923 if (*padname != '\0')
924 pads = g_slist_prepend (pads, gst_parse_strdup (padname));
933 /*************************************************************
934 * Grammar explanation: (cont'd)
935 * a _chainlist_ is just a list of _chain_s.
937 * You can specify _link_s with named
938 * _reference_ on each side. That
939 * works already after the explanations above.
940 * someSourceName.Pad ! someSinkName.
941 * someSourceName.Pad,anotherPad ! someSinkName.Apad,Bpad
943 * If a syntax error occurs, the already finished _chain_s
944 * and _links_ are kept intact.
945 *************************************************************/
947 chainlist: /* NOP */ { $$ = NULL; }
948 | chainlist chain { if ($1){
949 gst_parse_free_reference(&($1->last));
950 gst_parse_free_reference(&($2->first));
951 $2->first = $1->first;
952 $2->elements = g_slist_concat ($1->elements, $2->elements);
953 gst_parse_chain_free ($1);
957 | chainlist error { $$=$1;
958 GST_CAT_DEBUG (GST_CAT_PIPELINE,"trying to recover from syntax error");
959 SET_ERROR (graph->error, GST_PARSE_ERROR_SYNTAX, _("syntax error"));
963 /*************************************************************
964 * Grammar explanation: (cont'd)
966 *************************************************************/
969 assignments: /* NOP */ { $$ = NULL; }
970 | ASSIGNMENT assignments { $$ = g_slist_prepend ($2, $1); }
973 binopener: '(' { $$ = gst_parse_strdup(_("bin")); }
974 | BINREF { $$ = $1; }
976 bin: binopener assignments chainlist ')' {
979 GstBin *bin = (GstBin *) gst_element_factory_make ($1, NULL);
981 SET_ERROR (graph->error, GST_PARSE_ERROR_EMPTY_BIN,
982 _("specified empty bin \"%s\", not allowed"), $1);
983 chain = gst_parse_chain_new ();
984 chain->first.element = chain->last.element = NULL;
985 chain->first.name = chain->last.name = NULL;
986 chain->first.pads = chain->last.pads = NULL;
987 chain->elements = NULL;
990 add_missing_element(graph, $1);
991 SET_ERROR (graph->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
992 _("no bin \"%s\", unpacking elements"), $1);
993 /* clear property-list */
994 g_slist_foreach ($2, (GFunc) gst_parse_strfree, NULL);
998 for (walk = chain->elements; walk; walk = walk->next )
999 gst_bin_add (bin, GST_ELEMENT (walk->data));
1000 g_slist_free (chain->elements);
1001 chain->elements = g_slist_prepend (NULL, bin);
1004 /* set the properties now
1005 * HINT: property-list cleared above, if bin==NULL
1007 for (walk = $2; walk; walk = walk->next)
1008 gst_parse_element_set ((gchar *) walk->data,
1009 GST_ELEMENT (bin), graph);
1011 gst_parse_strfree ($1);
1015 /*************************************************************
1016 * Grammar explanation: (cont'd)
1018 *************************************************************/
1020 graph: chainlist { $$ = graph;
1023 SET_ERROR (graph->error, GST_PARSE_ERROR_EMPTY, _("empty pipeline not allowed"));
1032 yyerror (void *scanner, graph_t *graph, const char *s)
1034 /* FIXME: This should go into the GError somehow, but how? */
1035 GST_WARNING ("Error during parsing: %s", s);
1041 priv_gst_parse_launch (const gchar *str, GError **error, GstParseContext *ctx,
1042 GstParseFlags flags)
1051 g_return_val_if_fail (str != NULL, NULL);
1052 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
1060 #ifdef __GST_PARSE_TRACE
1061 GST_CAT_DEBUG (GST_CAT_PIPELINE, "TRACE: tracing enabled");
1062 __strings = __chains = __links = 0;
1063 #endif /* __GST_PARSE_TRACE */
1065 /* g_print("Now scanning: %s\n", str); */
1067 dstr = g_strdup (str);
1068 priv_gst_parse_yylex_init (&scanner);
1069 priv_gst_parse_yy_scan_string (dstr, scanner);
1075 if (yyparse (scanner, &g) != 0) {
1076 SET_ERROR (error, GST_PARSE_ERROR_SYNTAX,
1077 "Unrecoverable syntax error while parsing pipeline %s", str);
1079 priv_gst_parse_yylex_destroy (scanner);
1084 priv_gst_parse_yylex_destroy (scanner);
1087 GST_CAT_DEBUG (GST_CAT_PIPELINE, "got %u elements and %u links",
1088 g.chain ? g_slist_length (g.chain->elements) : 0,
1089 g_slist_length (g.links));
1091 /* ensure chain is not NULL */
1093 g.chain=gst_parse_chain_new ();
1094 g.chain->elements=NULL;
1095 g.chain->first.element=NULL;
1096 g.chain->first.name=NULL;
1097 g.chain->first.pads=NULL;
1098 g.chain->last.element=NULL;
1099 g.chain->last.name=NULL;
1100 g.chain->last.pads=NULL;
1103 /* ensure elements is not empty */
1104 if(!g.chain->elements){
1105 g.chain->elements= g_slist_prepend (NULL, NULL);
1108 /* put all elements in our bin if necessary */
1109 if(g.chain->elements->next){
1110 if (flags & GST_PARSE_FLAG_PLACE_IN_BIN)
1111 bin = GST_BIN (gst_element_factory_make ("bin", NULL));
1113 bin = GST_BIN (gst_element_factory_make ("pipeline", NULL));
1116 for (walk = g.chain->elements; walk; walk = walk->next) {
1117 if (walk->data != NULL)
1118 gst_bin_add (bin, GST_ELEMENT (walk->data));
1120 g_slist_free (g.chain->elements);
1121 g.chain->elements = g_slist_prepend (NULL, bin);
1124 ret = (GstElement *) g.chain->elements->data;
1125 g_slist_free (g.chain->elements);
1126 g.chain->elements=NULL;
1127 if (GST_IS_BIN (ret))
1128 bin = GST_BIN (ret);
1129 gst_parse_free_chain (g.chain);
1133 /* resolve and perform links */
1134 for (walk = g.links; walk; walk = walk->next) {
1135 link_t *l = (link_t *) walk->data;
1137 err=gst_resolve_reference( &(l->src), ret);
1140 SET_ERROR (error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
1141 "No src-element named \"%s\" - omitting link", l->src.name);
1143 /* probably a missing element which we've handled already */
1144 SET_ERROR (error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
1145 "No src-element found - omitting link");
1147 gst_parse_free_link (l);
1151 err=gst_resolve_reference( &(l->sink), ret);
1154 SET_ERROR (error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
1155 "No sink-element named \"%s\" - omitting link", l->src.name);
1157 /* probably a missing element which we've handled already */
1158 SET_ERROR (error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
1159 "No sink-element found - omitting link");
1161 gst_parse_free_link (l);
1164 gst_parse_perform_link (l, &g);
1166 g_slist_free (g.links);
1169 #ifdef __GST_PARSE_TRACE
1170 GST_CAT_DEBUG (GST_CAT_PIPELINE,
1171 "TRACE: %u strings, %u chains and %u links left", __strings, __chains,
1173 if (__strings || __chains || __links) {
1174 g_warning ("TRACE: %u strings, %u chains and %u links left", __strings,
1177 #endif /* __GST_PARSE_TRACE */
1183 gst_parse_free_chain (g.chain);
1187 g_slist_foreach (g.links, (GFunc)gst_parse_free_link, NULL);
1188 g_slist_free (g.links);