X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=win%2FC%23%2FfrmPreview.cs;h=14080bd4851cbd6a76ff50194584ddd6773d2c2b;hb=55b0015a8c50106e553bc2f48336cc2a1c495459;hp=0951f34a7877504241db089060aea6ed4df5fbf9;hpb=09f854c0f5519faa2cc67f364ee747888d948d24;p=handbrake-jp%2Fhandbrake-jp-git.git diff --git a/win/C#/frmPreview.cs b/win/C#/frmPreview.cs index 0951f34a..14080bd4 100644 --- a/win/C#/frmPreview.cs +++ b/win/C#/frmPreview.cs @@ -1,4 +1,9 @@ -namespace Handbrake +/* frmPreview.cs $ + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +namespace Handbrake { using System; using System.Diagnostics; @@ -10,17 +15,17 @@ using QTOControlLib; using QTOLibrary; using Services; + using Parsing; public partial class frmPreview : Form { - private readonly Queue Process = new Queue(); - - private delegate void UpdateUIHandler(); - private string CurrentlyPlaying = string.Empty; private readonly frmMain MainWindow; private Thread Player; private readonly bool NoQT; + private readonly Queue Process = new Queue(); + private delegate void UpdateUIHandler(); + private bool playWithVLC; public frmPreview(frmMain mw) { @@ -40,13 +45,24 @@ 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 private void btn_playVLC_Click(object sender, EventArgs e) { - lbl_status.Visible = true; + ProgressBarStatus.Visible = true; + ProgressBarStatus.Value = 0; + lbl_encodeStatus.Visible = true; + playWithVLC = true; + try { if (!NoQT) @@ -63,7 +79,7 @@ btn_playQT.Enabled = false; btn_playVLC.Enabled = false; - lbl_status.Text = "Encoding Sample for (VLC) ..."; + this.Text += " (Encoding)"; int duration; int.TryParse(cb_duration.Text, out duration); string query = QueryGenerator.GenerateCliQuery(MainWindow, 3, duration, cb_preview.Text); @@ -72,6 +88,7 @@ private void btn_playQT_Click(object sender, EventArgs e) { + playWithVLC = false; if (NoQT) { MessageBox.Show(this, @@ -87,7 +104,9 @@ } else { - lbl_status.Visible = true; + ProgressBarStatus.Visible = true; + ProgressBarStatus.Value = 0; + lbl_encodeStatus.Visible = true; try { QTControl.URL = string.Empty; @@ -103,7 +122,7 @@ btn_playQT.Enabled = false; btn_playVLC.Enabled = false; - lbl_status.Text = "Encoding Sample for (QT) ..."; + this.Text += " (Encoding)"; int duration; int.TryParse(cb_duration.Text, out duration); string query = QueryGenerator.GenerateCliQuery(MainWindow, 3, duration, cb_preview.Text); @@ -121,6 +140,7 @@ else { Process.CreatePreviewSample((string) state); + if (Process.HbProcess != null) { Process.HbProcess.WaitForExit(); @@ -130,6 +150,34 @@ } } + 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,29 +187,27 @@ BeginInvoke(new UpdateUIHandler(EncodeCompleted)); return; } + + ProgressBarStatus.Visible = false; + lbl_encodeStatus.Visible = false; + if (!NoQT) btn_playQT.Enabled = true; btn_playVLC.Enabled = true; - // Decide which Player to use. - string playerSelection = lbl_status.Text.Contains("QT") ? "QT" : "VLC"; - - lbl_status.Text = "Loading Clip ..."; + this.Text = this.Text.Replace(" (Encoding)", string.Empty); // Get the sample filename if (MainWindow.text_destination.Text != string.Empty) CurrentlyPlaying = MainWindow.text_destination.Text.Replace(".mp4", "_sample.mp4").Replace(".m4v", "_sample.m4v"). Replace(".mkv", "_sample.mkv"); - ; // Play back in QT or VLC - if (playerSelection == "QT") + if (!playWithVLC) Play(); else PlayVLC(); - - lbl_status.Text = string.Empty; } catch (Exception exc) { @@ -181,7 +227,6 @@ { Player = new Thread(OpenMovie) {IsBackground = true}; Player.Start(); - lbl_status.Visible = false; } /// @@ -227,7 +272,6 @@ string args = "\"" + CurrentlyPlaying + "\""; ProcessStartInfo vlc = new ProcessStartInfo(Properties.Settings.Default.VLC_Path, args); System.Diagnostics.Process.Start(vlc); - lbl_status.Text = "VLC will now launch."; } } else @@ -235,7 +279,6 @@ "Unable to find the preview file. Either the file was deleted or the encode failed. Check the activity log for details.", "VLC", MessageBoxButtons.OK, MessageBoxIcon.Warning); } - lbl_status.Visible = false; } /// @@ -275,5 +318,11 @@ } #endregion + + protected override void OnClosing(System.ComponentModel.CancelEventArgs e) + { + Process.EncodeStarted -= Process_EncodeStarted; + base.OnClosing(e); + } } } \ No newline at end of file