From fe53ec37cbb0da69f4ef0b924303378397d49fc6 Mon Sep 17 00:00:00 2001 From: sr55 Date: Fri, 26 Jun 2015 20:14:25 +0000 Subject: WinGui: Completely replace the plist preset import code with the functionality built into libhb. This now allows the new json preset format to be imported, as well as the legacy plist format. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@7318 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- .../HandBrake.ApplicationServices.csproj | 2 +- .../Interop/HandBrakePresetService.cs | 22 ++ .../Interop/HbLib/HbFunctions.cs | 6 +- .../Json/Presets/PresetTransportContainer.cs | 41 ++++ .../Services/Encode/Factories/EncodeFactory.cs | 4 +- .../Utilities/Converters.cs | 231 --------------------- 6 files changed, 69 insertions(+), 237 deletions(-) create mode 100644 win/CS/HandBrake.ApplicationServices/Interop/Json/Presets/PresetTransportContainer.cs delete mode 100644 win/CS/HandBrake.ApplicationServices/Utilities/Converters.cs (limited to 'win/CS/HandBrake.ApplicationServices') diff --git a/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj b/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj index 524729f20..1a080047f 100644 --- a/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj +++ b/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj @@ -114,6 +114,7 @@ + @@ -193,7 +194,6 @@ - diff --git a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakePresetService.cs b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakePresetService.cs index e2610905d..8d4f34e9e 100644 --- a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakePresetService.cs +++ b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakePresetService.cs @@ -14,6 +14,7 @@ namespace HandBrake.ApplicationServices.Interop using System.Runtime.InteropServices; using HandBrake.ApplicationServices.Interop.HbLib; + using HandBrake.ApplicationServices.Interop.Helpers; using HandBrake.ApplicationServices.Interop.Json.Presets; using HandBrake.ApplicationServices.Services.Logging; using HandBrake.ApplicationServices.Services.Logging.Model; @@ -43,5 +44,26 @@ namespace HandBrake.ApplicationServices.Interop return presetList; } + + /// + /// The get preset from file. + /// + /// + /// The filename. + /// + /// + /// The . + /// + public static PresetTransportContainer GetPresetFromFile(string filename) + { + IntPtr presetStringPointer = HBFunctions.hb_presets_read_file_json(InteropUtilities.ToUtf8PtrFromString(filename)); + string presetJson = Marshal.PtrToStringAnsi(presetStringPointer); + + LogHelper.LogMessage(new LogMessage(presetJson, LogMessageType.libhb, LogLevel.debug)); + + PresetTransportContainer preset = JsonConvert.DeserializeObject(presetJson); + + return preset; + } } } diff --git a/win/CS/HandBrake.ApplicationServices/Interop/HbLib/HbFunctions.cs b/win/CS/HandBrake.ApplicationServices/Interop/HbLib/HbFunctions.cs index 1b68df438..d8d8289f1 100644 --- a/win/CS/HandBrake.ApplicationServices/Interop/HbLib/HbFunctions.cs +++ b/win/CS/HandBrake.ApplicationServices/Interop/HbLib/HbFunctions.cs @@ -440,8 +440,8 @@ namespace HandBrake.ApplicationServices.Interop.HbLib [DllImport("hb.dll", EntryPoint = "hb_presets_builtin_get_json", CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr hb_presets_builtin_get_json(); - // hb_value_t * hb_plist_parse_file(const char *filename); - [DllImport("hb.dll", EntryPoint = "hb_plist_parse_file", CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr hb_plist_parse_file(IntPtr filename); + // char * hb_presets_read_file_json(const char *filename); + [DllImport("hb.dll", EntryPoint = "hb_presets_read_file_json", CallingConvention = CallingConvention.Cdecl)] + public static extern IntPtr hb_presets_read_file_json(IntPtr filename); } } diff --git a/win/CS/HandBrake.ApplicationServices/Interop/Json/Presets/PresetTransportContainer.cs b/win/CS/HandBrake.ApplicationServices/Interop/Json/Presets/PresetTransportContainer.cs new file mode 100644 index 000000000..8f1dd9e78 --- /dev/null +++ b/win/CS/HandBrake.ApplicationServices/Interop/Json/Presets/PresetTransportContainer.cs @@ -0,0 +1,41 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// The preset transport container. +// This is a model for importing the JSON / Plist presets into the GUI. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrake.ApplicationServices.Interop.Json.Presets +{ + using System.Collections.Generic; + + /// + /// The preset transport container. + /// This is a model for importing the JSON / Plist presets into the GUI. + /// + public class PresetTransportContainer + { + /// + /// Gets or sets the children array. + /// + public List PresetList { get; set; } + + /// + /// Gets or sets the version major. + /// + public string VersionMajor { get; set; } + + /// + /// Gets or sets the version micro. + /// + public string VersionMicro { get; set; } + + /// + /// Gets or sets the version minor. + /// + public string VersionMinor { get; set; } + } +} diff --git a/win/CS/HandBrake.ApplicationServices/Services/Encode/Factories/EncodeFactory.cs b/win/CS/HandBrake.ApplicationServices/Services/Encode/Factories/EncodeFactory.cs index e133492ff..8d93668bf 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/Encode/Factories/EncodeFactory.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/Encode/Factories/EncodeFactory.cs @@ -263,7 +263,7 @@ namespace HandBrake.ApplicationServices.Services.Encode.Factories { Video video = new Video(); - HBVideoEncoder videoEncoder = HandBrakeEncoderHelpers.VideoEncoders.FirstOrDefault(e => e.ShortName == ApplicationServices.Utilities.Converters.GetVideoEncoder(job.VideoEncoder)); + HBVideoEncoder videoEncoder = HandBrakeEncoderHelpers.VideoEncoders.FirstOrDefault(e => e.ShortName == EnumHelper.GetShortName(job.VideoEncoder)); Validate.NotNull(videoEncoder, "Video encoder " + job.VideoEncoder + " not recognized."); if (videoEncoder != null) { @@ -336,7 +336,7 @@ namespace HandBrake.ApplicationServices.Services.Encode.Factories audio.AudioList = new List(); foreach (AudioTrack item in job.AudioTracks) { - HBAudioEncoder encoder = HandBrakeEncoderHelpers.GetAudioEncoder(ApplicationServices.Utilities.Converters.GetCliAudioEncoder(item.Encoder)); + HBAudioEncoder encoder = HandBrakeEncoderHelpers.GetAudioEncoder(EnumHelper.GetShortName(item.Encoder)); Validate.NotNull(encoder, "Unrecognized audio encoder:" + item.Encoder); HBMixdown mixdown = HandBrakeEncoderHelpers.GetMixdown(EnumHelper.GetShortName(item.MixDown)); diff --git a/win/CS/HandBrake.ApplicationServices/Utilities/Converters.cs b/win/CS/HandBrake.ApplicationServices/Utilities/Converters.cs deleted file mode 100644 index dd38fb286..000000000 --- a/win/CS/HandBrake.ApplicationServices/Utilities/Converters.cs +++ /dev/null @@ -1,231 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. -// -// -// A class to convert various things to native C# objects -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace HandBrake.ApplicationServices.Utilities -{ - using System; - - using HandBrake.ApplicationServices.Interop.Model.Encoding; - using HandBrake.ApplicationServices.Services.Encode.Model.Models; - - /// - /// A class to convert various things to native C# objects - /// - public class Converters - { - /** - * TODO: - * - Many of these converters can be ditched at a later point. Should be able to model all this within the enums themsevles. - * - **/ - - #region Audio - - /// - /// Get the GUI equiv to a CLI mixdown - /// - /// - /// The Audio Mixdown - /// - /// - /// The GUI representation of the mixdown - /// - [Obsolete("Use EnumHelper instead")] - public static Mixdown GetAudioMixDown(string mixdown) - { - switch (mixdown.Trim()) - { - case "Mono": - return Mixdown.Mono; - case "Stereo": - return Mixdown.Stereo; - case "Dolby Surround": - return Mixdown.DolbySurround; - case "Dolby Pro Logic II": - return Mixdown.DolbyProLogicII; - case "5.1 Channels": - return Mixdown.FivePoint1Channels; - case "6.1 Channels": - return Mixdown.SixPoint1Channels; - case "7.1 Channels": - return Mixdown.SevenPoint1Channels; - case "7.1 (5F/2R/LFE)": - return Mixdown.Five_2_LFE; - case "None": - case "Passthru": - return Mixdown.None; - default: - return Mixdown.Auto; - } - } - - /// - /// Get the GUI equiv to a GUI audio encoder string - /// - /// - /// The Audio Encoder - /// - /// - /// The GUI representation of that audio encoder - /// - [Obsolete("Use EnumHelper instead")] - public static AudioEncoder GetAudioEncoder(string audioEnc) - { - switch (audioEnc) - { - case "AAC (faac)": - case "AAC (ffmpeg)": - case "AAC (avcodec)": - return AudioEncoder.ffaac; - case "AAC (FDK)": - case "AAC (CoreAudio)": - return AudioEncoder.fdkaac; - case "HE-AAC (FDK)": - case "HE-AAC (CoreAudio)": - case "HE-AAC": - return AudioEncoder.fdkheaac; - case "MP3 (lame)": - case "MP3": - return AudioEncoder.Lame; - case "Vorbis (vorbis)": - case "Vorbis": - return AudioEncoder.Vorbis; - case "AC3 (ffmpeg)": - case "AC3": - return AudioEncoder.Ac3; - case "AC3 Passthru": - return AudioEncoder.Ac3Passthrough; - case "DTS Passthru": - return AudioEncoder.DtsPassthrough; - case "DTS-HD Passthru": - return AudioEncoder.DtsHDPassthrough; - case "AAC Passthru": - return AudioEncoder.AacPassthru; - case "MP3 Passthru": - return AudioEncoder.Mp3Passthru; - case "FLAC (ffmpeg)": - case "FLAC 16-bit": - return AudioEncoder.ffflac; - case "FLAC (24-bit)": - case "FLAC 24-bit": - return AudioEncoder.ffflac24; - case "TrueHD Passthru": - return AudioEncoder.TrueHDPassthrough; - case "E-AC3 Passthru": - return AudioEncoder.EAc3Passthrough; - case "FLAC Passthru": - return AudioEncoder.FlacPassthru; - case "Auto Passthru": - return AudioEncoder.Passthrough; - default: - return AudioEncoder.ffaac; - } - } - - /// - /// Get the CLI Audio Encoder name - /// - /// - /// String The GUI Encode name - /// - /// - /// String CLI encoder name - /// - public static string GetCliAudioEncoder(AudioEncoder selectedEncoder) - { - return EnumHelper.GetShortName(selectedEncoder); - } - - #endregion - - #region Video - - /// - /// Get the Video Encoder for a given string - /// - /// - /// The encoder name - /// - /// - /// VideoEncoder enum object - /// - public static string GetVideoEncoder(VideoEncoder encoder) - { - switch (encoder) - { - case VideoEncoder.FFMpeg: - return "mpeg4"; - case VideoEncoder.FFMpeg2: - return "mpeg2"; - case VideoEncoder.X264: - return "x264"; - case VideoEncoder.QuickSync: - return "qsv_h264"; - case VideoEncoder.Theora: - return "theora"; - case VideoEncoder.X265: - return "x265"; - case VideoEncoder.VP8: - return "VP8"; - default: - return "x264"; - } - } - - #endregion - - #region File Format - - /// - /// Get the OutputFormat Enum for a given string - /// - /// - /// OutputFormat as a string - /// - /// - /// An OutputFormat Enum - /// - public static OutputFormat GetFileFormat(string format) - { - switch (format.ToLower()) - { - default: - return OutputFormat.Mp4; - case "m4v": - return OutputFormat.Mp4; - case "mkv": - return OutputFormat.Mkv; - } - } - - /// - /// Get the OutputFormat Enum for a given string - /// - /// - /// OutputFormat as a string - /// - /// - /// An OutputFormat Enum - /// - public static string GetFileFormat(OutputFormat format) - { - switch (format) - { - default: - return "mp4"; - case OutputFormat.Mp4: - return "m4v"; - case OutputFormat.Mkv: - return "mkv"; - } - } - - #endregion - } -} -- cgit v1.2.3