diff options
author | sr55 <[email protected]> | 2016-03-05 21:52:37 +0000 |
---|---|---|
committer | John Stebbins <[email protected]> | 2016-03-09 13:10:10 -0700 |
commit | 0205f13f2d3226343b3d27eb06170679fd292593 (patch) | |
tree | 4d783d2e24f44f635fb6ceaef46e8ee6fd7daeb5 /win/CS | |
parent | b7f4685f8d765d7a5c1335bf4ddc957bf9417433 (diff) |
WinGui: Initial support for dict based filter options.
Diffstat (limited to 'win/CS')
7 files changed, 190 insertions, 34 deletions
diff --git a/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj b/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj index 16afa531b..60f7a7b9d 100644 --- a/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj +++ b/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj @@ -86,6 +86,7 @@ <Compile Include="Interop\EventArgs\MessageLoggedEventArgs.cs" />
<Compile Include="Interop\EventArgs\ScanProgressEventArgs.cs" />
<Compile Include="Interop\HandBrakeEncoderHelpers.cs" />
+ <Compile Include="Interop\HandBrakeFilterHelpers.cs" />
<Compile Include="Interop\HandBrakeInstance.cs" />
<Compile Include="Interop\HandBrakeInstanceManager.cs" />
<Compile Include="Interop\HandBrakeLanguagesHelper.cs" />
@@ -113,6 +114,7 @@ <Compile Include="Interop\Json\Anamorphic\AnamorphicGeometry.cs" />
<Compile Include="Interop\Json\Anamorphic\DestSettings.cs" />
<Compile Include="Interop\Json\Encode\QSV.cs" />
+ <Compile Include="Interop\Json\Filters\PresetTune.cs" />
<Compile Include="Interop\Json\Presets\AudioList.cs" />
<Compile Include="Interop\Json\Presets\HBPreset.cs" />
<Compile Include="Interop\Json\Presets\PresetCategory.cs" />
@@ -136,6 +138,7 @@ <Compile Include="Interop\Json\Encode\Video.cs" />
<Compile Include="Interop\Factories\AnamorphicFactory.cs" />
<Compile Include="Interop\Model\Encoding\DeinterlaceFilter.cs" />
+ <Compile Include="Interop\Model\Encoding\HBPresetTune.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Interop\Json\Scan\SourceAudioTrack.cs" />
<Compile Include="Interop\Json\Scan\SourceChapter.cs" />
diff --git a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeFilterHelpers.cs b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeFilterHelpers.cs new file mode 100644 index 000000000..d398ffff9 --- /dev/null +++ b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeFilterHelpers.cs @@ -0,0 +1,64 @@ +// -------------------------------------------------------------------------------------------------------------------- +// <copyright file="HandBrakeFilterHelpers.cs" company="HandBrake Project (http://handbrake.fr)"> +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// </copyright> +// <summary> +// Defines the HandBrakeFilterHelpers type. +// </summary> +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrake.ApplicationServices.Interop +{ + using System; + using System.Collections.Generic; + using System.Linq; + using System.Runtime.InteropServices; + + using HandBrake.ApplicationServices.Interop.HbLib; + using HandBrake.ApplicationServices.Interop.Json.Filters; + using HandBrake.ApplicationServices.Interop.Model.Encoding; + + using Newtonsoft.Json; + + /// <summary> + /// The hand brake filter helpers. + /// </summary> + public class HandBrakeFilterHelpers + { + /// <summary> + /// The get filter presets. + /// </summary> + /// <param name="filter"> + /// The filter. + /// </param> + /// <returns> + /// The <see cref="List"/>. + /// </returns> + public static List<HBPresetTune> GetFilterPresets(int filter) + { + IntPtr ptr = HBFunctions.hb_filter_get_presets_json(filter); + string result = Marshal.PtrToStringAnsi(ptr); + List<PresetTune> list = JsonConvert.DeserializeObject<List<PresetTune>>(result); + + return list.Select(item => new HBPresetTune(item.Name, item.Short_Name)).ToList(); + } + + /// <summary> + /// The get filter tunes. + /// </summary> + /// <param name="filter"> + /// The filter. + /// </param> + /// <returns> + /// The <see cref="List"/>. + /// </returns> + public static List<HBPresetTune> GetFilterTunes(int filter) + { + IntPtr ptr = HBFunctions.hb_filter_get_tunes_json(filter); + string result = Marshal.PtrToStringAnsi(ptr); + List<PresetTune> list = JsonConvert.DeserializeObject<List<PresetTune>>(result); + + return list.Select(item => new HBPresetTune(item.Name, item.Short_Name)).ToList(); + } + } +} diff --git a/win/CS/HandBrake.ApplicationServices/Interop/HbLib/HbFunctions.cs b/win/CS/HandBrake.ApplicationServices/Interop/HbLib/HbFunctions.cs index 03606e587..6a7dd6637 100644 --- a/win/CS/HandBrake.ApplicationServices/Interop/HbLib/HbFunctions.cs +++ b/win/CS/HandBrake.ApplicationServices/Interop/HbLib/HbFunctions.cs @@ -362,11 +362,20 @@ namespace HandBrake.ApplicationServices.Interop.HbLib [DllImport("hb.dll", EntryPoint = "hb_filter_init", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr hb_filter_init(int filter_id);
- [DllImport("hb.dll", EntryPoint = "hb_generate_filter_settings", CallingConvention = CallingConvention.Cdecl)]
- public static extern IntPtr hb_generate_filter_settings(
+ [DllImport("hb.dll", EntryPoint = "hb_generate_filter_settings_json", CallingConvention = CallingConvention.Cdecl)]
+ public static extern IntPtr hb_generate_filter_settings_json(
int filter_id,
[In] [MarshalAs(UnmanagedType.LPStr)] string preset,
- [In] [MarshalAs(UnmanagedType.LPStr)] string tune);
+ [In] [MarshalAs(UnmanagedType.LPStr)] string tune,
+ [In] [MarshalAs(UnmanagedType.LPStr)] string custom);
+
+ /// char* hb_filter_get_presets_json(int filter_id);
+ [DllImport("hb.dll", EntryPoint = "hb_filter_get_presets_json", CallingConvention = CallingConvention.Cdecl)]
+ public static extern IntPtr hb_filter_get_presets_json(int filter_id);
+
+ /// char* hb_filter_get_tuness_json(int filter_id);
+ [DllImport("hb.dll", EntryPoint = "hb_filter_get_tunes_json", CallingConvention = CallingConvention.Cdecl)]
+ public static extern IntPtr hb_filter_get_tunes_json(int filter_id);
[DllImport("hb.dll", EntryPoint = "hb_x264_encopt_name", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr hb_x264_encopt_name(IntPtr name);
diff --git a/win/CS/HandBrake.ApplicationServices/Interop/Json/Encode/Filter.cs b/win/CS/HandBrake.ApplicationServices/Interop/Json/Encode/Filter.cs index 87bb43190..4479f5d77 100644 --- a/win/CS/HandBrake.ApplicationServices/Interop/Json/Encode/Filter.cs +++ b/win/CS/HandBrake.ApplicationServices/Interop/Json/Encode/Filter.cs @@ -9,6 +9,8 @@ namespace HandBrake.ApplicationServices.Interop.Json.Encode
{
+ using Newtonsoft.Json.Linq;
+
/// <summary>
/// The filter list.
/// </summary>
@@ -22,6 +24,6 @@ namespace HandBrake.ApplicationServices.Interop.Json.Encode /// <summary>
/// Gets or sets the settings.
/// </summary>
- public string Settings { get; set; }
+ public JToken Settings { get; set; }
}
}
\ No newline at end of file diff --git a/win/CS/HandBrake.ApplicationServices/Interop/Json/Filters/PresetTune.cs b/win/CS/HandBrake.ApplicationServices/Interop/Json/Filters/PresetTune.cs new file mode 100644 index 000000000..f69cec099 --- /dev/null +++ b/win/CS/HandBrake.ApplicationServices/Interop/Json/Filters/PresetTune.cs @@ -0,0 +1,27 @@ +// -------------------------------------------------------------------------------------------------------------------- +// <copyright file="PresetTune.cs" company="HandBrake Project (http://handbrake.fr)"> +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// </copyright> +// <summary> +// Defines the PresetTune type. +// </summary> +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrake.ApplicationServices.Interop.Json.Filters +{ + /// <summary> + /// The preset tune. + /// </summary> + public class PresetTune + { + /// <summary> + /// Gets or sets the name. + /// </summary> + public string Name { get; set; } + + /// <summary> + /// Gets or sets the short name. + /// </summary> + public string Short_Name { get; set; } + } +} diff --git a/win/CS/HandBrake.ApplicationServices/Interop/Model/Encoding/HBPresetTune.cs b/win/CS/HandBrake.ApplicationServices/Interop/Model/Encoding/HBPresetTune.cs new file mode 100644 index 000000000..e5c914fb1 --- /dev/null +++ b/win/CS/HandBrake.ApplicationServices/Interop/Model/Encoding/HBPresetTune.cs @@ -0,0 +1,42 @@ +// -------------------------------------------------------------------------------------------------------------------- +// <copyright file="HBPresetTune.cs" company="HandBrake Project (http://handbrake.fr)"> +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// </copyright> +// <summary> +// Defines the HBPresetTune type. +// </summary> +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrake.ApplicationServices.Interop.Model.Encoding +{ + /// <summary> + /// The hb preset tune. + /// </summary> + public class HBPresetTune + { + /// <summary> + /// Initializes a new instance of the <see cref="T:System.Object"/> class. + /// </summary> + /// <param name="name"> + /// The name. + /// </param> + /// <param name="shortName"> + /// The short Name. + /// </param> + public HBPresetTune(string name, string shortName) + { + this.Name = name; + this.ShortName = shortName; + } + + /// <summary> + /// Gets the name. + /// </summary> + public string Name { get; private set; } + + /// <summary> + /// Gets the short name. + /// </summary> + public string ShortName { get; private set; } + } +} diff --git a/win/CS/HandBrakeWPF/Services/Encode/Factories/EncodeFactory.cs b/win/CS/HandBrakeWPF/Services/Encode/Factories/EncodeFactory.cs index be1b5e4c6..6c02ffd08 100644 --- a/win/CS/HandBrakeWPF/Services/Encode/Factories/EncodeFactory.cs +++ b/win/CS/HandBrakeWPF/Services/Encode/Factories/EncodeFactory.cs @@ -26,6 +26,8 @@ namespace HandBrakeWPF.Services.Encode.Factories using HandBrakeWPF.Utilities; + using Newtonsoft.Json.Linq; + using AudioEncoder = HandBrakeWPF.Services.Encode.Model.Models.AudioEncoder; using AudioEncoderRateType = HandBrakeWPF.Services.Encode.Model.Models.AudioEncoderRateType; using AudioTrack = HandBrakeWPF.Services.Encode.Model.Models.AudioTrack; @@ -403,25 +405,31 @@ namespace HandBrakeWPF.Services.Encode.Factories // Detelecine if (job.Detelecine != Detelecine.Off) { - Filter filterItem = new Filter { ID = (int)hb_filter_ids.HB_FILTER_DETELECINE, Settings = job.CustomDetelecine }; + IntPtr settingsPtr = HBFunctions.hb_generate_filter_settings_json((int)hb_filter_ids.HB_FILTER_DETELECINE, null, null, job.CustomDetelecine); + string unparsedJson = Marshal.PtrToStringAnsi(settingsPtr); + JToken settings = JObject.Parse(unparsedJson); + + Filter filterItem = new Filter { ID = (int)hb_filter_ids.HB_FILTER_DETELECINE, Settings = settings }; filter.FilterList.Add(filterItem); } // Deinterlace if (job.DeinterlaceFilter == DeinterlaceFilter.Deinterlace) { - IntPtr settingsPtr = HBFunctions.hb_generate_filter_settings((int)hb_filter_ids.HB_FILTER_DEINTERLACE, EnumHelper<Deinterlace>.GetShortName(job.Deinterlace), job.CustomDeinterlace); - string settings = Marshal.PtrToStringAnsi(settingsPtr); + IntPtr settingsPtr = HBFunctions.hb_generate_filter_settings_json((int)hb_filter_ids.HB_FILTER_DEINTERLACE, EnumHelper<Deinterlace>.GetShortName(job.Deinterlace), null, job.CustomDeinterlace); + string unparsedJson = Marshal.PtrToStringAnsi(settingsPtr); + JToken root = JObject.Parse(unparsedJson); - Filter filterItem = new Filter { ID = (int)hb_filter_ids.HB_FILTER_DEINTERLACE, Settings = settings }; + Filter filterItem = new Filter { ID = (int)hb_filter_ids.HB_FILTER_DEINTERLACE, Settings = root }; filter.FilterList.Add(filterItem); } // Decomb if (job.DeinterlaceFilter == DeinterlaceFilter.Decomb) { - IntPtr settingsPtr = HBFunctions.hb_generate_filter_settings((int)hb_filter_ids.HB_FILTER_DECOMB, EnumHelper<Decomb>.GetShortName(job.Decomb), job.CustomDecomb); - string settings = Marshal.PtrToStringAnsi(settingsPtr); + IntPtr settingsPtr = HBFunctions.hb_generate_filter_settings_json((int)hb_filter_ids.HB_FILTER_DECOMB, EnumHelper<Decomb>.GetShortName(job.Decomb), null, job.CustomDecomb); + string unparsedJson = Marshal.PtrToStringAnsi(settingsPtr); + JToken settings = JObject.Parse(unparsedJson); Filter filterItem = new Filter { ID = (int)hb_filter_ids.HB_FILTER_DECOMB, Settings = settings }; filter.FilterList.Add(filterItem); @@ -434,16 +442,9 @@ namespace HandBrakeWPF.Services.Encode.Factories ? hb_filter_ids.HB_FILTER_HQDN3D : hb_filter_ids.HB_FILTER_NLMEANS; - string settings; - if (!string.IsNullOrEmpty(job.CustomDenoise)) - { - settings = job.CustomDenoise; - } - else - { - IntPtr settingsPtr = HBFunctions.hb_generate_filter_settings((int)id, job.DenoisePreset.ToString().ToLower().Replace(" ", string.Empty), job.DenoiseTune.ToString().ToLower().Replace(" ", string.Empty)); - settings = Marshal.PtrToStringAnsi(settingsPtr); - } + IntPtr settingsPtr = HBFunctions.hb_generate_filter_settings_json((int)id, job.DenoisePreset.ToString().ToLower().Replace(" ", string.Empty), job.DenoiseTune.ToString().ToLower().Replace(" ", string.Empty), job.CustomDenoise); + string unparsedJson = Marshal.PtrToStringAnsi(settingsPtr); + JToken settings = JObject.Parse(unparsedJson); Filter filterItem = new Filter { ID = (int)id, Settings = settings }; filter.FilterList.Add(filterItem); @@ -452,23 +453,24 @@ namespace HandBrakeWPF.Services.Encode.Factories // Deblock if (job.Deblock >= 5) { - Filter filterItem = new Filter { ID = (int)hb_filter_ids.HB_FILTER_DEBLOCK, Settings = job.Deblock.ToString() }; + IntPtr settingsPtr = HBFunctions.hb_generate_filter_settings_json((int)hb_filter_ids.HB_FILTER_DEBLOCK, null, null, string.Format("qp={0}", job.Deblock)); + string unparsedJson = Marshal.PtrToStringAnsi(settingsPtr); + JToken settings = JObject.Parse(unparsedJson); + + Filter filterItem = new Filter { ID = (int)hb_filter_ids.HB_FILTER_DEBLOCK, Settings = settings }; filter.FilterList.Add(filterItem); } // CropScale Filter + string cropSettings = string.Format("width={0}:height={1}:crop-top={2}:crop-bottom={3}:crop-left={4}:crop-right={5}", job.Width, job.Height, job.Cropping.Top, job.Cropping.Bottom, job.Cropping.Left, job.Cropping.Right); + IntPtr cropSettingsPtr = HBFunctions.hb_generate_filter_settings_json((int)hb_filter_ids.HB_FILTER_CROP_SCALE, null, null, cropSettings); + string unparsedCropSettingsJson = Marshal.PtrToStringAnsi(cropSettingsPtr); + JToken cropSettingsJson = JObject.Parse(unparsedCropSettingsJson); + Filter cropScale = new Filter { ID = (int)hb_filter_ids.HB_FILTER_CROP_SCALE, - Settings = - string.Format( - "{0}:{1}:{2}:{3}:{4}:{5}", - job.Width, - job.Height, - job.Cropping.Top, - job.Cropping.Bottom, - job.Cropping.Left, - job.Cropping.Right) + Settings = cropSettingsJson }; filter.FilterList.Add(cropScale); @@ -482,8 +484,11 @@ namespace HandBrakeWPF.Services.Encode.Factories // Rotate if (job.Rotation != 0 || job.FlipVideo) { - IntPtr settingsPtr = HBFunctions.hb_generate_filter_settings((int)hb_filter_ids.HB_FILTER_ROTATE, string.Format("{0}:{1}", job.Rotation, job.FlipVideo ? "1" : "0"), string.Empty); - string settings = Marshal.PtrToStringAnsi(settingsPtr); + string rotateSettings = string.Format("angle={0}:hflip={1}", job.Rotation, job.FlipVideo ? "1" : "0"); + IntPtr settingsPtr = HBFunctions.hb_generate_filter_settings_json((int)hb_filter_ids.HB_FILTER_ROTATE, null, null, rotateSettings); + string unparsedJson = Marshal.PtrToStringAnsi(settingsPtr); + JToken settings = JObject.Parse(unparsedJson); + Filter filterItem = new Filter { ID = (int)hb_filter_ids.HB_FILTER_ROTATE, Settings = settings }; filter.FilterList.Add(filterItem); } @@ -503,8 +508,12 @@ namespace HandBrakeWPF.Services.Encode.Factories } } - string framerateString = num.HasValue ? string.Format("{0}:{1}:{2}", fm, num, den) : string.Format("{0}", fm); // filter_cfr, filter_vrate.num, filter_vrate.den - Filter framerateShaper = new Filter { ID = (int)hb_filter_ids.HB_FILTER_VFR, Settings = framerateString }; + string framerateString = num.HasValue ? string.Format("mode={0}:rate={1}/{2}", fm, num, den) : string.Format("{0}", fm); // filter_cfr, filter_vrate.num, filter_vrate.den + IntPtr framerateSettingsPtr = HBFunctions.hb_generate_filter_settings_json((int)hb_filter_ids.HB_FILTER_VFR, null, null, framerateString); + string unparsedFramerateJson = Marshal.PtrToStringAnsi(framerateSettingsPtr); + JToken framerateSettings = JObject.Parse(unparsedFramerateJson); + + Filter framerateShaper = new Filter { ID = (int)hb_filter_ids.HB_FILTER_VFR, Settings = framerateSettings }; filter.FilterList.Add(framerateShaper); return filter; |