From 5cb74690284105db70a467ab77c2af3f44e42348 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 5 Nov 2017 16:51:23 -0500 Subject: support track selection before playback --- MediaBrowser.Controller/Entities/Audio/Audio.cs | 5 +++ MediaBrowser.Controller/Entities/BaseItem.cs | 2 +- .../Entities/IHasMediaSources.cs | 1 + MediaBrowser.Controller/Entities/Video.cs | 5 +++ MediaBrowser.Controller/LiveTv/LiveTvChannel.cs | 5 +++ .../MediaEncoding/EncodingHelper.cs | 16 ++++--- .../MediaEncoding/IEncodingManager.cs | 3 +- .../Providers/DirectoryService.cs | 52 ++++++++++++---------- .../Providers/IDirectoryService.cs | 3 ++ 9 files changed, 59 insertions(+), 33 deletions(-) (limited to 'MediaBrowser.Controller') diff --git a/MediaBrowser.Controller/Entities/Audio/Audio.cs b/MediaBrowser.Controller/Entities/Audio/Audio.cs index 16fd75d2e9..8ef1060d1a 100644 --- a/MediaBrowser.Controller/Entities/Audio/Audio.cs +++ b/MediaBrowser.Controller/Entities/Audio/Audio.cs @@ -51,6 +51,11 @@ namespace MediaBrowser.Controller.Entities.Audio return 1; } + public bool SupportsMediaSourceSelection() + { + return false; + } + [IgnoreDataMember] public override bool SupportsPlayedStatus { diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index 7f6949feba..f6a8f1d5a4 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -2040,7 +2040,7 @@ namespace MediaBrowser.Controller.Entities .Where(i => i.IsLocalFile) .Select(i => FileSystem.GetDirectoryName(i.Path)) .Distinct(StringComparer.OrdinalIgnoreCase) - .SelectMany(i => FileSystem.GetFilePaths(i)) + .SelectMany(i => directoryService.GetFilePaths(i)) .ToList(); var deletedImages = ImageInfos diff --git a/MediaBrowser.Controller/Entities/IHasMediaSources.cs b/MediaBrowser.Controller/Entities/IHasMediaSources.cs index 54786134f3..399fe9f5a3 100644 --- a/MediaBrowser.Controller/Entities/IHasMediaSources.cs +++ b/MediaBrowser.Controller/Entities/IHasMediaSources.cs @@ -13,5 +13,6 @@ namespace MediaBrowser.Controller.Entities /// Task{IEnumerable{MediaSourceInfo}}. List GetMediaSources(bool enablePathSubstitution); List GetMediaStreams(); + bool SupportsMediaSourceSelection(); } } diff --git a/MediaBrowser.Controller/Entities/Video.cs b/MediaBrowser.Controller/Entities/Video.cs index 52f1dd0514..60db53f790 100644 --- a/MediaBrowser.Controller/Entities/Video.cs +++ b/MediaBrowser.Controller/Entities/Video.cs @@ -109,6 +109,11 @@ namespace MediaBrowser.Controller.Entities get { return true; } } + public bool SupportsMediaSourceSelection() + { + return SourceType == SourceType.Library; + } + /// /// Gets or sets the timestamp. /// diff --git a/MediaBrowser.Controller/LiveTv/LiveTvChannel.cs b/MediaBrowser.Controller/LiveTv/LiveTvChannel.cs index 16010b7f5a..ac961d757e 100644 --- a/MediaBrowser.Controller/LiveTv/LiveTvChannel.cs +++ b/MediaBrowser.Controller/LiveTv/LiveTvChannel.cs @@ -24,6 +24,11 @@ namespace MediaBrowser.Controller.LiveTv return list; } + public bool SupportsMediaSourceSelection() + { + return false; + } + public override UnratedItem GetBlockUnratedType() { return UnratedItem.LiveTvChannel; diff --git a/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs b/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs index bddafe9a6a..8f8791922d 100644 --- a/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs +++ b/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs @@ -1325,6 +1325,8 @@ namespace MediaBrowser.Controller.MediaEncoding if (state.VideoStream != null && state.VideoStream.Width.HasValue && state.VideoStream.Height.HasValue) { videoSizeParam = string.Format("scale={0}:{1}", state.VideoStream.Width.Value.ToString(_usCulture), state.VideoStream.Height.Value.ToString(_usCulture)); + + videoSizeParam += ":force_original_aspect_ratio=decrease"; } var mapPrefix = state.SubtitleStream.IsExternal ? @@ -1335,7 +1337,7 @@ namespace MediaBrowser.Controller.MediaEncoding ? 0 : state.SubtitleStream.Index; - return string.Format(" -filter_complex \"[{0}:{1}]{4}[sub] ; [0:{2}] [sub] overlay{3}\"", + return string.Format(" -filter_complex \"[{0}:{1}]{4}[sub];[0:{2}][sub]overlay{3}\"", mapPrefix.ToString(_usCulture), subtitleStreamIndex.ToString(_usCulture), state.VideoStream.Index.ToString(_usCulture), @@ -2094,6 +2096,12 @@ namespace MediaBrowser.Controller.MediaEncoding args += " -avoid_negative_ts disabled -start_at_zero"; } + // This is for internal graphical subs + if (hasGraphicalSubs) + { + args += GetGraphicalSubtitleParam(state, encodingOptions, videoCodec); + } + var qualityParam = GetVideoQualityParam(state, videoCodec, encodingOptions, defaultH264Preset); if (!string.IsNullOrEmpty(qualityParam)) @@ -2101,12 +2109,6 @@ namespace MediaBrowser.Controller.MediaEncoding args += " " + qualityParam.Trim(); } - // This is for internal graphical subs - if (hasGraphicalSubs) - { - args += GetGraphicalSubtitleParam(state, encodingOptions, videoCodec); - } - if (!state.RunTimeTicks.HasValue) { args += " -flags -global_header"; diff --git a/MediaBrowser.Controller/MediaEncoding/IEncodingManager.cs b/MediaBrowser.Controller/MediaEncoding/IEncodingManager.cs index 81269fe3fa..7d50efd5ed 100644 --- a/MediaBrowser.Controller/MediaEncoding/IEncodingManager.cs +++ b/MediaBrowser.Controller/MediaEncoding/IEncodingManager.cs @@ -3,6 +3,7 @@ using System.Threading; using System.Threading.Tasks; using MediaBrowser.Controller.Entities; using MediaBrowser.Model.Entities; +using MediaBrowser.Controller.Providers; namespace MediaBrowser.Controller.MediaEncoding { @@ -11,6 +12,6 @@ namespace MediaBrowser.Controller.MediaEncoding /// /// Refreshes the chapter images. /// - Task RefreshChapterImages(Video video, List chapters, bool extractImages, bool saveChapters, CancellationToken cancellationToken); + Task RefreshChapterImages(Video video, IDirectoryService directoryService, List chapters, bool extractImages, bool saveChapters, CancellationToken cancellationToken); } } diff --git a/MediaBrowser.Controller/Providers/DirectoryService.cs b/MediaBrowser.Controller/Providers/DirectoryService.cs index d957470d3b..d673198fdc 100644 --- a/MediaBrowser.Controller/Providers/DirectoryService.cs +++ b/MediaBrowser.Controller/Providers/DirectoryService.cs @@ -14,11 +14,11 @@ namespace MediaBrowser.Controller.Providers private readonly ILogger _logger; private readonly IFileSystem _fileSystem; - private readonly ConcurrentDictionary _cache = - new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase); + private readonly Dictionary _cache = new Dictionary(StringComparer.OrdinalIgnoreCase); - private readonly ConcurrentDictionary _fileCache = - new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase); + private readonly Dictionary _fileCache = new Dictionary(StringComparer.OrdinalIgnoreCase); + + private readonly Dictionary> _filePathCache = new Dictionary>(StringComparer.OrdinalIgnoreCase); public DirectoryService(ILogger logger, IFileSystem fileSystem) { @@ -32,11 +32,6 @@ namespace MediaBrowser.Controller.Providers } public FileSystemMetadata[] GetFileSystemEntries(string path) - { - return GetFileSystemEntries(path, false); - } - - private FileSystemMetadata[] GetFileSystemEntries(string path, bool clearCache) { if (string.IsNullOrWhiteSpace(path)) { @@ -45,13 +40,6 @@ namespace MediaBrowser.Controller.Providers FileSystemMetadata[] entries; - if (clearCache) - { - FileSystemMetadata[] removed; - - _cache.TryRemove(path, out removed); - } - if (!_cache.TryGetValue(path, out entries)) { //_logger.Debug("Getting files for " + path); @@ -66,21 +54,17 @@ namespace MediaBrowser.Controller.Providers entries = new FileSystemMetadata[] { }; } - _cache.TryAdd(path, entries); + //_cache.TryAdd(path, entries); + _cache[path] = entries; } return entries; } public List GetFiles(string path) - { - return GetFiles(path, false); - } - - public List GetFiles(string path, bool clearCache) { var list = new List(); - var items = GetFileSystemEntries(path, clearCache); + var items = GetFileSystemEntries(path); foreach (var item in items) { if (!item.IsDirectory) @@ -100,7 +84,8 @@ namespace MediaBrowser.Controller.Providers if (file != null && file.Exists) { - _fileCache.TryAdd(path, file); + //_fileCache.TryAdd(path, file); + _fileCache[path] = file; } else { @@ -111,5 +96,24 @@ namespace MediaBrowser.Controller.Providers return file; //return _fileSystem.GetFileInfo(path); } + + public List GetFilePaths(string path) + { + return GetFilePaths(path, false); + } + + public List GetFilePaths(string path, bool clearCache) + { + List result; + if (clearCache || !_filePathCache.TryGetValue(path, out result)) + { + result = _fileSystem.GetFilePaths(path).ToList(); + + _filePathCache[path] = result; + } + + return result; + } + } } diff --git a/MediaBrowser.Controller/Providers/IDirectoryService.cs b/MediaBrowser.Controller/Providers/IDirectoryService.cs index 6f864f4be2..0b4574f6e5 100644 --- a/MediaBrowser.Controller/Providers/IDirectoryService.cs +++ b/MediaBrowser.Controller/Providers/IDirectoryService.cs @@ -8,5 +8,8 @@ namespace MediaBrowser.Controller.Providers FileSystemMetadata[] GetFileSystemEntries(string path); List GetFiles(string path); FileSystemMetadata GetFile(string path); + + List GetFilePaths(string path); + List GetFilePaths(string path, bool clearCache); } } \ No newline at end of file -- cgit v1.2.3