From: RandomEngy Date: Mon, 7 Nov 2016 05:36:45 +0000 (-0800) Subject: Interop: Added functions to get the list of keys for filter settings, and the default... X-Git-Tag: 1.0.0~138^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6e73fcdb6c92b924b5b3b2c6a73ed3c479f2fd84;p=handbrake Interop: Added functions to get the list of keys for filter settings, and the default settings for a filter. --- diff --git a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeFilterHelpers.cs b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeFilterHelpers.cs index d398ffff9..0db9f4f37 100644 --- a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeFilterHelpers.cs +++ b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeFilterHelpers.cs @@ -15,6 +15,7 @@ namespace HandBrake.ApplicationServices.Interop using System.Runtime.InteropServices; using HandBrake.ApplicationServices.Interop.HbLib; + using HandBrake.ApplicationServices.Interop.Helpers; using HandBrake.ApplicationServices.Interop.Json.Filters; using HandBrake.ApplicationServices.Interop.Model.Encoding; @@ -60,5 +61,44 @@ namespace HandBrake.ApplicationServices.Interop return list.Select(item => new HBPresetTune(item.Name, item.Short_Name)).ToList(); } + + /// + /// Gets a list of keys for custom settings for the filter. + /// + /// The filter to look up. + /// The list of keys for custom settings for the filter. + public static List GetFilterKeys(int filter) + { + IntPtr ptr = HBFunctions.hb_filter_get_keys(filter); + return InteropUtilities.ToStringListFromArrayPtr(ptr); + } + + /// + /// Gets the default settings for the filter. + /// + /// The filter to look up. + /// The default settings for that filter. + public static IDictionary GetDefaultCustomSettings(int filter) + { + string presetName; + + List presets = GetFilterPresets(filter); + if (presets.Any(p => p.ShortName == "default")) + { + presetName = "default"; + } + else if (presets.Any(p => p.ShortName == "medium")) + { + presetName = "medium"; + } + else + { + return new Dictionary(); + } + + IntPtr ptr = HBFunctions.hb_generate_filter_settings_json(filter, presetName, null, null); + string result = Marshal.PtrToStringAnsi(ptr); + return JsonConvert.DeserializeObject>(result); + } } } diff --git a/win/CS/HandBrake.ApplicationServices/Interop/HbLib/HbFunctions.cs b/win/CS/HandBrake.ApplicationServices/Interop/HbLib/HbFunctions.cs index 6a7dd6637..d844217b0 100644 --- a/win/CS/HandBrake.ApplicationServices/Interop/HbLib/HbFunctions.cs +++ b/win/CS/HandBrake.ApplicationServices/Interop/HbLib/HbFunctions.cs @@ -377,6 +377,10 @@ namespace HandBrake.ApplicationServices.Interop.HbLib [DllImport("hb.dll", EntryPoint = "hb_filter_get_tunes_json", CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr hb_filter_get_tunes_json(int filter_id); + // char ** hb_filter_get_keys(int filter_id); + [DllImport("hb.dll", EntryPoint = "hb_filter_get_keys", CallingConvention = CallingConvention.Cdecl)] + public static extern IntPtr hb_filter_get_keys(int filter_id); + [DllImport("hb.dll", EntryPoint = "hb_x264_encopt_name", CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr hb_x264_encopt_name(IntPtr name);