コード例 #1
0
        public string BuildImageHeader(string container,
                                       int?width,
                                       int?height)
        {
            string orgOp = ";DLNA.ORG_OP=" + DlnaMaps.GetImageOrgOpValue();

            // 0 = native, 1 = transcoded
            const string orgCi = ";DLNA.ORG_CI=0";

            DlnaFlags flagValue = DlnaFlags.StreamingTransferMode |
                                  DlnaFlags.BackgroundTransferMode |
                                  DlnaFlags.DlnaV15;

            string dlnaflags = string.Format(";DLNA.ORG_FLAGS={0}",
                                             DlnaMaps.FlagsToString(flagValue));

            ResponseProfile mediaProfile = _profile.GetImageMediaProfile(container,
                                                                         width,
                                                                         height);

            string orgPn = mediaProfile == null ? null : mediaProfile.OrgPn;

            if (string.IsNullOrEmpty(orgPn))
            {
                orgPn = GetImageOrgPnValue(container, width, height);
            }

            string contentFeatures = string.IsNullOrEmpty(orgPn) ? string.Empty : "DLNA.ORG_PN=" + orgPn;

            return((contentFeatures + orgOp + orgCi + dlnaflags).Trim(';'));
        }
コード例 #2
0
        public string BuildAudioHeader(string container,
                                       string audioCodec,
                                       int?audioBitrate,
                                       int?audioSampleRate,
                                       int?audioChannels,
                                       int?audioBitDepth,
                                       bool isDirectStream,
                                       long?runtimeTicks,
                                       TranscodeSeekInfo transcodeSeekInfo)
        {
            // first bit means Time based seek supported, second byte range seek supported (not sure about the order now), so 01 = only byte seek, 10 = time based, 11 = both, 00 = none
            string orgOp = ";DLNA.ORG_OP=" + DlnaMaps.GetOrgOpValue(runtimeTicks.HasValue, isDirectStream, transcodeSeekInfo);

            // 0 = native, 1 = transcoded
            string orgCi = isDirectStream ? ";DLNA.ORG_CI=0" : ";DLNA.ORG_CI=1";

            DlnaFlags flagValue = DlnaFlags.StreamingTransferMode |
                                  DlnaFlags.BackgroundTransferMode |
                                  DlnaFlags.InteractiveTransferMode |
                                  DlnaFlags.DlnaV15;

            //if (isDirectStream)
            //{
            //    flagValue = flagValue | DlnaFlags.ByteBasedSeek;
            //}
            //else if (runtimeTicks.HasValue)
            //{
            //    flagValue = flagValue | DlnaFlags.TimeBasedSeek;
            //}

            string dlnaflags = string.Format(";DLNA.ORG_FLAGS={0}",
                                             DlnaMaps.FlagsToString(flagValue));

            ResponseProfile mediaProfile = _profile.GetAudioMediaProfile(container,
                                                                         audioCodec,
                                                                         audioChannels,
                                                                         audioBitrate,
                                                                         audioSampleRate,
                                                                         audioBitDepth);

            string orgPn = mediaProfile == null ? null : mediaProfile.OrgPn;

            if (string.IsNullOrEmpty(orgPn))
            {
                orgPn = GetAudioOrgPnValue(container, audioBitrate, audioSampleRate, audioChannels);
            }

            string contentFeatures = string.IsNullOrEmpty(orgPn) ? string.Empty : "DLNA.ORG_PN=" + orgPn;

            return((contentFeatures + orgOp + orgCi + dlnaflags).Trim(';'));
        }
コード例 #3
0
        /// <summary>
        /// Builds a image header.
        /// </summary>
        /// <param name="profile">A <see cref="DeviceProfile"/>.</param>
        /// <param name="container">The container.</param>
        /// <param name="width">Optional width.</param>
        /// <param name="height">Optional height.</param>
        /// <param name="isDirectStream">True if the image is via direct stream.</param>
        /// <param name="orgPn">Optional organisation.</param>
        /// <returns>A string representation.</returns>
        public static string BuildImageHeader(
            DeviceProfile profile,
            string container,
            int?width,
            int?height,
            bool isDirectStream,
            string?orgPn = null)
        {
            if (profile == null)
            {
                throw new ArgumentNullException(nameof(profile));
            }

            string orgOp = ";DLNA.ORG_OP=" + DlnaMaps.GetImageOrgOpValue();

            // 0 = native, 1 = transcoded
            var orgCi = isDirectStream ? ";DLNA.ORG_CI=0" : ";DLNA.ORG_CI=1";

            const DlnaFlags FlagValue = DlnaFlags.BackgroundTransferMode |
                                        DlnaFlags.InteractiveTransferMode |
                                        DlnaFlags.DlnaV15;

            string dlnaflags = string.Format(
                CultureInfo.InvariantCulture,
                ";DLNA.ORG_FLAGS={0}",
                DlnaMaps.FlagsToString(FlagValue));

            if (string.IsNullOrEmpty(orgPn))
            {
                var mediaProfile = profile.GetImageMediaProfile(
                    container,
                    width,
                    height);

                orgPn = mediaProfile?.OrgPn;

                if (string.IsNullOrEmpty(orgPn))
                {
                    orgPn = GetImageOrgPnValue(container, width, height);
                }
            }

            if (string.IsNullOrEmpty(orgPn))
            {
                return(orgOp.TrimStart(';') + orgCi + dlnaflags);
            }

            return("DLNA.ORG_PN=" + orgPn + orgOp + orgCi + dlnaflags);
        }
コード例 #4
0
        public List <string> BuildVideoHeader(string container,
                                              string videoCodec,
                                              string audioCodec,
                                              int?width,
                                              int?height,
                                              int?bitDepth,
                                              int?videoBitrate,
                                              TransportStreamTimestamp timestamp,
                                              bool isDirectStream,
                                              long?runtimeTicks,
                                              string videoProfile,
                                              double?videoLevel,
                                              float?videoFramerate,
                                              int?packetLength,
                                              TranscodeSeekInfo transcodeSeekInfo,
                                              bool?isAnamorphic,
                                              bool?isInterlaced,
                                              int?refFrames,
                                              int?numVideoStreams,
                                              int?numAudioStreams,
                                              string videoCodecTag,
                                              bool?isAvc)
        {
            // first bit means Time based seek supported, second byte range seek supported (not sure about the order now), so 01 = only byte seek, 10 = time based, 11 = both, 00 = none
            string orgOp = ";DLNA.ORG_OP=" + DlnaMaps.GetOrgOpValue(runtimeTicks.HasValue, isDirectStream, transcodeSeekInfo);

            // 0 = native, 1 = transcoded
            string orgCi = isDirectStream ? ";DLNA.ORG_CI=0" : ";DLNA.ORG_CI=1";

            DlnaFlags flagValue = DlnaFlags.StreamingTransferMode |
                                  DlnaFlags.BackgroundTransferMode |
                                  DlnaFlags.InteractiveTransferMode |
                                  DlnaFlags.DlnaV15;

            //if (isDirectStream)
            //{
            //    flagValue = flagValue | DlnaFlags.ByteBasedSeek;
            //}
            //else if (runtimeTicks.HasValue)
            //{
            //    flagValue = flagValue | DlnaFlags.TimeBasedSeek;
            //}

            string dlnaflags = string.Format(";DLNA.ORG_FLAGS={0}",
                                             DlnaMaps.FlagsToString(flagValue));

            ResponseProfile mediaProfile = _profile.GetVideoMediaProfile(container,
                                                                         audioCodec,
                                                                         videoCodec,
                                                                         width,
                                                                         height,
                                                                         bitDepth,
                                                                         videoBitrate,
                                                                         videoProfile,
                                                                         videoLevel,
                                                                         videoFramerate,
                                                                         packetLength,
                                                                         timestamp,
                                                                         isAnamorphic,
                                                                         isInterlaced,
                                                                         refFrames,
                                                                         numVideoStreams,
                                                                         numAudioStreams,
                                                                         videoCodecTag,
                                                                         isAvc);

            List <string> orgPnValues = new List <string>();

            if (mediaProfile != null && !string.IsNullOrEmpty(mediaProfile.OrgPn))
            {
                orgPnValues.AddRange(mediaProfile.OrgPn.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries));
            }
            else
            {
                foreach (string s in GetVideoOrgPnValue(container, videoCodec, audioCodec, width, height, timestamp))
                {
                    orgPnValues.Add(s);
                    break;
                }
            }

            List <string> contentFeatureList = new List <string>();

            foreach (string orgPn in orgPnValues)
            {
                string contentFeatures = string.IsNullOrEmpty(orgPn) ? string.Empty : "DLNA.ORG_PN=" + orgPn;

                var value = (contentFeatures + orgOp + orgCi + dlnaflags).Trim(';');

                contentFeatureList.Add(value);
            }

            if (orgPnValues.Count == 0)
            {
                string contentFeatures = string.Empty;

                var value = (contentFeatures + orgOp + orgCi + dlnaflags).Trim(';');

                contentFeatureList.Add(value);
            }

            return(contentFeatureList);
        }
コード例 #5
0
ファイル: DlnaMaps.cs プロジェクト: jindal1979/roadie
 internal static string FlagsToString(DlnaFlags flags)
 {
     return($"{(ulong)flags:X8}{0:D24}");
 }
コード例 #6
0
 public static string FlagsToString(DlnaFlags flags)
 {
     return(string.Format(CultureInfo.InvariantCulture, "{0:X8}{1:D24}", (ulong)flags, 0));
 }
コード例 #7
0
ファイル: DlnaMaps.cs プロジェクト: vitska/simpleDLNA
 internal static string FlagsToString(DlnaFlags flags)
 {
     return(string.Format("{0:X8}{1:D24}", (ulong)flags, 0));
 }
コード例 #8
0
ファイル: DlnaMaps.cs プロジェクト: rodionovstepan/simpleDLNA
 internal static string FlagsToString(DlnaFlags flags)
 {
     return string.Format("{0:X8}{1:D24}", (ulong)flags, 0);
 }
コード例 #9
0
ファイル: DlnaMaps.cs プロジェクト: nmaier/simpleDLNA
 internal static string FlagsToString(DlnaFlags flags)
 {
     return $"{(ulong)flags:X8}{0:D24}";
 }
コード例 #10
0
        public string BuildVideoHeader(string container,
                                       string videoCodec,
                                       string audioCodec,
                                       int?width,
                                       int?height,
                                       int?bitDepth,
                                       int?videoBitrate,
                                       int?audioChannels,
                                       int?audioBitrate,
                                       TransportStreamTimestamp timestamp,
                                       bool isDirectStream,
                                       long?runtimeTicks,
                                       string videoProfile,
                                       double?videoLevel,
                                       double?videoFramerate,
                                       int?packetLength,
                                       TranscodeSeekInfo transcodeSeekInfo)
        {
            // first bit means Time based seek supported, second byte range seek supported (not sure about the order now), so 01 = only byte seek, 10 = time based, 11 = both, 00 = none
            string orgOp = ";DLNA.ORG_OP=" + DlnaMaps.GetOrgOpValue(runtimeTicks.HasValue, isDirectStream, transcodeSeekInfo);

            // 0 = native, 1 = transcoded
            string orgCi = isDirectStream ? ";DLNA.ORG_CI=0" : ";DLNA.ORG_CI=1";

            DlnaFlags flagValue = DlnaFlags.StreamingTransferMode |
                                  DlnaFlags.BackgroundTransferMode |
                                  DlnaFlags.DlnaV15;

            if (isDirectStream)
            {
                //flagValue = flagValue | DlnaFlags.DLNA_ORG_FLAG_BYTE_BASED_SEEK;
            }
            else if (runtimeTicks.HasValue)
            {
                //flagValue = flagValue | DlnaFlags.DLNA_ORG_FLAG_TIME_BASED_SEEK;
            }

            string dlnaflags = string.Format(";DLNA.ORG_FLAGS={0}",
                                             DlnaMaps.FlagsToString(flagValue));

            ResponseProfile mediaProfile = _profile.GetVideoMediaProfile(container,
                                                                         audioCodec,
                                                                         videoCodec,
                                                                         audioBitrate,
                                                                         audioChannels,
                                                                         width,
                                                                         height,
                                                                         bitDepth,
                                                                         videoBitrate,
                                                                         videoProfile,
                                                                         videoLevel,
                                                                         videoFramerate,
                                                                         packetLength,
                                                                         timestamp);

            string orgPn = mediaProfile == null ? null : mediaProfile.OrgPn;

            if (string.IsNullOrEmpty(orgPn))
            {
                foreach (string s in GetVideoOrgPnValue(container, videoCodec, audioCodec, width, height, timestamp))
                {
                    orgPn = s;
                    break;
                }
            }

            if (string.IsNullOrEmpty(orgPn))
            {
                // TODO: Support multiple values and return multiple headers?
                foreach (string s in (orgPn ?? string.Empty).Split(','))
                {
                    orgPn = s;
                    break;
                }
            }

            string contentFeatures = string.IsNullOrEmpty(orgPn) ? string.Empty : "DLNA.ORG_PN=" + orgPn;

            return((contentFeatures + orgOp + orgCi + dlnaflags).Trim(';'));
        }
コード例 #11
0
 private static string FlagsToString(DlnaFlags flags)
 {
     //return Enum.Format(typeof(DlnaFlags), flags, "x");
     return(string.Format("{0:X8}{1:D24}", (ulong)flags, 0));
 }
コード例 #12
0
        /// <summary>
        /// Builds an audio header.
        /// </summary>
        /// <param name="profile">A <see cref="DeviceProfile"/>.</param>
        /// <param name="container">The container.</param>
        /// <param name="audioCodec">The audio codec.</param>
        /// <param name="audioBitrate">Optional. The audio bitrate.</param>
        /// <param name="audioSampleRate">Optional. The sample audio rate.</param>
        /// <param name="audioChannels">Optional. The number of audio channels.</param>
        /// <param name="audioBitDepth">Optional. The audio bit depth.</param>
        /// <param name="isDirectStream">True if being accessed by audio stream.</param>
        /// <param name="runtimeTicks">Optional. The runtime ticks.</param>
        /// <param name="transcodeSeekInfo">An instance of <see cref="TranscodeSeekInfo"/>.</param>
        /// <returns>A string representation.</returns>
        public static string BuildAudioHeader(
            DeviceProfile profile,
            string container,
            string?audioCodec,
            int?audioBitrate,
            int?audioSampleRate,
            int?audioChannels,
            int?audioBitDepth,
            bool isDirectStream,
            long?runtimeTicks,
            TranscodeSeekInfo transcodeSeekInfo)
        {
            if (profile == null)
            {
                throw new ArgumentNullException(nameof(profile));
            }

            // first bit means Time based seek supported, second byte range seek supported (not sure about the order now), so 01 = only byte seek, 10 = time based, 11 = both, 00 = none
            string orgOp = ";DLNA.ORG_OP=" + DlnaMaps.GetOrgOpValue(runtimeTicks > 0, isDirectStream, transcodeSeekInfo);

            // 0 = native, 1 = transcoded
            string orgCi = isDirectStream ? ";DLNA.ORG_CI=0" : ";DLNA.ORG_CI=1";

            const DlnaFlags FlagValue = DlnaFlags.StreamingTransferMode |
                                        DlnaFlags.BackgroundTransferMode |
                                        DlnaFlags.InteractiveTransferMode |
                                        DlnaFlags.DlnaV15;

            // if (isDirectStream)
            // {
            //     flagValue = flagValue | DlnaFlags.ByteBasedSeek;
            // }
            //  else if (runtimeTicks.HasValue)
            // {
            //     flagValue = flagValue | DlnaFlags.TimeBasedSeek;
            // }

            string dlnaflags = string.Format(
                CultureInfo.InvariantCulture,
                ";DLNA.ORG_FLAGS={0}",
                DlnaMaps.FlagsToString(FlagValue));

            var mediaProfile = profile.GetAudioMediaProfile(
                container,
                audioCodec,
                audioChannels,
                audioBitrate,
                audioSampleRate,
                audioBitDepth);

            var orgPn = mediaProfile?.OrgPn;

            if (string.IsNullOrEmpty(orgPn))
            {
                orgPn = GetAudioOrgPnValue(container, audioBitrate, audioSampleRate, audioChannels);
            }

            if (string.IsNullOrEmpty(orgPn))
            {
                return(orgOp.TrimStart(';') + orgCi + dlnaflags);
            }

            return("DLNA.ORG_PN=" + orgPn + orgOp + orgCi + dlnaflags);
        }