update ProcessManager

This commit is contained in:
Luke Pulverenti 2015-03-02 13:48:21 -05:00
parent 0d8636d859
commit f3159f3fef
18 changed files with 77 additions and 101 deletions

View File

@ -1,5 +1,4 @@
using MediaBrowser.Controller.Activity;
using MediaBrowser.Controller.Channels;
using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
@ -9,11 +8,9 @@ using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Localization;
using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Controller.Session;
using MediaBrowser.Model.Activity;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Querying;
using ServiceStack;
using System;

View File

@ -362,6 +362,12 @@
<Compile Include="..\MediaBrowser.Model\Dlna\MediaFormatProfileResolver.cs">
<Link>Dlna\MediaFormatProfileResolver.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\Dlna\PlaybackErrorCode.cs">
<Link>Dlna\PlaybackErrorCode.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\Dlna\PlaybackException.cs">
<Link>Dlna\PlaybackException.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\Dlna\ProfileCondition.cs">
<Link>Dlna\ProfileCondition.cs</Link>
</Compile>

View File

@ -327,6 +327,12 @@
<Compile Include="..\MediaBrowser.Model\Dlna\MediaFormatProfileResolver.cs">
<Link>Dlna\MediaFormatProfileResolver.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\Dlna\PlaybackErrorCode.cs">
<Link>Dlna\PlaybackErrorCode.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\Dlna\PlaybackException.cs">
<Link>Dlna\PlaybackException.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\Dlna\ProfileCondition.cs">
<Link>Dlna\ProfileCondition.cs</Link>
</Compile>

View File

@ -0,0 +1,9 @@

namespace MediaBrowser.Model.Dlna
{
public enum PlaybackErrorCode
{
NotAllowed = 0,
NoCompatibleStream = 1
}
}

View File

@ -0,0 +1,9 @@
using System;
namespace MediaBrowser.Model.Dlna
{
public class PlaybackException : Exception
{
public PlaybackErrorCode ErrorCode { get; set;}
}
}

View File

@ -31,7 +31,13 @@ namespace MediaBrowser.Model.Dlna
List<StreamInfo> streams = new List<StreamInfo>();
foreach (MediaSourceInfo i in mediaSources)
streams.Add(BuildAudioItem(i, options));
{
StreamInfo streamInfo = BuildAudioItem(i, options);
if (streamInfo != null)
{
streams.Add(streamInfo);
}
}
foreach (StreamInfo stream in streams)
{
@ -63,7 +69,13 @@ namespace MediaBrowser.Model.Dlna
List<StreamInfo> streams = new List<StreamInfo>();
foreach (MediaSourceInfo i in mediaSources)
streams.Add(BuildVideoItem(i, options));
{
StreamInfo streamInfo = BuildVideoItem(i, options);
if (streamInfo != null)
{
streams.Add(streamInfo);
}
}
foreach (StreamInfo stream in streams)
{
@ -97,7 +109,10 @@ namespace MediaBrowser.Model.Dlna
{
return stream;
}
return null;
PlaybackException error = new PlaybackException();
error.ErrorCode = PlaybackErrorCode.NoCompatibleStream;
throw error;
}
private StreamInfo BuildAudioItem(MediaSourceInfo item, AudioOptions options)
@ -186,6 +201,11 @@ namespace MediaBrowser.Model.Dlna
if (transcodingProfile != null)
{
if (!item.SupportsTranscoding)
{
return null;
}
playlistItem.PlayMethod = PlayMethod.Transcode;
playlistItem.TranscodeSeekInfo = transcodingProfile.TranscodeSeekInfo;
playlistItem.EstimateContentLength = transcodingProfile.EstimateContentLength;
@ -290,6 +310,11 @@ namespace MediaBrowser.Model.Dlna
if (transcodingProfile != null)
{
if (!item.SupportsTranscoding)
{
return null;
}
if (subtitleStream != null)
{
SubtitleProfile subtitleProfile = GetSubtitleProfile(subtitleStream, options.Profile, options.Context);

View File

@ -22,6 +22,7 @@ namespace MediaBrowser.Model.Dto
public long? RunTimeTicks { get; set; }
public bool ReadAtNativeFramerate { get; set; }
public bool SupportsTranscoding { get; set; }
public VideoType? VideoType { get; set; }
@ -45,6 +46,7 @@ namespace MediaBrowser.Model.Dto
MediaStreams = new List<MediaStream>();
RequiredHttpHeaders = new Dictionary<string, string>();
PlayableStreamFileNames = new List<string>();
SupportsTranscoding = true;
}
public int? DefaultAudioStreamIndex { get; set; }

View File

@ -125,6 +125,8 @@
<Compile Include="Devices\DeviceInfo.cs" />
<Compile Include="Devices\DevicesOptions.cs" />
<Compile Include="Dlna\EncodingContext.cs" />
<Compile Include="Dlna\PlaybackErrorCode.cs" />
<Compile Include="Dlna\PlaybackException.cs" />
<Compile Include="Dlna\Profiles\DefaultProfile.cs" />
<Compile Include="Dlna\ResolutionConfiguration.cs" />
<Compile Include="Dlna\ResolutionNormalizer.cs" />

View File

@ -1,19 +1,18 @@
using System.Collections.Generic;
using System.Linq;
using MediaBrowser.Common.IO;
using MediaBrowser.Common.IO;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Controller.Resolvers;
using MediaBrowser.Model.Entities;
using System;
using System.IO;
using MediaBrowser.Model.Logging;
using MediaBrowser.Naming.Common;
using MediaBrowser.Naming.IO;
using MediaBrowser.Naming.TV;
using MediaBrowser.Server.Implementations.Logging;
using EpisodeInfo = MediaBrowser.Controller.Providers.EpisodeInfo;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV
{

View File

@ -47,7 +47,7 @@
<ItemGroup>
<Reference Include="ImageMagickSharp, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\ImageMagickSharp.1.0.0.5\lib\net45\ImageMagickSharp.dll</HintPath>
<HintPath>..\packages\ImageMagickSharp.1.0.0.6\lib\net45\ImageMagickSharp.dll</HintPath>
</Reference>
<Reference Include="MediaBrowser.Naming, Version=1.0.5509.27636, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="ImageMagickSharp" version="1.0.0.5" targetFramework="net45" />
<package id="ImageMagickSharp" version="1.0.0.6" targetFramework="net45" />
<package id="MediaBrowser.Naming" version="1.0.0.32" targetFramework="net45" />
<package id="Mono.Nat" version="1.2.21.0" targetFramework="net45" />
<package id="morelinq" version="1.1.0" targetFramework="net45" />

View File

@ -75,7 +75,6 @@
<Link>Properties\SharedVersion.cs</Link>
</Compile>
<Compile Include="Diagnostics\LinuxProcessManager.cs" />
<Compile Include="Diagnostics\ProcessManager.cs" />
<Compile Include="Native\BaseMonoApp.cs" />
<Compile Include="Networking\CertificateGenerator.cs" />
<Compile Include="Program.cs" />

View File

@ -1,5 +1,4 @@
using MediaBrowser.Controller.Diagnostics;
using System;
using System.Diagnostics;
namespace MediaBrowser.Server.Mono.Diagnostics
@ -8,17 +7,17 @@ namespace MediaBrowser.Server.Mono.Diagnostics
{
public void SuspendProcess(Process process)
{
throw new NotImplementedException();
process.PriorityClass = ProcessPriorityClass.Idle;
}
public void ResumeProcess(Process process)
{
throw new NotImplementedException();
process.PriorityClass = ProcessPriorityClass.Normal;
}
public bool SupportsSuspension
{
get { return false; }
get { return true; }
}
}
}

View File

@ -56,6 +56,7 @@
<Compile Include="ApplicationHost.cs" />
<Compile Include="ApplicationPathHelper.cs" />
<Compile Include="Browser\BrowserLauncher.cs" />
<Compile Include="Diagnostics\ProcessManager.cs" />
<Compile Include="EntryPoints\KeepServerAwake.cs" />
<Compile Include="EntryPoints\StartupWizard.cs" />
<Compile Include="FFMpeg\FFMpegDownloader.cs" />

View File

@ -62,7 +62,7 @@
<ItemGroup>
<Reference Include="ImageMagickSharp, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\ImageMagickSharp.1.0.0.5\lib\net45\ImageMagickSharp.dll</HintPath>
<HintPath>..\packages\ImageMagickSharp.1.0.0.6\lib\net45\ImageMagickSharp.dll</HintPath>
</Reference>
<Reference Include="MediaBrowser.IsoMounter">
<HintPath>..\packages\MediaBrowser.IsoMounting.3.0.69\lib\net45\MediaBrowser.IsoMounter.dll</HintPath>
@ -113,7 +113,6 @@
<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" />

View File

@ -3,6 +3,7 @@ using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Diagnostics;
using MediaBrowser.IsoMounter;
using MediaBrowser.Model.Logging;
using MediaBrowser.Server.Mono.Diagnostics;
using MediaBrowser.Server.Startup.Common;
using MediaBrowser.ServerApplication.Networking;
using System.Collections.Generic;
@ -113,7 +114,7 @@ namespace MediaBrowser.ServerApplication.Native
public IProcessManager GetProcessManager()
{
return new WindowsProcessManager();
return new ProcessManager();
}
}
}

View File

@ -1,78 +0,0 @@
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)
}
}

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="ImageMagickSharp" version="1.0.0.5" targetFramework="net45" />
<package id="ImageMagickSharp" version="1.0.0.6" targetFramework="net45" />
<package id="MediaBrowser.IsoMounting" version="3.0.69" targetFramework="net45" />
<package id="System.Data.SQLite.Core" version="1.0.94.0" targetFramework="net45" />
</packages>