mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-06 05:47:14 -04:00
Fix streambuilder reasons for direct playback checks
This commit is contained in:
parent
3229ba4918
commit
0c8b9091a5
@ -385,7 +385,7 @@ namespace MediaBrowser.Model.Dlna
|
|||||||
// If device requirements are satisfied then allow both direct stream and direct play
|
// If device requirements are satisfied then allow both direct stream and direct play
|
||||||
if (item.SupportsDirectPlay)
|
if (item.SupportsDirectPlay)
|
||||||
{
|
{
|
||||||
if (IsItemBitrateEligibleForDirectPlay(item, options.GetMaxBitrate(true) ?? 0, PlayMethod.DirectPlay))
|
if (IsItemBitrateEligibleForDirectPlayback(item, options.GetMaxBitrate(true) ?? 0, PlayMethod.DirectPlay))
|
||||||
{
|
{
|
||||||
if (options.EnableDirectPlay)
|
if (options.EnableDirectPlay)
|
||||||
{
|
{
|
||||||
@ -401,7 +401,7 @@ namespace MediaBrowser.Model.Dlna
|
|||||||
// While options takes the network and other factors into account. Only applies to direct stream
|
// While options takes the network and other factors into account. Only applies to direct stream
|
||||||
if (item.SupportsDirectStream)
|
if (item.SupportsDirectStream)
|
||||||
{
|
{
|
||||||
if (IsItemBitrateEligibleForDirectPlay(item, options.GetMaxBitrate(true) ?? 0, PlayMethod.DirectStream))
|
if (IsItemBitrateEligibleForDirectPlayback(item, options.GetMaxBitrate(true) ?? 0, PlayMethod.DirectStream))
|
||||||
{
|
{
|
||||||
if (options.EnableDirectStream)
|
if (options.EnableDirectStream)
|
||||||
{
|
{
|
||||||
@ -604,11 +604,11 @@ namespace MediaBrowser.Model.Dlna
|
|||||||
|
|
||||||
var videoStream = item.VideoStream;
|
var videoStream = item.VideoStream;
|
||||||
|
|
||||||
var directPlayEligibilityResult = IsEligibleForDirectPlay(item, options.GetMaxBitrate(false) ?? 0, options, PlayMethod.DirectPlay);
|
var directPlayBitrateEligibility = IsBitrateEligibleForDirectPlayback(item, options.GetMaxBitrate(false) ?? 0, options, PlayMethod.DirectPlay);
|
||||||
var directStreamEligibilityResult = IsEligibleForDirectPlay(item, options.GetMaxBitrate(false) ?? 0, options, PlayMethod.DirectStream);
|
var directStreamBitrateEligibility = IsBitrateEligibleForDirectPlayback(item, options.GetMaxBitrate(false) ?? 0, options, PlayMethod.DirectStream);
|
||||||
bool isEligibleForDirectPlay = options.EnableDirectPlay && (options.ForceDirectPlay || directPlayEligibilityResult == 0);
|
bool isEligibleForDirectPlay = options.EnableDirectPlay && (options.ForceDirectPlay || directPlayBitrateEligibility == 0);
|
||||||
bool isEligibleForDirectStream = options.EnableDirectStream && (options.ForceDirectStream || directPlayEligibilityResult == 0);
|
bool isEligibleForDirectStream = options.EnableDirectStream && (options.ForceDirectStream || directStreamBitrateEligibility == 0);
|
||||||
var transcodeReasons = directPlayEligibilityResult | directStreamEligibilityResult;
|
var transcodeReasons = directPlayBitrateEligibility | directStreamBitrateEligibility;
|
||||||
|
|
||||||
_logger.LogDebug(
|
_logger.LogDebug(
|
||||||
"Profile: {0}, Path: {1}, isEligibleForDirectPlay: {2}, isEligibleForDirectStream: {3}",
|
"Profile: {0}, Path: {1}, isEligibleForDirectPlay: {2}, isEligibleForDirectStream: {3}",
|
||||||
@ -625,7 +625,7 @@ namespace MediaBrowser.Model.Dlna
|
|||||||
var directPlay = directPlayInfo.PlayMethod;
|
var directPlay = directPlayInfo.PlayMethod;
|
||||||
transcodeReasons |= directPlayInfo.TranscodeReasons;
|
transcodeReasons |= directPlayInfo.TranscodeReasons;
|
||||||
|
|
||||||
if (directPlay != null)
|
if (directPlay.HasValue)
|
||||||
{
|
{
|
||||||
directPlayProfile = directPlayInfo.Profile;
|
directPlayProfile = directPlayInfo.Profile;
|
||||||
playlistItem.PlayMethod = directPlay.Value;
|
playlistItem.PlayMethod = directPlay.Value;
|
||||||
@ -676,7 +676,7 @@ namespace MediaBrowser.Model.Dlna
|
|||||||
|
|
||||||
playlistItem.TranscodeReasons = transcodeReasons;
|
playlistItem.TranscodeReasons = transcodeReasons;
|
||||||
|
|
||||||
if (playlistItem.PlayMethod != PlayMethod.DirectStream || !options.EnableDirectStream)
|
if (playlistItem.PlayMethod != PlayMethod.DirectStream && playlistItem.PlayMethod != PlayMethod.DirectPlay)
|
||||||
{
|
{
|
||||||
// Can't direct play, find the transcoding profile
|
// Can't direct play, find the transcoding profile
|
||||||
// If we do this for direct-stream we will overwrite the info
|
// If we do this for direct-stream we will overwrite the info
|
||||||
@ -687,6 +687,8 @@ namespace MediaBrowser.Model.Dlna
|
|||||||
|
|
||||||
BuildStreamVideoItem(playlistItem, options, item, videoStream, audioStream, candidateAudioStreams, transcodingProfile.Container, transcodingProfile.VideoCodec, transcodingProfile.AudioCodec);
|
BuildStreamVideoItem(playlistItem, options, item, videoStream, audioStream, candidateAudioStreams, transcodingProfile.Container, transcodingProfile.VideoCodec, transcodingProfile.AudioCodec);
|
||||||
|
|
||||||
|
playlistItem.PlayMethod = PlayMethod.Transcode;
|
||||||
|
|
||||||
if (subtitleStream != null)
|
if (subtitleStream != null)
|
||||||
{
|
{
|
||||||
var subtitleProfile = GetSubtitleProfile(item, subtitleStream, options.Profile.SubtitleProfiles, PlayMethod.Transcode, _transcoderSupport, transcodingProfile.Container, transcodingProfile.Protocol);
|
var subtitleProfile = GetSubtitleProfile(item, subtitleStream, options.Profile.SubtitleProfiles, PlayMethod.Transcode, _transcoderSupport, transcodingProfile.Container, transcodingProfile.Protocol);
|
||||||
@ -696,17 +698,12 @@ namespace MediaBrowser.Model.Dlna
|
|||||||
playlistItem.SubtitleCodecs = new[] { subtitleProfile.Format };
|
playlistItem.SubtitleCodecs = new[] { subtitleProfile.Format };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (playlistItem.PlayMethod != PlayMethod.DirectPlay)
|
|
||||||
{
|
|
||||||
playlistItem.PlayMethod = PlayMethod.Transcode;
|
|
||||||
|
|
||||||
if ((playlistItem.TranscodeReasons & (VideoReasons | TranscodeReason.ContainerBitrateExceedsLimit)) != 0)
|
if ((playlistItem.TranscodeReasons & (VideoReasons | TranscodeReason.ContainerBitrateExceedsLimit)) != 0)
|
||||||
{
|
{
|
||||||
ApplyTranscodingConditions(playlistItem, transcodingProfile.Conditions, null, true, true);
|
ApplyTranscodingConditions(playlistItem, transcodingProfile.Conditions, null, true, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
_logger.LogInformation(
|
_logger.LogInformation(
|
||||||
"StreamBuilder.BuildVideoItem( Profile={0}, Path={1}, AudioStreamIndex={2}, SubtitleStreamIndex={3} ) => ( PlayMethod={4}, TranscodeReason={5} ) {6}",
|
"StreamBuilder.BuildVideoItem( Profile={0}, Path={1}, AudioStreamIndex={2}, SubtitleStreamIndex={3} ) => ( PlayMethod={4}, TranscodeReason={5} ) {6}",
|
||||||
@ -771,12 +768,12 @@ namespace MediaBrowser.Model.Dlna
|
|||||||
|
|
||||||
private void BuildStreamVideoItem(StreamInfo playlistItem, VideoOptions options, MediaSourceInfo item, MediaStream videoStream, MediaStream audioStream, IEnumerable<MediaStream> candidateAudioStreams, string container, string videoCodec, string audioCodec)
|
private void BuildStreamVideoItem(StreamInfo playlistItem, VideoOptions options, MediaSourceInfo item, MediaStream videoStream, MediaStream audioStream, IEnumerable<MediaStream> candidateAudioStreams, string container, string videoCodec, string audioCodec)
|
||||||
{
|
{
|
||||||
// prefer matching video codecs
|
// Prefer matching video codecs
|
||||||
var videoCodecs = ContainerProfile.SplitValue(videoCodec);
|
var videoCodecs = ContainerProfile.SplitValue(videoCodec);
|
||||||
var directVideoCodec = ContainerProfile.ContainsContainer(videoCodecs, videoStream?.Codec) ? videoStream?.Codec : null;
|
var directVideoCodec = ContainerProfile.ContainsContainer(videoCodecs, videoStream?.Codec) ? videoStream?.Codec : null;
|
||||||
playlistItem.VideoCodecs = directVideoCodec != null ? new[] { directVideoCodec } : videoCodecs;
|
playlistItem.VideoCodecs = directVideoCodec != null ? new[] { directVideoCodec } : videoCodecs;
|
||||||
|
|
||||||
// copy video codec options as a starting point, this applies to transcode and direct-stream
|
// Copy video codec options as a starting point, this applies to transcode and direct-stream
|
||||||
playlistItem.MaxFramerate = videoStream?.AverageFrameRate;
|
playlistItem.MaxFramerate = videoStream?.AverageFrameRate;
|
||||||
var qualifier = videoStream?.Codec;
|
var qualifier = videoStream?.Codec;
|
||||||
if (videoStream?.Level != null)
|
if (videoStream?.Level != null)
|
||||||
@ -799,7 +796,7 @@ namespace MediaBrowser.Model.Dlna
|
|||||||
playlistItem.SetOption(qualifier, "level", videoStream.Level.ToString());
|
playlistItem.SetOption(qualifier, "level", videoStream.Level.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
// prefer matching audio codecs, could do better here
|
// Prefer matching audio codecs, could do better here
|
||||||
var audioCodecs = ContainerProfile.SplitValue(audioCodec);
|
var audioCodecs = ContainerProfile.SplitValue(audioCodec);
|
||||||
var directAudioStream = candidateAudioStreams.FirstOrDefault(stream => ContainerProfile.ContainsContainer(audioCodecs, stream.Codec));
|
var directAudioStream = candidateAudioStreams.FirstOrDefault(stream => ContainerProfile.ContainsContainer(audioCodecs, stream.Codec));
|
||||||
playlistItem.AudioCodecs = audioCodecs;
|
playlistItem.AudioCodecs = audioCodecs;
|
||||||
@ -809,7 +806,7 @@ namespace MediaBrowser.Model.Dlna
|
|||||||
playlistItem.AudioStreamIndex = audioStream.Index;
|
playlistItem.AudioStreamIndex = audioStream.Index;
|
||||||
playlistItem.AudioCodecs = new[] { audioStream.Codec };
|
playlistItem.AudioCodecs = new[] { audioStream.Codec };
|
||||||
|
|
||||||
// copy matching audio codec options
|
// Copy matching audio codec options
|
||||||
playlistItem.AudioSampleRate = audioStream.SampleRate;
|
playlistItem.AudioSampleRate = audioStream.SampleRate;
|
||||||
playlistItem.SetOption(qualifier, "audiochannels", audioStream.Channels.ToString());
|
playlistItem.SetOption(qualifier, "audiochannels", audioStream.Channels.ToString());
|
||||||
|
|
||||||
@ -1070,7 +1067,7 @@ namespace MediaBrowser.Model.Dlna
|
|||||||
DeviceProfile profile = options.Profile;
|
DeviceProfile profile = options.Profile;
|
||||||
string container = mediaSource.Container;
|
string container = mediaSource.Container;
|
||||||
|
|
||||||
// video
|
// Video
|
||||||
int? width = videoStream?.Width;
|
int? width = videoStream?.Width;
|
||||||
int? height = videoStream?.Height;
|
int? height = videoStream?.Height;
|
||||||
int? bitDepth = videoStream?.BitDepth;
|
int? bitDepth = videoStream?.BitDepth;
|
||||||
@ -1082,7 +1079,7 @@ namespace MediaBrowser.Model.Dlna
|
|||||||
bool? isInterlaced = videoStream?.IsInterlaced;
|
bool? isInterlaced = videoStream?.IsInterlaced;
|
||||||
string videoCodecTag = videoStream?.CodecTag;
|
string videoCodecTag = videoStream?.CodecTag;
|
||||||
bool? isAvc = videoStream?.IsAVC;
|
bool? isAvc = videoStream?.IsAVC;
|
||||||
// audio
|
// Audio
|
||||||
var defaultLanguage = audioStream?.Language ?? string.Empty;
|
var defaultLanguage = audioStream?.Language ?? string.Empty;
|
||||||
var defaultMarked = audioStream?.IsDefault ?? false;
|
var defaultMarked = audioStream?.IsDefault ?? false;
|
||||||
|
|
||||||
@ -1211,6 +1208,7 @@ namespace MediaBrowser.Model.Dlna
|
|||||||
return (Result: (Profile: directPlayProfile, PlayMethod: playMethod, AudioStreamIndex: selectedAudioStream?.Index, TranscodeReason: failureReasons), Order: order, Rank: ranked);
|
return (Result: (Profile: directPlayProfile, PlayMethod: playMethod, AudioStreamIndex: selectedAudioStream?.Index, TranscodeReason: failureReasons), Order: order, Rank: ranked);
|
||||||
})
|
})
|
||||||
.OrderByDescending(analysis => analysis.Result.PlayMethod)
|
.OrderByDescending(analysis => analysis.Result.PlayMethod)
|
||||||
|
.ThenByDescending(analysis => analysis.Rank)
|
||||||
.ThenBy(analysis => analysis.Order)
|
.ThenBy(analysis => analysis.Order)
|
||||||
.ToArray()
|
.ToArray()
|
||||||
.ToLookup(analysis => analysis.Result.PlayMethod != null);
|
.ToLookup(analysis => analysis.Result.PlayMethod != null);
|
||||||
@ -1223,7 +1221,7 @@ namespace MediaBrowser.Model.Dlna
|
|||||||
return profileMatch;
|
return profileMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
var failureReasons = analyzedProfiles[false].OrderBy(a => a.Result.TranscodeReason).ThenBy(analysis => analysis.Order).FirstOrDefault().Result.TranscodeReason;
|
var failureReasons = analyzedProfiles[false].Select(analysis => analysis.Result).FirstOrDefault().TranscodeReason;
|
||||||
if (failureReasons == 0)
|
if (failureReasons == 0)
|
||||||
{
|
{
|
||||||
failureReasons = TranscodeReason.DirectPlayError;
|
failureReasons = TranscodeReason.DirectPlayError;
|
||||||
@ -1269,13 +1267,13 @@ namespace MediaBrowser.Model.Dlna
|
|||||||
mediaSource.Path ?? "Unknown path");
|
mediaSource.Path ?? "Unknown path");
|
||||||
}
|
}
|
||||||
|
|
||||||
private TranscodeReason IsEligibleForDirectPlay(
|
private TranscodeReason IsBitrateEligibleForDirectPlayback(
|
||||||
MediaSourceInfo item,
|
MediaSourceInfo item,
|
||||||
long maxBitrate,
|
long maxBitrate,
|
||||||
VideoOptions options,
|
VideoOptions options,
|
||||||
PlayMethod playMethod)
|
PlayMethod playMethod)
|
||||||
{
|
{
|
||||||
bool result = IsItemBitrateEligibleForDirectPlay(item, maxBitrate, playMethod);
|
bool result = IsItemBitrateEligibleForDirectPlayback(item, maxBitrate, playMethod);
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
return TranscodeReason.ContainerBitrateExceedsLimit;
|
return TranscodeReason.ContainerBitrateExceedsLimit;
|
||||||
@ -1443,7 +1441,7 @@ namespace MediaBrowser.Model.Dlna
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsItemBitrateEligibleForDirectPlay(MediaSourceInfo item, long maxBitrate, PlayMethod playMethod)
|
private bool IsItemBitrateEligibleForDirectPlayback(MediaSourceInfo item, long maxBitrate, PlayMethod playMethod)
|
||||||
{
|
{
|
||||||
// Don't restrict by bitrate if coming from an external domain
|
// Don't restrict by bitrate if coming from an external domain
|
||||||
if (item.IsRemote)
|
if (item.IsRemote)
|
||||||
|
Loading…
Reference in New Issue
Block a user