windows: Make GStreamer installation relocatable
authorChun-wei Fan <fanchunwei@src.gnome.org>
Thu, 6 Feb 2014 06:18:31 +0000 (14:18 +0800)
committerSebastian Dröge <sebastian@centricular.com>
Thu, 6 Feb 2014 22:31:23 +0000 (23:31 +0100)
Use the technique that is now done in GTK+ so that the plugins do not have
to be installed in c:\gstreamer\lib\<debug>\gstreamer-$(GSTApiVersion),
but can be installed in
<parent_folder_of_gstreamer_main_dll>\lib\<debug>\gstreamer-$(GSTApiVersion),
or as per g_win32_get_package_installation_directory_of_module() allows.

https://bugzilla.gnome.org/show_bug.cgi?id=679115

gst/gst.c
gst/gstpluginloader.c
gst/gstpreset.c
gst/gstregistry.c

index 17cbcca..f734dc9 100644 (file)
--- a/gst/gst.c
+++ b/gst/gst.c
@@ -461,6 +461,7 @@ static gboolean
 init_pre (GOptionContext * context, GOptionGroup * group, gpointer data,
     GError ** error)
 {
+  gchar *libdir;
   if (gst_initialized) {
     GST_DEBUG ("already initialized");
     return TRUE;
@@ -481,8 +482,24 @@ init_pre (GOptionContext * context, GOptionGroup * group, gpointer data,
 
   /* This is the earliest we can make stuff show up in the logs.
    * So give some useful info about GStreamer here */
+#ifdef G_OS_WIN32
+  {
+    gchar *basedir = g_win32_get_package_installation_directory_of_module (_priv_gst_dll_handle);
+
+    libdir = g_build_filename (basedir,
+#ifdef _DEBUG
+                               "debug"
+#endif
+                               "lib",
+                               NULL);
+    g_free (basedir);
+  }
+#else
+  libdir = g_strdup (LIBDIR);
+#endif
   GST_INFO ("Initializing GStreamer Core Library version %s", VERSION);
-  GST_INFO ("Using library installed in %s", LIBDIR);
+  GST_INFO ("Using library installed in %s", libdir);
+  g_free (libdir);
 
   /* Print some basic system details if possible (OS/architecture) */
 #ifdef HAVE_SYS_UTSNAME_H
index 13a8fd5..9235136 100644 (file)
 #include <fcntl.h>
 #include <unistd.h>
 #else
+#define WIN32_LEAN_AND_MEAN
+
 #define fsync(fd) _commit(fd)
 #include <io.h>
+
+#include <windows.h>
+extern HMODULE _priv_gst_dll_handle;
 #endif
 
 #ifdef HAVE_SYS_UTSNAME_H
@@ -470,7 +475,22 @@ gst_plugin_loader_spawn (GstPluginLoader * loader)
 
   if (!res) {
     GST_LOG ("Trying installed plugin scanner");
+
+#ifdef G_OS_WIN32
+    {
+      gchar *basedir;
+
+      basedir = g_win32_get_package_installation_directory_of_module (_priv_gst_dll_handle);
+      helper_bin = g_build_filename (basedir,
+                                     "lib",
+                                     "gstreamer-" GST_API_VERSION,
+                                     "gst-plugin-scanner.exe",
+                                     NULL);
+      g_free (basedir);
+    }
+#else
     helper_bin = g_strdup (GST_PLUGIN_SCANNER_INSTALLED);
+#endif
     res = gst_plugin_loader_try_helper (loader, helper_bin);
     g_free (helper_bin);
 
index 2db8439..6f51447 100644 (file)
 #endif
 #include <glib/gstdio.h>
 
+#ifdef G_OS_WIN32
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+extern HMODULE _priv_gst_dll_handle;
+#endif
+
 #define GST_CAT_DEFAULT preset_debug
 GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
 
@@ -175,8 +182,18 @@ preset_get_paths (GstPreset * preset, const gchar ** preset_user_path,
       gchar *preset_dir;
 
       /* system presets in '$GST_DATADIR/gstreamer-1.0/presets/GstAudioPanorama.prs' */
+#ifdef G_OS_WIN32
+      gchar *basedir = g_win32_get_package_installation_directory_of_module (_priv_gst_dll_handle);
+      preset_dir = g_build_filename (basedir,
+                                     "share",
+                                     "gstreamer-" GST_API_VERSION,
+                                     "presets",
+                                     NULL);
+      g_free (basedir);
+#else
       preset_dir = g_build_filename (GST_DATADIR, "gstreamer-" GST_API_VERSION,
           "presets", NULL);
+#endif
       GST_INFO_OBJECT (preset, "system_preset_dir: '%s'", preset_dir);
       preset_path = g_strdup_printf ("%s" G_DIR_SEPARATOR_S "%s.prs",
           preset_dir, element_name);
index 79014c8..0830395 100644 (file)
@@ -1593,8 +1593,6 @@ scan_and_update_registry (GstRegistry * default_registry,
     g_free (home_plugins);
 
     /* add the main (installed) library path */
-    GST_DEBUG ("scanning main plugins %s", PLUGINDIR);
-    changed |= gst_registry_scan_path_internal (&context, PLUGINDIR);
 
 #ifdef G_OS_WIN32
     {
@@ -1606,8 +1604,13 @@ scan_and_update_registry (GstRegistry * default_registry,
           (_priv_gst_dll_handle);
 
       dir =
-          g_build_filename (base_dir, "lib", "gstreamer-" GST_API_VERSION,
-          NULL);
+          g_build_filename (base_dir,
+#ifdef _DEBUG
+                            "debug"
+#endif
+                            "lib",
+                            "gstreamer-" GST_API_VERSION,
+                            NULL);
       GST_DEBUG ("scanning DLL dir %s", dir);
 
       changed |= gst_registry_scan_path_internal (&context, dir);
@@ -1615,6 +1618,9 @@ scan_and_update_registry (GstRegistry * default_registry,
       g_free (dir);
       g_free (base_dir);
     }
+#else
+    GST_DEBUG ("scanning main plugins %s", PLUGINDIR);
+    changed |= gst_registry_scan_path_internal (&context, PLUGINDIR);
 #endif
   } else {
     gchar **list;