1 %{
2 #include "../gst_private.h"
3 
4 #include <glib-object.h>
5 #include <glib.h>
6 #include <stdio.h>
7 #include <string.h>
8 #include <stdlib.h>
9 
10 #include "../gst-i18n-lib.h"
11 
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"
21 #include "types.h"
22 
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.
26  */
27 
28 #define YYERROR_VERBOSE 1
29 
30 #define YYENABLE_NLS 0
31 
32 #ifndef YYLTYPE_IS_TRIVIAL
33 #define YYLTYPE_IS_TRIVIAL 0
34 #endif
35 
36 /*******************************************************************************************
37 *** Tracing memory leaks
38 *******************************************************************************************/
39 
40 #ifdef __GST_PARSE_TRACE
41 static guint __strings;
42 static guint __links;
43 static guint __chains;
44 gchar *
__gst_parse_strdup(gchar * org)45 __gst_parse_strdup (gchar *org)
46 {
47   gchar *ret;
48   __strings++;
49   ret = g_strdup (org);
50   /* g_print ("ALLOCATED STR   (%3u): %p %s\n", __strings, ret, ret); */
51   return ret;
52 }
53 void
__gst_parse_strfree(gchar * str)54 __gst_parse_strfree (gchar *str)
55 {
56   if (str) {
57     /* g_print ("FREEING STR     (%3u): %p %s\n", __strings - 1, str, str); */
58     g_free (str);
59     g_return_if_fail (__strings > 0);
60     __strings--;
61   }
62 }
__gst_parse_link_new(void)63 link_t *__gst_parse_link_new (void)
64 {
65   link_t *ret;
66   __links++;
67   ret = g_slice_new0 (link_t);
68   /* g_print ("ALLOCATED LINK  (%3u): %p\n", __links, ret); */
69   return ret;
70 }
71 void
__gst_parse_link_free(link_t * data)72 __gst_parse_link_free (link_t *data)
73 {
74   if (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);
78     __links--;
79   }
80 }
81 chain_t *
__gst_parse_chain_new(void)82 __gst_parse_chain_new (void)
83 {
84   chain_t *ret;
85   __chains++;
86   ret = g_slice_new0 (chain_t);
87   /* g_print ("@%p: ALLOCATED CHAIN (%3u):\n", ret, __chains); */
88   return ret;
89 }
90 void
__gst_parse_chain_free(chain_t * data)91 __gst_parse_chain_free (chain_t *data)
92 {
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);
96   __chains--;
97 }
98 
99 #endif /* __GST_PARSE_TRACE */
100 
101 /*******************************************************************************************
102 *** define SET_ERROR macro/function
103 *******************************************************************************************/
104 #ifdef G_HAVE_ISO_VARARGS
105 
106 #  define SET_ERROR(error, type, ...) \
107 G_STMT_START { \
108   GST_CAT_ERROR (GST_CAT_PIPELINE, __VA_ARGS__); \
109   if ((error) && !*(error)) { \
110     g_set_error ((error), GST_PARSE_ERROR, (type), __VA_ARGS__); \
111   } \
112 } G_STMT_END
113 
114 #elif defined(G_HAVE_GNUC_VARARGS)
115 
116 #  define SET_ERROR(error, type, args...) \
117 G_STMT_START { \
118   GST_CAT_ERROR (GST_CAT_PIPELINE, args ); \
119   if ((error) && !*(error)) { \
120     g_set_error ((error), GST_PARSE_ERROR, (type), args ); \
121   } \
122 } G_STMT_END
123 
124 #else
125 
126 static inline void
SET_ERROR(GError ** error,gint type,const char * format,...)127 SET_ERROR (GError **error, gint type, const char *format, ...)
128 {
129   if (error) {
130     if (*error) {
131       g_warning ("error while parsing");
132     } else {
133       va_list varargs;
134       char *string;
135 
136       va_start (varargs, format);
137       string = g_strdup_vprintf (format, varargs);
138       va_end (varargs);
139 
140       g_set_error (error, GST_PARSE_ERROR, type, string);
141 
142       g_free (string);
143     }
144   }
145 }
146 
147 #endif /* G_HAVE_ISO_VARARGS */
148 
149 /*** define YYPRINTF macro/function if we're debugging */
150 
151 /* bison 1.35 calls this macro with side effects, we need to make sure the
152    side effects work - crappy bison */
153 
154 #ifndef GST_DISABLE_GST_DEBUG
155 #  define YYDEBUG 1
156 
157 #  ifdef G_HAVE_ISO_VARARGS
158 
159 /* #  define YYFPRINTF(a, ...) GST_CAT_DEBUG (GST_CAT_PIPELINE, __VA_ARGS__) */
160 #    define YYFPRINTF(a, ...) \
161 G_STMT_START { \
162      GST_CAT_LOG (GST_CAT_PIPELINE, __VA_ARGS__); \
163 } G_STMT_END
164 
165 #  elif defined(G_HAVE_GNUC_VARARGS)
166 
167 #    define YYFPRINTF(a, args...) \
168 G_STMT_START { \
169      GST_CAT_LOG (GST_CAT_PIPELINE, args); \
170 } G_STMT_END
171 
172 #  else
173 
174 static inline void
YYPRINTF(const char * format,...)175 YYPRINTF(const char *format, ...)
176 {
177   va_list varargs;
178   gchar *temp;
179 
180   va_start (varargs, format);
181   temp = g_strdup_vprintf (format, varargs);
182   GST_CAT_LOG (GST_CAT_PIPELINE, "%s", temp);
183   g_free (temp);
184   va_end (varargs);
185 }
186 
187 #  endif /* G_HAVE_ISO_VARARGS */
188 
189 #endif /* GST_DISABLE_GST_DEBUG */
190 
191 
192 /*
193  * include headers generated by bison & flex, after defining (or not defining) YYDEBUG
194  */
195 #include "grammar.tab.h"
196 #include "parse_lex.h"
197 
198 /*******************************************************************************************
199 *** report missing elements/bins/..
200 *******************************************************************************************/
201 
202 
add_missing_element(graph_t * graph,gchar * name)203 static void  add_missing_element(graph_t *graph,gchar *name){
204   if ((graph)->ctx){
205     (graph)->ctx->missing_elements = g_list_append ((graph)->ctx->missing_elements, g_strdup (name));
206     }
207 }
208 
209 
210 /*******************************************************************************************
211 *** helpers for pipeline-setup
212 *******************************************************************************************/
213 
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 : "", \
223 	(l)->src.element); \
224      gst_parse_free_link (l); \
225    }else{ \
226      graph->links = g_slist_append (graph->links, l ); \
227    }   \
228 } G_STMT_END
229 
230 typedef struct {
231   gchar *src_pad;
232   gchar *sink_pad;
233   GstElement *sink;
234   GstCaps *caps;
235   gulong pad_added_signal_id, no_more_pads_signal_id;
236   gboolean all_pads;
237 } DelayedLink;
238 
239 typedef struct {
240   gchar *name;
241   gchar *value_str;
242   gulong signal_id;
243 } DelayedSet;
244 
gst_resolve_reference(reference_t * rr,GstElement * pipeline)245 static int  gst_resolve_reference(reference_t *rr, GstElement *pipeline){
246   GstBin *bin;
247 
248   if(rr->element) return  0;  /* already resolved! */
249   if(!rr->name)   return -2;  /* no chance! */
250 
251   if (GST_IS_BIN (pipeline)){
252     bin = GST_BIN (pipeline);
253     rr->element = gst_bin_get_by_name_recurse_up (bin, rr->name);
254   } else {
255     rr->element = strcmp (GST_ELEMENT_NAME (pipeline), rr->name) == 0 ?
256 		gst_object_ref(pipeline) : NULL;
257   }
258   if(rr->element) return 0; /* resolved */
259   else            return -1; /* not found */
260 }
261 
gst_parse_free_delayed_set(DelayedSet * set)262 static void gst_parse_free_delayed_set (DelayedSet *set)
263 {
264   g_free(set->name);
265   g_free(set->value_str);
266   g_slice_free(DelayedSet, set);
267 }
268 
269 static void gst_parse_new_child(GstChildProxy *child_proxy, GObject *object,
270     const gchar * name, gpointer data);
271 
gst_parse_add_delayed_set(GstElement * element,gchar * name,gchar * value_str)272 static void gst_parse_add_delayed_set (GstElement *element, gchar *name, gchar *value_str)
273 {
274   DelayedSet *data = g_slice_new0 (DelayedSet);
275 
276   GST_CAT_LOG_OBJECT (GST_CAT_PIPELINE, element, "delaying property set %s to %s",
277     name, value_str);
278 
279   data->name = g_strdup(name);
280   data->value_str = g_strdup(value_str);
281   data->signal_id = g_signal_connect_data(element, "child-added",
282       G_CALLBACK (gst_parse_new_child), data, (GClosureNotify)
283       gst_parse_free_delayed_set, (GConnectFlags) 0);
284 
285   /* FIXME: we would need to listen on all intermediate bins too */
286   if (GST_IS_BIN (element)) {
287     gchar **names, **current;
288     GstElement *parent, *child;
289 
290     current = names = g_strsplit (name, "::", -1);
291     parent = gst_bin_get_by_name (GST_BIN_CAST (element), current[0]);
292     current++;
293     while (parent && current[0]) {
294       child = gst_bin_get_by_name (GST_BIN (parent), current[0]);
295       if (!child && current[1]) {
296         char *sub_name = g_strjoinv ("::", &current[0]);
297 
298         gst_parse_add_delayed_set(parent, sub_name, value_str);
299         g_free (sub_name);
300       }
301       gst_object_unref (parent);
302       parent = child;
303       current++;
304     }
305     if (parent)
306       gst_object_unref (parent);
307     g_strfreev (names);
308   }
309 }
310 
gst_parse_new_child(GstChildProxy * child_proxy,GObject * object,const gchar * name,gpointer data)311 static void gst_parse_new_child(GstChildProxy *child_proxy, GObject *object,
312     const gchar * name, gpointer data)
313 {
314   DelayedSet *set = (DelayedSet *) data;
315   GParamSpec *pspec;
316   GValue v = { 0, };
317   GObject *target = NULL;
318   GType value_type;
319 
320   GST_CAT_LOG_OBJECT (GST_CAT_PIPELINE, child_proxy, "new child %s, checking property %s",
321       name, set->name);
322 
323   if (gst_child_proxy_lookup (child_proxy, set->name, &target, &pspec)) {
324     gboolean got_value = FALSE;
325 
326     value_type = pspec->value_type;
327 
328     GST_CAT_LOG_OBJECT (GST_CAT_PIPELINE, child_proxy, "parsing delayed property %s as a %s from %s",
329       pspec->name, g_type_name (value_type), set->value_str);
330     g_value_init (&v, value_type);
331     if (gst_value_deserialize (&v, set->value_str))
332       got_value = TRUE;
333     else if (g_type_is_a (value_type, GST_TYPE_ELEMENT)) {
334        GstElement *bin;
335 
336        bin = gst_parse_bin_from_description_full (set->value_str, TRUE, NULL,
337            GST_PARSE_FLAG_NO_SINGLE_ELEMENT_BINS | GST_PARSE_FLAG_PLACE_IN_BIN, NULL);
338        if (bin) {
339          g_value_set_object (&v, bin);
340          got_value = TRUE;
341        }
342     }
343     g_signal_handler_disconnect (child_proxy, set->signal_id);
344     if (!got_value)
345       goto error;
346     g_object_set_property (target, pspec->name, &v);
347   } else {
348     const gchar *obj_name = GST_OBJECT_NAME(object);
349     gint len = strlen (obj_name);
350 
351     /* do a delayed set */
352     if ((strlen (set->name) > (len + 2)) && !strncmp (set->name, obj_name, len) && !strncmp (&set->name[len], "::", 2)) {
353       gst_parse_add_delayed_set (GST_ELEMENT(child_proxy), set->name, set->value_str);
354     }
355   }
356 
357 out:
358   if (G_IS_VALUE (&v))
359     g_value_unset (&v);
360   if (target)
361     g_object_unref (target);
362   return;
363 
364 error:
365   GST_CAT_ERROR (GST_CAT_PIPELINE, "could not set property \"%s\" in %"
366       GST_PTR_FORMAT, pspec->name, target);
367   goto out;
368 }
369 
gst_parse_element_set(gchar * value,GstElement * element,graph_t * graph)370 static void gst_parse_element_set (gchar *value, GstElement *element, graph_t *graph)
371 {
372   GParamSpec *pspec = NULL;
373   gchar *pos = value;
374   GValue v = { 0, };
375   GObject *target = NULL;
376   GType value_type;
377 
378   /* do nothing if assignment is for missing element */
379   if (element == NULL)
380     goto out;
381 
382   /* parse the string, so the property name is null-terminated and pos points
383      to the beginning of the value */
384   while (!g_ascii_isspace (*pos) && (*pos != '=')) pos++;
385   if (*pos == '=') {
386     *pos = '\0';
387   } else {
388     *pos = '\0';
389     pos++;
390     while (g_ascii_isspace (*pos)) pos++;
391   }
392   pos++;
393   while (g_ascii_isspace (*pos)) pos++;
394   /* truncate a string if it is delimited with double quotes */
395   if (*pos == '"' && pos[strlen (pos) - 1] == '"') {
396     pos++;
397     pos[strlen (pos) - 1] = '\0';
398   }
399   gst_parse_unescape (pos);
400 
401   if (GST_IS_CHILD_PROXY (element)) {
402     if (!gst_child_proxy_lookup (GST_CHILD_PROXY (element), value, &target, &pspec)) {
403       /* do a delayed set */
404       gst_parse_add_delayed_set (element, value, pos);
405     }
406   } else {
407     pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (element), value);
408     if (pspec != NULL) {
409       target = G_OBJECT (g_object_ref (element));
410       GST_CAT_LOG_OBJECT (GST_CAT_PIPELINE, target, "found %s property", value);
411     } else {
412       SET_ERROR (graph->error, GST_PARSE_ERROR_NO_SUCH_PROPERTY, \
413           _("no property \"%s\" in element \"%s\""), value, \
414           GST_ELEMENT_NAME (element));
415     }
416   }
417 
418   if (pspec != NULL && target != NULL) {
419     gboolean got_value = FALSE;
420 
421     value_type = pspec->value_type;
422 
423     GST_CAT_LOG_OBJECT (GST_CAT_PIPELINE, element, "parsing property %s as a %s",
424         pspec->name, g_type_name (value_type));
425 
426     g_value_init (&v, value_type);
427     if (gst_value_deserialize (&v, pos))
428       got_value = TRUE;
429     else if (g_type_is_a (value_type, GST_TYPE_ELEMENT)) {
430        GstElement *bin;
431 
432        bin = gst_parse_bin_from_description_full (pos, TRUE, NULL,
433            GST_PARSE_FLAG_NO_SINGLE_ELEMENT_BINS | GST_PARSE_FLAG_PLACE_IN_BIN, NULL);
434        if (bin) {
435          g_value_set_object (&v, bin);
436          got_value = TRUE;
437        }
438     }
439     if (!got_value)
440       goto error;
441     g_object_set_property (target, pspec->name, &v);
442   }
443 
444 out:
445   gst_parse_strfree (value);
446   if (G_IS_VALUE (&v))
447     g_value_unset (&v);
448   if (target)
449     g_object_unref (target);
450   return;
451 
452 error:
453   SET_ERROR (graph->error, GST_PARSE_ERROR_COULD_NOT_SET_PROPERTY,
454          _("could not set property \"%s\" in element \"%s\" to \"%s\""),
455 	 value, GST_ELEMENT_NAME (element), pos);
456   goto out;
457 }
458 
gst_parse_free_reference(reference_t * rr)459 static void gst_parse_free_reference (reference_t *rr)
460 {
461   if(rr->element) gst_object_unref(rr->element);
462   gst_parse_strfree (rr->name);
463   g_slist_foreach (rr->pads, (GFunc) gst_parse_strfree, NULL);
464   g_slist_free (rr->pads);
465 }
466 
gst_parse_free_link(link_t * link)467 static void gst_parse_free_link (link_t *link)
468 {
469   gst_parse_free_reference (&(link->src));
470   gst_parse_free_reference (&(link->sink));
471   if (link->caps) gst_caps_unref (link->caps);
472   gst_parse_link_free (link);
473 }
474 
gst_parse_free_chain(chain_t * ch)475 static void gst_parse_free_chain (chain_t *ch)
476 {
477   GSList *walk;
478   gst_parse_free_reference (&(ch->first));
479   gst_parse_free_reference (&(ch->last));
480   for(walk=ch->elements;walk;walk=walk->next)
481     gst_object_unref (walk->data);
482   g_slist_free (ch->elements);
483   gst_parse_chain_free (ch);
484 }
485 
gst_parse_free_delayed_link(DelayedLink * link)486 static void gst_parse_free_delayed_link (DelayedLink *link)
487 {
488   g_free (link->src_pad);
489   g_free (link->sink_pad);
490   if (link->caps) gst_caps_unref (link->caps);
491   g_slice_free (DelayedLink, link);
492 }
493 
494 #define PRETTY_PAD_NAME_FMT "%s %s of %s named %s"
495 #define PRETTY_PAD_NAME_ARGS(elem, pad_name) \
496   (pad_name ? "pad " : "some"), (pad_name ? pad_name : "pad"), \
497   G_OBJECT_TYPE_NAME(elem), GST_STR_NULL (GST_ELEMENT_NAME (elem))
498 
gst_parse_no_more_pads(GstElement * src,gpointer data)499 static void gst_parse_no_more_pads (GstElement *src, gpointer data)
500 {
501   DelayedLink *link = data;
502 
503   /* Don't warn for all-pads links, as we expect those to
504    * still be active at no-more-pads */
505   if (!link->all_pads) {
506     GST_ELEMENT_WARNING(src, PARSE, DELAYED_LINK,
507       (_("Delayed linking failed.")),
508       ("failed delayed linking " PRETTY_PAD_NAME_FMT " to " PRETTY_PAD_NAME_FMT,
509           PRETTY_PAD_NAME_ARGS (src, link->src_pad),
510           PRETTY_PAD_NAME_ARGS (link->sink, link->sink_pad)));
511   }
512   /* we keep the handlers connected, so that in case an element still adds a pad
513    * despite no-more-pads, we will consider it for pending delayed links */
514 }
515 
gst_parse_found_pad(GstElement * src,GstPad * pad,gpointer data)516 static void gst_parse_found_pad (GstElement *src, GstPad *pad, gpointer data)
517 {
518   DelayedLink *link = data;
519 
520   GST_CAT_INFO (GST_CAT_PIPELINE,
521                 "trying delayed linking %s " PRETTY_PAD_NAME_FMT " to " PRETTY_PAD_NAME_FMT,
522 		            link->all_pads ? "all pads" : "one pad",
523                 PRETTY_PAD_NAME_ARGS (src, link->src_pad),
524                 PRETTY_PAD_NAME_ARGS (link->sink, link->sink_pad));
525 
526   if (gst_element_link_pads_filtered (src, link->src_pad, link->sink,
527       link->sink_pad, link->caps)) {
528     /* do this here, we don't want to get any problems later on when
529      * unlocking states */
530     GST_CAT_DEBUG (GST_CAT_PIPELINE,
531                    "delayed linking %s " PRETTY_PAD_NAME_FMT " to " PRETTY_PAD_NAME_FMT " worked",
532 		               link->all_pads ? "all pads" : "one pad",
533                	   PRETTY_PAD_NAME_ARGS (src, link->src_pad),
534                    PRETTY_PAD_NAME_ARGS (link->sink, link->sink_pad));
535     g_signal_handler_disconnect (src, link->no_more_pads_signal_id);
536     /* releases 'link' */
537     if (!link->all_pads)
538       g_signal_handler_disconnect (src, link->pad_added_signal_id);
539   }
540 }
541 
542 /* both padnames and the caps may be NULL */
543 static gboolean
gst_parse_perform_delayed_link(GstElement * src,const gchar * src_pad,GstElement * sink,const gchar * sink_pad,GstCaps * caps,gboolean all_pads)544 gst_parse_perform_delayed_link (GstElement *src, const gchar *src_pad,
545                                 GstElement *sink, const gchar *sink_pad,
546                                 GstCaps *caps, gboolean all_pads)
547 {
548   GList *templs = gst_element_class_get_pad_template_list (
549       GST_ELEMENT_GET_CLASS (src));
550 
551   for (; templs; templs = templs->next) {
552     GstPadTemplate *templ = (GstPadTemplate *) templs->data;
553     if ((GST_PAD_TEMPLATE_DIRECTION (templ) == GST_PAD_SRC) &&
554         (GST_PAD_TEMPLATE_PRESENCE(templ) == GST_PAD_SOMETIMES))
555     {
556       DelayedLink *data = g_slice_new (DelayedLink);
557 
558       data->all_pads = all_pads;
559 
560       /* TODO: maybe we should check if src_pad matches this template's names */
561 
562       GST_CAT_DEBUG (GST_CAT_PIPELINE,
563                      "trying delayed link " PRETTY_PAD_NAME_FMT " to " PRETTY_PAD_NAME_FMT,
564                      PRETTY_PAD_NAME_ARGS (src, src_pad),
565                      PRETTY_PAD_NAME_ARGS (sink, sink_pad));
566 
567       data->src_pad = g_strdup (src_pad);
568       data->sink = sink;
569       data->sink_pad = g_strdup (sink_pad);
570       if (caps) {
571       	data->caps = gst_caps_copy (caps);
572       } else {
573       	data->caps = NULL;
574       }
575       data->pad_added_signal_id = g_signal_connect_data (src, "pad-added",
576           G_CALLBACK (gst_parse_found_pad), data,
577           (GClosureNotify) gst_parse_free_delayed_link, (GConnectFlags) 0);
578       data->no_more_pads_signal_id = g_signal_connect (src, "no-more-pads",
579           G_CALLBACK (gst_parse_no_more_pads), data);
580       return TRUE;
581     }
582   }
583   return FALSE;
584 }
585 
586 static gboolean
gst_parse_element_can_do_caps(GstElement * e,GstPadDirection dir,GstCaps * link_caps)587 gst_parse_element_can_do_caps (GstElement * e, GstPadDirection dir,
588     GstCaps * link_caps)
589 {
590   gboolean can_do = FALSE, done = FALSE;
591   GstIterator *it;
592 
593   it = (dir == GST_PAD_SRC) ? gst_element_iterate_src_pads (e) : gst_element_iterate_sink_pads (e);
594 
595   while (!done && !can_do) {
596     GValue v = G_VALUE_INIT;
597     GstPad *pad;
598     GstCaps *caps;
599 
600     switch (gst_iterator_next (it, &v)) {
601       case GST_ITERATOR_OK:
602         pad = g_value_get_object (&v);
603 
604         caps = gst_pad_get_current_caps (pad);
605         if (caps == NULL)
606           caps = gst_pad_query_caps (pad, NULL);
607 
608         can_do = gst_caps_can_intersect (caps, link_caps);
609 
610         GST_TRACE ("can_do: %d for %" GST_PTR_FORMAT " and %" GST_PTR_FORMAT,
611             can_do, caps, link_caps);
612 
613         gst_caps_unref (caps);
614 
615         g_value_unset (&v);
616         break;
617       case GST_ITERATOR_DONE:
618       case GST_ITERATOR_ERROR:
619         done = TRUE;
620         break;
621       case GST_ITERATOR_RESYNC:
622         gst_iterator_resync (it);
623         break;
624     }
625   }
626 
627   gst_iterator_free (it);
628 
629   return can_do;
630 }
631 
632 /*
633  * performs a link and frees the struct. src and sink elements must be given
634  * return values   0 - link performed
635  *                 1 - link delayed
636  *                <0 - error
637  */
638 static gint
gst_parse_perform_link(link_t * link,graph_t * graph)639 gst_parse_perform_link (link_t *link, graph_t *graph)
640 {
641   GstElement *src = link->src.element;
642   GstElement *sink = link->sink.element;
643   GSList *srcs = link->src.pads;
644   GSList *sinks = link->sink.pads;
645   g_assert (GST_IS_ELEMENT (src));
646   g_assert (GST_IS_ELEMENT (sink));
647 
648   GST_CAT_INFO (GST_CAT_PIPELINE,
649       "linking " PRETTY_PAD_NAME_FMT " to " PRETTY_PAD_NAME_FMT " (%u/%u) with caps \"%" GST_PTR_FORMAT "\"",
650       PRETTY_PAD_NAME_ARGS (src, link->src.name),
651       PRETTY_PAD_NAME_ARGS (sink, link->sink.name),
652       g_slist_length (srcs), g_slist_length (sinks), link->caps);
653 
654   if (!srcs || !sinks) {
655     gboolean found_one = gst_element_link_pads_filtered (src,
656         srcs ? (const gchar *) srcs->data : NULL, sink,
657         sinks ? (const gchar *) sinks->data : NULL, link->caps);
658 
659     if (found_one) {
660       if (!link->all_pads)
661         goto success; /* Linked one, and not an all-pads link = we're done */
662 
663       /* Try and link more available pads */
664       while (gst_element_link_pads_filtered (src,
665         srcs ? (const gchar *) srcs->data : NULL, sink,
666         sinks ? (const gchar *) sinks->data : NULL, link->caps));
667     }
668 
669     /* We either didn't find any static pads, or this is a all-pads link,
670      * in which case watch for future pads and link those. Not a failure
671      * in the all-pads case if there's no sometimes pads to watch */
672     if (gst_parse_perform_delayed_link (src,
673           srcs ? (const gchar *) srcs->data : NULL,
674           sink, sinks ? (const gchar *) sinks->data : NULL, link->caps,
675 	  link->all_pads) || link->all_pads) {
676       goto success;
677     } else {
678       goto error;
679     }
680   }
681   if (g_slist_length (link->src.pads) != g_slist_length (link->sink.pads)) {
682     goto error;
683   }
684   while (srcs && sinks) {
685     const gchar *src_pad = (const gchar *) srcs->data;
686     const gchar *sink_pad = (const gchar *) sinks->data;
687     srcs = g_slist_next (srcs);
688     sinks = g_slist_next (sinks);
689     if (gst_element_link_pads_filtered (src, src_pad, sink, sink_pad,
690         link->caps)) {
691       continue;
692     } else {
693       if (gst_parse_perform_delayed_link (src, src_pad,
694                                           sink, sink_pad,
695 					  link->caps, link->all_pads)) {
696 	continue;
697       } else {
698         goto error;
699       }
700     }
701   }
702 
703 success:
704   gst_parse_free_link (link);
705   return 0;
706 
707 error:
708   if (link->caps != NULL) {
709     gboolean src_can_do_caps, sink_can_do_caps;
710     gchar *caps_str = gst_caps_to_string (link->caps);
711 
712     src_can_do_caps =
713         gst_parse_element_can_do_caps (src, GST_PAD_SRC, link->caps);
714     sink_can_do_caps =
715         gst_parse_element_can_do_caps (sink, GST_PAD_SINK, link->caps);
716 
717     if (!src_can_do_caps && sink_can_do_caps) {
718       SET_ERROR (graph->error, GST_PARSE_ERROR_LINK,
719           _("could not link %s to %s, %s can't handle caps %s"),
720           GST_ELEMENT_NAME (src), GST_ELEMENT_NAME (sink),
721           GST_ELEMENT_NAME (src), caps_str);
722     } else if (src_can_do_caps && !sink_can_do_caps) {
723       SET_ERROR (graph->error, GST_PARSE_ERROR_LINK,
724           _("could not link %s to %s, %s can't handle caps %s"),
725           GST_ELEMENT_NAME (src), GST_ELEMENT_NAME (sink),
726           GST_ELEMENT_NAME (sink), caps_str);
727     } else if (!src_can_do_caps && !sink_can_do_caps) {
728       SET_ERROR (graph->error, GST_PARSE_ERROR_LINK,
729           _("could not link %s to %s, neither element can handle caps %s"),
730           GST_ELEMENT_NAME (src), GST_ELEMENT_NAME (sink), caps_str);
731     } else {
732       SET_ERROR (graph->error, GST_PARSE_ERROR_LINK,
733           _("could not link %s to %s with caps %s"),
734           GST_ELEMENT_NAME (src), GST_ELEMENT_NAME (sink), caps_str);
735     }
736     g_free (caps_str);
737   } else {
738     SET_ERROR (graph->error, GST_PARSE_ERROR_LINK,
739         _("could not link %s to %s"), GST_ELEMENT_NAME (src),
740         GST_ELEMENT_NAME (sink));
741   }
742   gst_parse_free_link (link);
743   return -1;
744 }
745 
746 
747 static int yyerror (void *scanner, graph_t *graph, const char *s);
748 %}
749 
750 %union {
751     gchar *ss;
752     chain_t *cc;
753     link_t *ll;
754     reference_t rr;
755     GstElement *ee;
756     GSList *pp;
757     graph_t *gg;
758 }
759 
760 /* No grammar ambiguities expected, FAIL otherwise */
761 %expect 0
762 
763 %token <ss> PARSE_URL
764 %token <ss> IDENTIFIER
765 %left  <ss> REF PADREF BINREF
766 %token <ss> ASSIGNMENT
767 %token <ss> LINK
768 %token <ss> LINK_ALL
769 
770 %type <ss> binopener
771 %type <gg> graph
772 %type <cc> chain bin chainlist openchain elementary
773 %type <rr> reference
774 %type <ll> link
775 %type <ee> element
776 %type <pp> morepads pads assignments
777 
778 %destructor {	gst_parse_strfree ($$);		} <ss>
779 %destructor {	if($$)
780 		  gst_parse_free_chain($$);	} <cc>
781 %destructor {	gst_parse_free_link ($$);	} <ll>
782 %destructor {	gst_parse_free_reference(&($$));} <rr>
783 %destructor {	gst_object_unref ($$);		} <ee>
784 %destructor {	GSList *walk;
785 		for(walk=$$;walk;walk=walk->next)
786 		  gst_parse_strfree (walk->data);
787 		g_slist_free ($$);		} <pp>
788 
789 
790 
791 %left '(' ')'
792 %left ','
793 %right '.'
794 %left '!' '=' ':'
795 
796 %lex-param { void *scanner }
797 %parse-param { void *scanner }
798 %parse-param { graph_t *graph }
799 %pure-parser
800 
801 %start graph
802 %%
803 
804 /*************************************************************
805 * Grammar explanation:
806 *   _element_s are specified by an identifier of their type.
807 *   a name can be give in the optional property-assignments
808 *	coffeeelement
809 *	fakesrc name=john
810 *	identity silence=false name=frodo
811 *   (cont'd)
812 **************************************************************/
813 element:	IDENTIFIER     		      { $$ = gst_element_factory_make ($1, NULL);
814 						if ($$ == NULL) {
815 						  add_missing_element(graph, $1);
816 						  SET_ERROR (graph->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT, _("no element \"%s\""), $1);
817 						}
818 						gst_parse_strfree ($1);
819                                               }
820 	|	element ASSIGNMENT	      { gst_parse_element_set ($2, $1, graph);
821 						$$ = $1;
822 	                                      }
823 	;
824 
825 /*************************************************************
826 * Grammar explanation: (cont'd)
827 *   a graph has (pure) _element_s, _bin_s and _link_s.
828 *   since bins are special elements, bins and elements can
829 *   be generalized as _elementary_.
830 *   The construction of _bin_s will be discussed later.
831 *   (cont'd)
832 *
833 **************************************************************/
834 elementary:
835 	element				      { $$ = gst_parse_chain_new ();
836 						/* g_print ("@%p: CHAINing elementary\n", $$); */
837 						$$->first.element = $1? gst_object_ref($1) : NULL;
838 						$$->last.element = $1? gst_object_ref($1) : NULL;
839 						$$->first.name = $$->last.name = NULL;
840 						$$->first.pads = $$->last.pads = NULL;
841 						$$->elements = $1 ? g_slist_prepend (NULL, $1) : NULL;
842 					      }
843 	| bin				      { $$=$1; }
844 	;
845 
846 /*************************************************************
847 * Grammar explanation: (cont'd)
848 *   a _chain_ is a list of _elementary_s that have _link_s in between
849 *   which are represented through infix-notation.
850 *
851 *	fakesrc ! sometransformation ! fakesink
852 *
853 *   every _link_ can be augmented with _pads_.
854 *
855 *	coffeesrc .sound ! speakersink
856 *	multisrc  .movie,ads ! .projector,smallscreen multisink
857 *
858 *   and every _link_ can be setup to filter media-types
859 *	mediasrc ! audio/x-raw, signed=TRUE ! stereosink
860 *
861 * User HINT:
862 *   if the lexer does not recognize your media-type it
863 *   will make it an element name. that results in errors
864 *   like
865 *	NO SUCH ELEMENT: no element audio7x-raw
866 *   '7' vs. '/' in https://en.wikipedia.org/wiki/QWERTZ
867 *
868 * Parsing HINT:
869 *   in the parser we need to differ between chains that can
870 *   be extended by more elementaries (_openchain_) and others
871 *   that are syntactically closed (handled later in this file).
872 *	(e.g. fakesrc ! sinkreferencename.padname)
873 **************************************************************/
874 chain:	openchain			      { $$=$1;
875 						if($$->last.name){
876 							SET_ERROR (graph->error, GST_PARSE_ERROR_SYNTAX,
877 							_("unexpected reference \"%s\" - ignoring"), $$->last.name);
878 							gst_parse_strfree($$->last.name);
879 							$$->last.name=NULL;
880 						}
881 						if($$->last.pads){
882 							SET_ERROR (graph->error, GST_PARSE_ERROR_SYNTAX,
883 							_("unexpected pad-reference \"%s\" - ignoring"), (gchar*)$$->last.pads->data);
884 							g_slist_foreach ($$->last.pads, (GFunc) gst_parse_strfree, NULL);
885 							g_slist_free ($$->last.pads);
886 							$$->last.pads=NULL;
887 						}
888 					      }
889 	;
890 
891 openchain:
892 	elementary pads			      { $$=$1;
893 						$$->last.pads = g_slist_concat ($$->last.pads, $2);
894 						/* g_print ("@%p@%p: FKI elementary pads\n", $1, $$->last.pads); */
895 					      }
896 	| openchain link pads elementary pads
897 					      {
898 						$2->src  = $1->last;
899 						$2->sink = $4->first;
900 						$2->sink.pads = g_slist_concat ($3, $2->sink.pads);
901 						TRY_SETUP_LINK($2);
902 						$4->first = $1->first;
903 						$4->elements = g_slist_concat ($1->elements, $4->elements);
904 						gst_parse_chain_free($1);
905 						$$ = $4;
906 						$$->last.pads = g_slist_concat ($$->last.pads, $5);
907 					      }
908 	;
909 
910 link:	LINK				      { $$ = gst_parse_link_new ();
911 						$$->all_pads = FALSE;
912 						if ($1) {
913 						  $$->caps = gst_caps_from_string ($1);
914 						  if ($$->caps == NULL)
915 						    SET_ERROR (graph->error, GST_PARSE_ERROR_LINK, _("could not parse caps \"%s\""), $1);
916 						  gst_parse_strfree ($1);
917 						}
918 					      }
919 	| LINK_ALL		              { $$ = gst_parse_link_new ();
920 						$$->all_pads = TRUE;
921 						if ($1) {
922 						  $$->caps = gst_caps_from_string ($1);
923 						  if ($$->caps == NULL)
924 						    SET_ERROR (graph->error, GST_PARSE_ERROR_LINK, _("could not parse caps \"%s\""), $1);
925 						  gst_parse_strfree ($1);
926 						}
927 					      }
928 	;
929 pads:		/* NOP */		      { $$ = NULL; }
930 	|	PADREF morepads		      { $$ = $2;
931 						$$ = g_slist_prepend ($$, $1);
932 					      }
933 	;
934 morepads:	/* NOP */		      { $$ = NULL; }
935 	|	',' IDENTIFIER morepads	      { $$ = g_slist_prepend ($3, $2); }
936 	;
937 
938 /*************************************************************
939 * Grammar explanation: (cont'd)
940 *   the first and last elements of a _chain_ can be give
941 *   as URL. This creates special elements that fit the URL.
942 *
943 *	fakesrc ! http://fake-sink.org
944 *       http://somesource.org ! fakesink
945 **************************************************************/
946 
947 chain:	openchain link PARSE_URL	      { GstElement *element =
948 							  gst_element_make_from_uri (GST_URI_SINK, $3, NULL, NULL);
949 						/* FIXME: get and parse error properly */
950 						if (!element) {
951 						  SET_ERROR (graph->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
952 							  _("no sink element for URI \"%s\""), $3);
953 						}
954 						$$ = $1;
955 						$2->sink.element = element?gst_object_ref(element):NULL;
956 						$2->src = $1->last;
957 						TRY_SETUP_LINK($2);
958 						$$->last.element = NULL;
959 						$$->last.name = NULL;
960 						$$->last.pads = NULL;
961 						if(element) $$->elements = g_slist_append ($$->elements, element);
962 						g_free ($3);
963 					      }
964 	;
965 openchain:
966 	PARSE_URL			      { GstElement *element =
967 							  gst_element_make_from_uri (GST_URI_SRC, $1, NULL, NULL);
968 						/* FIXME: get and parse error properly */
969 						if (!element) {
970 						  SET_ERROR (graph->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
971 						    _("no source element for URI \"%s\""), $1);
972 						}
973 						$$ = gst_parse_chain_new ();
974 						/* g_print ("@%p: CHAINing srcURL\n", $$); */
975 						$$->first.element = NULL;
976 						$$->first.name = NULL;
977 						$$->first.pads = NULL;
978 						$$->last.element = element ? gst_object_ref(element):NULL;
979 						$$->last.name = NULL;
980 						$$->last.pads = NULL;
981 						$$->elements = element ? g_slist_prepend (NULL, element)  : NULL;
982 						g_free($1);
983 					      }
984 	;
985 
986 
987 /*************************************************************
988 * Grammar explanation: (cont'd)
989 *   the first and last elements of a _chain_ can be linked
990 *   to a named _reference_ (with optional pads).
991 *
992 *	fakesrc ! nameOfSinkElement.
993 *	fakesrc ! nameOfSinkElement.Padname
994 *	fakesrc ! nameOfSinkElement.Padname, anotherPad
995 *	nameOfSource.Padname ! fakesink
996 **************************************************************/
997 
998 chain:	openchain link reference	      { $$ = $1;
999 						$2->sink= $3;
1000 						$2->src = $1->last;
1001 						TRY_SETUP_LINK($2);
1002 						$$->last.element = NULL;
1003 						$$->last.name = NULL;
1004 						$$->last.pads = NULL;
1005 					      }
1006 	;
1007 
1008 
1009 openchain:
1010 	reference 			      { $$ = gst_parse_chain_new ();
1011 						$$->last=$1;
1012 						$$->first.element = NULL;
1013 						$$->first.name = NULL;
1014 						$$->first.pads = NULL;
1015 						$$->elements = NULL;
1016 					      }
1017 	;
1018 reference:	REF morepads		      {
1019 						gchar *padname = $1;
1020 						GSList *pads = $2;
1021 						if (padname) {
1022 						  while (*padname != '.') padname++;
1023 						  *padname = '\0';
1024 						  padname++;
1025 						  if (*padname != '\0')
1026 						    pads = g_slist_prepend (pads, gst_parse_strdup (padname));
1027 						}
1028 						$$.element=NULL;
1029 						$$.name=$1;
1030 						$$.pads=pads;
1031 					      }
1032 	;
1033 
1034 
1035 /*************************************************************
1036 * Grammar explanation: (cont'd)
1037 *   a _chainlist_ is just a list of _chain_s.
1038 *
1039 *   You can specify _link_s with named
1040 *   _reference_ on each side. That
1041 *   works already after the explanations above.
1042 *	someSourceName.Pad ! someSinkName.
1043 *	someSourceName.Pad,anotherPad ! someSinkName.Apad,Bpad
1044 *
1045 *   If a syntax error occurs, the already finished _chain_s
1046 *   and _links_ are kept intact.
1047 *************************************************************/
1048 
1049 chainlist: /* NOP */			      { $$ = NULL; }
1050 	| chainlist chain		      { if ($1){
1051 						  gst_parse_free_reference(&($1->last));
1052 						  gst_parse_free_reference(&($2->first));
1053 						  $2->first = $1->first;
1054 						  $2->elements = g_slist_concat ($1->elements, $2->elements);
1055 						  gst_parse_chain_free ($1);
1056 						}
1057 						$$ = $2;
1058 					      }
1059 	| chainlist error		      { $$=$1;
1060 						GST_CAT_DEBUG (GST_CAT_PIPELINE,"trying to recover from syntax error");
1061 						SET_ERROR (graph->error, GST_PARSE_ERROR_SYNTAX, _("syntax error"));
1062 					      }
1063 	;
1064 
1065 /*************************************************************
1066 * Grammar explanation: (cont'd)
1067 *   _bins_
1068 *************************************************************/
1069 
1070 
1071 assignments:	/* NOP */		      { $$ = NULL; }
1072 	|	ASSIGNMENT assignments 	      { $$ = g_slist_prepend ($2, $1); }
1073 	;
1074 
1075 binopener:	'('			      { $$ = gst_parse_strdup("bin"); }
1076 	|	BINREF			      { $$ = $1; }
1077 	;
1078 bin:	binopener assignments chainlist ')'   {
1079 						chain_t *chain = $3;
1080 						GSList *walk;
1081 						GstBin *bin = (GstBin *) gst_element_factory_make ($1, NULL);
1082 						if (!chain) {
1083 						  SET_ERROR (graph->error, GST_PARSE_ERROR_EMPTY_BIN,
1084 						    _("specified empty bin \"%s\", not allowed"), $1);
1085 						  chain = gst_parse_chain_new ();
1086 						  chain->first.element = chain->last.element = NULL;
1087 						  chain->first.name    = chain->last.name    = NULL;
1088 						  chain->first.pads    = chain->last.pads    = NULL;
1089 						  chain->elements = NULL;
1090 						}
1091 						if (!bin) {
1092 						  add_missing_element(graph, $1);
1093 						  SET_ERROR (graph->error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
1094 						    _("no bin \"%s\", unpacking elements"), $1);
1095 						  /* clear property-list */
1096 						  g_slist_foreach ($2, (GFunc) gst_parse_strfree, NULL);
1097 						  g_slist_free ($2);
1098 						  $2 = NULL;
1099 						} else {
1100 						  for (walk = chain->elements; walk; walk = walk->next )
1101 						    gst_bin_add (bin, GST_ELEMENT (walk->data));
1102 						  g_slist_free (chain->elements);
1103 						  chain->elements = g_slist_prepend (NULL, bin);
1104 						}
1105 						$$ = chain;
1106 						/* set the properties now
1107 						 * HINT: property-list cleared above, if bin==NULL
1108 						 */
1109 						for (walk = $2; walk; walk = walk->next)
1110 						  gst_parse_element_set ((gchar *) walk->data,
1111 							GST_ELEMENT (bin), graph);
1112 						g_slist_free ($2);
1113 						gst_parse_strfree ($1);
1114 					      }
1115 	;
1116 
1117 /*************************************************************
1118 * Grammar explanation: (cont'd)
1119 *   _graph_
1120 *************************************************************/
1121 
1122 graph:	chainlist			      { $$ = graph;
1123 						$$->chain = $1;
1124 						if(!$1) {
1125 						  SET_ERROR (graph->error, GST_PARSE_ERROR_EMPTY, _("empty pipeline not allowed"));
1126 						}
1127 					      }
1128 	;
1129 
1130 %%
1131 
1132 
1133 static int
1134 yyerror (void *scanner, graph_t *graph, const char *s)
1135 {
1136   /* FIXME: This should go into the GError somehow, but how? */
1137   GST_WARNING ("Error during parsing: %s", s);
1138   return -1;
1139 }
1140 
1141 
1142 GstElement *
1143 priv_gst_parse_launch (const gchar *str, GError **error, GstParseContext *ctx,
1144     GstParseFlags flags)
1145 {
1146   graph_t g;
1147   gchar *dstr;
1148   GSList *walk;
1149   GstElement *ret;
1150   yyscan_t scanner;
1151 
1152   g_return_val_if_fail (str != NULL, NULL);
1153   g_return_val_if_fail (error == NULL || *error == NULL, NULL);
1154 
1155   g.chain = NULL;
1156   g.links = NULL;
1157   g.error = error;
1158   g.ctx = ctx;
1159   g.flags = flags;
1160 
1161 #ifdef __GST_PARSE_TRACE
1162   GST_CAT_DEBUG (GST_CAT_PIPELINE, "TRACE: tracing enabled");
1163   __strings = __chains = __links = 0;
1164 #endif /* __GST_PARSE_TRACE */
1165 
1166   /* g_print("Now scanning: %s\n", str); */
1167 
1168   dstr = g_strdup (str);
1169   priv_gst_parse_yylex_init (&scanner);
1170   priv_gst_parse_yy_scan_string (dstr, scanner);
1171 
1172 #if YYDEBUG
1173   yydebug = 1;
1174 #endif
1175 
1176   if (yyparse (scanner, &g) != 0) {
1177     SET_ERROR (error, GST_PARSE_ERROR_SYNTAX,
1178         "Unrecoverable syntax error while parsing pipeline %s", str);
1179 
1180     priv_gst_parse_yylex_destroy (scanner);
1181     g_free (dstr);
1182 
1183     goto error1;
1184   }
1185   priv_gst_parse_yylex_destroy (scanner);
1186   g_free (dstr);
1187 
1188   GST_CAT_DEBUG (GST_CAT_PIPELINE, "got %u elements and %u links",
1189       g.chain ? g_slist_length (g.chain->elements) : 0,
1190       g_slist_length (g.links));
1191 
1192   /* ensure chain is not NULL */
1193   if (!g.chain){
1194     g.chain=gst_parse_chain_new ();
1195     g.chain->elements=NULL;
1196     g.chain->first.element=NULL;
1197     g.chain->first.name=NULL;
1198     g.chain->first.pads=NULL;
1199     g.chain->last.element=NULL;
1200     g.chain->last.name=NULL;
1201     g.chain->last.pads=NULL;
1202   };
1203 
1204   /* ensure elements is not empty */
1205   if(!g.chain->elements){
1206     g.chain->elements= g_slist_prepend (NULL, NULL);
1207   };
1208 
1209   /* put all elements in our bin if necessary */
1210   if(g.chain->elements->next){
1211     GstBin *bin;
1212     if (flags & GST_PARSE_FLAG_PLACE_IN_BIN)
1213       bin = GST_BIN (gst_element_factory_make ("bin", NULL));
1214     else
1215       bin = GST_BIN (gst_element_factory_make ("pipeline", NULL));
1216     g_assert (bin);
1217 
1218     for (walk = g.chain->elements; walk; walk = walk->next) {
1219       if (walk->data != NULL)
1220         gst_bin_add (bin, GST_ELEMENT (walk->data));
1221     }
1222     g_slist_free (g.chain->elements);
1223     g.chain->elements = g_slist_prepend (NULL, bin);
1224   }
1225 
1226   ret = (GstElement *) g.chain->elements->data;
1227   g_slist_free (g.chain->elements);
1228   g.chain->elements=NULL;
1229   gst_parse_free_chain (g.chain);
1230   g.chain = NULL;
1231 
1232 
1233   /* resolve and perform links */
1234   for (walk = g.links; walk; walk = walk->next) {
1235     link_t *l = (link_t *) walk->data;
1236     int err;
1237     err=gst_resolve_reference( &(l->src), ret);
1238     if (err) {
1239        if(-1==err){
1240           SET_ERROR (error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
1241               "No src-element named \"%s\" - omitting link", l->src.name);
1242        }else{
1243           /* probably a missing element which we've handled already */
1244           SET_ERROR (error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
1245               "No src-element found - omitting link");
1246        }
1247        gst_parse_free_link (l);
1248        continue;
1249     }
1250 
1251     err=gst_resolve_reference( &(l->sink), ret);
1252     if (err) {
1253        if(-1==err){
1254           SET_ERROR (error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
1255               "No sink-element named \"%s\" - omitting link", l->src.name);
1256        }else{
1257           /* probably a missing element which we've handled already */
1258           SET_ERROR (error, GST_PARSE_ERROR_NO_SUCH_ELEMENT,
1259               "No sink-element found - omitting link");
1260        }
1261        gst_parse_free_link (l);
1262        continue;
1263     }
1264     gst_parse_perform_link (l, &g);
1265   }
1266   g_slist_free (g.links);
1267 
1268 out:
1269 #ifdef __GST_PARSE_TRACE
1270   GST_CAT_DEBUG (GST_CAT_PIPELINE,
1271       "TRACE: %u strings, %u chains and %u links left", __strings, __chains,
1272       __links);
1273   if (__strings || __chains || __links) {
1274     g_warning ("TRACE: %u strings, %u chains and %u links left", __strings,
1275         __chains, __links);
1276   }
1277 #endif /* __GST_PARSE_TRACE */
1278 
1279   return ret;
1280 
1281 error1:
1282   if (g.chain) {
1283     gst_parse_free_chain (g.chain);
1284     g.chain=NULL;
1285   }
1286 
1287   g_slist_foreach (g.links, (GFunc)gst_parse_free_link, NULL);
1288   g_slist_free (g.links);
1289 
1290   if (error)
1291     g_assert (*error);
1292   ret = NULL;
1293 
1294   goto out;
1295 }
1296