From 34db38d676420cf1fc827f339f5c894d5b798762 Mon Sep 17 00:00:00 2001 From: sr55 Date: Sat, 17 Jan 2015 19:39:49 +0000 Subject: WinGui: - Numerous fixes to the JSON api code. Live preview should now work again. Possible fix for issue where queued jobs where stopping at a random point and not continuing. - Fix Clear button on the audio tab. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6760 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- .../Model/HBConfiguration.cs | 5 -- .../Services/Encode/EncodeBase.cs | 14 ++-- .../Services/Encode/EncodeService.cs | 26 +++---- .../Services/Encode/LibEncode.cs | 56 ++++++--------- .../Services/Encode/Model/EncodeTask.cs | 2 +- .../Services/Scan/Interfaces/IScan.cs | 5 +- .../Services/Scan/LibScan.cs | 7 +- .../Utilities/InteropModelCreator.cs | 79 +++++++++++----------- .../Utilities/QueryGeneratorUtility.cs | 6 +- .../HandBrakeInterop/HandBrakeInstance.cs | 7 +- .../HandBrakeInterop/HandBrakeInstanceManager.cs | 47 +++++++++++++ .../HandBrakeInterop/HandBrakeUtils.cs | 4 +- .../HandBrakeInterop/Json/Encode/Range.cs | 19 ++++-- .../Json/Factories/EncodeFactory.cs | 40 ++++++++--- .../HandBrakeInterop/Model/EncodeJob.cs | 13 +++- .../HandBrakeInterop/Model/VideoRangeType.cs | 4 +- .../Factories/HBConfigurationFactory.cs | 40 ++++------- win/CS/HandBrakeWPF/ViewModels/PreviewViewModel.cs | 4 +- .../ViewModels/StaticPreviewViewModel.cs | 3 +- win/CS/HandBrakeWPF/Views/AudioView.xaml | 2 +- 20 files changed, 224 insertions(+), 159 deletions(-) (limited to 'win') diff --git a/win/CS/HandBrake.ApplicationServices/Model/HBConfiguration.cs b/win/CS/HandBrake.ApplicationServices/Model/HBConfiguration.cs index 04b6efab6..ecb82ba85 100644 --- a/win/CS/HandBrake.ApplicationServices/Model/HBConfiguration.cs +++ b/win/CS/HandBrake.ApplicationServices/Model/HBConfiguration.cs @@ -14,11 +14,6 @@ namespace HandBrake.ApplicationServices.Model /// public class HBConfiguration { - /// - /// Gets or sets a value indicating whether is logging enabled. - /// - public bool IsLoggingEnabled { get; set; } - /// /// Gets or sets a value indicating whether is dvd nav disabled. /// diff --git a/win/CS/HandBrake.ApplicationServices/Services/Encode/EncodeBase.cs b/win/CS/HandBrake.ApplicationServices/Services/Encode/EncodeBase.cs index a86f20978..65ef02ed3 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/Encode/EncodeBase.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/Encode/EncodeBase.cs @@ -338,10 +338,16 @@ namespace HandBrake.ApplicationServices.Services.Encode File.Delete(logFile2); } - this.fileWriter = new StreamWriter(logFile) { AutoFlush = true }; - this.fileWriter.WriteLine(this.header); - this.fileWriter.WriteLine(string.Format("CLI Query: {0}", query)); - this.fileWriter.WriteLine(); + lock (FileWriterLock) + { + this.fileWriter = new StreamWriter(logFile) { AutoFlush = true }; + this.fileWriter.WriteLine(this.header); + if (!isLibhb) + { + this.fileWriter.WriteLine(string.Format("CLI Query: {0}", query)); + } + this.fileWriter.WriteLine(); + } } catch (Exception) { diff --git a/win/CS/HandBrake.ApplicationServices/Services/Encode/EncodeService.cs b/win/CS/HandBrake.ApplicationServices/Services/Encode/EncodeService.cs index 841e049de..2253d96e8 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/Encode/EncodeService.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/Encode/EncodeService.cs @@ -96,17 +96,14 @@ namespace HandBrake.ApplicationServices.Services.Encode this.IsEncoding = true; this.currentTask = encodeQueueTask; - if (encodeQueueTask.Configuration.IsLoggingEnabled) + try { - try - { - this.SetupLogging(this.currentTask, false); - } - catch (Exception) - { - this.IsEncoding = false; - throw; - } + this.SetupLogging(this.currentTask, false); + } + catch (Exception) + { + this.IsEncoding = false; + throw; } // Make sure the path exists, attempt to create it if it doesn't @@ -126,7 +123,7 @@ namespace HandBrake.ApplicationServices.Services.Encode ProcessStartInfo cliStart = new ProcessStartInfo(handbrakeCLIPath, query) { RedirectStandardOutput = true, - RedirectStandardError = encodeQueueTask.Configuration.IsLoggingEnabled, + RedirectStandardError = true, UseShellExecute = false, CreateNoWindow = true }; @@ -137,11 +134,8 @@ namespace HandBrake.ApplicationServices.Services.Encode this.startTime = DateTime.Now; - if (encodeQueueTask.Configuration.IsLoggingEnabled) - { - this.HbProcess.ErrorDataReceived += this.HbProcErrorDataReceived; - this.HbProcess.BeginErrorReadLine(); - } + this.HbProcess.ErrorDataReceived += this.HbProcErrorDataReceived; + this.HbProcess.BeginErrorReadLine(); this.HbProcess.OutputDataReceived += this.HbProcess_OutputDataReceived; this.HbProcess.BeginOutputReadLine(); diff --git a/win/CS/HandBrake.ApplicationServices/Services/Encode/LibEncode.cs b/win/CS/HandBrake.ApplicationServices/Services/Encode/LibEncode.cs index 0da939e19..0fbc7dbfe 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/Encode/LibEncode.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/Encode/LibEncode.cs @@ -45,16 +45,14 @@ namespace HandBrake.ApplicationServices.Services.Encode /// private DateTime startTime; - /// - /// A flag to indicate if logging is enabled or not. - /// - private bool loggingEnabled; - /// /// The Current Task /// private QueueTask currentTask; + /// + /// A local instance of the scanned source. + /// private Source scannedSource; #endregion @@ -94,13 +92,11 @@ namespace HandBrake.ApplicationServices.Services.Encode { // Setup this.startTime = DateTime.Now; - this.loggingEnabled = job.Configuration.IsLoggingEnabled; this.currentTask = job; // Create a new HandBrake instance // Setup the HandBrake Instance - this.instance = new HandBrakeInstance(); - this.instance.Initialize(1); + this.instance = HandBrakeInstanceManager.GetEncodeInstance(job.Configuration.Verbosity); this.instance.EncodeCompleted += this.InstanceEncodeCompleted; this.instance.EncodeProgress += this.InstanceEncodeProgress; @@ -115,17 +111,14 @@ namespace HandBrake.ApplicationServices.Services.Encode this.IsEncoding = true; // Enable logging if required. - if (job.Configuration.IsLoggingEnabled) + try + { + this.SetupLogging(job, true); + } + catch (Exception) { - try - { - this.SetupLogging(job, true); - } - catch (Exception) - { - this.IsEncoding = false; - throw; - } + this.IsEncoding = false; + throw; } // Verify the Destination Path Exists, and if not, create it. @@ -133,14 +126,15 @@ namespace HandBrake.ApplicationServices.Services.Encode // 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.StartScan(job.Task.Source, job.Configuration.PreviewScanCount, job.Task.Title); this.instance.ScanCompleted += delegate - { - // Process into internal structures. - this.scannedSource = new Source { Titles = LibScan.ConvertTitles(this.instance.Titles, this.instance.FeatureTitle) }; // TODO work around the bad Internal API. - this.ScanCompleted(job, this.instance); - }; + { + // Process into internal structures. + this.scannedSource = new Source { Titles = LibScan.ConvertTitles(this.instance.Titles, this.instance.FeatureTitle) }; // TODO work around the bad Internal API. + this.ScanCompleted(job, this.instance); + }; + + this.instance.StartScan(job.Task.Source, job.Configuration.PreviewScanCount, job.Task.Title); } catch (Exception exc) { @@ -268,12 +262,9 @@ namespace HandBrake.ApplicationServices.Services.Encode /// private void HandBrakeInstanceErrorLogged(object sender, MessageLoggedEventArgs e) { - if (this.loggingEnabled) + lock (LogLock) { - lock (LogLock) - { - this.ProcessLogMessage(e.Message); - } + this.ProcessLogMessage(e.Message); } } @@ -288,12 +279,9 @@ namespace HandBrake.ApplicationServices.Services.Encode /// private void HandBrakeInstanceMessageLogged(object sender, MessageLoggedEventArgs e) { - if (this.loggingEnabled) + lock (LogLock) { - lock (LogLock) - { - this.ProcessLogMessage(e.Message); - } + this.ProcessLogMessage(e.Message); } } diff --git a/win/CS/HandBrake.ApplicationServices/Services/Encode/Model/EncodeTask.cs b/win/CS/HandBrake.ApplicationServices/Services/Encode/Model/EncodeTask.cs index 991d60a76..86b0d06ec 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/Encode/Model/EncodeTask.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/Encode/Model/EncodeTask.cs @@ -555,7 +555,7 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model /// /// Gets or sets PreviewEncodeStartAt. /// - public string PreviewEncodeStartAt { get; set; } + public int PreviewEncodeStartAt { get; set; } /// /// Gets or sets a value indicating whether advanced panel enabled. diff --git a/win/CS/HandBrake.ApplicationServices/Services/Scan/Interfaces/IScan.cs b/win/CS/HandBrake.ApplicationServices/Services/Scan/Interfaces/IScan.cs index 4d61d6078..086a97487 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/Scan/Interfaces/IScan.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/Scan/Interfaces/IScan.cs @@ -101,10 +101,13 @@ namespace HandBrake.ApplicationServices.Services.Scan.Interfaces /// /// The preview. /// + /// + /// The configuration. + /// /// /// The . /// - BitmapImage GetPreview(EncodeTask task, int preview); + BitmapImage GetPreview(EncodeTask task, int preview, HBConfiguration configuration); /// /// Kill the scan diff --git a/win/CS/HandBrake.ApplicationServices/Services/Scan/LibScan.cs b/win/CS/HandBrake.ApplicationServices/Services/Scan/LibScan.cs index 6d1dcb104..650b07516 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/Scan/LibScan.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/Scan/LibScan.cs @@ -264,17 +264,20 @@ namespace HandBrake.ApplicationServices.Services.Scan /// /// The preview. /// + /// + /// The configuraiton. + /// /// /// The . /// - public BitmapImage GetPreview(EncodeTask job, int preview) + public BitmapImage GetPreview(EncodeTask job, int preview, HBConfiguration configuraiton) { if (this.instance == null) { return null; } - EncodeJob encodeJob = InteropModelCreator.GetEncodeJob(job); + EncodeJob encodeJob = InteropModelCreator.GetEncodeJob(job, configuraiton); BitmapImage bitmapImage = null; try diff --git a/win/CS/HandBrake.ApplicationServices/Utilities/InteropModelCreator.cs b/win/CS/HandBrake.ApplicationServices/Utilities/InteropModelCreator.cs index edea7fb9d..ec5194e95 100644 --- a/win/CS/HandBrake.ApplicationServices/Utilities/InteropModelCreator.cs +++ b/win/CS/HandBrake.ApplicationServices/Utilities/InteropModelCreator.cs @@ -12,6 +12,7 @@ namespace HandBrake.ApplicationServices.Utilities using System; using System.Collections.Generic; using System.Linq; + using System.Windows.Media.Animation; using HandBrake.ApplicationServices.Model; using HandBrake.ApplicationServices.Services.Encode.Model; @@ -39,12 +40,12 @@ namespace HandBrake.ApplicationServices.Utilities public static EncodeJob GetEncodeJob(QueueTask task) { // Sanity Checking - if (task == null || task.Task == null) + if (task == null || task.Task == null || task.Configuration == null) { return null; } - return GetEncodeJob(task.Task); + return GetEncodeJob(task.Task, task.Configuration); } /// @@ -53,10 +54,13 @@ namespace HandBrake.ApplicationServices.Utilities /// /// The task. /// + /// + /// The configuration. + /// /// /// An Interop.EncodeJob model. /// - public static EncodeJob GetEncodeJob(EncodeTask task) + public static EncodeJob GetEncodeJob(EncodeTask task, HBConfiguration configuration) { // The current Job Configuration EncodeTask work = task; @@ -72,17 +76,17 @@ namespace HandBrake.ApplicationServices.Utilities foreach (AudioTrack track in work.AudioTracks) { AudioEncoding newTrack = new AudioEncoding - { - Bitrate = track.Bitrate, - Drc = track.DRC, - Gain = track.Gain, - Encoder = Converters.GetCliAudioEncoder(track.Encoder), - InputNumber = track.Track.HasValue ? track.Track.Value : 0, - Mixdown = Converters.GetCliMixDown(track.MixDown), - SampleRateRaw = GetSampleRateRaw(track.SampleRate), - EncodeRateType = AudioEncodeRateType.Bitrate, - Name = track.TrackName - }; + { + Bitrate = track.Bitrate, + Drc = track.DRC, + Gain = track.Gain, + Encoder = Converters.GetCliAudioEncoder(track.Encoder), + InputNumber = track.Track.HasValue ? track.Track.Value : 0, + Mixdown = Converters.GetCliMixDown(track.MixDown), + SampleRateRaw = GetSampleRateRaw(track.SampleRate), + EncodeRateType = AudioEncodeRateType.Bitrate, + Name = track.TrackName + }; profile.AudioEncodings.Add(newTrack); if (track.Track != null) @@ -95,6 +99,7 @@ namespace HandBrake.ApplicationServices.Utilities job.OutputPath = work.Destination; job.SourcePath = work.Source; job.Title = work.Title; + // job.SourceType = work.Type; switch (work.PointToPointMode) { @@ -107,6 +112,9 @@ namespace HandBrake.ApplicationServices.Utilities case PointToPointMode.Frames: job.RangeType = VideoRangeType.Frames; break; + case PointToPointMode.Preview: + job.RangeType = VideoRangeType.Preview; + break; } if (work.PointToPointMode == PointToPointMode.Seconds) @@ -125,6 +133,13 @@ namespace HandBrake.ApplicationServices.Utilities job.FramesStart = work.StartPoint; } + if (work.PointToPointMode == PointToPointMode.Preview) + { + job.StartAtPreview = work.PreviewStartAt.HasValue ? work.PreviewStartAt.Value : 1; + job.SecondsEnd = work.PreviewDuration.HasValue ? work.PreviewEncodeDuration : 30; + job.SeekPoints = configuration.PreviewScanCount; + } + job.Angle = work.Angle; job.EncodingProfile = profile; @@ -143,17 +158,9 @@ namespace HandBrake.ApplicationServices.Utilities // Picture Settings profile.Anamorphic = work.Anamorphic; - profile.Cropping = new Cropping - { - Top = work.Cropping.Top, - Bottom = work.Cropping.Bottom, - Left = work.Cropping.Left, - Right = work.Cropping.Right - }; + profile.Cropping = new Cropping { Top = work.Cropping.Top, Bottom = work.Cropping.Bottom, Left = work.Cropping.Left, Right = work.Cropping.Right }; profile.CroppingType = CroppingType.Custom; // TODO deal with this better - profile.DisplayWidth = work.DisplayWidth.HasValue - ? int.Parse(Math.Round(work.DisplayWidth.Value, 0).ToString()) - : 0; + profile.DisplayWidth = work.DisplayWidth.HasValue ? int.Parse(Math.Round(work.DisplayWidth.Value, 0).ToString()) : 0; profile.PixelAspectX = work.PixelAspectX; profile.PixelAspectY = work.PixelAspectY; profile.Height = work.Height.HasValue ? work.Height.Value : 0; @@ -172,7 +179,9 @@ namespace HandBrake.ApplicationServices.Utilities profile.DenoiseTune = work.DenoiseTune.ToString().ToLower().Replace(" ", string.Empty); profile.CustomDetelecine = work.CustomDetelecine; if (work.Deblock > 4) + { profile.Deblock = work.Deblock; + } profile.Decomb = work.Decomb; profile.Deinterlace = work.Deinterlace; profile.Denoise = work.Denoise; @@ -209,7 +218,7 @@ namespace HandBrake.ApplicationServices.Utilities profile.VideoLevel = work.H264Level; } else if (work.VideoEncoder == VideoEncoder.X265) - { + { profile.VideoPreset = work.X265Preset.ToString().ToLower().Replace(" ", string.Empty); if (work.H265Profile != x265Profile.None) @@ -229,7 +238,7 @@ namespace HandBrake.ApplicationServices.Utilities profile.VideoProfile = work.H264Profile.ToString().ToLower().Replace(" ", string.Empty); profile.VideoLevel = work.H264Level; } - + // Chapter Markers profile.IncludeChapterMarkers = work.IncludeChapterMarkers; job.CustomChapterNames = work.ChapterNames.Select(item => item.ChapterName).ToList(); @@ -247,11 +256,11 @@ namespace HandBrake.ApplicationServices.Utilities job.Subtitles.SrtSubtitles.Add( new SrtSubtitle { - CharacterCode = track.SrtCharCode, - Default = track.Default, - FileName = track.SrtFileName, - LanguageCode = track.SrtLang, - Offset = track.SrtOffset, + CharacterCode = track.SrtCharCode, + Default = track.Default, + FileName = track.SrtFileName, + LanguageCode = track.SrtLang, + Offset = track.SrtOffset, BurnedIn = track.Burned }); } @@ -260,13 +269,7 @@ namespace HandBrake.ApplicationServices.Utilities if (track.SourceTrack != null) { job.Subtitles.SourceSubtitles.Add( - new SourceSubtitle - { - BurnedIn = track.Burned, - Default = track.Default, - Forced = track.Forced, - TrackNumber = track.SourceTrack.TrackNumber - }); + new SourceSubtitle { BurnedIn = track.Burned, Default = track.Default, Forced = track.Forced, TrackNumber = track.SourceTrack.TrackNumber }); } } } diff --git a/win/CS/HandBrake.ApplicationServices/Utilities/QueryGeneratorUtility.cs b/win/CS/HandBrake.ApplicationServices/Utilities/QueryGeneratorUtility.cs index 653732d2b..4c0eddac1 100644 --- a/win/CS/HandBrake.ApplicationServices/Utilities/QueryGeneratorUtility.cs +++ b/win/CS/HandBrake.ApplicationServices/Utilities/QueryGeneratorUtility.cs @@ -47,7 +47,7 @@ namespace HandBrake.ApplicationServices.Utilities } string query = string.Empty; - query += SourceQuery(task, null, null, configuration.PreviewScanCount); + query += SourceQuery(task, null, -1, configuration.PreviewScanCount); query += DestinationQuery(task); query += GenerateTabbedComponentsQuery(task, true, configuration.Verbosity, configuration.IsDvdNavDisabled, configuration.DisableQuickSyncDecoding, configuration.EnableDxva, configuration.ScalingMode == VideoScaler.BicubicCl); @@ -72,7 +72,7 @@ namespace HandBrake.ApplicationServices.Utilities /// /// A Cli query suitable for generating a preview video. /// - public static string GeneratePreviewQuery(EncodeTask task, HBConfiguration configuration, int duration, string startAtPreview) + public static string GeneratePreviewQuery(EncodeTask task, HBConfiguration configuration, int duration, int startAtPreview) { string query = string.Empty; query += SourceQuery(task, duration, startAtPreview, configuration.PreviewScanCount); @@ -164,7 +164,7 @@ namespace HandBrake.ApplicationServices.Utilities /// /// A Cli Query as a string /// - private static string SourceQuery(EncodeTask task, int? duration, string preview, int previewScanCount) + private static string SourceQuery(EncodeTask task, int? duration, int preview, int previewScanCount) { string query = string.Empty; diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs index cdb368c9a..a36e672ca 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs @@ -389,6 +389,7 @@ namespace HandBrake.Interop /// /// The scan Preview Count. /// + [HandleProcessCorruptedStateExceptions] public void StartEncode(EncodeJob jobToStart, Title title, int scanPreviewCount) { this.StartEncode(jobToStart, title, false, 0, 0, 0, scanPreviewCount); @@ -418,13 +419,14 @@ namespace HandBrake.Interop /// /// Number of previews /// + [HandleProcessCorruptedStateExceptions] public void StartEncode(EncodeJob job, Title title, bool preview, int previewNumber, int previewSeconds, double overallSelectedLengthSeconds, int scanPreviewCount) { JsonEncodeObject encodeObject = EncodeFactory.Create(job, title); JsonSerializerSettings settings = new JsonSerializerSettings { - NullValueHandling = NullValueHandling.Ignore + NullValueHandling = NullValueHandling.Ignore, }; string encode = JsonConvert.SerializeObject(encodeObject, Formatting.Indented, settings); @@ -444,6 +446,7 @@ namespace HandBrake.Interop /// /// Pauses the current encode. /// + [HandleProcessCorruptedStateExceptions] public void PauseEncode() { HBFunctions.hb_pause(this.hbHandle); @@ -452,6 +455,7 @@ namespace HandBrake.Interop /// /// Resumes a paused encode. /// + [HandleProcessCorruptedStateExceptions] public void ResumeEncode() { HBFunctions.hb_resume(this.hbHandle); @@ -460,6 +464,7 @@ namespace HandBrake.Interop /// /// Stops the current encode. /// + [HandleProcessCorruptedStateExceptions] public void StopEncode() { HBFunctions.hb_stop(this.hbHandle); diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstanceManager.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstanceManager.cs index 1ef749bd8..b1a889db0 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstanceManager.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstanceManager.cs @@ -20,6 +20,7 @@ namespace HandBrake.Interop public static class HandBrakeInstanceManager { private static HandBrakeInstance scanInstance; + private static HandBrakeInstance encodeInstance; /// /// Gets the scanInstance. @@ -45,6 +46,30 @@ namespace HandBrake.Interop return scanInstance; } + /// + /// The get encode instance. + /// + /// + /// The verbosity. + /// + /// + /// The . + /// + public static IHandBrakeInstance GetEncodeInstance(int verbosity) + { + if (encodeInstance != null) + { + encodeInstance.Dispose(); + encodeInstance = null; + } + + HandBrakeInstance newInstance = new HandBrakeInstance(); + newInstance.Initialize(verbosity); + encodeInstance = newInstance; + + return encodeInstance; + } + /// /// Gets the last scan scan instance. /// @@ -66,5 +91,27 @@ namespace HandBrake.Interop return scanInstance.Handle; } } + + /// + /// Gets the last encode scan instance. + /// + public static IHandBrakeInstance LastEncodeScanInstance + { + get + { + return encodeInstance; + } + } + + /// + /// Gets the encode handle. + /// + internal static IntPtr LastEncodeHandle + { + get + { + return encodeInstance.Handle; + } + } } } diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeUtils.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeUtils.cs index 4cb51886d..abb67a074 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeUtils.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeUtils.cs @@ -310,8 +310,8 @@ namespace HandBrake.Interop { switch (job.RangeType) { - case VideoRangeType.All: - return title.Duration.TotalSeconds; + // case VideoRangeType.All: + // return title.Duration.TotalSeconds; case VideoRangeType.Chapters: TimeSpan duration = TimeSpan.Zero; for (int i = job.ChapterStart; i <= job.ChapterEnd; i++) diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Json/Encode/Range.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Json/Encode/Range.cs index 2d9a45ee1..2538f93f5 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/Json/Encode/Range.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/Json/Encode/Range.cs @@ -17,36 +17,41 @@ namespace HandBrake.Interop.Json.Encode /// /// Gets or sets the chapter end. /// - public int ChapterEnd { get; set; } + public int? ChapterEnd { get; set; } /// /// Gets or sets the chapter start. /// - public int ChapterStart { get; set; } + public int? ChapterStart { get; set; } /// /// Gets or sets the frame to start. /// - public int FrameToStart { get; set; } + public int? FrameToStart { get; set; } /// /// Gets or sets the frame to stop. /// - public int FrameToStop { get; set; } + public int? FrameToStop { get; set; } /// /// Gets or sets the pts to start. /// - public int PtsToStart { get; set; } + public int? PtsToStart { get; set; } /// /// Gets or sets the pts to stop. /// - public int PtsToStop { get; set; } + public int? PtsToStop { get; set; } /// /// Gets or sets the start at preview. /// - public int StartAtPreview { get; set; } + public int? StartAtPreview { get; set; } + + /// + /// Gets or sets the seek points. + /// + public int? SeekPoints { get; set; } } } \ No newline at end of file diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Json/Factories/EncodeFactory.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Json/Factories/EncodeFactory.cs index 060821341..6d10b64eb 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/Json/Factories/EncodeFactory.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/Json/Factories/EncodeFactory.cs @@ -14,6 +14,7 @@ namespace HandBrake.Interop.Json.Factories using System.Globalization; using System.Linq; using System.Runtime.InteropServices; + using System.Windows.Media.Animation; using HandBrake.Interop.HbLib; using HandBrake.Interop.Helpers; @@ -31,6 +32,12 @@ namespace HandBrake.Interop.Json.Factories /// internal class EncodeFactory { + /* + * TODO: + * 1. OpenCL and HWD Support + * 2. Rotate Support + */ + /// /// The create. /// @@ -72,19 +79,32 @@ namespace HandBrake.Interop.Json.Factories /// private static Source CreateSource(EncodeJob job) { + Range range = new Range(); + switch (job.RangeType) + { + case VideoRangeType.Chapters: + range.ChapterEnd = job.ChapterEnd; + range.ChapterStart = job.ChapterStart; + break; + case VideoRangeType.Seconds: + range.PtsToStart = (int)(job.SecondsStart * 90000); + range.PtsToStop = (int)((job.SecondsEnd - job.SecondsStart) * 90000); + break; + case VideoRangeType.Frames: + range.FrameToStart = job.FramesStart; + range.FrameToStop = job.FramesEnd; + break; + case VideoRangeType.Preview: + range.StartAtPreview = job.StartAtPreview; + range.SeekPoints = job.SeekPoints; + range.PtsToStop = job.SecondsEnd * 90000; + break; + } + Source source = new Source { Title = job.Title, - Range = - new Range - { - ChapterEnd = job.ChapterEnd, - ChapterStart = job.ChapterStart, - FrameToStart = job.FramesStart, - FrameToStop = job.FramesEnd, - PtsToStart = (int)(job.SecondsStart * 90000), - PtsToStop = (int)((job.SecondsEnd - job.SecondsStart) * 90000), - }, + Range = range, Angle = job.Angle }; return source; diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/EncodeJob.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/EncodeJob.cs index 1f857a94f..cd54342a7 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/EncodeJob.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/EncodeJob.cs @@ -78,10 +78,21 @@ namespace HandBrake.Interop.Model /// public VideoRangeType RangeType { get; set; } + /// + /// Gets or sets the seek points. + /// This is the number of preview points. + /// + public int SeekPoints { get; set; } + + /// + /// Gets or sets the start at preview. + /// + public int StartAtPreview { get; set; } + /// /// Gets or sets the seconds end. /// - public double SecondsEnd { get; set; } + public int SecondsEnd { get; set; } /// /// Gets or sets the seconds start. diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/VideoRangeType.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/VideoRangeType.cs index afde441e5..6ffabf99f 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/VideoRangeType.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/VideoRangeType.cs @@ -19,8 +19,8 @@ namespace HandBrake.Interop.Model /// /// The entire title. /// - [Display(Name = "All")] - All, + [Display(Name = "Preview")] + Preview, /// /// A chapter range. diff --git a/win/CS/HandBrakeWPF/Factories/HBConfigurationFactory.cs b/win/CS/HandBrakeWPF/Factories/HBConfigurationFactory.cs index 8be9bcd41..c0ba00633 100644 --- a/win/CS/HandBrakeWPF/Factories/HBConfigurationFactory.cs +++ b/win/CS/HandBrakeWPF/Factories/HBConfigurationFactory.cs @@ -12,7 +12,6 @@ namespace HandBrakeWPF.Factories using Caliburn.Micro; using HandBrake.ApplicationServices.Model; - using HandBrake.ApplicationServices.Services.Interfaces; using HandBrakeWPF.Services.Interfaces; @@ -29,42 +28,27 @@ namespace HandBrakeWPF.Factories /// /// The create. /// - /// - /// The is logging enabled. - /// /// /// The . /// - public static HBConfiguration Create(bool isLoggingEnabled) + public static HBConfiguration Create() { HBConfiguration config = new HBConfiguration { - IsDvdNavDisabled = UserSettingService.GetUserSetting(UserSettingConstants.DisableLibDvdNav), - IsLoggingEnabled = isLoggingEnabled, - DisableQuickSyncDecoding = UserSettingService.GetUserSetting(UserSettingConstants.DisableQuickSyncDecoding), - EnableDxva = UserSettingService.GetUserSetting(UserSettingConstants.EnableDxva), - ScalingMode = UserSettingService.GetUserSetting(UserSettingConstants.ScalingMode), - PreviewScanCount = UserSettingService.GetUserSetting(UserSettingConstants.PreviewScanCount), - Verbosity = UserSettingService.GetUserSetting(UserSettingConstants.Verbosity), - MinScanDuration = UserSettingService.GetUserSetting(UserSettingConstants.MinScanDuration), - ProcessPriority = UserSettingService.GetUserSetting(UserSettingConstants.ProcessPriority), - SaveLogToCopyDirectory = UserSettingService.GetUserSetting(UserSettingConstants.SaveLogToCopyDirectory), - SaveLogWithVideo = UserSettingService.GetUserSetting(UserSettingConstants.SaveLogWithVideo), - SaveLogCopyDirectory = UserSettingService.GetUserSetting(UserSettingConstants.SaveLogCopyDirectory), + IsDvdNavDisabled = UserSettingService.GetUserSetting(UserSettingConstants.DisableLibDvdNav), + DisableQuickSyncDecoding = UserSettingService.GetUserSetting(UserSettingConstants.DisableQuickSyncDecoding), + EnableDxva = UserSettingService.GetUserSetting(UserSettingConstants.EnableDxva), + ScalingMode = UserSettingService.GetUserSetting(UserSettingConstants.ScalingMode), + PreviewScanCount = UserSettingService.GetUserSetting(UserSettingConstants.PreviewScanCount), + Verbosity = UserSettingService.GetUserSetting(UserSettingConstants.Verbosity), + MinScanDuration = UserSettingService.GetUserSetting(UserSettingConstants.MinScanDuration), + ProcessPriority = UserSettingService.GetUserSetting(UserSettingConstants.ProcessPriority), + SaveLogToCopyDirectory = UserSettingService.GetUserSetting(UserSettingConstants.SaveLogToCopyDirectory), + SaveLogWithVideo = UserSettingService.GetUserSetting(UserSettingConstants.SaveLogWithVideo), + SaveLogCopyDirectory = UserSettingService.GetUserSetting(UserSettingConstants.SaveLogCopyDirectory), }; return config; } - - /// - /// The create. - /// - /// - /// The . - /// - public static HBConfiguration Create() - { - return Create(true); - } } } diff --git a/win/CS/HandBrakeWPF/ViewModels/PreviewViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/PreviewViewModel.cs index 693d7a459..f117b9ef5 100644 --- a/win/CS/HandBrakeWPF/ViewModels/PreviewViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/PreviewViewModel.cs @@ -302,9 +302,9 @@ namespace HandBrakeWPF.ViewModels // Setup the encode task as a preview encode encodeTask.IsPreviewEncode = true; - encodeTask.PreviewEncodeStartAt = this.StartAt.ToString(CultureInfo.InvariantCulture); + encodeTask.PreviewEncodeStartAt = this.StartAt; encodeTask.PreviewEncodeDuration = this.Duration; - QueueTask task = new QueueTask(encodeTask, HBConfigurationFactory.Create(false)); + QueueTask task = new QueueTask(encodeTask, HBConfigurationFactory.Create()); ThreadPool.QueueUserWorkItem(this.CreatePreview, task); } diff --git a/win/CS/HandBrakeWPF/ViewModels/StaticPreviewViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/StaticPreviewViewModel.cs index a910c272b..7f94f5d4c 100644 --- a/win/CS/HandBrakeWPF/ViewModels/StaticPreviewViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/StaticPreviewViewModel.cs @@ -20,6 +20,7 @@ namespace HandBrakeWPF.ViewModels using HandBrake.ApplicationServices.Services.Scan.Interfaces; using HandBrake.Interop.Model.Encoding; + using HandBrakeWPF.Factories; using HandBrakeWPF.ViewModels.Interfaces; /// @@ -250,7 +251,7 @@ namespace HandBrakeWPF.ViewModels BitmapImage image = null; try { - image = this.scanService.GetPreview(this.Task, this.SelectedPreviewImage); + image = this.scanService.GetPreview(this.Task, this.SelectedPreviewImage, HBConfigurationFactory.Create()); } catch (Exception exc) { diff --git a/win/CS/HandBrakeWPF/Views/AudioView.xaml b/win/CS/HandBrakeWPF/Views/AudioView.xaml index ab2db0dbd..21a3dd59d 100644 --- a/win/CS/HandBrakeWPF/Views/AudioView.xaml +++ b/win/CS/HandBrakeWPF/Views/AudioView.xaml @@ -82,7 +82,7 @@