示例#1
0
        public TSPacket(byte[] byteBuffer)
        {
            _bitstream = new BitstreamReader();
            _bitstream.Init(byteBuffer, 0);

            uint magic = _bitstream.ReadUBits(8);
            if (magic != 0x47)
                throw new TSDemuxException("sync bits not found");

            _transport_error_indicator = _bitstream.ReadUBits(1);
            _payload_unit_start_indicator = _bitstream.ReadUBits(1);
            _transport_priority = _bitstream.ReadUBits(1);
            _pid = _bitstream.ReadUBits(13);
            _transport_scrambling_control = _bitstream.ReadUBits(2);
            _adaptation_field_control = _bitstream.ReadUBits(2);
            _continuity_counter = _bitstream.ReadUBits(4);

            _headerSize = 4;

            if (!IsValidPID())
            {
                throw new TSDemuxException("Invalid TS packet PID!");
            }

            if (HasAdaptationField())
            {
                uint adaptationLength = _bitstream.ReadUBits(8);
                if (adaptationLength > 0)
                {
                    _adaptation_field = new byte[adaptationLength];

                    for (int i = 0; i < adaptationLength; i++)
                    {
                        _adaptation_field[i] = _bitstream.ReadByte();
                    }

                    _discontinuity = ((_adaptation_field[0] & 0x80) != 0x00);
                }

                _headerSize += ((int)adaptationLength + 1);
            }
        }
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="msd"></param>
 public ADTSParser(SampleBuffer outputBuffer, HLSStream hlsStream)
     : base(outputBuffer, hlsStream)
 {
     _bitstream = new BitstreamReader();
 }
示例#3
0
 /// <summary>
 /// Default constructor.
 /// </summary>
 /// <param name="sampler">Output sampler</param>
 public PESParser(MediaFormatParser formatParser)
 {
     _output = formatParser;
     _byteBuffer = new byte[1024];
     _bitstream = new BitstreamReader();
 }