summaryrefslogtreecommitdiffstats
path: root/win
diff options
context:
space:
mode:
authorsr55 <[email protected]>2020-04-10 20:28:16 +0100
committersr55 <[email protected]>2020-04-10 20:28:16 +0100
commitb0a2c68ee60bd3d15889fa41cf1879c276a9e1b8 (patch)
tree52cf128eb55652d65d944e96e43c685b0c15da9f /win
parent0abc8cb07a4d6ca27d0a0c300a78957b610b773e (diff)
WinGui:
- Adding multi-instance support in the UI for the worker process. - Handling port conflicts better. It will now try up to 100 ports from the default port set in preferences.
Diffstat (limited to 'win')
-rw-r--r--win/CS/HandBrake.Worker/Program.cs7
-rw-r--r--win/CS/HandBrakeWPF/Instance/RemoteInstance.cs32
-rw-r--r--win/CS/HandBrakeWPF/Properties/Resources.Designer.cs2
-rw-r--r--win/CS/HandBrakeWPF/Properties/Resources.resx2
-rw-r--r--win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs23
-rw-r--r--win/CS/HandBrakeWPF/Services/UserSettingService.cs2
6 files changed, 55 insertions, 13 deletions
diff --git a/win/CS/HandBrake.Worker/Program.cs b/win/CS/HandBrake.Worker/Program.cs
index 74114bd9e..f925ade38 100644
--- a/win/CS/HandBrake.Worker/Program.cs
+++ b/win/CS/HandBrake.Worker/Program.cs
@@ -41,17 +41,16 @@ namespace HandBrake.Worker
}
}
- Console.WriteLine("Starting HandBrake Engine ...");
+ Console.WriteLine("Worker: Starting HandBrake Engine ...");
router = new ApiRouter();
router.TerminationEvent += Router_TerminationEvent;
- Console.WriteLine("Starting Web Server ...");
- Console.WriteLine("Using Port: {0}", port);
+ Console.WriteLine("Worker: Starting Web Server on port {0} ...", port);
Dictionary<string, Func<HttpListenerRequest, string>> apiHandlers = RegisterApiHandlers();
HttpServer webServer = new HttpServer(apiHandlers, port);
webServer.Run();
- Console.WriteLine("Web Server Started");
+ Console.WriteLine("Worker: Server Started");
manualResetEvent.WaitOne();
diff --git a/win/CS/HandBrakeWPF/Instance/RemoteInstance.cs b/win/CS/HandBrakeWPF/Instance/RemoteInstance.cs
index 847e9cf4c..1d11c1cce 100644
--- a/win/CS/HandBrakeWPF/Instance/RemoteInstance.cs
+++ b/win/CS/HandBrakeWPF/Instance/RemoteInstance.cs
@@ -11,8 +11,12 @@
namespace HandBrakeWPF.Instance
{
using System;
+ using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
+ using System.Linq;
+ using System.Net;
+ using System.Net.NetworkInformation;
using System.Threading.Tasks;
using System.Timers;
using System.Windows.Media.Animation;
@@ -46,7 +50,7 @@ namespace HandBrakeWPF.Instance
private readonly ILog logService;
- private const double EncodePollIntervalMs = 250;
+ private const double EncodePollIntervalMs = 500;
private Process workerProcess;
private Timer encodePollTimer;
@@ -56,7 +60,7 @@ namespace HandBrakeWPF.Instance
{
this.configuration = configuration;
this.logService = logService;
- this.port = configuration.RemoteServicePort;
+ this.port = this.GetOpenPort(this.configuration.RemoteServicePort);
this.serverUrl = string.Format("http://127.0.0.1:{0}/", this.port);
}
@@ -139,7 +143,7 @@ namespace HandBrakeWPF.Instance
StartInfo =
{
FileName = "HandBrake.Worker.exe",
- Arguments = string.Format(" --port={0}", this.port),
+ Arguments = string.Format(" --port={0}", port),
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
@@ -155,7 +159,7 @@ namespace HandBrakeWPF.Instance
workerProcess.BeginErrorReadLine();
- this.logService.LogMessage(string.Format("Worker Process started with Process ID: {0}", this.workerProcess.Id));
+ this.logService.LogMessage(string.Format("Worker Process started with Process ID: {0} and port: {1}", this.workerProcess.Id, port));
}
}
@@ -267,5 +271,25 @@ namespace HandBrakeWPF.Instance
this.EncodeCompleted?.Invoke(sender: this, e: new EncodeCompletedEventArgs(state.WorkDone.Error));
}
}
+
+ private int GetOpenPort(int startPort)
+ {
+ int portStartIndex = startPort;
+
+ IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties();
+ IPEndPoint[] tcpEndPoints = properties.GetActiveTcpListeners();
+
+ List<int> usedPorts = tcpEndPoints.Select(p => p.Port).ToList<int>();
+ int unusedPort = 0;
+
+ unusedPort = Enumerable.Range(portStartIndex, 99).FirstOrDefault(p => !usedPorts.Contains(p));
+
+ if (startPort != unusedPort)
+ {
+ this.logService.LogMessage(string.Format("Port {0} in use. Using {1} instead", startPort, unusedPort));
+ }
+
+ return unusedPort;
+ }
}
}
diff --git a/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs b/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs
index d89147d4f..be72f0b9d 100644
--- a/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs
+++ b/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs
@@ -3447,7 +3447,7 @@ namespace HandBrakeWPF.Properties {
}
/// <summary>
- /// Looks up a localized string similar to Run each queued job in a separate worker process. (Experimental! Note, Limited to one instance of HandBrake currently!).
+ /// Looks up a localized string similar to Run each queued job in a separate worker process. (Experimental).
/// </summary>
public static string OptionsView_EnableWorkerProcesses {
get {
diff --git a/win/CS/HandBrakeWPF/Properties/Resources.resx b/win/CS/HandBrakeWPF/Properties/Resources.resx
index f1b86d39e..7acca6007 100644
--- a/win/CS/HandBrakeWPF/Properties/Resources.resx
+++ b/win/CS/HandBrakeWPF/Properties/Resources.resx
@@ -2210,7 +2210,7 @@ This will also stop any existing running jobs.</value>
<value>Please select a single job to view summary information.</value>
</data>
<data name="OptionsView_EnableWorkerProcesses" xml:space="preserve">
- <value>Run each queued job in a separate worker process. (Experimental! Note, Limited to one instance of HandBrake currently!)</value>
+ <value>Run each queued job in a separate worker process. (Experimental)</value>
</data>
<data name="OptionsView_WorkerDefaultPort" xml:space="preserve">
<value>Default network port for worker:</value>
diff --git a/win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs b/win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs
index c59326f4e..02e5dc2c4 100644
--- a/win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs
+++ b/win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs
@@ -200,7 +200,7 @@ namespace HandBrakeWPF.Services.Encode
/// <param name="message">Log message content</param>
protected void ServiceLogMessage(string message)
{
- this.log.LogMessage(string.Format("{0}# {1}{0}", Environment.NewLine, message));
+ this.log.LogMessage(string.Format("{0}# {1}", Environment.NewLine, message));
}
protected void TimedLogMessage(string message)
@@ -249,7 +249,26 @@ namespace HandBrakeWPF.Services.Encode
{
this.IsEncoding = false;
- this.ServiceLogMessage(e.Error != 0 ? string.Format("Encode Failed ({0})", e.Error) : "Encode Completed!");
+ string completeMessage = "Job Completed!";
+ switch (e.Error)
+ {
+ case 0:
+ break;
+ case 1:
+ completeMessage = "Job Cancelled!";
+ break;
+ case 2:
+ completeMessage = string.Format("Job Failed. Check log and input settings ({0})", e.Error);
+ break;
+ case 3:
+ completeMessage = string.Format("Job Failed to Initialise. Check log and input settings ({0})", e.Error);
+ break;
+ default:
+ completeMessage = string.Format("Job Failed ({0})", e.Error);
+ break;
+ }
+
+ this.ServiceLogMessage(completeMessage);
// Handling Log Data
string hbLog = this.ProcessLogs(this.currentTask.Destination, this.isPreviewInstance, this.currentConfiguration);
diff --git a/win/CS/HandBrakeWPF/Services/UserSettingService.cs b/win/CS/HandBrakeWPF/Services/UserSettingService.cs
index 4c181541a..1570e6f85 100644
--- a/win/CS/HandBrakeWPF/Services/UserSettingService.cs
+++ b/win/CS/HandBrakeWPF/Services/UserSettingService.cs
@@ -304,7 +304,7 @@ namespace HandBrakeWPF.Services
defaults.Add(UserSettingConstants.DefaultPlayer, false);
// Experimental
- defaults.Add(UserSettingConstants.RemoteServiceEnabled, false);
+ defaults.Add(UserSettingConstants.RemoteServiceEnabled, true);
defaults.Add(UserSettingConstants.RemoteServicePort, 8037);
// Misc