diff options
author | sr55 <[email protected]> | 2019-09-22 17:09:04 +0100 |
---|---|---|
committer | sr55 <[email protected]> | 2019-09-22 17:09:21 +0100 |
commit | 9552988c29ec0fff026528bb6501635783f5c22f (patch) | |
tree | 5c2eefeae4bd6fc5d04ff029b566a8ebbcee7cbc /win/CS/HandBrakeWPF/Services | |
parent | 63c732376f959699e0d199232dae8a08846f3595 (diff) |
WinGui:
- Add a non-static wrapper around HbFunctions.cs
- Add a Wrapper Provider that for now, returns only a direct in-process wrapper instance for libhb HbFunctions calls.
- Update all calls to use the new non-static wrapper provider / interface
Diffstat (limited to 'win/CS/HandBrakeWPF/Services')
5 files changed, 50 insertions, 20 deletions
diff --git a/win/CS/HandBrakeWPF/Services/Encode/Factories/EncodeTaskFactory.cs b/win/CS/HandBrakeWPF/Services/Encode/Factories/EncodeTaskFactory.cs index f5de098ac..003f13f17 100644 --- a/win/CS/HandBrakeWPF/Services/Encode/Factories/EncodeTaskFactory.cs +++ b/win/CS/HandBrakeWPF/Services/Encode/Factories/EncodeTaskFactory.cs @@ -17,6 +17,7 @@ namespace HandBrakeWPF.Services.Encode.Factories 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; @@ -45,6 +46,9 @@ namespace HandBrakeWPF.Services.Encode.Factories /// </summary> internal class EncodeTaskFactory { + // TODO make this non-static + private static IHbFunctions hbFunctions; + /// <summary> /// The create. /// </summary> @@ -54,11 +58,16 @@ namespace HandBrakeWPF.Services.Encode.Factories /// <param name="configuration"> /// The configuration. /// </param> + /// <param name="hbFunctionsWrapper"> + /// An instance of IHbFunctions + /// </param> /// <returns> /// The <see cref="JsonEncodeObject"/>. /// </returns> - internal static JsonEncodeObject Create(EncodeTask job, HBConfiguration configuration) + internal static JsonEncodeObject Create(EncodeTask job, HBConfiguration configuration, IHbFunctions hbFunctionsWrapper) { + hbFunctions = hbFunctionsWrapper; + JsonEncodeObject encode = new JsonEncodeObject { SequenceID = 0, @@ -407,7 +416,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); + IntPtr settingsPtr = hbFunctions.hb_generate_filter_settings_json((int)hb_filter_ids.HB_FILTER_DETELECINE, null, null, job.CustomDetelecine); string unparsedJson = Marshal.PtrToStringAnsi(settingsPtr); if (!string.IsNullOrEmpty(unparsedJson)) { @@ -421,7 +430,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); + 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); if (!string.IsNullOrEmpty(unparsedJson)) { @@ -435,7 +444,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); + 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); if (!string.IsNullOrEmpty(unparsedJson)) { @@ -450,7 +459,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); + 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); if (!string.IsNullOrEmpty(unparsedJson)) { @@ -473,7 +482,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); + 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); if (!string.IsNullOrEmpty(unparsedJson)) @@ -492,7 +501,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); + IntPtr settingsPtr = hbFunctions.hb_generate_filter_settings_json((int)id, job.SharpenPreset.Key, job.SharpenTune.Key, job.SharpenCustom); string unparsedJson = Marshal.PtrToStringAnsi(settingsPtr); if (!string.IsNullOrEmpty(unparsedJson)) @@ -507,7 +516,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); + 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); if (!string.IsNullOrEmpty(unparsedJson)) { @@ -520,7 +529,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); + IntPtr cropSettingsPtr = hbFunctions.hb_generate_filter_settings_json((int)hb_filter_ids.HB_FILTER_CROP_SCALE, null, null, cropSettings); string unparsedCropSettingsJson = Marshal.PtrToStringAnsi(cropSettingsPtr); if (!string.IsNullOrEmpty(unparsedCropSettingsJson)) { @@ -545,7 +554,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); + IntPtr settingsPtr = hbFunctions.hb_generate_filter_settings_json((int)hb_filter_ids.HB_FILTER_ROTATE, null, null, rotateSettings); string unparsedJson = Marshal.PtrToStringAnsi(settingsPtr); if (!string.IsNullOrEmpty(unparsedJson)) { @@ -562,7 +571,7 @@ namespace HandBrakeWPF.Services.Encode.Factories 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 = hbFunctions.hb_video_framerate_get_from_name(frameratePrt); if (vrate > 0) { @@ -572,7 +581,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); + IntPtr framerateSettingsPtr = hbFunctions.hb_generate_filter_settings_json((int)hb_filter_ids.HB_FILTER_VFR, null, null, framerateString); string unparsedFramerateJson = Marshal.PtrToStringAnsi(framerateSettingsPtr); if (!string.IsNullOrEmpty(unparsedFramerateJson)) { diff --git a/win/CS/HandBrakeWPF/Services/Encode/Factories/QueueFactory.cs b/win/CS/HandBrakeWPF/Services/Encode/Factories/QueueFactory.cs index bb7f9ac62..b17385b47 100644 --- a/win/CS/HandBrakeWPF/Services/Encode/Factories/QueueFactory.cs +++ b/win/CS/HandBrakeWPF/Services/Encode/Factories/QueueFactory.cs @@ -11,10 +11,15 @@ namespace HandBrakeWPF.Services.Encode.Factories { using System.Collections.Generic; + using Caliburn.Micro; + + using HandBrake.Interop.Interop.HbLib.Wrappers.Interfaces; using HandBrake.Interop.Interop.Json.Queue; + using HandBrake.Interop.Interop.Providers.Interfaces; using HandBrake.Interop.Model; using HandBrakeWPF.Services.Encode.Model; + using HandBrakeWPF.Services.Interfaces; using Newtonsoft.Json; @@ -42,10 +47,13 @@ namespace HandBrakeWPF.Services.Encode.Factories NullValueHandling = NullValueHandling.Ignore, }; + IHbFunctionsProvider provider = IoC.Get<IHbFunctionsProvider>(); // TODO remove IoC call. + IHbFunctions hbFunctions = provider.GetHbFunctionsWrapper(); + List<Task> queueJobs = new List<Task>(); foreach (var item in tasks) { - Task task = new Task { Job = EncodeTaskFactory.Create(item, configuration) }; + Task task = new Task { Job = EncodeTaskFactory.Create(item, configuration, hbFunctions) }; queueJobs.Add(task); } diff --git a/win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs b/win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs index 188e6bb35..5c147aa4e 100644 --- a/win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs +++ b/win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs @@ -16,11 +16,13 @@ namespace HandBrakeWPF.Services.Encode using HandBrake.Interop.Interop.EventArgs; using HandBrake.Interop.Interop.Interfaces; using HandBrake.Interop.Interop.Json.State; + using HandBrake.Interop.Interop.Providers.Interfaces; using HandBrake.Interop.Model; using HandBrakeWPF.Exceptions; using HandBrakeWPF.Properties; using HandBrakeWPF.Services.Encode.Factories; + using HandBrakeWPF.Services.Interfaces; using EncodeTask = Model.EncodeTask; using HandBrakeInstanceManager = Instance.HandBrakeInstanceManager; @@ -38,6 +40,7 @@ namespace HandBrakeWPF.Services.Encode #region Private Variables private ILog log = LogService.GetLogger(); + private readonly IHbFunctionsProvider hbFunctionsProvider; private IEncodeInstance instance; private DateTime startTime; private EncodeTask currentTask; @@ -46,6 +49,11 @@ namespace HandBrakeWPF.Services.Encode #endregion + public LibEncode(IHbFunctionsProvider hbFunctionsProvider) + { + this.hbFunctionsProvider = hbFunctionsProvider; + } + /// <summary> /// Gets a value indicating whether is pasued. /// </summary> @@ -113,7 +121,7 @@ namespace HandBrakeWPF.Services.Encode this.VerifyEncodeDestinationPath(task); // Get an EncodeJob object for the Interop Library - this.instance.StartEncode(EncodeTaskFactory.Create(task, configuration)); + this.instance.StartEncode(EncodeTaskFactory.Create(task, configuration, hbFunctionsProvider.GetHbFunctionsWrapper())); // Fire the Encode Started Event this.InvokeEncodeStarted(System.EventArgs.Empty); diff --git a/win/CS/HandBrakeWPF/Services/PowerService.cs b/win/CS/HandBrakeWPF/Services/PowerService.cs index 9239a2cd2..e73027f57 100644 --- a/win/CS/HandBrakeWPF/Services/PowerService.cs +++ b/win/CS/HandBrakeWPF/Services/PowerService.cs @@ -3,11 +3,10 @@ // This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. // </copyright> // <summary> -// The Error Service +// The Power Service // </summary> // -------------------------------------------------------------------------------------------------------------------- - namespace HandBrakeWPF.Services { using System; @@ -17,7 +16,6 @@ namespace HandBrakeWPF.Services { private void GetPowerState() { - System.Management.ObjectQuery query = new ObjectQuery("Select * FROM Win32_Battery"); ManagementObjectSearcher searcher = new ManagementObjectSearcher(query); @@ -30,7 +28,6 @@ namespace HandBrakeWPF.Services Console.WriteLine("Property {0}: Value is {1}", property.Name, property.Value); } } - } } } diff --git a/win/CS/HandBrakeWPF/Services/Scan/Factories/TitleFactory.cs b/win/CS/HandBrakeWPF/Services/Scan/Factories/TitleFactory.cs index dc787b5c9..9b96771aa 100644 --- a/win/CS/HandBrakeWPF/Services/Scan/Factories/TitleFactory.cs +++ b/win/CS/HandBrakeWPF/Services/Scan/Factories/TitleFactory.cs @@ -11,11 +11,16 @@ namespace HandBrakeWPF.Services.Scan.Factories { using System; + using Caliburn.Micro; + using HandBrake.Interop.Interop.HbLib; + using HandBrake.Interop.Interop.HbLib.Wrappers.Interfaces; using HandBrake.Interop.Interop.Json.Scan; using HandBrake.Interop.Interop.Model; + using HandBrake.Interop.Interop.Providers.Interfaces; using HandBrakeWPF.Services.Encode.Model.Models; + using HandBrakeWPF.Services.Interfaces; using HandBrakeWPF.Services.Scan.Model; public class TitleFactory @@ -93,8 +98,11 @@ namespace HandBrakeWPF.Services.Scan.Factories break; } - bool canBurn = HBFunctions.hb_subtitle_can_burn(track.Source) > 0; - bool canSetForcedOnly = HBFunctions.hb_subtitle_can_force(track.Source) > 0; + IHbFunctionsProvider provider = IoC.Get<IHbFunctionsProvider>(); // TODO remove IoC call + IHbFunctions hbFunctions = provider.GetHbFunctionsWrapper(); + + bool canBurn = hbFunctions.hb_subtitle_can_burn(track.Source) > 0; + bool canSetForcedOnly = hbFunctions.hb_subtitle_can_force(track.Source) > 0; converted.Subtitles.Add(new Subtitle(track.Source, currentSubtitleTrack, track.Language, track.LanguageCode, convertedType, canBurn, canSetForcedOnly, track.Name)); currentSubtitleTrack++; |