Exemple #1
0
        /// <summary>
        /// Builds the dlna URL.
        /// </summary>
        private static string BuildDlnaUrl(DeviceInfo deviceProperties, PlaylistItem item)
        {
            var usCulture = new CultureInfo("en-US");
            
            var list = new List<string>
            {
                item.DeviceProfileId ?? string.Empty,
                deviceProperties.UUID ?? string.Empty,
                item.MediaSourceId ?? string.Empty,
                (!item.Transcode).ToString().ToLower(),
                item.VideoCodec ?? string.Empty,
                item.AudioCodec ?? string.Empty,
                item.AudioStreamIndex.HasValue ? item.AudioStreamIndex.Value.ToString(usCulture) : string.Empty,
                item.SubtitleStreamIndex.HasValue ? item.SubtitleStreamIndex.Value.ToString(usCulture) : string.Empty,
                item.VideoBitrate.HasValue ? item.VideoBitrate.Value.ToString(usCulture) : string.Empty,
                item.AudioBitrate.HasValue ? item.AudioBitrate.Value.ToString(usCulture) : string.Empty,
                item.MaxAudioChannels.HasValue ? item.MaxAudioChannels.Value.ToString(usCulture) : string.Empty,
                item.MaxFramerate.HasValue ? item.MaxFramerate.Value.ToString(usCulture) : string.Empty,
                item.MaxWidth.HasValue ? item.MaxWidth.Value.ToString(usCulture) : string.Empty,
                item.MaxHeight.HasValue ? item.MaxHeight.Value.ToString(usCulture) : string.Empty,
                item.StartPositionTicks.ToString(usCulture),
                item.VideoLevel.HasValue ? item.VideoLevel.Value.ToString(usCulture) : string.Empty
            };

            return string.Format("Params={0}", string.Join(";", list.ToArray()));
        }
        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;
        }
        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;
        }
Exemple #4
0
        /// <summary>
        /// Gets the audio URL.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="serverAddress">The server address.</param>
        /// <returns>System.String.</returns>
        internal static string GetAudioUrl(PlaylistItem item, string serverAddress)
        {
            if (!item.Transcode)
                return string.Format("{0}/audio/{1}/stream.{2}?Static=True", serverAddress, item.ItemId, item.FileFormat);

            return string.Format("{0}/audio/{1}/stream.mp3?AudioCodec=Mp3", serverAddress, item.ItemId);
        }
Exemple #5
0
        /// <summary>
        /// Gets the dlna headers.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <returns></returns>
        internal static string GetDlnaHeaders(PlaylistItem item)
        {
            var orgOp = item.Transcode ? ";DLNA.ORG_OP=00" : ";DLNA.ORG_OP=01";

            var orgCi = item.Transcode ? ";DLNA.ORG_CI=0" : ";DLNA.ORG_CI=1";

            const string dlnaflags = ";DLNA.ORG_FLAGS=01500000000000000000000000000000";

            var contentFeatures = string.Empty;

            if (string.Equals(item.FileFormat, "mp3", StringComparison.OrdinalIgnoreCase))
            {
                contentFeatures = "DLNA.ORG_PN=MP3";
            }
            else if (string.Equals(item.FileFormat, "wma", StringComparison.OrdinalIgnoreCase))
            {
                contentFeatures = "DLNA.ORG_PN=WMABASE";
            }
            else if (string.Equals(item.FileFormat, "avi", StringComparison.OrdinalIgnoreCase))
            {
                contentFeatures = "DLNA.ORG_PN=AVI";
            }
            else if (string.Equals(item.FileFormat, "mkv", StringComparison.OrdinalIgnoreCase))
            {
                contentFeatures = "DLNA.ORG_PN=MATROSKA";
            }
            else if (string.Equals(item.FileFormat, "mp4", StringComparison.OrdinalIgnoreCase))
            {
                contentFeatures = "DLNA.ORG_PN=AVC_MP4_MP_HD_720p_AAC";
            }
            else if (string.Equals(item.FileFormat, "mpeg", StringComparison.OrdinalIgnoreCase))
            {
                contentFeatures = "DLNA.ORG_PN=MPEG_PS_PAL";
            }
            else if (string.Equals(item.FileFormat, "ts", StringComparison.OrdinalIgnoreCase))
            {
                contentFeatures = "DLNA.ORG_PN=MPEG_PS_PAL";
            }
            else if (item.IsVideo)
            {
                //Default to AVI for video
                contentFeatures = "DLNA.ORG_PN=AVI";
            }
            else
            {
                //Default to MP3 for audio
                contentFeatures = "DLNA.ORG_PN=MP3";
            }

            return (contentFeatures + orgOp + orgCi + dlnaflags).Trim(';');
        }
        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;
        }
Exemple #7
0
        /// <summary>
        /// Gets the video URL.
        /// </summary>
        /// <param name="deviceProperties">The device properties.</param>
        /// <param name="item">The item.</param>
        /// <param name="streams">The streams.</param>
        /// <param name="serverAddress">The server address.</param>
        /// <returns>The url to send to the device</returns>
        internal static string GetVideoUrl(DeviceInfo deviceProperties, PlaylistItem item, List<MediaStream> streams, string serverAddress)
        {
            var dlnaCommand = BuildDlnaUrl(deviceProperties, item);

            return string.Format("{0}/Videos/{1}/stream{2}?{3}", serverAddress, item.ItemId, item.Container, dlnaCommand);
        }
Exemple #8
0
        /// <summary>
        /// Gets the audio URL.
        /// </summary>
        /// <param name="deviceProperties">The device properties.</param>
        /// <param name="item">The item.</param>
        /// <param name="streams">The streams.</param>
        /// <param name="serverAddress">The server address.</param>
        /// <returns>System.String.</returns>
        internal static string GetAudioUrl(DeviceInfo deviceProperties, PlaylistItem item, List<MediaStream> streams, string serverAddress)
        {
            var dlnaCommand = BuildDlnaUrl(deviceProperties, item);

            return string.Format("{0}/audio/{1}/stream{2}?{3}", serverAddress, item.ItemId, "." + item.Container.TrimStart('.'), dlnaCommand);
        }
        public static PlaylistItem GetBasicConfig(BaseItem item, TranscodeSettings[] profileTranscodings)
        {
            var playlistItem = new PlaylistItem();

            playlistItem.ItemId = item.Id.ToString();

            if (string.Equals(item.MediaType, Model.Entities.MediaType.Video, StringComparison.OrdinalIgnoreCase))
            {
                playlistItem.IsVideo = true;
            }
            else
            {
                playlistItem.IsAudio = true;
            }


            var path = item.Path.ToLower();

            //Check the DlnaProfile associated with the renderer
            if (profileTranscodings != null)
            {
                foreach (TranscodeSettings transcodeSetting in profileTranscodings)
                {
                    if (string.IsNullOrWhiteSpace(transcodeSetting.Container))
                    {
                        continue;
                    }
                    if (path.EndsWith(transcodeSetting.Container))
                    {
                        playlistItem.Transcode  = true;
                        playlistItem.FileFormat = transcodeSetting.TargetContainer;
                        return(playlistItem);
                    }
                }
            }
            if (playlistItem.IsVideo)
            {
                //Check to see if we support serving the format statically
                foreach (string supported in PlayToConfiguration.SupportedStaticFormats)
                {
                    if (path.EndsWith(supported))
                    {
                        playlistItem.Transcode  = false;
                        playlistItem.FileFormat = supported;
                        return(playlistItem);
                    }
                }

                playlistItem.Transcode  = true;
                playlistItem.FileFormat = "ts";
            }
            else
            {
                foreach (string supported in PlayToConfiguration.SupportedStaticFormats)
                {
                    if (path.EndsWith(supported))
                    {
                        playlistItem.Transcode  = false;
                        playlistItem.FileFormat = supported;
                        return(playlistItem);
                    }
                }

                playlistItem.Transcode  = true;
                playlistItem.FileFormat = "mp3";
            }

            return(playlistItem);
        }
        private string GetDlnaHeaders(PlaylistItem item)
        {
            var profile = item.Profile;
            var streamInfo = item.StreamInfo;

            if (streamInfo.MediaType == DlnaProfileType.Audio)
            {
                return new ContentFeatureBuilder(profile)
                    .BuildAudioHeader(streamInfo.Container,
                    streamInfo.AudioCodec,
                    streamInfo.TargetAudioBitrate,
                    streamInfo.TargetAudioSampleRate,
                    streamInfo.TargetAudioChannels,
                    streamInfo.IsDirectStream,
                    streamInfo.RunTimeTicks,
                    streamInfo.TranscodeSeekInfo);
            }

            if (streamInfo.MediaType == DlnaProfileType.Video)
            {
                var list = new ContentFeatureBuilder(profile)
                    .BuildVideoHeader(streamInfo.Container,
                    streamInfo.VideoCodec,
                    streamInfo.AudioCodec,
                    streamInfo.TargetWidth,
                    streamInfo.TargetHeight,
                    streamInfo.TargetVideoBitDepth,
                    streamInfo.TargetVideoBitrate,
                    streamInfo.TargetAudioChannels,
                    streamInfo.TargetAudioBitrate,
                    streamInfo.TargetTimestamp,
                    streamInfo.IsDirectStream,
                    streamInfo.RunTimeTicks,
                    streamInfo.TargetVideoProfile,
                    streamInfo.TargetVideoLevel,
                    streamInfo.TargetFramerate,
                    streamInfo.TargetPacketLength,
                    streamInfo.TranscodeSeekInfo,
                    streamInfo.IsTargetAnamorphic,
                    streamInfo.TargetRefFrames);

                return list.FirstOrDefault();
            }

            return null;
        }
        private void ApplyTranscodingConditions(PlaylistItem item, IEnumerable<ProfileCondition> conditions)
        {
            foreach (var condition in conditions
                .Where(i => !string.IsNullOrEmpty(i.Value)))
            {
                var value = condition.Value;

                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:
                    case ProfileConditionValue.VideoBitDepth:
                    case ProfileConditionValue.VideoProfile:
                    {
                        // Not supported yet
                        break;
                    }
                    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");
                }
            }
        }
        private string GetDlnaHeaders(PlaylistItem item)
        {
            var streamInfo = item.StreamInfo;

            var orgOp = !streamInfo.IsDirectStream ? ";DLNA.ORG_OP=00" : ";DLNA.ORG_OP=01";

            var orgCi = !streamInfo.IsDirectStream ? ";DLNA.ORG_CI=0" : ";DLNA.ORG_CI=1";

            const string dlnaflags = ";DLNA.ORG_FLAGS=01500000000000000000000000000000";

            string contentFeatures;

            var container = streamInfo.Container.TrimStart('.');

            if (string.Equals(container, "mp3", StringComparison.OrdinalIgnoreCase))
            {
                contentFeatures = "DLNA.ORG_PN=MP3";
            }
            else if (string.Equals(container, "wma", StringComparison.OrdinalIgnoreCase))
            {
                contentFeatures = "DLNA.ORG_PN=WMABASE";
            }
            else if (string.Equals(container, "wmw", StringComparison.OrdinalIgnoreCase))
            {
                contentFeatures = "DLNA.ORG_PN=WMVMED_BASE";
            }
            else if (string.Equals(container, "asf", StringComparison.OrdinalIgnoreCase))
            {
                contentFeatures = "DLNA.ORG_PN=WMVMED_BASE";
            }
            else if (string.Equals(container, "avi", StringComparison.OrdinalIgnoreCase))
            {
                contentFeatures = "DLNA.ORG_PN=AVI";
            }
            else if (string.Equals(container, "mkv", StringComparison.OrdinalIgnoreCase))
            {
                contentFeatures = "DLNA.ORG_PN=MATROSKA";
            }
            else if (string.Equals(container, "mp4", StringComparison.OrdinalIgnoreCase))
            {
                contentFeatures = "DLNA.ORG_PN=AVC_MP4_MP_HD_720p_AAC";
            }
            else if (string.Equals(container, "mpeg", StringComparison.OrdinalIgnoreCase))
            {
                contentFeatures = "DLNA.ORG_PN=MPEG_PS_PAL";
            }
            else if (string.Equals(container, "ts", StringComparison.OrdinalIgnoreCase))
            {
                contentFeatures = "DLNA.ORG_PN=MPEG_PS_PAL";
            }
            else if (streamInfo.MediaType == DlnaProfileType.Video)
            {
                // Default to AVI for video
                contentFeatures = "DLNA.ORG_PN=AVI";
            }
            else
            {
                // Default to MP3 for audio
                contentFeatures = "DLNA.ORG_PN=MP3";
            }

            return (contentFeatures + orgOp + orgCi + dlnaflags).Trim(';');
        }
Exemple #13
0
        /// <summary>
        /// Gets the video URL.
        /// </summary>
        /// <param name="deviceProperties">The device properties.</param>
        /// <param name="item">The item.</param>
        /// <param name="streams">The streams.</param>
        /// <param name="serverAddress">The server address.</param>
        /// <returns>The url to send to the device</returns>
        internal static string GetVideoUrl(DeviceProperties deviceProperties, PlaylistItem item, List<MediaStream> streams, string serverAddress)
        {
            if (!item.Transcode)
                return string.Format("{0}/Videos/{1}/stream.{2}?Static=True", serverAddress, item.ItemId, item.FileFormat);

            var videostream = streams.Where(m => m.Type == MediaStreamType.Video).OrderBy(m => m.IsDefault).FirstOrDefault();
            var audiostream = streams.Where(m => m.Type == MediaStreamType.Audio).OrderBy(m => m.IsDefault).FirstOrDefault();

            var videoCodec = GetVideoCodec(videostream);
            var audioCodec = GetAudioCodec(audiostream);
            int? videoBitrate = null;
            int? audioBitrate = null;
            int? audioChannels = null;

            if (videoCodec != VideoCodecs.Copy)
                videoBitrate = 2000000;

            if (audioCodec != AudioCodecs.Copy)
            {
                audioBitrate = 128000;
                audioChannels = 2;
            }

            string dlnaCommand = BuildDlnaUrl(deviceProperties.UUID, videoCodec, audioCodec, null, null, videoBitrate, audioChannels, audioBitrate, item.StartPositionTicks, "baseline", "3");
            return string.Format("{0}/Videos/{1}/stream.{2}?{3}", serverAddress, item.ItemId, item.FileFormat, dlnaCommand);
        }
Exemple #14
0
        public static PlaylistItem GetBasicConfig(BaseItem item, TranscodeSettings[] profileTranscodings)
        {

            var playlistItem = new PlaylistItem();
            playlistItem.ItemId = item.Id.ToString();

            if (string.Equals(item.MediaType, Model.Entities.MediaType.Video, StringComparison.OrdinalIgnoreCase))
            {
                playlistItem.IsVideo = true;
            }
            else
            {
                playlistItem.IsAudio = true;
            }


            var path = item.Path.ToLower();

            //Check the DlnaProfile associated with the renderer
            if (profileTranscodings != null)
            {
                foreach (TranscodeSettings transcodeSetting in profileTranscodings)
                {
                    if (string.IsNullOrWhiteSpace(transcodeSetting.Container))
                        continue;
                    if (path.EndsWith(transcodeSetting.Container))
                    {
                        playlistItem.Transcode = true;
                        playlistItem.FileFormat = transcodeSetting.TargetContainer;
                        return playlistItem;
                    }
                }
            }
            if (playlistItem.IsVideo)
            {

                //Check to see if we support serving the format statically
                foreach (string supported in PlayToConfiguration.SupportedStaticFormats)
                {
                    if (path.EndsWith(supported))
                    {
                        playlistItem.Transcode = false;
                        playlistItem.FileFormat = supported;
                        return playlistItem;
                    }
                }

                playlistItem.Transcode = true;
                playlistItem.FileFormat = "ts";
            }
            else
            {
                foreach (string supported in PlayToConfiguration.SupportedStaticFormats)
                {
                    if (path.EndsWith(supported))
                    {
                        playlistItem.Transcode = false;
                        playlistItem.FileFormat = supported;
                        return playlistItem;
                    }
                }

                playlistItem.Transcode = true;
                playlistItem.FileFormat = "mp3";
            }

            return playlistItem;
        }