Beispiel #1
0
        public TsPacket(byte[] buffer, int offset = 0)
        {
            int position = offset;

            if (buffer.Length - offset < Length)
            {
                throw new ArgumentOutOfRangeException("Buffer must contain at least " + Length + " bytes.");
            }
            if (buffer[position++] != SyncByte)
            {
                throw new ArgumentException("Packet does not begin with 0x" + SyncByte.ToString("X2") + " sync byte.");
            }
            _header1 = (ushort)((buffer[position++] << 8) | buffer[position++]);
            _header2 = buffer[position++];

            if (HasAdaptationField)
            {
                _adaptationField = new AdaptationField(buffer, position);
                position        += AdaptationField.Length + 1;
            }

            if (HasPayload)
            {
                int payloadLength = Length - (position - offset);
                _payload = new byte[payloadLength];
                Buffer.BlockCopy(buffer, position, _payload, 0, payloadLength);
                position += payloadLength;
            }
            int stuffingLength = Length - (position - offset);

            if (stuffingLength > 0)
            {
                Debug.WriteLine("Has " + stuffingLength + " bytes of Transport Packet stuffing.");
                Stuffing = new byte[stuffingLength];
            }
        }
Beispiel #2
0
        public TsPacket(byte[] buffer, int offset=0)
        {
            int position = offset;

            if (buffer.Length - offset < Length) 
                throw new ArgumentOutOfRangeException("Buffer must contain at least " + Length + " bytes.");
            if (buffer[position++] != SyncByte) 
                throw new ArgumentException("Packet does not begin with 0x" + SyncByte.ToString("X2") + " sync byte.");
            _header1 = (ushort)((buffer[position++] << 8) | buffer[position++]);
            _header2 = buffer[position++];

            if(HasAdaptationField)
            {
                _adaptationField = new AdaptationField(buffer, position);
                position += AdaptationField.Length + 1;
            }

            if (HasPayload)
            {
                int payloadLength = Length - (position - offset);
                _payload = new byte[payloadLength];
                Buffer.BlockCopy(buffer, position, _payload, 0, payloadLength);
                position += payloadLength;
            }
            int stuffingLength = Length - (position - offset);
            if (stuffingLength > 0)
            {
                Debug.WriteLine("Has " + stuffingLength + " bytes of Transport Packet stuffing.");
                Stuffing = new byte[stuffingLength];
            }
        }