From c93740461e5cef99deb378e587b75cf74950b94e Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 2 Jan 2015 00:36:27 -0500 Subject: [PATCH] support audio sync transcoding --- MediaBrowser.Api/ApiEntryPoint.cs | 5 ++- .../Playback/BaseStreamingService.cs | 4 +- .../Playback/Hls/HlsSegmentService.cs | 5 ++- .../Playback/Hls/VideoHlsService.cs | 3 +- .../MediaBrowser.Controller.csproj | 1 + .../MediaEncoding/IMediaEncoder.cs | 11 +++++ .../Savers/XmlSaverHelpers.cs | 3 +- .../Encoder/MediaEncoder.cs | 45 ++++++++++++++++++- .../MediaBrowser.MediaEncoding.csproj | 5 +++ MediaBrowser.Model/Dlna/StreamBuilder.cs | 6 ++- MediaBrowser.Model/Dlna/StreamInfo.cs | 1 + MediaBrowser.Model/Sync/LocalItem.cs | 2 +- .../Devices/DeviceManager.cs | 2 +- .../EntryPoints/UsageEntryPoint.cs | 6 ++- .../EntryPoints/UsageReporter.cs | 14 +++++- .../Library/LibraryManager.cs | 16 +++---- .../Localization/Server/server.json | 1 + .../Sync/AppSyncProvider.cs | 4 +- .../Sync/SyncJobProcessor.cs | 31 ++++++++----- .../Sync/SyncManager.cs | 11 +++-- .../Sync/SyncScheduledTask.cs | 7 ++- .../ApplicationHost.cs | 21 ++++++--- 22 files changed, 157 insertions(+), 47 deletions(-) diff --git a/MediaBrowser.Api/ApiEntryPoint.cs b/MediaBrowser.Api/ApiEntryPoint.cs index a05d7d1b2..0eb92d5a7 100644 --- a/MediaBrowser.Api/ApiEntryPoint.cs +++ b/MediaBrowser.Api/ApiEntryPoint.cs @@ -4,6 +4,7 @@ using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Plugins; using MediaBrowser.Controller.Session; using MediaBrowser.Model.Configuration; +using MediaBrowser.Model.Dlna; using MediaBrowser.Model.Logging; using MediaBrowser.Model.Session; using System; @@ -85,7 +86,9 @@ namespace MediaBrowser.Api /// private void DeleteEncodedMediaCache() { - foreach (var file in Directory.EnumerateFiles(_config.ApplicationPaths.TranscodingTempPath, "*", SearchOption.AllDirectories) + var path = Path.Combine(_config.ApplicationPaths.TranscodingTempPath, EncodingContext.Streaming.ToString().ToLower()); + + foreach (var file in Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories) .ToList()) { File.Delete(file); diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index 03106b6e7..0858a0347 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -119,8 +119,8 @@ namespace MediaBrowser.Api.Playback /// System.String. private string GetOutputFilePath(StreamState state) { - var folder = ServerConfigurationManager.ApplicationPaths.TranscodingTempPath; - + var folder = Path.Combine(ServerConfigurationManager.ApplicationPaths.TranscodingTempPath, EncodingContext.Streaming.ToString().ToLower()); + var outputFileExtension = GetOutputFileExtension(state); var data = GetCommandLineArguments("dummy\\dummy", "dummyTranscodingId", state, false); diff --git a/MediaBrowser.Api/Playback/Hls/HlsSegmentService.cs b/MediaBrowser.Api/Playback/Hls/HlsSegmentService.cs index 2263a2b37..14045b3a5 100644 --- a/MediaBrowser.Api/Playback/Hls/HlsSegmentService.cs +++ b/MediaBrowser.Api/Playback/Hls/HlsSegmentService.cs @@ -1,4 +1,5 @@ using MediaBrowser.Controller; +using MediaBrowser.Model.Dlna; using ServiceStack; using System; using System.IO; @@ -65,7 +66,7 @@ namespace MediaBrowser.Api.Playback.Hls { var file = request.PlaylistId + Path.GetExtension(Request.PathInfo); - file = Path.Combine(_appPaths.TranscodingTempPath, file); + file = Path.Combine(_appPaths.TranscodingTempPath, EncodingContext.Streaming.ToString().ToLower(), file); return ResultFactory.GetStaticFileResult(Request, file, FileShare.ReadWrite); } @@ -84,7 +85,7 @@ namespace MediaBrowser.Api.Playback.Hls { var file = request.SegmentId + Path.GetExtension(Request.PathInfo); - file = Path.Combine(_appPaths.TranscodingTempPath, file); + file = Path.Combine(_appPaths.TranscodingTempPath, EncodingContext.Streaming.ToString().ToLower(), file); return ResultFactory.GetStaticFileResult(Request, file, FileShare.ReadWrite); } diff --git a/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs b/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs index de845c88d..d786b51b3 100644 --- a/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs @@ -5,6 +5,7 @@ using MediaBrowser.Controller.Dlna; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.LiveTv; using MediaBrowser.Controller.MediaEncoding; +using MediaBrowser.Model.Dlna; using MediaBrowser.Model.IO; using ServiceStack; using System; @@ -70,7 +71,7 @@ namespace MediaBrowser.Api.Playback.Hls { var file = request.SegmentId + Path.GetExtension(Request.PathInfo); - file = Path.Combine(ServerConfigurationManager.ApplicationPaths.TranscodingTempPath, file); + file = Path.Combine(ServerConfigurationManager.ApplicationPaths.TranscodingTempPath, EncodingContext.Streaming.ToString().ToLower(), file); return ResultFactory.GetStaticFileResult(Request, file); } diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index 3ed87ced8..1d16db62c 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -199,6 +199,7 @@ + diff --git a/MediaBrowser.Controller/MediaEncoding/IMediaEncoder.cs b/MediaBrowser.Controller/MediaEncoding/IMediaEncoder.cs index 38c2c83c4..8f56bfda5 100644 --- a/MediaBrowser.Controller/MediaEncoding/IMediaEncoder.cs +++ b/MediaBrowser.Controller/MediaEncoding/IMediaEncoder.cs @@ -96,5 +96,16 @@ namespace MediaBrowser.Controller.MediaEncoding /// The ticks. /// System.String. string GetTimeParameter(long ticks); + + /// + /// Encodes the audio. + /// + /// The options. + /// The progress. + /// The cancellation token. + /// Task. + Task EncodeAudio(EncodingJobOptions options, + IProgress progress, + CancellationToken cancellationToken); } } diff --git a/MediaBrowser.LocalMetadata/Savers/XmlSaverHelpers.cs b/MediaBrowser.LocalMetadata/Savers/XmlSaverHelpers.cs index 4388ec964..b5b9278cc 100644 --- a/MediaBrowser.LocalMetadata/Savers/XmlSaverHelpers.cs +++ b/MediaBrowser.LocalMetadata/Savers/XmlSaverHelpers.cs @@ -112,7 +112,8 @@ namespace MediaBrowser.LocalMetadata.Savers "Website", "Zap2ItId", "CollectionItems", - "PlaylistItems" + "PlaylistItems", + "Shares" }.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase); diff --git a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs index 7fb27e25f..a7d8b6f1d 100644 --- a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs +++ b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs @@ -1,10 +1,16 @@ +using MediaBrowser.Common.IO; +using MediaBrowser.Controller.Channels; +using MediaBrowser.Controller.Configuration; +using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.LiveTv; using MediaBrowser.Controller.MediaEncoding; +using MediaBrowser.Controller.Session; using MediaBrowser.Model.Entities; +using MediaBrowser.Model.IO; using MediaBrowser.Model.Logging; using MediaBrowser.Model.MediaInfo; using MediaBrowser.Model.Serialization; using System; -using System.Collections.Concurrent; using System.Diagnostics; using System.Globalization; using System.IO; @@ -51,11 +57,26 @@ namespace MediaBrowser.MediaEncoding.Encoder public string Version { get; private set; } - public MediaEncoder(ILogger logger, IJsonSerializer jsonSerializer, string ffMpegPath, string ffProbePath, string version) + protected readonly IServerConfigurationManager ConfigurationManager; + protected readonly IFileSystem FileSystem; + protected readonly ILiveTvManager LiveTvManager; + protected readonly IIsoManager IsoManager; + protected readonly ILibraryManager LibraryManager; + protected readonly IChannelManager ChannelManager; + protected readonly ISessionManager SessionManager; + + 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) { _logger = logger; _jsonSerializer = jsonSerializer; Version = version; + ConfigurationManager = configurationManager; + FileSystem = fileSystem; + LiveTvManager = liveTvManager; + IsoManager = isoManager; + LibraryManager = libraryManager; + ChannelManager = channelManager; + SessionManager = sessionManager; FFProbePath = ffProbePath; FFMpegPath = ffMpegPath; } @@ -511,5 +532,25 @@ namespace MediaBrowser.MediaEncoding.Encoder throw new ApplicationException(msg); } } + + public async Task EncodeAudio(EncodingJobOptions options, + IProgress progress, + CancellationToken cancellationToken) + { + var job = await new AudioEncoder(this, + _logger, + ConfigurationManager, + FileSystem, + LiveTvManager, + IsoManager, + LibraryManager, + ChannelManager, + SessionManager) + .Start(options, progress, cancellationToken).ConfigureAwait(false); + + await job.TaskCompletionSource.Task.ConfigureAwait(false); + + return job.OutputFilePath; + } } } diff --git a/MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.csproj b/MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.csproj index 5c472ebc8..9daa3319f 100644 --- a/MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.csproj +++ b/MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.csproj @@ -57,7 +57,12 @@ + + + + + diff --git a/MediaBrowser.Model/Dlna/StreamBuilder.cs b/MediaBrowser.Model/Dlna/StreamBuilder.cs index 208ea1420..7c47b0d44 100644 --- a/MediaBrowser.Model/Dlna/StreamBuilder.cs +++ b/MediaBrowser.Model/Dlna/StreamBuilder.cs @@ -109,7 +109,8 @@ namespace MediaBrowser.Model.Dlna ItemId = options.ItemId, MediaType = DlnaProfileType.Audio, MediaSource = item, - RunTimeTicks = item.RunTimeTicks + RunTimeTicks = item.RunTimeTicks, + Context = options.Context }; int? maxBitrateSetting = options.GetMaxBitrate(); @@ -240,7 +241,8 @@ namespace MediaBrowser.Model.Dlna ItemId = options.ItemId, MediaType = DlnaProfileType.Video, MediaSource = item, - RunTimeTicks = item.RunTimeTicks + RunTimeTicks = item.RunTimeTicks, + Context = options.Context }; int? audioStreamIndex = options.AudioStreamIndex ?? item.DefaultAudioStreamIndex; diff --git a/MediaBrowser.Model/Dlna/StreamInfo.cs b/MediaBrowser.Model/Dlna/StreamInfo.cs index 703c73566..22eb0cf6c 100644 --- a/MediaBrowser.Model/Dlna/StreamInfo.cs +++ b/MediaBrowser.Model/Dlna/StreamInfo.cs @@ -18,6 +18,7 @@ namespace MediaBrowser.Model.Dlna public string ItemId { get; set; } public PlayMethod PlayMethod { get; set; } + public EncodingContext Context { get; set; } public DlnaProfileType MediaType { get; set; } diff --git a/MediaBrowser.Model/Sync/LocalItem.cs b/MediaBrowser.Model/Sync/LocalItem.cs index 51faaff90..ec4544524 100644 --- a/MediaBrowser.Model/Sync/LocalItem.cs +++ b/MediaBrowser.Model/Sync/LocalItem.cs @@ -23,7 +23,7 @@ namespace MediaBrowser.Model.Sync /// Gets or sets the unique identifier. /// /// The unique identifier. - public string UniqueId { get; set; } + public string Id { get; set; } /// /// Gets or sets the item identifier. /// diff --git a/MediaBrowser.Server.Implementations/Devices/DeviceManager.cs b/MediaBrowser.Server.Implementations/Devices/DeviceManager.cs index 99fa40789..ddd5ef58d 100644 --- a/MediaBrowser.Server.Implementations/Devices/DeviceManager.cs +++ b/MediaBrowser.Server.Implementations/Devices/DeviceManager.cs @@ -9,12 +9,12 @@ using MediaBrowser.Model.Extensions; using MediaBrowser.Model.Logging; using MediaBrowser.Model.Querying; using MediaBrowser.Model.Session; +using MediaBrowser.Model.Users; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; -using MediaBrowser.Model.Users; namespace MediaBrowser.Server.Implementations.Devices { diff --git a/MediaBrowser.Server.Implementations/EntryPoints/UsageEntryPoint.cs b/MediaBrowser.Server.Implementations/EntryPoints/UsageEntryPoint.cs index fcc664011..0e99ee673 100644 --- a/MediaBrowser.Server.Implementations/EntryPoints/UsageEntryPoint.cs +++ b/MediaBrowser.Server.Implementations/EntryPoints/UsageEntryPoint.cs @@ -1,6 +1,7 @@ using MediaBrowser.Common; using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Net; +using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Plugins; using MediaBrowser.Controller.Session; using MediaBrowser.Model.Logging; @@ -21,6 +22,7 @@ namespace MediaBrowser.Server.Implementations.EntryPoints private readonly IHttpClient _httpClient; private readonly ILogger _logger; private readonly ISessionManager _sessionManager; + private readonly IUserManager _userManager; private Timer _timer; private readonly TimeSpan _frequency = TimeSpan.FromHours(24); @@ -65,7 +67,7 @@ namespace MediaBrowser.Server.Implementations.EntryPoints { try { - await new UsageReporter(_applicationHost, _networkManager, _httpClient) + await new UsageReporter(_applicationHost, _networkManager, _httpClient, _userManager) .ReportAppUsage(client, CancellationToken.None) .ConfigureAwait(false); } @@ -107,7 +109,7 @@ namespace MediaBrowser.Server.Implementations.EntryPoints { try { - await new UsageReporter(_applicationHost, _networkManager, _httpClient) + await new UsageReporter(_applicationHost, _networkManager, _httpClient, _userManager) .ReportServerUsage(CancellationToken.None) .ConfigureAwait(false); } diff --git a/MediaBrowser.Server.Implementations/EntryPoints/UsageReporter.cs b/MediaBrowser.Server.Implementations/EntryPoints/UsageReporter.cs index 36ba55828..5be267313 100644 --- a/MediaBrowser.Server.Implementations/EntryPoints/UsageReporter.cs +++ b/MediaBrowser.Server.Implementations/EntryPoints/UsageReporter.cs @@ -1,7 +1,11 @@ using MediaBrowser.Common; using MediaBrowser.Common.Net; +using MediaBrowser.Controller.Library; +using MediaBrowser.Model.Connect; using System; using System.Collections.Generic; +using System.Globalization; +using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -12,13 +16,15 @@ namespace MediaBrowser.Server.Implementations.EntryPoints private readonly IApplicationHost _applicationHost; private readonly INetworkManager _networkManager; private readonly IHttpClient _httpClient; + private readonly IUserManager _userManager; private const string MbAdminUrl = "http://www.mb3admin.com/admin/"; - public UsageReporter(IApplicationHost applicationHost, INetworkManager networkManager, IHttpClient httpClient) + public UsageReporter(IApplicationHost applicationHost, INetworkManager networkManager, IHttpClient httpClient, IUserManager userManager) { _applicationHost = applicationHost; _networkManager = networkManager; _httpClient = httpClient; + _userManager = userManager; } public Task ReportServerUsage(CancellationToken cancellationToken) @@ -38,6 +44,12 @@ namespace MediaBrowser.Server.Implementations.EntryPoints { "isservice", _applicationHost.IsRunningAsService.ToString().ToLower()} }; + var users = _userManager.Users.ToList(); + + data["localusers"] = users.Count(i => !i.ConnectLinkType.HasValue).ToString(CultureInfo.InvariantCulture); + data["guests"] = users.Count(i => i.ConnectLinkType.HasValue && i.ConnectLinkType.Value == UserLinkType.Guest).ToString(CultureInfo.InvariantCulture); + data["linkedusers"] = users.Count(i => i.ConnectLinkType.HasValue && i.ConnectLinkType.Value == UserLinkType.LinkedUser).ToString(CultureInfo.InvariantCulture); + return _httpClient.Post(MbAdminUrl + "service/registration/ping", data, cancellationToken); } diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index b4a4c7e9a..37a68b52b 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -1556,14 +1556,7 @@ namespace MediaBrowser.Server.Implementations.Library { // Types cannot be overridden, so go from the top down until we find a configured content type - var type = GetTopFolderContentType(item); - - if (!string.IsNullOrWhiteSpace(type)) - { - return type; - } - - type = GetInheritedContentType(item); + var type = GetInheritedContentType(item); if (!string.IsNullOrWhiteSpace(type)) { @@ -1575,6 +1568,13 @@ namespace MediaBrowser.Server.Implementations.Library public string GetInheritedContentType(BaseItem item) { + var type = GetTopFolderContentType(item); + + if (!string.IsNullOrWhiteSpace(type)) + { + return type; + } + return item.Parents .Select(GetConfiguredContentType) .LastOrDefault(i => !string.IsNullOrWhiteSpace(i)); diff --git a/MediaBrowser.Server.Implementations/Localization/Server/server.json b/MediaBrowser.Server.Implementations/Localization/Server/server.json index cf4f0c4bf..e07c9adb7 100644 --- a/MediaBrowser.Server.Implementations/Localization/Server/server.json +++ b/MediaBrowser.Server.Implementations/Localization/Server/server.json @@ -1317,5 +1317,6 @@ "NameSeasonUnknown": "Season Unknown", "NameSeasonNumber": "Season {0}", "LabelNewUserNameHelp": "Usernames can contain letters (a-z), numbers (0-9), dashes (-), underscores (_), apostrophes ('), and periods (.)", + "TabJobs": "Jobs", "TabSyncJobs": "Sync Jobs" } diff --git a/MediaBrowser.Server.Implementations/Sync/AppSyncProvider.cs b/MediaBrowser.Server.Implementations/Sync/AppSyncProvider.cs index 8f6129dca..6cc5be955 100644 --- a/MediaBrowser.Server.Implementations/Sync/AppSyncProvider.cs +++ b/MediaBrowser.Server.Implementations/Sync/AppSyncProvider.cs @@ -46,7 +46,9 @@ namespace MediaBrowser.Server.Implementations.Sync public DeviceProfile GetDeviceProfile(SyncTarget target) { - return new DeviceProfile(); + var caps = _deviceManager.GetCapabilities(target.Id); + + return caps == null || caps.DeviceProfile == null ? new DeviceProfile() : caps.DeviceProfile; } public string Name diff --git a/MediaBrowser.Server.Implementations/Sync/SyncJobProcessor.cs b/MediaBrowser.Server.Implementations/Sync/SyncJobProcessor.cs index 97c6a6dc8..8e5b765a6 100644 --- a/MediaBrowser.Server.Implementations/Sync/SyncJobProcessor.cs +++ b/MediaBrowser.Server.Implementations/Sync/SyncJobProcessor.cs @@ -1,6 +1,7 @@ using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.MediaEncoding; using MediaBrowser.Controller.Sync; using MediaBrowser.Controller.TV; using MediaBrowser.Model.Dlna; @@ -28,8 +29,9 @@ namespace MediaBrowser.Server.Implementations.Sync private readonly ILogger _logger; private readonly IUserManager _userManager; private readonly ITVSeriesManager _tvSeriesManager; + private readonly IMediaEncoder MediaEncoder; - public SyncJobProcessor(ILibraryManager libraryManager, ISyncRepository syncRepo, ISyncManager syncManager, ILogger logger, IUserManager userManager, ITVSeriesManager tvSeriesManager) + public SyncJobProcessor(ILibraryManager libraryManager, ISyncRepository syncRepo, ISyncManager syncManager, ILogger logger, IUserManager userManager, ITVSeriesManager tvSeriesManager, IMediaEncoder mediaEncoder) { _libraryManager = libraryManager; _syncRepo = syncRepo; @@ -37,6 +39,7 @@ namespace MediaBrowser.Server.Implementations.Sync _logger = logger; _userManager = userManager; _tvSeriesManager = tvSeriesManager; + MediaEncoder = mediaEncoder; } public async Task EnsureJobItems(SyncJob job) @@ -392,7 +395,7 @@ namespace MediaBrowser.Server.Implementations.Sync { var options = new VideoOptions { - Context = EncodingContext.Streaming, + Context = EncodingContext.Static, ItemId = item.Id.ToString("N"), DeviceId = jobItem.TargetId, Profile = profile, @@ -406,7 +409,10 @@ namespace MediaBrowser.Server.Implementations.Sync if (streamInfo.PlayMethod == PlayMethod.Transcode) { + jobItem.Status = SyncJobItemStatus.Converting; await _syncRepo.Update(jobItem).ConfigureAwait(false); + + //jobItem.OutputPath = await MediaEncoder.EncodeAudio(new EncodingJobOptions(streamInfo, profile), new Progress(), cancellationToken); } else { @@ -418,12 +424,12 @@ namespace MediaBrowser.Server.Implementations.Sync { jobItem.OutputPath = await DownloadFile(jobItem, mediaSource, cancellationToken).ConfigureAwait(false); } - throw new InvalidOperationException(string.Format("Cannot direct stream {0} protocol", mediaSource.Protocol)); + else + { + throw new InvalidOperationException(string.Format("Cannot direct stream {0} protocol", mediaSource.Protocol)); + } } - // TODO: Transcode - jobItem.OutputPath = mediaSource.Path; - jobItem.Progress = 50; jobItem.Status = SyncJobItemStatus.Transferring; await _syncRepo.Update(jobItem).ConfigureAwait(false); @@ -433,7 +439,7 @@ namespace MediaBrowser.Server.Implementations.Sync { var options = new AudioOptions { - Context = EncodingContext.Streaming, + Context = EncodingContext.Static, ItemId = item.Id.ToString("N"), DeviceId = jobItem.TargetId, Profile = profile, @@ -447,7 +453,10 @@ namespace MediaBrowser.Server.Implementations.Sync if (streamInfo.PlayMethod == PlayMethod.Transcode) { + jobItem.Status = SyncJobItemStatus.Converting; await _syncRepo.Update(jobItem).ConfigureAwait(false); + + jobItem.OutputPath = await MediaEncoder.EncodeAudio(new EncodingJobOptions(streamInfo, profile), new Progress(), cancellationToken); } else { @@ -459,12 +468,12 @@ namespace MediaBrowser.Server.Implementations.Sync { jobItem.OutputPath = await DownloadFile(jobItem, mediaSource, cancellationToken).ConfigureAwait(false); } - throw new InvalidOperationException(string.Format("Cannot direct stream {0} protocol", mediaSource.Protocol)); + else + { + throw new InvalidOperationException(string.Format("Cannot direct stream {0} protocol", mediaSource.Protocol)); + } } - // TODO: Transcode - jobItem.OutputPath = mediaSource.Path; - jobItem.Progress = 50; jobItem.Status = SyncJobItemStatus.Transferring; await _syncRepo.Update(jobItem).ConfigureAwait(false); diff --git a/MediaBrowser.Server.Implementations/Sync/SyncManager.cs b/MediaBrowser.Server.Implementations/Sync/SyncManager.cs index 7e8db3e6a..68eaa38d3 100644 --- a/MediaBrowser.Server.Implementations/Sync/SyncManager.cs +++ b/MediaBrowser.Server.Implementations/Sync/SyncManager.cs @@ -8,6 +8,7 @@ using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.LiveTv; +using MediaBrowser.Controller.MediaEncoding; using MediaBrowser.Controller.Sync; using MediaBrowser.Controller.TV; using MediaBrowser.Model.Dlna; @@ -36,10 +37,11 @@ namespace MediaBrowser.Server.Implementations.Sync private readonly Func _dtoService; private readonly IApplicationHost _appHost; private readonly ITVSeriesManager _tvSeriesManager; + private readonly Func MediaEncoder; private ISyncProvider[] _providers = { }; - public SyncManager(ILibraryManager libraryManager, ISyncRepository repo, IImageProcessor imageProcessor, ILogger logger, IUserManager userManager, Func dtoService, IApplicationHost appHost, ITVSeriesManager tvSeriesManager) + public SyncManager(ILibraryManager libraryManager, ISyncRepository repo, IImageProcessor imageProcessor, ILogger logger, IUserManager userManager, Func dtoService, IApplicationHost appHost, ITVSeriesManager tvSeriesManager, Func mediaEncoder) { _libraryManager = libraryManager; _repo = repo; @@ -49,6 +51,7 @@ namespace MediaBrowser.Server.Implementations.Sync _dtoService = dtoService; _appHost = appHost; _tvSeriesManager = tvSeriesManager; + MediaEncoder = mediaEncoder; } public void AddParts(IEnumerable providers) @@ -58,7 +61,7 @@ namespace MediaBrowser.Server.Implementations.Sync public async Task CreateJob(SyncJobRequest request) { - var processor = new SyncJobProcessor(_libraryManager, _repo, this, _logger, _userManager, _tvSeriesManager); + var processor = new SyncJobProcessor(_libraryManager, _repo, this, _logger, _userManager, _tvSeriesManager, MediaEncoder()); var user = _userManager.GetUserById(request.UserId); @@ -162,7 +165,7 @@ namespace MediaBrowser.Server.Implementations.Sync if (item == null) { - var processor = new SyncJobProcessor(_libraryManager, _repo, this, _logger, _userManager, _tvSeriesManager); + var processor = new SyncJobProcessor(_libraryManager, _repo, this, _logger, _userManager, _tvSeriesManager, MediaEncoder()); var user = _userManager.GetUserById(job.UserId); @@ -392,7 +395,7 @@ namespace MediaBrowser.Server.Implementations.Sync await _repo.Update(jobItem).ConfigureAwait(false); - var processor = new SyncJobProcessor(_libraryManager, _repo, this, _logger, _userManager, _tvSeriesManager); + var processor = new SyncJobProcessor(_libraryManager, _repo, this, _logger, _userManager, _tvSeriesManager, MediaEncoder()); await processor.UpdateJobStatus(jobItem.JobId).ConfigureAwait(false); } diff --git a/MediaBrowser.Server.Implementations/Sync/SyncScheduledTask.cs b/MediaBrowser.Server.Implementations/Sync/SyncScheduledTask.cs index e7e30b857..797184298 100644 --- a/MediaBrowser.Server.Implementations/Sync/SyncScheduledTask.cs +++ b/MediaBrowser.Server.Implementations/Sync/SyncScheduledTask.cs @@ -1,5 +1,6 @@ using MediaBrowser.Common.ScheduledTasks; using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.MediaEncoding; using MediaBrowser.Controller.Sync; using MediaBrowser.Controller.TV; using MediaBrowser.Model.Logging; @@ -18,8 +19,9 @@ namespace MediaBrowser.Server.Implementations.Sync private readonly ILogger _logger; private readonly IUserManager _userManager; private readonly ITVSeriesManager _tvSeriesManager; + private readonly IMediaEncoder MediaEncoder; - public SyncScheduledTask(ILibraryManager libraryManager, ISyncRepository syncRepo, ISyncManager syncManager, ILogger logger, IUserManager userManager, ITVSeriesManager tvSeriesManager) + public SyncScheduledTask(ILibraryManager libraryManager, ISyncRepository syncRepo, ISyncManager syncManager, ILogger logger, IUserManager userManager, ITVSeriesManager tvSeriesManager, IMediaEncoder mediaEncoder) { _libraryManager = libraryManager; _syncRepo = syncRepo; @@ -27,6 +29,7 @@ namespace MediaBrowser.Server.Implementations.Sync _logger = logger; _userManager = userManager; _tvSeriesManager = tvSeriesManager; + MediaEncoder = mediaEncoder; } public string Name @@ -49,7 +52,7 @@ namespace MediaBrowser.Server.Implementations.Sync public Task Execute(CancellationToken cancellationToken, IProgress progress) { - return new SyncJobProcessor(_libraryManager, _syncRepo, _syncManager, _logger, _userManager, _tvSeriesManager).Sync(progress, + return new SyncJobProcessor(_libraryManager, _syncRepo, _syncManager, _logger, _userManager, _tvSeriesManager, MediaEncoder).Sync(progress, cancellationToken); } diff --git a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs index ed5441336..8a1721b7e 100644 --- a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs +++ b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs @@ -476,16 +476,13 @@ namespace MediaBrowser.Server.Startup.Common var innerProgress = new ActionableProgress(); innerProgress.RegisterAction(p => progress.Report((.75 * p) + 15)); - await RegisterMediaEncoder(innerProgress).ConfigureAwait(false); - progress.Report(90); - ImageProcessor = new ImageProcessor(LogManager.GetLogger("ImageProcessor"), ServerConfigurationManager.ApplicationPaths, FileSystemManager, JsonSerializer, MediaEncoder); RegisterSingleInstance(ImageProcessor); TVSeriesManager = new TVSeriesManager(UserManager, UserDataManager, LibraryManager); RegisterSingleInstance(TVSeriesManager); - SyncManager = new SyncManager(LibraryManager, SyncRepository, ImageProcessor, LogManager.GetLogger("SyncManager"), UserManager, () => DtoService, this, TVSeriesManager); + SyncManager = new SyncManager(LibraryManager, SyncRepository, ImageProcessor, LogManager.GetLogger("SyncManager"), UserManager, () => DtoService, this, TVSeriesManager, () => MediaEncoder); RegisterSingleInstance(SyncManager); DtoService = new DtoService(Logger, LibraryManager, UserDataManager, ItemRepository, ImageProcessor, ServerConfigurationManager, FileSystemManager, ProviderManager, () => ChannelManager, SyncManager, this); @@ -547,6 +544,9 @@ namespace MediaBrowser.Server.Startup.Common ChapterManager = new ChapterManager(LibraryManager, LogManager.GetLogger("ChapterManager"), ServerConfigurationManager, ItemRepository); RegisterSingleInstance(ChapterManager); + await RegisterMediaEncoder(innerProgress).ConfigureAwait(false); + progress.Report(90); + EncodingManager = new EncodingManager(FileSystemManager, Logger, MediaEncoder, ChapterManager); RegisterSingleInstance(EncodingManager); @@ -591,7 +591,18 @@ namespace MediaBrowser.Server.Startup.Common new FFmpegValidator(Logger, ApplicationPaths).Validate(info); - MediaEncoder = new MediaEncoder(LogManager.GetLogger("MediaEncoder"), JsonSerializer, info.EncoderPath, info.ProbePath, info.Version); + MediaEncoder = new MediaEncoder(LogManager.GetLogger("MediaEncoder"), + JsonSerializer, + info.EncoderPath, + info.ProbePath, + info.Version, + ServerConfigurationManager, + FileSystemManager, + LiveTvManager, + IsoManager, + LibraryManager, + ChannelManager, + SessionManager); RegisterSingleInstance(MediaEncoder); }