Esempio n. 1
0
        public static Box FromStream(Stream stream, BaseMediaOptions options = BaseMediaOptions.LoadChildren)
        {
            Box box = null;

            try
            {
                ulong offset = (ulong)stream.Position;

                uint  size      = stream.ReadBEUInt32();
                uint  type      = stream.ReadBEUInt32();
                ulong?largeSize = null;

                if (size == 1)
                {
                    largeSize = stream.ReadBEUInt64();
                }

                BoxType boxType = (type == uuidType)
                    ? new BoxType(new Guid(stream.ReadBytes(16)))
                    : new BoxType(type);

                AvailableBoxTypes.TryGetValue(boxType, out Type t);

                box = t != null ? (Box)Activator.CreateInstance(t) : new Boxes.UnknownBox(boxType);

                box.Size      = size;
                box.LargeSize = largeSize;
                box.Offset    = offset;
                box.Initialize(ConstrainedStream.WrapStream(stream), options);
            }
            catch (EndOfStreamException) { }

            return(box);
        }
Esempio n. 2
0
 protected Box()
 {
     BoxAttribute[] boxAttributes = (BoxAttribute[])this.GetType().GetCustomAttributes(typeof(BoxAttribute), true);
     if (boxAttributes != null && boxAttributes.Length != 0)
     {
         Type = boxAttributes[0].Type;
     }
     else if (!(this is Boxes.UnknownBox))
     {
         throw new Exception("BMFF Box derivative is not decorated with a BoxAttribute.");
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Deserializes a specific box type from the stream.
        /// </summary>
        /// <exception cref="System.FormatException">Thrown when the next box in the stream is not the expected type.</exception>
        /// <param name="stream">Stream containing the box to be deserialized at the current position.</param>
        protected Box(Stream stream)
        {
            Offset = (ulong)stream.Position;

            Size = stream.ReadBEUInt32();
            uint type = stream.ReadBEUInt32();

            if (Size == 1)
            {
                LargeSize = stream.ReadBEUInt64();
            }

            if (type == 0x75756964) // 'uuid'
            {
                Type = new BoxType(new Guid(stream.ReadBytes(16)));
            }
            else
            {
                Type = new BoxType(type);
            }

            bool foundMatchingAttribute = false;

            object[] boxAttributes = this.GetType().GetCustomAttributes(typeof(BoxAttribute), true);
            foreach (BoxAttribute boxAttribute in boxAttributes)
            {
                if (boxAttribute.Type == Type)
                {
                    foundMatchingAttribute = true;
                }
            }
            if (!foundMatchingAttribute)
            {
                throw new FormatException("Unexpected BMFF Box Type.");
            }

            Initialize(stream);
        }
Esempio n. 4
0
 public BoxAttribute(Guid uuid, string description = null)
 {
     Type        = new BoxType(uuid);
     Description = description;
 }
Esempio n. 5
0
 public BoxAttribute(int type, string description = null)
 {
     Type        = new BoxType((uint)type);
     Description = description;
 }
Esempio n. 6
0
 public BoxAttribute(string type, string description = null)
 {
     Type        = new BoxType(type);
     Description = description;
 }
Esempio n. 7
0
 public BoxAttribute(Guid uuid, string description = null)
 {
     Type = new BoxType(uuid);
     Description = description;
 }
Esempio n. 8
0
 public BoxAttribute(int type, string description = null)
 {
     Type = new BoxType((uint)type);
     Description = description;
 }
Esempio n. 9
0
 public BoxAttribute(string type, string description = null)
 {
     Type = new BoxType(type);
     Description = description;
 }