]> granicus.if.org Git - handbrake/commitdiff
WinGui: Stub the RemoteInstance implementation of IEncodeInstance.
authorsr55 <sr55.hb@outlook.com>
Sun, 10 Jun 2018 12:46:17 +0000 (13:46 +0100)
committersr55 <sr55.hb@outlook.com>
Sun, 10 Jun 2018 12:46:17 +0000 (13:46 +0100)
win/CS/HandBrakeWPF/HandBrakeWPF.csproj
win/CS/HandBrakeWPF/Instance/RemoteInstance.cs [new file with mode: 0644]

index 0131e9297e499d74d536e9d7447a1a7eb647d552..1c1d4da4222ed594640b70e748cfe95b11f46f74 100644 (file)
     <Compile Include="Helpers\MP4Helper.cs" />\r
     <Compile Include="Helpers\TimeSpanHelper.cs" />\r
     <Compile Include="Helpers\Validate.cs" />\r
+    <Compile Include="Instance\RemoteInstance.cs" />\r
     <Compile Include="Model\Audio\AudioBehaviourTrack.cs" />\r
     <Compile Include="Model\Audio\AudioTrackDefaultsMode.cs" />\r
     <Compile Include="Model\Audio\AudioBehaviourModes.cs" />\r
diff --git a/win/CS/HandBrakeWPF/Instance/RemoteInstance.cs b/win/CS/HandBrakeWPF/Instance/RemoteInstance.cs
new file mode 100644 (file)
index 0000000..bfefb6c
--- /dev/null
@@ -0,0 +1,88 @@
+// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="RemoteInstance.cs" company="HandBrake Project (http://handbrake.fr)">
+//   This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
+// </copyright>
+// <summary>
+//   An Implementation of IEncodeInstance that works with a remote process rather than locally in-process.
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrakeWPF.Instance
+{
+    using System;
+    using System.Diagnostics;
+
+    using HandBrake.Interop.Interop.EventArgs;
+    using HandBrake.Interop.Interop.Interfaces;
+    using HandBrake.Interop.Interop.Json.Encode;
+
+    public class RemoteInstance : IEncodeInstance
+    {
+        private Process workerProcess;
+
+        public event EventHandler<EncodeCompletedEventArgs> EncodeCompleted;
+
+        public event EventHandler<EncodeProgressEventArgs> EncodeProgress;
+
+        public void PauseEncode()
+        {
+            throw new NotImplementedException();
+        }
+
+        public void ResumeEncode()
+        {
+            throw new NotImplementedException();
+        }
+
+        public void StartEncode(JsonEncodeObject jobToStart)
+        {
+            throw new NotImplementedException();
+        }
+
+        public void StopEncode()
+        {
+            throw new NotImplementedException();
+        }
+
+        protected virtual void OnEncodeCompleted(EncodeCompletedEventArgs e)
+        {
+            this.EncodeCompleted?.Invoke(this, e);
+        }
+
+        protected virtual void OnEncodeProgress(EncodeProgressEventArgs e)
+        {
+            this.EncodeProgress?.Invoke(this, e);
+        }
+
+        private void StartServer()
+        {
+            if (this.workerProcess == null || this.workerProcess.HasExited)
+            {
+                this.workerProcess = new Process();
+
+                // TODO Take default port from preferences, then find a usable port thereafter.
+                this.workerProcess.StartInfo =
+                    new ProcessStartInfo("HandBrake.Worker.exe", "--port=8080")
+                        {
+                            WindowStyle = ProcessWindowStyle.Normal
+                        };
+
+                this.workerProcess.Start();
+                this.workerProcess.Exited += this.WorkerProcess_Exited;
+            }
+        }
+
+        private void WorkerProcess_Exited(object sender, EventArgs e)
+        {
+            Debug.WriteLine("Worker Process has exited");
+        }
+
+        private void StopServer()
+        {
+            if (this.workerProcess != null && !this.workerProcess.HasExited)
+            {
+                this.workerProcess.Kill();
+            }
+        }
+    }
+}