From c8a106f485ff7e340ee8ca67adac3351ec6a31b6 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 12 Jan 2014 01:31:21 -0500 Subject: [PATCH] move media encoder to server project --- .../Playback/BaseStreamingService.cs | 3 +- .../Playback/Hls/AudioHlsService.cs | 2 +- .../Playback/Hls/BaseHlsService.cs | 2 +- .../Playback/Hls/VideoHlsService.cs | 2 +- .../Playback/Progressive/AudioService.cs | 2 +- .../BaseProgressiveStreamingService.cs | 2 +- .../Playback/Progressive/VideoService.cs | 2 +- .../MediaBrowser.Common.csproj | 2 - .../Entities/Audio/Audio.cs | 2 +- .../LiveTv/ILiveTvManager.cs | 3 +- .../MediaBrowser.Controller.csproj | 2 + .../MediaInfo/FFMpegManager.cs | 3 +- .../MediaInfo/IMediaEncoder.cs | 15 ++--- .../MediaInfo/InternalMediaInfoResult.cs | 8 +-- .../MediaInfo/MediaEncoderHelpers.cs | 21 +++++-- MediaBrowser.Model/Entities/MediaStream.cs | 23 ++++++- .../MediaInfo/AudioImageProvider.cs | 4 +- .../MediaInfo/BaseFFProbeProvider.cs | 9 ++- .../MediaInfo/FFProbeAudioInfoProvider.cs | 5 +- .../MediaInfo/FFProbeVideoInfoProvider.cs | 7 +-- .../MediaInfo/VideoImageProvider.cs | 3 +- .../LiveTv/LiveTvDtoService.cs | 2 +- .../LiveTv/LiveTvManager.cs | 62 +++++++++++++++++-- .../MediaEncoder/MediaEncoder.cs | 24 +++---- .../ApplicationHost.cs | 7 +-- 25 files changed, 144 insertions(+), 73 deletions(-) rename {MediaBrowser.Common => MediaBrowser.Controller}/MediaInfo/IMediaEncoder.cs (87%) rename MediaBrowser.Common/MediaInfo/MediaInfoResult.cs => MediaBrowser.Controller/MediaInfo/InternalMediaInfoResult.cs (98%) diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index d9bd873cd..59fac5726 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -1,6 +1,5 @@ using MediaBrowser.Common.Extensions; using MediaBrowser.Common.IO; -using MediaBrowser.Common.MediaInfo; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Entities; @@ -733,7 +732,7 @@ namespace MediaBrowser.Api.Playback return "-"; } - var type = InputType.AudioFile; + var type = InputType.File; var inputPath = new[] { state.MediaPath }; diff --git a/MediaBrowser.Api/Playback/Hls/AudioHlsService.cs b/MediaBrowser.Api/Playback/Hls/AudioHlsService.cs index d5bf22362..a64cdb119 100644 --- a/MediaBrowser.Api/Playback/Hls/AudioHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/AudioHlsService.cs @@ -1,9 +1,9 @@ using MediaBrowser.Common.IO; -using MediaBrowser.Common.MediaInfo; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.LiveTv; +using MediaBrowser.Controller.MediaInfo; using MediaBrowser.Controller.Persistence; using MediaBrowser.Model.Dto; using MediaBrowser.Model.IO; diff --git a/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs b/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs index 8ac8dc9fc..1c4326928 100644 --- a/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs @@ -1,11 +1,11 @@ using MediaBrowser.Common.Extensions; using MediaBrowser.Common.IO; -using MediaBrowser.Common.MediaInfo; using MediaBrowser.Common.Net; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.LiveTv; +using MediaBrowser.Controller.MediaInfo; using MediaBrowser.Controller.Persistence; using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Dto; diff --git a/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs b/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs index 8fbb42f24..c87f61a1f 100644 --- a/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs @@ -1,9 +1,9 @@ using MediaBrowser.Common.IO; -using MediaBrowser.Common.MediaInfo; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.LiveTv; +using MediaBrowser.Controller.MediaInfo; using MediaBrowser.Controller.Persistence; using MediaBrowser.Model.IO; using ServiceStack; diff --git a/MediaBrowser.Api/Playback/Progressive/AudioService.cs b/MediaBrowser.Api/Playback/Progressive/AudioService.cs index 050c06627..a7ef684a5 100644 --- a/MediaBrowser.Api/Playback/Progressive/AudioService.cs +++ b/MediaBrowser.Api/Playback/Progressive/AudioService.cs @@ -1,10 +1,10 @@ using MediaBrowser.Common.IO; -using MediaBrowser.Common.MediaInfo; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Drawing; using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.LiveTv; +using MediaBrowser.Controller.MediaInfo; using MediaBrowser.Controller.Persistence; using MediaBrowser.Model.IO; using ServiceStack; diff --git a/MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs b/MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs index 0ae96effd..9c5acb7a0 100644 --- a/MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs +++ b/MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs @@ -1,12 +1,12 @@ using System; using MediaBrowser.Common.IO; -using MediaBrowser.Common.MediaInfo; using MediaBrowser.Common.Net; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Drawing; using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.LiveTv; +using MediaBrowser.Controller.MediaInfo; using MediaBrowser.Controller.Persistence; using MediaBrowser.Model.Dto; using MediaBrowser.Model.IO; diff --git a/MediaBrowser.Api/Playback/Progressive/VideoService.cs b/MediaBrowser.Api/Playback/Progressive/VideoService.cs index c3ec02a59..f3ccaa244 100644 --- a/MediaBrowser.Api/Playback/Progressive/VideoService.cs +++ b/MediaBrowser.Api/Playback/Progressive/VideoService.cs @@ -1,10 +1,10 @@ using MediaBrowser.Common.IO; -using MediaBrowser.Common.MediaInfo; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Drawing; using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.LiveTv; +using MediaBrowser.Controller.MediaInfo; using MediaBrowser.Controller.Persistence; using MediaBrowser.Model.IO; using ServiceStack; diff --git a/MediaBrowser.Common/MediaBrowser.Common.csproj b/MediaBrowser.Common/MediaBrowser.Common.csproj index 6098c4bb3..63819c5a9 100644 --- a/MediaBrowser.Common/MediaBrowser.Common.csproj +++ b/MediaBrowser.Common/MediaBrowser.Common.csproj @@ -65,8 +65,6 @@ - - diff --git a/MediaBrowser.Controller/Entities/Audio/Audio.cs b/MediaBrowser.Controller/Entities/Audio/Audio.cs index 028fc964d..9e4129cd1 100644 --- a/MediaBrowser.Controller/Entities/Audio/Audio.cs +++ b/MediaBrowser.Controller/Entities/Audio/Audio.cs @@ -109,7 +109,7 @@ namespace MediaBrowser.Controller.Entities.Audio /// System.String. public override string GetUserDataKey() { - var parent = Parent as MusicAlbum; + var parent = FindParent(); if (parent != null) { diff --git a/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs b/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs index d23c8c555..1856182da 100644 --- a/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs +++ b/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs @@ -1,5 +1,4 @@ -using System.IO; -using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Entities; using MediaBrowser.Model.LiveTv; using MediaBrowser.Model.Querying; using System.Collections.Generic; diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index 61de32e41..9082186fd 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -125,6 +125,8 @@ + + diff --git a/MediaBrowser.Controller/MediaInfo/FFMpegManager.cs b/MediaBrowser.Controller/MediaInfo/FFMpegManager.cs index 644222949..c1951038c 100644 --- a/MediaBrowser.Controller/MediaInfo/FFMpegManager.cs +++ b/MediaBrowser.Controller/MediaInfo/FFMpegManager.cs @@ -1,6 +1,5 @@ using MediaBrowser.Common.Extensions; using MediaBrowser.Common.IO; -using MediaBrowser.Common.MediaInfo; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Movies; @@ -178,7 +177,7 @@ namespace MediaBrowser.Controller.MediaInfo Directory.CreateDirectory(parentPath); - await _encoder.ExtractImage(inputPath, type, video.Video3DFormat, time, path, cancellationToken).ConfigureAwait(false); + await _encoder.ExtractImage(inputPath, type, false, video.Video3DFormat, time, path, cancellationToken).ConfigureAwait(false); chapter.ImagePath = path; changesMade = true; } diff --git a/MediaBrowser.Common/MediaInfo/IMediaEncoder.cs b/MediaBrowser.Controller/MediaInfo/IMediaEncoder.cs similarity index 87% rename from MediaBrowser.Common/MediaInfo/IMediaEncoder.cs rename to MediaBrowser.Controller/MediaInfo/IMediaEncoder.cs index 82643779b..8e0d696c9 100644 --- a/MediaBrowser.Common/MediaInfo/IMediaEncoder.cs +++ b/MediaBrowser.Controller/MediaInfo/IMediaEncoder.cs @@ -3,7 +3,7 @@ using System.Threading; using System.Threading.Tasks; using MediaBrowser.Model.Entities; -namespace MediaBrowser.Common.MediaInfo +namespace MediaBrowser.Controller.MediaInfo { /// /// Interface IMediaEncoder @@ -27,12 +27,13 @@ namespace MediaBrowser.Common.MediaInfo /// /// The input files. /// The type. + /// if set to true [is audio]. /// The threed format. /// The offset. /// The output path. /// The cancellation token. /// Task. - Task ExtractImage(string[] inputFiles, InputType type, Video3DFormat? threedFormat, TimeSpan? offset, string outputPath, CancellationToken cancellationToken); + Task ExtractImage(string[] inputFiles, InputType type, bool isAudio, Video3DFormat? threedFormat, TimeSpan? offset, string outputPath, CancellationToken cancellationToken); /// /// Extracts the text subtitle. @@ -62,7 +63,7 @@ namespace MediaBrowser.Common.MediaInfo /// The type. /// The cancellation token. /// Task. - Task GetMediaInfo(string[] inputFiles, InputType type, CancellationToken cancellationToken); + Task GetMediaInfo(string[] inputFiles, InputType type, CancellationToken cancellationToken); /// /// Gets the probe size argument. @@ -86,13 +87,9 @@ namespace MediaBrowser.Common.MediaInfo public enum InputType { /// - /// The audio file + /// The file /// - AudioFile, - /// - /// The video file - /// - VideoFile, + File, /// /// The bluray /// diff --git a/MediaBrowser.Common/MediaInfo/MediaInfoResult.cs b/MediaBrowser.Controller/MediaInfo/InternalMediaInfoResult.cs similarity index 98% rename from MediaBrowser.Common/MediaInfo/MediaInfoResult.cs rename to MediaBrowser.Controller/MediaInfo/InternalMediaInfoResult.cs index d9a666f30..3ceec1b90 100644 --- a/MediaBrowser.Common/MediaInfo/MediaInfoResult.cs +++ b/MediaBrowser.Controller/MediaInfo/InternalMediaInfoResult.cs @@ -1,12 +1,12 @@ -using MediaBrowser.Model.Entities; -using System.Collections.Generic; +using System.Collections.Generic; +using MediaBrowser.Model.Entities; -namespace MediaBrowser.Common.MediaInfo +namespace MediaBrowser.Controller.MediaInfo { /// /// Class MediaInfoResult /// - public class MediaInfoResult + public class InternalMediaInfoResult { /// /// Gets or sets the streams. diff --git a/MediaBrowser.Controller/MediaInfo/MediaEncoderHelpers.cs b/MediaBrowser.Controller/MediaInfo/MediaEncoderHelpers.cs index 261454f6d..300071b7b 100644 --- a/MediaBrowser.Controller/MediaInfo/MediaEncoderHelpers.cs +++ b/MediaBrowser.Controller/MediaInfo/MediaEncoderHelpers.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; -using MediaBrowser.Common.MediaInfo; using MediaBrowser.Model.Entities; using MediaBrowser.Model.IO; @@ -29,7 +28,7 @@ namespace MediaBrowser.Controller.MediaInfo { var inputPath = isoMount == null ? new[] { videoPath } : new[] { isoMount.MountedPath }; - type = InputType.VideoFile; + type = InputType.File; switch (videoType) { @@ -87,7 +86,7 @@ namespace MediaBrowser.Controller.MediaInfo /// InputType. public static InputType GetInputType(VideoType? videoType, IsoType? isoType) { - var type = InputType.AudioFile; + var type = InputType.File; if (videoType.HasValue) { @@ -119,12 +118,22 @@ namespace MediaBrowser.Controller.MediaInfo return type; } - public static IEnumerable GetMediaStreams(MediaInfoResult data) + public static Model.Entities.MediaInfo GetMediaInfo(InternalMediaInfoResult data) { var internalStreams = data.streams ?? new MediaStreamInfo[] { }; - return internalStreams.Select(s => GetMediaStream(s, data.format)) - .Where(i => i != null); + var info = new Model.Entities.MediaInfo(); + + info.MediaStreams = internalStreams.Select(s => GetMediaStream(s, data.format)) + .Where(i => i != null) + .ToList(); + + if (data.format != null) + { + info.Format = data.format.format_name; + } + + return info; } private static readonly CultureInfo UsCulture = new CultureInfo("en-US"); diff --git a/MediaBrowser.Model/Entities/MediaStream.cs b/MediaBrowser.Model/Entities/MediaStream.cs index 133631649..59455889d 100644 --- a/MediaBrowser.Model/Entities/MediaStream.cs +++ b/MediaBrowser.Model/Entities/MediaStream.cs @@ -1,4 +1,5 @@ - +using System.Collections.Generic; + namespace MediaBrowser.Model.Entities { /// @@ -145,4 +146,24 @@ namespace MediaBrowser.Model.Entities /// Subtitle } + + public class MediaInfo + { + /// + /// Gets or sets the media streams. + /// + /// The media streams. + public List MediaStreams { get; set; } + + /// + /// Gets or sets the format. + /// + /// The format. + public string Format { get; set; } + + public MediaInfo() + { + MediaStreams = new List(); + } + } } diff --git a/MediaBrowser.Providers/MediaInfo/AudioImageProvider.cs b/MediaBrowser.Providers/MediaInfo/AudioImageProvider.cs index fd78a7565..8d768a6a0 100644 --- a/MediaBrowser.Providers/MediaInfo/AudioImageProvider.cs +++ b/MediaBrowser.Providers/MediaInfo/AudioImageProvider.cs @@ -1,9 +1,9 @@ using MediaBrowser.Common.Extensions; -using MediaBrowser.Common.MediaInfo; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.MediaInfo; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Logging; @@ -163,7 +163,7 @@ namespace MediaBrowser.Providers.MediaInfo Directory.CreateDirectory(parentPath); - await _mediaEncoder.ExtractImage(new[] { item.Path }, InputType.AudioFile, null, null, path, cancellationToken).ConfigureAwait(false); + await _mediaEncoder.ExtractImage(new[] { item.Path }, InputType.File, true, null, null, path, cancellationToken).ConfigureAwait(false); } finally { diff --git a/MediaBrowser.Providers/MediaInfo/BaseFFProbeProvider.cs b/MediaBrowser.Providers/MediaInfo/BaseFFProbeProvider.cs index cd08f5828..95cbb3e4e 100644 --- a/MediaBrowser.Providers/MediaInfo/BaseFFProbeProvider.cs +++ b/MediaBrowser.Providers/MediaInfo/BaseFFProbeProvider.cs @@ -1,5 +1,4 @@ -using MediaBrowser.Common.MediaInfo; -using MediaBrowser.Controller.Configuration; +using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.MediaInfo; using MediaBrowser.Controller.Providers; @@ -104,11 +103,11 @@ namespace MediaBrowser.Providers.MediaInfo /// inputPath /// or /// cache - protected async Task GetMediaInfo(BaseItem item, IIsoMount isoMount, CancellationToken cancellationToken) + protected async Task GetMediaInfo(BaseItem item, IIsoMount isoMount, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - var type = InputType.AudioFile; + var type = InputType.File; var inputPath = isoMount == null ? new[] { item.Path } : new[] { isoMount.MountedPath }; var video = item as Video; @@ -146,7 +145,7 @@ namespace MediaBrowser.Providers.MediaInfo /// Normalizes the FF probe result. /// /// The result. - protected void NormalizeFFProbeResult(MediaInfoResult result) + protected void NormalizeFFProbeResult(InternalMediaInfoResult result) { if (result.format != null && result.format.tags != null) { diff --git a/MediaBrowser.Providers/MediaInfo/FFProbeAudioInfoProvider.cs b/MediaBrowser.Providers/MediaInfo/FFProbeAudioInfoProvider.cs index a8432969b..d27b65e2a 100644 --- a/MediaBrowser.Providers/MediaInfo/FFProbeAudioInfoProvider.cs +++ b/MediaBrowser.Providers/MediaInfo/FFProbeAudioInfoProvider.cs @@ -1,5 +1,4 @@ using MediaBrowser.Common.Extensions; -using MediaBrowser.Common.MediaInfo; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; @@ -58,9 +57,9 @@ namespace MediaBrowser.Providers.MediaInfo /// The cancellation token. /// The data. /// Task. - protected Task Fetch(Audio audio, CancellationToken cancellationToken, MediaInfoResult data) + protected Task Fetch(Audio audio, CancellationToken cancellationToken, InternalMediaInfoResult data) { - var mediaStreams = MediaEncoderHelpers.GetMediaStreams(data).ToList(); + var mediaStreams = MediaEncoderHelpers.GetMediaInfo(data).MediaStreams; audio.HasEmbeddedImage = mediaStreams.Any(i => i.Type == MediaStreamType.Video); diff --git a/MediaBrowser.Providers/MediaInfo/FFProbeVideoInfoProvider.cs b/MediaBrowser.Providers/MediaInfo/FFProbeVideoInfoProvider.cs index 4ce8cf069..fc2c5c370 100644 --- a/MediaBrowser.Providers/MediaInfo/FFProbeVideoInfoProvider.cs +++ b/MediaBrowser.Providers/MediaInfo/FFProbeVideoInfoProvider.cs @@ -1,5 +1,4 @@ using DvdLib.Ifo; -using MediaBrowser.Common.MediaInfo; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Localization; @@ -310,7 +309,7 @@ namespace MediaBrowser.Providers.MediaInfo /// The data. /// The iso mount. /// Task. - protected async Task Fetch(Video video, bool force, BaseProviderInfo providerInfo, CancellationToken cancellationToken, MediaInfoResult data, IIsoMount isoMount) + protected async Task Fetch(Video video, bool force, BaseProviderInfo providerInfo, CancellationToken cancellationToken, InternalMediaInfoResult data, IIsoMount isoMount) { if (data.format != null) { @@ -323,7 +322,7 @@ namespace MediaBrowser.Providers.MediaInfo } } - var mediaStreams = MediaEncoderHelpers.GetMediaStreams(data).ToList(); + var mediaStreams = MediaEncoderHelpers.GetMediaInfo(data).MediaStreams; var chapters = data.Chapters ?? new List(); @@ -370,7 +369,7 @@ namespace MediaBrowser.Providers.MediaInfo /// The video. /// if set to true [force]. /// The data. - private void FetchWtvInfo(Video video, bool force, MediaInfoResult data) + private void FetchWtvInfo(Video video, bool force, InternalMediaInfoResult data) { if (data.format == null || data.format.tags == null) { diff --git a/MediaBrowser.Providers/MediaInfo/VideoImageProvider.cs b/MediaBrowser.Providers/MediaInfo/VideoImageProvider.cs index d5815690f..fc8826b61 100644 --- a/MediaBrowser.Providers/MediaInfo/VideoImageProvider.cs +++ b/MediaBrowser.Providers/MediaInfo/VideoImageProvider.cs @@ -1,5 +1,4 @@ using MediaBrowser.Common.Extensions; -using MediaBrowser.Common.MediaInfo; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; @@ -255,7 +254,7 @@ namespace MediaBrowser.Providers.MediaInfo var inputPath = MediaEncoderHelpers.GetInputArgument(video.Path, video.LocationType == LocationType.Remote, video.VideoType, video.IsoType, isoMount, video.PlayableStreamFileNames, out type); - await _mediaEncoder.ExtractImage(inputPath, type, video.Video3DFormat, imageOffset, path, cancellationToken).ConfigureAwait(false); + await _mediaEncoder.ExtractImage(inputPath, type, false, video.Video3DFormat, imageOffset, path, cancellationToken).ConfigureAwait(false); video.PrimaryImagePath = path; } diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvDtoService.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvDtoService.cs index 83da28b8f..c042e7750 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvDtoService.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvDtoService.cs @@ -368,7 +368,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv return null; } - private const string InternalVersionNumber = "2"; + private const string InternalVersionNumber = "3"; public Guid GetInternalChannelId(string serviceName, string externalId) { diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs index 3bc146bd4..17e17ab70 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs @@ -6,12 +6,14 @@ using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.LiveTv; +using MediaBrowser.Controller.MediaInfo; using MediaBrowser.Controller.Persistence; using MediaBrowser.Model.Entities; using MediaBrowser.Model.LiveTv; using MediaBrowser.Model.Logging; using MediaBrowser.Model.Querying; using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.IO; using System.Linq; @@ -23,7 +25,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv /// /// Class LiveTvManager /// - public class LiveTvManager : ILiveTvManager + public class LiveTvManager : ILiveTvManager, IDisposable { private readonly IServerApplicationPaths _appPaths; private readonly IFileSystem _fileSystem; @@ -31,15 +33,19 @@ namespace MediaBrowser.Server.Implementations.LiveTv private readonly IItemRepository _itemRepo; private readonly IUserManager _userManager; private readonly ILibraryManager _libraryManager; + private readonly IMediaEncoder _mediaEncoder; private readonly LiveTvDtoService _tvDtoService; private readonly List _services = new List(); + private readonly ConcurrentDictionary _openStreams = + new ConcurrentDictionary(); + private List _channelIdList = new List(); private Dictionary _programs = new Dictionary(); - public LiveTvManager(IServerApplicationPaths appPaths, IFileSystem fileSystem, ILogger logger, IItemRepository itemRepo, IImageProcessor imageProcessor, IUserDataManager userDataManager, IDtoService dtoService, IUserManager userManager, ILibraryManager libraryManager) + public LiveTvManager(IServerApplicationPaths appPaths, IFileSystem fileSystem, ILogger logger, IItemRepository itemRepo, IImageProcessor imageProcessor, IUserDataManager userDataManager, IDtoService dtoService, IUserManager userManager, ILibraryManager libraryManager, IMediaEncoder mediaEncoder) { _appPaths = appPaths; _fileSystem = fileSystem; @@ -47,6 +53,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv _itemRepo = itemRepo; _userManager = userManager; _libraryManager = libraryManager; + _mediaEncoder = mediaEncoder; _tvDtoService = new LiveTvDtoService(dtoService, userDataManager, imageProcessor, logger, _itemRepo); } @@ -180,7 +187,14 @@ namespace MediaBrowser.Server.Implementations.LiveTv var recording = recordings.First(i => _tvDtoService.GetInternalRecordingId(service.Name, i.Id) == new Guid(id)); - return await service.GetRecordingStream(recording.Id, cancellationToken).ConfigureAwait(false); + var result = await service.GetRecordingStream(recording.Id, cancellationToken).ConfigureAwait(false); + + if (!string.IsNullOrEmpty(result.Id)) + { + _openStreams.AddOrUpdate(result.Id, result, (key, info) => result); + } + + return result; } public async Task GetChannelStream(string id, CancellationToken cancellationToken) @@ -189,12 +203,19 @@ namespace MediaBrowser.Server.Implementations.LiveTv var channel = GetInternalChannel(id); - return await service.GetChannelStream(channel.ChannelInfo.Id, cancellationToken).ConfigureAwait(false); + var result = await service.GetChannelStream(channel.ChannelInfo.Id, cancellationToken).ConfigureAwait(false); + + if (!string.IsNullOrEmpty(result.Id)) + { + _openStreams.AddOrUpdate(result.Id, result, (key, info) => result); + } + + return result; } private async Task GetChannel(ChannelInfo channelInfo, string serviceName, CancellationToken cancellationToken) { - var path = Path.Combine(_appPaths.ItemsByNamePath, "channels", _fileSystem.GetValidFilename(serviceName), _fileSystem.GetValidFilename(channelInfo.Name)); + var path = Path.Combine(_appPaths.ItemsByNamePath, "channels", _fileSystem.GetValidFilename(channelInfo.Name)); var fileInfo = new DirectoryInfo(path); @@ -1047,5 +1068,36 @@ namespace MediaBrowser.Server.Implementations.LiveTv EndDate = endDate }; } + + /// + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. + /// + public void Dispose() + { + Dispose(true); + } + + private readonly object _disposeLock = new object(); + /// + /// Releases unmanaged and - optionally - managed resources. + /// + /// true to release both managed and unmanaged resources; false to release only unmanaged resources. + protected virtual void Dispose(bool dispose) + { + if (dispose) + { + lock (_disposeLock) + { + foreach (var stream in _openStreams.Values.ToList()) + { + var task = CloseLiveStream(stream.Id, CancellationToken.None); + + Task.WaitAll(task); + } + + _openStreams.Clear(); + } + } + } } } diff --git a/MediaBrowser.Server.Implementations/MediaEncoder/MediaEncoder.cs b/MediaBrowser.Server.Implementations/MediaEncoder/MediaEncoder.cs index bcc857a80..6f956ba20 100644 --- a/MediaBrowser.Server.Implementations/MediaEncoder/MediaEncoder.cs +++ b/MediaBrowser.Server.Implementations/MediaEncoder/MediaEncoder.cs @@ -1,6 +1,6 @@ using MediaBrowser.Common.Configuration; using MediaBrowser.Common.IO; -using MediaBrowser.Common.MediaInfo; +using MediaBrowser.Controller.MediaInfo; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Logging; using MediaBrowser.Model.Serialization; @@ -104,10 +104,10 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder /// The type. /// The cancellation token. /// Task. - public Task GetMediaInfo(string[] inputFiles, InputType type, + public Task GetMediaInfo(string[] inputFiles, InputType type, CancellationToken cancellationToken) { - return GetMediaInfoInternal(GetInputArgument(inputFiles, type), type != InputType.AudioFile, + return GetMediaInfoInternal(GetInputArgument(inputFiles, type), type != InputType.File, GetProbeSizeArgument(type), cancellationToken); } @@ -125,8 +125,7 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder switch (type) { case InputType.Dvd: - case InputType.VideoFile: - case InputType.AudioFile: + case InputType.File: inputPath = GetConcatInputArgument(inputFiles); break; case InputType.Bluray: @@ -173,7 +172,7 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder /// The cancellation token. /// Task{MediaInfoResult}. /// - private async Task GetMediaInfoInternal(string inputPath, bool extractChapters, + private async Task GetMediaInfoInternal(string inputPath, bool extractChapters, string probeSizeArgument, CancellationToken cancellationToken) { @@ -206,7 +205,7 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder await _ffProbeResourcePool.WaitAsync(cancellationToken).ConfigureAwait(false); - MediaInfoResult result; + InternalMediaInfoResult result; string standardError = null; try @@ -236,7 +235,7 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder process.BeginErrorReadLine(); } - result = _jsonSerializer.DeserializeFromStream(process.StandardOutput.BaseStream); + result = _jsonSerializer.DeserializeFromStream(process.StandardOutput.BaseStream); if (extractChapters) { @@ -307,7 +306,7 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder /// /// The result. /// The standard error. - private void AddChapters(MediaInfoResult result, string standardError) + private void AddChapters(InternalMediaInfoResult result, string standardError) { var lines = standardError.Split('\n').Select(l => l.TrimStart()); @@ -797,19 +796,20 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder /// /// The input files. /// The type. + /// if set to true [is audio]. /// The threed format. /// The offset. /// The output path. /// The cancellation token. /// Task. /// Must use inputPath list overload - public async Task ExtractImage(string[] inputFiles, InputType type, Video3DFormat? threedFormat, TimeSpan? offset, string outputPath, CancellationToken cancellationToken) + public async Task ExtractImage(string[] inputFiles, InputType type, bool isAudio, Video3DFormat? threedFormat, TimeSpan? offset, string outputPath, CancellationToken cancellationToken) { - var resourcePool = type == InputType.AudioFile ? _audioImageResourcePool : _videoImageResourcePool; + var resourcePool = isAudio ? _audioImageResourcePool : _videoImageResourcePool; var inputArgument = GetInputArgument(inputFiles, type); - if (type != InputType.AudioFile) + if (!isAudio) { try { diff --git a/MediaBrowser.ServerApplication/ApplicationHost.cs b/MediaBrowser.ServerApplication/ApplicationHost.cs index a14ffc433..21efe8f9f 100644 --- a/MediaBrowser.ServerApplication/ApplicationHost.cs +++ b/MediaBrowser.ServerApplication/ApplicationHost.cs @@ -6,7 +6,6 @@ using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Implementations; using MediaBrowser.Common.Implementations.ScheduledTasks; using MediaBrowser.Common.IO; -using MediaBrowser.Common.MediaInfo; using MediaBrowser.Common.Net; using MediaBrowser.Common.Progress; using MediaBrowser.Controller; @@ -284,9 +283,6 @@ namespace MediaBrowser.ServerApplication DtoService = new DtoService(Logger, LibraryManager, UserManager, UserDataManager, ItemRepository, ImageProcessor); RegisterSingleInstance(DtoService); - - LiveTvManager = new LiveTvManager(ApplicationPaths, FileSystemManager, Logger, ItemRepository, ImageProcessor, UserDataManager, DtoService, UserManager, LibraryManager); - RegisterSingleInstance(LiveTvManager); progress.Report(15); var innerProgress = new ActionableProgress(); @@ -295,6 +291,9 @@ namespace MediaBrowser.ServerApplication await RegisterMediaEncoder(innerProgress).ConfigureAwait(false); progress.Report(90); + LiveTvManager = new LiveTvManager(ApplicationPaths, FileSystemManager, Logger, ItemRepository, ImageProcessor, UserDataManager, DtoService, UserManager, LibraryManager, MediaEncoder); + RegisterSingleInstance(LiveTvManager); + var displayPreferencesTask = Task.Run(async () => await ConfigureDisplayPreferencesRepositories().ConfigureAwait(false)); var itemsTask = Task.Run(async () => await ConfigureItemRepositories().ConfigureAwait(false)); var userdataTask = Task.Run(async () => await ConfigureUserDataRepositories().ConfigureAwait(false));