gstfunnel: avoid access of freed pad
[platform/upstream/gstreamer.git] / gst / gst_private.h
1 /* GStreamer
2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3  *                    2000 Wim Taymans <wtay@chello.be>
4  *
5  * gst_private.h: Private header for within libgst
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 #ifndef __GST_PRIVATE_H__
24 #define __GST_PRIVATE_H__
25
26 #ifdef HAVE_CONFIG_H
27 # ifndef GST_LICENSE   /* don't include config.h twice, it has no guards */
28 #  include "config.h"
29 # endif
30 #endif
31
32 /* This needs to be before glib.h, since it might be used in inline
33  * functions */
34 extern const char             g_log_domain_gstreamer[];
35
36 #include <glib.h>
37
38 #include <stdlib.h>
39 #include <string.h>
40
41 /* Needed for GstRegistry * */
42 #include "gstregistry.h"
43 #include "gststructure.h"
44
45 /* we need this in pretty much all files */
46 #include "gstinfo.h"
47
48 /* for the flags in the GstPluginDep structure below */
49 #include "gstplugin.h"
50
51 /* for the pad cache */
52 #include "gstpad.h"
53
54 /* for GstElement */
55 #include "gstelement.h"
56
57 /* for GstToc */
58 #include "gsttoc.h"
59
60 G_BEGIN_DECLS
61
62 /* used by gstparse.c and grammar.y */
63 struct _GstParseContext {
64   GList * missing_elements;
65 };
66
67 /* used by gstplugin.c and gstregistrybinary.c */
68 typedef struct {
69   /* details registered via gst_plugin_add_dependency() */
70   GstPluginDependencyFlags  flags;
71   gchar **env_vars;
72   gchar **paths;
73   gchar **names;
74
75   /* information saved from the last time the plugin was loaded (-1 = unset) */
76   guint   env_hash;  /* hash of content of environment variables in env_vars */
77   guint   stat_hash; /* hash of stat() on all relevant files and directories */
78 } GstPluginDep;
79
80 struct _GstPluginPrivate {
81   GList *deps;    /* list of GstPluginDep structures */
82   GstStructure *cache_data;
83 };
84
85 /* FIXME: could rename all priv_gst_* functions to __gst_* now */
86 gboolean priv_gst_plugin_loading_have_whitelist (void);
87
88 guint32  priv_gst_plugin_loading_get_whitelist_hash (void);
89
90 gboolean priv_gst_plugin_desc_is_whitelisted (GstPluginDesc * desc,
91                                               const gchar   * filename);
92
93 gboolean _priv_plugin_deps_env_vars_changed (GstPlugin * plugin);
94 gboolean _priv_plugin_deps_files_changed (GstPlugin * plugin);
95
96 gboolean _priv_gst_in_valgrind (void);
97
98 /* init functions called from gst_init(). */
99 void  _priv_gst_quarks_initialize (void);
100 void  _priv_gst_mini_object_initialize (void);
101 void  _priv_gst_buffer_initialize (void);
102 void  _priv_gst_buffer_list_initialize (void);
103 void  _priv_gst_structure_initialize (void);
104 void  _priv_gst_caps_initialize (void);
105 void  _priv_gst_event_initialize (void);
106 void  _priv_gst_format_initialize (void);
107 void  _priv_gst_message_initialize (void);
108 void  _priv_gst_memory_initialize (void);
109 void  _priv_gst_meta_initialize (void);
110 void  _priv_gst_plugin_initialize (void);
111 void  _priv_gst_query_initialize (void);
112 void  _priv_gst_sample_initialize (void);
113 void  _priv_gst_tag_initialize (void);
114 void  _priv_gst_value_initialize (void);
115 void  _priv_gst_debug_init (void);
116
117 /* TOC functions */
118 /* These functions are used to parse TOC messages, events and queries */
119 GstToc*        __gst_toc_from_structure (const GstStructure *toc);
120 GstStructure*  __gst_toc_to_structure (const GstToc *toc);
121 gboolean       __gst_toc_structure_get_updated (const GstStructure * toc);
122 void           __gst_toc_structure_set_updated (GstStructure * toc, gboolean updated);
123 gchar*         __gst_toc_structure_get_extend_uid (const GstStructure * toc);
124 void           __gst_toc_structure_set_extend_uid (GstStructure * toc, const gchar * extend_uid);
125
126 /* Private registry functions */
127 gboolean _priv_gst_registry_remove_cache_plugins (GstRegistry *registry);
128 void _priv_gst_registry_cleanup (void);
129 gboolean _gst_plugin_loader_client_run (void);
130
131 /* Used in GstBin for manual state handling */
132 void _priv_gst_element_state_changed (GstElement *element, GstState oldstate,
133     GstState newstate, GstState pending);
134
135 /* used in both gststructure.c and gstcaps.c; numbers are completely made up */
136 #define STRUCTURE_ESTIMATED_STRING_LEN(s) (16 + gst_structure_n_fields(s) * 22)
137
138 gboolean  priv_gst_structure_append_to_gstring (const GstStructure * structure,
139                                                 GString            * s);
140 /* registry cache backends */
141 gboolean                priv_gst_registry_binary_read_cache     (GstRegistry * registry, const char *location);
142 gboolean                priv_gst_registry_binary_write_cache    (GstRegistry * registry, GList * plugins, const char *location);
143
144 void      __gst_element_factory_add_static_pad_template (GstElementFactory    * elementfactory,
145                                                          GstStaticPadTemplate * templ);
146
147 void      __gst_element_factory_add_interface           (GstElementFactory    * elementfactory,
148                                                          const gchar          * interfacename);
149
150 /* used in gstvalue.c and gststructure.c */
151 #define GST_ASCII_IS_STRING(c) (g_ascii_isalnum((c)) || ((c) == '_') || \
152     ((c) == '-') || ((c) == '+') || ((c) == '/') || ((c) == ':') || \
153     ((c) == '.'))
154
155 /* This is only meant for internal uses */
156 gint priv_gst_date_time_compare (gconstpointer dt1, gconstpointer dt2);
157
158 #ifndef GST_DISABLE_REGISTRY
159 /* Secret variable to initialise gst without registry cache */
160 GST_EXPORT gboolean _gst_disable_registry_cache;
161 #endif
162
163 /* provide inline gst_g_value_get_foo_unchecked(), used in gststructure.c */
164 #define DEFINE_INLINE_G_VALUE_GET_UNCHECKED(ret_type,name_type,v_field) \
165 static inline ret_type                                                  \
166 gst_g_value_get_##name_type##_unchecked (const GValue *value)           \
167 {                                                                       \
168   return value->data[0].v_field;                                        \
169 }
170
171 DEFINE_INLINE_G_VALUE_GET_UNCHECKED(gboolean,boolean,v_int)
172 DEFINE_INLINE_G_VALUE_GET_UNCHECKED(gint,int,v_int)
173 DEFINE_INLINE_G_VALUE_GET_UNCHECKED(guint,uint,v_uint)
174 DEFINE_INLINE_G_VALUE_GET_UNCHECKED(gint64,int64,v_int64)
175 DEFINE_INLINE_G_VALUE_GET_UNCHECKED(guint64,uint64,v_uint64)
176 DEFINE_INLINE_G_VALUE_GET_UNCHECKED(gfloat,float,v_float)
177 DEFINE_INLINE_G_VALUE_GET_UNCHECKED(gdouble,double,v_double)
178 DEFINE_INLINE_G_VALUE_GET_UNCHECKED(const gchar *,string,v_pointer)
179
180
181 /*** debugging categories *****************************************************/
182
183 #ifndef GST_REMOVE_GST_DEBUG
184
185 GST_EXPORT GstDebugCategory *GST_CAT_GST_INIT;
186 GST_EXPORT GstDebugCategory *GST_CAT_MEMORY;
187 GST_EXPORT GstDebugCategory *GST_CAT_PARENTAGE;
188 GST_EXPORT GstDebugCategory *GST_CAT_STATES;
189 GST_EXPORT GstDebugCategory *GST_CAT_SCHEDULING;
190 GST_EXPORT GstDebugCategory *GST_CAT_BUFFER;
191 GST_EXPORT GstDebugCategory *GST_CAT_BUFFER_LIST;
192 GST_EXPORT GstDebugCategory *GST_CAT_BUS;
193 GST_EXPORT GstDebugCategory *GST_CAT_CAPS;
194 GST_EXPORT GstDebugCategory *GST_CAT_CLOCK;
195 GST_EXPORT GstDebugCategory *GST_CAT_ELEMENT_PADS;
196 GST_EXPORT GstDebugCategory *GST_CAT_PADS;
197 GST_EXPORT GstDebugCategory *GST_CAT_PERFORMANCE;
198 GST_EXPORT GstDebugCategory *GST_CAT_PIPELINE;
199 GST_EXPORT GstDebugCategory *GST_CAT_PLUGIN_LOADING;
200 GST_EXPORT GstDebugCategory *GST_CAT_PLUGIN_INFO;
201 GST_EXPORT GstDebugCategory *GST_CAT_PROPERTIES;
202 GST_EXPORT GstDebugCategory *GST_CAT_NEGOTIATION;
203 GST_EXPORT GstDebugCategory *GST_CAT_REFCOUNTING;
204 GST_EXPORT GstDebugCategory *GST_CAT_ERROR_SYSTEM;
205 GST_EXPORT GstDebugCategory *GST_CAT_EVENT;
206 GST_EXPORT GstDebugCategory *GST_CAT_MESSAGE;
207 GST_EXPORT GstDebugCategory *GST_CAT_PARAMS;
208 GST_EXPORT GstDebugCategory *GST_CAT_CALL_TRACE;
209 GST_EXPORT GstDebugCategory *GST_CAT_SIGNAL;
210 GST_EXPORT GstDebugCategory *GST_CAT_PROBE;
211 GST_EXPORT GstDebugCategory *GST_CAT_REGISTRY;
212 GST_EXPORT GstDebugCategory *GST_CAT_QOS;
213 GST_EXPORT GstDebugCategory *GST_CAT_META;
214
215 /* Categories that should be completely private to
216  * libgstreamer should be done like this: */
217 #define GST_CAT_POLL _priv_GST_CAT_POLL
218 extern GstDebugCategory *_priv_GST_CAT_POLL;
219
220 #else
221
222 #define GST_CAT_GST_INIT         NULL
223 #define GST_CAT_AUTOPLUG         NULL
224 #define GST_CAT_AUTOPLUG_ATTEMPT NULL
225 #define GST_CAT_PARENTAGE        NULL
226 #define GST_CAT_STATES           NULL
227 #define GST_CAT_SCHEDULING       NULL
228 #define GST_CAT_DATAFLOW         NULL
229 #define GST_CAT_BUFFER           NULL
230 #define GST_CAT_BUFFER_LIST      NULL
231 #define GST_CAT_BUS              NULL
232 #define GST_CAT_CAPS             NULL
233 #define GST_CAT_CLOCK            NULL
234 #define GST_CAT_ELEMENT_PADS     NULL
235 #define GST_CAT_PADS             NULL
236 #define GST_CAT_PERFORMANCE      NULL
237 #define GST_CAT_PIPELINE         NULL
238 #define GST_CAT_PLUGIN_LOADING   NULL
239 #define GST_CAT_PLUGIN_INFO      NULL
240 #define GST_CAT_PROPERTIES       NULL
241 #define GST_CAT_NEGOTIATION      NULL
242 #define GST_CAT_REFCOUNTING      NULL
243 #define GST_CAT_ERROR_SYSTEM     NULL
244 #define GST_CAT_EVENT            NULL
245 #define GST_CAT_MESSAGE          NULL
246 #define GST_CAT_PARAMS           NULL
247 #define GST_CAT_CALL_TRACE       NULL
248 #define GST_CAT_SIGNAL           NULL
249 #define GST_CAT_PROBE            NULL
250 #define GST_CAT_REGISTRY         NULL
251 #define GST_CAT_QOS              NULL
252 #define GST_CAT_TYPES            NULL
253 #define GST_CAT_POLL             NULL
254 #define GST_CAT_META             NULL
255
256 #endif
257
258
259 /**** objects made opaque until the private bits have been made private ****/
260
261 #include <gmodule.h>
262 #include <time.h> /* time_t */
263 #include <sys/types.h> /* off_t */
264 #include <sys/stat.h> /* off_t */
265
266 typedef struct _GstPluginPrivate GstPluginPrivate;
267
268 struct _GstPlugin {
269   GstObject       object;
270
271   /*< private >*/
272   GstPluginDesc desc;
273
274   GstPluginDesc *orig_desc;
275
276   gchar *       filename;
277   gchar *       basename;       /* base name (non-dir part) of plugin path */
278
279   GModule *     module;         /* contains the module if plugin is loaded */
280
281   off_t         file_size;
282   time_t        file_mtime;
283   gboolean      registered;     /* TRUE when the registry has seen a filename
284                                  * that matches the plugin's basename */
285
286   GstPluginPrivate *priv;
287
288   gpointer _gst_reserved[GST_PADDING];
289 };
290
291 struct _GstPluginClass {
292   GstObjectClass  object_class;
293
294   /*< private >*/
295   gpointer _gst_reserved[GST_PADDING];
296 };
297
298 struct _GstPluginFeature {
299   GstObject      object;
300
301   /*< private >*/
302   gboolean       loaded;
303   guint          rank;
304
305   const gchar   *plugin_name;
306   GstPlugin     *plugin;      /* weak ref */
307
308   /*< private >*/
309   gpointer _gst_reserved[GST_PADDING];
310 };
311
312 struct _GstPluginFeatureClass {
313   GstObjectClass        parent_class;
314
315   /*< private >*/
316   gpointer _gst_reserved[GST_PADDING];
317 };
318
319 #include "gsttypefind.h"
320
321 struct _GstTypeFindFactory {
322   GstPluginFeature              feature;
323   /* <private> */
324
325   GstTypeFindFunction           function;
326   gchar **                      extensions;
327   GstCaps *                     caps; /* FIXME: not yet saved in registry */
328
329   gpointer                      user_data;
330   GDestroyNotify                user_data_notify;
331
332   gpointer _gst_reserved[GST_PADDING];
333 };
334
335 struct _GstTypeFindFactoryClass {
336   GstPluginFeatureClass         parent;
337   /* <private> */
338
339   gpointer _gst_reserved[GST_PADDING];
340 };
341
342 struct _GstElementFactory {
343   GstPluginFeature      parent;
344
345   GType                 type;                   /* unique GType of element or 0 if not loaded */
346
347   gpointer              metadata;
348
349   GList *               staticpadtemplates;     /* GstStaticPadTemplate list */
350   guint                 numpadtemplates;
351
352   /* URI interface stuff */
353   GstURIType            uri_type;
354   gchar **              uri_protocols;
355
356   GList *               interfaces;             /* interface type names this element implements */
357
358   /*< private >*/
359   gpointer _gst_reserved[GST_PADDING];
360 };
361
362 struct _GstElementFactoryClass {
363   GstPluginFeatureClass parent_class;
364
365   gpointer _gst_reserved[GST_PADDING];
366 };
367
368 G_END_DECLS
369 #endif /* __GST_PRIVATE_H__ */