[longomatch] Add GStreamer utils to check for installation errors



commit 904909fc073aae1a13004954e9c0bd21e63ecd07
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Mon Jul 25 18:45:02 2011 +0200

    Add GStreamer utils to check for installation errors

 LongoMatch/Common/GStreamer.cs |  117 ++++++++++++++++++++++++++++++++++++++++
 LongoMatch/LongoMatch.mdp      |    1 +
 LongoMatch/Main.cs             |    5 +-
 LongoMatch/Makefile.am         |    1 +
 4 files changed, 122 insertions(+), 2 deletions(-)
---
diff --git a/LongoMatch/Common/GStreamer.cs b/LongoMatch/Common/GStreamer.cs
new file mode 100644
index 0000000..43309e8
--- /dev/null
+++ b/LongoMatch/Common/GStreamer.cs
@@ -0,0 +1,117 @@
+// 
+//  Copyright (C) 2011 Andoni Morales Alastruey
+// 
+//  This program is free software; you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation; either version 2 of the License, or
+//  (at your option) any later version.
+// 
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+//  GNU General Public License for more details.
+//  
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+// 
+using System;
+using System.IO;
+using System.Runtime.InteropServices;
+using Gtk;
+using LongoMatch.Gui;
+
+namespace LongoMatch.Common
+{
+	public class GStreamer
+	{
+		
+		[DllImport("libgstreamer-0.10.dll") /* willfully unmapped */ ]
+		static extern void gst_init (string argv);
+		[DllImport("libgstreamer-0.10.dll") /* willfully unmapped */ ]
+		static extern IntPtr gst_registry_get_default ();
+		[DllImport("libgstreamer-0.10.dll") /* willfully unmapped */ ]
+		static extern IntPtr gst_registry_lookup_feature (IntPtr raw, string name);
+		[DllImport("libgstreamer-0.10.dll") /* willfully unmapped */ ]
+		static extern void gst_object_unref (IntPtr raw);
+		
+		private const string GST_DIRECTORY = ".gstreamer-0.10";
+		private const string REGISTRY_PATH = "registry.bin";
+		
+		public static void Init() {
+			SetUpEnvironment ();
+			gst_init ("");
+		}
+		
+		public static bool CheckInstallation () {
+			/* This check only makes sense on windows */
+			if (Environment.OSVersion.Platform != PlatformID.Win32NT)
+				return true;
+			
+			if (!CheckBasicPlugins()) {
+				HandleInstallationError();
+				return false;
+			}
+			return true;
+		}
+		
+		private static void SetUpEnvironment () {
+			string gstDirectory, registryPath;
+			
+			if (Environment.OSVersion.Platform != PlatformID.Win32NT)
+				return;
+			
+			gstDirectory = GetGstDirectory();
+			registryPath = GetRegistryPath();
+			
+			if (!Directory.Exists (gstDirectory))
+				Directory.CreateDirectory (gstDirectory);
+			
+			/* Use a custom path for the registry in Windows */
+			Environment.SetEnvironmentVariable("GST_REGISTRY", registryPath);
+			Environment.SetEnvironmentVariable("GST_PLUGIN_PATH",MainClass.RelativeToPrefix("lib\\gstreamer-0.10"));
+		}
+		
+		private static string GetGstDirectory () {
+			return Path.Combine (MainClass.HomeDir(), GST_DIRECTORY);
+		}
+		
+		private static string GetRegistryPath() {
+			return Path.Combine (GetGstDirectory(), REGISTRY_PATH);
+		}
+		
+		private static bool CheckBasicPlugins () {
+			IntPtr registry = gst_registry_get_default();
+			
+			/* After software updates, sometimes the registry is not regenerated properly
+			 * and plugins appears to be missing. We only check for a few plugins for now */
+			if (!ElementExists (registry, "ffdec_h264"))
+				return false;
+			if (!ElementExists (registry, "d3dvideosink"))
+				return false;
+			return true;
+		}
+		
+		private static bool ElementExists (IntPtr registry, string element_name) {
+			bool ret = false;
+			
+			Console.WriteLine ("Checking plugin: " + element_name);
+			var feature = gst_registry_lookup_feature (registry, element_name);
+			if (feature != IntPtr.Zero){
+				ret = true;
+				gst_object_unref (feature);
+			}
+			Console.WriteLine ("Checking plugin: " + ret);
+			return ret;
+		}
+		
+		private static void HandleInstallationError () {
+			File.Delete(GetRegistryPath());
+			
+			MessagePopup.PopupMessage(null, MessageType.Error, "An error has been detected in the current " +
+				"installation.\n Try restarting " + Constants.SOFTWARE_NAME + " and contact with the " +
+			    "development team if the problem persists.");
+		}
+	}
+}
+
diff --git a/LongoMatch/LongoMatch.mdp b/LongoMatch/LongoMatch.mdp
index 9105d45..1ea4f3a 100644
--- a/LongoMatch/LongoMatch.mdp
+++ b/LongoMatch/LongoMatch.mdp
@@ -197,6 +197,7 @@
     <File subtype="Code" buildaction="Compile" name="Gui/TreeView/ListTreeViewBase.cs" />
     <File subtype="Code" buildaction="Compile" name="Gui/Component/CategoriesScale.cs" />
     <File subtype="Code" buildaction="Compile" name="Common/Cairo.cs" />
+    <File subtype="Code" buildaction="Compile" name="Common/GStreamer.cs" />
   </Contents>
   <References>
     <ProjectReference type="Gac" localcopy="True" refto="Mono.Posix, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" />
diff --git a/LongoMatch/Main.cs b/LongoMatch/Main.cs
index 31d05fd..4ef25d2 100644
--- a/LongoMatch/Main.cs
+++ b/LongoMatch/Main.cs
@@ -55,7 +55,9 @@ namespace LongoMatch
 
 			GLib.ExceptionManager.UnhandledException += new GLib.UnhandledExceptionHandler(OnException);
 
-			LongoMatch.Video.Player.GstPlayer.InitBackend("");
+			GStreamer.Init();
+			if (! GStreamer.CheckInstallation())
+				return;
 
 			//Comprobamos los archivos de inicio
 			CheckDirs();
@@ -178,7 +180,6 @@ namespace LongoMatch
 			
 			if (Environment.OSVersion.Platform == PlatformID.Win32NT) {
 				baseDirectory = System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory,"../");
-				Environment.SetEnvironmentVariable("GST_PLUGIN_PATH",RelativeToPrefix("lib\\gstreamer-0.10"));
 			}
 			else
 				baseDirectory = System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory,"../../");
diff --git a/LongoMatch/Makefile.am b/LongoMatch/Makefile.am
index 1e897fc..116c1a3 100644
--- a/LongoMatch/Makefile.am
+++ b/LongoMatch/Makefile.am
@@ -7,6 +7,7 @@ SOURCES = \
 	Common/Enums.cs \
 	Common/Cairo.cs \
 	Common/Constants.cs \
+	Common/GStreamer.cs \
 	Compat/0.0/DatabaseMigrator.cs \
 	Compat/0.0/DB/DataBase.cs \
 	Compat/0.0/DB/MediaFile.cs \



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]