Пример #1
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="TagLib.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, TagLib.File file,
                          IsoHandlerBox handler)
            : base(header, handler)
        {
            if (file == null)
            {
                throw new ArgumentNullException(nameof(file));
            }

            data = LoadData(file);
        }
Пример #2
0
        /// <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="TagLib.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, TagLib.File file,
                                IsoHandlerBox handler)
            : base(header, handler)
        {
            if (file == null)
            {
                throw new ArgumentNullException(nameof(file));
            }

            children = LoadChildren(file);
        }
Пример #3
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="TagLib.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, TagLib.File file,
                              IsoHandlerBox handler)
            : base(header, handler)
        {
            if (file == null)
            {
                throw new ArgumentNullException(nameof(file));
            }

            file.Seek(base.DataPosition + 6);
            DataReferenceIndex = file.ReadBlock(2)
                                 .ToUShort();
        }
Пример #4
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="TagLib.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,
                                       TagLib.File file,
                                       IsoHandlerBox handler)
            : base(header, file, handler)
        {
            if (file == null)
            {
                throw new ArgumentNullException(nameof(file));
            }

            EntryCount = file.ReadBlock(4)
                         .ToUInt();

            children = LoadChildren(file);
        }
Пример #5
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="TagLib.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, TagLib.File file,
                          IsoHandlerBox handler)
            : base(header, handler)
        {
            if (file == null)
            {
                throw new ArgumentNullException(nameof(file));
            }

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

            version = header_data[0];
            Flags   = header_data.Mid(1, 3)
                      .ToUInt();
        }
Пример #6
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="TagLib.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, TagLib.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);
             */
        }
Пример #7
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="TagLib.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, TagLib.File file,
                                 IsoHandlerBox handler)
            : base(header, file, handler)
        {
            var box_data = file.ReadBlock(DataSize);

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

            for (var i = 0; i < Offsets.Length; i++)
            {
                Offsets[i] = box_data.Mid(4 + i * 4,
                                          4)
                             .ToUInt();
            }
        }
Пример #8
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="TagLib.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, TagLib.File file,
                                   IsoHandlerBox handler)
            : base(header, file, handler)
        {
            if (file == null)
            {
                throw new ArgumentNullException(nameof(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);
        }
Пример #9
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="TagLib.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, TagLib.File file,
                             IsoHandlerBox handler)
            : base(header, file, handler)
        {
            if (file == null)
            {
                throw new ArgumentNullException(nameof(file));
            }

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

            HandlerType = box_data.Mid(0, 4);

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

            if (end < 16)
            {
                end = box_data.Count;
            }

            Name = end > 16 ? box_data.ToString(StringType.UTF8, 16, end - 16) : string.Empty;
        }
Пример #10
0
 /// <summary>
 ///     Constructs and initializes a new instance of
 ///     <see
 ///         cref="AppleDataBox" />
 ///     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="TagLib.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 AppleDataBox(BoxHeader header, TagLib.File file,
                     IsoHandlerBox handler)
     : base(header, file, handler)
 {
     Data = LoadData(file);
 }
Пример #11
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="TagLib.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, TagLib.File file,
                                 IsoHandlerBox handler)
            : base(header, file, handler)
        {
            if (file == null)
            {
                throw new ArgumentNullException(nameof(file));
            }

            var        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)
            {
                NextTrackId = data.Mid(0, 4)
                              .ToUInt();
            }
        }
Пример #12
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="TagLib.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, TagLib.File file, IsoHandlerBox handler) : base(header, handler)
 {
     // We do not care what is in this custom data section
     // see: https://developer.apple.com/library/mac/#documentation/QuickTime/QTFF/QTFFChap2/qtff2.html
     Data = LoadData(file);
 }
Пример #13
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="TagLib.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, TagLib.File file,
                   IsoHandlerBox handler)
     : base(header, file, handler)
 {
     children = LoadChildren(file);
 }
Пример #14
0
        /// <summary>
        ///     Constructs and initializes a new instance of
        ///     <see
        ///         cref="AppleElementaryStreamDescriptor" />
        ///     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="TagLib.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>
        /// <exception cref="CorruptFileException">
        ///     Valid data could not be read.
        /// </exception>
        public AppleElementaryStreamDescriptor(BoxHeader header,
                                               TagLib.File file,
                                               IsoHandlerBox handler)
            : base(header, file, handler)
        {
            var offset   = 0;
            var box_data = file.ReadBlock(DataSize);

            DecoderConfig = new ByteVector();

            // Elementary Stream Descriptor Tag
            if (box_data[offset++] == 3)
            {
                // We have a descriptor tag. Check that it's at
                // least 20 long.
                if (ReadLength(box_data, ref offset) < 20)
                {
                    throw new CorruptFileException(
                              "Insufficient data present.");
                }

                StreamId = box_data.Mid(offset, 2)
                           .ToUShort();

                offset        += 2;
                StreamPriority = box_data[offset++];
            }
            else
            {
                // The tag wasn't found, so the next two byte
                // are the ID, and after that, business as
                // usual.
                StreamId = box_data.Mid(offset, 2)
                           .ToUShort();

                offset += 2;
            }

            // Verify that the next data is the Decoder
            // Configuration Descriptor Tag and escape if it won't
            // work out.
            if (box_data[offset++] != 4)
            {
                throw new CorruptFileException(
                          "Could not identify decoder configuration descriptor.");
            }

            // Check that it's at least 15 long.
            if (ReadLength(box_data, ref offset) < 15)
            {
                throw new CorruptFileException(
                          "Could not read data. Too small.");
            }

            // Read a lot of good info.
            ObjectTypeId = box_data[offset++];
            StreamType   = box_data[offset++];
            BufferSizeDB = box_data.Mid(offset, 3)
                           .ToUInt();

            offset     += 3;
            max_bitrate = box_data.Mid(offset, 4)
                          .ToUInt();

            offset         += 4;
            average_bitrate = box_data.Mid(offset, 4)
                              .ToUInt();

            offset += 4;

            // Verify that the next data is the Decoder Specific
            // Descriptor Tag and escape if it won't work out.
            if (box_data[offset++] != 5)
            {
                throw new CorruptFileException(
                          "Could not identify decoder specific descriptor.");
            }

            // The rest of the info is decoder specific.
            var length = ReadLength(box_data, ref offset);

            DecoderConfig = box_data.Mid(offset, (int)length);
        }