]> granicus.if.org Git - handbrake/commitdiff
WinGui: Initial implementation of the new JSON API for encoding. Not exposed to end...
authorsr55 <sr55.hb@outlook.com>
Fri, 26 Dec 2014 22:26:22 +0000 (22:26 +0000)
committersr55 <sr55.hb@outlook.com>
Fri, 26 Dec 2014 22:26:22 +0000 (22:26 +0000)
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6654 b64f7644-9d1e-0410-96f1-a4d463321fa5

22 files changed:
win/CS/HandBrake.ApplicationServices/Services/Encode/EventArgs/EncodeProgressEventArgs.cs
win/CS/HandBrake.Interop/HandBrakeInterop/EventArgs/EncodeProgressEventArgs.cs
win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs
win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInterop.csproj
win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeUtils.cs
win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/HbFunctions.cs
win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/hb_audio.cs [deleted file]
win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/hb_chapter_s.cs [deleted file]
win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/hb_error_code.cs
win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/hb_filter_object_s.cs [deleted file]
win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/hb_subtitle.cs
win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/hb_title_s.cs
win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/hb_title_set_s.cs [deleted file]
win/CS/HandBrake.Interop/HandBrakeInterop/Interfaces/IHandBrakeInstance.cs
win/CS/HandBrake.Interop/HandBrakeInterop/Json/Anamorphic/AnamorphicGeometry.cs
win/CS/HandBrake.Interop/HandBrakeInterop/Json/Anamorphic/DestSettings.cs
win/CS/HandBrake.Interop/HandBrakeInterop/Json/Encode/JsonEncodeObject.cs
win/CS/HandBrake.Interop/HandBrakeInterop/Json/Factories/AnamorphicFactory.cs [new file with mode: 0644]
win/CS/HandBrake.Interop/HandBrakeInterop/Json/Factories/EncodeFactory.cs
win/CS/HandBrake.Interop/HandBrakeInterop/Json/Factories/ScanFactory.cs
win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/Anamorphic.cs
win/CS/HandBrake.Interop/HandBrakeInterop/Model/Scan/Chapter.cs

index 1b93434dae8aa5cdde038e826ad3af210a8002ae..87d7775253786452d153ea352e3348fad68d9e51 100644 (file)
@@ -22,19 +22,19 @@ namespace HandBrake.ApplicationServices.Services.Encode.EventArgs
         /// Gets or sets PercentComplete.\r
         /// </summary>\r
         [DataMember]\r
-        public float PercentComplete { get; set; }\r
+        public double PercentComplete { get; set; }\r
 \r
         /// <summary>\r
         /// Gets or sets CurrentFrameRate.\r
         /// </summary>\r
         [DataMember]\r
-        public float CurrentFrameRate { get; set; }\r
+        public double CurrentFrameRate { get; set; }\r
 \r
         /// <summary>\r
         /// Gets or sets AverageFrameRate.\r
         /// </summary>\r
         [DataMember]\r
-        public float AverageFrameRate { get; set; }\r
+        public double AverageFrameRate { get; set; }\r
 \r
         /// <summary>\r
         /// Gets or sets EstimatedTimeLeft.\r
index 9e2883e3b8d716f9c37ff1f976484fbb250006bd..9118ddd7a7f6a5c9694632b1ca89e1eed78d3f59 100644 (file)
@@ -19,17 +19,17 @@ namespace HandBrake.Interop.EventArgs
            /// <summary>\r
            /// Gets or sets FractionComplete.\r
            /// </summary>\r
-           public float FractionComplete { get; set; }\r
+        public double FractionComplete { get; set; }\r
 \r
            /// <summary>\r
            /// Gets or sets CurrentFrameRate.\r
            /// </summary>\r
-           public float CurrentFrameRate { get; set; }\r
+        public double CurrentFrameRate { get; set; }\r
 \r
            /// <summary>\r
            /// Gets or sets AverageFrameRate.\r
            /// </summary>\r
-           public float AverageFrameRate { get; set; }\r
+        public double AverageFrameRate { get; set; }\r
 \r
            /// <summary>\r
            /// Gets or sets EstimatedTimeLeft.\r
index b67c26a4efe058da886fc25e80020f1bd9ebff36..9febb93c083361ba695fb9d15105d619a55ae641 100644 (file)
@@ -26,6 +26,7 @@ namespace HandBrake.Interop
     using HandBrake.Interop.HbLib;\r
     using HandBrake.Interop.Helpers;\r
     using HandBrake.Interop.Interfaces;\r
+    using HandBrake.Interop.Json.Encode;\r
     using HandBrake.Interop.Json.Factories;\r
     using HandBrake.Interop.Json.Scan;\r
     using HandBrake.Interop.Json.State;\r
@@ -42,11 +43,6 @@ namespace HandBrake.Interop
     /// </summary>\r
     public class HandBrakeInstance : IHandBrakeInstance, IDisposable\r
     {\r
-        /// <summary>\r
-        /// The modulus for picture size when auto-sizing dimensions.\r
-        /// </summary>\r
-        private const int PictureAutoSizeModulus = 2;\r
-\r
         /// <summary>\r
         /// The number of MS between status polls when scanning.\r
         /// </summary>\r
@@ -57,11 +53,6 @@ namespace HandBrake.Interop
         /// </summary>\r
         private const double EncodePollIntervalMs = 200;\r
 \r
-        /// <summary>\r
-        /// X264 options to add for a turbo first pass.\r
-        /// </summary>\r
-        private const string TurboX264Opts = "ref=1:subme=2:me=dia:analyse=none:trellis=0:no-fast-pskip=0:8x8dct=0:weightb=0";\r
-\r
         /// <summary>\r
         /// The native handle to the HandBrake instance.\r
         /// </summary>\r
@@ -82,36 +73,16 @@ namespace HandBrake.Interop
         /// </summary>\r
         private Timer encodePollTimer;\r
 \r
-        /// <summary>\r
-        /// The list of original titles in native structure form.\r
-        /// </summary>\r
-        private List<hb_title_s> originalTitles;\r
-\r
         /// <summary>\r
         /// The list of titles on this instance.\r
         /// </summary>\r
         private List<Title> titles;\r
 \r
-        /// <summary>\r
-        /// The current encode job for this instance.\r
-        /// </summary>\r
-        private EncodeJob currentJob;\r
-\r
-        /// <summary>\r
-        /// True if the current job is scanning for subtitles.\r
-        /// </summary>\r
-        private bool subtitleScan;\r
-\r
         /// <summary>\r
         /// The index of the default title.\r
         /// </summary>\r
         private int featureTitle;\r
 \r
-        /// <summary>\r
-        /// A list of native memory locations allocated by this instance.\r
-        /// </summary>\r
-        private List<IntPtr> encodeAllocatedMemory;\r
-\r
         /// <summary>\r
         /// A value indicating whether this object has been disposed or not.\r
         /// </summary>\r
@@ -295,39 +266,48 @@ namespace HandBrake.Interop
         /// <returns>An image with the requested preview.</returns>\r
         public BitmapImage GetPreview(EncodeJob job, int previewNumber)\r
         {\r
-            IntPtr nativeJobPtr = HBFunctions.hb_job_init_by_index(this.hbHandle, this.GetTitleIndex(job.Title));\r
-            var nativeJob = InteropUtilities.ToStructureFromPtr<hb_job_s>(nativeJobPtr);\r
 \r
-            List<IntPtr> allocatedMemory = this.ApplyJob(ref nativeJob, job);\r
+            Title title = this.Titles.FirstOrDefault(t => t.TitleNumber == job.Title);\r
+            Validate.NotNull(title, "GetPreview: Title should not have been null. This is probably a bug.");\r
+\r
+            hb_geometry_settings_s uiGeometry = new hb_geometry_settings_s\r
+            {\r
+                crop = new[] { job.EncodingProfile.Cropping.Top, job.EncodingProfile.Cropping.Bottom, job.EncodingProfile.Cropping.Left, job.EncodingProfile.Cropping.Right },\r
+                itu_par = 0,\r
+                keep = (int)AnamorphicFactory.KeepSetting.HB_KEEP_WIDTH + (job.EncodingProfile.KeepDisplayAspect ? 0x04 : 0), // TODO Keep Width?\r
+                maxWidth = job.EncodingProfile.MaxWidth,\r
+                maxHeight = job.EncodingProfile.MaxHeight,\r
+                mode = (int)(hb_anamorphic_mode_t)job.EncodingProfile.Anamorphic,\r
+                modulus = job.EncodingProfile.Modulus,\r
+                geometry = new hb_geometry_s { height = job.EncodingProfile.Height, width = job.EncodingProfile.Width, \r
+                    par = job.EncodingProfile.Anamorphic != Anamorphic.Custom \r
+                        ? new hb_rational_t { den = title.ParVal.Height, num = title.ParVal.Width }\r
+                        : new hb_rational_t { den = job.EncodingProfile.PixelAspectY, num = job.EncodingProfile.PixelAspectX } }\r
+            };\r
+\r
+            // Sanatise the input.\r
+           Json.Anamorphic.Geometry resultGeometry = AnamorphicFactory.CreateGeometry(job, title, AnamorphicFactory.KeepSetting.HB_KEEP_WIDTH); // TODO this keep isn't right.\r
 \r
-            // There are some problems with getting previews with deinterlacing. Disabling for now.\r
-            nativeJob.deinterlace = 0;\r
+           int outputWidth = resultGeometry.Width;\r
+           int outputHeight = resultGeometry.Height;\r
+           int imageBufferSize = outputWidth * outputHeight * 4;\r
+           IntPtr nativeBuffer = Marshal.AllocHGlobal(imageBufferSize);\r
 \r
-            int outputWidth = nativeJob.width;\r
-            int outputHeight = nativeJob.height;\r
-            int imageBufferSize = outputWidth * outputHeight * 4;\r
-            IntPtr nativeBuffer = Marshal.AllocHGlobal(imageBufferSize);\r
-            allocatedMemory.Add(nativeBuffer);\r
-            HBFunctions.hb_get_preview(this.hbHandle, ref nativeJob, previewNumber, nativeBuffer);\r
 \r
-            // We've used the job to get the preview. Clean up the job.\r
-            InteropUtilities.CloseJob(nativeJobPtr);\r
+            HBFunctions.hb_get_preview2(this.hbHandle, job.Title, previewNumber, ref uiGeometry, 0);\r
 \r
             // Copy the filled image buffer to a managed array.\r
             byte[] managedBuffer = new byte[imageBufferSize];\r
             Marshal.Copy(nativeBuffer, managedBuffer, 0, imageBufferSize);\r
 \r
-            // We've copied the data out of unmanaged memory. Clean up that memory now.\r
-            InteropUtilities.FreeMemory(allocatedMemory);\r
-\r
             var bitmap = new Bitmap(outputWidth, outputHeight);\r
             BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, outputWidth, outputHeight), ImageLockMode.WriteOnly, PixelFormat.Format32bppRgb);\r
 \r
             IntPtr ptr = bitmapData.Scan0;\r
 \r
-            for (int i = 0; i < nativeJob.height; i++)\r
+            for (int i = 0; i < job.EncodingProfile.Height; i++)\r
             {\r
-                Marshal.Copy(managedBuffer, i * nativeJob.width * 4, ptr, nativeJob.width * 4);\r
+                Marshal.Copy(managedBuffer, i * job.EncodingProfile.Width * 4, ptr, job.EncodingProfile.Width * 4);\r
                 ptr = IntPtr.Add(ptr, bitmapData.Stride);\r
             }\r
 \r
@@ -458,138 +438,28 @@ namespace HandBrake.Interop
         /// <summary>\r
         /// Starts an encode with the given job.\r
         /// </summary>\r
-        /// <param name="job">\r
-        /// The job to start.\r
-        /// </param>\r
-        /// <param name="preview">\r
-        /// True if this is a preview encode.\r
-        /// </param>\r
-        /// <param name="previewNumber">\r
-        /// The preview number to start the encode at (0-based).\r
-        /// </param>\r
-        /// <param name="previewSeconds">\r
-        /// The number of seconds in the preview.\r
-        /// </param>\r
-        /// <param name="overallSelectedLengthSeconds">\r
-        /// The currently selected encode length. Used in preview\r
-        /// for calculating bitrate when the target size would be wrong.\r
-        /// </param>\r
-        /// <param name="scanPreviewCount">\r
-        /// The scan Preview Count.\r
-        /// </param>\r
+        /// <param name="job">The job to start.</param>\r
+        /// <param name="preview">The scan Preview Count.</param>\r
+        /// <param name="previewNumber">Preview Feature: Preview to encode</param>\r
+        /// <param name="previewSeconds">Number of seconds to encode for the preview</param>\r
+        /// <param name="overallSelectedLengthSeconds"></param>\r
+        /// <param name="scanPreviewCount">Number of previews</param>\r
         public void StartEncode(EncodeJob job, bool preview, int previewNumber, int previewSeconds, double overallSelectedLengthSeconds, int scanPreviewCount)\r
         {\r
-            EncodingProfile profile = job.EncodingProfile;\r
-            if (job.ChosenAudioTracks == null)\r
-            {\r
-                throw new ArgumentException("job.ChosenAudioTracks cannot be null.");\r
-            }\r
-\r
             this.previewCount = scanPreviewCount;\r
-            this.currentJob = job;\r
-\r
-            IntPtr nativeJobPtr = HBFunctions.hb_job_init_by_index(this.hbHandle, this.GetTitleIndex(job.Title));\r
-            var nativeJob = InteropUtilities.ToStructureFromPtr<hb_job_s>(nativeJobPtr);\r
-\r
-            this.encodeAllocatedMemory = this.ApplyJob(ref nativeJob, job, preview, previewNumber, previewSeconds, overallSelectedLengthSeconds);\r
-\r
-            this.subtitleScan = false;\r
-            if (job.Subtitles != null && job.Subtitles.SourceSubtitles != null)\r
-            {\r
-                foreach (SourceSubtitle subtitle in job.Subtitles.SourceSubtitles)\r
-                {\r
-                    if (subtitle.TrackNumber == 0)\r
-                    {\r
-                        this.subtitleScan = true;\r
-                        break;\r
-                    }\r
-                }\r
-            }\r
-\r
-            string videoOptions = profile.VideoOptions ?? string.Empty;\r
-            IntPtr originalVideoOptions = Marshal.StringToHGlobalAnsi(videoOptions);\r
-            this.encodeAllocatedMemory.Add(originalVideoOptions);\r
-\r
-            if (!string.IsNullOrEmpty(profile.VideoProfile))\r
-            {\r
-                nativeJob.encoder_profile = Marshal.StringToHGlobalAnsi(profile.VideoProfile);\r
-                this.encodeAllocatedMemory.Add(nativeJob.encoder_profile);\r
-            }\r
-\r
-            if (!string.IsNullOrEmpty(profile.VideoPreset))\r
-            {\r
-                nativeJob.encoder_preset = Marshal.StringToHGlobalAnsi(profile.VideoPreset);\r
-                this.encodeAllocatedMemory.Add(nativeJob.encoder_preset);\r
-            }\r
-\r
-            if (profile.VideoTunes != null && profile.VideoTunes.Count > 0)\r
-            {\r
-                nativeJob.encoder_tune = Marshal.StringToHGlobalAnsi(string.Join(",", profile.VideoTunes));\r
-                this.encodeAllocatedMemory.Add(nativeJob.encoder_tune);\r
-            }\r
-\r
-            if (!string.IsNullOrEmpty(job.EncodingProfile.VideoLevel))\r
-            {\r
-                nativeJob.encoder_level = Marshal.StringToHGlobalAnsi(job.EncodingProfile.VideoLevel);\r
-                this.encodeAllocatedMemory.Add(nativeJob.encoder_level);\r
-            }\r
 \r
-            if (this.subtitleScan)\r
-            {\r
-                // If we need to scan subtitles, enqueue a pre-processing job to do that.\r
-                nativeJob.pass = -1;\r
-                nativeJob.indepth_scan = 1;\r
-\r
-                nativeJob.encoder_options = IntPtr.Zero;\r
-\r
-                HBFunctions.hb_add(this.hbHandle, ref nativeJob);\r
-            }\r
+            JsonEncodeObject encodeObject = EncodeFactory.Create(job, lastScan);\r
 \r
-            nativeJob.indepth_scan = 0;\r
-\r
-            if (job.EncodingProfile.VideoEncodeRateType != VideoEncodeRateType.ConstantQuality && job.EncodingProfile.TwoPass)\r
+            JsonSerializerSettings settings = new JsonSerializerSettings\r
             {\r
-                // First pass. Apply turbo options if needed.\r
-                nativeJob.pass = 1;\r
-                string firstPassAdvancedOptions = videoOptions;\r
-                if (job.EncodingProfile.TurboFirstPass)\r
-                {\r
-                    if (firstPassAdvancedOptions == string.Empty)\r
-                    {\r
-                        firstPassAdvancedOptions = TurboX264Opts;\r
-                    }\r
-                    else\r
-                    {\r
-                        firstPassAdvancedOptions += ":" + TurboX264Opts;\r
-                    }\r
-                }\r
-\r
-                nativeJob.encoder_options = Marshal.StringToHGlobalAnsi(firstPassAdvancedOptions);\r
-                this.encodeAllocatedMemory.Add(nativeJob.encoder_options);\r
-\r
-                HBFunctions.hb_add(this.hbHandle, ref nativeJob);\r
-\r
-                // Second pass. Apply normal options.\r
-                nativeJob.pass = 2;\r
-                nativeJob.encoder_options = originalVideoOptions;\r
-\r
-                HBFunctions.hb_add(this.hbHandle, ref nativeJob);\r
-            }\r
-            else\r
-            {\r
-                // One pass job.\r
-                nativeJob.pass = 0;\r
-                nativeJob.encoder_options = originalVideoOptions;\r
-\r
-                HBFunctions.hb_add(this.hbHandle, ref nativeJob);\r
-            }\r
+                NullValueHandling = NullValueHandling.Ignore\r
+            };\r
 \r
+            string encode = JsonConvert.SerializeObject(encodeObject, Formatting.Indented, settings);\r
+            HBFunctions.hb_add_json(this.hbHandle, Marshal.StringToHGlobalAnsi(encode));\r
             HBFunctions.hb_start(this.hbHandle);\r
 \r
-            // Should be safe to clean up the job we started with; a copy is in the queue now.\r
-            InteropUtilities.CloseJob(nativeJobPtr);\r
-\r
-            this.encodePollTimer = new Timer();\r
+            this.encodePollTimer = new System.Timers.Timer();\r
             this.encodePollTimer.Interval = EncodePollIntervalMs;\r
 \r
             this.encodePollTimer.Elapsed += (o, e) =>\r
@@ -637,49 +507,6 @@ namespace HandBrake.Interop
             }\r
         }\r
 \r
-        /// <summary>\r
-        /// Gets the final size for a given encode job.\r
-        /// </summary>\r
-        /// <param name="job">The encode job to use.</param>\r
-        /// <param name="width">The storage width.</param>\r
-        /// <param name="height">The storage height.</param>\r
-        /// <param name="parWidth">The pixel aspect X number.</param>\r
-        /// <param name="parHeight">The pixel aspect Y number.</param>\r
-        public void GetSize(EncodeJob job, out int width, out int height, out int parWidth, out int parHeight)\r
-        {\r
-            Title title = this.GetTitle(job.Title);\r
-\r
-            if (job.EncodingProfile.Anamorphic == Anamorphic.None)\r
-            {\r
-                Size storageDimensions = CalculateNonAnamorphicOutput(job.EncodingProfile, title);\r
-\r
-                width = storageDimensions.Width;\r
-                height = storageDimensions.Height;\r
-\r
-                parWidth = 1;\r
-                parHeight = 1;\r
-\r
-                return;\r
-            }\r
-\r
-            IntPtr nativeJobPtr = HBFunctions.hb_job_init_by_index(this.hbHandle, this.GetTitleIndex(title));\r
-            var nativeJob = InteropUtilities.ToStructureFromPtr<hb_job_s>(nativeJobPtr);\r
-\r
-            List<IntPtr> allocatedMemory = this.ApplyJob(ref nativeJob, job);\r
-            InteropUtilities.FreeMemory(allocatedMemory);\r
-\r
-            InteropUtilities.CloseJob(nativeJobPtr);\r
-\r
-            // During the ApplyJob call, it modified nativeJob to have the correct width, height and PAR.\r
-            // We use those for the size.\r
-            width = nativeJob.width;\r
-            height = nativeJob.height;\r
-            parWidth = nativeJob.anamorphic.par_width;\r
-            parHeight = nativeJob.anamorphic.par_height;\r
-        }\r
-\r
-\r
-\r
         /// <summary>\r
         /// Frees any resources associated with this object.\r
         /// </summary>\r
@@ -714,104 +541,6 @@ namespace HandBrake.Interop
             this.disposed = true;\r
         }\r
 \r
-        /// <summary>\r
-        /// Calculates the output size for a non-anamorphic job.\r
-        /// </summary>\r
-        /// <param name="profile">The encoding profile for the job.</param>\r
-        /// <param name="title">The title being encoded.</param>\r
-        /// <returns>The dimensions of the final encode.</returns>\r
-        private static Size CalculateNonAnamorphicOutput(EncodingProfile profile, Title title)\r
-        {\r
-            int sourceWidth = title.Resolution.Width;\r
-            int sourceHeight = title.Resolution.Height;\r
-\r
-            int width = profile.Width;\r
-            int height = profile.Height;\r
-\r
-            Cropping crop;\r
-            switch (profile.CroppingType)\r
-            {\r
-                case CroppingType.Automatic:\r
-                    crop = title.AutoCropDimensions;\r
-                    break;\r
-                case CroppingType.Custom:\r
-                    crop = profile.Cropping;\r
-                    break;\r
-                default:\r
-                    crop = new Cropping();\r
-                    break;\r
-            }\r
-\r
-            sourceWidth -= crop.Left;\r
-            sourceWidth -= crop.Right;\r
-\r
-            sourceHeight -= crop.Top;\r
-            sourceHeight -= crop.Bottom;\r
-\r
-            double croppedAspectRatio = ((double)sourceWidth * title.ParVal.Width) / (sourceHeight * title.ParVal.Height);\r
-\r
-            if (width == 0)\r
-            {\r
-                width = sourceWidth;\r
-            }\r
-\r
-            if (profile.MaxWidth > 0 && width > profile.MaxWidth)\r
-            {\r
-                width = profile.MaxWidth;\r
-            }\r
-\r
-            if (height == 0)\r
-            {\r
-                height = sourceHeight;\r
-            }\r
-\r
-            if (profile.MaxHeight > 0 && height > profile.MaxHeight)\r
-            {\r
-                height = profile.MaxHeight;\r
-            }\r
-\r
-            if (profile.KeepDisplayAspect)\r
-            {\r
-                if ((profile.Width == 0 && profile.Height == 0) || profile.Width == 0)\r
-                {\r
-                    width = (int)((double)height * croppedAspectRatio);\r
-                    if (profile.MaxWidth > 0 && width > profile.MaxWidth)\r
-                    {\r
-                        width = profile.MaxWidth;\r
-                        height = (int)((double)width / croppedAspectRatio);\r
-                        height = GetNearestValue(height, PictureAutoSizeModulus);\r
-                    }\r
-\r
-                    width = GetNearestValue(width, PictureAutoSizeModulus);\r
-                }\r
-                else if (profile.Height == 0)\r
-                {\r
-                    height = (int)((double)width / croppedAspectRatio);\r
-                    if (profile.MaxHeight > 0 && height > profile.MaxHeight)\r
-                    {\r
-                        height = profile.MaxHeight;\r
-                        width = (int)((double)height * croppedAspectRatio);\r
-                        width = GetNearestValue(width, PictureAutoSizeModulus);\r
-                    }\r
-\r
-                    height = GetNearestValue(height, PictureAutoSizeModulus);\r
-                }\r
-            }\r
-\r
-            return new Size(width, height);\r
-        }\r
-\r
-        /// <summary>\r
-        /// Gets the closest value to the given number divisible by the given modulus.\r
-        /// </summary>\r
-        /// <param name="number">The number to approximate.</param>\r
-        /// <param name="modulus">The modulus.</param>\r
-        /// <returns>The closest value to the given number divisible by the given modulus.</returns>\r
-        private static int GetNearestValue(int number, int modulus)\r
-        {\r
-            return modulus * ((number + modulus / 2) / modulus);\r
-        }\r
-\r
         /// <summary>\r
         /// Checks the status of the ongoing scan.\r
         /// </summary>\r
@@ -839,7 +568,6 @@ namespace HandBrake.Interop
             {\r
                 this.titles = new List<Title>();\r
 \r
-                IntPtr titleSetPtr = HBFunctions.hb_get_title_set(this.hbHandle);\r
                 var jsonMsg = HBFunctions.hb_get_title_set_json(this.hbHandle);\r
                 string scanJson = Marshal.PtrToStringAnsi(jsonMsg);\r
                 JsonScanObject scanObject = JsonConvert.DeserializeObject<JsonScanObject>(scanJson);\r
@@ -858,9 +586,6 @@ namespace HandBrake.Interop
                     this.titles.Add(title);\r
                 }\r
 \r
-                hb_title_set_s titleSet = InteropUtilities.ToStructureFromPtr<hb_title_set_s>(titleSetPtr);\r
-                this.originalTitles = titleSet.list_title.ToListFromHandBrakeList<hb_title_s>();\r
-\r
                 this.scanPollTimer.Stop();\r
 \r
                 if (this.ScanCompleted != null)\r
@@ -870,745 +595,46 @@ namespace HandBrake.Interop
             }\r
         }\r
 \r
+        /// <summary>\r
+        /// Checks the status of the ongoing encode.\r
+        /// </summary>\r
         /// <summary>\r
         /// Checks the status of the ongoing encode.\r
         /// </summary>\r
         private void PollEncodeProgress()\r
         {\r
-            hb_state_s state = new hb_state_s();\r
-            HBFunctions.hb_get_state(this.hbHandle, ref state);\r
+            IntPtr json = HBFunctions.hb_get_state_json(this.hbHandle);\r
+            string statusJson = Marshal.PtrToStringAnsi(json);\r
+            JsonState state = JsonConvert.DeserializeObject<JsonState>(statusJson);\r
 \r
-            if (state.state == NativeConstants.HB_STATE_WORKING)\r
+            if (state.State == NativeConstants.HB_STATE_WORKING)\r
             {\r
                 if (this.EncodeProgress != null)\r
                 {\r
-                    int pass = 1;\r
-                    int rawJobNumber = state.param.working.job_cur;\r
-\r
-                    if (this.currentJob.EncodingProfile.VideoEncodeRateType != VideoEncodeRateType.ConstantQuality && this.currentJob.EncodingProfile.TwoPass)\r
-                    {\r
-                        if (this.subtitleScan)\r
-                        {\r
-                            switch (rawJobNumber)\r
-                            {\r
-                                case 1:\r
-                                    pass = -1;\r
-                                    break;\r
-                                case 2:\r
-                                    pass = 1;\r
-                                    break;\r
-                                case 3:\r
-                                    pass = 2;\r
-                                    break;\r
-                                default:\r
-                                    break;\r
-                            }\r
-                        }\r
-                        else\r
-                        {\r
-                            switch (rawJobNumber)\r
-                            {\r
-                                case 1:\r
-                                    pass = 1;\r
-                                    break;\r
-                                case 2:\r
-                                    pass = 2;\r
-                                    break;\r
-                                default:\r
-                                    break;\r
-                            }\r
-                        }\r
-                    }\r
-                    else\r
-                    {\r
-                        if (this.subtitleScan)\r
-                        {\r
-                            switch (rawJobNumber)\r
-                            {\r
-                                case 1:\r
-                                    pass = -1;\r
-                                    break;\r
-                                case 2:\r
-                                    pass = 1;\r
-                                    break;\r
-                                default:\r
-                                    break;\r
-                            }\r
-                        }\r
-                        else\r
-                        {\r
-                            pass = 1;\r
-                        }\r
-                    }\r
-\r
                     var progressEventArgs = new EncodeProgressEventArgs\r
                     {\r
-                        FractionComplete = state.param.working.progress,\r
-                        CurrentFrameRate = state.param.working.rate_cur,\r
-                        AverageFrameRate = state.param.working.rate_avg,\r
-                        EstimatedTimeLeft = new TimeSpan(state.param.working.hours, state.param.working.minutes, state.param.working.seconds),\r
-                        Pass = pass\r
+                        FractionComplete = state.Working.Progress,\r
+                        CurrentFrameRate = state.Working.Rate,\r
+                        AverageFrameRate = state.Working.RateAvg,\r
+                        EstimatedTimeLeft = new TimeSpan(state.Working.Hours, state.Working.Minutes, state.Working.Seconds),\r
+                        Pass = 1, // TODO\r
                     };\r
 \r
                     this.EncodeProgress(this, progressEventArgs);\r
                 }\r
             }\r
-            else if (state.state == NativeConstants.HB_STATE_WORKDONE)\r
+            else if (state.State == NativeConstants.HB_STATE_WORKDONE)\r
             {\r
-                InteropUtilities.FreeMemory(this.encodeAllocatedMemory);\r
                 this.encodePollTimer.Stop();\r
 \r
-                               if (this.EncodeCompleted != null)\r
-                               {\r
-                                       this.EncodeCompleted(this, new EncodeCompletedEventArgs { Error = state.param.workdone.error != hb_error_code.HB_ERROR_NONE });\r
-                               }\r
-            }\r
-        }\r
-\r
-        /// <summary>\r
-        /// Applies the encoding job to the native memory structure and returns a list of memory\r
-        /// locations allocated during this.\r
-        /// </summary>\r
-        /// <param name="nativeJob">The native structure to apply to job info to.</param>\r
-        /// <param name="job">The job info to apply.</param>\r
-        /// <returns>The list of memory locations allocated for the job.</returns>\r
-        private List<IntPtr> ApplyJob(ref hb_job_s nativeJob, EncodeJob job)\r
-        {\r
-            return this.ApplyJob(ref nativeJob, job, false, 0, 0, 0);\r
-        }\r
-\r
-        /// <summary>\r
-        /// Applies the encoding job to the native memory structure and returns a list of memory\r
-        /// locations allocated during this.\r
-        /// </summary>\r
-        /// <param name="nativeJob">The native structure to apply to job info to.</param>\r
-        /// <param name="job">The job info to apply.</param>\r
-        /// <param name="preview">True if this is a preview encode.</param>\r
-        /// <param name="previewNumber">The preview number (0-based) to encode.</param>\r
-        /// <param name="previewSeconds">The number of seconds in the preview.</param>\r
-        /// <param name="overallSelectedLengthSeconds">The currently selected encode length. Used in preview\r
-        /// for calculating bitrate when the target size would be wrong.</param>\r
-        /// <returns>The list of memory locations allocated for the job.</returns>\r
-        private List<IntPtr> ApplyJob(ref hb_job_s nativeJob, EncodeJob job, bool preview, int previewNumber, int previewSeconds, double overallSelectedLengthSeconds)\r
-        {\r
-            var allocatedMemory = new List<IntPtr>();\r
-            Title title = this.GetTitle(job.Title);\r
-            hb_title_s originalTitle = this.GetOriginalTitle(job.Title);\r
-\r
-            EncodingProfile profile = job.EncodingProfile;\r
-\r
-            if (preview)\r
-            {\r
-                nativeJob.start_at_preview = previewNumber + 1;\r
-                nativeJob.seek_points = this.previewCount;\r
-\r
-                // There are 90,000 PTS per second.\r
-                nativeJob.pts_to_stop = previewSeconds * 90000;\r
-            }\r
-            else\r
-            {\r
-                switch (job.RangeType)\r
+                if (this.EncodeCompleted != null)\r
                 {\r
-                    case VideoRangeType.All:\r
-                        break;\r
-                    case VideoRangeType.Chapters:\r
-                        if (job.ChapterStart > 0 && job.ChapterEnd > 0)\r
-                        {\r
-                            nativeJob.chapter_start = job.ChapterStart;\r
-                            nativeJob.chapter_end = job.ChapterEnd;\r
-                        }\r
-                        else\r
-                        {\r
-                            nativeJob.chapter_start = 1;\r
-                            nativeJob.chapter_end = title.Chapters.Count;\r
-                        }\r
-\r
-                        break;\r
-                    case VideoRangeType.Seconds:\r
-                        if (job.SecondsStart < 0 || job.SecondsEnd < 0 || job.SecondsStart >= job.SecondsEnd)\r
-                        {\r
-                            throw new ArgumentException("Seconds range " + job.SecondsStart + "-" + job.SecondsEnd + " is invalid.", "job");\r
-                        }\r
-\r
-                        // If they've selected the "full" title duration, leave off the arguments to make it clean\r
-                        if (job.SecondsStart > 0 || job.SecondsEnd < title.Duration.TotalSeconds)\r
-                        {\r
-                            // For some reason "pts_to_stop" actually means the number of pts to stop AFTER the start point.\r
-                            nativeJob.pts_to_start = (int)(job.SecondsStart * 90000);\r
-                            nativeJob.pts_to_stop = (int)((job.SecondsEnd - job.SecondsStart) * 90000);\r
-                        }\r
-                        break;\r
-                    case VideoRangeType.Frames:\r
-                        if (job.FramesStart < 0 || job.FramesEnd < 0 || job.FramesStart >= job.FramesEnd)\r
-                        {\r
-                            throw new ArgumentException("Frames range " + job.FramesStart + "-" + job.FramesEnd + " is invalid.", "job");\r
-                        }\r
-\r
-                        // "frame_to_stop" actually means the number of frames total to encode AFTER the start point.\r
-                        nativeJob.frame_to_start = job.FramesStart;\r
-                        nativeJob.frame_to_stop = job.FramesEnd - job.FramesStart;\r
-                        break;\r
-                }\r
-            }\r
-\r
-            // Chapter markers\r
-            nativeJob.chapter_markers = profile.IncludeChapterMarkers ? 1 : 0;\r
-\r
-            List<IntPtr> nativeChapters = nativeJob.list_chapter.ToIntPtrList();\r
-\r
-            if (!preview && profile.IncludeChapterMarkers)\r
-            {\r
-                int numChapters = title.Chapters.Count;\r
-\r
-                if (job.UseDefaultChapterNames)\r
-                {\r
-                    for (int i = 0; i < numChapters; i++)\r
-                    {\r
-                        if (i < nativeChapters.Count)\r
-                        {\r
-                            HBFunctions.hb_chapter_set_title(nativeChapters[i], "Chapter " + (i + 1));\r
-                        }\r
-                    }\r
-                }\r
-                else\r
-                {\r
-                    for (int i = 0; i < numChapters; i++)\r
+                    this.EncodeCompleted(this, new EncodeCompletedEventArgs\r
                     {\r
-                        if (i < nativeChapters.Count && i < job.CustomChapterNames.Count)\r
-                        {\r
-                            IntPtr chapterNamePtr;\r
-\r
-                            if (string.IsNullOrWhiteSpace(job.CustomChapterNames[i]))\r
-                            {\r
-                                chapterNamePtr = InteropUtilities.ToUtf8PtrFromString("Chapter " + (i + 1));\r
-                            }\r
-                            else\r
-                            {\r
-                                chapterNamePtr = InteropUtilities.ToUtf8PtrFromString(job.CustomChapterNames[i]);\r
-                            }\r
-\r
-                            HBFunctions.hb_chapter_set_title__ptr(nativeChapters[i], chapterNamePtr);\r
-                            Marshal.FreeHGlobal(chapterNamePtr);\r
-                        }\r
-                    }\r
-                }\r
-            }\r
-\r
-            Cropping crop = GetCropping(profile, title);\r
-\r
-            nativeJob.crop[0] = crop.Top;\r
-            nativeJob.crop[1] = crop.Bottom;\r
-            nativeJob.crop[2] = crop.Left;\r
-            nativeJob.crop[3] = crop.Right;\r
-\r
-            var filterList = new List<hb_filter_object_s>();\r
-\r
-            // FILTERS: These must be added in the correct order since we cannot depend on the automatic ordering in hb_add_filter . Ordering is determined\r
-            // by the order they show up in the filters enum.\r
-\r
-            // Detelecine\r
-            if (profile.Detelecine != Detelecine.Off)\r
-            {\r
-                string settings = null;\r
-                if (profile.Detelecine == Detelecine.Custom)\r
-                {\r
-                    settings = profile.CustomDetelecine;\r
-                }\r
-\r
-                this.AddFilter(filterList, (int)hb_filter_ids.HB_FILTER_DETELECINE, settings, allocatedMemory);\r
-            }\r
-\r
-            // Decomb\r
-            if (profile.Decomb != Decomb.Off)\r
-            {\r
-                string settings = null;\r
-                switch (profile.Decomb)\r
-                {\r
-                    case Decomb.Default:\r
-                        break;\r
-                    case Decomb.Fast:\r
-                        settings = "7:2:6:9:1:80";\r
-                        break;\r
-                    case Decomb.Bob:\r
-                        settings = "455";\r
-                        break;\r
-                    case Decomb.Custom:\r
-                        settings = profile.CustomDecomb;\r
-                        break;\r
-                    default:\r
-                        break;\r
-                }\r
-\r
-                this.AddFilter(filterList, (int)hb_filter_ids.HB_FILTER_DECOMB, settings, allocatedMemory);\r
-            }\r
-\r
-            // Deinterlace\r
-            if (profile.Deinterlace != Deinterlace.Off)\r
-            {\r
-                nativeJob.deinterlace = 1;\r
-                string settings = null;\r
-\r
-                switch (profile.Deinterlace)\r
-                {\r
-                    case Deinterlace.Fast:\r
-                        settings = "0";\r
-                        break;\r
-                    case Deinterlace.Slow:\r
-                        settings = "1";\r
-                        break;\r
-                    case Deinterlace.Slower:\r
-                        settings = "3";\r
-                        break;\r
-                    case Deinterlace.Bob:\r
-                        settings = "15";\r
-                        break;\r
-                    case Deinterlace.Custom:\r
-                        settings = profile.CustomDeinterlace;\r
-                        break;\r
-                    default:\r
-                        break;\r
-                }\r
-\r
-                this.AddFilter(filterList, (int)hb_filter_ids.HB_FILTER_DEINTERLACE, settings, allocatedMemory);\r
-            }\r
-            else\r
-            {\r
-                nativeJob.deinterlace = 0;\r
-            }\r
-\r
-            // VFR\r
-            if (profile.Framerate == 0)\r
-            {\r
-                if (profile.ConstantFramerate)\r
-                {\r
-                    // CFR with "Same as Source". Use the title rate\r
-                    nativeJob.cfr = 1;\r
-                    nativeJob.vrate = originalTitle.vrate.num;\r
-                    nativeJob.vrate_base = originalTitle.vrate.den;\r
-                }\r
-                else\r
-                {\r
-                    // Pure VFR "Same as Source"\r
-                    nativeJob.cfr = 0;\r
-                }\r
-            }\r
-            else\r
-            {\r
-                // Specified framerate\r
-                if (profile.ConstantFramerate)\r
-                {\r
-                    // Mark as pure CFR\r
-                    nativeJob.cfr = 1;\r
-                }\r
-                else\r
-                {\r
-                    // Mark as peak framerate\r
-                    nativeJob.cfr = 2;\r
-                }\r
-\r
-                nativeJob.vrate = 27000000;\r
-                nativeJob.vrate_base = Converters.Converters.FramerateToVrate(profile.Framerate);\r
-            }\r
-\r
-            string vfrSettings = string.Format(CultureInfo.InvariantCulture, "{0}:{1}:{2}", nativeJob.cfr, nativeJob.vrate, nativeJob.vrate_base);\r
-            this.AddFilter(filterList, (int)hb_filter_ids.HB_FILTER_VFR, vfrSettings, allocatedMemory);\r
-\r
-            // Deblock\r
-            if (profile.Deblock > 0)\r
-            {\r
-                this.AddFilter(filterList, (int)hb_filter_ids.HB_FILTER_DEBLOCK, profile.Deblock.ToString(CultureInfo.InvariantCulture), allocatedMemory);\r
-            }\r
-\r
-            // Denoise\r
-            if (profile.Denoise != Denoise.Off)\r
-            {\r
-                   int filterType = profile.Denoise == Denoise.hqdn3d ? (int)hb_filter_ids.HB_FILTER_HQDN3D : (int)hb_filter_ids.HB_FILTER_NLMEANS;\r
-\r
-                               this.AddFilterFromPreset(filterList, filterType, profile.DenoisePreset, profile.DenoiseTune);\r
-            }\r
-\r
-            // Crop/scale\r
-            int width = profile.Width;\r
-            int height = profile.Height;\r
-\r
-            int cropHorizontal = crop.Left + crop.Right;\r
-            int cropVertical = crop.Top + crop.Bottom;\r
-\r
-            if (width == 0)\r
-            {\r
-                width = title.Resolution.Width - cropHorizontal;\r
-            }\r
-\r
-            if (profile.MaxWidth > 0 && width > profile.MaxWidth)\r
-            {\r
-                width = profile.MaxWidth;\r
-            }\r
-\r
-            if (height == 0)\r
-            {\r
-                height = title.Resolution.Height - cropVertical;\r
-            }\r
-\r
-            if (profile.MaxHeight > 0 && height > profile.MaxHeight)\r
-            {\r
-                height = profile.MaxHeight;\r
-            }\r
-\r
-            // The job width can sometimes start not clean, due to interference from\r
-            // preview generation. We reset it here to allow good calculations.\r
-            nativeJob.width = width;\r
-            nativeJob.height = height;\r
-\r
-            nativeJob.grayscale = profile.Grayscale ? 1 : 0;\r
-\r
-            switch (profile.Anamorphic)\r
-            {\r
-                case Anamorphic.None:\r
-                    nativeJob.anamorphic.mode = 0;\r
-\r
-                    Size outputSize = CalculateNonAnamorphicOutput(profile, title);\r
-                    width = outputSize.Width;\r
-                    height = outputSize.Height;\r
-\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
-\r
-                    nativeJob.maxWidth = profile.MaxWidth;\r
-                    nativeJob.maxHeight = profile.MaxHeight;\r
-\r
-                           nativeJob.modulus = 2;\r
-\r
-                    break;\r
-                case Anamorphic.Strict:\r
-                    nativeJob.anamorphic.mode = hb_anamorphic_mode_t.HB_ANAMORPHIC_STRICT;\r
-\r
-                    nativeJob.anamorphic.par_width = title.ParVal.Width;\r
-                    nativeJob.anamorphic.par_height = title.ParVal.Height;\r
-                    break;\r
-                case Anamorphic.Loose:\r
-                    nativeJob.anamorphic.mode = hb_anamorphic_mode_t.HB_ANAMORPHIC_LOOSE;\r
-\r
-                    nativeJob.modulus = profile.Modulus;\r
-\r
-                    nativeJob.width = width;\r
-\r
-                    nativeJob.maxWidth = profile.MaxWidth;\r
-\r
-                    nativeJob.anamorphic.par_width = title.ParVal.Width;\r
-                    nativeJob.anamorphic.par_height = title.ParVal.Height;\r
-                    break;\r
-                case Anamorphic.Custom:\r
-                    nativeJob.anamorphic.mode = hb_anamorphic_mode_t.HB_ANAMORPHIC_CUSTOM;\r
-\r
-                    nativeJob.modulus = profile.Modulus;\r
-\r
-                    if (profile.UseDisplayWidth)\r
-                    {\r
-                        if (profile.KeepDisplayAspect)\r
-                        {\r
-                            int cropWidth = title.Resolution.Width - cropHorizontal;\r
-                            int cropHeight = title.Resolution.Height - cropVertical;\r
-\r
-                            double displayAspect = ((double)(cropWidth * title.ParVal.Width)) / (cropHeight * title.ParVal.Height);\r
-                            int displayWidth = profile.DisplayWidth;\r
-\r
-                            if (profile.Height > 0)\r
-                            {\r
-                                displayWidth = (int)((double)profile.Height * displayAspect);\r
-                            }\r
-                            else if (displayWidth > 0)\r
-                            {\r
-                                height = (int)((double)displayWidth / displayAspect);\r
-                            }\r
-                            else\r
-                            {\r
-                                displayWidth = (int)((double)height * displayAspect);\r
-                            }\r
-\r
-                            nativeJob.anamorphic.dar_width = displayWidth;\r
-                            nativeJob.anamorphic.dar_height = height;\r
-                            nativeJob.anamorphic.keep_display_aspect = 1;\r
-                        }\r
-                        else\r
-                        {\r
-                            nativeJob.anamorphic.dar_width = profile.DisplayWidth;\r
-                            nativeJob.anamorphic.dar_height = height;\r
-                            nativeJob.anamorphic.keep_display_aspect = 0;\r
-                        }\r
-                    }\r
-                    else\r
-                    {\r
-                        nativeJob.anamorphic.par_width = profile.PixelAspectX;\r
-                        nativeJob.anamorphic.par_height = profile.PixelAspectY;\r
-                        nativeJob.anamorphic.keep_display_aspect = 0;\r
-                    }\r
-\r
-                    nativeJob.width = width;\r
-                    nativeJob.height = height;\r
-\r
-                    nativeJob.maxWidth = profile.MaxWidth;\r
-                    nativeJob.maxHeight = profile.MaxHeight;\r
-\r
-                    break;\r
-                default:\r
-                    break;\r
-            }\r
-\r
-            // Need to fix up values before adding crop/scale filter\r
-            if (profile.Anamorphic != Anamorphic.None)\r
-            {\r
-                int anamorphicWidth = 0, anamorphicHeight = 0, anamorphicParWidth = 0, anamorphicParHeight = 0;\r
-\r
-                HBFunctions.hb_set_anamorphic_size(ref nativeJob, ref anamorphicWidth, ref anamorphicHeight, ref anamorphicParWidth, ref anamorphicParHeight);\r
-                nativeJob.width = anamorphicWidth;\r
-                nativeJob.height = anamorphicHeight;\r
-                nativeJob.anamorphic.par_width = anamorphicParWidth;\r
-                nativeJob.anamorphic.par_height = anamorphicParHeight;\r
-            }\r
-\r
-            string cropScaleSettings = string.Format(\r
-                CultureInfo.InvariantCulture,\r
-                "{0}:{1}:{2}:{3}:{4}:{5}",\r
-                nativeJob.width,\r
-                nativeJob.height,\r
-                nativeJob.crop[0],\r
-                nativeJob.crop[1],\r
-                nativeJob.crop[2],\r
-                nativeJob.crop[3]);\r
-            this.AddFilter(filterList, (int)hb_filter_ids.HB_FILTER_CROP_SCALE, cropScaleSettings, allocatedMemory);\r
-\r
-\r
-\r
-\r
-\r
-            HBVideoEncoder videoEncoder = Encoders.VideoEncoders.FirstOrDefault(e => e.ShortName == profile.VideoEncoder);\r
-            if (videoEncoder == null)\r
-            {\r
-                throw new ArgumentException("Video encoder " + profile.VideoEncoder + " not recognized.");\r
-            }\r
-\r
-            nativeJob.vcodec = videoEncoder.Id;\r
-\r
-\r
-\r
-            // areBframes\r
-            // color_matrix\r
-            List<hb_audio_s> titleAudio = originalTitle.list_audio.ToListFromHandBrakeList<hb_audio_s>();\r
-\r
-            var audioList = new List<hb_audio_s>();\r
-            int numTracks = 0;\r
-\r
-            List<Tuple<AudioEncoding, int>> outputTrackList = this.GetOutputTracks(job, title);\r
-\r
-            if (!string.IsNullOrEmpty(profile.AudioEncoderFallback))\r
-            {\r
-                HBAudioEncoder audioEncoder = Encoders.GetAudioEncoder(profile.AudioEncoderFallback);\r
-                if (audioEncoder == null)\r
-                {\r
-                    throw new ArgumentException("Unrecognized fallback audio encoder: " + profile.AudioEncoderFallback);\r
-                }\r
-\r
-                nativeJob.acodec_fallback = Encoders.GetAudioEncoder(profile.AudioEncoderFallback).Id;\r
-            }\r
-\r
-            nativeJob.acodec_copy_mask = (int)NativeConstants.HB_ACODEC_ANY;\r
-\r
-            foreach (Tuple<AudioEncoding, int> outputTrack in outputTrackList)\r
-            {\r
-                   AudioEncoding encoding = outputTrack.Item1;\r
-                   int trackNumber = outputTrack.Item2;\r
-\r
-                               audioList.Add(this.ConvertAudioBack(encoding, titleAudio[trackNumber - 1], numTracks++, allocatedMemory));\r
-            }\r
-\r
-            NativeList nativeAudioList = InteropUtilities.ToHandBrakeListFromList<hb_audio_s>(audioList);\r
-            nativeJob.list_audio = nativeAudioList.Ptr;\r
-            allocatedMemory.AddRange(nativeAudioList.AllocatedMemory);\r
-\r
-            if (job.Subtitles != null)\r
-            {\r
-                if (job.Subtitles.SourceSubtitles != null && job.Subtitles.SourceSubtitles.Count > 0)\r
-                {\r
-                    List<hb_subtitle_s> titleSubtitles = originalTitle.list_subtitle.ToListFromHandBrakeList<hb_subtitle_s>();\r
-\r
-                    foreach (SourceSubtitle sourceSubtitle in job.Subtitles.SourceSubtitles)\r
-                    {\r
-                        if (sourceSubtitle.TrackNumber == 0)\r
-                        {\r
-                            // Use subtitle search.\r
-                            nativeJob.select_subtitle_config.force = sourceSubtitle.Forced ? 1 : 0;\r
-                            nativeJob.select_subtitle_config.default_track = sourceSubtitle.Default ? 1 : 0;\r
-\r
-                            if (!sourceSubtitle.BurnedIn)\r
-                            {\r
-                                nativeJob.select_subtitle_config.dest = hb_subtitle_config_s_subdest.PASSTHRUSUB;\r
-                            }\r
-\r
-                            nativeJob.indepth_scan = 1;\r
-                        }\r
-                        else\r
-                        {\r
-                            // Use specified subtitle.\r
-                            hb_subtitle_s nativeSubtitle = titleSubtitles[sourceSubtitle.TrackNumber - 1];\r
-                            var subtitleConfig = new hb_subtitle_config_s();\r
-\r
-                            subtitleConfig.force = sourceSubtitle.Forced ? 1 : 0;\r
-                            subtitleConfig.default_track = sourceSubtitle.Default ? 1 : 0;\r
-\r
-                            bool supportsBurn = nativeSubtitle.source == hb_subtitle_s_subsource.VOBSUB || nativeSubtitle.source == hb_subtitle_s_subsource.SSASUB || nativeSubtitle.source == hb_subtitle_s_subsource.PGSSUB;\r
-                            if (supportsBurn && sourceSubtitle.BurnedIn)\r
-                            {\r
-                                subtitleConfig.dest = hb_subtitle_config_s_subdest.RENDERSUB;\r
-                            }\r
-                            else\r
-                            {\r
-                                subtitleConfig.dest = hb_subtitle_config_s_subdest.PASSTHRUSUB;\r
-                            }\r
-\r
-                            int subtitleAddSucceded = HBFunctions.hb_subtitle_add(ref nativeJob, ref subtitleConfig, sourceSubtitle.TrackNumber - 1);\r
-                            if (subtitleAddSucceded == 0)\r
-                            {\r
-                                Debug.WriteLine("Subtitle add failed");\r
-                            }\r
-                        }\r
-                    }\r
-                }\r
-\r
-                if (job.Subtitles.SrtSubtitles != null)\r
-                {\r
-                    foreach (SrtSubtitle srtSubtitle in job.Subtitles.SrtSubtitles)\r
-                    {\r
-                        var subtitleConfig = new hb_subtitle_config_s();\r
-\r
-                           subtitleConfig.dest = srtSubtitle.BurnedIn ? hb_subtitle_config_s_subdest.RENDERSUB : hb_subtitle_config_s_subdest.PASSTHRUSUB;\r
-                        subtitleConfig.src_codeset = srtSubtitle.CharacterCode;\r
-                        subtitleConfig.src_filename = srtSubtitle.FileName;\r
-                        subtitleConfig.offset = srtSubtitle.Offset;\r
-                        subtitleConfig.default_track = srtSubtitle.Default ? 1 : 0;\r
-\r
-                        int srtAddSucceded = HBFunctions.hb_srt_add(ref nativeJob, ref subtitleConfig, srtSubtitle.LanguageCode);\r
-                        if (srtAddSucceded == 0)\r
-                        {\r
-                            Debug.WriteLine("SRT add failed");\r
-                        }\r
-                    }\r
-                }\r
-\r
-                bool hasBurnedSubtitle = job.Subtitles.SourceSubtitles != null && job.Subtitles.SourceSubtitles.Any(s => s.BurnedIn);\r
-                if (hasBurnedSubtitle)\r
-                {\r
-                    this.AddFilter(filterList, (int)hb_filter_ids.HB_FILTER_RENDER_SUB, string.Format(CultureInfo.InvariantCulture, "{0}:{1}:{2}:{3}", crop.Top, crop.Bottom, crop.Left, crop.Right), allocatedMemory);\r
+                        Error = state.WorkDone.Error != (int)hb_error_code.HB_ERROR_NONE\r
+                    });\r
                 }\r
             }\r
-\r
-                       // Rotate\r
-               if (profile.FlipHorizontal || profile.FlipVertical || profile.Rotation != PictureRotation.None)\r
-               {\r
-                       bool rotate90 = false;\r
-                       bool flipHorizontal = profile.FlipHorizontal;\r
-                       bool flipVertical = profile.FlipVertical;\r
-\r
-                       switch (profile.Rotation)\r
-                       {\r
-                               case PictureRotation.Clockwise90:\r
-                                       rotate90 = true;\r
-                                       break;\r
-                               case PictureRotation.Clockwise180:\r
-                                       flipHorizontal = !flipHorizontal;\r
-                                       flipVertical = !flipVertical;\r
-                                       break;\r
-                               case PictureRotation.Clockwise270:\r
-                                       rotate90 = true;\r
-                                       flipHorizontal = !flipHorizontal;\r
-                                       flipVertical = !flipVertical;\r
-                                       break;\r
-                       }\r
-\r
-                       int rotateSetting = 0;\r
-                               if (flipVertical)\r
-                       {\r
-                               rotateSetting |= 1;\r
-                       }\r
-\r
-                               if (flipHorizontal)\r
-                       {\r
-                               rotateSetting |= 2;\r
-                       }\r
-\r
-                               if (rotate90)\r
-                       {\r
-                               rotateSetting |= 4;\r
-                       }\r
-\r
-                               this.AddFilter(filterList, (int)hb_filter_ids.HB_FILTER_ROTATE, rotateSetting.ToString(CultureInfo.InvariantCulture), allocatedMemory);\r
-               }\r
-\r
-            // Construct final filter list\r
-            nativeJob.list_filter = this.ConvertFilterListToNative(filterList, allocatedMemory).Ptr;\r
-\r
-            if (profile.ScaleMethod == ScaleMethod.Bicubic)\r
-            {\r
-                HBFunctions.hb_get_opencl_env();\r
-                nativeJob.use_opencl = 1;\r
-            }\r
-            else\r
-            {\r
-                nativeJob.use_opencl = 0;\r
-            }\r
-\r
-            nativeJob.qsv.decode = profile.QsvDecode ? 1 : 0;\r
-            nativeJob.use_hwd = job.DxvaDecoding ? 1 : 0;\r
-\r
-            if (profile.ContainerName != null)\r
-            {\r
-                nativeJob.mux = HBFunctions.hb_container_get_from_name(profile.ContainerName);\r
-            }\r
-\r
-                       if (job.OutputPath == null)\r
-                       {\r
-                               nativeJob.file = IntPtr.Zero;\r
-                       }\r
-                       else\r
-                       {\r
-                               IntPtr outputPathPtr = InteropUtilities.ToUtf8PtrFromString(job.OutputPath);\r
-                               allocatedMemory.Add(outputPathPtr);\r
-                               nativeJob.file = outputPathPtr;\r
-                       }\r
-\r
-            nativeJob.largeFileSize = profile.LargeFile ? 1 : 0;\r
-            nativeJob.mp4_optimize = profile.Optimize ? 1 : 0;\r
-            nativeJob.ipod_atom = profile.IPod5GSupport ? 1 : 0;\r
-\r
-            if (title.AngleCount > 1)\r
-            {\r
-                nativeJob.angle = job.Angle;\r
-            }\r
-\r
-            switch (profile.VideoEncodeRateType)\r
-            {\r
-                case VideoEncodeRateType.ConstantQuality:\r
-                    nativeJob.vquality = (float)profile.Quality;\r
-                    nativeJob.vbitrate = 0;\r
-                    break;\r
-                case VideoEncodeRateType.AverageBitrate:\r
-                    nativeJob.vquality = -1;\r
-                    nativeJob.vbitrate = profile.VideoBitrate;\r
-                    break;\r
-                case VideoEncodeRateType.TargetSize:\r
-                    nativeJob.vquality = -1;\r
-                    nativeJob.vbitrate = this.CalculateBitrate(job, profile.TargetSize, overallSelectedLengthSeconds);\r
-                    break;\r
-                default:\r
-                    break;\r
-            }\r
-\r
-            // frames_to_skip\r
-\r
-            return allocatedMemory;\r
         }\r
 \r
         /// <summary>\r
@@ -1653,68 +679,6 @@ namespace HandBrake.Interop
             return list;\r
         }\r
 \r
-        /// <summary>\r
-        /// Adds a filter to the given filter list.\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="settings">Settings for the filter.</param>\r
-        /// <param name="allocatedMemory">The list of allocated memory.</param>\r
-        private void AddFilter(List<hb_filter_object_s> filterList, int filterType, string settings, List<IntPtr> allocatedMemory)\r
-        {\r
-            IntPtr settingsNativeString = Marshal.StringToHGlobalAnsi(settings);\r
-            hb_filter_object_s filter = InteropUtilities.ToStructureFromPtr<hb_filter_object_s>(HBFunctions.hb_filter_init(filterType));\r
-            filter.settings = settingsNativeString;\r
-\r
-            allocatedMemory.Add(settingsNativeString);\r
-            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
-        /// <remarks>Sorts the list by filter ID before converting to a native list, as HB expects it that way.\r
-        /// The list memory itself will be added to the allocatedMemory list.</remarks>\r
-        /// <param name="filterList">The filter list to convert.</param>\r
-        /// <param name="allocatedMemory">The list of allocated memory to add to.</param>\r
-        /// <returns>The converted list.</returns>\r
-        private NativeList ConvertFilterListToNative(List<hb_filter_object_s> filterList, List<IntPtr> allocatedMemory)\r
-        {\r
-            var filterPtrList = new List<IntPtr>();\r
-\r
-            var sortedList = filterList.OrderBy(f => f.id);\r
-            foreach (var filter in sortedList)\r
-            {\r
-                IntPtr filterPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(hb_filter_object_s)));\r
-                Marshal.StructureToPtr(filter, filterPtr, false);\r
-\r
-                allocatedMemory.Add(filterPtr);\r
-                filterPtrList.Add(filterPtr);\r
-            }\r
-\r
-            NativeList filterListNative = InteropUtilities.ToHandBrakeListFromPtrList(filterPtrList);\r
-            allocatedMemory.AddRange(filterListNative.AllocatedMemory);\r
-\r
-            return filterListNative;\r
-        }\r
-\r
         /// <summary>\r
         /// Gets the title, given the 1-based title number.\r
         /// </summary>\r
@@ -1724,170 +688,5 @@ namespace HandBrake.Interop
         {\r
             return this.Titles.SingleOrDefault(title => title.TitleNumber == titleNumber);\r
         }\r
-\r
-        /// <summary>\r
-        /// Gets the 1-based title index of the given title.\r
-        /// </summary>\r
-        /// <param name="titleNumber">The 1-based title title number.</param>\r
-        /// <returns>The 1-based title index.</returns>\r
-        private int GetTitleIndex(int titleNumber)\r
-        {\r
-            Title title = this.GetTitle(titleNumber);\r
-            return this.GetTitleIndex(title);\r
-        }\r
-\r
-        /// <summary>\r
-        /// Gets the 1-based title index of the given title.\r
-        /// </summary>\r
-        /// <param name="title">The title to look up</param>\r
-        /// <returns>The 1-based title index of the given title.</returns>\r
-        private int GetTitleIndex(Title title)\r
-        {\r
-            return this.Titles.IndexOf(title) + 1;\r
-        }\r
-\r
-        /// <summary>\r
-        /// Gets the native title object from the title index.\r
-        /// </summary>\r
-        /// <param name="titleIndex">The index of the title (1-based).</param>\r
-        /// <returns>Gets the native title object for the given index.</returns>\r
-        private hb_title_s GetOriginalTitle(int titleIndex)\r
-        {\r
-            List<hb_title_s> matchingTitles = this.originalTitles.Where(title => title.index == titleIndex).ToList();\r
-            if (matchingTitles.Count == 0)\r
-            {\r
-                throw new ArgumentException("Could not find specified title.");\r
-            }\r
-\r
-            if (matchingTitles.Count > 1)\r
-            {\r
-                throw new ArgumentException("Multiple titles matched.");\r
-            }\r
-\r
-            return matchingTitles[0];\r
-        }\r
-\r
-        /// <summary>\r
-        /// Applies an audio encoding to a native audio encoding base structure.\r
-        /// </summary>\r
-        /// <param name="encoding">The encoding to apply.</param>\r
-        /// <param name="baseStruct">The base native structure.</param>\r
-        /// <param name="outputTrack">The output track number (0-based).</param>\r
-        /// <param name="allocatedMemory">The collection of allocated memory.</param>\r
-        /// <returns>The resulting native audio structure.</returns>\r
-        private hb_audio_s ConvertAudioBack(AudioEncoding encoding, hb_audio_s baseStruct, int outputTrack, List<IntPtr> allocatedMemory)\r
-        {\r
-            hb_audio_s nativeAudio = baseStruct;\r
-            HBAudioEncoder encoder = Encoders.GetAudioEncoder(encoding.Encoder);\r
-\r
-                       if (encoder == null)\r
-                       {\r
-                               throw new InvalidOperationException("Could not find audio encoder " + encoding.Name);\r
-                       }\r
-\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
-                                       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 = baseStruct.config.input.codec | NativeConstants.HB_ACODEC_PASS_FLAG;\r
-                       isPassthrough = true;\r
-               }\r
-\r
-            nativeAudio.config.output.track = outputTrack;\r
-                       nativeAudio.config.output.codec = outputCodec;\r
-            nativeAudio.config.output.compression_level = -1;\r
-            nativeAudio.config.output.samplerate = nativeAudio.config.input.samplerate;\r
-            nativeAudio.config.output.dither_method = -1;\r
-\r
-                       if (!isPassthrough)\r
-            {\r
-                if (encoding.SampleRateRaw != 0)\r
-                {\r
-                    nativeAudio.config.output.samplerate = encoding.SampleRateRaw;\r
-                }\r
-\r
-                HBMixdown mixdown = Encoders.GetMixdown(encoding.Mixdown);\r
-                nativeAudio.config.output.mixdown = mixdown.Id;\r
-\r
-                if (encoding.EncodeRateType == AudioEncodeRateType.Bitrate)\r
-                {\r
-                    // Disable quality targeting.\r
-                    nativeAudio.config.output.quality = -3;\r
-\r
-                    if (encoding.Bitrate == 0)\r
-                    {\r
-                        // Bitrate of 0 means auto: choose the default for this codec, sample rate and mixdown.\r
-                        nativeAudio.config.output.bitrate = HBFunctions.hb_audio_bitrate_get_default(\r
-                            nativeAudio.config.output.codec,\r
-                            nativeAudio.config.output.samplerate,\r
-                            nativeAudio.config.output.mixdown);\r
-                    }\r
-                    else\r
-                    {\r
-                        nativeAudio.config.output.bitrate = encoding.Bitrate;\r
-                    }\r
-                }\r
-                else if (encoding.EncodeRateType == AudioEncodeRateType.Quality)\r
-                {\r
-                    // Bitrate of -1 signals quality targeting.\r
-                    nativeAudio.config.output.bitrate = -1;\r
-                    nativeAudio.config.output.quality = encoding.Quality;\r
-                }\r
-\r
-                // If this encoder supports compression level, pass it in.\r
-                if (encoder.SupportsCompression)\r
-                {\r
-                    nativeAudio.config.output.compression_level = encoding.Compression;\r
-                }\r
-\r
-                nativeAudio.config.output.dynamic_range_compression = encoding.Drc;\r
-                nativeAudio.config.output.gain = encoding.Gain;\r
-            }\r
-\r
-            if (!string.IsNullOrEmpty(encoding.Name))\r
-            {\r
-                IntPtr encodingNamePtr = Marshal.StringToHGlobalAnsi(encoding.Name);\r
-                nativeAudio.config.output.name = encodingNamePtr;\r
-                allocatedMemory.Add(encodingNamePtr);\r
-            }\r
-\r
-               if (nativeAudio.padding == null)\r
-               {\r
-                               nativeAudio.padding = new byte[MarshalingConstants.AudioPaddingBytes];\r
-               }\r
-\r
-            return nativeAudio;\r
-        }\r
-\r
-        /// <summary>\r
-        /// Gets the cropping to use for the given encoding profile and title.\r
-        /// </summary>\r
-        /// <param name="profile">The encoding profile to use.</param>\r
-        /// <param name="title">The title being encoded.</param>\r
-        /// <returns>The cropping to use for the encode.</returns>\r
-        private static Cropping GetCropping(EncodingProfile profile, Title title)\r
-        {\r
-            Cropping crop;\r
-            switch (profile.CroppingType)\r
-            {\r
-                case CroppingType.Automatic:\r
-                    crop = title.AutoCropDimensions;\r
-                    break;\r
-                case CroppingType.Custom:\r
-                    crop = profile.Cropping;\r
-                    break;\r
-                default:\r
-                    crop = new Cropping();\r
-                    break;\r
-            }\r
-            return crop;\r
-        }\r
     }\r
 }\r
index f722cdabd2e41e7806b65511e49dcec9daa6144b..65f5458f00d8f393aca5fb8ea6973d8d074a6c33 100644 (file)
     <Compile Include="HandBrakeInstance.cs" />\r
     <Compile Include="HbLib\HBDelegates.cs" />\r
     <Compile Include="HbLib\HBFunctions.cs" />\r
-    <Compile Include="HbLib\hb_audio.cs" />\r
-    <Compile Include="HbLib\hb_chapter_s.cs" />\r
     <Compile Include="HbLib\hb_container_s.cs" />\r
     <Compile Include="HbLib\hb_encoder_s.cs" />\r
     <Compile Include="HbLib\hb_error_code.cs" />\r
     <Compile Include="HbLib\hb_filter_ids.cs" />\r
-    <Compile Include="HbLib\hb_filter_object_s.cs" />\r
     <Compile Include="HbLib\hb_geometry.cs" />\r
     <Compile Include="HbLib\hb_handle_s.cs" />\r
     <Compile Include="HbLib\hb_mixdown_s.cs" />\r
     <Compile Include="HbLib\hb_state_s.cs" />\r
     <Compile Include="HbLib\hb_subtitle.cs" />\r
     <Compile Include="HbLib\hb_subtitle_config_s.cs" />\r
-    <Compile Include="HbLib\hb_title_set_s.cs" />\r
     <Compile Include="HbLib\iso639_lang_t.cs" />\r
     <Compile Include="HbLib\hb_job_s.cs" />\r
     <Compile Include="HbLib\hb_title_s.cs" />\r
     <Compile Include="HbLib\NativeConstants.cs" />\r
+    <Compile Include="Helpers\Validate.cs" />\r
     <Compile Include="Interfaces\IHandBrakeInstance.cs" />\r
     <Compile Include="Helpers\InteropUtilities.cs" />\r
+    <Compile Include="Json\Anamorphic\AnamorphicGeometry.cs" />\r
+    <Compile Include="Json\Anamorphic\AnamorphicResult.cs" />\r
+    <Compile Include="Json\Anamorphic\DestSettings.cs" />\r
+    <Compile Include="Json\Anamorphic\Geometry.cs" />\r
+    <Compile Include="Json\Anamorphic\PAR.cs" />\r
+    <Compile Include="Json\Anamorphic\SourceGeometry.cs" />\r
+    <Compile Include="Json\Encode\Audio.cs" />\r
+    <Compile Include="Json\Encode\AudioList.cs" />\r
+    <Compile Include="Json\Encode\ChapterList.cs" />\r
+    <Compile Include="Json\Encode\Destination.cs" />\r
+    <Compile Include="Json\Encode\Filter.cs" />\r
+    <Compile Include="Json\Encode\FilterList.cs" />\r
+    <Compile Include="Json\Encode\JsonEncodeObject.cs" />\r
+    <Compile Include="Json\Encode\MetaData.cs" />\r
+    <Compile Include="Json\Encode\Mp4Options.cs" />\r
+    <Compile Include="Json\Encode\Range.cs" />\r
+    <Compile Include="Json\Encode\Search.cs" />\r
+    <Compile Include="Json\Encode\Source.cs" />\r
+    <Compile Include="Json\Encode\SRT.cs" />\r
+    <Compile Include="Json\Encode\Subtitle.cs" />\r
+    <Compile Include="Json\Encode\SubtitleList.cs" />\r
+    <Compile Include="Json\Encode\Video.cs" />\r
+    <Compile Include="Json\Factories\AnamorphicFactory.cs" />\r
+    <Compile Include="Json\Factories\EncodeFactory.cs" />\r
     <Compile Include="Json\Factories\ScanFactory.cs" />\r
     <Compile Include="Json\Scan\AudioList.cs" />\r
     <Compile Include="Json\Scan\ChapterList.cs" />\r
index 4070d880265f77ec952c71d8014ce7a6d1527fde..fb92c3783fb6a36e573ff01937722793a706b1c9 100644 (file)
@@ -11,14 +11,19 @@ namespace HandBrake.Interop
 {\r
     using System;\r
     using System.Collections.Generic;\r
+    using System.Linq;\r
     using System.Runtime.InteropServices;\r
 \r
     using HandBrake.Interop.EventArgs;\r
     using HandBrake.Interop.HbLib;\r
+    using HandBrake.Interop.Json.Anamorphic;\r
+    using HandBrake.Interop.Json.Scan;\r
     using HandBrake.Interop.Model;\r
     using HandBrake.Interop.Model.Encoding;\r
     using HandBrake.Interop.Model.Scan;\r
 \r
+    using Newtonsoft.Json;\r
+\r
     /// <summary>\r
     /// HandBrake Interop Utilities\r
     /// </summary>\r
index 1763d0a742b76752ba638f6b650debfe99f338c2..8eafea9f244bdacf905a215190bb85c41da1e699 100644 (file)
@@ -89,14 +89,6 @@ namespace HandBrake.Interop.HbLib
                [DllImport("hb.dll", EntryPoint = "hb_get_titles", CallingConvention = CallingConvention.Cdecl)]\r
                public static extern IntPtr hb_get_titles(IntPtr hbHandle);\r
 \r
-               /// Return Type: void\r
-               ///param0: hb_handle_t*\r
-               ///param1: hb_title_t*\r
-               ///param2: int\r
-               ///param3: uint8_t*\r
-               [DllImport("hb.dll", EntryPoint = "hb_get_preview", CallingConvention = CallingConvention.Cdecl)]\r
-               public static extern void hb_get_preview(IntPtr hbHandle, ref hb_job_s title, int preview, IntPtr buffer);\r
-\r
 \r
                /// Return Type: void\r
                ///param0: hb_job_t*\r
@@ -105,15 +97,6 @@ namespace HandBrake.Interop.HbLib
                [DllImport("hb.dll", EntryPoint = "hb_set_size", CallingConvention = CallingConvention.Cdecl)]\r
                public static extern void hb_set_size(ref hb_job_s param0, double ratio, int pixels);\r
 \r
-               /// Return Type: void\r
-               ///param0: hb_job_t*\r
-               ///output_width: int*\r
-               ///output_height: int*\r
-               ///output_par_width: int*\r
-               ///output_par_height: int*\r
-               [DllImport("hb.dll", EntryPoint = "hb_set_anamorphic_size", CallingConvention = CallingConvention.Cdecl)]\r
-               public static extern void hb_set_anamorphic_size(ref hb_job_s job, ref int output_width, ref int output_height, ref int output_par_width, ref int output_par_height);\r
-\r
         [DllImport("hb.dll", EntryPoint = "hb_set_anamorphic_size2", CallingConvention = CallingConvention.Cdecl)]\r
         public static extern void hb_set_anamorphic_size2(ref hb_geometry_s sourceGeometry, ref hb_geometry_settings_s uiGeometry, ref hb_geometry_s result);\r
         \r
@@ -170,19 +153,6 @@ namespace HandBrake.Interop.HbLib
                [DllImport("hb.dll", EntryPoint = "hb_stop", CallingConvention = CallingConvention.Cdecl)]\r
                public static extern void hb_stop(IntPtr hbHandle);\r
 \r
-               /// Return Type: void\r
-               ///param0: hb_handle_t*\r
-               ///param1: hb_state_t*\r
-               [DllImport("hb.dll", EntryPoint = "hb_get_state", CallingConvention = CallingConvention.Cdecl)]\r
-               public static extern void hb_get_state(IntPtr hbHandle, ref hb_state_s state);\r
-\r
-\r
-               /// Return Type: void\r
-               ///param0: hb_handle_t*\r
-               ///param1: hb_state_t*\r
-               [DllImport("hb.dll", EntryPoint = "hb_get_state2", CallingConvention = CallingConvention.Cdecl)]\r
-               public static extern void hb_get_state2(IntPtr hbHandle, ref hb_state_s param1);\r
-\r
 \r
                /// Return Type: int\r
                ///param0: hb_handle_t*\r
@@ -439,10 +409,6 @@ namespace HandBrake.Interop.HbLib
                [DllImport("hb.dll", EntryPoint = "hb_chapter_set_title", CallingConvention = CallingConvention.Cdecl)]\r
                public static extern void hb_chapter_set_title__ptr(IntPtr chapter, IntPtr title);\r
 \r
-               /// void hb_add_filter( hb_job_t * job, hb_filter_object_t * filter, const char * settings ); \r
-               [DllImport("hb.dll", EntryPoint = "hb_add_filter", CallingConvention = CallingConvention.Cdecl)]\r
-               public static extern void hb_add_filter(ref hb_job_s job, ref hb_filter_object_s filter, IntPtr settings);\r
-\r
                /// hb_filter_object_t * hb_filter_init( int filter_id );\r
                [DllImport("hb.dll", EntryPoint = "hb_filter_init", CallingConvention = CallingConvention.Cdecl)]\r
                public static extern IntPtr hb_filter_init(int filter_id);\r
@@ -479,6 +445,9 @@ namespace HandBrake.Interop.HbLib
                [DllImport("hb.dll", EntryPoint = "hb_qsv_info_init", CallingConvention = CallingConvention.Cdecl)]\r
                public static extern int hb_qsv_info_init();\r
 \r
+        // hb_image_t* hb_get_preview2(hb_handle_t* h, int title_idx, int picture, hb_geometry_settings_t* geo, int deinterlace);\r
+        [DllImport("hb.dll", EntryPoint = "hb_get_preview2", CallingConvention = CallingConvention.Cdecl)]\r
+        public static extern IntPtr hb_get_preview2(IntPtr hbHandle, int title_idx, int preview_idx,  ref hb_geometry_settings_s geo, int deinterlace);\r
 \r
         /* JSON API */\r
 \r
@@ -496,7 +465,7 @@ namespace HandBrake.Interop.HbLib
 \r
         // char     * hb_job_to_json(const hb_job_t * job);\r
         [DllImport("hb.dll", EntryPoint = "hb_job_to_json", CallingConvention = CallingConvention.Cdecl)]\r
-        public static extern IntPtr hb_job_to_json(IntPtr hb_job_t);\r
+        public static extern IntPtr hb_job_to_json(ref hb_job_s hb_job_t);\r
 \r
         // hb_job_t * hb_json_to_job(hb_handle_t * h, const char * json_job);\r
         [DllImport("hb.dll", EntryPoint = "hb_json_to_job", CallingConvention = CallingConvention.Cdecl)]\r
@@ -513,5 +482,9 @@ namespace HandBrake.Interop.HbLib
         // char     * hb_get_state_json(hb_handle_t * h);\r
         [DllImport("hb.dll", EntryPoint = "hb_get_state_json", CallingConvention = CallingConvention.Cdecl)]\r
         public static extern IntPtr hb_get_state_json(IntPtr hbHandle);\r
+\r
+        // char* hb_get_preview_params_json(int title_idx, int preview_idx, int deinterlace, hb_geometry_settings_t *settings)\r
+        [DllImport("hb.dll", EntryPoint = "hb_get_preview_params_json", CallingConvention = CallingConvention.Cdecl)]\r
+        public static extern IntPtr hb_get_preview_params_json(int title_idx, int preview_idx, int deinterlace, ref hb_geometry_settings_s settings);\r
        }\r
 }\r
diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/hb_audio.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/hb_audio.cs
deleted file mode 100644 (file)
index 7814fb2..0000000
+++ /dev/null
@@ -1,149 +0,0 @@
-// --------------------------------------------------------------------------------------------------------------------\r
-// <copyright file="hb_audio.cs" company="HandBrake Project (http://handbrake.fr)">\r
-//   This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.\r
-// </copyright>\r
-// <summary>\r
-//   Defines the hb_audio_s type.\r
-// </summary>\r
-// <auto-generated> Disable Stylecop Warnings for this file  </auto-generated>\r
-// --------------------------------------------------------------------------------------------------------------------\r
-\r
-namespace HandBrake.Interop.HbLib\r
-{\r
-       using System;\r
-       using System.Runtime.InteropServices;\r
-\r
-       using HandBrake.Interop.Helpers;\r
-\r
-    [StructLayout(LayoutKind.Sequential)]\r
-       public struct hb_audio_s\r
-       {\r
-               /// int\r
-               public int id;\r
-\r
-               /// hb_audio_config_t->hb_audio_config_s\r
-               public hb_audio_config_s config;\r
-\r
-               // Padding for the part of the struct we don't care about marshaling.\r
-               [MarshalAs(UnmanagedType.ByValArray, SizeConst = MarshalingConstants.AudioPaddingBytes, ArraySubType = UnmanagedType.U1)]\r
-               public byte[] padding;\r
-\r
-               // Anonymous_e6c7b779_b5a3_4e80_9fa8_13619d14f545\r
-               // public Anonymous_e6c7b779_b5a3_4e80_9fa8_13619d14f545 priv;\r
-       }\r
-\r
-       [StructLayout(LayoutKind.Sequential)]\r
-       public struct hb_audio_config_s\r
-       {\r
-               public hb_audio_config_output_s output;\r
-               public hb_audio_config_input_s input;\r
-\r
-               public hb_audio_config_lang_s lang;\r
-       }\r
-\r
-       [StructLayout(LayoutKind.Sequential)]\r
-       public struct hb_audio_config_output_s\r
-       {\r
-               public int mixdown;\r
-\r
-               /// int\r
-               public int track;\r
-\r
-               /// uint32_t->unsigned int\r
-               public uint codec;\r
-\r
-               /// int\r
-               public int samplerate;\r
-\r
-               public int samples_per_frame;\r
-\r
-               /// int\r
-               public int bitrate;\r
-\r
-        public double quality;\r
-\r
-        public double compression_level;\r
-\r
-               /// double\r
-               public double dynamic_range_compression;\r
-\r
-               public double gain;\r
-\r
-               public int normalize_mix_level;\r
-\r
-               public int dither_method;\r
-\r
-               public IntPtr name;\r
-\r
-               public int delay;\r
-       }\r
-\r
-       [StructLayout(LayoutKind.Sequential)]\r
-       public struct hb_audio_config_input_s\r
-       {\r
-               /// int\r
-               public int track;\r
-\r
-               /* Input audio codec */\r
-               public uint codec;\r
-\r
-               /* Per-codec config info */\r
-               public uint codec_param;\r
-\r
-               /* Registration descriptor of source */\r
-               public uint reg_desc;\r
-\r
-               /* Stream type from source stream */\r
-               public uint stream_type;\r
-\r
-               /* Substream type for multiplexed streams */\r
-               public uint substream_type;\r
-\r
-               /* Bitsream version */\r
-               public uint version;\r
-\r
-               /* Bitstream flags, codec-specific */\r
-               public uint flags;\r
-\r
-               /* Bitstream mode, codec-specific */\r
-               public uint mode;\r
-\r
-               /* Input sample rate (Hz) */\r
-               public int samplerate;\r
-\r
-               /* Number of samples per frame */\r
-               public int samples_per_frame;\r
-\r
-               /* Input bitrate (bps) */\r
-               public int bitrate;\r
-\r
-               /* Source matrix encoding mode, set by the audio decoder */\r
-               public int matrix_encoding;\r
-\r
-               /* Source channel layout, set by the audio decoder */\r
-               public ulong channel_layout;\r
-\r
-               /* Source channel map, set by the audio decoder */\r
-               // hb_chan_map_t\r
-               public IntPtr channel_map;\r
-       }\r
-\r
-       [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]\r
-       public struct hb_audio_config_lang_s\r
-       {\r
-               /// char[1024]\r
-               [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1024)]\r
-               public string description;\r
-\r
-               /// char[1024]\r
-               [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1024)]\r
-               public string simple;\r
-\r
-               /// char[4]\r
-               [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 4)]\r
-               public string iso639_2;\r
-\r
-               /// uint8_t->unsigned char\r
-               public byte type;\r
-       }\r
-}\r
diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/hb_chapter_s.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/hb_chapter_s.cs
deleted file mode 100644 (file)
index fa3c63a..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-// --------------------------------------------------------------------------------------------------------------------\r
-// <copyright file="hb_chapter_s.cs" company="HandBrake Project (http://handbrake.fr)">\r
-//   This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.\r
-// </copyright>\r
-// <summary>\r
-//   Defines the hb_chapter_s type.\r
-// </summary>\r
-// <auto-generated> Disable Stylecop Warnings for this file  </auto-generated>\r
-// --------------------------------------------------------------------------------------------------------------------\r
-\r
-namespace HandBrake.Interop.HbLib\r
-{\r
-       using System.Runtime.InteropServices;\r
-\r
-       [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]\r
-       public struct hb_chapter_s\r
-       {\r
-               /// int\r
-               public int index;\r
-\r
-               /// int\r
-               public int pgcn;\r
-\r
-               /// int\r
-               public int pgn;\r
-\r
-               /// int\r
-               public int cell_start;\r
-\r
-               /// int\r
-               public int cell_end;\r
-\r
-               /// int\r
-               public ulong block_start;\r
-\r
-               /// int\r
-               public ulong block_end;\r
-\r
-               /// int\r
-               public ulong block_count;\r
-\r
-               /// int\r
-               public int hours;\r
-\r
-               /// int\r
-               public int minutes;\r
-\r
-               /// int\r
-               public int seconds;\r
-\r
-               /// uint64_t->unsigned int\r
-               public ulong duration;\r
-\r
-               /// char *\r
-               [MarshalAs(UnmanagedType.LPStr)]\r
-               public string title;\r
-       }\r
-}\r
index 86d8f3f0857a8fd9e69dbd5eed8eb3330bd602bd..7c107f41c280fd071dd442e1cc5d6d99ff5f0c31 100644 (file)
@@ -1,9 +1,4 @@
-using System;\r
-using System.Collections.Generic;\r
-using System.Linq;\r
-using System.Text;\r
-\r
-namespace HandBrake.Interop.HbLib\r
+namespace HandBrake.Interop.HbLib\r
 {\r
        public enum hb_error_code\r
        {\r
diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/hb_filter_object_s.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/hb_filter_object_s.cs
deleted file mode 100644 (file)
index 1329b88..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-// --------------------------------------------------------------------------------------------------------------------\r
-// <copyright file="hb_filter_object_s.cs" company="HandBrake Project (http://handbrake.fr)">\r
-//   This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.\r
-// </copyright>\r
-// <auto-generated> Disable Stylecop Warnings for this file  </auto-generated>\r
-// --------------------------------------------------------------------------------------------------------------------\r
-\r
-namespace HandBrake.Interop.HbLib\r
-{\r
-       using System;\r
-       using System.Runtime.InteropServices;\r
-\r
-       [StructLayout(LayoutKind.Sequential)]\r
-       public struct hb_filter_object_s\r
-       {\r
-               public int id;\r
-               public int enforce_order;\r
-               public IntPtr name;\r
-               public IntPtr settings;\r
-\r
-               // Internal stuff we need to marshal\r
-               public IntPtr init;\r
-               public IntPtr work;\r
-               public IntPtr close;\r
-               public IntPtr info;\r
-               public IntPtr fifo_in;\r
-               public IntPtr fifo_out;\r
-               public IntPtr subtitle;\r
-               public IntPtr private_data;\r
-               public IntPtr thread;\r
-               public IntPtr done;\r
-               public int status;\r
-               public int chapter_val;\r
-               public long chapter_time;\r
-       }\r
-}\r
index 2821b2d1cbd1a16460074809f75522c9a33a5c56..77c21a190df1a62cf5dbdf5fcbb1281df7d73e68 100644 (file)
@@ -7,84 +7,7 @@
 \r
 namespace HandBrake.Interop.HbLib\r
 {\r
-       using System;\r
-       using System.Runtime.InteropServices;\r
-\r
-       [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]\r
-       public struct hb_subtitle_s\r
-       {\r
-               /// int\r
-               public int id;\r
-\r
-               /// int\r
-               public int track;\r
-\r
-               public int out_track;\r
-\r
-               /// hb_subtitle_config_t->hb_subtitle_config_s\r
-               public hb_subtitle_config_s config;\r
-\r
-               /// hb_subtitle_s_subtype\r
-               public hb_subtitle_s_subtype format;\r
-\r
-               /// hb_subtitle_s_subsource\r
-               public hb_subtitle_s_subsource source;\r
-\r
-               /// char[1024]\r
-               [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1024)]\r
-               public string lang;\r
-\r
-               /// char[4]\r
-               [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 4)]\r
-               public string iso639_2;\r
-\r
-               /// uint8_t->unsigned char\r
-               public byte type;\r
-\r
-               [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16, ArraySubType = UnmanagedType.U4)]\r
-               public uint[] palette;\r
-\r
-               public byte palette_set;\r
-\r
-               public int width;\r
-\r
-               public int height;\r
-\r
-               public IntPtr extradata;\r
-\r
-               public int extradata_size;\r
-\r
-               /// int\r
-               public int hits;\r
-\r
-               /// int\r
-               public int forced_hits;\r
-\r
-               public uint codec;\r
-\r
-               public uint reg_desc;\r
-\r
-               public uint stream_type;\r
-\r
-               public uint substream_type;\r
-\r
-               /// hb_fifo_t*\r
-               public IntPtr fifo_in;\r
-\r
-               /// hb_fifo_t*\r
-               public IntPtr fifo_raw;\r
-\r
-               /// hb_fifo_t*\r
-               public IntPtr fifo_sync;\r
-\r
-               /// hb_fifo_t*\r
-               public IntPtr fifo_out;\r
-\r
-               /// hb_mux_data_t*\r
-               public IntPtr mux_data;\r
-       }\r
-\r
-       public enum hb_subtitle_s_subtype\r
+    public enum hb_subtitle_s_subtype\r
        {\r
                PICTURESUB,\r
 \r
index 3e43ac2a63d8394df411798deb35ed6a2d6ae596..2e9d498684832585cede6a93f0c05f8187a2e8f1 100644 (file)
@@ -16,14 +16,14 @@ namespace HandBrake.Interop.HbLib
                /// Anonymous_990d28ea_6cf3_4fbc_8143_4df9513e9550\r
                public hb_title_type_anon type;\r
 \r
-               public uint reg_desc;
-
-               /// char[1024]
-               [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1024)]
-               public byte[] path;
-
-               /// char[1024]
-               [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1024)]
+               public uint reg_desc;\r
+\r
+               /// char[1024]\r
+               [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1024)]\r
+               public byte[] path;\r
+\r
+               /// char[1024]\r
+               [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1024)]\r
                public string name;\r
 \r
                /// int\r
diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/hb_title_set_s.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/hb_title_set_s.cs
deleted file mode 100644 (file)
index 087e7cd..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-// --------------------------------------------------------------------------------------------------------------------\r
-// <copyright file="hb_title_set_s.cs" company="HandBrake Project (http://handbrake.fr)">\r
-//   This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.\r
-// </copyright>\r
-// <auto-generated> Disable Stylecop Warnings for this file  </auto-generated>\r
-// --------------------------------------------------------------------------------------------------------------------\r
-\r
-namespace HandBrake.Interop.HbLib\r
-{\r
-       using System;\r
-       using System.Runtime.InteropServices;\r
-\r
-       [StructLayout(LayoutKind.Sequential)]\r
-       public struct hb_title_set_s\r
-       {\r
-               ///hb_list_t   *\r
-               public IntPtr list_title;\r
-\r
-               // int\r
-               public int feature;\r
-       }\r
-}\r
index ea86eb85c75a341b0e3e78a7ef1adddbdd544688..64c03cbef964934d9751acdd3ed95e3c6ea3269e 100644 (file)
@@ -127,26 +127,6 @@ namespace HandBrake.Interop.Interfaces
         /// </returns>\r
         BitmapImage GetPreview(EncodeJob job, int previewNumber);\r
 \r
-        /// <summary>\r
-        /// Gets the final size for a given encode job.\r
-        /// </summary>\r
-        /// <param name="job">\r
-        /// The encode job to use.\r
-        /// </param>\r
-        /// <param name="width">\r
-        /// The storage width.\r
-        /// </param>\r
-        /// <param name="height">\r
-        /// The storage height.\r
-        /// </param>\r
-        /// <param name="parWidth">\r
-        /// The pixel aspect X number.\r
-        /// </param>\r
-        /// <param name="parHeight">\r
-        /// The pixel aspect Y number.\r
-        /// </param>\r
-        void GetSize(EncodeJob job, out int width, out int height, out int parWidth, out int parHeight);\r
-\r
         /// <summary>\r
         /// Pauses the current encode.\r
         /// </summary>\r
@@ -218,7 +198,6 @@ namespace HandBrake.Interop.Interfaces
         /// </param>\r
         void StartScan(string path, int previewCount, int titleIndex);\r
 \r
-\r
         /// <summary>\r
         /// Starts a scan of the given path.\r
         /// </summary>\r
index 684eac6861d23e41efbabbae92c1bc6b41b4377c..24ac9202b8a63324103c1add8b9a8964d7bc0d59 100644 (file)
@@ -17,7 +17,7 @@ namespace HandBrake.Interop.Json.Anamorphic
         /// <summary>\r
         /// Gets or sets the dest geometry.\r
         /// </summary>\r
-        public DestSettings DestGeometry { get; set; }\r
+        public DestSettings DestSettings { get; set; }\r
 \r
         /// <summary>\r
         /// Gets or sets the source geometry.\r
index 1f4f95542877d738486fb2878c57e81687c434a0..be65d4150d94f4873bb83f04c0d5c5d5de4ec95a 100644 (file)
@@ -44,7 +44,7 @@ namespace HandBrake.Interop.Json.Anamorphic
         /// <summary>\r
         /// Gets or sets a value indicating whether keep display aspect.\r
         /// </summary>\r
-        public bool Keep { get; set; }\r
+        public int Keep { get; set; }\r
 \r
         /// <summary>\r
         /// Gets or sets the max height.\r
index c5e6c6aa180b7846f65ef63b07428300c5931f6e..c4849f7c5d208c18a63adcd46e66a09b60d9dd1b 100644 (file)
@@ -14,7 +14,7 @@ namespace HandBrake.Interop.Json.Encode
     /// <summary>\r
     /// The root object.\r
     /// </summary>\r
-    public class JsonEncodeObject\r
+    internal class JsonEncodeObject\r
     {\r
         /// <summary>\r
         /// Gets or sets the audio.\r
diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Json/Factories/AnamorphicFactory.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Json/Factories/AnamorphicFactory.cs
new file mode 100644 (file)
index 0000000..cb882c1
--- /dev/null
@@ -0,0 +1,109 @@
+// --------------------------------------------------------------------------------------------------------------------\r
+// <copyright file="AnamorphicFactory.cs" company="HandBrake Project (http://handbrake.fr)">\r
+//   This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.\r
+// </copyright>\r
+// <summary>\r
+//   The Anamorphic factory.\r
+// </summary>\r
+// --------------------------------------------------------------------------------------------------------------------\r
+\r
+namespace HandBrake.Interop.Json.Factories\r
+{\r
+    using System;\r
+    using System.Collections.Generic;\r
+    using System.Runtime.InteropServices;\r
+\r
+    using HandBrake.Interop.HbLib;\r
+    using HandBrake.Interop.Json.Anamorphic;\r
+    using HandBrake.Interop.Model;\r
+    using HandBrake.Interop.Model.Encoding;\r
+    using HandBrake.Interop.Model.Scan;\r
+\r
+    using Newtonsoft.Json;\r
+\r
+    public class AnamorphicFactory\r
+    {\r
+        /// <summary>\r
+        /// The keep setting.\r
+        /// </summary>\r
+        public enum KeepSetting\r
+        {\r
+            HB_KEEP_WIDTH = 0x01,\r
+            HB_KEEP_HEIGHT = 0x02,\r
+            HB_KEEP_DISPLAY_ASPECT = 0x04\r
+        }\r
+\r
+        /// <summary>\r
+        /// The create geometry.\r
+        /// </summary>\r
+        /// <param name="job">\r
+        /// The job.\r
+        /// </param>\r
+        /// <param name="title">\r
+        /// The current title.\r
+        /// </param>\r
+        /// <param name="keepWidthOrHeight">\r
+        /// Keep Width or Height. (Not Display Aspect)\r
+        /// </param>\r
+        /// <returns>\r
+        /// The <see cref="Scan.Geometry"/>.\r
+        /// </returns>\r
+        public static Geometry CreateGeometry(EncodeJob job, Title title, KeepSetting keepWidthOrHeight) // Todo remove the need for these objects. Should use simpler objects.\r
+        {\r
+            int settingMode = (int)keepWidthOrHeight + (job.EncodingProfile.KeepDisplayAspect ? 0x04 : 0);\r
+\r
+            // Sanatise the Geometry First.\r
+            AnamorphicGeometry anamorphicGeometry = new AnamorphicGeometry\r
+            {\r
+                SourceGeometry = new SourceGeometry\r
+                                 {\r
+                                    Width = title.Resolution.Width,\r
+                                    Height = title.Resolution.Height,\r
+                                    PAR = new PAR { Num = title.ParVal.Width, Den = title.ParVal.Height }\r
+                                 },\r
+                DestSettings = new DestSettings\r
+                               {\r
+                                    AnamorphicMode = (int)job.EncodingProfile.Anamorphic,\r
+                                    Geometry = { \r
+                                                Width = job.EncodingProfile.Width, Height = job.EncodingProfile.Height,\r
+                                                PAR = new PAR\r
+                                                      {\r
+                                                          Num = job.EncodingProfile.Anamorphic != Anamorphic.Custom ? title.ParVal.Width : job.EncodingProfile.PixelAspectX,\r
+                                                          Den = job.EncodingProfile.Anamorphic != Anamorphic.Custom ? title.ParVal.Height : job.EncodingProfile.PixelAspectY,\r
+                                                      } \r
+                                               },\r
+                                    Keep = settingMode,\r
+                                    Crop = new List<int> { job.EncodingProfile.Cropping.Top, job.EncodingProfile.Cropping.Bottom, job.EncodingProfile.Cropping.Left, job.EncodingProfile.Cropping.Right },\r
+                                    Modulus = job.EncodingProfile.Modulus,\r
+                                    MaxWidth = job.EncodingProfile.MaxWidth,\r
+                                    MaxHeight = job.EncodingProfile.MaxHeight,\r
+                                    ItuPAR = false\r
+                               }\r
+            };\r
+\r
+            if (job.EncodingProfile.Anamorphic == Anamorphic.Custom)\r
+            {\r
+                anamorphicGeometry.DestSettings.Geometry.PAR = new PAR { Num = job.EncodingProfile.PixelAspectX, Den = job.EncodingProfile.PixelAspectY };\r
+            }\r
+            else\r
+            {\r
+                anamorphicGeometry.DestSettings.Geometry.PAR = new PAR { Num = title.ParVal.Width, Den = title.ParVal.Height };\r
+            }\r
+\r
+            string encode = JsonConvert.SerializeObject(anamorphicGeometry, Formatting.Indented, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });\r
+            IntPtr json = HBFunctions.hb_set_anamorphic_size_json(Marshal.StringToHGlobalAnsi(encode));\r
+            string result = Marshal.PtrToStringAnsi(json);\r
+            AnamorphicResult resultGeometry = JsonConvert.DeserializeObject<AnamorphicResult>(result);\r
+\r
+            // Setup the Destination Gemotry.\r
+            Geometry geometry = new Geometry\r
+                {\r
+                    Width = resultGeometry.Width,\r
+                    Height = resultGeometry.Height,\r
+                    PAR = resultGeometry.PAR\r
+                };\r
+            return geometry;\r
+        }\r
+\r
+    }\r
+}\r
index 17013ae5bff1de6e16daecd283516216ca0a0ec5..fd2274e3f36ac09c406684aaff485cb7e3eca4a7 100644 (file)
@@ -418,52 +418,6 @@ namespace HandBrake.Interop.Json.Factories
             return filter;\r
         }\r
 \r
-        /// <summary>\r
-        /// The create geometry.\r
-        /// </summary>\r
-        /// <param name="job">\r
-        /// The job.\r
-        /// </param>\r
-        /// <returns>\r
-        /// The <see cref="Geometry"/>.\r
-        /// </returns>\r
-        private static Json.Anamorphic.Geometry CreateGeometry(EncodeJob job, JsonScanObject scannedSource)\r
-        {\r
-            TitleList title = scannedSource.TitleList.FirstOrDefault(c => c.Index == job.Title);\r
-\r
-            // Sanatise the Geometry First.\r
-            AnamorphicGeometry anamorphicGeometry = new AnamorphicGeometry\r
-                {\r
-                    DestGeometry = new DestSettings(),\r
-                    SourceGeometry =\r
-                        new SourceGeometry\r
-                            {\r
-                                Width = title.Geometry.Width,\r
-                                Height = title.Geometry.Height,\r
-                                PAR = new Json.Anamorphic.PAR { Num = title.Geometry.PAR.Num, Den = title.Geometry.PAR.Den }\r
-                            }\r
-                };\r
-\r
-            anamorphicGeometry.DestGeometry.AnamorphicMode = (int)job.EncodingProfile.Anamorphic;\r
-            anamorphicGeometry.DestGeometry.Geometry.Width = job.EncodingProfile.Width;\r
-            anamorphicGeometry.DestGeometry.Geometry.Height = job.EncodingProfile.Height;\r
-            anamorphicGeometry.DestGeometry.Keep = job.EncodingProfile.KeepDisplayAspect;\r
-            anamorphicGeometry.DestGeometry.Geometry.PAR = new Json.Anamorphic.PAR { Num = job.EncodingProfile.PixelAspectX, Den = job.EncodingProfile.PixelAspectY };\r
-            anamorphicGeometry.DestGeometry.Crop = new List<int> { job.EncodingProfile.Cropping.Top, job.EncodingProfile.Cropping.Bottom, job.EncodingProfile.Cropping.Left, job.EncodingProfile.Cropping.Right };\r
-\r
-            string encode = JsonConvert.SerializeObject(anamorphicGeometry, Formatting.Indented, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });\r
-            IntPtr json = HBFunctions.hb_set_anamorphic_size_json(Marshal.StringToHGlobalAnsi(encode));\r
-            string statusJson = Marshal.PtrToStringAnsi(json);\r
-            AnamorphicResult sanatisedGeometry = JsonConvert.DeserializeObject<AnamorphicResult>(statusJson);\r
-\r
-            // Setup the Destination Gemotry.\r
-            Json.Anamorphic.Geometry geometry = new Json.Anamorphic.Geometry();\r
-            geometry.Width = sanatisedGeometry.Width;\r
-            geometry.Height = sanatisedGeometry.Height;\r
-            geometry.PAR = sanatisedGeometry.PAR;\r
-            return geometry;\r
-        }\r
-\r
         /// <summary>\r
         /// The create meta data.\r
         /// </summary>\r
@@ -478,40 +432,5 @@ namespace HandBrake.Interop.Json.Factories
             MetaData metaData = new MetaData();\r
             return metaData;\r
         }\r
-\r
-\r
-        /// <summary>\r
-        /// Adds a filter to the given filter list.\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="settings">Settings for the filter.</param>\r
-        /// <param name="allocatedMemory">The list of allocated memory.</param>\r
-        private void AddFilter(List<hb_filter_object_s> filterList, int filterType, string settings, List<IntPtr> allocatedMemory)\r
-        {\r
-            IntPtr settingsNativeString = Marshal.StringToHGlobalAnsi(settings);\r
-            hb_filter_object_s filter = InteropUtilities.ToStructureFromPtr<hb_filter_object_s>(HBFunctions.hb_filter_init(filterType));\r
-            filter.settings = settingsNativeString;\r
-\r
-            allocatedMemory.Add(settingsNativeString);\r
-            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
 }\r
index 446ae5c1be9a6d9b05f52f916aa858ff5ab111ed..e8153b239a7a2c2d6e50404aed5265bd899901a5 100644 (file)
@@ -143,40 +143,9 @@ namespace HandBrake.Interop.Json.Factories
                     Language = subtitle.Language,\r
                     LanguageCode = subtitle.LanguageCode,\r
                     SubtitleSourceInt = subtitle.Source,\r
-                   // SubtitleSource =  null,\r
+                    SubtitleSource = (SubtitleSource)subtitle.Source  // TODO Check correct\r
                 };\r
 \r
\r
-                //switch (subtitle.subsource)\r
-                //{\r
-                //    case hb_subtitle_s_subsource.CC608SUB:\r
-                //        newSubtitle.SubtitleSource = SubtitleSource.CC608;\r
-                //        break;\r
-                //    case hb_subtitle_s_subsource.CC708SUB:\r
-                //        newSubtitle.SubtitleSource = SubtitleSource.CC708;\r
-                //        break;\r
-                //    case hb_subtitle_s_subsource.SRTSUB:\r
-                //        newSubtitle.SubtitleSource = SubtitleSource.SRT;\r
-                //        break;\r
-                //    case hb_subtitle_s_subsource.SSASUB:\r
-                //        newSubtitle.SubtitleSource = SubtitleSource.SSA;\r
-                //        break;\r
-                //    case hb_subtitle_s_subsource.TX3GSUB:\r
-                //        newSubtitle.SubtitleSource = SubtitleSource.TX3G;\r
-                //        break;\r
-                //    case hb_subtitle_s_subsource.UTF8SUB:\r
-                //        newSubtitle.SubtitleSource = SubtitleSource.UTF8;\r
-                //        break;\r
-                //    case hb_subtitle_s_subsource.VOBSUB:\r
-                //        newSubtitle.SubtitleSource = SubtitleSource.VobSub;\r
-                //        break;\r
-                //    case hb_subtitle_s_subsource.PGSSUB:\r
-                //        newSubtitle.SubtitleSource = SubtitleSource.PGS;\r
-                //        break;\r
-                //    default:\r
-                //        break;\r
-                //}\r
-\r
                 subtiles.Add(newSubtitle);\r
 \r
                 currentSubtitleTrack++;\r
@@ -241,8 +210,7 @@ namespace HandBrake.Interop.Json.Factories
                 {\r
                     Name = chapter.Name,\r
                     ChapterNumber = currentTrack,\r
-                    Duration = new TimeSpan(chapter.Duration.Hours, chapter.Duration.Minutes, chapter.Duration.Seconds),\r
-                    // DurationPts = chapter.duration\r
+                    Duration = new TimeSpan(chapter.Duration.Hours, chapter.Duration.Minutes, chapter.Duration.Seconds)\r
                 };\r
 \r
                 tracks.Add(newChapter);\r
index 42e4428ed0fb60fece40e746797406e2d7b10b81..f410bc5bb8d44c13ce1ba045e24ed2f7d61a3dbe 100644 (file)
@@ -25,4 +25,4 @@ namespace HandBrake.Interop.Model.Encoding
                [Display(Name = "Custom")]\r
                Custom = 3\r
        }\r
-}\r
+}
\ No newline at end of file
index 70e35e6f3f7d8383971ffda752c4c9c900c4ba3b..3d7a999f828f7b23eed8a4c10b9ce1f2c64c7b73 100644 (file)
@@ -32,11 +32,6 @@ namespace HandBrake.Interop.Model.Scan
                /// </summary>\r
                public TimeSpan Duration { get; set; }\r
 \r
-               /// <summary>\r
-               /// Gets or sets the duration of this chapter in PTS.\r
-               /// </summary>\r
-               public ulong DurationPts { get; set; }\r
-\r
                /// <summary>\r
                /// Override of the ToString method to make this object easier to use in the UI\r
                /// </summary>\r