Added mthodes to request an element to create pads: gst_element_request_pad*
[platform/upstream/gstreamer.git] / gst / gst.c
1 /* GStreamer
2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3  *                    2000 Wim Taymans <wtay@chello.be>
4  *
5  * gst.c: Initialization and non-pipeline operations
6  *
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.
11  *
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.
16  *
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.
21  */
22
23 #include <stdlib.h>
24
25 #include "gst_private.h"
26
27 #include "gstcpu.h"
28 #include "gsttype.h"
29 #include "gstplugin.h"
30 #include "gstbuffer.h"
31 #include "gstbin.h"
32 #include "gstpipeline.h"
33 #include "gstthread.h"
34
35
36
37 gchar *_gst_progname;
38
39
40 extern gint _gst_trace_on;
41
42
43 static gboolean         gst_init_check          (int *argc, gchar ***argv);
44
45 /**
46  * gst_init:
47  * @argc: pointer to application's argc
48  * @argv: pointer to application's argv
49  *
50  * Initializes the GStreamer library, setting up internal path lists,
51  * registering built-in elements, and loading standard plugins.
52  */
53 void 
54 gst_init (int *argc, char **argv[]) 
55 {
56   GstTrace *gst_trace;
57
58   GST_INFO (GST_CAT_GST_INIT, "Initializing GStreamer Core Library");
59
60   if (!g_thread_supported ()) g_thread_init (NULL);
61
62   _gst_progname = g_strdup(*argv[0]);
63
64   gtk_init (argc,argv);
65
66   if (!gst_init_check (argc,argv)) {
67     exit (0);
68   }
69
70   _gst_cpu_initialize ();
71   _gst_type_initialize ();
72   _gst_plugin_initialize ();
73   _gst_buffer_initialize ();
74
75   /* register some standard builtin types */
76   gst_elementfactory_new ("bin", gst_bin_get_type (), &gst_bin_details);
77   gst_elementfactory_new ("pipeline", gst_pipeline_get_type (), &gst_pipeline_details);
78   gst_elementfactory_new ("thread", gst_thread_get_type (), &gst_thread_details);
79
80   _gst_trace_on = 0;
81   if (_gst_trace_on) {
82     gst_trace = gst_trace_new ("gst.trace",1024);
83     gst_trace_set_default (gst_trace);
84   }
85 }
86
87 /* returns FALSE if the program can be aborted */
88 static gboolean
89 gst_init_check (int     *argc,
90                 gchar ***argv)
91 {
92   gboolean ret = TRUE;
93   gboolean showhelp = FALSE;
94
95   if (argc && argv) {
96     gint i, j, k;
97
98     for (i=1; i< *argc; i++) {
99       if (!strncmp ("--gst-info-mask=", (*argv)[i], 16)) {
100         guint32 val;
101
102         // handle either 0xHEX or dec
103         if (*((*argv)[i]+17) == 'x') {
104           sscanf ((*argv)[i]+18, "%08x", &val);
105         } else {
106           sscanf ((*argv)[i]+16, "%d", &val);
107         }
108
109         gst_info_set_categories (val);
110
111         (*argv)[i] = NULL;
112       }
113       else if (!strncmp ("--gst-debug-mask=", (*argv)[i], 17)) {
114         guint32 val;
115
116         // handle either 0xHEX or dec
117         if (*((*argv)[i]+18) == 'x') {
118           sscanf ((*argv)[i]+19, "%08x", &val);
119         } else {
120           sscanf ((*argv)[i]+17, "%d", &val);
121         }
122
123         gst_debug_set_categories (val);
124
125         (*argv)[i] = NULL;
126       }
127       else if (!strncmp ("--help", (*argv)[i], 6)) {
128         showhelp = TRUE;
129       }
130     }
131
132     for (i = 1; i < *argc; i++) {
133       for (k = i; k < *argc; k++)
134         if ((*argv)[k] != NULL)
135           break;
136
137       if (k > i) {
138         k -= i;
139         for (j = i + k; j < *argc; j++)
140           (*argv)[j-k] = (*argv)[j];
141         *argc -= k;
142       }
143     }
144   }
145
146   if (showhelp) {
147     guint i;
148
149     g_print ("usage %s [OPTION...]\n", (*argv)[0]);
150
151     g_print ("\nGStreamer options\n");
152     g_print ("  --gst-info-mask=FLAGS               Gst info flags to set (current %08x)\n", gst_info_get_categories());
153     g_print ("  --gst-debug-mask=FLAGS              Gst debugging flags to set\n");
154
155     g_print ("\nGStreamer info/debug FLAGS (to be OR'ed)\n");
156
157     for (i = 0; i<GST_CAT_MAX_CATEGORY; i++) {
158       g_print ("   0x%08x    %s     %s\n", 1<<i, 
159                   (gst_info_get_categories() & (1<<i)?"(enabled)":"         "),
160                    gst_get_category_name (i));
161     }
162
163     ret = FALSE;
164   }
165
166   return ret;
167 }
168
169 /**
170  * gst_main:
171  *
172  * Enter the main GStreamer processing loop 
173  */
174 void 
175 gst_main (void) 
176 {
177   gtk_main ();
178 }
179
180 /**
181  * gst_main_quit:
182  *
183  * Exits the main GStreamer processing loop 
184  */
185 void 
186 gst_main_quit (void) 
187 {
188   gtk_main_quit ();
189 }