public async Task <ActionResult <PlaybackInfoResponse> > GetPostedPlaybackInfo( [FromRoute, Required] Guid itemId, [FromQuery] Guid?userId, [FromQuery] int?maxStreamingBitrate, [FromQuery] long?startTimeTicks, [FromQuery] int?audioStreamIndex, [FromQuery] int?subtitleStreamIndex, [FromQuery] int?maxAudioChannels, [FromQuery] string?mediaSourceId, [FromQuery] string?liveStreamId, [FromQuery] bool?autoOpenLiveStream, [FromQuery] bool?enableDirectPlay, [FromQuery] bool?enableDirectStream, [FromQuery] bool?enableTranscoding, [FromQuery] bool?allowVideoStreamCopy, [FromQuery] bool?allowAudioStreamCopy, [FromBody(EmptyBodyBehavior = EmptyBodyBehavior.Allow)] PlaybackInfoDto?playbackInfoDto) { var authInfo = _authContext.GetAuthorizationInfo(Request); var profile = playbackInfoDto?.DeviceProfile; _logger.LogInformation("GetPostedPlaybackInfo profile: {@Profile}", profile); if (profile == null) { var caps = _deviceManager.GetCapabilities(authInfo.DeviceId); if (caps != null) { profile = caps.DeviceProfile; } } // Copy params from posted body // TODO clean up when breaking API compatibility. userId ??= playbackInfoDto?.UserId; maxStreamingBitrate ??= playbackInfoDto?.MaxStreamingBitrate; startTimeTicks ??= playbackInfoDto?.StartTimeTicks; audioStreamIndex ??= playbackInfoDto?.AudioStreamIndex; subtitleStreamIndex ??= playbackInfoDto?.SubtitleStreamIndex; maxAudioChannels ??= playbackInfoDto?.MaxAudioChannels; mediaSourceId ??= playbackInfoDto?.MediaSourceId; liveStreamId ??= playbackInfoDto?.LiveStreamId; autoOpenLiveStream ??= playbackInfoDto?.AutoOpenLiveStream ?? false; enableDirectPlay ??= playbackInfoDto?.EnableDirectPlay ?? true; enableDirectStream ??= playbackInfoDto?.EnableDirectStream ?? true; enableTranscoding ??= playbackInfoDto?.EnableTranscoding ?? true; allowVideoStreamCopy ??= playbackInfoDto?.AllowVideoStreamCopy ?? true; allowAudioStreamCopy ??= playbackInfoDto?.AllowAudioStreamCopy ?? true; var info = await _mediaInfoHelper.GetPlaybackInfo( itemId, userId, mediaSourceId, liveStreamId) .ConfigureAwait(false); if (profile != null) { // set device specific data var item = _libraryManager.GetItemById(itemId); foreach (var mediaSource in info.MediaSources) { _mediaInfoHelper.SetDeviceSpecificData( item, mediaSource, profile, authInfo, maxStreamingBitrate ?? profile.MaxStreamingBitrate, startTimeTicks ?? 0, mediaSourceId ?? string.Empty, audioStreamIndex, subtitleStreamIndex, maxAudioChannels, info !.PlaySessionId !, userId ?? Guid.Empty, enableDirectPlay.Value, enableDirectStream.Value, enableTranscoding.Value, allowVideoStreamCopy.Value, allowAudioStreamCopy.Value, Request.HttpContext.GetNormalizedRemoteIp()); } _mediaInfoHelper.SortMediaSources(info, maxStreamingBitrate); } if (autoOpenLiveStream.Value) { var mediaSource = string.IsNullOrWhiteSpace(mediaSourceId) ? info.MediaSources[0] : info.MediaSources.FirstOrDefault(i => string.Equals(i.Id, mediaSourceId, StringComparison.Ordinal)); if (mediaSource != null && mediaSource.RequiresOpening && string.IsNullOrWhiteSpace(mediaSource.LiveStreamId)) { var openStreamResult = await _mediaInfoHelper.OpenMediaSource( Request, new LiveStreamRequest { AudioStreamIndex = audioStreamIndex, DeviceProfile = playbackInfoDto?.DeviceProfile, EnableDirectPlay = enableDirectPlay.Value, EnableDirectStream = enableDirectStream.Value, ItemId = itemId, MaxAudioChannels = maxAudioChannels, MaxStreamingBitrate = maxStreamingBitrate, PlaySessionId = info.PlaySessionId, StartTimeTicks = startTimeTicks, SubtitleStreamIndex = subtitleStreamIndex, UserId = userId ?? Guid.Empty, OpenToken = mediaSource.OpenToken }).ConfigureAwait(false); info.MediaSources = new[] { openStreamResult.MediaSource }; } } if (info.MediaSources != null) { foreach (var mediaSource in info.MediaSources) { _mediaInfoHelper.NormalizeMediaSourceContainer(mediaSource, profile !, DlnaProfileType.Video); } } return(info); }
public async Task <ActionResult> GetUniversalAudioStream( [FromRoute, Required] Guid itemId, [FromRoute, Required] 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) { var deviceProfile = GetDeviceProfile(container, transcodingContainer, audioCodec, transcodingProtocol, breakOnNonKeyFrames, transcodingAudioChannels, maxAudioSampleRate, maxAudioBitDepth, maxAudioChannels); _authorizationContext.GetAuthorizationInfo(Request).DeviceId = deviceId; var authInfo = _authorizationContext.GetAuthorizationInfo(Request); _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( itemId, userId, mediaSourceId) .ConfigureAwait(false); if (deviceProfile != null) { // set device specific data var item = _libraryManager.GetItemById(itemId); foreach (var sourceInfo in info.MediaSources) { _mediaInfoHelper.SetDeviceSpecificData( item, sourceInfo, deviceProfile, authInfo, maxStreamingBitrate ?? deviceProfile.MaxStreamingBitrate, startTimeTicks ?? 0, mediaSourceId ?? string.Empty, null, null, maxAudioChannels, info !.PlaySessionId !, userId ?? Guid.Empty, true, true, true, true, true, Request.HttpContext.Connection.RemoteIpAddress.ToString()); } _mediaInfoHelper.SortMediaSources(info, maxStreamingBitrate); } if (info.MediaSources != null) { foreach (var source in info.MediaSources) { _mediaInfoHelper.NormalizeMediaSourceContainer(source, deviceProfile !, DlnaProfileType.Video); } } var mediaSource = info.MediaSources ![0];