/// <summary>
        /// This method looks for the beginning of an MPEG-4 header and if one is found it will parse it
        /// by calling Parser.Parse().
        /// </summary>
        override public IDataBlock DetectData(IDataReader dataReader, IDataBlockBuilder dataBlockBuilder, IScanContext context)
        {
            if (ReferenceHeaders != null)
            {
                var referenceHeaders = new Dictionary <IDataPacket, VideoObjectLayer>();
                foreach (IReferenceHeader header in ReferenceHeaders)
                {
                    IInputFile headerFile = context.CreateReferenceHeaderFile(header);
                    using (var parser = new Mpeg4Parser(new BitStreamDataReader(headerFile.CreateDataReader())))
                    {
                        Mpeg4Header root;
                        while (parser.ParseRoot(root = new Mpeg4Header(context.Detectors), parser.Length))
                        {
                            VideoObjectLayer vol = root.FindChild(Mpeg4HeaderName.VideoObjectLayer, true) as VideoObjectLayer;
                            if (vol != null)
                            {
                                referenceHeaders[headerFile.CreateDataPacket()] = vol;
                            }
                        }
                    }
                }

                context.ReferenceHeader = referenceHeaders;
            }

            return(Carve(dataReader, dataBlockBuilder, context));
        }
Beispiel #2
0
        public IDataBlock DetectData(IDataReader dataReader, IDataBlockBuilder dataBlockBuilder, IScanContext context)
        {
            bool isFragmented = context.IsFragmented;

            if (ReferenceHeaders != null)
            {
                var referenceHeaders = new Dictionary <IDataPacket, ISequenceState>();
                foreach (IReferenceHeader header in ReferenceHeaders)
                {
                    IInputFile headerFile = context.CreateReferenceHeaderFile(header);
                    using (var reader = headerFile.CreateDataReader())
                    {
                        var headerDataBlock = _carver.Carve(new BitStreamDataReader(reader), dataBlockBuilder, context);
                        if (headerDataBlock != null)
                        {
                            referenceHeaders[headerFile.CreateDataPacket()] = context.ReferenceHeader as ISequenceState;
                        }
                    }
                }

                context.ReferenceHeader = referenceHeaders;
            }

            // Restore scan context
            context.Results      = null;
            context.IsFragmented = isFragmented;
            // context.ReferenceHeader

            return(_carver.Carve(new BitStreamDataReader(dataReader), dataBlockBuilder, context));
        }
Beispiel #3
0
        public int ReadInputFile(IInputFile inputFile, long position, byte[] array, int arrayOffset, int count)
        {
            PreConditions.Argument("inputFile").Value(inputFile).IsNotNull();

            IDataReader dataReader;

            if (!_dataReaders.TryGetValue(inputFile, out dataReader))
            {
                dataReader = inputFile.CreateDataReader();
                _dataReaders.Add(inputFile, dataReader);
            }

            dataReader.Position = position;
            return(dataReader.Read(array, arrayOffset, count));
        }
Beispiel #4
0
        private void BuildReferenceHeaders(IScanContext context, IDataBlockBuilder dataBlockBuilder)
        {
            var referenceHeaders = new Dictionary <IDataPacket, IPictureState>();

            foreach (IReferenceHeader header in ReferenceHeaders)
            {
                IInputFile headerFile = context.CreateReferenceHeaderFile(header);
                using (var reader = headerFile.CreateDataReader())
                {
                    var headerDataBlock = _carver.Carve(new BitStreamDataReader(reader), dataBlockBuilder, context);
                    if (headerDataBlock != null)
                    {
                        referenceHeaders[headerFile.CreateDataPacket()] = context.ReferenceHeader as IPictureState;
                    }
                }
            }

            // Set reference header and reset other state
            context.ReferenceHeader = referenceHeaders;
            context.Results         = null;
            context.IsFragmented    = false;
        }
Beispiel #5
0
        public IReferenceHeader AddHeader(ICodecDetector detector, string filename)
        {
            IInputFile inputFile = _createInputFile(new Project(_createInputFile, "dummy.xml"), filename);

            using (var dataReader = inputFile.CreateDataReader())
            {
                var         codecParametersBuilder = new CodecParametersBuilder();
                IDataPacket headerData             = detector.FindReferenceHeader(dataReader, codecParametersBuilder);
                if (headerData == null)
                {
                    return(null);                    // No header detected
                }

                byte[] b      = ReadDataPacketToByteArray(headerData, dataReader);
                var    header = new ReferenceHeader(b, codecParametersBuilder.Build());
                // Use the filename as 'Setting' and leave 'Brand' and 'Model' as undefined.
                header.Setting = Path.GetFileNameWithoutExtension(filename);

                _referenceHeaders.Add(header);
                return(header);
            }
        }
 public void CreateDataReader()
 {
     Assert.AreSame(_dataReader, _inputFile.CreateDataReader());
 }