]> granicus.if.org Git - handbrake/commitdiff
Some additions for mixdowns and ability encode from JSON string.
authorRandomEngy <david.rickard@gmail.com>
Fri, 17 Nov 2017 07:02:28 +0000 (23:02 -0800)
committerScott <628593+sr55@users.noreply.github.com>
Sat, 18 Nov 2017 14:29:34 +0000 (14:29 +0000)
win/CS/HandBrake.ApplicationServices/Interop/HandBrakeEncoderHelpers.cs
win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstance.cs
win/CS/HandBrake.ApplicationServices/Interop/HbLib/HbFunctions.cs

index b0e72976abc4b255b135a6c1235a27aa893b102c..125c0444909744f37fdf0b1620d63140f49d0d6f 100644 (file)
@@ -244,6 +244,16 @@ namespace HandBrake.ApplicationServices.Interop
             return Mixdowns.SingleOrDefault(m => m.ShortName == shortName);\r
         }\r
 \r
+               /// <summary>\r
+               /// Gets the mixdown with the specified ID.\r
+               /// </summary>\r
+               /// <param name="id">The mixdown ID.</param>\r
+               /// <returns>The requested mixdown.</returns>\r
+           public static HBMixdown GetMixdown(int id)\r
+           {\r
+                   return Mixdowns.SingleOrDefault(m => m.Id == id);\r
+           }\r
+\r
         /// <summary>\r
         /// Gets the container with the specified short name.\r
         /// </summary>\r
@@ -489,6 +499,17 @@ namespace HandBrake.ApplicationServices.Interop
             return Mixdowns.Single(m => m.Id == defaultMixdown);\r
         }\r
 \r
+               /// <summary>\r
+               /// Sanitizes the given sample rate for the given encoder.\r
+               /// </summary>\r
+               /// <param name="encoder">The encoder.</param>\r
+               /// <param name="sampleRate">The sample rate to sanitize.</param>\r
+               /// <returns>The sanitized sample rate.</returns>\r
+           public static int SanitizeSampleRate(HBAudioEncoder encoder, int sampleRate)\r
+           {\r
+                   return HBFunctions.hb_audio_samplerate_find_closest(sampleRate, (uint)encoder.Id);\r
+           }\r
+\r
         /// <summary>\r
         /// Gets the bitrate limits for the given audio codec, sample rate and mixdown.\r
         /// </summary>\r
index 45b2f84882aa281260c9ea651077f40ac8caf7c9..b44dd385c7ae75b7ccd368eeb182df368610c9a2 100644 (file)
@@ -82,6 +82,11 @@ namespace HandBrake.ApplicationServices.Interop
         /// </summary>\r
         private JsonScanObject titles;\r
 \r
+        /// <summary>\r
+        /// The raw JSON for the titles list.\r
+        /// </summary>\r
+        private string titlesJson;\r
+\r
         /// <summary>\r
         /// The index of the default title.\r
         /// </summary>\r
@@ -153,6 +158,17 @@ namespace HandBrake.ApplicationServices.Interop
             }\r
         }\r
 \r
+        /// <summary>\r
+        /// Gets the raw JSON for the list of titles on this instance.\r
+        /// </summary>\r
+        public string TitlesJson\r
+        {\r
+            get\r
+            {\r
+                return this.titlesJson;\r
+            }\r
+        }\r
+\r
         /// <summary>\r
         /// Gets the index of the default title.\r
         /// </summary>\r
@@ -360,7 +376,17 @@ namespace HandBrake.ApplicationServices.Interop
             };\r
 \r
             string encode = JsonConvert.SerializeObject(encodeObject, Formatting.Indented, settings);\r
-            HBFunctions.hb_add_json(this.hbHandle, InteropUtilities.ToUtf8PtrFromString(encode));\r
+            this.StartEncode(encode);\r
+        }\r
+\r
+        /// <summary>\r
+        /// Starts an encode with the given job JSON.\r
+        /// </summary>\r
+        /// <param name="encodeJson">The JSON for the job to start.</param>\r
+        [HandleProcessCorruptedStateExceptions]\r
+        public void StartEncode(string encodeJson)\r
+        {\r
+            HBFunctions.hb_add_json(this.hbHandle, InteropUtilities.ToUtf8PtrFromString(encodeJson));\r
             HBFunctions.hb_start(this.hbHandle);\r
 \r
             this.encodePollTimer = new Timer();\r
@@ -497,8 +523,8 @@ namespace HandBrake.ApplicationServices.Interop
                 this.scanPollTimer.Stop();\r
 \r
                 var jsonMsg = HBFunctions.hb_get_title_set_json(this.hbHandle);\r
-                string scanJson = InteropUtilities.ToStringFromUtf8Ptr(jsonMsg);\r
-                this.log.LogMessage(scanJson, LogMessageType.Progress, LogLevel.Trace);\r
+                this.titlesJson = InteropUtilities.ToStringFromUtf8Ptr(jsonMsg);\r
+                this.log.LogMessage(this.titlesJson, LogMessageType.Progress, LogLevel.Trace);\r
 \r
                 if (string.IsNullOrEmpty(scanJson))\r
                 {\r
@@ -506,7 +532,7 @@ namespace HandBrake.ApplicationServices.Interop
                 }\r
                 else\r
                 {\r
-                    this.titles = JsonConvert.DeserializeObject<JsonScanObject>(scanJson);\r
+                    this.titles = JsonConvert.DeserializeObject<JsonScanObject>(this.titlesJson);\r
                     if (this.titles != null)\r
                     {\r
                         this.featureTitle = this.titles.MainFeature;\r
index beaf2e689672c3afcc6a567333d4d84fe2377081..63eac34684c37375550cfc67385d80c7ffd8838f 100644 (file)
@@ -201,6 +201,8 @@ namespace HandBrake.ApplicationServices.Interop.HbLib
         [DllImport("hb", EntryPoint = "hb_audio_samplerate_get_next", CallingConvention = CallingConvention.Cdecl)]\r
         public static extern IntPtr hb_audio_samplerate_get_next(IntPtr last);\r
 \r
+        [DllImport("hb", EntryPoint = "hb_audio_samplerate_find_closest", CallingConvention = CallingConvention.Cdecl)]\r
+           public static extern int hb_audio_samplerate_find_closest(int samplerate, uint codec);\r
 \r
         [DllImport("hb", EntryPoint = "hb_audio_bitrate_get_best", CallingConvention = CallingConvention.Cdecl)]\r
         public static extern int hb_audio_bitrate_get_best(uint codec, int bitrate, int samplerate, int mixdown);\r