X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=gst%2Fgst.c;h=8087aa41097d0da550f82f6cddcbfd109581b170;hb=a87b4551a6090663a1714f263d4e20fe75eb46ca;hp=c411683f10bb324de8a1b35ee2b9df3bd5867d4d;hpb=5c47cf759af29678bb4e2907430f38d848aa30ea;p=platform%2Fupstream%2Fgstreamer.git diff --git a/gst/gst.c b/gst/gst.c index c411683..8087aa4 100644 --- a/gst/gst.c +++ b/gst/gst.c @@ -22,11 +22,12 @@ /** * SECTION:gst + * @title: GStreamer * @short_description: Media library supporting arbitrary formats and filter * graphs. * * GStreamer is a framework for constructing graphs of various filters - * (termed elements here) that will handle streaming media. Any discreet + * (termed elements here) that will handle streaming media. Any discrete * (packetizable) media type is supported, with provisions for automatically * determining source type. Formatting/framing information is provided with * a powerful negotiation framework. Plugins are heavily used to provide for @@ -40,9 +41,9 @@ * and argv variables so that GStreamer can process its own command line * options, as shown in the following example. * - * - * Initializing the gstreamer library - * + * ## Initializing the gstreamer library + * + * |[ * int * main (int argc, char *argv[]) * { @@ -50,17 +51,16 @@ * gst_init (&argc, &argv); * ... * } - * - * + * ]| * - * It's allowed to pass two NULL pointers to gst_init() in case you don't want + * It's allowed to pass two %NULL pointers to gst_init() in case you don't want * to pass the command line args to GStreamer. * * You can also use GOption to initialize your own parameters as shown in * the next code fragment: - * - * Initializing own parameters when initializing gstreamer - * + * + * ## Initializing own parameters when initializing gstreamer + * |[ * static gboolean stats = FALSE; * ... * int @@ -81,18 +81,14 @@ * g_option_context_free (ctx); * ... * } - * - * + * ]| * * Use gst_version() to query the library version at runtime or use the * GST_VERSION_* macros to find the version at compile time. Optionally * gst_version_string() returns a printable string. * * The gst_deinit() call is used to clean up all internal resources used - * by GStreamer. It is mostly used in unit tests - * to check for leaks. - * - * Last reviewed on 2006-08-11 (0.10.10) + * by GStreamer. It is mostly used in unit tests to check for leaks. */ #include "gst_private.h" @@ -115,7 +111,6 @@ #include /* for LC_ALL */ #include "gst.h" -#include "gsttrace.h" #define GST_CAT_DEFAULT GST_CAT_GST_INIT @@ -125,13 +120,16 @@ static gboolean gst_initialized = FALSE; static gboolean gst_deinitialized = FALSE; +GstClockTime _priv_gst_start_time; + #ifdef G_OS_WIN32 HMODULE _priv_gst_dll_handle = NULL; #endif #ifndef GST_DISABLE_REGISTRY -GList *_priv_gst_plugin_paths = NULL; /* for delayed processing in post_init */ +GList *_priv_gst_plugin_paths = NULL; /* for delayed processing in init_post */ +extern gboolean _priv_gst_disable_registry; extern gboolean _priv_gst_disable_registry_update; #endif @@ -194,6 +192,17 @@ enum */ #ifdef G_OS_WIN32 +/* Note: DllMain is only called when DLLs are loaded or unloaded, so this will + * never be called if libgstreamer-1.0 is linked statically. Do not add any code + * here to, say, initialize variables or set things up since that will only + * happen for dynamically-built GStreamer. + * + * Also, ideally this should not be defined when GStreamer is built statically. + * i.e., it should be conditional on #ifdef DLL_EXPORT. It will be ignored, but + * if other libraries make the same mistake of defining it when building + * statically, there will be a symbol collision during linking. Fixing this + * requires one to build two object files: one for static linking and another + * for dynamic linking. */ BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved); BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) @@ -320,14 +329,18 @@ gst_init_get_option_group (void) gboolean gst_init_check (int *argc, char **argv[], GError ** err) { + static GMutex init_lock; #ifndef GST_DISABLE_OPTION_PARSING GOptionGroup *group; GOptionContext *ctx; #endif gboolean res; + g_mutex_lock (&init_lock); + if (gst_initialized) { GST_DEBUG ("already initialized gst"); + g_mutex_unlock (&init_lock); return TRUE; } #ifndef GST_DISABLE_OPTION_PARSING @@ -346,11 +359,7 @@ gst_init_check (int *argc, char **argv[], GError ** err) gst_initialized = res; - if (res) { - GST_INFO ("initialized GStreamer successfully"); - } else { - GST_INFO ("failed to initialize GStreamer"); - } + g_mutex_unlock (&init_lock); return res; } @@ -370,11 +379,9 @@ gst_init_check (int *argc, char **argv[], GError ** err) * Running GStreamer Applications * for how to disable automatic registry updates. * - * - * This function will terminate your program if it was unable to initialize - * GStreamer for some reason. If you want your program to fall back, - * use gst_init_check() instead. - * + * > This function will terminate your program if it was unable to initialize + * > GStreamer for some reason. If you want your program to fall back, + * > use gst_init_check() instead. * * WARNING: This function does not work in the same way as corresponding * functions in other glib-style libraries, such as gtk_init\(\). In @@ -402,7 +409,7 @@ gst_init (int *argc, char **argv[]) * Use this function to check if GStreamer has been initialized with gst_init() * or gst_init_check(). * - * Returns: TRUE if initialization has been done, FALSE otherwise. + * Returns: %TRUE if initialization has been done, %FALSE otherwise. */ gboolean gst_is_initialized (void) @@ -466,9 +473,8 @@ init_pre (GOptionContext * context, GOptionGroup * group, gpointer data, GST_DEBUG ("already initialized"); return TRUE; } -#if !GLIB_CHECK_VERSION(2, 35, 0) - g_type_init (); -#endif + + _priv_gst_start_time = gst_util_get_timestamp (); #ifndef GST_DISABLE_GST_DEBUG _priv_gst_debug_init (); @@ -502,6 +508,15 @@ init_pre (GOptionContext * context, GOptionGroup * group, gpointer data, GST_INFO ("Using library installed in %s", libdir); g_free (libdir); +#ifndef GST_DISABLE_REGISTRY + { + const gchar *disable_registry; + if ((disable_registry = g_getenv ("GST_REGISTRY_DISABLE"))) { + _priv_gst_disable_registry = (strcmp (disable_registry, "yes") == 0); + } + } +#endif + /* Print some basic system details if possible (OS/architecture) */ #ifdef HAVE_SYS_UTSNAME_H { @@ -562,12 +577,9 @@ init_post (GOptionContext * context, GOptionGroup * group, gpointer data, llf = G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_ERROR | G_LOG_FLAG_FATAL; g_log_set_handler (g_log_domain_gstreamer, llf, debug_log_handler, NULL); -#ifndef GST_DISABLE_TRACE - _priv_gst_alloc_trace_initialize (); -#endif - _priv_gst_mini_object_initialize (); _priv_gst_quarks_initialize (); + _priv_gst_allocator_initialize (); _priv_gst_memory_initialize (); _priv_gst_format_initialize (); _priv_gst_query_initialize (); @@ -575,11 +587,13 @@ init_post (GOptionContext * context, GOptionGroup * group, gpointer data, _priv_gst_caps_initialize (); _priv_gst_caps_features_initialize (); _priv_gst_meta_initialize (); + _priv_gst_message_initialize (); g_type_class_ref (gst_object_get_type ()); g_type_class_ref (gst_pad_get_type ()); g_type_class_ref (gst_element_factory_get_type ()); g_type_class_ref (gst_element_get_type ()); + g_type_class_ref (gst_tracer_factory_get_type ()); g_type_class_ref (gst_type_find_factory_get_type ()); g_type_class_ref (gst_bin_get_type ()); g_type_class_ref (gst_bus_get_type ()); @@ -605,6 +619,8 @@ init_post (GOptionContext * context, GOptionGroup * group, gpointer data, g_type_class_ref (gst_state_change_return_get_type ()); g_type_class_ref (gst_state_change_get_type ()); g_type_class_ref (gst_element_flags_get_type ()); + g_type_class_ref (gst_tracer_value_scope_get_type ()); + g_type_class_ref (gst_tracer_value_flags_get_type ()); g_type_class_ref (gst_core_error_get_type ()); g_type_class_ref (gst_library_error_get_type ()); g_type_class_ref (gst_resource_error_get_type ()); @@ -663,22 +679,26 @@ init_post (GOptionContext * context, GOptionGroup * group, gpointer data, g_type_class_ref (gst_meta_flags_get_type ()); g_type_class_ref (gst_toc_entry_type_get_type ()); g_type_class_ref (gst_toc_scope_get_type ()); + g_type_class_ref (gst_toc_loop_type_get_type ()); g_type_class_ref (gst_control_binding_get_type ()); g_type_class_ref (gst_control_source_get_type ()); g_type_class_ref (gst_lock_flags_get_type ()); g_type_class_ref (gst_allocator_flags_get_type ()); g_type_class_ref (gst_stream_flags_get_type ()); + g_type_class_ref (gst_stream_type_get_type ()); + g_type_class_ref (gst_stack_trace_flags_get_type ()); _priv_gst_event_initialize (); _priv_gst_buffer_initialize (); - _priv_gst_message_initialize (); _priv_gst_buffer_list_initialize (); _priv_gst_sample_initialize (); - _priv_gst_value_initialize (); _priv_gst_context_initialize (); + _priv_gst_date_time_initialize (); + _priv_gst_value_initialize (); + _priv_gst_tag_initialize (); + _priv_gst_toc_initialize (); g_type_class_ref (gst_param_spec_fraction_get_type ()); - _priv_gst_tag_initialize (); gst_parse_context_get_type (); _priv_gst_plugin_initialize (); @@ -694,7 +714,7 @@ init_post (GOptionContext * context, GOptionGroup * group, gpointer data, * gstreamer as being initialized, since it is the case from a plugin point of * view. * - * If anything fails, it will be put back to FALSE in gst_init_check(). + * If anything fails, it will be put back to %FALSE in gst_init_check(). * This allows some special plugins that would call gst_init() to not cause a * looping effect (i.e. initializing GStreamer twice). */ @@ -707,6 +727,11 @@ init_post (GOptionContext * context, GOptionGroup * group, gpointer data, glib_minor_version, glib_micro_version); GST_INFO ("GLib headers version: %d.%d.%d", GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION, GLIB_MICRO_VERSION); + GST_INFO ("initialized GStreamer successfully"); + +#ifndef GST_DISABLE_GST_DEBUG + _priv_gst_tracing_init (); +#endif return TRUE; } @@ -741,8 +766,41 @@ gst_debug_help (void) /* FIXME this is gross. why don't debug have categories PluginFeatures? */ for (g = list2; g; g = g_list_next (g)) { GstPlugin *plugin = GST_PLUGIN_CAST (g->data); + GList *features, *orig_features; + + if (GST_OBJECT_FLAG_IS_SET (plugin, GST_PLUGIN_FLAG_BLACKLISTED)) + continue; gst_plugin_load (plugin); + /* Now create one of each feature so the class_init functions + * are called, as that's where most debug categories are + * registered. FIXME: If debug categories were a plugin feature, + * this would be unneeded */ + orig_features = features = + gst_registry_get_feature_list_by_plugin (gst_registry_get (), + gst_plugin_get_name (plugin)); + while (features) { + GstPluginFeature *feature; + + if (G_UNLIKELY (features->data == NULL)) + goto next; + + feature = GST_PLUGIN_FEATURE (features->data); + if (GST_IS_ELEMENT_FACTORY (feature)) { + GstElementFactory *factory; + GstElement *e; + + factory = GST_ELEMENT_FACTORY (feature); + e = gst_element_factory_create (factory, NULL); + if (e) + gst_object_unref (e); + } + + next: + features = g_list_next (features); + } + + gst_plugin_feature_list_free (orig_features); } g_list_free (list2); @@ -848,7 +906,8 @@ parse_one_option (gint opt, const gchar * arg, GError ** err) break; case ARG_PLUGIN_PATH: #ifndef GST_DISABLE_REGISTRY - split_and_iterate (arg, G_SEARCHPATH_SEPARATOR_S, add_path_func, NULL); + if (!_priv_gst_disable_registry) + split_and_iterate (arg, G_SEARCHPATH_SEPARATOR_S, add_path_func, NULL); #endif /* GST_DISABLE_REGISTRY */ break; case ARG_PLUGIN_LOAD: @@ -859,7 +918,8 @@ parse_one_option (gint opt, const gchar * arg, GError ** err) break; case ARG_REGISTRY_UPDATE_DISABLE: #ifndef GST_DISABLE_REGISTRY - _priv_gst_disable_registry_update = TRUE; + if (!_priv_gst_disable_registry) + _priv_gst_disable_registry_update = TRUE; #endif break; case ARG_REGISTRY_FORK_DISABLE: @@ -927,7 +987,7 @@ parse_goption_arg (const gchar * opt, * This function is therefore mostly used by testsuites and other memory * profiling tools. * - * After this call GStreamer (including this method) should not be used anymore. + * After this call GStreamer (including this method) should not be used anymore. */ void gst_deinit (void) @@ -941,7 +1001,6 @@ gst_deinit (void) GST_DEBUG ("already deinitialized"); return; } - g_thread_pool_set_max_unused_threads (0); bin_class = GST_BIN_CLASS (g_type_class_peek (gst_bin_get_type ())); if (bin_class->pool != NULL) { @@ -965,15 +1024,23 @@ gst_deinit (void) gst_object_unref (clock); _priv_gst_registry_cleanup (); + _priv_gst_allocator_cleanup (); -#ifndef GST_DISABLE_TRACE - _priv_gst_alloc_trace_deinit (); + /* We want to destroy tracers as late as possible for the leaks tracer + * but still need to keep the caps system alive as it may have to use + * gst_caps_to_string() to display leaked caps. */ +#ifndef GST_DISABLE_GST_DEBUG + _priv_gst_tracing_deinit (); #endif + _priv_gst_caps_features_cleanup (); + _priv_gst_caps_cleanup (); + g_type_class_unref (g_type_class_peek (gst_object_get_type ())); g_type_class_unref (g_type_class_peek (gst_pad_get_type ())); g_type_class_unref (g_type_class_peek (gst_element_factory_get_type ())); g_type_class_unref (g_type_class_peek (gst_element_get_type ())); + g_type_class_unref (g_type_class_peek (gst_tracer_factory_get_type ())); g_type_class_unref (g_type_class_peek (gst_type_find_factory_get_type ())); g_type_class_unref (g_type_class_peek (gst_bin_get_type ())); g_type_class_unref (g_type_class_peek (gst_bus_get_type ())); @@ -994,6 +1061,8 @@ gst_deinit (void) g_type_class_unref (g_type_class_peek (gst_state_change_return_get_type ())); g_type_class_unref (g_type_class_peek (gst_state_change_get_type ())); g_type_class_unref (g_type_class_peek (gst_element_flags_get_type ())); + g_type_class_unref (g_type_class_peek (gst_tracer_value_scope_get_type ())); + g_type_class_unref (g_type_class_peek (gst_tracer_value_flags_get_type ())); g_type_class_unref (g_type_class_peek (gst_core_error_get_type ())); g_type_class_unref (g_type_class_peek (gst_library_error_get_type ())); g_type_class_unref (g_type_class_peek (gst_plugin_dependency_flags_get_type @@ -1055,14 +1124,17 @@ gst_deinit (void) g_type_class_unref (g_type_class_peek (gst_pad_probe_return_get_type ())); g_type_class_unref (g_type_class_peek (gst_segment_flags_get_type ())); g_type_class_unref (g_type_class_peek (gst_scheduling_flags_get_type ())); + g_type_class_unref (g_type_class_peek (gst_stream_type_get_type ())); g_type_class_unref (g_type_class_peek (gst_control_binding_get_type ())); g_type_class_unref (g_type_class_peek (gst_control_source_get_type ())); g_type_class_unref (g_type_class_peek (gst_toc_entry_type_get_type ())); + g_type_class_unref (g_type_class_peek (gst_toc_loop_type_get_type ())); g_type_class_unref (g_type_class_peek (gst_lock_flags_get_type ())); g_type_class_unref (g_type_class_peek (gst_allocator_flags_get_type ())); g_type_class_unref (g_type_class_peek (gst_stream_flags_get_type ())); g_type_class_unref (g_type_class_peek (gst_debug_color_mode_get_type ())); + g_type_class_unref (g_type_class_peek (gst_stack_trace_flags_get_type ())); gst_deinitialized = TRUE; GST_INFO ("deinitialized GStreamer");