From a3dcca3826d1b33645d1064da29634cb8a06a3d2 Mon Sep 17 00:00:00 2001 From: David Date: Sat, 1 Aug 2020 14:38:55 +0200 Subject: Move UniversalAudioService to Jellyfin.Api --- .../Controllers/UniversalAudioController.cs | 366 +++++++++++++++++++++ 1 file changed, 366 insertions(+) create mode 100644 Jellyfin.Api/Controllers/UniversalAudioController.cs (limited to 'Jellyfin.Api/Controllers/UniversalAudioController.cs') diff --git a/Jellyfin.Api/Controllers/UniversalAudioController.cs b/Jellyfin.Api/Controllers/UniversalAudioController.cs new file mode 100644 index 000000000..9e7b23b78 --- /dev/null +++ b/Jellyfin.Api/Controllers/UniversalAudioController.cs @@ -0,0 +1,366 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Net.Http; +using System.Threading.Tasks; +using Jellyfin.Api.Helpers; +using MediaBrowser.Common.Net; +using MediaBrowser.Controller.Configuration; +using MediaBrowser.Controller.Devices; +using MediaBrowser.Controller.Dlna; +using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.MediaEncoding; +using MediaBrowser.Controller.Net; +using MediaBrowser.Model.Dlna; +using MediaBrowser.Model.IO; +using MediaBrowser.Model.MediaInfo; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; + +namespace Jellyfin.Api.Controllers +{ + /// + /// The universal audio controller. + /// + public class UniversalAudioController : BaseJellyfinApiController + { + private readonly ILoggerFactory _loggerFactory; + private readonly IUserManager _userManager; + private readonly ILibraryManager _libraryManager; + private readonly IDeviceManager _deviceManager; + private readonly IDlnaManager _dlnaManager; + private readonly IMediaEncoder _mediaEncoder; + private readonly IFileSystem _fileSystem; + private readonly IMediaSourceManager _mediaSourceManager; + private readonly IAuthorizationContext _authorizationContext; + private readonly INetworkManager _networkManager; + private readonly IServerConfigurationManager _serverConfigurationManager; + private readonly TranscodingJobHelper _transcodingJobHelper; + private readonly IConfiguration _configuration; + private readonly ISubtitleEncoder _subtitleEncoder; + private readonly IStreamHelper _streamHelper; + + public UniversalAudioController( + ILoggerFactory loggerFactory, + IServerConfigurationManager serverConfigurationManager, + IUserManager userManager, + ILibraryManager libraryManager, + IMediaEncoder mediaEncoder, + IFileSystem fileSystem, + IDlnaManager dlnaManager, + IDeviceManager deviceManager, + IMediaSourceManager mediaSourceManager, + IAuthorizationContext authorizationContext, + INetworkManager networkManager, + TranscodingJobHelper transcodingJobHelper, + IConfiguration configuration, + ISubtitleEncoder subtitleEncoder, + IStreamHelper streamHelper) + { + _userManager = userManager; + _libraryManager = libraryManager; + _mediaEncoder = mediaEncoder; + _fileSystem = fileSystem; + _dlnaManager = dlnaManager; + _deviceManager = deviceManager; + _mediaSourceManager = mediaSourceManager; + _authorizationContext = authorizationContext; + _networkManager = networkManager; + _loggerFactory = loggerFactory; + _serverConfigurationManager = serverConfigurationManager; + _transcodingJobHelper = transcodingJobHelper; + _configuration = configuration; + _subtitleEncoder = subtitleEncoder; + _streamHelper = streamHelper; + } + + [HttpGet("/Audio/{itemId}/universal")] + [HttpGet("/Audio/{itemId}/{universal=universal}.{container?}")] + [HttpHead("/Audio/{itemId}/universal")] + [HttpHead("/Audio/{itemId}/{universal=universal}.{container?}")] + public async Task GetUniversalAudioStream( + [FromRoute] Guid itemId, + [FromRoute] string? container, + [FromQuery] string? mediaSourceId, + [FromQuery] string? deviceId, + [FromQuery] Guid? userId, + [FromQuery] string? audioCodec, + [FromQuery] int? maxAudioChannels, + [FromQuery] int? transcodingAudioChannels, + [FromQuery] long? maxStreamingBitrate, + [FromQuery] long? startTimeTicks, + [FromQuery] string? transcodingContainer, + [FromQuery] string? transcodingProtocol, + [FromQuery] int? maxAudioSampleRate, + [FromQuery] int? maxAudioBitDepth, + [FromQuery] bool? enableRemoteMedia, + [FromQuery] bool breakOnNonKeyFrames, + [FromQuery] bool enableRedirection = true) + { + bool isHeadRequest = Request.Method == System.Net.WebRequestMethods.Http.Head; + var deviceProfile = GetDeviceProfile(container, transcodingContainer, audioCodec, transcodingProtocol, breakOnNonKeyFrames, transcodingAudioChannels, maxAudioSampleRate, maxAudioBitDepth, maxAudioChannels); + _authorizationContext.GetAuthorizationInfo(Request).DeviceId = deviceId; + + var mediaInfoController = new MediaInfoController(_mediaSourceManager, _deviceManager, _libraryManager, _networkManager, _mediaEncoder, _userManager, _authorizationContext, _loggerFactory.CreateLogger(), _serverConfigurationManager); + var playbackInfoResult = await mediaInfoController.GetPlaybackInfo(itemId, userId).ConfigureAwait(false); + var mediaSource = playbackInfoResult.Value.MediaSources[0]; + + if (mediaSource.SupportsDirectPlay && mediaSource.Protocol == MediaProtocol.Http) + { + if (enableRedirection) + { + if (mediaSource.IsRemote && enableRemoteMedia.HasValue && enableRemoteMedia.Value) + { + return Redirect(mediaSource.Path); + } + } + } + + var isStatic = mediaSource.SupportsDirectStream; + if (!isStatic && string.Equals(mediaSource.TranscodingSubProtocol, "hls", StringComparison.OrdinalIgnoreCase)) + { + // TODO new DynamicHlsController + // var dynamicHlsController = new DynamicHlsController(); + var transcodingProfile = deviceProfile.TranscodingProfiles[0]; + + // hls segment container can only be mpegts or fmp4 per ffmpeg documentation + // TODO: remove this when we switch back to the segment muxer + var supportedHLSContainers = new[] { "mpegts", "fmp4" }; + + /* + var newRequest = new GetMasterHlsAudioPlaylist + { + AudioBitRate = isStatic ? (int?)null : Convert.ToInt32(Math.Min(request.MaxStreamingBitrate ?? 192000, int.MaxValue)), + AudioCodec = transcodingProfile.AudioCodec, + Container = ".m3u8", + DeviceId = request.DeviceId, + Id = request.Id, + MaxAudioChannels = request.MaxAudioChannels, + MediaSourceId = mediaSource.Id, + PlaySessionId = playbackInfoResult.PlaySessionId, + StartTimeTicks = request.StartTimeTicks, + Static = isStatic, + // fallback to mpegts if device reports some weird value unsupported by hls + SegmentContainer = Array.Exists(supportedHLSContainers, element => element == request.TranscodingContainer) ? request.TranscodingContainer : "mpegts", + AudioSampleRate = request.MaxAudioSampleRate, + MaxAudioBitDepth = request.MaxAudioBitDepth, + BreakOnNonKeyFrames = transcodingProfile.BreakOnNonKeyFrames, + TranscodeReasons = mediaSource.TranscodeReasons == null ? null : string.Join(",", mediaSource.TranscodeReasons.Select(i => i.ToString()).ToArray()) + }; + + if (isHeadRequest) + { + audioController.Request.Method = HttpMethod.Head.Method; + return await service.Head(newRequest).ConfigureAwait(false); + } + + return await service.Get(newRequest).ConfigureAwait(false);*/ + // TODO remove this line + return Content(string.Empty); + } + else + { + var audioController = new AudioController( + _dlnaManager, + _userManager, + _authorizationContext, + _libraryManager, + _mediaSourceManager, + _serverConfigurationManager, + _mediaEncoder, + _streamHelper, + _fileSystem, + _subtitleEncoder, + _configuration, + _deviceManager, + _transcodingJobHelper, + // TODO HttpClient + new HttpClient()); + + if (isHeadRequest) + { + audioController.Request.Method = HttpMethod.Head.Method; + return await audioController.GetAudioStream( + itemId, + isStatic ? null : ("." + mediaSource.TranscodingContainer), + isStatic, + null, + null, + null, + playbackInfoResult.Value.PlaySessionId, + null, + null, + null, + mediaSource.Id, + deviceId, + audioCodec, + null, + null, + null, + breakOnNonKeyFrames, + maxAudioSampleRate, + maxAudioBitDepth, + isStatic ? (int?)null : Convert.ToInt32(Math.Min(maxStreamingBitrate ?? 192000, int.MaxValue)), + null, + maxAudioChannels, + null, + null, + null, + null, + null, + startTimeTicks, + null, + null, + null, + null, + SubtitleDeliveryMethod.Embed, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + mediaSource.TranscodeReasons == null ? null : string.Join(",", mediaSource.TranscodeReasons.Select(i => i.ToString()).ToArray()), + null, + null, + null, + null) + .ConfigureAwait(false); + } + + return await audioController.GetAudioStream( + itemId, + isStatic ? null : ("." + mediaSource.TranscodingContainer), + isStatic, + null, + null, + null, + playbackInfoResult.Value.PlaySessionId, + null, + null, + null, + mediaSource.Id, + deviceId, + audioCodec, + null, + null, + null, + breakOnNonKeyFrames, + maxAudioSampleRate, + maxAudioBitDepth, + isStatic ? (int?)null : Convert.ToInt32(Math.Min(maxStreamingBitrate ?? 192000, int.MaxValue)), + null, + maxAudioChannels, + null, + null, + null, + null, + null, + startTimeTicks, + null, + null, + null, + null, + SubtitleDeliveryMethod.Embed, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + mediaSource.TranscodeReasons == null ? null : string.Join(",", mediaSource.TranscodeReasons.Select(i => i.ToString()).ToArray()), + null, + null, + null, + null) + .ConfigureAwait(false); + } + } + + private DeviceProfile GetDeviceProfile( + string? container, + string? transcodingContainer, + string? audioCodec, + string? transcodingProtocol, + bool? breakOnNonKeyFrames, + int? transcodingAudioChannels, + int? maxAudioSampleRate, + int? maxAudioBitDepth, + int? maxAudioChannels) + { + var deviceProfile = new DeviceProfile(); + + var directPlayProfiles = new List(); + + var containers = (container ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); + + foreach (var cont in containers) + { + var parts = cont.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries); + + var audioCodecs = parts.Length == 1 ? null : string.Join(",", parts.Skip(1).ToArray()); + + directPlayProfiles.Add(new DirectPlayProfile { Type = DlnaProfileType.Audio, Container = parts[0], AudioCodec = audioCodecs }); + } + + deviceProfile.DirectPlayProfiles = directPlayProfiles.ToArray(); + + deviceProfile.TranscodingProfiles = new[] + { + new TranscodingProfile + { + Type = DlnaProfileType.Audio, + Context = EncodingContext.Streaming, + Container = transcodingContainer, + AudioCodec = audioCodec, + Protocol = transcodingProtocol, + BreakOnNonKeyFrames = breakOnNonKeyFrames ?? false, + MaxAudioChannels = transcodingAudioChannels?.ToString(CultureInfo.InvariantCulture) + } + }; + + var codecProfiles = new List(); + var conditions = new List(); + + if (maxAudioSampleRate.HasValue) + { + // codec profile + conditions.Add(new ProfileCondition { Condition = ProfileConditionType.LessThanEqual, IsRequired = false, Property = ProfileConditionValue.AudioSampleRate, Value = maxAudioSampleRate.Value.ToString(CultureInfo.InvariantCulture) }); + } + + if (maxAudioBitDepth.HasValue) + { + // codec profile + conditions.Add(new ProfileCondition { Condition = ProfileConditionType.LessThanEqual, IsRequired = false, Property = ProfileConditionValue.AudioBitDepth, Value = maxAudioBitDepth.Value.ToString(CultureInfo.InvariantCulture) }); + } + + if (maxAudioChannels.HasValue) + { + // codec profile + conditions.Add(new ProfileCondition { Condition = ProfileConditionType.LessThanEqual, IsRequired = false, Property = ProfileConditionValue.AudioChannels, Value = maxAudioChannels.Value.ToString(CultureInfo.InvariantCulture) }); + } + + if (conditions.Count > 0) + { + // codec profile + codecProfiles.Add(new CodecProfile { Type = CodecType.Audio, Container = container, Conditions = conditions.ToArray() }); + } + + deviceProfile.CodecProfiles = codecProfiles.ToArray(); + + return deviceProfile; + } + } +} -- cgit v1.2.3 From d3dc9da5d6780f110bc71b0772d27a97ebb0349f Mon Sep 17 00:00:00 2001 From: David Date: Sat, 1 Aug 2020 15:09:44 +0200 Subject: Prepare DynamicHlsController merge --- .../Controllers/UniversalAudioController.cs | 213 +++++++++++++++++---- 1 file changed, 176 insertions(+), 37 deletions(-) (limited to 'Jellyfin.Api/Controllers/UniversalAudioController.cs') diff --git a/Jellyfin.Api/Controllers/UniversalAudioController.cs b/Jellyfin.Api/Controllers/UniversalAudioController.cs index 9e7b23b78..311c0a3b9 100644 --- a/Jellyfin.Api/Controllers/UniversalAudioController.cs +++ b/Jellyfin.Api/Controllers/UniversalAudioController.cs @@ -4,6 +4,7 @@ using System.Globalization; using System.Linq; using System.Net.Http; using System.Threading.Tasks; +using Jellyfin.Api.Constants; using Jellyfin.Api.Helpers; using MediaBrowser.Common.Net; using MediaBrowser.Controller.Configuration; @@ -15,6 +16,8 @@ using MediaBrowser.Controller.Net; using MediaBrowser.Model.Dlna; using MediaBrowser.Model.IO; using MediaBrowser.Model.MediaInfo; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; @@ -40,8 +43,26 @@ namespace Jellyfin.Api.Controllers private readonly TranscodingJobHelper _transcodingJobHelper; private readonly IConfiguration _configuration; private readonly ISubtitleEncoder _subtitleEncoder; - private readonly IStreamHelper _streamHelper; + private readonly IHttpClientFactory _httpClientFactory; + /// + /// Initializes a new instance of the class. + /// + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. public UniversalAudioController( ILoggerFactory loggerFactory, IServerConfigurationManager serverConfigurationManager, @@ -57,7 +78,7 @@ namespace Jellyfin.Api.Controllers TranscodingJobHelper transcodingJobHelper, IConfiguration configuration, ISubtitleEncoder subtitleEncoder, - IStreamHelper streamHelper) + IHttpClientFactory httpClientFactory) { _userManager = userManager; _libraryManager = libraryManager; @@ -73,13 +94,39 @@ namespace Jellyfin.Api.Controllers _transcodingJobHelper = transcodingJobHelper; _configuration = configuration; _subtitleEncoder = subtitleEncoder; - _streamHelper = streamHelper; + _httpClientFactory = httpClientFactory; } + /// + /// Gets an audio stream. + /// + /// The item id. + /// Optional. The audio container. + /// The media version id, if playing an alternate version. + /// The device id of the client requesting. Used to stop encoding processes when needed. + /// Optional. The user id. + /// Optional. The audio codec to transcode to. + /// Optional. The maximum number of audio channels. + /// Optional. The number of how many audio channels to transcode to. + /// Optional. The maximum streaming bitrate. + /// Optional. Specify a starting offset, in ticks. 1 tick = 10000 ms. + /// Optional. The container to transcode to. + /// Optional. The transcoding protocol. + /// Optional. The maximum audio sample rate. + /// Optional. The maximum audio bit depth. + /// Optional. Whether to enable remote media. + /// Optional. Whether to break on non key frames. + /// Whether to enable redirection. Defaults to true. + /// Audio stream returned. + /// Redirected to remote audio stream. + /// A containing the audio file. [HttpGet("/Audio/{itemId}/universal")] [HttpGet("/Audio/{itemId}/{universal=universal}.{container?}")] [HttpHead("/Audio/{itemId}/universal")] [HttpHead("/Audio/{itemId}/{universal=universal}.{container?}")] + [Authorize(Policy = Policies.DefaultAuthorization)] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status302Found)] public async Task GetUniversalAudioStream( [FromRoute] Guid itemId, [FromRoute] string? container, @@ -121,44 +168,138 @@ namespace Jellyfin.Api.Controllers var isStatic = mediaSource.SupportsDirectStream; if (!isStatic && string.Equals(mediaSource.TranscodingSubProtocol, "hls", StringComparison.OrdinalIgnoreCase)) { - // TODO new DynamicHlsController - // var dynamicHlsController = new DynamicHlsController(); + var dynamicHlsController = new DynamicHlsController( + _libraryManager, + _userManager, + _dlnaManager, + _authorizationContext, + _mediaSourceManager, + _serverConfigurationManager, + _mediaEncoder, + _fileSystem, + _subtitleEncoder, + _configuration, + _deviceManager, + _transcodingJobHelper, + _networkManager, + _loggerFactory.CreateLogger()); var transcodingProfile = deviceProfile.TranscodingProfiles[0]; // hls segment container can only be mpegts or fmp4 per ffmpeg documentation // TODO: remove this when we switch back to the segment muxer - var supportedHLSContainers = new[] { "mpegts", "fmp4" }; - - /* - var newRequest = new GetMasterHlsAudioPlaylist - { - AudioBitRate = isStatic ? (int?)null : Convert.ToInt32(Math.Min(request.MaxStreamingBitrate ?? 192000, int.MaxValue)), - AudioCodec = transcodingProfile.AudioCodec, - Container = ".m3u8", - DeviceId = request.DeviceId, - Id = request.Id, - MaxAudioChannels = request.MaxAudioChannels, - MediaSourceId = mediaSource.Id, - PlaySessionId = playbackInfoResult.PlaySessionId, - StartTimeTicks = request.StartTimeTicks, - Static = isStatic, - // fallback to mpegts if device reports some weird value unsupported by hls - SegmentContainer = Array.Exists(supportedHLSContainers, element => element == request.TranscodingContainer) ? request.TranscodingContainer : "mpegts", - AudioSampleRate = request.MaxAudioSampleRate, - MaxAudioBitDepth = request.MaxAudioBitDepth, - BreakOnNonKeyFrames = transcodingProfile.BreakOnNonKeyFrames, - TranscodeReasons = mediaSource.TranscodeReasons == null ? null : string.Join(",", mediaSource.TranscodeReasons.Select(i => i.ToString()).ToArray()) - }; + var supportedHlsContainers = new[] { "mpegts", "fmp4" }; if (isHeadRequest) { - audioController.Request.Method = HttpMethod.Head.Method; - return await service.Head(newRequest).ConfigureAwait(false); + dynamicHlsController.Request.Method = HttpMethod.Head.Method; + return await dynamicHlsController.GetMasterHlsAudioPlaylist( + itemId, + ".m3u8", + isStatic, + null, + null, + null, + playbackInfoResult.Value.PlaySessionId, + // fallback to mpegts if device reports some weird value unsupported by hls + Array.Exists(supportedHlsContainers, element => element == transcodingContainer) ? transcodingContainer : "mpegts", + null, + null, + mediaSource.Id, + deviceId, + transcodingProfile.AudioCodec, + null, + null, + transcodingProfile.BreakOnNonKeyFrames, + maxAudioSampleRate, + maxAudioBitDepth, + null, + isStatic ? (int?)null : Convert.ToInt32(Math.Min(maxStreamingBitrate ?? 192000, int.MaxValue)), + null, + maxAudioChannels, + null, + null, + null, + null, + null, + startTimeTicks, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + mediaSource.TranscodeReasons == null ? null : string.Join(",", mediaSource.TranscodeReasons.Select(i => i.ToString()).ToArray()), + null, + null, + null, + null, + null, + null) + .ConfigureAwait(false); } - return await service.Get(newRequest).ConfigureAwait(false);*/ - // TODO remove this line - return Content(string.Empty); + return await dynamicHlsController.GetMasterHlsAudioPlaylist( + itemId, + ".m3u8", + isStatic, + null, + null, + null, + playbackInfoResult.Value.PlaySessionId, + // fallback to mpegts if device reports some weird value unsupported by hls + Array.Exists(supportedHlsContainers, element => element == transcodingContainer) ? transcodingContainer : "mpegts", + null, + null, + mediaSource.Id, + deviceId, + transcodingProfile.AudioCodec, + null, + null, + transcodingProfile.BreakOnNonKeyFrames, + maxAudioSampleRate, + maxAudioBitDepth, + null, + isStatic ? (int?)null : Convert.ToInt32(Math.Min(maxStreamingBitrate ?? 192000, int.MaxValue)), + null, + maxAudioChannels, + null, + null, + null, + null, + null, + startTimeTicks, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + mediaSource.TranscodeReasons == null ? null : string.Join(",", mediaSource.TranscodeReasons.Select(i => i.ToString()).ToArray()), + null, + null, + null, + null, + null, + null) + .ConfigureAwait(false); } else { @@ -170,14 +311,12 @@ namespace Jellyfin.Api.Controllers _mediaSourceManager, _serverConfigurationManager, _mediaEncoder, - _streamHelper, _fileSystem, _subtitleEncoder, _configuration, _deviceManager, _transcodingJobHelper, - // TODO HttpClient - new HttpClient()); + _httpClientFactory); if (isHeadRequest) { @@ -304,11 +443,11 @@ namespace Jellyfin.Api.Controllers var directPlayProfiles = new List(); - var containers = (container ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); + var containers = RequestHelpers.Split(container, ',', true); foreach (var cont in containers) { - var parts = cont.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries); + var parts = RequestHelpers.Split(cont, ',', true); var audioCodecs = parts.Length == 1 ? null : string.Join(",", parts.Skip(1).ToArray()); -- cgit v1.2.3 From 24c5016f487193791a807c14b12b388939320240 Mon Sep 17 00:00:00 2001 From: David Date: Sat, 1 Aug 2020 18:22:40 +0200 Subject: Fix parameters --- Jellyfin.Api/Controllers/UniversalAudioController.cs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'Jellyfin.Api/Controllers/UniversalAudioController.cs') diff --git a/Jellyfin.Api/Controllers/UniversalAudioController.cs b/Jellyfin.Api/Controllers/UniversalAudioController.cs index 311c0a3b9..0c7ef258a 100644 --- a/Jellyfin.Api/Controllers/UniversalAudioController.cs +++ b/Jellyfin.Api/Controllers/UniversalAudioController.cs @@ -209,12 +209,12 @@ namespace Jellyfin.Api.Controllers transcodingProfile.AudioCodec, null, null, + null, transcodingProfile.BreakOnNonKeyFrames, maxAudioSampleRate, maxAudioBitDepth, null, isStatic ? (int?)null : Convert.ToInt32(Math.Min(maxStreamingBitrate ?? 192000, int.MaxValue)), - null, maxAudioChannels, null, null, @@ -226,6 +226,7 @@ namespace Jellyfin.Api.Controllers null, null, null, + SubtitleDeliveryMethod.Hls, null, null, null, @@ -240,10 +241,8 @@ namespace Jellyfin.Api.Controllers mediaSource.TranscodeReasons == null ? null : string.Join(",", mediaSource.TranscodeReasons.Select(i => i.ToString()).ToArray()), null, null, - null, - null, - null, - null) + EncodingContext.Static, + new Dictionary()) .ConfigureAwait(false); } @@ -264,12 +263,12 @@ namespace Jellyfin.Api.Controllers transcodingProfile.AudioCodec, null, null, + null, transcodingProfile.BreakOnNonKeyFrames, maxAudioSampleRate, maxAudioBitDepth, null, isStatic ? (int?)null : Convert.ToInt32(Math.Min(maxStreamingBitrate ?? 192000, int.MaxValue)), - null, maxAudioChannels, null, null, @@ -281,6 +280,7 @@ namespace Jellyfin.Api.Controllers null, null, null, + SubtitleDeliveryMethod.Hls, null, null, null, @@ -295,10 +295,8 @@ namespace Jellyfin.Api.Controllers mediaSource.TranscodeReasons == null ? null : string.Join(",", mediaSource.TranscodeReasons.Select(i => i.ToString()).ToArray()), null, null, - null, - null, - null, - null) + EncodingContext.Static, + new Dictionary()) .ConfigureAwait(false); } else -- cgit v1.2.3 From 8e05b226459eb0c513e227002f03068ca1e8dfc9 Mon Sep 17 00:00:00 2001 From: David Date: Sat, 1 Aug 2020 19:03:11 +0200 Subject: Use correct MediaInfo method --- Jellyfin.Api/Controllers/UniversalAudioController.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'Jellyfin.Api/Controllers/UniversalAudioController.cs') diff --git a/Jellyfin.Api/Controllers/UniversalAudioController.cs b/Jellyfin.Api/Controllers/UniversalAudioController.cs index 0c7ef258a..536088052 100644 --- a/Jellyfin.Api/Controllers/UniversalAudioController.cs +++ b/Jellyfin.Api/Controllers/UniversalAudioController.cs @@ -6,6 +6,7 @@ using System.Net.Http; using System.Threading.Tasks; using Jellyfin.Api.Constants; using Jellyfin.Api.Helpers; +using Jellyfin.Api.Models.VideoDtos; using MediaBrowser.Common.Net; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Devices; @@ -151,7 +152,18 @@ namespace Jellyfin.Api.Controllers _authorizationContext.GetAuthorizationInfo(Request).DeviceId = deviceId; var mediaInfoController = new MediaInfoController(_mediaSourceManager, _deviceManager, _libraryManager, _networkManager, _mediaEncoder, _userManager, _authorizationContext, _loggerFactory.CreateLogger(), _serverConfigurationManager); - var playbackInfoResult = await mediaInfoController.GetPlaybackInfo(itemId, userId).ConfigureAwait(false); + var playbackInfoResult = await mediaInfoController.GetPostedPlaybackInfo( + itemId, + userId, + maxStreamingBitrate, + startTimeTicks, + null, + null, + maxAudioChannels, + mediaSourceId, + null, + new DeviceProfileDto { DeviceProfile = deviceProfile }) + .ConfigureAwait(false); var mediaSource = playbackInfoResult.Value.MediaSources[0]; if (mediaSource.SupportsDirectPlay && mediaSource.Protocol == MediaProtocol.Http) -- cgit v1.2.3 From a7eee4f4e52a9cdd94f56a6f5d57ab5abd453221 Mon Sep 17 00:00:00 2001 From: David Date: Sat, 1 Aug 2020 19:25:20 +0200 Subject: Remove duplicate code --- .../Controllers/UniversalAudioController.cs | 103 --------------------- 1 file changed, 103 deletions(-) (limited to 'Jellyfin.Api/Controllers/UniversalAudioController.cs') diff --git a/Jellyfin.Api/Controllers/UniversalAudioController.cs b/Jellyfin.Api/Controllers/UniversalAudioController.cs index 536088052..44dd5f1fd 100644 --- a/Jellyfin.Api/Controllers/UniversalAudioController.cs +++ b/Jellyfin.Api/Controllers/UniversalAudioController.cs @@ -204,58 +204,6 @@ namespace Jellyfin.Api.Controllers if (isHeadRequest) { dynamicHlsController.Request.Method = HttpMethod.Head.Method; - return await dynamicHlsController.GetMasterHlsAudioPlaylist( - itemId, - ".m3u8", - isStatic, - null, - null, - null, - playbackInfoResult.Value.PlaySessionId, - // fallback to mpegts if device reports some weird value unsupported by hls - Array.Exists(supportedHlsContainers, element => element == transcodingContainer) ? transcodingContainer : "mpegts", - null, - null, - mediaSource.Id, - deviceId, - transcodingProfile.AudioCodec, - null, - null, - null, - transcodingProfile.BreakOnNonKeyFrames, - maxAudioSampleRate, - maxAudioBitDepth, - null, - isStatic ? (int?)null : Convert.ToInt32(Math.Min(maxStreamingBitrate ?? 192000, int.MaxValue)), - maxAudioChannels, - null, - null, - null, - null, - null, - startTimeTicks, - null, - null, - null, - null, - SubtitleDeliveryMethod.Hls, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - mediaSource.TranscodeReasons == null ? null : string.Join(",", mediaSource.TranscodeReasons.Select(i => i.ToString()).ToArray()), - null, - null, - EncodingContext.Static, - new Dictionary()) - .ConfigureAwait(false); } return await dynamicHlsController.GetMasterHlsAudioPlaylist( @@ -331,57 +279,6 @@ namespace Jellyfin.Api.Controllers if (isHeadRequest) { audioController.Request.Method = HttpMethod.Head.Method; - return await audioController.GetAudioStream( - itemId, - isStatic ? null : ("." + mediaSource.TranscodingContainer), - isStatic, - null, - null, - null, - playbackInfoResult.Value.PlaySessionId, - null, - null, - null, - mediaSource.Id, - deviceId, - audioCodec, - null, - null, - null, - breakOnNonKeyFrames, - maxAudioSampleRate, - maxAudioBitDepth, - isStatic ? (int?)null : Convert.ToInt32(Math.Min(maxStreamingBitrate ?? 192000, int.MaxValue)), - null, - maxAudioChannels, - null, - null, - null, - null, - null, - startTimeTicks, - null, - null, - null, - null, - SubtitleDeliveryMethod.Embed, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - mediaSource.TranscodeReasons == null ? null : string.Join(",", mediaSource.TranscodeReasons.Select(i => i.ToString()).ToArray()), - null, - null, - null, - null) - .ConfigureAwait(false); } return await audioController.GetAudioStream( -- cgit v1.2.3 From d2dd847b6042845f9c0146acb953d454f13dbe9c Mon Sep 17 00:00:00 2001 From: David Date: Sat, 1 Aug 2020 19:25:53 +0200 Subject: Remove duplicate code --- .../Controllers/UniversalAudioController.cs | 98 +++++++++++----------- 1 file changed, 49 insertions(+), 49 deletions(-) (limited to 'Jellyfin.Api/Controllers/UniversalAudioController.cs') diff --git a/Jellyfin.Api/Controllers/UniversalAudioController.cs b/Jellyfin.Api/Controllers/UniversalAudioController.cs index 44dd5f1fd..87d9a611a 100644 --- a/Jellyfin.Api/Controllers/UniversalAudioController.cs +++ b/Jellyfin.Api/Controllers/UniversalAudioController.cs @@ -282,55 +282,55 @@ namespace Jellyfin.Api.Controllers } return await audioController.GetAudioStream( - itemId, - isStatic ? null : ("." + mediaSource.TranscodingContainer), - isStatic, - null, - null, - null, - playbackInfoResult.Value.PlaySessionId, - null, - null, - null, - mediaSource.Id, - deviceId, - audioCodec, - null, - null, - null, - breakOnNonKeyFrames, - maxAudioSampleRate, - maxAudioBitDepth, - isStatic ? (int?)null : Convert.ToInt32(Math.Min(maxStreamingBitrate ?? 192000, int.MaxValue)), - null, - maxAudioChannels, - null, - null, - null, - null, - null, - startTimeTicks, - null, - null, - null, - null, - SubtitleDeliveryMethod.Embed, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - mediaSource.TranscodeReasons == null ? null : string.Join(",", mediaSource.TranscodeReasons.Select(i => i.ToString()).ToArray()), - null, - null, - null, - null) + itemId, + isStatic ? null : ("." + mediaSource.TranscodingContainer), + isStatic, + null, + null, + null, + playbackInfoResult.Value.PlaySessionId, + null, + null, + null, + mediaSource.Id, + deviceId, + audioCodec, + null, + null, + null, + breakOnNonKeyFrames, + maxAudioSampleRate, + maxAudioBitDepth, + isStatic ? (int?)null : Convert.ToInt32(Math.Min(maxStreamingBitrate ?? 192000, int.MaxValue)), + null, + maxAudioChannels, + null, + null, + null, + null, + null, + startTimeTicks, + null, + null, + null, + null, + SubtitleDeliveryMethod.Embed, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + mediaSource.TranscodeReasons == null ? null : string.Join(",", mediaSource.TranscodeReasons.Select(i => i.ToString()).ToArray()), + null, + null, + null, + null) .ConfigureAwait(false); } } -- cgit v1.2.3