From adbd01221818bc206b72509b85ab5076463d4158 Mon Sep 17 00:00:00 2001 From: sr55 Date: Sun, 28 Feb 2021 12:09:42 +0000 Subject: WinGui: Add a warning in preferencs -> Safemode when Hardware support is not available. --- .../Interop/HandBrakeHardwareEncoderHelper.cs | 40 +++++++++++++++++----- .../HandBrakeWPF/Properties/Resources.Designer.cs | 13 +++++-- win/CS/HandBrakeWPF/Properties/Resources.resx | 7 ++-- win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs | 4 +++ win/CS/HandBrakeWPF/Views/OptionsView.xaml | 16 +++++++-- 5 files changed, 66 insertions(+), 14 deletions(-) (limited to 'win/CS') diff --git a/win/CS/HandBrake.Interop/Interop/HandBrakeHardwareEncoderHelper.cs b/win/CS/HandBrake.Interop/Interop/HandBrakeHardwareEncoderHelper.cs index f0e55062a..168b7773d 100644 --- a/win/CS/HandBrake.Interop/Interop/HandBrakeHardwareEncoderHelper.cs +++ b/win/CS/HandBrake.Interop/Interop/HandBrakeHardwareEncoderHelper.cs @@ -11,6 +11,8 @@ namespace HandBrake.Interop.Interop { using System; using System.Diagnostics; + using System.Dynamic; + using System.Runtime.InteropServices; using HandBrake.Interop.Interop.HbLib; @@ -19,6 +21,28 @@ namespace HandBrake.Interop.Interop private static bool? isNvencH264Available; // Local cache to prevent log spam. private static bool? isNvencH265Available; + public static bool IsSafeMode + { + get + { + try + { + if (RuntimeInformation.ProcessArchitecture == Architecture.Arm64) + { + return false; + } + + return (HBFunctions.hb_qsv_available() + HBFunctions.hb_vce_h264_available() + + HBFunctions.hb_nvenc_h264_available()) == -3; + } + catch (Exception) + { + // Silent failure. Typically this means the dll hasn't been built with --enable-qsv + return false; + } + } + } + /* QuickSync Support */ public static bool IsQsvAvailable @@ -27,7 +51,7 @@ namespace HandBrake.Interop.Interop { try { - return HBFunctions.hb_qsv_available() != 0; + return HBFunctions.hb_qsv_available() > 0; } catch (Exception) { @@ -43,7 +67,7 @@ namespace HandBrake.Interop.Interop { try { - return (HBFunctions.hb_qsv_available() & NativeConstants.HB_VCODEC_QSV_H264) != 0; + return (HBFunctions.hb_qsv_available() & NativeConstants.HB_VCODEC_QSV_H264) > 0; } catch (Exception) { @@ -59,7 +83,7 @@ namespace HandBrake.Interop.Interop { try { - return (HBFunctions.hb_qsv_available() & NativeConstants.HB_VCODEC_QSV_H265) != 0; + return (HBFunctions.hb_qsv_available() & NativeConstants.HB_VCODEC_QSV_H265) > 0; } catch (Exception) { @@ -94,7 +118,7 @@ namespace HandBrake.Interop.Interop { try { - return (HBFunctions.hb_qsv_available() & NativeConstants.HB_VCODEC_QSV_H265_10BIT) != 0; + return (HBFunctions.hb_qsv_available() & NativeConstants.HB_VCODEC_QSV_H265_10BIT) > 0; } catch (Exception) { @@ -112,7 +136,7 @@ namespace HandBrake.Interop.Interop { try { - return HBFunctions.hb_vce_h264_available() != 0; + return HBFunctions.hb_vce_h264_available() > 0; } catch (Exception) { @@ -128,7 +152,7 @@ namespace HandBrake.Interop.Interop { try { - return HBFunctions.hb_vce_h265_available() != 0; + return HBFunctions.hb_vce_h265_available() > 0; } catch (Exception) { @@ -148,7 +172,7 @@ namespace HandBrake.Interop.Interop { if (isNvencH264Available == null) { - isNvencH264Available = HBFunctions.hb_nvenc_h264_available() != 0; + isNvencH264Available = HBFunctions.hb_nvenc_h264_available() > 0; } return isNvencH264Available.Value; @@ -174,7 +198,7 @@ namespace HandBrake.Interop.Interop if (isNvencH265Available == null) { - isNvencH265Available = HBFunctions.hb_nvenc_h265_available() != 0; + isNvencH265Available = HBFunctions.hb_nvenc_h265_available() > 0; } return isNvencH265Available.Value; diff --git a/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs b/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs index 922b9f129..0b9f31970 100644 --- a/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs +++ b/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs @@ -3617,7 +3617,7 @@ namespace HandBrakeWPF.Properties { } /// - /// Looks up a localized string similar to Run each queued job in a separate worker process. (Experimental). + /// Looks up a localized string similar to Run each queued job in a separate worker process.. /// public static string OptionsView_EnableWorkerProcesses { get { @@ -3654,7 +3654,7 @@ namespace HandBrakeWPF.Properties { } /// - /// 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. + /// Looks up a localized string similar to Hardware encoding support is currently disabled. If you did not start HandBrake with the "--no-hardware" option, 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.. /// @@ -3808,6 +3808,15 @@ namespace HandBrakeWPF.Properties { } } + /// + /// Looks up a localized string similar to Warning: Please note that this is a "Safe Mode" build of HandBrake that does not include support for hardware encoders. If you wish to use hardware encoder support, please download a non-"Safe Mode" build from the website.. + /// + public static string OptionsView_SafeMode { + get { + return ResourceManager.GetString("OptionsView_SafeMode", resourceCulture); + } + } + /// /// Looks up a localized string similar to Please select a folder.. /// diff --git a/win/CS/HandBrakeWPF/Properties/Resources.resx b/win/CS/HandBrakeWPF/Properties/Resources.resx index f0ee417b4..2bc277e9a 100644 --- a/win/CS/HandBrakeWPF/Properties/Resources.resx +++ b/win/CS/HandBrakeWPF/Properties/Resources.resx @@ -1843,7 +1843,7 @@ VLC and MPC-HC are supported. Other players may also work but are not validated. Show 'Add Selection to Queue' on the toolbar - Hardware encoding support is currently disabled. Please make sure you are running up-to-date drivers for all graphics adaptors in this system. + Hardware encoding support is currently disabled. If you did not start HandBrake with the "--no-hardware" option, 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. @@ -2191,7 +2191,7 @@ This will also stop any existing running jobs. Please select a single job to view summary information. - Run each queued job in a separate worker process. (Experimental) + Run each queued job in a separate worker process. Default network port for worker: @@ -2457,4 +2457,7 @@ Fields are limited to: Missing file "hb.dll". Please re-install. + + Warning: Please note that this is a "Safe Mode" build of HandBrake that does not include support for hardware encoders. If you wish to use hardware encoder support, please download a non-"Safe Mode" build from the website. + \ No newline at end of file diff --git a/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs index 2eb5ce954..817fb4041 100644 --- a/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs @@ -881,6 +881,10 @@ namespace HandBrakeWPF.ViewModels public bool IsHardwareFallbackMode => HandBrakeUtils.IsInitNoHardware(); + public bool IsSafeMode => HandBrakeHardwareEncoderHelper.IsSafeMode; + + public bool IsHardwareOptionsVisibile => !IsSafeMode && !IsHardwareFallbackMode; + /* About HandBrake */ diff --git a/win/CS/HandBrakeWPF/Views/OptionsView.xaml b/win/CS/HandBrakeWPF/Views/OptionsView.xaml index dc7a7ab46..1709d0160 100644 --- a/win/CS/HandBrakeWPF/Views/OptionsView.xaml +++ b/win/CS/HandBrakeWPF/Views/OptionsView.xaml @@ -338,7 +338,19 @@ - + + + + + + + + + + + + + @@ -348,7 +360,7 @@ - + -- cgit v1.2.3