OSDN Git Service

WinGui:
authorbrianmario <brianmario@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Thu, 19 Jul 2007 05:13:50 +0000 (05:13 +0000)
committerbrianmario <brianmario@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Thu, 19 Jul 2007 05:13:50 +0000 (05:13 +0000)
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

win/C#/CLI/Jobs/Encode.cs
win/C#/CLI/Jobs/Job.cs
win/C#/CLI/Jobs/ParseDVD.cs
win/C#/Parsing/Parser.cs
win/C#/frmDvdInfo.cs
win/C#/frmMain.Designer.cs
win/C#/frmMain.cs
win/C#/frmReadDVD.cs

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