From a020ee671a4baa3cfc03aa408776707a79e184b9 Mon Sep 17 00:00:00 2001 From: randomengy Date: Thu, 22 Nov 2012 18:36:29 +0000 Subject: [PATCH] Interop: Updated to work with hb_chapter_set_title for chapter markers. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5078 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- .../HandBrakeInterop/HandBrakeInstance.cs | 63 ++++++++++--------- .../HandBrakeInterop/HandBrakeUtils.cs | 40 ++++++++++++ .../HandBrakeInterop/HbLib/HbFunctions.cs | 15 +++-- .../HandBrakeInterop/InteropUtilities.cs | 21 ++++++- .../Properties/AssemblyInfo.cs | 4 +- 5 files changed, 108 insertions(+), 35 deletions(-) diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs index 4b54674b6..a1263a4fb 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs @@ -405,30 +405,8 @@ namespace HandBrake.Interop IntPtr nativeJobPtr = HBFunctions.hb_job_init_by_index(this.hbHandle, job.Title); var nativeJob = InteropUtilities.ReadStructure(nativeJobPtr); - //hb_job_s nativeJob = InteropUtilities.ReadStructure(this.GetOriginalTitle(job.Title).job); this.encodeAllocatedMemory = this.ApplyJob(ref nativeJob, job, preview, previewNumber, previewSeconds, overallSelectedLengthSeconds); - if (!preview && profile.IncludeChapterMarkers) - { - Title title = this.GetTitle(job.Title); - int numChapters = title.Chapters.Count; - - if (job.UseDefaultChapterNames) - { - for (int i = 0; i < numChapters; i++) - { - HBFunctions.hb_set_chapter_name(this.hbHandle, job.Title, i + 1, "Chapter " + (i + 1)); - } - } - else - { - for (int i = 0; i < numChapters; i++) - { - HBFunctions.hb_set_chapter_name(this.hbHandle, job.Title, i + 1, job.CustomChapterNames[i]); - } - } - } - this.subtitleScan = false; if (job.Subtitles.SourceSubtitles != null) { @@ -786,7 +764,7 @@ namespace HandBrake.Interop IntPtr titleSetPtr = HBFunctions.hb_get_title_set(this.hbHandle); hb_title_set_s titleSet = InteropUtilities.ReadStructure(titleSetPtr); - this.originalTitles = InteropUtilities.ConvertList(titleSet.list_title); + this.originalTitles = titleSet.list_title.ToList(); foreach (hb_title_s title in this.originalTitles) { @@ -988,8 +966,37 @@ namespace HandBrake.Interop } } + // Chapter markers nativeJob.chapter_markers = profile.IncludeChapterMarkers ? 1 : 0; + List nativeChapters = nativeJob.list_chapter.ToIntPtrList(); + + if (!preview && profile.IncludeChapterMarkers) + { + int numChapters = title.Chapters.Count; + + if (job.UseDefaultChapterNames) + { + for (int i = 0; i < numChapters; i++) + { + if (i < nativeChapters.Count) + { + HBFunctions.hb_chapter_set_title(nativeChapters[i], "Chapter " + (i + 1)); + } + } + } + else + { + for (int i = 0; i < numChapters; i++) + { + if (i < nativeChapters.Count && i < job.CustomChapterNames.Count) + { + HBFunctions.hb_chapter_set_title(nativeChapters[i], job.CustomChapterNames[i]); + } + } + } + } + Cropping crop = GetCropping(profile, title); nativeJob.crop[0] = crop.Top; @@ -1309,7 +1316,7 @@ namespace HandBrake.Interop // areBframes // color_matrix - List titleAudio = InteropUtilities.ConvertList(originalTitle.list_audio); + List titleAudio = originalTitle.list_audio.ToList(); var audioList = new List(); int numTracks = 0; @@ -1361,7 +1368,7 @@ namespace HandBrake.Interop { if (job.Subtitles.SourceSubtitles != null && job.Subtitles.SourceSubtitles.Count > 0) { - List titleSubtitles = InteropUtilities.ConvertList(originalTitle.list_subtitle); + List titleSubtitles = originalTitle.list_subtitle.ToList(); foreach (SourceSubtitle sourceSubtitle in job.Subtitles.SourceSubtitles) { @@ -1682,7 +1689,7 @@ namespace HandBrake.Interop } int currentSubtitleTrack = 1; - List subtitleList = InteropUtilities.ConvertList(title.list_subtitle); + List subtitleList = title.list_subtitle.ToList(); foreach (hb_subtitle_s subtitle in subtitleList) { var newSubtitle = new Subtitle @@ -1737,7 +1744,7 @@ namespace HandBrake.Interop } int currentAudioTrack = 1; - List audioList = InteropUtilities.ConvertList(title.list_audio); + List audioList = title.list_audio.ToList(); foreach (hb_audio_s audio in audioList) { var newAudio = new AudioTrack @@ -1758,7 +1765,7 @@ namespace HandBrake.Interop currentAudioTrack++; } - List chapterList = InteropUtilities.ConvertList(title.list_chapter); + List chapterList = title.list_chapter.ToList(); foreach (hb_chapter_s chapter in chapterList) { var newChapter = new Chapter diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeUtils.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeUtils.cs index 496136421..6fde37c57 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeUtils.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeUtils.cs @@ -165,6 +165,46 @@ namespace HandBrake.Interop fakeInterlaced ? 1 : 0) == 0; } + /// + /// Creates an X264 options string from the given settings. + /// + /// The x264 preset. + /// The x264 tunes being used. + /// The extra options string. + /// The H.264 profile. + /// The H.264 level. + /// The width of the final picture. + /// The height of the final picture. + /// The full x264 options string from the given inputs. + public static string CreateX264OptionsString( + string preset, + IList tunes, + string extraOptions, + string profile, + string level, + int width, + int height) + { + if (width <= 0) + { + throw new ArgumentException("width must be positive."); + } + + if (height <= 0) + { + throw new ArgumentException("height must be positive."); + } + + return HBFunctions.hb_x264_param_unparse( + preset, + string.Join(",", tunes), + extraOptions, + profile, + level, + width, + height); + } + /// /// Gets the total number of seconds on the given encode job. /// diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/HbFunctions.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/HbFunctions.cs index f033dc448..cd4ca877d 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/HbFunctions.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/HbFunctions.cs @@ -135,9 +135,6 @@ namespace HandBrake.Interop.HbLib [DllImport("hb.dll", EntryPoint = "hb_job", CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr hb_job(IntPtr hbHandle, int jobIndex); - [DllImport("hb.dll", EntryPoint = "hb_set_chapter_name", CallingConvention = CallingConvention.Cdecl)] - public static extern void hb_set_chapter_name(IntPtr hbHandle, int title_index, int chapter_index, [In] [MarshalAs(UnmanagedType.LPStr)] string chapter_name); - [DllImport("hb.dll", EntryPoint = "hb_set_job", CallingConvention = CallingConvention.Cdecl)] public static extern void hb_set_job(IntPtr hbHandle, int title_index, ref hb_job_s job); @@ -324,7 +321,7 @@ namespace HandBrake.Interop.HbLib ///void hb_chapter_set_title(hb_chapter_t *chapter, const char *title); [DllImport("hb.dll", EntryPoint = "hb_chapter_set_title", CallingConvention = CallingConvention.Cdecl)] - public static extern void hb_chapter_set_title(ref hb_chapter_s chapter, IntPtr title); + public static extern void hb_chapter_set_title(IntPtr chapter, [In] [MarshalAs(UnmanagedType.LPStr)] string title); /// void hb_add_filter( hb_job_t * job, hb_filter_object_t * filter, const char * settings ); [DllImport("hb.dll", EntryPoint = "hb_add_filter", CallingConvention = CallingConvention.Cdecl)] @@ -339,5 +336,15 @@ namespace HandBrake.Interop.HbLib [DllImport("hb.dll", EntryPoint = "hb_check_h264_level", CallingConvention = CallingConvention.Cdecl)] 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); + + [DllImport("hb.dll", EntryPoint = "hb_x264_param_unparse", CallingConvention = CallingConvention.Cdecl)] + public static extern string hb_x264_param_unparse( + [In] [MarshalAs(UnmanagedType.LPStr)] string x264_preset, + [In] [MarshalAs(UnmanagedType.LPStr)] string x264_tune, + [In] [MarshalAs(UnmanagedType.LPStr)] string x264_encopts, + [In] [MarshalAs(UnmanagedType.LPStr)] string x264_profile, + [In] [MarshalAs(UnmanagedType.LPStr)] string h264_level, + int width, + int height); } } diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/InteropUtilities.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/InteropUtilities.cs index db72feac5..de73dd607 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/InteropUtilities.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/InteropUtilities.cs @@ -37,7 +37,7 @@ namespace HandBrake.Interop /// The type of structure in the list. /// The pointer to the native list. /// The converted managed list. - public static List ConvertList(IntPtr listPtr) + public static List ToList(this IntPtr listPtr) { List returnList = new List(); hb_list_s itemList = ReadStructure(listPtr); @@ -51,6 +51,25 @@ namespace HandBrake.Interop return returnList; } + /// + /// Converts the HB list to a managed list of pointers. + /// + /// The list to convert. + /// The managed list of pointers. + public static List ToIntPtrList(this IntPtr listPtr) + { + var returnList = new List(); + hb_list_s itemList = ReadStructure(listPtr); + + for (int i = 0; i < itemList.items_count; i++) + { + IntPtr itemPtr = Marshal.ReadIntPtr(itemList.items, i * Marshal.SizeOf(typeof(IntPtr))); + returnList.Add(itemPtr); + } + + return returnList; + } + /// /// Converts the given native array to a managed collection. /// diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Properties/AssemblyInfo.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Properties/AssemblyInfo.cs index 395fe9363..523d7a8dd 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/Properties/AssemblyInfo.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.32.0.0")] -[assembly: AssemblyFileVersion("1.32.0.0")] +[assembly: AssemblyVersion("1.33.0.0")] +[assembly: AssemblyFileVersion("1.33.0.0")] -- 2.40.0