1 /* GStreamer |
1 /* GStreamer |
2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu> |
2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu> |
3 * 2000 Wim Taymans <wtay@chello.be> |
3 * 2000 Wim Taymans <wtay@chello.be> |
4 * 2002 Andy Wingo <wingo@pobox.com> |
4 * 2002 Andy Wingo <wingo@pobox.com> |
|
5 * 2008 Tim-Philipp Müller <tim centricular net> |
5 * |
6 * |
6 * gstparse.c: get a pipeline from a text pipeline description |
7 * gstparse.c: get a pipeline from a text pipeline description |
7 * |
8 * |
8 * This library is free software; you can redistribute it and/or |
9 * This library is free software; you can redistribute it and/or |
9 * modify it under the terms of the GNU Library General Public |
10 * modify it under the terms of the GNU Library General Public |
24 /** |
25 /** |
25 * SECTION:gstparse |
26 * SECTION:gstparse |
26 * @short_description: Get a pipeline from a text pipeline description |
27 * @short_description: Get a pipeline from a text pipeline description |
27 * |
28 * |
28 * These function allow to create a pipeline based on the syntax used in the |
29 * These function allow to create a pipeline based on the syntax used in the |
29 * gst-launch utillity. |
30 * gst-launch utility. |
30 */ |
31 */ |
31 |
32 |
32 |
33 |
33 #include "gst_private.h" |
34 #include "gst_private.h" |
34 #include <string.h> |
35 #include <string.h> |
35 |
36 |
36 #include "gstparse.h" |
37 #include "gstparse.h" |
37 #include "gsterror.h" |
38 #include "gsterror.h" |
38 #include "gstinfo.h" |
39 #include "gstinfo.h" |
39 |
40 |
40 extern GstElement *_gst_parse_launch (const gchar *, GError **); |
41 extern GstElement *_gst_parse_launch (const gchar *, GError **, |
|
42 GstParseContext *, GstParseFlags); |
41 |
43 |
42 /** |
44 /** |
43 * gst_parse_error_quark: |
45 * gst_parse_error_quark: |
44 * |
46 * |
45 * Get the error quark used by the parsing subsystem. |
47 * Get the error quark used by the parsing subsystem. |
58 if (!quark) |
60 if (!quark) |
59 quark = g_quark_from_static_string ("gst_parse_error"); |
61 quark = g_quark_from_static_string ("gst_parse_error"); |
60 return quark; |
62 return quark; |
61 } |
63 } |
62 |
64 |
|
65 |
|
66 /** |
|
67 * gst_parse_context_new: |
|
68 * |
|
69 * Allocates a parse context for use with gst_parse_launch_full() or |
|
70 * gst_parse_launchv_full(). |
|
71 * |
|
72 * Returns: a newly-allocated parse context. Free with gst_parse_context_free() |
|
73 * when no longer needed. |
|
74 * |
|
75 * Since: 0.10.20 |
|
76 */ |
|
77 #ifdef __SYMBIAN32__ |
|
78 EXPORT_C |
|
79 #endif |
|
80 |
|
81 GstParseContext * |
|
82 gst_parse_context_new (void) |
|
83 { |
|
84 #ifndef GST_DISABLE_PARSE |
|
85 GstParseContext *ctx; |
|
86 |
|
87 ctx = g_slice_new (GstParseContext); |
|
88 ctx->missing_elements = NULL; |
|
89 |
|
90 return ctx; |
|
91 #else |
|
92 return NULL; |
|
93 #endif |
|
94 } |
|
95 |
|
96 /** |
|
97 * gst_parse_context_free: |
|
98 * @context: a #GstParseContext |
|
99 * |
|
100 * Frees a parse context previously allocated with gst_parse_context_new(). |
|
101 * |
|
102 * Since: 0.10.20 |
|
103 */ |
|
104 #ifdef __SYMBIAN32__ |
|
105 EXPORT_C |
|
106 #endif |
|
107 |
|
108 void |
|
109 gst_parse_context_free (GstParseContext * context) |
|
110 { |
|
111 #ifndef GST_DISABLE_PARSE |
|
112 if (context) { |
|
113 g_list_foreach (context->missing_elements, (GFunc) g_free, NULL); |
|
114 g_list_free (context->missing_elements); |
|
115 g_slice_free (GstParseContext, context); |
|
116 } |
|
117 #endif |
|
118 } |
|
119 |
|
120 /** |
|
121 * gst_parse_context_get_missing_elements: |
|
122 * @context: a #GstParseContext |
|
123 * |
|
124 * Retrieve missing elements from a previous run of gst_parse_launch_full() |
|
125 * or gst_parse_launchv_full(). Will only return results if an error code |
|
126 * of %GST_PARSE_ERROR_NO_SUCH_ELEMENT was returned. |
|
127 * |
|
128 * Returns: a NULL-terminated array of element factory name strings of |
|
129 * missing elements. Free with g_strfreev() when no longer needed. |
|
130 * |
|
131 * Since: 0.10.20 |
|
132 */ |
|
133 #ifdef __SYMBIAN32__ |
|
134 EXPORT_C |
|
135 #endif |
|
136 |
|
137 gchar ** |
|
138 gst_parse_context_get_missing_elements (GstParseContext * context) |
|
139 { |
|
140 #ifndef GST_DISABLE_PARSE |
|
141 gchar **arr; |
|
142 GList *l; |
|
143 guint len, i; |
|
144 |
|
145 g_return_val_if_fail (context != NULL, NULL); |
|
146 |
|
147 len = g_list_length (context->missing_elements); |
|
148 |
|
149 if (G_UNLIKELY (len == 0)) |
|
150 return NULL; |
|
151 |
|
152 arr = g_new (gchar *, len + 1); |
|
153 |
|
154 for (i = 0, l = context->missing_elements; l != NULL; l = l->next, ++i) |
|
155 arr[i] = g_strdup (l->data); |
|
156 |
|
157 arr[i] = NULL; |
|
158 |
|
159 return arr; |
|
160 #else |
|
161 return NULL; |
|
162 #endif |
|
163 } |
|
164 |
63 #ifndef GST_DISABLE_PARSE |
165 #ifndef GST_DISABLE_PARSE |
64 static gchar * |
166 static gchar * |
65 _gst_parse_escape (const gchar * str) |
167 _gst_parse_escape (const gchar * str) |
66 { |
168 { |
67 GString *gstr = NULL; |
169 GString *gstr = NULL; |
68 gchar *newstr = NULL; |
|
69 |
170 |
70 g_return_val_if_fail (str != NULL, NULL); |
171 g_return_val_if_fail (str != NULL, NULL); |
71 |
172 |
72 gstr = g_string_sized_new (strlen (str)); |
173 gstr = g_string_sized_new (strlen (str)); |
73 |
174 |
100 EXPORT_C |
198 EXPORT_C |
101 #endif |
199 #endif |
102 |
200 |
103 GstElement * |
201 GstElement * |
104 gst_parse_launchv (const gchar ** argv, GError ** error) |
202 gst_parse_launchv (const gchar ** argv, GError ** error) |
|
203 { |
|
204 return gst_parse_launchv_full (argv, NULL, 0, error); |
|
205 } |
|
206 |
|
207 /** |
|
208 * gst_parse_launchv_full: |
|
209 * @argv: null-terminated array of arguments |
|
210 * @context: a parse context allocated with gst_parse_context_new(), or %NULL |
|
211 * @flags: parsing options, or #GST_PARSE_FLAG_NONE |
|
212 * @error: pointer to a #GError (which must be initialised to %NULL) |
|
213 * |
|
214 * Create a new element based on command line syntax. |
|
215 * @error will contain an error message if an erroneous pipeline is specified. |
|
216 * An error does not mean that the pipeline could not be constructed. |
|
217 * |
|
218 * Returns: a new element on success; on failure, either %NULL or a |
|
219 * partially-constructed bin or element will be returned and @error will be set |
|
220 * (unless you passed #GST_PARSE_FLAG_FATAL_ERRORS in @flags, then %NULL will |
|
221 * always be returned on failure) |
|
222 * |
|
223 * Since: 0.10.20 |
|
224 */ |
|
225 #ifdef __SYMBIAN32__ |
|
226 EXPORT_C |
|
227 #endif |
|
228 |
|
229 GstElement * |
|
230 gst_parse_launchv_full (const gchar ** argv, GstParseContext * context, |
|
231 GstParseFlags flags, GError ** error) |
105 { |
232 { |
106 #ifndef GST_DISABLE_PARSE |
233 #ifndef GST_DISABLE_PARSE |
107 GstElement *element; |
234 GstElement *element; |
108 GString *str; |
235 GString *str; |
109 const gchar **argvp, *arg; |
236 const gchar **argvp, *arg; |
110 gchar *tmp; |
237 gchar *tmp; |
111 |
238 |
112 g_return_val_if_fail (argv != NULL, NULL); |
239 g_return_val_if_fail (argv != NULL, NULL); |
|
240 g_return_val_if_fail (error == NULL || *error == NULL, NULL); |
113 |
241 |
114 /* let's give it a nice size. */ |
242 /* let's give it a nice size. */ |
115 str = g_string_sized_new (1024); |
243 str = g_string_sized_new (1024); |
116 |
244 |
117 argvp = argv; |
245 argvp = argv; |
122 g_free (tmp); |
250 g_free (tmp); |
123 g_string_append_c (str, ' '); |
251 g_string_append_c (str, ' '); |
124 argvp++; |
252 argvp++; |
125 } |
253 } |
126 |
254 |
127 element = gst_parse_launch (str->str, error); |
255 element = gst_parse_launch_full (str->str, context, flags, error); |
128 |
256 |
129 g_string_free (str, TRUE); |
257 g_string_free (str, TRUE); |
130 |
258 |
131 return element; |
259 return element; |
132 #else |
260 #else |
133 gchar *msg; |
261 /* gst_parse_launch_full() will set a GST_CORE_ERROR_DISABLED error for us */ |
134 |
262 return gst_parse_launch_full ("", NULL, 0, error); |
135 GST_WARNING ("Disabled API called: gst_parse_launchv()"); |
|
136 |
|
137 msg = gst_error_get_message (GST_CORE_ERROR, GST_CORE_ERROR_DISABLED); |
|
138 g_set_error (error, GST_CORE_ERROR, GST_CORE_ERROR_DISABLED, "%s", msg); |
|
139 g_free (msg); |
|
140 |
|
141 return NULL; |
|
142 #endif |
263 #endif |
143 } |
264 } |
144 |
265 |
145 /** |
266 /** |
146 * gst_parse_launch: |
267 * gst_parse_launch: |
161 #endif |
282 #endif |
162 |
283 |
163 GstElement * |
284 GstElement * |
164 gst_parse_launch (const gchar * pipeline_description, GError ** error) |
285 gst_parse_launch (const gchar * pipeline_description, GError ** error) |
165 { |
286 { |
|
287 return gst_parse_launch_full (pipeline_description, NULL, 0, error); |
|
288 } |
|
289 |
|
290 /** |
|
291 * gst_parse_launch_full: |
|
292 * @pipeline_description: the command line describing the pipeline |
|
293 * @context: a parse context allocated with gst_parse_context_new(), or %NULL |
|
294 * @flags: parsing options, or #GST_PARSE_FLAG_NONE |
|
295 * @error: the error message in case of an erroneous pipeline. |
|
296 * |
|
297 * Create a new pipeline based on command line syntax. |
|
298 * Please note that you might get a return value that is not %NULL even though |
|
299 * the @error is set. In this case there was a recoverable parsing error and you |
|
300 * can try to play the pipeline. |
|
301 * |
|
302 * Returns: a new element on success, %NULL on failure. If more than one toplevel |
|
303 * element is specified by the @pipeline_description, all elements are put into |
|
304 * a #GstPipeline, which then is returned. |
|
305 * |
|
306 * Since: 0.10.20 |
|
307 */ |
|
308 #ifdef __SYMBIAN32__ |
|
309 EXPORT_C |
|
310 #endif |
|
311 |
|
312 GstElement * |
|
313 gst_parse_launch_full (const gchar * pipeline_description, |
|
314 GstParseContext * context, GstParseFlags flags, GError ** error) |
|
315 { |
166 #ifndef GST_DISABLE_PARSE |
316 #ifndef GST_DISABLE_PARSE |
167 GstElement *element; |
317 GstElement *element; |
168 |
318 |
169 g_return_val_if_fail (pipeline_description != NULL, NULL); |
319 g_return_val_if_fail (pipeline_description != NULL, NULL); |
170 |
320 g_return_val_if_fail (error == NULL || *error == NULL, NULL); |
171 GST_CAT_INFO (GST_CAT_PIPELINE, "parsing pipeline description %s", |
321 |
|
322 GST_CAT_INFO (GST_CAT_PIPELINE, "parsing pipeline description '%s'", |
172 pipeline_description); |
323 pipeline_description); |
173 |
324 |
174 element = _gst_parse_launch (pipeline_description, error); |
325 element = _gst_parse_launch (pipeline_description, error, context, flags); |
|
326 |
|
327 /* don't return partially constructed pipeline if FATAL_ERRORS was given */ |
|
328 if (G_UNLIKELY (error != NULL && *error != NULL && element != NULL)) { |
|
329 if ((flags & GST_PARSE_FLAG_FATAL_ERRORS)) { |
|
330 gst_object_unref (element); |
|
331 element = NULL; |
|
332 } |
|
333 } |
175 |
334 |
176 return element; |
335 return element; |
177 #else |
336 #else |
178 gchar *msg; |
337 gchar *msg; |
179 |
338 |
180 GST_WARNING ("Disabled API called: gst_parse_launch()"); |
339 GST_WARNING ("Disabled API called"); |
181 |
340 |
182 msg = gst_error_get_message (GST_CORE_ERROR, GST_CORE_ERROR_DISABLED); |
341 msg = gst_error_get_message (GST_CORE_ERROR, GST_CORE_ERROR_DISABLED); |
183 g_set_error (error, GST_CORE_ERROR, GST_CORE_ERROR_DISABLED, "%s", msg); |
342 g_set_error (error, GST_CORE_ERROR, GST_CORE_ERROR_DISABLED, "%s", msg); |
184 g_free (msg); |
343 g_free (msg); |
185 |
344 |