summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrake.ApplicationServices
diff options
context:
space:
mode:
authorRandomEngy <[email protected]>2017-11-16 23:02:28 -0800
committerScott <[email protected]>2017-11-18 14:29:34 +0000
commit2c5f96a2fdbe7407fd360e424ac43cac0fd3ad26 (patch)
tree7cf68cacb9d7f20df5d8cd52e3eed489b298c796 /win/CS/HandBrake.ApplicationServices
parent17a4bb75f924854532636f4e3450ae9f4a4d8c81 (diff)
Some additions for mixdowns and ability encode from JSON string.
Diffstat (limited to 'win/CS/HandBrake.ApplicationServices')
-rw-r--r--win/CS/HandBrake.ApplicationServices/Interop/HandBrakeEncoderHelpers.cs21
-rw-r--r--win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstance.cs34
-rw-r--r--win/CS/HandBrake.ApplicationServices/Interop/HbLib/HbFunctions.cs2
3 files changed, 53 insertions, 4 deletions
diff --git a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeEncoderHelpers.cs b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeEncoderHelpers.cs
index b0e72976a..125c04449 100644
--- a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeEncoderHelpers.cs
+++ b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeEncoderHelpers.cs
@@ -244,6 +244,16 @@ namespace HandBrake.ApplicationServices.Interop
return Mixdowns.SingleOrDefault(m => m.ShortName == shortName);
}
+ /// <summary>
+ /// Gets the mixdown with the specified ID.
+ /// </summary>
+ /// <param name="id">The mixdown ID.</param>
+ /// <returns>The requested mixdown.</returns>
+ public static HBMixdown GetMixdown(int id)
+ {
+ return Mixdowns.SingleOrDefault(m => m.Id == id);
+ }
+
/// <summary>
/// Gets the container with the specified short name.
/// </summary>
@@ -489,6 +499,17 @@ namespace HandBrake.ApplicationServices.Interop
return Mixdowns.Single(m => m.Id == defaultMixdown);
}
+ /// <summary>
+ /// Sanitizes the given sample rate for the given encoder.
+ /// </summary>
+ /// <param name="encoder">The encoder.</param>
+ /// <param name="sampleRate">The sample rate to sanitize.</param>
+ /// <returns>The sanitized sample rate.</returns>
+ public static int SanitizeSampleRate(HBAudioEncoder encoder, int sampleRate)
+ {
+ return HBFunctions.hb_audio_samplerate_find_closest(sampleRate, (uint)encoder.Id);
+ }
+
/// <summary>
/// Gets the bitrate limits for the given audio codec, sample rate and mixdown.
/// </summary>
diff --git a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstance.cs b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstance.cs
index 45b2f8488..b44dd385c 100644
--- a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstance.cs
+++ b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstance.cs
@@ -83,6 +83,11 @@ namespace HandBrake.ApplicationServices.Interop
private JsonScanObject titles;
/// <summary>
+ /// The raw JSON for the titles list.
+ /// </summary>
+ private string titlesJson;
+
+ /// <summary>
/// The index of the default title.
/// </summary>
private int featureTitle;
@@ -154,6 +159,17 @@ namespace HandBrake.ApplicationServices.Interop
}
/// <summary>
+ /// Gets the raw JSON for the list of titles on this instance.
+ /// </summary>
+ public string TitlesJson
+ {
+ get
+ {
+ return this.titlesJson;
+ }
+ }
+
+ /// <summary>
/// Gets the index of the default title.
/// </summary>
public int FeatureTitle
@@ -360,7 +376,17 @@ namespace HandBrake.ApplicationServices.Interop
};
string encode = JsonConvert.SerializeObject(encodeObject, Formatting.Indented, settings);
- HBFunctions.hb_add_json(this.hbHandle, InteropUtilities.ToUtf8PtrFromString(encode));
+ this.StartEncode(encode);
+ }
+
+ /// <summary>
+ /// Starts an encode with the given job JSON.
+ /// </summary>
+ /// <param name="encodeJson">The JSON for the job to start.</param>
+ [HandleProcessCorruptedStateExceptions]
+ public void StartEncode(string encodeJson)
+ {
+ HBFunctions.hb_add_json(this.hbHandle, InteropUtilities.ToUtf8PtrFromString(encodeJson));
HBFunctions.hb_start(this.hbHandle);
this.encodePollTimer = new Timer();
@@ -497,8 +523,8 @@ namespace HandBrake.ApplicationServices.Interop
this.scanPollTimer.Stop();
var jsonMsg = HBFunctions.hb_get_title_set_json(this.hbHandle);
- string scanJson = InteropUtilities.ToStringFromUtf8Ptr(jsonMsg);
- this.log.LogMessage(scanJson, LogMessageType.Progress, LogLevel.Trace);
+ this.titlesJson = InteropUtilities.ToStringFromUtf8Ptr(jsonMsg);
+ this.log.LogMessage(this.titlesJson, LogMessageType.Progress, LogLevel.Trace);
if (string.IsNullOrEmpty(scanJson))
{
@@ -506,7 +532,7 @@ namespace HandBrake.ApplicationServices.Interop
}
else
{
- this.titles = JsonConvert.DeserializeObject<JsonScanObject>(scanJson);
+ this.titles = JsonConvert.DeserializeObject<JsonScanObject>(this.titlesJson);
if (this.titles != null)
{
this.featureTitle = this.titles.MainFeature;
diff --git a/win/CS/HandBrake.ApplicationServices/Interop/HbLib/HbFunctions.cs b/win/CS/HandBrake.ApplicationServices/Interop/HbLib/HbFunctions.cs
index beaf2e689..63eac3468 100644
--- a/win/CS/HandBrake.ApplicationServices/Interop/HbLib/HbFunctions.cs
+++ b/win/CS/HandBrake.ApplicationServices/Interop/HbLib/HbFunctions.cs
@@ -201,6 +201,8 @@ namespace HandBrake.ApplicationServices.Interop.HbLib
[DllImport("hb", EntryPoint = "hb_audio_samplerate_get_next", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr hb_audio_samplerate_get_next(IntPtr last);
+ [DllImport("hb", EntryPoint = "hb_audio_samplerate_find_closest", CallingConvention = CallingConvention.Cdecl)]
+ public static extern int hb_audio_samplerate_find_closest(int samplerate, uint codec);
[DllImport("hb", 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);