private long TrimResult()
        {
            if (_lastHeader == null)
            {
                return(0L);
            }

            // Trim zero byte stuffing from last header (if any)
            string zeroByteStuffingName      = Enum.GetName(typeof(NalUnitParser.Attribute), NalUnitParser.Attribute.TrailingZeroBytes);
            var    zeroByteStuffingAttribute = _lastHeader.FindAttributeByName(zeroByteStuffingName);

            if (zeroByteStuffingAttribute == null)
            {
                return(0L);
            }

            uint byteCount = (uint)zeroByteStuffingAttribute.Value;

            // Rebuild the last header, omitting the zero byte stuffing attribute
            var resultNodeBuilder = new ResultNodeBuilder
            {
                Name       = _lastHeader.Name,
                Metadata   = _lastHeader,
                DataPacket = _lastHeader.GetSubPacket(0, (_lastHeader.Length - byteCount))
            };

            foreach (IResultAttribute attribute in _lastHeader.Attributes.Where(a => a.Name != zeroByteStuffingName))
            {
                resultNodeBuilder.AddAttribute(attribute);
            }

            // Replace the last header with the new (trimmed) header
            IResultNode parent = _lastHeader.Parent;

            parent.RemoveChild(_lastHeader);
            parent.AddChild(resultNodeBuilder.Build());

            // Compensate end offset for zero byte trimming
            return(-byteCount);
        }
예제 #2
0
        public IDataBlock DetectData(IDataReader dataReader, IDataBlockBuilder dataBlockBuilder, IScanContext context)
        {
            long startOffset = dataReader.Position;
            long endOffset   = dataReader.Length;

            IMetadata          metadata          = new Metadata(CodecID.Unknown, context.Detectors);
            IResultNode        root              = new RootResult(metadata, dataReader.GetDataPacket(0, 1).InputFile);
            IResultNodeBuilder resultNodeBuilder = new ResultNodeBuilder
            {
                Name       = "Data",
                Metadata   = metadata,
                DataPacket = dataReader.GetDataPacket(startOffset, (endOffset - startOffset))
            };

            root.AddChild(resultNodeBuilder.Build());
            context.Results = root;

            dataBlockBuilder.DataFormat  = CodecID.Unknown;
            dataBlockBuilder.StartOffset = startOffset;
            dataBlockBuilder.EndOffset   = endOffset;
            dataReader.Position          = endOffset;
            return(dataBlockBuilder.Build());
        }