diff options
Diffstat (limited to 'win')
16 files changed, 149 insertions, 76 deletions
diff --git a/win/CS/HandBrake.Interop/Interop/HandBrakeEncoderHelpers.cs b/win/CS/HandBrake.Interop/Interop/HandBrakeEncoderHelpers.cs index 7e6586bda..4d1dcea2e 100644 --- a/win/CS/HandBrake.Interop/Interop/HandBrakeEncoderHelpers.cs +++ b/win/CS/HandBrake.Interop/Interop/HandBrakeEncoderHelpers.cs @@ -36,7 +36,10 @@ namespace HandBrake.Interop.Interop /// </summary> static HandBrakeEncoderHelpers() { - HandBrakeUtils.EnsureGlobalInit(); + if (!HandBrakeUtils.IsInitialised()) + { + throw new Exception("Please Initialise with HandBrakeUtils.EnsureGlobalInit before using!"); + } } /// <summary> diff --git a/win/CS/HandBrake.Interop/Interop/HandBrakeInstance.cs b/win/CS/HandBrake.Interop/Interop/HandBrakeInstance.cs index 6e7103bd6..bf7e3ce30 100644 --- a/win/CS/HandBrake.Interop/Interop/HandBrakeInstance.cs +++ b/win/CS/HandBrake.Interop/Interop/HandBrakeInstance.cs @@ -110,9 +110,12 @@ namespace HandBrake.Interop.Interop /// <param name="verbosity"> /// The code for the logging verbosity to use. /// </param> - public void Initialize(int verbosity) + /// <param name="noHardware"> + /// True disables hardware init. + /// </param> + public void Initialize(int verbosity, bool noHardware) { - HandBrakeUtils.EnsureGlobalInit(); + HandBrakeUtils.EnsureGlobalInit(noHardware); HandBrakeUtils.RegisterLogger(); this.Handle = HBFunctions.hb_init(verbosity, update_check: 0); diff --git a/win/CS/HandBrake.Interop/Interop/HandBrakeUnitConversionHelpers.cs b/win/CS/HandBrake.Interop/Interop/HandBrakeUnitConversionHelpers.cs index 93cc0fc0c..fd9da07a0 100644 --- a/win/CS/HandBrake.Interop/Interop/HandBrakeUnitConversionHelpers.cs +++ b/win/CS/HandBrake.Interop/Interop/HandBrakeUnitConversionHelpers.cs @@ -33,7 +33,10 @@ namespace HandBrake.Interop.Interop /// </summary> static HandBrakeUnitConversionHelpers() { - HandBrakeUtils.EnsureGlobalInit(); + if (!HandBrakeUtils.IsInitialised()) + { + throw new Exception("Please Initialise with HandBrakeUtils.EnsureGlobalInit before using!"); + } VideoRates = new Dictionary<double, int>(); foreach (var framerate in HandBrakeEncoderHelpers.VideoFramerates) diff --git a/win/CS/HandBrake.Interop/Interop/HandBrakeUtils.cs b/win/CS/HandBrake.Interop/Interop/HandBrakeUtils.cs index 642e7d069..6752cdb7a 100644 --- a/win/CS/HandBrake.Interop/Interop/HandBrakeUtils.cs +++ b/win/CS/HandBrake.Interop/Interop/HandBrakeUtils.cs @@ -43,7 +43,8 @@ namespace HandBrake.Interop.Interop /// </summary> private static bool globalInitialized; - private static bool failedWithHardware = false; + private static bool initSuccess = false; + private static bool initNoHardware = false; /// <summary> /// Fires when HandBrake has logged a message. @@ -55,29 +56,37 @@ namespace HandBrake.Interop.Interop /// </summary> public static event EventHandler<MessageLoggedEventArgs> ErrorLogged; - /// <summary> - /// Initializes static members of the HandBrakeUtils class. + /// Ensures the HB global initialize method has been called. /// </summary> - static HandBrakeUtils() + public static void EnsureGlobalInit(bool initNoHardwareMode) { if (!globalInitialized) { try { - bool passed = TryInit(); - if (!passed) + if (initNoHardwareMode) + { + initNoHardware = true; + if (HBFunctions.hb_global_init_no_hardware() == -1) + { + throw new InvalidOperationException("HB global init failed."); + } + + initSuccess = true; + } + else { - failedWithHardware = true; + initSuccess = TryInit(); } } catch (Exception e) { - failedWithHardware = true; + initSuccess = false; } // Try without Hardware support. Bad drivers can sometimes cause issues. - if (failedWithHardware) + if (!initSuccess) { if (HBFunctions.hb_global_init_no_hardware() == -1) { @@ -89,36 +98,6 @@ namespace HandBrake.Interop.Interop } } - //[HandleProcessCorruptedStateExceptions] - static bool TryInit() - { - try - { - if (HBFunctions.hb_global_init() == -1) - { - throw new InvalidOperationException("HB global init failed."); - } - } - //catch (AccessViolationException e) - //{ - // return false; - //} - catch (Exception e) - { - return false; - } - - return true; - } - - /// <summary> - /// Ensures the HB global initialize method has been called. - /// </summary> - public static void EnsureGlobalInit() - { - // Does nothing, but invokes static ctor. - } - /// <summary> /// Enables or disables LibDVDNav. If disabled libdvdread will be used instead. /// </summary> @@ -365,9 +344,32 @@ namespace HandBrake.Interop.Interop ErrorLogged?.Invoke(null, new MessageLoggedEventArgs(message)); } - public static bool IsUsingNoHardwareFallback() + public static bool IsInitialised() + { + return initSuccess; + } + + public static bool IsInitNoHardware() + { + return initNoHardware; + } + + [HandleProcessCorruptedStateExceptions] + private static bool TryInit() { - return failedWithHardware; + try + { + if (HBFunctions.hb_global_init() == -1) + { + throw new InvalidOperationException("HB global init failed."); + } + } + catch (Exception e) + { + return false; + } + + return true; } } } diff --git a/win/CS/HandBrake.Interop/Interop/Interfaces/IEncodeInstance.cs b/win/CS/HandBrake.Interop/Interop/Interfaces/IEncodeInstance.cs index f0c4a2575..104983b8f 100644 --- a/win/CS/HandBrake.Interop/Interop/Interfaces/IEncodeInstance.cs +++ b/win/CS/HandBrake.Interop/Interop/Interfaces/IEncodeInstance.cs @@ -33,7 +33,7 @@ namespace HandBrake.Interop.Interop.Interfaces /// <param name="verbosity"> /// The code for the logging verbosity to use. /// </param> - void Initialize(int verbosity); + void Initialize(int verbosity, bool noHardware); /// <summary> /// Frees any resources associated with this object. diff --git a/win/CS/HandBrake.Interop/Model/HBConfiguration.cs b/win/CS/HandBrake.Interop/Model/HBConfiguration.cs index 77ea30954..2ec9f8302 100644 --- a/win/CS/HandBrake.Interop/Model/HBConfiguration.cs +++ b/win/CS/HandBrake.Interop/Model/HBConfiguration.cs @@ -73,5 +73,11 @@ namespace HandBrake.Interop.Model /// Gets or sets a value indicating what port the worker process is to use. /// </summary> public int RemoteServicePort { get; set; } + + public bool EnableVceEncoder { get; set; } + + public bool EnableNvencEncoder { get; set; } + + public bool EnableQsvEncoder { get; set; } } } diff --git a/win/CS/HandBrake.Worker/ApiRouter.cs b/win/CS/HandBrake.Worker/ApiRouter.cs index 79b0ad262..8d1869465 100644 --- a/win/CS/HandBrake.Worker/ApiRouter.cs +++ b/win/CS/HandBrake.Worker/ApiRouter.cs @@ -32,7 +32,7 @@ namespace HandBrake.Worker } // TODO support verbosity - this.handbrakeInstance.Initialize(1); + this.handbrakeInstance.Initialize(1, true); // TODO enable user setting support for nohardware return null; } diff --git a/win/CS/HandBrakeWPF/App.xaml.cs b/win/CS/HandBrakeWPF/App.xaml.cs index 7aa538137..c784eb7a5 100644 --- a/win/CS/HandBrakeWPF/App.xaml.cs +++ b/win/CS/HandBrakeWPF/App.xaml.cs @@ -20,7 +20,10 @@ namespace HandBrakeWPF using Caliburn.Micro;
+ using HandBrake.Interop.Interop;
+
using HandBrakeWPF.Helpers;
+ using HandBrakeWPF.Instance;
using HandBrakeWPF.Model;
using HandBrakeWPF.Services.Interfaces;
using HandBrakeWPF.Startup;
@@ -119,6 +122,28 @@ namespace HandBrakeWPF }
}
+
+ // NO-Hardware Mode
+ bool noHardware = e.Args.Any(f => f.Equals("--no-hardware"));
+
+ // Initialise the Engine
+ HandBrakeWPF.Helpers.LogManager.Init();
+
+ try
+ {
+ HandBrakeInstanceManager.Init(noHardware);
+ }
+ catch (Exception exception)
+ {
+ if (!noHardware)
+ {
+ MessageBox.Show(HandBrakeWPF.Properties.Resources.Startup_InitFailed, HandBrakeWPF.Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
+ }
+
+ throw exception;
+ }
+
+ // Initialise the GUI
base.OnStartup(e);
// If we have a file dropped on the icon, try scanning it.
@@ -144,7 +169,7 @@ namespace HandBrakeWPF Caliburn.Micro.Execute.OnUIThreadAsync(() => {
if (e.ExceptionObject.GetType() == typeof(FileNotFoundException))
{
- GeneralApplicationException exception = new GeneralApplicationException("A file appears to be missing.", "Try re-installing Microsoft .NET Framework 4.0", (Exception)e.ExceptionObject);
+ GeneralApplicationException exception = new GeneralApplicationException("A file appears to be missing.", "Try re-installing Microsoft .NET Framework 4.7.1", (Exception)e.ExceptionObject);
this.ShowError(exception);
}
else
@@ -168,7 +193,7 @@ namespace HandBrakeWPF {
if (e.Exception.GetType() == typeof(FileNotFoundException))
{
- GeneralApplicationException exception = new GeneralApplicationException("A file appears to be missing.", "Try re-installing Microsoft .NET Framework 4.0", e.Exception);
+ GeneralApplicationException exception = new GeneralApplicationException("A file appears to be missing.", "Try re-installing Microsoft .NET Framework 4.7.1", e.Exception);
this.ShowError(exception);
}
else if (e.Exception.GetType() == typeof(GeneralApplicationException))
diff --git a/win/CS/HandBrakeWPF/Factories/HBConfigurationFactory.cs b/win/CS/HandBrakeWPF/Factories/HBConfigurationFactory.cs index f4e0b9ee7..b2aba62ae 100644 --- a/win/CS/HandBrakeWPF/Factories/HBConfigurationFactory.cs +++ b/win/CS/HandBrakeWPF/Factories/HBConfigurationFactory.cs @@ -36,8 +36,6 @@ namespace HandBrakeWPF.Factories HBConfiguration config = new HBConfiguration
{
IsDvdNavDisabled = UserSettingService.GetUserSetting<bool>(UserSettingConstants.DisableLibDvdNav),
- EnableQuickSyncDecoding = UserSettingService.GetUserSetting<bool>(UserSettingConstants.EnableQuickSyncDecoding),
- UseQSVDecodeForNonQSVEnc = UserSettingService.GetUserSetting<bool>(UserSettingConstants.UseQSVDecodeForNonQSVEnc),
ScalingMode = UserSettingService.GetUserSetting<VideoScaler>(UserSettingConstants.ScalingMode, typeof(int)),
PreviewScanCount = UserSettingService.GetUserSetting<int>(UserSettingConstants.PreviewScanCount, typeof(int)),
Verbosity = UserSettingService.GetUserSetting<int>(UserSettingConstants.Verbosity, typeof(int)),
@@ -46,8 +44,13 @@ namespace HandBrakeWPF.Factories SaveLogWithVideo = UserSettingService.GetUserSetting<bool>(UserSettingConstants.SaveLogWithVideo),
SaveLogCopyDirectory = UserSettingService.GetUserSetting<string>(UserSettingConstants.SaveLogCopyDirectory),
RemoteServiceEnabled = UserSettingService.GetUserSetting<bool>(UserSettingConstants.RemoteServiceEnabled),
- RemoteServicePort = UserSettingService.GetUserSetting<int>(UserSettingConstants.RemoteServicePort, typeof(int))
- };
+ RemoteServicePort = UserSettingService.GetUserSetting<int>(UserSettingConstants.RemoteServicePort, typeof(int)),
+ EnableVceEncoder = UserSettingService.GetUserSetting<bool>(UserSettingConstants.EnableVceEncoder),
+ EnableNvencEncoder = UserSettingService.GetUserSetting<bool>(UserSettingConstants.EnableNvencEncoder),
+ EnableQsvEncoder = UserSettingService.GetUserSetting<bool>(UserSettingConstants.EnableQuickSyncEncoding),
+ EnableQuickSyncDecoding = UserSettingService.GetUserSetting<bool>(UserSettingConstants.EnableQuickSyncDecoding),
+ UseQSVDecodeForNonQSVEnc = UserSettingService.GetUserSetting<bool>(UserSettingConstants.UseQSVDecodeForNonQSVEnc)
+ };
return config;
}
diff --git a/win/CS/HandBrakeWPF/Instance/HandBrakeInstanceManager.cs b/win/CS/HandBrakeWPF/Instance/HandBrakeInstanceManager.cs index d841dfab5..bfcf2ecd7 100644 --- a/win/CS/HandBrakeWPF/Instance/HandBrakeInstanceManager.cs +++ b/win/CS/HandBrakeWPF/Instance/HandBrakeInstanceManager.cs @@ -9,10 +9,15 @@ namespace HandBrakeWPF.Instance { + using System; + using System.Runtime.CompilerServices; + using HandBrake.Interop.Interop; using HandBrake.Interop.Interop.Interfaces; using HandBrake.Interop.Model; + using HandBrakeWPF.Factories; + /// <summary> /// The HandBrake Instance manager. /// Only supports scanning right now. @@ -22,20 +27,16 @@ namespace HandBrakeWPF.Instance private static IEncodeInstance encodeInstance; private static HandBrakeInstance scanInstance; private static HandBrakeInstance previewInstance; - - /// <summary> - /// Initializes static members of the <see cref="HandBrakeInstanceManager"/> class. - /// </summary> - static HandBrakeInstanceManager() - { - } + private static bool noHardware; /// <summary> /// The init. /// </summary> - public static void Init() + public static void Init(bool noHardwareMode) { - // Nothing to do. Triggers static constructor. + noHardware = noHardwareMode; + HandBrakeUtils.RegisterLogger(); + HandBrakeUtils.EnsureGlobalInit(noHardwareMode); } /// <summary> @@ -52,6 +53,11 @@ namespace HandBrakeWPF.Instance /// </returns> public static IEncodeInstance GetEncodeInstance(int verbosity, HBConfiguration configuration) { + if (!HandBrakeUtils.IsInitialised()) + { + throw new Exception("Please call Init before Using!"); + } + if (encodeInstance != null) { encodeInstance.Dispose(); @@ -68,8 +74,9 @@ namespace HandBrakeWPF.Instance { newInstance = new HandBrakeInstance(); } - - newInstance.Initialize(verbosity); + + newInstance.Initialize(verbosity, noHardware); + encodeInstance = newInstance; HandBrakeUtils.SetDvdNav(!configuration.IsDvdNavDisabled); @@ -83,11 +90,19 @@ namespace HandBrakeWPF.Instance /// <param name="verbosity"> /// The verbosity. /// </param> + /// <param name="configuration"> + /// HandBrakes config + /// </param> /// <returns> /// The <see cref="IHandBrakeInstance"/>. /// </returns> - public static IHandBrakeInstance GetScanInstance(int verbosity) + public static IHandBrakeInstance GetScanInstance(int verbosity, HBConfiguration configuration) { + if (!HandBrakeUtils.IsInitialised()) + { + throw new Exception("Please call Init before Using!"); + } + if (scanInstance != null) { scanInstance.Dispose(); @@ -95,7 +110,7 @@ namespace HandBrakeWPF.Instance } HandBrakeInstance newInstance = new HandBrakeInstance(); - newInstance.Initialize(verbosity); + newInstance.Initialize(verbosity, noHardware); scanInstance = newInstance; return scanInstance; @@ -115,6 +130,11 @@ namespace HandBrakeWPF.Instance /// </returns> public static IHandBrakeInstance GetPreviewInstance(int verbosity, HBConfiguration configuration) { + if (!HandBrakeUtils.IsInitialised()) + { + throw new Exception("Please call Init before Using!"); + } + if (previewInstance != null) { previewInstance.Dispose(); @@ -122,7 +142,7 @@ namespace HandBrakeWPF.Instance } HandBrakeInstance newInstance = new HandBrakeInstance(); - newInstance.Initialize(verbosity); + newInstance.Initialize(verbosity, noHardware); previewInstance = newInstance; HandBrakeUtils.SetDvdNav(!configuration.IsDvdNavDisabled); diff --git a/win/CS/HandBrakeWPF/Instance/RemoteInstance.cs b/win/CS/HandBrakeWPF/Instance/RemoteInstance.cs index 375dd2db1..e7c077c52 100644 --- a/win/CS/HandBrakeWPF/Instance/RemoteInstance.cs +++ b/win/CS/HandBrakeWPF/Instance/RemoteInstance.cs @@ -98,7 +98,7 @@ namespace HandBrakeWPF.Instance return state; } - public void Initialize(int verbosity) + public void Initialize(int verbosity, bool noHardware) { this.StartServer(); } diff --git a/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs b/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs index 13ecd9daa..0a34c24c8 100644 --- a/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs +++ b/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs @@ -3051,7 +3051,7 @@ namespace HandBrakeWPF.Properties { } /// <summary> - /// Looks up a localized string similar to Hardware encoding support has been automatically disabled on your system due to an issue detected during hardware detection. Please make sure you are running up-to-date drivers for all graphics adaptors in this system. + /// Looks up a localized string similar to Hardware encoding support is currently disabled. Please make sure you are running up-to-date drivers for all graphics adaptors in this system. /// ///This will not impact any of the software encoders.. /// </summary> @@ -4591,6 +4591,15 @@ namespace HandBrakeWPF.Properties { } /// <summary> + /// Looks up a localized string similar to HandBrake's engine failed to initialise. This is often caused by out of date GPU drivers.\n Please update the GPU drivers for any onboard and discrete graphics your system has.. + /// </summary> + public static string Startup_InitFailed { + get { + return ResourceManager.GetString("Startup_InitFailed", resourceCulture); + } + } + + /// <summary> /// Looks up a localized string similar to Ready. /// </summary> public static string State_Ready { diff --git a/win/CS/HandBrakeWPF/Properties/Resources.resx b/win/CS/HandBrakeWPF/Properties/Resources.resx index 4546be660..4df1fbf68 100644 --- a/win/CS/HandBrakeWPF/Properties/Resources.resx +++ b/win/CS/HandBrakeWPF/Properties/Resources.resx @@ -1899,7 +1899,7 @@ This will not affect your current settings in the Subtitle tab.</value> <value>Show 'Add Selection to Queue' on the toolbar</value>
</data>
<data name="OptionsView_HardwareDetectFailed" xml:space="preserve">
- <value>Hardware encoding support has been automatically disabled on your system due to an issue detected during hardware detection. Please make sure you are running up-to-date drivers for all graphics adaptors in this system.
+ <value>Hardware encoding support is currently disabled. Please make sure you are running up-to-date drivers for all graphics adaptors in this system.
This will not impact any of the software encoders.</value>
</data>
@@ -1938,4 +1938,7 @@ Time Remaining: {5}, Elapsed: {6:d\:hh\:mm\:ss} {7}</value> <data name="Portable_IniFileError" xml:space="preserve">
<value>Portable Mode: Unable to read portable.ini. There may be an error in this file. Please retry using portable.ini.template as a guide.</value>
</data>
+ <data name="Startup_InitFailed" xml:space="preserve">
+ <value>HandBrake's engine failed to initialise. This is often caused by out of date GPU drivers.\n Please update the GPU drivers for any onboard and discrete graphics your system has.</value>
+ </data>
</root>
\ No newline at end of file diff --git a/win/CS/HandBrakeWPF/Services/Scan/LibScan.cs b/win/CS/HandBrakeWPF/Services/Scan/LibScan.cs index de26ae87d..d545ee2ed 100644 --- a/win/CS/HandBrakeWPF/Services/Scan/LibScan.cs +++ b/win/CS/HandBrakeWPF/Services/Scan/LibScan.cs @@ -128,7 +128,7 @@ namespace HandBrakeWPF.Services.Scan this.postScanOperation = postAction; // Create a new HandBrake Instance. - this.instance = HandBrakeInstanceManager.GetScanInstance(configuraiton.Verbosity); + this.instance = HandBrakeInstanceManager.GetScanInstance(configuraiton.Verbosity, configuraiton); this.instance.ScanProgress += this.InstanceScanProgress; this.instance.ScanCompleted += this.InstanceScanCompleted; diff --git a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs index 0b663f384..56e8d6d0d 100644 --- a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs @@ -117,8 +117,6 @@ namespace HandBrakeWPF.ViewModels IQueueViewModel queueViewModel, IMetaDataViewModel metaDataViewModel, INotifyIconService notifyIconService)
: base(userSettingService)
{
- HandBrakeUtils.RegisterLogger();
-
this.scanService = scanService;
this.presetService = presetService;
this.errorService = errorService;
@@ -185,8 +183,6 @@ namespace HandBrakeWPF.ViewModels // Setup Commands
this.QueueCommand = new QueueCommands(this.QueueViewModel);
- LogManager.Init();
- HandBrakeInstanceManager.Init();
}
#region View Model Properties
diff --git a/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs index 1baeca994..374b1bcee 100644 --- a/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs @@ -1150,7 +1150,7 @@ namespace HandBrakeWPF.ViewModels }
}
- public bool IsHardwareFallbackMode => HandBrakeUtils.IsUsingNoHardwareFallback();
+ public bool IsHardwareFallbackMode => HandBrakeUtils.IsInitNoHardware();
#endregion
|