diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2015-03-02 14:46:28 -0500 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2015-03-02 14:46:28 -0500 |
| commit | 12ba57d4232eb1c38af8a47dbc0fad90ad8941cb (patch) | |
| tree | 6a82899207dbbda49107ad1c05da9c7d85107b8f | |
| parent | f3159f3feff6a0ef11edb50cfc456f8c43d26d79 (diff) | |
adjust process throttle
4 files changed, 82 insertions, 1 deletions
diff --git a/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs b/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs index 1abaf5274..4f4f5f1cb 100644 --- a/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs @@ -116,6 +116,7 @@ namespace MediaBrowser.Api.Playback.Hls if (File.Exists(segmentPath)) { + job = ApiEntryPoint.Instance.GetTranscodingJob(playlistPath, TranscodingJobType); return await GetSegmentResult(playlistPath, segmentPath, index, segmentLength, job, cancellationToken).ConfigureAwait(false); } @@ -124,6 +125,7 @@ namespace MediaBrowser.Api.Playback.Hls { if (File.Exists(segmentPath)) { + job = ApiEntryPoint.Instance.GetTranscodingJob(playlistPath, TranscodingJobType); return await GetSegmentResult(playlistPath, segmentPath, index, segmentLength, job, cancellationToken).ConfigureAwait(false); } else diff --git a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj b/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj index 58830360e..e01353f80 100644 --- a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj +++ b/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj @@ -113,6 +113,7 @@ <Compile Include="Native\Standby.cs" /> <Compile Include="Native\ServerAuthorization.cs" /> <Compile Include="Native\WindowsApp.cs" /> + <Compile Include="Native\WindowsProcessManager.cs" /> <Compile Include="Networking\CertificateGenerator.cs" /> <Compile Include="Networking\NativeMethods.cs" /> <Compile Include="Networking\NetworkManager.cs" /> diff --git a/MediaBrowser.ServerApplication/Native/WindowsApp.cs b/MediaBrowser.ServerApplication/Native/WindowsApp.cs index d518a82d4..74abcb36c 100644 --- a/MediaBrowser.ServerApplication/Native/WindowsApp.cs +++ b/MediaBrowser.ServerApplication/Native/WindowsApp.cs @@ -114,7 +114,7 @@ namespace MediaBrowser.ServerApplication.Native public IProcessManager GetProcessManager() { - return new ProcessManager(); + return new WindowsProcessManager(); } } } diff --git a/MediaBrowser.ServerApplication/Native/WindowsProcessManager.cs b/MediaBrowser.ServerApplication/Native/WindowsProcessManager.cs new file mode 100644 index 000000000..f3497aef5 --- /dev/null +++ b/MediaBrowser.ServerApplication/Native/WindowsProcessManager.cs @@ -0,0 +1,78 @@ +using MediaBrowser.Controller.Diagnostics; +using System; +using System.Diagnostics; +using System.Runtime.InteropServices; + +namespace MediaBrowser.ServerApplication.Native +{ + public class WindowsProcessManager : IProcessManager + { + public void SuspendProcess(Process process) + { + process.Suspend(); + } + + public void ResumeProcess(Process process) + { + process.Resume(); + } + + public bool SupportsSuspension + { + get { return true; } + } + } + + public static class ProcessExtension + { + [DllImport("kernel32.dll")] + static extern IntPtr OpenThread(ThreadAccess dwDesiredAccess, bool bInheritHandle, uint dwThreadId); + [DllImport("kernel32.dll")] + static extern uint SuspendThread(IntPtr hThread); + [DllImport("kernel32.dll")] + static extern int ResumeThread(IntPtr hThread); + + public static void Suspend(this Process process) + { + foreach (ProcessThread thread in process.Threads) + { + var pOpenThread = OpenThread(ThreadAccess.SUSPEND_RESUME, false, (uint)thread.Id); + if (pOpenThread == IntPtr.Zero) + { + break; + } + SuspendThread(pOpenThread); + } + } + public static void Resume(this Process process) + { + foreach (ProcessThread thread in process.Threads) + { + var pOpenThread = OpenThread(ThreadAccess.SUSPEND_RESUME, false, (uint)thread.Id); + if (pOpenThread == IntPtr.Zero) + { + break; + } + ResumeThread(pOpenThread); + } + } + public static void Print(this Process process) + { + Console.WriteLine("{0,8} {1}", process.Id, process.ProcessName); + } + } + + [Flags] + public enum ThreadAccess : int + { + TERMINATE = (0x0001), + SUSPEND_RESUME = (0x0002), + GET_CONTEXT = (0x0008), + SET_CONTEXT = (0x0010), + SET_INFORMATION = (0x0020), + QUERY_INFORMATION = (0x0040), + SET_THREAD_TOKEN = (0x0080), + IMPERSONATE = (0x0100), + DIRECT_IMPERSONATION = (0x0200) + } +} |
