Ejemplo n.º 1
0
        private List <PlayMethod> GetAudioDirectPlayMethods(MediaSourceInfo item, AudioOptions options)
        {
            MediaStream audioStream = item.DefaultAudioStream;

            DirectPlayProfile directPlayProfile = null;

            foreach (DirectPlayProfile i in options.Profile.DirectPlayProfiles)
            {
                if (i.Type == DlnaProfileType.Audio && IsAudioDirectPlaySupported(i, item, audioStream))
                {
                    directPlayProfile = i;
                    break;
                }
            }

            List <PlayMethod> playMethods = new List <PlayMethod>();

            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()))
                {
                    playMethods.Add(PlayMethod.DirectStream);
                }

                // The profile describes what the device supports
                // If device requirements are satisfied then allow both direct stream and direct play
                if (IsAudioEligibleForDirectPlay(item, options.Profile.MaxStaticBitrate))
                {
                    playMethods.Add(PlayMethod.DirectPlay);
                }
            }

            return(playMethods);
        }
Ejemplo n.º 2
0
        public DeviceProfile()
        {
            DirectPlayProfiles = new DirectPlayProfile[] { };
            TranscodingProfiles = new TranscodingProfile[] { };
            ResponseProfiles = new ResponseProfile[] { };
            CodecProfiles = new CodecProfile[] { };
            ContainerProfiles = new ContainerProfile[] { };

            SupportedMediaTypes = "Audio,Photo,Video";
        }
Ejemplo n.º 3
0
        public DeviceProfile()
        {
            DirectPlayProfiles  = new DirectPlayProfile[] { };
            TranscodingProfiles = new TranscodingProfile[] { };
            ResponseProfiles    = new ResponseProfile[] { };
            CodecProfiles       = new CodecProfile[] { };
            ContainerProfiles   = new ContainerProfile[] { };

            XmlRootAttributes = new XmlAttribute[] { };

            SupportedMediaTypes = "Audio,Photo,Video";
        }
Ejemplo n.º 4
0
        private bool IsVideoDirectPlaySupported(DirectPlayProfile profile, MediaSourceInfo item, MediaStream videoStream, MediaStream audioStream)
        {
            // Only plain video files can be direct played
            if (item.VideoType != VideoType.VideoFile)
            {
                return(false);
            }

            if (profile.Container.Length > 0)
            {
                // Check container type
                string mediaContainer = item.Container ?? string.Empty;
                bool   any            = false;
                foreach (string i in profile.GetContainers())
                {
                    if (StringHelper.EqualsIgnoreCase(i, mediaContainer))
                    {
                        any = true;
                        break;
                    }
                }
                if (!any)
                {
                    return(false);
                }
            }

            // Check video codec
            List <string> videoCodecs = profile.GetVideoCodecs();

            if (videoCodecs.Count > 0)
            {
                string videoCodec = videoStream == null ? null : videoStream.Codec;
                if (string.IsNullOrEmpty(videoCodec) || !ListHelper.ContainsIgnoreCase(videoCodecs, videoCodec))
                {
                    return(false);
                }
            }

            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);
        }
Ejemplo n.º 5
0
        private bool IsAudioDirectPlaySupported(DirectPlayProfile profile, MediaSourceInfo item, MediaStream audioStream)
        {
            if (profile.Container.Length > 0)
            {
                // Check container type
                var mediaContainer = item.Container ?? string.Empty;
                if (!profile.GetContainers().Any(i => string.Equals(i, mediaContainer, StringComparison.OrdinalIgnoreCase)))
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 6
0
        public DeviceProfile()
        {
            DirectPlayProfiles  = new DirectPlayProfile[] { };
            TranscodingProfiles = new TranscodingProfile[] { };
            ResponseProfiles    = new ResponseProfile[] { };
            CodecProfiles       = new CodecProfile[] { };
            ContainerProfiles   = new ContainerProfile[] { };
            SubtitleProfiles    = Array.Empty <SubtitleProfile>();

            XmlRootAttributes = new XmlAttribute[] { };

            SupportedMediaTypes = "Audio,Photo,Video";
            MaxStreamingBitrate = 8000000;
            MaxStaticBitrate    = 8000000;
            MusicStreamingTranscodingBitrate = 128000;
        }
Ejemplo n.º 7
0
        private bool IsSupported(DirectPlayProfile profile, Photo item)
        {
            var mediaPath = item.Path;

            if (profile.Container.Length > 0)
            {
                // Check container type
                var mediaContainer = Path.GetExtension(mediaPath);
                if (!profile.GetContainers().Any(i => string.Equals("." + i.TrimStart('.'), mediaContainer, StringComparison.OrdinalIgnoreCase)))
                {
                    return false;
                }
            }

            return true;
        }
Ejemplo n.º 8
0
        private bool IsVideoDirectPlaySupported(DirectPlayProfile profile, MediaSourceInfo item, MediaStream videoStream, MediaStream audioStream)
        {
            // Only plain video files can be direct played
            if (item.VideoType != VideoType.VideoFile)
            {
                return(false);
            }

            if (profile.Container.Length > 0)
            {
                // Check container type
                var mediaContainer = item.Container ?? string.Empty;
                if (!profile.GetContainers().Any(i => string.Equals(i, mediaContainer, StringComparison.OrdinalIgnoreCase)))
                {
                    return(false);
                }
            }

            // Check video codec
            var videoCodecs = profile.GetVideoCodecs();

            if (videoCodecs.Count > 0)
            {
                var videoCodec = videoStream == null ? null : videoStream.Codec;
                if (string.IsNullOrEmpty(videoCodec) || !videoCodecs.Contains(videoCodec, StringComparer.OrdinalIgnoreCase))
                {
                    return(false);
                }
            }

            var audioCodecs = profile.GetAudioCodecs();

            if (audioCodecs.Count > 0)
            {
                // Check audio codecs
                var audioCodec = audioStream == null ? null : audioStream.Codec;
                if (string.IsNullOrEmpty(audioCodec) || !audioCodecs.Contains(audioCodec, StringComparer.OrdinalIgnoreCase))
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 9
0
        private List <PlayMethod> GetAudioDirectPlayMethods(MediaSourceInfo item, MediaStream audioStream, AudioOptions options)
        {
            DirectPlayProfile directPlayProfile = null;

            foreach (DirectPlayProfile i in options.Profile.DirectPlayProfiles)
            {
                if (i.Type == DlnaProfileType.Audio && IsAudioDirectPlaySupported(i, item, audioStream))
                {
                    directPlayProfile = i;
                    break;
                }
            }

            List <PlayMethod> playMethods = new List <PlayMethod>();

            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()))
                {
                    playMethods.Add(PlayMethod.DirectStream);
                }

                // 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)))
                {
                    playMethods.Add(PlayMethod.DirectPlay);
                }
            }
            else
            {
                _logger.Info("Profile: {0}, No direct play profiles found for Path: {1}",
                             options.Profile.Name ?? "Unknown Profile",
                             item.Path ?? "Unknown path");
            }

            return(playMethods);
        }
Ejemplo n.º 10
0
        private bool IsAudioDirectPlaySupported(DirectPlayProfile profile, MediaSourceInfo item, MediaStream audioStream)
        {
            if (profile.Container.Length > 0)
            {
                // Check container type
                string mediaContainer = item.Container ?? string.Empty;
                bool   any            = false;
                foreach (string i in profile.GetContainers())
                {
                    if (StringHelper.EqualsIgnoreCase(i, mediaContainer))
                    {
                        any = true;
                        break;
                    }
                }
                if (!any)
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 11
0
 public DeviceProfile()
 {
     DirectPlayProfiles = new DirectPlayProfile[] { };
     TranscodingProfiles = new TranscodingProfile[] { };
     ResponseProfiles = new ResponseProfile[] { };
     CodecProfiles = new CodecProfile[] { };
     ContainerProfiles = new ContainerProfile[] { };
     SubtitleProfiles = new SubtitleProfile[] { };
  
     XmlRootAttributes = new XmlAttribute[] { };
     
     SupportedMediaTypes = "Audio,Photo,Video";
     MaxStreamingBitrate = 8000000;
     MaxStaticBitrate = 8000000;
     MusicStreamingTranscodingBitrate = 128000;
 }
Ejemplo n.º 12
0
        private bool IsAudioDirectPlaySupported(DirectPlayProfile profile, MediaSourceInfo item, MediaStream audioStream)
        {
            if (profile.Container.Length > 0)
            {
                // Check container type
                var mediaContainer = item.Container ?? string.Empty;
                if (!profile.GetContainers().Any(i => string.Equals(i, mediaContainer, StringComparison.OrdinalIgnoreCase)))
                {
                    return false;
                }
            }

            return true;
        }
Ejemplo n.º 13
0
        private bool IsVideoDirectPlaySupported(DirectPlayProfile profile, MediaSourceInfo item, MediaStream videoStream, MediaStream audioStream)
        {
            if (profile.Container.Length > 0)
            {
                // Check container type
                string mediaContainer = item.Container ?? string.Empty;
                bool any = false;
                foreach (string i in profile.GetContainers())
                {
                    if (StringHelper.EqualsIgnoreCase(i, mediaContainer))
                    {
                        any = true;
                        break;
                    }
                }
                if (!any)
                {
                    return false;
                }
            }

            // Check video codec
            List<string> videoCodecs = profile.GetVideoCodecs();
            if (videoCodecs.Count > 0)
            {
                string videoCodec = videoStream == null ? null : videoStream.Codec;
                if (string.IsNullOrEmpty(videoCodec) || !ListHelper.ContainsIgnoreCase(videoCodecs, videoCodec))
                {
                    return false;
                }
            }

            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;
        }
Ejemplo n.º 14
0
        private bool IsAudioDirectPlaySupported(DirectPlayProfile profile, MediaSourceInfo item, MediaStream audioStream)
        {
            if (profile.Container.Length > 0)
            {
                // Check container type
                string mediaContainer = item.Container ?? string.Empty;
                bool any = false;
                foreach (string i in profile.GetContainers())
                {
                    if (StringHelper.EqualsIgnoreCase(i, mediaContainer))
                    {
                        any = true;
                        break;
                    }
                }
                if (!any)
                {
                    return false;
                }
            }

            return true;
        }
Ejemplo n.º 15
0
        private PlayMethod?GetVideoDirectPlayProfile(VideoOptions options,
                                                     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 (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;

            // Check container conditions
            foreach (ProfileCondition i in conditions)
            {
                if (!conditionProcessor.IsVideoConditionSatisfied(i, audioBitrate, audioChannels, width, height, bitDepth, videoBitrate, videoProfile, videoLevel, videoFramerate, packetLength, timestamp, isAnamorphic, isCabac, refFrames))
                {
                    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 (ProfileCondition 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, isCabac, refFrames))
                {
                    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 (ProfileCondition c in i.Conditions)
                        {
                            conditions.Add(c);
                        }
                    }
                }

                foreach (ProfileCondition i in conditions)
                {
                    if (!conditionProcessor.IsVideoAudioConditionSatisfied(i, audioChannels, audioBitrate, audioProfile))
                    {
                        return(null);
                    }
                }
            }

            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 (!mediaSource.SupportsDirectStream)
            {
                return(null);
            }

            return(PlayMethod.DirectStream);
        }
Ejemplo n.º 16
0
        private bool IsVideoDirectPlaySupported(DirectPlayProfile profile, MediaSourceInfo item, MediaStream videoStream, MediaStream audioStream)
        {
            // Only plain video files can be direct played
            if (item.VideoType != VideoType.VideoFile)
            {
                return false;
            }

            if (profile.Container.Length > 0)
            {
                // Check container type
                var mediaContainer = item.Container ?? string.Empty;
                if (!profile.GetContainers().Any(i => string.Equals(i, mediaContainer, StringComparison.OrdinalIgnoreCase)))
                {
                    return false;
                }
            }

            // Check video codec
            var videoCodecs = profile.GetVideoCodecs();
            if (videoCodecs.Count > 0)
            {
                var videoCodec = videoStream == null ? null : videoStream.Codec;
                if (string.IsNullOrEmpty(videoCodec) || !videoCodecs.Contains(videoCodec, StringComparer.OrdinalIgnoreCase))
                {
                    return false;
                }
            }

            var audioCodecs = profile.GetAudioCodecs();
            if (audioCodecs.Count > 0)
            {
                // Check audio codecs
                var audioCodec = audioStream == null ? null : audioStream.Codec;
                if (string.IsNullOrEmpty(audioCodec) || !audioCodecs.Contains(audioCodec, StringComparer.OrdinalIgnoreCase))
                {
                    return false;
                }
            }

            return true;
        }
Ejemplo n.º 17
0
        public DeviceProfile()
        {
            DirectPlayProfiles = new DirectPlayProfile[] { };
            TranscodingProfiles = new TranscodingProfile[] { };
            ResponseProfiles = new ResponseProfile[] { };
            CodecProfiles = new CodecProfile[] { };
            ContainerProfiles = new ContainerProfile[] { };

            SoftSubtitleProfiles = new SubtitleProfile[] { };
            ExternalSubtitleProfiles = new SubtitleProfile[] { };
            
            XmlRootAttributes = new XmlAttribute[] { };
            
            SupportedMediaTypes = "Audio,Photo,Video";
        }
Ejemplo n.º 18
0
        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))
                {
                    conditions.AddRange(i.Conditions);
                }
            }

            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;

            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))
                {
                    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))
                {
                    conditions.AddRange(i.Conditions);
                }
            }

            foreach (ProfileCondition i in conditions)
            {
                if (!conditionProcessor.IsVideoConditionSatisfied(i, audioBitrate, audioChannels, width, height, bitDepth, videoBitrate, videoProfile, videoLevel, videoFramerate, packetLength, timestamp))
                {
                    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))
                    {
                        conditions.AddRange(i.Conditions);
                    }
                }

                foreach (ProfileCondition i in conditions)
                {
                    if (!conditionProcessor.IsVideoAudioConditionSatisfied(i, audioChannels, audioBitrate, audioProfile))
                    {
                        return(null);
                    }
                }
            }

            return(directPlay);
        }
Ejemplo n.º 19
0
        private StreamInfo BuildVideoItem(MediaSourceInfo item, VideoOptions options)
        {
            StreamInfo playlistItem = new StreamInfo
            {
                ItemId       = options.ItemId,
                MediaType    = DlnaProfileType.Video,
                MediaSource  = item,
                RunTimeTicks = item.RunTimeTicks
            };

            int?audioStreamIndex = options.AudioStreamIndex ?? item.DefaultAudioStreamIndex;

            playlistItem.SubtitleStreamIndex = options.SubtitleStreamIndex ?? item.DefaultSubtitleStreamIndex;

            MediaStream audioStream    = audioStreamIndex.HasValue ? item.GetMediaStream(MediaStreamType.Audio, audioStreamIndex.Value) : null;
            MediaStream subtitleStream = playlistItem.SubtitleStreamIndex.HasValue ? item.GetMediaStream(MediaStreamType.Subtitle, playlistItem.SubtitleStreamIndex.Value) : null;

            MediaStream videoStream = item.VideoStream;

            int?maxBitrateSetting = options.GetMaxBitrate();

            if (IsEligibleForDirectPlay(item, maxBitrateSetting, subtitleStream, options))
            {
                // See if it can be direct played
                DirectPlayProfile directPlay = GetVideoDirectPlayProfile(options.Profile, item, videoStream, audioStream);

                if (directPlay != null)
                {
                    playlistItem.PlayMethod = PlayMethod.DirectStream;
                    playlistItem.Container  = item.Container;

                    if (subtitleStream != null)
                    {
                        playlistItem.SubtitleDeliveryMethod = GetSubtitleDeliveryMethod(subtitleStream, options);
                    }

                    return(playlistItem);
                }
            }

            // Can't direct play, find the transcoding profile
            TranscodingProfile transcodingProfile = null;

            foreach (TranscodingProfile i in options.Profile.TranscodingProfiles)
            {
                if (i.Type == playlistItem.MediaType && i.Context == options.Context)
                {
                    transcodingProfile = i;
                    break;
                }
            }

            if (transcodingProfile != null)
            {
                if (subtitleStream != null)
                {
                    playlistItem.SubtitleDeliveryMethod = GetSubtitleDeliveryMethod(subtitleStream, options);
                }

                playlistItem.PlayMethod            = PlayMethod.Transcode;
                playlistItem.Container             = transcodingProfile.Container;
                playlistItem.EstimateContentLength = transcodingProfile.EstimateContentLength;
                playlistItem.TranscodeSeekInfo     = transcodingProfile.TranscodeSeekInfo;
                playlistItem.AudioCodec            = transcodingProfile.AudioCodec.Split(',')[0];
                playlistItem.VideoCodec            = transcodingProfile.VideoCodec;
                playlistItem.Protocol         = transcodingProfile.Protocol;
                playlistItem.AudioStreamIndex = audioStreamIndex;
                playlistItem.VideoProfile     = transcodingProfile.VideoProfile;

                List <ProfileCondition> videoTranscodingConditions = new List <ProfileCondition>();
                foreach (CodecProfile i in options.Profile.CodecProfiles)
                {
                    if (i.Type == CodecType.Video && i.ContainsCodec(transcodingProfile.VideoCodec))
                    {
                        foreach (ProfileCondition c in i.Conditions)
                        {
                            videoTranscodingConditions.Add(c);
                        }
                        break;
                    }
                }
                ApplyTranscodingConditions(playlistItem, videoTranscodingConditions);

                List <ProfileCondition> audioTranscodingConditions = new List <ProfileCondition>();
                foreach (CodecProfile i in options.Profile.CodecProfiles)
                {
                    if (i.Type == CodecType.VideoAudio && i.ContainsCodec(transcodingProfile.AudioCodec))
                    {
                        foreach (ProfileCondition c in i.Conditions)
                        {
                            audioTranscodingConditions.Add(c);
                        }
                        break;
                    }
                }
                ApplyTranscodingConditions(playlistItem, audioTranscodingConditions);

                // Honor requested max channels
                if (options.MaxAudioChannels.HasValue)
                {
                    int currentValue = playlistItem.MaxAudioChannels ?? options.MaxAudioChannels.Value;

                    playlistItem.MaxAudioChannels = Math.Min(options.MaxAudioChannels.Value, currentValue);
                }

                if (!playlistItem.AudioBitrate.HasValue)
                {
                    playlistItem.AudioBitrate = GetAudioBitrate(playlistItem.TargetAudioChannels, playlistItem.TargetAudioCodec);
                }

                // Honor max rate
                if (maxBitrateSetting.HasValue)
                {
                    int videoBitrate = maxBitrateSetting.Value;

                    if (playlistItem.AudioBitrate.HasValue)
                    {
                        videoBitrate -= playlistItem.AudioBitrate.Value;
                    }

                    int currentValue = playlistItem.VideoBitrate ?? videoBitrate;

                    playlistItem.VideoBitrate = Math.Min(videoBitrate, currentValue);
                }
            }

            return(playlistItem);
        }
Ejemplo n.º 20
0
        private bool IsSupported(DirectPlayProfile profile, Video item, MediaStream videoStream, MediaStream audioStream)
        {
            if (item.VideoType != VideoType.VideoFile)
            {
                return false;
            }

            var mediaPath = item.Path;

            if (profile.Container.Length > 0)
            {
                // Check container type
                var mediaContainer = Path.GetExtension(mediaPath);
                if (!profile.GetContainers().Any(i => string.Equals("." + i.TrimStart('.'), mediaContainer, StringComparison.OrdinalIgnoreCase)))
                {
                    return false;
                }
            }

            // Check video codec
            var videoCodecs = profile.GetVideoCodecs();
            if (videoCodecs.Count > 0)
            {
                var videoCodec = videoStream == null ? null : videoStream.Codec;
                if (string.IsNullOrWhiteSpace(videoCodec) || !videoCodecs.Contains(videoCodec, StringComparer.OrdinalIgnoreCase))
                {
                    return false;
                }
            }

            var audioCodecs = profile.GetAudioCodecs();
            if (audioCodecs.Count > 0)
            {
                // Check audio codecs
                var audioCodec = audioStream == null ? null : audioStream.Codec;
                if (string.IsNullOrWhiteSpace(audioCodec) || !audioCodecs.Contains(audioCodec, StringComparer.OrdinalIgnoreCase))
                {
                    return false;
                }
            }

            return true;
        }
Ejemplo n.º 21
0
        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;
            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, 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, 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);
        }
Ejemplo n.º 22
0
        private StreamInfo BuildAudioItem(MediaSourceInfo item, AudioOptions options)
        {
            StreamInfo playlistItem = new StreamInfo
            {
                ItemId       = options.ItemId,
                MediaType    = DlnaProfileType.Audio,
                MediaSource  = item,
                RunTimeTicks = item.RunTimeTicks,
                Context      = options.Context
            };

            int?maxBitrateSetting = options.GetMaxBitrate();

            MediaStream audioStream = item.DefaultAudioStream;

            // Honor the max bitrate setting
            if (IsAudioEligibleForDirectPlay(item, maxBitrateSetting))
            {
                DirectPlayProfile directPlay = null;
                foreach (DirectPlayProfile i in options.Profile.DirectPlayProfiles)
                {
                    if (i.Type == playlistItem.MediaType && IsAudioDirectPlaySupported(i, item, audioStream))
                    {
                        directPlay = i;
                        break;
                    }
                }

                if (directPlay != null)
                {
                    string audioCodec = audioStream == null ? null : audioStream.Codec;

                    // 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))
                            {
                                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))
                            {
                                all = false;
                                break;
                            }
                        }

                        if (all)
                        {
                            playlistItem.PlayMethod = PlayMethod.DirectStream;
                            playlistItem.Container  = item.Container;

                            return(playlistItem);
                        }
                    }
                }
            }

            TranscodingProfile transcodingProfile = null;

            foreach (TranscodingProfile i in options.Profile.TranscodingProfiles)
            {
                if (i.Type == playlistItem.MediaType && i.Context == options.Context)
                {
                    transcodingProfile = i;
                    break;
                }
            }

            if (transcodingProfile != null)
            {
                playlistItem.PlayMethod            = PlayMethod.Transcode;
                playlistItem.TranscodeSeekInfo     = transcodingProfile.TranscodeSeekInfo;
                playlistItem.EstimateContentLength = transcodingProfile.EstimateContentLength;
                playlistItem.Container             = transcodingProfile.Container;
                playlistItem.AudioCodec            = transcodingProfile.AudioCodec;
                playlistItem.Protocol = transcodingProfile.Protocol;

                List <CodecProfile> audioCodecProfiles = new List <CodecProfile>();
                foreach (CodecProfile i in options.Profile.CodecProfiles)
                {
                    if (i.Type == CodecType.Audio && i.ContainsCodec(transcodingProfile.AudioCodec))
                    {
                        audioCodecProfiles.Add(i);
                    }

                    if (audioCodecProfiles.Count >= 1)
                    {
                        break;
                    }
                }

                List <ProfileCondition> audioTranscodingConditions = new List <ProfileCondition>();
                foreach (CodecProfile i in audioCodecProfiles)
                {
                    foreach (ProfileCondition c in i.Conditions)
                    {
                        audioTranscodingConditions.Add(c);
                    }
                }

                ApplyTranscodingConditions(playlistItem, audioTranscodingConditions);

                // Honor requested max channels
                if (options.MaxAudioChannels.HasValue)
                {
                    int currentValue = playlistItem.MaxAudioChannels ?? options.MaxAudioChannels.Value;

                    playlistItem.MaxAudioChannels = Math.Min(options.MaxAudioChannels.Value, currentValue);
                }

                int configuredBitrate = options.AudioTranscodingBitrate ??
                                        (options.Context == EncodingContext.Static ? options.Profile.MusicSyncBitrate : options.Profile.MusicStreamingTranscodingBitrate) ??
                                        128000;

                playlistItem.AudioBitrate = Math.Min(configuredBitrate, playlistItem.AudioBitrate ?? configuredBitrate);
            }

            return(playlistItem);
        }