--- /dev/null
+/* EncodeProgressEventArgs.cs $\r
+ This file is part of the HandBrake source code.\r
+ Homepage: <http://handbrake.fr>.\r
+ It may be used under the terms of the GNU General Public License. */\r
+\r
+namespace HandBrake.ApplicationServices\r
+{\r
+ using System;\r
+\r
+ /// <summary>\r
+ /// Encode Progress Event Args\r
+ /// </summary>\r
+ public class EncodeProgressEventArgs : EventArgs\r
+ {\r
+ /// <summary>\r
+ /// Gets or sets PercentComplete.\r
+ /// </summary>\r
+ public float PercentComplete { get; set; }\r
+\r
+ /// <summary>\r
+ /// Gets or sets CurrentFrameRate.\r
+ /// </summary>\r
+ public float CurrentFrameRate { get; set; }\r
+\r
+ /// <summary>\r
+ /// Gets or sets AverageFrameRate.\r
+ /// </summary>\r
+ public float AverageFrameRate { get; set; }\r
+\r
+ /// <summary>\r
+ /// Gets or sets EstimatedTimeLeft.\r
+ /// </summary>\r
+ public TimeSpan EstimatedTimeLeft { get; set; }\r
+\r
+ /// <summary>\r
+ /// Gets or sets Task.\r
+ /// </summary>\r
+ public int Task { get; set; }\r
+ }\r
+}\r
<Reference Include="System.Xml" />\r
</ItemGroup>\r
<ItemGroup>\r
+ <Compile Include="EncodeProgressEventArgs.cs" />\r
<Compile Include="frmExceptionWindow.cs">\r
<SubType>Form</SubType>\r
</Compile>\r
\r
using HandBrake.ApplicationServices.Functions;\r
using HandBrake.ApplicationServices.Model;\r
+ using HandBrake.ApplicationServices.Parsing;\r
using HandBrake.ApplicationServices.Properties;\r
using HandBrake.ApplicationServices.Services.Interfaces;\r
\r
/// </summary>\r
private int processID;\r
\r
+ /* Constructor */\r
+\r
+ /// <summary>\r
+ /// Initializes a new instance of the <see cref="Encode"/> class.\r
+ /// </summary>\r
+ public Encode()\r
+ {\r
+ this.EncodeStarted += Encode_EncodeStarted;\r
+ }\r
+\r
+ /* Delegates */\r
+\r
+ /// <summary>\r
+ /// Encode Progess Status\r
+ /// </summary>\r
+ /// <param name="sender">\r
+ /// The sender.\r
+ /// </param>\r
+ /// <param name="e">\r
+ /// The EncodeProgressEventArgs.\r
+ /// </param>\r
+ public delegate void EncodeProgessStatus(object sender, EncodeProgressEventArgs e);\r
+\r
/* Event Handlers */\r
\r
/// <summary>\r
/// </summary>\r
public event EventHandler EncodeEnded;\r
\r
+ /// <summary>\r
+ /// Encode process has progressed\r
+ /// </summary>\r
+ public event EncodeProgessStatus EncodeStatusChanged;\r
+\r
/* Properties */\r
\r
/// <summary>\r
/// Gets or sets The HB Process\r
/// </summary>\r
- public Process HbProcess { get; set; }\r
+ protected Process HbProcess { get; set; }\r
\r
/// <summary>\r
/// Gets a value indicating whether IsEncoding.\r
\r
if (HbProcess != null)\r
this.processHandle = HbProcess.MainWindowHandle; // Set the process Handle\r
- \r
+\r
// Start the Log Monitor\r
windowTimer = new Timer(new TimerCallback(ReadFile), null, 1000, 1000);\r
\r
private void HbProcess_Exited(object sender, EventArgs e)\r
{\r
IsEncoding = false;\r
+\r
+ windowTimer.Dispose();\r
+ ReadFile(null);\r
+\r
+ if (this.EncodeEnded != null)\r
+ this.EncodeEnded(this, new EventArgs());\r
}\r
\r
/// <summary>\r
}\r
\r
/// <summary>\r
- /// Perform an action after an encode. e.g a shutdown, standby, restart etc.\r
- /// </summary>\r
- protected void Finish()\r
- {\r
- if (!IsEncoding)\r
- {\r
- windowTimer.Dispose();\r
- ReadFile(null);\r
- }\r
-\r
- if (this.EncodeEnded != null)\r
- this.EncodeEnded(this, new EventArgs());\r
-\r
- // Growl\r
- if (Settings.Default.growlQueue)\r
- GrowlCommunicator.Notify("Queue Completed", "Put down that cocktail...\nyour Handbrake queue is done.");\r
-\r
- // Do something whent he encode ends.\r
- switch (Settings.Default.CompletionOption)\r
- {\r
- case "Shutdown":\r
- Process.Start("Shutdown", "-s -t 60");\r
- break;\r
- case "Log Off":\r
- Win32.ExitWindowsEx(0, 0);\r
- break;\r
- case "Suspend":\r
- Application.SetSuspendState(PowerState.Suspend, true, true);\r
- break;\r
- case "Hibernate":\r
- Application.SetSuspendState(PowerState.Hibernate, true, true);\r
- break;\r
- case "Lock System":\r
- Win32.LockWorkStation();\r
- break;\r
- case "Quit HandBrake":\r
- Application.Exit();\r
- break;\r
- default:\r
- break;\r
- }\r
- }\r
-\r
- /// <summary>\r
/// Add the CLI Query to the Log File.\r
/// </summary>\r
/// <param name="encJob">\r
logBuffer.AppendLine(e.Data);\r
}\r
}\r
+\r
+ /// <summary>\r
+ /// Encode Started\r
+ /// </summary>\r
+ /// <param name="sender">\r
+ /// The sender.\r
+ /// </param>\r
+ /// <param name="e">\r
+ /// The EventArgs.\r
+ /// </param>\r
+ private void Encode_EncodeStarted(object sender, EventArgs e)\r
+ {\r
+ Thread monitor = new Thread(EncodeMonitor);\r
+ monitor.Start();\r
+ }\r
+\r
+ /// <summary>\r
+ /// Monitor the Job\r
+ /// </summary>\r
+ private void EncodeMonitor()\r
+ {\r
+ try\r
+ {\r
+ Parser encode = new Parser(HbProcess.StandardOutput.BaseStream);\r
+ encode.OnEncodeProgress += EncodeOnEncodeProgress;\r
+ while (!encode.EndOfStream)\r
+ encode.ReadEncodeStatus();\r
+\r
+ // Main.ShowExceptiowWindow("Encode Monitor Stopped", "Stopped");\r
+ }\r
+ catch (Exception exc)\r
+ {\r
+ Main.ShowExceptiowWindow("An Unknown Error has occured", exc.ToString());\r
+ }\r
+ }\r
+\r
+ /// <summary>\r
+ /// Displays the Encode status in the GUI\r
+ /// </summary>\r
+ /// <param name="sender">The sender</param>\r
+ /// <param name="currentTask">The current task</param>\r
+ /// <param name="taskCount">Number of tasks</param>\r
+ /// <param name="percentComplete">Percent complete</param>\r
+ /// <param name="currentFps">Current encode speed in fps</param>\r
+ /// <param name="avg">Avg encode speed</param>\r
+ /// <param name="timeRemaining">Time Left</param>\r
+ private void EncodeOnEncodeProgress(object sender, int currentTask, int taskCount, float percentComplete, float currentFps, float avg, TimeSpan timeRemaining)\r
+ {\r
+ EncodeProgressEventArgs eventArgs = new EncodeProgressEventArgs\r
+ {\r
+ AverageFrameRate = avg,\r
+ CurrentFrameRate = currentFps,\r
+ EstimatedTimeLeft = timeRemaining,\r
+ PercentComplete = percentComplete,\r
+ Task = currentTask\r
+ };\r
+\r
+ if (this.EncodeStatusChanged != null)\r
+ this.EncodeStatusChanged(this, eventArgs);\r
+ }\r
}\r
}
\ No newline at end of file
namespace HandBrake.ApplicationServices.Services.Interfaces\r
{\r
using System;\r
- using System.Diagnostics;\r
\r
/// <summary>\r
/// The IEncode Interface\r
event EventHandler EncodeEnded;\r
\r
/// <summary>\r
- /// Gets or sets The HB Process\r
+ /// Encode process has progressed\r
/// </summary>\r
- Process HbProcess { get; set; }\r
+ event Encode.EncodeProgessStatus EncodeStatusChanged;\r
\r
/// <summary>\r
/// Gets a value indicating whether IsEncoding.\r
{\r
using System;\r
using System.Collections.ObjectModel;\r
- using System.Diagnostics;\r
\r
using HandBrake.ApplicationServices.Model;\r
\r
/// <summary>\r
/// The IQueue Interface\r
/// </summary>\r
- public interface IQueue\r
+ public interface IQueue : IEncode\r
{\r
/// <summary>\r
/// Fires when the Queue has started\r
int Count { get; }\r
\r
/// <summary>\r
- /// Gets or sets The HB Process\r
- /// </summary>\r
- Process HbProcess { get; set; }\r
-\r
- /// <summary>\r
/// Gets a value indicating whether IsEncoding.\r
/// </summary>\r
bool IsEncoding { get; }\r
/// Requests a pause of the encode queue.\r
/// </summary>\r
void Pause();\r
-\r
- /// <summary>\r
- /// Fires when a new CLI Job starts\r
- /// </summary>\r
- event EventHandler EncodeStarted;\r
-\r
- /// <summary>\r
- /// Fires when a CLI job finishes.\r
- /// </summary>\r
- event EventHandler EncodeEnded;\r
-\r
- /// <summary>\r
- /// Create a preview sample video\r
- /// </summary>\r
- /// <param name="query">\r
- /// The CLI Query\r
- /// </param>\r
- void CreatePreviewSample(string query);\r
-\r
- /// <summary>\r
- /// Kill the CLI process\r
- /// </summary>\r
- void Stop();\r
-\r
- /// <summary>\r
- /// Attempt to Safely kill a DirectRun() CLI\r
- /// NOTE: This will not work with a MinGW CLI\r
- /// Note: http://www.cygwin.com/ml/cygwin/2006-03/msg00330.html\r
- /// </summary>\r
- void SafelyClose();\r
}\r
}
\ No newline at end of file
using System;\r
using System.Collections.Generic;\r
using System.Collections.ObjectModel;\r
+ using System.Diagnostics;\r
using System.IO;\r
using System.Linq;\r
using System.Threading;\r
\r
using HandBrake.ApplicationServices.Functions;\r
using HandBrake.ApplicationServices.Model;\r
+ using HandBrake.ApplicationServices.Properties;\r
using HandBrake.ApplicationServices.Services.Interfaces;\r
\r
/// <summary>\r
/// </summary>\r
private int nextJobId;\r
\r
+ #region Events\r
/// <summary>\r
/// Fires when the Queue has started\r
/// </summary>\r
/// Fires when the entire encode queue has completed.\r
/// </summary>\r
public event EventHandler QueueCompleted;\r
+ #endregion\r
\r
#region Properties\r
/// <summary>\r
Finish();\r
}\r
\r
+ /// <summary>\r
+ /// Perform an action after an encode. e.g a shutdown, standby, restart etc.\r
+ /// </summary>\r
+ private void Finish()\r
+ {\r
+ // Growl\r
+ if (Settings.Default.growlQueue)\r
+ GrowlCommunicator.Notify("Queue Completed", "Put down that cocktail...\nyour Handbrake queue is done.");\r
+\r
+ // Do something whent he encode ends.\r
+ switch (Settings.Default.CompletionOption)\r
+ {\r
+ case "Shutdown":\r
+ Process.Start("Shutdown", "-s -t 60");\r
+ break;\r
+ case "Log Off":\r
+ Win32.ExitWindowsEx(0, 0);\r
+ break;\r
+ case "Suspend":\r
+ Application.SetSuspendState(PowerState.Suspend, true, true);\r
+ break;\r
+ case "Hibernate":\r
+ Application.SetSuspendState(PowerState.Hibernate, true, true);\r
+ break;\r
+ case "Lock System":\r
+ Win32.LockWorkStation();\r
+ break;\r
+ case "Quit HandBrake":\r
+ Application.Exit();\r
+ break;\r
+ default:\r
+ break;\r
+ }\r
+ }\r
+\r
#endregion\r
}\r
}
\ No newline at end of file
private DVD currentSource;\r
private IScan SourceScan = new ScanService();\r
private List<DriveInformation> drives;\r
- private Thread encodeMonitor;\r
\r
// Delegates **********************************************************\r
private delegate void UpdateWindowHandler();\r
private void encodeStarted(object sender, EventArgs e)\r
{\r
SetEncodeStarted();\r
-\r
- // Experimental HBProc Process Monitoring.\r
- if (Properties.Settings.Default.enocdeStatusInGui)\r
- {\r
- encodeMonitor = new Thread(EncodeMonitorThread);\r
- encodeMonitor.Start();\r
- }\r
+ encodeQueue.EncodeStatusChanged += EncodeQueue_EncodeStatusChanged;\r
}\r
\r
private void encodeEnded(object sender, EventArgs e)\r
{\r
+ encodeQueue.EncodeStatusChanged -= EncodeQueue_EncodeStatusChanged;\r
SetEncodeFinished();\r
}\r
\r
private void mnu_UpdateCheck_Click(object sender, EventArgs e)\r
{\r
lbl_updateCheck.Visible = true;\r
- Main.BeginCheckForUpdates(new AsyncCallback(updateCheckDoneMenu), false);\r
+ Main.BeginCheckForUpdates(new AsyncCallback(this.UpdateCheckDoneMenu), false);\r
}\r
\r
/// <summary>\r
!Properties.Settings.Default.showCliForInGuiEncodeStatus)\r
{\r
encodeQueue.Stop();\r
- if (encodeQueue.HbProcess != null)\r
- encodeQueue.HbProcess.WaitForExit();\r
}\r
else\r
{\r
if (overwrite == DialogResult.Yes)\r
{\r
if (encodeQueue.Count == 0)\r
- encodeQueue.Add(query, getTitle(), sourcePath, text_destination.Text, (rtf_query.Text != string.Empty));\r
+ encodeQueue.Add(query, this.GetTitle(), sourcePath, text_destination.Text, (rtf_query.Text != string.Empty));\r
\r
queueWindow.SetQueue();\r
if (encodeQueue.Count > 1)\r
"There is already a queue item for this destination path. \n\n If you continue, the encode will be overwritten. Do you wish to continue?",\r
"Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);\r
if (result == DialogResult.Yes)\r
- encodeQueue.Add(query, getTitle(), sourcePath, text_destination.Text, (rtf_query.Text != string.Empty));\r
+ encodeQueue.Add(query, this.GetTitle(), sourcePath, text_destination.Text, (rtf_query.Text != string.Empty));\r
}\r
else\r
- encodeQueue.Add(query, getTitle(), sourcePath, text_destination.Text, (rtf_query.Text != string.Empty));\r
+ encodeQueue.Add(query, this.GetTitle(), sourcePath, text_destination.Text, (rtf_query.Text != string.Empty));\r
\r
lbl_encode.Text = encodeQueue.Count + " encode(s) pending in the queue";\r
\r
}\r
\r
/// <summary>\r
+ /// Display the Encode Status\r
+ /// </summary>\r
+ /// <param name="sender">\r
+ /// The sender.\r
+ /// </param>\r
+ /// <param name="e">\r
+ /// The e.\r
+ /// </param>\r
+ private void EncodeQueue_EncodeStatusChanged(object sender, HandBrake.ApplicationServices.EncodeProgressEventArgs e)\r
+ {\r
+ if (this.InvokeRequired)\r
+ {\r
+ this.BeginInvoke(new Encode.EncodeProgessStatus(EncodeQueue_EncodeStatusChanged), new[] { sender, e });\r
+ return;\r
+ }\r
+\r
+ lbl_encode.Text =\r
+ string.Format(\r
+ "{0:00.00}%, FPS: {1:000.0}, Avg FPS: {2:000.0}, Time Remaining: {3}",\r
+ e.PercentComplete,\r
+ e.CurrentFrameRate,\r
+ e.AverageFrameRate,\r
+ e.EstimatedTimeLeft);\r
+\r
+ ProgressBarStatus.Value = (int)Math.Round(e.PercentComplete);\r
+ }\r
+\r
+ /// <summary>\r
/// Set the DVD Drive selection in the "Source" Menu\r
/// </summary>\r
private void SetDriveSelectionMenuItem()\r
/// <returns>\r
/// The title.\r
/// </returns>\r
- private int getTitle()\r
+ private int GetTitle()\r
{\r
int title = 0;\r
if (drp_dvdtitle.SelectedItem != null)\r
/// <param name="result">\r
/// The result.\r
/// </param>\r
- private void updateCheckDoneMenu(IAsyncResult result)\r
+ private void UpdateCheckDoneMenu(IAsyncResult result)\r
{\r
// Make sure it's running on the calling thread\r
if (InvokeRequired)\r
{\r
- Invoke(new MethodInvoker(() => updateCheckDoneMenu(result)));\r
+ Invoke(new MethodInvoker(() => this.UpdateCheckDoneMenu(result)));\r
return;\r
}\r
UpdateCheckInformation info;\r
\r
#endregion\r
\r
- #region In-GUI Encode Status\r
-\r
- /// <summary>\r
- /// Starts a new thread to monitor and process the CLI encode status\r
- /// </summary>\r
- private void EncodeMonitorThread()\r
- {\r
- try\r
- {\r
- Parser encode = new Parser(encodeQueue.HbProcess.StandardOutput.BaseStream);\r
- encode.OnEncodeProgress += EncodeOnEncodeProgress;\r
- while (!encode.EndOfStream)\r
- encode.ReadEncodeStatus();\r
-\r
- SetEncodeFinished();\r
- }\r
- catch (Exception exc)\r
- {\r
- MessageBox.Show(exc.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Displays the Encode status in the GUI\r
- /// </summary>\r
- /// <param name="sender">The sender</param>\r
- /// <param name="currentTask">The current task</param>\r
- /// <param name="taskCount">Number of tasks</param>\r
- /// <param name="percentComplete">Percent complete</param>\r
- /// <param name="currentFps">Current encode speed in fps</param>\r
- /// <param name="av">Avg encode speed</param>\r
- /// <param name="timeRemaining">Time Left</param>\r
- private void EncodeOnEncodeProgress(object sender, int currentTask, int taskCount, float percentComplete, float currentFps, float av, TimeSpan timeRemaining)\r
- {\r
- if (this.InvokeRequired)\r
- {\r
- this.BeginInvoke(\r
- new EncodeProgressEventHandler(EncodeOnEncodeProgress),\r
- new[] { sender, currentTask, taskCount, percentComplete, currentFps, av, timeRemaining });\r
- return;\r
- }\r
- lbl_encode.Text =\r
- string.Format(\r
- "{0:00.00}%, FPS: {1:000.0}, Avg FPS: {2:000.0}, Time Remaining: {3}",\r
- percentComplete,\r
- currentFps,\r
- av,\r
- timeRemaining);\r
-\r
- ProgressBarStatus.Value = (int)Math.Round(percentComplete);\r
- }\r
-\r
- #endregion\r
-\r
// This is the END of the road ****************************************\r
}\r
}
\ No newline at end of file
this.btn_playQT.Name = "btn_playQT";\r
this.btn_playQT.Size = new System.Drawing.Size(96, 22);\r
this.btn_playQT.Text = "Play with QT";\r
- this.btn_playQT.Click += new System.EventHandler(this.btn_playQT_Click);\r
+ this.btn_playQT.Click += new System.EventHandler(this.PlayQT_Click);\r
// \r
// btn_playVLC\r
// \r
this.btn_playVLC.Name = "btn_playVLC";\r
this.btn_playVLC.Size = new System.Drawing.Size(101, 22);\r
this.btn_playVLC.Text = "Play with VLC";\r
- this.btn_playVLC.Click += new System.EventHandler(this.btn_playVLC_Click);\r
+ this.btn_playVLC.Click += new System.EventHandler(this.PlayVLC_Click);\r
// \r
// QTControl\r
// \r
using System.Windows.Forms;\r
using Functions;\r
\r
- using HandBrake.ApplicationServices.Parsing;\r
using HandBrake.ApplicationServices.Services;\r
+ using HandBrake.ApplicationServices.Services.Interfaces;\r
\r
using QTOControlLib;\r
using QTOLibrary;\r
\r
+ /// <summary>\r
+ /// The Preview Window\r
+ /// </summary>\r
public partial class frmPreview : Form\r
{\r
- private string CurrentlyPlaying = string.Empty;\r
- private readonly frmMain MainWindow;\r
- private Thread Player;\r
- private readonly bool NoQT;\r
- private readonly Queue Process = new Queue();\r
- private delegate void UpdateUIHandler();\r
+ /// <summary>\r
+ /// The Main Window\r
+ /// </summary>\r
+ private readonly frmMain mainWindow;\r
+\r
+ /// <summary>\r
+ /// True if QT is not installed\r
+ /// </summary>\r
+ private readonly bool noQT;\r
+\r
+ /// <summary>\r
+ /// The encode queue\r
+ /// </summary>\r
+ private readonly IQueue encodeQueue = new Queue();\r
+\r
+ /// <summary>\r
+ /// What is currently playing\r
+ /// </summary>\r
+ private string currentlyPlaying = string.Empty;\r
+\r
+ /// <summary>\r
+ /// Play With VLC tracker\r
+ /// </summary>\r
private bool playWithVLC;\r
\r
+ /// <summary>\r
+ /// A Thread for the video player\r
+ /// </summary>\r
+ private Thread player;\r
+\r
+ /// <summary>\r
+ /// Initializes a new instance of the <see cref="frmPreview"/> class.\r
+ /// </summary>\r
+ /// <param name="mw">\r
+ /// The mw.\r
+ /// </param>\r
public frmPreview(frmMain mw)\r
{\r
try\r
}\r
catch (Exception)\r
{\r
- NoQT = true;\r
+ this.noQT = true;\r
}\r
- this.MainWindow = mw;\r
+ this.mainWindow = mw;\r
cb_preview.SelectedIndex = 0;\r
cb_duration.SelectedIndex = 1;\r
\r
cb_preview.Items.Add(i.ToString());\r
cb_preview.SelectedIndex = 0;\r
\r
- Process.EncodeStarted += new EventHandler(Process_EncodeStarted);\r
+ encodeQueue.EncodeStarted += this.EncodeQueue_EncodeStarted;\r
+ encodeQueue.EncodeEnded += this.EncodeQueue_EncodeEnded;\r
}\r
- private void Process_EncodeStarted(object sender, EventArgs e)\r
+\r
+ /// <summary>\r
+ /// Update UI Delegate\r
+ /// </summary>\r
+ /// <param name="sender">\r
+ /// The sender.\r
+ /// </param>\r
+ /// <param name="e">\r
+ /// The e.\r
+ /// </param>\r
+ private delegate void UpdateUIHandler(object sender, EventArgs e);\r
+\r
+ /// <summary>\r
+ /// The Open Movie Handler\r
+ /// </summary>\r
+ private delegate void OpenMovieHandler();\r
+\r
+ /// <summary>\r
+ /// The encode has started\r
+ /// </summary>\r
+ /// <param name="sender">\r
+ /// The sender.\r
+ /// </param>\r
+ /// <param name="e">\r
+ /// The e.\r
+ /// </param>\r
+ private void EncodeQueue_EncodeStarted(object sender, EventArgs e)\r
{\r
- Thread encodeMon = new Thread(EncodeMonitorThread);\r
- encodeMon.Start();\r
+ encodeQueue.EncodeStatusChanged += this.EncodeQueue_EncodeStatusChanged;\r
+ }\r
+\r
+ /// <summary>\r
+ /// The Enocde has ended\r
+ /// </summary>\r
+ /// <param name="sender">\r
+ /// The sender.\r
+ /// </param>\r
+ /// <param name="e">\r
+ /// The e.\r
+ /// </param>\r
+ private void EncodeQueue_EncodeEnded(object sender, EventArgs e)\r
+ {\r
+ encodeQueue.EncodeStatusChanged -= this.EncodeQueue_EncodeStatusChanged;\r
+\r
+ try\r
+ {\r
+ if (this.InvokeRequired)\r
+ {\r
+ this.BeginInvoke(new UpdateUIHandler(EncodeQueue_EncodeEnded), new[] { sender, e });\r
+ return;\r
+ }\r
+\r
+ ProgressBarStatus.Visible = false;\r
+ lbl_encodeStatus.Visible = false;\r
+\r
+ if (!this.noQT)\r
+ btn_playQT.Enabled = true;\r
+ btn_playVLC.Enabled = true;\r
+\r
+ this.Text = this.Text.Replace(" (Encoding)", string.Empty);\r
+\r
+ // Get the sample filename\r
+ if (this.mainWindow.text_destination.Text != string.Empty)\r
+ this.currentlyPlaying =\r
+ this.mainWindow.text_destination.Text.Replace(".mp4", "_sample.mp4").Replace(".m4v", "_sample.m4v").\r
+ Replace(".mkv", "_sample.mkv");\r
+\r
+ // Play back in QT or VLC\r
+ if (!playWithVLC)\r
+ Play();\r
+ else\r
+ PlayVLC();\r
+ }\r
+ catch (Exception exc)\r
+ {\r
+ Main.ShowExceptiowWindow("An Unexpected error has occured", exc.ToString());\r
+ }\r
+ }\r
+\r
+ /// <summary>\r
+ /// Encode status has changed\r
+ /// </summary>\r
+ /// <param name="sender">\r
+ /// The sender.\r
+ /// </param>\r
+ /// <param name="e">\r
+ /// The e.\r
+ /// </param>\r
+ private void EncodeQueue_EncodeStatusChanged(object sender, HandBrake.ApplicationServices.EncodeProgressEventArgs e)\r
+ {\r
+ if (this.InvokeRequired)\r
+ {\r
+ this.BeginInvoke(new Encode.EncodeProgessStatus(this.EncodeQueue_EncodeStatusChanged), new[] { sender, e });\r
+ return;\r
+ }\r
+\r
+ lbl_encodeStatus.Text = e.PercentComplete + "%";\r
+ ProgressBarStatus.Value = (int)Math.Round(e.PercentComplete);\r
}\r
\r
#region Encode Sample\r
\r
- private void btn_playVLC_Click(object sender, EventArgs e)\r
+ /// <summary>\r
+ /// Play with VLC\r
+ /// </summary>\r
+ /// <param name="sender">\r
+ /// The sender.\r
+ /// </param>\r
+ /// <param name="e">\r
+ /// The e.\r
+ /// </param>\r
+ private void PlayVLC_Click(object sender, EventArgs e)\r
{\r
ProgressBarStatus.Visible = true;\r
ProgressBarStatus.Value = 0;\r
\r
try\r
{\r
- if (!NoQT)\r
+ if (!this.noQT)\r
QTControl.URL = string.Empty;\r
\r
- if (File.Exists(CurrentlyPlaying))\r
- File.Delete(CurrentlyPlaying);\r
+ if (File.Exists(this.currentlyPlaying))\r
+ File.Delete(this.currentlyPlaying);\r
}\r
catch (Exception)\r
{\r
- MessageBox.Show(this, "Unable to delete previous preview file. You may need to restart the application.", \r
+ MessageBox.Show(this, "Unable to delete previous preview file. You may need to restart the application.",\r
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
}\r
\r
this.Text += " (Encoding)";\r
int duration;\r
int.TryParse(cb_duration.Text, out duration);\r
- string query = QueryGenerator.GenerateCliQuery(MainWindow, 3, duration, cb_preview.Text);\r
- ThreadPool.QueueUserWorkItem(ProcMonitor, query);\r
+ string query = QueryGenerator.GenerateCliQuery(this.mainWindow, 3, duration, cb_preview.Text);\r
+ ThreadPool.QueueUserWorkItem(this.CreatePreview, query);\r
}\r
\r
- private void btn_playQT_Click(object sender, EventArgs e)\r
+ /// <summary>\r
+ /// Encode and Play with QT\r
+ /// </summary>\r
+ /// <param name="sender">\r
+ /// The sender.\r
+ /// </param>\r
+ /// <param name="e">\r
+ /// The e.\r
+ /// </param>\r
+ private void PlayQT_Click(object sender, EventArgs e)\r
{\r
playWithVLC = false;\r
- if (NoQT)\r
+ if (this.noQT)\r
{\r
- MessageBox.Show(this, \r
- "It would appear QuickTime 7 is not installed or not accessible. Please (re)install QuickTime.", \r
+ MessageBox.Show(this,\r
+ "It would appear QuickTime 7 is not installed or not accessible. Please (re)install QuickTime.",\r
"Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
return;\r
}\r
- if (MainWindow.text_destination.Text.Contains(".mkv"))\r
+ if (this.mainWindow.text_destination.Text.Contains(".mkv"))\r
{\r
- MessageBox.Show(this, \r
- "The QuickTime Control does not support MKV files, It is recommended you use VLC option instead.", \r
+ MessageBox.Show(this,\r
+ "The QuickTime Control does not support MKV files, It is recommended you use VLC option instead.",\r
"Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
}\r
else\r
try\r
{\r
QTControl.URL = string.Empty;\r
- if (File.Exists(CurrentlyPlaying))\r
- File.Delete(CurrentlyPlaying);\r
+ if (File.Exists(this.currentlyPlaying))\r
+ File.Delete(this.currentlyPlaying);\r
}\r
catch (Exception)\r
{\r
- MessageBox.Show(this, \r
- "Unable to delete previous preview file. You may need to restart the application.", \r
+ MessageBox.Show(this,\r
+ "Unable to delete previous preview file. You may need to restart the application.",\r
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
}\r
\r
this.Text += " (Encoding)";\r
int duration;\r
int.TryParse(cb_duration.Text, out duration);\r
- string query = QueryGenerator.GenerateCliQuery(MainWindow, 3, duration, cb_preview.Text);\r
+ string query = QueryGenerator.GenerateCliQuery(this.mainWindow, 3, duration, cb_preview.Text);\r
\r
- ThreadPool.QueueUserWorkItem(ProcMonitor, query);\r
+ ThreadPool.QueueUserWorkItem(this.CreatePreview, query);\r
}\r
}\r
\r
- private void ProcMonitor(object state)\r
+ /// <summary>\r
+ /// Create the Preview.\r
+ /// </summary>\r
+ /// <param name="state">\r
+ /// The state.\r
+ /// </param>\r
+ private void CreatePreview(object state)\r
{\r
// Make sure we are not already encoding and if we are then display an error.\r
- if (Process.HbProcess != null)\r
- MessageBox.Show(this, "Handbrake is already encoding a video!", "Status", MessageBoxButtons.OK, \r
- MessageBoxIcon.Warning);\r
- else\r
+ if (encodeQueue.IsEncoding)\r
{\r
- Process.CreatePreviewSample((string) state);\r
+ MessageBox.Show(\r
+ this,\r
+ "Handbrake is already encoding a video!",\r
+ "Status",\r
+ MessageBoxButtons.OK,\r
+ MessageBoxIcon.Warning);\r
\r
- if (Process.HbProcess != null)\r
- {\r
- Process.HbProcess.WaitForExit();\r
- Process.HbProcess = null;\r
- }\r
- EncodeCompleted();\r
- }\r
- }\r
-\r
- private void EncodeMonitorThread()\r
- {\r
- try\r
- {\r
- Parser encode = new Parser(Process.HbProcess.StandardOutput.BaseStream);\r
- encode.OnEncodeProgress += EncodeOnEncodeProgress;\r
- while (!encode.EndOfStream)\r
- encode.ReadEncodeStatus();\r
- }\r
- catch (Exception exc)\r
- {\r
- MessageBox.Show(exc.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
- }\r
- }\r
-\r
- private void EncodeOnEncodeProgress(object Sender, int CurrentTask, int TaskCount, float PercentComplete, float CurrentFps, float AverageFps, TimeSpan TimeRemaining)\r
- {\r
- if (this.InvokeRequired)\r
- {\r
- this.BeginInvoke(\r
- new EncodeProgressEventHandler(EncodeOnEncodeProgress),\r
- new[] { Sender, CurrentTask, TaskCount, PercentComplete, CurrentFps, AverageFps, TimeRemaining });\r
return;\r
}\r
- lbl_encodeStatus.Text = PercentComplete + "%";\r
- ProgressBarStatus.Value = (int)Math.Round(PercentComplete);\r
- }\r
-\r
- private void EncodeCompleted()\r
- {\r
- try\r
- {\r
- if (InvokeRequired)\r
- {\r
- BeginInvoke(new UpdateUIHandler(EncodeCompleted));\r
- return;\r
- }\r
-\r
- ProgressBarStatus.Visible = false;\r
- lbl_encodeStatus.Visible = false;\r
\r
- if (!NoQT)\r
- btn_playQT.Enabled = true;\r
- btn_playVLC.Enabled = true;\r
-\r
- this.Text = this.Text.Replace(" (Encoding)", string.Empty);\r
-\r
- // Get the sample filename\r
- if (MainWindow.text_destination.Text != string.Empty)\r
- CurrentlyPlaying =\r
- MainWindow.text_destination.Text.Replace(".mp4", "_sample.mp4").Replace(".m4v", "_sample.m4v").\r
- Replace(".mkv", "_sample.mkv");\r
-\r
- // Play back in QT or VLC\r
- if (!playWithVLC)\r
- Play();\r
- else\r
- PlayVLC();\r
- }\r
- catch (Exception exc)\r
- {\r
- MessageBox.Show(this, "frmPreview.cs EncodeCompleted " + exc, "Error", MessageBoxButtons.OK, \r
- MessageBoxIcon.Error);\r
- }\r
+ encodeQueue.CreatePreviewSample((string)state);\r
}\r
\r
#endregion\r
/// </summary>\r
private void Play()\r
{\r
- Player = new Thread(OpenMovie) {IsBackground = true};\r
- Player.Start();\r
+ this.player = new Thread(OpenMovie) { IsBackground = true };\r
+ this.player.Start();\r
}\r
\r
/// <summary>\r
private void PlayVLC()\r
{\r
// Launch VLC and Play video.\r
- if (CurrentlyPlaying != string.Empty)\r
+ if (this.currentlyPlaying != string.Empty)\r
{\r
- if (File.Exists(CurrentlyPlaying))\r
+ if (File.Exists(this.currentlyPlaying))\r
{\r
// Attempt to find VLC if it doesn't exist in the default set location.\r
string vlcPath;\r
}\r
else\r
{\r
- MessageBox.Show(this, \r
- "Unable to detect VLC Player. \nPlease make sure VLC is installed and the directory specified in HandBrake's options is correct. (See: \"Tools Menu > Options > Picture Tab\") ", \r
+ MessageBox.Show(this,\r
+ "Unable to detect VLC Player. \nPlease make sure VLC is installed and the directory specified in HandBrake's options is correct. (See: \"Tools Menu > Options > Picture Tab\") ",\r
"VLC", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
}\r
}\r
\r
if (File.Exists(Properties.Settings.Default.VLC_Path))\r
{\r
- string args = "\"" + CurrentlyPlaying + "\"";\r
+ string args = "\"" + this.currentlyPlaying + "\"";\r
ProcessStartInfo vlc = new ProcessStartInfo(Properties.Settings.Default.VLC_Path, args);\r
- System.Diagnostics.Process.Start(vlc);\r
+ Process.Start(vlc);\r
}\r
}\r
else\r
- MessageBox.Show(this, \r
- "Unable to find the preview file. Either the file was deleted or the encode failed. Check the activity log for details.", \r
+ MessageBox.Show(this,\r
+ "Unable to find the preview file. Either the file was deleted or the encode failed. Check the activity log for details.",\r
"VLC", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
}\r
}\r
{\r
if (InvokeRequired)\r
{\r
- BeginInvoke(new UpdateUIHandler(OpenMovie));\r
+ BeginInvoke(new OpenMovieHandler(OpenMovie));\r
return;\r
}\r
- QTControl.URL = CurrentlyPlaying;\r
+ QTControl.URL = this.currentlyPlaying;\r
QTControl.SetSizing(QTSizingModeEnum.qtControlFitsMovie, true);\r
- QTControl.URL = CurrentlyPlaying;\r
+ QTControl.URL = this.currentlyPlaying;\r
QTControl.Show();\r
\r
this.ClientSize = QTControl.Size;\r
catch (COMException ex)\r
{\r
QTUtils qtu = new QTUtils();\r
- MessageBox.Show(this, \r
- "Unable to open movie:\n\nError Code: " + ex.ErrorCode.ToString("X") +\r
- "\nQT Error code : " + qtu.QTErrorFromErrorCode(ex.ErrorCode), "QT", \r
- MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
+ Main.ShowExceptiowWindow("Unable to open movie.", ex + Environment.NewLine + qtu.QTErrorFromErrorCode(ex.ErrorCode));\r
}\r
catch (Exception ex)\r
{\r
- MessageBox.Show(this, "Unable to open movie:\n\n" + ex, "QT", MessageBoxButtons.OK, \r
- MessageBoxIcon.Warning);\r
+ Main.ShowExceptiowWindow("Unable to open movie.", ex.ToString());\r
}\r
}\r
\r
#endregion\r
\r
+ /// <summary>\r
+ /// Remove any subscribed events then close.\r
+ /// </summary>\r
+ /// <param name="e">\r
+ /// The e.\r
+ /// </param>\r
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)\r
{\r
- Process.EncodeStarted -= Process_EncodeStarted;\r
+ encodeQueue.EncodeStarted -= this.EncodeQueue_EncodeStarted;\r
+ encodeQueue.EncodeEnded -= this.EncodeQueue_EncodeEnded;\r
base.OnClosing(e);\r
}\r
}\r