diff options
author | sr55 <[email protected]> | 2010-06-11 18:57:37 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2010-06-11 18:57:37 +0000 |
commit | 4ecb7b2c297ba7e87c0a9ab8e0768d45fc4f0810 (patch) | |
tree | 0bcc32549872c771f0cf21c71a7b1da31513f153 /win/C#/HandBrake.ApplicationServices | |
parent | 20c52cb94e7cb9db92a58a8aca3f92715d073f98 (diff) |
WinGui:
- Improvements to the IQueue and IEncode interface. This allows for some cleanup of code in frmMain and frmPreview
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@3376 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/C#/HandBrake.ApplicationServices')
6 files changed, 180 insertions, 86 deletions
diff --git a/win/C#/HandBrake.ApplicationServices/EncodeProgressEventArgs.cs b/win/C#/HandBrake.ApplicationServices/EncodeProgressEventArgs.cs new file mode 100644 index 000000000..8939e11c2 --- /dev/null +++ b/win/C#/HandBrake.ApplicationServices/EncodeProgressEventArgs.cs @@ -0,0 +1,40 @@ +/* EncodeProgressEventArgs.cs $
+ This file is part of the HandBrake source code.
+ Homepage: <http://handbrake.fr>.
+ It may be used under the terms of the GNU General Public License. */
+
+namespace HandBrake.ApplicationServices
+{
+ using System;
+
+ /// <summary>
+ /// Encode Progress Event Args
+ /// </summary>
+ public class EncodeProgressEventArgs : EventArgs
+ {
+ /// <summary>
+ /// Gets or sets PercentComplete.
+ /// </summary>
+ public float PercentComplete { get; set; }
+
+ /// <summary>
+ /// Gets or sets CurrentFrameRate.
+ /// </summary>
+ public float CurrentFrameRate { get; set; }
+
+ /// <summary>
+ /// Gets or sets AverageFrameRate.
+ /// </summary>
+ public float AverageFrameRate { get; set; }
+
+ /// <summary>
+ /// Gets or sets EstimatedTimeLeft.
+ /// </summary>
+ public TimeSpan EstimatedTimeLeft { get; set; }
+
+ /// <summary>
+ /// Gets or sets Task.
+ /// </summary>
+ public int Task { get; set; }
+ }
+}
diff --git a/win/C#/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj b/win/C#/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj index ce6412ffa..c2496e948 100644 --- a/win/C#/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj +++ b/win/C#/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj @@ -63,6 +63,7 @@ <Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="EncodeProgressEventArgs.cs" />
<Compile Include="frmExceptionWindow.cs">
<SubType>Form</SubType>
</Compile>
diff --git a/win/C#/HandBrake.ApplicationServices/Services/Encode.cs b/win/C#/HandBrake.ApplicationServices/Services/Encode.cs index 38c9b8086..d4e971e63 100644 --- a/win/C#/HandBrake.ApplicationServices/Services/Encode.cs +++ b/win/C#/HandBrake.ApplicationServices/Services/Encode.cs @@ -14,6 +14,7 @@ namespace HandBrake.ApplicationServices.Services using HandBrake.ApplicationServices.Functions;
using HandBrake.ApplicationServices.Model;
+ using HandBrake.ApplicationServices.Parsing;
using HandBrake.ApplicationServices.Properties;
using HandBrake.ApplicationServices.Services.Interfaces;
@@ -56,6 +57,29 @@ namespace HandBrake.ApplicationServices.Services /// </summary>
private int processID;
+ /* Constructor */
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="Encode"/> class.
+ /// </summary>
+ public Encode()
+ {
+ this.EncodeStarted += Encode_EncodeStarted;
+ }
+
+ /* Delegates */
+
+ /// <summary>
+ /// Encode Progess Status
+ /// </summary>
+ /// <param name="sender">
+ /// The sender.
+ /// </param>
+ /// <param name="e">
+ /// The EncodeProgressEventArgs.
+ /// </param>
+ public delegate void EncodeProgessStatus(object sender, EncodeProgressEventArgs e);
+
/* Event Handlers */
/// <summary>
@@ -68,12 +92,17 @@ namespace HandBrake.ApplicationServices.Services /// </summary>
public event EventHandler EncodeEnded;
+ /// <summary>
+ /// Encode process has progressed
+ /// </summary>
+ public event EncodeProgessStatus EncodeStatusChanged;
+
/* Properties */
/// <summary>
/// Gets or sets The HB Process
/// </summary>
- public Process HbProcess { get; set; }
+ protected Process HbProcess { get; set; }
/// <summary>
/// Gets a value indicating whether IsEncoding.
@@ -183,7 +212,7 @@ namespace HandBrake.ApplicationServices.Services if (HbProcess != null)
this.processHandle = HbProcess.MainWindowHandle; // Set the process Handle
-
+
// Start the Log Monitor
windowTimer = new Timer(new TimerCallback(ReadFile), null, 1000, 1000);
@@ -241,6 +270,12 @@ namespace HandBrake.ApplicationServices.Services private void HbProcess_Exited(object sender, EventArgs e)
{
IsEncoding = false;
+
+ windowTimer.Dispose();
+ ReadFile(null);
+
+ if (this.EncodeEnded != null)
+ this.EncodeEnded(this, new EventArgs());
}
/// <summary>
@@ -324,50 +359,6 @@ namespace HandBrake.ApplicationServices.Services }
/// <summary>
- /// Perform an action after an encode. e.g a shutdown, standby, restart etc.
- /// </summary>
- protected void Finish()
- {
- if (!IsEncoding)
- {
- windowTimer.Dispose();
- ReadFile(null);
- }
-
- if (this.EncodeEnded != null)
- this.EncodeEnded(this, new EventArgs());
-
- // Growl
- if (Settings.Default.growlQueue)
- GrowlCommunicator.Notify("Queue Completed", "Put down that cocktail...\nyour Handbrake queue is done.");
-
- // Do something whent he encode ends.
- switch (Settings.Default.CompletionOption)
- {
- case "Shutdown":
- Process.Start("Shutdown", "-s -t 60");
- break;
- case "Log Off":
- Win32.ExitWindowsEx(0, 0);
- break;
- case "Suspend":
- Application.SetSuspendState(PowerState.Suspend, true, true);
- break;
- case "Hibernate":
- Application.SetSuspendState(PowerState.Hibernate, true, true);
- break;
- case "Lock System":
- Win32.LockWorkStation();
- break;
- case "Quit HandBrake":
- Application.Exit();
- break;
- default:
- break;
- }
- }
-
- /// <summary>
/// Add the CLI Query to the Log File.
/// </summary>
/// <param name="encJob">
@@ -550,5 +541,65 @@ namespace HandBrake.ApplicationServices.Services logBuffer.AppendLine(e.Data);
}
}
+
+ /// <summary>
+ /// Encode Started
+ /// </summary>
+ /// <param name="sender">
+ /// The sender.
+ /// </param>
+ /// <param name="e">
+ /// The EventArgs.
+ /// </param>
+ private void Encode_EncodeStarted(object sender, EventArgs e)
+ {
+ Thread monitor = new Thread(EncodeMonitor);
+ monitor.Start();
+ }
+
+ /// <summary>
+ /// Monitor the Job
+ /// </summary>
+ private void EncodeMonitor()
+ {
+ try
+ {
+ Parser encode = new Parser(HbProcess.StandardOutput.BaseStream);
+ encode.OnEncodeProgress += EncodeOnEncodeProgress;
+ while (!encode.EndOfStream)
+ encode.ReadEncodeStatus();
+
+ // Main.ShowExceptiowWindow("Encode Monitor Stopped", "Stopped");
+ }
+ catch (Exception exc)
+ {
+ Main.ShowExceptiowWindow("An Unknown Error has occured", exc.ToString());
+ }
+ }
+
+ /// <summary>
+ /// Displays the Encode status in the GUI
+ /// </summary>
+ /// <param name="sender">The sender</param>
+ /// <param name="currentTask">The current task</param>
+ /// <param name="taskCount">Number of tasks</param>
+ /// <param name="percentComplete">Percent complete</param>
+ /// <param name="currentFps">Current encode speed in fps</param>
+ /// <param name="avg">Avg encode speed</param>
+ /// <param name="timeRemaining">Time Left</param>
+ private void EncodeOnEncodeProgress(object sender, int currentTask, int taskCount, float percentComplete, float currentFps, float avg, TimeSpan timeRemaining)
+ {
+ EncodeProgressEventArgs eventArgs = new EncodeProgressEventArgs
+ {
+ AverageFrameRate = avg,
+ CurrentFrameRate = currentFps,
+ EstimatedTimeLeft = timeRemaining,
+ PercentComplete = percentComplete,
+ Task = currentTask
+ };
+
+ if (this.EncodeStatusChanged != null)
+ this.EncodeStatusChanged(this, eventArgs);
+ }
}
}
\ No newline at end of file diff --git a/win/C#/HandBrake.ApplicationServices/Services/Interfaces/IEncode.cs b/win/C#/HandBrake.ApplicationServices/Services/Interfaces/IEncode.cs index 3b1a95dba..9a0681c2c 100644 --- a/win/C#/HandBrake.ApplicationServices/Services/Interfaces/IEncode.cs +++ b/win/C#/HandBrake.ApplicationServices/Services/Interfaces/IEncode.cs @@ -6,7 +6,6 @@ namespace HandBrake.ApplicationServices.Services.Interfaces
{
using System;
- using System.Diagnostics;
/// <summary>
/// The IEncode Interface
@@ -24,9 +23,9 @@ namespace HandBrake.ApplicationServices.Services.Interfaces event EventHandler EncodeEnded;
/// <summary>
- /// Gets or sets The HB Process
+ /// Encode process has progressed
/// </summary>
- Process HbProcess { get; set; }
+ event Encode.EncodeProgessStatus EncodeStatusChanged;
/// <summary>
/// Gets a value indicating whether IsEncoding.
diff --git a/win/C#/HandBrake.ApplicationServices/Services/Interfaces/IQueue.cs b/win/C#/HandBrake.ApplicationServices/Services/Interfaces/IQueue.cs index a01f13a1e..981f3c19e 100644 --- a/win/C#/HandBrake.ApplicationServices/Services/Interfaces/IQueue.cs +++ b/win/C#/HandBrake.ApplicationServices/Services/Interfaces/IQueue.cs @@ -7,14 +7,13 @@ namespace HandBrake.ApplicationServices.Services.Interfaces {
using System;
using System.Collections.ObjectModel;
- using System.Diagnostics;
using HandBrake.ApplicationServices.Model;
/// <summary>
/// The IQueue Interface
/// </summary>
- public interface IQueue
+ public interface IQueue : IEncode
{
/// <summary>
/// Fires when the Queue has started
@@ -59,11 +58,6 @@ namespace HandBrake.ApplicationServices.Services.Interfaces int Count { get; }
/// <summary>
- /// Gets or sets The HB Process
- /// </summary>
- Process HbProcess { get; set; }
-
- /// <summary>
/// Gets a value indicating whether IsEncoding.
/// </summary>
bool IsEncoding { get; }
@@ -153,35 +147,5 @@ namespace HandBrake.ApplicationServices.Services.Interfaces /// Requests a pause of the encode queue.
/// </summary>
void Pause();
-
- /// <summary>
- /// Fires when a new CLI Job starts
- /// </summary>
- event EventHandler EncodeStarted;
-
- /// <summary>
- /// Fires when a CLI job finishes.
- /// </summary>
- event EventHandler EncodeEnded;
-
- /// <summary>
- /// Create a preview sample video
- /// </summary>
- /// <param name="query">
- /// The CLI Query
- /// </param>
- void CreatePreviewSample(string query);
-
- /// <summary>
- /// Kill the CLI process
- /// </summary>
- void Stop();
-
- /// <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>
- void SafelyClose();
}
}
\ No newline at end of file diff --git a/win/C#/HandBrake.ApplicationServices/Services/Queue.cs b/win/C#/HandBrake.ApplicationServices/Services/Queue.cs index 226ea68b1..0a1eb3c3d 100644 --- a/win/C#/HandBrake.ApplicationServices/Services/Queue.cs +++ b/win/C#/HandBrake.ApplicationServices/Services/Queue.cs @@ -8,6 +8,7 @@ namespace HandBrake.ApplicationServices.Services using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
+ using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
@@ -16,6 +17,7 @@ namespace HandBrake.ApplicationServices.Services using HandBrake.ApplicationServices.Functions;
using HandBrake.ApplicationServices.Model;
+ using HandBrake.ApplicationServices.Properties;
using HandBrake.ApplicationServices.Services.Interfaces;
/// <summary>
@@ -38,6 +40,7 @@ namespace HandBrake.ApplicationServices.Services /// </summary>
private int nextJobId;
+ #region Events
/// <summary>
/// Fires when the Queue has started
/// </summary>
@@ -58,6 +61,7 @@ namespace HandBrake.ApplicationServices.Services /// Fires when the entire encode queue has completed.
/// </summary>
public event EventHandler QueueCompleted;
+ #endregion
#region Properties
/// <summary>
@@ -406,6 +410,41 @@ namespace HandBrake.ApplicationServices.Services Finish();
}
+ /// <summary>
+ /// Perform an action after an encode. e.g a shutdown, standby, restart etc.
+ /// </summary>
+ private void Finish()
+ {
+ // Growl
+ if (Settings.Default.growlQueue)
+ GrowlCommunicator.Notify("Queue Completed", "Put down that cocktail...\nyour Handbrake queue is done.");
+
+ // Do something whent he encode ends.
+ switch (Settings.Default.CompletionOption)
+ {
+ case "Shutdown":
+ Process.Start("Shutdown", "-s -t 60");
+ break;
+ case "Log Off":
+ Win32.ExitWindowsEx(0, 0);
+ break;
+ case "Suspend":
+ Application.SetSuspendState(PowerState.Suspend, true, true);
+ break;
+ case "Hibernate":
+ Application.SetSuspendState(PowerState.Hibernate, true, true);
+ break;
+ case "Lock System":
+ Win32.LockWorkStation();
+ break;
+ case "Quit HandBrake":
+ Application.Exit();
+ break;
+ default:
+ break;
+ }
+ }
+
#endregion
}
}
\ No newline at end of file |