From aa290062d63021c5a2251f5a71086313af0bacbd Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 16 Feb 2017 02:13:32 -0500 Subject: [PATCH 1/3] fix server restart --- Emby.Server.Implementations/HttpServer/HttpListenerHost.cs | 2 -- Emby.Server.Implementations/ServerManager/ServerManager.cs | 4 ++++ MediaBrowser.ServerApplication/MainStartup.cs | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs index c65289e13..6fcdab874 100644 --- a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs +++ b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs @@ -767,8 +767,6 @@ namespace Emby.Server.Implementations.HttpServer { if (_disposed) return; - Dispose(); - lock (_disposeLock) { if (_disposed) return; diff --git a/Emby.Server.Implementations/ServerManager/ServerManager.cs b/Emby.Server.Implementations/ServerManager/ServerManager.cs index f7e4c0ce2..4c9228e54 100644 --- a/Emby.Server.Implementations/ServerManager/ServerManager.cs +++ b/Emby.Server.Implementations/ServerManager/ServerManager.cs @@ -303,6 +303,7 @@ namespace Emby.Server.Implementations.ServerManager /// private void DisposeHttpServer() { + _logger.Info("Disposing web socket connections"); foreach (var socket in _webSocketConnections) { // Dispose the connection @@ -314,6 +315,9 @@ namespace Emby.Server.Implementations.ServerManager if (HttpServer != null) { HttpServer.WebSocketConnected -= HttpServer_WebSocketConnected; + + _logger.Info("Disposing http server"); + HttpServer.Dispose(); } } diff --git a/MediaBrowser.ServerApplication/MainStartup.cs b/MediaBrowser.ServerApplication/MainStartup.cs index 70b86c4a6..0e3f684b5 100644 --- a/MediaBrowser.ServerApplication/MainStartup.cs +++ b/MediaBrowser.ServerApplication/MainStartup.cs @@ -676,6 +676,7 @@ namespace MediaBrowser.ServerApplication _appHostDisposed = true; _appHost.Dispose(); + _logger.Info("App host dispose complete"); } } From 03317b291de069d351a6055f202fe557d09ef74a Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 16 Feb 2017 02:14:12 -0500 Subject: [PATCH 2/3] improve subtitle responses --- .../Subtitles/SubtitleEncoder.cs | 45 ++++++++----------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs b/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs index 0bbc2d916..ca22dac2d 100644 --- a/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs +++ b/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs @@ -19,6 +19,7 @@ using System.Threading; using System.Threading.Tasks; using MediaBrowser.Model.IO; using MediaBrowser.Model.Diagnostics; +using MediaBrowser.Model.Dto; using MediaBrowser.Model.Text; using UniversalDetector; @@ -137,18 +138,29 @@ namespace MediaBrowser.MediaEncoding.Subtitles throw new ArgumentNullException("mediaSourceId"); } - var subtitle = await GetSubtitleStream(itemId, mediaSourceId, subtitleStreamIndex, cancellationToken) + var mediaSources = await _mediaSourceManager.GetPlayackMediaSources(itemId, null, false, new[] { MediaType.Audio, MediaType.Video }, cancellationToken).ConfigureAwait(false); + + var mediaSource = mediaSources + .First(i => string.Equals(i.Id, mediaSourceId, StringComparison.OrdinalIgnoreCase)); + + var subtitleStream = mediaSource.MediaStreams + .First(i => i.Type == MediaStreamType.Subtitle && i.Index == subtitleStreamIndex); + + var subtitle = await GetSubtitleStream(mediaSource, subtitleStream, cancellationToken) .ConfigureAwait(false); var inputFormat = subtitle.Item2; var writer = TryGetWriter(outputFormat); - if (string.Equals(inputFormat, outputFormat, StringComparison.OrdinalIgnoreCase) && writer == null) + // Return the original if we don't have any way of converting it + if (writer == null) { return subtitle.Item1; } - if (writer == null) + // Return the original if the same format is being requested + // Character encoding was already handled in GetSubtitleStream + if (string.Equals(inputFormat, outputFormat, StringComparison.OrdinalIgnoreCase)) { return subtitle.Item1; } @@ -159,36 +171,17 @@ namespace MediaBrowser.MediaEncoding.Subtitles } } - private async Task> GetSubtitleStream(string itemId, - string mediaSourceId, - int subtitleStreamIndex, + private async Task> GetSubtitleStream(MediaSourceInfo mediaSource, + MediaStream subtitleStream, CancellationToken cancellationToken) { - if (string.IsNullOrWhiteSpace(itemId)) - { - throw new ArgumentNullException("itemId"); - } - if (string.IsNullOrWhiteSpace(mediaSourceId)) - { - throw new ArgumentNullException("mediaSourceId"); - } - - var mediaSources = await _mediaSourceManager.GetPlayackMediaSources(itemId, null, false, new[] { MediaType.Audio, MediaType.Video }, cancellationToken).ConfigureAwait(false); - - var mediaSource = mediaSources - .First(i => string.Equals(i.Id, mediaSourceId, StringComparison.OrdinalIgnoreCase)); - - var subtitleStream = mediaSource.MediaStreams - .First(i => i.Type == MediaStreamType.Subtitle && i.Index == subtitleStreamIndex); - var inputFiles = new[] { mediaSource.Path }; if (mediaSource.VideoType.HasValue) { - if (mediaSource.VideoType.Value == VideoType.BluRay || - mediaSource.VideoType.Value == VideoType.Dvd) + if (mediaSource.VideoType.Value == VideoType.BluRay || mediaSource.VideoType.Value == VideoType.Dvd) { - var mediaSourceItem = (Video)_libraryManager.GetItemById(new Guid(mediaSourceId)); + var mediaSourceItem = (Video)_libraryManager.GetItemById(new Guid(mediaSource.Id)); inputFiles = mediaSourceItem.GetPlayableStreamFiles().ToArray(); } } From f6590ebf279397b33a583d4bb0531a6a3cde2fe6 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 16 Feb 2017 02:39:57 -0500 Subject: [PATCH 3/3] update to sqlite 3.17.0 --- Emby.Server.Core/Emby.Server.Core.xproj | 1 - Emby.Server.Core/project.json | 6 ------ Emby.Server.Implementations/LiveTv/LiveTvManager.cs | 7 +------ 3 files changed, 1 insertion(+), 13 deletions(-) diff --git a/Emby.Server.Core/Emby.Server.Core.xproj b/Emby.Server.Core/Emby.Server.Core.xproj index 00f7664bd..fefaa6284 100644 --- a/Emby.Server.Core/Emby.Server.Core.xproj +++ b/Emby.Server.Core/Emby.Server.Core.xproj @@ -16,7 +16,6 @@ 2.0 - diff --git a/Emby.Server.Core/project.json b/Emby.Server.Core/project.json index e987da6aa..70543d7df 100644 --- a/Emby.Server.Core/project.json +++ b/Emby.Server.Core/project.json @@ -56,9 +56,6 @@ "Emby.Drawing": { "target": "project" }, - "ServiceStack": { - "target": "project" - }, "SocketHttpListener.Portable": { "target": "project" } @@ -121,9 +118,6 @@ }, "SocketHttpListener.Portable": { "target": "project" - }, - "ServiceStack": { - "target": "project" } } } diff --git a/Emby.Server.Implementations/LiveTv/LiveTvManager.cs b/Emby.Server.Implementations/LiveTv/LiveTvManager.cs index e30280967..b139c68f4 100644 --- a/Emby.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/Emby.Server.Implementations/LiveTv/LiveTvManager.cs @@ -1477,12 +1477,7 @@ namespace Emby.Server.Implementations.LiveTv private DateTime _lastRecordingRefreshTime; private async Task RefreshRecordings(CancellationToken cancellationToken) { - const int cacheMinutes = 3; - - if ((DateTime.UtcNow - _lastRecordingRefreshTime).TotalMinutes < cacheMinutes) - { - return; - } + const int cacheMinutes = 2; await _refreshRecordingsLock.WaitAsync(cancellationToken).ConfigureAwait(false);