summaryrefslogtreecommitdiffstats
path: root/win/CS
diff options
context:
space:
mode:
authorsr55 <[email protected]>2020-07-18 16:58:39 +0100
committersr55 <[email protected]>2020-07-18 16:58:51 +0100
commit0014ddb8b4a559e07beffd70bc712511e8c9d881 (patch)
treee7875019e84db0e916ed95ce80016d3a4385b8fd /win/CS
parent2513a7306223c71a199bacc2502b8227272bec4f (diff)
WinGui: Make QSV hardware detection APIs information available to the UI for use and refactor the video tab preset defaulting behaviour. Better defaults for Nvidia, AMD and VCE hardware based on current generation hardware.
Diffstat (limited to 'win/CS')
-rw-r--r--win/CS/HandBrake.Interop/Interop/HbLib/HbFunctions.cs6
-rw-r--r--win/CS/HandBrake.Interop/Interop/HbLib/Wrappers/HbFunctionsDirect.cs10
-rw-r--r--win/CS/HandBrake.Interop/Interop/HbLib/Wrappers/Interfaces/IHbFunctions.cs4
-rw-r--r--win/CS/HandBrake.Interop/Utilities/SystemInfo.cs41
-rw-r--r--win/CS/HandBrakeWPF/ViewModels/ChaptersViewModel.cs14
-rw-r--r--win/CS/HandBrakeWPF/ViewModels/VideoViewModel.cs49
6 files changed, 104 insertions, 20 deletions
diff --git a/win/CS/HandBrake.Interop/Interop/HbLib/HbFunctions.cs b/win/CS/HandBrake.Interop/Interop/HbLib/HbFunctions.cs
index 742f63aea..c3b99c735 100644
--- a/win/CS/HandBrake.Interop/Interop/HbLib/HbFunctions.cs
+++ b/win/CS/HandBrake.Interop/Interop/HbLib/HbFunctions.cs
@@ -301,5 +301,11 @@ namespace HandBrake.Interop.Interop.HbLib
[DllImport("hb", EntryPoint = "hb_filter_get_tunes_json", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr hb_filter_get_tunes_json(int filter_id);
+
+ [DllImport("hb", EntryPoint = "hb_get_cpu_platform", CallingConvention = CallingConvention.Cdecl)]
+ public static extern int hb_get_cpu_platform();
+
+ [DllImport("hb", EntryPoint = "qsv_hardware_generation", CallingConvention = CallingConvention.Cdecl)]
+ public static extern int qsv_hardware_generation(int cpu_platform);
}
}
diff --git a/win/CS/HandBrake.Interop/Interop/HbLib/Wrappers/HbFunctionsDirect.cs b/win/CS/HandBrake.Interop/Interop/HbLib/Wrappers/HbFunctionsDirect.cs
index b98794d5d..7a892dc22 100644
--- a/win/CS/HandBrake.Interop/Interop/HbLib/Wrappers/HbFunctionsDirect.cs
+++ b/win/CS/HandBrake.Interop/Interop/HbLib/Wrappers/HbFunctionsDirect.cs
@@ -497,5 +497,15 @@ namespace HandBrake.Interop.Interop.HbLib.Wrappers
{
return HBFunctions.hb_filter_get_tunes_json(filter_id);
}
+
+ public int hb_get_cpu_platform()
+ {
+ return HBFunctions.hb_get_cpu_platform();
+ }
+
+ public int qsv_hardware_generation(int cpu_platform)
+ {
+ return HBFunctions.qsv_hardware_generation(cpu_platform);
+ }
}
}
diff --git a/win/CS/HandBrake.Interop/Interop/HbLib/Wrappers/Interfaces/IHbFunctions.cs b/win/CS/HandBrake.Interop/Interop/HbLib/Wrappers/Interfaces/IHbFunctions.cs
index b876c9f16..01c8e614b 100644
--- a/win/CS/HandBrake.Interop/Interop/HbLib/Wrappers/Interfaces/IHbFunctions.cs
+++ b/win/CS/HandBrake.Interop/Interop/HbLib/Wrappers/Interfaces/IHbFunctions.cs
@@ -211,5 +211,9 @@ namespace HandBrake.Interop.Interop.HbLib.Wrappers.Interfaces
IntPtr hb_filter_get_presets_json(int filter_id);
IntPtr hb_filter_get_tunes_json(int filter_id);
+
+ int hb_get_cpu_platform();
+
+ int qsv_hardware_generation(int cpu_platform);
}
}
diff --git a/win/CS/HandBrake.Interop/Utilities/SystemInfo.cs b/win/CS/HandBrake.Interop/Utilities/SystemInfo.cs
index b22e16d6c..6a0c72283 100644
--- a/win/CS/HandBrake.Interop/Utilities/SystemInfo.cs
+++ b/win/CS/HandBrake.Interop/Utilities/SystemInfo.cs
@@ -10,6 +10,7 @@
namespace HandBrake.Interop.Utilities
{
using System;
+ using System.Diagnostics;
using HandBrake.Interop.Interop.HbLib.Wrappers.Interfaces;
using HandBrake.Interop.Interop.Providers;
@@ -17,9 +18,6 @@ namespace HandBrake.Interop.Utilities
using Interop.HbLib;
- /// <summary>
- /// The System Information.
- /// </summary>
public class SystemInfo
{
private static bool? isNvencH264Available; // Local cache to prevent log spam.
@@ -33,9 +31,9 @@ namespace HandBrake.Interop.Utilities
hbFunctions = hbFunctionsProvider.GetHbFunctionsWrapper();
}
- /// <summary>
- /// Gets a value indicating whether is qsv available.
- /// </summary>
+
+ /* QuickSync Support */
+
public static bool IsQsvAvailable
{
get
@@ -52,9 +50,6 @@ namespace HandBrake.Interop.Utilities
}
}
- /// <summary>
- /// Gets a value indicating whether is qsv available.
- /// </summary>
public static bool IsQsvAvailableH264
{
get
@@ -71,9 +66,6 @@ namespace HandBrake.Interop.Utilities
}
}
- /// <summary>
- /// Gets a value indicating whether is qsv available.
- /// </summary>
public static bool IsQsvAvailableH265
{
get
@@ -90,6 +82,26 @@ namespace HandBrake.Interop.Utilities
}
}
+ public static int QsvHardwareGeneration
+ {
+ get
+ {
+ try
+ {
+ int cpu_platform = hbFunctions.hb_get_cpu_platform();
+ int hardware = hbFunctions.qsv_hardware_generation(cpu_platform);
+ return hardware;
+ }
+ catch (Exception exc)
+ {
+ // Silent failure. -1 means unsupported.
+ Debug.WriteLine(exc);
+ return -1;
+ }
+ }
+ }
+
+
public static bool IsQsvAvailableH26510bit
{
get
@@ -106,6 +118,9 @@ namespace HandBrake.Interop.Utilities
}
}
+
+ /* AMD VCE Support */
+
public static bool IsVceH264Available
{
get
@@ -138,6 +153,8 @@ namespace HandBrake.Interop.Utilities
}
}
+ /* Nvidia NVEnc Support */
+
public static bool IsNVEncH264Available
{
get
diff --git a/win/CS/HandBrakeWPF/ViewModels/ChaptersViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/ChaptersViewModel.cs
index dedfadf9f..91323761f 100644
--- a/win/CS/HandBrakeWPF/ViewModels/ChaptersViewModel.cs
+++ b/win/CS/HandBrakeWPF/ViewModels/ChaptersViewModel.cs
@@ -400,7 +400,19 @@ namespace HandBrakeWPF.ViewModels
// differences (e.g. longer title sequences and different distributor credits)
if (hasTimestamps)
{
- var diffs = importedChapters.Zip(this.Chapters, (import, source) => source.Duration - import.Value.Item2);
+ List<TimeSpan> diffs = new List<TimeSpan>();
+ foreach (KeyValuePair<int, Tuple<string, TimeSpan>> import in importedChapters)
+ {
+ ChapterMarker sourceMarker = this.Chapters[import.Key - 1];
+ TimeSpan source = sourceMarker.Duration;
+
+ TimeSpan diff = source - import.Value.Item2;
+ diffs.Add(diff);
+
+ }
+
+
+ // var diffs = importedChapters.Zip(this.Chapters, (import, source) => source.Duration - import.Value.Item2);
if (diffs.Count(diff => Math.Abs(diff.TotalSeconds) > 15) > 2)
{
if (this.errorService.ShowMessageBox(
diff --git a/win/CS/HandBrakeWPF/ViewModels/VideoViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/VideoViewModel.cs
index 5170e45c7..d79398348 100644
--- a/win/CS/HandBrakeWPF/ViewModels/VideoViewModel.cs
+++ b/win/CS/HandBrakeWPF/ViewModels/VideoViewModel.cs
@@ -1435,14 +1435,9 @@ namespace HandBrakeWPF.ViewModels
}
this.VideoPresetMaxValue = encoder.Presets.Count - 1;
- int middlePreset = (int)Math.Round((decimal)(this.VideoPresetMaxValue / 2), 0);
+
- if (selectedEncoder == VideoEncoder.NvencH264 || selectedEncoder == VideoEncoder.NvencH265)
- {
- middlePreset = this.VideoPresets.IndexOf(this.VideoPresets.FirstOrDefault(s => s.ShortName == "slow"));
- }
-
- this.VideoPresetValue = middlePreset;
+ this.VideoPresetValue = GetDefaultEncoderPreset(selectedEncoder);
}
else
{
@@ -1532,5 +1527,45 @@ namespace HandBrakeWPF.ViewModels
this.SetRF(displayRF);
}
+
+ private int GetDefaultEncoderPreset(VideoEncoder selectedEncoder)
+ {
+ int defaultPreset = (int)Math.Round((decimal)(this.VideoPresetMaxValue / 2), 0);
+
+ // Override for NVEnc
+ if (selectedEncoder == VideoEncoder.NvencH264 || selectedEncoder == VideoEncoder.NvencH265)
+ {
+ // TODO -> is the RTX good enough to default to a more balanced preset?
+ defaultPreset = this.VideoPresets.IndexOf(this.VideoPresets.FirstOrDefault(s => s.ShortName == "slow"));
+ }
+
+ // Override for QuickSync
+ if (selectedEncoder == VideoEncoder.QuickSyncH265 || selectedEncoder == VideoEncoder.QuickSyncH26510b)
+ {
+ if (HandBrake.Interop.Utilities.SystemInfo.QsvHardwareGeneration > 6)
+ {
+ defaultPreset = this.VideoPresets.IndexOf(this.VideoPresets.FirstOrDefault(s => s.ShortName == "speed")); // TGL
+ }
+ else
+ {
+ defaultPreset = this.VideoPresets.IndexOf(this.VideoPresets.FirstOrDefault(s => s.ShortName == "balanced")); // ICL and Earlier.
+ }
+ }
+
+ if (selectedEncoder == VideoEncoder.QuickSync)
+ {
+ // h264 encoder hasn't changed much in recent years, so stick to balanced.
+ defaultPreset = this.VideoPresets.IndexOf(this.VideoPresets.FirstOrDefault(s => s.ShortName == "balanced"));
+ }
+
+ // Override for VCE
+ if (selectedEncoder == VideoEncoder.VceH264 || selectedEncoder == VideoEncoder.VceH265)
+ {
+ // TODO Would be good to have VCE version detection.
+ defaultPreset = this.VideoPresets.IndexOf(this.VideoPresets.FirstOrDefault(s => s.ShortName == "balanced"));
+ }
+
+ return defaultPreset;
+ }
}
} \ No newline at end of file