Ejemplo n.º 1
0
        public Packet(byte[] packetBuffer)
        {
            TransportErrorIndicator   = 1 == packetBuffer[1] >> 7;                   // Set by demodulator if can't correct errors in the stream, to tell the demultiplexer that the packet has an uncorrectable error
            PayloadUnitStartIndicator = 1 == ((packetBuffer[1] & 64) >> 6);          // and with 01000000 to get second byte - 1 means start of PES data or PSI otherwise zero
            TransportPriority         = 1 == ((packetBuffer[1] & 32) >> 5);          // and with 00100000 to get third byte - 1 means higher priority than other packets with the same PID
            PacketId               = (packetBuffer[1] & 31) * 256 + packetBuffer[2]; // and with 00011111 to get last 5 bytes
            ScramblingControl      = packetBuffer[3] >> 6;                           // '00' = Not scrambled.   The following per DVB spec:[12]   '01' = Reserved for future use,   '10' = Scrambled with even key,   '11' = Scrambled with odd key
            AdaptationFieldControl = (packetBuffer[3] & 48) >> 4;                    // and with 00110000, 01 = no adaptation fields (payload only), 10 = adaptation field only, 11 = adaptation field and payload
            ContinuityCounter      = packetBuffer[3] & 15;
            AdaptionFieldLength    = AdaptationFieldControl > 1 ? (0xFF & packetBuffer[4]) + 1 : 0;

            if (AdaptationFieldControl == Helper.B00000010 || AdaptationFieldControl == Helper.B00000011)
            {
                AdaptationField = new AdaptationField(packetBuffer);
            }

            if (AdaptationFieldControl == Helper.B00000001 || AdaptationFieldControl == Helper.B00000011) // Payload exists -  binary '01' || '11'
            {
                int payloadStart = 4;
                if (AdaptationField != null)
                {
                    payloadStart += (1 + AdaptationField.Length);
                }

                if (PacketId == ProgramAssociationTablePacketId)                                           // PAT = Program Association Table: lists all programs available in the transport stream.
                {
                    ProgramAssociationTable = new ProgramAssociationTable(packetBuffer, payloadStart + 1); // TODO: What index?
                }

                // Save payload
                Payload = new byte[packetBuffer.Length - payloadStart];
                Buffer.BlockCopy(packetBuffer, payloadStart, Payload, 0, Payload.Length);
            }
        }
Ejemplo n.º 2
0
        public Packet(byte[] packetBuffer)
        {
            TransportErrorIndicator = 1 == packetBuffer[1] >> 7; // Set by demodulator if can't correct errors in the stream, to tell the demultiplexer that the packet has an uncorrectable error
            PayloadUnitStartIndicator = 1 == ((packetBuffer[1] & 64) >> 6); // and with 01000000 to get second byte - 1 means start of PES data or PSI otherwise zero
            TransportPriority = 1 == ((packetBuffer[1] & 32) >> 5); // and with 00100000 to get third byte - 1 means higher priority than other packets with the same PID
            PacketId = (packetBuffer[1] & 31) * 256 + packetBuffer[2];// and with 00011111 to get last 5 bytes
            ScramblingControl = packetBuffer[3] >> 6; // '00' = Not scrambled.   The following per DVB spec:[12]   '01' = Reserved for future use,   '10' = Scrambled with even key,   '11' = Scrambled with odd key
            AdaptationFieldControl = (packetBuffer[3] & 48) >> 4; // and with 00110000, 01 = no adaptation fields (payload only), 10 = adaptation field only, 11 = adaptation field and payload
            ContinuityCounter = packetBuffer[3] & 15;
            AdaptionFieldLength = AdaptationFieldControl > 1 ? (0xFF & packetBuffer[4]) + 1 : 0;

            if (AdaptationFieldControl == Helper.B00000010 || AdaptationFieldControl == Helper.B00000011)
                AdaptationField = new AdaptationField(packetBuffer);

            if (AdaptationFieldControl == Helper.B00000001 || AdaptationFieldControl == Helper.B00000011) // Payload exists -  binary '01' || '11'
            {
                int payloadStart = 4;
                if (AdaptationField != null)
                    payloadStart += (1 + AdaptationField.Length);

                if (PacketId == ProgramAssociationTablePacketId) // PAT = Program Association Table: lists all programs available in the transport stream.
                {
                    ProgramAssociationTable = new ProgramAssociationTable(packetBuffer, payloadStart + 1); // TODO: What index?
                }

                // Save payload
                Payload = new byte[packetBuffer.Length - payloadStart];
                Buffer.BlockCopy(packetBuffer, payloadStart, Payload, 0, Payload.Length);
            }
        }