summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrakeWPF/Services
diff options
context:
space:
mode:
authorsr55 <[email protected]>2012-09-25 15:23:17 +0000
committersr55 <[email protected]>2012-09-25 15:23:17 +0000
commit83af0dca6f4ecc16d5a4dcc6b6ccd97b707f7156 (patch)
tree5deeb98145f9fccd54ccf05007a06702e9197271 /win/CS/HandBrakeWPF/Services
parentc9c4474cc265ea02f25fc5e94b161705402ab807 (diff)
WinGui: LibHb Encode and Scan support (off by default for the moment until I have time to test this and tidy up some of the code) Can be turned on in preferences.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4980 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/CS/HandBrakeWPF/Services')
-rw-r--r--win/CS/HandBrakeWPF/Services/EncodeServiceWrapper.cs257
-rw-r--r--win/CS/HandBrakeWPF/Services/ScanServiceWrapper.cs243
2 files changed, 500 insertions, 0 deletions
diff --git a/win/CS/HandBrakeWPF/Services/EncodeServiceWrapper.cs b/win/CS/HandBrakeWPF/Services/EncodeServiceWrapper.cs
new file mode 100644
index 000000000..79d79164f
--- /dev/null
+++ b/win/CS/HandBrakeWPF/Services/EncodeServiceWrapper.cs
@@ -0,0 +1,257 @@
+// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="EncodeServiceWrapper.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>
+// We have multiple implementations of IEncode. This is a wrapper class for the GUI so that the
+// implementation used is controllable via user settings.
+// Over time, this class will go away when the LibHB and process isolation code matures.
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrakeWPF.Services
+{
+ using System;
+
+ using Caliburn.Micro;
+
+ using HandBrake.ApplicationServices.Exceptions;
+ using HandBrake.ApplicationServices.Isolation;
+ using HandBrake.ApplicationServices.Model;
+ using HandBrake.ApplicationServices.Services;
+ using HandBrake.ApplicationServices.Services.Interfaces;
+ using HandBrake.Interop.Interfaces;
+
+ using EncodeCompletedEventArgs = HandBrake.ApplicationServices.EventArgs.EncodeCompletedEventArgs;
+ using EncodeProgressEventArgs = HandBrake.ApplicationServices.EventArgs.EncodeProgressEventArgs;
+
+ /// <summary>
+ /// We have multiple implementations of Iencode. This is a wrapper class for the GUI so that the
+ /// implementation used is controllable via user settings.
+ /// Over time, this class will go away when the LibHB and process isolation code matures.
+ /// </summary>
+ public class EncodeServiceWrapper : IEncodeServiceWrapper
+ {
+ #region Constants and Fields
+
+ /// <summary>
+ /// The encode service.
+ /// </summary>
+ private readonly IEncode encodeService;
+
+ #endregion
+
+ #region Constructors and Destructors
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="EncodeServiceWrapper"/> class.
+ /// </summary>
+ /// <param name="userSettingService">
+ /// The user setting service.
+ /// </param>
+ public EncodeServiceWrapper(IUserSettingService userSettingService)
+ {
+ var useLibHb = userSettingService.GetUserSetting<bool>(UserSettingConstants.EnableLibHb);
+ var useProcessIsolation =
+ userSettingService.GetUserSetting<bool>(UserSettingConstants.EnableProcessIsolation);
+ var port = userSettingService.GetUserSetting<string>(UserSettingConstants.ServerPort);
+
+ if (useLibHb)
+ {
+ try
+ {
+ if (useProcessIsolation)
+ {
+ this.encodeService = new IsolatedEncodeService(port);
+ }
+ else
+ {
+ IHandBrakeInstance handBrakeInstance = IoC.Get<IHandBrakeInstance>();
+ this.encodeService = new LibEncode(userSettingService, handBrakeInstance);
+ }
+ }
+ catch (Exception exc)
+ {
+ // Try to recover from errors.
+ userSettingService.SetUserSetting(UserSettingConstants.EnableLibHb, false);
+ throw new GeneralApplicationException(
+ "Unable to initialise LibHB or Background worker service",
+ "Falling back to using HandBrakeCLI.exe. Setting has been reset",
+ exc);
+ }
+ }
+ else
+ {
+ this.encodeService = new Encode(userSettingService);
+ }
+
+ this.encodeService.EncodeCompleted += this.EncodeServiceEncodeCompleted;
+ this.encodeService.EncodeStarted += this.EncodeServiceEncodeStarted;
+ this.encodeService.EncodeStatusChanged += this.EncodeServiceEncodeStatusChanged;
+ }
+
+ #endregion
+
+ #region Events
+
+ /// <summary>
+ /// The encode completed.
+ /// </summary>
+ public event EncodeCompletedStatus EncodeCompleted;
+
+ /// <summary>
+ /// The encode started.
+ /// </summary>
+ public event EventHandler EncodeStarted;
+
+ /// <summary>
+ /// The encode status changed.
+ /// </summary>
+ public event EncodeProgessStatus EncodeStatusChanged;
+
+ #endregion
+
+ #region Properties
+
+ /// <summary>
+ /// Gets ActivityLog.
+ /// </summary>
+ public string ActivityLog
+ {
+ get
+ {
+ return this.encodeService.ActivityLog;
+ }
+ }
+
+ /// <summary>
+ /// Gets a value indicating whether IsEncoding.
+ /// </summary>
+ public bool IsEncoding
+ {
+ get
+ {
+ return this.encodeService.IsEncoding;
+ }
+ }
+
+ #endregion
+
+ #region Implemented Interfaces
+
+ #region IEncode
+
+ /// <summary>
+ /// Copy the log file to the desired destinations
+ /// </summary>
+ /// <param name="destination">
+ /// The destination.
+ /// </param>
+ public void ProcessLogs(string destination)
+ {
+ this.encodeService.ProcessLogs(destination);
+ }
+
+ /// <summary>
+ /// Attempt to Safely kill a DirectRun() CLI
+ /// NOTE: This will not work with a MinGW CLI
+ /// Note: http://www.cygwin.com/ml/cygwin/2006-03/msg00330.html
+ /// </summary>
+ public void SafelyStop()
+ {
+ this.encodeService.SafelyStop();
+ }
+
+ /// <summary>
+ /// Shutdown the service.
+ /// </summary>
+ public void Shutdown()
+ {
+ this.encodeService.Shutdown();
+ this.encodeService.EncodeCompleted -= this.EncodeServiceEncodeCompleted;
+ this.encodeService.EncodeStarted -= this.EncodeServiceEncodeStarted;
+ this.encodeService.EncodeStatusChanged -= this.EncodeServiceEncodeStatusChanged;
+ }
+
+ /// <summary>
+ /// Start with a LibHb EncodeJob Object
+ /// </summary>
+ /// <param name="job">
+ /// The job.
+ /// </param>
+ /// <param name="enableLogging">
+ /// The enable Logging.
+ /// </param>
+ public void Start(QueueTask job, bool enableLogging)
+ {
+ this.encodeService.Start(job, enableLogging);
+ }
+
+ /// <summary>
+ /// Kill the CLI process
+ /// </summary>
+ public void Stop()
+ {
+ this.encodeService.Stop();
+ }
+
+ #endregion
+
+ #endregion
+
+ #region Methods
+
+ /// <summary>
+ /// The encode service_ encode completed.
+ /// </summary>
+ /// <param name="sender">
+ /// The sender.
+ /// </param>
+ /// <param name="e">
+ /// The EncodeCompletedEventArgs.
+ /// </param>
+ private void EncodeServiceEncodeCompleted(object sender, EncodeCompletedEventArgs e)
+ {
+ if (EncodeCompleted != null)
+ {
+ this.EncodeCompleted(sender, e);
+ }
+ }
+
+ /// <summary>
+ /// The encode service_ encode started.
+ /// </summary>
+ /// <param name="sender">
+ /// The sender.
+ /// </param>
+ /// <param name="e">
+ /// The EventArgs
+ /// </param>
+ private void EncodeServiceEncodeStarted(object sender, EventArgs e)
+ {
+ if (EncodeStarted != null)
+ {
+ this.EncodeStarted(sender, e);
+ }
+ }
+
+ /// <summary>
+ /// The encode service_ encode status changed.
+ /// </summary>
+ /// <param name="sender">
+ /// The sender.
+ /// </param>
+ /// <param name="e">
+ /// The EncodeProgressEventArgs.
+ /// </param>
+ private void EncodeServiceEncodeStatusChanged(object sender, EncodeProgressEventArgs e)
+ {
+ if (EncodeStatusChanged != null)
+ {
+ this.EncodeStatusChanged(sender, e);
+ }
+ }
+
+ #endregion
+ }
+} \ No newline at end of file
diff --git a/win/CS/HandBrakeWPF/Services/ScanServiceWrapper.cs b/win/CS/HandBrakeWPF/Services/ScanServiceWrapper.cs
new file mode 100644
index 000000000..a25213a6b
--- /dev/null
+++ b/win/CS/HandBrakeWPF/Services/ScanServiceWrapper.cs
@@ -0,0 +1,243 @@
+// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="ScanServiceWrapper.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>
+// We have multiple implementations of IScan. This is a wrapper class for the GUI so that the
+// implementation used is controllable via user settings.
+// Over time, this class will go away when the LibHB and process isolation code matures.
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrakeWPF.Services
+{
+ using System;
+
+ using Caliburn.Micro;
+
+ using HandBrake.ApplicationServices.Exceptions;
+ using HandBrake.ApplicationServices.Isolation;
+ using HandBrake.ApplicationServices.Parsing;
+ using HandBrake.ApplicationServices.Services;
+ using HandBrake.ApplicationServices.Services.Interfaces;
+ using HandBrake.Interop.Interfaces;
+
+ /// <summary>
+ /// We have multiple implementations of IScan. This is a wrapper class for the GUI so that the
+ /// implementation used is controllable via user settings.
+ /// Over time, this class will go away when the LibHB and process isolation code matures.
+ /// </summary>
+ public class ScanServiceWrapper : IScanServiceWrapper
+ {
+ #region Constants and Fields
+
+ /// <summary>
+ /// The scan service.
+ /// </summary>
+ private readonly IScan scanService;
+
+ #endregion
+
+ #region Constructors and Destructors
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="ScanServiceWrapper"/> class.
+ /// </summary>
+ /// <param name="userSettingService">
+ /// The user setting service.
+ /// </param>
+ public ScanServiceWrapper(IUserSettingService userSettingService)
+ {
+ var useLibHb = userSettingService.GetUserSetting<bool>(UserSettingConstants.EnableLibHb);
+ var useProcessIsolation =
+ userSettingService.GetUserSetting<bool>(UserSettingConstants.EnableProcessIsolation);
+ string port = userSettingService.GetUserSetting<string>(UserSettingConstants.ServerPort);
+
+ if (useLibHb)
+ {
+ try
+ {
+ if (useProcessIsolation)
+ {
+ this.scanService = new IsolatedScanService(port);
+ }
+ else
+ {
+ IHandBrakeInstance handBrakeInstance = IoC.Get<IHandBrakeInstance>();
+ this.scanService = new LibScan(userSettingService, handBrakeInstance);
+ }
+ }
+ catch(Exception exc)
+ {
+ // Try to recover from errors.
+ userSettingService.SetUserSetting(UserSettingConstants.EnableLibHb, false);
+ throw new GeneralApplicationException("Unable to initialise LibHB or Background worker service", "Falling back to using HandBrakeCLI.exe. Setting has been reset", exc);
+ }
+ }
+ else
+ {
+ this.scanService = new ScanService(userSettingService);
+ }
+
+ this.scanService.ScanCompleted += this.ScanServiceScanCompleted;
+ this.scanService.ScanStared += this.ScanServiceScanStared;
+ this.scanService.ScanStatusChanged += this.ScanServiceScanStatusChanged;
+ }
+
+ /// <summary>
+ /// The scan service scan status changed event
+ /// </summary>
+ /// <param name="sender">
+ /// The sender.
+ /// </param>
+ /// <param name="e">
+ /// The ScanProgressEventArgs.
+ /// </param>
+ private void ScanServiceScanStatusChanged(object sender, HandBrake.ApplicationServices.EventArgs.ScanProgressEventArgs e)
+ {
+ this.ScanStatusChanged(sender, e);
+ }
+
+ /// <summary>
+ /// The scan service scan stared event
+ /// </summary>
+ /// <param name="sender">
+ /// The sender.
+ /// </param>
+ /// <param name="e">
+ /// The EventArgs
+ /// </param>
+ private void ScanServiceScanStared(object sender, EventArgs e)
+ {
+ this.ScanStared(sender, e);
+ }
+
+ /// <summary>
+ /// The scan service scan completed event
+ /// </summary>
+ /// <param name="sender">
+ /// The sender.
+ /// </param>
+ /// <param name="e">
+ /// The ScanCompletedEventArgs
+ /// </param>
+ private void ScanServiceScanCompleted(object sender, HandBrake.ApplicationServices.EventArgs.ScanCompletedEventArgs e)
+ {
+ this.ScanCompleted(sender, e);
+ }
+
+ #endregion
+
+ #region Events
+
+ /// <summary>
+ /// The scan completed.
+ /// </summary>
+ public event ScanCompletedStatus ScanCompleted;
+
+ /// <summary>
+ /// The scan stared.
+ /// </summary>
+ public event EventHandler ScanStared;
+
+ /// <summary>
+ /// The scan status changed.
+ /// </summary>
+ public event ScanProgessStatus ScanStatusChanged;
+
+ #endregion
+
+ #region Properties
+
+ /// <summary>
+ /// Gets ActivityLog.
+ /// </summary>
+ public string ActivityLog
+ {
+ get
+ {
+ return this.scanService.ActivityLog;
+ }
+ }
+
+ /// <summary>
+ /// Gets a value indicating whether IsScanning.
+ /// </summary>
+ public bool IsScanning
+ {
+ get
+ {
+ return this.scanService.IsScanning;
+ }
+ }
+
+ /// <summary>
+ /// Gets the Souce Data.
+ /// </summary>
+ public Source SouceData
+ {
+ get
+ {
+ return this.scanService.SouceData;
+ }
+ }
+
+ #endregion
+
+ #region Implemented Interfaces
+
+ #region IScan
+
+ /// <summary>
+ /// Take a Scan Log file, and process it as if it were from the CLI.
+ /// </summary>
+ /// <param name="path">
+ /// The path to the log file.
+ /// </param>
+ public void DebugScanLog(string path)
+ {
+ this.scanService.DebugScanLog(path);
+ }
+
+ /// <summary>
+ /// Shutdown the service.
+ /// </summary>
+ public void Shutdown()
+ {
+ this.scanService.Shutdown();
+ }
+
+ /// <summary>
+ /// Scan a Source Path.
+ /// Title 0: scan all
+ /// </summary>
+ /// <param name="sourcePath">
+ /// Path to the file to scan
+ /// </param>
+ /// <param name="title">
+ /// int title number. 0 for scan all
+ /// </param>
+ /// <param name="previewCount">
+ /// The preview Count.
+ /// </param>
+ /// <param name="postAction">
+ /// The post Action.
+ /// </param>
+ public void Scan(string sourcePath, int title, int previewCount, Action<bool> postAction)
+ {
+ this.scanService.Scan(sourcePath, title, previewCount, postAction);
+ }
+
+ /// <summary>
+ /// Kill the scan
+ /// </summary>
+ public void Stop()
+ {
+ this.scanService.Stop();
+ }
+
+ #endregion
+
+ #endregion
+ }
+} \ No newline at end of file