Пример #1
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);
     }
 }
Пример #2
0
 public bool IsImageConditionSatisfied(ProfileCondition condition, int? width, int? height)
 {
     switch (condition.Property)
     {
         case ProfileConditionValue.Height:
             return IsConditionSatisfied(condition, height);
         case ProfileConditionValue.Width:
             return IsConditionSatisfied(condition, width);
         default:
             throw new ArgumentException("Unexpected condition on image file: " + condition.Property);
     }
 }
Пример #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,
     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;
     }
 }
Пример #4
0
 public bool IsAudioConditionSatisfied(ProfileCondition condition, int? audioChannels, int? audioBitrate)
 {
     switch (condition.Property)
     {
         case ProfileConditionValue.AudioBitrate:
             return IsConditionSatisfied(condition, audioBitrate);
         case ProfileConditionValue.AudioChannels:
             return IsConditionSatisfied(condition, audioChannels);
         default:
             throw new ArgumentException("Unexpected condition on audio file: " + condition.Property);
     }
 }
Пример #5
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);
            }

            var 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: " + condition.Condition);
            }
        }
Пример #6
0
        private bool IsConditionSatisfied(ProfileCondition condition, string currentValue)
        {
            if (string.IsNullOrEmpty(currentValue))
            {
                // If the value is unknown, it satisfies if not marked as required
                return(!condition.IsRequired);
            }

            var expected = condition.Value;

            switch (condition.Condition)
            {
            case ProfileConditionType.Equals:
                return(string.Equals(currentValue, expected, StringComparison.OrdinalIgnoreCase));

            case ProfileConditionType.NotEquals:
                return(!string.Equals(currentValue, expected, StringComparison.OrdinalIgnoreCase));

            default:
                throw new InvalidOperationException("Unexpected ProfileConditionType");
            }
        }
Пример #7
0
        public bool IsVideoAudioConditionSatisfied(ProfileCondition condition,
                                                   int?audioChannels,
                                                   int?audioBitrate,
                                                   string audioProfile,
                                                   bool?isSecondaryTrack)
        {
            switch (condition.Property)
            {
            case ProfileConditionValue.AudioProfile:
                return(IsConditionSatisfied(condition, audioProfile));

            case ProfileConditionValue.AudioBitrate:
                return(IsConditionSatisfied(condition, audioBitrate));

            case ProfileConditionValue.AudioChannels:
                return(IsConditionSatisfied(condition, audioChannels));

            case ProfileConditionValue.IsSecondaryAudio:
                return(IsConditionSatisfied(condition, isSecondaryTrack));

            default:
                throw new ArgumentException("Unexpected condition on audio file: " + condition.Property);
            }
        }
Пример #8
0
 public CodecProfile()
 {
     Conditions = new ProfileCondition[] {};
 }
Пример #9
0
 public bool IsVideoAudioConditionSatisfied(ProfileCondition condition, 
     int? audioChannels, 
     int? audioBitrate,
     string audioProfile,
     bool? isSecondaryTrack)
 {
     switch (condition.Property)
     {
         case ProfileConditionValue.AudioProfile:
             return IsConditionSatisfied(condition, audioProfile);
         case ProfileConditionValue.AudioBitrate:
             return IsConditionSatisfied(condition, audioBitrate);
         case ProfileConditionValue.AudioChannels:
             return IsConditionSatisfied(condition, audioChannels);
         case ProfileConditionValue.IsSecondaryAudio:
             return IsConditionSatisfied(condition, isSecondaryTrack);
         default:
             throw new ArgumentException("Unexpected condition on audio file: " + condition.Property);
     }
 }
Пример #10
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");
     }
 }
Пример #11
0
        private bool IsConditionSatisfied(ProfileCondition condition, double? currentValue)
        {
            if (!currentValue.HasValue)
            {
                // If the value is unknown, it satisfies if not marked as required
                return !condition.IsRequired;
            }

            double expected;
            if (DoubleHelper.TryParseCultureInvariant(condition.Value, out expected))
            {
                switch (condition.Condition)
                {
                    case ProfileConditionType.Equals:
                        return currentValue.Value.Equals(expected);
                    case ProfileConditionType.GreaterThanEqual:
                        return currentValue.Value >= expected;
                    case ProfileConditionType.LessThanEqual:
                        return currentValue.Value <= expected;
                    case ProfileConditionType.NotEquals:
                        return !currentValue.Value.Equals(expected);
                    default:
                        throw new InvalidOperationException("Unexpected ProfileConditionType");
                }
            }

            return false;
        }
Пример #12
0
        private bool IsConditionSatisfied(ProfileCondition condition, bool? currentValue)
        {
            if (!currentValue.HasValue)
            {
                // If the value is unknown, it satisfies if not marked as required
                return !condition.IsRequired;
            }

            bool expected;
            if (BoolHelper.TryParseCultureInvariant(condition.Value, out expected))
            {
                switch (condition.Condition)
                {
                    case ProfileConditionType.Equals:
                        return currentValue.Value == expected;
                    case ProfileConditionType.NotEquals:
                        return currentValue.Value != expected;
                    default:
                        throw new InvalidOperationException("Unexpected ProfileConditionType");
                }
            }

            return false;
        }
Пример #13
0
        private bool IsConditionSatisfied(ProfileCondition condition, string currentValue)
        {
            if (string.IsNullOrEmpty(currentValue))
            {
                // If the value is unknown, it satisfies if not marked as required
                return !condition.IsRequired;
            }

            string expected = condition.Value;

            switch (condition.Condition)
            {
                case ProfileConditionType.Equals:
                    return StringHelper.EqualsIgnoreCase(currentValue, expected);
                case ProfileConditionType.NotEquals:
                    return !StringHelper.EqualsIgnoreCase(currentValue, expected);
                default:
                    throw new InvalidOperationException("Unexpected ProfileConditionType");
            }
        }
Пример #14
0
        public bool IsVideoConditionSatisfied(ProfileCondition condition,
                                              int?audioBitrate,
                                              int?audioChannels,
                                              int?width,
                                              int?height,
                                              int?bitDepth,
                                              int?videoBitrate,
                                              string videoProfile,
                                              double?videoLevel,
                                              float?videoFramerate,
                                              int?packetLength,
                                              TransportStreamTimestamp?timestamp,
                                              bool?isAnamorphic,
                                              int?refFrames)
        {
            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.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.AudioBitrate:
                return(IsConditionSatisfied(condition, audioBitrate));

            case ProfileConditionValue.AudioChannels:
                return(IsConditionSatisfied(condition, audioChannels));

            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.VideoTimestamp:
                return(IsConditionSatisfied(condition, timestamp));

            default:
                throw new ArgumentException("Unexpected condition on video file: " + condition.Property);
            }
        }
Пример #15
0
 public ContainerProfile()
 {
     Conditions = new ProfileCondition[] { };
 }
Пример #16
0
 public CodecProfile()
 {
     Conditions      = new ProfileCondition[] { };
     ApplyConditions = new ProfileCondition[] { };
 }
Пример #17
0
 private void LogConditionFailure(DeviceProfile profile, string type, ProfileCondition condition, MediaSourceInfo mediaSource)
 {
     _logger.Debug("Profile: {0}, DirectPlay=false. Reason={1}.{2} Condition: {3}. ConditionValue: {4}. IsRequired: {5}. Path: {6}",
         type,
         profile.Name ?? "Unknown Profile",
         condition.Property,
         condition.Condition,
         condition.Value ?? string.Empty,
         condition.IsRequired,
         mediaSource.Path ?? "Unknown path");
 }
Пример #18
0
 public ContainerProfile()
 {
     Conditions = new ProfileCondition[] { };
 }
Пример #19
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,
                                              int?refFrames,
                                              int?numVideoStreams,
                                              int?numAudioStreams,
                                              string videoCodecTag)
        {
            switch (condition.Property)
            {
            case ProfileConditionValue.IsAnamorphic:
                return(IsConditionSatisfied(condition, isAnamorphic));

            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);
            }
        }
Пример #20
0
 /// <summary>
 /// Gets the condition value.
 /// </summary>
 /// <param name="condition">The condition.</param>
 /// <param name="mediaPath">The media path.</param>
 /// <param name="videoStream">The video stream.</param>
 /// <param name="audioStream">The audio stream.</param>
 /// <returns>System.Nullable{System.Int64}.</returns>
 /// <exception cref="System.InvalidOperationException">Unexpected Property</exception>
 private long? GetConditionValue(ProfileCondition condition, string mediaPath, MediaStream videoStream, MediaStream audioStream)
 {
     switch (condition.Property)
     {
         case ProfileConditionValue.AudioBitrate:
             return audioStream == null ? null : audioStream.BitRate;
         case ProfileConditionValue.AudioChannels:
             return audioStream == null ? null : audioStream.Channels;
         case ProfileConditionValue.VideoBitrate:
             return videoStream == null ? null : videoStream.BitRate;
         case ProfileConditionValue.VideoFramerate:
             return videoStream == null ? null : (ConvertToLong(videoStream.AverageFrameRate ?? videoStream.RealFrameRate));
         case ProfileConditionValue.Height:
             return videoStream == null ? null : videoStream.Height;
         case ProfileConditionValue.Width:
             return videoStream == null ? null : videoStream.Width;
         case ProfileConditionValue.VideoLevel:
             return videoStream == null ? null : ConvertToLong(videoStream.Level);
         default:
             throw new InvalidOperationException("Unexpected Property");
     }
 }
Пример #21
0
        /// <summary>
        /// Determines whether [is condition satisfied] [the specified condition].
        /// </summary>
        /// <param name="condition">The condition.</param>
        /// <param name="mediaPath">The media path.</param>
        /// <param name="videoStream">The video stream.</param>
        /// <param name="audioStream">The audio stream.</param>
        /// <returns><c>true</c> if [is condition satisfied] [the specified condition]; otherwise, <c>false</c>.</returns>
        /// <exception cref="System.InvalidOperationException">Unexpected ProfileConditionType</exception>
        private bool IsConditionSatisfied(ProfileCondition condition, string mediaPath, MediaStream videoStream, MediaStream audioStream)
        {
            if (condition.Property == ProfileConditionValue.Has64BitOffsets)
            {
                // TODO: Determine how to evaluate this
            }

            if (condition.Property == ProfileConditionValue.VideoProfile)
            {
                var profile = videoStream == null ? null : videoStream.Profile;

                if (!string.IsNullOrWhiteSpace(profile))
                {
                    switch (condition.Condition)
                    {
                        case ProfileConditionType.Equals:
                            return string.Equals(profile, condition.Value, StringComparison.OrdinalIgnoreCase);
                        case ProfileConditionType.NotEquals:
                            return !string.Equals(profile, condition.Value, StringComparison.OrdinalIgnoreCase);
                        default:
                            throw new InvalidOperationException("Unexpected ProfileConditionType");
                    }
                }
            }

            else if (condition.Property == ProfileConditionValue.AudioProfile)
            {
                var profile = audioStream == null ? null : audioStream.Profile;

                if (!string.IsNullOrWhiteSpace(profile))
                {
                    switch (condition.Condition)
                    {
                        case ProfileConditionType.Equals:
                            return string.Equals(profile, condition.Value, StringComparison.OrdinalIgnoreCase);
                        case ProfileConditionType.NotEquals:
                            return !string.Equals(profile, condition.Value, StringComparison.OrdinalIgnoreCase);
                        default:
                            throw new InvalidOperationException("Unexpected ProfileConditionType");
                    }
                }
            }

            else
            {
                var actualValue = GetConditionValue(condition, mediaPath, videoStream, audioStream);

                if (actualValue.HasValue)
                {
                    long expected;
                    if (long.TryParse(condition.Value, NumberStyles.Any, _usCulture, out expected))
                    {
                        switch (condition.Condition)
                        {
                            case ProfileConditionType.Equals:
                                return actualValue.Value == expected;
                            case ProfileConditionType.GreaterThanEqual:
                                return actualValue.Value >= expected;
                            case ProfileConditionType.LessThanEqual:
                                return actualValue.Value <= expected;
                            case ProfileConditionType.NotEquals:
                                return actualValue.Value != expected;
                            default:
                                throw new InvalidOperationException("Unexpected ProfileConditionType");
                        }
                    }
                }
            }

            // Value doesn't exist in metadata. Fail it if required.
            return !condition.IsRequired;
        }