capsfeature: add cleanup priv function
[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., 51 Franklin St, Fifth Floor,
20  * Boston, MA 02110-1301, 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 GstDeviceProvider */
58 #include "gstdeviceprovider.h"
59
60 /* for GstToc */
61 #include "gsttoc.h"
62
63 #include "gstdatetime.h"
64
65 #include "gsttracerutils.h"
66
67 G_BEGIN_DECLS
68
69 /* used by gstparse.c and grammar.y */
70 struct _GstParseContext {
71   GList * missing_elements;
72 };
73
74 /* used by gstplugin.c and gstregistrybinary.c */
75 typedef struct {
76   /* details registered via gst_plugin_add_dependency() */
77   GstPluginDependencyFlags  flags;
78   gchar **env_vars;
79   gchar **paths;
80   gchar **names;
81
82   /* information saved from the last time the plugin was loaded (-1 = unset) */
83   guint   env_hash;  /* hash of content of environment variables in env_vars */
84   guint   stat_hash; /* hash of stat() on all relevant files and directories */
85 } GstPluginDep;
86
87 struct _GstPluginPrivate {
88   GList *deps;    /* list of GstPluginDep structures */
89   GstStructure *cache_data;
90 };
91
92 /* FIXME: could rename all priv_gst_* functions to __gst_* now */
93 G_GNUC_INTERNAL  gboolean priv_gst_plugin_loading_have_whitelist (void);
94
95 G_GNUC_INTERNAL  guint32  priv_gst_plugin_loading_get_whitelist_hash (void);
96
97 G_GNUC_INTERNAL  gboolean priv_gst_plugin_desc_is_whitelisted (GstPluginDesc * desc,
98                                                                const gchar   * filename);
99
100 G_GNUC_INTERNAL  gboolean _priv_plugin_deps_env_vars_changed (GstPlugin * plugin);
101
102 G_GNUC_INTERNAL  gboolean _priv_plugin_deps_files_changed (GstPlugin * plugin);
103
104 G_GNUC_INTERNAL  gboolean _priv_gst_in_valgrind (void);
105
106 /* init functions called from gst_init(). */
107 G_GNUC_INTERNAL  void  _priv_gst_quarks_initialize (void);
108 G_GNUC_INTERNAL  void  _priv_gst_mini_object_initialize (void);
109 G_GNUC_INTERNAL  void  _priv_gst_memory_initialize (void);
110 G_GNUC_INTERNAL  void  _priv_gst_allocator_initialize (void);
111 G_GNUC_INTERNAL  void  _priv_gst_buffer_initialize (void);
112 G_GNUC_INTERNAL  void  _priv_gst_buffer_list_initialize (void);
113 G_GNUC_INTERNAL  void  _priv_gst_structure_initialize (void);
114 G_GNUC_INTERNAL  void  _priv_gst_caps_initialize (void);
115 G_GNUC_INTERNAL  void  _priv_gst_caps_features_initialize (void);
116 G_GNUC_INTERNAL  void  _priv_gst_event_initialize (void);
117 G_GNUC_INTERNAL  void  _priv_gst_format_initialize (void);
118 G_GNUC_INTERNAL  void  _priv_gst_message_initialize (void);
119 G_GNUC_INTERNAL  void  _priv_gst_meta_initialize (void);
120 G_GNUC_INTERNAL  void  _priv_gst_plugin_initialize (void);
121 G_GNUC_INTERNAL  void  _priv_gst_query_initialize (void);
122 G_GNUC_INTERNAL  void  _priv_gst_sample_initialize (void);
123 G_GNUC_INTERNAL  void  _priv_gst_tag_initialize (void);
124 G_GNUC_INTERNAL  void  _priv_gst_value_initialize (void);
125 G_GNUC_INTERNAL  void  _priv_gst_debug_init (void);
126 G_GNUC_INTERNAL  void  _priv_gst_context_initialize (void);
127 G_GNUC_INTERNAL  void  _priv_gst_toc_initialize (void);
128 G_GNUC_INTERNAL  void  _priv_gst_date_time_initialize (void);
129
130 /* cleanup functions called from gst_deinit(). */
131 G_GNUC_INTERNAL  void  _priv_gst_allocator_cleanup (void);
132 G_GNUC_INTERNAL  void  _priv_gst_caps_features_cleanup (void);
133
134 /* Private registry functions */
135 G_GNUC_INTERNAL
136 gboolean _priv_gst_registry_remove_cache_plugins (GstRegistry *registry);
137
138 G_GNUC_INTERNAL  void _priv_gst_registry_cleanup (void);
139
140 gboolean _gst_plugin_loader_client_run (void);
141
142 G_GNUC_INTERNAL  GstPlugin * _priv_gst_plugin_load_file_for_registry (const gchar *filename,
143                                                                       GstRegistry * registry,
144                                                                       GError** error);
145
146 /* Used in GstBin for manual state handling */
147 G_GNUC_INTERNAL  void _priv_gst_element_state_changed (GstElement *element,
148                       GstState oldstate, GstState newstate, GstState pending);
149
150 /* used in both gststructure.c and gstcaps.c; numbers are completely made up */
151 #define STRUCTURE_ESTIMATED_STRING_LEN(s) (16 + gst_structure_n_fields(s) * 22)
152 #define FEATURES_ESTIMATED_STRING_LEN(s) (16 + gst_caps_features_get_size(s) * 14)
153
154 G_GNUC_INTERNAL
155 gboolean  priv_gst_structure_append_to_gstring (const GstStructure * structure,
156                                                 GString            * s);
157 G_GNUC_INTERNAL
158 gboolean priv__gst_structure_append_template_to_gstring (GQuark field_id,
159                                                         const GValue *value,
160                                                         gpointer user_data);
161
162 G_GNUC_INTERNAL
163 void priv_gst_caps_features_append_to_gstring (const GstCapsFeatures * features, GString *s);
164
165 G_GNUC_INTERNAL
166 gboolean priv_gst_structure_parse_name (gchar * str, gchar **start, gchar ** end, gchar ** next);
167 G_GNUC_INTERNAL
168 gboolean priv_gst_structure_parse_fields (gchar *str, gchar ** end, GstStructure *structure);
169
170 /* used in gstvalue.c and gststructure.c */
171
172 #define GST_WRAPPED_PTR_FORMAT     "p\aa"
173
174 G_GNUC_INTERNAL
175 gchar *priv_gst_string_take_and_wrap (gchar * s);
176
177 /* registry cache backends */
178 G_GNUC_INTERNAL
179 gboolean                priv_gst_registry_binary_read_cache     (GstRegistry * registry, const char *location);
180
181 G_GNUC_INTERNAL
182 gboolean                priv_gst_registry_binary_write_cache    (GstRegistry * registry, GList * plugins, const char *location);
183
184
185 G_GNUC_INTERNAL
186 void      __gst_element_factory_add_static_pad_template (GstElementFactory    * elementfactory,
187                                                          GstStaticPadTemplate * templ);
188
189 G_GNUC_INTERNAL
190 void      __gst_element_factory_add_interface           (GstElementFactory    * elementfactory,
191                                                          const gchar          * interfacename);
192
193 /* used in gstvalue.c and gststructure.c */
194 #define GST_ASCII_IS_STRING(c) (g_ascii_isalnum((c)) || ((c) == '_') || \
195     ((c) == '-') || ((c) == '+') || ((c) == '/') || ((c) == ':') || \
196     ((c) == '.'))
197
198 /* This is only meant for internal uses */
199 G_GNUC_INTERNAL
200 gint __gst_date_time_compare (const GstDateTime * dt1, const GstDateTime * dt2);
201
202 G_GNUC_INTERNAL
203 gchar * __gst_date_time_serialize (GstDateTime * datetime, gboolean with_usecs);
204
205 /* Non-static, for access from the testsuite, but not for external use */
206 gboolean
207 _priv_gst_do_linear_regression (GstClockTime *times, guint n,
208     GstClockTime * m_num, GstClockTime * m_denom, GstClockTime * b,
209     GstClockTime * xbase, gdouble * r_squared);
210
211 /* For use in gstdebugutils */
212 G_GNUC_INTERNAL
213 GstCapsFeatures * __gst_caps_get_features_unchecked (const GstCaps * caps, guint idx);
214
215 #ifndef GST_DISABLE_REGISTRY
216 /* Secret variable to initialise gst without registry cache */
217 GST_EXPORT gboolean _gst_disable_registry_cache;
218 #endif
219
220 /* provide inline gst_g_value_get_foo_unchecked(), used in gststructure.c */
221 #define DEFINE_INLINE_G_VALUE_GET_UNCHECKED(ret_type,name_type,v_field) \
222 static inline ret_type                                                  \
223 gst_g_value_get_##name_type##_unchecked (const GValue *value)           \
224 {                                                                       \
225   return value->data[0].v_field;                                        \
226 }
227
228 DEFINE_INLINE_G_VALUE_GET_UNCHECKED(gboolean,boolean,v_int)
229 DEFINE_INLINE_G_VALUE_GET_UNCHECKED(gint,int,v_int)
230 DEFINE_INLINE_G_VALUE_GET_UNCHECKED(guint,uint,v_uint)
231 DEFINE_INLINE_G_VALUE_GET_UNCHECKED(gint64,int64,v_int64)
232 DEFINE_INLINE_G_VALUE_GET_UNCHECKED(guint64,uint64,v_uint64)
233 DEFINE_INLINE_G_VALUE_GET_UNCHECKED(gfloat,float,v_float)
234 DEFINE_INLINE_G_VALUE_GET_UNCHECKED(gdouble,double,v_double)
235 DEFINE_INLINE_G_VALUE_GET_UNCHECKED(const gchar *,string,v_pointer)
236
237
238 /*** debugging categories *****************************************************/
239
240 #ifndef GST_REMOVE_GST_DEBUG
241
242 GST_EXPORT GstDebugCategory *GST_CAT_GST_INIT;
243 GST_EXPORT GstDebugCategory *GST_CAT_MEMORY;
244 GST_EXPORT GstDebugCategory *GST_CAT_PARENTAGE;
245 GST_EXPORT GstDebugCategory *GST_CAT_STATES;
246 GST_EXPORT GstDebugCategory *GST_CAT_SCHEDULING;
247 GST_EXPORT GstDebugCategory *GST_CAT_BUFFER;
248 GST_EXPORT GstDebugCategory *GST_CAT_BUFFER_LIST;
249 GST_EXPORT GstDebugCategory *GST_CAT_BUS;
250 GST_EXPORT GstDebugCategory *GST_CAT_CAPS;
251 GST_EXPORT GstDebugCategory *GST_CAT_CLOCK;
252 GST_EXPORT GstDebugCategory *GST_CAT_ELEMENT_PADS;
253 GST_EXPORT GstDebugCategory *GST_CAT_PADS;
254 GST_EXPORT GstDebugCategory *GST_CAT_PERFORMANCE;
255 GST_EXPORT GstDebugCategory *GST_CAT_PIPELINE;
256 GST_EXPORT GstDebugCategory *GST_CAT_PLUGIN_LOADING;
257 GST_EXPORT GstDebugCategory *GST_CAT_PLUGIN_INFO;
258 GST_EXPORT GstDebugCategory *GST_CAT_PROPERTIES;
259 GST_EXPORT GstDebugCategory *GST_CAT_NEGOTIATION;
260 GST_EXPORT GstDebugCategory *GST_CAT_REFCOUNTING;
261 GST_EXPORT GstDebugCategory *GST_CAT_ERROR_SYSTEM;
262 GST_EXPORT GstDebugCategory *GST_CAT_EVENT;
263 GST_EXPORT GstDebugCategory *GST_CAT_MESSAGE;
264 GST_EXPORT GstDebugCategory *GST_CAT_PARAMS;
265 GST_EXPORT GstDebugCategory *GST_CAT_CALL_TRACE;
266 GST_EXPORT GstDebugCategory *GST_CAT_SIGNAL;
267 GST_EXPORT GstDebugCategory *GST_CAT_PROBE;
268 GST_EXPORT GstDebugCategory *GST_CAT_REGISTRY;
269 GST_EXPORT GstDebugCategory *GST_CAT_QOS;
270 GST_EXPORT GstDebugCategory *GST_CAT_META;
271 GST_EXPORT GstDebugCategory *GST_CAT_LOCKING;
272 GST_EXPORT GstDebugCategory *GST_CAT_CONTEXT;
273
274 /* Categories that should be completely private to
275  * libgstreamer should be done like this: */
276 #define GST_CAT_POLL _priv_GST_CAT_POLL
277 extern GstDebugCategory *_priv_GST_CAT_POLL;
278
279 #define GST_CAT_PROTECTION _priv_GST_CAT_PROTECTION
280 extern GstDebugCategory *_priv_GST_CAT_PROTECTION;
281
282 extern GstClockTime _priv_gst_start_time;
283
284 #else
285
286 #define GST_CAT_GST_INIT         NULL
287 #define GST_CAT_AUTOPLUG         NULL
288 #define GST_CAT_AUTOPLUG_ATTEMPT NULL
289 #define GST_CAT_PARENTAGE        NULL
290 #define GST_CAT_STATES           NULL
291 #define GST_CAT_SCHEDULING       NULL
292 #define GST_CAT_DATAFLOW         NULL
293 #define GST_CAT_BUFFER           NULL
294 #define GST_CAT_BUFFER_LIST      NULL
295 #define GST_CAT_BUS              NULL
296 #define GST_CAT_CAPS             NULL
297 #define GST_CAT_CLOCK            NULL
298 #define GST_CAT_ELEMENT_PADS     NULL
299 #define GST_CAT_PADS             NULL
300 #define GST_CAT_PERFORMANCE      NULL
301 #define GST_CAT_PIPELINE         NULL
302 #define GST_CAT_PLUGIN_LOADING   NULL
303 #define GST_CAT_PLUGIN_INFO      NULL
304 #define GST_CAT_PROPERTIES       NULL
305 #define GST_CAT_NEGOTIATION      NULL
306 #define GST_CAT_REFCOUNTING      NULL
307 #define GST_CAT_ERROR_SYSTEM     NULL
308 #define GST_CAT_EVENT            NULL
309 #define GST_CAT_MESSAGE          NULL
310 #define GST_CAT_PARAMS           NULL
311 #define GST_CAT_CALL_TRACE       NULL
312 #define GST_CAT_SIGNAL           NULL
313 #define GST_CAT_PROBE            NULL
314 #define GST_CAT_REGISTRY         NULL
315 #define GST_CAT_QOS              NULL
316 #define GST_CAT_TYPES            NULL
317 #define GST_CAT_POLL             NULL
318 #define GST_CAT_META             NULL
319 #define GST_CAT_LOCKING          NULL
320 #define GST_CAT_CONTEXT          NULL
321 #define GST_CAT_PROTECTION       NULL
322
323 #endif
324
325 #ifdef GST_DISABLE_GST_DEBUG
326 /* for _gst_element_error_printf */
327 #define __gst_vasprintf __gst_info_fallback_vasprintf
328 int __gst_vasprintf (char **result, char const *format, va_list args);
329 #endif
330
331 /**** objects made opaque until the private bits have been made private ****/
332
333 #include <gmodule.h>
334 #include <time.h> /* time_t */
335 #include <sys/types.h> /* off_t */
336 #include <sys/stat.h> /* off_t */
337
338 typedef struct _GstPluginPrivate GstPluginPrivate;
339
340 struct _GstPlugin {
341   GstObject       object;
342
343   /*< private >*/
344   GstPluginDesc desc;
345
346   GstPluginDesc *orig_desc;
347
348   gchar *       filename;
349   gchar *       basename;       /* base name (non-dir part) of plugin path */
350
351   GModule *     module;         /* contains the module if plugin is loaded */
352
353   off_t         file_size;
354   time_t        file_mtime;
355   gboolean      registered;     /* TRUE when the registry has seen a filename
356                                  * that matches the plugin's basename */
357
358   GstPluginPrivate *priv;
359
360   gpointer _gst_reserved[GST_PADDING];
361 };
362
363 struct _GstPluginClass {
364   GstObjectClass  object_class;
365
366   /*< private >*/
367   gpointer _gst_reserved[GST_PADDING];
368 };
369
370 struct _GstPluginFeature {
371   GstObject      object;
372
373   /*< private >*/
374   gboolean       loaded;
375   guint          rank;
376
377   const gchar   *plugin_name;
378   GstPlugin     *plugin;      /* weak ref */
379
380   /*< private >*/
381   gpointer _gst_reserved[GST_PADDING];
382 };
383
384 struct _GstPluginFeatureClass {
385   GstObjectClass        parent_class;
386
387   /*< private >*/
388   gpointer _gst_reserved[GST_PADDING];
389 };
390
391 #include "gsttypefind.h"
392
393 struct _GstTypeFindFactory {
394   GstPluginFeature              feature;
395   /* <private> */
396
397   GstTypeFindFunction           function;
398   gchar **                      extensions;
399   GstCaps *                     caps;
400
401   gpointer                      user_data;
402   GDestroyNotify                user_data_notify;
403
404   gpointer _gst_reserved[GST_PADDING];
405 };
406
407 struct _GstTypeFindFactoryClass {
408   GstPluginFeatureClass         parent;
409   /* <private> */
410
411   gpointer _gst_reserved[GST_PADDING];
412 };
413
414 struct _GstTracerFactory {
415   GstPluginFeature              feature;
416   /* <private> */
417
418   GType                         type;
419
420   /*
421   gpointer                      user_data;
422   GDestroyNotify                user_data_notify;
423   */
424
425   gpointer _gst_reserved[GST_PADDING];
426 };
427
428 struct _GstTracerFactoryClass {
429   GstPluginFeatureClass         parent;
430   /* <private> */
431
432   gpointer _gst_reserved[GST_PADDING];
433 };
434
435 struct _GstElementFactory {
436   GstPluginFeature      parent;
437
438   GType                 type;                   /* unique GType of element or 0 if not loaded */
439
440   gpointer              metadata;
441
442   GList *               staticpadtemplates;     /* GstStaticPadTemplate list */
443   guint                 numpadtemplates;
444
445   /* URI interface stuff */
446   GstURIType            uri_type;
447   gchar **              uri_protocols;
448
449   GList *               interfaces;             /* interface type names this element implements */
450
451   /*< private >*/
452   gpointer _gst_reserved[GST_PADDING];
453 };
454
455 struct _GstElementFactoryClass {
456   GstPluginFeatureClass parent_class;
457
458   gpointer _gst_reserved[GST_PADDING];
459 };
460
461 struct _GstDeviceProviderFactory {
462   GstPluginFeature           feature;
463   /* <private> */
464
465   GType                      type;              /* unique GType the device factory or 0 if not loaded */
466
467   volatile GstDeviceProvider *provider;
468   gpointer                   metadata;
469
470   gpointer _gst_reserved[GST_PADDING];
471 };
472
473 struct _GstDeviceProviderFactoryClass {
474   GstPluginFeatureClass         parent;
475   /* <private> */
476
477   gpointer _gst_reserved[GST_PADDING];
478 };
479
480 /* privat flag used by GstBus / GstMessage */
481 #define GST_MESSAGE_FLAG_ASYNC_DELIVERY (GST_MINI_OBJECT_FLAG_LAST << 0)
482
483 G_END_DECLS
484 #endif /* __GST_PRIVATE_H__ */