From 7129aebff7254512f7319b059c507db6f9c77ca2 Mon Sep 17 00:00:00 2001 From: sr55 Date: Sun, 11 Sep 2011 17:18:41 +0000 Subject: WinGui: Some further work to enable libhb encode support. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4218 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- win/CS/Controls/Filters.cs | 115 ++++++++++++ win/CS/Controls/Subtitles.cs | 12 ++ win/CS/Functions/QueryGenerator.cs | 209 ++++++++++++++++++++- .../Model/EncodeTask.cs | 10 + .../HandBrake.ApplicationServices/Model/Preset.cs | 5 - .../Model/QueueTask.cs | 22 +-- win/CS/frmMain.cs | 48 ++--- 7 files changed, 359 insertions(+), 62 deletions(-) (limited to 'win') diff --git a/win/CS/Controls/Filters.cs b/win/CS/Controls/Filters.cs index e4c9bf226..698077f35 100644 --- a/win/CS/Controls/Filters.cs +++ b/win/CS/Controls/Filters.cs @@ -8,6 +8,7 @@ namespace Handbrake.Controls using System; using System.Windows.Forms; + using HandBrake.ApplicationServices.Functions; using HandBrake.ApplicationServices.Model.Encoding; using HandBrake.Interop.Model.Encoding; @@ -34,6 +35,120 @@ namespace Handbrake.Controls drop_detelecine.SelectedIndex = 0; } + #region Properties + + /// + /// Gets Decomb. + /// + public Decomb Decomb + { + get + { + return EnumHelper.GetValue(drop_decomb.Text); + } + } + + /// + /// Gets CustomDecombValue. + /// + public string CustomDecombValue + { + get + { + return text_customDC.Text; + } + } + + /// + /// Gets Deinterlace. + /// + public Deinterlace Deinterlace + { + get + { + return EnumHelper.GetValue(drop_deinterlace.Text); + } + } + + /// + /// Gets CustomDeInterlaceValue. + /// + public string CustomDeInterlaceValue + { + get + { + return text_customDI.Text; + } + } + + /// + /// Gets Detelecine. + /// + public Detelecine Detelecine + { + get + { + return EnumHelper.GetValue(drop_detelecine.Text); + } + } + + /// + /// Gets CustomDeTelecineValue. + /// + public string CustomDeTelecineValue + { + get + { + return text_customDT.Text; + } + } + + /// + /// Gets Denoise. + /// + public Denoise Denoise + { + get + { + return EnumHelper.GetValue(drop_denoise.Text); + } + } + + /// + /// Gets CustomDenoiseValue. + /// + public string CustomDenoiseValue + { + get + { + return text_customDN.Text; + } + } + + /// + /// Gets Deblock. + /// + public int Deblock + { + get + { + return slider_deblock.Value; + } + } + + /// + /// Gets a value indicating whether GrayScale. + /// + public bool GrayScale + { + get + { + return check_grayscale.Checked; + } + } + + #endregion + /// /// Gets the CLI query for the query generator. /// diff --git a/win/CS/Controls/Subtitles.cs b/win/CS/Controls/Subtitles.cs index 35b05aa26..654c99fdc 100644 --- a/win/CS/Controls/Subtitles.cs +++ b/win/CS/Controls/Subtitles.cs @@ -9,6 +9,7 @@ namespace Handbrake.Controls using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; + using System.ComponentModel; using System.IO; using System.Linq; using System.Windows.Forms; @@ -62,6 +63,17 @@ namespace Handbrake.Controls srt_lang.SelectedIndex = 40; } + /// + /// Gets SubtitlesList. + /// + public List SubtitlesList + { + get + { + return subList; + } + } + #region Public Methods /// /// Gets the CLI Query for this panel diff --git a/win/CS/Functions/QueryGenerator.cs b/win/CS/Functions/QueryGenerator.cs index 881188da7..ac5947ba6 100644 --- a/win/CS/Functions/QueryGenerator.cs +++ b/win/CS/Functions/QueryGenerator.cs @@ -14,12 +14,16 @@ namespace Handbrake.Functions using HandBrake.ApplicationServices; using HandBrake.ApplicationServices.Functions; + using HandBrake.ApplicationServices.Model; using HandBrake.ApplicationServices.Model.Encoding; using HandBrake.ApplicationServices.Services; using HandBrake.ApplicationServices.Services.Interfaces; + using HandBrake.Interop.Model; + using HandBrake.Interop.Model.Encoding; using Handbrake.Model; + using OutputFormat = HandBrake.ApplicationServices.Model.Encoding.OutputFormat; using UserSettingConstants = Handbrake.UserSettingConstants; /// @@ -56,17 +60,34 @@ namespace Handbrake.Functions return query; } - public static string GenerateFullQuery(frmMain mainWindow) + public static QueueTask GenerateFullQuery(frmMain mainWindow) { + // Create the CLI Query string query = string.Empty; - query += SourceQuery(mainWindow, mainWindow.drop_mode.SelectedIndex, 0, null); - query += DestinationQuery(mainWindow, QueryEncodeMode.Standard); - query += GenerateTabbedComponentsQuery(mainWindow, true, QueryPictureSettingsMode.UserInterfaceSettings, 0, 0); - return query; + // Create the Queue Task and setup the EncodeTask model object. + Preset preset = mainWindow.treeView_presets.SelectedNode.Tag as Preset; + bool isCustom = true; + if (preset != null && preset.IsBuildIn) + { + isCustom = false; + } + + EncodeTask task = CreateEncodeTaskObject(mainWindow); + QueueTask queueTask = new QueueTask(query) + { + Source = task.Source, + Destination = task.Destination, + Title = mainWindow.GetTitle(), + CustomQuery = (mainWindow.rtf_query.Text != string.Empty) || isCustom, + Task = task, + Query = query, + }; + + return queueTask; } #region Individual Query Sections @@ -527,6 +548,184 @@ namespace Handbrake.Functions #endregion + #region EncodeTask + + /// + /// Create the EncodeTask model from the currently selected control options. + /// + /// + /// The frm main. + /// + /// + /// An EncodeTask Object + /// + private static EncodeTask CreateEncodeTaskObject(frmMain frmMain) + { + EncodeTask task = new EncodeTask(); + + // Source, Destination and Output Settings + task.Destination = frmMain.text_destination.Text; + string sourcePath = frmMain.selectedTitle != null && File.Exists(frmMain.selectedTitle.SourceName) + ? frmMain.selectedTitle.SourceName.Trim() + : frmMain.sourcePath; + if (!string.IsNullOrEmpty(sourcePath) && sourcePath.Trim() != "Select \"Source\" to continue") + { + task.Source = sourcePath; + } + + if (frmMain.drp_dvdtitle.Text != string.Empty) + { + string[] titleInfo = frmMain.drp_dvdtitle.Text.Split(' '); + int title; + int.TryParse(titleInfo[0], out title); + task.Title = title; + } + + + int start, end, angle; + int.TryParse(frmMain.drop_chapterStart.Text, out start); + int.TryParse(frmMain.drop_chapterFinish.Text, out end); + int.TryParse(frmMain.drop_angle.Text, out angle); + task.StartPoint = start; + task.EndPoint = end; + task.Angle = angle; + + switch (frmMain.drop_mode.SelectedIndex) + { + case 0: // Chapters + task.PointToPointMode = PointToPointMode.Chapters; + break; + case 1: // Seconds + task.PointToPointMode = PointToPointMode.Seconds; + break; + case 2: // Frames + task.PointToPointMode = PointToPointMode.Frames; + break; + default: + break; + } + + task.OutputFormat = EnumHelper.GetValue(frmMain.drop_format.Text.Replace(" File", string.Empty).Trim()); + task.LargeFile = frmMain.check_largeFile.Checked; + task.IPod5GSupport = frmMain.check_largeFile.Checked; + task.OptimizeMP4 = frmMain.check_optimiseMP4.Checked; + + // Picture Settings + int width, height; + int.TryParse(frmMain.PictureSettings.crop_top.Text, out width); + int.TryParse(frmMain.PictureSettings.crop_top.Text, out height); + task.Width = width; + task.Height = height; + int top, bottom, left, right; + int.TryParse(frmMain.PictureSettings.crop_top.Text, out top); + int.TryParse(frmMain.PictureSettings.crop_top.Text, out bottom); + int.TryParse(frmMain.PictureSettings.crop_top.Text, out left); + int.TryParse(frmMain.PictureSettings.crop_top.Text, out right); + task.Cropping = new Cropping(top, bottom, left, right); + + int modulus, displayWidth, parX, parY; + int.TryParse(frmMain.PictureSettings.drp_modulus.SelectedItem.ToString(), out modulus); + int.TryParse(frmMain.PictureSettings.updownDisplayWidth.Text, out displayWidth); + int.TryParse(frmMain.PictureSettings.updownParWidth.Text, out parX); + int.TryParse(frmMain.PictureSettings.updownParHeight.Text, out parY); + switch (frmMain.PictureSettings.drp_anamorphic.SelectedIndex) + { + case 0: + task.Anamorphic = Anamorphic.None; + task.Modulus = modulus; + break; + case 1: + task.Anamorphic = Anamorphic.Strict; + break; + case 2: + task.Anamorphic = Anamorphic.Loose; + task.Modulus = modulus; + break; + case 3: + task.Anamorphic = Anamorphic.Custom; + task.Modulus = modulus; + task.DisplayWidth = displayWidth; + task.KeepDisplayAspect = frmMain.PictureSettings.check_KeepAR.Checked; + task.PixelAspectX = parX; + task.PixelAspectY = parY; + break; + } + + // Filter Settings + task.Deblock = frmMain.Filters.Deblock; + task.Decomb = frmMain.Filters.Decomb; + task.CustomDecomb = frmMain.Filters.CustomDecombValue; + task.Deinterlace = frmMain.Filters.Deinterlace; + task.CustomDeinterlace = frmMain.Filters.CustomDeInterlaceValue; + task.Deblock = frmMain.Filters.Deblock; + task.Denoise = frmMain.Filters.Denoise; + task.CustomDenoise = frmMain.Filters.CustomDenoiseValue; + task.Detelecine = frmMain.Filters.Detelecine; + task.CustomDetelecine = frmMain.Filters.CustomDeTelecineValue; + task.Grayscale = frmMain.Filters.GrayScale; + + // Video Settings + task.VideoEncoder = EnumHelper.GetValue(frmMain.drp_videoEncoder.Text); + int videoBitrate; + int.TryParse(frmMain.text_bitrate.Text, out videoBitrate); + task.VideoBitrate = videoBitrate; + task.VideoEncodeRateType = frmMain.radio_cq.Checked + ? VideoEncodeRateType.ConstantQuality + : VideoEncodeRateType.AverageBitrate; + task.TwoPass = frmMain.check_2PassEncode.Checked; + task.TurboFirstPass = frmMain.check_turbo.Checked; + double framerate; + double.TryParse(frmMain.drp_videoFramerate.Text, out framerate); + task.Framerate = framerate; + task.FramerateMode = frmMain.drp_videoFramerate.SelectedIndex == 0 + ? (frmMain.radio_constantFramerate.Checked ? FramerateMode.CFR : FramerateMode.VFR) + : (frmMain.radio_constantFramerate.Checked ? FramerateMode.CFR : FramerateMode.PFR); + + if (frmMain.radio_cq.Checked) + { + double cqStep = UserSettingService.GetUserSetting(ASUserSettingConstants.X264Step); + switch (frmMain.drp_videoEncoder.Text) + { + case "MPEG-4 (FFmpeg)": + case "MPEG-2 (FFmpeg)": + task.Quality = 31 - (frmMain.slider_videoQuality.Value - 1); + break; + case "H.264 (x264)": + double value = 51 - (frmMain.slider_videoQuality.Value * cqStep); + task.Quality = Math.Round(value, 2); + break; + case "VP3 (Theora)": + task.Quality = frmMain.slider_videoQuality.Value; + break; + } + } + + // Audio + task.AudioTracks = new List(frmMain.AudioSettings.AudioTracks); + + // Subtitles + task.SubtitleTracks = new List(frmMain.Subtitles.SubtitlesList); + + // Chapters + task.IncludeChapterMarkers = frmMain.Check_ChapterMarkers.Checked; + task.ChapterNames = new List(); + foreach (DataGridViewRow row in frmMain.data_chpt.Rows) + { + task.ChapterNames.Add(row.Cells[1].Value.ToString()); + } + + // Advanced Options + task.AdvancedEncoderOptions = X264Query(frmMain).Replace("-x", string.Empty).Trim(); + + // Extra Settings + task.Verbosity = UserSettingService.GetUserSetting(ASUserSettingConstants.Verbosity); + task.DisableLibDvdNav = UserSettingService.GetUserSetting(ASUserSettingConstants.DisableLibDvdNav); + + return task; + } + + #endregion + #region Helpers /// diff --git a/win/CS/HandBrake.ApplicationServices/Model/EncodeTask.cs b/win/CS/HandBrake.ApplicationServices/Model/EncodeTask.cs index bcc07d55f..ce46132af 100644 --- a/win/CS/HandBrake.ApplicationServices/Model/EncodeTask.cs +++ b/win/CS/HandBrake.ApplicationServices/Model/EncodeTask.cs @@ -293,6 +293,16 @@ namespace HandBrake.ApplicationServices.Model /// public string AdvancedEncoderOptions { get; set; } + /// + /// Gets or sets Verbosity. + /// + public int Verbosity { get; set; } + + /// + /// Gets or sets a value indicating whether disableLibDvdNav. + /// + public bool DisableLibDvdNav { get; set; } + #endregion #region Preset Information (TODO This should probably be dropped) diff --git a/win/CS/HandBrake.ApplicationServices/Model/Preset.cs b/win/CS/HandBrake.ApplicationServices/Model/Preset.cs index e20ad2dee..ede38b26f 100644 --- a/win/CS/HandBrake.ApplicationServices/Model/Preset.cs +++ b/win/CS/HandBrake.ApplicationServices/Model/Preset.cs @@ -30,11 +30,6 @@ namespace HandBrake.ApplicationServices.Model /// public bool CropSettings { get; set; } - /// - /// Gets or sets the Settings for this encode/preset. Can be used in place of Query property. - /// - public EncodeTask EncodeSettings { get; set; } - /// /// Gets or sets The version number which associates this preset with a HB build /// diff --git a/win/CS/HandBrake.ApplicationServices/Model/QueueTask.cs b/win/CS/HandBrake.ApplicationServices/Model/QueueTask.cs index 245a3171d..8c2425ee7 100644 --- a/win/CS/HandBrake.ApplicationServices/Model/QueueTask.cs +++ b/win/CS/HandBrake.ApplicationServices/Model/QueueTask.cs @@ -5,18 +5,11 @@ namespace HandBrake.ApplicationServices.Model { - using HandBrake.ApplicationServices.Utilities; - /// /// The QueueTask. /// public class QueueTask { - /// - /// The Encode task backing field. - /// - private EncodeTask task; - /// /// Initializes a new instance of the class. /// @@ -71,20 +64,9 @@ namespace HandBrake.ApplicationServices.Model public QueueItemStatus Status { get; set; } /// - /// Gets the Encode Task. + /// Gets or sets the Encode Task. /// - public EncodeTask Task - { - get - { - if (this.task == null) - { - task = QueryParserUtility.Parse(this.Query); - } - - return this.task; - } - } + public EncodeTask Task { get; set; } /// /// Gets a value indicating whether or not this instance is empty. diff --git a/win/CS/frmMain.cs b/win/CS/frmMain.cs index 9a2baa5d1..63623343d 100644 --- a/win/CS/frmMain.cs +++ b/win/CS/frmMain.cs @@ -21,6 +21,7 @@ namespace Handbrake using HandBrake.ApplicationServices; using HandBrake.ApplicationServices.EventArgs; + using HandBrake.ApplicationServices.Model.Encoding; using HandBrake.ApplicationServices.Model.General; using HandBrake.ApplicationServices.Utilities; using HandBrake.ApplicationServices.Functions; @@ -845,7 +846,7 @@ namespace Handbrake Preset preset = new Preset { Name = parsed.PresetName, - Query = QueryGenerator.GenerateFullQuery(this), + Query = QueryGenerator.GenerateFullQuery(this).Query, CropSettings = parsed.UsesPictureSettings }; @@ -860,7 +861,7 @@ namespace Handbrake Preset preset = new Preset { Name = parsed.PresetName, - Query = QueryGenerator.GenerateFullQuery(this), + Query = QueryGenerator.GenerateFullQuery(this).Query, CropSettings = parsed.UsesPictureSettings, }; PresetLoader.LoadPreset(this, preset); @@ -982,18 +983,17 @@ namespace Handbrake // If we have a custom query, then we'll want to figure out what the new source and destination is, otherwise we'll just use the gui components. string jobSourcePath = !string.IsNullOrEmpty(rtf_query.Text) ? Main.GetSourceFromQuery(rtf_query.Text) : sourcePath; string jobDestination = !string.IsNullOrEmpty(rtf_query.Text) ? Main.GetDestinationFromQuery(rtf_query.Text) : text_destination.Text; + QueueTask task = QueryGenerator.GenerateFullQuery(this); if (this.queueProcessor.QueueManager.Count != 0 || (!string.IsNullOrEmpty(jobSourcePath) && !string.IsNullOrEmpty(jobDestination))) { - string generatedQuery = QueryGenerator.GenerateFullQuery(this); string specifiedQuery = rtf_query.Text != string.Empty ? rtf_query.Text - : QueryGenerator.GenerateFullQuery(this); - string query = string.Empty; + : task.Query; // Check to make sure the generated query matches the GUI settings if (this.userSettingService.GetUserSetting(UserSettingConstants.PromptOnUnmatchingQueries) && !string.IsNullOrEmpty(specifiedQuery) && - generatedQuery != specifiedQuery) + task.Query != specifiedQuery) { DialogResult result = MessageBox.Show("The query under the \"Query Editor\" tab " + "does not match the current GUI settings.\n\nBecause the manual query takes " + @@ -1009,12 +1009,12 @@ namespace Handbrake { case DialogResult.Yes: // Replace the manual query with the generated one - query = generatedQuery; - rtf_query.Text = generatedQuery; + + rtf_query.Text = task.Query; break; case DialogResult.No: // Use the manual query - query = specifiedQuery; + task.Query = specifiedQuery; break; case DialogResult.Cancel: // Don't start the encode @@ -1023,7 +1023,7 @@ namespace Handbrake } else { - query = specifiedQuery; + task.Query = specifiedQuery; } DialogResult overwrite = DialogResult.Yes; @@ -1038,16 +1038,10 @@ namespace Handbrake if (overwrite == DialogResult.Yes) { - QueueTask task = new QueueTask(query) - { - Title = this.GetTitle(), - Source = jobSourcePath, - Destination = jobDestination, - CustomQuery = (this.rtf_query.Text != string.Empty) - }; + if (this.queueProcessor.QueueManager.Count == 0) - this.queueProcessor.QueueManager.Add(task); + this.queueProcessor.QueueManager.Add(QueryGenerator.GenerateFullQuery(this)); queueWindow.SetQueue(); if (this.queueProcessor.QueueManager.Count > 1) @@ -1202,10 +1196,6 @@ namespace Handbrake private bool AddItemToQueue(bool showError) { - string query = QueryGenerator.GenerateFullQuery(this); - if (!string.IsNullOrEmpty(rtf_query.Text)) - query = rtf_query.Text; - // If we have a custom query, then we'll want to figure out what the new source and destination is, otherwise we'll just use the gui components. string jobSourcePath = !string.IsNullOrEmpty(rtf_query.Text) ? Main.GetSourceFromQuery(rtf_query.Text) : sourcePath; string jobDestination = !string.IsNullOrEmpty(rtf_query.Text) ? Main.GetDestinationFromQuery(rtf_query.Text) : text_destination.Text; @@ -1242,14 +1232,8 @@ namespace Handbrake } // Add the job. - QueueTask task = new QueueTask(query) - { - Title = this.GetTitle(), - Source = jobSourcePath, - Destination = jobDestination, - CustomQuery = (this.rtf_query.Text != string.Empty) - }; - this.queueProcessor.QueueManager.Add(task); + + this.queueProcessor.QueueManager.Add(QueryGenerator.GenerateFullQuery(this)); lbl_encode.Text = this.queueProcessor.QueueManager.Count + " encode(s) pending in the queue"; @@ -2083,7 +2067,7 @@ namespace Handbrake // Query Editor Tab private void btn_generate_Query_Click(object sender, EventArgs e) { - rtf_query.Text = QueryGenerator.GenerateFullQuery(this); + rtf_query.Text = QueryGenerator.GenerateFullQuery(this).Query; } private void btn_clear_Click(object sender, EventArgs e) @@ -2540,7 +2524,7 @@ namespace Handbrake /// /// The title. /// - private int GetTitle() + public int GetTitle() { int title = 0; if (drp_dvdtitle.SelectedItem != null) -- cgit v1.2.3