Exemplo n.º 1
0
        public NalUnitReader(IH264Reader reader, BitStreamDataReader dataReader, IH264State state)
        {
            _reader     = reader;
            _dataReader = dataReader;
            _state      = state;

            _maxTrailingZeroByteLength            = (uint)H264Detector.Configurable[H264Detector.ConfigurationKey.MaxTrailingZeroByteLength];
            _maxReferenceHeaderRetriesPerFragment = (uint)H264Detector.Configurable[H264Detector.ConfigurationKey.MaxReferenceHeaderRetriesPerFragment];
        }
        private bool ParseLongLengthPrefixedNalUnit(IH264Reader reader, IResultNodeState resultState)
        {
            uint nalUnitLength      = reader.GetUInt(NalUnitParser.Attribute.NalUnitLength);
            long nalUnitEndPosition = (reader.Position + nalUnitLength);

            if (nalUnitEndPosition > reader.Length)
            {
                return(false);
            }

            //Parse remainder with specific nalunitparser (NOTE: Is not a sub-object)
            reader.ParseOneNalUnit(_nalUnitParser, resultState, nalUnitEndPosition);

            return(reader.Position == nalUnitEndPosition);
        }
        public H264ResultTreeBuilder(BitStreamDataReader dataReader, IH264Reader reader, IH264State state, IScanContext scanContext, NalUnitStreamParser nalUnitStreamParser, ByteStreamParser byteStreamParser)
        {
            _falseHitReduction   = (bool)H264Detector.Configurable[H264Detector.ConfigurationKey.FalseHitReduction];
            _dataReader          = dataReader;
            _reader              = reader;
            _state               = state;
            _scanContext         = scanContext;
            _nalUnitStreamParser = nalUnitStreamParser;
            _byteStreamParser    = byteStreamParser;

            Configurable <H264Detector.ConfigurationKey> configurable = H264Detector.Configurable;

            _maxGapBetweenPpsAndSlice = (uint)configurable[H264Detector.ConfigurationKey.MaxGapBetweenPpsAndSlice];
            _maxGapBetweenPpsAndSps   = (uint)configurable[H264Detector.ConfigurationKey.MaxGapBetweenPpsAndSps];
            _maxGapBetweenNalUnits    = (uint)configurable[H264Detector.ConfigurationKey.MaxGapBetweenNalUnits];
        }
        public void Parse(IH264Reader reader, IResultNodeState resultState)
        {
            long bytesRemaining = (reader.Length - reader.Position);

            if (bytesRemaining < 4)
            {
                resultState.Invalidate();
                return;
            }

            long startPosition = reader.Position;

            // Check whether a sequence parameter set and a picture parameter set are
            // separated by exactly one byte in a NAL unit stream.
            // This is the case for H.264 streams embedded in 3GPP files.
            ulong nextFiveBytes = reader.PeekFiveBytes();

            if ((_state.NalUnitType == NalUnitType.SequenceParameterSet) &&
                !IsShortLengthPrefixedNalUnit((uint)(nextFiveBytes >> 16), bytesRemaining) &&
                IsShortLengthPrefixedNalUnit((uint)(nextFiveBytes >> 8) & 0xffffff, (bytesRemaining - 1)))
            {
                // Skip the byte that is part of the 3GPP container
                reader.Position++;
                bytesRemaining--;
                nextFiveBytes = reader.PeekFiveBytes();
            }
            if (IsShortLengthPrefixedNalUnit((uint)(nextFiveBytes >> 16), bytesRemaining))
            {
                if (ParseShortLengthPrefixedNalUnit(reader, resultState) && resultState.Valid)
                {
                    return;                     // Successfully parse SPS or PPS NAL unit
                }

                resultState.Reset();
                reader.Position = startPosition;
            }
            if (IsLongLengthPrefixedNalUnit(nextFiveBytes, bytesRemaining))
            {
                if (ParseLongLengthPrefixedNalUnit(reader, resultState))
                {
                    return;                     // Successfully parse slice NAL unit
                }
            }

            resultState.Invalidate();
        }
Exemplo n.º 5
0
        public void Parse(IH264Reader reader, IResultNodeState resultState)
        {
            if (reader.Position == reader.Length)
            {
                resultState.Invalidate();
                return;
            }

            long nalUnitEndPosition;

            // Remove 'zero byte' and 'start code prefix' for the 'byte stream' format
            if (reader.PeekUInt() == 0x00000001)
            {
                // TODO: hoort eigenlijk bij de StartCodePrefix - zie pg. 305 van ITU-T H.264 (03/2010)
                reader.GetFixedByte(0x00, NalUnitParser.Attribute.ZeroByte);
            }

            reader.GetFixedThreeBytes(0x000001, NalUnitParser.Attribute.StartCodePrefix);
            var windowStart = reader.Position;

            if (reader.NextNalUnit())                 //Forward till after next nalunit startcode
            {
                nalUnitEndPosition = reader.Position; //Position of next nalunit start
            }
            else
            {
                nalUnitEndPosition = reader.Length;
            }

            reader.Position = windowStart;            //rewind

            if (!resultState.Valid)
            {
                return;
            }

            //Parse remainder with specific nalunitparser (NOTE: Is not a sub-object)
            reader.ParseOneNalUnit(_nalUnitParser, resultState, nalUnitEndPosition);
        }