revise endpoint attributes

This commit is contained in:
Luke Pulverenti
2014-11-14 21:31:03 -05:00
parent 15a56fa069
commit a4b75934e5
59 changed files with 714 additions and 494 deletions

View File

@@ -496,10 +496,10 @@ namespace MediaBrowser.Server.Startup.Common
RegisterSingleInstance(activityLogRepo);
RegisterSingleInstance<IActivityManager>(new ActivityManager(LogManager.GetLogger("ActivityManager"), activityLogRepo, UserManager));
var authContext = new AuthorizationContext();
var authContext = new AuthorizationContext(AuthenticationRepository);
RegisterSingleInstance<IAuthorizationContext>(authContext);
RegisterSingleInstance<ISessionContext>(new SessionContext(UserManager, authContext, SessionManager));
RegisterSingleInstance<IAuthService>(new AuthService(UserManager, SessionManager, authContext, ServerConfigurationManager, ConnectManager));
RegisterSingleInstance<IAuthService>(new AuthService(UserManager, authContext, ServerConfigurationManager, ConnectManager));
RegisterSingleInstance<ISubtitleEncoder>(new SubtitleEncoder(LibraryManager, LogManager.GetLogger("SubtitleEncoder"), ApplicationPaths, FileSystemManager, MediaEncoder, JsonSerializer));
@@ -534,6 +534,8 @@ namespace MediaBrowser.Server.Startup.Common
var info = await new FFMpegDownloader(Logger, ApplicationPaths, HttpClient, ZipClient, FileSystemManager)
.GetFFMpegInfo(NativeApp.Environment, _startupOptions, progress).ConfigureAwait(false);
new FFmpegValidator(Logger, ApplicationPaths).Validate(info);
MediaEncoder = new MediaEncoder(LogManager.GetLogger("MediaEncoder"), JsonSerializer, info.EncoderPath, info.ProbePath, info.Version);
RegisterSingleInstance(MediaEncoder);
}

View File

@@ -0,0 +1,116 @@
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Model.Logging;
using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Text;
namespace MediaBrowser.Server.Startup.Common.FFMpeg
{
public class FFmpegValidator
{
private readonly ILogger _logger;
private readonly IApplicationPaths _appPaths;
public FFmpegValidator(ILogger logger, IApplicationPaths appPaths)
{
_logger = logger;
_appPaths = appPaths;
}
public void Validate(FFMpegInfo info)
{
_logger.Info("FFMpeg: {0}", info.EncoderPath);
_logger.Info("FFProbe: {0}", info.ProbePath);
var fileInfo = new FileInfo(info.EncoderPath);
var cachePath = Path.Combine(_appPaths.CachePath, fileInfo.Length.ToString(CultureInfo.InvariantCulture).GetMD5().ToString("N"));
if (!File.Exists(cachePath))
{
ValidateCodecs(info.EncoderPath);
Directory.CreateDirectory(Path.GetDirectoryName(cachePath));
File.WriteAllText(cachePath, string.Empty, Encoding.UTF8);
}
}
private void ValidateCodecs(string path)
{
var output = GetOutput(path, "-encoders");
var required = new[]
{
"libx264",
"mpeg4",
"msmpeg4",
"libvpx",
//"libvpx-vp9",
"aac",
"ac3",
"libmp3lame",
"libvorbis",
"srt"
};
foreach (var encoder in required)
{
var srch = " " + encoder + " ";
if (output.IndexOf(srch, StringComparison.OrdinalIgnoreCase) == -1)
{
throw new ArgumentException("ffmpeg is missing encoder " + encoder);
}
}
}
private string GetOutput(string path, string arguments)
{
var process = new Process
{
StartInfo = new ProcessStartInfo
{
CreateNoWindow = true,
UseShellExecute = false,
FileName = path,
Arguments = arguments,
WindowStyle = ProcessWindowStyle.Hidden,
ErrorDialog = false,
RedirectStandardOutput = true,
RedirectStandardError = true
}
};
using (process)
{
process.Start();
try
{
process.BeginErrorReadLine();
using (var reader = new StreamReader(process.StandardOutput.BaseStream))
{
return reader.ReadToEnd();
}
}
catch
{
// Hate having to do this
try
{
process.Kill();
}
catch (Exception ex1)
{
_logger.ErrorException("Error killing ffmpeg", ex1);
}
throw;
}
}
}
}
}

View File

@@ -59,6 +59,7 @@
<Compile Include="FFMpeg\FFMpegDownloader.cs" />
<Compile Include="FFMpeg\FFMpegDownloadInfo.cs" />
<Compile Include="FFMpeg\FFMpegInfo.cs" />
<Compile Include="FFMpeg\FFmpegValidator.cs" />
<Compile Include="INativeApp.cs" />
<Compile Include="Migrations\DeprecatePlugins.cs" />
<Compile Include="Migrations\IVersionMigration.cs" />