diff options
Diffstat (limited to 'win/CS/HandBrake.Interop')
6 files changed, 63 insertions, 46 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; } } } |