diff options
author | randomengy <[email protected]> | 2012-11-22 18:36:29 +0000 |
---|---|---|
committer | randomengy <[email protected]> | 2012-11-22 18:36:29 +0000 |
commit | a020ee671a4baa3cfc03aa408776707a79e184b9 (patch) | |
tree | 3014304229d4880a0ed75e44f10ff0ef1455c9a0 | |
parent | 29b2060a937a748c76302d9b687a46bca8634ccc (diff) |
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
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<hb_job_s>(nativeJobPtr);
- //hb_job_s nativeJob = InteropUtilities.ReadStructure<hb_job_s>(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<hb_title_set_s>(titleSetPtr);
- this.originalTitles = InteropUtilities.ConvertList<hb_title_s>(titleSet.list_title);
+ this.originalTitles = titleSet.list_title.ToList<hb_title_s>();
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<IntPtr> 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<hb_audio_s> titleAudio = InteropUtilities.ConvertList<hb_audio_s>(originalTitle.list_audio);
+ List<hb_audio_s> titleAudio = originalTitle.list_audio.ToList<hb_audio_s>();
var audioList = new List<hb_audio_s>();
int numTracks = 0;
@@ -1361,7 +1368,7 @@ namespace HandBrake.Interop {
if (job.Subtitles.SourceSubtitles != null && job.Subtitles.SourceSubtitles.Count > 0)
{
- List<hb_subtitle_s> titleSubtitles = InteropUtilities.ConvertList<hb_subtitle_s>(originalTitle.list_subtitle);
+ List<hb_subtitle_s> titleSubtitles = originalTitle.list_subtitle.ToList<hb_subtitle_s>();
foreach (SourceSubtitle sourceSubtitle in job.Subtitles.SourceSubtitles)
{
@@ -1682,7 +1689,7 @@ namespace HandBrake.Interop }
int currentSubtitleTrack = 1;
- List<hb_subtitle_s> subtitleList = InteropUtilities.ConvertList<hb_subtitle_s>(title.list_subtitle);
+ List<hb_subtitle_s> subtitleList = title.list_subtitle.ToList<hb_subtitle_s>();
foreach (hb_subtitle_s subtitle in subtitleList)
{
var newSubtitle = new Subtitle
@@ -1737,7 +1744,7 @@ namespace HandBrake.Interop }
int currentAudioTrack = 1;
- List<hb_audio_s> audioList = InteropUtilities.ConvertList<hb_audio_s>(title.list_audio);
+ List<hb_audio_s> audioList = title.list_audio.ToList<hb_audio_s>();
foreach (hb_audio_s audio in audioList)
{
var newAudio = new AudioTrack
@@ -1758,7 +1765,7 @@ namespace HandBrake.Interop currentAudioTrack++;
}
- List<hb_chapter_s> chapterList = InteropUtilities.ConvertList<hb_chapter_s>(title.list_chapter);
+ List<hb_chapter_s> chapterList = title.list_chapter.ToList<hb_chapter_s>();
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 @@ -166,6 +166,46 @@ namespace HandBrake.Interop }
/// <summary>
+ /// Creates an X264 options string from the given settings.
+ /// </summary>
+ /// <param name="preset">The x264 preset.</param>
+ /// <param name="tunes">The x264 tunes being used.</param>
+ /// <param name="extraOptions">The extra options string.</param>
+ /// <param name="profile">The H.264 profile.</param>
+ /// <param name="level">The H.264 level.</param>
+ /// <param name="width">The width of the final picture.</param>
+ /// <param name="height">The height of the final picture.</param>
+ /// <returns>The full x264 options string from the given inputs.</returns>
+ public static string CreateX264OptionsString(
+ string preset,
+ IList<string> 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);
+ }
+
+ /// <summary>
/// Gets the total number of seconds on the given encode job.
/// </summary>
/// <param name="job">The encode job to query.</param>
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 /// <typeparam name="T">The type of structure in the list.</typeparam>
/// <param name="listPtr">The pointer to the native list.</param>
/// <returns>The converted managed list.</returns>
- public static List<T> ConvertList<T>(IntPtr listPtr)
+ public static List<T> ToList<T>(this IntPtr listPtr)
{
List<T> returnList = new List<T>();
hb_list_s itemList = ReadStructure<hb_list_s>(listPtr);
@@ -52,6 +52,25 @@ namespace HandBrake.Interop }
/// <summary>
+ /// Converts the HB list to a managed list of pointers.
+ /// </summary>
+ /// <param name="listPtr">The list to convert.</param>
+ /// <returns>The managed list of pointers.</returns>
+ public static List<IntPtr> ToIntPtrList(this IntPtr listPtr)
+ {
+ var returnList = new List<IntPtr>();
+ hb_list_s itemList = ReadStructure<hb_list_s>(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;
+ }
+
+ /// <summary>
/// Converts the given native array to a managed collection.
/// </summary>
/// <typeparam name="T">The type of item in the list.</typeparam>
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")]
|