private async Task <object> GetUniversalStream(GetUniversalAudioStream request, bool isHeadRequest) { var deviceProfile = GetDeviceProfile(request); AuthorizationContext.GetAuthorizationInfo(Request).DeviceId = request.DeviceId; var mediaInfoService = new MediaInfoService( _loggerFactory.CreateLogger <MediaInfoService>(), ServerConfigurationManager, ResultFactory, MediaSourceManager, DeviceManager, LibraryManager, NetworkManager, MediaEncoder, UserManager, AuthorizationContext) { Request = Request }; var playbackInfoResult = await mediaInfoService.GetPlaybackInfo(new GetPostedPlaybackInfo { Id = request.Id, MaxAudioChannels = request.MaxAudioChannels, MaxStreamingBitrate = request.MaxStreamingBitrate, StartTimeTicks = request.StartTimeTicks, UserId = request.UserId, DeviceProfile = deviceProfile, MediaSourceId = request.MediaSourceId }).ConfigureAwait(false); var mediaSource = playbackInfoResult.MediaSources[0]; if (mediaSource.SupportsDirectPlay && mediaSource.Protocol == MediaProtocol.Http) { if (request.EnableRedirection) { if (mediaSource.IsRemote && request.EnableRemoteMedia) { return(ResultFactory.GetRedirectResult(mediaSource.Path)); } } } var isStatic = mediaSource.SupportsDirectStream; if (!isStatic && string.Equals(mediaSource.TranscodingSubProtocol, "hls", StringComparison.OrdinalIgnoreCase)) { var service = new DynamicHlsService( _loggerFactory.CreateLogger <DynamicHlsService>(), ServerConfigurationManager, ResultFactory, UserManager, LibraryManager, IsoManager, MediaEncoder, FileSystem, DlnaManager, DeviceManager, MediaSourceManager, JsonSerializer, AuthorizationContext, NetworkManager, _encodingHelper) { Request = Request }; 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) { return(await service.Head(newRequest).ConfigureAwait(false)); } return(await service.Get(newRequest).ConfigureAwait(false)); } else { var service = new AudioService( _loggerFactory.CreateLogger <AudioService>(), ServerConfigurationManager, ResultFactory, HttpClient, UserManager, LibraryManager, IsoManager, MediaEncoder, FileSystem, DlnaManager, DeviceManager, MediaSourceManager, JsonSerializer, AuthorizationContext, _encodingHelper) { Request = Request }; var newRequest = new GetAudioStream { AudioBitRate = isStatic ? (int?)null : Convert.ToInt32(Math.Min(request.MaxStreamingBitrate ?? 192000, int.MaxValue)), AudioCodec = request.AudioCodec, Container = isStatic ? null : ("." + mediaSource.TranscodingContainer), DeviceId = request.DeviceId, Id = request.Id, MaxAudioChannels = request.MaxAudioChannels, MediaSourceId = mediaSource.Id, PlaySessionId = playbackInfoResult.PlaySessionId, StartTimeTicks = request.StartTimeTicks, Static = isStatic, AudioSampleRate = request.MaxAudioSampleRate, MaxAudioBitDepth = request.MaxAudioBitDepth, TranscodeReasons = mediaSource.TranscodeReasons == null ? null : string.Join(",", mediaSource.TranscodeReasons.Select(i => i.ToString()).ToArray()) }; if (isHeadRequest) { return(await service.Head(newRequest).ConfigureAwait(false)); } return(await service.Get(newRequest).ConfigureAwait(false)); } }
private async Task <object> GetUniversalStream(GetUniversalAudioStream request, bool isHeadRequest) { var deviceProfile = GetDeviceProfile(request); AuthorizationContext.GetAuthorizationInfo(Request).DeviceId = request.DeviceId; var mediaInfoService = new MediaInfoService(MediaSourceManager, DeviceManager, LibraryManager, ServerConfigurationManager, NetworkManager, MediaEncoder, UserManager, JsonSerializer, AuthorizationContext, _loggerFactory) { Request = Request }; var playbackInfoResult = await mediaInfoService.GetPlaybackInfo(new GetPostedPlaybackInfo { Id = request.Id, MaxAudioChannels = request.MaxAudioChannels, MaxStreamingBitrate = request.MaxStreamingBitrate, StartTimeTicks = request.StartTimeTicks, UserId = request.UserId, DeviceProfile = deviceProfile, MediaSourceId = request.MediaSourceId }).ConfigureAwait(false); var mediaSource = playbackInfoResult.MediaSources[0]; if (mediaSource.SupportsDirectPlay && mediaSource.Protocol == MediaProtocol.Http) { if (request.EnableRedirection) { if (mediaSource.IsRemote && request.EnableRemoteMedia) { return(ResultFactory.GetRedirectResult(mediaSource.Path)); } } } var isStatic = mediaSource.SupportsDirectStream; if (!isStatic && string.Equals(mediaSource.TranscodingSubProtocol, "hls", StringComparison.OrdinalIgnoreCase)) { var service = new DynamicHlsService(ServerConfigurationManager, UserManager, LibraryManager, IsoManager, MediaEncoder, FileSystem, DlnaManager, SubtitleEncoder, DeviceManager, MediaSourceManager, JsonSerializer, AuthorizationContext, NetworkManager) { Request = Request }; var transcodingProfile = deviceProfile.TranscodingProfiles[0]; 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, SegmentContainer = request.TranscodingContainer, 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) { return(await service.Head(newRequest).ConfigureAwait(false)); } return(await service.Get(newRequest).ConfigureAwait(false)); } else { var service = new AudioService(HttpClient, ServerConfigurationManager, UserManager, LibraryManager, IsoManager, MediaEncoder, FileSystem, DlnaManager, SubtitleEncoder, DeviceManager, MediaSourceManager, JsonSerializer, AuthorizationContext, EnvironmentInfo) { Request = Request }; var newRequest = new GetAudioStream { AudioBitRate = isStatic ? (int?)null : Convert.ToInt32(Math.Min(request.MaxStreamingBitrate ?? 192000, int.MaxValue)), AudioCodec = request.AudioCodec, Container = isStatic ? null : ("." + mediaSource.TranscodingContainer), DeviceId = request.DeviceId, Id = request.Id, MaxAudioChannels = request.MaxAudioChannels, MediaSourceId = mediaSource.Id, PlaySessionId = playbackInfoResult.PlaySessionId, StartTimeTicks = request.StartTimeTicks, Static = isStatic, AudioSampleRate = request.MaxAudioSampleRate, MaxAudioBitDepth = request.MaxAudioBitDepth, TranscodeReasons = mediaSource.TranscodeReasons == null ? null : string.Join(",", mediaSource.TranscodeReasons.Select(i => i.ToString()).ToArray()) }; if (isHeadRequest) { return(await service.Head(newRequest).ConfigureAwait(false)); } return(await service.Get(newRequest).ConfigureAwait(false)); } }
private async Task <object> GetUniversalStream(GetUniversalAudioStream request, bool isHeadRequest) { var deviceProfile = GetDeviceProfile(request); AuthorizationContext.GetAuthorizationInfo(Request).DeviceId = request.DeviceId; var mediaInfoService = new MediaInfoService(MediaSourceManager, DeviceManager, LibraryManager, ServerConfigurationManager, NetworkManager, MediaEncoder, UserManager, JsonSerializer, AuthorizationContext) { Request = Request }; var playbackInfoResult = await mediaInfoService.GetPlaybackInfo(new GetPostedPlaybackInfo { Id = request.Id, MaxAudioChannels = request.MaxAudioChannels, MaxStreamingBitrate = request.MaxStreamingBitrate, StartTimeTicks = request.StartTimeTicks, UserId = request.UserId, DeviceProfile = deviceProfile, MediaSourceId = request.MediaSourceId }).ConfigureAwait(false); var mediaSource = playbackInfoResult.MediaSources[0]; var isStatic = mediaSource.SupportsDirectStream; if (!isStatic && string.Equals(mediaSource.TranscodingSubProtocol, "hls", StringComparison.OrdinalIgnoreCase)) { var service = new DynamicHlsService(ServerConfigurationManager, UserManager, LibraryManager, IsoManager, MediaEncoder, FileSystem, DlnaManager, SubtitleEncoder, DeviceManager, MediaSourceManager, ZipClient, JsonSerializer, AuthorizationContext, NetworkManager) { Request = Request }; var transcodingProfile = deviceProfile.TranscodingProfiles[0]; 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 }; if (isHeadRequest) { return(await service.Head(newRequest).ConfigureAwait(false)); } return(await service.Get(newRequest).ConfigureAwait(false)); } else { var service = new AudioService(ServerConfigurationManager, UserManager, LibraryManager, IsoManager, MediaEncoder, FileSystem, DlnaManager, SubtitleEncoder, DeviceManager, MediaSourceManager, ZipClient, JsonSerializer, AuthorizationContext, ImageProcessor) { Request = Request }; var newRequest = new GetAudioStream { AudioBitRate = isStatic ? (int?)null : Convert.ToInt32(Math.Min(request.MaxStreamingBitrate ?? 192000, int.MaxValue)), //AudioCodec = request.AudioCodec, Container = isStatic ? null : ("." + mediaSource.TranscodingContainer), DeviceId = request.DeviceId, Id = request.Id, MaxAudioChannels = request.MaxAudioChannels, MediaSourceId = mediaSource.Id, PlaySessionId = playbackInfoResult.PlaySessionId, StartTimeTicks = request.StartTimeTicks, Static = isStatic }; if (isHeadRequest) { return(await service.Head(newRequest).ConfigureAwait(false)); } return(await service.Get(newRequest).ConfigureAwait(false)); } }