Exemplo n.º 1
0
        /// <summary>
        ///    Loads the children of the current instance from a
        ///    specified file using the internal data position and size.
        /// </summary>
        /// <param name="file">
        ///    The <see cref="TagLibSharp.File" /> from which the current
        ///    instance was read and from which to read the children.
        /// </param>
        /// <returns>
        ///    A <see cref="T:System.Collections.Generic.IEnumerable`1" /> object enumerating the
        ///    boxes read from the file.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        ///    <paramref name="file" /> is <see langword="null" />.
        /// </exception>
        protected IEnumerable <Box> LoadChildren(TagLibSharp.File file)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }

            List <Box> children = new List <Box> ();

            long position = DataPosition;
            long end      = position + DataSize;

            header.Box = this;
            while (position < end)
            {
                Box child = BoxFactory.CreateBox(file,
                                                 position, header, handler,
                                                 children.Count);
                children.Add(child);
                position += child.Size;
            }
            header.Box = null;

            return(children);
        }
Exemplo n.º 2
0
        /// <summary>
        ///    Creates a box by reading it from a file given its
        ///    position in the file, parent header, handler, and index
        ///    in its parent.
        /// </summary>
        /// <param name="file">
        ///    A <see cref="TagLibSharp.File" /> object containing the file
        ///    to read from.
        /// </param>
        /// <param name="position">
        ///    A <see cref="long" /> value specifying at what seek
        ///    position in <paramref name="file" /> to start reading.
        /// </param>
        /// <param name="parent">
        ///    A <see cref="BoxHeader" /> object containing the header
        ///    of the parent box.
        /// </param>
        /// <param name="handler">
        ///    A <see cref="IsoHandlerBox" /> object containing the
        ///    handler that applies to the new box.
        /// </param>
        /// <param name="index">
        ///    A <see cref="int" /> value containing the index of the
        ///    new box in its parent.
        /// </param>
        /// <returns>
        ///    A newly created <see cref="Box" /> object.
        /// </returns>
        internal static Box CreateBox(TagLibSharp.File file, long position,
                                      BoxHeader parent,
                                      IsoHandlerBox handler, int index)
        {
            BoxHeader header = new BoxHeader(file, position);

            return(CreateBox(file, header, parent, handler, index));
        }
Exemplo n.º 3
0
        /// <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="TagLibSharp.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(TagLibSharp.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;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        ///    Loads the data of the current instance from a specified
        ///    file using the internal data position and size.
        /// </summary>
        /// <param name="file">
        ///    The <see cref="TagLibSharp.File" /> from which the current
        ///    instance was read and from which to read the data.
        /// </param>
        /// <returns>
        ///    A <see cref="ByteVector" /> object containing the data
        ///    read from the file.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        ///    <paramref name="file" /> is <see langword="null" />.
        /// </exception>
        protected ByteVector LoadData(TagLibSharp.File file)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }

            file.Seek(DataPosition);
            return(file.ReadBlock(DataSize));
        }
Exemplo n.º 5
0
        /// <summary>
        ///    Constructs and initializes a new instance of <see
        ///    cref="UnknownBox" /> with a provided header and handler
        ///    by reading the contents from a specified file.
        /// </summary>
        /// <param name="header">
        ///    A <see cref="BoxHeader" /> object containing the header
        ///    to use for the new instance.
        /// </param>
        /// <param name="file">
        ///    A <see cref="TagLibSharp.File" /> object to read the contents
        ///    of the box from.
        /// </param>
        /// <param name="handler">
        ///    A <see cref="IsoHandlerBox" /> object containing the
        ///    handler that applies to the new instance.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///    <paramref name="file" /> is <see langword="null" />.
        /// </exception>
        public UnknownBox(BoxHeader header, TagLibSharp.File file,
                          IsoHandlerBox handler)
            : base(header, handler)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }

            this.data = LoadData(file);
        }
        /// <summary>
        ///    Constructs and initializes a new instance of <see
        ///    cref="AppleItemListBox" /> with a provided header and
        ///    handler by reading the contents from a specified file.
        /// </summary>
        /// <param name="header">
        ///    A <see cref="BoxHeader" /> object containing the header
        ///    to use for the new instance.
        /// </param>
        /// <param name="file">
        ///    A <see cref="TagLibSharp.File" /> object to read the contents
        ///    of the box from.
        /// </param>
        /// <param name="handler">
        ///    A <see cref="IsoHandlerBox" /> object containing the
        ///    handler that applies to the new instance.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///    <paramref name="file" /> is <see langword="null" />.
        /// </exception>
        public AppleItemListBox(BoxHeader header, TagLibSharp.File file,
                                IsoHandlerBox handler)
            : base(header, handler)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }

            children = LoadChildren(file);
        }
Exemplo n.º 7
0
        /// <summary>
        ///    Constructs and initializes a new instance of <see
        ///    cref="IsoSampleEntry" /> with a provided header and
        ///    handler by reading the contents from a specified file.
        /// </summary>
        /// <param name="header">
        ///    A <see cref="BoxHeader" /> object containing the header
        ///    to use for the new instance.
        /// </param>
        /// <param name="file">
        ///    A <see cref="TagLibSharp.File" /> object to read the contents
        ///    of the box from.
        /// </param>
        /// <param name="handler">
        ///    A <see cref="IsoHandlerBox" /> object containing the
        ///    handler that applies to the new instance.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///    <paramref name="file" /> is <see langword="null" />.
        /// </exception>
        public IsoSampleEntry(BoxHeader header, TagLibSharp.File file,
                              IsoHandlerBox handler)
            : base(header, handler)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }

            file.Seek(base.DataPosition + 6);
            data_reference_index = file.ReadBlock(2).ToUShort();
        }
Exemplo n.º 8
0
        /// <summary>
        ///    Constructs and initializes a new instance of <see
        ///    cref="IsoSampleDescriptionBox" /> with a provided header
        ///    and handler by reading the contents from a specified
        ///    file.
        /// </summary>
        /// <param name="header">
        ///    A <see cref="BoxHeader" /> object containing the header
        ///    to use for the new instance.
        /// </param>
        /// <param name="file">
        ///    A <see cref="TagLibSharp.File" /> object to read the contents
        ///    of the box from.
        /// </param>
        /// <param name="handler">
        ///    A <see cref="IsoHandlerBox" /> object containing the
        ///    handler that applies to the new instance.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///    <paramref name="file" /> is <see langword="null" />.
        /// </exception>
        public IsoSampleDescriptionBox(BoxHeader header,
                                       TagLibSharp.File file,
                                       IsoHandlerBox handler)
            : base(header, file, handler)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }

            entry_count = file.ReadBlock(4).ToUInt();
            children    = LoadChildren(file);
        }
        /*
         * /// <summary>
         * ///    Contains the children of the box.
         * /// </summary>
         * private BoxList children;
         */

        #endregion



        #region Constructors

        /// <summary>
        ///    Constructs and initializes a new instance of <see
        ///    cref="IsoVisualSampleEntry" /> with a provided header and
        ///    handler by reading the contents from a specified file.
        /// </summary>
        /// <param name="header">
        ///    A <see cref="BoxHeader" /> object containing the header
        ///    to use for the new instance.
        /// </param>
        /// <param name="file">
        ///    A <see cref="TagLibSharp.File" /> object to read the contents
        ///    of the box from.
        /// </param>
        /// <param name="handler">
        ///    A <see cref="IsoHandlerBox" /> object containing the
        ///    handler that applies to the new instance.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///    <paramref name="file" /> is <see langword="null" />.
        /// </exception>
        public IsoVisualSampleEntry(BoxHeader header, TagLibSharp.File file,
                                    IsoHandlerBox handler)
            : base(header, file, handler)
        {
            file.Seek(base.DataPosition + 16);
            width  = file.ReadBlock(2).ToUShort();
            height = file.ReadBlock(2).ToUShort();

            /*
             * TODO: What are the children anyway?
             * children = LoadChildren (file);
             */
        }
Exemplo n.º 10
0
        /// <summary>
        ///    Searches for an audio header in a <see cref="TagLibSharp.File"
        ///    /> starting at a specified position and searching through
        ///    a specified number of bytes.
        /// </summary>
        /// <param name="header">
        ///    A <see cref="AudioHeader" /> object in which the found
        ///    header will be stored.
        /// </param>
        /// <param name="file">
        ///    A <see cref="TagLibSharp.File" /> object to search.
        /// </param>
        /// <param name="position">
        ///    A <see cref="long" /> value specifying the seek position
        ///    in <paramref name="file" /> at which to start searching.
        /// </param>
        /// <param name="length">
        ///    A <see cref="int" /> value specifying the maximum number
        ///    of bytes to search before aborting.
        /// </param>
        /// <returns>
        ///    A <see cref="bool" /> value indicating whether or not a
        ///    header was found.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        ///    <paramref name="file" /> is <see langword="null" />.
        /// </exception>
        public static bool Find(out AudioHeader header,
                                TagLibSharp.File file, long position,
                                int length)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }

            long end = position + length;

            header = AudioHeader.Unknown;

            file.Seek(position);

            ByteVector buffer = file.ReadBlock(3);

            if (buffer.Count < 3)
            {
                return(false);
            }

            do
            {
                file.Seek(position + 3);
                buffer = buffer.Mid(buffer.Count - 3);
                buffer.Add(file.ReadBlock(
                               (int)File.BufferSize));

                for (int i = 0; i < buffer.Count - 3 &&
                     (length < 0 || position + i < end); i++)
                {
                    if (buffer [i] == 0xFF &&
                        buffer [i + 1] > 0xE0)
                    {
                        try {
                            header = new AudioHeader(
                                buffer.Mid(i, 4),
                                file, position + i);
                            return(true);
                        } catch (CorruptFileException) {
                        }
                    }
                }

                position += File.BufferSize;
            } while (buffer.Count > 3 && (length < 0 || position < end));

            return(false);
        }
Exemplo n.º 11
0
        /// <summary>
        ///    Constructs and initializes a new instance of <see
        ///    cref="IsoChunkOffsetBox" /> with a provided header and
        ///    handler by reading the contents from a specified file.
        /// </summary>
        /// <param name="header">
        ///    A <see cref="BoxHeader" /> object containing the header
        ///    to use for the new instance.
        /// </param>
        /// <param name="file">
        ///    A <see cref="TagLibSharp.File" /> object to read the contents
        ///    of the box from.
        /// </param>
        /// <param name="handler">
        ///    A <see cref="IsoHandlerBox" /> object containing the
        ///    handler that applies to the new instance.
        /// </param>
        public IsoChunkOffsetBox(BoxHeader header, TagLibSharp.File file,
                                 IsoHandlerBox handler)
            : base(header, file, handler)
        {
            ByteVector box_data = file.ReadBlock(DataSize);

            offsets = new uint [(int)
                                box_data.Mid(0, 4).ToUInt()];

            for (int i = 0; i < offsets.Length; i++)
            {
                offsets [i] = box_data.Mid(4 + i * 4,
                                           4).ToUInt();
            }
        }
Exemplo n.º 12
0
        /// <summary>
        ///    Constructs and initializes a new instance of <see
        ///    cref="FullBox" /> with a provided header and handler by
        ///    reading the contents from a specified file.
        /// </summary>
        /// <param name="header">
        ///    A <see cref="BoxHeader" /> object containing the header
        ///    to use for the new instance.
        /// </param>
        /// <param name="file">
        ///    A <see cref="TagLibSharp.File" /> object to read the contents
        ///    of the box from.
        /// </param>
        /// <param name="handler">
        ///    A <see cref="IsoHandlerBox" /> object containing the
        ///    handler that applies to the new instance.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///    <paramref name="file" /> is <see langword="null" />.
        /// </exception>
        protected FullBox(BoxHeader header, TagLibSharp.File file,
                          IsoHandlerBox handler)
            : base(header, handler)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }

            file.Seek(base.DataPosition);
            ByteVector header_data = file.ReadBlock(4);

            version = header_data [0];
            flags   = header_data.Mid(1, 3).ToUInt();
        }
Exemplo n.º 13
0
        /// <summary>
        ///    Constructs and initializes a new instance of <see
        ///    cref="AviHeaderList" /> by reading the contents of a raw
        ///    RIFF list from a specified position in a <see
        ///    cref="TagLibSharp.File"/>.
        /// </summary>
        /// <param name="file">
        ///    A <see cref="TagLibSharp.File" /> object containing the file
        ///    from which the contents of the new instance is to be
        ///    read.
        /// </param>
        /// <param name="position">
        ///    A <see cref="long" /> value specify at what position to
        ///    read the list.
        /// </param>
        /// <param name="length">
        ///    A <see cref="int" /> value specifying the number of bytes
        ///    to read.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///    <paramref name="file" /> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        ///    <paramref name="position" /> is less than zero or greater
        ///    than the size of the file.
        /// </exception>
        /// <exception cref="CorruptFileException">
        ///    The list does not contain an AVI header or the AVI header
        ///    is the wrong length.
        /// </exception>
        public AviHeaderList(TagLibSharp.File file, long position,
                             int length)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }

            if (length < 0)
            {
                throw new ArgumentOutOfRangeException(
                          "length");
            }

            if (position < 0 || position > file.Length - length)
            {
                throw new ArgumentOutOfRangeException(
                          "position");
            }

            List list = new List(file, position, length);

            if (!list.ContainsKey("avih"))
            {
                throw new CorruptFileException(
                          "Avi header not found.");
            }

            ByteVector header_data = list ["avih"][0];

            if (header_data.Count != 0x38)
            {
                throw new CorruptFileException(
                          "Invalid header length.");
            }

            header = new AviHeader(header_data, 0);

            foreach (ByteVector list_data in list["LIST"])
            {
                if (list_data.StartsWith("strl"))
                {
                    codecs.Add(AviStream
                               .ParseStreamList(list_data)
                               .Codec);
                }
            }
        }
Exemplo n.º 14
0
        /// <summary>
        ///    Constructs and initializes a new instance of <see
        ///    cref="FileParser" /> for a specified file.
        /// </summary>
        /// <param name="file">
        ///    A <see cref="TagLibSharp.File" /> object to perform operations
        ///    on.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///    <paramref name="file" /> is <see langword="null" />.
        /// </exception>
        /// <exception cref="CorruptFileException">
        ///    <paramref name="file" /> does not start with a
        ///    "<c>ftyp</c>" box.
        /// </exception>
        public FileParser(TagLibSharp.File file)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }

            this.file    = file;
            first_header = new BoxHeader(file, 0);

            if (first_header.BoxType != "ftyp")
            {
                throw new CorruptFileException(
                          "File does not start with 'ftyp' box.");
            }
        }
Exemplo n.º 15
0
        /// <summary>
        ///    Constructs and initializes a new instance of <see
        ///    cref="IsoVisualSampleEntry" /> with a provided header and
        ///    handler by reading the contents from a specified file.
        /// </summary>
        /// <param name="header">
        ///    A <see cref="BoxHeader" /> object containing the header
        ///    to use for the new instance.
        /// </param>
        /// <param name="file">
        ///    A <see cref="TagLibSharp.File" /> object to read the contents
        ///    of the box from.
        /// </param>
        /// <param name="handler">
        ///    A <see cref="IsoHandlerBox" /> object containing the
        ///    handler that applies to the new instance.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///    <paramref name="file" /> is <see langword="null" />.
        /// </exception>
        public IsoAudioSampleEntry(BoxHeader header, TagLibSharp.File file,
                                   IsoHandlerBox handler)
            : base(header, file, handler)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }

            file.Seek(base.DataPosition + 8);
            channel_count = file.ReadBlock(2).ToUShort();
            sample_size   = file.ReadBlock(2).ToUShort();
            file.Seek(base.DataPosition + 16);
            sample_rate = file.ReadBlock(4).ToUInt();
            children    = LoadChildren(file);
        }
Exemplo n.º 16
0
        /// <summary>
        ///    Overwrites the header on disk, updating it to include a
        ///    change in the size of the box.
        /// </summary>
        /// <param name="file">
        ///    A <see cref="TagLibSharp.File" /> object containing the file
        ///    from which the box originates.
        /// </param>
        /// <param name="sizeChange">
        ///    A <see cref="long" /> value indicating the change in the
        ///    size of the box described by the current instance.
        /// </param>
        /// <returns>
        ///    The size change encountered by the box that parents the
        ///    box described the the current instance, equal to the
        ///    size change of the box plus any size change that should
        ///    happen in the header.
        /// </returns>
        public long Overwrite(TagLibSharp.File file, long sizeChange)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }

            if (!from_disk)
            {
                throw new InvalidOperationException(
                          "Cannot overwrite headers not on disk.");
            }

            long old_header_size = HeaderSize;

            DataSize += sizeChange;
            file.Insert(Render(), position, old_header_size);
            return(sizeChange + HeaderSize - old_header_size);
        }
Exemplo n.º 17
0
        /// <summary>
        ///    Constructs and initializes a new instance of <see
        ///    cref="ListTag" /> by reading the contents of a raw RIFF
        ///    list from a specified position in a <see
        ///    cref="TagLibSharp.File" />.
        /// </summary>
        /// <param name="file">
        ///    A <see cref="TagLibSharp.File" /> object containing the file
        ///    from which the contents of the new instance is to be
        ///    read.
        /// </param>
        /// <param name="position">
        ///    A <see cref="long" /> value specify at what position to
        ///    read the list.
        /// </param>
        /// <param name="length">
        ///    A <see cref="int" /> value specifying the number of bytes
        ///    to read.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///    <paramref name="file" /> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        ///    <paramref name="position" /> is less than zero or greater
        ///    than the size of the file.
        /// </exception>
        protected ListTag(TagLibSharp.File file, long position, int length)
        {
            if (file == null)
            {
                throw new System.ArgumentNullException("file");
            }

            if (length < 0)
            {
                throw new ArgumentOutOfRangeException(
                          "length");
            }

            if (position < 0 || position > file.Length - length)
            {
                throw new ArgumentOutOfRangeException(
                          "position");
            }

            fields = new List(file, position, length);
        }
Exemplo n.º 18
0
        /// <summary>
        ///    Constructs and initializes a new instance of <see
        ///    cref="VideoHeader" /> by reading it from a specified
        ///    location in a specified file.
        /// </summary>
        /// <param name="file">
        ///    A <see cref="TagLibSharp.File" /> object to read from.
        /// </param>
        /// <param name="position">
        ///    A <see cref="long" /> value indicating the position in
        ///    <paramref name="file" /> at which the header begins.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///    <paramref name="file" /> is <see langword="null" />.
        /// </exception>
        /// <exception cref="CorruptFileException">
        ///    Insufficient data could be read for the header.
        /// </exception>
        public VideoHeader(TagLibSharp.File file, long position)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }

            file.Seek(position);
            ByteVector data = file.ReadBlock(7);

            if (data.Count < 7)
            {
                throw new CorruptFileException(
                          "Insufficient data in header.");
            }

            width            = data.Mid(0, 2).ToUShort() >> 4;
            height           = data.Mid(1, 2).ToUShort() & 0x0FFF;
            frame_rate_index = data [3] & 0x0F;
            bitrate          = (int)((data.Mid(4, 3).ToUInt() >> 6) &
                                     0x3FFFF);
        }
Exemplo n.º 19
0
        /// <summary>
        ///    Constructs and initializes a new instance of <see
        ///    cref="List" /> by reading the contents of a raw RIFF list
        ///    from a specified position in a <see cref="TagLibSharp.File"/>.
        /// </summary>
        /// <param name="file">
        ///    A <see cref="TagLibSharp.File" /> object containing the file
        ///    from which the contents of the new instance is to be
        ///    read.
        /// </param>
        /// <param name="position">
        ///    A <see cref="long" /> value specify at what position to
        ///    read the list.
        /// </param>
        /// <param name="length">
        ///    A <see cref="int" /> value specifying the number of bytes
        ///    to read.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///    <paramref name="file" /> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        ///    <paramref name="position" /> is less than zero or greater
        ///    than the size of the file.
        /// </exception>
        public List(TagLibSharp.File file, long position, int length)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }

            if (length < 0)
            {
                throw new ArgumentOutOfRangeException(
                          "length");
            }

            if (position < 0 || position > file.Length - length)
            {
                throw new ArgumentOutOfRangeException(
                          "position");
            }

            file.Seek(position);
            Parse(file.ReadBlock(length));
        }
Exemplo n.º 20
0
        /// <summary>
        ///    Constructs and initializes a new instance of <see
        ///    cref="IsoHandlerBox" /> with a provided header and
        ///    handler by reading the contents from a specified file.
        /// </summary>
        /// <param name="header">
        ///    A <see cref="BoxHeader" /> object containing the header
        ///    to use for the new instance.
        /// </param>
        /// <param name="file">
        ///    A <see cref="TagLibSharp.File" /> object to read the contents
        ///    of the box from.
        /// </param>
        /// <param name="handler">
        ///    A <see cref="IsoHandlerBox" /> object containing the
        ///    handler that applies to the new instance.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///    <paramref name="file" /> is <see langword="null" />.
        /// </exception>
        public IsoHandlerBox(BoxHeader header, TagLibSharp.File file,
                             IsoHandlerBox handler)
            : base(header, file, handler)
        {
            if (file == null)
            {
                throw new System.ArgumentNullException("file");
            }

            file.Seek(DataPosition + 4);
            ByteVector box_data = file.ReadBlock(DataSize - 4);

            handler_type = box_data.Mid(0, 4);

            int end = box_data.Find((byte)0, 16);

            if (end < 16)
            {
                end = box_data.Count;
            }
            name = box_data.ToString(StringType.UTF8, 16, end - 16);
        }
Exemplo n.º 21
0
 /// <summary>
 ///    Creates a box by reading it from a file given its header
 ///    and handler.
 /// </summary>
 /// <param name="file">
 ///    A <see cref="TagLibSharp.File" /> object containing the file
 ///    to read from.
 /// </param>
 /// <param name="header">
 ///    A <see cref="BoxHeader" /> object containing the header
 ///    of the box to create.
 /// </param>
 /// <returns>
 ///    A newly created <see cref="Box" /> object.
 /// </returns>
 public static Box CreateBox(TagLibSharp.File file, BoxHeader header)
 {
     return(CreateBox(file, header, null));
 }
Exemplo n.º 22
0
 /// <summary>
 ///    Constructs and initializes a new instance of <see
 ///    cref="IsoMetaBox" /> with a provided header and
 ///    handler by reading the contents from a specified file.
 /// </summary>
 /// <param name="header">
 ///    A <see cref="BoxHeader" /> object containing the header
 ///    to use for the new instance.
 /// </param>
 /// <param name="file">
 ///    A <see cref="TagLibSharp.File" /> object to read the contents
 ///    of the box from.
 /// </param>
 /// <param name="handler">
 ///    A <see cref="IsoHandlerBox" /> object containing the
 ///    handler that applies to the new instance.
 /// </param>
 public IsoFreeSpaceBox(BoxHeader header, TagLibSharp.File file,
                        IsoHandlerBox handler)
     : base(header, handler)
 {
     padding = DataSize;
 }
Exemplo n.º 23
0
 /// <summary>
 ///    Constructs and initializes a new instance of <see
 ///    cref="IsoMetaBox" /> with a provided header and
 ///    handler by reading the contents from a specified file.
 /// </summary>
 /// <param name="header">
 ///    A <see cref="BoxHeader" /> object containing the header
 ///    to use for the new instance.
 /// </param>
 /// <param name="file">
 ///    A <see cref="TagLibSharp.File" /> object to read the contents
 ///    of the box from.
 /// </param>
 /// <param name="handler">
 ///    A <see cref="IsoHandlerBox" /> object containing the
 ///    handler that applies to the new instance.
 /// </param>
 /// <exception cref="ArgumentNullException">
 ///    <paramref name="file" /> is <see langword="null" />.
 /// </exception>
 public IsoMetaBox(BoxHeader header, TagLibSharp.File file,
                   IsoHandlerBox handler)
     : base(header, file, handler)
 {
     children = LoadChildren(file);
 }
Exemplo n.º 24
0
 /// <summary>
 ///    Constructs and initializes a new instance of <see
 ///    cref="InfoTag" /> by reading the contents of a raw RIFF
 ///    list from a specified position in a <see
 ///    cref="TagLibSharp.File"/>.
 /// </summary>
 /// <param name="file">
 ///    A <see cref="TagLibSharp.File" /> object containing the file
 ///    from which the contents of the new instance is to be
 ///    read.
 /// </param>
 /// <param name="position">
 ///    A <see cref="long" /> value specify at what position to
 ///    read the list.
 /// </param>
 /// <param name="length">
 ///    A <see cref="int" /> value specifying the number of bytes
 ///    to read.
 /// </param>
 /// <exception cref="ArgumentNullException">
 ///    <paramref name="file" /> is <see langword="null" />.
 /// </exception>
 /// <exception cref="ArgumentOutOfRangeException">
 ///    <paramref name="position" /> is less than zero or greater
 ///    than the size of the file.
 /// </exception>
 public InfoTag(TagLibSharp.File file, long position, int length)
     : base(file, position, length)
 {
 }
Exemplo n.º 25
0
 /// <summary>
 ///    Constructs and initializes a new instance of <see
 ///    cref="AppleAdditionalInfoBox" /> with a provided header
 ///    and handler by reading the contents from a specified
 ///    file.
 /// </summary>
 /// <param name="header">
 ///    A <see cref="BoxHeader" /> object containing the header
 ///    to use for the new instance.
 /// </param>
 /// <param name="file">
 ///    A <see cref="TagLibSharp.File" /> object to read the contents
 ///    of the box from.
 /// </param>
 /// <param name="handler">
 ///    A <see cref="IsoHandlerBox" /> object containing the
 ///    handler that applies to the new instance.
 /// </param>
 /// <exception cref="ArgumentNullException">
 ///    <paramref name="file" /> is <see langword="null" />.
 /// </exception>
 public AppleAdditionalInfoBox(BoxHeader header, TagLibSharp.File file, IsoHandlerBox handler) : base(header, file, handler)
 {
     Data = file.ReadBlock(DataSize);
 }
Exemplo n.º 26
0
 /// <summary>
 ///    Creates a box by reading it from a file given its
 ///    position in the file and handler.
 /// </summary>
 /// <param name="file">
 ///    A <see cref="TagLibSharp.File" /> object containing the file
 ///    to read from.
 /// </param>
 /// <param name="position">
 ///    A <see cref="long" /> value specifying at what seek
 ///    position in <paramref name="file" /> to start reading.
 /// </param>
 /// <param name="handler">
 ///    A <see cref="IsoHandlerBox" /> object containing the
 ///    handler that applies to the new box.
 /// </param>
 /// <returns>
 ///    A newly created <see cref="Box" /> object.
 /// </returns>
 public static Box CreateBox(TagLibSharp.File file, long position,
                             IsoHandlerBox handler)
 {
     return(CreateBox(file, position, BoxHeader.Empty,
                      handler, -1));
 }
Exemplo n.º 27
0
        /// <summary>
        ///    Creates a box by reading it from a file given its header,
        ///    parent header, handler, and index in its parent.
        /// </summary>
        /// <param name="file">
        ///    A <see cref="TagLibSharp.File" /> object containing the file
        ///    to read from.
        /// </param>
        /// <param name="header">
        ///    A <see cref="BoxHeader" /> object containing the header
        ///    of the box to create.
        /// </param>
        /// <param name="parent">
        ///    A <see cref="BoxHeader" /> object containing the header
        ///    of the parent box.
        /// </param>
        /// <param name="handler">
        ///    A <see cref="IsoHandlerBox" /> object containing the
        ///    handler that applies to the new box.
        /// </param>
        /// <param name="index">
        ///    A <see cref="int" /> value containing the index of the
        ///    new box in its parent.
        /// </param>
        /// <returns>
        ///    A newly created <see cref="Box" /> object.
        /// </returns>
        private static Box CreateBox(TagLibSharp.File file,
                                     BoxHeader header,
                                     BoxHeader parent,
                                     IsoHandlerBox handler,
                                     int index)
        {
            // The first few children of an "stsd" are sample
            // entries.
            if (parent.BoxType == BoxType.Stsd &&
                parent.Box is IsoSampleDescriptionBox &&
                index < (parent.Box as IsoSampleDescriptionBox).EntryCount)
            {
                if (handler != null &&
                    handler.HandlerType == BoxType.Soun)
                {
                    return(new IsoAudioSampleEntry(header,
                                                   file, handler));
                }
                else if (handler != null && handler.HandlerType == BoxType.Vide)
                {
                    return(new IsoVisualSampleEntry(header,
                                                    file, handler));
                }
                else if (handler != null && handler.HandlerType == BoxType.Alis)
                {
                    return(new IsoAudioSampleEntry(header,
                                                   file, handler));
                }
                else
                {
                    return(new IsoSampleEntry(header,
                                              file, handler));
                }
            }

            // Standard items...
            ByteVector type = header.BoxType;

            if (type == BoxType.Mvhd)
            {
                return(new IsoMovieHeaderBox(header, file,
                                             handler));
            }
            else if (type == BoxType.Stbl)
            {
                return(new IsoSampleTableBox(header, file,
                                             handler));
            }
            else if (type == BoxType.Stsd)
            {
                return(new IsoSampleDescriptionBox(header,
                                                   file, handler));
            }
            else if (type == BoxType.Stco)
            {
                return(new IsoChunkOffsetBox(header, file,
                                             handler));
            }
            else if (type == BoxType.Co64)
            {
                return(new IsoChunkLargeOffsetBox(header, file,
                                                  handler));
            }
            else if (type == BoxType.Hdlr)
            {
                return(new IsoHandlerBox(header, file,
                                         handler));
            }
            else if (type == BoxType.Udta)
            {
                return(new IsoUserDataBox(header, file,
                                          handler));
            }
            else if (type == BoxType.Meta)
            {
                return(new IsoMetaBox(header, file, handler));
            }
            else if (type == BoxType.Ilst)
            {
                return(new AppleItemListBox(header, file,
                                            handler));
            }
            else if (type == BoxType.Data)
            {
                return(new AppleDataBox(header, file, handler));
            }
            else if (type == BoxType.Esds)
            {
                return(new AppleElementaryStreamDescriptor(
                           header, file, handler));
            }
            else if (type == BoxType.Free || type == BoxType.Skip)
            {
                return(new IsoFreeSpaceBox(header, file,
                                           handler));
            }
            else if (type == BoxType.Mean || type == BoxType.Name)
            {
                return(new AppleAdditionalInfoBox(header, file,
                                                  handler));
            }

            // If we still don't have a tag, and we're inside an
            // ItemListBox, load the box as an AnnotationBox
            // (Apple tag item).
            if (parent.BoxType == BoxType.Ilst)
            {
                return(new AppleAnnotationBox(header, file,
                                              handler));
            }

            // Nothing good. Go generic.
            return(new UnknownBox(header, file, handler));
        }
Exemplo n.º 28
0
        /// <summary>
        ///    Constructs and initializes a new instance of <see
        ///    cref="IsoMovieHeaderBox" /> with a provided header and
        ///    handler by reading the contents from a specified file.
        /// </summary>
        /// <param name="header">
        ///    A <see cref="BoxHeader" /> object containing the header
        ///    to use for the new instance.
        /// </param>
        /// <param name="file">
        ///    A <see cref="TagLibSharp.File" /> object to read the contents
        ///    of the box from.
        /// </param>
        /// <param name="handler">
        ///    A <see cref="IsoHandlerBox" /> object containing the
        ///    handler that applies to the new instance.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///    <paramref name="file" /> is <see langword="null" />.
        /// </exception>
        public IsoMovieHeaderBox(BoxHeader header, TagLibSharp.File file,
                                 IsoHandlerBox handler)
            : base(header, file, handler)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }

            int        bytes_remaining = DataSize;
            ByteVector data;

            if (Version == 1)
            {
                // Read version one (large integers).
                data = file.ReadBlock(Math.Min(28,
                                               bytes_remaining));
                if (data.Count >= 8)
                {
                    creation_time = data.Mid(0,
                                             8).ToULong();
                }
                if (data.Count >= 16)
                {
                    modification_time = data.Mid(8,
                                                 8).ToULong();
                }
                if (data.Count >= 20)
                {
                    timescale = data.Mid(16, 4).ToUInt();
                }
                if (data.Count >= 28)
                {
                    duration = data.Mid(20, 8).ToULong();
                }
                bytes_remaining -= 28;
            }
            else
            {
                // Read version zero (normal integers).
                data = file.ReadBlock(Math.Min(16,
                                               bytes_remaining));
                if (data.Count >= 4)
                {
                    creation_time = data.Mid(0,
                                             4).ToUInt();
                }
                if (data.Count >= 8)
                {
                    modification_time = data.Mid(4,
                                                 4).ToUInt();
                }
                if (data.Count >= 12)
                {
                    timescale = data.Mid(8, 4).ToUInt();
                }
                if (data.Count >= 16)
                {
                    duration = data.Mid(12, 4).ToUInt();
                }
                bytes_remaining -= 16;
            }

            data = file.ReadBlock(Math.Min(6, bytes_remaining));
            if (data.Count >= 4)
            {
                rate = data.Mid(0, 4).ToUInt();
            }
            if (data.Count >= 6)
            {
                volume = data.Mid(4, 2).ToUShort();
            }
            file.Seek(file.Tell + 70);
            bytes_remaining -= 76;

            data = file.ReadBlock(Math.Min(4,
                                           bytes_remaining));

            if (data.Count >= 4)
            {
                next_track_id = data.Mid(0, 4).ToUInt();
            }
        }
Exemplo n.º 29
0
 /// <summary>
 ///    Creates a box by reading it from a file given its header
 ///    and handler.
 /// </summary>
 /// <param name="file">
 ///    A <see cref="TagLibSharp.File" /> object containing the file
 ///    to read from.
 /// </param>
 /// <param name="header">
 ///    A <see cref="BoxHeader" /> object containing the header
 ///    of the box to create.
 /// </param>
 /// <param name="handler">
 ///    A <see cref="IsoHandlerBox" /> object containing the
 ///    handler that applies to the new box.
 /// </param>
 /// <returns>
 ///    A newly created <see cref="Box" /> object.
 /// </returns>
 public static Box CreateBox(TagLibSharp.File file, BoxHeader header,
                             IsoHandlerBox handler)
 {
     return(CreateBox(file, header, BoxHeader.Empty,
                      handler, -1));
 }
Exemplo n.º 30
0
 /// <summary>
 ///    Creates a box by reading it from a file given its
 ///    position in the file.
 /// </summary>
 /// <param name="file">
 ///    A <see cref="TagLibSharp.File" /> object containing the file
 ///    to read from.
 /// </param>
 /// <param name="position">
 ///    A <see cref="long" /> value specifying at what seek
 ///    position in <paramref name="file" /> to start reading.
 /// </param>
 /// <returns>
 ///    A newly created <see cref="Box" /> object.
 /// </returns>
 public static Box CreateBox(TagLibSharp.File file, long position)
 {
     return(CreateBox(file, position, null));
 }