From 24f6d27cf9d979ab0743665b37e60fd1295776d1 Mon Sep 17 00:00:00 2001 From: sr55 Date: Sat, 7 Mar 2015 22:54:38 +0000 Subject: WinGui: Updating the app to handle the latest JSON API change regarding the Automatic title scan on encode. This Simplifies the API in the services library. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6977 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- .../Services/Encode/EncodeBase.cs | 66 -------- .../Services/Encode/Factories/EncodeFactory.cs | 44 ++--- .../Services/Encode/Interfaces/IEncode.cs | 5 - .../Services/Encode/LibEncode.cs | 178 ++++++--------------- 4 files changed, 60 insertions(+), 233 deletions(-) (limited to 'win/CS/HandBrake.ApplicationServices/Services') diff --git a/win/CS/HandBrake.ApplicationServices/Services/Encode/EncodeBase.cs b/win/CS/HandBrake.ApplicationServices/Services/Encode/EncodeBase.cs index 9b817069b..3ba8a847f 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/Encode/EncodeBase.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/Encode/EncodeBase.cs @@ -234,72 +234,6 @@ namespace HandBrake.ApplicationServices.Services.Encode } } - /// - /// Pase the status output (from standard output) - /// - /// - /// The encode Status. - /// - /// - /// The start Time. - /// - /// - /// The . - /// - public EncodeProgressEventArgs ReadEncodeStatus(string encodeStatus, DateTime startTime) - { - try - { - Match m = Regex.Match( - encodeStatus, - @"^Encoding: task ([0-9]*) of ([0-9]*), ([0-9]*\.[0-9]*) %( \(([0-9]*\.[0-9]*) fps, avg ([0-9]*\.[0-9]*) fps, ETA ([0-9]{2})h([0-9]{2})m([0-9]{2})s\))?"); - - if (m.Success) - { - int currentTask = int.Parse(m.Groups[1].Value); - int totalTasks = int.Parse(m.Groups[2].Value); - float percent = float.Parse(m.Groups[3].Value, CultureInfo.InvariantCulture); - float currentFps = m.Groups[5].Value == string.Empty - ? 0.0F - : float.Parse(m.Groups[5].Value, CultureInfo.InvariantCulture); - float avgFps = m.Groups[6].Value == string.Empty - ? 0.0F - : float.Parse(m.Groups[6].Value, CultureInfo.InvariantCulture); - string remaining = string.Empty; - if (m.Groups[7].Value != string.Empty) - { - remaining = m.Groups[7].Value + ":" + m.Groups[8].Value + ":" + m.Groups[9].Value; - } - if (string.IsNullOrEmpty(remaining)) - { - remaining = "Calculating ..."; - } - - EncodeProgressEventArgs eventArgs = new EncodeProgressEventArgs - { - AverageFrameRate = avgFps, - CurrentFrameRate = currentFps, - EstimatedTimeLeft = - Converters.EncodeToTimespan( - remaining), - PercentComplete = percent, - Task = currentTask, - TaskCount = totalTasks, - ElapsedTime = - DateTime.Now - startTime, - }; - - return eventArgs; - } - - return null; - } - catch (Exception) - { - return null; - } - } - /// /// Setup the logging. /// diff --git a/win/CS/HandBrake.ApplicationServices/Services/Encode/Factories/EncodeFactory.cs b/win/CS/HandBrake.ApplicationServices/Services/Encode/Factories/EncodeFactory.cs index 81f619b71..50bd04930 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/Encode/Factories/EncodeFactory.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/Encode/Factories/EncodeFactory.cs @@ -15,12 +15,10 @@ namespace HandBrake.ApplicationServices.Services.Encode.Factories using System.Runtime.InteropServices; using HandBrake.ApplicationServices.Interop; - using HandBrake.ApplicationServices.Interop.Factories; using HandBrake.ApplicationServices.Interop.HbLib; using HandBrake.ApplicationServices.Interop.Helpers; using HandBrake.ApplicationServices.Interop.Json.Anamorphic; using HandBrake.ApplicationServices.Interop.Json.Encode; - using HandBrake.ApplicationServices.Interop.Model; using HandBrake.ApplicationServices.Interop.Model.Encoding; using HandBrake.ApplicationServices.Model; using HandBrake.ApplicationServices.Services.Encode.Model; @@ -47,24 +45,21 @@ namespace HandBrake.ApplicationServices.Services.Encode.Factories /// /// The encode job. /// - /// - /// The title. - /// /// /// The configuration. /// /// /// The . /// - internal static JsonEncodeObject Create(EncodeTask job, SourceVideoInfo title, HBConfiguration configuration) + internal static JsonEncodeObject Create(EncodeTask job, HBConfiguration configuration) { JsonEncodeObject encode = new JsonEncodeObject { SequenceID = 0, Audio = CreateAudio(job), Destination = CreateDestination(job), - Filter = CreateFilter(job, title), - PAR = CreatePAR(job, title), + Filter = CreateFilter(job), + PAR = CreatePAR(job), MetaData = CreateMetaData(job), Source = CreateSource(job, configuration), Subtitle = CreateSubtitle(job), @@ -114,7 +109,8 @@ namespace HandBrake.ApplicationServices.Services.Encode.Factories { Title = job.Title, Range = range, - Angle = job.Angle + Angle = job.Angle, + Path = job.Source, }; return source; } @@ -161,16 +157,12 @@ namespace HandBrake.ApplicationServices.Services.Encode.Factories /// /// The Job /// - /// - /// The title. - /// /// /// The produced PAR object. /// - private static PAR CreatePAR(EncodeTask job, SourceVideoInfo title) + private static PAR CreatePAR(EncodeTask job) { - Geometry resultGeometry = AnamorphicFactory.CreateGeometry(job, title, AnamorphicFactory.KeepSetting.HB_KEEP_WIDTH); - return new PAR { Num = resultGeometry.PAR.Num, Den = resultGeometry.PAR.Den }; + return new PAR { Num = job.PixelAspectX, Den = job.PixelAspectY }; } /// @@ -385,13 +377,10 @@ namespace HandBrake.ApplicationServices.Services.Encode.Factories /// /// The job. /// - /// - /// The title. - /// /// /// The . /// - private static Filter CreateFilter(EncodeTask job, SourceVideoInfo title) + private static Filter CreateFilter(EncodeTask job) { Filter filter = new Filter { @@ -461,21 +450,15 @@ namespace HandBrake.ApplicationServices.Services.Encode.Factories IntPtr frameratePrt = Marshal.StringToHGlobalAnsi(job.Framerate.ToString()); // TODO check culture int vrate = HBFunctions.hb_video_framerate_get_from_name(frameratePrt); - int num; - int den; + int? num = null; + int? den = null; if (vrate > 0) { num = 27000000; den = vrate; } - else - { - // cfr or pfr flag with no rate specified implies use the title rate. - num = title.FramerateNumerator ?? 0; - den = title.FramerateDenominator ?? 0; - } - string framerateString = string.Format("{0}:{1}:{2}", fm, num, den); // filter_cfr, filter_vrate.num, filter_vrate.den + string framerateString = num.HasValue ? string.Format("{0}:{1}:{2}", fm, num, den) : string.Format("{0}", fm); // filter_cfr, filter_vrate.num, filter_vrate.den FilterList framerateShaper = new FilterList { ID = (int)hb_filter_ids.HB_FILTER_VFR, Settings = framerateString }; filter.FilterList.Add(framerateShaper); @@ -510,15 +493,14 @@ namespace HandBrake.ApplicationServices.Services.Encode.Factories } // CropScale Filter - Geometry resultGeometry = AnamorphicFactory.CreateGeometry(job, title, AnamorphicFactory.KeepSetting.HB_KEEP_WIDTH); FilterList cropScale = new FilterList { ID = (int)hb_filter_ids.HB_FILTER_CROP_SCALE, Settings = string.Format( "{0}:{1}:{2}:{3}:{4}:{5}", - resultGeometry.Width, - resultGeometry.Height, + job.Width, + job.Height, job.Cropping.Top, job.Cropping.Bottom, job.Cropping.Left, diff --git a/win/CS/HandBrake.ApplicationServices/Services/Encode/Interfaces/IEncode.cs b/win/CS/HandBrake.ApplicationServices/Services/Encode/Interfaces/IEncode.cs index aa53ed180..e0685d4ad 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/Encode/Interfaces/IEncode.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/Encode/Interfaces/IEncode.cs @@ -71,11 +71,6 @@ namespace HandBrake.ApplicationServices.Services.Encode.Interfaces /// int LogIndex { get; } - /// - /// Gets a value indicating whether can pause. - /// - bool CanPause { get; } - /// /// Gets a value indicating whether is pasued. /// diff --git a/win/CS/HandBrake.ApplicationServices/Services/Encode/LibEncode.cs b/win/CS/HandBrake.ApplicationServices/Services/Encode/LibEncode.cs index 0f2113ca1..0ae99b964 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/Encode/LibEncode.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/Encode/LibEncode.cs @@ -11,19 +11,14 @@ namespace HandBrake.ApplicationServices.Services.Encode { using System; using System.Diagnostics; - using System.Linq; - using System.ServiceModel.Channels; - using HandBrake.ApplicationServices.Model; - using HandBrake.ApplicationServices.Services.Encode.Interfaces; - using HandBrake.ApplicationServices.Services.Scan; - using HandBrake.ApplicationServices.Services.Scan.Model; - using HandBrake.ApplicationServices.Utilities; using HandBrake.ApplicationServices.Interop; using HandBrake.ApplicationServices.Interop.EventArgs; using HandBrake.ApplicationServices.Interop.Interfaces; using HandBrake.ApplicationServices.Interop.Model; + using HandBrake.ApplicationServices.Model; using HandBrake.ApplicationServices.Services.Encode.Factories; + using HandBrake.ApplicationServices.Services.Encode.Interfaces; /// /// LibHB Implementation of IEncode @@ -52,31 +47,8 @@ namespace HandBrake.ApplicationServices.Services.Encode /// private QueueTask currentTask; - /// - /// A local instance of the scanned source. - /// - private Source scannedSource; - #endregion - /// - /// Initializes a new instance of the class. - /// - public LibEncode() - { - } - - /// - /// Gets a value indicating whether can pause. - /// - public bool CanPause - { - get - { - return true; - } - } - /// /// Gets a value indicating whether is pasued. /// @@ -90,62 +62,69 @@ namespace HandBrake.ApplicationServices.Services.Encode /// public void Start(QueueTask job) { - // Setup - this.startTime = DateTime.Now; - this.currentTask = job; - - // Create a new HandBrake instance - // Setup the HandBrake Instance - HandBrakeUtils.MessageLogged += this.HandBrakeInstanceMessageLogged; - HandBrakeUtils.ErrorLogged += this.HandBrakeInstanceErrorLogged; - this.instance = HandBrakeInstanceManager.GetEncodeInstance(job.Configuration.Verbosity); - this.instance.EncodeCompleted += this.InstanceEncodeCompleted; - this.instance.EncodeProgress += this.InstanceEncodeProgress; - try { + // Setup + this.startTime = DateTime.Now; + this.currentTask = job; + + // Create a new HandBrake instance + // Setup the HandBrake Instance + HandBrakeUtils.MessageLogged += this.HandBrakeInstanceMessageLogged; + HandBrakeUtils.ErrorLogged += this.HandBrakeInstanceErrorLogged; + this.instance = HandBrakeInstanceManager.GetEncodeInstance(job.Configuration.Verbosity); + this.instance.EncodeCompleted += this.InstanceEncodeCompleted; + this.instance.EncodeProgress += this.InstanceEncodeProgress; + // Sanity Checking and Setup if (this.IsEncoding) { throw new Exception("HandBrake is already encoding."); } - + this.IsEncoding = true; - - // Enable logging if required. - try - { - this.SetupLogging(job, true); - } - catch (Exception) - { - this.IsEncoding = false; - throw; - } + this.SetupLogging(job, true); // Verify the Destination Path Exists, and if not, create it. this.VerifyEncodeDestinationPath(job); - // We have to scan the source again but only the title so the HandBrake instance is initialised correctly. - // Since the UI sends the crop params down, we don't have to do all the previews. - - this.instance.ScanCompleted += delegate - { - // Process into internal structures. - this.scannedSource = new Source { Titles = LibScan.ConvertTitles(this.instance.Titles) }; // TODO work around the bad Internal API. - this.ScanCompleted(job, this.instance); - }; + ServiceLogMessage("Starting Encode ..."); - HandBrakeUtils.SetDvdNav(!job.Configuration.IsDvdNavDisabled); + // Get an EncodeJob object for the Interop Library + instance.StartEncode(EncodeFactory.Create(job.Task, job.Configuration)); - ServiceLogMessage("Scanning title for encoding ... "); + // Fire the Encode Started Event + this.InvokeEncodeStarted(System.EventArgs.Empty); - this.instance.StartScan(job.ScannedSourcePath, job.Configuration.PreviewScanCount, TimeSpan.FromSeconds(job.Configuration.MinScanDuration), job.Task.Title); + // Set the Process Priority + switch (job.Configuration.ProcessPriority) + { + case "Realtime": + Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.RealTime; + break; + case "High": + Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.High; + break; + case "Above Normal": + Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.AboveNormal; + break; + case "Normal": + Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.Normal; + break; + case "Low": + Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.Idle; + break; + default: + Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.BelowNormal; + break; + } } catch (Exception exc) { - ServiceLogMessage("Scan Failed ... " + Environment.NewLine + exc); - this.InvokeEncodeCompleted(new EventArgs.EncodeCompletedEventArgs(false, exc, "An Error has occured.", this.currentTask.Task.Destination)); + this.IsEncoding = false; + + ServiceLogMessage("Failed to start encoding ..." + Environment.NewLine + exc); + this.InvokeEncodeCompleted(new EventArgs.EncodeCompletedEventArgs(false, exc, "Unable to start encoding", job.Task.Source)); } } @@ -195,69 +174,6 @@ namespace HandBrake.ApplicationServices.Services.Encode } } - /// - /// The scan completed. - /// - /// - /// The job. - /// - /// - /// The instance. - /// - private void ScanCompleted(QueueTask job, IHandBrakeInstance instance) - { - try - { - ServiceLogMessage("Scan Completed. Setting up the job for encoding ..."); - - // Start the Encode - Title title = this.scannedSource.Titles.FirstOrDefault(t => t.TitleNumber == job.Task.Title); - if (title == null) - { - ServiceLogMessage("Title not found."); - throw new Exception("Unable to get title for encoding. Encode Failed."); - } - - ServiceLogMessage("Starting Encode ..."); - - // Get an EncodeJob object for the Interop Library - SourceVideoInfo videoInfo = new SourceVideoInfo(title.FramerateNumerator, title.FramerateDenominator, title.Resolution, title.ParVal); - instance.StartEncode(EncodeFactory.Create(job.Task, videoInfo, job.Configuration)); - - // Fire the Encode Started Event - this.InvokeEncodeStarted(System.EventArgs.Empty); - - // Set the Process Priority - switch (job.Configuration.ProcessPriority) - { - case "Realtime": - Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.RealTime; - break; - case "High": - Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.High; - break; - case "Above Normal": - Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.AboveNormal; - break; - case "Normal": - Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.Normal; - break; - case "Low": - Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.Idle; - break; - default: - Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.BelowNormal; - break; - } - } - catch (Exception exc) - { - this.IsEncoding = false; - - ServiceLogMessage("Failed to start encoding ..." + Environment.NewLine + exc); - this.InvokeEncodeCompleted(new EventArgs.EncodeCompletedEventArgs(false, exc, "Unable to start encoding", job.Task.Source)); - } - } #region HandBrakeInstance Event Handlers. -- cgit v1.2.3