plugin dependencies: fix 6cddce7663cb4b6ee061950d20365f42cb755851
[platform/upstream/gstreamer.git] / gst / gst.c
index 8087aa4..c542766 100644 (file)
--- a/gst/gst.c
+++ b/gst/gst.c
 #define WIN32_LEAN_AND_MEAN     /* prevents from including too many things */
 #include <windows.h>            /* GetStdHandle, windows console */
 #endif
+#if defined (__APPLE__)
+#include <errno.h>
+#include <libproc.h>            /* proc_pidpath, PROC_PIDPATHINFO_MAXSIZE */
+#endif
 
 #include "gst-i18n-lib.h"
 #include <locale.h>             /* for LC_ALL */
@@ -133,6 +137,8 @@ extern gboolean _priv_gst_disable_registry;
 extern gboolean _priv_gst_disable_registry_update;
 #endif
 
+gchar *_gst_executable_path = NULL;
+
 #ifndef GST_DISABLE_GST_DEBUG
 const gchar *priv_gst_dump_dot_dir;
 #endif
@@ -311,6 +317,56 @@ gst_init_get_option_group (void)
 #endif
 }
 
+#if defined(__linux__)
+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);
+  }
+}
+#elif defined(G_OS_WIN32)
+static void
+find_executable_path (void)
+{
+  char buffer[MAX_PATH];
+
+  if (!GetModuleFilename (NULL, buffer, MAX_PATH))
+    return;
+
+  _gst_executable_path = g_strdup (buffer);
+}
+#elif defined(__APPLE__)
+static void
+find_executable_path (void)
+{
+  int ret;
+  pid_t pid;
+  char pathbuf[PROC_PIDPATHINFO_MAXSIZE];
+
+  pid = getpid ();
+  ret = proc_pidpath (pid, pathbuf, sizeof (pathbuf));
+  if (ret > 0)
+    _gst_executable_path = g_strdup (pathbuf);
+}
+#else
+static void
+find_executable_path (void)
+{
+  GST_FIXME ("Couldn't look up executable path, add support for this platform");
+}
+#endif
+
+
 /**
  * gst_init_check:
  * @argc: (inout) (allow-none): pointer to application's argc
@@ -474,6 +530,8 @@ init_pre (GOptionContext * context, GOptionGroup * group, gpointer data,
     return TRUE;
   }
 
+  find_executable_path ();
+
   _priv_gst_start_time = gst_util_get_timestamp ();
 
 #ifndef GST_DISABLE_GST_DEBUG
@@ -1003,7 +1061,7 @@ gst_deinit (void)
   }
   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) {
+  if (bin_class && bin_class->pool != NULL) {
     g_thread_pool_free (bin_class->pool, FALSE, TRUE);
     bin_class->pool = NULL;
   }
@@ -1019,6 +1077,11 @@ gst_deinit (void)
   _priv_gst_plugin_paths = NULL;
 #endif
 
+  if (_gst_executable_path) {
+    g_free (_gst_executable_path);
+    _gst_executable_path = NULL;
+  }
+
   clock = gst_system_clock_obtain ();
   gst_object_unref (clock);
   gst_object_unref (clock);