Skip to content

Commit

Permalink
Some additions for mixdowns and ability encode from JSON string.
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomEngy authored and sr55 committed Nov 18, 2017
1 parent 17a4bb7 commit 2c5f96a
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,16 @@ public static HBMixdown GetMixdown(string shortName)
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>
Expand Down Expand Up @@ -489,6 +499,17 @@ public static HBMixdown GetDefaultMixdown(HBAudioEncoder encoder, ulong layout)
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>
Expand Down
34 changes: 30 additions & 4 deletions win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ public class HandBrakeInstance : IHandBrakeInstance, IDisposable
/// </summary>
private JsonScanObject titles;

/// <summary>
/// The raw JSON for the titles list.
/// </summary>
private string titlesJson;

/// <summary>
/// The index of the default title.
/// </summary>
Expand Down Expand Up @@ -153,6 +158,17 @@ public JsonScanObject Titles
}
}

/// <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>
Expand Down Expand Up @@ -360,7 +376,17 @@ public void StartEncode(JsonEncodeObject encodeObject)
};

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();
Expand Down Expand Up @@ -497,16 +523,16 @@ private void PollScanProgress()
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))
{
this.log.LogMessage("Scan Error: No Scan Data Returned.", LogMessageType.API, LogLevel.Error);
}
else
{
this.titles = JsonConvert.DeserializeObject<JsonScanObject>(scanJson);
this.titles = JsonConvert.DeserializeObject<JsonScanObject>(this.titlesJson);
if (this.titles != null)
{
this.featureTitle = this.titles.MainFeature;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ public static class HBFunctions
[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);
Expand Down

0 comments on commit 2c5f96a

Please sign in to comment.