diff options
-rw-r--r-- | win/C#/CLI/Jobs/Encode.cs | 2 | ||||
-rw-r--r-- | win/C#/CLI/Jobs/Job.cs | 14 | ||||
-rw-r--r-- | win/C#/CLI/Jobs/ParseDVD.cs | 2 | ||||
-rw-r--r-- | win/C#/Parsing/Parser.cs | 35 | ||||
-rw-r--r-- | win/C#/frmDvdInfo.cs | 4 | ||||
-rw-r--r-- | win/C#/frmMain.Designer.cs | 16 | ||||
-rw-r--r-- | win/C#/frmMain.cs | 25 | ||||
-rw-r--r-- | win/C#/frmReadDVD.cs | 4 |
8 files changed, 76 insertions, 26 deletions
diff --git a/win/C#/CLI/Jobs/Encode.cs b/win/C#/CLI/Jobs/Encode.cs index e09673856..ed537b515 100644 --- a/win/C#/CLI/Jobs/Encode.cs +++ b/win/C#/CLI/Jobs/Encode.cs @@ -4,7 +4,7 @@ using System.Text; namespace Handbrake.CLI.Jobs
{
- public class Encode
+ public class Encode : Job
{
public override string ToString()
{
diff --git a/win/C#/CLI/Jobs/Job.cs b/win/C#/CLI/Jobs/Job.cs index f1c02c352..454bb21c6 100644 --- a/win/C#/CLI/Jobs/Job.cs +++ b/win/C#/CLI/Jobs/Job.cs @@ -7,20 +7,6 @@ namespace Handbrake.CLI.Jobs {
public class Job
{
- private string m_exec;
-
- private Process m_proc;
- /// <summary>
- /// The base process associated with this job
- /// </summary>
- public Process Process
- {
- get
- {
- return this.m_proc;
- }
- }
-
public Job()
{
}
diff --git a/win/C#/CLI/Jobs/ParseDVD.cs b/win/C#/CLI/Jobs/ParseDVD.cs index d902fc35c..a56a28d65 100644 --- a/win/C#/CLI/Jobs/ParseDVD.cs +++ b/win/C#/CLI/Jobs/ParseDVD.cs @@ -4,7 +4,7 @@ using System.Text; namespace Handbrake.CLI.Jobs
{
- public class ParseDVD
+ public class ParseDVD : Job
{
public override string ToString()
{
diff --git a/win/C#/Parsing/Parser.cs b/win/C#/Parsing/Parser.cs index afd5471d0..f56999a0d 100644 --- a/win/C#/Parsing/Parser.cs +++ b/win/C#/Parsing/Parser.cs @@ -22,6 +22,18 @@ namespace Handbrake.Parsing public delegate void ScanProgressEventHandler(object Sender, int CurrentTitle, int TitleCount);
/// <summary>
+ /// A delegate to handle encode progress updates
+ /// </summary>
+ /// <param name="Sender">The object which raised the event</param>
+ /// <param name="CurrentTask">The current task being processed from the queue</param>
+ /// <param name="TaskCount">The total number of tasks in queue</param>
+ /// <param name="PercentComplete">The percentage this task is complete</param>
+ /// <param name="CurrentFps">The current encoding fps</param>
+ /// <param name="AverageFps">The average encoding fps for this task</param>
+ /// <param name="TimeRemaining">The estimated time remaining for this task to complete</param>
+ public delegate void EncodeProgressEventHandler(object Sender, int CurrentTask, int TaskCount, float PercentComplete, float CurrentFps, float AverageFps, TimeSpan TimeRemaining);
+
+ /// <summary>
/// A simple wrapper around a StreamReader to keep track of the entire output from a cli process
/// </summary>
internal class Parser : StreamReader
@@ -41,17 +53,19 @@ namespace Handbrake.Parsing /// <summary>
/// Raised upon a new line being read from stdout/stderr
/// </summary>
- public static event DataReadEventHandler OnReadLine;
+ public event DataReadEventHandler OnReadLine;
/// <summary>
/// Raised upon the entire stdout/stderr stream being read in a single call
/// </summary>
- public static event DataReadEventHandler OnReadToEnd;
+ public event DataReadEventHandler OnReadToEnd;
/// <summary>
/// Raised upon the catching of a "Scanning title # of #..." in the stream
/// </summary>
- public static event ScanProgressEventHandler OnScanProgress;
+ public event ScanProgressEventHandler OnScanProgress;
+
+ public event EncodeProgressEventHandler OnEncodeProgress;
/// <summary>
/// Default constructor for this object
@@ -75,6 +89,21 @@ namespace Handbrake.Parsing {
OnScanProgress(this, int.Parse(m.Groups[1].Value), int.Parse(m.Groups[2].Value));
}
+ m = Regex.Match(tmp, @"^Encoding: task ([0-9]*) of ([0-9]*), ([0-9]*\.[0-9]*) %( \(([0-9]*\.[0-9]*) fps, avg ([0-9]*\.[0-9]*) fps, ETA ([0-9]{2})h([0-9]{2})m([0-9]{2})s\))?");
+ if (m.Success && OnEncodeProgress != null)
+ {
+ int currentTask = int.Parse(m.Groups[1].Value);
+ int totalTasks = int.Parse(m.Groups[2].Value);
+ float percent = float.Parse(m.Groups[3].Value);
+ float currentFps = m.Groups[5].Value == string.Empty ? 0.0F : float.Parse(m.Groups[5].Value);
+ float avgFps = m.Groups[6].Value == string.Empty ? 0.0F : float.Parse(m.Groups[6].Value);
+ TimeSpan remaining = TimeSpan.Zero;
+ if (m.Groups[7].Value != string.Empty)
+ {
+ remaining = TimeSpan.Parse(m.Groups[7].Value + ":" + m.Groups[8].Value + ":" + m.Groups[9].Value);
+ }
+ OnEncodeProgress(this, currentTask, totalTasks, percent, currentFps, avgFps, remaining);
+ }
return tmp;
}
diff --git a/win/C#/frmDvdInfo.cs b/win/C#/frmDvdInfo.cs index 7d58cb146..06ca59932 100644 --- a/win/C#/frmDvdInfo.cs +++ b/win/C#/frmDvdInfo.cs @@ -16,12 +16,10 @@ namespace Handbrake public frmDvdInfo()
{
InitializeComponent();
- Parsing.Parser.OnReadLine += HandleParsedData;
- Parsing.Parser.OnReadToEnd += HandleParsedData;
this.rtf_dvdInfo.Text = string.Empty;
}
- private void HandleParsedData(object Sender, string Data)
+ public void HandleParsedData(object Sender, string Data)
{
if (this.InvokeRequired)
{
diff --git a/win/C#/frmMain.Designer.cs b/win/C#/frmMain.Designer.cs index 59c864c24..3d6431f5f 100644 --- a/win/C#/frmMain.Designer.cs +++ b/win/C#/frmMain.Designer.cs @@ -170,6 +170,7 @@ namespace Handbrake this.btn_queue = new System.Windows.Forms.Button();
this.btn_encode = new System.Windows.Forms.Button();
this.Version = new System.Windows.Forms.Label();
+ this.tempEncodeLbl = new System.Windows.Forms.Label();
Label38 = new System.Windows.Forms.Label();
this.frmMainMenu.SuspendLayout();
this.GroupBox1.SuspendLayout();
@@ -1283,7 +1284,7 @@ namespace Handbrake this.slider_videoQuality.Location = new System.Drawing.Point(129, 90);
this.slider_videoQuality.Maximum = 100;
this.slider_videoQuality.Name = "slider_videoQuality";
- this.slider_videoQuality.Size = new System.Drawing.Size(167, 42);
+ this.slider_videoQuality.Size = new System.Drawing.Size(167, 45);
this.slider_videoQuality.TabIndex = 6;
this.slider_videoQuality.TickFrequency = 17;
this.slider_videoQuality.Scroll += new System.EventHandler(this.slider_videoQuality_Scroll);
@@ -1711,11 +1712,23 @@ namespace Handbrake this.Version.TabIndex = 415;
this.Version.Text = "Version 2.3";
//
+ // tempEncodeLbl
+ //
+ this.tempEncodeLbl.AutoSize = true;
+ this.tempEncodeLbl.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
+ this.tempEncodeLbl.Location = new System.Drawing.Point(370, 19);
+ this.tempEncodeLbl.Name = "tempEncodeLbl";
+ this.tempEncodeLbl.Size = new System.Drawing.Size(115, 13);
+ this.tempEncodeLbl.TabIndex = 418;
+ this.tempEncodeLbl.Text = "Encoding started...";
+ this.tempEncodeLbl.Visible = false;
+ //
// frmMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(675, 621);
+ this.Controls.Add(this.tempEncodeLbl);
this.Controls.Add(this.lbl_update);
this.Controls.Add(this.btn_queue);
this.Controls.Add(this.btn_encode);
@@ -1893,6 +1906,7 @@ namespace Handbrake internal System.Windows.Forms.Label Version;
private System.Windows.Forms.Label lbl_chptWarn;
internal System.Windows.Forms.SaveFileDialog DVD_Save;
+ private System.Windows.Forms.Label tempEncodeLbl;
}
}
\ No newline at end of file diff --git a/win/C#/frmMain.cs b/win/C#/frmMain.cs index e050a403e..b2dba365a 100644 --- a/win/C#/frmMain.cs +++ b/win/C#/frmMain.cs @@ -598,6 +598,7 @@ namespace Handbrake private void btn_encode_Click(object sender, EventArgs e)
{
String query = "";
+ tempEncodeLbl.Visible = true;
if (QueryEditorText.Text == "")
{
@@ -611,11 +612,31 @@ namespace Handbrake ThreadPool.QueueUserWorkItem(procMonitor, query);
}
+ private void encode_OnEncodeProgress(object Sender, int CurrentTask, int TaskCount, float PercentComplete, float CurrentFps, float AverageFps, TimeSpan TimeRemaining)
+ {
+ if (this.InvokeRequired)
+ {
+ this.BeginInvoke(new Parsing.EncodeProgressEventHandler(encode_OnEncodeProgress),
+ new object[] { Sender, CurrentTask, TaskCount, PercentComplete, CurrentFps, AverageFps, TimeRemaining });
+ return;
+ }
+ tempEncodeLbl.Text = string.Format("Encode Progress: {0}%", PercentComplete);
+ }
+
private void procMonitor(object state)
{
Functions.CLI process = new Functions.CLI();
- hbProc = process.runCli(this, (string)state, false, false, false, false);
- MessageBox.Show("The encode process has now started.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
+ hbProc = process.runCli(this, (string)state, true, true, false, true);
+
+ Parsing.Parser encode = new Parsing.Parser(hbProc.StandardError.BaseStream);
+ //TODO: prevent this event from being subscribed more than once
+ encode.OnEncodeProgress += encode_OnEncodeProgress;
+ while (!encode.EndOfStream)
+ {
+ encode.ReadLine();
+ }
+
+ MessageBox.Show("The ncode process has now started.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
hbProc.WaitForExit();
hbProc.Close();
hbProc.Dispose();
diff --git a/win/C#/frmReadDVD.cs b/win/C#/frmReadDVD.cs index f969f9789..231064f66 100644 --- a/win/C#/frmReadDVD.cs +++ b/win/C#/frmReadDVD.cs @@ -27,7 +27,6 @@ namespace Handbrake this.inputFile = inputFile;
this.mainWindow = parent;
this.dvdInfo = dvdInfoWindow;
- Parsing.Parser.OnScanProgress += Parser_OnScanProgress;
}
private void btn_ok_Click(object sender, EventArgs e)
@@ -65,6 +64,9 @@ namespace Handbrake hbProc = process.runCli(this, query, true, true, false, true);
Parsing.Parser readData = new Parsing.Parser(hbProc.StandardError.BaseStream);
+ readData.OnScanProgress += Parser_OnScanProgress;
+ readData.OnReadLine += dvdInfo.HandleParsedData;
+ readData.OnReadToEnd += dvdInfo.HandleParsedData;
hbProc.Close();
// Setup the parser
|