Package rtpi.packets

Examples of rtpi.packets.RtpiDataPacket


    }

    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();
View Full Code Here


 
  if (!iter.hasNext()) {
      throw new IllegalValueException("UdpUnreliable: empty RTP/I ADU");
  }

  RtpiDataPacket packet = (RtpiDataPacket) iter.next();

  if (packet.getFragmentCount()!=0) {
      throw new IllegalValueException("UdpUnreliable: fragment count of the first packet is not 0");
  }

  int sequenceNumber=packet.getSequenceNumber();
  int fragmentCount=packet.getFragmentCount();
  int type=packet.getType();
  int payloadType=packet.getPayloadType();
  int priority=packet.getPriority();
  int participantID=packet.getParticipantID();
  long subcomponentID=packet.getSubcomponentID();
  long timestamp=packet.getTimestamp();

  while (iter.hasNext()) {
      packet=(RtpiDataPacket) iter.next();
      if (sequenceNumber!=packet.getSequenceNumber()) {
    throw new IllegalValueException("UdpUnreliable: packets of the same RTP/I ADU have different sequence numbers");
      }
      if (((++fragmentCount)%0x0000FFFF)!=packet.getFragmentCount()) {
    throw new IllegalValueException("UdpUnreliable: packets of the same RTP/I ADU have non contiguous fragment counts");
      }
      if (type!=packet.getType()) {
    throw new IllegalValueException("UdpUnreliable: packets of the same RTP/I ADU have different types");
      }
      if (payloadType!=packet.getPayloadType()) {
    throw new IllegalValueException("UdpUnreliable: packets of the same RTP/I ADU have different payload types");
      }
      if (priority!=packet.getPriority()) {
    throw new IllegalValueException("UdpUnreliable: packets of the same RTP/I ADU have different priorities");
      }
      if (participantID!=packet.getParticipantID()) {
    throw new IllegalValueException("UdpUnreliable: packets of the same RTP/I ADU have different paticipant IDs");
      }
      if (subcomponentID!=packet.getSubcomponentID()) {
    throw new IllegalValueException("UdpUnreliable: packets of the same RTP/I ADU have different sub-component IDs");
      }
      if (timestamp!=packet.getTimestamp()) {
    throw new IllegalValueException("UdpUnreliable: packets of the same RTP/I ADU have different timestamps");
      }
  }   

  if (packet.getEnd()!=1) {
      throw new IllegalValueException("UdpUnreliable: end bit not set in last packet of RTP/I ADU");
  }

        messages.put(new Message(Message.TRANSMIT_RTPI_ADU, packets));
    }
View Full Code Here

        messages.put(new Message(Message.TRANSMIT_RTPI_ADU, packets));
    }

    private void execTransmitRtpiAdu(LinkedList packets) {
  ListIterator iter = packets.listIterator();
  RtpiDataPacket packet=null;
 
  while (iter.hasNext()) {
      packet=(RtpiDataPacket) iter.next();
      packet.setReliabilityType(0);
      packet.setExtension(0);
      try {
    packet.flush();
      } catch (Exception ex) {
    System.err.println("UdpUnreliable: error while flushing RtpiDataPacket "+ex);
      }
      TransportPacket tpacket = new TransportPacket(packet.getLength()+
                RtpiDataPacket.HEADER_SIZE, packet.getPacketData());
      transport.sendTransportPacket(tpacket);
  }
    }
View Full Code Here

    }

    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();
View Full Code Here

    void put(RtpiDataPacket packet) {

  lastPacketReceivedAt = System.currentTimeMillis();

  RtpiDataPacket packet2 = (RtpiDataPacket) buffer.getLast();

  if (packet2.getFragmentCount() < packet.getFragmentCount()) { // this should be the most common case!
      buffer.add(packet);
      return;
  }

  int position=buffer.size();

  do {
      position--;
      packet2 = (RtpiDataPacket) buffer.get(position);
  } while (packet2.getFragmentCount() > packet.getFragmentCount() && position!=0);

  if (position==0 && packet2.getFragmentCount() > packet.getFragmentCount()) {
      position--;
  }
  buffer.add(position+1, packet);
    }
View Full Code Here

  if (!it.hasNext()) {
      return false;
  }

  RtpiDataPacket packet=(RtpiDataPacket) it.next();
  int fragmentCount=packet.getFragmentCount();

  if (fragmentCount!=0) {
      return false;
  }

  while(it.hasNext()) {
      packet = (RtpiDataPacket)it.next();
      if (packet.getFragmentCount()!=fragmentCount+1) {
    return false;
      }
      fragmentCount++;
  }

  if (packet.getEnd()!=1) {
      return false;
  }

  return true;
    }
View Full Code Here

    void put(RtpiDataPacket packet) {

  lastPacketReceivedAt = System.currentTimeMillis();

  RtpiDataPacket packet2 = (RtpiDataPacket) buffer.getLast();

  if (packet2.getFragmentCount() < packet.getFragmentCount()) { // this should be the most common case!
      buffer.add(packet);
      return;
  }

  int position=buffer.size();

  do {
      position--;
      packet2 = (RtpiDataPacket) buffer.get(position);
  } while (packet2.getFragmentCount() > packet.getFragmentCount() && position!=0);

  if (position==0 && packet2.getFragmentCount() > packet.getFragmentCount()) {
      position--;
  }
  buffer.add(position+1, packet);
    }
View Full Code Here

  if (!it.hasNext()) {
      return false;
  }

  RtpiDataPacket packet=(RtpiDataPacket) it.next();
  int fragmentCount=packet.getFragmentCount();

  if (fragmentCount!=0) {
      return false;
  }

  while(it.hasNext()) {
      packet = (RtpiDataPacket)it.next();
      if (packet.getFragmentCount()!=fragmentCount+1) {
    return false;
      }
      fragmentCount++;
  }

  if (packet.getEnd()!=1) {
      return false;
  }

  return true;
    }
View Full Code Here

 
  if (!iter.hasNext()) {
      throw new IllegalValueException("UdpUnreliable: empty RTP/I ADU");
  }

  RtpiDataPacket packet = (RtpiDataPacket) iter.next();

  if (packet.getFragmentCount()!=0) {
      throw new IllegalValueException("UdpUnreliable: fragment count of the first packet is not 0");
  }

  int sequenceNumber=packet.getSequenceNumber();
  int fragmentCount=packet.getFragmentCount();
  int type=packet.getType();
  int payloadType=packet.getPayloadType();
  int priority=packet.getPriority();
  int participantID=packet.getParticipantID();
  long subcomponentID=packet.getSubcomponentID();
  long timestamp=packet.getTimestamp();

  while (iter.hasNext()) {
      packet=(RtpiDataPacket) iter.next();
      if (sequenceNumber!=packet.getSequenceNumber()) {
    throw new IllegalValueException("UdpUnreliable: packets of the same RTP/I ADU have different sequence numbers");
      }
      if (((++fragmentCount)%0x0000FFFF)!=packet.getFragmentCount()) {
    throw new IllegalValueException("UdpUnreliable: packets of the same RTP/I ADU have non contiguous fragment counts");
      }
      if (type!=packet.getType()) {
    throw new IllegalValueException("UdpUnreliable: packets of the same RTP/I ADU have different types");
      }
      if (payloadType!=packet.getPayloadType()) {
    throw new IllegalValueException("UdpUnreliable: packets of the same RTP/I ADU have different payload types");
      }
      if (priority!=packet.getPriority()) {
    throw new IllegalValueException("UdpUnreliable: packets of the same RTP/I ADU have different priorities");
      }
      if (participantID!=packet.getParticipantID()) {
    throw new IllegalValueException("UdpUnreliable: packets of the same RTP/I ADU have different paticipant IDs");
      }
      if (subcomponentID!=packet.getSubcomponentID()) {
    throw new IllegalValueException("UdpUnreliable: packets of the same RTP/I ADU have different sub-component IDs");
      }
      if (timestamp!=packet.getTimestamp()) {
    throw new IllegalValueException("UdpUnreliable: packets of the same RTP/I ADU have different timestamps");
      }
  }   

  if (packet.getEnd()!=1) {
      throw new IllegalValueException("UdpUnreliable: end bit not set in last packet of RTP/I ADU");
  }

        messages.put(new Message(Message.TRANSMIT_RTPI_ADU, packets));
    }
View Full Code Here

        messages.put(new Message(Message.TRANSMIT_RTPI_ADU, packets));
    }

    private void execTransmitRtpiAdu(LinkedList packets) {
  ListIterator iter = packets.listIterator();
  RtpiDataPacket packet=null;
 
  while (iter.hasNext()) {
      packet=(RtpiDataPacket) iter.next();
      packet.setReliabilityType(0);
      packet.setExtension(0);
      try {
    packet.flush();
      } catch (Exception ex) {
    System.err.println("UdpUnreliable: error while flushing RtpiDataPacket "+ex);
      }
      TransportPacket tpacket = new TransportPacket(packet.getLength()+
                RtpiDataPacket.HEADER_SIZE, packet.getPacketData());
      transport.sendTransportPacket(tpacket);
  }
    }
View Full Code Here

TOP

Related Classes of rtpi.packets.RtpiDataPacket

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.