Browse Source

rework shutdown

Luke Pulverenti 9 years ago
parent
commit
60ac2e8712

+ 1 - 1
Emby.Drawing/ImageProcessor.cs

@@ -225,7 +225,7 @@ namespace Emby.Drawing
                 return originalImagePath;
                 return originalImagePath;
             }
             }
 
 
-            var quality = options.Quality ?? 90;
+            var quality = options.Quality;
 
 
             var outputFormat = GetOutputFormat(options.OutputFormat);
             var outputFormat = GetOutputFormat(options.OutputFormat);
             var cacheFilePath = GetCacheFilePath(originalImagePath, newSize, quality, dateModified, outputFormat, options.AddPlayedIndicator, options.PercentPlayed, options.UnplayedCount, options.BackgroundColor);
             var cacheFilePath = GetCacheFilePath(originalImagePath, newSize, quality, dateModified, outputFormat, options.AddPlayedIndicator, options.PercentPlayed, options.UnplayedCount, options.BackgroundColor);

+ 1 - 1
MediaBrowser.Api/Images/ImageService.cs

@@ -623,7 +623,7 @@ namespace MediaBrowser.Api.Images
                 Item = item,
                 Item = item,
                 MaxHeight = request.MaxHeight,
                 MaxHeight = request.MaxHeight,
                 MaxWidth = request.MaxWidth,
                 MaxWidth = request.MaxWidth,
-                Quality = request.Quality,
+                Quality = request.Quality ?? 100,
                 Width = request.Width,
                 Width = request.Width,
                 AddPlayedIndicator = request.AddPlayedIndicator,
                 AddPlayedIndicator = request.AddPlayedIndicator,
                 PercentPlayed = request.PercentPlayed ?? 0,
                 PercentPlayed = request.PercentPlayed ?? 0,

+ 2 - 2
MediaBrowser.Controller/Drawing/ImageProcessingOptions.cs

@@ -25,7 +25,7 @@ namespace MediaBrowser.Controller.Drawing
 
 
         public int? MaxHeight { get; set; }
         public int? MaxHeight { get; set; }
 
 
-        public int? Quality { get; set; }
+        public int Quality { get; set; }
 
 
         public List<IImageEnhancer> Enhancers { get; set; }
         public List<IImageEnhancer> Enhancers { get; set; }
 
 
@@ -50,7 +50,7 @@ namespace MediaBrowser.Controller.Drawing
 
 
         public bool HasDefaultOptionsWithoutSize(string originalImagePath)
         public bool HasDefaultOptionsWithoutSize(string originalImagePath)
         {
         {
-            return (!Quality.HasValue || Quality.Value == 100) &&
+            return (Quality == 100) &&
                 IsOutputFormatDefault(originalImagePath) &&
                 IsOutputFormatDefault(originalImagePath) &&
                 !AddPlayedIndicator &&
                 !AddPlayedIndicator &&
                 PercentPlayed.Equals(0) &&
                 PercentPlayed.Equals(0) &&

+ 6 - 1
MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs

@@ -130,13 +130,18 @@ namespace MediaBrowser.MediaEncoding.Probing
             var stream = new MediaStream
             var stream = new MediaStream
             {
             {
                 Codec = streamInfo.codec_name,
                 Codec = streamInfo.codec_name,
-                CodecTag = streamInfo.codec_tag_string,
                 Profile = streamInfo.profile,
                 Profile = streamInfo.profile,
                 Level = streamInfo.level,
                 Level = streamInfo.level,
                 Index = streamInfo.index,
                 Index = streamInfo.index,
                 PixelFormat = streamInfo.pix_fmt
                 PixelFormat = streamInfo.pix_fmt
             };
             };
 
 
+            // Filter out junk
+            if (!string.IsNullOrWhiteSpace(streamInfo.codec_tag_string) && streamInfo.codec_tag_string.IndexOf("[0]", StringComparison.OrdinalIgnoreCase) == -1)
+            {
+                stream.CodecTag = streamInfo.codec_tag_string;
+            }
+
             if (streamInfo.tags != null)
             if (streamInfo.tags != null)
             {
             {
                 stream.Language = GetDictionaryValue(streamInfo.tags, "language");
                 stream.Language = GetDictionaryValue(streamInfo.tags, "language");

+ 32 - 0
MediaBrowser.Server.Implementations/Persistence/MediaStreamColumns.cs

@@ -27,6 +27,38 @@ namespace MediaBrowser.Server.Implementations.Persistence
             AddIsCabacColumn();
             AddIsCabacColumn();
             AddKeyFramesColumn();
             AddKeyFramesColumn();
             AddRefFramesCommand();
             AddRefFramesCommand();
+            AddCodecTagColumn();
+        }
+
+        private void AddCodecTagColumn()
+        {
+            using (var cmd = _connection.CreateCommand())
+            {
+                cmd.CommandText = "PRAGMA table_info(mediastreams)";
+
+                using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult))
+                {
+                    while (reader.Read())
+                    {
+                        if (!reader.IsDBNull(1))
+                        {
+                            var name = reader.GetString(1);
+
+                            if (string.Equals(name, "CodecTag", StringComparison.OrdinalIgnoreCase))
+                            {
+                                return;
+                            }
+                        }
+                    }
+                }
+            }
+
+            var builder = new StringBuilder();
+
+            builder.AppendLine("alter table mediastreams");
+            builder.AppendLine("add column CodecTag TEXT");
+
+            _connection.RunQueries(new[] { builder.ToString() }, _logger);
         }
         }
 
 
         private void AddPixelFormatColumnCommand()
         private void AddPixelFormatColumnCommand()

+ 10 - 2
MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs

@@ -121,7 +121,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
             _connection = await SqliteExtensions.ConnectToDb(dbFile, _logger).ConfigureAwait(false);
             _connection = await SqliteExtensions.ConnectToDb(dbFile, _logger).ConfigureAwait(false);
 
 
             var createMediaStreamsTableCommand
             var createMediaStreamsTableCommand
-               = "create table if not exists mediastreams (ItemId GUID, StreamIndex INT, StreamType TEXT, Codec TEXT, Language TEXT, ChannelLayout TEXT, Profile TEXT, AspectRatio TEXT, Path TEXT, IsInterlaced BIT, BitRate INT NULL, Channels INT NULL, SampleRate INT NULL, IsDefault BIT, IsForced BIT, IsExternal BIT, Height INT NULL, Width INT NULL, AverageFrameRate FLOAT NULL, RealFrameRate FLOAT NULL, Level FLOAT NULL, PixelFormat TEXT, BitDepth INT NULL, IsAnamorphic BIT NULL, RefFrames INT NULL, IsCabac BIT NULL, KeyFrames TEXT NULL, PRIMARY KEY (ItemId, StreamIndex))";
+               = "create table if not exists mediastreams (ItemId GUID, StreamIndex INT, StreamType TEXT, Codec TEXT, Language TEXT, ChannelLayout TEXT, Profile TEXT, AspectRatio TEXT, Path TEXT, IsInterlaced BIT, BitRate INT NULL, Channels INT NULL, SampleRate INT NULL, IsDefault BIT, IsForced BIT, IsExternal BIT, Height INT NULL, Width INT NULL, AverageFrameRate FLOAT NULL, RealFrameRate FLOAT NULL, Level FLOAT NULL, PixelFormat TEXT, BitDepth INT NULL, IsAnamorphic BIT NULL, RefFrames INT NULL, IsCabac BIT NULL, KeyFrames TEXT NULL, CodecTag TEXT NULL, PRIMARY KEY (ItemId, StreamIndex))";
 
 
             string[] queries = {
             string[] queries = {
 
 
@@ -320,7 +320,8 @@ namespace MediaBrowser.Server.Implementations.Persistence
             "IsAnamorphic",
             "IsAnamorphic",
             "RefFrames",
             "RefFrames",
             "IsCabac",
             "IsCabac",
-            "KeyFrames"
+            "KeyFrames",
+            "CodecTag"
         };
         };
 
 
         /// <summary>
         /// <summary>
@@ -2209,6 +2210,8 @@ namespace MediaBrowser.Server.Implementations.Persistence
                         _saveStreamCommand.GetParameter(index++).Value = string.Join(",", stream.KeyFrames.Select(i => i.ToString(CultureInfo.InvariantCulture)).ToArray());
                         _saveStreamCommand.GetParameter(index++).Value = string.Join(",", stream.KeyFrames.Select(i => i.ToString(CultureInfo.InvariantCulture)).ToArray());
                     }
                     }
 
 
+                    _saveStreamCommand.GetParameter(index++).Value = stream.CodecTag;
+                    
                     _saveStreamCommand.Transaction = transaction;
                     _saveStreamCommand.Transaction = transaction;
                     _saveStreamCommand.ExecuteNonQuery();
                     _saveStreamCommand.ExecuteNonQuery();
                 }
                 }
@@ -2370,6 +2373,11 @@ namespace MediaBrowser.Server.Implementations.Persistence
                 }
                 }
             }
             }
 
 
+            if (!reader.IsDBNull(27))
+            {
+                item.CodecTag = reader.GetString(27);
+            }
+
             return item;
             return item;
         }
         }
 
 

+ 18 - 3
MediaBrowser.ServerApplication/MainStartup.cs

@@ -29,6 +29,7 @@ namespace MediaBrowser.ServerApplication
         private static ILogger _logger;
         private static ILogger _logger;
 
 
         private static bool _isRunningAsService = false;
         private static bool _isRunningAsService = false;
+        private static bool _appHostDisposed;
 
 
         /// <summary>
         /// <summary>
         /// Defines the entry point of the application.
         /// Defines the entry point of the application.
@@ -329,7 +330,7 @@ namespace MediaBrowser.ServerApplication
         {
         {
             _logger.Info("Shutting down");
             _logger.Info("Shutting down");
 
 
-            _appHost.Dispose();
+            DisposeAppHost();
         }
         }
 
 
         /// <summary>
         /// <summary>
@@ -500,14 +501,15 @@ namespace MediaBrowser.ServerApplication
             }
             }
             else
             else
             {
             {
+                DisposeAppHost();
+
                 ShutdownWindowsApplication();
                 ShutdownWindowsApplication();
             }
             }
         }
         }
 
 
         public static void Restart()
         public static void Restart()
         {
         {
-            _logger.Info("Disposing app host");
-            _appHost.Dispose();
+            DisposeAppHost();
 
 
             if (!_isRunningAsService)
             if (!_isRunningAsService)
             {
             {
@@ -522,11 +524,24 @@ namespace MediaBrowser.ServerApplication
             }
             }
         }
         }
 
 
+        private static void DisposeAppHost()
+        {
+            if (!_appHostDisposed)
+            {
+                _logger.Info("Disposing app host");
+
+                _appHostDisposed = true;
+                _appHost.Dispose();
+            }
+        }
+
         private static void ShutdownWindowsApplication()
         private static void ShutdownWindowsApplication()
         {
         {
             _logger.Info("Calling Application.Exit");
             _logger.Info("Calling Application.Exit");
             Application.Exit();
             Application.Exit();
 
 
+            Environment.Exit(0);
+
             _logger.Info("Calling ApplicationTaskCompletionSource.SetResult");
             _logger.Info("Calling ApplicationTaskCompletionSource.SetResult");
             ApplicationTaskCompletionSource.SetResult(true);
             ApplicationTaskCompletionSource.SetResult(true);
         }
         }

+ 2 - 2
SharedVersion.cs

@@ -1,4 +1,4 @@
 using System.Reflection;
 using System.Reflection;
 
 
-//[assembly: AssemblyVersion("3.0.*")]
-[assembly: AssemblyVersion("3.0.5768.7")]
+[assembly: AssemblyVersion("3.0.*")]
+//[assembly: AssemblyVersion("3.0.5768.7")]