private IDataPacket CreateH264StartCodePrefixDataPacket(IProject project) { string defraserDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); IInputFile inputFile = _createInputFile(project, Path.Combine(defraserDirectory, "StartCodePrefix.h264")); return(inputFile.CreateDataPacket()); }
/// <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)); }
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)); }
public void Scan(IInputFile inputFile, IProgressReporter progressReporter) { PreConditions.Argument("inputFile").Value(inputFile).IsNotNull(); PreConditions.Argument("progressReporter").Value(progressReporter).IsNotNull(); if (inputFile.Length == 0L) { return; } _inputFile = inputFile; using (IDataReader dataReader = _dataReaderPool.CreateDataReader(inputFile.CreateDataPacket())) { Scan(dataReader, progressReporter); } }
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; }
public void Carve(string path, long position, long length, StringList codecDetectors, StringList containerDetectors, IDataBlockCallback callback, IBaseProgressListener baseProgressListener) { IProject project = CreateProject("C:/nonExistingFolder"); IInputFile inputFile = CreateInputFile(project, path); IFileScanner fileScanner = CreateFileScanner(); IDetectorFactory detectorFactory = CreateDetectorFactory(); CancelableProgressAdapter progressReporter = new CancelableProgressAdapter(baseProgressListener); fileScanner.CodecDetectors = detectorFactory.CodecDetectors.Where(detector => codecDetectors.Contains(detector.Name)); fileScanner.ContainerDetectors = detectorFactory.ContainerDetectors.Where(detector => containerDetectors.Contains(detector.Name)); fileScanner.DataBlockDetected += (o, e) => { callback.DataBlockDetectedWithCodecs(e.DataBlock.StartOffset, e.DataBlock.EndOffset, GetCodecStreamsAndKeyFrames(e.DataBlock)); }; try { StartPolling(progressReporter); (fileScanner as FileScanner).Scan(inputFile, CreateDataReaderPool().CreateDataReader(inputFile.CreateDataPacket().GetSubPacket(position, length)), progressReporter); } finally { _polling = false; } }
public void Carve(string path, long position, long length, IDataBlockCallback callback) { IProject project = CreateProject("C:/folderDieNietBestaat"); IInputFile inputFile = CreateInputFile(project, path); IFileScanner fileScanner = CreateFileScanner(); IDetectorFactory detectorFactory = CreateDetectorFactory(); fileScanner.CodecDetectors = detectorFactory.CodecDetectors; fileScanner.ContainerDetectors = detectorFactory.ContainerDetectors; fileScanner.DataBlockDetected += (o, e) => { callback.DataBlockDetectedWithCodecs(e.DataBlock.StartOffset, e.DataBlock.EndOffset, GetCodecStreamsAndKeyFrames(e.DataBlock)); }; (fileScanner as FileScanner).Scan(inputFile, CreateDataReaderPool().CreateDataReader(inputFile.CreateDataPacket().GetSubPacket(position, length)), new NullProgressReporter()); }
/// <summary> /// Creates a new file scanner for scanning (multiple) files. /// </summary> /// <param name="containerDataScanner">The <see cref="IDataScanner"/> for container formats</param> /// <param name="codecDataScanner">The <see cref="IDataScanner"/> for codec formats</param> /// <param name="dataReaderPool">The shared pool of file data readers</param> /// <param name="createDataBlockBuilder">The factory method for creating data blocks</param> /// <param name="createSubProgressReporter">The factory method for creating a sub progress reporter</param> /// data scanner fors canning codec streams (of a detected data block)</param> /// <exception cref="ArgumentNullException">If any argument is <c>null</c></exception> public FileScanner(IDataScanner containerDataScanner, IDataScanner codecDataScanner, IDataScanner codecStreamDataScanner, IDataReaderPool dataReaderPool, Creator <IDataBlockBuilder> createDataBlockBuilder, Creator <IProgressReporter, IProgressReporter, long, long, long> createSubProgressReporter) { PreConditions.Argument("containerDataScanner").Value(containerDataScanner).IsNotNull(); PreConditions.Argument("codecDataScanner").Value(codecDataScanner).IsNotNull(); PreConditions.Argument("codecStreamDataScanner").Value(codecStreamDataScanner).IsNotNull(); PreConditions.Argument("dataReaderPool").Value(dataReaderPool).IsNotNull(); PreConditions.Argument("createDataBlockBuilder").Value(createDataBlockBuilder).IsNotNull(); PreConditions.Argument("createSubProgressReporter").Value(createSubProgressReporter).IsNotNull(); _containerDataScanner = containerDataScanner; _codecDataScanner = codecDataScanner; _codecStreamDataScanner = codecStreamDataScanner; _dataReaderPool = dataReaderPool; _createDataBlockBuilder = createDataBlockBuilder; _createSubProgressReporter = createSubProgressReporter; _codecDataScanner.DataBlockDetected += (sender, e) => FixAndReportDataBlock(e.DataBlock); _containerDataScanner.DataBlockDetected += (sender, e) => ScanCodecStreams(e, e.DataBlock); _containerDataScanner.UnknownDataDetected += (sender, e) => ScanForCodecFormats(_inputFile.CreateDataPacket().GetSubPacket(e.Offset, e.Length)); // The default is that container blocks are allowed to overlap. See also issue DEFR-867. AllowOverlap = true; }