Exemple #1
0
 public static M3U8AttributeValueInstance <string> QuotedStringParser(M3U8Attribute attribute, string value)
 {
     if (value.Length < 2 || 34 != (int)value[0] || 34 != (int)value[value.Length - 1])
     {
         return((M3U8AttributeValueInstance <string>)null);
     }
     return((M3U8AttributeValueInstance <string>) new StringAttributeInstance(attribute, value.Substring(1, value.Length - 2)));
 }
        public static M3U8AttributeValueInstance<IEnumerable<string>> QuotedCsvParser(M3U8Attribute attribute, string value)
        {
            value = StripQuotes(value);

            var values = value.Split(',').Select(s => s.Trim()).ToArray();

            return new CsvStringsAttributeInstance(attribute, values);
        }
        public static M3U8AttributeValueInstance<string> QuotedStringParser(M3U8Attribute attribute, string value)
        {
            // TODO: Remove escape characters here.  Fixup StringAttributeInstance.ToString() to match.

            if (value.Length < 2 || '"' != value[0] || '"' != value[value.Length - 1])
            {
                // TODO: Complain...?
                return null;
            }

            return new StringAttributeInstance(attribute, value.Substring(1, value.Length - 2));
        }
        public static M3U8AttributeInstance Create(M3U8Attribute attribute, string value)
        {
            var index = value.IndexOfAny(ResolutionSeparator);

            if (index < 1 || index + 1 >= value.Length)
                return null;

            var x = int.Parse(value.Substring(0, index), CultureInfo.InvariantCulture);
            var y = int.Parse(value.Substring(index + 1), CultureInfo.InvariantCulture);

            return new ResolutionAttributeInstance(attribute, x, y);
        }
Exemple #5
0
        public static M3U8AttributeInstance Create(M3U8Attribute attribute, string value)
        {
            int length = value.IndexOfAny(ResolutionAttributeInstance.ResolutionSeparator);

            if (length < 1 || length + 1 >= value.Length)
            {
                return((M3U8AttributeInstance)null);
            }
            int x = int.Parse(value.Substring(0, length), (IFormatProvider)CultureInfo.InvariantCulture);
            int y = int.Parse(value.Substring(length + 1), (IFormatProvider)CultureInfo.InvariantCulture);

            return((M3U8AttributeInstance) new ResolutionAttributeInstance(attribute, x, y));
        }
Exemple #6
0

        
        public static M3U8AttributeInstance Create(M3U8Attribute attribute, string value)
        {
            // TODO: Consolidate code between ByterangeAttributeInstance and ByterangeTagInstance

            var index = value.IndexOf('@');

            if (index < 0 || index + 1 >= value.Length)
                return new ByterangeAttributeInstance(attribute, long.Parse(value, CultureInfo.InvariantCulture), null);

            var length = long.Parse(value.Substring(0, index), CultureInfo.InvariantCulture);
            var offset = long.Parse(value.Substring(index + 1), CultureInfo.InvariantCulture);

            return new ByterangeAttributeInstance(attribute, length, offset);
        }
Exemple #8
0
        public void Register(M3U8Attribute attribute)
        {
            var oldAttributes = _attributes;

            for (;;)
            {
                var attributes = new Dictionary<string, M3U8Attribute>(oldAttributes);

                attributes[attribute.Name] = attribute;

#pragma warning disable 0420
                var currentAttributes = Interlocked.CompareExchange(ref _attributes, attributes, oldAttributes);
#pragma warning restore 0420

                if (currentAttributes == oldAttributes)
                    return;

                oldAttributes = currentAttributes;
            }
        }
Exemple #9
0
 public HexadecimalIntegerAttributeInstance(M3U8Attribute attribute, byte[] value)
     : base(attribute, value)
 {
 }
Exemple #10
0

        
Exemple #11
0
        public static M3U8AttributeValueInstance <byte[]> HexadecialIntegerParser(M3U8Attribute attribute, string value)
        {
            if (string.IsNullOrWhiteSpace(value))
            {
                return((M3U8AttributeValueInstance <byte[]>)null);
            }
            int num1 = value.IndexOf("0x", StringComparison.OrdinalIgnoreCase);

            if (num1 < 0 || num1 + 2 >= value.Length)
            {
                return((M3U8AttributeValueInstance <byte[]>)null);
            }
            int         num2 = num1 + 2;
            List <byte> list = new List <byte>(16);
            int         num3 = 0;
            bool        flag = false;

            for (int index = num2; index < value.Length; ++index)
            {
                char ch = value[index];
                byte num4;
                if ((int)ch >= 48 && (int)ch <= 57)
                {
                    num4 = (byte)((uint)ch - 48U);
                }
                else if ((int)ch >= 97 && (int)ch <= 102)
                {
                    num4 = (byte)((int)ch - 97 + 10);
                }
                else if ((int)ch >= 65 && (int)ch <= 70)
                {
                    num4 = (byte)((int)ch - 65 + 10);
                }
                else
                {
                    continue;
                }
                if (flag)
                {
                    list.Add((byte)((uint)(num3 << 4) | (uint)num4));
                    flag = false;
                }
                else
                {
                    num3 = (int)num4;
                    flag = true;
                }
            }
            if (flag)
            {
                list.Add((byte)(num3 << 4));
                int num4 = 0;
                for (int index = 0; index < list.Count; ++index)
                {
                    byte num5 = list[index];
                    list[index] = (byte)(num4 << 4 | (int)num5 >> 4);
                    num4        = (int)(byte)((uint)num5 & 15U);
                }
            }
            return((M3U8AttributeValueInstance <byte[]>) new HexadecimalIntegerAttributeInstance(attribute, list.ToArray()));
        }
 public static M3U8AttributeValueInstance<long> DecimalIntegerParser(M3U8Attribute attribute, string value)
 {
     return new M3U8AttributeValueInstance<long>(attribute, long.Parse(value, CultureInfo.InvariantCulture));
 }
Exemple #13
0
 public StringAttributeInstance(M3U8Attribute attribute, string value)
     : base(attribute, value)
 {
 }
Exemple #14
0
 public static M3U8AttributeValueInstance <IEnumerable <string> > QuotedCsvParser(M3U8Attribute attribute, string value)
 {
     value = M3U8AttributeSupport.StripQuotes(value);
     string[] strArray = Enumerable.ToArray <string>(Enumerable.Select <string, string>((IEnumerable <string>)value.Split(','), (Func <string, string>)(s => s.Trim())));
     return((M3U8AttributeValueInstance <IEnumerable <string> >) new CsvStringsAttributeInstance(attribute, (IEnumerable <string>)strArray));
 }
Exemple #15
0
 public M3U8AttributeInstance(M3U8Attribute attribute)
 {
     this.Attribute = attribute;
 }
Exemple #16
0
 public static M3U8AttributeValueInstance <long> DecimalIntegerParser(M3U8Attribute attribute, string value)
 {
     return(new M3U8AttributeValueInstance <long>(attribute, long.Parse(value, (IFormatProvider)CultureInfo.InvariantCulture)));
 }
 public CsvStringsAttributeInstance(M3U8Attribute attribute, IEnumerable <string> codecs)
     : base(attribute, codecs)
 {
 }
 public ResolutionAttributeInstance(M3U8Attribute attribute, int x, int y)
     : base(attribute)
 {
     X = x;
     Y = y;
 }
        /// <summary>
        ///     Parse "hexadecimal-integer" consisting of 0x or 0X followed by 1..n
        /// </summary>
        /// <param name="attribute"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static M3U8AttributeValueInstance<byte[]> HexadecialIntegerParser(M3U8Attribute attribute, string value)
        {
            if (string.IsNullOrWhiteSpace(value))
                return null;

            var start = value.IndexOf("0x", StringComparison.OrdinalIgnoreCase);

            if (start < 0 || start + 2 >= value.Length)
                return null;

            start += 2;

            var bytes = new List<byte>(16);

            var currentNibble = 0;
            var haveNibble = false;

            for (var i = start; i < value.Length; ++i)
            {
                var c = value[i];
                byte v;

                if (c >= '0' && c <= '9')
                    v = (byte)(c - '0');
                else if (c >= 'a' && c <= 'f')
                    v = (byte)(c - 'a' + 10);
                else if (c >= 'A' && c <= 'F')
                    v = (byte)(c - 'A' + 10);
                else
                {
                    // Skip everything else or fail?
                    // Are spaces okay?

                    continue;
                }

                if (haveNibble)
                {
                    bytes.Add((byte)((currentNibble << 4) | v));
                    haveNibble = false;
                }
                else
                {
                    currentNibble = v;
                    haveNibble = true;
                }
            }

            if (haveNibble)
            {
                // We now discover that we actually needed a leading zero when we first started...
                bytes.Add((byte)(currentNibble << 4));

                currentNibble = 0;

                for (var i = 0; i < bytes.Count; ++i)
                {
                    var b = bytes[i];

                    bytes[i] = (byte)((currentNibble << 4) | (b >> 4));

                    currentNibble = (byte)(b & 0x0f);
                }
            }

            return new HexadecimalIntegerAttributeInstance(attribute, bytes.ToArray());
        }
 public ByterangeAttributeInstance(M3U8Attribute attribute, long length, long? offset)
     : base(attribute)
 {
     Length = length;
     Offset = offset;
 }
Exemple #21
0
 public ResolutionAttributeInstance(M3U8Attribute attribute, int x, int y)
     : base(attribute)
 {
     this.X = x;
     this.Y = y;
 }
 public M3U8AttributeValueInstance(M3U8Attribute attribute, TValue value)
     : base(attribute)
 {
     this.Value = value;
 }
 public M3U8AttributeInstance(M3U8Attribute attribute)
 {
     Attribute = attribute;
 }