/// <summary> /// Adds a specified box to the current instance. /// </summary> /// <param name="box"> /// A <see cref="Box" /> object to add to the current /// instance. /// </param> public void AddChild (Box box) { ICollection<Box> children = Children as ICollection<Box>; if (children != null) children.Add (box); }
/// <summary> /// Constructs and initializes a new instance of <see /// cref="BoxHeader" /> with a specified box type and /// optionally extended type. /// </summary> /// <param name="type"> /// A <see cref="ByteVector" /> object containing the four /// byte box type. /// </param> /// <param name="extendedType"> /// A <see cref="ByteVector" /> object containing the four /// byte box type. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="type" /> is <see langref="null" /> - or - /// <paramref name="type" /> is equal to "<c>uuid</c>" and /// <paramref name="extendedType" /> is <see langref="null" /// />. /// </exception> /// <exception cref="ArgumentException"> /// <paramref name="type" /> isn't exactly 4 bytes long - or /// - <paramref name="type" /> isn't "<c>uuid</c>" but /// <paramref name="extendedType" /> isn't <see /// langref="null" /> - or - paramref name="type" /> is /// "<c>uuid</c>" but <paramref name="extendedType" /> isn't /// exactly 16 bytes long. /// </exception> public BoxHeader (ByteVector type, ByteVector extendedType) { position = -1; box = null; from_disk = false; box_type = type; if (type == null) throw new ArgumentNullException ("type"); if (type.Count != 4) throw new ArgumentException ( "Box type must be 4 bytes in length.", "type"); box_size = header_size = 8; if (type != "uuid") { if (extendedType != null) throw new ArgumentException ( "Extended type only permitted for 'uuid'.", "extendedType"); this.extended_type = extendedType; return; } if (extendedType == null) throw new ArgumentNullException ("extendedType"); if (extendedType.Count != 16) throw new ArgumentException ( "Extended type must be 16 bytes in length.", "extendedType"); box_size = header_size = 24; this.extended_type = extendedType; }
/* /// <summary> /// Removes all children with a specified box type from the /// current instance. /// </summary> /// <param name="type"> /// A <see cref="ByteVector" /> object containing the box /// type to remove. /// </param> public void RemoveChild (System.Type type) { ICollection<Box> children = Children as ICollection<Box>; if (children == null) return; foreach (Box b in new List<Box> (children)) if (b.GetType () == type) children.Remove (b); } */ /// <summary> /// Removes a specified box from the current instance. /// </summary> /// <param name="box"> /// A <see cref="Box" /> object to remove from the current /// instance. /// </param> public void RemoveChild (Box box) { ICollection<Box> children = Children as ICollection<Box>; if (children != null) children.Remove (box); }
/// <summary> /// Constructs and initializes a new instance of <see /// cref="BoxHeader" /> by reading it from a specified seek /// position in a specified file. /// </summary> /// <param name="file"> /// A <see cref="TagLib.File" /> object to read the new /// instance from. /// </param> /// <param name="position"> /// A <see cref="long" /> value specifiying the seek position /// in <paramref name="file" /> at which to start reading. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="file" /> is <see langword="null" />. /// </exception> /// <exception cref="CorruptFileException"> /// There isn't enough data in the file to read the complete /// header. /// </exception> public BoxHeader (TagLib.File file, long position) { if (file == null) throw new ArgumentNullException ("file"); this.box = null; this.from_disk = true; this.position = position; file.Seek (position); ByteVector data = file.ReadBlock (32); int offset = 0; if (data.Count < 8 + offset) throw new CorruptFileException ( "Not enough data in box header."); header_size = 8; box_size = data.Mid (offset, 4).ToUInt (); box_type = data.Mid (offset + 4, 4); // If the size is 1, that just tells us we have a // massive ULONG size waiting for us in the next 8 // bytes. if (box_size == 1) { if (data.Count < 8 + offset) throw new CorruptFileException ( "Not enough data in box header."); header_size += 8; box_size = data.Mid (offset, 8).ToULong (); offset += 8; } // UUID has a special header with 16 extra bytes. if (box_type == Mpeg4.BoxType.Uuid) { if (data.Count < 16 + offset) throw new CorruptFileException ( "Not enough data in box header."); header_size += 16; extended_type = data.Mid (offset, 16); } else extended_type = null; }