diff options
Diffstat (limited to 'win/CS/HandBrakeWPF/Services/Encode/Factories/EncodeTaskFactory.cs')
-rw-r--r-- | win/CS/HandBrakeWPF/Services/Encode/Factories/EncodeTaskFactory.cs | 44 |
1 files changed, 13 insertions, 31 deletions
diff --git a/win/CS/HandBrakeWPF/Services/Encode/Factories/EncodeTaskFactory.cs b/win/CS/HandBrakeWPF/Services/Encode/Factories/EncodeTaskFactory.cs index 6621d3f82..ee4928bc9 100644 --- a/win/CS/HandBrakeWPF/Services/Encode/Factories/EncodeTaskFactory.cs +++ b/win/CS/HandBrakeWPF/Services/Encode/Factories/EncodeTaskFactory.cs @@ -9,15 +9,12 @@ namespace HandBrakeWPF.Services.Encode.Factories { - using System; using System.Collections.Generic; using System.Globalization; using System.Linq; - using System.Runtime.InteropServices; using HandBrake.Interop.Interop; using HandBrake.Interop.Interop.HbLib; - using HandBrake.Interop.Interop.HbLib.Wrappers.Interfaces; using HandBrake.Interop.Interop.Json.Encode; using HandBrake.Interop.Interop.Json.Shared; using HandBrake.Interop.Interop.Model.Encoding; @@ -49,13 +46,10 @@ namespace HandBrakeWPF.Services.Encode.Factories internal class EncodeTaskFactory { private readonly IUserSettingService userSettingService; - private IHbFunctions hbFunctions; - public EncodeTaskFactory(IUserSettingService userSettingService, IHbFunctions hbFunctionsWrapper) + public EncodeTaskFactory(IUserSettingService userSettingService) { this.userSettingService = userSettingService; - - this.hbFunctions = hbFunctionsWrapper; } internal JsonEncodeObject Create(EncodeTask job, HBConfiguration configuration) @@ -354,8 +348,7 @@ namespace HandBrakeWPF.Services.Encode.Factories // Detelecine if (job.Detelecine != Detelecine.Off) { - IntPtr settingsPtr = hbFunctions.hb_generate_filter_settings_json((int)hb_filter_ids.HB_FILTER_DETELECINE, null, null, job.CustomDetelecine); - string unparsedJson = Marshal.PtrToStringAnsi(settingsPtr); + string unparsedJson = HandBrakeFilterHelpers.GenerateFilterSettingJson((int)hb_filter_ids.HB_FILTER_DETELECINE, null, null, job.CustomDetelecine); if (!string.IsNullOrEmpty(unparsedJson)) { JToken settings = JObject.Parse(unparsedJson); @@ -368,8 +361,7 @@ namespace HandBrakeWPF.Services.Encode.Factories // Deinterlace if (job.DeinterlaceFilter == DeinterlaceFilter.Yadif) { - IntPtr settingsPtr = hbFunctions.hb_generate_filter_settings_json((int)hb_filter_ids.HB_FILTER_DEINTERLACE, job.DeinterlacePreset?.ShortName, null, job.CustomDeinterlaceSettings); - string unparsedJson = Marshal.PtrToStringAnsi(settingsPtr); + string unparsedJson = HandBrakeFilterHelpers.GenerateFilterSettingJson((int)hb_filter_ids.HB_FILTER_DEINTERLACE, job.DeinterlacePreset?.ShortName, null, job.CustomDeinterlaceSettings); if (!string.IsNullOrEmpty(unparsedJson)) { JToken root = JObject.Parse(unparsedJson); @@ -382,8 +374,7 @@ namespace HandBrakeWPF.Services.Encode.Factories // Decomb if (job.DeinterlaceFilter == DeinterlaceFilter.Decomb) { - IntPtr settingsPtr = hbFunctions.hb_generate_filter_settings_json((int)hb_filter_ids.HB_FILTER_DECOMB, job.DeinterlacePreset?.ShortName, null, job.CustomDeinterlaceSettings); - string unparsedJson = Marshal.PtrToStringAnsi(settingsPtr); + string unparsedJson = HandBrakeFilterHelpers.GenerateFilterSettingJson((int)hb_filter_ids.HB_FILTER_DECOMB, job.DeinterlacePreset?.ShortName, null, job.CustomDeinterlaceSettings); if (!string.IsNullOrEmpty(unparsedJson)) { JToken settings = JObject.Parse(unparsedJson); @@ -397,8 +388,7 @@ namespace HandBrakeWPF.Services.Encode.Factories { if (job.CombDetect != CombDetect.Off) { - IntPtr settingsPtr = hbFunctions.hb_generate_filter_settings_json((int)hb_filter_ids.HB_FILTER_COMB_DETECT, EnumHelper<CombDetect>.GetShortName(job.CombDetect), null, job.CustomCombDetect); - string unparsedJson = Marshal.PtrToStringAnsi(settingsPtr); + string unparsedJson = HandBrakeFilterHelpers.GenerateFilterSettingJson((int)hb_filter_ids.HB_FILTER_COMB_DETECT, EnumHelper<CombDetect>.GetShortName(job.CombDetect), null, job.CustomCombDetect); if (!string.IsNullOrEmpty(unparsedJson)) { JToken settings = JObject.Parse(unparsedJson); @@ -420,8 +410,7 @@ namespace HandBrakeWPF.Services.Encode.Factories ? hb_filter_ids.HB_FILTER_HQDN3D : hb_filter_ids.HB_FILTER_NLMEANS; - 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); + string unparsedJson = HandBrakeFilterHelpers.GenerateFilterSettingJson((int)id, job.DenoisePreset.ToString().ToLower().Replace(" ", string.Empty), job.DenoiseTune.ToString().ToLower().Replace(" ", string.Empty), job.CustomDenoise); if (!string.IsNullOrEmpty(unparsedJson)) { @@ -439,8 +428,7 @@ namespace HandBrakeWPF.Services.Encode.Factories ? hb_filter_ids.HB_FILTER_LAPSHARP : hb_filter_ids.HB_FILTER_UNSHARP; - IntPtr settingsPtr = hbFunctions.hb_generate_filter_settings_json((int)id, job.SharpenPreset.Key, job.SharpenTune.Key, job.SharpenCustom); - string unparsedJson = Marshal.PtrToStringAnsi(settingsPtr); + string unparsedJson = HandBrakeFilterHelpers.GenerateFilterSettingJson((int)id, job.SharpenPreset.Key, job.SharpenTune.Key, job.SharpenCustom); if (!string.IsNullOrEmpty(unparsedJson)) { @@ -454,8 +442,7 @@ namespace HandBrakeWPF.Services.Encode.Factories // Deblock if (job.DeblockPreset != null && job.DeblockPreset.Key != "off") { - IntPtr settingsPtr = hbFunctions.hb_generate_filter_settings_json((int)hb_filter_ids.HB_FILTER_DEBLOCK, job.DeblockPreset.Key, job.DeblockTune.Key, job.CustomDeblock); - string unparsedJson = Marshal.PtrToStringAnsi(settingsPtr); + string unparsedJson = HandBrakeFilterHelpers.GenerateFilterSettingJson((int)hb_filter_ids.HB_FILTER_DEBLOCK, job.DeblockPreset.Key, job.DeblockTune.Key, job.CustomDeblock); if (!string.IsNullOrEmpty(unparsedJson)) { JToken settings = JObject.Parse(unparsedJson); @@ -467,8 +454,7 @@ namespace HandBrakeWPF.Services.Encode.Factories // 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); + string unparsedCropSettingsJson = HandBrakeFilterHelpers.GenerateFilterSettingJson((int)hb_filter_ids.HB_FILTER_CROP_SCALE, null, null, cropSettings); if (!string.IsNullOrEmpty(unparsedCropSettingsJson)) { JToken cropSettingsJson = JObject.Parse(unparsedCropSettingsJson); @@ -485,8 +471,7 @@ namespace HandBrakeWPF.Services.Encode.Factories if (job.Padding.Enabled) { string padSettings = string.Format("width={0}:height={1}:color={2}:x={3}:y={4}", job.Width, job.Height, job.Padding.Color, job.Padding.X, job.Padding.Y); - IntPtr padSettingsPtr = hbFunctions.hb_generate_filter_settings_json((int)hb_filter_ids.HB_FILTER_PAD, null, null, padSettings); - string unparsedPadSettingsJson = Marshal.PtrToStringAnsi(padSettingsPtr); + string unparsedPadSettingsJson = HandBrakeFilterHelpers.GenerateFilterSettingJson((int)hb_filter_ids.HB_FILTER_PAD, null, null, padSettings); if (!string.IsNullOrEmpty(unparsedPadSettingsJson)) { JToken PadSettingsJson = JObject.Parse(unparsedPadSettingsJson); @@ -511,8 +496,7 @@ namespace HandBrakeWPF.Services.Encode.Factories if (job.Rotation != 0 || job.FlipVideo) { 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); + string unparsedJson = HandBrakeFilterHelpers.GenerateFilterSettingJson((int)hb_filter_ids.HB_FILTER_ROTATE, null, null, rotateSettings); if (!string.IsNullOrEmpty(unparsedJson)) { JToken settings = JObject.Parse(unparsedJson); @@ -527,8 +511,7 @@ namespace HandBrakeWPF.Services.Encode.Factories int? num = null, den = null; if (job.Framerate != null) { - IntPtr frameratePrt = Marshal.StringToHGlobalAnsi(job.Framerate.Value.ToString(CultureInfo.InvariantCulture)); - int vrate = hbFunctions.hb_video_framerate_get_from_name(frameratePrt); + int vrate = HandBrakeUnitConversionHelpers.GetFramerateFromName(job.Framerate.Value.ToString(CultureInfo.InvariantCulture)); if (vrate > 0) { @@ -538,8 +521,7 @@ namespace HandBrakeWPF.Services.Encode.Factories } string framerateString = num.HasValue ? string.Format("mode={0}:rate={1}/{2}", fm, num, den) : string.Format("mode={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); + string unparsedFramerateJson = HandBrakeFilterHelpers.GenerateFilterSettingJson((int)hb_filter_ids.HB_FILTER_VFR, null, null, framerateString); if (!string.IsNullOrEmpty(unparsedFramerateJson)) { JToken framerateSettings = JObject.Parse(unparsedFramerateJson); |