]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - glsdk/gstreamer0-10.git/blob - gst/gstparse.c
docs, gst: typo fixes
[glsdk/gstreamer0-10.git] / gst / gstparse.c
1 /* GStreamer
2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3  *                    2000 Wim Taymans <wtay@chello.be>
4  *                    2002 Andy Wingo <wingo@pobox.com>
5  *                    2008 Tim-Philipp Müller <tim centricular net>
6  *
7  * gstparse.c: get a pipeline from a text pipeline description
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Library General Public
11  * License as published by the Free Software Foundation; either
12  * version 2 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Library General Public License for more details.
18  *
19  * You should have received a copy of the GNU Library General Public
20  * License along with this library; if not, write to the
21  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22  * Boston, MA 02111-1307, USA.
23  */
25 /**
26  * SECTION:gstparse
27  * @short_description: Get a pipeline from a text pipeline description
28  *
29  * These function allow to create a pipeline based on the syntax used in the
30  * gst-launch utility (see man-page for syntax documentation).
31  *
32  * Please note that these functions take several measures to create
33  * somewhat dynamic pipelines. Due to that such pipelines are not always
34  * reusable (set the state to NULL and back to PLAYING).
35  */
37 #include "gst_private.h"
38 #include <string.h>
40 #include "gstparse.h"
41 #include "gsterror.h"
42 #include "gstinfo.h"
43 #ifndef GST_DISABLE_PARSE
44 #include "parse/types.h"
45 #endif
47 static void
48 _prepend_missing_element (gchar * element, GList ** list)
49 {
50   *list = g_list_prepend (*list, g_strdup (element));
51 }
53 static GstParseContext *
54 gst_parse_context_copy (const GstParseContext * context)
55 {
56   GstParseContext *ret = NULL;
57 #ifndef GST_DISABLE_PARSE
59   ret = gst_parse_context_new ();
60   if (context) {
61     g_list_foreach (context->missing_elements, (GFunc) _prepend_missing_element,
62         &ret->missing_elements);
63     ret->missing_elements = g_list_reverse (ret->missing_elements);
64   }
65 #endif
66   return ret;
67 }
69 GType
70 gst_parse_context_get_type (void)
71 {
72   static GType type = 0;
74   if (G_UNLIKELY (type == 0)) {
75     type = g_boxed_type_register_static ("GstParseContext",
76         (GBoxedCopyFunc) gst_parse_context_copy,
77         (GBoxedFreeFunc) gst_parse_context_free);
78   }
80   return type;
81 }
83 /**
84  * gst_parse_error_quark:
85  *
86  * Get the error quark used by the parsing subsystem.
87  *
88  * Returns: the quark of the parse errors.
89  */
90 GQuark
91 gst_parse_error_quark (void)
92 {
93   static GQuark quark = 0;
95   if (!quark)
96     quark = g_quark_from_static_string ("gst_parse_error");
97   return quark;
98 }
101 /**
102  * gst_parse_context_new:
103  *
104  * Allocates a parse context for use with gst_parse_launch_full() or
105  * gst_parse_launchv_full().
106  *
107  * Free-function: gst_parse_context_free
108  *
109  * Returns: (transfer full): a newly-allocated parse context. Free with
110  *     gst_parse_context_free() when no longer needed.
111  *
112  * Since: 0.10.20
113  */
114 GstParseContext *
115 gst_parse_context_new (void)
117 #ifndef GST_DISABLE_PARSE
118   GstParseContext *ctx;
120   ctx = g_slice_new (GstParseContext);
121   ctx->missing_elements = NULL;
123   return ctx;
124 #else
125   return NULL;
126 #endif
129 /**
130  * gst_parse_context_free:
131  * @context: (transfer full): a #GstParseContext
132  *
133  * Frees a parse context previously allocated with gst_parse_context_new().
134  *
135  * Since: 0.10.20
136  */
137 void
138 gst_parse_context_free (GstParseContext * context)
140 #ifndef GST_DISABLE_PARSE
141   if (context) {
142     g_list_foreach (context->missing_elements, (GFunc) g_free, NULL);
143     g_list_free (context->missing_elements);
144     g_slice_free (GstParseContext, context);
145   }
146 #endif
149 /**
150  * gst_parse_context_get_missing_elements:
151  * @context: a #GstParseContext
152  *
153  * Retrieve missing elements from a previous run of gst_parse_launch_full()
154  * or gst_parse_launchv_full(). Will only return results if an error code
155  * of %GST_PARSE_ERROR_NO_SUCH_ELEMENT was returned.
156  *
157  * Returns: (transfer full) (array zero-terminated=1) (element-type gchar*): a
158  *     NULL-terminated array of element factory name strings of missing
159  *     elements. Free with g_strfreev() when no longer needed.
160  *
161  * Since: 0.10.20
162  */
163 gchar **
164 gst_parse_context_get_missing_elements (GstParseContext * context)
166 #ifndef GST_DISABLE_PARSE
167   gchar **arr;
168   GList *l;
169   guint len, i;
171   g_return_val_if_fail (context != NULL, NULL);
173   len = g_list_length (context->missing_elements);
175   if (G_UNLIKELY (len == 0))
176     return NULL;
178   arr = g_new (gchar *, len + 1);
180   for (i = 0, l = context->missing_elements; l != NULL; l = l->next, ++i)
181     arr[i] = g_strdup (l->data);
183   arr[i] = NULL;
185   return arr;
186 #else
187   return NULL;
188 #endif
191 #ifndef GST_DISABLE_PARSE
192 static gchar *
193 _gst_parse_escape (const gchar * str)
195   GString *gstr = NULL;
197   g_return_val_if_fail (str != NULL, NULL);
199   gstr = g_string_sized_new (strlen (str));
201   while (*str) {
202     if (*str == ' ')
203       g_string_append_c (gstr, '\\');
204     g_string_append_c (gstr, *str);
205     str++;
206   }
208   return g_string_free (gstr, FALSE);
210 #endif /* !GST_DISABLE_PARSE */
212 /**
213  * gst_parse_launchv:
214  * @argv: (in) (array zero-terminated=1): null-terminated array of arguments
215  * @error: pointer to a #GError
216  *
217  * Create a new element based on command line syntax.
218  * @error will contain an error message if an erroneuos pipeline is specified.
219  * An error does not mean that the pipeline could not be constructed.
220  *
221  * Returns: (transfer full): a new element on success and %NULL on failure.
222  */
223 GstElement *
224 gst_parse_launchv (const gchar ** argv, GError ** error)
226   return gst_parse_launchv_full (argv, NULL, GST_PARSE_FLAG_NONE, error);
229 /**
230  * gst_parse_launchv_full:
231  * @argv: (in) (array zero-terminated=1): null-terminated array of arguments
232  * @context: (allow-none): a parse context allocated with
233  *     gst_parse_context_new(), or %NULL
234  * @flags: parsing options, or #GST_PARSE_FLAG_NONE
235  * @error: pointer to a #GError (which must be initialised to %NULL)
236  *
237  * Create a new element based on command line syntax.
238  * @error will contain an error message if an erroneous pipeline is specified.
239  * An error does not mean that the pipeline could not be constructed.
240  *
241  * Returns: (transfer full): a new element on success; on failure, either %NULL
242  *   or a partially-constructed bin or element will be returned and @error will
243  *   be set (unless you passed #GST_PARSE_FLAG_FATAL_ERRORS in @flags, then
244  *   %NULL will always be returned on failure)
245  *
246  * Since: 0.10.20
247  */
248 GstElement *
249 gst_parse_launchv_full (const gchar ** argv, GstParseContext * context,
250     GstParseFlags flags, GError ** error)
252 #ifndef GST_DISABLE_PARSE
253   GstElement *element;
254   GString *str;
255   const gchar **argvp, *arg;
256   gchar *tmp;
258   g_return_val_if_fail (argv != NULL, NULL);
259   g_return_val_if_fail (error == NULL || *error == NULL, NULL);
261   /* let's give it a nice size. */
262   str = g_string_sized_new (1024);
264   argvp = argv;
265   while (*argvp) {
266     arg = *argvp;
267     tmp = _gst_parse_escape (arg);
268     g_string_append (str, tmp);
269     g_free (tmp);
270     g_string_append_c (str, ' ');
271     argvp++;
272   }
274   element = gst_parse_launch_full (str->str, context, flags, error);
276   g_string_free (str, TRUE);
278   return element;
279 #else
280   /* gst_parse_launch_full() will set a GST_CORE_ERROR_DISABLED error for us */
281   return gst_parse_launch_full ("", NULL, 0, error);
282 #endif
285 /**
286  * gst_parse_launch:
287  * @pipeline_description: the command line describing the pipeline
288  * @error: the error message in case of an erroneous pipeline.
289  *
290  * Create a new pipeline based on command line syntax.
291  * Please note that you might get a return value that is not %NULL even though
292  * the @error is set. In this case there was a recoverable parsing error and you
293  * can try to play the pipeline.
294  *
295  * Returns: (transfer full): a new element on success, %NULL on failure. If
296  *    more than one toplevel element is specified by the @pipeline_description,
297  *   all elements are put into a #GstPipeline, which than is returned.
298  */
299 GstElement *
300 gst_parse_launch (const gchar * pipeline_description, GError ** error)
302   return gst_parse_launch_full (pipeline_description, NULL, GST_PARSE_FLAG_NONE,
303       error);
306 /**
307  * gst_parse_launch_full:
308  * @pipeline_description: the command line describing the pipeline
309  * @context: (allow-none): a parse context allocated with
310  *      gst_parse_context_new(), or %NULL
311  * @flags: parsing options, or #GST_PARSE_FLAG_NONE
312  * @error: the error message in case of an erroneous pipeline.
313  *
314  * Create a new pipeline based on command line syntax.
315  * Please note that you might get a return value that is not %NULL even though
316  * the @error is set. In this case there was a recoverable parsing error and you
317  * can try to play the pipeline.
318  *
319  * Returns: (transfer full): a new element on success, %NULL on failure. If
320  *    more than one toplevel element is specified by the @pipeline_description,
321  *    all elements are put into a #GstPipeline, which then is returned.
322  *
323  * Since: 0.10.20
324  */
325 GstElement *
326 gst_parse_launch_full (const gchar * pipeline_description,
327     GstParseContext * context, GstParseFlags flags, GError ** error)
329 #ifndef GST_DISABLE_PARSE
330   GstElement *element;
332   g_return_val_if_fail (pipeline_description != NULL, NULL);
333   g_return_val_if_fail (error == NULL || *error == NULL, NULL);
335   GST_CAT_INFO (GST_CAT_PIPELINE, "parsing pipeline description '%s'",
336       pipeline_description);
338   element = _gst_parse_launch (pipeline_description, error, context, flags);
340   /* don't return partially constructed pipeline if FATAL_ERRORS was given */
341   if (G_UNLIKELY (error != NULL && *error != NULL && element != NULL)) {
342     if ((flags & GST_PARSE_FLAG_FATAL_ERRORS)) {
343       gst_object_unref (element);
344       element = NULL;
345     }
346   }
348   return element;
349 #else
350   gchar *msg;
352   GST_WARNING ("Disabled API called");
354   msg = gst_error_get_message (GST_CORE_ERROR, GST_CORE_ERROR_DISABLED);
355   g_set_error (error, GST_CORE_ERROR, GST_CORE_ERROR_DISABLED, "%s", msg);
356   g_free (msg);
358   return NULL;
359 #endif