element: Enforce that elements created by gst_element_factory_create/make() are floating
[platform/upstream/gstreamer.git] / gst / gst.c
index c674708..2f4c789 100644 (file)
--- a/gst/gst.c
+++ b/gst/gst.c
 #include <windows.h>            /* GetStdHandle, windows console */
 #endif
 #if defined (__APPLE__)
-#include <errno.h>
+#include "TargetConditionals.h"
+#if !TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR && !TARGET_OS_EMBEDDED
 #include <libproc.h>            /* proc_pidpath, PROC_PIDPATHINFO_MAXSIZE */
 #endif
+#endif
 
 #include "gst-i18n-lib.h"
 #include <locale.h>             /* for LC_ALL */
@@ -235,7 +237,7 @@ DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
  * threading system as one of the very first things in your program
  * (see the example at the beginning of this section).
  *
- * Returns: (transfer full): a pointer to GStreamer's option group.
+ * Returns: (transfer full) (nullable): a pointer to GStreamer's option group.
  */
 
 GOptionGroup *
@@ -322,17 +324,13 @@ static void
 find_executable_path (void)
 {
   GError *error = NULL;
-  gchar *path;
 
   if (_gst_executable_path)
     return;
 
-  path = g_file_read_link ("/proc/self/exe", &error);
-
-  if (path) {
-    _gst_executable_path = g_path_get_dirname (path);
-    g_free (path);
-  }
+  _gst_executable_path = g_file_read_link ("/proc/self/exe", &error);
+  if (error)
+    g_error_free (error);
 }
 #elif defined(G_OS_WIN32)
 static void
@@ -345,7 +343,7 @@ find_executable_path (void)
 
   _gst_executable_path = g_strdup (buffer);
 }
-#elif defined(__APPLE__)
+#elif defined(__APPLE__) && !TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR && !TARGET_OS_EMBEDDED
 static void
 find_executable_path (void)
 {
@@ -366,6 +364,27 @@ find_executable_path (void)
 }
 #endif
 
+/**
+ * gst_get_main_executable_path:
+ *
+ * This helper is mostly helpful for plugins that need to
+ * inspect the folder of the main executable to determine
+ * their set of features.
+ *
+ * When a plugin is initialized from the gst-plugin-scanner
+ * external process, the returned path will be the same as from the
+ * parent process.
+ *
+ * Returns: (transfer none) (nullable): The path of the executable that
+ *   initialized GStreamer, or %NULL if it could not be determined.
+ *
+ * Since: 1.14
+ */
+const gchar *
+gst_get_main_executable_path (void)
+{
+  return _gst_executable_path;
+}
 
 /**
  * gst_init_check:
@@ -473,7 +492,8 @@ gst_is_initialized (void)
   return gst_initialized;
 }
 
-#ifndef GST_DISABLE_REGISTRY
+#ifndef GST_DISABLE_OPTION_PARSING
+#  ifndef GST_DISABLE_REGISTRY
 static void
 add_path_func (gpointer data, gpointer user_data)
 {
@@ -481,6 +501,7 @@ add_path_func (gpointer data, gpointer user_data)
   _priv_gst_plugin_paths =
       g_list_append (_priv_gst_plugin_paths, g_strdup (data));
 }
+#  endif
 #endif
 
 #ifndef GST_DISABLE_OPTION_PARSING
@@ -612,7 +633,7 @@ gst_register_core_elements (GstPlugin * plugin)
 
 /*
  * this bit handles:
- * - initalization of threads if we use them
+ * - initialization of threads if we use them
  * - log handler
  * - initial output
  * - initializes gst_format
@@ -745,6 +766,7 @@ init_post (GOptionContext * context, GOptionGroup * group, gpointer data,
   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 ());
+  g_type_class_ref (gst_promise_result_get_type ());
 
   _priv_gst_event_initialize ();
   _priv_gst_buffer_initialize ();
@@ -794,7 +816,8 @@ init_post (GOptionContext * context, GOptionGroup * group, gpointer data,
   return TRUE;
 }
 
-#ifndef GST_DISABLE_GST_DEBUG
+#ifndef GST_DISABLE_OPTION_PARSING
+#  ifndef GST_DISABLE_GST_DEBUG
 static gboolean
 select_all (GstPlugin * plugin, gpointer user_data)
 {
@@ -916,7 +939,8 @@ gst_debug_help (void)
   g_slist_free (list);
   g_print ("\n");
 }
-#endif
+#  endif /* GST_DISABLE_OPTION_PARSING */
+#endif /* GST_DISABLE_GST_DEBUG */
 
 #ifndef GST_DISABLE_OPTION_PARSING
 static gboolean
@@ -1053,6 +1077,9 @@ gst_deinit (void)
   GstBinClass *bin_class;
   GstClock *clock;
 
+  if (!gst_initialized)
+    return;
+
   GST_INFO ("deinitializing GStreamer");
 
   if (gst_deinitialized) {
@@ -1060,7 +1087,7 @@ gst_deinit (void)
     return;
   }
   g_thread_pool_set_max_unused_threads (0);
-  bin_class = GST_BIN_CLASS (g_type_class_peek (gst_bin_get_type ()));
+  bin_class = (GstBinClass *) g_type_class_peek (gst_bin_get_type ());
   if (bin_class && bin_class->pool != NULL) {
     g_thread_pool_free (bin_class->pool, FALSE, TRUE);
     bin_class->pool = NULL;
@@ -1098,6 +1125,7 @@ gst_deinit (void)
 
   _priv_gst_caps_features_cleanup ();
   _priv_gst_caps_cleanup ();
+  _priv_gst_debug_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 ()));
@@ -1198,6 +1226,7 @@ gst_deinit (void)
   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 ()));
+  g_type_class_unref (g_type_class_peek (gst_promise_result_get_type ()));
 
   gst_deinitialized = TRUE;
   GST_INFO ("deinitialized GStreamer");