gstreamer_core/gst/gstparse.c
changeset 0 0e761a78d257
child 8 4a7fac7dd34a
equal deleted inserted replaced
-1:000000000000 0:0e761a78d257
       
     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 /**
       
    25  * SECTION:gstparse
       
    26  * @short_description: Get a pipeline from a text pipeline description
       
    27  *
       
    28  * These function allow to create a pipeline based on the syntax used in the
       
    29  * gst-launch utillity.
       
    30  */
       
    31 
       
    32 
       
    33 #include "gst_private.h"
       
    34 #include <string.h>
       
    35 
       
    36 #include "gstparse.h"
       
    37 #include "gsterror.h"
       
    38 #include "gstinfo.h"
       
    39 
       
    40 extern GstElement *_gst_parse_launch (const gchar *, GError **);
       
    41 
       
    42 /**
       
    43  * gst_parse_error_quark:
       
    44  *
       
    45  * Get the error quark used by the parsing subsystem.
       
    46  *
       
    47  * Returns: the quark of the parse errors.
       
    48  */
       
    49 #ifdef __SYMBIAN32__
       
    50 EXPORT_C
       
    51 #endif
       
    52 
       
    53 GQuark
       
    54 gst_parse_error_quark (void)
       
    55 {
       
    56   static GQuark quark = 0;
       
    57 
       
    58   if (!quark)
       
    59     quark = g_quark_from_static_string ("gst_parse_error");
       
    60   return quark;
       
    61 }
       
    62 
       
    63 #ifndef GST_DISABLE_PARSE
       
    64 static gchar *
       
    65 _gst_parse_escape (const gchar * str)
       
    66 {
       
    67   GString *gstr = NULL;
       
    68   gchar *newstr = NULL;
       
    69 
       
    70   g_return_val_if_fail (str != NULL, NULL);
       
    71 
       
    72   gstr = g_string_sized_new (strlen (str));
       
    73 
       
    74   while (*str) {
       
    75     if (*str == ' ')
       
    76       g_string_append_c (gstr, '\\');
       
    77     g_string_append_c (gstr, *str);
       
    78     str++;
       
    79   }
       
    80 
       
    81   newstr = gstr->str;
       
    82   g_string_free (gstr, FALSE);
       
    83 
       
    84   return newstr;
       
    85 }
       
    86 #endif /* !GST_DISABLE_PARSE */
       
    87 
       
    88 /**
       
    89  * gst_parse_launchv:
       
    90  * @argv: null-terminated array of arguments
       
    91  * @error: pointer to a #GError
       
    92  *
       
    93  * Create a new element based on command line syntax.
       
    94  * @error will contain an error message if an erroneuos pipeline is specified.
       
    95  * An error does not mean that the pipeline could not be constructed.
       
    96  *
       
    97  * Returns: a new element on success and %NULL on failure.
       
    98  */
       
    99 #ifdef __SYMBIAN32__
       
   100 EXPORT_C
       
   101 #endif
       
   102 
       
   103 GstElement *
       
   104 gst_parse_launchv (const gchar ** argv, GError ** error)
       
   105 {
       
   106 #ifndef GST_DISABLE_PARSE
       
   107   GstElement *element;
       
   108   GString *str;
       
   109   const gchar **argvp, *arg;
       
   110   gchar *tmp;
       
   111 
       
   112   g_return_val_if_fail (argv != NULL, NULL);
       
   113 
       
   114   /* let's give it a nice size. */
       
   115   str = g_string_sized_new (1024);
       
   116 
       
   117   argvp = argv;
       
   118   while (*argvp) {
       
   119     arg = *argvp;
       
   120     tmp = _gst_parse_escape (arg);
       
   121     g_string_append (str, tmp);
       
   122     g_free (tmp);
       
   123     g_string_append_c (str, ' ');
       
   124     argvp++;
       
   125   }
       
   126 
       
   127   element = gst_parse_launch (str->str, error);
       
   128 
       
   129   g_string_free (str, TRUE);
       
   130 
       
   131   return element;
       
   132 #else
       
   133   gchar *msg;
       
   134 
       
   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
       
   143 }
       
   144 
       
   145 /**
       
   146  * gst_parse_launch:
       
   147  * @pipeline_description: the command line describing the pipeline
       
   148  * @error: the error message in case of an erroneous pipeline.
       
   149  *
       
   150  * Create a new pipeline based on command line syntax.
       
   151  * Please note that you might get a return value that is not %NULL even though
       
   152  * the @error is set. In this case there was a recoverable parsing error and you
       
   153  * can try to play the pipeline.
       
   154  *
       
   155  * Returns: a new element on success, %NULL on failure. If more than one toplevel
       
   156  * element is specified by the @pipeline_description, all elements are put into
       
   157  * a #GstPipeline, which than is returned.
       
   158  */
       
   159 #ifdef __SYMBIAN32__
       
   160 EXPORT_C
       
   161 #endif
       
   162 
       
   163 GstElement *
       
   164 gst_parse_launch (const gchar * pipeline_description, GError ** error)
       
   165 {
       
   166 #ifndef GST_DISABLE_PARSE
       
   167   GstElement *element;
       
   168 
       
   169   g_return_val_if_fail (pipeline_description != NULL, NULL);
       
   170 
       
   171   GST_CAT_INFO (GST_CAT_PIPELINE, "parsing pipeline description %s",
       
   172       pipeline_description);
       
   173 
       
   174   element = _gst_parse_launch (pipeline_description, error);
       
   175 
       
   176   return element;
       
   177 #else
       
   178   gchar *msg;
       
   179 
       
   180   GST_WARNING ("Disabled API called: gst_parse_launch()");
       
   181 
       
   182   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);
       
   184   g_free (msg);
       
   185 
       
   186   return NULL;
       
   187 #endif
       
   188 }