Selaa lähdekoodia

improve ffmpeg cleanup

Luke Pulverenti 10 vuotta sitten
vanhempi
sitoutus
4f7e8fee24

+ 3 - 5
MediaBrowser.Controller/Entities/BaseItem.cs

@@ -1161,12 +1161,10 @@ namespace MediaBrowser.Controller.Entities
                 return true;
             }
 
-            var locations = user.RootFolder
-                .GetChildren(user, true)
-                .OfType<CollectionFolder>()
-                .SelectMany(i => i.PhysicalLocations);
+            var folders = user.RootFolder.GetChildren(user, true).Select(i => i.Id).ToList();
+            var itemCollectionFolders = LibraryManager.GetCollectionFolders(this).Select(i => i.Id).ToList();
 
-            return locations.Any(l => FileSystem.ContainsSubPath(l, topParent.Path));
+            return itemCollectionFolders.Any(folders.Contains);
         }
 
         /// <summary>

+ 81 - 52
MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs

@@ -1,3 +1,4 @@
+using System.Collections.Generic;
 using MediaBrowser.Common.IO;
 using MediaBrowser.Controller.Channels;
 using MediaBrowser.Controller.Configuration;
@@ -74,6 +75,8 @@ namespace MediaBrowser.MediaEncoding.Encoder
         protected readonly Func<ISubtitleEncoder> SubtitleEncoder;
         protected readonly Func<IMediaSourceManager> MediaSourceManager;
 
+        private List<Process> _runningProcesses = new List<Process>(); 
+
         public MediaEncoder(ILogger logger, IJsonSerializer jsonSerializer, string ffMpegPath, string ffProbePath, string version, IServerConfigurationManager configurationManager, IFileSystem fileSystem, ILiveTvManager liveTvManager, IIsoManager isoManager, ILibraryManager libraryManager, IChannelManager channelManager, ISessionManager sessionManager, Func<ISubtitleEncoder> subtitleEncoder, Func<IMediaSourceManager> mediaSourceManager)
         {
             _logger = logger;
@@ -192,7 +195,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
 
             try
             {
-                process.Start();
+                StartProcess(process);
             }
             catch (Exception ex)
             {
@@ -375,7 +378,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
 
             await resourcePool.WaitAsync(cancellationToken).ConfigureAwait(false);
 
-            process.Start();
+            StartProcess(process);
 
             var memoryStream = new MemoryStream();
 
@@ -391,18 +394,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
 
             if (!ranToCompletion)
             {
-                try
-                {
-                    _logger.Info("Killing ffmpeg process");
-
-                    process.StandardInput.WriteLine("q");
-
-                    process.WaitForExit(1000);
-                }
-                catch (Exception ex)
-                {
-                    _logger.ErrorException("Error killing process", ex);
-                }
+                StopProcess(process, 1000, false);
             }
 
             resourcePool.Release();
@@ -426,31 +418,6 @@ namespace MediaBrowser.MediaEncoding.Encoder
             return memoryStream;
         }
 
-        public Task<Stream> EncodeImage(ImageEncodingOptions options, CancellationToken cancellationToken)
-        {
-            throw new NotImplementedException();
-        }
-
-        /// <summary>
-        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
-        /// </summary>
-        public void Dispose()
-        {
-            Dispose(true);
-        }
-
-        /// <summary>
-        /// Releases unmanaged and - optionally - managed resources.
-        /// </summary>
-        /// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
-        protected virtual void Dispose(bool dispose)
-        {
-            if (dispose)
-            {
-                _videoImageResourcePool.Dispose();
-            }
-        }
-
         public string GetTimeParameter(long ticks)
         {
             var time = TimeSpan.FromTicks(ticks);
@@ -519,7 +486,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
 
             try
             {
-                process.Start();
+                StartProcess(process);
 
                 // Need to give ffmpeg enough time to make all the thumbnails, which could be a while,
                 // but we still need to detect if the process hangs.
@@ -543,18 +510,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
 
                 if (!ranToCompletion)
                 {
-                    try
-                    {
-                        _logger.Info("Killing ffmpeg process");
-
-                        process.StandardInput.WriteLine("q");
-
-                        process.WaitForExit(1000);
-                    }
-                    catch (Exception ex)
-                    {
-                        _logger.ErrorException("Error killing process", ex);
-                    }
+                    StopProcess(process, 1000, false);
                 }
             }
             finally
@@ -615,5 +571,78 @@ namespace MediaBrowser.MediaEncoding.Encoder
 
             return job.OutputFilePath;
         }
+
+        private void StartProcess(Process process)
+        {
+            process.Start();
+
+            lock (_runningProcesses)
+            {
+                _runningProcesses.Add(process);
+            }
+        }
+        private void StopProcess(Process process, int waitTimeMs, bool enableForceKill)
+        {
+            try
+            {
+                _logger.Info("Killing ffmpeg process");
+
+                process.StandardInput.WriteLine("q");
+
+                if (!process.WaitForExit(1000))
+                {
+                    if (enableForceKill)
+                    {
+                        process.Kill();
+                    }
+                }
+            }
+            catch (Exception ex)
+            {
+                _logger.ErrorException("Error killing process", ex);
+            }
+            finally
+            {
+                lock (_runningProcesses)
+                {
+                    _runningProcesses.Remove(process);
+                }
+            }
+        }
+
+        private void StopProcesses()
+        {
+            List<Process> proceses;
+            lock (_runningProcesses)
+            {
+                proceses = _runningProcesses.ToList();
+            }
+
+            foreach (var process in proceses)
+            {
+                StopProcess(process, 500, true);
+            }
+        }
+
+        /// <summary>
+        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
+        /// </summary>
+        public void Dispose()
+        {
+            Dispose(true);
+        }
+
+        /// <summary>
+        /// Releases unmanaged and - optionally - managed resources.
+        /// </summary>
+        /// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
+        protected virtual void Dispose(bool dispose)
+        {
+            if (dispose)
+            {
+                _videoImageResourcePool.Dispose();
+                StopProcesses();
+            }
+        }
     }
 }

+ 1 - 0
MediaBrowser.Model/Dto/BaseItemDto.cs

@@ -63,6 +63,7 @@ namespace MediaBrowser.Model.Dto
         public string PreferredMetadataCountryCode { get; set; }
 
         public string AwardSummary { get; set; }
+        public string ShareUrl { get; set; }
 
         public float? Metascore { get; set; }
 

+ 3 - 0
MediaBrowser.Model/Users/UserPolicy.cs

@@ -62,6 +62,8 @@ namespace MediaBrowser.Model.Users
         public bool EnableAllFolders { get; set; }
 
         public int InvalidLoginAttemptCount { get; set; }
+
+        public bool EnablePublicSharing { get; set; }
         
         public UserPolicy()
         {
@@ -94,6 +96,7 @@ namespace MediaBrowser.Model.Users
             EnableAllDevices = true;
 
             EnableContentDownloading = true;
+            EnablePublicSharing = true;
         }
     }
 }

+ 1 - 1
MediaBrowser.Server.Implementations/Connect/ConnectManager.cs

@@ -517,7 +517,7 @@ namespace MediaBrowser.Server.Implementations.Connect
 
                 if (!connectUser.IsActive)
                 {
-                    throw new ArgumentException("The Emby account has been disabled.");
+                    throw new ArgumentException("The Emby account is not active. Please ensure the account has been activated by following the instructions within the email confirmation.");
                 }
 
                 connectUserId = connectUser.Id;

+ 1 - 1
MediaBrowser.Server.Implementations/Library/LibraryManager.cs

@@ -1513,7 +1513,7 @@ namespace MediaBrowser.Server.Implementations.Library
 
             return GetUserRootFolder().Children
                 .OfType<Folder>()
-                .Where(i => string.Equals(i.Path, item.Path, StringComparison.OrdinalIgnoreCase) || i.PhysicalLocations.Contains(item.Path));
+                .Where(i => string.Equals(i.Path, item.Path, StringComparison.OrdinalIgnoreCase) || i.PhysicalLocations.Contains(item.Path, StringComparer.OrdinalIgnoreCase));
         }
 
         public string GetContentType(BaseItem item)

+ 1 - 0
MediaBrowser.Server.Implementations/Localization/JavaScript/javascript.json

@@ -40,6 +40,7 @@
     "TitleLiveTV": "Live TV",
     "TitleSync": "Sync",
     "ButtonDonate": "Donate",
+    "HeaderMyMedia": "My Media",
     "TitleNotifications": "Notifications",
     "ErrorLaunchingChromecast": "There was an error launching chromecast. Please ensure your device is connected to your wireless network.",
     "MessageErrorLoadingSupporterInfo": "There was an error loading supporter information. Please try again later.",

+ 4 - 4
MediaBrowser.Server.Implementations/Localization/Server/server.json

@@ -552,7 +552,7 @@
     "LabelPublicHttpsPort": "Public https port number:",
     "LabelPublicHttpsPortHelp": "The public port number that should be mapped to the local https port.",
     "LabelEnableHttps": "Report https as external address",
-    "LabelEnableHttpsHelp": "If enabled, the server will report an https url to clients as it's external address. This may break clients that do not yet support https.",
+    "LabelEnableHttpsHelp": "If enabled, the server will report an https url to clients as it's external address.",
     "LabelHttpsPort": "Local https port number:",
     "LabelHttpsPortHelp": "The tcp port number that Emby's https server should bind to.",
     "LabelWebSocketPortNumber": "Web socket port number:",
@@ -896,9 +896,9 @@
     "LabelHomePageSection2": "Home page section 2:",
     "LabelHomePageSection3": "Home page section 3:",
     "LabelHomePageSection4": "Home page section 4:",
-    "OptionMyViewsButtons": "My views (buttons)",
-    "OptionMyViews": "My views",
-    "OptionMyViewsSmall": "My views (small)",
+    "OptionMyMediaButtons": "My media (buttons)",
+    "OptionMyMedia": "My media",
+    "OptionMyMediaSmall": "My media (small)",
     "OptionResumablemedia": "Resume",
     "OptionLatestMedia": "Latest media",
     "OptionLatestChannelMedia": "Latest channel items",

+ 1 - 1
README.md

@@ -12,7 +12,7 @@ We have several client apps released and in production:
 - [iPad](https://itunes.apple.com/us/app/media-browser-client/id879475585 "iPad")
 - [iPhone](https://itunes.apple.com/us/app/media-browser-for-ios/id705058087?mt=8 "iPhone")
 - [Media Portal](http://www.team-mediaportal.com/ "Media Portal")
-- [Roku](http://www.roku.com/channels/#!details/44191/media-browser-for-roku "Roku")
+- [Roku](https://www.roku.com/channels#!details/44191/emby "Roku")
 - Windows 7/8 Desktop
 - Windows Media Center
 - [Windows Phone](http://www.windowsphone.com/s?appid=f4971ed9-f651-4bf6-84bb-94fd98613b86 "Windows Phone")