summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrake.ApplicationServices
diff options
context:
space:
mode:
Diffstat (limited to 'win/CS/HandBrake.ApplicationServices')
-rw-r--r--win/CS/HandBrake.ApplicationServices/Isolation/IsolatedEncodeService.cs25
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/Encode.cs33
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/Interfaces/IEncode.cs15
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/LibEncode.cs140
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/LibScan.cs1
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/ServerService.cs5
-rw-r--r--win/CS/HandBrake.ApplicationServices/Utilities/InteropModelCreator.cs163
7 files changed, 260 insertions, 122 deletions
diff --git a/win/CS/HandBrake.ApplicationServices/Isolation/IsolatedEncodeService.cs b/win/CS/HandBrake.ApplicationServices/Isolation/IsolatedEncodeService.cs
index 31c1d8cec..2f29d7054 100644
--- a/win/CS/HandBrake.ApplicationServices/Isolation/IsolatedEncodeService.cs
+++ b/win/CS/HandBrake.ApplicationServices/Isolation/IsolatedEncodeService.cs
@@ -93,6 +93,17 @@ namespace HandBrake.ApplicationServices.Isolation
}
/// <summary>
+ /// Gets a value indicating whether can pause.
+ /// </summary>
+ public bool CanPause
+ {
+ get
+ {
+ return false; // TODO make this work.
+ }
+ }
+
+ /// <summary>
/// Gets a value indicating whether IsEncoding.
/// </summary>
public bool IsEncoding
@@ -172,6 +183,20 @@ namespace HandBrake.ApplicationServices.Isolation
}
/// <summary>
+ /// The pause.
+ /// </summary>
+ public void Pause()
+ {
+ }
+
+ /// <summary>
+ /// The resume.
+ /// </summary>
+ public void Resume()
+ {
+ }
+
+ /// <summary>
/// Kill the CLI process
/// </summary>
public void Stop()
diff --git a/win/CS/HandBrake.ApplicationServices/Services/Encode.cs b/win/CS/HandBrake.ApplicationServices/Services/Encode.cs
index 4779d353e..806c08fa5 100644
--- a/win/CS/HandBrake.ApplicationServices/Services/Encode.cs
+++ b/win/CS/HandBrake.ApplicationServices/Services/Encode.cs
@@ -74,6 +74,17 @@ namespace HandBrake.ApplicationServices.Services
/// </summary>
protected Process HbProcess { get; set; }
+ /// <summary>
+ /// Gets a value indicating whether can pause.
+ /// </summary>
+ public bool CanPause
+ {
+ get
+ {
+ return false;
+ }
+ }
+
#endregion
#region Public Methods
@@ -202,6 +213,28 @@ namespace HandBrake.ApplicationServices.Services
}
/// <summary>
+ /// The pause.
+ /// </summary>
+ /// <exception cref="NotImplementedException">
+ /// This feature is not available for CLI based encoding.
+ /// </exception>
+ public void Pause()
+ {
+ throw new NotImplementedException("This feature is not available for CLI based encoding.");
+ }
+
+ /// <summary>
+ /// The resume.
+ /// </summary>
+ /// <exception cref="NotImplementedException">
+ /// This feature is not available for CLI based encoding.
+ /// </exception>
+ public void Resume()
+ {
+ throw new NotImplementedException("This feature is not available for CLI based encoding.");
+ }
+
+ /// <summary>
/// Kill the CLI process
/// </summary>
public override void Stop()
diff --git a/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IEncode.cs b/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IEncode.cs
index fbb59ec2b..8d70247f7 100644
--- a/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IEncode.cs
+++ b/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IEncode.cs
@@ -72,6 +72,11 @@ namespace HandBrake.ApplicationServices.Services.Interfaces
int LogIndex { get; }
/// <summary>
+ /// Gets a value indicating whether can pause.
+ /// </summary>
+ bool CanPause { get; }
+
+ /// <summary>
/// Start with a LibHb EncodeJob Object
/// </summary>
/// <param name="job">
@@ -83,6 +88,16 @@ namespace HandBrake.ApplicationServices.Services.Interfaces
void Start(QueueTask job, bool enableLogging);
/// <summary>
+ /// The pause.
+ /// </summary>
+ void Pause();
+
+ /// <summary>
+ /// The resume.
+ /// </summary>
+ void Resume();
+
+ /// <summary>
/// Kill the CLI process
/// </summary>
void Stop();
diff --git a/win/CS/HandBrake.ApplicationServices/Services/LibEncode.cs b/win/CS/HandBrake.ApplicationServices/Services/LibEncode.cs
index f7247f6cf..f6da448ac 100644
--- a/win/CS/HandBrake.ApplicationServices/Services/LibEncode.cs
+++ b/win/CS/HandBrake.ApplicationServices/Services/LibEncode.cs
@@ -42,14 +42,14 @@ namespace HandBrake.ApplicationServices.Services
private readonly IUserSettingService userSettingService;
/// <summary>
- /// The Start time of the current Encode;
+ /// The instance.
/// </summary>
- private DateTime startTime;
+ private IHandBrakeInstance instance;
/// <summary>
- /// An Instance of the HandBrake Interop Library
+ /// The Start time of the current Encode;
/// </summary>
- private IHandBrakeInstance instance;
+ private DateTime startTime;
/// <summary>
/// A flag to indicate if logging is enabled or not.
@@ -69,24 +69,27 @@ namespace HandBrake.ApplicationServices.Services
/// <param name="userSettingService">
/// The user Setting Service.
/// </param>
- /// <param name="handBrakeInstance">
- /// The hand Brake Instance.
- /// </param>
- public LibEncode(IUserSettingService userSettingService, IHandBrakeInstance handBrakeInstance)
+ public LibEncode(IUserSettingService userSettingService)
: base(userSettingService)
{
this.userSettingService = userSettingService;
- // Setup the HandBrake Instance
- this.instance = handBrakeInstance;
- this.instance.EncodeCompleted += this.InstanceEncodeCompleted;
- this.instance.EncodeProgress += this.InstanceEncodeProgress;
-
HandBrakeUtils.MessageLogged += this.HandBrakeInstanceMessageLogged;
HandBrakeUtils.ErrorLogged += this.HandBrakeInstanceErrorLogged;
}
/// <summary>
+ /// Gets a value indicating whether can pause.
+ /// </summary>
+ public bool CanPause
+ {
+ get
+ {
+ return true;
+ }
+ }
+
+ /// <summary>
/// Start with a LibHb EncodeJob Object
/// </summary>
/// <param name="job">
@@ -97,10 +100,18 @@ namespace HandBrake.ApplicationServices.Services
/// </param>
public void Start(QueueTask job, bool enableLogging)
{
+ // Setup
this.startTime = DateTime.Now;
this.loggingEnabled = enableLogging;
this.currentTask = job;
+ // Create a new HandBrake instance
+ // Setup the HandBrake Instance
+ instance = new HandBrakeInstance();
+ instance.Initialize(1);
+ instance.EncodeCompleted += this.InstanceEncodeCompleted;
+ instance.EncodeProgress += this.InstanceEncodeProgress;
+
try
{
// Sanity Checking and Setup
@@ -111,9 +122,6 @@ namespace HandBrake.ApplicationServices.Services
this.IsEncoding = true;
- // Get an EncodeJob object for the Interop Library
- EncodeJob encodeJob = InteropModelCreator.GetEncodeJob(job);
-
// Enable logging if required.
if (enableLogging)
{
@@ -131,34 +139,14 @@ namespace HandBrake.ApplicationServices.Services
// Verify the Destination Path Exists, and if not, create it.
this.VerifyEncodeDestinationPath(job);
- // Start the Encode
- this.instance.StartEncode(encodeJob);
-
- // Set the Process Priority
- switch (this.userSettingService.GetUserSetting<string>(ASUserSettingConstants.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;
- }
+ // 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.
+ instance.StartScan(job.Task.Source, 1, job.Task.Title);
- // Fire the Encode Started Event
- this.InvokeEncodeStarted(EventArgs.Empty);
+ instance.ScanCompleted += delegate
+ {
+ ScanCompleted(job, instance);
+ };
}
catch (Exception exc)
{
@@ -167,6 +155,28 @@ namespace HandBrake.ApplicationServices.Services
}
/// <summary>
+ /// Pause the currently running encode.
+ /// </summary>
+ public void Pause()
+ {
+ if (this.instance != null)
+ {
+ this.instance.PauseEncode();
+ }
+ }
+
+ /// <summary>
+ /// Resume the currently running encode.
+ /// </summary>
+ public void Resume()
+ {
+ if (this.instance != null)
+ {
+ this.instance.ResumeEncode();
+ }
+ }
+
+ /// <summary>
/// Kill the CLI process
/// </summary>
public override void Stop()
@@ -190,6 +200,50 @@ namespace HandBrake.ApplicationServices.Services
// Nothing to do for this implementation.
}
+ /// <summary>
+ /// The scan completed.
+ /// </summary>
+ /// <param name="job">
+ /// The job.
+ /// </param>
+ /// <param name="instance">
+ /// The instance.
+ /// </param>
+ private void ScanCompleted(QueueTask job, IHandBrakeInstance instance)
+ {
+ // Get an EncodeJob object for the Interop Library
+ EncodeJob encodeJob = InteropModelCreator.GetEncodeJob(job);
+
+ // Start the Encode
+ instance.StartEncode(encodeJob);
+
+ // Fire the Encode Started Event
+ this.InvokeEncodeStarted(EventArgs.Empty);
+
+ // Set the Process Priority
+ switch (this.userSettingService.GetUserSetting<string>(ASUserSettingConstants.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;
+ }
+ }
+
#region HandBrakeInstance Event Handlers.
/// <summary>
/// Log a message
diff --git a/win/CS/HandBrake.ApplicationServices/Services/LibScan.cs b/win/CS/HandBrake.ApplicationServices/Services/LibScan.cs
index 157380b8c..a6a634b53 100644
--- a/win/CS/HandBrake.ApplicationServices/Services/LibScan.cs
+++ b/win/CS/HandBrake.ApplicationServices/Services/LibScan.cs
@@ -13,7 +13,6 @@ namespace HandBrake.ApplicationServices.Services
using System.Collections.Generic;
using System.IO;
using System.Text;
- using System.Threading;
using HandBrake.ApplicationServices.EventArgs;
using HandBrake.ApplicationServices.Model.Encoding;
diff --git a/win/CS/HandBrake.ApplicationServices/Services/ServerService.cs b/win/CS/HandBrake.ApplicationServices/Services/ServerService.cs
index 4e0039c55..ab0acd596 100644
--- a/win/CS/HandBrake.ApplicationServices/Services/ServerService.cs
+++ b/win/CS/HandBrake.ApplicationServices/Services/ServerService.cs
@@ -16,8 +16,6 @@ namespace HandBrake.ApplicationServices.Services
using HandBrake.ApplicationServices.Model;
using HandBrake.ApplicationServices.Services.Interfaces;
- using HandBrake.Interop;
- using HandBrake.Interop.Interfaces;
using EncodeCompletedEventArgs = HandBrake.ApplicationServices.EventArgs.EncodeCompletedEventArgs;
using EncodeProgressEventArgs = HandBrake.ApplicationServices.EventArgs.EncodeProgressEventArgs;
@@ -104,8 +102,7 @@ namespace HandBrake.ApplicationServices.Services
Console.WriteLine("Service Started. Waiting for Clients...");
// Setup the services we are going to use.
- IHandBrakeInstance instance = new HandBrakeInstance();
- encodeService = new LibEncode(new UserSettingService(), instance); // TODO this needs wired up with castle
+ encodeService = new LibEncode(new UserSettingService()); // TODO this needs wired up with castle
shutdownFlag = new ManualResetEvent(false);
shutdownFlag.WaitOne();
diff --git a/win/CS/HandBrake.ApplicationServices/Utilities/InteropModelCreator.cs b/win/CS/HandBrake.ApplicationServices/Utilities/InteropModelCreator.cs
index b6a50485f..81b4a63c1 100644
--- a/win/CS/HandBrake.ApplicationServices/Utilities/InteropModelCreator.cs
+++ b/win/CS/HandBrake.ApplicationServices/Utilities/InteropModelCreator.cs
@@ -17,6 +17,7 @@ namespace HandBrake.ApplicationServices.Utilities
using HandBrake.ApplicationServices.Model.Encoding;
using HandBrake.Interop.Model;
using HandBrake.Interop.Model.Encoding;
+ using HandBrake.Interop.Model.Encoding.x264;
/// <summary>
/// A Utility Class to Convert a
@@ -45,12 +46,10 @@ namespace HandBrake.ApplicationServices.Utilities
// Which will be converted to this EncodeJob Model.
EncodeJob job = new EncodeJob();
-
EncodingProfile profile = new EncodingProfile();
job.EncodingProfile = profile;
- profile.Anamorphic = work.Anamorphic;
-
+ // Audio Settings
profile.AudioEncodings = new List<AudioEncoding>();
job.ChosenAudioTracks = new List<int>();
foreach (AudioTrack track in work.AudioTracks)
@@ -63,7 +62,7 @@ namespace HandBrake.ApplicationServices.Utilities
Encoder = Converters.GetCliAudioEncoder(track.Encoder),
InputNumber = track.Track.HasValue ? track.Track.Value : 0,
Mixdown = Converters.GetCliMixDown(track.MixDown),
- SampleRateRaw = GetSampleRateRaw(track.SampleRate),
+ SampleRateRaw = GetSampleRateRaw(track.SampleRate),
};
profile.AudioEncodings.Add(newTrack);
@@ -72,6 +71,60 @@ namespace HandBrake.ApplicationServices.Utilities
job.ChosenAudioTracks.Add(track.Track.Value);
}
}
+
+ // Title Settings
+ job.OutputPath = work.Destination;
+ job.SourcePath = work.Source;
+ job.Title = work.Title;
+ // job.SourceType = work.Type;
+ switch (work.PointToPointMode)
+ {
+ case PointToPointMode.Chapters:
+ job.RangeType = VideoRangeType.Chapters;
+ break;
+ case PointToPointMode.Seconds:
+ job.RangeType = VideoRangeType.Seconds;
+ break;
+ case PointToPointMode.Frames:
+ job.RangeType = VideoRangeType.Frames;
+ break;
+ }
+
+ if (work.PointToPointMode == PointToPointMode.Seconds)
+ {
+ job.SecondsEnd = work.EndPoint;
+ job.SecondsStart = work.StartPoint;
+ }
+ if (work.PointToPointMode == PointToPointMode.Chapters)
+ {
+ job.ChapterStart = work.StartPoint;
+ job.ChapterEnd = work.EndPoint;
+ }
+ if (work.PointToPointMode == PointToPointMode.Frames)
+ {
+ job.FramesEnd = work.EndPoint;
+ job.FramesStart = work.StartPoint;
+ }
+
+ job.Angle = work.Angle;
+ job.EncodingProfile = profile;
+
+ // Output Settings
+ profile.IPod5GSupport = work.IPod5GSupport;
+ profile.Optimize = work.OptimizeMP4;
+ switch (work.OutputFormat)
+ {
+ case OutputFormat.Mp4:
+ case OutputFormat.M4V:
+ profile.OutputFormat = Container.Mp4;
+ break;
+ case OutputFormat.Mkv:
+ profile.OutputFormat = Container.Mkv;
+ break;
+ }
+
+ // Picture Settings
+ profile.Anamorphic = work.Anamorphic;
profile.Cropping = new Cropping
{
Top = work.Cropping.Top,
@@ -79,101 +132,63 @@ namespace HandBrake.ApplicationServices.Utilities
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.PixelAspectX = work.PixelAspectX;
+ profile.PixelAspectY = work.PixelAspectY;
+ profile.Height = work.Height.HasValue ? work.Height.Value : 0;
+ profile.KeepDisplayAspect = work.KeepDisplayAspect;
+ profile.MaxHeight = work.MaxHeight.HasValue ? work.MaxHeight.Value : 0;
+ profile.MaxWidth = work.MaxWidth.HasValue ? work.MaxWidth.Value : 0;
+ profile.Modulus = work.Modulus.HasValue ? work.Modulus.Value : 16;
+ profile.UseDisplayWidth = true;
+ profile.Width = work.Width.HasValue ? work.Width.Value : 0;
+
+ // Filter Settings
profile.CustomDecomb = work.CustomDecomb;
profile.CustomDeinterlace = work.CustomDeinterlace;
profile.CustomDenoise = work.CustomDenoise;
profile.CustomDetelecine = work.CustomDetelecine;
- profile.Deblock = work.Deblock;
+ if (work.Deblock > 4)
+ profile.Deblock = work.Deblock;
profile.Decomb = work.Decomb;
profile.Deinterlace = work.Deinterlace;
profile.Denoise = work.Denoise;
profile.Detelecine = work.Detelecine;
- profile.DisplayWidth = work.DisplayWidth.HasValue
- ? int.Parse(Math.Round(work.DisplayWidth.Value, 0).ToString())
- : 0;
- profile.Framerate = work.Framerate.HasValue ? work.Framerate.Value : 0;
profile.Grayscale = work.Grayscale;
- profile.Height = work.Height.HasValue ? work.Height.Value : 0;
- profile.IPod5GSupport = work.IPod5GSupport;
- profile.IncludeChapterMarkers = work.IncludeChapterMarkers;
- profile.KeepDisplayAspect = work.KeepDisplayAspect;
- profile.MaxHeight = work.MaxHeight.HasValue ? work.MaxHeight.Value : 0;
- profile.MaxWidth = work.MaxWidth.HasValue ? work.MaxWidth.Value : 0;
- profile.Modulus = work.Modulus.HasValue ? work.Modulus.Value : 16;
- profile.Optimize = work.OptimizeMP4;
- switch (work.OutputFormat)
- {
- case OutputFormat.Mp4:
- case OutputFormat.M4V:
- profile.OutputFormat = Container.Mp4;
- break;
- case OutputFormat.Mkv:
- profile.OutputFormat = Container.Mkv;
- break;
- }
- profile.ConstantFramerate = work.FramerateMode == FramerateMode.CFR;
- profile.PixelAspectX = work.PixelAspectX;
- profile.PixelAspectY = work.PixelAspectY;
- switch (work.OutputFormat)
- {
- case OutputFormat.Mp4:
- profile.PreferredExtension = OutputExtension.Mp4;
- break;
- case OutputFormat.M4V:
- profile.PreferredExtension = OutputExtension.M4v;
- break;
- }
+ // Video Settings
+ profile.Framerate = work.Framerate.HasValue ? work.Framerate.Value : 0;
+ profile.ConstantFramerate = work.FramerateMode == FramerateMode.CFR;
profile.Quality = work.Quality.HasValue ? work.Quality.Value : 0;
- profile.UseDisplayWidth = true;
profile.VideoBitrate = work.VideoBitrate.HasValue ? work.VideoBitrate.Value : 0;
profile.VideoEncodeRateType = work.VideoEncodeRateType;
profile.VideoEncoder = Converters.GetVideoEncoder(work.VideoEncoder);
- profile.Width = work.Width.HasValue ? work.Width.Value : 0;
- profile.X264Options = work.AdvancedEncoderOptions;
- if (work.PointToPointMode == PointToPointMode.Chapters)
+ profile.H264Level = work.H264Level;
+ profile.X264Profile = work.H264Profile.ToString().ToLower().Replace(" ", string.Empty); // TODO change these away from strings.
+ profile.X264Preset = work.X264Preset.ToString().ToLower().Replace(" ", string.Empty);
+ profile.X264Tunes = new List<string>();
+
+ if (work.X264Tune != x264Tune.None)
{
- job.ChapterStart = work.StartPoint;
- job.ChapterEnd = work.EndPoint;
+ profile.X264Tunes.Add(work.X264Tune.ToString().ToLower().Replace(" ", string.Empty));
}
- job.Angle = work.Angle;
- job.EncodingProfile = profile;
- if (work.PointToPointMode == PointToPointMode.Frames)
+ if (work.FastDecode)
{
- job.FramesEnd = work.EndPoint;
- job.FramesStart = work.StartPoint;
+ profile.X264Tunes.Add("fastdecode");
}
+ // Chapter Markers
+ profile.IncludeChapterMarkers = work.IncludeChapterMarkers;
job.CustomChapterNames = work.ChapterNames.Select(item => item.ChapterName).ToList();
job.UseDefaultChapterNames = work.IncludeChapterMarkers;
- job.OutputPath = work.Destination;
- switch (work.PointToPointMode)
- {
- case PointToPointMode.Chapters:
- job.RangeType = VideoRangeType.Chapters;
- break;
- case PointToPointMode.Seconds:
- job.RangeType = VideoRangeType.Seconds;
- break;
- case PointToPointMode.Frames:
- job.RangeType = VideoRangeType.Frames;
- break;
- }
-
- if (work.PointToPointMode == PointToPointMode.Seconds)
- {
- job.SecondsEnd = work.EndPoint;
- job.SecondsStart = work.StartPoint;
- }
-
- job.SourcePath = work.Source;
- // job.SourceType = work.Type;
- job.Title = work.Title;
+ // Advanced Settings
+ profile.X264Options = work.AdvancedEncoderOptions;
// Subtitles
job.Subtitles = new Subtitles { SourceSubtitles = new List<SourceSubtitle>(), SrtSubtitles = new List<SrtSubtitle>() };