2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 /* #define DEBUG(format,args...) g_print (format, ##args) */
24 #define DEBUG(format,args...)
25 #define DEBUG_NOPREFIX(format,args...)
26 #define VERBOSE(format,args...)
30 #include "gst_private.h"
32 #include "parse/types.h"
34 typedef struct _gst_parse_delayed_pad gst_parse_delayed_pad;
35 struct _gst_parse_delayed_pad
51 gst_parse_error_quark (void)
53 static GQuark quark = 0;
55 quark = g_quark_from_static_string ("gst_parse_error");
59 G_GNUC_UNUSED static void
60 dynamic_connect (GstElement * element, GstPad * newpad, gpointer data)
62 dyn_connect *connect = (dyn_connect *) data;
64 if (!strcmp (gst_pad_get_name (newpad), connect->srcpadname)) {
65 gst_element_set_state (connect->pipeline, GST_STATE_PAUSED);
66 if (!gst_pad_connect (newpad, connect->target))
67 g_warning ("could not connect %s:%s to %s:%s", GST_DEBUG_PAD_NAME (newpad),
68 GST_DEBUG_PAD_NAME (connect->target));
69 gst_element_set_state (connect->pipeline, GST_STATE_PLAYING);
74 make_elements (graph_t *g, GError **error)
80 if (!(g->bins || g->elements)) {
83 GST_PARSE_ERROR_SYNTAX,
88 if (g->current_bin_type)
89 bin_type = g->current_bin_type;
91 bin_type = "pipeline";
93 if (!(g->bin = gst_elementfactory_make (bin_type, NULL))) {
96 GST_PARSE_ERROR_NO_SUCH_ELEMENT,
97 "No such bin type %s", bin_type);
103 e = (element_t*)l->data;
104 if (!(e->element = gst_elementfactory_make (e->type, NULL))) {
107 GST_PARSE_ERROR_NO_SUCH_ELEMENT,
108 "No such element %s", e->type);
111 gst_bin_add (GST_BIN (g->bin), e->element);
117 if (!make_elements ((graph_t*)l->data, error))
119 gst_bin_add (GST_BIN (g->bin), ((graph_t*)l->data)->bin);
127 set_properties (graph_t *g, GError **error)
136 e = (element_t*)l->data;
137 l2 = e->property_values;
139 p = (property_t*)l2->data;
140 if ((pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (e->element), p->name))) {
141 g_object_set_property (G_OBJECT (e->element), p->name, p->value);
145 GST_PARSE_ERROR_NO_SUCH_PROPERTY,
146 "No such property '%s' in element '%s'",
147 p->name, GST_OBJECT_NAME (GST_OBJECT (e->element)));
150 l2 = g_list_next (l2);
157 if (!set_properties ((graph_t*)l->data, error))
166 find_element_by_index_recurse (graph_t *g, gint i)
174 e = (element_t*)l->data;
183 if ((element = find_element_by_index_recurse ((graph_t*)l->data, i)))
192 find_element_by_index (graph_t *g, gint i)
197 return find_element_by_index_recurse (g, i);
201 make_connections (graph_t *g, GError **error)
205 GstElement *src, *sink;
210 c = (connection_t*)l->data;
212 if (!(src = gst_bin_get_by_name (GST_BIN (g->bin), c->src_name))) {
215 GST_PARSE_ERROR_NO_SUCH_ELEMENT,
216 "No such element '%s'",
221 src = find_element_by_index (g, c->src_index);
225 if (!(sink = gst_bin_get_by_name (GST_BIN (g->bin), c->sink_name))) {
228 GST_PARSE_ERROR_NO_SUCH_ELEMENT,
229 "No such element '%s'",
234 sink = find_element_by_index (g, c->sink_index);
241 /* balanced multipad connection */
243 if (!gst_element_connect_pads (src, (gchar*)a->data, sink, (gchar*)b->data)) {
246 GST_PARSE_ERROR_CONNECT,
247 "Could not connect %s:%s to %s:%s",
248 GST_OBJECT_NAME (src), (gchar*)a->data,
249 GST_OBJECT_NAME (sink), (gchar*)b->data);
256 if (!(p1 = gst_element_get_pad (src, (gchar*)a->data))) {
259 GST_PARSE_ERROR_CONNECT,
260 "Could not get a pad %s from element %s",
261 (gchar*)a->data, GST_OBJECT_NAME (src));
264 if (!(p2 = gst_element_get_compatible_pad (sink, p1))) {
267 GST_PARSE_ERROR_CONNECT,
268 "Could not find a compatible pad in element %s to for %s:%s",
269 GST_OBJECT_NAME (sink), GST_OBJECT_NAME (src), (gchar*)a->data);
272 if (!gst_pad_connect (p1, p2)) {
275 GST_PARSE_ERROR_CONNECT,
276 "Could not connect %s:%s to %s:%s",
277 GST_OBJECT_NAME (src), GST_OBJECT_NAME (p1),
278 GST_OBJECT_NAME (sink), GST_OBJECT_NAME (p1));
282 if (!(p2 = gst_element_get_pad (sink, (gchar*)b->data))) {
285 GST_PARSE_ERROR_CONNECT,
286 "Could not get a pad %s from element %s",
287 (gchar*)b->data, GST_OBJECT_NAME (sink));
290 if (!(p1 = gst_element_get_compatible_pad (src, p2))) {
293 GST_PARSE_ERROR_CONNECT,
294 "Could not find a compatible pad in element %s to for %s:%s",
295 GST_OBJECT_NAME (src), GST_OBJECT_NAME (sink), (gchar*)b->data);
298 if (!gst_pad_connect (p1, p2)) {
301 GST_PARSE_ERROR_CONNECT,
302 "Could not connect %s:%s to %s:%s",
303 GST_OBJECT_NAME (src), GST_OBJECT_NAME (p1),
304 GST_OBJECT_NAME (sink), GST_OBJECT_NAME (p1));
308 if (!gst_element_connect (src, sink)) {
311 GST_PARSE_ERROR_CONNECT,
312 "Could not connect %s to %s",
313 GST_OBJECT_NAME (src), GST_OBJECT_NAME (sink));
322 if (!make_connections ((graph_t*)l->data, error))
331 pipeline_from_graph (graph_t *g, GError **error)
333 if (!make_elements (g, error))
336 if (!set_properties (g, error))
339 if (!make_connections (g, error))
342 return (GstBin*)g->bin;
347 * @argv: null-terminated array of arguments
349 * Create a new pipeline based on command line syntax.
351 * Returns: a new pipeline on success, NULL on failure
354 gst_parse_launchv (const gchar **argv, GError **error)
357 gchar *pipeline_description;
359 /* i think this cast works out ok... */
360 pipeline_description = g_strjoinv (" ", (gchar**)argv);
362 pipeline = gst_parse_launch (pipeline_description, error);
369 * @pipeline_description: the command line describing the pipeline
371 * Create a new pipeline based on command line syntax.
373 * Returns: a new GstPipeline (cast to a Bin) on success, NULL on failure
376 gst_parse_launch (const gchar * pipeline_description, GError **error)
379 static GStaticMutex flex_lock = G_STATIC_MUTEX_INIT;
381 g_return_val_if_fail (pipeline_description != NULL, NULL);
383 GST_INFO (GST_CAT_PIPELINE, "parsing pipeline description %s",
384 pipeline_description);
386 /* the need for the mutex will go away with flex 2.5.6 */
387 g_static_mutex_lock (&flex_lock);
388 graph = _gst_parse_launch (pipeline_description, error);
389 g_static_mutex_unlock (&flex_lock);
394 return pipeline_from_graph (graph, error);