From: brianmario Date: Thu, 19 Jul 2007 05:13:50 +0000 (+0000) Subject: WinGui: X-Git-Url: http://git.osdn.jp/view?a=commitdiff_plain;h=d17a20014ed86bbb98149a8626515fac765064ea;p=handbrake-jp%2Fhandbrake-jp-git.git WinGui: updated parsing code events to not be static anymore added encode parsing to catch encode progress added OnEncodeProgress event git-svn-id: svn://localhost/HandBrake/trunk@717 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- diff --git a/win/C#/CLI/Jobs/Encode.cs b/win/C#/CLI/Jobs/Encode.cs index e0967385..ed537b51 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 f1c02c35..454bb21c 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; - /// - /// The base process associated with this job - /// - 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 d902fc35..a56a28d6 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 afd5471d..f56999a0 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); /// + /// A delegate to handle encode progress updates + /// + /// The object which raised the event + /// The current task being processed from the queue + /// The total number of tasks in queue + /// The percentage this task is complete + /// The current encoding fps + /// The average encoding fps for this task + /// The estimated time remaining for this task to complete + public delegate void EncodeProgressEventHandler(object Sender, int CurrentTask, int TaskCount, float PercentComplete, float CurrentFps, float AverageFps, TimeSpan TimeRemaining); + + /// /// A simple wrapper around a StreamReader to keep track of the entire output from a cli process /// internal class Parser : StreamReader @@ -41,17 +53,19 @@ namespace Handbrake.Parsing /// /// Raised upon a new line being read from stdout/stderr /// - public static event DataReadEventHandler OnReadLine; + public event DataReadEventHandler OnReadLine; /// /// Raised upon the entire stdout/stderr stream being read in a single call /// - public static event DataReadEventHandler OnReadToEnd; + public event DataReadEventHandler OnReadToEnd; /// /// Raised upon the catching of a "Scanning title # of #..." in the stream /// - public static event ScanProgressEventHandler OnScanProgress; + public event ScanProgressEventHandler OnScanProgress; + + public event EncodeProgressEventHandler OnEncodeProgress; /// /// 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 7d58cb14..06ca5993 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 59c864c2..3d6431f5 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 e050a403..b2dba365 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 f969f978..231064f6 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