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