}
private void execReceiveTransportPacket(TransportPacket tpacket) {
int position=0;
do {
RtpiDataPacket packet = new RtpiDataPacket(tpacket.getData(), position);
try {
packet.parse();
} catch (Exception ex) {
System.err.println("UdpUnreliable: Exception while parsing RTP/I packet "+ex+" - packet ignored!");
return;
}
if (packet.getReliabilityType()!=0) {
System.err.println("UdpUnreliable: Illegal reliability type in receive RtpiDataPacket "+
packet.getReliabilityType()+" - packet ignored!");
return;
}
if (packet.getType()!=RtpiDataPacket.EVENT &&
packet.getType()!=RtpiDataPacket.STATE &&
packet.getType()!=RtpiDataPacket.DELTA_STATE &&
packet.getType()!=RtpiDataPacket.STATE_QUERY) {
System.err.println("UdpUnreliable: Illegal ADU type in receive RtpiDataPacket "+
packet.getType()+" - packet ignored!");
return;
}
if (packet.getFragmentCount()==0 && packet.getEnd()==1) {
LinkedList packets = new LinkedList();
packets.add(packet);
recipient.receiveRtpiAdu(packets);
} else {
Hashtable subcomponents = (Hashtable) senders.get(new Integer(packet.getParticipantID()));
if (subcomponents==null) {
subcomponents = new Hashtable();
senders.put (new Integer(packet.getParticipantID()),subcomponents);
Hashtable aduTypes=new Hashtable();
subcomponents.put(new Long(packet.getSubcomponentID()),aduTypes);
Hashtable adus = new Hashtable();
aduTypes.put(new Long(packet.getType()), adus);
RtpiDataPacketBuffer buffer = new RtpiDataPacketBuffer(packet);
adus.put(new Integer(packet.getSequenceNumber()), buffer);
} else {
Hashtable aduTypes=(Hashtable) subcomponents.get(new Long(packet.getSubcomponentID()));
if (aduTypes==null) {
aduTypes = new Hashtable();
subcomponents.put(new Long(packet.getSubcomponentID()), aduTypes);
Hashtable adus = new Hashtable();
aduTypes.put(new Long(packet.getType()), adus);
RtpiDataPacketBuffer buffer = new RtpiDataPacketBuffer(packet);
adus.put(new Integer(packet.getSequenceNumber()), buffer);
} else {
Hashtable adus = (Hashtable) aduTypes.get(new Long (packet.getType()));
if (adus==null) {
adus = new Hashtable();
aduTypes.put(new Long(packet.getType()), adus);
RtpiDataPacketBuffer buffer = new RtpiDataPacketBuffer(packet);
adus.put(new Integer(packet.getSequenceNumber()), buffer);
} else {
RtpiDataPacketBuffer buffer = (RtpiDataPacketBuffer) adus.get(new Integer(packet.getSequenceNumber()));
if (buffer==null) {
buffer = new RtpiDataPacketBuffer(packet);
adus.put(new Integer(packet.getSequenceNumber()), buffer);
} else {
buffer.put(packet);
if (buffer.isComplete()) {
recipient.receiveRtpiAdu(buffer.getPackets());
adus.remove(new Integer(packet.getSequenceNumber()));
if (adus.isEmpty()) { // we remove all empty hashtables this may be inefficient
// an optimization could be to keep the tables and delete
// them periodically or when the become to memory consumant!
aduTypes.remove(new Integer(packet.getType()));
if (aduTypes.isEmpty()) {
subcomponents.remove(new Long(packet.getSubcomponentID()));
if (subcomponents.isEmpty()) {
senders.remove(new Integer(packet.getParticipantID()));
}
}
}
}
}
}
}
}
}
position+=packet.getLength()+RtpiDataPacket.HEADER_SIZE;
position+=(4-position%4)%4;
} while(position < tpacket.getLength());
removeOutdatedPackets();