예제 #1
0
파일: Box.cs 프로젝트: mcguirepr/bmff
        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);
        }
예제 #2
0
파일: Box.cs 프로젝트: evgeniylevakhin/bmff
 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.");
     }
 }
예제 #3
0
파일: Box.cs 프로젝트: evgeniylevakhin/bmff
        /// <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);
        }
예제 #4
0
 public BoxAttribute(Guid uuid, string description = null)
 {
     Type        = new BoxType(uuid);
     Description = description;
 }
예제 #5
0
 public BoxAttribute(int type, string description = null)
 {
     Type        = new BoxType((uint)type);
     Description = description;
 }
예제 #6
0
 public BoxAttribute(string type, string description = null)
 {
     Type        = new BoxType(type);
     Description = description;
 }
예제 #7
0
 public BoxAttribute(Guid uuid, string description = null)
 {
     Type = new BoxType(uuid);
     Description = description;
 }
예제 #8
0
 public BoxAttribute(int type, string description = null)
 {
     Type = new BoxType((uint)type);
     Description = description;
 }
예제 #9
0
 public BoxAttribute(string type, string description = null)
 {
     Type = new BoxType(type);
     Description = description;
 }