summaryrefslogtreecommitdiffstats
path: root/win/CS
diff options
context:
space:
mode:
authorsr55 <[email protected]>2018-12-09 21:15:40 +0000
committersr55 <[email protected]>2018-12-09 21:15:56 +0000
commit6dde7dab7f8585d98cdbeba4b8408f0d94c15663 (patch)
tree3b91cfbb1cbc1ea3bf568e190b23d0bb356275aa /win/CS
parentf1cc52aae69360bb4d415391453434e12320b0b3 (diff)
WinGui: Some further tidyup of HandBrake.Interop. Remove the instance manager. The consumers should manage this themselves.
Diffstat (limited to 'win/CS')
-rw-r--r--win/CS/HandBrake.Interop/HandBrake.Interop.csproj1
-rw-r--r--win/CS/HandBrake.Interop/Interop/HandBrakeEncoderHelpers.cs32
-rw-r--r--win/CS/HandBrake.Interop/Interop/HandBrakeInstance.cs154
-rw-r--r--win/CS/HandBrake.Interop/Interop/HandBrakeInstanceManager.cs116
-rw-r--r--win/CS/HandBrakeWPF/Instance/HandBrakeInstanceManager.cs55
-rw-r--r--win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs2
-rw-r--r--win/CS/HandBrakeWPF/Services/Scan/LibScan.cs1
7 files changed, 92 insertions, 269 deletions
diff --git a/win/CS/HandBrake.Interop/HandBrake.Interop.csproj b/win/CS/HandBrake.Interop/HandBrake.Interop.csproj
index 3571728ea..d7cc5090a 100644
--- a/win/CS/HandBrake.Interop/HandBrake.Interop.csproj
+++ b/win/CS/HandBrake.Interop/HandBrake.Interop.csproj
@@ -58,7 +58,6 @@
<Compile Include="Interop\HandBrakeEncoderHelpers.cs" />
<Compile Include="Interop\HandBrakeFilterHelpers.cs" />
<Compile Include="Interop\HandBrakeInstance.cs" />
- <Compile Include="Interop\HandBrakeInstanceManager.cs" />
<Compile Include="Interop\HandBrakeLanguagesHelper.cs" />
<Compile Include="Interop\HandBrakePresetService.cs" />
<Compile Include="Interop\HandBrakeUnitConversionHelpers.cs" />
diff --git a/win/CS/HandBrake.Interop/Interop/HandBrakeEncoderHelpers.cs b/win/CS/HandBrake.Interop/Interop/HandBrakeEncoderHelpers.cs
index f684d7367..1bdb849d5 100644
--- a/win/CS/HandBrake.Interop/Interop/HandBrakeEncoderHelpers.cs
+++ b/win/CS/HandBrake.Interop/Interop/HandBrakeEncoderHelpers.cs
@@ -9,6 +9,7 @@
namespace HandBrake.Interop.Interop
{
+ using System;
using System.Collections.Generic;
using System.Linq;
@@ -22,39 +23,12 @@ namespace HandBrake.Interop.Interop
/// </summary>
public static class HandBrakeEncoderHelpers
{
- /// <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>
- /// List of HandBrake mixdowns.
- /// </summary>
private static List<HBMixdown> mixdowns;
-
- /// <summary>
- /// List of HandBrake containers.
- /// </summary>
private static List<HBContainer> containers;
-
- /// <summary>
- /// The audio bitrates.
- /// </summary>
private static List<int> audioBitrates;
-
- /// <summary>
- /// Audio sample rates in Hz.
- /// </summary>
private static List<HBRate> audioSampleRates;
/// <summary>
@@ -432,9 +406,9 @@ namespace HandBrake.Interop.Interop
/// <returns>
/// True if DRC can be applied to the track with the given encoder.
/// </returns>
- public static bool CanApplyDrc(int trackNumber, HBAudioEncoder encoder, int title)
+ public static bool CanApplyDrc(IntPtr handle, int trackNumber, HBAudioEncoder encoder, int title)
{
- return HBFunctions.hb_audio_can_apply_drc2(HandBrakeInstanceManager.LastScanHandle, title, trackNumber, encoder.Id) > 0;
+ return HBFunctions.hb_audio_can_apply_drc2(handle, title, trackNumber, encoder.Id) > 0;
}
/// <summary>
diff --git a/win/CS/HandBrake.Interop/Interop/HandBrakeInstance.cs b/win/CS/HandBrake.Interop/Interop/HandBrakeInstance.cs
index c6aa42fe3..6e7103bd6 100644
--- a/win/CS/HandBrake.Interop/Interop/HandBrakeInstance.cs
+++ b/win/CS/HandBrake.Interop/Interop/HandBrakeInstance.cs
@@ -30,59 +30,12 @@ namespace HandBrake.Interop.Interop
using Newtonsoft.Json;
- /// <summary>
- /// A wrapper for a HandBrake instance.
- /// </summary>
public class HandBrakeInstance : IHandBrakeInstance, IDisposable
{
- /// <summary>
- /// The number of MS between status polls when scanning.
- /// </summary>
private const double ScanPollIntervalMs = 250;
-
- /// <summary>
- /// The number of MS between status polls when encoding.
- /// </summary>
private const double EncodePollIntervalMs = 250;
-
- /// <summary>
- /// The native handle to the HandBrake instance.
- /// </summary>
- private IntPtr hbHandle;
-
- /// <summary>
- /// The number of previews created during scan.
- /// </summary>
- private int previewCount;
-
- /// <summary>
- /// The timer to poll for scan status.
- /// </summary>
private Timer scanPollTimer;
-
- /// <summary>
- /// The timer to poll for encode status.
- /// </summary>
private Timer encodePollTimer;
-
- /// <summary>
- /// The list of titles on this instance.
- /// </summary>
- 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;
-
- /// <summary>
- /// A value indicating whether this object has been disposed or not.
- /// </summary>
private bool disposed;
/// <summary>
@@ -90,7 +43,7 @@ namespace HandBrake.Interop.Interop
/// </summary>
~HandBrakeInstance()
{
- if (this.hbHandle != IntPtr.Zero)
+ if (this.Handle != IntPtr.Zero)
{
this.Dispose(false);
}
@@ -119,80 +72,37 @@ namespace HandBrake.Interop.Interop
/// <summary>
/// Gets the handle.
/// </summary>
- internal IntPtr Handle
- {
- get
- {
- return this.hbHandle;
- }
- }
+ internal IntPtr Handle { get; private set; }
/// <summary>
/// Gets the number of previews created during scan.
/// </summary>
- public int PreviewCount
- {
- get
- {
- return this.previewCount;
- }
- }
+ public int PreviewCount { get; private set; }
/// <summary>
/// Gets the list of titles on this instance.
/// </summary>
- public JsonScanObject Titles
- {
- get
- {
- return this.titles;
- }
- }
+ public JsonScanObject Titles { get; private set; }
/// <summary>
/// Gets the raw JSON for the list of titles on this instance.
/// </summary>
- public string TitlesJson
- {
- get
- {
- return this.titlesJson;
- }
- }
+ public string TitlesJson { get; private set; }
/// <summary>
/// Gets the index of the default title.
/// </summary>
- public int FeatureTitle
- {
- get
- {
- return this.featureTitle;
- }
- }
+ public int FeatureTitle { get; private set; }
/// <summary>
/// Gets the HandBrake version string.
/// </summary>
- public string Version
- {
- get
- {
- var versionPtr = HBFunctions.hb_get_version(this.hbHandle);
- return Marshal.PtrToStringAnsi(versionPtr);
- }
- }
+ public string Version => Marshal.PtrToStringAnsi(HBFunctions.hb_get_version(this.Handle));
/// <summary>
/// Gets the HandBrake build number.
/// </summary>
- public int Build
- {
- get
- {
- return HBFunctions.hb_get_build(this.hbHandle);
- }
- }
+ public int Build => HBFunctions.hb_get_build(this.Handle);
/// <summary>
/// Initializes this instance.
@@ -205,7 +115,7 @@ namespace HandBrake.Interop.Interop
HandBrakeUtils.EnsureGlobalInit();
HandBrakeUtils.RegisterLogger();
- this.hbHandle = HBFunctions.hb_init(verbosity, update_check: 0);
+ this.Handle = HBFunctions.hb_init(verbosity, update_check: 0);
}
/// <summary>
@@ -225,10 +135,10 @@ namespace HandBrake.Interop.Interop
/// </param>
public void StartScan(string path, int previewCount, TimeSpan minDuration, int titleIndex)
{
- this.previewCount = previewCount;
+ this.PreviewCount = previewCount;
IntPtr pathPtr = InteropUtilities.ToUtf8PtrFromString(path);
- HBFunctions.hb_scan(this.hbHandle, pathPtr, titleIndex, previewCount, 1, (ulong)(minDuration.TotalSeconds * 90000));
+ HBFunctions.hb_scan(this.Handle, pathPtr, titleIndex, previewCount, 1, (ulong)(minDuration.TotalSeconds * 90000));
Marshal.FreeHGlobal(pathPtr);
this.scanPollTimer = new Timer();
@@ -256,7 +166,7 @@ namespace HandBrake.Interop.Interop
[HandleProcessCorruptedStateExceptions]
public void StopScan()
{
- HBFunctions.hb_scan_stop(this.hbHandle);
+ HBFunctions.hb_scan_stop(this.Handle);
}
/// <summary>
@@ -303,7 +213,7 @@ namespace HandBrake.Interop.Interop
};
// Fetch the image data from LibHb
- IntPtr resultingImageStuct = HBFunctions.hb_get_preview2(this.hbHandle, settings.TitleNumber, previewNumber, ref uiGeometry, deinterlace ? 1 : 0);
+ IntPtr resultingImageStuct = HBFunctions.hb_get_preview2(this.Handle, settings.TitleNumber, previewNumber, ref uiGeometry, deinterlace ? 1 : 0);
hb_image_s image = InteropUtilities.ToStructureFromPtr<hb_image_s>(resultingImageStuct);
// Copy the filled image buffer to a managed array.
@@ -334,7 +244,7 @@ namespace HandBrake.Interop.Interop
/// <returns>True if DRC can be applied to the track with the given encoder.</returns>
public bool CanApplyDrc(int trackNumber, HBAudioEncoder encoder, int title)
{
- return HBFunctions.hb_audio_can_apply_drc2(this.hbHandle, title, trackNumber, encoder.Id) > 0;
+ return HBFunctions.hb_audio_can_apply_drc2(this.Handle, title, trackNumber, encoder.Id) > 0;
}
/// <summary>
@@ -362,8 +272,8 @@ namespace HandBrake.Interop.Interop
[HandleProcessCorruptedStateExceptions]
public void StartEncode(string encodeJson)
{
- HBFunctions.hb_add_json(this.hbHandle, InteropUtilities.ToUtf8PtrFromString(encodeJson));
- HBFunctions.hb_start(this.hbHandle);
+ HBFunctions.hb_add_json(this.Handle, InteropUtilities.ToUtf8PtrFromString(encodeJson));
+ HBFunctions.hb_start(this.Handle);
this.encodePollTimer = new Timer();
this.encodePollTimer.Interval = EncodePollIntervalMs;
@@ -388,7 +298,7 @@ namespace HandBrake.Interop.Interop
[HandleProcessCorruptedStateExceptions]
public void PauseEncode()
{
- HBFunctions.hb_pause(this.hbHandle);
+ HBFunctions.hb_pause(this.Handle);
}
/// <summary>
@@ -397,7 +307,7 @@ namespace HandBrake.Interop.Interop
[HandleProcessCorruptedStateExceptions]
public void ResumeEncode()
{
- HBFunctions.hb_resume(this.hbHandle);
+ HBFunctions.hb_resume(this.Handle);
}
/// <summary>
@@ -406,20 +316,20 @@ namespace HandBrake.Interop.Interop
[HandleProcessCorruptedStateExceptions]
public void StopEncode()
{
- HBFunctions.hb_stop(this.hbHandle);
+ HBFunctions.hb_stop(this.Handle);
// Also remove all jobs from the queue (in case we stopped a 2-pass encode)
var currentJobs = new List<IntPtr>();
- int jobs = HBFunctions.hb_count(this.hbHandle);
+ int jobs = HBFunctions.hb_count(this.Handle);
for (int i = 0; i < jobs; i++)
{
- currentJobs.Add(HBFunctions.hb_job(this.hbHandle, 0));
+ currentJobs.Add(HBFunctions.hb_job(this.Handle, 0));
}
foreach (IntPtr job in currentJobs)
{
- HBFunctions.hb_rem(this.hbHandle, job);
+ HBFunctions.hb_rem(this.Handle, job);
}
}
@@ -432,7 +342,7 @@ namespace HandBrake.Interop.Interop
[HandleProcessCorruptedStateExceptions]
public JsonState GetEncodeProgress()
{
- IntPtr json = HBFunctions.hb_get_state_json(this.hbHandle);
+ IntPtr json = HBFunctions.hb_get_state_json(this.Handle);
string statusJson = Marshal.PtrToStringAnsi(json);
JsonState state = JsonConvert.DeserializeObject<JsonState>(statusJson);
@@ -479,7 +389,7 @@ namespace HandBrake.Interop.Interop
// Free unmanaged objects.
IntPtr handlePtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr)));
- Marshal.WriteIntPtr(handlePtr, this.hbHandle);
+ Marshal.WriteIntPtr(handlePtr, this.Handle);
HBFunctions.hb_close(handlePtr);
Marshal.FreeHGlobal(handlePtr);
@@ -492,7 +402,7 @@ namespace HandBrake.Interop.Interop
[HandleProcessCorruptedStateExceptions]
private void PollScanProgress()
{
- IntPtr json = HBFunctions.hb_get_state_json(this.hbHandle);
+ IntPtr json = HBFunctions.hb_get_state_json(this.Handle);
string statusJson = Marshal.PtrToStringAnsi(json);
JsonState state = null;
if (!string.IsNullOrEmpty(statusJson))
@@ -513,15 +423,15 @@ namespace HandBrake.Interop.Interop
{
this.scanPollTimer.Stop();
- var jsonMsg = HBFunctions.hb_get_title_set_json(this.hbHandle);
- this.titlesJson = InteropUtilities.ToStringFromUtf8Ptr(jsonMsg);
+ var jsonMsg = HBFunctions.hb_get_title_set_json(this.Handle);
+ this.TitlesJson = InteropUtilities.ToStringFromUtf8Ptr(jsonMsg);
- if (!string.IsNullOrEmpty(this.titlesJson))
+ if (!string.IsNullOrEmpty(this.TitlesJson))
{
- this.titles = JsonConvert.DeserializeObject<JsonScanObject>(this.titlesJson);
- if (this.titles != null)
+ this.Titles = JsonConvert.DeserializeObject<JsonScanObject>(this.TitlesJson);
+ if (this.Titles != null)
{
- this.featureTitle = this.titles.MainFeature;
+ this.FeatureTitle = this.Titles.MainFeature;
}
}
@@ -538,7 +448,7 @@ namespace HandBrake.Interop.Interop
[HandleProcessCorruptedStateExceptions]
private void PollEncodeProgress()
{
- IntPtr json = HBFunctions.hb_get_state_json(this.hbHandle);
+ IntPtr json = HBFunctions.hb_get_state_json(this.Handle);
string statusJson = Marshal.PtrToStringAnsi(json);
JsonState state = JsonConvert.DeserializeObject<JsonState>(statusJson);
diff --git a/win/CS/HandBrake.Interop/Interop/HandBrakeInstanceManager.cs b/win/CS/HandBrake.Interop/Interop/HandBrakeInstanceManager.cs
deleted file mode 100644
index 76855c5d1..000000000
--- a/win/CS/HandBrake.Interop/Interop/HandBrakeInstanceManager.cs
+++ /dev/null
@@ -1,116 +0,0 @@
-// --------------------------------------------------------------------------------------------------------------------
-// <copyright file="HandBrakeInstanceManager.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>
-// <summary>
-// The hand brake instance manager.
-// </summary>
-// --------------------------------------------------------------------------------------------------------------------
-
-namespace HandBrake.Interop.Interop
-{
- using System;
-
- using HandBrake.Interop.Interop.Interfaces;
- using HandBrake.Interop.Model;
-
- /// <summary>
- /// The HandBrake Instance manager.
- /// Only supports scanning right now.
- /// </summary>
- public static class HandBrakeInstanceManager
- {
- private static HandBrakeInstance scanInstance;
- private static HandBrakeInstance previewInstance;
-
- /// <summary>
- /// Initializes static members of the <see cref="HandBrakeInstanceManager"/> class.
- /// </summary>
- static HandBrakeInstanceManager()
- {
- }
-
- /// <summary>
- /// The init.
- /// </summary>
- public static void Init()
- {
- // Nothing to do. Triggers static constructor.
- }
-
- /// <summary>
- /// Gets the scanInstance.
- /// </summary>
- /// <param name="verbosity">
- /// The verbosity.
- /// </param>
- /// <returns>
- /// The <see cref="IHandBrakeInstance"/>.
- /// </returns>
- public static IHandBrakeInstance GetScanInstance(int verbosity)
- {
- if (scanInstance != null)
- {
- scanInstance.Dispose();
- scanInstance = null;
- }
-
- HandBrakeInstance newInstance = new HandBrakeInstance();
- newInstance.Initialize(verbosity);
- scanInstance = newInstance;
-
- return scanInstance;
- }
-
- /// <summary>
- /// The get encode instance.
- /// </summary>
- /// <param name="verbosity">
- /// The verbosity.
- /// </param>
- /// <param name="configuration">
- /// The configuration.
- /// </param>
- /// <returns>
- /// The <see cref="IHandBrakeInstance"/>.
- /// </returns>
- public static IHandBrakeInstance GetPreviewInstance(int verbosity, HBConfiguration configuration)
- {
- if (previewInstance != null)
- {
- previewInstance.Dispose();
- previewInstance = null;
- }
-
- HandBrakeInstance newInstance = new HandBrakeInstance();
- newInstance.Initialize(verbosity);
- previewInstance = newInstance;
-
- HandBrakeUtils.SetDvdNav(!configuration.IsDvdNavDisabled);
-
- return previewInstance;
- }
-
- /// <summary>
- /// Gets the last scan scan instance.
- /// </summary>
- internal static IHandBrakeInstance LastScanScanInstance
- {
- get
- {
- return scanInstance;
- }
- }
-
- /// <summary>
- /// Gets the handle.
- /// </summary>
- internal static IntPtr LastScanHandle
- {
- get
- {
- return scanInstance.Handle;
- }
- }
- }
-}
diff --git a/win/CS/HandBrakeWPF/Instance/HandBrakeInstanceManager.cs b/win/CS/HandBrakeWPF/Instance/HandBrakeInstanceManager.cs
index 3fcf00e8f..d841dfab5 100644
--- a/win/CS/HandBrakeWPF/Instance/HandBrakeInstanceManager.cs
+++ b/win/CS/HandBrakeWPF/Instance/HandBrakeInstanceManager.cs
@@ -20,6 +20,8 @@ namespace HandBrakeWPF.Instance
public static class HandBrakeInstanceManager
{
private static IEncodeInstance encodeInstance;
+ private static HandBrakeInstance scanInstance;
+ private static HandBrakeInstance previewInstance;
/// <summary>
/// Initializes static members of the <see cref="HandBrakeInstanceManager"/> class.
@@ -74,5 +76,58 @@ namespace HandBrakeWPF.Instance
return encodeInstance;
}
+
+ /// <summary>
+ /// Gets the scanInstance.
+ /// </summary>
+ /// <param name="verbosity">
+ /// The verbosity.
+ /// </param>
+ /// <returns>
+ /// The <see cref="IHandBrakeInstance"/>.
+ /// </returns>
+ public static IHandBrakeInstance GetScanInstance(int verbosity)
+ {
+ if (scanInstance != null)
+ {
+ scanInstance.Dispose();
+ scanInstance = null;
+ }
+
+ HandBrakeInstance newInstance = new HandBrakeInstance();
+ newInstance.Initialize(verbosity);
+ scanInstance = newInstance;
+
+ return scanInstance;
+ }
+
+ /// <summary>
+ /// The get encode instance.
+ /// </summary>
+ /// <param name="verbosity">
+ /// The verbosity.
+ /// </param>
+ /// <param name="configuration">
+ /// The configuration.
+ /// </param>
+ /// <returns>
+ /// The <see cref="IHandBrakeInstance"/>.
+ /// </returns>
+ public static IHandBrakeInstance GetPreviewInstance(int verbosity, HBConfiguration configuration)
+ {
+ if (previewInstance != null)
+ {
+ previewInstance.Dispose();
+ previewInstance = null;
+ }
+
+ HandBrakeInstance newInstance = new HandBrakeInstance();
+ newInstance.Initialize(verbosity);
+ previewInstance = newInstance;
+
+ HandBrakeUtils.SetDvdNav(!configuration.IsDvdNavDisabled);
+
+ return previewInstance;
+ }
}
}
diff --git a/win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs b/win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs
index 5c37dc4dd..382dd7cf9 100644
--- a/win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs
+++ b/win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs
@@ -80,7 +80,7 @@ namespace HandBrakeWPF.Services.Encode
this.log.Reset(); // Reset so we have a clean log for the start of the encode.
this.ServiceLogMessage("Starting Encode ...");
- this.instance = task.IsPreviewEncode ? HandBrake.Interop.Interop.HandBrakeInstanceManager.GetPreviewInstance(configuration.Verbosity, configuration) : HandBrakeInstanceManager.GetEncodeInstance(configuration.Verbosity, configuration);
+ this.instance = task.IsPreviewEncode ? HandBrakeInstanceManager.GetPreviewInstance(configuration.Verbosity, configuration) : HandBrakeInstanceManager.GetEncodeInstance(configuration.Verbosity, configuration);
this.instance.EncodeCompleted += this.InstanceEncodeCompleted;
this.instance.EncodeProgress += this.InstanceEncodeProgress;
diff --git a/win/CS/HandBrakeWPF/Services/Scan/LibScan.cs b/win/CS/HandBrakeWPF/Services/Scan/LibScan.cs
index e3148866a..40823f3f7 100644
--- a/win/CS/HandBrakeWPF/Services/Scan/LibScan.cs
+++ b/win/CS/HandBrakeWPF/Services/Scan/LibScan.cs
@@ -23,6 +23,7 @@ namespace HandBrakeWPF.Services.Scan
using HandBrake.Interop.Interop.Model.Preview;
using HandBrake.Interop.Model;
+ using HandBrakeWPF.Instance;
using HandBrakeWPF.Services.Encode.Model;
using HandBrakeWPF.Services.Encode.Model.Models;
using HandBrakeWPF.Services.Scan.EventArgs;