Browse Source

update ffmpeg

Luke Pulverenti 9 years ago
parent
commit
132766ff15

+ 2 - 2
MediaBrowser.Common.Implementations/Security/MbAdmin.cs

@@ -3,11 +3,11 @@ namespace MediaBrowser.Common.Implementations.Security
 {
     public class MbAdmin
     {
-        public const string HttpUrl = "http://www.mb3admin.com/admin/";
+        public const string HttpUrl = "https://www.mb3admin.com/admin/";
         
         /// <summary>
         /// Leaving as http for now until we get it squared away
         /// </summary>
-        public const string HttpsUrl = "http://www.mb3admin.com/admin/";
+        public const string HttpsUrl = "https://www.mb3admin.com/admin/";
     }
 }

+ 1 - 1
MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs

@@ -21,7 +21,7 @@ namespace MediaBrowser.Common.Implementations.Security
     public class PluginSecurityManager : ISecurityManager
     {
         private const string MBValidateUrl = MbAdmin.HttpsUrl + "service/registration/validate";
-        private const string AppstoreRegUrl = /*MbAdmin.HttpsUrl*/ "http://mb3admin.com/admin/service/appstore/register";
+        private const string AppstoreRegUrl = /*MbAdmin.HttpsUrl*/ "https://mb3admin.com/admin/service/appstore/register";
 
         /// <summary>
         /// The _is MB supporter

+ 33 - 14
MediaBrowser.Dlna/Ssdp/SsdpHandler.cs

@@ -36,7 +36,7 @@ namespace MediaBrowser.Dlna.Ssdp
         private Timer _notificationTimer;
 
         private bool _isDisposed;
-        private readonly ConcurrentDictionary<string, List<UpnpDevice>> _devices = new ConcurrentDictionary<string, List<UpnpDevice>>();
+        private readonly Dictionary<string, List<UpnpDevice>> _devices = new Dictionary<string, List<UpnpDevice>>();
 
         private readonly IApplicationHost _appHost;
 
@@ -172,9 +172,12 @@ namespace MediaBrowser.Dlna.Ssdp
         {
             get
             {
-                var devices = _devices.ToList();
+                lock (_devices)
+                {
+                    var devices = _devices.ToList();
 
-                return devices.SelectMany(i => i.Value).ToList();
+                    return devices.SelectMany(i => i.Value).ToList();
+                }
             }
         }
 
@@ -482,26 +485,42 @@ namespace MediaBrowser.Dlna.Ssdp
 
         public void RegisterNotification(string uuid, Uri descriptionUri, IPAddress address, IEnumerable<string> services)
         {
-            var list = _devices.GetOrAdd(uuid, new List<UpnpDevice>());
+            lock (_devices)
+            {
+                List<UpnpDevice> list;
+                List<UpnpDevice> dl;
+                if (_devices.TryGetValue(uuid, out dl))
+                {
+                    list = dl;
+                }
+                else
+                {
+                    list = new List<UpnpDevice>();
+                    _devices[uuid] = list;
+                }
 
-            list.AddRange(services.Select(i => new UpnpDevice(uuid, i, descriptionUri, address)));
+                list.AddRange(services.Select(i => new UpnpDevice(uuid, i, descriptionUri, address)));
 
-            NotifyAll();
-            _logger.Debug("Registered mount {0} at {1}", uuid, descriptionUri);
+                NotifyAll();
+                _logger.Debug("Registered mount {0} at {1}", uuid, descriptionUri);
+            }
         }
 
         public void UnregisterNotification(string uuid)
         {
-            List<UpnpDevice> dl;
-            if (_devices.TryRemove(uuid, out dl))
+            lock (_devices)
             {
-
-                foreach (var d in dl.ToList())
+                List<UpnpDevice> dl;
+                if (_devices.TryGetValue(uuid, out dl))
                 {
-                    NotifyDevice(d, "byebye", true);
-                }
+                    _devices.Remove(uuid);
+                    foreach (var d in dl.ToList())
+                    {
+                        NotifyDevice(d, "byebye", true);
+                    }
 
-                _logger.Debug("Unregistered mount {0}", uuid);
+                    _logger.Debug("Unregistered mount {0}", uuid);
+                }
             }
         }
 

+ 1 - 1
MediaBrowser.Server.Implementations/EntryPoints/UsageReporter.cs

@@ -18,7 +18,7 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
         private readonly IHttpClient _httpClient;
         private readonly IUserManager _userManager;
         private readonly ILogger _logger;
-        private const string MbAdminUrl = "http://www.mb3admin.com/admin/";
+        private const string MbAdminUrl = "https://www.mb3admin.com/admin/";
 
         public UsageReporter(IApplicationHost applicationHost, IHttpClient httpClient, IUserManager userManager, ILogger logger)
         {

+ 1 - 1
MediaBrowser.Server.Startup.Common/ApplicationHost.cs

@@ -618,7 +618,7 @@ namespace MediaBrowser.Server.Startup.Common
         /// <returns>Task.</returns>
         private async Task RegisterMediaEncoder(IProgress<double> progress)
         {
-            var info = await new FFMpegDownloader(Logger, ApplicationPaths, HttpClient, ZipClient, FileSystemManager, NativeApp.Environment)
+            var info = await new FFMpegDownloader(Logger, ApplicationPaths, HttpClient, ZipClient, FileSystemManager, NativeApp.Environment, NativeApp.GetType().Assembly)
                 .GetFFMpegInfo(NativeApp.Environment, _startupOptions, progress).ConfigureAwait(false);
 
             var mediaEncoder = new MediaEncoder(LogManager.GetLogger("MediaEncoder"),

+ 5 - 11
MediaBrowser.Server.Startup.Common/FFMpeg/FFMpegDownloadInfo.cs

@@ -8,6 +8,7 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg
         public string FFProbeFilename { get; set; }
         public string ArchiveType { get; set; }
         public string[] DownloadUrls { get; set; }
+        public bool IsEmbedded { get; set; }
 
         public FFMpegDownloadInfo()
         {
@@ -54,8 +55,9 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg
 
                     info.FFMpegFilename = "ffmpeg.exe";
                     info.FFProbeFilename = "ffprobe.exe";
-                    info.Version = "20160131";
+                    info.Version = "20160401";
                     info.ArchiveType = "7z";
+                    info.IsEmbedded = true;
 
                     switch (environment.SystemArchitecture)
                     {
@@ -81,17 +83,9 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg
                     switch (environment.SystemArchitecture)
                     {
                         case Architecture.X86_X64:
-                            return new[]
-                            {
-                                "https://github.com/MediaBrowser/Emby.Resources/raw/master/ffmpeg/windows/ffmpeg-20160131-win64.7z",
-                                "http://ffmpeg.zeranoe.com/builds/win64/static/ffmpeg-20151109-git-480bad7-win64-static.7z"
-                            };
+                            return new string[] { "MediaBrowser.ServerApplication.ffmpeg.ffmpegx64.7z" };
                         case Architecture.X86:
-                            return new[]
-                            {
-                                "https://github.com/MediaBrowser/Emby.Resources/raw/master/ffmpeg/windows/ffmpeg-20160131-win32.7z",
-                                "http://ffmpeg.zeranoe.com/builds/win32/static/ffmpeg-20151109-git-480bad7-win32-static.7z"
-                            };
+                            return new string[] { "MediaBrowser.ServerApplication.ffmpeg.ffmpegx86.7z" };
                     }
                     break;
 

+ 33 - 14
MediaBrowser.Server.Startup.Common/FFMpeg/FFMpegDownloader.cs

@@ -8,6 +8,7 @@ using System;
 using System.Collections.Generic;
 using System.IO;
 using System.Linq;
+using System.Reflection;
 using System.Text;
 using System.Threading;
 using System.Threading.Tasks;
@@ -23,13 +24,14 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg
         private readonly IZipClient _zipClient;
         private readonly IFileSystem _fileSystem;
         private readonly NativeEnvironment _environment;
+        private Assembly _ownerAssembly;
 
         private readonly string[] _fontUrls =
         {
             "https://github.com/MediaBrowser/MediaBrowser.Resources/raw/master/ffmpeg/ARIALUNI.7z"
         };
 
-        public FFMpegDownloader(ILogger logger, IApplicationPaths appPaths, IHttpClient httpClient, IZipClient zipClient, IFileSystem fileSystem, NativeEnvironment environment)
+        public FFMpegDownloader(ILogger logger, IApplicationPaths appPaths, IHttpClient httpClient, IZipClient zipClient, IFileSystem fileSystem, NativeEnvironment environment, Assembly ownerAssembly)
         {
             _logger = logger;
             _appPaths = appPaths;
@@ -37,6 +39,7 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg
             _zipClient = zipClient;
             _fileSystem = fileSystem;
             _environment = environment;
+            _ownerAssembly = ownerAssembly;
         }
 
         public async Task<FFMpegInfo> GetFFMpegInfo(NativeEnvironment environment, StartupOptions options, IProgress<double> progress)
@@ -78,11 +81,11 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg
                 Version = version
             };
 
-			_fileSystem.CreateDirectory(versionedDirectoryPath);
+            _fileSystem.CreateDirectory(versionedDirectoryPath);
 
             var excludeFromDeletions = new List<string> { versionedDirectoryPath };
 
-			if (!_fileSystem.FileExists(info.ProbePath) || !_fileSystem.FileExists(info.EncoderPath))
+            if (!_fileSystem.FileExists(info.ProbePath) || !_fileSystem.FileExists(info.EncoderPath))
             {
                 // ffmpeg not present. See if there's an older version we can start with
                 var existingVersion = GetExistingVersion(info, rootEncoderPath);
@@ -106,7 +109,10 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg
                 }
             }
 
-            await DownloadFonts(versionedDirectoryPath).ConfigureAwait(false);
+            if (_environment.OperatingSystem == OperatingSystem.Windows)
+            {
+                await DownloadFonts(versionedDirectoryPath).ConfigureAwait(false);
+            }
 
             DeleteOlderFolders(Path.GetDirectoryName(versionedDirectoryPath), excludeFromDeletions);
 
@@ -189,6 +195,21 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg
 
         private async Task DownloadFFMpeg(FFMpegDownloadInfo downloadinfo, string directory, IProgress<double> progress)
         {
+            if (downloadinfo.IsEmbedded)
+            {
+                var tempFile = Path.Combine(_appPaths.TempDirectory, Guid.NewGuid().ToString());
+                _fileSystem.CreateDirectory(Path.GetDirectoryName(tempFile));
+
+                using (var stream = _ownerAssembly.GetManifestResourceStream(downloadinfo.DownloadUrls[0]))
+                {
+                    using (var fs = _fileSystem.GetFileStream(tempFile, FileMode.Create, FileAccess.Write, FileShare.Read, true))
+                    {
+                        await stream.CopyToAsync(fs).ConfigureAwait(false);
+                    }
+                }
+                ExtractFFMpeg(downloadinfo, tempFile, directory);
+            }
+
             foreach (var url in downloadinfo.DownloadUrls)
             {
                 progress.Report(0);
@@ -216,10 +237,8 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg
             {
                 throw new ApplicationException("ffmpeg unvailable. Please install it and start the server with two command line arguments: -ffmpeg \"{PATH}\" and -ffprobe \"{PATH}\"");
             }
-            else
-            {
-                throw new ApplicationException("Unable to download required components. Please try again later.");
-            }
+
+            throw new ApplicationException("Unable to download required components. Please try again later.");
         }
 
         private void ExtractFFMpeg(FFMpegDownloadInfo downloadinfo, string tempFile, string targetFolder)
@@ -228,7 +247,7 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg
 
             var tempFolder = Path.Combine(_appPaths.TempDirectory, Guid.NewGuid().ToString());
 
-			_fileSystem.CreateDirectory(tempFolder);
+            _fileSystem.CreateDirectory(tempFolder);
 
             try
             {
@@ -247,7 +266,7 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg
                     }))
                 {
                     var targetFile = Path.Combine(targetFolder, Path.GetFileName(file));
-					_fileSystem.CopyFile(file, targetFile, true);
+                    _fileSystem.CopyFile(file, targetFile, true);
                     SetFilePermissions(targetFile);
                 }
             }
@@ -311,13 +330,13 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg
             {
                 var fontsDirectory = Path.Combine(targetPath, "fonts");
 
-				_fileSystem.CreateDirectory(fontsDirectory);
+                _fileSystem.CreateDirectory(fontsDirectory);
 
                 const string fontFilename = "ARIALUNI.TTF";
 
                 var fontFile = Path.Combine(fontsDirectory, fontFilename);
 
-				if (_fileSystem.FileExists(fontFile))
+                if (_fileSystem.FileExists(fontFile))
                 {
                     await WriteFontConfigFile(fontsDirectory).ConfigureAwait(false);
                 }
@@ -360,7 +379,7 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg
             {
                 try
                 {
-					_fileSystem.CopyFile(existingFile, Path.Combine(fontsDirectory, fontFilename), true);
+                    _fileSystem.CopyFile(existingFile, Path.Combine(fontsDirectory, fontFilename), true);
                     return;
                 }
                 catch (IOException ex)
@@ -422,7 +441,7 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg
             const string fontConfigFilename = "fonts.conf";
             var fontConfigFile = Path.Combine(fontsDirectory, fontConfigFilename);
 
-			if (!_fileSystem.FileExists(fontConfigFile))
+            if (!_fileSystem.FileExists(fontConfigFile))
             {
                 var contents = string.Format("<?xml version=\"1.0\"?><fontconfig><dir>{0}</dir><alias><family>Arial</family><prefer>Arial Unicode MS</prefer></alias></fontconfig>", fontsDirectory);
 

+ 2 - 0
MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj

@@ -144,6 +144,8 @@
     <None Include="App.config" />
     <None Include="app.manifest" />
     <EmbeddedResource Include="Native\RegisterServer.bat" />
+    <EmbeddedResource Include="ffmpeg\ffmpegx64.7z" />
+    <EmbeddedResource Include="ffmpeg\ffmpegx86.7z" />
     <None Include="packages.config" />
   </ItemGroup>
   <ItemGroup>

+ 1 - 0
MediaBrowser.ServerApplication/ffmpeg/ffmpegx64.7z.REMOVED.git-id

@@ -0,0 +1 @@
+9dc10b022537738edce7eb71aa8dd4adbfee2c7b

+ 1 - 0
MediaBrowser.ServerApplication/ffmpeg/ffmpegx86.7z.REMOVED.git-id

@@ -0,0 +1 @@
+00fa1afa35fbd0a7e97ad7956e42ae17f6882f64