From f2ca02b9220a88a018759932dd9608b2de8a91cf Mon Sep 17 00:00:00 2001 From: sr55 Date: Fri, 21 Feb 2014 22:06:24 +0000 Subject: WinGui: Some tidy up and refactoring in the interop library. Few small internal namespace changes. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6053 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- .../HandBrakeInterop/Converters.cs | 225 -------------- .../HandBrakeInterop/Converters/Converters.cs | 226 ++++++++++++++ .../HandBrakeInterop/HandBrakeInstance.cs | 20 +- .../HandBrakeInterop/HandBrakeInterop.csproj | 14 +- .../HandBrakeInterop/HandBrakeUtils.cs | 12 +- .../HandBrakeInterop/HbLib/hb_audio.cs | 8 +- .../HandBrakeInterop/HbLib/hb_job_s.cs | 4 +- .../HandBrakeInterop/Helpers/InteropUtilities.cs | 249 +++++++++++++++ .../HandBrakeInterop/Helpers/Languages.cs | 51 ++++ .../Helpers/MarshalingConstants.cs | 32 ++ .../HandBrakeInterop/Helpers/NativeList.cs | 125 ++++++++ .../HandBrakeInterop/Helpers/Utilities.cs | 66 ++++ .../HandBrakeInterop/InteropUtilities.cs | 243 --------------- .../HandBrake.Interop/HandBrakeInterop/Language.cs | 48 --- .../HandBrakeInterop/Languages.cs | 54 ---- .../HandBrakeInterop/MarshalingConstants.cs | 32 -- .../HandBrakeInterop/Model/Encoders.cs | 2 + .../HandBrakeInterop/Model/Encoding/Anamorphic.cs | 5 +- .../Model/Encoding/AudioEncodeRateType.cs | 23 +- .../HandBrakeInterop/Model/Encoding/Container.cs | 20 +- .../Model/Encoding/CroppingType.cs | 3 + .../HandBrakeInterop/Model/Encoding/Decomb.cs | 5 +- .../HandBrakeInterop/Model/Encoding/Denoise.cs | 5 +- .../HandBrakeInterop/Model/Encoding/Detelecine.cs | 5 +- .../Model/Encoding/EncodingProfile.cs | 336 +++++++++++++++++---- .../Model/Encoding/HBAudioEncoder.cs | 149 +++++---- .../HandBrakeInterop/Model/Encoding/HBContainer.cs | 47 ++- .../HandBrakeInterop/Model/Encoding/HBMixdown.cs | 58 ++-- .../HandBrakeInterop/Model/Encoding/HBRate.cs | 3 + .../Model/Encoding/HBVideoEncoder.cs | 60 ++-- .../Model/Encoding/OutputExtension.cs | 5 +- .../HandBrakeInterop/Model/Encoding/ScaleMethod.cs | 5 +- .../Model/Encoding/VideoEncodeRateType.cs | 5 +- .../HandBrakeInterop/Model/Language.cs | 48 +++ .../HandBrakeInterop/NativeList.cs | 125 -------- .../HandBrakeInterop/Utilities.cs | 66 ---- 36 files changed, 1365 insertions(+), 1019 deletions(-) delete mode 100644 win/CS/HandBrake.Interop/HandBrakeInterop/Converters.cs create mode 100644 win/CS/HandBrake.Interop/HandBrakeInterop/Converters/Converters.cs create mode 100644 win/CS/HandBrake.Interop/HandBrakeInterop/Helpers/InteropUtilities.cs create mode 100644 win/CS/HandBrake.Interop/HandBrakeInterop/Helpers/Languages.cs create mode 100644 win/CS/HandBrake.Interop/HandBrakeInterop/Helpers/MarshalingConstants.cs create mode 100644 win/CS/HandBrake.Interop/HandBrakeInterop/Helpers/NativeList.cs create mode 100644 win/CS/HandBrake.Interop/HandBrakeInterop/Helpers/Utilities.cs delete mode 100644 win/CS/HandBrake.Interop/HandBrakeInterop/InteropUtilities.cs delete mode 100644 win/CS/HandBrake.Interop/HandBrakeInterop/Language.cs delete mode 100644 win/CS/HandBrake.Interop/HandBrakeInterop/Languages.cs delete mode 100644 win/CS/HandBrake.Interop/HandBrakeInterop/MarshalingConstants.cs create mode 100644 win/CS/HandBrake.Interop/HandBrakeInterop/Model/Language.cs delete mode 100644 win/CS/HandBrake.Interop/HandBrakeInterop/NativeList.cs delete mode 100644 win/CS/HandBrake.Interop/HandBrakeInterop/Utilities.cs (limited to 'win/CS/HandBrake.Interop/HandBrakeInterop') diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Converters.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Converters.cs deleted file mode 100644 index 57c19659a..000000000 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/Converters.cs +++ /dev/null @@ -1,225 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. -// -// -// Defines the Converters type. -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace HandBrake.Interop -{ - using System; - using System.Collections.Generic; - using System.Globalization; - - using HandBrake.Interop.HbLib; - using HandBrake.Interop.Model.Encoding; - using HandBrake.Interop.SourceData; - using HandBrake.Interop.Model; - - /// - /// Converters for various encoding values. - /// - public static class Converters - { - /// - /// Video Frame Rates - /// - private static readonly Dictionary VideoRates; - - /// - /// Initializes static members of the Converters class. - /// - static Converters() - { - HandBrakeUtils.EnsureGlobalInit(); - - VideoRates = new Dictionary(); - foreach (var framerate in Encoders.VideoFramerates) - { - VideoRates.Add(double.Parse(framerate.Name, CultureInfo.InvariantCulture), framerate.Rate); - } - } - - /// - /// Convert Framerate to Video Rates - /// - /// - /// The framerate. - /// - /// - /// The vrate if a valid framerate is passed in. - /// - /// - /// Thrown when framerate is invalid. - /// - public static int FramerateToVrate(double framerate) - { - if (!VideoRates.ContainsKey(framerate)) - { - throw new ArgumentException("Framerate not recognized.", "framerate"); - } - - return VideoRates[framerate]; - } - - /// - /// Convert Native HB Internal Audio int to a AudioCodec model. - /// - /// - /// The codec. - /// - /// - /// An AudioCodec object. - /// - public static AudioCodec NativeToAudioCodec(uint codec) - { - switch (codec) - { - case NativeConstants.HB_ACODEC_AC3: - return AudioCodec.Ac3; - case NativeConstants.HB_ACODEC_DCA: - return AudioCodec.Dts; - case NativeConstants.HB_ACODEC_DCA_HD: - return AudioCodec.DtsHD; - case NativeConstants.HB_ACODEC_LAME: - case NativeConstants.HB_ACODEC_MP3: - return AudioCodec.Mp3; - case NativeConstants.HB_ACODEC_FAAC: - case NativeConstants.HB_ACODEC_FFAAC: - case NativeConstants.HB_ACODEC_CA_AAC: - case NativeConstants.HB_ACODEC_CA_HAAC: - case NativeConstants.HB_ACODEC_FDK_HAAC: // TODO Check this is correct - case NativeConstants.HB_ACODEC_FDK_AAC: // TODO Check this is correct - return AudioCodec.Aac; - case NativeConstants.HB_ACODEC_FFFLAC: - return AudioCodec.Flac; - - default: - return AudioCodec.Other; - } - } - - /// - /// Converts a native HB encoder structure to an Encoder model. - /// - /// The structure to convert. - /// The converted model. - public static HBVideoEncoder NativeToVideoEncoder(hb_encoder_s encoder) - { - return new HBVideoEncoder - { - Id = encoder.codec, - ShortName = encoder.short_name, - DisplayName = encoder.name, - CompatibleContainers = encoder.muxers - }; - } - - /// - /// Converts a native HB encoder structure to an Encoder model. - /// - /// The structure to convert. - /// The converted model. - public static HBAudioEncoder NativeToAudioEncoder(hb_encoder_s encoder) - { - var result = new HBAudioEncoder - { - Id = encoder.codec, - ShortName = encoder.short_name, - DisplayName = encoder.name, - CompatibleContainers = encoder.muxers - }; - - result.QualityLimits = Encoders.GetAudioQualityLimits(encoder.codec); - result.DefaultQuality = HBFunctions.hb_audio_quality_get_default((uint)encoder.codec); - result.CompressionLimits = Encoders.GetAudioCompressionLimits(encoder.codec); - result.DefaultCompression = HBFunctions.hb_audio_compression_get_default((uint)encoder.codec); - - return result; - } - - /// - /// Converts a native HB rate structure to an HBRate object. - /// - /// The structure to convert. - /// The converted rate object. - public static HBRate NativeToRate(hb_rate_s rate) - { - return new HBRate - { - Name = rate.name, - Rate = rate.rate - }; - } - - /// - /// Converts a native HB mixdown structure to a Mixdown model. - /// - /// The structure to convert. - /// The converted model. - public static HBMixdown NativeToMixdown(hb_mixdown_s mixdown) - { - return new HBMixdown - { - Id = mixdown.amixdown, - ShortName = mixdown.short_name, - DisplayName = mixdown.name - }; - } - - /// - /// Converts a native HB container structure into an HBContainer object. - /// - /// The structure to convert. - /// The converted structure. - public static HBContainer NativeToContainer(hb_container_s container) - { - return new HBContainer - { - DisplayName = container.name, - ShortName = container.short_name, - DefaultExtension = container.default_extension, - Id = container.format - }; - } - - /// - /// Converts a native language structure to a Language object. - /// - /// The structure to convert. - /// The converted structure. - public static Language NativeToLanguage(iso639_lang_t language) - { - string englishName = InteropUtilities.ReadUtf8Ptr(language.eng_name); - string nativeName = InteropUtilities.ReadUtf8Ptr(language.native_name); - return new Language - { - Code = language.iso639_2, - EnglishName = englishName, - NativeName = nativeName - }; - } - - /// - /// Converts the PTS amount to a TimeSpan. There may be some accuracy loss here. - /// - /// The PTS to convert. - /// The timespan for it. - public static TimeSpan PtsToTimeSpan(ulong pts) - { - return TimeSpan.FromTicks((long)((pts * 10000000) / 90000)); - } - - /// - /// Converts the PTS amount to seconds. - /// - /// The PTS to convert. - /// The corresponding number of seconds. - public static double PtsToSeconds(ulong pts) - { - return (double)pts / 90000; - } - } -} diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Converters/Converters.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Converters/Converters.cs new file mode 100644 index 000000000..7a45d6334 --- /dev/null +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/Converters/Converters.cs @@ -0,0 +1,226 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// Defines the Converters type. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrake.Interop.Converters +{ + using System; + using System.Collections.Generic; + using System.Globalization; + + using HandBrake.Interop.HbLib; + using HandBrake.Interop.Helpers; + using HandBrake.Interop.Model; + using HandBrake.Interop.Model.Encoding; + using HandBrake.Interop.SourceData; + + /// + /// Converters for various encoding values. + /// + public static class Converters + { + /// + /// Video Frame Rates + /// + private static readonly Dictionary VideoRates; + + /// + /// Initializes static members of the Converters class. + /// + static Converters() + { + HandBrakeUtils.EnsureGlobalInit(); + + VideoRates = new Dictionary(); + foreach (var framerate in Encoders.VideoFramerates) + { + VideoRates.Add(double.Parse(framerate.Name, CultureInfo.InvariantCulture), framerate.Rate); + } + } + + /// + /// Convert Framerate to Video Rates + /// + /// + /// The framerate. + /// + /// + /// The vrate if a valid framerate is passed in. + /// + /// + /// Thrown when framerate is invalid. + /// + public static int FramerateToVrate(double framerate) + { + if (!VideoRates.ContainsKey(framerate)) + { + throw new ArgumentException("Framerate not recognized.", "framerate"); + } + + return VideoRates[framerate]; + } + + /// + /// Convert Native HB Internal Audio int to a AudioCodec model. + /// + /// + /// The codec. + /// + /// + /// An AudioCodec object. + /// + public static AudioCodec NativeToAudioCodec(uint codec) + { + switch (codec) + { + case NativeConstants.HB_ACODEC_AC3: + return AudioCodec.Ac3; + case NativeConstants.HB_ACODEC_DCA: + return AudioCodec.Dts; + case NativeConstants.HB_ACODEC_DCA_HD: + return AudioCodec.DtsHD; + case NativeConstants.HB_ACODEC_LAME: + case NativeConstants.HB_ACODEC_MP3: + return AudioCodec.Mp3; + case NativeConstants.HB_ACODEC_FAAC: + case NativeConstants.HB_ACODEC_FFAAC: + case NativeConstants.HB_ACODEC_CA_AAC: + case NativeConstants.HB_ACODEC_CA_HAAC: + case NativeConstants.HB_ACODEC_FDK_HAAC: // TODO Check this is correct + case NativeConstants.HB_ACODEC_FDK_AAC: // TODO Check this is correct + return AudioCodec.Aac; + case NativeConstants.HB_ACODEC_FFFLAC: + return AudioCodec.Flac; + + default: + return AudioCodec.Other; + } + } + + /// + /// Converts a native HB encoder structure to an Encoder model. + /// + /// The structure to convert. + /// The converted model. + public static HBVideoEncoder NativeToVideoEncoder(hb_encoder_s encoder) + { + return new HBVideoEncoder + { + Id = encoder.codec, + ShortName = encoder.short_name, + DisplayName = encoder.name, + CompatibleContainers = encoder.muxers + }; + } + + /// + /// Converts a native HB encoder structure to an Encoder model. + /// + /// The structure to convert. + /// The converted model. + public static HBAudioEncoder NativeToAudioEncoder(hb_encoder_s encoder) + { + var result = new HBAudioEncoder + { + Id = encoder.codec, + ShortName = encoder.short_name, + DisplayName = encoder.name, + CompatibleContainers = encoder.muxers, + QualityLimits = Encoders.GetAudioQualityLimits(encoder.codec), + DefaultQuality = HBFunctions.hb_audio_quality_get_default((uint)encoder.codec), + CompressionLimits = Encoders.GetAudioCompressionLimits(encoder.codec), + DefaultCompression = + HBFunctions.hb_audio_compression_get_default((uint)encoder.codec) + }; + + return result; + } + + /// + /// Converts a native HB rate structure to an HBRate object. + /// + /// The structure to convert. + /// The converted rate object. + public static HBRate NativeToRate(hb_rate_s rate) + { + return new HBRate + { + Name = rate.name, + Rate = rate.rate + }; + } + + /// + /// Converts a native HB mixdown structure to a Mixdown model. + /// + /// The structure to convert. + /// The converted model. + public static HBMixdown NativeToMixdown(hb_mixdown_s mixdown) + { + return new HBMixdown + { + Id = mixdown.amixdown, + ShortName = mixdown.short_name, + DisplayName = mixdown.name + }; + } + + /// + /// Converts a native HB container structure into an HBContainer object. + /// + /// The structure to convert. + /// The converted structure. + public static HBContainer NativeToContainer(hb_container_s container) + { + return new HBContainer + { + DisplayName = container.name, + ShortName = container.short_name, + DefaultExtension = container.default_extension, + Id = container.format + }; + } + + /// + /// Converts a native language structure to a Language object. + /// + /// The structure to convert. + /// The converted structure. + public static Language NativeToLanguage(iso639_lang_t language) + { + string englishName = InteropUtilities.ReadUtf8Ptr(language.eng_name); + string nativeName = InteropUtilities.ReadUtf8Ptr(language.native_name); + return new Language + { + Code = language.iso639_2, + EnglishName = englishName, + NativeName = nativeName + }; + } + + /// + /// Converts the PTS amount to a TimeSpan. There may be some accuracy loss here. + /// + /// The PTS to convert. + /// The timespan for it. + public static TimeSpan PtsToTimeSpan(ulong pts) + { + return TimeSpan.FromTicks((long)((pts * 10000000) / 90000)); + } + + /// + /// Converts the PTS amount to seconds. + /// + /// The PTS to convert. + /// The corresponding number of seconds. + public static double PtsToSeconds(ulong pts) + { + return (double)pts / 90000; + } + } +} diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs index a9c610bb4..b231d9239 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs @@ -20,6 +20,7 @@ namespace HandBrake.Interop using HandBrake.Interop.EventArgs; using HandBrake.Interop.HbLib; + using HandBrake.Interop.Helpers; using HandBrake.Interop.Interfaces; using HandBrake.Interop.Model; using HandBrake.Interop.Model.Encoding; @@ -1175,7 +1176,7 @@ namespace HandBrake.Interop } nativeJob.vrate = 27000000; - nativeJob.vrate_base = Converters.FramerateToVrate(profile.Framerate); + nativeJob.vrate_base = Converters.Converters.FramerateToVrate(profile.Framerate); } string vfrSettings = string.Format(CultureInfo.InvariantCulture, "{0}:{1}:{2}", nativeJob.cfr, nativeJob.vrate, nativeJob.vrate_base); @@ -1498,17 +1499,6 @@ namespace HandBrake.Interop nativeJob.qsv.decode = profile.QsvDecode ? 1 : 0; nativeJob.use_hwd = job.DxvaDecoding ? 1 : 0; -#pragma warning disable 612, 618 - if (profile.OutputFormat == Container.Mp4) - { - nativeJob.mux = HBFunctions.hb_container_get_from_name("av_mp4"); - } - else if (profile.OutputFormat == Container.Mkv) - { - nativeJob.mux = HBFunctions.hb_container_get_from_name("av_mkv"); - } -#pragma warning restore 612, 618 - if (profile.ContainerName != null) { nativeJob.mux = HBFunctions.hb_container_get_from_name(profile.ContainerName); @@ -1790,7 +1780,7 @@ namespace HandBrake.Interop Playlist = title.playlist, Resolution = new Size(title.width, title.height), ParVal = new Size(title.pixel_aspect_width, title.pixel_aspect_height), - Duration = Converters.PtsToTimeSpan(title.duration), + Duration = Converters.Converters.PtsToTimeSpan(title.duration), DurationPts = title.duration, AutoCropDimensions = new Cropping { @@ -1885,7 +1875,7 @@ namespace HandBrake.Interop var newAudio = new AudioTrack { TrackNumber = currentAudioTrack, - Codec = Converters.NativeToAudioCodec(audio.config.input.codec), + Codec = Converters.Converters.NativeToAudioCodec(audio.config.input.codec), CodecParam = audio.config.input.codec_param, CodecId = audio.config.input.codec, Language = audio.config.lang.simple, @@ -1908,7 +1898,7 @@ namespace HandBrake.Interop { Name = chapter.title, ChapterNumber = chapter.index, - Duration = Converters.PtsToTimeSpan(chapter.duration), + Duration = Converters.Converters.PtsToTimeSpan(chapter.duration), DurationPts = chapter.duration }; diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInterop.csproj b/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInterop.csproj index b195c54a0..b6e60faad 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInterop.csproj +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInterop.csproj @@ -125,7 +125,7 @@ - + @@ -150,10 +150,10 @@ - - - - + + + + @@ -192,7 +192,7 @@ - + @@ -203,7 +203,7 @@ - + diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeUtils.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeUtils.cs index b065293ba..03150d1e8 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeUtils.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeUtils.cs @@ -104,8 +104,8 @@ namespace HandBrake.Interop if (loggingCallback == null) { // Keep the callback as a member to prevent it from being garbage collected. - loggingCallback = new LoggingCallback(LoggingHandler); - errorCallback = new LoggingCallback(ErrorHandler); + loggingCallback = LoggingHandler; + errorCallback = ErrorHandler; HBFunctions.hb_register_logger(loggingCallback); HBFunctions.hb_register_error_handler(errorCallback); } @@ -151,7 +151,12 @@ namespace HandBrake.Interop /// /// Gets the standard x264 option name given the starting point. /// - /// The standard x264 option name. + /// + /// The name. + /// + /// + /// The standard x264 option name. + /// public static string SanitizeX264OptName(string name) { IntPtr namePtr = Marshal.StringToHGlobalAnsi(name); @@ -224,7 +229,6 @@ namespace HandBrake.Interop string x264Settings = Marshal.PtrToStringAnsi(ptr); - return x264Settings; } diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/hb_audio.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/hb_audio.cs index f0627670d..c6bc59fb3 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/hb_audio.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/hb_audio.cs @@ -13,7 +13,9 @@ namespace HandBrake.Interop.HbLib using System; using System.Runtime.InteropServices; - [StructLayout(LayoutKind.Sequential)] + using HandBrake.Interop.Helpers; + + [StructLayout(LayoutKind.Sequential)] public struct hb_audio_s { /// int @@ -26,8 +28,8 @@ namespace HandBrake.Interop.HbLib [MarshalAs(UnmanagedType.ByValArray, SizeConst = MarshalingConstants.AudioPaddingBytes, ArraySubType = UnmanagedType.U1)] public byte[] padding; - /// Anonymous_e6c7b779_b5a3_4e80_9fa8_13619d14f545 - //public Anonymous_e6c7b779_b5a3_4e80_9fa8_13619d14f545 priv; + // Anonymous_e6c7b779_b5a3_4e80_9fa8_13619d14f545 + // public Anonymous_e6c7b779_b5a3_4e80_9fa8_13619d14f545 priv; } [StructLayout(LayoutKind.Sequential)] diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/hb_job_s.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/hb_job_s.cs index 5f41366c1..a3ea3dbb3 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/hb_job_s.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/hb_job_s.cs @@ -13,7 +13,9 @@ namespace HandBrake.Interop.HbLib using System; using System.Runtime.InteropServices; - [StructLayout(LayoutKind.Sequential)] + using HandBrake.Interop.Helpers; + + [StructLayout(LayoutKind.Sequential)] public struct hb_job_s { /// int diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Helpers/InteropUtilities.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Helpers/InteropUtilities.cs new file mode 100644 index 000000000..0019aa2d2 --- /dev/null +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/Helpers/InteropUtilities.cs @@ -0,0 +1,249 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// Helper utilities for native interop. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrake.Interop.Helpers +{ + using System; + using System.Collections.Generic; + using System.Linq; + using System.Runtime.InteropServices; + using System.Text; + + using HandBrake.Interop.HbLib; + + /// + /// Helper utilities for native interop. + /// + public static class InteropUtilities + { + /// + /// Reads the given native structure pointer. + /// + /// The type to convert the structure to. + /// The pointer to the native structure. + /// The converted structure. + public static T ReadStructure(IntPtr structPtr) + { + return (T)Marshal.PtrToStructure(structPtr, typeof(T)); + } + + /// + /// Reads the given native UTF-8 string. + /// + /// The pointer to the string. + /// The resulting string. + public static string ReadUtf8Ptr(IntPtr stringPtr) + { + var data = new List(); + var ptr = stringPtr; + var offset = 0; + while (true) + { + byte ch = Marshal.ReadByte(ptr, offset++); + if (ch == 0) + { + break; + } + + data.Add(ch); + } + + return Encoding.UTF8.GetString(data.ToArray()); + } + + /// + /// Creates a pointer to a UTF-8 null-terminated string. + /// + /// + /// The string to encode. + /// + /// + /// The . + /// + public static IntPtr CreateUtf8Ptr(string str) + { + byte[] bytes = Encoding.UTF8.GetBytes(str); + IntPtr stringPtr = Marshal.AllocHGlobal(bytes.Length + 1); + var offset = 0; + foreach (byte b in bytes) + { + Marshal.WriteByte(stringPtr, offset, b); + offset++; + } + + Marshal.WriteByte(stringPtr, offset, 0); + return stringPtr; + } + + /// + /// Converts the given native HandBrake list to a managed list. + /// + /// The type of structure in the list. + /// The pointer to the native list. + /// The converted managed list. + public static List ToList(this IntPtr listPtr) + { + List returnList = new List(); + NativeList nativeList = new NativeList(listPtr); + + for (int i = 0; i < nativeList.Count; i++) + { + IntPtr itemPtr = nativeList[i]; + returnList.Add(ReadStructure(itemPtr)); + } + + return returnList; + } + + /// + /// Converts the HB list to a managed list of pointers. + /// + /// The list to convert. + /// The managed list of pointers. + public static List ToIntPtrList(this IntPtr listPtr) + { + var returnList = new List(); + NativeList nativeList = new NativeList(listPtr); + + for (int i = 0; i < nativeList.Count; i++) + { + IntPtr itemPtr = nativeList[i]; + returnList.Add(itemPtr); + } + + return returnList; + } + + /// + /// Converts the given native array to a managed collection. + /// + /// The type of item in the list. + /// The pointer to the array. + /// The number of items in the array. + /// The converted collection. + public static IEnumerable ConvertArray(IntPtr arrayPtr, int count) + { + IntPtr currentItem = arrayPtr; + + var result = new List(); + for (int i = 0; i < count; i++) + { + T nativeEncoder = ReadStructure(currentItem); + result.Add(nativeEncoder); + + currentItem = IntPtr.Add(currentItem, Marshal.SizeOf(typeof(T))); + } + + return result; + } + + /// + /// Creates a native HandBrake list from the given managed list of pointers. + /// + /// The managed list to convert. + /// The converted native list. + public static NativeList CreateIntPtrList(List list) + { + NativeList returnList = NativeList.CreateList(); + + foreach (IntPtr ptr in list) + { + returnList.Add(ptr); + } + + return returnList; + } + + /// + /// Creates a native HandBrake list from the given managed list of structures. + /// + /// The type of structures in the list. + /// The managed list to convert. + /// The converted native list. + public static NativeList ConvertListBack(List list) + { + NativeList returnList = NativeList.CreateList(); + foreach (T item in list) + { + IntPtr itemPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(T))); + returnList.AllocatedMemory.Add(itemPtr); + Marshal.StructureToPtr(item, itemPtr, false); + + returnList.Add(itemPtr); + } + + return returnList; + } + + /// + /// Reads in a list of objects given an interator and a conversion function. + /// + /// The type of the struct given by the iterator. + /// The object type to convert to. + /// The iterator to use to build the list. + /// The converter to convert from the struct to the object. + /// The list of objects. + public static List GetListFromIterator(Func iterator, Func converter) + { + return ReadStructureListFromIterator(iterator).Select(converter).ToList(); + } + + /// + /// Reads in a list of structs given an iterator. + /// + /// The type of the struct. + /// The iterator to use to build the list. + /// The list of structs. + public static List ReadStructureListFromIterator(Func iterator) + { + var structureList = new List(); + IntPtr current = IntPtr.Zero; + + current = iterator(current); + while (current != IntPtr.Zero) + { + T encoder = ReadStructure(current); + structureList.Add(encoder); + + current = iterator(current); + } + + return structureList; + } + + /// + /// Closes the given job. + /// + /// The pointer to the job. + public static void CloseJob(IntPtr nativeJobPtr) + { + // Create a point to the job pointer first. + IntPtr nativeJobPtrPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr))); + + // Assign the new pointer to the job pointer and tell HB to clean the job up. + Marshal.WriteIntPtr(nativeJobPtrPtr, nativeJobPtr); + HBFunctions.hb_job_close(nativeJobPtrPtr); + + // Free the pointer we used. + Marshal.FreeHGlobal(nativeJobPtrPtr); + } + + /// + /// Frees all the memory locations in the given list. + /// + /// The list of memory locations to free. + public static void FreeMemory(List memoryList) + { + foreach (IntPtr memoryLocation in memoryList) + { + Marshal.FreeHGlobal(memoryLocation); + } + } + } +} diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Helpers/Languages.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Helpers/Languages.cs new file mode 100644 index 000000000..b89e190eb --- /dev/null +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/Helpers/Languages.cs @@ -0,0 +1,51 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// Contains utilities for converting language codes. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrake.Interop.Helpers +{ + using System.Collections.Generic; + + using HandBrake.Interop.HbLib; + using HandBrake.Interop.Model; + + /// + /// Contains utilities for converting language codes. + /// + public static class Languages + { + /// + /// The list of all languages. + /// + private static IList allLanguages; + + /// + /// Gets a list of all languages. + /// + public static IList AllLanguages + { + get + { + return allLanguages + ?? (allLanguages = + InteropUtilities.GetListFromIterator(HBFunctions.lang_get_next, Converters.Converters.NativeToLanguage)); + } + } + + /// + /// Gets the language object for the given code. + /// + /// The ISO-639-2 code for the language. + /// Object that describes the language. + public static Language Get(string code) + { + iso639_lang_t language = InteropUtilities.ReadStructure(HBFunctions.lang_for_code2(code)); + return Converters.Converters.NativeToLanguage(language); + } + } +} diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Helpers/MarshalingConstants.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Helpers/MarshalingConstants.cs new file mode 100644 index 000000000..98ed5048f --- /dev/null +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/Helpers/MarshalingConstants.cs @@ -0,0 +1,32 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// Defines the MarshalingConstants type. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrake.Interop.Helpers +{ + /// + /// The marshaling constants. + /// + public static class MarshalingConstants + { +#if X64 + public const int JobPaddingBytes = 49264; + public const int AudioPaddingBytes = 49208; +#else + /// + /// Job Padding Bytes + /// + public const int JobPaddingBytes = 49216; + + /// + /// Audio Padding Bytes + /// + public const int AudioPaddingBytes = 49180; +#endif + } +} diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Helpers/NativeList.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Helpers/NativeList.cs new file mode 100644 index 000000000..c77c58cb9 --- /dev/null +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/Helpers/NativeList.cs @@ -0,0 +1,125 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// Represents a HandBrake style native list. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrake.Interop.Helpers +{ + using System; + using System.Collections.Generic; + using System.Runtime.InteropServices; + + using HandBrake.Interop.HbLib; + + /// + /// Represents a HandBrake style native list. + /// + public class NativeList : IDisposable + { + /// + /// Initializes a new instance of the NativeList class. + /// + /// The pointer to use for the list. + public NativeList(IntPtr listPtr) + { + this.Ptr = listPtr; + } + + /// + /// The list of native memory locations allocated for this list. + /// + private readonly List allocatedMemory = new List(); + + /// + /// Gets the pointer to the native list. + /// + public IntPtr Ptr { get; private set; } + + /// + /// Gets the number of items in the list. + /// + public int Count + { + get + { + return HBFunctions.hb_list_count(this.Ptr); + } + } + + /// + /// Gets the list of native memory locations allocated for this list. + /// + public List AllocatedMemory + { + get + { + return this.allocatedMemory; + } + } + + /// + /// Adds an item to the end of the list. + /// + /// The item to add. + public void Add(IntPtr item) + { + HBFunctions.hb_list_add(this.Ptr, item); + } + + /// + /// Inserts an item into the list. + /// + /// The index to insert the item at. + /// The item to insert. + public void Insert(int position, IntPtr item) + { + HBFunctions.hb_list_insert(this.Ptr, position, item); + } + + /// + /// Removes an item from the list. + /// + /// The item to remove. + public void Remove(IntPtr item) + { + HBFunctions.hb_list_rem(this.Ptr, item); + } + + /// + /// Gets an item out of the list. + /// + /// Index in the list. + /// The item at that index in the list. + public IntPtr this[int i] + { + get + { + return HBFunctions.hb_list_item(this.Ptr, i); + } + } + + /// + /// Disposes resources associated with this object. + /// + public void Dispose() + { + IntPtr listPtrPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr))); + Marshal.WriteIntPtr(listPtrPtr, this.Ptr); + HBFunctions.hb_list_close(listPtrPtr); + Marshal.FreeHGlobal(listPtrPtr); + } + + /// + /// Creates a new list in unmanaged memory. + /// + /// The created list. + public static NativeList CreateList() + { + return new NativeList(HBFunctions.hb_list_init()); + } + } +} diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Helpers/Utilities.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Helpers/Utilities.cs new file mode 100644 index 000000000..77106f72d --- /dev/null +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/Helpers/Utilities.cs @@ -0,0 +1,66 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// Defines the Utilities type. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrake.Interop.Helpers +{ + using HandBrake.Interop.Model.Encoding; + + /// + /// The utilities. + /// + public static class Utilities + { + /// + /// Get the Greatest Common Factor + /// + /// + /// The a. + /// + /// + /// The b. + /// + /// + /// The greatest common factor + /// + public static int GreatestCommonFactor(int a, int b) + { + if (a == 0) + { + return b; + } + + if (b == 0) + { + return a; + } + + if (a > b) + { + return GreatestCommonFactor(a % b, b); + } + + return GreatestCommonFactor(a, b % a); + } + + /// + /// Determines if the given audio encoder is a passthrough encoder choice. + /// + /// The audio encoder to examine. + /// True if the encoder is passthrough. + public static bool IsPassthrough(AudioEncoder encoder) + { + return encoder == AudioEncoder.Ac3Passthrough || + encoder == AudioEncoder.DtsHDPassthrough || + encoder == AudioEncoder.DtsPassthrough || + encoder == AudioEncoder.Mp3Passthru || + encoder == AudioEncoder.AacPassthru || + encoder == AudioEncoder.Passthrough; + } + } +} diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/InteropUtilities.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/InteropUtilities.cs deleted file mode 100644 index 0dac9be4a..000000000 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/InteropUtilities.cs +++ /dev/null @@ -1,243 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. -// -// -// Helper utilities for native interop. -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace HandBrake.Interop -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Runtime.InteropServices; - using System.Text; - using HandBrake.Interop.HbLib; - - /// - /// Helper utilities for native interop. - /// - public static class InteropUtilities - { - /// - /// Reads the given native structure pointer. - /// - /// The type to convert the structure to. - /// The pointer to the native structure. - /// The converted structure. - public static T ReadStructure(IntPtr structPtr) - { - return (T)Marshal.PtrToStructure(structPtr, typeof(T)); - } - - /// - /// Reads the given native UTF-8 string. - /// - /// The pointer to the string. - /// The resulting string. - public static string ReadUtf8Ptr(IntPtr stringPtr) - { - var data = new List(); - var ptr = stringPtr; - var offset = 0; - while (true) - { - byte ch = Marshal.ReadByte(ptr, offset++); - if (ch == 0) - { - break; - } - - data.Add(ch); - } - - return Encoding.UTF8.GetString(data.ToArray()); - } - - /// - /// Creates a pointer to a UTF-8 null-terminated string. - /// - /// The string to encode. - public static IntPtr CreateUtf8Ptr(string str) - { - byte[] bytes = Encoding.UTF8.GetBytes(str); - IntPtr stringPtr = Marshal.AllocHGlobal(bytes.Length + 1); - var offset = 0; - foreach (byte b in bytes) - { - Marshal.WriteByte(stringPtr, offset, b); - offset++; - } - - Marshal.WriteByte(stringPtr, offset, 0); - return stringPtr; - } - - /// - /// Converts the given native HandBrake list to a managed list. - /// - /// The type of structure in the list. - /// The pointer to the native list. - /// The converted managed list. - public static List ToList(this IntPtr listPtr) - { - List returnList = new List(); - NativeList nativeList = new NativeList(listPtr); - - for (int i = 0; i < nativeList.Count; i++) - { - IntPtr itemPtr = nativeList[i]; - returnList.Add(ReadStructure(itemPtr)); - } - - return returnList; - } - - /// - /// Converts the HB list to a managed list of pointers. - /// - /// The list to convert. - /// The managed list of pointers. - public static List ToIntPtrList(this IntPtr listPtr) - { - var returnList = new List(); - NativeList nativeList = new NativeList(listPtr); - - for (int i = 0; i < nativeList.Count; i++) - { - IntPtr itemPtr = nativeList[i]; - returnList.Add(itemPtr); - } - - return returnList; - } - - /// - /// Converts the given native array to a managed collection. - /// - /// The type of item in the list. - /// The pointer to the array. - /// The number of items in the array. - /// The converted collection. - public static IEnumerable ConvertArray(IntPtr arrayPtr, int count) - { - IntPtr currentItem = arrayPtr; - - var result = new List(); - for (int i = 0; i < count; i++) - { - T nativeEncoder = ReadStructure(currentItem); - result.Add(nativeEncoder); - - currentItem = IntPtr.Add(currentItem, Marshal.SizeOf(typeof(T))); - } - - return result; - } - - /// - /// Creates a native HandBrake list from the given managed list of pointers. - /// - /// The managed list to convert. - /// The converted native list. - public static NativeList CreateIntPtrList(List list) - { - NativeList returnList = NativeList.CreateList(); - - foreach (IntPtr ptr in list) - { - returnList.Add(ptr); - } - - return returnList; - } - - /// - /// Creates a native HandBrake list from the given managed list of structures. - /// - /// The type of structures in the list. - /// The managed list to convert. - /// The converted native list. - public static NativeList ConvertListBack(List list) - { - NativeList returnList = NativeList.CreateList(); - foreach (T item in list) - { - IntPtr itemPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(T))); - returnList.AllocatedMemory.Add(itemPtr); - Marshal.StructureToPtr(item, itemPtr, false); - - returnList.Add(itemPtr); - } - - return returnList; - } - - /// - /// Reads in a list of objects given an interator and a conversion function. - /// - /// The type of the struct given by the iterator. - /// The object type to convert to. - /// The iterator to use to build the list. - /// The converter to convert from the struct to the object. - /// The list of objects. - public static List GetListFromIterator(Func iterator, Func converter) - { - return ReadStructureListFromIterator(iterator).Select(converter).ToList(); - } - - /// - /// Reads in a list of structs given an iterator. - /// - /// The type of the struct. - /// The iterator to use to build the list. - /// The list of structs. - public static List ReadStructureListFromIterator(Func iterator) - { - var structureList = new List(); - IntPtr current = IntPtr.Zero; - - current = iterator(current); - while (current != IntPtr.Zero) - { - T encoder = ReadStructure(current); - structureList.Add(encoder); - - current = iterator(current); - } - - return structureList; - } - - /// - /// Closes the given job. - /// - /// The pointer to the job. - public static void CloseJob(IntPtr nativeJobPtr) - { - // Create a point to the job pointer first. - IntPtr nativeJobPtrPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr))); - - // Assign the new pointer to the job pointer and tell HB to clean the job up. - Marshal.WriteIntPtr(nativeJobPtrPtr, nativeJobPtr); - HBFunctions.hb_job_close(nativeJobPtrPtr); - - // Free the pointer we used. - Marshal.FreeHGlobal(nativeJobPtrPtr); - } - - /// - /// Frees all the memory locations in the given list. - /// - /// The list of memory locations to free. - public static void FreeMemory(List memoryList) - { - foreach (IntPtr memoryLocation in memoryList) - { - Marshal.FreeHGlobal(memoryLocation); - } - } - } -} diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Language.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Language.cs deleted file mode 100644 index c2f17281e..000000000 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/Language.cs +++ /dev/null @@ -1,48 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. -// -// -// Represents a language. -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace HandBrake.Interop -{ - /// - /// Represents a language. - /// - public class Language - { - /// - /// Gets or sets the english name of the language. - /// - public string EnglishName { get; set; } - - /// - /// Gets or sets the native name of the language. - /// - public string NativeName { get; set; } - - /// - /// Gets or sets the language code. - /// - public string Code { get; set; } - - /// - /// Gets the display string for the language. - /// - public string Display - { - get - { - if (!string.IsNullOrEmpty(this.NativeName) && this.NativeName != this.EnglishName) - { - return this.EnglishName + " (" + this.NativeName + ")"; - } - - return this.EnglishName; - } - } - } -} diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Languages.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Languages.cs deleted file mode 100644 index f8d3db624..000000000 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/Languages.cs +++ /dev/null @@ -1,54 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. -// -// -// Contains utilities for converting language codes. -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace HandBrake.Interop -{ - using System.Collections.Generic; - using HbLib; - - /// - /// Contains utilities for converting language codes. - /// - public static class Languages - { - /// - /// The list of all languages. - /// - private static IList allLanguages; - - /// - /// Gets a list of all languages. - /// - public static IList AllLanguages - { - get - { - if (allLanguages == null) - { - allLanguages = InteropUtilities.GetListFromIterator( - HBFunctions.lang_get_next, - Converters.NativeToLanguage); - } - - return allLanguages; - } - } - - /// - /// Gets the language object for the given code. - /// - /// The ISO-639-2 code for the language. - /// Object that describes the language. - public static Language Get(string code) - { - iso639_lang_t language = InteropUtilities.ReadStructure(HBFunctions.lang_for_code2(code)); - return Converters.NativeToLanguage(language); - } - } -} diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/MarshalingConstants.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/MarshalingConstants.cs deleted file mode 100644 index 05261251a..000000000 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/MarshalingConstants.cs +++ /dev/null @@ -1,32 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. -// -// -// Defines the MarshalingConstants type. -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace HandBrake.Interop -{ - /// - /// The marshaling constants. - /// - public static class MarshalingConstants - { -#if X64 - public const int JobPaddingBytes = 49264; - public const int AudioPaddingBytes = 49208; -#else - /// - /// Job Padding Bytes - /// - public const int JobPaddingBytes = 49216; - - /// - /// Audio Padding Bytes - /// - public const int AudioPaddingBytes = 49180; -#endif - } -} diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoders.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoders.cs index ba6a1ebd6..593c1015f 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoders.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoders.cs @@ -13,7 +13,9 @@ namespace HandBrake.Interop.Model using System.Collections.Generic; using System.Linq; + using HandBrake.Interop.Converters; using HandBrake.Interop.HbLib; + using HandBrake.Interop.Helpers; using HandBrake.Interop.Model.Encoding; using HandBrake.Interop.SourceData; diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/Anamorphic.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/Anamorphic.cs index 0c798457b..42e4428ed 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/Anamorphic.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/Anamorphic.cs @@ -11,7 +11,10 @@ namespace HandBrake.Interop.Model.Encoding { using System.ComponentModel.DataAnnotations; - public enum Anamorphic + /// + /// The anamorphic. + /// + public enum Anamorphic { [Display(Name = "None")] None = 0, diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/AudioEncodeRateType.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/AudioEncodeRateType.cs index ca162a47f..6017b872c 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/AudioEncodeRateType.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/AudioEncodeRateType.cs @@ -1,17 +1,18 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. -// +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// The audio encode rate type. +// // -------------------------------------------------------------------------------------------------------------------- namespace HandBrake.Interop.Model.Encoding -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Text; - - public enum AudioEncodeRateType +{ + /// + /// The audio encode rate type. + /// + public enum AudioEncodeRateType { Bitrate, Quality diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/Container.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/Container.cs index 2a526170e..08f33caff 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/Container.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/Container.cs @@ -1,15 +1,21 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. -// +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// Defines the Container type. +// // -------------------------------------------------------------------------------------------------------------------- namespace HandBrake.Interop.Model.Encoding { using System; - using System.ComponentModel.DataAnnotations; - - [Flags] + using System.ComponentModel.DataAnnotations; + + /// + /// The container. + /// + [Flags] public enum Container { None = 0x0, diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/CroppingType.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/CroppingType.cs index 64f68a476..e7c8da445 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/CroppingType.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/CroppingType.cs @@ -2,6 +2,9 @@ // // This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. // +// +// The type of cropping to apply. +// // -------------------------------------------------------------------------------------------------------------------- namespace HandBrake.Interop.Model.Encoding diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/Decomb.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/Decomb.cs index a376ef893..c205545b3 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/Decomb.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/Decomb.cs @@ -9,7 +9,10 @@ namespace HandBrake.Interop.Model.Encoding { - public enum Decomb + /// + /// The decomb. + /// + public enum Decomb { Off = 0, Default = 2, diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/Denoise.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/Denoise.cs index ec64d9e75..a2ab0f0a4 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/Denoise.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/Denoise.cs @@ -9,7 +9,10 @@ namespace HandBrake.Interop.Model.Encoding { - public enum Denoise + /// + /// The denoise. + /// + public enum Denoise { Off = 0, Weak = 2, diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/Detelecine.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/Detelecine.cs index af7930973..c69350684 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/Detelecine.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/Detelecine.cs @@ -9,7 +9,10 @@ namespace HandBrake.Interop.Model.Encoding { - public enum Detelecine + /// + /// The detelecine. + /// + public enum Detelecine { Off = 0, Default = 2, diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/EncodingProfile.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/EncodingProfile.cs index 81a1b8afd..f37766281 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/EncodingProfile.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/EncodingProfile.cs @@ -9,82 +9,288 @@ namespace HandBrake.Interop.Model.Encoding { - using System; - using System.Collections.Generic; + using System.Collections.Generic; using HandBrake.Interop.Model; - public class EncodingProfile + /// + /// The encoding profile. + /// + public class EncodingProfile { - public EncodingProfile() + /// + /// Initializes a new instance of the class. + /// + public EncodingProfile() { this.Cropping = new Cropping(); } - [Obsolete("Use ContainerName instead.")] - public Container OutputFormat { get; set; } - - public string ContainerName { get; set; } - public OutputExtension PreferredExtension { get; set; } - public bool IncludeChapterMarkers { get; set; } - public bool LargeFile { get; set; } - public bool Optimize { get; set; } - public bool IPod5GSupport { get; set; } - - public int Width { get; set; } - public int Height { get; set; } - public int MaxWidth { get; set; } - public int MaxHeight { get; set; } - public ScaleMethod ScaleMethod { get; set; } - public CroppingType CroppingType { get; set; } - public Cropping Cropping { get; set; } - public Anamorphic Anamorphic { get; set; } - public bool UseDisplayWidth { get; set; } - public int DisplayWidth { get; set; } - public bool KeepDisplayAspect { get; set; } - public int PixelAspectX { get; set; } - public int PixelAspectY { get; set; } - public int Modulus { get; set; } - - public Deinterlace Deinterlace { get; set; } - public string CustomDeinterlace { get; set; } - public Decomb Decomb { get; set; } - public string CustomDecomb { get; set; } - public Detelecine Detelecine { get; set; } - public string CustomDetelecine { get; set; } - public Denoise Denoise { get; set; } - public string CustomDenoise { get; set; } - public int Deblock { get; set; } - public bool Grayscale { get; set; } - - public string VideoEncoder { get; set; } - public string X264Options { get; set; } - public string X264Profile { get; set; } - public string X264Preset { get; set; } - - public List X264Tunes { get; set; } - public string QsvPreset { get; set; } - public bool QsvDecode { get; set; } - public string H264Level { get; set; } - public VideoEncodeRateType VideoEncodeRateType { get; set; } - public double Quality { get; set; } - public int TargetSize { get; set; } - public int VideoBitrate { get; set; } - public bool TwoPass { get; set; } - public bool TurboFirstPass { get; set; } - public double Framerate { get; set; } - public bool ConstantFramerate { get; set; } - - public List AudioEncodings { get; set; } - public string AudioEncoderFallback { get; set; } - - public EncodingProfile Clone() + #region Destination and Output Settings + + /// + /// Gets or sets the container name. + /// + public string ContainerName { get; set; } + + /// + /// Gets or sets the preferred extension. + /// + public OutputExtension PreferredExtension { get; set; } + + /// + /// Gets or sets a value indicating whether include chapter markers. + /// + public bool IncludeChapterMarkers { get; set; } + + /// + /// Gets or sets a value indicating whether large file. + /// + public bool LargeFile { get; set; } + + /// + /// Gets or sets a value indicating whether optimize. + /// + public bool Optimize { get; set; } + + /// + /// Gets or sets a value indicating whether i pod 5 g support. + /// + public bool IPod5GSupport { get; set; } + #endregion + + #region Picture Settings + + /// + /// Gets or sets the width. + /// + public int Width { get; set; } + + /// + /// Gets or sets the height. + /// + public int Height { get; set; } + + /// + /// Gets or sets the max width. + /// + public int MaxWidth { get; set; } + + /// + /// Gets or sets the max height. + /// + public int MaxHeight { get; set; } + + /// + /// Gets or sets the scale method. + /// + public ScaleMethod ScaleMethod { get; set; } + + /// + /// Gets or sets the cropping type. + /// + public CroppingType CroppingType { get; set; } + + /// + /// Gets or sets the cropping. + /// + public Cropping Cropping { get; set; } + + /// + /// Gets or sets the anamorphic. + /// + public Anamorphic Anamorphic { get; set; } + + /// + /// Gets or sets a value indicating whether use display width. + /// + public bool UseDisplayWidth { get; set; } + + /// + /// Gets or sets the display width. + /// + public int DisplayWidth { get; set; } + + /// + /// Gets or sets a value indicating whether keep display aspect. + /// + public bool KeepDisplayAspect { get; set; } + + /// + /// Gets or sets the pixel aspect x. + /// + public int PixelAspectX { get; set; } + + /// + /// Gets or sets the pixel aspect y. + /// + public int PixelAspectY { get; set; } + + /// + /// Gets or sets the modulus. + /// + public int Modulus { get; set; } + #endregion + + #region Filters + + /// + /// Gets or sets the deinterlace. + /// + public Deinterlace Deinterlace { get; set; } + + /// + /// Gets or sets the custom deinterlace. + /// + public string CustomDeinterlace { get; set; } + + /// + /// Gets or sets the decomb. + /// + public Decomb Decomb { get; set; } + + /// + /// Gets or sets the custom decomb. + /// + public string CustomDecomb { get; set; } + + /// + /// Gets or sets the detelecine. + /// + public Detelecine Detelecine { get; set; } + + /// + /// Gets or sets the custom detelecine. + /// + public string CustomDetelecine { get; set; } + + /// + /// Gets or sets the denoise. + /// + public Denoise Denoise { get; set; } + + /// + /// Gets or sets the custom denoise. + /// + public string CustomDenoise { get; set; } + + /// + /// Gets or sets the deblock. + /// + public int Deblock { get; set; } + + /// + /// Gets or sets a value indicating whether grayscale. + /// + public bool Grayscale { get; set; } + #endregion + + #region Video + + /// + /// Gets or sets the video encoder. + /// + public string VideoEncoder { get; set; } + + /// + /// Gets or sets the x 264 options. + /// + public string X264Options { get; set; } + + /// + /// Gets or sets the x 264 profile. + /// + public string X264Profile { get; set; } + + /// + /// Gets or sets the x 264 preset. + /// + public string X264Preset { get; set; } + + /// + /// Gets or sets the x 264 tunes. + /// + public List X264Tunes { get; set; } + + /// + /// Gets or sets the qsv preset. + /// + public string QsvPreset { get; set; } + + /// + /// Gets or sets a value indicating whether qsv decode. + /// + public bool QsvDecode { get; set; } + + /// + /// Gets or sets the h 264 level. + /// + public string H264Level { get; set; } + + /// + /// Gets or sets the video encode rate type. + /// + public VideoEncodeRateType VideoEncodeRateType { get; set; } + + /// + /// Gets or sets the quality. + /// + public double Quality { get; set; } + + /// + /// Gets or sets the target size. + /// + public int TargetSize { get; set; } + + /// + /// Gets or sets the video bitrate. + /// + public int VideoBitrate { get; set; } + + /// + /// Gets or sets a value indicating whether two pass. + /// + public bool TwoPass { get; set; } + + /// + /// Gets or sets a value indicating whether turbo first pass. + /// + public bool TurboFirstPass { get; set; } + + /// + /// Gets or sets the framerate. + /// + public double Framerate { get; set; } + + /// + /// Gets or sets a value indicating whether constant framerate. + /// + public bool ConstantFramerate { get; set; } + #endregion + + #region Audio + + /// + /// Gets or sets the audio encodings. + /// + public List AudioEncodings { get; set; } + + /// + /// Gets or sets the audio encoder fallback. + /// + public string AudioEncoderFallback { get; set; } + #endregion + + /// + /// The clone. + /// + /// + /// The . + /// + public EncodingProfile Clone() { var profile = new EncodingProfile { -#pragma warning disable 612, 618 - OutputFormat = this.OutputFormat, -#pragma warning restore 612, 618 ContainerName = this.ContainerName, PreferredExtension = this.PreferredExtension, IncludeChapterMarkers = this.IncludeChapterMarkers, diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/HBAudioEncoder.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/HBAudioEncoder.cs index a3a95ab33..478e309a6 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/HBAudioEncoder.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/HBAudioEncoder.cs @@ -1,53 +1,96 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace HandBrake.Interop.Model.Encoding -{ - using HandBrake.Interop.HbLib; - - public class HBAudioEncoder - { - public string ShortName { get; set; } - - public string DisplayName { get; set; } - - public int Id { get; set; } - - public int CompatibleContainers { get; set; } - - public bool SupportsQuality - { - get - { - return this.QualityLimits.High >= 0; - } - } - - public RangeLimits QualityLimits { get; set; } - - public float DefaultQuality { get; set; } - - public bool SupportsCompression - { - get - { - return this.CompressionLimits.High >= 0; - } - } - - public RangeLimits CompressionLimits { get; set; } - - public float DefaultCompression { get; set; } - - public bool IsPassthrough - { - get - { - return (this.Id & NativeConstants.HB_ACODEC_PASS_FLAG) > 0; - } - } - } -} +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// The hb audio encoder. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrake.Interop.Model.Encoding +{ + using HandBrake.Interop.HbLib; + + /// + /// The hb audio encoder. + /// + public class HBAudioEncoder + { + #region Public Properties + + /// + /// Gets or sets the compatible containers. + /// + public int CompatibleContainers { get; set; } + + /// + /// Gets or sets the compression limits. + /// + public RangeLimits CompressionLimits { get; set; } + + /// + /// Gets or sets the default compression. + /// + public float DefaultCompression { get; set; } + + /// + /// Gets or sets the default quality. + /// + public float DefaultQuality { get; set; } + + /// + /// Gets or sets the display name. + /// + public string DisplayName { get; set; } + + /// + /// Gets or sets the id. + /// + public int Id { get; set; } + + /// + /// Gets a value indicating whether is passthrough. + /// + public bool IsPassthrough + { + get + { + return (this.Id & NativeConstants.HB_ACODEC_PASS_FLAG) > 0; + } + } + + /// + /// Gets or sets the quality limits. + /// + public RangeLimits QualityLimits { get; set; } + + /// + /// Gets or sets the short name. + /// + public string ShortName { get; set; } + + /// + /// Gets a value indicating whether supports compression. + /// + public bool SupportsCompression + { + get + { + return this.CompressionLimits.High >= 0; + } + } + + /// + /// Gets a value indicating whether supports quality. + /// + public bool SupportsQuality + { + get + { + return this.QualityLimits.High >= 0; + } + } + + #endregion + } +} \ No newline at end of file diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/HBContainer.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/HBContainer.cs index 136006075..3b6feea48 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/HBContainer.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/HBContainer.cs @@ -1,18 +1,41 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// The hb container. +// +// -------------------------------------------------------------------------------------------------------------------- namespace HandBrake.Interop.Model.Encoding { - public class HBContainer - { - public string ShortName { get; set; } + /// + /// The hb container. + /// + public class HBContainer + { + #region Public Properties - public string DisplayName { get; set; } + /// + /// Gets or sets the default extension. + /// + public string DefaultExtension { get; set; } - public string DefaultExtension { get; set; } + /// + /// Gets or sets the display name. + /// + public string DisplayName { get; set; } - public int Id { get; set; } - } -} + /// + /// Gets or sets the id. + /// + public int Id { get; set; } + + /// + /// Gets or sets the short name. + /// + public string ShortName { get; set; } + + #endregion + } +} \ No newline at end of file diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/HBMixdown.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/HBMixdown.cs index 493beb9fa..94d9dc24b 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/HBMixdown.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/HBMixdown.cs @@ -1,22 +1,36 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace HandBrake.Interop.Model.Encoding -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Text; - - public class HBMixdown - { - public string ShortName { get; set; } - - public string DisplayName { get; set; } - - public int Id { get; set; } - } -} +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// The hb mixdown. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrake.Interop.Model.Encoding +{ + /// + /// The hb mixdown. + /// + public class HBMixdown + { + #region Public Properties + + /// + /// Gets or sets the display name. + /// + public string DisplayName { get; set; } + + /// + /// Gets or sets the id. + /// + public int Id { get; set; } + + /// + /// Gets or sets the short name. + /// + public string ShortName { get; set; } + + #endregion + } +} \ No newline at end of file diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/HBRate.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/HBRate.cs index 2862574dc..b8dfabbc3 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/HBRate.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/HBRate.cs @@ -2,6 +2,9 @@ // // This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. // +// +// Represents a rate in HandBrake: audio sample rate or video framerate. +// // -------------------------------------------------------------------------------------------------------------------- namespace HandBrake.Interop.Model.Encoding diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/HBVideoEncoder.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/HBVideoEncoder.cs index 6bc04a5be..98bbcc319 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/HBVideoEncoder.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/HBVideoEncoder.cs @@ -1,19 +1,41 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace HandBrake.Interop.Model.Encoding -{ - public class HBVideoEncoder - { - public string ShortName { get; set; } - - public string DisplayName { get; set; } - - public int Id { get; set; } - - public int CompatibleContainers { get; set; } - } -} +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// The hb video encoder. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrake.Interop.Model.Encoding +{ + /// + /// The hb video encoder. + /// + public class HBVideoEncoder + { + #region Public Properties + + /// + /// Gets or sets the compatible containers. + /// + public int CompatibleContainers { get; set; } + + /// + /// Gets or sets the display name. + /// + public string DisplayName { get; set; } + + /// + /// Gets or sets the id. + /// + public int Id { get; set; } + + /// + /// Gets or sets the short name. + /// + public string ShortName { get; set; } + + #endregion + } +} \ No newline at end of file diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/OutputExtension.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/OutputExtension.cs index ff8e89fda..f4b2415fa 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/OutputExtension.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/OutputExtension.cs @@ -9,7 +9,10 @@ namespace HandBrake.Interop.Model.Encoding { - public enum OutputExtension + /// + /// The output extension. + /// + public enum OutputExtension { Mp4, M4v diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/ScaleMethod.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/ScaleMethod.cs index 31c624893..f0c840085 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/ScaleMethod.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/ScaleMethod.cs @@ -1,7 +1,10 @@ // -------------------------------------------------------------------------------------------------------------------- -// +// // This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. // +// +// Scaling Method +// // -------------------------------------------------------------------------------------------------------------------- namespace HandBrake.Interop.Model.Encoding diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/VideoEncodeRateType.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/VideoEncodeRateType.cs index 7bf052efb..4afeb7123 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/VideoEncodeRateType.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/VideoEncodeRateType.cs @@ -9,7 +9,10 @@ namespace HandBrake.Interop.Model.Encoding { - public enum VideoEncodeRateType + /// + /// The video encode rate type. + /// + public enum VideoEncodeRateType { TargetSize = 0, AverageBitrate = 1, diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Language.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Language.cs new file mode 100644 index 000000000..9d731ed69 --- /dev/null +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Language.cs @@ -0,0 +1,48 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// Represents a language. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrake.Interop.Model +{ + /// + /// Represents a language. + /// + public class Language + { + /// + /// Gets or sets the english name of the language. + /// + public string EnglishName { get; set; } + + /// + /// Gets or sets the native name of the language. + /// + public string NativeName { get; set; } + + /// + /// Gets or sets the language code. + /// + public string Code { get; set; } + + /// + /// Gets the display string for the language. + /// + public string Display + { + get + { + if (!string.IsNullOrEmpty(this.NativeName) && this.NativeName != this.EnglishName) + { + return this.EnglishName + " (" + this.NativeName + ")"; + } + + return this.EnglishName; + } + } + } +} diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/NativeList.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/NativeList.cs deleted file mode 100644 index 1e24f9ce4..000000000 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/NativeList.cs +++ /dev/null @@ -1,125 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. -// -// -// Represents a HandBrake style native list. -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace HandBrake.Interop -{ - using System; - using System.Collections.Generic; - using System.Runtime.InteropServices; - - using HandBrake.Interop.HbLib; - - /// - /// Represents a HandBrake style native list. - /// - public class NativeList : IDisposable - { - /// - /// Initializes a new instance of the NativeList class. - /// - /// The pointer to use for the list. - public NativeList(IntPtr listPtr) - { - this.Ptr = listPtr; - } - - /// - /// The list of native memory locations allocated for this list. - /// - private List allocatedMemory = new List(); - - /// - /// Gets or sets the pointer to the native list. - /// - public IntPtr Ptr { get; private set; } - - /// - /// Gets the number of items in the list. - /// - public int Count - { - get - { - return HBFunctions.hb_list_count(this.Ptr); - } - } - - /// - /// Gets the list of native memory locations allocated for this list. - /// - public List AllocatedMemory - { - get - { - return allocatedMemory; - } - } - - /// - /// Adds an item to the end of the list. - /// - /// The item to add. - public void Add(IntPtr item) - { - HBFunctions.hb_list_add(this.Ptr, item); - } - - /// - /// Inserts an item into the list. - /// - /// The index to insert the item at. - /// The item to insert. - public void Insert(int position, IntPtr item) - { - HBFunctions.hb_list_insert(this.Ptr, position, item); - } - - /// - /// Removes an item from the list. - /// - /// The item to remove. - public void Remove(IntPtr item) - { - HBFunctions.hb_list_rem(this.Ptr, item); - } - - /// - /// Gets an item out of the list. - /// - /// Index in the list. - /// The item at that index in the list. - public IntPtr this[int i] - { - get - { - return HBFunctions.hb_list_item(this.Ptr, i); - } - } - - /// - /// Disposes resources associated with this object. - /// - public void Dispose() - { - IntPtr listPtrPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr))); - Marshal.WriteIntPtr(listPtrPtr, this.Ptr); - HBFunctions.hb_list_close(listPtrPtr); - Marshal.FreeHGlobal(listPtrPtr); - } - - /// - /// Creates a new list in unmanaged memory. - /// - /// The created list. - public static NativeList CreateList() - { - return new NativeList(HBFunctions.hb_list_init()); - } - } -} diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Utilities.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Utilities.cs deleted file mode 100644 index 11246230c..000000000 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/Utilities.cs +++ /dev/null @@ -1,66 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. -// -// -// Defines the Utilities type. -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace HandBrake.Interop -{ - using HandBrake.Interop.Model.Encoding; - - /// - /// The utilities. - /// - public static class Utilities - { - /// - /// Get the Greatest Common Factor - /// - /// - /// The a. - /// - /// - /// The b. - /// - /// - /// The greatest common factor - /// - public static int GreatestCommonFactor(int a, int b) - { - if (a == 0) - { - return b; - } - - if (b == 0) - { - return a; - } - - if (a > b) - { - return GreatestCommonFactor(a % b, b); - } - - return GreatestCommonFactor(a, b % a); - } - - /// - /// Determines if the given audio encoder is a passthrough encoder choice. - /// - /// The audio encoder to examine. - /// True if the encoder is passthrough. - public static bool IsPassthrough(AudioEncoder encoder) - { - return encoder == AudioEncoder.Ac3Passthrough || - encoder == AudioEncoder.DtsHDPassthrough || - encoder == AudioEncoder.DtsPassthrough || - encoder == AudioEncoder.Mp3Passthru || - encoder == AudioEncoder.AacPassthru || - encoder == AudioEncoder.Passthrough; - } - } -} -- cgit v1.2.3