summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsr55 <[email protected]>2010-05-19 19:22:01 +0000
committersr55 <[email protected]>2010-05-19 19:22:01 +0000
commit7fda78b54bdc920653ca3d9d2da0be56712c0a77 (patch)
treeac5755fe215be6af02aef38d2e052a86c9fc2736
parentc80ba825d496edc98e2c4129896598e96b56a0d9 (diff)
WinGui:
- Fix ingui encode status. - Preview window now has a progress bar indicating encode status. CLI window no longer pops up during the encode. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@3306 b64f7644-9d1e-0410-96f1-a4d463321fa5
-rw-r--r--win/C#/Services/Encode.cs61
-rw-r--r--win/C#/Services/Queue.cs2
-rw-r--r--win/C#/frmPreview.Designer.cs29
-rw-r--r--win/C#/frmPreview.cs59
4 files changed, 115 insertions, 36 deletions
diff --git a/win/C#/Services/Encode.cs b/win/C#/Services/Encode.cs
index 677c62c62..a6da85026 100644
--- a/win/C#/Services/Encode.cs
+++ b/win/C#/Services/Encode.cs
@@ -104,7 +104,7 @@ namespace Handbrake.Services
/// </param>
public void CreatePreviewSample(string query)
{
- this.Run(new Job { Query = query });
+ this.Run(new Job { Query = query }, true);
}
/// <summary>
@@ -148,82 +148,77 @@ namespace Handbrake.Services
/// <param name="encJob">
/// The enc Job.
/// </param>
- protected void Run(Job encJob)
+ /// <param name="RequireStandardOuput">
+ /// Set to True to show no window and force standard output redirect
+ /// </param>
+ protected void Run(Job encJob, bool RequireStandardOuput)
{
this.job = encJob;
try
{
ResetLogReader();
-
- if (this.EncodeStarted != null)
- this.EncodeStarted(this, new EventArgs());
-
IsEncoding = true;
string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe");
- string logPath =
- Path.Combine(
- Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs",
- "last_encode_log.txt");
- string strCmdLine = String.Format(@" /C """"{0}"" {1} 2>""{2}"" """, handbrakeCLIPath, encJob.Query,
- logPath);
+ string logPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs", "last_encode_log.txt");
+ string strCmdLine = String.Format(@" /C """"{0}"" {1} 2>""{2}"" """, handbrakeCLIPath, encJob.Query, logPath);
var cliStart = new ProcessStartInfo("CMD.exe", strCmdLine);
- if (Settings.Default.enocdeStatusInGui)
+ if (Settings.Default.enocdeStatusInGui || RequireStandardOuput)
{
cliStart.RedirectStandardOutput = true;
cliStart.UseShellExecute = false;
- if (!Settings.Default.showCliForInGuiEncodeStatus)
+ if (!Settings.Default.showCliForInGuiEncodeStatus || RequireStandardOuput)
cliStart.CreateNoWindow = true;
}
if (Settings.Default.cli_minimized)
cliStart.WindowStyle = ProcessWindowStyle.Minimized;
Process[] before = Process.GetProcesses(); // Get a list of running processes before starting.
- Process startProcess = Process.Start(cliStart);
-
+ HbProcess = Process.Start(cliStart);
this.processID = Main.GetCliProcess(before);
- // Fire the Encode Started Event
- if (this.EncodeStarted != null)
- this.EncodeStarted(this, new EventArgs());
-
- if (startProcess != null)
- this.processHandle = startProcess.MainWindowHandle; // Set the process Handle
-
+ if (HbProcess != null)
+ this.processHandle = HbProcess.MainWindowHandle; // Set the process Handle
+
// Start the Log Monitor
windowTimer = new Timer(new TimerCallback(ReadFile), null, 1000, 1000);
// Set the process Priority
+ Process hbCliProcess = null;
if (this.processID != -1)
{
- HbProcess = Process.GetProcessById(this.processID);
- HbProcess.EnableRaisingEvents = true;
- HbProcess.Exited += new EventHandler(HbProcess_Exited);
+ hbCliProcess = Process.GetProcessById(this.processID);
+ hbCliProcess.EnableRaisingEvents = true;
+ hbCliProcess.Exited += new EventHandler(HbProcess_Exited);
}
- if (HbProcess != null)
+ if (hbCliProcess != null)
switch (Settings.Default.processPriority)
{
case "Realtime":
- HbProcess.PriorityClass = ProcessPriorityClass.RealTime;
+ hbCliProcess.PriorityClass = ProcessPriorityClass.RealTime;
break;
case "High":
- HbProcess.PriorityClass = ProcessPriorityClass.High;
+ hbCliProcess.PriorityClass = ProcessPriorityClass.High;
break;
case "Above Normal":
- HbProcess.PriorityClass = ProcessPriorityClass.AboveNormal;
+ hbCliProcess.PriorityClass = ProcessPriorityClass.AboveNormal;
break;
case "Normal":
- HbProcess.PriorityClass = ProcessPriorityClass.Normal;
+ hbCliProcess.PriorityClass = ProcessPriorityClass.Normal;
break;
case "Low":
- HbProcess.PriorityClass = ProcessPriorityClass.Idle;
+ hbCliProcess.PriorityClass = ProcessPriorityClass.Idle;
break;
default:
- HbProcess.PriorityClass = ProcessPriorityClass.BelowNormal;
+ hbCliProcess.PriorityClass = ProcessPriorityClass.BelowNormal;
break;
}
+
+ // Fire the Encode Started Event
+ if (this.EncodeStarted != null)
+ this.EncodeStarted(this, new EventArgs());
}
catch (Exception exc)
{
diff --git a/win/C#/Services/Queue.cs b/win/C#/Services/Queue.cs
index 39437fcbc..695b585d6 100644
--- a/win/C#/Services/Queue.cs
+++ b/win/C#/Services/Queue.cs
@@ -350,7 +350,7 @@ namespace Handbrake.Services
Job encJob = this.GetNextJob();
this.WriteQueueStateToFile("hb_queue_recovery.xml"); // Update the queue recovery file
- Run(encJob);
+ Run(encJob, false);
if (HbProcess == null)
{
diff --git a/win/C#/frmPreview.Designer.cs b/win/C#/frmPreview.Designer.cs
index 086819348..2816e0016 100644
--- a/win/C#/frmPreview.Designer.cs
+++ b/win/C#/frmPreview.Designer.cs
@@ -42,6 +42,9 @@
this.QTControl = new AxQTOControlLib.AxQTControl();
this.panel1 = new System.Windows.Forms.Panel();
this.lbl_status = new System.Windows.Forms.Label();
+ this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
+ this.ProgressBarStatus = new System.Windows.Forms.ToolStripProgressBar();
+ this.lbl_encodeStatus = new System.Windows.Forms.ToolStripLabel();
this.toolBar.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.QTControl)).BeginInit();
this.panel1.SuspendLayout();
@@ -56,7 +59,10 @@
this.toolStripLabel2,
this.cb_duration,
this.btn_playQT,
- this.btn_playVLC});
+ this.btn_playVLC,
+ this.toolStripSeparator1,
+ this.ProgressBarStatus,
+ this.lbl_encodeStatus});
this.toolBar.Location = new System.Drawing.Point(0, 0);
this.toolBar.Name = "toolBar";
this.toolBar.RenderMode = System.Windows.Forms.ToolStripRenderMode.Professional;
@@ -175,6 +181,24 @@
this.lbl_status.Text = "{0}";
this.lbl_status.Visible = false;
//
+ // toolStripSeparator1
+ //
+ this.toolStripSeparator1.Name = "toolStripSeparator1";
+ this.toolStripSeparator1.Size = new System.Drawing.Size(6, 25);
+ //
+ // ProgressBarStatus
+ //
+ this.ProgressBarStatus.Name = "ProgressBarStatus";
+ this.ProgressBarStatus.Size = new System.Drawing.Size(100, 22);
+ this.ProgressBarStatus.Visible = false;
+ //
+ // lbl_encodeStatus
+ //
+ this.lbl_encodeStatus.Name = "lbl_encodeStatus";
+ this.lbl_encodeStatus.Size = new System.Drawing.Size(38, 22);
+ this.lbl_encodeStatus.Text = "0.00%";
+ this.lbl_encodeStatus.Visible = false;
+ //
// frmPreview
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -210,5 +234,8 @@
private System.Windows.Forms.ToolStripButton btn_playVLC;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Label lbl_status;
+ private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
+ private System.Windows.Forms.ToolStripProgressBar ProgressBarStatus;
+ private System.Windows.Forms.ToolStripLabel lbl_encodeStatus;
}
} \ No newline at end of file
diff --git a/win/C#/frmPreview.cs b/win/C#/frmPreview.cs
index 0951f34a7..03b569883 100644
--- a/win/C#/frmPreview.cs
+++ b/win/C#/frmPreview.cs
@@ -1,4 +1,6 @@
-namespace Handbrake
+using Handbrake.Parsing;
+
+namespace Handbrake
{
using System;
using System.Diagnostics;
@@ -40,6 +42,14 @@
for (int i = 1; i <= Properties.Settings.Default.previewScanCount; i++)
cb_preview.Items.Add(i.ToString());
cb_preview.SelectedIndex = 0;
+
+ Process.EncodeStarted += new EventHandler(Process_EncodeStarted);
+ }
+
+ private void Process_EncodeStarted(object sender, EventArgs e)
+ {
+ Thread encodeMon = new Thread(EncodeMonitorThread);
+ encodeMon.Start();
}
#region Encode Sample
@@ -47,6 +57,10 @@
private void btn_playVLC_Click(object sender, EventArgs e)
{
lbl_status.Visible = true;
+ ProgressBarStatus.Visible = true;
+ ProgressBarStatus.Value = 0;
+ lbl_encodeStatus.Visible = true;
+
try
{
if (!NoQT)
@@ -88,6 +102,9 @@
else
{
lbl_status.Visible = true;
+ ProgressBarStatus.Visible = true;
+ ProgressBarStatus.Value = 0;
+ lbl_encodeStatus.Visible = true;
try
{
QTControl.URL = string.Empty;
@@ -121,6 +138,7 @@
else
{
Process.CreatePreviewSample((string) state);
+
if (Process.HbProcess != null)
{
Process.HbProcess.WaitForExit();
@@ -130,6 +148,35 @@
}
}
+ private void EncodeMonitorThread()
+ {
+ try
+ {
+ Parser encode = new Parser(Process.HbProcess.StandardOutput.BaseStream);
+ encode.OnEncodeProgress += EncodeOnEncodeProgress;
+ while (!encode.EndOfStream)
+ encode.ReadEncodeStatus();
+ }
+ catch (Exception exc)
+ {
+ MessageBox.Show(exc.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private void EncodeOnEncodeProgress(object Sender, int CurrentTask, int TaskCount, float PercentComplete, float CurrentFps, float AverageFps, TimeSpan TimeRemaining)
+ {
+ if (this.InvokeRequired)
+ {
+ this.BeginInvoke(
+ new EncodeProgressEventHandler(EncodeOnEncodeProgress),
+ new[] { Sender, CurrentTask, TaskCount, PercentComplete, CurrentFps, AverageFps, TimeRemaining });
+ return;
+ }
+ lbl_encodeStatus.Text = PercentComplete + "%";
+ ProgressBarStatus.Value = (int)Math.Round(PercentComplete);
+ }
+
+
private void EncodeCompleted()
{
try
@@ -139,6 +186,10 @@
BeginInvoke(new UpdateUIHandler(EncodeCompleted));
return;
}
+
+ ProgressBarStatus.Visible = false;
+ lbl_encodeStatus.Visible = false;
+
if (!NoQT)
btn_playQT.Enabled = true;
btn_playVLC.Enabled = true;
@@ -275,5 +326,11 @@
}
#endregion
+
+ protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
+ {
+ Process.EncodeStarted -= Process_EncodeStarted;
+ base.OnClosing(e);
+ }
}
} \ No newline at end of file