Bläddra i källkod

Move GetRecordingStreamMediaSources to IMediaSourceManager

Patrick Barron 1 år sedan
förälder
incheckning
051fa04a80

+ 34 - 1
Emby.Server.Implementations/Library/MediaSourceManager.cs

@@ -11,14 +11,15 @@ using System.Linq;
 using System.Text.Json;
 using System.Threading;
 using System.Threading.Tasks;
-using EasyCaching.Core.Configurations;
 using Jellyfin.Data.Entities;
 using Jellyfin.Data.Enums;
 using Jellyfin.Extensions.Json;
 using MediaBrowser.Common.Configuration;
 using MediaBrowser.Common.Extensions;
+using MediaBrowser.Controller;
 using MediaBrowser.Controller.Entities;
 using MediaBrowser.Controller.Library;
+using MediaBrowser.Controller.LiveTv;
 using MediaBrowser.Controller.MediaEncoding;
 using MediaBrowser.Controller.Persistence;
 using MediaBrowser.Controller.Providers;
@@ -37,6 +38,7 @@ namespace Emby.Server.Implementations.Library
         // Do not use a pipe here because Roku http requests to the server will fail, without any explicit error message.
         private const char LiveStreamIdDelimeter = '_';
 
+        private readonly IServerApplicationHost _appHost;
         private readonly IItemRepository _itemRepo;
         private readonly IUserManager _userManager;
         private readonly ILibraryManager _libraryManager;
@@ -55,6 +57,7 @@ namespace Emby.Server.Implementations.Library
         private IMediaSourceProvider[] _providers;
 
         public MediaSourceManager(
+            IServerApplicationHost appHost,
             IItemRepository itemRepo,
             IApplicationPaths applicationPaths,
             ILocalizationManager localizationManager,
@@ -66,6 +69,7 @@ namespace Emby.Server.Implementations.Library
             IMediaEncoder mediaEncoder,
             IDirectoryService directoryService)
         {
+            _appHost = appHost;
             _itemRepo = itemRepo;
             _userManager = userManager;
             _libraryManager = libraryManager;
@@ -799,6 +803,35 @@ namespace Emby.Server.Implementations.Library
             return result.Item1;
         }
 
+        public async Task<List<MediaSourceInfo>> GetRecordingStreamMediaSources(ActiveRecordingInfo info, CancellationToken cancellationToken)
+        {
+            var stream = new MediaSourceInfo
+            {
+                EncoderPath = _appHost.GetApiUrlForLocalAccess() + "/LiveTv/LiveRecordings/" + info.Id + "/stream",
+                EncoderProtocol = MediaProtocol.Http,
+                Path = info.Path,
+                Protocol = MediaProtocol.File,
+                Id = info.Id,
+                SupportsDirectPlay = false,
+                SupportsDirectStream = true,
+                SupportsTranscoding = true,
+                IsInfiniteStream = true,
+                RequiresOpening = false,
+                RequiresClosing = false,
+                BufferMs = 0,
+                IgnoreDts = true,
+                IgnoreIndex = true
+            };
+
+            await new LiveStreamHelper(_mediaEncoder, _logger, _appPaths)
+                .AddMediaInfoWithProbe(stream, false, false, cancellationToken).ConfigureAwait(false);
+
+            return new List<MediaSourceInfo>
+            {
+                stream
+            };
+        }
+
         public async Task CloseLiveStream(string id)
         {
             ArgumentException.ThrowIfNullOrEmpty(id);

+ 0 - 32
Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs

@@ -47,7 +47,6 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
 
         private const int TunerDiscoveryDurationMs = 3000;
 
-        private readonly IServerApplicationHost _appHost;
         private readonly ILogger<EmbyTV> _logger;
         private readonly IHttpClientFactory _httpClientFactory;
         private readonly IServerConfigurationManager _config;
@@ -76,7 +75,6 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
         private bool _disposed;
 
         public EmbyTV(
-            IServerApplicationHost appHost,
             IStreamHelper streamHelper,
             IMediaSourceManager mediaSourceManager,
             ILogger<EmbyTV> logger,
@@ -91,7 +89,6 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
         {
             Current = this;
 
-            _appHost = appHost;
             _logger = logger;
             _httpClientFactory = httpClientFactory;
             _config = config;
@@ -1021,35 +1018,6 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
             throw new NotImplementedException();
         }
 
-        public async Task<List<MediaSourceInfo>> GetRecordingStreamMediaSources(ActiveRecordingInfo info, CancellationToken cancellationToken)
-        {
-            var stream = new MediaSourceInfo
-            {
-                EncoderPath = _appHost.GetApiUrlForLocalAccess() + "/LiveTv/LiveRecordings/" + info.Id + "/stream",
-                EncoderProtocol = MediaProtocol.Http,
-                Path = info.Path,
-                Protocol = MediaProtocol.File,
-                Id = info.Id,
-                SupportsDirectPlay = false,
-                SupportsDirectStream = true,
-                SupportsTranscoding = true,
-                IsInfiniteStream = true,
-                RequiresOpening = false,
-                RequiresClosing = false,
-                BufferMs = 0,
-                IgnoreDts = true,
-                IgnoreIndex = true
-            };
-
-            await new LiveStreamHelper(_mediaEncoder, _logger, _config.CommonApplicationPaths)
-                .AddMediaInfoWithProbe(stream, false, false, cancellationToken).ConfigureAwait(false);
-
-            return new List<MediaSourceInfo>
-            {
-                stream
-            };
-        }
-
         public Task CloseLiveStream(string id, CancellationToken cancellationToken)
         {
             return Task.CompletedTask;

+ 1 - 1
Emby.Server.Implementations/LiveTv/LiveTvMediaSourceProvider.cs

@@ -61,7 +61,7 @@ namespace Emby.Server.Implementations.LiveTv
             {
                 if (activeRecordingInfo is not null)
                 {
-                    sources = await EmbyTV.EmbyTV.Current.GetRecordingStreamMediaSources(activeRecordingInfo, cancellationToken)
+                    sources = await _mediaSourceManager.GetRecordingStreamMediaSources(activeRecordingInfo, cancellationToken)
                         .ConfigureAwait(false);
                 }
                 else

+ 9 - 0
MediaBrowser.Controller/Library/IMediaSourceManager.cs

@@ -8,6 +8,7 @@ using System.Threading;
 using System.Threading.Tasks;
 using Jellyfin.Data.Entities;
 using MediaBrowser.Controller.Entities;
+using MediaBrowser.Controller.LiveTv;
 using MediaBrowser.Controller.Persistence;
 using MediaBrowser.Model.Dto;
 using MediaBrowser.Model.Entities;
@@ -116,6 +117,14 @@ namespace MediaBrowser.Controller.Library
         /// <returns>An instance of <see cref="ILiveStream"/>.</returns>
         public ILiveStream GetLiveStreamInfoByUniqueId(string uniqueId);
 
+        /// <summary>
+        /// Gets the media sources for an active recording.
+        /// </summary>
+        /// <param name="info">The <see cref="ActiveRecordingInfo"/>.</param>
+        /// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param>
+        /// <returns>A task containing the <see cref="MediaSourceInfo"/>'s for the recording.</returns>
+        Task<List<MediaSourceInfo>> GetRecordingStreamMediaSources(ActiveRecordingInfo info, CancellationToken cancellationToken);
+
         /// <summary>
         /// Closes the media source.
         /// </summary>