source: trunk/third/gstreamer/gst/gstparse.c @ 21005

Revision 21005, 3.7 KB checked in by ghudson, 20 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r21004, which included commits to RCS files with non-trunk default branches.
Line 
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 *
6 * gstparse.c: get a pipeline from a text pipeline description
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 * Library General Public License for more details.
17 *
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
22 */
23
24#include <string.h>
25
26#include "gst_private.h"
27
28#include "gstparse.h"
29#include "gstinfo.h"
30
31extern GstElement *_gst_parse_launch (const gchar *, GError **);
32
33GQuark
34gst_parse_error_quark (void)
35{
36  static GQuark quark = 0;
37
38  if (!quark)
39    quark = g_quark_from_static_string ("gst_parse_error");
40  return quark;
41}
42
43static gchar *
44_gst_parse_escape (const gchar * str)
45{
46  GString *gstr = NULL;
47  gchar *newstr = NULL;
48
49  g_return_val_if_fail (str != NULL, NULL);
50
51  gstr = g_string_sized_new (strlen (str));
52
53  while (*str) {
54    if (*str == ' ')
55      g_string_append_c (gstr, '\\');
56    g_string_append_c (gstr, *str);
57    str++;
58  }
59
60  newstr = gstr->str;
61  g_string_free (gstr, FALSE);
62
63  return newstr;
64}
65
66/**
67 * gst_parse_launchv:
68 * @argv: null-terminated array of arguments
69 * @error: pointer to a #GError
70 *
71 * Create a new element based on command line syntax.
72 * #error will contain an error message if an erroneuos pipeline is specified.
73 * An error does not mean that the pipeline could not be constructed.
74 *
75 * Returns: a new element on success and NULL on failure.
76 */
77GstElement *
78gst_parse_launchv (const gchar ** argv, GError ** error)
79{
80  GstElement *element;
81  GString *str;
82  const gchar **argvp, *arg;
83  gchar *tmp;
84
85  g_return_val_if_fail (argv != NULL, NULL);
86
87  /* let's give it a nice size. */
88  str = g_string_sized_new (1024);
89
90  argvp = argv;
91  while (*argvp) {
92    arg = *argvp;
93    tmp = _gst_parse_escape (arg);
94    g_string_append (str, tmp);
95    g_free (tmp);
96    g_string_append (str, " ");
97    argvp++;
98  }
99
100  element = gst_parse_launch (str->str, error);
101
102  g_string_free (str, TRUE);
103
104  return element;
105}
106
107/**
108 * gst_parse_launch:
109 * @pipeline_description: the command line describing the pipeline
110 * @error: the error message in case of an erroneous pipeline.
111 *
112 * Create a new pipeline based on command line syntax.
113 * Please note that you might get a return value that is not NULL even though
114 * the error is set. In this case there was a recoverable parsing error and you
115 * can try to play the pipeline.
116 *
117 * Returns: a new element on success, NULL on failure. If more than one toplevel
118 * element is specified by the pipeline_description, all elements are put into
119 * a #GstPipeline ant that is returned.
120 */
121GstElement *
122gst_parse_launch (const gchar * pipeline_description, GError ** error)
123{
124  GstElement *element;
125  static GStaticMutex flex_lock = G_STATIC_MUTEX_INIT;
126
127  g_return_val_if_fail (pipeline_description != NULL, NULL);
128
129  GST_CAT_INFO (GST_CAT_PIPELINE, "parsing pipeline description %s",
130      pipeline_description);
131
132  /* the need for the mutex will go away with flex 2.5.6 */
133  g_static_mutex_lock (&flex_lock);
134  element = _gst_parse_launch (pipeline_description, error);
135  g_static_mutex_unlock (&flex_lock);
136
137  return element;
138}
Note: See TracBrowser for help on using the repository browser.