mirror of
				https://github.com/jellyfin/jellyfin.git
				synced 2025-11-04 03:27:21 -05:00 
			
		
		
		
	Simplify UniversalAudioController code, remove redundant null checks
This commit is contained in:
		
							parent
							
								
									176e182629
								
							
						
					
					
						commit
						e9bb448e89
					
				@ -10,13 +10,11 @@ using Jellyfin.Api.Helpers;
 | 
				
			|||||||
using Jellyfin.Api.ModelBinders;
 | 
					using Jellyfin.Api.ModelBinders;
 | 
				
			||||||
using Jellyfin.Api.Models.StreamingDtos;
 | 
					using Jellyfin.Api.Models.StreamingDtos;
 | 
				
			||||||
using MediaBrowser.Common.Extensions;
 | 
					using MediaBrowser.Common.Extensions;
 | 
				
			||||||
using MediaBrowser.Controller.Devices;
 | 
					 | 
				
			||||||
using MediaBrowser.Controller.Library;
 | 
					using MediaBrowser.Controller.Library;
 | 
				
			||||||
using MediaBrowser.Controller.MediaEncoding;
 | 
					using MediaBrowser.Controller.MediaEncoding;
 | 
				
			||||||
using MediaBrowser.Controller.Net;
 | 
					using MediaBrowser.Controller.Net;
 | 
				
			||||||
using MediaBrowser.Model.Dlna;
 | 
					using MediaBrowser.Model.Dlna;
 | 
				
			||||||
using MediaBrowser.Model.MediaInfo;
 | 
					using MediaBrowser.Model.MediaInfo;
 | 
				
			||||||
using MediaBrowser.Model.Session;
 | 
					 | 
				
			||||||
using Microsoft.AspNetCore.Authorization;
 | 
					using Microsoft.AspNetCore.Authorization;
 | 
				
			||||||
using Microsoft.AspNetCore.Http;
 | 
					using Microsoft.AspNetCore.Http;
 | 
				
			||||||
using Microsoft.AspNetCore.Mvc;
 | 
					using Microsoft.AspNetCore.Mvc;
 | 
				
			||||||
@ -31,7 +29,6 @@ namespace Jellyfin.Api.Controllers
 | 
				
			|||||||
    public class UniversalAudioController : BaseJellyfinApiController
 | 
					    public class UniversalAudioController : BaseJellyfinApiController
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        private readonly IAuthorizationContext _authorizationContext;
 | 
					        private readonly IAuthorizationContext _authorizationContext;
 | 
				
			||||||
        private readonly IDeviceManager _deviceManager;
 | 
					 | 
				
			||||||
        private readonly ILibraryManager _libraryManager;
 | 
					        private readonly ILibraryManager _libraryManager;
 | 
				
			||||||
        private readonly ILogger<UniversalAudioController> _logger;
 | 
					        private readonly ILogger<UniversalAudioController> _logger;
 | 
				
			||||||
        private readonly MediaInfoHelper _mediaInfoHelper;
 | 
					        private readonly MediaInfoHelper _mediaInfoHelper;
 | 
				
			||||||
@ -42,7 +39,6 @@ namespace Jellyfin.Api.Controllers
 | 
				
			|||||||
        /// Initializes a new instance of the <see cref="UniversalAudioController"/> class.
 | 
					        /// Initializes a new instance of the <see cref="UniversalAudioController"/> class.
 | 
				
			||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
        /// <param name="authorizationContext">Instance of the <see cref="IAuthorizationContext"/> interface.</param>
 | 
					        /// <param name="authorizationContext">Instance of the <see cref="IAuthorizationContext"/> interface.</param>
 | 
				
			||||||
        /// <param name="deviceManager">Instance of the <see cref="IDeviceManager"/> interface.</param>
 | 
					 | 
				
			||||||
        /// <param name="libraryManager">Instance of the <see cref="ILibraryManager"/> interface.</param>
 | 
					        /// <param name="libraryManager">Instance of the <see cref="ILibraryManager"/> interface.</param>
 | 
				
			||||||
        /// <param name="logger">Instance of the <see cref="ILogger{UniversalAudioController}"/> interface.</param>
 | 
					        /// <param name="logger">Instance of the <see cref="ILogger{UniversalAudioController}"/> interface.</param>
 | 
				
			||||||
        /// <param name="mediaInfoHelper">Instance of <see cref="MediaInfoHelper"/>.</param>
 | 
					        /// <param name="mediaInfoHelper">Instance of <see cref="MediaInfoHelper"/>.</param>
 | 
				
			||||||
@ -50,7 +46,6 @@ namespace Jellyfin.Api.Controllers
 | 
				
			|||||||
        /// <param name="dynamicHlsHelper">Instance of <see cref="DynamicHlsHelper"/>.</param>
 | 
					        /// <param name="dynamicHlsHelper">Instance of <see cref="DynamicHlsHelper"/>.</param>
 | 
				
			||||||
        public UniversalAudioController(
 | 
					        public UniversalAudioController(
 | 
				
			||||||
            IAuthorizationContext authorizationContext,
 | 
					            IAuthorizationContext authorizationContext,
 | 
				
			||||||
            IDeviceManager deviceManager,
 | 
					 | 
				
			||||||
            ILibraryManager libraryManager,
 | 
					            ILibraryManager libraryManager,
 | 
				
			||||||
            ILogger<UniversalAudioController> logger,
 | 
					            ILogger<UniversalAudioController> logger,
 | 
				
			||||||
            MediaInfoHelper mediaInfoHelper,
 | 
					            MediaInfoHelper mediaInfoHelper,
 | 
				
			||||||
@ -58,7 +53,6 @@ namespace Jellyfin.Api.Controllers
 | 
				
			|||||||
            DynamicHlsHelper dynamicHlsHelper)
 | 
					            DynamicHlsHelper dynamicHlsHelper)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            _authorizationContext = authorizationContext;
 | 
					            _authorizationContext = authorizationContext;
 | 
				
			||||||
            _deviceManager = deviceManager;
 | 
					 | 
				
			||||||
            _libraryManager = libraryManager;
 | 
					            _libraryManager = libraryManager;
 | 
				
			||||||
            _logger = logger;
 | 
					            _logger = logger;
 | 
				
			||||||
            _mediaInfoHelper = mediaInfoHelper;
 | 
					            _mediaInfoHelper = mediaInfoHelper;
 | 
				
			||||||
@ -123,23 +117,12 @@ namespace Jellyfin.Api.Controllers
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            _logger.LogInformation("GetPostedPlaybackInfo profile: {@Profile}", deviceProfile);
 | 
					            _logger.LogInformation("GetPostedPlaybackInfo profile: {@Profile}", deviceProfile);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (deviceProfile == null)
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                var clientCapabilities = _deviceManager.GetCapabilities(authInfo.DeviceId);
 | 
					 | 
				
			||||||
                if (clientCapabilities != null)
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    deviceProfile = clientCapabilities.DeviceProfile;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            var info = await _mediaInfoHelper.GetPlaybackInfo(
 | 
					            var info = await _mediaInfoHelper.GetPlaybackInfo(
 | 
				
			||||||
                    itemId,
 | 
					                    itemId,
 | 
				
			||||||
                    userId,
 | 
					                    userId,
 | 
				
			||||||
                    mediaSourceId)
 | 
					                    mediaSourceId)
 | 
				
			||||||
                .ConfigureAwait(false);
 | 
					                .ConfigureAwait(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (deviceProfile != null)
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
            // set device specific data
 | 
					            // set device specific data
 | 
				
			||||||
            var item = _libraryManager.GetItemById(itemId);
 | 
					            var item = _libraryManager.GetItemById(itemId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -167,27 +150,17 @@ namespace Jellyfin.Api.Controllers
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            _mediaInfoHelper.SortMediaSources(info, maxStreamingBitrate);
 | 
					            _mediaInfoHelper.SortMediaSources(info, maxStreamingBitrate);
 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (info.MediaSources != null)
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
            foreach (var source in info.MediaSources)
 | 
					            foreach (var source in info.MediaSources)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                    _mediaInfoHelper.NormalizeMediaSourceContainer(source, deviceProfile!, DlnaProfileType.Video);
 | 
					                _mediaInfoHelper.NormalizeMediaSourceContainer(source, deviceProfile, DlnaProfileType.Video);
 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            var mediaSource = info.MediaSources![0];
 | 
					            var mediaSource = info.MediaSources[0];
 | 
				
			||||||
            if (mediaSource.SupportsDirectPlay && mediaSource.Protocol == MediaProtocol.Http)
 | 
					            if (mediaSource.SupportsDirectPlay && mediaSource.Protocol == MediaProtocol.Http && enableRedirection && mediaSource.IsRemote && enableRemoteMedia.HasValue && enableRemoteMedia.Value)
 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                if (enableRedirection)
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    if (mediaSource.IsRemote && enableRemoteMedia.HasValue && enableRemoteMedia.Value)
 | 
					 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                return Redirect(mediaSource.Path);
 | 
					                return Redirect(mediaSource.Path);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            var isStatic = mediaSource.SupportsDirectStream;
 | 
					            var isStatic = mediaSource.SupportsDirectStream;
 | 
				
			||||||
            if (!isStatic && string.Equals(mediaSource.TranscodingSubProtocol, "hls", StringComparison.OrdinalIgnoreCase))
 | 
					            if (!isStatic && string.Equals(mediaSource.TranscodingSubProtocol, "hls", StringComparison.OrdinalIgnoreCase))
 | 
				
			||||||
@ -249,7 +222,7 @@ namespace Jellyfin.Api.Controllers
 | 
				
			|||||||
                BreakOnNonKeyFrames = breakOnNonKeyFrames,
 | 
					                BreakOnNonKeyFrames = breakOnNonKeyFrames,
 | 
				
			||||||
                AudioSampleRate = maxAudioSampleRate,
 | 
					                AudioSampleRate = maxAudioSampleRate,
 | 
				
			||||||
                MaxAudioChannels = maxAudioChannels,
 | 
					                MaxAudioChannels = maxAudioChannels,
 | 
				
			||||||
                AudioBitRate = isStatic ? (int?)null : (audioBitRate ?? maxStreamingBitrate),
 | 
					                AudioBitRate = isStatic ? null : (audioBitRate ?? maxStreamingBitrate),
 | 
				
			||||||
                MaxAudioBitDepth = maxAudioBitDepth,
 | 
					                MaxAudioBitDepth = maxAudioBitDepth,
 | 
				
			||||||
                AudioChannels = maxAudioChannels,
 | 
					                AudioChannels = maxAudioChannels,
 | 
				
			||||||
                CopyTimestamps = true,
 | 
					                CopyTimestamps = true,
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user