public EncodingJobOptions(StreamInfo info, DeviceProfile deviceProfile) { OutputContainer = info.Container; StartTimeTicks = info.StartPositionTicks; MaxWidth = info.MaxWidth; MaxHeight = info.MaxHeight; MaxFramerate = info.MaxFramerate; Profile = info.VideoProfile; Level = info.VideoLevel; ItemId = info.ItemId; MediaSourceId = info.MediaSourceId; AudioCodec = info.AudioCodec; MaxAudioChannels = info.MaxAudioChannels; AudioBitRate = info.AudioBitrate; AudioSampleRate = info.TargetAudioSampleRate; DeviceProfile = deviceProfile; VideoCodec = info.VideoCodec; VideoBitRate = info.VideoBitrate; AudioStreamIndex = info.AudioStreamIndex; MaxRefFrames = info.MaxRefFrames; MaxVideoBitDepth = info.MaxVideoBitDepth; SubtitleMethod = info.SubtitleDeliveryMethod; Cabac = info.Cabac; Context = info.Context; if (info.SubtitleDeliveryMethod == SubtitleDeliveryMethod.Encode || info.SubtitleDeliveryMethod == SubtitleDeliveryMethod.Embed) { SubtitleStreamIndex = info.SubtitleStreamIndex; } }
public PlaylistItem Create(Photo item, DeviceProfile profile) { var playlistItem = new PlaylistItem { ItemId = item.Id.ToString("N"), MediaType = DlnaProfileType.Photo }; var directPlay = profile.DirectPlayProfiles .FirstOrDefault(i => i.Type == playlistItem.MediaType && IsSupported(i, item)); if (directPlay != null) { playlistItem.Transcode = false; playlistItem.Container = Path.GetExtension(item.Path); return playlistItem; } var transcodingProfile = profile.TranscodingProfiles .FirstOrDefault(i => i.Type == playlistItem.MediaType && IsSupported(profile, i, item)); if (transcodingProfile != null) { playlistItem.Transcode = true; playlistItem.Container = "." + transcodingProfile.Container.TrimStart('.'); } return playlistItem; }
public DidlBuilder(DeviceProfile profile, User user, IImageProcessor imageProcessor, string serverAddress) { _profile = profile; _imageProcessor = imageProcessor; _serverAddress = serverAddress; _user = user; }
public PlaylistItem Create(Photo item, DeviceProfile profile) { var playlistItem = new PlaylistItem { StreamInfo = new StreamInfo { ItemId = item.Id.ToString("N"), MediaType = DlnaProfileType.Photo, }, Profile = profile }; var directPlay = profile.DirectPlayProfiles .FirstOrDefault(i => i.Type == DlnaProfileType.Photo && IsSupported(i, item)); if (directPlay != null) { playlistItem.StreamInfo.PlayMethod = PlayMethod.DirectStream; playlistItem.StreamInfo.Container = Path.GetExtension(item.Path); return playlistItem; } var transcodingProfile = profile.TranscodingProfiles .FirstOrDefault(i => i.Type == DlnaProfileType.Photo); if (transcodingProfile != null) { playlistItem.StreamInfo.PlayMethod = PlayMethod.Transcode; playlistItem.StreamInfo.Container = "." + transcodingProfile.Container.TrimStart('.'); } return playlistItem; }
private User GetUser(DeviceProfile profile) { if (!string.IsNullOrEmpty(profile.UserId)) { var user = _userManager.GetUserById(profile.UserId); if (user != null) { return user; } } var userId = _config.GetDlnaConfiguration().DefaultUserId; if (!string.IsNullOrEmpty(userId)) { var user = _userManager.GetUserById(userId); if (user != null) { return user; } } // No configuration so it's going to be pretty arbitrary return _userManager.Users.First(); }
public DidlBuilder(DeviceProfile profile, User user, IImageProcessor imageProcessor, string serverAddress, IUserDataManager userDataManager, ILocalizationManager localization) { _profile = profile; _imageProcessor = imageProcessor; _serverAddress = serverAddress; _userDataManager = userDataManager; _localization = localization; _user = user; }
public DescriptionXmlBuilder(DeviceProfile profile, string serverUdn) { if (string.IsNullOrWhiteSpace(serverUdn)) { throw new ArgumentNullException("serverUdn"); } _profile = profile; _serverUdn = serverUdn; }
public ControlHandler(ILogger logger, ILibraryManager libraryManager, DeviceProfile profile, string serverAddress, IImageProcessor imageProcessor, IUserDataManager userDataManager, User user, int systemUpdateId, IServerConfigurationManager config) : base(config, logger) { _libraryManager = libraryManager; _userDataManager = userDataManager; _user = user; _systemUpdateId = systemUpdateId; _profile = profile; _didlBuilder = new DidlBuilder(profile, user, imageProcessor, serverAddress, userDataManager); }
public DidlBuilder(DeviceProfile profile, User user, IImageProcessor imageProcessor, string serverAddress, string accessToken, IUserDataManager userDataManager, ILocalizationManager localization, IMediaSourceManager mediaSourceManager, ILogger logger) { _profile = profile; _imageProcessor = imageProcessor; _serverAddress = serverAddress; _userDataManager = userDataManager; _localization = localization; _mediaSourceManager = mediaSourceManager; _logger = logger; _accessToken = accessToken; _user = user; }
public ControlHandler(ILogger logger, ILibraryManager libraryManager, DeviceProfile profile, string serverAddress, IDtoService dtoService, IImageProcessor imageProcessor, IUserDataManager userDataManager, User user, int systemUpdateId) { _logger = logger; _libraryManager = libraryManager; _profile = profile; _serverAddress = serverAddress; _dtoService = dtoService; _imageProcessor = imageProcessor; _userDataManager = userDataManager; _user = user; _systemUpdateId = systemUpdateId; }
public ControlHandler(ILogger logger, ILibraryManager libraryManager, DeviceProfile profile, string serverAddress, string accessToken, IImageProcessor imageProcessor, IUserDataManager userDataManager, User user, int systemUpdateId, IServerConfigurationManager config, ILocalizationManager localization, IChannelManager channelManager, IMediaSourceManager mediaSourceManager) : base(config, logger) { _libraryManager = libraryManager; _userDataManager = userDataManager; _user = user; _systemUpdateId = systemUpdateId; _channelManager = channelManager; _profile = profile; _config = config; _didlBuilder = new DidlBuilder(profile, user, imageProcessor, serverAddress, accessToken, userDataManager, localization, mediaSourceManager, Logger); }
public static ClientCapabilities CreateCapabilities(bool supportsPlayback, bool supportsContentUpload, bool supportsSync, DeviceProfile profile = null) { return new ClientCapabilities { SupportsMediaControl = supportsPlayback, SupportsContentUploading = supportsContentUpload, SupportsSync = supportsSync, SupportsOfflineAccess = supportsSync, DeviceProfile = supportsSync && profile != null ? profile : null, AppStoreUrl = "https://www.windowsphone.com/s?appid=f4971ed9-f651-4bf6-84bb-94fd98613b86", IconUrl = "https://raw.githubusercontent.com/MediaBrowser/MediaBrowser.WindowsPhone/BETA/MarketPlace/WP8/StoreLogo.png" }; }
public LiveStreamRequest(AudioOptions options) { MaxStreamingBitrate = options.MaxBitrate; ItemId = options.ItemId; DeviceProfile = options.Profile; VideoOptions videoOptions = options as VideoOptions; if (videoOptions != null) { AudioStreamIndex = videoOptions.AudioStreamIndex; SubtitleStreamIndex = videoOptions.SubtitleStreamIndex; } }
public PlaylistItem Create(Audio item, List<MediaStream> mediaStreams, DeviceProfile profile) { var playlistItem = new PlaylistItem { ItemId = item.Id.ToString("N"), MediaType = DlnaProfileType.Audio }; var audioStream = mediaStreams.FirstOrDefault(i => i.Type == MediaStreamType.Audio); var directPlay = profile.DirectPlayProfiles .FirstOrDefault(i => i.Type == playlistItem.MediaType && IsSupported(i, item, audioStream)); if (directPlay != null) { var audioCodec = audioStream == null ? null : audioStream.Codec; // Make sure audio codec profiles are satisfied if (!string.IsNullOrEmpty(audioCodec) && profile.CodecProfiles.Where(i => i.Type == CodecType.Audio && i.ContainsCodec(audioCodec)) .All(i => AreConditionsSatisfied(i.Conditions, item.Path, null, audioStream))) { playlistItem.Transcode = false; playlistItem.Container = Path.GetExtension(item.Path); return playlistItem; } } var transcodingProfile = profile.TranscodingProfiles .FirstOrDefault(i => i.Type == playlistItem.MediaType && IsSupported(profile, i, item)); if (transcodingProfile != null) { playlistItem.Transcode = true; playlistItem.Container = "." + transcodingProfile.Container.TrimStart('.'); playlistItem.AudioCodec = transcodingProfile.AudioCodec; var audioTranscodingConditions = profile.CodecProfiles .Where(i => i.Type == CodecType.Audio && i.ContainsCodec(transcodingProfile.AudioCodec)) .Take(1) .SelectMany(i => i.Conditions); ApplyTranscodingConditions(playlistItem, audioTranscodingConditions); } return playlistItem; }
public DescriptionXmlBuilder(DeviceProfile profile, string serverUdn, string serverAddress, string serverName, string serverId) { if (string.IsNullOrWhiteSpace(serverUdn)) { throw new ArgumentNullException("serverUdn"); } if (string.IsNullOrWhiteSpace(serverAddress)) { throw new ArgumentNullException("serverAddress"); } _profile = profile; _serverUdn = serverUdn; _serverAddress = serverAddress; _serverName = serverName; _serverId = serverId; }
private async Task SyncGeneric(SyncJobItem jobItem, BaseItem item, DeviceProfile profile, CancellationToken cancellationToken) { jobItem.OutputPath = item.Path; jobItem.Progress = 50; jobItem.Status = SyncJobItemStatus.Transferring; await _syncRepo.Update(jobItem).ConfigureAwait(false); }
private async Task Sync(SyncJobItem jobItem, Audio item, DeviceProfile profile, CancellationToken cancellationToken) { var options = new AudioOptions { Context = EncodingContext.Static, ItemId = item.Id.ToString("N"), DeviceId = jobItem.TargetId, Profile = profile, MediaSources = item.GetMediaSources(false).ToList() }; var streamInfo = new StreamBuilder().BuildAudioItem(options); var mediaSource = streamInfo.MediaSource; jobItem.MediaSourceId = streamInfo.MediaSourceId; if (streamInfo.PlayMethod == PlayMethod.Transcode) { jobItem.Status = SyncJobItemStatus.Converting; await _syncRepo.Update(jobItem).ConfigureAwait(false); jobItem.OutputPath = await _mediaEncoder.EncodeAudio(new EncodingJobOptions(streamInfo, profile), new Progress<double>(), cancellationToken); } else { if (mediaSource.Protocol == MediaProtocol.File) { jobItem.OutputPath = mediaSource.Path; } else if (mediaSource.Protocol == MediaProtocol.Http) { jobItem.OutputPath = await DownloadFile(jobItem, mediaSource, cancellationToken).ConfigureAwait(false); } else { throw new InvalidOperationException(string.Format("Cannot direct stream {0} protocol", mediaSource.Protocol)); } } jobItem.Progress = 50; jobItem.Status = SyncJobItemStatus.Transferring; await _syncRepo.Update(jobItem).ConfigureAwait(false); }
private PlaylistItem GetPlaylistItem(BaseItem item, List<MediaSourceInfo> mediaSources, DeviceProfile profile, string deviceId, string mediaSourceId, int? audioStreamIndex, int? subtitleStreamIndex) { if (string.Equals(item.MediaType, MediaType.Video, StringComparison.OrdinalIgnoreCase)) { return new PlaylistItem { StreamInfo = new StreamBuilder().BuildVideoItem(new VideoOptions { ItemId = item.Id.ToString("N"), MediaSources = mediaSources, Profile = profile, DeviceId = deviceId, MaxBitrate = profile.MaxStreamingBitrate, MediaSourceId = mediaSourceId, AudioStreamIndex = audioStreamIndex, SubtitleStreamIndex = subtitleStreamIndex }), Profile = profile }; } if (string.Equals(item.MediaType, MediaType.Audio, StringComparison.OrdinalIgnoreCase)) { return new PlaylistItem { StreamInfo = new StreamBuilder().BuildAudioItem(new AudioOptions { ItemId = item.Id.ToString("N"), MediaSources = mediaSources, Profile = profile, DeviceId = deviceId, MaxBitrate = profile.MaxStreamingBitrate, MediaSourceId = mediaSourceId }), Profile = profile }; } if (string.Equals(item.MediaType, MediaType.Photo, StringComparison.OrdinalIgnoreCase)) { return new PlaylistItemFactory().Create((Photo)item, profile); } throw new ArgumentException("Unrecognized item type."); }
public ContentFeatureBuilder(DeviceProfile profile) { _profile = profile; }
private void SaveProfile(DeviceProfile profile, string path, DeviceProfileType type) { lock (_profiles) { _profiles[path] = new Tuple<InternalProfileInfo, DeviceProfile>(GetInternalProfileInfo(_fileSystem.GetFileInfo(path), type), profile); } _xmlSerializer.SerializeToFile(profile, path); }
public ControlHandler(ILogger logger, DeviceProfile profile, IServerConfigurationManager config) : base(config, logger) { _profile = profile; }
private bool IsSupported(DeviceProfile profile, TranscodingProfile transcodingProfile, Video item) { // Placeholder for future conditions return true; }
/// <summary> /// Recreates the object using serialization, to ensure it's not a subclass. /// If it's a subclass it may not serlialize properly to xml (different root element tag name) /// </summary> /// <param name="profile"></param> /// <returns></returns> private DeviceProfile ReserializeProfile(DeviceProfile profile) { if (profile.GetType() == typeof(DeviceProfile)) { return profile; } var json = _jsonSerializer.SerializeToString(profile); return _jsonSerializer.DeserializeFromString<DeviceProfile>(json); }
public static ClientCapabilities App(DeviceProfile profile = null) { return CreateCapabilities(false, true, SyncService.SyncEnabled, profile); }
private static DeviceProfile GetWindowsPhoneProfileNonS4(bool isHls = false) { var profile = new DeviceProfile(); var transcodingProfiles = new List<TranscodingProfile> { new TranscodingProfile { Container = "mp3", AudioCodec = "mp3", Type = DlnaProfileType.Audio, Context = EncodingContext.Streaming }, new TranscodingProfile { Container = "mp4", VideoCodec = "h264", AudioCodec = "aac", Type = DlnaProfileType.Video, Context = EncodingContext.Static }, new TranscodingProfile { Container = "mp3", AudioCodec = "mp3", Type = DlnaProfileType.Audio, Context = EncodingContext.Static }, new TranscodingProfile { Container = "jpeg,png,gif,bmp", Type = DlnaProfileType.Photo, Context = EncodingContext.Static } }; if (isHls) { transcodingProfiles.Add(new TranscodingProfile { Protocol = "hls", Container = "ts", VideoCodec = "h264", AudioCodec = "aac", Type = DlnaProfileType.Video, Context = EncodingContext.Streaming }); } transcodingProfiles.Add(new TranscodingProfile { Container = "mp4", VideoCodec = "h264", AudioCodec = "aac", Type = DlnaProfileType.Video, Context = EncodingContext.Streaming }); profile.TranscodingProfiles = transcodingProfiles.ToArray(); profile.DirectPlayProfiles = new[] { new DirectPlayProfile { Container = "3gp,mp4,mov,m4v", VideoCodec = "h264", AudioCodec = "aac,mp3", Type = DlnaProfileType.Video }, new DirectPlayProfile { Container = "mp4,m4v,avi,3gp", VideoCodec = "mpeg4,msmpeg4", AudioCodec = "aac,mp3", Type = DlnaProfileType.Video }, new DirectPlayProfile { Container = "wmv", VideoCodec = "vc1", AudioCodec = "aac,mp3", Type = DlnaProfileType.Video }, new DirectPlayProfile { Container = "asf", VideoCodec = "wmv2,wmv3,vc1", AudioCodec = "wmav2,wmapro,wmavoice", Type = DlnaProfileType.Video }, new DirectPlayProfile { Container = "asf", AudioCodec = "wmav2,wmapro,wmavoice", Type = DlnaProfileType.Audio }, new DirectPlayProfile { Container = "mp3,mp4,aac,wma", Type = DlnaProfileType.Audio }, new DirectPlayProfile { Container = "jpeg,png,gif,bmp", Type = DlnaProfileType.Photo } }; profile.CodecProfiles = new[] { new CodecProfile { Type = CodecType.Video, Codec="h264", Conditions = new [] { new ProfileCondition { Condition = ProfileConditionType.LessThanEqual, Property = ProfileConditionValue.Width, Value = "1280" }, new ProfileCondition { Condition = ProfileConditionType.LessThanEqual, Property = ProfileConditionValue.Height, Value = "720" }, new ProfileCondition { Condition = ProfileConditionType.LessThanEqual, Property = ProfileConditionValue.VideoBitrate, Value = "10000000", IsRequired = false }, new ProfileCondition { Condition = ProfileConditionType.LessThanEqual, Property = ProfileConditionValue.VideoFramerate, Value = "30", IsRequired = false }, new ProfileCondition { Condition = ProfileConditionType.LessThanEqual, Property = ProfileConditionValue.VideoLevel, Value = "31" }, new ProfileCondition(ProfileConditionType.EqualsAny, ProfileConditionValue.VideoProfile, "high|main|baseline|constrained baseline"), new ProfileCondition { Condition = ProfileConditionType.NotEquals, Property = ProfileConditionValue.IsAnamorphic, Value = "true" } } }, new CodecProfile { Type = CodecType.Video, Codec="mpeg4,msmpeg4,wmv2,wmv3,vc1", Conditions = new [] { new ProfileCondition { Condition = ProfileConditionType.LessThanEqual, Property = ProfileConditionValue.Width, Value = "800" }, new ProfileCondition { Condition = ProfileConditionType.LessThanEqual, Property = ProfileConditionValue.Height, Value = "600" }, new ProfileCondition { Condition = ProfileConditionType.LessThanEqual, Property = ProfileConditionValue.VideoBitrate, Value = "2000000", IsRequired = false }, new ProfileCondition { Condition = ProfileConditionType.LessThanEqual, Property = ProfileConditionValue.VideoFramerate, Value = "30", IsRequired = false }, new ProfileCondition { Condition = ProfileConditionType.NotEquals, Property = ProfileConditionValue.IsAnamorphic, Value = "true" } } }, new CodecProfile { Type = CodecType.VideoAudio, Conditions = new [] { new ProfileCondition { Condition = ProfileConditionType.LessThanEqual, Property = ProfileConditionValue.AudioBitrate, Value = "320000" }, new ProfileCondition { Condition = ProfileConditionType.LessThanEqual, Property = ProfileConditionValue.AudioChannels, Value = "2" } } }, new CodecProfile { Type = CodecType.Audio, Conditions = new [] { new ProfileCondition { Condition = ProfileConditionType.LessThanEqual, Property = ProfileConditionValue.AudioBitrate, Value = "320000" } } } }; profile.MaxStreamingBitrate = 20000000; profile.MaxStaticBitrate = 20000000; return profile; }
private DirectPlayProfile GetVideoDirectPlayProfile(DeviceProfile profile, MediaSourceInfo mediaSource, MediaStream videoStream, MediaStream audioStream) { // See if it can be direct played var directPlay = profile.DirectPlayProfiles .FirstOrDefault(i => i.Type == DlnaProfileType.Video && IsVideoDirectPlaySupported(i, mediaSource, videoStream, audioStream)); if (directPlay == null) { return(null); } var container = mediaSource.Container; var conditions = profile.ContainerProfiles .Where(i => i.Type == DlnaProfileType.Video && i.GetContainers().Contains(container, StringComparer.OrdinalIgnoreCase)) .SelectMany(i => i.Conditions); var conditionProcessor = new ConditionProcessor(); var width = videoStream == null ? null : videoStream.Width; var height = videoStream == null ? null : videoStream.Height; var bitDepth = videoStream == null ? null : videoStream.BitDepth; var videoBitrate = videoStream == null ? null : videoStream.BitRate; var videoLevel = videoStream == null ? null : videoStream.Level; var videoProfile = videoStream == null ? null : videoStream.Profile; var videoFramerate = videoStream == null ? null : videoStream.AverageFrameRate ?? videoStream.AverageFrameRate; var audioBitrate = audioStream == null ? null : audioStream.BitRate; var audioChannels = audioStream == null ? null : audioStream.Channels; var timestamp = videoStream == null ? TransportStreamTimestamp.None : mediaSource.Timestamp; var packetLength = videoStream == null ? null : videoStream.PacketLength; // Check container conditions if (!conditions.All(i => conditionProcessor.IsVideoConditionSatisfied(i, audioBitrate, audioChannels, width, height, bitDepth, videoBitrate, videoProfile, videoLevel, videoFramerate, packetLength, timestamp))) { return(null); } var videoCodec = videoStream == null ? null : videoStream.Codec; if (string.IsNullOrEmpty(videoCodec)) { return(null); } conditions = profile.CodecProfiles .Where(i => i.Type == CodecType.Video && i.ContainsCodec(videoCodec)) .SelectMany(i => i.Conditions); if (!conditions.All(i => conditionProcessor.IsVideoConditionSatisfied(i, audioBitrate, audioChannels, width, height, bitDepth, videoBitrate, videoProfile, videoLevel, videoFramerate, packetLength, timestamp))) { return(null); } if (audioStream != null) { var audioCodec = audioStream.Codec; if (string.IsNullOrEmpty(audioCodec)) { return(null); } conditions = profile.CodecProfiles .Where(i => i.Type == CodecType.VideoAudio && i.ContainsCodec(audioCodec)) .SelectMany(i => i.Conditions); if (!conditions.All(i => conditionProcessor.IsVideoAudioConditionSatisfied(i, audioChannels, audioBitrate))) { return(null); } } return(directPlay); }
private PlayMethod? GetVideoDirectPlayProfile(DeviceProfile profile, MediaSourceInfo mediaSource, MediaStream videoStream, MediaStream audioStream, bool isEligibleForDirectPlay, bool isEligibleForDirectStream) { // See if it can be direct played DirectPlayProfile directPlay = null; foreach (DirectPlayProfile i in profile.DirectPlayProfiles) { if (i.Type == DlnaProfileType.Video && IsVideoDirectPlaySupported(i, mediaSource, videoStream, audioStream)) { directPlay = i; break; } } if (directPlay == null) { _logger.Debug("Profile: {0}, No direct play profiles found for Path: {1}", profile.Name ?? "Unknown Profile", mediaSource.Path ?? "Unknown path"); return null; } string container = mediaSource.Container; List<ProfileCondition> conditions = new List<ProfileCondition>(); foreach (ContainerProfile i in profile.ContainerProfiles) { if (i.Type == DlnaProfileType.Video && ListHelper.ContainsIgnoreCase(i.GetContainers(), container)) { foreach (ProfileCondition c in i.Conditions) { conditions.Add(c); } } } ConditionProcessor conditionProcessor = new ConditionProcessor(); 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; bool? isCabac = videoStream == null ? null : videoStream.IsCabac; int? audioBitrate = audioStream == null ? null : audioStream.BitRate; int? audioChannels = audioStream == null ? null : audioStream.Channels; string audioProfile = audioStream == null ? null : audioStream.Profile; TransportStreamTimestamp? timestamp = videoStream == null ? TransportStreamTimestamp.None : mediaSource.Timestamp; int? packetLength = videoStream == null ? null : videoStream.PacketLength; int? refFrames = videoStream == null ? null : videoStream.RefFrames; int? numAudioStreams = mediaSource.GetStreamCount(MediaStreamType.Audio); int? numVideoStreams = mediaSource.GetStreamCount(MediaStreamType.Video); // 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)) { LogConditionFailure(profile, "VideoContainerProfile", i, mediaSource); return null; } } string videoCodec = videoStream == null ? null : videoStream.Codec; if (string.IsNullOrEmpty(videoCodec)) { _logger.Debug("Profile: {0}, DirectPlay=false. Reason=Unknown video codec. Path: {1}", profile.Name ?? "Unknown Profile", mediaSource.Path ?? "Unknown path"); return null; } conditions = new List<ProfileCondition>(); foreach (CodecProfile i in profile.CodecProfiles) { if (i.Type == CodecType.Video && i.ContainsCodec(videoCodec, container)) { 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)) { LogConditionFailure(profile, "VideoCodecProfile", i, mediaSource); return null; } } if (audioStream != null) { string audioCodec = audioStream.Codec; if (string.IsNullOrEmpty(audioCodec)) { _logger.Debug("Profile: {0}, DirectPlay=false. Reason=Unknown audio codec. Path: {1}", profile.Name ?? "Unknown Profile", mediaSource.Path ?? "Unknown path"); return null; } conditions = new List<ProfileCondition>(); foreach (CodecProfile i in profile.CodecProfiles) { if (i.Type == CodecType.VideoAudio && i.ContainsCodec(audioCodec, container)) { 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); return null; } } } 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; } return null; }
private void LogConditionFailure(DeviceProfile profile, string type, ProfileCondition condition, MediaSourceInfo mediaSource) { _logger.Debug("Profile: {0}, DirectPlay=false. Reason={1}.{2} Condition: {3}. ConditionValue: {4}. IsRequired: {5}. Path: {6}", type, profile.Name ?? "Unknown Profile", condition.Property, condition.Condition, condition.Value ?? string.Empty, condition.IsRequired, mediaSource.Path ?? "Unknown path"); }
public void CreateProfile(DeviceProfile profile) { profile = ReserializeProfile(profile); if (string.IsNullOrWhiteSpace(profile.Name)) { throw new ArgumentException("Profile is missing Name"); } var newFilename = _fileSystem.GetValidFilename(profile.Name) + ".xml"; var path = Path.Combine(UserProfilesPath, newFilename); _xmlSerializer.SerializeToFile(profile, path); }
private DirectPlayProfile GetVideoDirectPlayProfile(DeviceProfile profile, MediaSourceInfo mediaSource, MediaStream videoStream, MediaStream audioStream) { // See if it can be direct played DirectPlayProfile directPlay = null; foreach (DirectPlayProfile i in profile.DirectPlayProfiles) { if (i.Type == DlnaProfileType.Video && IsVideoDirectPlaySupported(i, mediaSource, videoStream, audioStream)) { directPlay = i; break; } } if (directPlay == null) { return null; } string container = mediaSource.Container; List<ProfileCondition> conditions = new List<ProfileCondition>(); foreach (ContainerProfile i in profile.ContainerProfiles) { if (i.Type == DlnaProfileType.Video && ListHelper.ContainsIgnoreCase(i.GetContainers(), container)) { foreach (var c in i.Conditions) { conditions.Add(c); } } } ConditionProcessor conditionProcessor = new ConditionProcessor(); 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; int? audioBitrate = audioStream == null ? null : audioStream.BitRate; int? audioChannels = audioStream == null ? null : audioStream.Channels; string audioProfile = audioStream == null ? null : audioStream.Profile; TransportStreamTimestamp? timestamp = videoStream == null ? TransportStreamTimestamp.None : mediaSource.Timestamp; int? packetLength = videoStream == null ? null : videoStream.PacketLength; // Check container conditions foreach (ProfileCondition i in conditions) { if (!conditionProcessor.IsVideoConditionSatisfied(i, audioBitrate, audioChannels, width, height, bitDepth, videoBitrate, videoProfile, videoLevel, videoFramerate, packetLength, timestamp, isAnamorphic)) { return null; } } string videoCodec = videoStream == null ? null : videoStream.Codec; if (string.IsNullOrEmpty(videoCodec)) { return null; } conditions = new List<ProfileCondition>(); foreach (CodecProfile i in profile.CodecProfiles) { if (i.Type == CodecType.Video && i.ContainsCodec(videoCodec)) { foreach (var c in i.Conditions) { conditions.Add(c); } } } foreach (ProfileCondition i in conditions) { if (!conditionProcessor.IsVideoConditionSatisfied(i, audioBitrate, audioChannels, width, height, bitDepth, videoBitrate, videoProfile, videoLevel, videoFramerate, packetLength, timestamp, isAnamorphic)) { return null; } } if (audioStream != null) { string audioCodec = audioStream.Codec; if (string.IsNullOrEmpty(audioCodec)) { return null; } conditions = new List<ProfileCondition>(); foreach (CodecProfile i in profile.CodecProfiles) { if (i.Type == CodecType.VideoAudio && i.ContainsCodec(audioCodec)) { foreach (var c in i.Conditions) { conditions.Add(c); } } } foreach (ProfileCondition i in conditions) { if (!conditionProcessor.IsVideoAudioConditionSatisfied(i, audioChannels, audioBitrate, audioProfile)) { return null; } } } return directPlay; }
public void UpdateProfile(DeviceProfile profile) { profile = ReserializeProfile(profile); if (string.IsNullOrWhiteSpace(profile.Id)) { throw new ArgumentException("Profile is missing Id"); } if (string.IsNullOrWhiteSpace(profile.Name)) { throw new ArgumentException("Profile is missing Name"); } var current = GetProfileInfosInternal().First(i => string.Equals(i.Info.Id, profile.Id, StringComparison.OrdinalIgnoreCase)); var newFilename = _fileSystem.GetValidFilename(profile.Name) + ".xml"; var path = Path.Combine(UserProfilesPath, newFilename); if (!string.Equals(path, current.Path, StringComparison.Ordinal) && current.Info.Type != DeviceProfileType.System) { _fileSystem.DeleteFile(current.Path); } _xmlSerializer.SerializeToFile(profile, path); }
private PlayMethod?GetVideoDirectPlayProfile(DeviceProfile profile, MediaSourceInfo mediaSource, MediaStream videoStream, MediaStream audioStream, bool isEligibleForDirectPlay, bool isEligibleForDirectStream) { if (videoStream == null) { _logger.Info("Profile: {0}, Cannot direct stream with no known video stream. Path: {1}", profile.Name ?? "Unknown Profile", mediaSource.Path ?? "Unknown path"); return(null); } // See if it can be direct played DirectPlayProfile directPlay = null; foreach (DirectPlayProfile i in profile.DirectPlayProfiles) { if (i.Type == DlnaProfileType.Video && IsVideoDirectPlaySupported(i, mediaSource, videoStream, audioStream)) { directPlay = i; break; } } if (directPlay == null) { _logger.Info("Profile: {0}, No direct play profiles found for Path: {1}", profile.Name ?? "Unknown Profile", mediaSource.Path ?? "Unknown path"); return(null); } string container = mediaSource.Container; List <ProfileCondition> conditions = new List <ProfileCondition>(); foreach (ContainerProfile i in profile.ContainerProfiles) { if (i.Type == DlnaProfileType.Video && ListHelper.ContainsIgnoreCase(i.GetContainers(), container)) { foreach (ProfileCondition c in i.Conditions) { conditions.Add(c); } } } ConditionProcessor conditionProcessor = new ConditionProcessor(); 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; bool? isCabac = videoStream == null ? null : videoStream.IsCabac; string videoCodecTag = videoStream == null ? null : videoStream.CodecTag; int? audioBitrate = audioStream == null ? null : audioStream.BitRate; int? audioChannels = audioStream == null ? null : audioStream.Channels; string audioProfile = audioStream == null ? null : audioStream.Profile; TransportStreamTimestamp?timestamp = videoStream == null ? TransportStreamTimestamp.None : mediaSource.Timestamp; int?packetLength = videoStream == null ? null : videoStream.PacketLength; int?refFrames = videoStream == null ? null : videoStream.RefFrames; int?numAudioStreams = mediaSource.GetStreamCount(MediaStreamType.Audio); int?numVideoStreams = mediaSource.GetStreamCount(MediaStreamType.Video); // 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)) { LogConditionFailure(profile, "VideoContainerProfile", i, mediaSource); return(null); } } string videoCodec = videoStream == null ? null : videoStream.Codec; if (string.IsNullOrEmpty(videoCodec)) { _logger.Info("Profile: {0}, DirectPlay=false. Reason=Unknown video codec. Path: {1}", profile.Name ?? "Unknown Profile", mediaSource.Path ?? "Unknown path"); return(null); } conditions = new List <ProfileCondition>(); foreach (CodecProfile i in profile.CodecProfiles) { if (i.Type == CodecType.Video && i.ContainsCodec(videoCodec, container)) { 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)) { LogConditionFailure(profile, "VideoCodecProfile", i, mediaSource); return(null); } } if (audioStream != null) { string audioCodec = audioStream.Codec; if (string.IsNullOrEmpty(audioCodec)) { _logger.Info("Profile: {0}, DirectPlay=false. Reason=Unknown audio codec. Path: {1}", profile.Name ?? "Unknown Profile", mediaSource.Path ?? "Unknown path"); return(null); } conditions = new List <ProfileCondition>(); foreach (CodecProfile i in profile.CodecProfiles) { if (i.Type == CodecType.VideoAudio && i.ContainsCodec(audioCodec, container)) { 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); return(null); } } } 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); } return(null); }