public uint PeekUInt()
 {
     return(_dataReader.ShowBits(32));
 }
        private IStreamParser FindNalUnit(bool firstHeader)
        {
            bool detectByteStreamFormat    = firstHeader || (_streamParser == _byteStreamParser);
            bool detectNalUnitStreamFormat = firstHeader || (_streamParser == _nalUnitStreamParser);

            while (_dataReader.State == DataReaderState.Ready)
            {
                // Note: This assumes that a valid NAL unit is less than 1MB in size.
                uint startCode      = _dataReader.NextStartCode(9, 0, 23);
                long bytesRemaining = (_dataReader.Length - _dataReader.Position);
                if (bytesRemaining < 4)
                {
                    _dataReader.Position = _dataReader.Length;
                    break;
                }

                // Check for 'byte stream' format with '00 00 01' start code prefix
                if (detectByteStreamFormat)
                {
                    if (((startCode & ~0xff) == 0x00000100) && NalUnitStartByteByteStream[startCode & 0xff])
                    {
                        return(_byteStreamParser);
                    }
                }

                // Check for 'NAL unit stream' format: "00 LL xx", where 'LL' is the length prefix and 'xx' is the NAL unit byte
                if (detectNalUnitStreamFormat)
                {
                    if (_nalUnitStreamParser.IsShortLengthPrefixedNalUnit(startCode >> 8, bytesRemaining))
                    {
                        // Note: The data should not contain illegal sequences of '00 00 0x xx',
                        //       other than start code prefix emulation prevention sequences.
                        return(_nalUnitStreamParser);
                    }
                }

                // Advance to next position, i.e. the NAL unit byte
                _dataReader.Position++;

                // Check for 'byte stream' format with '00 00 00 01' start code prefix
                var nalUnitByte = (byte)(_dataReader.ShowBits(32) & 0xff);
                if (detectByteStreamFormat)
                {
                    if ((startCode == 0x00000001) && NalUnitStartByteSequenceParameterSet[nalUnitByte])
                    {
                        _dataReader.Position--;
                        return(_byteStreamParser);
                    }
                }

                // Check for 'NAL unit stream' format: "00 LL LL LL xx", where 'LLLLLL' is the length prefix and 'xx' is the NAL unit byte
                if (detectNalUnitStreamFormat)
                {
                    ulong nextFiveBytes = ((ulong)startCode << 8) | nalUnitByte;
                    if (_nalUnitStreamParser.IsLongLengthPrefixedNalUnit(nextFiveBytes, bytesRemaining))
                    {
                        // TODO: The data should not contain illegal sequences of '00 00 0x xx',
                        //       other than start code prefix emulation prevention sequences.

                        _dataReader.Position--;
                        return(_nalUnitStreamParser);
                    }
                }
            }

            // No more NAL units!
            return(null);
        }
 public uint ShowBits(int numBits)
 {
     return(_dataReader.ShowBits(numBits));
 }