public MediaFormatProfile ResolveVideoFormat(string container, string videoCodec, string audioCodec, int? width, int? height, int? bitrate, TransportStreamTimestamp timestampType)
        {
            if (string.Equals(container, "asf", StringComparison.OrdinalIgnoreCase))
                return ResolveVideoASFFormat(videoCodec, audioCodec, width, height, bitrate);
            if (string.Equals(container, "mp4", StringComparison.OrdinalIgnoreCase))
                return ResolveVideoMP4Format(videoCodec, audioCodec, width, height, bitrate);
            if (string.Equals(container, "avi", StringComparison.OrdinalIgnoreCase))
                return MediaFormatProfile.AVI;
            if (string.Equals(container, "mkv", StringComparison.OrdinalIgnoreCase))
                return MediaFormatProfile.MATROSKA;
            if (string.Equals(container, "mpeg2ps", StringComparison.OrdinalIgnoreCase) || string.Equals(container, "ts", StringComparison.OrdinalIgnoreCase))
                // MediaFormatProfile.MPEG_PS_PAL, MediaFormatProfile.MPEG_PS_NTSC
                return MediaFormatProfile.MPEG_PS_NTSC;
            if (string.Equals(container, "mpeg1video", StringComparison.OrdinalIgnoreCase))
                return MediaFormatProfile.MPEG1;
            if (string.Equals(container, "mpeg2ts", StringComparison.OrdinalIgnoreCase) || string.Equals(container, "mpegts", StringComparison.OrdinalIgnoreCase) || string.Equals(container, "m2ts", StringComparison.OrdinalIgnoreCase))
                return ResolveVideoMPEG2TSFormat(videoCodec, audioCodec, width, height, bitrate, timestampType);
            if (string.Equals(container, "flv", StringComparison.OrdinalIgnoreCase))
                return MediaFormatProfile.FLV;
            if (string.Equals(container, "wtv", StringComparison.OrdinalIgnoreCase))
                return MediaFormatProfile.WTV;
            if (string.Equals(container, "3gp", StringComparison.OrdinalIgnoreCase))
                return ResolveVideo3GPFormat(videoCodec, audioCodec, width, height, bitrate);
            if (string.Equals(container, "ogv", StringComparison.OrdinalIgnoreCase) || string.Equals(container, "ogg", StringComparison.OrdinalIgnoreCase))
                return MediaFormatProfile.OGV;

            throw new ArgumentException("Unsupported container: " + container);
        }
Ejemplo n.º 2
0
        public ResponseProfile GetVideoMediaProfile(string container,
                                                    string audioCodec,
                                                    string videoCodec,
                                                    int?audioBitrate,
                                                    int?audioChannels,
                                                    int?width,
                                                    int?height,
                                                    int?bitDepth,
                                                    int?videoBitrate,
                                                    string videoProfile,
                                                    double?videoLevel,
                                                    double?videoFramerate,
                                                    int?packetLength,
                                                    TransportStreamTimestamp timestamp)
        {
            container = (container ?? string.Empty).TrimStart('.');

            return(ResponseProfiles.FirstOrDefault(i =>
            {
                if (i.Type != DlnaProfileType.Video)
                {
                    return false;
                }

                var containers = i.GetContainers().ToList();
                if (containers.Count > 0 && !containers.Contains(container))
                {
                    return false;
                }

                var audioCodecs = i.GetAudioCodecs().ToList();
                if (audioCodecs.Count > 0 && !audioCodecs.Contains(audioCodec ?? string.Empty))
                {
                    return false;
                }

                var videoCodecs = i.GetVideoCodecs().ToList();
                if (videoCodecs.Count > 0 && !videoCodecs.Contains(videoCodec ?? string.Empty))
                {
                    return false;
                }

                var conditionProcessor = new ConditionProcessor();
                return i.Conditions.All(c => conditionProcessor.IsVideoConditionSatisfied(c,
                                                                                          audioBitrate,
                                                                                          audioChannels,
                                                                                          width,
                                                                                          height,
                                                                                          bitDepth,
                                                                                          videoBitrate,
                                                                                          videoProfile,
                                                                                          videoLevel,
                                                                                          videoFramerate,
                                                                                          packetLength,
                                                                                          timestamp));
            }));
        }
Ejemplo n.º 3
0
 public bool IsVideoConditionSatisfied(ProfileCondition condition,
     int? width,
     int? height,
     int? bitDepth,
     int? videoBitrate,
     string videoProfile,
     double? videoLevel,
     float? videoFramerate,
     int? packetLength,
     TransportStreamTimestamp? timestamp,
     bool? isAnamorphic,
     bool? isCabac,
     int? refFrames,
     int? numVideoStreams,
     int? numAudioStreams)
 {
     switch (condition.Property)
     {
         case ProfileConditionValue.AudioProfile:
             // TODO: Implement
             return true;
         case ProfileConditionValue.Has64BitOffsets:
             // TODO: Implement
             return true;
         case ProfileConditionValue.IsAnamorphic:
             return IsConditionSatisfied(condition, isAnamorphic);
         case ProfileConditionValue.IsCabac:
             return IsConditionSatisfied(condition, isCabac);
         case ProfileConditionValue.VideoFramerate:
             return IsConditionSatisfied(condition, videoFramerate);
         case ProfileConditionValue.VideoLevel:
             return IsConditionSatisfied(condition, videoLevel);
         case ProfileConditionValue.VideoProfile:
             return IsConditionSatisfied(condition, videoProfile);
         case ProfileConditionValue.PacketLength:
             return IsConditionSatisfied(condition, packetLength);
         case ProfileConditionValue.VideoBitDepth:
             return IsConditionSatisfied(condition, bitDepth);
         case ProfileConditionValue.VideoBitrate:
             return IsConditionSatisfied(condition, videoBitrate);
         case ProfileConditionValue.Height:
             return IsConditionSatisfied(condition, height);
         case ProfileConditionValue.Width:
             return IsConditionSatisfied(condition, width);
         case ProfileConditionValue.RefFrames:
             return IsConditionSatisfied(condition, refFrames);
         case ProfileConditionValue.NumAudioStreams:
             return IsConditionSatisfied(condition, numAudioStreams);
         case ProfileConditionValue.NumVideoStreams:
             return IsConditionSatisfied(condition, numVideoStreams);
         case ProfileConditionValue.VideoTimestamp:
             return IsConditionSatisfied(condition, timestamp);
         default:
             throw new ArgumentException("Unexpected condition on video file: " + condition.Property);
     }
 }
        public List<MediaFormatProfile> ResolveVideoFormat(string container, string videoCodec, string audioCodec, int? width, int? height, TransportStreamTimestamp timestampType)
        {
            if (StringHelper.EqualsIgnoreCase(container, "asf"))
            {
                MediaFormatProfile? val = ResolveVideoASFFormat(videoCodec, audioCodec, width, height);
                return val.HasValue ? new List<MediaFormatProfile> { val.Value } : new List<MediaFormatProfile>();
            }

            if (StringHelper.EqualsIgnoreCase(container, "mp4"))
            {
                MediaFormatProfile? val = ResolveVideoMP4Format(videoCodec, audioCodec, width, height);
                return val.HasValue ? new List<MediaFormatProfile> { val.Value } : new List<MediaFormatProfile>();
            }

            if (StringHelper.EqualsIgnoreCase(container, "avi"))
                return new List<MediaFormatProfile> { MediaFormatProfile.AVI };

            if (StringHelper.EqualsIgnoreCase(container, "mkv"))
                return new List<MediaFormatProfile> { MediaFormatProfile.MATROSKA };

            if (StringHelper.EqualsIgnoreCase(container, "mpeg2ps") ||
                StringHelper.EqualsIgnoreCase(container, "ts"))

                return new List<MediaFormatProfile> { MediaFormatProfile.MPEG_PS_NTSC, MediaFormatProfile.MPEG_PS_PAL };

            if (StringHelper.EqualsIgnoreCase(container, "mpeg1video"))
                return new List<MediaFormatProfile> { MediaFormatProfile.MPEG1 };

            if (StringHelper.EqualsIgnoreCase(container, "mpeg2ts") ||
                StringHelper.EqualsIgnoreCase(container, "mpegts") ||
                StringHelper.EqualsIgnoreCase(container, "m2ts"))
            {

                return ResolveVideoMPEG2TSFormat(videoCodec, audioCodec, width, height, timestampType);
            }

            if (StringHelper.EqualsIgnoreCase(container, "flv"))
                return new List<MediaFormatProfile> { MediaFormatProfile.FLV };

            if (StringHelper.EqualsIgnoreCase(container, "wtv"))
                return new List<MediaFormatProfile> { MediaFormatProfile.WTV };

            if (StringHelper.EqualsIgnoreCase(container, "3gp"))
            {
                MediaFormatProfile? val = ResolveVideo3GPFormat(videoCodec, audioCodec);
                return val.HasValue ? new List<MediaFormatProfile> { val.Value } : new List<MediaFormatProfile>();
            }

            if (StringHelper.EqualsIgnoreCase(container, "ogv") || StringHelper.EqualsIgnoreCase(container, "ogg"))
                return new List<MediaFormatProfile> { MediaFormatProfile.OGV };

            return new List<MediaFormatProfile>();
        }
Ejemplo n.º 5
0
 public bool IsVideoConditionSatisfied(ProfileCondition condition,
     int? width,
     int? height,
     int? bitDepth,
     int? videoBitrate,
     string videoProfile,
     double? videoLevel,
     float? videoFramerate,
     int? packetLength,
     TransportStreamTimestamp? timestamp,
     bool? isAnamorphic,
     bool? isCabac,
     int? refFrames,
     int? numVideoStreams,
     int? numAudioStreams,
     string videoCodecTag)
 {
     switch (condition.Property)
     {
         case ProfileConditionValue.IsAnamorphic:
             return IsConditionSatisfied(condition, isAnamorphic);
         case ProfileConditionValue.IsCabac:
             return IsConditionSatisfied(condition, isCabac);
         case ProfileConditionValue.VideoFramerate:
             return IsConditionSatisfied(condition, videoFramerate);
         case ProfileConditionValue.VideoLevel:
             return IsConditionSatisfied(condition, videoLevel);
         case ProfileConditionValue.VideoProfile:
             return IsConditionSatisfied(condition, videoProfile);
         case ProfileConditionValue.VideoCodecTag:
             return IsConditionSatisfied(condition, videoCodecTag);
         case ProfileConditionValue.PacketLength:
             return IsConditionSatisfied(condition, packetLength);
         case ProfileConditionValue.VideoBitDepth:
             return IsConditionSatisfied(condition, bitDepth);
         case ProfileConditionValue.VideoBitrate:
             return IsConditionSatisfied(condition, videoBitrate);
         case ProfileConditionValue.Height:
             return IsConditionSatisfied(condition, height);
         case ProfileConditionValue.Width:
             return IsConditionSatisfied(condition, width);
         case ProfileConditionValue.RefFrames:
             return IsConditionSatisfied(condition, refFrames);
         case ProfileConditionValue.NumAudioStreams:
             return IsConditionSatisfied(condition, numAudioStreams);
         case ProfileConditionValue.NumVideoStreams:
             return IsConditionSatisfied(condition, numVideoStreams);
         case ProfileConditionValue.VideoTimestamp:
             return IsConditionSatisfied(condition, timestamp);
         default:
             return true;
     }
 }
Ejemplo n.º 6
0
        private bool IsConditionSatisfied(ProfileCondition condition, TransportStreamTimestamp?timestamp)
        {
            if (!timestamp.HasValue)
            {
                // If the value is unknown, it satisfies if not marked as required
                return(!condition.IsRequired);
            }

            TransportStreamTimestamp expected = (TransportStreamTimestamp)Enum.Parse(typeof(TransportStreamTimestamp), condition.Value, true);

            switch (condition.Condition)
            {
            case ProfileConditionType.Equals:
                return(timestamp == expected);

            case ProfileConditionType.NotEquals:
                return(timestamp != expected);

            default:
                throw new InvalidOperationException("Unexpected ProfileConditionType");
            }
        }
Ejemplo n.º 7
0
        public ResponseProfile GetVideoMediaProfile(string container,
                                                    string audioCodec,
                                                    string videoCodec,
                                                    int?width,
                                                    int?height,
                                                    int?bitDepth,
                                                    int?videoBitrate,
                                                    string videoProfile,
                                                    double?videoLevel,
                                                    float?videoFramerate,
                                                    int?packetLength,
                                                    TransportStreamTimestamp timestamp,
                                                    bool?isAnamorphic,
                                                    bool?isCabac,
                                                    int?refFrames,
                                                    int?numVideoStreams,
                                                    int?numAudioStreams)
        {
            container = StringHelper.TrimStart((container ?? string.Empty), '.');

            foreach (var i in ResponseProfiles)
            {
                if (i.Type != DlnaProfileType.Video)
                {
                    continue;
                }

                List <string> containers = i.GetContainers();
                if (containers.Count > 0 && !ListHelper.ContainsIgnoreCase(containers, container ?? string.Empty))
                {
                    continue;
                }

                List <string> audioCodecs = i.GetAudioCodecs();
                if (audioCodecs.Count > 0 && !ListHelper.ContainsIgnoreCase(audioCodecs, audioCodec ?? string.Empty))
                {
                    continue;
                }

                List <string> videoCodecs = i.GetVideoCodecs();
                if (videoCodecs.Count > 0 && !ListHelper.ContainsIgnoreCase(videoCodecs, videoCodec ?? string.Empty))
                {
                    continue;
                }

                ConditionProcessor conditionProcessor = new ConditionProcessor();

                var anyOff = false;
                foreach (ProfileCondition c in i.Conditions)
                {
                    if (!conditionProcessor.IsVideoConditionSatisfied(c, width, height, bitDepth, videoBitrate, videoProfile, videoLevel, videoFramerate, packetLength, timestamp, isAnamorphic, isCabac, refFrames, numVideoStreams, numAudioStreams))
                    {
                        anyOff = true;
                        break;
                    }
                }

                if (anyOff)
                {
                    continue;
                }

                return(i);
            }
            return(null);
        }
Ejemplo n.º 8
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 > 0, isDirectStream, transcodeSeekInfo);

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

            var 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);

            var 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;
                }
            }

            var 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);
        }
Ejemplo n.º 9
0
        public ResponseProfile GetVideoMediaProfile(string container, 
            string audioCodec,
            string videoCodec,
            int? audioBitrate,
            int? audioChannels,
            int? width,
            int? height,
            int? bitDepth,
            int? videoBitrate,
            string videoProfile,
            double? videoLevel,
            float? videoFramerate,
            int? packetLength,
            TransportStreamTimestamp timestamp,
            bool? isAnamorphic,
            bool? isCabac,
            int? refFrames)
        {
            container = StringHelper.TrimStart((container ?? string.Empty), '.');

            foreach (var i in ResponseProfiles)
            {
                if (i.Type != DlnaProfileType.Video)
                {
                    continue;
                }

                List<string> containers = i.GetContainers();
                if (containers.Count > 0 && !ListHelper.ContainsIgnoreCase(containers, container ?? string.Empty))
                {
                    continue;
                }

                List<string> audioCodecs = i.GetAudioCodecs();
                if (audioCodecs.Count > 0 && !ListHelper.ContainsIgnoreCase(audioCodecs, audioCodec ?? string.Empty))
                {
                    continue;
                }

                List<string> videoCodecs = i.GetVideoCodecs();
                if (videoCodecs.Count > 0 && !ListHelper.ContainsIgnoreCase(videoCodecs, videoCodec ?? string.Empty))
                {
                    continue;
                }

                ConditionProcessor conditionProcessor = new ConditionProcessor();

                var anyOff = false;
                foreach (ProfileCondition c in i.Conditions)
                {
                    if (!conditionProcessor.IsVideoConditionSatisfied(c, audioBitrate, audioChannels, width, height, bitDepth, videoBitrate, videoProfile, videoLevel, videoFramerate, packetLength, timestamp, isAnamorphic, isCabac, refFrames))
                    {
                        anyOff = true;
                        break;
                    }
                }

                if (anyOff)
                {
                    continue;
                }

                return i;
            }
            return null;
        }
Ejemplo n.º 10
0
        public ResponseProfile GetVideoMediaProfile(string container,
                                                    string audioCodec,
                                                    string videoCodec,
                                                    int?width,
                                                    int?height,
                                                    int?bitDepth,
                                                    int?videoBitrate,
                                                    string videoProfile,
                                                    double?videoLevel,
                                                    float?videoFramerate,
                                                    int?packetLength,
                                                    TransportStreamTimestamp timestamp,
                                                    bool?isAnamorphic,
                                                    bool?isInterlaced,
                                                    int?refFrames,
                                                    int?numVideoStreams,
                                                    int?numAudioStreams,
                                                    string videoCodecTag,
                                                    bool?isAvc)
        {
            foreach (var i in ResponseProfiles)
            {
                if (i.Type != DlnaProfileType.Video)
                {
                    continue;
                }

                if (!ContainerProfile.ContainsContainer(i.GetContainers(), container))
                {
                    continue;
                }

                var audioCodecs = i.GetAudioCodecs();
                if (audioCodecs.Length > 0 && !ListHelper.ContainsIgnoreCase(audioCodecs, audioCodec ?? string.Empty))
                {
                    continue;
                }

                var videoCodecs = i.GetVideoCodecs();
                if (videoCodecs.Length > 0 && !ListHelper.ContainsIgnoreCase(videoCodecs, videoCodec ?? string.Empty))
                {
                    continue;
                }

                var anyOff = false;
                foreach (ProfileCondition c in i.Conditions)
                {
                    if (!ConditionProcessor.IsVideoConditionSatisfied(GetModelProfileCondition(c), width, height, bitDepth, videoBitrate, videoProfile, videoLevel, videoFramerate, packetLength, timestamp, isAnamorphic, isInterlaced, refFrames, numVideoStreams, numAudioStreams, videoCodecTag, isAvc))
                    {
                        anyOff = true;
                        break;
                    }
                }

                if (anyOff)
                {
                    continue;
                }

                return(i);
            }
            return(null);
        }
Ejemplo n.º 11
0
        private List <string> GetVideoOrgPnValue(string container, string videoCodec, string audioCodec, int?width, int?height, TransportStreamTimestamp timestamp)
        {
            List <string> list = new List <string>();

            foreach (MediaFormatProfile i in new MediaFormatProfileResolver().ResolveVideoFormat(container, videoCodec, audioCodec, width, height, timestamp))
            {
                list.Add(i.ToString());
            }
            return(list);
        }
Ejemplo n.º 12
0
 public string[] ResolveVideoFormat(string container, string videoCodec, string audioCodec, int?width, int?height, TransportStreamTimestamp timestampType)
 {
     return(ResolveVideoFormatInternal(container, videoCodec, audioCodec, width, height, timestampType)
            .Select(i => i.ToString())
            .ToArray());
 }
Ejemplo n.º 13
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(';'));
        }
Ejemplo n.º 14
0
 private IEnumerable <string> GetVideoOrgPnValue(string container, string videoCodec, string audioCodec, int?width, int?height, TransportStreamTimestamp timestamp)
 {
     return(new MediaFormatProfileResolver()
            .ResolveVideoFormat(container,
                                videoCodec,
                                audioCodec,
                                width,
                                height,
                                timestamp)
            .Select(i => i.ToString()));
 }
        private MediaFormatProfile ResolveVideoMPEG2TSFormat(string videoCodec, string audioCodec, int? width, int? height, int? bitrate, TransportStreamTimestamp timestampType)
        {
            var suffix = "";

            switch (timestampType)
            {
                case TransportStreamTimestamp.NONE:
                    suffix = "_ISO";
                    break;
                case TransportStreamTimestamp.VALID:
                    suffix = "_T";
                    break;
            }

            String resolution = "S";
            if ((width.HasValue && width.Value > 720) || (height.HasValue && height.Value > 576))
            {
                resolution = "H";
            }

            //  if (videoCodec == VideoCodec.MPEG2)
            //  {
            //    List!(MediaFormatProfile) profiles = Arrays.asList(cast(MediaFormatProfile[])[ MediaFormatProfile.valueOf("MPEG_TS_SD_EU" + suffix), MediaFormatProfile.valueOf("MPEG_TS_SD_NA" + suffix), MediaFormatProfile.valueOf("MPEG_TS_SD_KO" + suffix) ]);

            //    if ((timestampType == TransportStreamTimestamp.VALID) && (audioCodec == AudioCodec.AAC)) {
            //      profiles.add(MediaFormatProfile.MPEG_TS_JP_T);
            //    }
            //    return profiles;
            //  }
            if (string.Equals(videoCodec, "h264", StringComparison.OrdinalIgnoreCase))
            {
                if (string.Equals(audioCodec, "lpcm", StringComparison.OrdinalIgnoreCase))
                    return MediaFormatProfile.AVC_TS_HD_50_LPCM_T;

                if (string.Equals(audioCodec, "dts", StringComparison.OrdinalIgnoreCase))
                {
                    if (timestampType == TransportStreamTimestamp.NONE)
                    {
                        return MediaFormatProfile.AVC_TS_HD_DTS_ISO;
                    }
                    return MediaFormatProfile.AVC_TS_HD_DTS_T;
                }
                //if (audioCodec == AudioCodec.MP2) {
                //  if (isNoTimestamp(timestampType)) {
                //    return Collections.singletonList(MediaFormatProfile.valueOf(String.format("AVC_TS_HP_%sD_MPEG1_L2_ISO", cast(Object[])[ resolution ])));
                //  }
                //  return Collections.singletonList(MediaFormatProfile.valueOf(String.format("AVC_TS_HP_%sD_MPEG1_L2_T", cast(Object[])[ resolution ])));
                //}

                //if (audioCodec == AudioCodec.AAC)
                //  return Collections.singletonList(MediaFormatProfile.valueOf(String.format("AVC_TS_MP_%sD_AAC_MULT5%s", cast(Object[])[ resolution, suffix ])));
                //if (audioCodec == AudioCodec.MP3)
                //  return Collections.singletonList(MediaFormatProfile.valueOf(String.format("AVC_TS_MP_%sD_MPEG1_L3%s", cast(Object[])[ resolution, suffix ])));
                //if ((audioCodec is null) || (audioCodec == AudioCodec.AC3)) {
                //  return Collections.singletonList(MediaFormatProfile.valueOf(String.format("AVC_TS_MP_%sD_AC3%s", cast(Object[])[ resolution, suffix ])));
                //}
            }
            else if (string.Equals(videoCodec, "vc1", StringComparison.OrdinalIgnoreCase))
            {
                if (string.IsNullOrEmpty(audioCodec) || string.Equals(audioCodec, "ac3", StringComparison.OrdinalIgnoreCase))
                {
                    if ((width.HasValue && width.Value > 720) || (height.HasValue && height.Value > 576))
                    {
                        return MediaFormatProfile.VC1_TS_AP_L2_AC3_ISO;
                    }
                    return MediaFormatProfile.VC1_TS_AP_L1_AC3_ISO;
                }
                //  if (audioCodec == AudioCodec.DTS) {
                //    suffix = suffix.equals("_ISO") ? suffix : "_T";
                //    return Collections.singletonList(MediaFormatProfile.valueOf(String.format("VC1_TS_HD_DTS%s", cast(Object[])[ suffix ])));
                //  }
                //} else if ((videoCodec == VideoCodec.MPEG4) || (videoCodec == VideoCodec.MSMPEG4)) {
                //  if (audioCodec == AudioCodec.AAC)
                //    return Collections.singletonList(MediaFormatProfile.valueOf(String.format("MPEG4_P2_TS_ASP_AAC%s", cast(Object[])[ suffix ])));
                //  if (audioCodec == AudioCodec.MP3)
                //    return Collections.singletonList(MediaFormatProfile.valueOf(String.format("MPEG4_P2_TS_ASP_MPEG1_L3%s", cast(Object[])[ suffix ])));
                //  if (audioCodec == AudioCodec.MP2)
                //    return Collections.singletonList(MediaFormatProfile.valueOf(String.format("MPEG4_P2_TS_ASP_MPEG2_L2%s", cast(Object[])[ suffix ])));
                //  if ((audioCodec is null) || (audioCodec == AudioCodec.AC3)) {
                //    return Collections.singletonList(MediaFormatProfile.valueOf(String.format("MPEG4_P2_TS_ASP_AC3%s", cast(Object[])[ suffix ])));
                //  }
            }

            throw new ArgumentException("Mpeg video file does not match any supported DLNA profile");
        }
        public List<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,
            float? videoFramerate,
            int? packetLength,
            TranscodeSeekInfo transcodeSeekInfo,
            bool? isAnamorphic,
            int? refFrames)
        {
            // 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,
                audioBitrate,
                audioChannels,
                width,
                height,
                bitDepth,
                videoBitrate,
                videoProfile,
                videoLevel,
                videoFramerate,
                packetLength,
                timestamp,
                isAnamorphic,
                refFrames);

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

            if (mediaProfile != null && !string.IsNullOrEmpty(mediaProfile.OrgPn))
            {
                orgPnValues.Add(mediaProfile.OrgPn);
            }
            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;
        }
 private List<string> GetVideoOrgPnValue(string container, string videoCodec, string audioCodec, int? width, int? height, TransportStreamTimestamp timestamp)
 {
     List<string> list = new List<string>();
     foreach (MediaFormatProfile i in new MediaFormatProfileResolver().ResolveVideoFormat(container, videoCodec, audioCodec, width, height, timestamp))
         list.Add(i.ToString());
     return list;
 }
Ejemplo n.º 18
0
        private MediaFormatProfile[] ResolveVideoFormatInternal(string container, string videoCodec, string audioCodec, int?width, int?height, TransportStreamTimestamp timestampType)
        {
            if (StringHelper.EqualsIgnoreCase(container, "asf"))
            {
                MediaFormatProfile?val = ResolveVideoASFFormat(videoCodec, audioCodec, width, height);
                return(val.HasValue ? new MediaFormatProfile[] { val.Value } : new MediaFormatProfile[] { });
            }

            if (StringHelper.EqualsIgnoreCase(container, "mp4"))
            {
                MediaFormatProfile?val = ResolveVideoMP4Format(videoCodec, audioCodec, width, height);
                return(val.HasValue ? new MediaFormatProfile[] { val.Value } : new MediaFormatProfile[] { });
            }

            if (StringHelper.EqualsIgnoreCase(container, "avi"))
            {
                return new MediaFormatProfile[] { MediaFormatProfile.AVI }
            }
            ;

            if (StringHelper.EqualsIgnoreCase(container, "mkv"))
            {
                return new MediaFormatProfile[] { MediaFormatProfile.MATROSKA }
            }
            ;

            if (StringHelper.EqualsIgnoreCase(container, "mpeg2ps") ||
                StringHelper.EqualsIgnoreCase(container, "ts"))
            {
                return new MediaFormatProfile[] { MediaFormatProfile.MPEG_PS_NTSC, MediaFormatProfile.MPEG_PS_PAL }
            }
            ;

            if (StringHelper.EqualsIgnoreCase(container, "mpeg1video"))
            {
                return new MediaFormatProfile[] { MediaFormatProfile.MPEG1 }
            }
            ;

            if (StringHelper.EqualsIgnoreCase(container, "mpeg2ts") ||
                StringHelper.EqualsIgnoreCase(container, "mpegts") ||
                StringHelper.EqualsIgnoreCase(container, "m2ts"))
            {
                return(ResolveVideoMPEG2TSFormat(videoCodec, audioCodec, width, height, timestampType));
            }

            if (StringHelper.EqualsIgnoreCase(container, "flv"))
            {
                return new MediaFormatProfile[] { MediaFormatProfile.FLV }
            }
            ;

            if (StringHelper.EqualsIgnoreCase(container, "wtv"))
            {
                return new MediaFormatProfile[] { MediaFormatProfile.WTV }
            }
            ;

            if (StringHelper.EqualsIgnoreCase(container, "3gp"))
            {
                MediaFormatProfile?val = ResolveVideo3GPFormat(videoCodec, audioCodec);

                return(val.HasValue ? new MediaFormatProfile[] { val.Value } : new MediaFormatProfile[] { });
            }

            if (StringHelper.EqualsIgnoreCase(container, "ogv") || StringHelper.EqualsIgnoreCase(container, "ogg"))
            {
                return new MediaFormatProfile[] { MediaFormatProfile.OGV }
            }
            ;

            return(new MediaFormatProfile[] { });
        }
Ejemplo n.º 19
0
        private MediaFormatProfile[] ResolveVideoMPEG2TSFormat(string videoCodec, string audioCodec, int?width, int?height, TransportStreamTimestamp timestampType)
        {
            string suffix = "";

            switch (timestampType)
            {
            case TransportStreamTimestamp.None:
                suffix = "_ISO";

                break;

            case TransportStreamTimestamp.Valid:
                suffix = "_T";
                break;
            }

            string resolution = "S";

            if ((width.HasValue && width.Value > 720) || (height.HasValue && height.Value > 576))
            {
                resolution = "H";
            }

            if (StringHelper.EqualsIgnoreCase(videoCodec, "mpeg2video"))
            {
                List <MediaFormatProfile> list = new List <MediaFormatProfile>();

                list.Add(ValueOf("MPEG_TS_SD_NA" + suffix));
                list.Add(ValueOf("MPEG_TS_SD_EU" + suffix));
                list.Add(ValueOf("MPEG_TS_SD_KO" + suffix));

                if ((timestampType == TransportStreamTimestamp.Valid) && StringHelper.EqualsIgnoreCase(audioCodec, "aac"))
                {
                    list.Add(MediaFormatProfile.MPEG_TS_JP_T);
                }
                return(list.ToArray(list.Count));
            }
            if (StringHelper.EqualsIgnoreCase(videoCodec, "h264"))
            {
                if (StringHelper.EqualsIgnoreCase(audioCodec, "lpcm"))
                {
                    return new MediaFormatProfile[] { MediaFormatProfile.AVC_TS_HD_50_LPCM_T }
                }
                ;

                if (StringHelper.EqualsIgnoreCase(audioCodec, "dts"))
                {
                    if (timestampType == TransportStreamTimestamp.None)
                    {
                        return(new MediaFormatProfile[] { MediaFormatProfile.AVC_TS_HD_DTS_ISO });
                    }
                    return(new MediaFormatProfile[] { MediaFormatProfile.AVC_TS_HD_DTS_T });
                }

                if (StringHelper.EqualsIgnoreCase(audioCodec, "mp2"))
                {
                    if (timestampType == TransportStreamTimestamp.None)
                    {
                        return(new MediaFormatProfile[] { ValueOf(string.Format("AVC_TS_HP_{0}D_MPEG1_L2_ISO", resolution)) });
                    }

                    return(new MediaFormatProfile[] { ValueOf(string.Format("AVC_TS_HP_{0}D_MPEG1_L2_T", resolution)) });
                }

                if (StringHelper.EqualsIgnoreCase(audioCodec, "aac"))
                {
                    return new MediaFormatProfile[] { ValueOf(string.Format("AVC_TS_MP_{0}D_AAC_MULT5{1}", resolution, suffix)) }
                }
                ;

                if (StringHelper.EqualsIgnoreCase(audioCodec, "mp3"))
                {
                    return new MediaFormatProfile[] { ValueOf(string.Format("AVC_TS_MP_{0}D_MPEG1_L3{1}", resolution, suffix)) }
                }
                ;

                if (string.IsNullOrEmpty(audioCodec) ||
                    StringHelper.EqualsIgnoreCase(audioCodec, "ac3"))
                {
                    return new MediaFormatProfile[] { ValueOf(string.Format("AVC_TS_MP_{0}D_AC3{1}", resolution, suffix)) }
                }
                ;
            }
            else if (StringHelper.EqualsIgnoreCase(videoCodec, "vc1"))
            {
                if (string.IsNullOrEmpty(audioCodec) || StringHelper.EqualsIgnoreCase(audioCodec, "ac3"))
                {
                    if ((width.HasValue && width.Value > 720) || (height.HasValue && height.Value > 576))
                    {
                        return(new MediaFormatProfile[] { MediaFormatProfile.VC1_TS_AP_L2_AC3_ISO });
                    }
                    return(new MediaFormatProfile[] { MediaFormatProfile.VC1_TS_AP_L1_AC3_ISO });
                }
                if (StringHelper.EqualsIgnoreCase(audioCodec, "dts"))
                {
                    suffix = StringHelper.EqualsIgnoreCase(suffix, "_ISO") ? suffix : "_T";

                    return(new MediaFormatProfile[] { ValueOf(string.Format("VC1_TS_HD_DTS{0}", suffix)) });
                }
            }
            else if (StringHelper.EqualsIgnoreCase(videoCodec, "mpeg4") || StringHelper.EqualsIgnoreCase(videoCodec, "msmpeg4"))
            {
                if (StringHelper.EqualsIgnoreCase(audioCodec, "aac"))
                {
                    return new MediaFormatProfile[] { ValueOf(string.Format("MPEG4_P2_TS_ASP_AAC{0}", suffix)) }
                }
                ;
                if (StringHelper.EqualsIgnoreCase(audioCodec, "mp3"))
                {
                    return new MediaFormatProfile[] { ValueOf(string.Format("MPEG4_P2_TS_ASP_MPEG1_L3{0}", suffix)) }
                }
                ;
                if (StringHelper.EqualsIgnoreCase(audioCodec, "mp2"))
                {
                    return new MediaFormatProfile[] { ValueOf(string.Format("MPEG4_P2_TS_ASP_MPEG2_L2{0}", suffix)) }
                }
                ;
                if (StringHelper.EqualsIgnoreCase(audioCodec, "ac3"))
                {
                    return new MediaFormatProfile[] { ValueOf(string.Format("MPEG4_P2_TS_ASP_AC3{0}", suffix)) }
                }
                ;
            }

            return(new MediaFormatProfile[] {});
        }
Ejemplo n.º 20
0
        public static MediaFormatProfile[] ResolveVideoFormat(string container, string videoCodec, string audioCodec, int?width, int?height, TransportStreamTimestamp timestampType)
        {
            if (string.Equals(container, "asf", StringComparison.OrdinalIgnoreCase))
            {
                MediaFormatProfile?val = ResolveVideoASFFormat(videoCodec, audioCodec, width, height);
                return(val.HasValue ? new MediaFormatProfile[] { val.Value } : Array.Empty <MediaFormatProfile>());
            }

            if (string.Equals(container, "mp4", StringComparison.OrdinalIgnoreCase))
            {
                MediaFormatProfile?val = ResolveVideoMP4Format(videoCodec, audioCodec, width, height);
                return(val.HasValue ? new MediaFormatProfile[] { val.Value } : Array.Empty <MediaFormatProfile>());
            }

            if (string.Equals(container, "avi", StringComparison.OrdinalIgnoreCase))
            {
                return(new MediaFormatProfile[] { MediaFormatProfile.AVI });
            }

            if (string.Equals(container, "mkv", StringComparison.OrdinalIgnoreCase))
            {
                return(new MediaFormatProfile[] { MediaFormatProfile.MATROSKA });
            }

            if (string.Equals(container, "mpeg2ps", StringComparison.OrdinalIgnoreCase) ||
                string.Equals(container, "ts", StringComparison.OrdinalIgnoreCase))
            {
                return(new MediaFormatProfile[] { MediaFormatProfile.MPEG_PS_NTSC, MediaFormatProfile.MPEG_PS_PAL });
            }

            if (string.Equals(container, "mpeg1video", StringComparison.OrdinalIgnoreCase))
            {
                return(new MediaFormatProfile[] { MediaFormatProfile.MPEG1 });
            }

            if (string.Equals(container, "mpeg2ts", StringComparison.OrdinalIgnoreCase) ||
                string.Equals(container, "mpegts", StringComparison.OrdinalIgnoreCase) ||
                string.Equals(container, "m2ts", StringComparison.OrdinalIgnoreCase))
            {
                return(ResolveVideoMPEG2TSFormat(videoCodec, audioCodec, width, height, timestampType));
            }

            if (string.Equals(container, "flv", StringComparison.OrdinalIgnoreCase))
            {
                return(new MediaFormatProfile[] { MediaFormatProfile.FLV });
            }

            if (string.Equals(container, "wtv", StringComparison.OrdinalIgnoreCase))
            {
                return(new MediaFormatProfile[] { MediaFormatProfile.WTV });
            }

            if (string.Equals(container, "3gp", StringComparison.OrdinalIgnoreCase))
            {
                MediaFormatProfile?val = ResolveVideo3GPFormat(videoCodec, audioCodec);
                return(val.HasValue ? new MediaFormatProfile[] { val.Value } : Array.Empty <MediaFormatProfile>());
            }

            if (string.Equals(container, "ogv", StringComparison.OrdinalIgnoreCase) || string.Equals(container, "ogg", StringComparison.OrdinalIgnoreCase))
            {
                return(new MediaFormatProfile[] { MediaFormatProfile.OGV });
            }

            return(Array.Empty <MediaFormatProfile>());
        }
Ejemplo n.º 21
0
        public static IEnumerable <string> BuildVideoHeader(
            DeviceProfile profile,
            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 > 0, isDirectStream, transcodeSeekInfo);

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

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

            if (isDirectStream)
            {
                flagValue |= DlnaFlags.ByteBasedSeek;
            }

            // Time based seek is curently disabled when streaming. On LG CX3 adding DlnaFlags.TimeBasedSeek and orgPn causes the DLNA playback to fail (format not supported). Further investigations are needed before enabling the remaining code paths.
            //  else if (runtimeTicks.HasValue)
            // {
            //     flagValue = flagValue | DlnaFlags.TimeBasedSeek;
            // }

            string dlnaflags = string.Format(
                CultureInfo.InvariantCulture,
                ";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);

            var orgPnValues = new List <string>();

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

            var contentFeatureList = new List <string>();

            foreach (string orgPn in orgPnValues)
            {
                if (string.IsNullOrEmpty(orgPn))
                {
                    contentFeatureList.Add(orgOp.TrimStart(';') + orgCi + dlnaflags);
                }
                else if (isDirectStream)
                {
                    // orgOp should be added all the time once the time based seek is resolved for transcoded streams
                    contentFeatureList.Add("DLNA.ORG_PN=" + orgPn + orgOp + orgCi + dlnaflags);
                }
                else
                {
                    contentFeatureList.Add("DLNA.ORG_PN=" + orgPn + orgCi + dlnaflags);
                }
            }

            if (orgPnValues.Count == 0)
            {
                contentFeatureList.Add(orgOp.TrimStart(';') + orgCi + dlnaflags);
            }

            return(contentFeatureList);
        }
Ejemplo n.º 22
0
        private static MediaFormatProfile[] ResolveVideoMPEG2TSFormat(string videoCodec, string audioCodec, int?width, int?height, TransportStreamTimestamp timestampType)
        {
            string suffix = string.Empty;

            switch (timestampType)
            {
            case TransportStreamTimestamp.None:
                suffix = "_ISO";
                break;

            case TransportStreamTimestamp.Valid:
                suffix = "_T";
                break;
            }

            string resolution = "S";

            if ((width.HasValue && width.Value > 720) || (height.HasValue && height.Value > 576))
            {
                resolution = "H";
            }

            if (string.Equals(videoCodec, "mpeg2video", StringComparison.OrdinalIgnoreCase))
            {
                var list = new List <MediaFormatProfile>
                {
                    ValueOf("MPEG_TS_SD_NA" + suffix),
                    ValueOf("MPEG_TS_SD_EU" + suffix),
                    ValueOf("MPEG_TS_SD_KO" + suffix)
                };

                if ((timestampType == TransportStreamTimestamp.Valid) && string.Equals(audioCodec, "aac", StringComparison.OrdinalIgnoreCase))
                {
                    list.Add(MediaFormatProfile.MPEG_TS_JP_T);
                }

                return(list.ToArray());
            }

            if (string.Equals(videoCodec, "h264", StringComparison.OrdinalIgnoreCase))
            {
                if (string.Equals(audioCodec, "lpcm", StringComparison.OrdinalIgnoreCase))
                {
                    return(new MediaFormatProfile[] { MediaFormatProfile.AVC_TS_HD_50_LPCM_T });
                }

                if (string.Equals(audioCodec, "dts", StringComparison.OrdinalIgnoreCase))
                {
                    if (timestampType == TransportStreamTimestamp.None)
                    {
                        return(new MediaFormatProfile[] { MediaFormatProfile.AVC_TS_HD_DTS_ISO });
                    }

                    return(new MediaFormatProfile[] { MediaFormatProfile.AVC_TS_HD_DTS_T });
                }

                if (string.Equals(audioCodec, "mp2", StringComparison.OrdinalIgnoreCase))
                {
                    if (timestampType == TransportStreamTimestamp.None)
                    {
                        return(new MediaFormatProfile[] { ValueOf(string.Format(CultureInfo.InvariantCulture, "AVC_TS_HP_{0}D_MPEG1_L2_ISO", resolution)) });
                    }

                    return(new MediaFormatProfile[] { ValueOf(string.Format(CultureInfo.InvariantCulture, "AVC_TS_HP_{0}D_MPEG1_L2_T", resolution)) });
                }

                if (string.Equals(audioCodec, "aac", StringComparison.OrdinalIgnoreCase))
                {
                    return(new MediaFormatProfile[] { ValueOf(string.Format(CultureInfo.InvariantCulture, "AVC_TS_MP_{0}D_AAC_MULT5{1}", resolution, suffix)) });
                }

                if (string.Equals(audioCodec, "mp3", StringComparison.OrdinalIgnoreCase))
                {
                    return(new MediaFormatProfile[] { ValueOf(string.Format(CultureInfo.InvariantCulture, "AVC_TS_MP_{0}D_MPEG1_L3{1}", resolution, suffix)) });
                }

                if (string.IsNullOrEmpty(audioCodec) ||
                    string.Equals(audioCodec, "ac3", StringComparison.OrdinalIgnoreCase))
                {
                    return(new MediaFormatProfile[] { ValueOf(string.Format(CultureInfo.InvariantCulture, "AVC_TS_MP_{0}D_AC3{1}", resolution, suffix)) });
                }
            }
            else if (string.Equals(videoCodec, "vc1", StringComparison.OrdinalIgnoreCase))
            {
                if (string.IsNullOrEmpty(audioCodec) || string.Equals(audioCodec, "ac3", StringComparison.OrdinalIgnoreCase))
                {
                    if ((width.HasValue && width.Value > 720) || (height.HasValue && height.Value > 576))
                    {
                        return(new MediaFormatProfile[] { MediaFormatProfile.VC1_TS_AP_L2_AC3_ISO });
                    }

                    return(new MediaFormatProfile[] { MediaFormatProfile.VC1_TS_AP_L1_AC3_ISO });
                }

                if (string.Equals(audioCodec, "dts", StringComparison.OrdinalIgnoreCase))
                {
                    suffix = string.Equals(suffix, "_ISO", StringComparison.OrdinalIgnoreCase) ? suffix : "_T";

                    return(new MediaFormatProfile[] { ValueOf(string.Format(CultureInfo.InvariantCulture, "VC1_TS_HD_DTS{0}", suffix)) });
                }
            }
            else if (string.Equals(videoCodec, "mpeg4", StringComparison.OrdinalIgnoreCase) || string.Equals(videoCodec, "msmpeg4", StringComparison.OrdinalIgnoreCase))
            {
                if (string.Equals(audioCodec, "aac", StringComparison.OrdinalIgnoreCase))
                {
                    return(new MediaFormatProfile[] { ValueOf(string.Format(CultureInfo.InvariantCulture, "MPEG4_P2_TS_ASP_AAC{0}", suffix)) });
                }

                if (string.Equals(audioCodec, "mp3", StringComparison.OrdinalIgnoreCase))
                {
                    return(new MediaFormatProfile[] { ValueOf(string.Format(CultureInfo.InvariantCulture, "MPEG4_P2_TS_ASP_MPEG1_L3{0}", suffix)) });
                }

                if (string.Equals(audioCodec, "mp2", StringComparison.OrdinalIgnoreCase))
                {
                    return(new MediaFormatProfile[] { ValueOf(string.Format(CultureInfo.InvariantCulture, "MPEG4_P2_TS_ASP_MPEG2_L2{0}", suffix)) });
                }

                if (string.Equals(audioCodec, "ac3", StringComparison.OrdinalIgnoreCase))
                {
                    return(new MediaFormatProfile[] { ValueOf(string.Format(CultureInfo.InvariantCulture, "MPEG4_P2_TS_ASP_AC3{0}", suffix)) });
                }
            }

            return(Array.Empty <MediaFormatProfile>());
        }
Ejemplo n.º 23
0
 private bool IsConditionSatisfied(ProfileCondition condition, TransportStreamTimestamp? timestamp)
 {
     if (!timestamp.HasValue)
     {
         // If the value is unknown, it satisfies if not marked as required
         return !condition.IsRequired;
     }
     
     TransportStreamTimestamp expected = (TransportStreamTimestamp)Enum.Parse(typeof(TransportStreamTimestamp), condition.Value, true);
     
     switch (condition.Condition)
     {
         case ProfileConditionType.Equals:
             return timestamp == expected;
         case ProfileConditionType.NotEquals:
             return timestamp != expected;
         default:
             throw new InvalidOperationException("Unexpected ProfileConditionType");
     }
 }
        private List<MediaFormatProfile> ResolveVideoMPEG2TSFormat(string videoCodec, string audioCodec, int? width, int? height, TransportStreamTimestamp timestampType)
        {
            string suffix = "";

            switch (timestampType)
            {
                case TransportStreamTimestamp.None:
                    suffix = "_ISO";
                    break;
                case TransportStreamTimestamp.Valid:
                    suffix = "_T";
                    break;
            }

            string resolution = "S";
            if ((width.HasValue && width.Value > 720) || (height.HasValue && height.Value > 576))
            {
                resolution = "H";
            }

            if (StringHelper.EqualsIgnoreCase(videoCodec, "mpeg2video"))
            {
                List<MediaFormatProfile> list = new List<MediaFormatProfile>();

                list.Add(ValueOf("MPEG_TS_SD_NA" + suffix));
                list.Add(ValueOf("MPEG_TS_SD_EU" + suffix));
                list.Add(ValueOf("MPEG_TS_SD_KO" + suffix));

                if ((timestampType == TransportStreamTimestamp.Valid) && StringHelper.EqualsIgnoreCase(audioCodec, "aac"))
                {
                    list.Add(MediaFormatProfile.MPEG_TS_JP_T);
                }
                return list;
            }
            if (StringHelper.EqualsIgnoreCase(videoCodec, "h264"))
            {
                if (StringHelper.EqualsIgnoreCase(audioCodec, "lpcm"))
                    return new List<MediaFormatProfile> { MediaFormatProfile.AVC_TS_HD_50_LPCM_T };

                if (StringHelper.EqualsIgnoreCase(audioCodec, "dts"))
                {
                    if (timestampType == TransportStreamTimestamp.None)
                    {
                        return new List<MediaFormatProfile> { MediaFormatProfile.AVC_TS_HD_DTS_ISO };
                    }
                    return new List<MediaFormatProfile> { MediaFormatProfile.AVC_TS_HD_DTS_T };
                }

                if (StringHelper.EqualsIgnoreCase(audioCodec, "mp2"))
                {
                    if (timestampType == TransportStreamTimestamp.None)
                    {
                        return new List<MediaFormatProfile> { ValueOf(string.Format("AVC_TS_HP_{0}D_MPEG1_L2_ISO", resolution)) };
                    }

                    return new List<MediaFormatProfile> { ValueOf(string.Format("AVC_TS_HP_{0}D_MPEG1_L2_T", resolution)) };
                }

                if (StringHelper.EqualsIgnoreCase(audioCodec, "aac"))
                    return new List<MediaFormatProfile> { ValueOf(string.Format("AVC_TS_MP_{0}D_AAC_MULT5{1}", resolution, suffix)) };

                if (StringHelper.EqualsIgnoreCase(audioCodec, "mp3"))
                    return new List<MediaFormatProfile> { ValueOf(string.Format("AVC_TS_MP_{0}D_MPEG1_L3{1}", resolution, suffix)) };

                if (string.IsNullOrEmpty(audioCodec) ||
                    StringHelper.EqualsIgnoreCase(audioCodec, "ac3"))
                    return new List<MediaFormatProfile> { ValueOf(string.Format("AVC_TS_MP_{0}D_AC3{1}", resolution, suffix)) };
            }
            else if (StringHelper.EqualsIgnoreCase(videoCodec, "vc1"))
            {
                if (string.IsNullOrEmpty(audioCodec) || StringHelper.EqualsIgnoreCase(audioCodec, "ac3"))
                {
                    if ((width.HasValue && width.Value > 720) || (height.HasValue && height.Value > 576))
                    {
                        return new List<MediaFormatProfile> { MediaFormatProfile.VC1_TS_AP_L2_AC3_ISO };
                    }
                    return new List<MediaFormatProfile> { MediaFormatProfile.VC1_TS_AP_L1_AC3_ISO };
                }
                if (StringHelper.EqualsIgnoreCase(audioCodec, "dts"))
                {
                    suffix = StringHelper.EqualsIgnoreCase(suffix, "_ISO") ? suffix : "_T";

                    return new List<MediaFormatProfile> { ValueOf(string.Format("VC1_TS_HD_DTS{0}", suffix)) };
                }

            }
            else if (StringHelper.EqualsIgnoreCase(videoCodec, "mpeg4") || StringHelper.EqualsIgnoreCase(videoCodec, "msmpeg4"))
            {
                if (StringHelper.EqualsIgnoreCase(audioCodec, "aac"))
                    return new List<MediaFormatProfile> { ValueOf(string.Format("MPEG4_P2_TS_ASP_AAC{0}", suffix)) };
                if (StringHelper.EqualsIgnoreCase(audioCodec, "mp3"))
                    return new List<MediaFormatProfile> { ValueOf(string.Format("MPEG4_P2_TS_ASP_MPEG1_L3{0}", suffix)) };
                if (StringHelper.EqualsIgnoreCase(audioCodec, "mp2"))
                    return new List<MediaFormatProfile> { ValueOf(string.Format("MPEG4_P2_TS_ASP_MPEG2_L2{0}", suffix)) };
                if (StringHelper.EqualsIgnoreCase(audioCodec, "ac3"))
                    return new List<MediaFormatProfile> { ValueOf(string.Format("MPEG4_P2_TS_ASP_AC3{0}", suffix)) };
            }

            return new List<MediaFormatProfile>();
        }
Ejemplo n.º 25
0
 private static string[] GetVideoOrgPnValue(string container, string videoCodec, string audioCodec, int?width, int?height, TransportStreamTimestamp timestamp)
 {
     return(new MediaFormatProfileResolver().ResolveVideoFormat(container, videoCodec, audioCodec, width, height, timestamp));
 }
 private static MediaFormatProfile[] GetVideoOrgPnValue(string container, string?videoCodec, string?audioCodec, int?width, int?height, TransportStreamTimestamp timestamp)
 {
     return(MediaFormatProfileResolver.ResolveVideoFormat(container, videoCodec ?? string.Empty, audioCodec ?? string.Empty, width, height, timestamp));
 }