Esempio n. 1
0
        public bool Parse(PacketEvent packet)
        {
            DataBuffer       rawInput = new DataBuffer(packet.GetData(), packet.GetLength());
            DataBufferReader reader   = new DataBufferReader();

            int firstByte = reader.Read8(rawInput);

            this.version      = firstByte >> 6;
            this.padding      = ((firstByte >> 5 & 1) != 0);
            this.hasExtension = ((firstByte >> 4 & 1) != 0);
            this.csrcCount    = firstByte & 0xF;

            int secondByte = reader.Read8(rawInput);

            this.marker      = (secondByte & 0x80) == 0x80;
            this.payloadType = secondByte & 0x7f;

            this.SequenceNumber = reader.Read16(rawInput);
            this.timestamp      = reader.ReadInteger(rawInput);
            this.ssrc           = reader.ReadInteger(rawInput);

            int  block3         = reader.Read8(rawInput);
            bool bflag          = (block3 >> 7 & 1) != 0;
            bool jflag          = ((block3 >> 6 & 1) & 0x1) != 0;
            bool zflag          = ((block3 >> 5 & 1) & 0x1) != 0;
            bool pflag          = ((block3 >> 4 & 1) & 0x1) != 0;
            int  command_length = block3 & 0x7;

            this.payload        = rawInput.Slice(rawInput.GetStreamPosition());
            this.payload_length = rawInput.GetBytesLength() - rawInput.GetStreamPosition();
            return(true);
        }
Esempio n. 2
0
        public bool Parse(PacketEvent packet)
        {
            this.valid = false;
            DataBuffer       rawInput = new DataBuffer(packet.GetData(), packet.GetLength());
            DataBufferReader reader   = new DataBufferReader();
            int protocol = reader.Read16(rawInput);

            if (protocol == 0xffff)
            {
                command = commandMap.GetValueOrDefault <int, AppleMIDICommand>(reader.Read16(rawInput));
                switch (command)
                {
                case AppleMIDICommand.INVITATION:
                case AppleMIDICommand.INVITATION_ACCEPTED:
                case AppleMIDICommand.INVITATION_REJECTED:
                case AppleMIDICommand.END:
                    this.valid       = true;
                    protocol_version = reader.ReadInteger(rawInput);
                    initiator_token  = reader.ReadInteger(rawInput);
                    ssrc             = reader.ReadInteger(rawInput);
                    name             = reader.ReadString(rawInput);
                    //                    this.version = buffer.readUInt32BE(4);
                    //                    this.token = buffer.readUInt32BE(8);
                    //                    this.ssrc = buffer.readUInt32BE(12);
                    //                    this.name = buffer.toString('utf-8', 16);

                    break;

                case AppleMIDICommand.SYNCHRONIZATION:
                    this.valid = true;
                    ssrc       = reader.ReadInteger(rawInput);
                    count      = reader.Read8(rawInput);
                    padding    = reader.Read24(rawInput);
                    timestamp1 = reader.ReadUnsignedInteger64(rawInput);
                    timestamp2 = reader.ReadUnsignedInteger64(rawInput);
                    timestamp3 = reader.ReadUnsignedInteger64(rawInput);
                    //                    this.ssrc = buffer.readUInt32BE(4, 8);
                    //                    this.count = buffer.readUInt8(8);
                    //                    this.padding = (buffer.readUInt8(9) << 0xF0) + buffer.readUInt16BE(10);
                    //                    this.timestamp1 = buffer.slice(12, 20); //[buffer.readUInt32BE(12), buffer.readUInt32BE(16)];
                    //                    this.timestamp2 = buffer.slice(20, 28); //[buffer.readUInt32BE(20), buffer.readUInt32BE(24)];
                    //                    this.timestamp3 = buffer.slice(28, 36); //[buffer.readUInt32BE(28), buffer.readUInt32BE(32)];
                    break;

                case AppleMIDICommand.RECEIVER_FEEDBACK:
                    this.valid     = true;
                    ssrc           = reader.ReadInteger(rawInput);
                    sequenceNumber = reader.Read16(rawInput);
                    //                    this.ssrc = buffer.readUInt32BE(4, 8);
                    //                    this.sequenceNumber = buffer.readUInt16BE(8);
                    break;

                case AppleMIDICommand.BITRATE_RECEIVE_LIMIT:
                    this.valid = true;
                    break;
                }
            }
            return(valid);
        }