From 4ecb7b2c297ba7e87c0a9ab8e0768d45fc4f0810 Mon Sep 17 00:00:00 2001 From: sr55 Date: Fri, 11 Jun 2010 18:57:37 +0000 Subject: 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 --- .../Services/Encode.cs | 143 ++++++++++++++------- 1 file changed, 97 insertions(+), 46 deletions(-) (limited to 'win/C#/HandBrake.ApplicationServices/Services/Encode.cs') 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 /// private int processID; + /* Constructor */ + + /// + /// Initializes a new instance of the class. + /// + public Encode() + { + this.EncodeStarted += Encode_EncodeStarted; + } + + /* Delegates */ + + /// + /// Encode Progess Status + /// + /// + /// The sender. + /// + /// + /// The EncodeProgressEventArgs. + /// + public delegate void EncodeProgessStatus(object sender, EncodeProgressEventArgs e); + /* Event Handlers */ /// @@ -68,12 +92,17 @@ namespace HandBrake.ApplicationServices.Services /// public event EventHandler EncodeEnded; + /// + /// Encode process has progressed + /// + public event EncodeProgessStatus EncodeStatusChanged; + /* Properties */ /// /// Gets or sets The HB Process /// - public Process HbProcess { get; set; } + protected Process HbProcess { get; set; } /// /// 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()); } /// @@ -323,50 +358,6 @@ namespace HandBrake.ApplicationServices.Services } } - /// - /// Perform an action after an encode. e.g a shutdown, standby, restart etc. - /// - 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; - } - } - /// /// Add the CLI Query to the Log File. /// @@ -550,5 +541,65 @@ namespace HandBrake.ApplicationServices.Services logBuffer.AppendLine(e.Data); } } + + /// + /// Encode Started + /// + /// + /// The sender. + /// + /// + /// The EventArgs. + /// + private void Encode_EncodeStarted(object sender, EventArgs e) + { + Thread monitor = new Thread(EncodeMonitor); + monitor.Start(); + } + + /// + /// Monitor the Job + /// + 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()); + } + } + + /// + /// Displays the Encode status in the GUI + /// + /// The sender + /// The current task + /// Number of tasks + /// Percent complete + /// Current encode speed in fps + /// Avg encode speed + /// Time Left + 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 -- cgit v1.2.3