]> granicus.if.org Git - handbrake/commitdiff
Interop: Updated to work with hb_chapter_set_title for chapter markers.
authorrandomengy <david.rickard@gmail.com>
Thu, 22 Nov 2012 18:36:29 +0000 (18:36 +0000)
committerrandomengy <david.rickard@gmail.com>
Thu, 22 Nov 2012 18:36:29 +0000 (18:36 +0000)
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5078 b64f7644-9d1e-0410-96f1-a4d463321fa5

win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs
win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeUtils.cs
win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/HbFunctions.cs
win/CS/HandBrake.Interop/HandBrakeInterop/InteropUtilities.cs
win/CS/HandBrake.Interop/HandBrakeInterop/Properties/AssemblyInfo.cs

index 4b54674b6539c2ca2876e88943b729b19704d530..a1263a4fbd13878adad337aee63c0619ad708897 100644 (file)
@@ -405,30 +405,8 @@ namespace HandBrake.Interop
                        IntPtr nativeJobPtr = HBFunctions.hb_job_init_by_index(this.hbHandle, job.Title);\r
                        var nativeJob = InteropUtilities.ReadStructure<hb_job_s>(nativeJobPtr);\r
 \r
-                       //hb_job_s nativeJob = InteropUtilities.ReadStructure<hb_job_s>(this.GetOriginalTitle(job.Title).job);\r
                        this.encodeAllocatedMemory = this.ApplyJob(ref nativeJob, job, preview, previewNumber, previewSeconds, overallSelectedLengthSeconds);\r
 \r
-                       if (!preview && profile.IncludeChapterMarkers)\r
-                       {\r
-                               Title title = this.GetTitle(job.Title);\r
-                               int numChapters = title.Chapters.Count;\r
-\r
-                               if (job.UseDefaultChapterNames)\r
-                               {\r
-                                       for (int i = 0; i < numChapters; i++)\r
-                                       {\r
-                                               HBFunctions.hb_set_chapter_name(this.hbHandle, job.Title, i + 1, "Chapter " + (i + 1));\r
-                                       }\r
-                               }\r
-                               else\r
-                               {\r
-                                       for (int i = 0; i < numChapters; i++)\r
-                                       {\r
-                                               HBFunctions.hb_set_chapter_name(this.hbHandle, job.Title, i + 1, job.CustomChapterNames[i]);\r
-                                       }\r
-                               }\r
-                       }\r
-\r
                        this.subtitleScan = false;\r
                        if (job.Subtitles.SourceSubtitles != null)\r
                        {\r
@@ -786,7 +764,7 @@ namespace HandBrake.Interop
 \r
                                IntPtr titleSetPtr = HBFunctions.hb_get_title_set(this.hbHandle);\r
                                hb_title_set_s titleSet = InteropUtilities.ReadStructure<hb_title_set_s>(titleSetPtr);\r
-                               this.originalTitles = InteropUtilities.ConvertList<hb_title_s>(titleSet.list_title);\r
+                               this.originalTitles = titleSet.list_title.ToList<hb_title_s>();\r
 \r
                                foreach (hb_title_s title in this.originalTitles)\r
                                {\r
@@ -988,8 +966,37 @@ namespace HandBrake.Interop
                                }\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
+                                       {\r
+                                               if (i < nativeChapters.Count && i < job.CustomChapterNames.Count)\r
+                                               {\r
+                                                       HBFunctions.hb_chapter_set_title(nativeChapters[i], job.CustomChapterNames[i]);\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+\r
                        Cropping crop = GetCropping(profile, title);\r
 \r
                        nativeJob.crop[0] = crop.Top;\r
@@ -1309,7 +1316,7 @@ namespace HandBrake.Interop
 \r
                        // areBframes\r
                        // color_matrix\r
-                       List<hb_audio_s> titleAudio = InteropUtilities.ConvertList<hb_audio_s>(originalTitle.list_audio);\r
+                       List<hb_audio_s> titleAudio = originalTitle.list_audio.ToList<hb_audio_s>();\r
                        \r
                        var audioList = new List<hb_audio_s>();\r
                        int numTracks = 0;\r
@@ -1361,7 +1368,7 @@ namespace HandBrake.Interop
                        {\r
                                if (job.Subtitles.SourceSubtitles != null && job.Subtitles.SourceSubtitles.Count > 0)\r
                                {\r
-                                       List<hb_subtitle_s> titleSubtitles = InteropUtilities.ConvertList<hb_subtitle_s>(originalTitle.list_subtitle);\r
+                                       List<hb_subtitle_s> titleSubtitles = originalTitle.list_subtitle.ToList<hb_subtitle_s>();\r
 \r
                                        foreach (SourceSubtitle sourceSubtitle in job.Subtitles.SourceSubtitles)\r
                                        {\r
@@ -1682,7 +1689,7 @@ namespace HandBrake.Interop
                        }\r
 \r
                        int currentSubtitleTrack = 1;\r
-                       List<hb_subtitle_s> subtitleList = InteropUtilities.ConvertList<hb_subtitle_s>(title.list_subtitle);\r
+                       List<hb_subtitle_s> subtitleList = title.list_subtitle.ToList<hb_subtitle_s>();\r
                        foreach (hb_subtitle_s subtitle in subtitleList)\r
                        {\r
                                var newSubtitle = new Subtitle\r
@@ -1737,7 +1744,7 @@ namespace HandBrake.Interop
                        }\r
 \r
                        int currentAudioTrack = 1;\r
-                       List<hb_audio_s> audioList = InteropUtilities.ConvertList<hb_audio_s>(title.list_audio);\r
+                       List<hb_audio_s> audioList = title.list_audio.ToList<hb_audio_s>();\r
                        foreach (hb_audio_s audio in audioList)\r
                        {\r
                                var newAudio = new AudioTrack\r
@@ -1758,7 +1765,7 @@ namespace HandBrake.Interop
                                currentAudioTrack++;\r
                        }\r
 \r
-                       List<hb_chapter_s> chapterList = InteropUtilities.ConvertList<hb_chapter_s>(title.list_chapter);\r
+                       List<hb_chapter_s> chapterList = title.list_chapter.ToList<hb_chapter_s>();\r
                        foreach (hb_chapter_s chapter in chapterList)\r
                        {\r
                                var newChapter = new Chapter\r
index 496136421e1206f99f4493be84000c0783072008..6fde37c57cfa342b81637a484bd5bc202b31f140 100644 (file)
@@ -165,6 +165,46 @@ namespace HandBrake.Interop
                                fakeInterlaced ? 1 : 0) == 0;\r
                }\r
 \r
+               /// <summary>\r
+               /// Creates an X264 options string from the given settings.\r
+               /// </summary>\r
+               /// <param name="preset">The x264 preset.</param>\r
+               /// <param name="tunes">The x264 tunes being used.</param>\r
+               /// <param name="extraOptions">The extra options string.</param>\r
+               /// <param name="profile">The H.264 profile.</param>\r
+               /// <param name="level">The H.264 level.</param>\r
+               /// <param name="width">The width of the final picture.</param>\r
+               /// <param name="height">The height of the final picture.</param>\r
+               /// <returns>The full x264 options string from the given inputs.</returns>\r
+               public static string CreateX264OptionsString(\r
+                       string preset, \r
+                       IList<string> tunes, \r
+                       string extraOptions, \r
+                       string profile,\r
+                       string level, \r
+                       int width, \r
+                       int height)\r
+               {\r
+                       if (width <= 0)\r
+                       {\r
+                               throw new ArgumentException("width must be positive.");\r
+                       }\r
+\r
+                       if (height <= 0)\r
+                       {\r
+                               throw new ArgumentException("height must be positive.");\r
+                       }\r
+\r
+                       return HBFunctions.hb_x264_param_unparse(\r
+                               preset,\r
+                               string.Join(",", tunes),\r
+                               extraOptions,\r
+                               profile,\r
+                               level,\r
+                               width,\r
+                               height);\r
+               }\r
+\r
                /// <summary>\r
                /// Gets the total number of seconds on the given encode job.\r
                /// </summary>\r
index f033dc4488e7247483d0ab8fb746cc0299f81c14..cd4ca877d24dd0812c5cce2d29016fb44a969186 100644 (file)
@@ -135,9 +135,6 @@ namespace HandBrake.Interop.HbLib
                [DllImport("hb.dll", EntryPoint = "hb_job", CallingConvention = CallingConvention.Cdecl)]\r
                public static extern IntPtr hb_job(IntPtr hbHandle, int jobIndex);\r
 \r
-               [DllImport("hb.dll", EntryPoint = "hb_set_chapter_name", CallingConvention = CallingConvention.Cdecl)]\r
-               public static extern void hb_set_chapter_name(IntPtr hbHandle, int title_index, int chapter_index, [In] [MarshalAs(UnmanagedType.LPStr)] string chapter_name);\r
-\r
                [DllImport("hb.dll", EntryPoint = "hb_set_job", CallingConvention = CallingConvention.Cdecl)]\r
                public static extern void hb_set_job(IntPtr hbHandle, int title_index, ref hb_job_s job);\r
 \r
@@ -324,7 +321,7 @@ namespace HandBrake.Interop.HbLib
 \r
                ///void hb_chapter_set_title(hb_chapter_t *chapter, const char *title);\r
                [DllImport("hb.dll", EntryPoint = "hb_chapter_set_title", CallingConvention = CallingConvention.Cdecl)]\r
-               public static extern void hb_chapter_set_title(ref hb_chapter_s chapter, IntPtr title);\r
+               public static extern void hb_chapter_set_title(IntPtr chapter, [In] [MarshalAs(UnmanagedType.LPStr)] string 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
@@ -339,5 +336,15 @@ namespace HandBrake.Interop.HbLib
 \r
                [DllImport("hb.dll", EntryPoint = "hb_check_h264_level", CallingConvention = CallingConvention.Cdecl)]\r
                public static extern int hb_check_h264_level([In] [MarshalAs(UnmanagedType.LPStr)] string level, int width, int height, int fps_num, int fps_den, int interlaced, int fake_interlaced);\r
+\r
+               [DllImport("hb.dll", EntryPoint = "hb_x264_param_unparse", CallingConvention = CallingConvention.Cdecl)]\r
+               public static extern string hb_x264_param_unparse(\r
+                       [In] [MarshalAs(UnmanagedType.LPStr)] string x264_preset,\r
+                       [In] [MarshalAs(UnmanagedType.LPStr)] string x264_tune,\r
+                       [In] [MarshalAs(UnmanagedType.LPStr)] string x264_encopts,\r
+                       [In] [MarshalAs(UnmanagedType.LPStr)] string x264_profile,\r
+                       [In] [MarshalAs(UnmanagedType.LPStr)] string h264_level,\r
+                       int width,\r
+                       int height);\r
        }\r
 }\r
index db72feac51b9452920f55941bbe80e30bc439909..de73dd607a4affdeb43f1998d65fd3d03399c884 100644 (file)
@@ -37,7 +37,7 @@ namespace HandBrake.Interop
                /// <typeparam name="T">The type of structure in the list.</typeparam>\r
                /// <param name="listPtr">The pointer to the native list.</param>\r
                /// <returns>The converted managed list.</returns>\r
-               public static List<T> ConvertList<T>(IntPtr listPtr)\r
+               public static List<T> ToList<T>(this IntPtr listPtr)\r
                {\r
                        List<T> returnList = new List<T>();\r
                        hb_list_s itemList = ReadStructure<hb_list_s>(listPtr);\r
@@ -51,6 +51,25 @@ namespace HandBrake.Interop
                        return returnList;\r
                }\r
 \r
+               /// <summary>\r
+               /// Converts the HB list to a managed list of pointers.\r
+               /// </summary>\r
+               /// <param name="listPtr">The list to convert.</param>\r
+               /// <returns>The managed list of pointers.</returns>\r
+               public static List<IntPtr> ToIntPtrList(this IntPtr listPtr)\r
+               {\r
+                       var returnList = new List<IntPtr>();\r
+                       hb_list_s itemList = ReadStructure<hb_list_s>(listPtr);\r
+\r
+                       for (int i = 0; i < itemList.items_count; i++)\r
+                       {\r
+                               IntPtr itemPtr = Marshal.ReadIntPtr(itemList.items, i * Marshal.SizeOf(typeof(IntPtr)));\r
+                               returnList.Add(itemPtr);\r
+                       }\r
+\r
+                       return returnList;\r
+               }\r
+\r
                /// <summary>\r
                /// Converts the given native array to a managed collection.\r
                /// </summary>\r
index 395fe93637198081feb00ce794d83de31cd0f14a..523d7a8ddb50c90fa9ad5bcf5b7aba473530601f 100644 (file)
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
 // You can specify all the values or you can default the Build and Revision Numbers \r
 // by using the '*' as shown below:\r
 // [assembly: AssemblyVersion("1.0.*")]\r
-[assembly: AssemblyVersion("1.32.0.0")]\r
-[assembly: AssemblyFileVersion("1.32.0.0")]\r
+[assembly: AssemblyVersion("1.33.0.0")]\r
+[assembly: AssemblyFileVersion("1.33.0.0")]\r