From 3cc0ad2a3599de1134b97057f14000ea9523fa3d Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 5 Apr 2015 23:47:01 -0400 Subject: add notification services tab --- .../EntryPoints/LibraryChangedNotifier.cs | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'MediaBrowser.Server.Implementations/EntryPoints') diff --git a/MediaBrowser.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs b/MediaBrowser.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs index 090f1e7569..1ffaf5b8ce 100644 --- a/MediaBrowser.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs +++ b/MediaBrowser.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs @@ -245,23 +245,17 @@ namespace MediaBrowser.Server.Implementations.EntryPoints var collections = user.RootFolder.GetChildren(user, true).ToList(); - var allRecursiveChildren = user.RootFolder - .GetRecursiveChildren(user) - .Select(i => i.Id) - .Distinct() - .ToDictionary(i => i); - return new LibraryUpdateInfo { - ItemsAdded = itemsAdded.SelectMany(i => TranslatePhysicalItemToUserLibrary(i, user, collections, allRecursiveChildren)).Select(i => i.Id.ToString("N")).Distinct().ToList(), + ItemsAdded = itemsAdded.SelectMany(i => TranslatePhysicalItemToUserLibrary(i, user, collections)).Select(i => i.Id.ToString("N")).Distinct().ToList(), - ItemsUpdated = itemsUpdated.SelectMany(i => TranslatePhysicalItemToUserLibrary(i, user, collections, allRecursiveChildren)).Select(i => i.Id.ToString("N")).Distinct().ToList(), + ItemsUpdated = itemsUpdated.SelectMany(i => TranslatePhysicalItemToUserLibrary(i, user, collections)).Select(i => i.Id.ToString("N")).Distinct().ToList(), - ItemsRemoved = itemsRemoved.SelectMany(i => TranslatePhysicalItemToUserLibrary(i, user, collections, allRecursiveChildren, true)).Select(i => i.Id.ToString("N")).Distinct().ToList(), + ItemsRemoved = itemsRemoved.SelectMany(i => TranslatePhysicalItemToUserLibrary(i, user, collections, true)).Select(i => i.Id.ToString("N")).Distinct().ToList(), - FoldersAddedTo = foldersAddedTo.SelectMany(i => TranslatePhysicalItemToUserLibrary(i, user, collections, allRecursiveChildren)).Select(i => i.Id.ToString("N")).Distinct().ToList(), + FoldersAddedTo = foldersAddedTo.SelectMany(i => TranslatePhysicalItemToUserLibrary(i, user, collections)).Select(i => i.Id.ToString("N")).Distinct().ToList(), - FoldersRemovedFrom = foldersRemovedFrom.SelectMany(i => TranslatePhysicalItemToUserLibrary(i, user, collections, allRecursiveChildren)).Select(i => i.Id.ToString("N")).Distinct().ToList() + FoldersRemovedFrom = foldersRemovedFrom.SelectMany(i => TranslatePhysicalItemToUserLibrary(i, user, collections)).Select(i => i.Id.ToString("N")).Distinct().ToList() }; } @@ -272,10 +266,9 @@ namespace MediaBrowser.Server.Implementations.EntryPoints /// The item. /// The user. /// The collections. - /// All recursive children. /// if set to true [include if not found]. /// IEnumerable{``0}. - private IEnumerable TranslatePhysicalItemToUserLibrary(T item, User user, IEnumerable collections, Dictionary allRecursiveChildren, bool includeIfNotFound = false) + private IEnumerable TranslatePhysicalItemToUserLibrary(T item, User user, IEnumerable collections, bool includeIfNotFound = false) where T : BaseItem { // If the physical root changed, return the user root @@ -294,7 +287,7 @@ namespace MediaBrowser.Server.Implementations.EntryPoints } // Return it only if it's in the user's library - if (includeIfNotFound || allRecursiveChildren.ContainsKey(item.Id) || (item.Parents.Any(i => i is BasePluginFolder) && item.IsVisibleStandalone(user))) + if (includeIfNotFound || item.IsVisibleStandalone(user)) { return new[] { item }; } -- cgit v1.2.3 From fbbab13b3134a0d6179e42fd8dbbc629654c1c28 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 10 Apr 2015 10:49:03 -0400 Subject: fix library changed --- .../Channels/ChannelAudioItem.cs | 2 +- .../Channels/ChannelFolderItem.cs | 2 +- .../Channels/ChannelVideoItem.cs | 2 +- MediaBrowser.Controller/Entities/BaseItem.cs | 31 +++++++++++++++------- .../EntryPoints/LibraryChangedNotifier.cs | 24 +++++------------ 5 files changed, 31 insertions(+), 30 deletions(-) (limited to 'MediaBrowser.Server.Implementations/EntryPoints') diff --git a/MediaBrowser.Controller/Channels/ChannelAudioItem.cs b/MediaBrowser.Controller/Channels/ChannelAudioItem.cs index 7582f4c91b..82fe66c7ba 100644 --- a/MediaBrowser.Controller/Channels/ChannelAudioItem.cs +++ b/MediaBrowser.Controller/Channels/ChannelAudioItem.cs @@ -104,7 +104,7 @@ namespace MediaBrowser.Controller.Channels public override bool IsVisibleStandalone(User user) { - return base.IsVisibleStandalone(user) && ChannelVideoItem.IsChannelVisible(this, user); + return IsVisibleStandaloneInternal(user, false) && ChannelVideoItem.IsChannelVisible(this, user); } } } diff --git a/MediaBrowser.Controller/Channels/ChannelFolderItem.cs b/MediaBrowser.Controller/Channels/ChannelFolderItem.cs index 43f5160a45..641d37161a 100644 --- a/MediaBrowser.Controller/Channels/ChannelFolderItem.cs +++ b/MediaBrowser.Controller/Channels/ChannelFolderItem.cs @@ -83,7 +83,7 @@ namespace MediaBrowser.Controller.Channels public override bool IsVisibleStandalone(User user) { - return base.IsVisibleStandalone(user) && ChannelVideoItem.IsChannelVisible(this, user); + return IsVisibleStandaloneInternal(user, false) && ChannelVideoItem.IsChannelVisible(this, user); } } } diff --git a/MediaBrowser.Controller/Channels/ChannelVideoItem.cs b/MediaBrowser.Controller/Channels/ChannelVideoItem.cs index d97341d8f9..ef3cc7cbab 100644 --- a/MediaBrowser.Controller/Channels/ChannelVideoItem.cs +++ b/MediaBrowser.Controller/Channels/ChannelVideoItem.cs @@ -133,7 +133,7 @@ namespace MediaBrowser.Controller.Channels public override bool IsVisibleStandalone(User user) { - return base.IsVisibleStandalone(user) && IsChannelVisible(this, user); + return IsVisibleStandaloneInternal(user, false) && IsChannelVisible(this, user); } internal static bool IsChannelVisible(IChannelItem item, User user) diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index f8384ea1c0..a1bcde9e68 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -1143,6 +1143,11 @@ namespace MediaBrowser.Controller.Entities } public virtual bool IsVisibleStandalone(User user) + { + return IsVisibleStandaloneInternal(user, true); + } + + protected bool IsVisibleStandaloneInternal(User user, bool checkFolders) { if (!IsVisible(user)) { @@ -1154,17 +1159,25 @@ namespace MediaBrowser.Controller.Entities return false; } - var topParent = Parents.LastOrDefault() ?? this; - - if (string.IsNullOrWhiteSpace(topParent.Path)) + if (checkFolders) { - return true; - } + var topParent = Parents.LastOrDefault() ?? this; - var folders = user.RootFolder.GetChildren(user, true).Select(i => i.Id).ToList(); - var itemCollectionFolders = LibraryManager.GetCollectionFolders(this).Select(i => i.Id).ToList(); + if (string.IsNullOrWhiteSpace(topParent.Path)) + { + return true; + } - return itemCollectionFolders.Any(folders.Contains); + var userCollectionFolders = user.RootFolder.GetChildren(user, true).Select(i => i.Id).ToList(); + var itemCollectionFolders = LibraryManager.GetCollectionFolders(this).Select(i => i.Id); + + if (!itemCollectionFolders.Any(userCollectionFolders.Contains)) + { + return false; + } + } + + return true; } /// @@ -1669,7 +1682,7 @@ namespace MediaBrowser.Controller.Entities else { existing.DateModified = FileSystem.GetLastWriteTimeUtc(newImage); - existing.Length = ((FileInfo) newImage).Length; + existing.Length = ((FileInfo)newImage).Length; } } diff --git a/MediaBrowser.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs b/MediaBrowser.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs index 1ffaf5b8ce..b1bc5dbe54 100644 --- a/MediaBrowser.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs +++ b/MediaBrowser.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs @@ -243,19 +243,17 @@ namespace MediaBrowser.Server.Implementations.EntryPoints { var user = _userManager.GetUserById(userId); - var collections = user.RootFolder.GetChildren(user, true).ToList(); - return new LibraryUpdateInfo { - ItemsAdded = itemsAdded.SelectMany(i => TranslatePhysicalItemToUserLibrary(i, user, collections)).Select(i => i.Id.ToString("N")).Distinct().ToList(), + ItemsAdded = itemsAdded.SelectMany(i => TranslatePhysicalItemToUserLibrary(i, user)).Select(i => i.Id.ToString("N")).Distinct().ToList(), - ItemsUpdated = itemsUpdated.SelectMany(i => TranslatePhysicalItemToUserLibrary(i, user, collections)).Select(i => i.Id.ToString("N")).Distinct().ToList(), + ItemsUpdated = itemsUpdated.SelectMany(i => TranslatePhysicalItemToUserLibrary(i, user)).Select(i => i.Id.ToString("N")).Distinct().ToList(), - ItemsRemoved = itemsRemoved.SelectMany(i => TranslatePhysicalItemToUserLibrary(i, user, collections, true)).Select(i => i.Id.ToString("N")).Distinct().ToList(), + ItemsRemoved = itemsRemoved.SelectMany(i => TranslatePhysicalItemToUserLibrary(i, user, true)).Select(i => i.Id.ToString("N")).Distinct().ToList(), - FoldersAddedTo = foldersAddedTo.SelectMany(i => TranslatePhysicalItemToUserLibrary(i, user, collections)).Select(i => i.Id.ToString("N")).Distinct().ToList(), + FoldersAddedTo = foldersAddedTo.SelectMany(i => TranslatePhysicalItemToUserLibrary(i, user)).Select(i => i.Id.ToString("N")).Distinct().ToList(), - FoldersRemovedFrom = foldersRemovedFrom.SelectMany(i => TranslatePhysicalItemToUserLibrary(i, user, collections)).Select(i => i.Id.ToString("N")).Distinct().ToList() + FoldersRemovedFrom = foldersRemovedFrom.SelectMany(i => TranslatePhysicalItemToUserLibrary(i, user)).Select(i => i.Id.ToString("N")).Distinct().ToList() }; } @@ -265,10 +263,9 @@ namespace MediaBrowser.Server.Implementations.EntryPoints /// /// The item. /// The user. - /// The collections. /// if set to true [include if not found]. /// IEnumerable{``0}. - private IEnumerable TranslatePhysicalItemToUserLibrary(T item, User user, IEnumerable collections, bool includeIfNotFound = false) + private IEnumerable TranslatePhysicalItemToUserLibrary(T item, User user, bool includeIfNotFound = false) where T : BaseItem { // If the physical root changed, return the user root @@ -277,15 +274,6 @@ namespace MediaBrowser.Server.Implementations.EntryPoints return new[] { user.RootFolder as T }; } - // Need to find what user collection folder this belongs to - if (item.Parent is AggregateFolder) - { - if (item.LocationType == LocationType.FileSystem) - { - return collections.Where(i => i.PhysicalLocations.Contains(item.Path)).Cast(); - } - } - // Return it only if it's in the user's library if (includeIfNotFound || item.IsVisibleStandalone(user)) { -- cgit v1.2.3 From a639d32454ed95c476c649473e3b43678b65e44f Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 11 Apr 2015 13:59:55 -0400 Subject: fix chapter image extraction --- MediaBrowser.Controller/Entities/BaseItem.cs | 5 ++ MediaBrowser.Dlna/Ssdp/SsdpHandler.cs | 12 ++- MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs | 98 ++++++++++++++-------- .../EntryPoints/LibraryChangedNotifier.cs | 19 ++++- .../MediaEncoder/EncodingManager.cs | 3 +- 5 files changed, 92 insertions(+), 45 deletions(-) (limited to 'MediaBrowser.Server.Implementations/EntryPoints') diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index ea8510b536..dbc0fc2827 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -1651,6 +1651,11 @@ namespace MediaBrowser.Controller.Entities return AddImages(imageType, images.Cast().ToList()); } + public bool AddImages(ImageType imageType, IEnumerable images) + { + return AddImages(imageType, images.ToList()); + } + /// /// Adds the images. /// diff --git a/MediaBrowser.Dlna/Ssdp/SsdpHandler.cs b/MediaBrowser.Dlna/Ssdp/SsdpHandler.cs index 8ca16832da..73bc4984c8 100644 --- a/MediaBrowser.Dlna/Ssdp/SsdpHandler.cs +++ b/MediaBrowser.Dlna/Ssdp/SsdpHandler.cs @@ -62,16 +62,22 @@ namespace MediaBrowser.Dlna.Ssdp { if (string.Equals(args.Method, "M-SEARCH", StringComparison.OrdinalIgnoreCase)) { - TimeSpan delay = GetSearchDelay(args.Headers); + var headers = args.Headers; + + TimeSpan delay = GetSearchDelay(headers); if (_config.GetDlnaConfiguration().EnableDebugLogging) { _logger.Debug("Delaying search response by {0} seconds", delay.TotalSeconds); } - await Task.Delay(delay).ConfigureAwait(false); + await Task.Delay(delay).ConfigureAwait(false); - RespondToSearch(args.EndPoint, args.Headers["st"]); + string st; + if (headers.TryGetValue("st", out st)) + { + RespondToSearch(args.EndPoint, st); + } } EventHelper.FireEventIfNotNull(MessageReceived, this, args, _logger); diff --git a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs index c309739d01..0bf0075722 100644 --- a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs +++ b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs @@ -75,7 +75,7 @@ namespace MediaBrowser.MediaEncoding.Encoder protected readonly Func SubtitleEncoder; protected readonly Func MediaSourceManager; - private readonly List _runningProcesses = new List(); + private readonly List _runningProcesses = new List(); 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 subtitleEncoder, Func mediaSourceManager) { @@ -197,9 +197,11 @@ namespace MediaBrowser.MediaEncoding.Encoder await _ffProbeResourcePool.WaitAsync(cancellationToken).ConfigureAwait(false); + var processWrapper = new ProcessWrapper(process, this); + try { - StartProcess(process); + StartProcess(processWrapper); } catch (Exception ex) { @@ -264,7 +266,7 @@ namespace MediaBrowser.MediaEncoding.Encoder } catch { - StopProcess(process, 100, true); + StopProcess(processWrapper, 100, true); throw; } @@ -303,7 +305,9 @@ namespace MediaBrowser.MediaEncoding.Encoder _logger.Debug("{0} {1}", process.StartInfo.FileName, process.StartInfo.Arguments); - StartProcess(process); + var processWrapper = new ProcessWrapper(process, this); + + StartProcess(processWrapper); var lines = new List(); var outputCancellationSource = new CancellationTokenSource(4000); @@ -325,7 +329,7 @@ namespace MediaBrowser.MediaEncoding.Encoder } finally { - StopProcess(process, 100, true); + StopProcess(processWrapper, 100, true); } return lines; @@ -382,23 +386,6 @@ namespace MediaBrowser.MediaEncoding.Encoder /// protected readonly CultureInfo UsCulture = new CultureInfo("en-US"); - /// - /// Processes the exited. - /// - /// The sender. - /// The instance containing the event data. - private void ProcessExited(object sender, EventArgs e) - { - var process = (Process) sender; - - lock (_runningProcesses) - { - _runningProcesses.Remove(process); - } - - process.Dispose(); - } - public Task ExtractAudioImage(string path, CancellationToken cancellationToken) { return ExtractImage(new[] { path }, MediaProtocol.File, true, null, null, cancellationToken); @@ -423,6 +410,10 @@ namespace MediaBrowser.MediaEncoding.Encoder { return await ExtractImageInternal(inputArgument, protocol, threedFormat, offset, true, resourcePool, cancellationToken).ConfigureAwait(false); } + catch (ArgumentException) + { + throw; + } catch { _logger.Error("I-frame image extraction failed, will attempt standard way. Input: {0}", inputArgument); @@ -505,7 +496,9 @@ namespace MediaBrowser.MediaEncoding.Encoder await resourcePool.WaitAsync(cancellationToken).ConfigureAwait(false); - StartProcess(process); + var processWrapper = new ProcessWrapper(process, this); + + StartProcess(processWrapper); var memoryStream = new MemoryStream(); @@ -521,12 +514,12 @@ namespace MediaBrowser.MediaEncoding.Encoder if (!ranToCompletion) { - StopProcess(process, 1000, false); + StopProcess(processWrapper, 1000, false); } resourcePool.Release(); - var exitCode = ranToCompletion ? process.ExitCode : -1; + var exitCode = ranToCompletion ? processWrapper.ExitCode ?? 0 : -1; process.Dispose(); @@ -611,9 +604,11 @@ namespace MediaBrowser.MediaEncoding.Encoder bool ranToCompletion; + var processWrapper = new ProcessWrapper(process, this); + try { - StartProcess(process); + StartProcess(processWrapper); // 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. @@ -637,7 +632,7 @@ namespace MediaBrowser.MediaEncoding.Encoder if (!ranToCompletion) { - StopProcess(process, 1000, false); + StopProcess(processWrapper, 1000, false); } } finally @@ -645,7 +640,7 @@ namespace MediaBrowser.MediaEncoding.Encoder resourcePool.Release(); } - var exitCode = ranToCompletion ? process.ExitCode : -1; + var exitCode = ranToCompletion ? processWrapper.ExitCode ?? 0 : -1; process.Dispose(); @@ -699,18 +694,16 @@ namespace MediaBrowser.MediaEncoding.Encoder return job.OutputFilePath; } - private void StartProcess(Process process) + private void StartProcess(ProcessWrapper process) { - process.Exited += ProcessExited; - - process.Start(); + process.Process.Start(); lock (_runningProcesses) { _runningProcesses.Add(process); } } - private void StopProcess(Process process, int waitTimeMs, bool enableForceKill) + private void StopProcess(ProcessWrapper process, int waitTimeMs, bool enableForceKill) { try { @@ -718,7 +711,7 @@ namespace MediaBrowser.MediaEncoding.Encoder try { - process.StandardInput.WriteLine("q"); + process.Process.StandardInput.WriteLine("q"); } catch (Exception) { @@ -727,7 +720,7 @@ namespace MediaBrowser.MediaEncoding.Encoder try { - if (process.WaitForExit(waitTimeMs)) + if (process.Process.WaitForExit(waitTimeMs)) { return; } @@ -739,7 +732,7 @@ namespace MediaBrowser.MediaEncoding.Encoder if (enableForceKill) { - process.Kill(); + process.Process .Kill(); } } catch (Exception ex) @@ -750,7 +743,7 @@ namespace MediaBrowser.MediaEncoding.Encoder private void StopProcesses() { - List proceses; + List proceses; lock (_runningProcesses) { proceses = _runningProcesses.ToList(); @@ -782,5 +775,36 @@ namespace MediaBrowser.MediaEncoding.Encoder StopProcesses(); } } + + private class ProcessWrapper + { + public readonly Process Process; + public bool HasExited; + public int? ExitCode; + private readonly MediaEncoder _mediaEncoder; + + public ProcessWrapper(Process process, MediaEncoder mediaEncoder) + { + Process = process; + this._mediaEncoder = mediaEncoder; + Process.Exited += Process_Exited; + } + + void Process_Exited(object sender, EventArgs e) + { + var process = (Process)sender; + + HasExited = true; + + ExitCode = process.ExitCode; + + lock (_mediaEncoder._runningProcesses) + { + _mediaEncoder._runningProcesses.Remove(this); + } + + process.Dispose(); + } + } } } diff --git a/MediaBrowser.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs b/MediaBrowser.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs index b1bc5dbe54..03daa4c2a7 100644 --- a/MediaBrowser.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs +++ b/MediaBrowser.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Channels; +using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Plugins; using MediaBrowser.Controller.Session; @@ -69,7 +70,7 @@ namespace MediaBrowser.Server.Implementations.EntryPoints /// The instance containing the event data. void libraryManager_ItemAdded(object sender, ItemChangeEventArgs e) { - if (e.Item.LocationType == LocationType.Virtual) + if (!FilterItem(e.Item)) { return; } @@ -102,7 +103,7 @@ namespace MediaBrowser.Server.Implementations.EntryPoints /// The instance containing the event data. void libraryManager_ItemUpdated(object sender, ItemChangeEventArgs e) { - if (e.Item.LocationType == LocationType.Virtual) + if (!FilterItem(e.Item)) { return; } @@ -130,7 +131,7 @@ namespace MediaBrowser.Server.Implementations.EntryPoints /// The instance containing the event data. void libraryManager_ItemRemoved(object sender, ItemChangeEventArgs e) { - if (e.Item.LocationType == LocationType.Virtual) + if (!FilterItem(e.Item)) { return; } @@ -257,6 +258,16 @@ namespace MediaBrowser.Server.Implementations.EntryPoints }; } + private bool FilterItem(BaseItem item) + { + if (item.LocationType == LocationType.Virtual) + { + return false; + } + + return !(item is IChannelItem); + } + /// /// Translates the physical item to user library. /// diff --git a/MediaBrowser.Server.Implementations/MediaEncoder/EncodingManager.cs b/MediaBrowser.Server.Implementations/MediaEncoder/EncodingManager.cs index 56557d6e1d..6b99883a52 100644 --- a/MediaBrowser.Server.Implementations/MediaEncoder/EncodingManager.cs +++ b/MediaBrowser.Server.Implementations/MediaEncoder/EncodingManager.cs @@ -151,8 +151,9 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder chapter.ImagePath = path; changesMade = true; } - catch + catch (Exception ex) { + _logger.ErrorException("Error extraching chapter images for {0}", ex, string.Join(",", inputPath)); success = false; break; } -- cgit v1.2.3 From 26094af11522dfc100d709dcd9296805ba1e3fc7 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 13 Apr 2015 12:21:10 -0400 Subject: update live stream termination --- MediaBrowser.Api/ApiEntryPoint.cs | 2 +- MediaBrowser.Api/Playback/Hls/BaseHlsService.cs | 16 ++++++- MediaBrowser.Api/Playback/Hls/VideoHlsService.cs | 2 - .../EntryPoints/ExternalPortForwarding.cs | 55 +++++++++++++++++----- 4 files changed, 59 insertions(+), 16 deletions(-) (limited to 'MediaBrowser.Server.Implementations/EntryPoints') diff --git a/MediaBrowser.Api/ApiEntryPoint.cs b/MediaBrowser.Api/ApiEntryPoint.cs index fd7ad2cf56..ba51f4f8c5 100644 --- a/MediaBrowser.Api/ApiEntryPoint.cs +++ b/MediaBrowser.Api/ApiEntryPoint.cs @@ -340,7 +340,7 @@ namespace MediaBrowser.Api // We can really reduce the timeout for apps that are using the newer api if (!string.IsNullOrWhiteSpace(job.PlaySessionId) && job.Type != TranscodingJobType.Progressive) { - timerDuration = 35000; + timerDuration = 20000; } if (job.KillTimer == null) diff --git a/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs b/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs index 701516b48c..919fe07733 100644 --- a/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs @@ -85,6 +85,7 @@ namespace MediaBrowser.Api.Playback.Hls state.Request.StartTimeTicks = null; } + TranscodingJob job = null; var playlist = state.OutputFilePath; if (!File.Exists(playlist)) @@ -97,7 +98,7 @@ namespace MediaBrowser.Api.Playback.Hls // If the playlist doesn't already exist, startup ffmpeg try { - await StartFfMpeg(state, playlist, cancellationTokenSource).ConfigureAwait(false); + job = await StartFfMpeg(state, playlist, cancellationTokenSource).ConfigureAwait(false); } catch { @@ -116,6 +117,12 @@ namespace MediaBrowser.Api.Playback.Hls if (isLive) { + job = job ?? ApiEntryPoint.Instance.OnTranscodeBeginRequest(playlist, TranscodingJobType); + + if (job != null) + { + ApiEntryPoint.Instance.OnTranscodeEndRequest(job); + } return ResultFactory.GetResult(GetLivePlaylistText(playlist, state.SegmentLength), MimeTypes.GetMimeType("playlist.m3u8"), new Dictionary()); } @@ -134,6 +141,13 @@ namespace MediaBrowser.Api.Playback.Hls var playlistText = GetMasterPlaylistFileText(playlist, videoBitrate + audioBitrate, appendBaselineStream, baselineStreamBitrate); + job = job ?? ApiEntryPoint.Instance.OnTranscodeBeginRequest(playlist, TranscodingJobType); + + if (job != null) + { + ApiEntryPoint.Instance.OnTranscodeEndRequest(job); + } + return ResultFactory.GetResult(playlistText, MimeTypes.GetMimeType("playlist.m3u8"), new Dictionary()); } diff --git a/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs b/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs index b1964f4aef..8e2854c5e8 100644 --- a/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs @@ -3,12 +3,10 @@ using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Devices; using MediaBrowser.Controller.Dlna; using MediaBrowser.Controller.Library; -using MediaBrowser.Controller.LiveTv; using MediaBrowser.Controller.MediaEncoding; using MediaBrowser.Model.IO; using ServiceStack; using System; -using System.IO; namespace MediaBrowser.Api.Playback.Hls { diff --git a/MediaBrowser.Server.Implementations/EntryPoints/ExternalPortForwarding.cs b/MediaBrowser.Server.Implementations/EntryPoints/ExternalPortForwarding.cs index 5c69db3e10..966e0a3e48 100644 --- a/MediaBrowser.Server.Implementations/EntryPoints/ExternalPortForwarding.cs +++ b/MediaBrowser.Server.Implementations/EntryPoints/ExternalPortForwarding.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Controller; +using System.Linq; +using MediaBrowser.Controller; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Plugins; using MediaBrowser.Model.Logging; @@ -47,7 +48,7 @@ namespace MediaBrowser.Server.Implementations.EntryPoints void _config_ConfigurationUpdated(object sender, EventArgs e) { _config.ConfigurationUpdated -= _config_ConfigurationUpdated; - + if (!string.Equals(_lastConfigIdentifier, GetConfigIdentifier(), StringComparison.OrdinalIgnoreCase)) { if (_isStarted) @@ -88,7 +89,7 @@ namespace MediaBrowser.Server.Implementations.EntryPoints NatUtility.UnhandledException += NatUtility_UnhandledException; NatUtility.StartDiscovery(); - _timer = new Timer(s => _createdRules = new List(), null, TimeSpan.FromMinutes(5), TimeSpan.FromMinutes(5)); + _timer = new Timer(s => _createdRules = new List(), null, TimeSpan.FromMinutes(3), TimeSpan.FromMinutes(3)); _lastConfigIdentifier = GetConfigIdentifier(); @@ -119,7 +120,7 @@ namespace MediaBrowser.Server.Implementations.EntryPoints CreateRules(device); } - catch (Exception) + catch (Exception ex) { // I think it could be a good idea to log the exception because // you are using permanent portmapping here (never expire) and that means that next time @@ -128,7 +129,7 @@ namespace MediaBrowser.Server.Implementations.EntryPoints // It also can fail with others like 727-ExternalPortOnlySupportsWildcard, 728-NoPortMapsAvailable // and those errors (upnp errors) could be useful for diagnosting. - //_logger.ErrorException("Error creating port forwarding rules", ex); + _logger.ErrorException("Error creating port forwarding rules", ex); } } @@ -138,25 +139,55 @@ namespace MediaBrowser.Server.Implementations.EntryPoints // On some systems the device discovered event seems to fire repeatedly // This check will help ensure we're not trying to port map the same device over and over + List currentMappings = null; + + try + { + currentMappings = device.GetAllMappings().ToList(); + } + catch (NotSupportedException) + { + } + var address = device.LocalAddress.ToString(); if (!_createdRules.Contains(address)) { _createdRules.Add(address); - CreatePortMap(device, _appHost.HttpPort, _config.Configuration.PublicPort); - CreatePortMap(device, _appHost.HttpsPort, _config.Configuration.PublicHttpsPort); + CreatePortMap(device, currentMappings, _appHost.HttpPort, _config.Configuration.PublicPort); + CreatePortMap(device, currentMappings, _appHost.HttpsPort, _config.Configuration.PublicHttpsPort); } } - private void CreatePortMap(INatDevice device, int privatePort, int publicPort) + private void CreatePortMap(INatDevice device, List currentMappings, int privatePort, int publicPort) { - _logger.Debug("Creating port map on port {0}", privatePort); + var hasMapping = false; + + if (currentMappings != null) + { + hasMapping = currentMappings.Any(i => i.PublicPort == publicPort && i.PrivatePort == privatePort); + } + else + { + try + { + var mapping = device.GetSpecificMapping(Protocol.Tcp, publicPort); + hasMapping = mapping != null; + } + catch (NotSupportedException) + { + } + } - device.CreatePortMap(new Mapping(Protocol.Tcp, privatePort, publicPort) + if (!hasMapping) { - Description = _appHost.Name - }); + _logger.Debug("Creating port map on port {0}", privatePort); + device.CreatePortMap(new Mapping(Protocol.Tcp, privatePort, publicPort) + { + Description = _appHost.Name + }); + } } // As I said before, this method will be never invoked. You can remove it. -- cgit v1.2.3