public IDataPacket GetSubPacket(long offset, long length)
        {
            PreConditions.Argument("offset").Value(offset).InRange(0L, (Length - 1L));
            PreConditions.Argument("length").Value(length).InRange(1L, (Length - offset));

            if ((offset == 0) && (length == Length))
            {
                return(this);                   // Sub-packet is the entire packet
            }

            long firstLength = _firstDataPacket.Length;

            if (offset >= firstLength)
            {
                return(_secondDataPacket.GetSubPacket((offset - firstLength), length));
            }

            long relativeEndOffset = (offset + length);

            if (relativeEndOffset <= firstLength)
            {
                return(_firstDataPacket.GetSubPacket(offset, length));
            }

            IDataPacket firstSubPacket  = _firstDataPacket.GetSubPacket(offset, (firstLength - offset));
            IDataPacket secondSubPacket = _secondDataPacket.GetSubPacket(0, (relativeEndOffset - firstLength));

            return(firstSubPacket.Append(secondSubPacket));
        }
        public override IDataPacket GetVideoHeaders(IResultNode headerPacket)
        {
            IDataPacket data = null;

            IResultNode parentNode = headerPacket.Parent;

            if (parentNode is GroupOfVop)
            {
                parentNode = parentNode.Parent;
            }
            if (parentNode != null)
            {
                // Add parent parent node (required WHEN available)
                IResultNode parentParentNode = parentNode.Parent;
                if ((parentParentNode != null) && (parentParentNode.Length > 0))
                {
                    data = parentParentNode;
                }

                // Add parent node (required)
                if (parentNode.Length > 0)
                {
                    data = (data == null) ? parentNode : data.Append(parentNode);
                }
            }
            return(data);
        }
        public override void TestFixtureSetup()
        {
            base.TestFixtureSetup();

            File.Delete(DataFileNameCopy);

            // Make a copy
            FileInfo fileInfo = new FileInfo(DataFileName);

            fileInfo.CopyTo(DataFileNameCopy);

            // Create fragmented data packet and bytes
            _dataPacket     = TestFramework.CreateDataPacket(InputFile, 10, 113);                               // < 123
            _dataPacket     = _dataPacket.Append(TestFramework.CreateDataPacket(InputFile, 151, 89));           // < 240
            _dataPacket     = _dataPacket.Append(TestFramework.CreateDataPacket(InputFile, 255, 17));           // < 272
            _dataPacket     = _dataPacket.Append(TestFramework.CreateDataPacket(InputFile, 289, 1));            // < 290
            _dataPacket     = _dataPacket.Append(TestFramework.CreateDataPacket(InputFile, 393, 44));           // < 437
            _dataPacket     = _dataPacket.Append(TestFramework.CreateDataPacket(InputFile, 0, 5));              // < 5
            _dataPacket     = _dataPacket.Append(TestFramework.CreateDataPacket(InputFile, 511, 22));           // < 533
            _dataPacket     = _dataPacket.Append(TestFramework.CreateDataPacket(InputFile, 140, 40));           // overlap!
            _fragmentedData = new byte[113 + 89 + 17 + 1 + 44 + 5 + 22 + 40];
            Array.Copy(base.DataReaderData, 10, _fragmentedData, 0, 113);
            Array.Copy(base.DataReaderData, 151, _fragmentedData, 113, 89);
            Array.Copy(base.DataReaderData, 255, _fragmentedData, 113 + 89, 17);
            Array.Copy(base.DataReaderData, 289, _fragmentedData, 113 + 89 + 17, 1);
            Array.Copy(base.DataReaderData, 393, _fragmentedData, 113 + 89 + 17 + 1, 44);
            Array.Copy(base.DataReaderData, 0, _fragmentedData, 113 + 89 + 17 + 1 + 44, 5);
            Array.Copy(base.DataReaderData, 511, _fragmentedData, 113 + 89 + 17 + 1 + 44 + 5, 22);
            Array.Copy(base.DataReaderData, 140, _fragmentedData, 113 + 89 + 17 + 1 + 44 + 5 + 22, 40);
        }
 public IDataPacket Append(IDataPacket dataPacket)
 {
     if (Detector != null)
     {
         throw new ArgumentException("Can not append to a codec stream");
     }
     return(_dataPacket.Append(dataPacket));
 }
        public override IDataPacket GetVideoData(IResultNode resultNode)
        {
            // Mpeg4 doesn't require other data (frames) to make itself visible.
            IDataPacket dataPacket = resultNode;

            // Duplicate the frame data, because otherwise, FFmpeg won't decode it.
            return(dataPacket.Append(dataPacket));
        }
Ejemplo n.º 6
0
        public IDataPacket GetVideoData(IResultNode resultNode)
        {
            if (!IsIntraSlice(resultNode))
            {
                return(null);
            }
            if (resultNode.Parent == null)
            {
                // Slice without headers (won't decode!)
                return(resultNode.Append(resultNode));
            }

            uint?firstMacroblockInSlice = GetFirstMacroblockInSlice(resultNode);

            if (!firstMacroblockInSlice.HasValue)
            {
                return(resultNode.Append(resultNode));
            }

            int index = GetParentIndex(resultNode);
            IList <IResultNode> siblings   = resultNode.Parent.Children;
            IDataPacket         dataPacket = resultNode;

            for (int i = (index + 1); i < siblings.Count; i++)
            {
                IResultNode sibling = siblings[i];
                if (!IsIntraSlice(sibling))
                {
                    break;                     // Not an intra-coded slice, so not part of the same IDR picture
                }

                uint?nextFirstMacroblockInSlice = GetFirstMacroblockInSlice(sibling);
                if (!nextFirstMacroblockInSlice.HasValue || (nextFirstMacroblockInSlice <= firstMacroblockInSlice))
                {
                    break;                     // Slice is not part of the same picture
                }

                firstMacroblockInSlice = nextFirstMacroblockInSlice.Value;
                dataPacket             = dataPacket.Append(sibling);
            }

            // Duplicate the frame data, because otherwise, FFmpeg won't decode it.
            return(dataPacket.Append(dataPacket));
        }
Ejemplo n.º 7
0
            /// <summary>
            /// Gets the data packet for the given <paramref name="result"/>
            /// and its descendents.
            /// </summary>
            /// <param name="result">the result</param>
            /// <returns>the data packet</returns>
            private static IDataPacket CreateDataPacket(IResultNode result)
            {
                IDataPacket dataPacket = result;

                foreach (IResultNode childResult in result.Children)
                {
                    dataPacket = dataPacket.Append(CreateDataPacket(childResult));
                }
                return(dataPacket);
            }
Ejemplo n.º 8
0
            private static IDataPacket CreateDataPacketAsH264ByteStream(IResultNode result, IDataPacket h264StartCodePrefixDataPacket)
            {
                IDataPacket dataPacket = ProducePlayableExport(result, h264StartCodePrefixDataPacket);

                foreach (IResultNode childResult in result.Children)
                {
                    dataPacket = dataPacket.Append(CreateDataPacketAsH264ByteStream(childResult, h264StartCodePrefixDataPacket));
                }
                return(dataPacket);
            }
        private static IDataPacket CreateReferenceHeader(CodecID codec, IDataPacket videoObject, IResultNode videoObjectLayer, ICodecParametersSpec codecParameters)
        {
            // Report codec parameters for reference header
            codecParameters.Codec      = codec;
            codecParameters.Width      = GetAttribute <uint>(videoObjectLayer, VideoObjectLayer.Attribute.Width);
            codecParameters.Height     = GetAttribute <uint>(videoObjectLayer, VideoObjectLayer.Attribute.Height);
            codecParameters["VTIRate"] = GetAttributeStringValue(videoObjectLayer, VideoObjectLayer.Attribute.VopTimeIncrementResolution);

            return(videoObject.Append(videoObjectLayer));
        }
Ejemplo n.º 10
0
            private IDataPacket GetData(IDataReader dataReader)
            {
                IDataPacket data = _extraData;

                foreach (Chunk chunk in _chunks)
                {
                    IDataPacket dp = dataReader.GetDataPacket((_fileOffset + chunk.Offset), chunk.Length);
                    data = (data == null) ? dp : data.Append(dp);
                }
                return(data);
            }
Ejemplo n.º 11
0
        public IDataPacket GetVideoData(IResultNode resultNode)
        {
            IResultNode pictureNode = GetPictureNode(resultNode);

            // Add the frame data
            IDataPacket data = pictureNode;

            foreach (IResultNode childResultNode in pictureNode.Children)
            {
                data = data.Append(childResultNode);

                if (childResultNode == resultNode)
                {
                    break;                     // The slice that was selected has been reached!
                }
            }

            // Duplicate the frame data, because otherwise, FFmpeg won't decode it.
            return(data.Append(data));
        }
        public IDataPacket Append(IDataPacket dataPacket)
        {
            PreConditions.Argument("dataPacket").Value(dataPacket).IsNotNull();

            if ((_secondDataPacket.Length + dataPacket.Length) <= _firstDataPacket.Length)
            {
                return(new DataPacketNode(_firstDataPacket, _secondDataPacket.Append(dataPacket)));
            }

            return(new DataPacketNode(this, dataPacket));
        }
Ejemplo n.º 13
0
        private void SaveCurrentBitmapToFile(string filePath, ImageFormat format, bool createForensicIntegrityLog)
        {
            if (_ffmpegResult != null && _ffmpegResult.SourcePacket != null && _ffmpegResult.Bitmap != null)
            {
                _ffmpegResult.Bitmap.Save(filePath, format);

                if (createForensicIntegrityLog)
                {
                    if (_ffmpegResult.SourcePacket != null)
                    {
                        IResultNode    headerSourceResult = _ffmpegResult.HeaderSource ?? _ffmpegResult.SourcePacket;
                        ICodecDetector codecDetector      = headerSourceResult.Detectors.FirstOrDefault() as ICodecDetector;
                        if (codecDetector == null)
                        {
                            return;
                        }
                        // FIXME: The detectors of the video headers cannot be determined (for forensic logging purposes)!!
                        IDataPacket usedBitmapHeaders = codecDetector.GetVideoHeaders(headerSourceResult);

                        string logFileName = string.Format("{0}.csv", filePath);
                        using (FileStream fs = new FileStream(logFileName, FileMode.Create, FileAccess.Write, FileShare.Read))
                        {
                            IDataPacket allUsedBitmapNodes = _ffmpegResult.SourcePacket;
                            // Prefix with bitmap headers (if any)
                            if (usedBitmapHeaders != null)
                            {
                                allUsedBitmapNodes = usedBitmapHeaders.Append(allUsedBitmapNodes);
                            }
                            // Append child nodes and determine detectors that were used
                            var detectors = new HashSet <IDetector>(_ffmpegResult.SourcePacket.Detectors);
                            foreach (var dataPacket in _ffmpegResult.SourcePacket.Children)
                            {
                                allUsedBitmapNodes = allUsedBitmapNodes.Append(dataPacket);
                                foreach (IDetector detector in dataPacket.Detectors)
                                {
                                    detectors.Add(detector);
                                }
                            }
                            _forensicIntegrityLog.Log(allUsedBitmapNodes, detectors, filePath, fs, ForensicLogType.ConvertedData);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Can't save integrity log. There is no packetdata available for the active bitmap.", "Save Integrity Log", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            else
            {
                MessageBox.Show("There is no frame opened, can't save empty frame to image.", "Save Image", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Ejemplo n.º 14
0
            private static IDataPacket ProducePlayableExport(IResultNode result, IDataPacket h264StartCodePrefixDataPacket)
            {
                if (result.DataFormat != CodecID.H264)
                {
                    return(result);
                }
                if (result.FindAttributeByName("StartCodePrefix") != null)
                {
                    return(result);
                }

                string nalUnitType       = result.FindAttributeByName("NalUnitType").ValueAsString;
                int    lengthPrefixBytes = ((nalUnitType == "7") || (nalUnitType == "8")) ? 2 : 4;

                return(h264StartCodePrefixDataPacket.Append(result.GetSubPacket(lengthPrefixBytes, (result.Length - lengthPrefixBytes))));
            }
Ejemplo n.º 15
0
        private static IDataPacket CreateReferenceHeader(CodecID codec, IResultNode sequenceHeader, ICodecParametersSpec codecParameters)
        {
            IDataPacket data = sequenceHeader;

            // Include sequence extensions
            foreach (IResultNode childResultNode in sequenceHeader.Children)
            {
                if (!IsSequenceExtension(childResultNode.Name))
                {
                    break;
                }

                data = data.Append(childResultNode);
            }

            // Report codec parameters for reference header
            var width  = GetAttribute <uint>(sequenceHeader, SequenceHeader.Attribute.HorizontalSizeValue);
            var height = GetAttribute <uint>(sequenceHeader, SequenceHeader.Attribute.VerticalSizeValue);

            if (sequenceHeader.HasChildren())
            {
                IResult sequenceExtension = sequenceHeader.GetFirstChild();
                if (sequenceExtension.Name == SequenceExtension.Name)
                {
                    width  |= GetAttribute <uint>(sequenceExtension, SequenceExtension.Attribute.HorizontalSizeExtension) << 12;
                    height |= GetAttribute <uint>(sequenceExtension, SequenceExtension.Attribute.VerticalSizeExtension) << 12;
                }
            }

            codecParameters.Codec     = codec;
            codecParameters.Width     = width;
            codecParameters.Height    = height;
            codecParameters.FrameRate = GetAttributeStringValue(sequenceHeader, SequenceHeader.Attribute.FrameRateCode);

            return(data);
        }
 public IDataPacket Append(IDataPacket dataPacket)
 {
     return(_dataPacket.Append(dataPacket));
 }
 public void AppendCreatesNewNode()
 {
     Assert.AreEqual(new DataPacketNode(_dataPacketSubPacketsOutOfOrder, _dataPacket3), _dataPacketSubPacketsOutOfOrder.Append(_dataPacket3));
 }
 public void AppendNull()
 {
     _dataPacket.Append(null);
 }
Ejemplo n.º 19
0
        private IDataPacket RescanDataPackets(IEnumerable <IDataPacket> dataPackets, IDataReaderPool dataReaderPool, IProgressReporter progressReporter)
        {
            IDataPacket concatenatedDataPacket = null;

            long totalByteCount = dataPackets.Sum(x => x.Length);
            long bytesSaved     = 0L;

            foreach (IDataPacket dataPacket in dataPackets)
            {
                if (progressReporter.CancellationPending)
                {
                    return(null);
                }

                IDataPacket rescannedDataPacket = dataPacket;
                if (dataPacket is ICodecStream)
                {
                    if (dataPacket is RescannedCodecStream)
                    {
                        rescannedDataPacket = dataPacket;
                    }
                    else
                    {
                        IProgressReporter rescanProgressReporter = new NullProgressReporter();
                        rescannedDataPacket = CreateDataBlockScanner().GetData(dataPacket as ICodecStream, rescanProgressReporter, dataReaderPool);
                    }
                }

                concatenatedDataPacket = (concatenatedDataPacket == null) ? rescannedDataPacket : concatenatedDataPacket.Append(rescannedDataPacket);
                bytesSaved            += dataPacket.Length;
            }
            return(concatenatedDataPacket);
        }
Ejemplo n.º 20
0
        private IDataPacket RescanDataPackets(IEnumerable <IDataPacket> dataPackets, IDataReaderPool dataReaderPool, IProgressReporter progressReporter)
        {
            IDataPacket concatenatedDataPacket = null;

            long totalByteCount = dataPackets.Sum(x => x.Length);
            long bytesSaved     = 0L;

            foreach (IDataPacket dataPacket in dataPackets)
            {
                if (progressReporter.CancellationPending)
                {
                    return(null);
                }

                IDataPacket rescannedDataPacket = dataPacket;
                if (dataPacket is ICodecStream)
                {
                    // FIXME: This check should not be necessary, but the user interface is not
                    //        consistent in rescanning data packets: either in the user interface
                    //        itself, or in the framework!
                    if (dataPacket is RescannedCodecStream)
                    {
                        // Note: data packet is already rescanned, so just append it ...
                        rescannedDataPacket = dataPacket;
                    }
                    else
                    {
                        IProgressReporter rescanProgressReporter = _createSubProgressReporter(progressReporter, bytesSaved, dataPacket.Length, totalByteCount);
                        rescannedDataPacket = _dataBlockScanner.GetData(dataPacket as ICodecStream, rescanProgressReporter, dataReaderPool);
                    }
                }

                concatenatedDataPacket = (concatenatedDataPacket == null) ? rescannedDataPacket : concatenatedDataPacket.Append(rescannedDataPacket);

                bytesSaved += dataPacket.Length;
            }
            return(concatenatedDataPacket);
        }
Ejemplo n.º 21
0
 private static IDataPacket Append(IDataPacket dataPacket1, IDataPacket dataPacket2)
 {
     return((dataPacket1 == null) ? dataPacket2 : dataPacket1.Append(dataPacket2));
 }
 public static IDataPacket Prepend(this IDataPacket dataPacket, IDataPacket prefix)
 {
     return((dataPacket == null) ? prefix : prefix.Append(dataPacket));
 }
Ejemplo n.º 23
0
 public void AddPayload(IDataPacket payload)
 {
     _data = (_data == null) ? payload : _data.Append(payload);
 }
Ejemplo n.º 24
0
        /// <summary>
        /// Gets the data of the entire detectable using all related fragments.
        /// </summary>
        /// <param name="detectable">the detectable</param>
        /// <returns>the complete data of the detectable</returns>
        private IDataPacket GetCompleteFragmentData(IFragment detectable, IProgressReporter progressReporter, IDataReaderPool dataReaderPool)
        {
            if ((detectable is IDataBlock) && (detectable.FragmentContainer == null))
            {
                // Unfragmented data block
                return(detectable);
            }

            IDataPacket data = null;

            if (detectable is IDataBlock)
            {
                // Fragmented data block
                foreach (IFragment fragment in detectable.FragmentContainer)
                {
                    data = (data == null) ? fragment : data.Append(fragment);
                }
                return(data);
            }

            if (!(detectable is ICodecStream))
            {
                throw new ArgumentException("Not an IDataBlock or ICodecStream", "detectable");
            }

            ICodecStream codecStream = (detectable as ICodecStream);
            IDataBlock   parent      = codecStream.DataBlock;

            if (parent.FragmentContainer == null)
            {
                if (detectable.FragmentContainer == null)
                {
                    // Unfragmented codec stream
                    return(_dataBlockScanner.GetData(detectable as ICodecStream, progressReporter, dataReaderPool));
                }

                // Fragmented codec stream
                foreach (IFragment fragment in detectable.FragmentContainer)
                {
                    IDataPacket fragmentData = _dataBlockScanner.GetData(fragment as ICodecStream, progressReporter, dataReaderPool);
                    if (progressReporter.CancellationPending)
                    {
                        return(null);
                    }

                    data = (data == null) ? fragmentData : data.Append(fragmentData);
                }
                return(data);
            }

            int streamIndex = codecStream.StreamNumber;

            // Fragmented codec stream in a fragmented data block
            foreach (IFragment dbFragment in parent.FragmentContainer)
            {
                foreach (ICodecStream fragment in ((IDataBlock)dbFragment).CodecStreams)
                {
                    if (fragment.StreamNumber == streamIndex)
                    {
                        IDataPacket fragmentData = _dataBlockScanner.GetData(fragment, progressReporter, dataReaderPool);
                        if (progressReporter.CancellationPending)
                        {
                            return(null);
                        }

                        data = (data == null) ? fragmentData : data.Append(fragmentData);
                    }
                }
            }
            return(data);
        }