From 8dc1d0c32d4ef674a1ae7b57476fbd15c7f9d0af Mon Sep 17 00:00:00 2001
From: Michael Graf <mgraf@igros.de>
Date: Sat, 26 Nov 2011 23:11:57 +0100
Subject: [PATCH] BDHandler: Make Bluray Source Filter a configurable setting.
 Added support for LAV Filter

---
 MediaPortal/Incubator/BDHandler/BDHandler.csproj   |    3 +-
 MediaPortal/Incubator/BDHandler/BDPlayer.cs        |   17 +++++----------
 MediaPortal/Incubator/BDHandler/BDPlayerBuilder.cs |   17 +++++++++++++--
 .../Incubator/BDHandler/Language/strings_en.xml    |    2 +
 .../BDHandler/Settings/BDPlayerSettings.cs         |   21 ++++++++++++++++++++
 MediaPortal/Incubator/BDHandler/plugin.xml         |   15 ++++++++++++++
 MediaPortal/Source/MP2-Client.sln                  |    8 ++++--
 7 files changed, 65 insertions(+), 18 deletions(-)

diff --git a/MediaPortal/Incubator/BDHandler/BDHandler.csproj b/MediaPortal/Incubator/BDHandler/BDHandler.csproj
index 05d472f..bbac6db 100644
--- a/MediaPortal/Incubator/BDHandler/BDHandler.csproj
+++ b/MediaPortal/Incubator/BDHandler/BDHandler.csproj
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+﻿<?xml version="1.0" encoding="utf-8"?>
 <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <PropertyGroup>
     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -99,6 +99,7 @@
       <DependentUpon>Resources.resx</DependentUpon>
     </Compile>
     <Compile Include="Settings\BDPlayerSettings.cs" />
+    <Compile Include="Settings\Configuration\BDSourceFilterConfig.cs" />
     <Compile Include="Settings\Configuration\VideoAVCCodec.cs" />
     <Content Include="Language\strings_en.xml" />
     <Content Include="plugin.xml">
diff --git a/MediaPortal/Incubator/BDHandler/BDPlayer.cs b/MediaPortal/Incubator/BDHandler/BDPlayer.cs
index af4b5d7..8e8c9d1 100644
--- a/MediaPortal/Incubator/BDHandler/BDPlayer.cs
+++ b/MediaPortal/Incubator/BDHandler/BDPlayer.cs
@@ -46,13 +46,6 @@ namespace MediaPortal.UI.Players.Video
   {
     #region Consts and delegates
        
-    // "MPC - Mpeg Source (Gabest)
-    public static CodecInfo MpcMpegSourceFilterInfo = new CodecInfo()
-                                                        {
-                                                          CLSID = "{1365BE7A-C86A-473C-9A41-C0A6E82C9FA3}",
-                                                          Name = "MPC - Mpeg Source (Gabest)"
-                                                        };
-
     public const double MINIMAL_FULL_FEATURE_LENGTH = 3000;
     public const string RES_PLAYBACK_CHAPTER = "[Playback.Chapter]";
 
@@ -131,8 +124,11 @@ namespace MediaPortal.UI.Players.Video
       // only continue with playback if a feature was selected or the extension was m2ts.
       if (DoFeatureSelection(ref strFile))
       {
-        // load the source filter         
-        if (TryAdd(MpcMpegSourceFilterInfo))
+        // find the SourceFilter
+        CodecInfo sourceFilter = ServiceRegistration.Get<ISettingsManager>().Load<BDPlayerSettings>().BDSourceFilter;
+
+        // load the SourceFilter         
+        if (TryAdd(sourceFilter))
         {
           IFileSourceFilter fileSourceFilter = FilterGraphTools.FindFilterByInterface<IFileSourceFilter>(_graphBuilder);
           // load the file
@@ -141,13 +137,12 @@ namespace MediaPortal.UI.Players.Video
         }
         else
         {
-          BDPlayerBuilder.LogError("Unable to load DirectShowFilter: {0}", MpcMpegSourceFilterInfo.Name);
+          BDPlayerBuilder.LogError("Unable to load DirectShowFilter: {0}", sourceFilter.Name);
           throw new Exception("Unable to load DirectShowFilter");
         }
       }
     }
 
-
     protected override void OnBeforeGraphRunning()
     {
       base.OnBeforeGraphRunning();
diff --git a/MediaPortal/Incubator/BDHandler/BDPlayerBuilder.cs b/MediaPortal/Incubator/BDHandler/BDPlayerBuilder.cs
index a9ed72f..7676a4c 100644
--- a/MediaPortal/Incubator/BDHandler/BDPlayerBuilder.cs
+++ b/MediaPortal/Incubator/BDHandler/BDPlayerBuilder.cs
@@ -26,8 +26,10 @@ using System;
 using MediaPortal.Common;
 using MediaPortal.Common.Logging;
 using MediaPortal.Common.ResourceAccess;
+using MediaPortal.Common.Settings;
 using MediaPortal.UI.Players.Video.Tools;
 using MediaPortal.UI.Presentation.Players;
+using MediaPortal.Plugins.BDHandler.Settings;
 
 namespace MediaPortal.UI.Players.Video
 {
@@ -37,11 +39,20 @@ namespace MediaPortal.UI.Players.Video
 
     public BDPlayerBuilder()
     {
-      Enabled = FilterGraphTools.IsThisComObjectInstalled(new Guid(BDPlayer.MpcMpegSourceFilterInfo.CLSID));
+      BDPlayerSettings settings = ServiceRegistration.Get<ISettingsManager>().Load<BDPlayerSettings>();
+      if (settings != null && settings.BDSourceFilter == null)
+      {
+        settings.BDSourceFilter = BDPlayerSettings.StandardBluraySourceFilter();
+        if (settings.BDSourceFilter != null)
+          ServiceRegistration.Get<ISettingsManager>().Save(settings);
+      }
+
+      Enabled = (settings != null && settings.BDSourceFilter != null);
+        
       if (Enabled)
-        LogInfo("Detected source filer '{0}' on the system.", BDPlayer.MpcMpegSourceFilterInfo.Name);
+        LogInfo("Detected BluRay Source Filter '{0}' on the system.", settings.BDSourceFilter.Name);
       else
-        LogWarn("'{0}' was not detected on the system.", BDPlayer.MpcMpegSourceFilterInfo.Name);
+        LogWarn("No BluRay Source Filter was detected on the system.");
     }
 
     #endregion
diff --git a/MediaPortal/Incubator/BDHandler/Language/strings_en.xml b/MediaPortal/Incubator/BDHandler/Language/strings_en.xml
index 6a7cf4e..5d52e70 100644
--- a/MediaPortal/Incubator/BDHandler/Language/strings_en.xml
+++ b/MediaPortal/Incubator/BDHandler/Language/strings_en.xml
@@ -3,5 +3,7 @@
   <Section Name="Settings">
     <String Name="Players.Codecs.VideoCodecs.AVC" Text="AVC Video Codec"/>
     <String Name="Players.Codecs.VideoCodecs.AVC.Help" Text="Set the codec used for AVC video (BluRay)"/>
+    <String Name="Players.Codecs.VideoCodecs.BDSourceFilter" Text="Bluray Source Filter"/>
+    <String Name="Players.Codecs.VideoCodecs.BDSourceFilter.Help" Text="Set the Source Filter used for BluRay playback. Currently only Gabest and LAV Splitter Source are supported."/>
   </Section>
 </Language>
\ No newline at end of file
diff --git a/MediaPortal/Incubator/BDHandler/Settings/BDPlayerSettings.cs b/MediaPortal/Incubator/BDHandler/Settings/BDPlayerSettings.cs
index b1cfd28..d8635b3 100644
--- a/MediaPortal/Incubator/BDHandler/Settings/BDPlayerSettings.cs
+++ b/MediaPortal/Incubator/BDHandler/Settings/BDPlayerSettings.cs
@@ -22,6 +22,7 @@
 
 #endregion
 
+using System;
 using MediaPortal.Common.Settings;
 using MediaPortal.UI.Players.Video.Tools;
 
@@ -33,9 +34,29 @@ namespace MediaPortal.Plugins.BDHandler.Settings
   public class BDPlayerSettings
   {
     /// <summary>
+    /// Returns the first supported Bluray Source Filter, which is installed on the system or
+    /// null, if none of the supported Bluray Source Filters is installed.
+    /// </summary>
+    public static CodecInfo StandardBluraySourceFilter()
+    {
+      foreach (CodecInfo codecInfo in Configuration.BDSourceFilterConfig.SupportedSourceFilters)
+        if (FilterGraphTools.IsThisComObjectInstalled(new Guid(codecInfo.CLSID)))
+          return codecInfo;
+
+      return null;
+    }
+    
+    /// <summary>
     /// Gets or Sets the preferred AVC codec.
     /// </summary>
     [Setting(SettingScope.User)]
     public CodecInfo AVCCodec { get; set; }
+
+    /// <summary>
+    /// Gets or Sets the Source Filter used for Blurays (currently only Gabest or LAV Splitter Source are supported).
+    /// </summary>
+    [Setting(SettingScope.User)]
+    public CodecInfo BDSourceFilter { get; set; }
+
   }
 }
\ No newline at end of file
diff --git a/MediaPortal/Incubator/BDHandler/plugin.xml b/MediaPortal/Incubator/BDHandler/plugin.xml
index 9bb0f74..c63ef32 100644
--- a/MediaPortal/Incubator/BDHandler/plugin.xml
+++ b/MediaPortal/Incubator/BDHandler/plugin.xml
@@ -59,4 +59,19 @@
         ClassName="MediaPortal.Plugins.BDHandler.Settings.Configuration.VideoAVCCodec"/>
   </Register>
 
+  <Register Location="/Configuration/Settings/Players/Codecs">
+    <ConfigGroup
+        Id="SourceFilters"
+        Redundant="true"
+        Text="[Settings.Players.Codecs.SourceFilters]"/>
+  </Register>
+
+  <Register Location="/Configuration/Settings/Players/Codecs/SourceFilters">
+    <ConfigSetting
+        Id="BluRaySourceFilter"
+        Text="[Settings.Players.Codecs.VideoCodecs.BDSourceFilter]"
+        HelpText="[Settings.Players.Codecs.VideoCodecs.BDSourceFilter.Help]"
+        ClassName="MediaPortal.Plugins.BDHandler.Settings.Configuration.BDSourceFilterConfig"/>
+  </Register>
+
 </Plugin>
diff --git a/MediaPortal/Source/MP2-Client.sln b/MediaPortal/Source/MP2-Client.sln
index 91dce3f..861fccb 100644
--- a/MediaPortal/Source/MP2-Client.sln
+++ b/MediaPortal/Source/MP2-Client.sln
@@ -1,5 +1,5 @@
 Microsoft Visual Studio Solution File, Format Version 11.00
-# Visual Studio 2010
+# Visual C# Express 2010
 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Extensions", "Extensions", "{26B21F24-5C09-4F49-ABE3-C1B3F9059D2B}"
 EndProject
 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{843A0AD1-33FC-4952-9465-B5E79C2C67D1}"
@@ -82,7 +82,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BDHandler", "..\Incubator\B
 EndProject
 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Incubator", "Incubator", "{D7E79601-A62E-4193-892F-033F8E7C90BD}"
 EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Players", "Players", "{55699D26-D191-495A-B73F-271D33D7FE44}"
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Players (2)", "Players (2)", "{55699D26-D191-495A-B73F-271D33D7FE44}"
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZipResourceProvider", "Extensions\ResourceProviders\ZipResourceProvider\ZipResourceProvider.csproj", "{33721BC7-193A-4B80-9CFF-DC8A50700443}"
 EndProject
@@ -173,6 +173,7 @@ Global
 		{9665887D-BEBF-4051-9151-7F189356682C}.Release|x86.ActiveCfg = Release|x86
 		{9665887D-BEBF-4051-9151-7F189356682C}.Release|x86.Build.0 = Release|x86
 		{EE24ACB8-4306-41BB-B59A-F134FBC7A9A1}.Debug|x86.ActiveCfg = Debug|x86
+		{EE24ACB8-4306-41BB-B59A-F134FBC7A9A1}.Debug|x86.Build.0 = Debug|x86
 		{EE24ACB8-4306-41BB-B59A-F134FBC7A9A1}.Release|x86.ActiveCfg = Release|x86
 		{EE24ACB8-4306-41BB-B59A-F134FBC7A9A1}.Release|x86.Build.0 = Release|x86
 		{B186C33C-7DC6-4F6B-911D-B8D3C6482C39}.Debug|x86.ActiveCfg = Debug|x86
@@ -245,7 +246,8 @@ Global
 		{ABB50339-0CA4-4CB4-8788-EA66C960ABCE}.Release|x86.Build.0 = Release|x86
 		{B368925B-5794-4931-9F3F-E143F6BB7BE5}.Debug|x86.ActiveCfg = Debug|x86
 		{B368925B-5794-4931-9F3F-E143F6BB7BE5}.Debug|x86.Build.0 = Debug|x86
-		{B368925B-5794-4931-9F3F-E143F6BB7BE5}.Release|x86.ActiveCfg = Release|Any CPU
+		{B368925B-5794-4931-9F3F-E143F6BB7BE5}.Release|x86.ActiveCfg = Release|x86
+		{B368925B-5794-4931-9F3F-E143F6BB7BE5}.Release|x86.Build.0 = Release|x86
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
-- 
1.7.6.msysgit.0

