]> granicus.if.org Git - handbrake/commitdiff
Interop: Added support for NL-Means denoise.
authorrandomengy <david.rickard@gmail.com>
Sun, 3 Aug 2014 04:33:09 +0000 (04:33 +0000)
committerrandomengy <david.rickard@gmail.com>
Sun, 3 Aug 2014 04:33:09 +0000 (04:33 +0000)
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6260 b64f7644-9d1e-0410-96f1-a4d463321fa5

win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj
win/CS/HandBrake.ApplicationServices/Model/Encoding/DenoisePreset.cs [moved from win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/DenoisePreset.cs with 91% similarity]
win/CS/HandBrake.ApplicationServices/Model/Encoding/DenoiseTune.cs [moved from win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/DenoiseTune.cs with 91% similarity]
win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs
win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInterop.csproj
win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/HbFunctions.cs
win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/hb_filter_ids.cs
win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoders.cs
win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/EncodingProfile.cs
win/CS/HandBrakeWPF/Converters/Filters/DenoisePresetConverter.cs
win/CS/HandBrakeWPF/ViewModels/FiltersViewModel.cs

index 0f082f0f3584a57567a4deceb2d1329abdd654eb..2a45218f33a376fec2a1502f0459b72c18c258e3 100644 (file)
     <Compile Include="LibHb\AudioVideoHelpers.cs" />\r
     <Compile Include="Model\Audio\AudioBehaviourModes.cs" />\r
     <Compile Include="Model\Audio\AudioBehaviours.cs" />\r
+    <Compile Include="Model\Encoding\DenoisePreset.cs" />\r
+    <Compile Include="Model\Encoding\DenoiseTune.cs" />\r
     <Compile Include="Model\HBConfiguration.cs" />\r
     <Compile Include="Model\Subtitle\SubtitleBehaviourModes.cs" />\r
     <Compile Include="Model\Subtitle\SubtitleBehaviours.cs" />\r
similarity index 91%
rename from win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/DenoisePreset.cs
rename to win/CS/HandBrake.ApplicationServices/Model/Encoding/DenoisePreset.cs
index b2663505217899b05cf7f7d3379e48f480ec5c0f..a411d19aef93417d68beaa3ebe5183065b03100d 100644 (file)
@@ -7,7 +7,7 @@
 // </summary>\r
 // --------------------------------------------------------------------------------------------------------------------\r
 \r
-namespace HandBrake.Interop.Model.Encoding\r
+namespace HandBrake.ApplicationServices.Model.Encoding\r
 {\r
     using System.ComponentModel.DataAnnotations;\r
 \r
similarity index 91%
rename from win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/DenoiseTune.cs
rename to win/CS/HandBrake.ApplicationServices/Model/Encoding/DenoiseTune.cs
index 35b5843a8899f65c12eb3eef0213cefb1abddb22..2fd13cfca66c4868071a6337c1ba034c2cff7b93 100644 (file)
@@ -7,7 +7,7 @@
 // </summary>\r
 // --------------------------------------------------------------------------------------------------------------------\r
 \r
-namespace HandBrake.Interop.Model.Encoding\r
+namespace HandBrake.ApplicationServices.Model.Encoding\r
 {\r
     using System.ComponentModel.DataAnnotations;\r
 \r
index 0e484794c5372548599d7ee2e3beab97207f1320..b08facbd292b7f894423d6ef494c4f294cb9ea1b 100644 (file)
@@ -1212,28 +1212,9 @@ namespace HandBrake.Interop
             // Denoise\r
             if (profile.Denoise != Denoise.Off)\r
             {\r
-                string settings = null;\r
-                switch (profile.DenoisePreset)\r
-                {\r
-                    case DenoisePreset.Weak:\r
-                        settings = "2:1:1:2:3:3";\r
-                        break;\r
-                    case DenoisePreset.Medium:\r
-                        settings = "3:2:2:2:3:3";\r
-                        break;\r
-                    case DenoisePreset.Strong:\r
-                        settings = "7:7:7:5:5:5";\r
-                        break;\r
-                    case DenoisePreset.Custom:\r
-                        settings = profile.CustomDenoise;\r
-                        break;\r
-                        // TODO Add new Presets.\r
-                    default:\r
-                        break;\r
-                }\r
+                   int filterType = profile.Denoise == Denoise.hqdn3d ? (int)hb_filter_ids.HB_FILTER_HQDN3D : (int)hb_filter_ids.HB_FILTER_NLMEANS;\r
 \r
-                // TODO Add Tunes\r
-                this.AddFilter(filterList, (int)hb_filter_ids.HB_FILTER_DENOISE, settings, allocatedMemory);\r
+                               this.AddFilterFromPreset(filterList, filterType, profile.DenoisePreset, profile.DenoiseTune);\r
             }\r
 \r
             // Crop/scale\r
@@ -1279,7 +1260,9 @@ namespace HandBrake.Interop
                     width = outputSize.Width;\r
                     height = outputSize.Height;\r
 \r
-                    nativeJob.anamorphic.keep_display_aspect = profile.KeepDisplayAspect ? 1 : 0;\r
+                    nativeJob.anamorphic.keep_display_aspect = 0;\r
+                                       nativeJob.anamorphic.par_width = 1;\r
+                                       nativeJob.anamorphic.par_height = 1;\r
 \r
                     nativeJob.width = width;\r
                     nativeJob.height = height;\r
@@ -1677,6 +1660,23 @@ namespace HandBrake.Interop
             filterList.Add(filter);\r
         }\r
 \r
+               /// <summary>\r
+               /// Adds a filter to the given filter list with the provided preset and tune.\r
+               /// </summary>\r
+               /// <param name="filterList">The list to add the filter to.</param>\r
+               /// <param name="filterType">The type of filter.</param>\r
+               /// <param name="preset">The preset name.</param>\r
+               /// <param name="tune">The tune name.</param>\r
+           private void AddFilterFromPreset(List<hb_filter_object_s> filterList, int filterType, string preset, string tune)\r
+           {\r
+                   IntPtr settingsPtr = HBFunctions.hb_generate_filter_settings(filterType, preset, tune);\r
+\r
+                       hb_filter_object_s filter = InteropUtilities.ToStructureFromPtr<hb_filter_object_s>(HBFunctions.hb_filter_init(filterType));\r
+                   filter.settings = settingsPtr;\r
+\r
+                       filterList.Add(filter);\r
+           }\r
+\r
         /// <summary>\r
         /// Converts the given filter list to a native list.\r
         /// </summary>\r
@@ -1777,12 +1777,16 @@ namespace HandBrake.Interop
 \r
                bool isPassthrough = encoder.IsPassthrough;\r
 \r
+               HBAudioEncoder inputCodec = Encoders.GetAudioEncoder((int)baseStruct.config.input.codec);\r
+\r
                uint outputCodec = (uint)encoder.Id;\r
                if (encoding.PassthroughIfPossible && \r
-                               encoder.Id == baseStruct.config.input.codec && \r
-                               (encoder.Id & NativeConstants.HB_ACODEC_PASS_MASK) > 0)\r
+                               (encoder.Id == baseStruct.config.input.codec || \r
+                                       inputCodec != null && (inputCodec.ShortName.ToLowerInvariant().Contains("aac") && encoder.ShortName.ToLowerInvariant().Contains("aac") ||\r
+                                       inputCodec.ShortName.ToLowerInvariant().Contains("mp3") && encoder.ShortName.ToLowerInvariant().Contains("mp3"))) &&\r
+                               (inputCodec.Id & NativeConstants.HB_ACODEC_PASS_MASK) > 0)\r
                {\r
-                       outputCodec |= NativeConstants.HB_ACODEC_PASS_FLAG;\r
+                               outputCodec = baseStruct.config.input.codec | NativeConstants.HB_ACODEC_PASS_FLAG;\r
                        isPassthrough = true;\r
                }\r
 \r
index a1f1b076b15e0d89d8e14dc260548300a8d55042..59d7835f3d10a3295f88257d854739ae536e0871 100644 (file)
     <Compile Include="HbLib\NativeConstants.cs" />\r
     <Compile Include="Interfaces\IHandBrakeInstance.cs" />\r
     <Compile Include="Helpers\InteropUtilities.cs" />\r
-    <Compile Include="Model\Encoding\DenoisePreset.cs" />\r
-    <Compile Include="Model\Encoding\DenoiseTune.cs" />\r
     <Compile Include="Model\Encoding\PictureRotation.cs" />\r
     <Compile Include="Model\Encoding\x265\x265Preset.cs" />\r
     <Compile Include="Model\Encoding\x265\x265Profile.cs" />\r
index 9402d094086f7eb082e365a22ec5f0a49671c9b8..cf8193f52eefe8a30d7e8a32092fd49dfdbc43a8 100644 (file)
@@ -444,6 +444,12 @@ namespace HandBrake.Interop.HbLib
                [DllImport("hb.dll", EntryPoint = "hb_filter_init", CallingConvention = CallingConvention.Cdecl)]\r
                public static extern IntPtr hb_filter_init(int filter_id);\r
 \r
+               [DllImport("hb.dll", EntryPoint = "hb_generate_filter_settings", CallingConvention = CallingConvention.Cdecl)]\r
+               public static extern IntPtr hb_generate_filter_settings(\r
+                       int filter_id,\r
+                       [In] [MarshalAs(UnmanagedType.LPStr)] string preset,\r
+                       [In] [MarshalAs(UnmanagedType.LPStr)] string tune);\r
+\r
                [DllImport("hb.dll", EntryPoint = "hb_x264_encopt_name", CallingConvention = CallingConvention.Cdecl)]\r
                public static extern IntPtr hb_x264_encopt_name(IntPtr name);\r
 \r
index 3c56b7f75ae5366267bfd073eb2424c2290a1056..90b60d846a925790b5cc00df1974e1429b5be556 100644 (file)
@@ -17,7 +17,8 @@ namespace HandBrake.Interop.HbLib
                HB_FILTER_VFR,\r
                // Filters that must operate on the original source image are next\r
                HB_FILTER_DEBLOCK,\r
-               HB_FILTER_DENOISE,\r
+               HB_FILTER_HQDN3D,\r
+               HB_FILTER_NLMEANS,\r
                HB_FILTER_RENDER_SUB,\r
                HB_FILTER_CROP_SCALE,\r
                // Finally filters that don't care what order they are in,\r
index f27fad285db6a68bc395356f82af690ad423685e..295586c8f955264dd7d76c123912a930c2b54830 100644 (file)
@@ -200,6 +200,16 @@ namespace HandBrake.Interop.Model
                        return AudioEncoders.SingleOrDefault(e => e.ShortName == shortName);\r
                }\r
 \r
+               /// <summary>\r
+               /// Gets the audio encoder with the specified codec ID.\r
+               /// </summary>\r
+               /// <param name="codecId">The ID of the audio encoder.</param>\r
+               /// <returns>The requested audio encoder.</returns>\r
+               public static HBAudioEncoder GetAudioEncoder(int codecId)\r
+               {\r
+                       return AudioEncoders.SingleOrDefault(e => e.Id == codecId);\r
+               }\r
+\r
                /// <summary>\r
                /// Gets the video encoder with the specified short name.\r
                /// </summary>\r
@@ -275,6 +285,16 @@ namespace HandBrake.Interop.Model
                        return HBFunctions.hb_audio_can_apply_drc(track.CodecId, track.CodecParam, encoder.Id) > 0;\r
                }\r
 \r
+               /// <summary>\r
+               /// Determines if the given input audio codec can be passed through.\r
+               /// </summary>\r
+               /// <param name="codecId">The input codec to consider.</param>\r
+               /// <returns>True if the codec can be passed through.</returns>\r
+               public static bool CanPassthroughAudio(int codecId)\r
+               {\r
+                       return (codecId & NativeConstants.HB_ACODEC_PASS_MASK) > 0;\r
+               }\r
+\r
                /// <summary>\r
                /// Sanitizes a mixdown given the output codec and input channel layout.\r
                /// </summary>\r
index 834ef5576014b984392ee3175ee27da79b87d44b..bcabcf282d864ef06262a4b2454fb824bdc5f8d5 100644 (file)
@@ -185,14 +185,20 @@ namespace HandBrake.Interop.Model.Encoding
         public Denoise Denoise { get; set; }\r
 \r
         /// <summary>\r
-        /// Gets or sets the denoise preset.\r
+        /// Gets or sets the denoise preset name.\r
         /// </summary>\r
-        public DenoisePreset DenoisePreset { get; set; }\r
+        public string DenoisePreset { get; set; }\r
 \r
         /// <summary>\r
-        /// Gets or sets the denoise tune.\r
+        /// Gets or sets the denoise tune name.\r
         /// </summary>\r
-        public DenoiseTune DenoiseTune { get; set; }\r
+        public string DenoiseTune { get; set; }\r
+\r
+               /// <summary>\r
+               /// Gets or sets a value indicating whether we should use the provided\r
+               /// custom denoise string or we should use the preset and tune.\r
+               /// </summary>\r
+               public bool UseCustomDenoise { get; set; }\r
 \r
         /// <summary>\r
         /// Gets or sets the custom denoise.\r
@@ -343,6 +349,9 @@ namespace HandBrake.Interop.Model.Encoding
                 Detelecine = this.Detelecine,\r
                 CustomDetelecine = this.CustomDetelecine,\r
                 Denoise = this.Denoise,\r
+                               DenoisePreset = this.DenoisePreset,\r
+                               DenoiseTune = this.DenoiseTune,\r
+                               UseCustomDenoise = this.UseCustomDenoise,\r
                 CustomDenoise = this.CustomDenoise,\r
                 Deblock = this.Deblock,\r
                 Grayscale = this.Grayscale,\r
index bb0ec1b7e3d95a4623bdc76d89f56dc75859e624..58576d747d9d44b9652dfef2d862816348ed8aab 100644 (file)
@@ -15,6 +15,7 @@ namespace HandBrakeWPF.Converters.Filters
     using System.Linq;\r
     using System.Windows.Data;\r
 \r
+    using HandBrake.ApplicationServices.Model.Encoding;\r
     using HandBrake.Interop.Model.Encoding;\r
 \r
     /// <summary>\r
index 70921b23f9d061f9c35d83dad0f96492fa18ad22..5fdeb9c4480730a7bedbf660f65dafd43e7f0d54 100644 (file)
@@ -15,6 +15,7 @@ namespace HandBrakeWPF.ViewModels
     using Caliburn.Micro;\r
 \r
     using HandBrake.ApplicationServices.Model;\r
+    using HandBrake.ApplicationServices.Model.Encoding;\r
     using HandBrake.ApplicationServices.Parsing;\r
     using HandBrake.ApplicationServices.Utilities;\r
     using HandBrake.Interop.Model.Encoding;\r