jellyfin-server/MediaBrowser.Model/Dlna/StreamBuilder.cs

679 lines
25 KiB
C#
Raw Normal View History

2014-04-02 21:55:19 +00:00
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
2014-04-30 15:07:02 +00:00
using MediaBrowser.Model.MediaInfo;
2014-04-02 21:55:19 +00:00
using System;
using System.Collections.Generic;
2014-04-01 22:23:07 +00:00
using System.Globalization;
using System.Linq;
namespace MediaBrowser.Model.Dlna
{
public class StreamBuilder
{
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
public StreamInfo BuildAudioItem(AudioOptions options)
{
ValidateAudioInput(options);
2014-04-03 22:50:04 +00:00
2014-05-08 20:09:53 +00:00
List<MediaSourceInfo> mediaSources = options.MediaSources;
2014-04-01 22:23:07 +00:00
// If the client wants a specific media soure, filter now
if (!string.IsNullOrEmpty(options.MediaSourceId))
{
// Avoid implicitly captured closure
2014-05-08 20:09:53 +00:00
string mediaSourceId = options.MediaSourceId;
2014-04-01 22:23:07 +00:00
2014-05-08 21:23:24 +00:00
mediaSources = new List<MediaSourceInfo>();
foreach (MediaSourceInfo i in mediaSources)
{
2014-05-09 19:43:06 +00:00
if (string.Equals(i.Id, mediaSourceId, StringComparison.OrdinalIgnoreCase))
2014-05-08 21:23:24 +00:00
mediaSources.Add(i);
}
2014-04-01 22:23:07 +00:00
}
2014-05-08 21:23:24 +00:00
List<StreamInfo> streams = new List<StreamInfo>();
foreach (MediaSourceInfo i in mediaSources)
streams.Add(BuildAudioItem(i, options));
2014-04-01 22:23:07 +00:00
2014-05-08 20:09:53 +00:00
foreach (StreamInfo stream in streams)
2014-04-01 22:23:07 +00:00
{
stream.DeviceId = options.DeviceId;
stream.DeviceProfileId = options.Profile.Id;
}
return GetOptimalStream(streams);
}
public StreamInfo BuildVideoItem(VideoOptions options)
{
ValidateInput(options);
2014-05-08 20:09:53 +00:00
List<MediaSourceInfo> mediaSources = options.MediaSources;
2014-04-01 22:23:07 +00:00
// If the client wants a specific media soure, filter now
if (!string.IsNullOrEmpty(options.MediaSourceId))
{
// Avoid implicitly captured closure
2014-05-08 20:09:53 +00:00
string mediaSourceId = options.MediaSourceId;
2014-04-01 22:23:07 +00:00
2014-05-08 21:23:24 +00:00
mediaSources = new List<MediaSourceInfo>();
foreach (MediaSourceInfo i in mediaSources)
{
2014-05-09 19:43:06 +00:00
if (string.Equals(i.Id, mediaSourceId, StringComparison.OrdinalIgnoreCase))
2014-05-08 21:23:24 +00:00
mediaSources.Add(i);
}
2014-04-01 22:23:07 +00:00
}
2014-05-08 21:23:24 +00:00
List<StreamInfo> streams = new List<StreamInfo>();
foreach (MediaSourceInfo i in mediaSources)
streams.Add(BuildVideoItem(i, options));
2014-04-01 22:23:07 +00:00
2014-05-08 20:09:53 +00:00
foreach (StreamInfo stream in streams)
2014-04-01 22:23:07 +00:00
{
stream.DeviceId = options.DeviceId;
stream.DeviceProfileId = options.Profile.Id;
}
return GetOptimalStream(streams);
}
private StreamInfo GetOptimalStream(List<StreamInfo> streams)
{
// Grab the first one that can be direct streamed
// If that doesn't produce anything, just take the first
2014-05-08 21:23:24 +00:00
foreach (StreamInfo i in streams)
{
if (i.IsDirectStream)
{
return i;
}
}
foreach (StreamInfo stream in streams)
{
return stream;
}
return null;
2014-04-01 22:23:07 +00:00
}
2014-04-06 17:53:23 +00:00
private StreamInfo BuildAudioItem(MediaSourceInfo item, AudioOptions options)
2014-04-01 22:23:07 +00:00
{
2014-05-08 20:09:53 +00:00
StreamInfo playlistItem = new StreamInfo
2014-04-01 22:23:07 +00:00
{
2014-04-06 17:53:23 +00:00
ItemId = options.ItemId,
2014-04-01 22:23:07 +00:00
MediaType = DlnaProfileType.Audio,
2014-04-18 17:16:25 +00:00
MediaSource = item,
2014-04-18 05:03:01 +00:00
RunTimeTicks = item.RunTimeTicks
2014-04-01 22:23:07 +00:00
};
2014-05-08 20:09:53 +00:00
int? maxBitrateSetting = options.MaxBitrate ?? options.Profile.MaxBitrate;
2014-05-09 19:43:06 +00:00
MediaStream audioStream = null;
foreach (MediaStream i in item.MediaStreams)
{
if (i.Type == MediaStreamType.Audio)
{
audioStream = i;
break;
}
}
2014-04-01 22:23:07 +00:00
2014-04-06 17:53:23 +00:00
// Honor the max bitrate setting
if (IsAudioEligibleForDirectPlay(item, maxBitrateSetting))
2014-04-01 22:23:07 +00:00
{
2014-05-09 19:43:06 +00:00
DirectPlayProfile directPlay = null;
foreach (DirectPlayProfile i in options.Profile.DirectPlayProfiles)
{
if (i.Type == playlistItem.MediaType && IsAudioDirectPlaySupported(i, item, audioStream))
{
directPlay = i;
break;
}
}
2014-04-01 22:23:07 +00:00
2014-04-06 17:53:23 +00:00
if (directPlay != null)
2014-04-01 22:23:07 +00:00
{
2014-05-08 20:09:53 +00:00
string audioCodec = audioStream == null ? null : audioStream.Codec;
2014-04-06 17:53:23 +00:00
// Make sure audio codec profiles are satisfied
2014-04-24 05:08:10 +00:00
if (!string.IsNullOrEmpty(audioCodec))
2014-04-06 17:53:23 +00:00
{
2014-05-08 20:09:53 +00:00
ConditionProcessor conditionProcessor = new ConditionProcessor();
2014-04-01 22:23:07 +00:00
2014-05-09 19:43:06 +00:00
List<ProfileCondition> conditions = new List<ProfileCondition>();
foreach (CodecProfile i in options.Profile.CodecProfiles)
{
if (i.Type == CodecType.Audio && i.ContainsCodec(audioCodec))
conditions.AddRange(i.Conditions);
}
2014-04-24 05:08:10 +00:00
2014-05-08 20:09:53 +00:00
int? audioChannels = audioStream.Channels;
int? audioBitrate = audioStream.BitRate;
2014-04-24 05:08:10 +00:00
2014-05-09 19:43:06 +00:00
bool all = true;
foreach (ProfileCondition c in conditions)
{
if (!conditionProcessor.IsAudioConditionSatisfied(c, audioChannels, audioBitrate))
{
all = false;
break;
}
}
if (all)
2014-04-24 05:08:10 +00:00
{
playlistItem.IsDirectStream = true;
playlistItem.Container = item.Container;
return playlistItem;
}
2014-04-06 17:53:23 +00:00
}
2014-04-01 22:23:07 +00:00
}
}
2014-05-09 19:43:06 +00:00
TranscodingProfile transcodingProfile = null;
foreach (TranscodingProfile i in options.Profile.TranscodingProfiles)
{
if (i.Type == playlistItem.MediaType)
{
transcodingProfile = i;
break;
}
}
2014-04-01 22:23:07 +00:00
if (transcodingProfile != null)
{
playlistItem.IsDirectStream = false;
2014-04-18 05:03:01 +00:00
playlistItem.TranscodeSeekInfo = transcodingProfile.TranscodeSeekInfo;
2014-04-18 17:16:25 +00:00
playlistItem.EstimateContentLength = transcodingProfile.EstimateContentLength;
2014-04-01 22:23:07 +00:00
playlistItem.Container = transcodingProfile.Container;
playlistItem.AudioCodec = transcodingProfile.AudioCodec;
playlistItem.Protocol = transcodingProfile.Protocol;
2014-04-01 22:23:07 +00:00
2014-05-09 19:43:06 +00:00
List<ProfileCondition> audioTranscodingConditions = options.Profile.CodecProfiles
2014-04-01 22:23:07 +00:00
.Where(i => i.Type == CodecType.Audio && i.ContainsCodec(transcodingProfile.AudioCodec))
.Take(1)
2014-05-09 19:43:06 +00:00
.SelectMany(i => i.Conditions)
.ToList();
2014-04-01 22:23:07 +00:00
ApplyTranscodingConditions(playlistItem, audioTranscodingConditions);
2014-04-06 17:53:23 +00:00
// Honor requested max channels
if (options.MaxAudioChannels.HasValue)
{
2014-05-08 20:09:53 +00:00
int currentValue = playlistItem.MaxAudioChannels ?? options.MaxAudioChannels.Value;
2014-04-06 17:53:23 +00:00
playlistItem.MaxAudioChannels = Math.Min(options.MaxAudioChannels.Value, currentValue);
}
// Honor requested max bitrate
if (maxBitrateSetting.HasValue)
2014-04-06 17:53:23 +00:00
{
2014-05-08 20:09:53 +00:00
int currentValue = playlistItem.AudioBitrate ?? maxBitrateSetting.Value;
2014-04-06 17:53:23 +00:00
playlistItem.AudioBitrate = Math.Min(maxBitrateSetting.Value, currentValue);
2014-04-06 17:53:23 +00:00
}
2014-04-01 22:23:07 +00:00
}
return playlistItem;
}
private StreamInfo BuildVideoItem(MediaSourceInfo item, VideoOptions options)
{
2014-05-08 20:09:53 +00:00
StreamInfo playlistItem = new StreamInfo
2014-04-01 22:23:07 +00:00
{
ItemId = options.ItemId,
MediaType = DlnaProfileType.Video,
2014-04-18 17:16:25 +00:00
MediaSource = item,
2014-04-18 05:03:01 +00:00
RunTimeTicks = item.RunTimeTicks
2014-04-01 22:23:07 +00:00
};
2014-05-09 19:43:06 +00:00
MediaStream audioStream = null;
foreach (MediaStream i in item.MediaStreams)
{
if (i.Type == MediaStreamType.Audio)
{
audioStream = i;
break;
}
}
MediaStream videoStream = null;
foreach (MediaStream i in item.MediaStreams)
{
if (i.Type == MediaStreamType.Video)
{
videoStream = i;
break;
}
}
2014-04-01 22:23:07 +00:00
2014-05-08 20:09:53 +00:00
int? maxBitrateSetting = options.MaxBitrate ?? options.Profile.MaxBitrate;
if (IsEligibleForDirectPlay(item, options, maxBitrateSetting))
2014-04-01 22:23:07 +00:00
{
// See if it can be direct played
2014-05-08 20:09:53 +00:00
DirectPlayProfile directPlay = GetVideoDirectPlayProfile(options.Profile, item, videoStream, audioStream);
2014-04-01 22:23:07 +00:00
if (directPlay != null)
{
2014-04-24 05:08:10 +00:00
playlistItem.IsDirectStream = true;
playlistItem.Container = item.Container;
2014-04-01 22:23:07 +00:00
2014-04-24 05:08:10 +00:00
return playlistItem;
2014-04-01 22:23:07 +00:00
}
}
// Can't direct play, find the transcoding profile
2014-05-08 21:23:24 +00:00
TranscodingProfile transcodingProfile = null;
foreach (TranscodingProfile i in options.Profile.TranscodingProfiles)
{
if (i.Type == playlistItem.MediaType)
{
transcodingProfile = i;
break;
}
}
2014-04-01 22:23:07 +00:00
if (transcodingProfile != null)
{
playlistItem.IsDirectStream = false;
playlistItem.Container = transcodingProfile.Container;
2014-04-18 17:16:25 +00:00
playlistItem.EstimateContentLength = transcodingProfile.EstimateContentLength;
2014-04-18 05:03:01 +00:00
playlistItem.TranscodeSeekInfo = transcodingProfile.TranscodeSeekInfo;
2014-05-08 21:23:24 +00:00
playlistItem.AudioCodec = transcodingProfile.AudioCodec.Split(',')[0];
2014-04-01 22:23:07 +00:00
playlistItem.VideoCodec = transcodingProfile.VideoCodec;
playlistItem.Protocol = transcodingProfile.Protocol;
2014-05-03 05:54:14 +00:00
playlistItem.AudioStreamIndex = options.AudioStreamIndex;
playlistItem.SubtitleStreamIndex = options.SubtitleStreamIndex;
2014-04-01 22:23:07 +00:00
2014-05-08 20:09:53 +00:00
IEnumerable<ProfileCondition> videoTranscodingConditions = options.Profile.CodecProfiles
2014-04-01 22:23:07 +00:00
.Where(i => i.Type == CodecType.Video && i.ContainsCodec(transcodingProfile.VideoCodec))
.Take(1)
.SelectMany(i => i.Conditions);
ApplyTranscodingConditions(playlistItem, videoTranscodingConditions);
2014-05-08 20:09:53 +00:00
IEnumerable<ProfileCondition> audioTranscodingConditions = options.Profile.CodecProfiles
2014-04-01 22:23:07 +00:00
.Where(i => i.Type == CodecType.VideoAudio && i.ContainsCodec(transcodingProfile.AudioCodec))
.Take(1)
.SelectMany(i => i.Conditions);
ApplyTranscodingConditions(playlistItem, audioTranscodingConditions);
2014-04-06 17:53:23 +00:00
// Honor requested max channels
if (options.MaxAudioChannels.HasValue)
{
2014-05-08 20:09:53 +00:00
int currentValue = playlistItem.MaxAudioChannels ?? options.MaxAudioChannels.Value;
2014-04-06 17:53:23 +00:00
playlistItem.MaxAudioChannels = Math.Min(options.MaxAudioChannels.Value, currentValue);
}
// Honor requested max bitrate
if (options.MaxAudioTranscodingBitrate.HasValue)
{
2014-05-08 20:09:53 +00:00
int currentValue = playlistItem.AudioBitrate ?? options.MaxAudioTranscodingBitrate.Value;
2014-04-06 17:53:23 +00:00
playlistItem.AudioBitrate = Math.Min(options.MaxAudioTranscodingBitrate.Value, currentValue);
}
// Honor max rate
if (maxBitrateSetting.HasValue)
2014-04-06 17:53:23 +00:00
{
2014-05-08 20:09:53 +00:00
int videoBitrate = maxBitrateSetting.Value;
2014-04-06 17:53:23 +00:00
if (playlistItem.AudioBitrate.HasValue)
{
videoBitrate -= playlistItem.AudioBitrate.Value;
}
2014-05-08 20:09:53 +00:00
int currentValue = playlistItem.VideoBitrate ?? videoBitrate;
2014-04-06 17:53:23 +00:00
playlistItem.VideoBitrate = Math.Min(videoBitrate, currentValue);
}
2014-04-01 22:23:07 +00:00
}
return playlistItem;
}
2014-04-24 05:08:10 +00:00
private DirectPlayProfile GetVideoDirectPlayProfile(DeviceProfile profile,
MediaSourceInfo mediaSource,
MediaStream videoStream,
MediaStream audioStream)
{
// See if it can be direct played
2014-05-08 21:23:24 +00:00
DirectPlayProfile directPlay = null;
foreach (DirectPlayProfile i in profile.DirectPlayProfiles)
{
if (i.Type == DlnaProfileType.Video && IsVideoDirectPlaySupported(i, mediaSource, videoStream, audioStream))
{
directPlay = i;
break;
}
}
2014-04-24 05:08:10 +00:00
if (directPlay == null)
{
return null;
}
2014-05-08 20:09:53 +00:00
string container = mediaSource.Container;
2014-04-24 05:08:10 +00:00
2014-05-09 19:43:06 +00:00
List<ProfileCondition> conditions = new List<ProfileCondition>();
foreach (ContainerProfile i in profile.ContainerProfiles)
{
if (i.Type == DlnaProfileType.Video &&
i.GetContainers().Contains(container, StringComparer.OrdinalIgnoreCase))
{
conditions.AddRange(i.Conditions);
}
}
2014-04-24 05:08:10 +00:00
2014-05-08 20:09:53 +00:00
ConditionProcessor conditionProcessor = new ConditionProcessor();
2014-04-24 05:08:10 +00:00
2014-05-08 20:09:53 +00:00
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;
2014-04-24 05:08:10 +00:00
2014-05-08 20:09:53 +00:00
int? audioBitrate = audioStream == null ? null : audioStream.BitRate;
int? audioChannels = audioStream == null ? null : audioStream.Channels;
string audioProfile = audioStream == null ? null : audioStream.Profile;
2014-04-24 05:08:10 +00:00
2014-05-08 20:09:53 +00:00
TransportStreamTimestamp? timestamp = videoStream == null ? TransportStreamTimestamp.None : mediaSource.Timestamp;
int? packetLength = videoStream == null ? null : videoStream.PacketLength;
2014-04-24 05:08:10 +00:00
// Check container conditions
2014-05-09 19:43:06 +00:00
foreach (ProfileCondition i in conditions)
2014-04-24 05:08:10 +00:00
{
2014-05-09 19:43:06 +00:00
if (!conditionProcessor.IsVideoConditionSatisfied(i, audioBitrate, audioChannels, width, height, bitDepth, videoBitrate, videoProfile, videoLevel, videoFramerate, packetLength, timestamp))
{
return null;
}
2014-04-24 05:08:10 +00:00
}
2014-05-08 20:09:53 +00:00
string videoCodec = videoStream == null ? null : videoStream.Codec;
2014-04-24 05:08:10 +00:00
if (string.IsNullOrEmpty(videoCodec))
{
return null;
}
2014-05-09 19:43:06 +00:00
conditions = new List<ProfileCondition>();
foreach (CodecProfile i in profile.CodecProfiles)
{
if (i.Type == CodecType.Video && i.ContainsCodec(videoCodec))
conditions.AddRange(i.Conditions);
}
2014-04-24 05:08:10 +00:00
2014-05-09 19:43:06 +00:00
foreach (ProfileCondition i in conditions)
2014-04-24 05:08:10 +00:00
{
2014-05-09 19:43:06 +00:00
if (!conditionProcessor.IsVideoConditionSatisfied(i, audioBitrate, audioChannels, width, height, bitDepth, videoBitrate, videoProfile, videoLevel, videoFramerate, packetLength, timestamp))
{
return null;
}
2014-04-24 05:08:10 +00:00
}
if (audioStream != null)
{
2014-05-08 20:09:53 +00:00
string audioCodec = audioStream.Codec;
2014-04-24 05:08:10 +00:00
if (string.IsNullOrEmpty(audioCodec))
{
return null;
}
2014-05-09 19:43:06 +00:00
conditions = new List<ProfileCondition>();
foreach (CodecProfile i in profile.CodecProfiles)
{
if (i.Type == CodecType.VideoAudio && i.ContainsCodec(audioCodec))
conditions.AddRange(i.Conditions);
}
2014-04-24 05:08:10 +00:00
2014-05-09 19:43:06 +00:00
foreach (ProfileCondition i in conditions)
2014-04-24 05:08:10 +00:00
{
2014-05-09 19:43:06 +00:00
if (!conditionProcessor.IsVideoAudioConditionSatisfied(i, audioChannels, audioBitrate, audioProfile))
{
return null;
}
2014-04-24 05:08:10 +00:00
}
}
return directPlay;
}
private bool IsEligibleForDirectPlay(MediaSourceInfo item, VideoOptions options, int? maxBitrate)
2014-04-01 22:23:07 +00:00
{
if (options.SubtitleStreamIndex.HasValue)
{
return false;
}
2014-04-03 22:50:04 +00:00
if (options.AudioStreamIndex.HasValue &&
2014-04-01 22:23:07 +00:00
item.MediaStreams.Count(i => i.Type == MediaStreamType.Audio) > 1)
{
return false;
}
return IsAudioEligibleForDirectPlay(item, maxBitrate);
2014-04-06 17:53:23 +00:00
}
private bool IsAudioEligibleForDirectPlay(MediaSourceInfo item, int? maxBitrate)
2014-04-06 17:53:23 +00:00
{
// Honor the max bitrate setting
return !maxBitrate.HasValue || (item.Bitrate.HasValue && item.Bitrate.Value <= maxBitrate.Value);
2014-04-01 22:23:07 +00:00
}
private void ValidateInput(VideoOptions options)
{
ValidateAudioInput(options);
if (options.AudioStreamIndex.HasValue && string.IsNullOrEmpty(options.MediaSourceId))
{
throw new ArgumentException("MediaSourceId is required when a specific audio stream is requested");
}
if (options.SubtitleStreamIndex.HasValue && string.IsNullOrEmpty(options.MediaSourceId))
{
throw new ArgumentException("MediaSourceId is required when a specific subtitle stream is requested");
}
}
private void ValidateAudioInput(AudioOptions options)
{
if (string.IsNullOrEmpty(options.ItemId))
{
throw new ArgumentException("ItemId is required");
}
if (string.IsNullOrEmpty(options.DeviceId))
{
throw new ArgumentException("DeviceId is required");
}
if (options.Profile == null)
{
throw new ArgumentException("Profile is required");
}
if (options.MediaSources == null)
{
throw new ArgumentException("MediaSources is required");
}
}
private void ApplyTranscodingConditions(StreamInfo item, IEnumerable<ProfileCondition> conditions)
{
2014-05-09 19:43:06 +00:00
foreach (ProfileCondition condition in conditions)
2014-04-01 22:23:07 +00:00
{
2014-05-08 20:09:53 +00:00
string value = condition.Value;
2014-04-01 22:23:07 +00:00
2014-05-09 19:43:06 +00:00
if (string.IsNullOrEmpty(value))
{
continue;
}
2014-04-01 22:23:07 +00:00
switch (condition.Property)
{
case ProfileConditionValue.AudioBitrate:
{
int num;
if (int.TryParse(value, NumberStyles.Any, _usCulture, out num))
{
item.AudioBitrate = num;
}
break;
}
case ProfileConditionValue.AudioChannels:
{
int num;
if (int.TryParse(value, NumberStyles.Any, _usCulture, out num))
{
item.MaxAudioChannels = num;
}
break;
}
case ProfileConditionValue.AudioProfile:
case ProfileConditionValue.Has64BitOffsets:
2014-04-24 05:08:10 +00:00
case ProfileConditionValue.PacketLength:
case ProfileConditionValue.VideoTimestamp:
2014-04-01 22:23:07 +00:00
case ProfileConditionValue.VideoBitDepth:
{
// Not supported yet
break;
}
2014-04-24 05:08:10 +00:00
case ProfileConditionValue.VideoProfile:
{
item.VideoProfile = value;
break;
}
2014-04-01 22:23:07 +00:00
case ProfileConditionValue.Height:
{
int num;
if (int.TryParse(value, NumberStyles.Any, _usCulture, out num))
{
item.MaxHeight = num;
}
break;
}
case ProfileConditionValue.VideoBitrate:
{
int num;
if (int.TryParse(value, NumberStyles.Any, _usCulture, out num))
{
item.VideoBitrate = num;
}
break;
}
case ProfileConditionValue.VideoFramerate:
{
int num;
if (int.TryParse(value, NumberStyles.Any, _usCulture, out num))
{
item.MaxFramerate = num;
}
break;
}
case ProfileConditionValue.VideoLevel:
{
int num;
if (int.TryParse(value, NumberStyles.Any, _usCulture, out num))
{
item.VideoLevel = num;
}
break;
}
case ProfileConditionValue.Width:
{
int num;
if (int.TryParse(value, NumberStyles.Any, _usCulture, out num))
{
item.MaxWidth = num;
}
break;
}
default:
throw new ArgumentException("Unrecognized ProfileConditionValue");
}
}
}
2014-04-06 17:53:23 +00:00
private bool IsAudioDirectPlaySupported(DirectPlayProfile profile, MediaSourceInfo item, MediaStream audioStream)
2014-04-01 22:23:07 +00:00
{
if (profile.Container.Length > 0)
{
// Check container type
2014-05-08 20:09:53 +00:00
string mediaContainer = item.Container ?? string.Empty;
2014-05-09 19:43:06 +00:00
bool any = false;
foreach (string i in profile.GetContainers())
{
if (string.Equals(i, mediaContainer, StringComparison.OrdinalIgnoreCase))
{
any = true;
break;
}
}
if (!any)
2014-04-01 22:23:07 +00:00
{
return false;
}
}
return true;
}
2014-04-06 17:53:23 +00:00
private bool IsVideoDirectPlaySupported(DirectPlayProfile profile, MediaSourceInfo item, MediaStream videoStream, MediaStream audioStream)
2014-04-01 22:23:07 +00:00
{
// Only plain video files can be direct played
if (item.VideoType != VideoType.VideoFile)
{
return false;
}
if (profile.Container.Length > 0)
{
// Check container type
2014-05-08 20:09:53 +00:00
string mediaContainer = item.Container ?? string.Empty;
2014-05-09 19:43:06 +00:00
bool any = false;
foreach (string i in profile.GetContainers())
{
if (string.Equals(i, mediaContainer, StringComparison.OrdinalIgnoreCase))
{
any = true;
break;
}
}
if (!any)
2014-04-01 22:23:07 +00:00
{
return false;
}
}
// Check video codec
2014-05-08 20:09:53 +00:00
List<string> videoCodecs = profile.GetVideoCodecs();
2014-04-01 22:23:07 +00:00
if (videoCodecs.Count > 0)
{
2014-05-08 20:09:53 +00:00
string videoCodec = videoStream == null ? null : videoStream.Codec;
2014-04-01 22:23:07 +00:00
if (string.IsNullOrEmpty(videoCodec) || !videoCodecs.Contains(videoCodec, StringComparer.OrdinalIgnoreCase))
{
return false;
}
}
2014-05-08 20:09:53 +00:00
List<string> audioCodecs = profile.GetAudioCodecs();
2014-04-01 22:23:07 +00:00
if (audioCodecs.Count > 0)
{
// Check audio codecs
2014-05-08 20:09:53 +00:00
string audioCodec = audioStream == null ? null : audioStream.Codec;
2014-04-01 22:23:07 +00:00
if (string.IsNullOrEmpty(audioCodec) || !audioCodecs.Contains(audioCodec, StringComparer.OrdinalIgnoreCase))
{
return false;
}
}
return true;
}
}
}