Add properties to StreamState to fix some errors

This commit is contained in:
David 2020-07-22 10:57:27 +02:00
parent 07e56850be
commit eae665a9c4
3 changed files with 62 additions and 31 deletions

View file

@ -92,7 +92,10 @@ namespace Jellyfin.Api.Helpers
var state = new StreamState(mediaSourceManager, transcodingJobType, transcodingJobHelper) var state = new StreamState(mediaSourceManager, transcodingJobType, transcodingJobHelper)
{ {
// TODO request was the StreamingRequest living in MediaBrowser.Api.Playback.Progressive // TODO request was the StreamingRequest living in MediaBrowser.Api.Playback.Progressive
Request = request, // Request = request,
DeviceId = deviceId,
PlaySessionId = playSessionId,
LiveStreamId = liveStreamId,
RequestedUrl = url, RequestedUrl = url,
UserAgent = request.Headers[HeaderNames.UserAgent], UserAgent = request.Headers[HeaderNames.UserAgent],
EnableDlnaHeaders = enableDlnaHeaders EnableDlnaHeaders = enableDlnaHeaders
@ -113,23 +116,23 @@ namespace Jellyfin.Api.Helpers
} }
*/ */
if (state.VideoRequest != null && !string.IsNullOrWhiteSpace(state.VideoRequest.VideoCodec)) if (state.IsVideoRequest && !string.IsNullOrWhiteSpace(state.VideoCodec))
{ {
state.SupportedVideoCodecs = state.VideoRequest.VideoCodec.Split(',').Where(i => !string.IsNullOrWhiteSpace(i)).ToArray(); state.SupportedVideoCodecs = state.VideoCodec.Split(',').Where(i => !string.IsNullOrWhiteSpace(i)).ToArray();
state.VideoRequest.VideoCodec = state.SupportedVideoCodecs.FirstOrDefault(); state.VideoCodec = state.SupportedVideoCodecs.FirstOrDefault();
} }
if (!string.IsNullOrWhiteSpace(audioCodec)) if (!string.IsNullOrWhiteSpace(audioCodec))
{ {
state.SupportedAudioCodecs = audioCodec.Split(',').Where(i => !string.IsNullOrWhiteSpace(i)).ToArray(); state.SupportedAudioCodecs = audioCodec.Split(',').Where(i => !string.IsNullOrWhiteSpace(i)).ToArray();
state.Request.AudioCodec = state.SupportedAudioCodecs.FirstOrDefault(i => mediaEncoder.CanEncodeToAudioCodec(i)) state.AudioCodec = state.SupportedAudioCodecs.FirstOrDefault(i => mediaEncoder.CanEncodeToAudioCodec(i))
?? state.SupportedAudioCodecs.FirstOrDefault(); ?? state.SupportedAudioCodecs.FirstOrDefault();
} }
if (!string.IsNullOrWhiteSpace(subtitleCodec)) if (!string.IsNullOrWhiteSpace(subtitleCodec))
{ {
state.SupportedSubtitleCodecs = subtitleCodec.Split(',').Where(i => !string.IsNullOrWhiteSpace(i)).ToArray(); state.SupportedSubtitleCodecs = subtitleCodec.Split(',').Where(i => !string.IsNullOrWhiteSpace(i)).ToArray();
state.Request.SubtitleCodec = state.SupportedSubtitleCodecs.FirstOrDefault(i => mediaEncoder.CanEncodeToSubtitleCodec(i)) state.SubtitleCodec = state.SupportedSubtitleCodecs.FirstOrDefault(i => mediaEncoder.CanEncodeToSubtitleCodec(i))
?? state.SupportedSubtitleCodecs.FirstOrDefault(); ?? state.SupportedSubtitleCodecs.FirstOrDefault();
} }
@ -203,7 +206,7 @@ namespace Jellyfin.Api.Helpers
if (isVideoRequest) if (isVideoRequest)
{ {
state.OutputVideoCodec = state.VideoRequest.VideoCodec; state.OutputVideoCodec = state.VideoCodec;
state.OutputVideoBitrate = EncodingHelper.GetVideoBitrateParamValue(state.VideoRequest, state.VideoStream, state.OutputVideoCodec); state.OutputVideoBitrate = EncodingHelper.GetVideoBitrateParamValue(state.VideoRequest, state.VideoStream, state.OutputVideoCodec);
encodingHelper.TryStreamCopy(state); encodingHelper.TryStreamCopy(state);
@ -288,7 +291,7 @@ namespace Jellyfin.Api.Helpers
var audioCodec = state.ActualOutputAudioCodec; var audioCodec = state.ActualOutputAudioCodec;
if (state.VideoRequest == null) if (!state.IsVideoRequest)
{ {
responseHeaders.Add("contentFeatures.dlna.org", new ContentFeatureBuilder(profile).BuildAudioHeader( responseHeaders.Add("contentFeatures.dlna.org", new ContentFeatureBuilder(profile).BuildAudioHeader(
state.OutputContainer, state.OutputContainer,
@ -426,12 +429,10 @@ namespace Jellyfin.Api.Helpers
return ext; return ext;
} }
var isVideoRequest = state.VideoRequest != null;
// Try to infer based on the desired video codec // Try to infer based on the desired video codec
if (isVideoRequest) if (state.IsVideoRequest)
{ {
var videoCodec = state.VideoRequest.VideoCodec; var videoCodec = state.VideoCodec;
if (string.Equals(videoCodec, "h264", StringComparison.OrdinalIgnoreCase) || if (string.Equals(videoCodec, "h264", StringComparison.OrdinalIgnoreCase) ||
string.Equals(videoCodec, "h265", StringComparison.OrdinalIgnoreCase)) string.Equals(videoCodec, "h265", StringComparison.OrdinalIgnoreCase))
@ -456,9 +457,9 @@ namespace Jellyfin.Api.Helpers
} }
// Try to infer based on the desired audio codec // Try to infer based on the desired audio codec
if (!isVideoRequest) if (!state.IsVideoRequest)
{ {
var audioCodec = state.Request.AudioCodec; var audioCodec = state.AudioCodec;
if (string.Equals("aac", audioCodec, StringComparison.OrdinalIgnoreCase)) if (string.Equals("aac", audioCodec, StringComparison.OrdinalIgnoreCase))
{ {
@ -531,7 +532,7 @@ namespace Jellyfin.Api.Helpers
var audioCodec = state.ActualOutputAudioCodec; var audioCodec = state.ActualOutputAudioCodec;
var videoCodec = state.ActualOutputVideoCodec; var videoCodec = state.ActualOutputVideoCodec;
var mediaProfile = state.VideoRequest == null var mediaProfile = !state.IsVideoRequest
? profile.GetAudioMediaProfile(state.OutputContainer, audioCodec, state.OutputAudioChannels, state.OutputAudioBitrate, state.OutputAudioSampleRate, state.OutputAudioBitDepth) ? profile.GetAudioMediaProfile(state.OutputContainer, audioCodec, state.OutputAudioChannels, state.OutputAudioBitrate, state.OutputAudioSampleRate, state.OutputAudioBitDepth)
: profile.GetVideoMediaProfile( : profile.GetVideoMediaProfile(
state.OutputContainer, state.OutputContainer,
@ -561,7 +562,7 @@ namespace Jellyfin.Api.Helpers
if (!(@static.HasValue && @static.Value)) if (!(@static.HasValue && @static.Value))
{ {
var transcodingProfile = state.VideoRequest == null ? profile.GetAudioTranscodingProfile(state.OutputContainer, audioCodec) : profile.GetVideoTranscodingProfile(state.OutputContainer, audioCodec, videoCodec); var transcodingProfile = !state.IsVideoRequest ? profile.GetAudioTranscodingProfile(state.OutputContainer, audioCodec) : profile.GetVideoTranscodingProfile(state.OutputContainer, audioCodec, videoCodec);
if (transcodingProfile != null) if (transcodingProfile != null)
{ {
@ -569,7 +570,7 @@ namespace Jellyfin.Api.Helpers
// state.EnableMpegtsM2TsMode = transcodingProfile.EnableMpegtsM2TsMode; // state.EnableMpegtsM2TsMode = transcodingProfile.EnableMpegtsM2TsMode;
state.TranscodeSeekInfo = transcodingProfile.TranscodeSeekInfo; state.TranscodeSeekInfo = transcodingProfile.TranscodeSeekInfo;
if (state.VideoRequest != null) if (!state.IsVideoRequest)
{ {
state.VideoRequest.CopyTimestamps = transcodingProfile.CopyTimestamps; state.VideoRequest.CopyTimestamps = transcodingProfile.CopyTimestamps;
state.VideoRequest.EnableSubtitlesInManifest = transcodingProfile.EnableSubtitlesInManifest; state.VideoRequest.EnableSubtitlesInManifest = transcodingProfile.EnableSubtitlesInManifest;

View file

@ -443,7 +443,7 @@ namespace Jellyfin.Api.Helpers
job.BitRate = bitRate; job.BitRate = bitRate;
} }
var deviceId = state.Request.DeviceId; var deviceId = state.DeviceId;
if (!string.IsNullOrWhiteSpace(deviceId)) if (!string.IsNullOrWhiteSpace(deviceId))
{ {
@ -525,12 +525,12 @@ namespace Jellyfin.Api.Helpers
var transcodingJob = this.OnTranscodeBeginning( var transcodingJob = this.OnTranscodeBeginning(
outputPath, outputPath,
state.Request.PlaySessionId, state.PlaySessionId,
state.MediaSource.LiveStreamId, state.MediaSource.LiveStreamId,
Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture), Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture),
transcodingJobType, transcodingJobType,
process, process,
state.Request.DeviceId, state.DeviceId,
state, state,
cancellationTokenSource); cancellationTokenSource);
@ -647,12 +647,12 @@ namespace Jellyfin.Api.Helpers
/// <returns>TranscodingJob.</returns> /// <returns>TranscodingJob.</returns>
public TranscodingJobDto OnTranscodeBeginning( public TranscodingJobDto OnTranscodeBeginning(
string path, string path,
string playSessionId, string? playSessionId,
string liveStreamId, string? liveStreamId,
string transcodingJobId, string transcodingJobId,
TranscodingJobType type, TranscodingJobType type,
Process process, Process process,
string deviceId, string? deviceId,
StreamState state, StreamState state,
CancellationTokenSource cancellationTokenSource) CancellationTokenSource cancellationTokenSource)
{ {
@ -706,9 +706,9 @@ namespace Jellyfin.Api.Helpers
_transcodingLocks.Remove(path); _transcodingLocks.Remove(path);
} }
if (!string.IsNullOrWhiteSpace(state.Request.DeviceId)) if (!string.IsNullOrWhiteSpace(state.DeviceId))
{ {
_sessionManager.ClearTranscodingInfo(state.Request.DeviceId); _sessionManager.ClearTranscodingInfo(state.DeviceId);
} }
} }
@ -747,7 +747,7 @@ namespace Jellyfin.Api.Helpers
state.IsoMount = await _isoManager.Mount(state.MediaPath, cancellationTokenSource.Token).ConfigureAwait(false); state.IsoMount = await _isoManager.Mount(state.MediaPath, cancellationTokenSource.Token).ConfigureAwait(false);
} }
if (state.MediaSource.RequiresOpening && string.IsNullOrWhiteSpace(state.Request.LiveStreamId)) if (state.MediaSource.RequiresOpening && string.IsNullOrWhiteSpace(state.LiveStreamId))
{ {
var liveStreamResponse = await _mediaSourceManager.OpenLiveStream( var liveStreamResponse = await _mediaSourceManager.OpenLiveStream(
new LiveStreamRequest { OpenToken = state.MediaSource.OpenToken }, new LiveStreamRequest { OpenToken = state.MediaSource.OpenToken },

View file

@ -53,10 +53,10 @@ namespace Jellyfin.Api.Models.StreamingDtos
/// </summary> /// </summary>
public TranscodingThrottler? TranscodingThrottler { get; set; } public TranscodingThrottler? TranscodingThrottler { get; set; }
/// <summary> /*/// <summary>
/// Gets the video request. /// Gets the video request.
/// </summary> /// </summary>
public VideoStreamRequest VideoRequest => Request as VideoStreamRequest; public VideoStreamRequest VideoRequest => Request as VideoStreamRequest;*/
/// <summary> /// <summary>
/// Gets or sets the direct stream provicer. /// Gets or sets the direct stream provicer.
@ -68,10 +68,10 @@ namespace Jellyfin.Api.Models.StreamingDtos
/// </summary> /// </summary>
public string? WaitForPath { get; set; } public string? WaitForPath { get; set; }
/// <summary> /*/// <summary>
/// Gets a value indicating whether the request outputs video. /// Gets a value indicating whether the request outputs video.
/// </summary> /// </summary>
public bool IsOutputVideo => Request is VideoStreamRequest; public bool IsOutputVideo => Request is VideoStreamRequest;*/
/// <summary> /// <summary>
/// Gets the segment length. /// Gets the segment length.
@ -161,6 +161,36 @@ namespace Jellyfin.Api.Models.StreamingDtos
/// </summary> /// </summary>
public TranscodingJobDto? TranscodingJob { get; set; } public TranscodingJobDto? TranscodingJob { get; set; }
/// <summary>
/// Gets or sets the device id.
/// </summary>
public string? DeviceId { get; set; }
/// <summary>
/// Gets or sets the play session id.
/// </summary>
public string? PlaySessionId { get; set; }
/// <summary>
/// Gets or sets the live stream id.
/// </summary>
public string? LiveStreamId { get; set; }
/// <summary>
/// Gets or sets the video coded.
/// </summary>
public string? VideoCodec { get; set; }
/// <summary>
/// Gets or sets the audio codec.
/// </summary>
public string? AudioCodec { get; set; }
/// <summary>
/// Gets or sets the subtitle codec.
/// </summary>
public string? SubtitleCodec { get; set; }
/// <inheritdoc /> /// <inheritdoc />
public void Dispose() public void Dispose()
{ {
@ -189,7 +219,7 @@ namespace Jellyfin.Api.Models.StreamingDtos
{ {
// REVIEW: Is this the right place for this? // REVIEW: Is this the right place for this?
if (MediaSource.RequiresClosing if (MediaSource.RequiresClosing
&& string.IsNullOrWhiteSpace(Request.LiveStreamId) && string.IsNullOrWhiteSpace(LiveStreamId)
&& !string.IsNullOrWhiteSpace(MediaSource.LiveStreamId)) && !string.IsNullOrWhiteSpace(MediaSource.LiveStreamId))
{ {
_mediaSourceManager.CloseLiveStream(MediaSource.LiveStreamId).GetAwaiter().GetResult(); _mediaSourceManager.CloseLiveStream(MediaSource.LiveStreamId).GetAwaiter().GetResult();