Esempio n. 1
0
        public override bool Parse(QtParser parser)
        {
            uint maxUnparsedBytes = (uint)QtDetector.Configurable[QtDetector.ConfigurationKey.FileTypeMaxUnparsedBytes];

            if (!base.Parse(parser) || parser.BytesRemaining > maxUnparsedBytes)
            {
                return(false);
            }

            Brand majorBrand = (Brand)parser.GetFourCC(Attribute.MajorBrand);

            parser.GetUInt(Attribute.MinorVersion, "{0:X8}");

            // Gets the list of compatible brands
            StringBuilder sb = new StringBuilder();
            List <Brand>  compatibleBrands = new List <Brand>();

            // Remaining data of the atom are the compatible brands
            while (parser.BytesRemaining >= 4)
            {
                uint compatibleBrand = parser.GetUInt();

                if (compatibleBrand != 0)
                {
                    if (sb.Length > 0)
                    {
                        sb.Append(", ");
                    }

                    // Add 4CC
                    sb.Append(compatibleBrand.ToString4CC());
                    compatibleBrands.Add((Brand)compatibleBrand);
                }
            }

            // Create attribute with comma separated list of compatible brands
            parser.AddAttribute(new FormattedAttribute <Attribute, string>(Attribute.CompatibleBrands, sb.ToString()));

            _dataFormat = GetDataFormat((Brand)majorBrand);
            if (DataFormat == CodecID.Unknown)
            {
                // Scan compatible brands for known brand
                foreach (Brand brand in compatibleBrands)
                {
                    _dataFormat = GetDataFormat(brand);

                    if (DataFormat != CodecID.Unknown)
                    {
                        break;
                    }
                }
            }

            // Unsupported formats, such as JPEG-2000, should be ignored
            parser.CheckAttribute(Attribute.MajorBrand, DataFormat != CodecID.Unknown);

            // We expect the major brand in the list of compatible brands
            parser.CheckAttribute(Attribute.CompatibleBrands, compatibleBrands.Contains(majorBrand), false);
            return(this.Valid);
        }
        public override bool Parse(QtParser parser)
        {
            if (!base.Parse(parser))
            {
                return(false);
            }

            parser.GetUShort(Attribute.SubSequenceIdentifer);
            parser.GetByte(Attribute.LayerNumber);
            byte flags        = parser.GetByte();
            bool durationFlag = (flags & 0x80) == 0x80;
            bool avgRateFlag  = (flags & 0x40) == 0x40;
            byte reserved     = (byte)(flags & 0x3F);

            parser.AddAttribute(new FormattedAttribute <Attribute, bool>(Attribute.DurationFlag, durationFlag));
            parser.AddAttribute(new FormattedAttribute <Attribute, bool>(Attribute.AvgRateFlag, avgRateFlag));
            parser.AddAttribute(new FormattedAttribute <Attribute, byte>(Attribute.Reserved, reserved));
            parser.CheckAttribute(Attribute.Reserved, reserved == 0, false);

            if (durationFlag)
            {
                parser.GetUInt(Attribute.Duration);
            }

            if (avgRateFlag)
            {
                parser.GetByte(Attribute.AccurateStatisticsFlag);
                parser.GetUShort(Attribute.AvgBitRate);
                parser.GetUShort(Attribute.AvgFrameRate);
            }

            parser.GetTable(Attribute.DependencyInfo, Attribute.NumReferences, NumberOfEntriesType.Byte, 32, () => new DependencyInfo(), parser.BytesRemaining);

            return(Valid);
        }
Esempio n. 3
0
            public override bool Parse(QtParser parser)
            {
                Matrix.Parse(parser);

                TypedValue = string.Format("({0}; {1}; {2}; {3}; {4}; {5}; {6}; {7}; {8})", Matrix.A, Matrix.B, Matrix.U, Matrix.C, Matrix.D, Matrix.V, Matrix.X, Matrix.Y, Matrix.W);

                return(Valid);
            }
Esempio n. 4
0
            public override bool Parse(QtParser parser)
            {
                short red   = parser.GetShort(LAttribute.Red);
                short green = parser.GetShort(LAttribute.Green);
                short blue  = parser.GetShort(LAttribute.Blue);

                TypedValue = string.Format("({0}, {1}, {2})", red, green, blue);

                return(Valid);
            }
        public override bool Parse(QtParser parser)
        {
            if (!base.Parse(parser))
            {
                return(false);
            }

            parser.GetTable(Attribute.FeatureEntities, Attribute.NumberOfFeatureEntities, NumberOfEntriesType.UInt, 16, () => new FeatureEntity(), parser.BytesRemaining);

            return(Valid);
        }
        public override bool Parse(QtParser parser)
        {
            if (!base.Parse(parser))
            {
                return(false);
            }

            parser.GetTable(Attribute.TimeToSampleTable, Attribute.NumberOfEntries, NumberOfEntriesType.UInt, 8, () => new TimeToSampleTableEntry(), parser.BytesRemaining);

            return(Valid);
        }
Esempio n. 7
0
        public override bool Parse(QtParser parser)
        {
            if (!base.Parse(parser))
            {
                return(false);
            }

            parser.CheckAttribute(Attribute.Size, Size == 8);

            return(this.Valid);
        }
        public override bool Parse(QtParser parser)
        {
            if (!base.Parse(parser))
            {
                return(false);
            }

            short rollDistance = parser.GetShort(Attribute.RollDistance);

            parser.CheckAttribute(Attribute.RollDistance, rollDistance != 0, false);

            return(Valid);
        }
        public override bool Parse(QtParser parser)
        {
            if (!base.Parse(parser))
            {
                return(false);
            }

            parser.GetInt(Attribute.Reserved);
            parser.GetShort(Attribute.Reserved);
            parser.GetShort(Attribute.DataReferenceIndex);

            return(this.Valid);
        }
Esempio n. 10
0
        public override bool Parse(QtParser parser)
        {
            if (!base.Parse(parser))
            {
                return(false);
            }

            parser.GetUInt(Attribute.GroupingType);

            parser.GetTable(Attribute.SampleToGroupTable, Attribute.EntryCount, NumberOfEntriesType.UInt, 8, () => new SampleToGroupEntry(), parser.BytesRemaining);

            return(Valid);
        }
Esempio n. 11
0
        public override bool Parse(QtParser parser)
        {
            if (!base.Parse(parser))
            {
                return(false);
            }

            parser.GetUInt(Attribute.Version, "{0:X8}");

            // TODO: the sequence of descriptors is taken (mostly) from ffmpeg
            // TODO: verify that this is the actual sequence seen in (all) 3GPP files
            BaseDescriptor descriptor = ReadDescriptor(parser);

            if (descriptor.Tag == DescriptorClassTag.ES_DescrTag)
            {
                parser.GetUShort();                             // ID
                parser.GetByte();                               // priority
            }
            else
            {
                parser.GetUShort();                             // ID
            }

            descriptor = ReadDescriptor(parser);
            if (descriptor.Tag == DescriptorClassTag.DecoderConfigDescrTag)
            {
                parser.GetByte(Attribute.ObjectTypeIndication);                         // 0x20 Visual ISO/IEC 14496-2
                parser.GetByte(Attribute.StreamType);
                parser.GetThreeBytes(Attribute.BufferSizeDB);                           // 3 bytes
                parser.GetUInt(Attribute.MaxBitrate);
                parser.GetUInt(Attribute.AvgBitrate);

                descriptor = ReadDescriptor(parser);
                if ((parser.Position + descriptor.Length) > parser.Length)
                {
                    return(false);
                }
                if (descriptor.Tag == DescriptorClassTag.DecSpecificInfoTag)
                {
                    // Extra data can be empty (0 bytes)
                    if (descriptor.Length > 0)
                    {
                        ExtraData = parser.GetDataPacket(parser.Position, descriptor.Length);
                    }

                    Attributes.Add(new FormattedAttribute <Attribute, long>(Attribute.DecSpecificInfoSize, descriptor.Length));
                }
                parser.Position += Math.Min(descriptor.Length, parser.Length - parser.Position);
            }
            return(this.Valid);
        }
        public override bool Parse(QtParser parser)
        {
            if (!base.Parse(parser))
            {
                return(false);
            }

            parser.GetTable(Attribute.EditListTable, Attribute.NumberOfEntries, NumberOfEntriesType.UInt, 12, () => new EditListTableEntry(), parser.BytesRemaining);

            // TODO add check: The last edit in a track should never be an empty edit
            // Empty edits have the media time set to -1

            return(Valid);
        }
Esempio n. 13
0
        public override bool Parse(QtParser parser)
        {
            if (!base.Parse(parser))
            {
                return(false);
            }

            parser.GetUInt(Attribute.PreloadStartTime);
            parser.GetInt(Attribute.PreloadDuration);
            parser.GetFlags <Attribute, PreloadFlags>(Attribute.PreloadFlags, 4);
            parser.GetFlags <Attribute, DefaultHints>(Attribute.DefaultHints, 4);

            return(this.Valid);
        }
Esempio n. 14
0
        public override bool Parse(QtParser parser)
        {
            if (!base.Parse(parser))
            {
                return(false);
            }

            parser.GetByte(Attribute.LayerNumber);
            parser.GetByte(Attribute.AccurateStatisticsFlag);
            parser.GetUShort(Attribute.AvgBitRate);
            parser.GetUShort(Attribute.AvgFrameRate);

            return(Valid);
        }
Esempio n. 15
0
        public override bool Parse(QtParser parser)
        {
            if (!base.Parse(parser))
            {
                return(false);
            }

            const int EntrySize       = 4;
            uint      numberOfEntries = (uint)(parser.BytesRemaining / EntrySize);

            parser.AddAttribute(new FormattedAttribute <Attribute, uint>(Attribute.TableSize, numberOfEntries));

            parser.GetTable(Attribute.TrackIDTable, Attribute.TableSize, numberOfEntries, EntrySize, () => new TrackID(), parser.BytesRemaining);

            return(Valid);
        }
Esempio n. 16
0
        /// <summary>
        /// Reads a MPEG-4 descriptor.
        /// </summary>
        /// <remarks>defined in ISO/IEC 14496-1 �2.2</remarks>
        private static BaseDescriptor ReadDescriptor(QtParser parser)
        {
            DescriptorClassTag tag = (DescriptorClassTag)parser.GetByte();

            // Expandable length [see ISO/IEC 14496-1 �3.3]
            int  count          = 4;
            uint nextByte       = parser.GetByte();
            uint sizeOfInstance = (nextByte & 0x7F);

            while ((nextByte & 0x80) != 0 && --count > 0)
            {
                nextByte       = parser.GetByte();
                sizeOfInstance = (sizeOfInstance << 7) | (nextByte & 0x7F);
            }
            return(new BaseDescriptor(tag, sizeOfInstance));
        }
Esempio n. 17
0
        public override bool Parse(QtParser parser)
        {
            if (!base.Parse(parser))
            {
                return(false);
            }

            ushort regionSize = parser.GetUShort(Attribute.RegionSize);

            parser.Parse(new RegionBounderyBox());
            parser.CheckAttribute(Attribute.RegionSize, regionSize == parser.BytesRemaining);
            if (Valid)
            {
                parser.GetHexDump(Attribute.ClippingRegionData, regionSize);
            }
            return(Valid);
        }
        public override bool Parse(QtParser parser)
        {
            uint flags = 0;

            for (int i = 0; i < _size; i++)
            {
                flags = (flags << 8) | parser.GetByte();
            }
            foreach (TFlag flag in Enum.GetValues(typeof(TFlag)))
            {
                parser.AddAttribute(new FormattedAttribute <TFlag, bool>(flag, IsFlagSet(flags, flag)));
            }

            this.TypedValue = flags;

            return(this.Valid);
        }
Esempio n. 19
0
        public override bool Parse(QtParser parser)
        {
            if (!base.Parse(parser))
            {
                return(false);
            }

            uint uncompressedSize = parser.GetUInt(Attribute.UncompressedSize);

            // TODO: finish decompression method and parse the decompressed movie atom
            //byte[] compressedData = new byte[parser.BytesRemaining];
            //parser.DataReader.Read(compressedData, 0, compressedData.Length);

            //DecompressZlib(compressedData, uncompressedSize);

            return(this.Valid);
        }
Esempio n. 20
0
        public override bool Parse(QtParser parser)
        {
            if (!base.Parse(parser))
            {
                return(false);
            }

            uint colorParameterType = parser.GetFourCC(Attribute.ColorParameterType);

            parser.CheckAttribute(Attribute.ColorParameterType, colorParameterType == "nclc".To4CC(), false);

            parser.GetUShort(Attribute.PrimariesIndex);
            parser.GetUShort(Attribute.TransferFunctionIndex);
            parser.GetUShort(Attribute.MatrixIndex);

            return(Valid);
        }
        public override bool Parse(QtParser parser)
        {
            if (!base.Parse(parser))
            {
                return(false);
            }

            // Reserved (6x byte)
            for (int i = 0; i < 6; i++)
            {
                parser.GetByte();
            }
            parser.GetUShort(Attribute.ReferenceIndex);
            parser.GetUShort(Attribute.PreDefined1);
            parser.GetUShort(Attribute.Reserved1);

            return(Valid);
        }
Esempio n. 22
0
        public override bool Parse(QtParser parser)
        {
            if (!base.Parse(parser))
            {
                return(false);
            }

            if (parser.BytesRemaining > 255)
            {
                Valid = false;
                string value = string.Format("{0} descriptor bytes found", parser.BytesRemaining);
                parser.AddAttribute(new FormattedAttribute <Attribute, string>(Attribute.Descriptor, value));
                parser.GetDataPacket(parser.Position, (long)parser.BytesRemaining);
                parser.Position += (long)parser.BytesRemaining;
            }

            return(Valid);
        }
        public override bool Parse(QtParser parser)
        {
            if (!base.Parse(parser))
            {
                return(false);
            }

            switch (_atomType)
            {
            case AtomType.ChunkOffset32Bit:
                parser.GetTable(Attribute.ChunkOffsetTable, Attribute.NumberOfEntries, NumberOfEntriesType.UInt, 4, () => new ChunkOffsetTableAttribute(AtomType.ChunkOffset32Bit), parser.BytesRemaining);
                break;

            case AtomType.ChunkOffset64Bit:
                parser.GetTable(Attribute.ChunkOffsetTable, Attribute.NumberOfEntries, NumberOfEntriesType.UInt, 8, () => new ChunkOffsetTableAttribute(AtomType.ChunkOffset64Bit), parser.BytesRemaining);
                break;
            }
            return(Valid);
        }
Esempio n. 24
0
        // See QuickTime File Format Specification, 2010-08-03, pg.1
        private static void ParseTcmiAtom(QtParser parser, uint size)
        {
            long tcmiPosition = (parser.Position - 4);

            parser.AddAttribute(new FormattedAttribute <QtAtom.Attribute, uint>(QtAtom.Attribute.Size, size));
            uint type = parser.GetFourCC(QtAtom.Attribute.Type);

            parser.CheckAttribute(QtAtom.Attribute.Type, type == Tcmi, false);
            parser.GetByte(QtAtom.Attribute.Version);
            parser.GetThreeBytes(QtAtom.Attribute.Flags);
            parser.GetUShort(Attribute.TextFont);
            parser.GetUShort(Attribute.TextFace);
            parser.GetUShort(Attribute.TextSize);
            parser.GetUShort(Attribute.TcmiReserved);
            parser.Parse(new Color(Attribute.TextColor));
            parser.Parse(new Color(Attribute.BackgroundColor));
            parser.GetPascalString(Attribute.FontName, 0);
            parser.CheckAttribute(QtAtom.Attribute.Size, size == (parser.Position - tcmiPosition), false);
        }
Esempio n. 25
0
        public override bool Parse(QtParser parser)
        {
            if (!base.Parse(parser))
            {
                return(false);
            }

            // TODO implement
            //for (i=0; i < sample_count; i++){
            //    unsigned int(16) dependency_count;
            //    for (k=0; k < dependency_count; k++)
            //    {
            //        signed int(16) relative_sample_number;
            //    }
            //}
            parser.Position += (long)parser.BytesRemaining;

            return(Valid);
        }
        public override bool Parse(QtParser parser)
        {
            if (!base.Parse(parser))
            {
                return(false);
            }

            uint sampleSize = parser.GetUInt(Attribute.SampleSize);

            if (sampleSize == 0)                // If the sample size is 0 than only read the number of samples in the track
            {
                parser.GetTable(Attribute.SampleSizeTable, Attribute.NumberOfEntries, NumberOfEntriesType.UInt, 4, () => new SampleSizeTableAttribute(), parser.BytesRemaining);
            }
            else
            {
                parser.GetUInt(Attribute.SampleCount);                  // Read the number on samples in the track
            }

            return(Valid);
        }
Esempio n. 27
0
        // for (i=0; i< numOfSequenceParameterSets; i++) {
        //   unsigned int(16) sequenceParameterSetLength ;
        //   bit(8*sequenceParameterSetLength) sequenceParameterSetNALUnit;
        // }
        //
        // for (i=0; i< numOfPictureParameterSets; i++) {
        //   unsigned int(16) pictureParameterSetLength;
        //   bit(8*pictureParameterSetLength) pictureParameterSetNALUnit;
        // }
        private static IDataPacket CreateNalUnit(QtParser parser, byte setCount, Attribute attribute)
        {
            long beginOffset    = parser.Position;
            int  totalSetLength = 0;

            for (int i = 0; i < setCount; i++)
            {
                ushort setLength = parser.GetUShort();
                parser.Position += setLength;
                totalSetLength  += setLength + sizeof(ushort);
            }
            if (totalSetLength > 0)
            {
                parser.Position = beginOffset;
                parser.GetHexDump <Attribute>(attribute, totalSetLength);

                return(parser.GetDataPacket(beginOffset, totalSetLength));
            }
            return(null);
        }
Esempio n. 28
0
        public override bool Parse(QtParser parser)
        {
            if (!base.Parse(parser))
            {
                return(false);
            }

            int colorTableSeed = parser.GetInt(Attribute.ColorTableSeed);

            parser.CheckAttribute(Attribute.ColorTableSeed, colorTableSeed == 0);
            ushort colorTableFlags = parser.GetUShort(Attribute.ColorTableFlags);

            parser.CheckAttribute(Attribute.ColorTableFlags, colorTableFlags == 0x8000);

            uint colorTableSize = parser.GetUShort(Attribute.ColorTableSize);

            colorTableSize++;                   // The color table size is zero-relative; 0 means there is one color in the array
            parser.GetTable(Attribute.ColorArray, Attribute.ColorTableSize, colorTableSize, 8, () => new Color(), parser.BytesRemaining);

            return(Valid);
        }
Esempio n. 29
0
        public override bool Parse(QtParser parser)
        {
            if (!base.Parse(parser))
            {
                return(false);
            }

            if (!CheckComponentSubType(ComponentSubType.tmcd))
            {
                Valid = false;
                return(Valid);
            }

            uint reserved = parser.GetUInt();

            if (reserved == 0)
            {
                parser.AddAttribute(new FormattedAttribute <QtSampleDescriptionAtom.Attribute, int>(QtSampleDescriptionAtom.Attribute.Reserved, (int)reserved));
                parser.GetShort(QtSampleDescriptionAtom.Attribute.Reserved);
                parser.GetShort(QtSampleDescriptionAtom.Attribute.DataReferenceIndex);
                reserved = parser.GetUInt(Attribute.Reserved1);
                parser.CheckAttribute(Attribute.Reserved1, reserved == 0, true);
                parser.Parse(new Flags());
                parser.GetInt(Attribute.TimeScale);
                parser.GetInt(Attribute.FrameDuration);
                parser.GetByte(Attribute.NumberOfFrames);
                reserved = parser.GetThreeBytes(Attribute.Reserved2);
                parser.CheckAttribute(Attribute.Reserved2, reserved == 0, false);

                if (parser.BytesRemaining > 0)
                {
                    parser.GetHexDump(QtAtom.Attribute.AdditionalData, (int)parser.BytesRemaining);
                }
            }
            else
            {
                ParseTcmiAtom(parser, reserved);
            }
            return(Valid);
        }
        public override bool Parse(QtParser parser)
        {
            if (!base.Parse(parser))
            {
                return(false);
            }

            parser.GetDateTime(Attribute.CreationTime, "{0:F}");
            parser.GetDateTime(Attribute.ModificationTime, "{0:F}");
            TrackID = parser.GetUInt(Attribute.TrackID);
            parser.GetUInt(Attribute.Reserved1);
            parser.GetUInt(Attribute.Duration);
            parser.GetULong(Attribute.Reserved2);
            parser.GetShort(Attribute.Layer);
            parser.GetShort(Attribute.AlternateGroup);
            parser.GetFixed8_8(Attribute.Volume);
            parser.GetUShort(Attribute.Reserved3);
            parser.GetMatrix(Attribute.MatrixStructure);
            parser.GetFixed16_16(Attribute.TrackWidth);
            parser.GetFixed16_16(Attribute.TrackHeight);

            return(this.Valid);
        }