From 52d4c21b22cfc91b63a680aa7e475cc0ca6012cb Mon Sep 17 00:00:00 2001 From: sr55 Date: Sat, 15 Apr 2017 12:26:59 +0100 Subject: [PATCH] WinGui: Handle HB_STATE_MUXING and HB_STATE_SEARCHING for better progress indication in the UI. #676 --- .../EventArgs/EncodeProgressEventArgs.cs | 36 +++++++++++++++- .../Interop/HandBrakeInstance.cs | 6 +-- .../Interop/HbLib/NativeConstants.cs | 1 + .../Properties/ResourcesUI.Designer.cs | 27 ++++++++++++ .../HandBrakeWPF/Properties/ResourcesUI.resx | 9 ++++ .../EventArgs/EncodeProgressEventArgs.cs | 35 ++++++++++++---- .../HandBrakeWPF/Services/Encode/LibEncode.cs | 4 +- .../Scan/EventArgs/ScanProgressEventArgs.cs | 5 --- .../HandBrakeWPF/ViewModels/MainViewModel.cs | 10 ++++- .../HandBrakeWPF/ViewModels/QueueViewModel.cs | 42 ++++++++++++++----- 10 files changed, 145 insertions(+), 30 deletions(-) diff --git a/win/CS/HandBrake.ApplicationServices/Interop/EventArgs/EncodeProgressEventArgs.cs b/win/CS/HandBrake.ApplicationServices/Interop/EventArgs/EncodeProgressEventArgs.cs index 5fad3248c..0da2fd178 100644 --- a/win/CS/HandBrake.ApplicationServices/Interop/EventArgs/EncodeProgressEventArgs.cs +++ b/win/CS/HandBrake.ApplicationServices/Interop/EventArgs/EncodeProgressEventArgs.cs @@ -40,7 +40,13 @@ namespace HandBrake.ApplicationServices.Interop.EventArgs /// /// The pass count. /// - public EncodeProgressEventArgs(double fractionComplete, double currentFrameRate, double averageFrameRate, TimeSpan estimatedTimeLeft, int passId, int pass, int passCount) + /// + /// A flag to indicate we are muxing. + /// + /// + /// Gets a value indicating that we are in the searching process. + /// + public EncodeProgressEventArgs(double fractionComplete, double currentFrameRate, double averageFrameRate, TimeSpan estimatedTimeLeft, int passId, int pass, int passCount, bool isMuxing, bool isSearching) { this.FractionComplete = fractionComplete; this.CurrentFrameRate = currentFrameRate; @@ -49,6 +55,8 @@ namespace HandBrake.ApplicationServices.Interop.EventArgs this.PassId = passId; this.Pass = pass; this.PassCount = passCount; + this.IsMuxing = isMuxing; + this.IsSearching = isSearching; } /// @@ -91,5 +99,31 @@ namespace HandBrake.ApplicationServices.Interop.EventArgs /// Gets the pass count. /// public int PassCount { get; private set; } + + /// + /// Gets a value indicating that we are in the muxing process. + /// + public bool IsMuxing { get; private set; } + + /// + /// Gets a value indicating that we are in the searching process. + /// + public bool IsSearching { get; } + + /// + /// Gets a value indicating that we are doing a subtitle scan pass. + /// + public bool IsSubtitleScan + { + get + { + if (this.PassId == -1) + { + return true; + } + + return false; + } + } } } diff --git a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstance.cs b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstance.cs index de0f0b2bc..861a5edaf 100644 --- a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstance.cs +++ b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstance.cs @@ -492,7 +492,7 @@ namespace HandBrake.ApplicationServices.Interop this.log.LogMessage(statusJson, LogMessageType.Progress, LogLevel.Trace); JsonState state = JsonConvert.DeserializeObject(statusJson); - if (state != null && state.State == NativeConstants.HB_STATE_SCANNING) + if (state != null && (state.State == NativeConstants.HB_STATE_SCANNING || state.State == NativeConstants.HB_STATE_SEARCHING)) { if (this.ScanProgress != null) { @@ -529,12 +529,12 @@ namespace HandBrake.ApplicationServices.Interop JsonState state = JsonConvert.DeserializeObject(statusJson); - if (state != null && state.State == NativeConstants.HB_STATE_WORKING) + if (state != null && (state.State == NativeConstants.HB_STATE_WORKING || state.State == NativeConstants.HB_STATE_MUXING || state.State == NativeConstants.HB_STATE_SEARCHING)) { if (this.EncodeProgress != null) { var progressEventArgs = new EncodeProgressEventArgs(state.Working.Progress, state.Working.Rate, state.Working.RateAvg, new TimeSpan(state.Working.Hours, state.Working.Minutes, state.Working.Seconds), - state.Working.PassID, state.Working.Pass, state.Working.PassCount); + state.Working.PassID, state.Working.Pass, state.Working.PassCount, state.State == NativeConstants.HB_STATE_MUXING, state.State == NativeConstants.HB_STATE_SEARCHING); this.EncodeProgress(this, progressEventArgs); } diff --git a/win/CS/HandBrake.ApplicationServices/Interop/HbLib/NativeConstants.cs b/win/CS/HandBrake.ApplicationServices/Interop/HbLib/NativeConstants.cs index bc593539f..9f4615bbf 100644 --- a/win/CS/HandBrake.ApplicationServices/Interop/HbLib/NativeConstants.cs +++ b/win/CS/HandBrake.ApplicationServices/Interop/HbLib/NativeConstants.cs @@ -59,6 +59,7 @@ namespace HandBrake.ApplicationServices.Interop.HbLib public const int HB_STATE_PAUSED = 16; public const int HB_STATE_WORKDONE = 32; public const int HB_STATE_MUXING = 64; + public const int HB_STATE_SEARCHING = 128; // Keep aspect ratio values public const int HB_KEEP_WIDTH = 0x01; diff --git a/win/CS/HandBrakeWPF/Properties/ResourcesUI.Designer.cs b/win/CS/HandBrakeWPF/Properties/ResourcesUI.Designer.cs index 0fee65fc9..c04e4e97e 100644 --- a/win/CS/HandBrakeWPF/Properties/ResourcesUI.Designer.cs +++ b/win/CS/HandBrakeWPF/Properties/ResourcesUI.Designer.cs @@ -753,6 +753,15 @@ namespace HandBrakeWPF.Properties { } } + /// + /// Looks up a localized string similar to Muxing: This may take a while.... + /// + public static string MainView_Muxing { + get { + return ResourceManager.GetString("MainView_Muxing", resourceCulture); + } + } + /// /// Looks up a localized string similar to Options. /// @@ -816,6 +825,15 @@ namespace HandBrakeWPF.Properties { } } + /// + /// Looks up a localized string similar to Encoding: {0}, {1:00.00}%, Time Remaining: {2}, {3}. + /// + public static string MainView_ProgressStatusWithTask { + get { + return ResourceManager.GetString("MainView_ProgressStatusWithTask", resourceCulture); + } + } + /// /// Looks up a localized string similar to Remove. /// @@ -834,6 +852,15 @@ namespace HandBrakeWPF.Properties { } } + /// + /// Looks up a localized string similar to Searching for start time. + /// + public static string MainView_Searching { + get { + return ResourceManager.GetString("MainView_Searching", resourceCulture); + } + } + /// /// Looks up a localized string similar to Set Default. /// diff --git a/win/CS/HandBrakeWPF/Properties/ResourcesUI.resx b/win/CS/HandBrakeWPF/Properties/ResourcesUI.resx index f6c92ea61..50a0c4bbd 100644 --- a/win/CS/HandBrakeWPF/Properties/ResourcesUI.resx +++ b/win/CS/HandBrakeWPF/Properties/ResourcesUI.resx @@ -899,4 +899,13 @@ This will not affect your current settings in the Subtitle tab. Play a sound when the queue or single encode completes: + + Muxing: This may take a while... + + + Encoding: {0}, {1:00.00}%, Time Remaining: {2}, {3} + + + Searching for start time + \ No newline at end of file diff --git a/win/CS/HandBrakeWPF/Services/Encode/EventArgs/EncodeProgressEventArgs.cs b/win/CS/HandBrakeWPF/Services/Encode/EventArgs/EncodeProgressEventArgs.cs index 940be6568..784245af6 100644 --- a/win/CS/HandBrakeWPF/Services/Encode/EventArgs/EncodeProgressEventArgs.cs +++ b/win/CS/HandBrakeWPF/Services/Encode/EventArgs/EncodeProgressEventArgs.cs @@ -10,54 +10,45 @@ namespace HandBrakeWPF.Services.Encode.EventArgs { using System; - using System.Runtime.Serialization; /// /// Encode Progress Event Args /// - [DataContract] public class EncodeProgressEventArgs : EventArgs { /// /// Gets or sets PercentComplete. /// - [DataMember] public double PercentComplete { get; set; } /// /// Gets or sets CurrentFrameRate. /// - [DataMember] public double CurrentFrameRate { get; set; } /// /// Gets or sets AverageFrameRate. /// - [DataMember] public double AverageFrameRate { get; set; } /// /// Gets or sets EstimatedTimeLeft. /// - [DataMember] public TimeSpan EstimatedTimeLeft { get; set; } /// /// Gets or sets Task. /// - [DataMember] public int Task { get; set; } /// /// Gets or sets TaskCount. /// - [DataMember] public int TaskCount { get; set; } /// /// Gets or sets ElapsedTime. /// - [DataMember] public TimeSpan ElapsedTime { get; set; } /// @@ -70,5 +61,31 @@ namespace HandBrakeWPF.Services.Encode.EventArgs /// 2: Encode second pass /// public int PassId { get; set; } + + /// + /// Gets a value indicating that we are in the muxing process. + /// + public bool IsMuxing { get; set; } + + /// + /// Gets a value indicating that we are in the searching process. + /// + public bool IsSearching { get; set; } + + /// + /// Gets a value indicating that we are doing a subtitle scan pass. + /// + public bool IsSubtitleScan + { + get + { + if (this.PassId == -1) + { + return true; + } + + return false; + } + } } } diff --git a/win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs b/win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs index 03763d448..2ad5f0688 100644 --- a/win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs +++ b/win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs @@ -180,7 +180,9 @@ namespace HandBrakeWPF.Services.Encode Task = e.Pass, TaskCount = e.PassCount, ElapsedTime = DateTime.Now - this.startTime, - PassId = e.PassId + PassId = e.PassId, + IsMuxing = e.IsMuxing, + IsSearching = e.IsSearching }; this.InvokeEncodeStatusChanged(args); diff --git a/win/CS/HandBrakeWPF/Services/Scan/EventArgs/ScanProgressEventArgs.cs b/win/CS/HandBrakeWPF/Services/Scan/EventArgs/ScanProgressEventArgs.cs index 8d815b746..113f7a923 100644 --- a/win/CS/HandBrakeWPF/Services/Scan/EventArgs/ScanProgressEventArgs.cs +++ b/win/CS/HandBrakeWPF/Services/Scan/EventArgs/ScanProgressEventArgs.cs @@ -10,30 +10,25 @@ namespace HandBrakeWPF.Services.Scan.EventArgs { using System; - using System.Runtime.Serialization; /// /// Scan Progress Event Args /// - [DataContract] public class ScanProgressEventArgs : EventArgs { /// /// Gets or sets the title currently being scanned. /// - [DataMember] public int CurrentTitle { get; set; } /// /// Gets or sets the total number of Titles. /// - [DataMember] public int Titles { get; set; } /// /// Gets or sets the percentage. /// - [DataMember] public decimal Percentage { get; set; } } } diff --git a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs index 283111b11..9bb991efc 100644 --- a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs @@ -2420,7 +2420,7 @@ namespace HandBrakeWPF.ViewModels if (this.queueProcessor.EncodeService.IsEncoding) { string jobsPending = string.Format(Resources.Main_JobsPending_addon, this.queueProcessor.Count); - if (e.PassId == -1) + if (e.IsSubtitleScan) { this.ProgramStatusLabel = string.Format(Resources.MainViewModel_EncodeStatusChanged_SubScan_StatusLabel, e.Task, @@ -2430,6 +2430,14 @@ namespace HandBrakeWPF.ViewModels e.ElapsedTime, jobsPending); } + else if (e.IsMuxing) + { + this.ProgramStatusLabel = ResourcesUI.MainView_Muxing; + } + else if (e.IsSearching) + { + this.ProgramStatusLabel = string.Format(ResourcesUI.MainView_ProgressStatusWithTask, ResourcesUI.MainView_Searching, e.PercentComplete, e.EstimatedTimeLeft, jobsPending); + } else { this.ProgramStatusLabel = diff --git a/win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs index c5351d729..2267c1a44 100644 --- a/win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs @@ -519,16 +519,38 @@ namespace HandBrakeWPF.ViewModels { Execute.OnUIThread(() => { - this.JobStatus = - string.Format( - Resources.QueueViewModel_QueueStatusDisplay, - e.Task, - e.TaskCount, - e.PercentComplete, - e.CurrentFrameRate, - e.AverageFrameRate, - e.EstimatedTimeLeft, - e.ElapsedTime); + string jobsPending = string.Format(Resources.Main_JobsPending_addon, this.queueProcessor.Count); + if (e.IsSubtitleScan) + { + this.JobStatus = string.Format(Resources.MainViewModel_EncodeStatusChanged_SubScan_StatusLabel, + e.Task, + e.TaskCount, + e.PercentComplete, + e.EstimatedTimeLeft, + e.ElapsedTime, + jobsPending); + } + else if (e.IsMuxing) + { + this.JobStatus = ResourcesUI.MainView_Muxing; + } + else if (e.IsSearching) + { + this.JobStatus = string.Format(ResourcesUI.MainView_ProgressStatusWithTask, ResourcesUI.MainView_Searching, e.PercentComplete, e.EstimatedTimeLeft, jobsPending); + } + else + { + this.JobStatus = + string.Format(Resources.MainViewModel_EncodeStatusChanged_StatusLabel, + e.Task, + e.TaskCount, + e.PercentComplete, + e.CurrentFrameRate, + e.AverageFrameRate, + e.EstimatedTimeLeft, + e.ElapsedTime, + jobsPending); + } }); } -- 2.40.0