Пример #1
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="TagLib.File" />
        ///     .
        /// </summary>
        /// <param name="file">
        ///     A <see cref="TagLib.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(TagLib.File file, long position,
                             int length)
        {
            if (file == null)
            {
                throw new ArgumentNullException(nameof(file));
            }

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

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

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

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

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

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

            Header = new AviHeader(header_data, 0);

            foreach (var list_data in list["LIST"])
            {
                if (list_data.StartsWith("strl"))
                {
                    codecs.Add(AviStream
                               .ParseStreamList(list_data)
                               .Codec);
                }
            }
        }
Пример #2
0
        /// <summary>
        ///     Parses a raw AVI stream list and returns the stream
        ///     information.
        /// </summary>
        /// <param name="data">
        ///     A <see cref="ByteVector" /> object containing raw stream
        ///     list.
        /// </param>
        /// <returns>
        ///     A <see cref="AviStream" /> object containing stream
        ///     information.
        /// </returns>
        public static AviStream ParseStreamList(ByteVector data)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            if (!data.StartsWith("strl"))
            {
                return(null);
            }

            AviStream stream = null;
            var       pos    = 4;

            while (pos + 8 < data.Count)
            {
                var id           = data.Mid(pos, 4);
                var block_length = (int)data.Mid(pos + 4, 4)
                                   .ToUInt(false);

                if (id == "strh" && stream == null)
                {
                    var stream_header =
                        new AviStreamHeader(data, pos + 8);

                    if (stream_header.Type == "vids")
                    {
                        stream = new AviVideoStream(
                            stream_header);
                    }
                    else if (stream_header.Type == "auds")
                    {
                        stream = new AviAudioStream(
                            stream_header);
                    }
                }
                else if (stream != null)
                {
                    stream.ParseItem(id, data, pos + 8, block_length);
                }

                pos += block_length + 8;
            }

            return(stream);
        }