diff options
Diffstat (limited to 'win/CS/HandBrake.Interop/Interop/HandBrakeEncoderHelpers.cs')
-rw-r--r-- | win/CS/HandBrake.Interop/Interop/HandBrakeEncoderHelpers.cs | 61 |
1 files changed, 34 insertions, 27 deletions
diff --git a/win/CS/HandBrake.Interop/Interop/HandBrakeEncoderHelpers.cs b/win/CS/HandBrake.Interop/Interop/HandBrakeEncoderHelpers.cs index 4d1dcea2e..d728809e3 100644 --- a/win/CS/HandBrake.Interop/Interop/HandBrakeEncoderHelpers.cs +++ b/win/CS/HandBrake.Interop/Interop/HandBrakeEncoderHelpers.cs @@ -14,15 +14,19 @@ namespace HandBrake.Interop.Interop using System.Linq; using HandBrake.Interop.Interop.HbLib; + using HandBrake.Interop.Interop.HbLib.Wrappers.Interfaces; using HandBrake.Interop.Interop.Helpers; using HandBrake.Interop.Interop.Model; using HandBrake.Interop.Interop.Model.Encoding; + using HandBrake.Interop.Interop.Providers; + using HandBrake.Interop.Interop.Providers.Interfaces; /// <summary> /// The encoders. /// </summary> public static class HandBrakeEncoderHelpers { + private static IHbFunctions hbFunctions; private static List<HBAudioEncoder> audioEncoders; private static List<HBVideoEncoder> videoEncoders; private static List<HBRate> videoFramerates; @@ -36,6 +40,9 @@ namespace HandBrake.Interop.Interop /// </summary> static HandBrakeEncoderHelpers() { + IHbFunctionsProvider hbFunctionsProvider = new HbFunctionsProvider(); + hbFunctions = hbFunctionsProvider.GetHbFunctionsWrapper(); + if (!HandBrakeUtils.IsInitialised()) { throw new Exception("Please Initialise with HandBrakeUtils.EnsureGlobalInit before using!"); @@ -51,7 +58,7 @@ namespace HandBrake.Interop.Interop { if (audioEncoders == null) { - audioEncoders = InteropUtilities.ToListFromIterator<hb_encoder_s, HBAudioEncoder>(HBFunctions.hb_audio_encoder_get_next, HandBrakeUnitConversionHelpers.NativeToAudioEncoder); + audioEncoders = InteropUtilities.ToListFromIterator<hb_encoder_s, HBAudioEncoder>(hbFunctions.hb_audio_encoder_get_next, HandBrakeUnitConversionHelpers.NativeToAudioEncoder); } return audioEncoders; @@ -67,7 +74,7 @@ namespace HandBrake.Interop.Interop { if (videoEncoders == null) { - videoEncoders = InteropUtilities.ToListFromIterator<hb_encoder_s, HBVideoEncoder>(HBFunctions.hb_video_encoder_get_next, HandBrakeUnitConversionHelpers.NativeToVideoEncoder); + videoEncoders = InteropUtilities.ToListFromIterator<hb_encoder_s, HBVideoEncoder>(hbFunctions.hb_video_encoder_get_next, HandBrakeUnitConversionHelpers.NativeToVideoEncoder); } return videoEncoders; @@ -83,7 +90,7 @@ namespace HandBrake.Interop.Interop { if (videoFramerates == null) { - videoFramerates = InteropUtilities.ToListFromIterator<hb_rate_s, HBRate>(HBFunctions.hb_video_framerate_get_next, HandBrakeUnitConversionHelpers.NativeToRate); + videoFramerates = InteropUtilities.ToListFromIterator<hb_rate_s, HBRate>(hbFunctions.hb_video_framerate_get_next, HandBrakeUnitConversionHelpers.NativeToRate); } return videoFramerates; @@ -99,7 +106,7 @@ namespace HandBrake.Interop.Interop { if (mixdowns == null) { - mixdowns = InteropUtilities.ToListFromIterator<hb_mixdown_s, HBMixdown>(HBFunctions.hb_mixdown_get_next, HandBrakeUnitConversionHelpers.NativeToMixdown); + mixdowns = InteropUtilities.ToListFromIterator<hb_mixdown_s, HBMixdown>(hbFunctions.hb_mixdown_get_next, HandBrakeUnitConversionHelpers.NativeToMixdown); } return mixdowns; @@ -115,7 +122,7 @@ namespace HandBrake.Interop.Interop { if (audioBitrates == null) { - audioBitrates = InteropUtilities.ToListFromIterator<hb_rate_s, int>(HBFunctions.hb_audio_bitrate_get_next, b => b.rate); + audioBitrates = InteropUtilities.ToListFromIterator<hb_rate_s, int>(hbFunctions.hb_audio_bitrate_get_next, b => b.rate); } return audioBitrates; @@ -131,7 +138,7 @@ namespace HandBrake.Interop.Interop { if (audioSampleRates == null) { - audioSampleRates = InteropUtilities.ToListFromIterator<hb_rate_s, HBRate>(HBFunctions.hb_audio_samplerate_get_next, HandBrakeUnitConversionHelpers.NativeToRate); + audioSampleRates = InteropUtilities.ToListFromIterator<hb_rate_s, HBRate>(hbFunctions.hb_audio_samplerate_get_next, HandBrakeUnitConversionHelpers.NativeToRate); } return audioSampleRates; @@ -147,7 +154,7 @@ namespace HandBrake.Interop.Interop { if (containers == null) { - containers = InteropUtilities.ToListFromIterator<hb_container_s, HBContainer>(HBFunctions.hb_container_get_next, HandBrakeUnitConversionHelpers.NativeToContainer); + containers = InteropUtilities.ToListFromIterator<hb_container_s, HBContainer>(hbFunctions.hb_container_get_next, HandBrakeUnitConversionHelpers.NativeToContainer); } return containers; @@ -161,7 +168,7 @@ namespace HandBrake.Interop.Interop { get { - return HBFunctions.hb_subtitle_can_burn((int)hb_subtitle_s_subsource.IMPORTSRT) > 0; + return hbFunctions.hb_subtitle_can_burn((int)hb_subtitle_s_subsource.IMPORTSRT) > 0; } } @@ -172,7 +179,7 @@ namespace HandBrake.Interop.Interop { get { - return HBFunctions.hb_subtitle_can_burn((int)hb_subtitle_s_subsource.IMPORTSSA) > 0; + return hbFunctions.hb_subtitle_can_burn((int)hb_subtitle_s_subsource.IMPORTSSA) > 0; } } @@ -267,7 +274,7 @@ namespace HandBrake.Interop.Interop /// </returns> public static bool SubtitleCanSetForcedOnly(int source) { - return HBFunctions.hb_subtitle_can_force(source) > 0; + return hbFunctions.hb_subtitle_can_force(source) > 0; } /// <summary> @@ -281,7 +288,7 @@ namespace HandBrake.Interop.Interop /// </returns> public static bool SubtitleCanBurn(int source) { - return HBFunctions.hb_subtitle_can_burn(source) > 0; + return hbFunctions.hb_subtitle_can_burn(source) > 0; } /// <summary> @@ -298,7 +305,7 @@ namespace HandBrake.Interop.Interop /// </returns> public static bool SubtitleCanPassthrough(int subtitleSourceType, int muxer) { - return HBFunctions.hb_subtitle_can_pass(subtitleSourceType, muxer) > 0; + return hbFunctions.hb_subtitle_can_pass(subtitleSourceType, muxer) > 0; } /// <summary> @@ -370,7 +377,7 @@ namespace HandBrake.Interop.Interop /// </returns> public static bool MixdownHasRemixSupport(HBMixdown mixdown, ulong layout) { - return HBFunctions.hb_mixdown_has_remix_support(mixdown.Id, layout) > 0; + return hbFunctions.hb_mixdown_has_remix_support(mixdown.Id, layout) > 0; } /// <summary> @@ -387,7 +394,7 @@ namespace HandBrake.Interop.Interop /// </returns> public static bool MixdownHasCodecSupport(HBMixdown mixdown, HBAudioEncoder encoder) { - return HBFunctions.hb_mixdown_has_codec_support(mixdown.Id, (uint)encoder.Id) > 0; + return hbFunctions.hb_mixdown_has_codec_support(mixdown.Id, (uint)encoder.Id) > 0; } /// <summary> @@ -403,7 +410,7 @@ namespace HandBrake.Interop.Interop /// <returns>True if available.</returns> public static bool MixdownIsSupported(HBMixdown mixdown, HBAudioEncoder encoder, long channelLayout) { - return HBFunctions.hb_mixdown_is_supported(mixdown.Id, (uint)encoder.Id, (uint)channelLayout) > 0; + return hbFunctions.hb_mixdown_is_supported(mixdown.Id, (uint)encoder.Id, (uint)channelLayout) > 0; } /// <summary> @@ -423,7 +430,7 @@ namespace HandBrake.Interop.Interop /// </returns> public static bool CanApplyDrc(IntPtr handle, int trackNumber, HBAudioEncoder encoder, int title) { - return HBFunctions.hb_audio_can_apply_drc2(handle, title, trackNumber, encoder.Id) > 0; + return hbFunctions.hb_audio_can_apply_drc2(handle, title, trackNumber, encoder.Id) > 0; } /// <summary> @@ -462,7 +469,7 @@ namespace HandBrake.Interop.Interop return null; } - int sanitizedMixdown = HBFunctions.hb_mixdown_get_best((uint)encoder.Id, layout, mixdown.Id); + int sanitizedMixdown = hbFunctions.hb_mixdown_get_best((uint)encoder.Id, layout, mixdown.Id); if (sanitizedMixdown != -1) { return Mixdowns.Single(m => m.Id == sanitizedMixdown); @@ -485,7 +492,7 @@ namespace HandBrake.Interop.Interop /// </returns> public static HBMixdown GetDefaultMixdown(HBAudioEncoder encoder, ulong layout) { - int defaultMixdown = HBFunctions.hb_mixdown_get_default((uint)encoder.Id, layout); + int defaultMixdown = hbFunctions.hb_mixdown_get_default((uint)encoder.Id, layout); return Mixdowns.Single(m => m.Id == defaultMixdown); } @@ -497,7 +504,7 @@ namespace HandBrake.Interop.Interop /// <returns>The sanitized sample rate.</returns> public static int SanitizeSampleRate(HBAudioEncoder encoder, int sampleRate) { - return HBFunctions.hb_audio_samplerate_find_closest(sampleRate, (uint)encoder.Id); + return hbFunctions.hb_audio_samplerate_find_closest(sampleRate, (uint)encoder.Id); } /// <summary> @@ -520,7 +527,7 @@ namespace HandBrake.Interop.Interop int low = 0; int high = 0; - HBFunctions.hb_audio_bitrate_get_limits((uint)encoder.Id, sampleRate, mixdown.Id, ref low, ref high); + hbFunctions.hb_audio_bitrate_get_limits((uint)encoder.Id, sampleRate, mixdown.Id, ref low, ref high); return new BitrateLimits(low, high); } @@ -541,7 +548,7 @@ namespace HandBrake.Interop.Interop float granularity = 0; int direction = 0; - HBFunctions.hb_video_quality_get_limits((uint)encoder.Id, ref low, ref high, ref granularity, ref direction); + hbFunctions.hb_video_quality_get_limits((uint)encoder.Id, ref low, ref high, ref granularity, ref direction); return new VideoQualityLimits(low, high, granularity, direction == 0); } @@ -566,7 +573,7 @@ namespace HandBrake.Interop.Interop /// </returns> public static int SanitizeAudioBitrate(int audioBitrate, HBAudioEncoder encoder, int sampleRate, HBMixdown mixdown) { - return HBFunctions.hb_audio_bitrate_get_best((uint)encoder.Id, audioBitrate, sampleRate, mixdown.Id); + return hbFunctions.hb_audio_bitrate_get_best((uint)encoder.Id, audioBitrate, sampleRate, mixdown.Id); } /// <summary> @@ -586,7 +593,7 @@ namespace HandBrake.Interop.Interop /// </returns> public static int GetDefaultBitrate(HBAudioEncoder encoder, int sampleRate, HBMixdown mixdown) { - return HBFunctions.hb_audio_bitrate_get_default((uint)encoder.Id, sampleRate, mixdown.Id); + return hbFunctions.hb_audio_bitrate_get_default((uint)encoder.Id, sampleRate, mixdown.Id); } /// <summary> @@ -602,7 +609,7 @@ namespace HandBrake.Interop.Interop { float low = 0, high = 0, granularity = 0; int direction = 0; - HBFunctions.hb_audio_quality_get_limits((uint)encoderId, ref low, ref high, ref granularity, ref direction); + hbFunctions.hb_audio_quality_get_limits((uint)encoderId, ref low, ref high, ref granularity, ref direction); return new RangeLimits(direction == 0, granularity, high, low); } @@ -620,7 +627,7 @@ namespace HandBrake.Interop.Interop { float low = 0, high = 0, granularity = 0; int direction = 0; - HBFunctions.hb_audio_compression_get_limits((uint)encoderId, ref low, ref high, ref granularity, ref direction); + hbFunctions.hb_audio_compression_get_limits((uint)encoderId, ref low, ref high, ref granularity, ref direction); return new RangeLimits(direction == 0, granularity, high, low); } @@ -636,7 +643,7 @@ namespace HandBrake.Interop.Interop /// </returns> public static double GetDefaultQuality(HBAudioEncoder encoder) { - return HBFunctions.hb_audio_quality_get_default((uint)encoder.Id); + return hbFunctions.hb_audio_quality_get_default((uint)encoder.Id); } /// <summary> @@ -650,7 +657,7 @@ namespace HandBrake.Interop.Interop /// </returns> public static double GetDefaultAudioCompression(HBAudioEncoder encoder) { - return HBFunctions.hb_audio_compression_get_default((uint)encoder.Id); + return hbFunctions.hb_audio_compression_get_default((uint)encoder.Id); } } } |