diff options
Diffstat (limited to 'MediaBrowser.Model/Dlna/StreamBuilder.cs')
| -rw-r--r-- | MediaBrowser.Model/Dlna/StreamBuilder.cs | 390 |
1 files changed, 265 insertions, 125 deletions
diff --git a/MediaBrowser.Model/Dlna/StreamBuilder.cs b/MediaBrowser.Model/Dlna/StreamBuilder.cs index b04f1b0fb..c05ca4187 100644 --- a/MediaBrowser.Model/Dlna/StreamBuilder.cs +++ b/MediaBrowser.Model/Dlna/StreamBuilder.cs @@ -11,17 +11,17 @@ namespace MediaBrowser.Model.Dlna { public class StreamBuilder { - private readonly ILocalPlayer _localPlayer; private readonly ILogger _logger; + private readonly ITranscoderSupport _transcoderSupport; - public StreamBuilder(ILocalPlayer localPlayer, ILogger logger) + public StreamBuilder(ITranscoderSupport transcoderSupport, ILogger logger) { - _localPlayer = localPlayer; + _transcoderSupport = transcoderSupport; _logger = logger; } public StreamBuilder(ILogger logger) - : this(new NullLocalPlayer(), logger) + : this(new FullTranscoderSupport(), logger) { } @@ -55,7 +55,7 @@ namespace MediaBrowser.Model.Dlna stream.DeviceProfileId = options.Profile.Id; } - return GetOptimalStream(streams); + return GetOptimalStream(streams, options.GetMaxBitrate()); } public StreamInfo BuildVideoItem(VideoOptions options) @@ -88,12 +88,12 @@ namespace MediaBrowser.Model.Dlna stream.DeviceProfileId = options.Profile.Id; } - return GetOptimalStream(streams); + return GetOptimalStream(streams, options.GetMaxBitrate()); } - private StreamInfo GetOptimalStream(List<StreamInfo> streams) + private StreamInfo GetOptimalStream(List<StreamInfo> streams, int? maxBitrate) { - streams = StreamInfoSorter.SortMediaSources(streams); + streams = StreamInfoSorter.SortMediaSources(streams, maxBitrate); foreach (StreamInfo stream in streams) { @@ -115,10 +115,29 @@ namespace MediaBrowser.Model.Dlna DeviceProfile = options.Profile }; + if (options.ForceDirectPlay) + { + playlistItem.PlayMethod = PlayMethod.DirectPlay; + playlistItem.Container = item.Container; + return playlistItem; + } + + if (options.ForceDirectStream) + { + playlistItem.PlayMethod = PlayMethod.DirectStream; + playlistItem.Container = item.Container; + return playlistItem; + } + MediaStream audioStream = item.GetDefaultAudioStream(null); List<PlayMethod> directPlayMethods = GetAudioDirectPlayMethods(item, audioStream, options); + ConditionProcessor conditionProcessor = new ConditionProcessor(); + + int? inputAudioChannels = audioStream == null ? null : audioStream.Channels; + int? inputAudioBitrate = audioStream == null ? null : audioStream.BitDepth; + if (directPlayMethods.Count > 0) { string audioCodec = audioStream == null ? null : audioStream.Codec; @@ -126,27 +145,36 @@ namespace MediaBrowser.Model.Dlna // Make sure audio codec profiles are satisfied if (!string.IsNullOrEmpty(audioCodec)) { - ConditionProcessor conditionProcessor = new ConditionProcessor(); - List<ProfileCondition> conditions = new List<ProfileCondition>(); foreach (CodecProfile i in options.Profile.CodecProfiles) { if (i.Type == CodecType.Audio && i.ContainsCodec(audioCodec, item.Container)) { - foreach (ProfileCondition c in i.Conditions) + bool applyConditions = true; + foreach (ProfileCondition applyCondition in i.ApplyConditions) { - conditions.Add(c); + if (!conditionProcessor.IsAudioConditionSatisfied(applyCondition, inputAudioChannels, inputAudioBitrate)) + { + LogConditionFailure(options.Profile, "AudioCodecProfile", applyCondition, item); + applyConditions = false; + break; + } + } + + if (applyConditions) + { + foreach (ProfileCondition c in i.Conditions) + { + conditions.Add(c); + } } } } - int? audioChannels = audioStream.Channels; - int? audioBitrate = audioStream.BitRate; - bool all = true; foreach (ProfileCondition c in conditions) { - if (!conditionProcessor.IsAudioConditionSatisfied(c, audioChannels, audioBitrate)) + if (!conditionProcessor.IsAudioConditionSatisfied(c, inputAudioChannels, inputAudioBitrate)) { LogConditionFailure(options.Profile, "AudioCodecProfile", c, item); all = false; @@ -156,19 +184,7 @@ namespace MediaBrowser.Model.Dlna if (all) { - if (item.Protocol == MediaProtocol.File && - directPlayMethods.Contains(PlayMethod.DirectPlay) && - _localPlayer.CanAccessFile(item.Path)) - { - playlistItem.PlayMethod = PlayMethod.DirectPlay; - } - else if (item.Protocol == MediaProtocol.Http && - directPlayMethods.Contains(PlayMethod.DirectPlay) && - _localPlayer.CanAccessUrl(item.Path, item.RequiredHttpHeaders.Count > 0)) - { - playlistItem.PlayMethod = PlayMethod.DirectPlay; - } - else if (directPlayMethods.Contains(PlayMethod.DirectStream)) + if (directPlayMethods.Contains(PlayMethod.DirectStream)) { playlistItem.PlayMethod = PlayMethod.DirectStream; } @@ -185,8 +201,11 @@ namespace MediaBrowser.Model.Dlna { if (i.Type == playlistItem.MediaType && i.Context == options.Context) { - transcodingProfile = i; - break; + if (_transcoderSupport.CanEncodeToAudioCodec(i.AudioCodec ?? i.Container)) + { + transcodingProfile = i; + break; + } } } @@ -201,7 +220,15 @@ namespace MediaBrowser.Model.Dlna playlistItem.TranscodeSeekInfo = transcodingProfile.TranscodeSeekInfo; playlistItem.EstimateContentLength = transcodingProfile.EstimateContentLength; playlistItem.Container = transcodingProfile.Container; - playlistItem.AudioCodec = transcodingProfile.AudioCodec; + + if (string.IsNullOrEmpty(transcodingProfile.AudioCodec)) + { + playlistItem.AudioCodecs = new string[] { }; + } + else + { + playlistItem.AudioCodecs = transcodingProfile.AudioCodec.Split(','); + } playlistItem.SubProtocol = transcodingProfile.Protocol; List<CodecProfile> audioCodecProfiles = new List<CodecProfile>(); @@ -218,9 +245,23 @@ namespace MediaBrowser.Model.Dlna List<ProfileCondition> audioTranscodingConditions = new List<ProfileCondition>(); foreach (CodecProfile i in audioCodecProfiles) { - foreach (ProfileCondition c in i.Conditions) + bool applyConditions = true; + foreach (ProfileCondition applyCondition in i.ApplyConditions) { - audioTranscodingConditions.Add(c); + if (!conditionProcessor.IsAudioConditionSatisfied(applyCondition, inputAudioChannels, inputAudioBitrate)) + { + LogConditionFailure(options.Profile, "AudioCodecProfile", applyCondition, item); + applyConditions = false; + break; + } + } + + if (applyConditions) + { + foreach (ProfileCondition c in i.Conditions) + { + audioTranscodingConditions.Add(c); + } } } @@ -271,7 +312,7 @@ namespace MediaBrowser.Model.Dlna if (directPlayProfile != null) { // While options takes the network and other factors into account. Only applies to direct stream - if (item.SupportsDirectStream && IsAudioEligibleForDirectPlay(item, options.GetMaxBitrate())) + if (item.SupportsDirectStream && IsAudioEligibleForDirectPlay(item, options.GetMaxBitrate()) && options.EnableDirectStream) { playMethods.Add(PlayMethod.DirectStream); } @@ -279,7 +320,7 @@ namespace MediaBrowser.Model.Dlna // The profile describes what the device supports // If device requirements are satisfied then allow both direct stream and direct play if (item.SupportsDirectPlay && - IsAudioEligibleForDirectPlay(item, GetBitrateForDirectPlayCheck(item, options))) + IsAudioEligibleForDirectPlay(item, GetBitrateForDirectPlayCheck(item, options)) && options.EnableDirectPlay) { playMethods.Add(PlayMethod.DirectPlay); } @@ -362,8 +403,8 @@ namespace MediaBrowser.Model.Dlna MediaStream videoStream = item.VideoStream; // TODO: This doesn't accout for situation of device being able to handle media bitrate, but wifi connection not fast enough - bool isEligibleForDirectPlay = IsEligibleForDirectPlay(item, GetBitrateForDirectPlayCheck(item, options), subtitleStream, options, PlayMethod.DirectPlay); - bool isEligibleForDirectStream = IsEligibleForDirectPlay(item, options.GetMaxBitrate(), subtitleStream, options, PlayMethod.DirectStream); + bool isEligibleForDirectPlay = options.EnableDirectPlay && (options.ForceDirectPlay || IsEligibleForDirectPlay(item, GetBitrateForDirectPlayCheck(item, options), subtitleStream, options, PlayMethod.DirectPlay)); + bool isEligibleForDirectStream = options.EnableDirectStream && (options.ForceDirectStream || IsEligibleForDirectPlay(item, options.GetMaxBitrate(), subtitleStream, options, PlayMethod.DirectStream)); _logger.Info("Profile: {0}, Path: {1}, isEligibleForDirectPlay: {2}, isEligibleForDirectStream: {3}", options.Profile.Name ?? "Unknown Profile", @@ -374,7 +415,7 @@ namespace MediaBrowser.Model.Dlna if (isEligibleForDirectPlay || isEligibleForDirectStream) { // See if it can be direct played - PlayMethod? directPlay = GetVideoDirectPlayProfile(options.Profile, item, videoStream, audioStream, isEligibleForDirectPlay, isEligibleForDirectStream); + PlayMethod? directPlay = GetVideoDirectPlayProfile(options, item, videoStream, audioStream, isEligibleForDirectPlay, isEligibleForDirectStream); if (directPlay != null) { @@ -383,7 +424,7 @@ namespace MediaBrowser.Model.Dlna if (subtitleStream != null) { - SubtitleProfile subtitleProfile = GetSubtitleProfile(subtitleStream, options.Profile.SubtitleProfiles, options.Context, directPlay.Value); + SubtitleProfile subtitleProfile = GetSubtitleProfile(subtitleStream, options.Profile.SubtitleProfiles, directPlay.Value); playlistItem.SubtitleDeliveryMethod = subtitleProfile.Method; playlistItem.SubtitleFormat = subtitleProfile.Format; @@ -413,7 +454,7 @@ namespace MediaBrowser.Model.Dlna if (subtitleStream != null) { - SubtitleProfile subtitleProfile = GetSubtitleProfile(subtitleStream, options.Profile.SubtitleProfiles, options.Context, PlayMethod.Transcode); + SubtitleProfile subtitleProfile = GetSubtitleProfile(subtitleStream, options.Profile.SubtitleProfiles, PlayMethod.Transcode); playlistItem.SubtitleDeliveryMethod = subtitleProfile.Method; playlistItem.SubtitleFormat = subtitleProfile.Format; @@ -424,38 +465,54 @@ namespace MediaBrowser.Model.Dlna playlistItem.EstimateContentLength = transcodingProfile.EstimateContentLength; playlistItem.TranscodeSeekInfo = transcodingProfile.TranscodeSeekInfo; - // TODO: We should probably preserve the full list and sent it tp the server that way - string[] supportedAudioCodecs = transcodingProfile.AudioCodec.Split(','); - string inputAudioCodec = audioStream == null ? null : audioStream.Codec; - foreach (string supportedAudioCodec in supportedAudioCodecs) + playlistItem.AudioCodecs = transcodingProfile.AudioCodec.Split(','); + + playlistItem.VideoCodec = transcodingProfile.VideoCodec; + playlistItem.CopyTimestamps = transcodingProfile.CopyTimestamps; + playlistItem.ForceLiveStream = transcodingProfile.ForceLiveStream; + playlistItem.EnableSubtitlesInManifest = transcodingProfile.EnableSubtitlesInManifest; + + if (!string.IsNullOrEmpty(transcodingProfile.MaxAudioChannels)) { - if (StringHelper.EqualsIgnoreCase(supportedAudioCodec, inputAudioCodec)) + int transcodingMaxAudioChannels; + if (IntHelper.TryParseCultureInvariant(transcodingProfile.MaxAudioChannels, out transcodingMaxAudioChannels)) { - playlistItem.AudioCodec = supportedAudioCodec; - break; + playlistItem.TranscodingMaxAudioChannels = transcodingMaxAudioChannels; } } - - if (string.IsNullOrEmpty(playlistItem.AudioCodec)) - { - playlistItem.AudioCodec = supportedAudioCodecs[0]; - } - - playlistItem.VideoCodec = transcodingProfile.VideoCodec; - playlistItem.CopyTimestamps = transcodingProfile.CopyTimestamps; playlistItem.SubProtocol = transcodingProfile.Protocol; playlistItem.AudioStreamIndex = audioStreamIndex; + ConditionProcessor conditionProcessor = new ConditionProcessor(); List<ProfileCondition> videoTranscodingConditions = new List<ProfileCondition>(); foreach (CodecProfile i in options.Profile.CodecProfiles) { if (i.Type == CodecType.Video && i.ContainsCodec(transcodingProfile.VideoCodec, transcodingProfile.Container)) { - foreach (ProfileCondition c in i.Conditions) + bool applyConditions = true; + foreach (ProfileCondition applyCondition in i.ApplyConditions) { - videoTranscodingConditions.Add(c); + bool? isSecondaryAudio = audioStream == null ? null : item.IsSecondaryAudio(audioStream); + int? inputAudioBitrate = audioStream == null ? null : audioStream.BitRate; + int? audioChannels = audioStream == null ? null : audioStream.Channels; + string audioProfile = audioStream == null ? null : audioStream.Profile; + + if (!conditionProcessor.IsVideoAudioConditionSatisfied(applyCondition, audioChannels, inputAudioBitrate, audioProfile, isSecondaryAudio)) + { + LogConditionFailure(options.Profile, "AudioCodecProfile", applyCondition, item); + applyConditions = false; + break; + } + } + + if (applyConditions) + { + foreach (ProfileCondition c in i.Conditions) + { + videoTranscodingConditions.Add(c); + } + break; } - break; } } ApplyTranscodingConditions(playlistItem, videoTranscodingConditions); @@ -463,13 +520,44 @@ namespace MediaBrowser.Model.Dlna List<ProfileCondition> audioTranscodingConditions = new List<ProfileCondition>(); foreach (CodecProfile i in options.Profile.CodecProfiles) { - if (i.Type == CodecType.VideoAudio && i.ContainsCodec(playlistItem.AudioCodec, transcodingProfile.Container)) + if (i.Type == CodecType.VideoAudio && i.ContainsCodec(playlistItem.TargetAudioCodec, transcodingProfile.Container)) { - foreach (ProfileCondition c in i.Conditions) + bool applyConditions = true; + foreach (ProfileCondition applyCondition in i.ApplyConditions) { - audioTranscodingConditions.Add(c); + int? width = videoStream == null ? null : videoStream.Width; + int? height = videoStream == null ? null : videoStream.Height; + int? bitDepth = videoStream == null ? null : videoStream.BitDepth; + int? videoBitrate = videoStream == null ? null : videoStream.BitRate; + double? videoLevel = videoStream == null ? null : videoStream.Level; + string videoProfile = videoStream == null ? null : videoStream.Profile; + float? videoFramerate = videoStream == null ? null : videoStream.AverageFrameRate ?? videoStream.AverageFrameRate; + bool? isAnamorphic = videoStream == null ? null : videoStream.IsAnamorphic; + string videoCodecTag = videoStream == null ? null : videoStream.CodecTag; + + TransportStreamTimestamp? timestamp = videoStream == null ? TransportStreamTimestamp.None : item.Timestamp; + int? packetLength = videoStream == null ? null : videoStream.PacketLength; + int? refFrames = videoStream == null ? null : videoStream.RefFrames; + + int? numAudioStreams = item.GetStreamCount(MediaStreamType.Audio); + int? numVideoStreams = item.GetStreamCount(MediaStreamType.Video); + + if (!conditionProcessor.IsVideoConditionSatisfied(applyCondition, width, height, bitDepth, videoBitrate, videoProfile, videoLevel, videoFramerate, packetLength, timestamp, isAnamorphic, refFrames, numVideoStreams, numAudioStreams, videoCodecTag)) + { + LogConditionFailure(options.Profile, "VideoCodecProfile", applyCondition, item); + applyConditions = false; + break; + } + } + + if (applyConditions) + { + foreach (ProfileCondition c in i.Conditions) + { + audioTranscodingConditions.Add(c); + } + break; } - break; } } ApplyTranscodingConditions(playlistItem, audioTranscodingConditions); @@ -508,12 +596,23 @@ namespace MediaBrowser.Model.Dlna private int GetAudioBitrate(int? maxTotalBitrate, int? targetAudioChannels, string targetAudioCodec, MediaStream audioStream) { var defaultBitrate = 128000; + if (StringHelper.EqualsIgnoreCase(targetAudioCodec, "ac3")) + { + defaultBitrate = 192000; + } if (targetAudioChannels.HasValue) { if (targetAudioChannels.Value >= 5 && (maxTotalBitrate ?? 0) >= 2000000) { - defaultBitrate = 320000; + if (StringHelper.EqualsIgnoreCase(targetAudioCodec, "ac3")) + { + defaultBitrate = 448000; + } + else + { + defaultBitrate = 320000; + } } } @@ -536,13 +635,24 @@ namespace MediaBrowser.Model.Dlna return Math.Min(defaultBitrate, encoderAudioBitrateLimit); } - private PlayMethod? GetVideoDirectPlayProfile(DeviceProfile profile, + private PlayMethod? GetVideoDirectPlayProfile(VideoOptions options, MediaSourceInfo mediaSource, MediaStream videoStream, MediaStream audioStream, bool isEligibleForDirectPlay, bool isEligibleForDirectStream) { + DeviceProfile profile = options.Profile; + + if (options.ForceDirectPlay) + { + return PlayMethod.DirectPlay; + } + if (options.ForceDirectStream) + { + return PlayMethod.DirectStream; + } + if (videoStream == null) { _logger.Info("Profile: {0}, Cannot direct stream with no known video stream. Path: {1}", @@ -597,7 +707,6 @@ namespace MediaBrowser.Model.Dlna string videoProfile = videoStream == null ? null : videoStream.Profile; float? videoFramerate = videoStream == null ? null : videoStream.AverageFrameRate ?? videoStream.AverageFrameRate; bool? isAnamorphic = videoStream == null ? null : videoStream.IsAnamorphic; - bool? isCabac = videoStream == null ? null : videoStream.IsCabac; string videoCodecTag = videoStream == null ? null : videoStream.CodecTag; int? audioBitrate = audioStream == null ? null : audioStream.BitRate; @@ -614,7 +723,7 @@ namespace MediaBrowser.Model.Dlna // Check container conditions foreach (ProfileCondition i in conditions) { - if (!conditionProcessor.IsVideoConditionSatisfied(i, width, height, bitDepth, videoBitrate, videoProfile, videoLevel, videoFramerate, packetLength, timestamp, isAnamorphic, isCabac, refFrames, numVideoStreams, numAudioStreams, videoCodecTag)) + if (!conditionProcessor.IsVideoConditionSatisfied(i, width, height, bitDepth, videoBitrate, videoProfile, videoLevel, videoFramerate, packetLength, timestamp, isAnamorphic, refFrames, numVideoStreams, numAudioStreams, videoCodecTag)) { LogConditionFailure(profile, "VideoContainerProfile", i, mediaSource); @@ -638,16 +747,30 @@ namespace MediaBrowser.Model.Dlna { if (i.Type == CodecType.Video && i.ContainsCodec(videoCodec, container)) { - foreach (ProfileCondition c in i.Conditions) + bool applyConditions = true; + foreach (ProfileCondition applyCondition in i.ApplyConditions) { - conditions.Add(c); + if (!conditionProcessor.IsVideoConditionSatisfied(applyCondition, width, height, bitDepth, videoBitrate, videoProfile, videoLevel, videoFramerate, packetLength, timestamp, isAnamorphic, refFrames, numVideoStreams, numAudioStreams, videoCodecTag)) + { + LogConditionFailure(profile, "VideoCodecProfile", applyCondition, mediaSource); + applyConditions = false; + break; + } + } + + if (applyConditions) + { + foreach (ProfileCondition c in i.Conditions) + { + conditions.Add(c); + } } } } foreach (ProfileCondition i in conditions) { - if (!conditionProcessor.IsVideoConditionSatisfied(i, width, height, bitDepth, videoBitrate, videoProfile, videoLevel, videoFramerate, packetLength, timestamp, isAnamorphic, isCabac, refFrames, numVideoStreams, numAudioStreams, videoCodecTag)) + if (!conditionProcessor.IsVideoConditionSatisfied(i, width, height, bitDepth, videoBitrate, videoProfile, videoLevel, videoFramerate, packetLength, timestamp, isAnamorphic, refFrames, numVideoStreams, numAudioStreams, videoCodecTag)) { LogConditionFailure(profile, "VideoCodecProfile", i, mediaSource); @@ -669,20 +792,35 @@ namespace MediaBrowser.Model.Dlna } conditions = new List<ProfileCondition>(); + bool? isSecondaryAudio = audioStream == null ? null : mediaSource.IsSecondaryAudio(audioStream); + foreach (CodecProfile i in profile.CodecProfiles) { if (i.Type == CodecType.VideoAudio && i.ContainsCodec(audioCodec, container)) { - foreach (ProfileCondition c in i.Conditions) + bool applyConditions = true; + foreach (ProfileCondition applyCondition in i.ApplyConditions) { - conditions.Add(c); + if (!conditionProcessor.IsVideoAudioConditionSatisfied(applyCondition, audioChannels, audioBitrate, audioProfile, isSecondaryAudio)) + { + LogConditionFailure(profile, "VideoAudioCodecProfile", applyCondition, mediaSource); + applyConditions = false; + break; + } + } + + if (applyConditions) + { + foreach (ProfileCondition c in i.Conditions) + { + conditions.Add(c); + } } } } foreach (ProfileCondition i in conditions) { - bool? isSecondaryAudio = audioStream == null ? null : mediaSource.IsSecondaryAudio(audioStream); if (!conditionProcessor.IsVideoAudioConditionSatisfied(i, audioChannels, audioBitrate, audioProfile, isSecondaryAudio)) { LogConditionFailure(profile, "VideoAudioCodecProfile", i, mediaSource); @@ -692,25 +830,6 @@ namespace MediaBrowser.Model.Dlna } } - if (isEligibleForDirectPlay && mediaSource.SupportsDirectPlay) - { - if (mediaSource.Protocol == MediaProtocol.Http) - { - if (_localPlayer.CanAccessUrl(mediaSource.Path, mediaSource.RequiredHttpHeaders.Count > 0)) - { - return PlayMethod.DirectPlay; - } - } - - else if (mediaSource.Protocol == MediaProtocol.File) - { - if (_localPlayer.CanAccessFile(mediaSource.Path)) - { - return PlayMethod.DirectPlay; - } - } - } - if (isEligibleForDirectStream && mediaSource.SupportsDirectStream) { return PlayMethod.DirectStream; @@ -739,7 +858,7 @@ namespace MediaBrowser.Model.Dlna { if (subtitleStream != null) { - SubtitleProfile subtitleProfile = GetSubtitleProfile(subtitleStream, options.Profile.SubtitleProfiles, options.Context, playMethod); + SubtitleProfile subtitleProfile = GetSubtitleProfile(subtitleStream, options.Profile.SubtitleProfiles, playMethod); if (subtitleProfile.Method != SubtitleDeliveryMethod.External && subtitleProfile.Method != SubtitleDeliveryMethod.Embed) { @@ -751,7 +870,7 @@ namespace MediaBrowser.Model.Dlna return IsAudioEligibleForDirectPlay(item, maxBitrate); } - public static SubtitleProfile GetSubtitleProfile(MediaStream subtitleStream, SubtitleProfile[] subtitleProfiles, EncodingContext context, PlayMethod playMethod) + public static SubtitleProfile GetSubtitleProfile(MediaStream subtitleStream, SubtitleProfile[] subtitleProfiles, PlayMethod playMethod) { if (playMethod != PlayMethod.Transcode && !subtitleStream.IsExternal) { @@ -775,7 +894,16 @@ namespace MediaBrowser.Model.Dlna } } - // Look for an external profile that matches the stream type (text/graphical) + // Look for an external or hls profile that matches the stream type (text/graphical) and doesn't require conversion + return GetExternalSubtitleProfile(subtitleStream, subtitleProfiles, playMethod, false) ?? GetExternalSubtitleProfile(subtitleStream, subtitleProfiles, playMethod, true) ?? new SubtitleProfile + { + Method = SubtitleDeliveryMethod.Encode, + Format = subtitleStream.Codec + }; + } + + private static SubtitleProfile GetExternalSubtitleProfile(MediaStream subtitleStream, SubtitleProfile[] subtitleProfiles, PlayMethod playMethod, bool allowConversion) + { foreach (SubtitleProfile profile in subtitleProfiles) { if (profile.Method != SubtitleDeliveryMethod.External && profile.Method != SubtitleDeliveryMethod.Hls) @@ -798,32 +926,47 @@ namespace MediaBrowser.Model.Dlna { bool requiresConversion = !StringHelper.EqualsIgnoreCase(subtitleStream.Codec, profile.Format); - if (subtitleStream.IsTextSubtitleStream || !requiresConversion) + if (!requiresConversion) { - if (subtitleStream.SupportsExternalStream) - { - return profile; - } + return profile; + } + + if (!allowConversion) + { + continue; + } + + if (subtitleStream.IsTextSubtitleStream && subtitleStream.SupportsExternalStream && subtitleStream.SupportsSubtitleConversionTo(profile.Format)) + { + return profile; } } } - return new SubtitleProfile - { - Method = SubtitleDeliveryMethod.Encode, - Format = subtitleStream.Codec - }; + return null; } private bool IsAudioEligibleForDirectPlay(MediaSourceInfo item, int? maxBitrate) { - if (!maxBitrate.HasValue || (item.Bitrate.HasValue && item.Bitrate.Value <= maxBitrate.Value)) + if (!maxBitrate.HasValue) + { + _logger.Info("Cannot direct play due to unknown supported bitrate"); + return false; + } + + if (!item.Bitrate.HasValue) + { + _logger.Info("Cannot direct play due to unknown content bitrate"); + return false; + } + + if (item.Bitrate.Value > maxBitrate.Value) { - return true; + _logger.Info("Bitrate exceeds DirectPlay limit"); + return false; } - _logger.Info("Bitrate exceeds DirectPlay limit"); - return false; + return true; } private void ValidateInput(VideoOptions options) @@ -898,22 +1041,6 @@ namespace MediaBrowser.Model.Dlna } break; } - case ProfileConditionValue.IsCabac: - { - bool val; - if (BoolHelper.TryParseCultureInvariant(value, out val)) - { - if (condition.Condition == ProfileConditionType.Equals) - { - item.Cabac = val; - } - else if (condition.Condition == ProfileConditionType.NotEquals) - { - item.Cabac = !val; - } - } - break; - } case ProfileConditionValue.IsAnamorphic: case ProfileConditionValue.AudioProfile: case ProfileConditionValue.Has64BitOffsets: @@ -1019,6 +1146,18 @@ namespace MediaBrowser.Model.Dlna } } + // Check audio codec + List<string> audioCodecs = profile.GetAudioCodecs(); + if (audioCodecs.Count > 0) + { + // Check audio codecs + string audioCodec = audioStream == null ? null : audioStream.Codec; + if (string.IsNullOrEmpty(audioCodec) || !ListHelper.ContainsIgnoreCase(audioCodecs, audioCodec)) + { + return false; + } + } + return true; } @@ -1054,6 +1193,7 @@ namespace MediaBrowser.Model.Dlna } } + // Check audio codec List<string> audioCodecs = profile.GetAudioCodecs(); if (audioCodecs.Count > 0) { |
