summaryrefslogtreecommitdiffstats
path: root/win
diff options
context:
space:
mode:
authorrandomengy <[email protected]>2013-06-18 02:05:59 +0000
committerrandomengy <[email protected]>2013-06-18 02:05:59 +0000
commitf7fbce3a0ca517b886a38ec59e41d619d5e0c157 (patch)
treea7529fe90a49012af982e37c95bece198a8c4995 /win
parenta7c727258d956a3a54e8b051d0b4838e56632685 (diff)
Interop: Bringing it up to speed with the latest nightlies. Interop now exposes the list of valid sample rates and framerates in Encoders.cs. Also fixing a problem with Custom anamorphic and maximum height.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5593 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win')
-rw-r--r--win/CS/HandBrake.Interop/HandBrakeInterop/Converters.cs72
-rw-r--r--win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs31
-rw-r--r--win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInterop.csproj1
-rw-r--r--win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeUtils.cs89
-rw-r--r--win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/HbFunctions.cs141
-rw-r--r--win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/Misc.cs13
-rw-r--r--win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/NativeConstants.cs4
-rw-r--r--win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/hb_job_s.cs4
-rw-r--r--win/CS/HandBrake.Interop/HandBrakeInterop/InteropUtilities.cs40
-rw-r--r--win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoders.cs138
-rw-r--r--win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/HBRate.cs24
-rw-r--r--win/CS/HandBrake.Interop/HandBrakeInterop/Properties/AssemblyInfo.cs4
12 files changed, 371 insertions, 190 deletions
diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Converters.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Converters.cs
index 4e04222ed..42d200e57 100644
--- a/win/CS/HandBrake.Interop/HandBrakeInterop/Converters.cs
+++ b/win/CS/HandBrake.Interop/HandBrakeInterop/Converters.cs
@@ -25,21 +25,21 @@ namespace HandBrake.Interop
/// <summary>
/// Video Frame Rates
/// </summary>
- private static readonly Dictionary<double, int> VideoRates = new Dictionary<double, int>
+ private static readonly Dictionary<double, int> VideoRates;
+
+ /// <summary>
+ /// Initializes static members of the Converters class.
+ /// </summary>
+ static Converters()
{
- {5, 5400000},
- {10, 2700000},
- {12, 2250000},
- {15, 1800000},
- {23.976, 1126125},
- {24, 1125000},
- {25, 1080000},
- {29.97, 900900},
- {30, 900000},
- {50, 540000},
- {59.94, 450450},
- {60, 450000}
- };
+ HandBrakeUtils.EnsureGlobalInit();
+
+ VideoRates = new Dictionary<double, int>();
+ foreach (var framerate in Encoders.VideoFramerates)
+ {
+ VideoRates.Add(double.Parse(framerate.Name), framerate.Rate);
+ }
+ }
/// <summary>
/// Convert Framerate to Video Rates
@@ -80,10 +80,10 @@ namespace HandBrake.Interop
return NativeConstants.HB_ACODEC_AC3;
case AudioEncoder.ffaac:
return NativeConstants.HB_ACODEC_FFAAC;
- case AudioEncoder.fdkaac:
- return NativeConstants.HB_ACODEC_FDK_AAC;
- case AudioEncoder.fdkheaac:
- return NativeConstants.HB_ACODEC_FDK_HAAC;
+ case AudioEncoder.fdkaac:
+ return NativeConstants.HB_ACODEC_FDK_AAC;
+ case AudioEncoder.fdkheaac:
+ return NativeConstants.HB_ACODEC_FDK_HAAC;
case AudioEncoder.AacPassthru:
return NativeConstants.HB_ACODEC_AAC_PASS;
case AudioEncoder.Lame:
@@ -129,8 +129,8 @@ namespace HandBrake.Interop
case NativeConstants.HB_ACODEC_FFAAC:
case NativeConstants.HB_ACODEC_CA_AAC:
case NativeConstants.HB_ACODEC_CA_HAAC:
- case NativeConstants.HB_ACODEC_FDK_HAAC: // TODO Check this is correct
- case NativeConstants.HB_ACODEC_FDK_AAC: // TODO Check this is correct
+ case NativeConstants.HB_ACODEC_FDK_HAAC: // TODO Check this is correct
+ case NativeConstants.HB_ACODEC_FDK_AAC: // TODO Check this is correct
return AudioCodec.Aac;
case NativeConstants.HB_ACODEC_FFFLAC:
return AudioCodec.Flac;
@@ -149,9 +149,9 @@ namespace HandBrake.Interop
{
var result = new HBVideoEncoder
{
- Id = encoder.encoder,
+ Id = encoder.codec,
ShortName = encoder.short_name,
- DisplayName = encoder.human_readable_name,
+ DisplayName = encoder.name,
CompatibleContainers = Container.None
};
@@ -177,9 +177,9 @@ namespace HandBrake.Interop
{
var result = new HBAudioEncoder
{
- Id = encoder.encoder,
+ Id = encoder.codec,
ShortName = encoder.short_name,
- DisplayName = encoder.human_readable_name,
+ DisplayName = encoder.name,
CompatibleContainers = Container.None
};
@@ -193,15 +193,29 @@ namespace HandBrake.Interop
result.CompatibleContainers = result.CompatibleContainers | Container.Mp4;
}
- result.QualityLimits = Encoders.GetAudioQualityLimits(encoder.encoder);
- result.DefaultQuality = HBFunctions.hb_get_default_audio_quality((uint)encoder.encoder);
- result.CompressionLimits = Encoders.GetAudioCompressionLimits(encoder.encoder);
- result.DefaultCompression = HBFunctions.hb_get_default_audio_compression((uint) encoder.encoder);
+ result.QualityLimits = Encoders.GetAudioQualityLimits(encoder.codec);
+ result.DefaultQuality = HBFunctions.hb_audio_quality_get_default((uint)encoder.codec);
+ result.CompressionLimits = Encoders.GetAudioCompressionLimits(encoder.codec);
+ result.DefaultCompression = HBFunctions.hb_audio_compression_get_default((uint)encoder.codec);
return result;
}
/// <summary>
+ /// Converts a native HB rate structure to an HBRate object.
+ /// </summary>
+ /// <param name="rate">The structure to convert.</param>
+ /// <returns>The converted rate object.</returns>
+ public static HBRate NativeToRate(hb_rate_s rate)
+ {
+ return new HBRate
+ {
+ Name = rate.name,
+ Rate = rate.rate
+ };
+ }
+
+ /// <summary>
/// Converts a native HB mixdown structure to a Mixdown model.
/// </summary>
/// <param name="mixdown">The structure to convert.</param>
@@ -212,7 +226,7 @@ namespace HandBrake.Interop
{
Id = mixdown.amixdown,
ShortName = mixdown.short_name,
- DisplayName = mixdown.human_readable_name
+ DisplayName = mixdown.name
};
}
diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs
index a65ca3e10..18beda7cc 100644
--- a/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs
+++ b/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs
@@ -50,16 +50,6 @@ namespace HandBrake.Interop
private const string TurboX264Opts = "ref=1:subme=2:me=dia:analyse=none:trellis=0:no-fast-pskip=0:8x8dct=0:weightb=0";
/// <summary>
- /// Lock for creation of handbrake instances;
- /// </summary>
- private static object instanceCreationLock = new object();
-
- /// <summary>
- /// True if a handbrake instance has been created.
- /// </summary>
- private static bool globalInitialized;
-
- /// <summary>
/// The native handle to the HandBrake instance.
/// </summary>
private IntPtr hbHandle;
@@ -181,13 +171,7 @@ namespace HandBrake.Interop
/// <param name="verbosity">The code for the logging verbosity to use.</param>
public void Initialize(int verbosity)
{
- lock (instanceCreationLock)
- {
- if (!globalInitialized)
- {
- globalInitialized = true;
- }
- }
+ HandBrakeUtils.EnsureGlobalInit();
HandBrakeUtils.RegisterLogger();
this.hbHandle = HBFunctions.hb_init(verbosity, update_check: 0);
@@ -406,6 +390,11 @@ namespace HandBrake.Interop
public void StartEncode(EncodeJob job, bool preview, int previewNumber, int previewSeconds, double overallSelectedLengthSeconds)
{
EncodingProfile profile = job.EncodingProfile;
+ if (job.ChosenAudioTracks == null)
+ {
+ throw new ArgumentException("job.ChosenAudioTracks cannot be null.");
+ }
+
this.currentJob = job;
IntPtr nativeJobPtr = HBFunctions.hb_job_init_by_index(this.hbHandle, this.GetTitleIndex(job.Title));
@@ -414,7 +403,7 @@ namespace HandBrake.Interop
this.encodeAllocatedMemory = this.ApplyJob(ref nativeJob, job, preview, previewNumber, previewSeconds, overallSelectedLengthSeconds);
this.subtitleScan = false;
- if (job.Subtitles.SourceSubtitles != null)
+ if (job.Subtitles != null && job.Subtitles.SourceSubtitles != null)
{
foreach (SourceSubtitle subtitle in job.Subtitles.SourceSubtitles)
{
@@ -1267,7 +1256,7 @@ namespace HandBrake.Interop
}
else
{
- displayWidth = (int)((double)cropHeight * displayAspect);
+ displayWidth = (int)((double)height * displayAspect);
}
nativeJob.anamorphic.dar_width = displayWidth;
@@ -1454,7 +1443,7 @@ namespace HandBrake.Interop
}
}
- bool hasBurnedSubtitle = job.Subtitles.SourceSubtitles.Any(s => s.BurnedIn);
+ bool hasBurnedSubtitle = job.Subtitles.SourceSubtitles != null && job.Subtitles.SourceSubtitles.Any(s => s.BurnedIn);
if (hasBurnedSubtitle)
{
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);
@@ -1684,7 +1673,7 @@ namespace HandBrake.Interop
if (encoding.Bitrate == 0)
{
// Bitrate of 0 means auto: choose the default for this codec, sample rate and mixdown.
- nativeAudio.config.output.bitrate = HBFunctions.hb_get_default_audio_bitrate(
+ nativeAudio.config.output.bitrate = HBFunctions.hb_audio_bitrate_get_default(
nativeAudio.config.output.codec,
nativeAudio.config.output.samplerate,
nativeAudio.config.output.mixdown);
diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInterop.csproj b/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInterop.csproj
index 59fe341b5..06e8394e7 100644
--- a/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInterop.csproj
+++ b/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInterop.csproj
@@ -161,6 +161,7 @@
<Compile Include="Model\Encoding\Detelecine.cs" />
<Compile Include="Model\Encoding\EncodingProfile.cs" />
<Compile Include="Model\Encoding\HBMixdown.cs" />
+ <Compile Include="Model\Encoding\HBRate.cs" />
<Compile Include="Model\Encoding\HBVideoEncoder.cs" />
<Compile Include="Model\Encoding\Mixdown.cs" />
<Compile Include="Model\Encoding\OutputExtension.cs" />
diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeUtils.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeUtils.cs
index 6833dfc36..48e8117be 100644
--- a/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeUtils.cs
+++ b/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeUtils.cs
@@ -40,6 +40,11 @@ namespace HandBrake.Interop
private static LoggingCallback errorCallback;
/// <summary>
+ /// True if the global initialize function has been called.
+ /// </summary>
+ private static bool globalInitialized;
+
+ /// <summary>
/// Fires when HandBrake has logged a message.
/// </summary>
public static event EventHandler<MessageLoggedEventArgs> MessageLogged;
@@ -50,6 +55,30 @@ namespace HandBrake.Interop
public static event EventHandler<MessageLoggedEventArgs> ErrorLogged;
/// <summary>
+ /// Initializes static members of the HandBrakeUtils class.
+ /// </summary>
+ static HandBrakeUtils()
+ {
+ if (!globalInitialized)
+ {
+ if (HBFunctions.hb_global_init() == -1)
+ {
+ throw new InvalidOperationException("HB global init failed.");
+ }
+
+ globalInitialized = true;
+ }
+ }
+
+ /// <summary>
+ /// Ensures the HB global initialize method has been called.
+ /// </summary>
+ public static void EnsureGlobalInit()
+ {
+ // Does nothing, but invokes static ctor.
+ }
+
+ /// <summary>
/// Enables or disables LibDVDNav. If disabled libdvdread will be used instead.
/// </summary>
/// <param name="enableDvdNav">True to enable LibDVDNav.</param>
@@ -94,12 +123,17 @@ namespace HandBrake.Interop
if (messageParts.Length > 0)
{
- if (MessageLogged != null)
+ message = messageParts[0];
+
+ // When MP4 muxing fails (for example when the file is too big without Large File Size)
+ // a message is logged but it isn't marked as an error.
+ if (message.StartsWith("MP4ERROR", StringComparison.Ordinal))
{
- MessageLogged(null, new MessageLoggedEventArgs { Message = messageParts[0] });
+ SendErrorEvent(message);
+ return;
}
- System.Diagnostics.Debug.WriteLine(messageParts[0]);
+ SendMessageEvent(message);
}
}
}
@@ -115,20 +149,11 @@ namespace HandBrake.Interop
// This error happens in normal operations. Log it as a message.
if (message == "dvd: ifoOpen failed")
{
- if (MessageLogged != null)
- {
- MessageLogged(null, new MessageLoggedEventArgs { Message = message });
- }
-
+ SendMessageEvent(message);
return;
}
- if (ErrorLogged != null)
- {
- ErrorLogged(null, new MessageLoggedEventArgs { Message = message });
- }
-
- System.Diagnostics.Debug.WriteLine("ERROR: " + message);
+ SendErrorEvent(message);
}
}
@@ -197,8 +222,8 @@ namespace HandBrake.Interop
throw new ArgumentException("height must be positive.");
}
- HBFunctions.hb_init(0, 0);
- IntPtr ptr = HBFunctions.hb_x264_param_unparse(
+ HBFunctions.hb_init(0, 0);
+ IntPtr ptr = HBFunctions.hb_x264_param_unparse(
preset,
string.Join(",", tunes),
extraOptions,
@@ -207,10 +232,10 @@ namespace HandBrake.Interop
width,
height);
- string x264Settings = Marshal.PtrToStringAnsi(ptr);
+ string x264Settings = Marshal.PtrToStringAnsi(ptr);
- return x264Settings;
+ return x264Settings;
}
/// <summary>
@@ -331,5 +356,33 @@ namespace HandBrake.Interop
return audioBytes;
}
+
+ /// <summary>
+ /// Sends the message logged event to any registered listeners.
+ /// </summary>
+ /// <param name="message">The message to send.</param>
+ private static void SendMessageEvent(string message)
+ {
+ if (MessageLogged != null)
+ {
+ MessageLogged(null, new MessageLoggedEventArgs { Message = message });
+ }
+
+ System.Diagnostics.Debug.WriteLine(message);
+ }
+
+ /// <summary>
+ /// Sends the error logged event to any registered listeners.
+ /// </summary>
+ /// <param name="message">The message to send</param>
+ private static void SendErrorEvent(string message)
+ {
+ if (ErrorLogged != null)
+ {
+ ErrorLogged(null, new MessageLoggedEventArgs { Message = message });
+ }
+
+ System.Diagnostics.Debug.WriteLine("ERROR: " + message);
+ }
}
}
diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/HbFunctions.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/HbFunctions.cs
index 00130a902..25f595995 100644
--- a/win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/HbFunctions.cs
+++ b/win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/HbFunctions.cs
@@ -21,6 +21,9 @@ namespace HandBrake.Interop.HbLib
[DllImport("hb.dll", EntryPoint = "hb_register_error_handler", CallingConvention = CallingConvention.Cdecl)]
public static extern void hb_register_error_handler(LoggingCallback callback);
+ [DllImport("hb.dll", EntryPoint = "hb_global_init", CallingConvention = CallingConvention.Cdecl)]
+ public static extern int hb_global_init();
+
/// Return Type: hb_handle_t*
///verbose: int
///update_check: int
@@ -210,81 +213,119 @@ namespace HandBrake.Interop.HbLib
public static extern int hb_srt_add(ref hb_job_s job, ref hb_subtitle_config_s subtitleConfig, string lang);
- [DllImport("hb.dll", EntryPoint = "hb_mixdown_is_supported", CallingConvention = CallingConvention.Cdecl)]
- public static extern int hb_mixdown_is_supported(int mixdown, uint codec, ulong layout);
- [DllImport("hb.dll", EntryPoint = "hb_mixdown_has_remix_support", CallingConvention = CallingConvention.Cdecl)]
- public static extern int hb_mixdown_has_remix_support(int mixdown, ulong layout);
+//int hb_video_framerate_get_from_name(const char *name);
+//const char* hb_video_framerate_get_name(int framerate);
+//const char* hb_video_framerate_sanitize_name(const char *name);
- [DllImport("hb.dll", EntryPoint = "hb_mixdown_has_codec_support", CallingConvention = CallingConvention.Cdecl)]
- public static extern int hb_mixdown_has_codec_support(int mixdown, uint codec);
+ // returns hb_rate_s
+ [DllImport("hb.dll", EntryPoint = "hb_video_framerate_get_next", CallingConvention = CallingConvention.Cdecl)]
+ public static extern IntPtr hb_video_framerate_get_next(IntPtr last);
+
+
+//int hb_audio_samplerate_get_best(uint32_t codec, int samplerate, int *sr_shift);
+//int hb_audio_samplerate_get_from_name(const char *name);
+//const char* hb_audio_samplerate_get_name(int samplerate);
+
+ // returns hb_rate_s
+ [DllImport("hb.dll", EntryPoint = "hb_audio_samplerate_get_next", CallingConvention = CallingConvention.Cdecl)]
+ public static extern IntPtr hb_audio_samplerate_get_next(IntPtr last);
+
+
+ [DllImport("hb.dll", EntryPoint = "hb_audio_bitrate_get_best", CallingConvention = CallingConvention.Cdecl)]
+ public static extern int hb_audio_bitrate_get_best(uint codec, int bitrate, int samplerate, int mixdown);
+
+ [DllImport("hb.dll", EntryPoint = "hb_audio_bitrate_get_default", CallingConvention = CallingConvention.Cdecl)]
+ public static extern int hb_audio_bitrate_get_default(uint codec, int samplerate, int mixdown);
- [DllImport("hb.dll", EntryPoint = "hb_get_default_mixdown", CallingConvention = CallingConvention.Cdecl)]
- public static extern int hb_get_default_mixdown(uint codec, ulong layout);
+ [DllImport("hb.dll", EntryPoint = "hb_audio_bitrate_get_limits", CallingConvention = CallingConvention.Cdecl)]
+ public static extern int hb_audio_bitrate_get_limits(uint codec, int samplerate, int mixdown, ref int low, ref int high);
- [DllImport("hb.dll", EntryPoint = "hb_get_best_mixdown", CallingConvention = CallingConvention.Cdecl)]
- public static extern int hb_get_best_mixdown(uint codec, ulong layout, int mixdown);
+ [DllImport("hb.dll", EntryPoint = "hb_audio_bitrate_get_next", CallingConvention = CallingConvention.Cdecl)]
+ public static extern IntPtr hb_audio_bitrate_get_next(IntPtr last);
- [DllImport("hb.dll", EntryPoint = "hb_get_best_audio_bitrate", CallingConvention = CallingConvention.Cdecl)]
- public static extern int hb_get_best_audio_bitrate(uint codec, int bitrate, int samplerate, int mixdown);
- [DllImport("hb.dll", EntryPoint = "hb_get_default_audio_bitrate", CallingConvention = CallingConvention.Cdecl)]
- public static extern int hb_get_default_audio_bitrate(uint codec, int samplerate, int mixdown);
+ [DllImport("hb.dll", EntryPoint = "hb_audio_quality_get_limits", CallingConvention = CallingConvention.Cdecl)]
+ public static extern void hb_audio_quality_get_limits(uint codec, ref float low, ref float high, ref float granularity, ref int direction);
- [DllImport("hb.dll", EntryPoint = "hb_get_audio_bitrate_limits", CallingConvention = CallingConvention.Cdecl)]
- public static extern int hb_get_audio_bitrate_limits(uint codec, int samplerate, int mixdown, ref int low, ref int high);
+//float hb_audio_quality_get_best(uint32_t codec, float quality);
- [DllImport("hb.dll", EntryPoint = "hb_get_audio_quality_limits", CallingConvention = CallingConvention.Cdecl)]
- public static extern void hb_get_audio_quality_limits(uint codec, ref float low, ref float high, ref float granularity, ref int direction);
+ [DllImport("hb.dll", EntryPoint = "hb_audio_quality_get_default", CallingConvention = CallingConvention.Cdecl)]
+ public static extern float hb_audio_quality_get_default(uint codec);
- [DllImport("hb.dll", EntryPoint = "hb_get_default_audio_quality", CallingConvention = CallingConvention.Cdecl)]
- public static extern float hb_get_default_audio_quality(uint codec);
- [DllImport("hb.dll", EntryPoint = "hb_get_audio_compression_limits", CallingConvention = CallingConvention.Cdecl)]
- public static extern void hb_get_audio_compression_limits(uint codec, ref float low, ref float high, ref float granularity, ref int direction);
+ [DllImport("hb.dll", EntryPoint = "hb_audio_compression_get_limits", CallingConvention = CallingConvention.Cdecl)]
+ public static extern void hb_audio_compression_get_limits(uint codec, ref float low, ref float high, ref float granularity, ref int direction);
- [DllImport("hb.dll", EntryPoint = "hb_get_default_audio_compression", CallingConvention = CallingConvention.Cdecl)]
- public static extern float hb_get_default_audio_compression(uint codec);
+//float hb_audio_compression_get_best(uint32_t codec, float compression);
+
+ [DllImport("hb.dll", EntryPoint = "hb_audio_compression_get_default", CallingConvention = CallingConvention.Cdecl)]
+ public static extern float hb_audio_compression_get_default(uint codec);
+
+
+//int hb_audio_dither_get_default();
+//int hb_audio_dither_get_default_method(); // default method, if enabled && supported
+//int hb_audio_dither_is_supported(uint32_t codec);
+//int hb_audio_dither_get_from_name(const char *name);
+//const char* hb_audio_dither_get_description(int method);
+//const hb_dither_t* hb_audio_dither_get_next(const hb_dither_t *last);
+
+ [DllImport("hb.dll", EntryPoint = "hb_mixdown_is_supported", CallingConvention = CallingConvention.Cdecl)]
+ public static extern int hb_mixdown_is_supported(int mixdown, uint codec, ulong layout);
+
+ [DllImport("hb.dll", EntryPoint = "hb_mixdown_has_codec_support", CallingConvention = CallingConvention.Cdecl)]
+ public static extern int hb_mixdown_has_codec_support(int mixdown, uint codec);
+
+ [DllImport("hb.dll", EntryPoint = "hb_mixdown_has_remix_support", CallingConvention = CallingConvention.Cdecl)]
+ public static extern int hb_mixdown_has_remix_support(int mixdown, ulong layout);
+//int hb_mixdown_get_discrete_channel_count(int mixdown);
+//int hb_mixdown_get_low_freq_channel_count(int mixdown);
- [DllImport("hb.dll", EntryPoint = "hb_get_video_rates", CallingConvention = CallingConvention.Cdecl)]
- public static extern IntPtr hb_get_video_rates();
+ [DllImport("hb.dll", EntryPoint = "hb_mixdown_get_best", CallingConvention = CallingConvention.Cdecl)]
+ public static extern int hb_mixdown_get_best(uint codec, ulong layout, int mixdown);
- [DllImport("hb.dll", EntryPoint = "hb_get_video_rates_count", CallingConvention = CallingConvention.Cdecl)]
- public static extern int hb_get_video_rates_count();
+ [DllImport("hb.dll", EntryPoint = "hb_mixdown_get_default", CallingConvention = CallingConvention.Cdecl)]
+ public static extern int hb_mixdown_get_default(uint codec, ulong layout);
- [DllImport("hb.dll", EntryPoint = "hb_get_audio_rates", CallingConvention = CallingConvention.Cdecl)]
- public static extern IntPtr hb_get_audio_rates();
+//int hb_mixdown_get_from_name(const char *name);
+//const char* hb_mixdown_get_name(int mixdown);
+//const char* hb_mixdown_get_short_name(int mixdown);
+//const char* hb_mixdown_sanitize_name(const char *name);
- [DllImport("hb.dll", EntryPoint = "hb_get_audio_rates_count", CallingConvention = CallingConvention.Cdecl)]
- public static extern int hb_get_audio_rates_count();
+ [DllImport("hb.dll", EntryPoint = "hb_mixdown_get_next", CallingConvention = CallingConvention.Cdecl)]
+ public static extern IntPtr hb_mixdown_get_next(IntPtr last);
- [DllImport("hb.dll", EntryPoint = "hb_get_audio_rates_default", CallingConvention = CallingConvention.Cdecl)]
- public static extern int hb_get_audio_rates_default();
+//int hb_video_encoder_get_default(int muxer);
+//int hb_video_encoder_get_from_name(const char *name);
+//const char* hb_video_encoder_get_name(int encoder);
+//const char* hb_video_encoder_get_short_name(int encoder);
+//const char* hb_video_encoder_sanitize_name(const char *name);
- [DllImport("hb.dll", EntryPoint = "hb_get_audio_bitrates", CallingConvention = CallingConvention.Cdecl)]
- public static extern IntPtr hb_get_audio_bitrates();
+ [DllImport("hb.dll", EntryPoint = "hb_video_encoder_get_next", CallingConvention = CallingConvention.Cdecl)]
+ public static extern IntPtr hb_video_encoder_get_next(IntPtr last);
- [DllImport("hb.dll", EntryPoint = "hb_get_audio_bitrates_count", CallingConvention = CallingConvention.Cdecl)]
- public static extern int hb_get_audio_bitrates_count();
+/*
+ * hb_audio_encoder_get_fallback_for_passthru() will sanitize a passthru codec
+ * to the matching audio encoder (if any is available).
+ *
+ * hb_audio_encoder_get_from_name(), hb_audio_encoder_sanitize_name() will
+ * sanitize legacy encoder names, but won't convert passthru to an encoder.
+ */
+//int hb_audio_encoder_get_fallback_for_passthru(int passthru);
+//int hb_audio_encoder_get_default(int muxer);
+//int hb_audio_encoder_get_from_name(const char *name);
+//const char* hb_audio_encoder_get_name(int encoder);
+//const char* hb_audio_encoder_get_short_name(int encoder);
+//const char* hb_audio_encoder_sanitize_name(const char *name);
- [DllImport("hb.dll", EntryPoint = "hb_get_audio_mixdowns", CallingConvention = CallingConvention.Cdecl)]
- public static extern IntPtr hb_get_audio_mixdowns();
+ [DllImport("hb.dll", EntryPoint = "hb_audio_encoder_get_next", CallingConvention = CallingConvention.Cdecl)]
+ public static extern IntPtr hb_audio_encoder_get_next(IntPtr last);
- [DllImport("hb.dll", EntryPoint = "hb_get_audio_mixdowns_count", CallingConvention = CallingConvention.Cdecl)]
- public static extern int hb_get_audio_mixdowns_count();
- [DllImport("hb.dll", EntryPoint = "hb_get_video_encoders", CallingConvention = CallingConvention.Cdecl)]
- public static extern IntPtr hb_get_video_encoders();
- [DllImport("hb.dll", EntryPoint = "hb_get_video_encoders_count", CallingConvention = CallingConvention.Cdecl)]
- public static extern int hb_get_video_encoders_count();
- [DllImport("hb.dll", EntryPoint = "hb_get_audio_encoders", CallingConvention = CallingConvention.Cdecl)]
- public static extern IntPtr hb_get_audio_encoders();
- [DllImport("hb.dll", EntryPoint = "hb_get_audio_encoders_count", CallingConvention = CallingConvention.Cdecl)]
- public static extern int hb_get_audio_encoders_count();
/// void hb_autopassthru_apply_settings( hb_job_t * job )
diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/Misc.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/Misc.cs
index c34f5daf5..6d6e62a34 100644
--- a/win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/Misc.cs
+++ b/win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/Misc.cs
@@ -56,7 +56,7 @@ namespace HandBrake.Interop.HbLib
{
/// char*
[MarshalAs(UnmanagedType.LPStr)]
- public string @string;
+ public string name;
/// int
public int rate;
@@ -65,13 +65,8 @@ namespace HandBrake.Interop.HbLib
[StructLayout(LayoutKind.Sequential)]
public struct hb_mixdown_s
{
- /// char*
[MarshalAs(UnmanagedType.LPStr)]
- public string human_readable_name;
-
- /// char*
- [MarshalAs(UnmanagedType.LPStr)]
- public string internal_name;
+ public string name;
/// char*
[MarshalAs(UnmanagedType.LPStr)]
@@ -85,12 +80,12 @@ namespace HandBrake.Interop.HbLib
public struct hb_encoder_s
{
[MarshalAs(UnmanagedType.LPStr)]
- public string human_readable_name;
+ public string name;
[MarshalAs(UnmanagedType.LPStr)]
public string short_name;
- public int encoder;
+ public int codec;
public int muxers;
}
diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/NativeConstants.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/NativeConstants.cs
index 52d1d253e..ae7fcd704 100644
--- a/win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/NativeConstants.cs
+++ b/win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/NativeConstants.cs
@@ -39,7 +39,7 @@ namespace HandBrake.Interop.HbLib
public const uint HB_ACODEC_AC3_PASS = (HB_ACODEC_AC3 | HB_ACODEC_PASS_FLAG);
public const uint HB_ACODEC_DCA_PASS = (HB_ACODEC_DCA | HB_ACODEC_PASS_FLAG);
public const uint HB_ACODEC_DCA_HD_PASS = (HB_ACODEC_DCA_HD | HB_ACODEC_PASS_FLAG);
- public const uint HB_ACODEC_ANY = (HB_ACODEC_MASK | HB_ACODEC_PASS_FLAG);
+ public const uint HB_ACODEC_ANY = (HB_ACODEC_MASK | HB_ACODEC_PASS_FLAG);
// Subtitle Types
public const int HB_SUBSTREAM_BD_TRUEHD = 0x72;
@@ -59,7 +59,7 @@ namespace HandBrake.Interop.HbLib
// Muxers
public const int HB_MUX_MASK = 0xFF0000;
public const int HB_MUX_MP4 = 0x010000;
- public const int HB_MUX_MKV = 0x200000;
+ public const int HB_MUX_MKV = 0x100000;
public const int HBTF_NO_IDR = 1 << 0;
diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/hb_job_s.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/hb_job_s.cs
index e9f08fe47..44f9e5ba8 100644
--- a/win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/hb_job_s.cs
+++ b/win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/hb_job_s.cs
@@ -74,10 +74,6 @@ namespace HandBrake.Interop.HbLib
/// int
public int vbitrate;
- public int pfr_vrate;
-
- public int pfr_vrate_base;
-
/// int
public int vrate;
diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/InteropUtilities.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/InteropUtilities.cs
index 8bf68b2e1..bd58ec6a0 100644
--- a/win/CS/HandBrake.Interop/HandBrakeInterop/InteropUtilities.cs
+++ b/win/CS/HandBrake.Interop/HandBrakeInterop/InteropUtilities.cs
@@ -11,9 +11,11 @@ namespace HandBrake.Interop
{
using System;
using System.Collections.Generic;
+ using System.Linq;
using System.Runtime.InteropServices;
using HandBrake.Interop.HbLib;
+ using Model.Encoding;
/// <summary>
/// Helper utilities for native interop.
@@ -91,7 +93,7 @@ namespace HandBrake.Interop
}
return result;
- }
+ }
/// <summary>
/// Creats a new, empty native HandBrake list.
@@ -183,6 +185,42 @@ namespace HandBrake.Interop
}
/// <summary>
+ /// Reads in a list of objects given an interator and a conversion function.
+ /// </summary>
+ /// <typeparam name="T1">The type of the struct given by the iterator.</typeparam>
+ /// <typeparam name="T2">The object type to convert to.</typeparam>
+ /// <param name="iterator">The iterator to use to build the list.</param>
+ /// <param name="converter">The converter to convert from the struct to the object.</param>
+ /// <returns>The list of objects.</returns>
+ public static List<T2> GetListFromIterator<T1, T2>(Func<IntPtr, IntPtr> iterator, Func<T1, T2> converter)
+ {
+ return ReadStructureListFromIterator<T1>(iterator).Select(converter).ToList();
+ }
+
+ /// <summary>
+ /// Reads in a list of structs given an iterator.
+ /// </summary>
+ /// <typeparam name="T">The type of the struct.</typeparam>
+ /// <param name="iterator">The iterator to use to build the list.</param>
+ /// <returns>The list of structs.</returns>
+ public static List<T> ReadStructureListFromIterator<T>(Func<IntPtr, IntPtr> iterator)
+ {
+ var structureList = new List<T>();
+ IntPtr current = IntPtr.Zero;
+
+ current = iterator(current);
+ while (current != IntPtr.Zero)
+ {
+ T encoder = ReadStructure<T>(current);
+ structureList.Add(encoder);
+
+ current = iterator(current);
+ }
+
+ return structureList;
+ }
+
+ /// <summary>
/// Closes the given job.
/// </summary>
/// <param name="nativeJobPtr">The pointer to the job.</param>
diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoders.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoders.cs
index 9f877cd9b..ebfefff0a 100644
--- a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoders.cs
+++ b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoders.cs
@@ -17,30 +17,48 @@ namespace HandBrake.Interop.Model
using HandBrake.Interop.Model.Encoding;
using HandBrake.Interop.SourceData;
- /// <summary>
- /// The encoders.
- /// </summary>
- public static class Encoders
+ /// <summary>
+ /// The encoders.
+ /// </summary>
+ public static class Encoders
{
- /// <summary>
- /// The audio encoders.
- /// </summary>
- private static List<HBAudioEncoder> audioEncoders;
-
- /// <summary>
- /// The video encoders.
- /// </summary>
- private static List<HBVideoEncoder> videoEncoders;
-
- /// <summary>
- /// The mixdowns.
- /// </summary>
- private static List<HBMixdown> mixdowns;
-
- /// <summary>
- /// The audio bitrates.
- /// </summary>
- private static List<int> audioBitrates;
+ /// <summary>
+ /// The audio encoders.
+ /// </summary>
+ private static List<HBAudioEncoder> audioEncoders;
+
+ /// <summary>
+ /// The video encoders.
+ /// </summary>
+ private static List<HBVideoEncoder> videoEncoders;
+
+ /// <summary>
+ /// Video framerates in pts.
+ /// </summary>
+ private static List<HBRate> videoFramerates;
+
+ /// <summary>
+ /// The mixdowns.
+ /// </summary>
+ private static List<HBMixdown> mixdowns;
+
+ /// <summary>
+ /// The audio bitrates.
+ /// </summary>
+ private static List<int> audioBitrates;
+
+ /// <summary>
+ /// Audio sample rates in Hz.
+ /// </summary>
+ private static List<HBRate> audioSampleRates;
+
+ /// <summary>
+ /// Initializes static members of the Encoders class.
+ /// </summary>
+ static Encoders()
+ {
+ HandBrakeUtils.EnsureGlobalInit();
+ }
/// <summary>
/// Gets a list of supported audio encoders.
@@ -51,12 +69,7 @@ namespace HandBrake.Interop.Model
{
if (audioEncoders == null)
{
- IntPtr encodersPtr = HBFunctions.hb_get_audio_encoders();
- int encoderCount = HBFunctions.hb_get_audio_encoders_count();
-
- audioEncoders = InteropUtilities.ConvertArray<hb_encoder_s>(encodersPtr, encoderCount)
- .Select(Converters.NativeToAudioEncoder)
- .ToList();
+ audioEncoders = InteropUtilities.GetListFromIterator<hb_encoder_s, HBAudioEncoder>(HBFunctions.hb_audio_encoder_get_next, Converters.NativeToAudioEncoder);
}
return audioEncoders;
@@ -72,12 +85,7 @@ namespace HandBrake.Interop.Model
{
if (videoEncoders == null)
{
- IntPtr encodersPtr = HBFunctions.hb_get_video_encoders();
- int encoderCount = HBFunctions.hb_get_video_encoders_count();
-
- videoEncoders = InteropUtilities.ConvertArray<hb_encoder_s>(encodersPtr, encoderCount)
- .Select(Converters.NativeToVideoEncoder)
- .ToList();
+ videoEncoders = InteropUtilities.GetListFromIterator<hb_encoder_s, HBVideoEncoder>(HBFunctions.hb_video_encoder_get_next, Converters.NativeToVideoEncoder);
}
return videoEncoders;
@@ -85,6 +93,22 @@ namespace HandBrake.Interop.Model
}
/// <summary>
+ /// Gets a list of supported video framerates (in pts).
+ /// </summary>
+ public static List<HBRate> VideoFramerates
+ {
+ get
+ {
+ if (videoFramerates == null)
+ {
+ videoFramerates = InteropUtilities.GetListFromIterator<hb_rate_s, HBRate>(HBFunctions.hb_video_framerate_get_next, Converters.NativeToRate);
+ }
+
+ return videoFramerates;
+ }
+ }
+
+ /// <summary>
/// Gets a list of supported mixdowns.
/// </summary>
public static List<HBMixdown> Mixdowns
@@ -93,12 +117,7 @@ namespace HandBrake.Interop.Model
{
if (mixdowns == null)
{
- IntPtr mixdownsPtr = HBFunctions.hb_get_audio_mixdowns();
- int mixdownsCount = HBFunctions.hb_get_audio_mixdowns_count();
-
- mixdowns = InteropUtilities.ConvertArray<hb_mixdown_s>(mixdownsPtr, mixdownsCount)
- .Select(Converters.NativeToMixdown)
- .ToList();
+ mixdowns = InteropUtilities.GetListFromIterator<hb_mixdown_s, HBMixdown>(HBFunctions.hb_mixdown_get_next, Converters.NativeToMixdown);
}
return mixdowns;
@@ -114,12 +133,7 @@ namespace HandBrake.Interop.Model
{
if (audioBitrates == null)
{
- IntPtr audioBitratesPtr = HBFunctions.hb_get_audio_bitrates();
- int audioBitratesCount = HBFunctions.hb_get_audio_bitrates_count();
-
- audioBitrates = InteropUtilities.ConvertArray<hb_rate_s>(audioBitratesPtr, audioBitratesCount)
- .Select(b => b.rate)
- .ToList();
+ audioBitrates = InteropUtilities.GetListFromIterator<hb_rate_s, int>(HBFunctions.hb_audio_bitrate_get_next, b => b.rate);
}
return audioBitrates;
@@ -127,6 +141,22 @@ namespace HandBrake.Interop.Model
}
/// <summary>
+ /// Gets a list of supported audio sample rates (in Hz).
+ /// </summary>
+ public static List<HBRate> AudioSampleRates
+ {
+ get
+ {
+ if (audioSampleRates == null)
+ {
+ audioSampleRates = InteropUtilities.GetListFromIterator<hb_rate_s, HBRate>(HBFunctions.hb_audio_samplerate_get_next, Converters.NativeToRate);
+ }
+
+ return audioSampleRates;
+ }
+ }
+
+ /// <summary>
/// Gets the audio encoder with the specified short name.
/// </summary>
/// <param name="shortName">The name of the audio encoder.</param>
@@ -199,7 +229,7 @@ namespace HandBrake.Interop.Model
/// <returns>A sanitized mixdown value.</returns>
public static HBMixdown SanitizeMixdown(HBMixdown mixdown, HBAudioEncoder encoder, ulong layout)
{
- int sanitizedMixdown = HBFunctions.hb_get_best_mixdown((uint)encoder.Id, layout, mixdown.Id);
+ int sanitizedMixdown = HBFunctions.hb_mixdown_get_best((uint)encoder.Id, layout, mixdown.Id);
return Mixdowns.Single(m => m.Id == sanitizedMixdown);
}
@@ -211,7 +241,7 @@ namespace HandBrake.Interop.Model
/// <returns>The default mixdown for the given codec and channel layout.</returns>
public static HBMixdown GetDefaultMixdown(HBAudioEncoder encoder, ulong layout)
{
- int defaultMixdown = HBFunctions.hb_get_default_mixdown((uint)encoder.Id, layout);
+ int defaultMixdown = HBFunctions.hb_mixdown_get_default((uint)encoder.Id, layout);
return Mixdowns.Single(m => m.Id == defaultMixdown);
}
@@ -227,7 +257,7 @@ namespace HandBrake.Interop.Model
int low = 0;
int high = 0;
- HBFunctions.hb_get_audio_bitrate_limits((uint)encoder.Id, sampleRate, mixdown.Id, ref low, ref high);
+ HBFunctions.hb_audio_bitrate_get_limits((uint)encoder.Id, sampleRate, mixdown.Id, ref low, ref high);
return new BitrateLimits { Low = low, High = high };
}
@@ -242,7 +272,7 @@ namespace HandBrake.Interop.Model
/// <returns>A sanitized audio bitrate.</returns>
public static int SanitizeAudioBitrate(int audioBitrate, HBAudioEncoder encoder, int sampleRate, HBMixdown mixdown)
{
- return HBFunctions.hb_get_best_audio_bitrate((uint)encoder.Id, audioBitrate, sampleRate, mixdown.Id);
+ return HBFunctions.hb_audio_bitrate_get_best((uint)encoder.Id, audioBitrate, sampleRate, mixdown.Id);
}
/// <summary>
@@ -254,7 +284,7 @@ namespace HandBrake.Interop.Model
/// <returns>The default bitrate for these parameters.</returns>
public static int GetDefaultBitrate(HBAudioEncoder encoder, int sampleRate, HBMixdown mixdown)
{
- return HBFunctions.hb_get_default_audio_bitrate((uint) encoder.Id, sampleRate, mixdown.Id);
+ return HBFunctions.hb_audio_bitrate_get_default((uint) encoder.Id, sampleRate, mixdown.Id);
}
/// <summary>
@@ -266,7 +296,7 @@ namespace HandBrake.Interop.Model
{
float low = 0, high = 0, granularity = 0;
int direction = 0;
- HBFunctions.hb_get_audio_quality_limits((uint)encoderId, ref low, ref high, ref granularity, ref direction);
+ HBFunctions.hb_audio_quality_get_limits((uint)encoderId, ref low, ref high, ref granularity, ref direction);
return new RangeLimits
{
@@ -286,7 +316,7 @@ namespace HandBrake.Interop.Model
{
float low = 0, high = 0, granularity = 0;
int direction = 0;
- HBFunctions.hb_get_audio_compression_limits((uint)encoderId, ref low, ref high, ref granularity, ref direction);
+ HBFunctions.hb_audio_compression_get_limits((uint)encoderId, ref low, ref high, ref granularity, ref direction);
return new RangeLimits
{
diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/HBRate.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/HBRate.cs
new file mode 100644
index 000000000..2862574dc
--- /dev/null
+++ b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/HBRate.cs
@@ -0,0 +1,24 @@
+// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="HBRate.cs" company="HandBrake Project (http://handbrake.fr)">
+// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
+// </copyright>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrake.Interop.Model.Encoding
+{
+ /// <summary>
+ /// Represents a rate in HandBrake: audio sample rate or video framerate.
+ /// </summary>
+ public class HBRate
+ {
+ /// <summary>
+ /// Gets or sets the name to use for this rate.
+ /// </summary>
+ public string Name { get; set; }
+
+ /// <summary>
+ /// Gets or sets the raw rate.
+ /// </summary>
+ public int Rate { get; set; }
+ }
+}
diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Properties/AssemblyInfo.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Properties/AssemblyInfo.cs
index 936eb0fa9..2902f4f11 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.40.0.0")]
-[assembly: AssemblyFileVersion("1.40.0.0")]
+[assembly: AssemblyVersion("1.43.0.0")]
+[assembly: AssemblyFileVersion("1.43.0.0")]