]> granicus.if.org Git - handbrake/commitdiff
Interop: Added functions to get the list of keys for filter settings, and the default...
authorRandomEngy <david.rickard@gmail.com>
Mon, 7 Nov 2016 05:36:45 +0000 (21:36 -0800)
committerRandomEngy <david.rickard@gmail.com>
Mon, 7 Nov 2016 05:36:45 +0000 (21:36 -0800)
win/CS/HandBrake.ApplicationServices/Interop/HandBrakeFilterHelpers.cs
win/CS/HandBrake.ApplicationServices/Interop/HbLib/HbFunctions.cs

index d398ffff991d79690c3a7afbf647ebfad53bf80d..0db9f4f37fc633728f081fc024eb38e3bab80021 100644 (file)
@@ -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();
         }
+
+        /// <summary>
+        /// Gets a list of keys for custom settings for the filter.
+        /// </summary>
+        /// <param name="filter">The filter to look up.</param>
+        /// <returns>The list of keys for custom settings for the filter.</returns>
+        public static List<string> GetFilterKeys(int filter)
+        {
+            IntPtr ptr = HBFunctions.hb_filter_get_keys(filter);
+            return InteropUtilities.ToStringListFromArrayPtr(ptr);
+        }
+
+        /// <summary>
+        /// Gets the default settings for the filter.
+        /// </summary>
+        /// <param name="filter">The filter to look up.</param>
+        /// <returns>The default settings for that filter.</returns>
+        public static IDictionary<string, string> GetDefaultCustomSettings(int filter)
+        {
+            string presetName;
+
+            List<HBPresetTune> 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<string, string>();
+            }
+
+            IntPtr ptr = HBFunctions.hb_generate_filter_settings_json(filter, presetName, null, null);
+            string result = Marshal.PtrToStringAnsi(ptr);
+            return JsonConvert.DeserializeObject<Dictionary<string, string>>(result);
+        }
     }
 }
index 6a7dd6637d2933675a6769b7985f85865f425d5d..d844217b008e3e2ea1acd6770dd77ff8756319ba 100644 (file)
@@ -377,6 +377,10 @@ namespace HandBrake.ApplicationServices.Interop.HbLib
         [DllImport("hb.dll", EntryPoint = "hb_filter_get_tunes_json", CallingConvention = CallingConvention.Cdecl)]\r
         public static extern IntPtr hb_filter_get_tunes_json(int filter_id);\r
 \r
+        // char ** hb_filter_get_keys(int filter_id);\r
+        [DllImport("hb.dll", EntryPoint = "hb_filter_get_keys", CallingConvention = CallingConvention.Cdecl)]\r
+        public static extern IntPtr hb_filter_get_keys(int filter_id);\r
+\r
         [DllImport("hb.dll", EntryPoint = "hb_x264_encopt_name", CallingConvention = CallingConvention.Cdecl)]\r
         public static extern IntPtr hb_x264_encopt_name(IntPtr name);\r
 \r