Beispiel #1
0
 public static UnsignedShort fromBytes(byte[] c, int idx) {
   UnsignedShort number = new UnsignedShort();
   if ((c.length - idx) < 2) {
     throw new IllegalArgumentException("An UnsignedShort number is composed of 2 bytes.");
   }
   number.value = ((c[0] << 8) | (c[1] & 0xFFFF));
   return number;
 }
Beispiel #2
0
  /**
   * Convert the packet instance into a {@link IoBuffer} ready to be sent.
   *
   * @return a new IoBuffer
   */
  public IoBuffer toByteBuffer() {
    int packetSize = 12 + csrc.length * 4 + payload.length;
    if (extension) packetSize += headerExtension.length;

    IoBuffer buffer = IoBuffer.allocate(packetSize);
    buffer.limit(packetSize);

    byte c = 0x00;
    int bPadding = padding ? 1 : 0;
    int bExtension = extension ? 1 : 0;
    c = (byte) ((version << 6) | (bPadding << 5) | (bExtension << 4) | csrcCount);
    buffer.put(c);

    int bMarker = marker ? 1 : 0;
    c = (byte) ((bMarker << 7) | payloadType.intValue());
    buffer.put(c);

    buffer.put(sequence.getBytes());
    buffer.put(timestamp.getBytes());
    buffer.put(ssrc.getBytes());

    for (byte i = 0; i < Math.min(csrcCount, csrc.length); i++) {
      buffer.put(csrc[i].getBytes());
    }

    // Write the extension header if present
    if (extension) {
      buffer.putShort(profileExtension);
      buffer.putShort((short) headerExtension.length);
      buffer.put(headerExtension);
    }

    buffer.put(payload);
    buffer.rewind();
    return buffer;
  }
Beispiel #3
0
 public static UnsignedShort fromString(String c, int radix) {
   UnsignedShort number = new UnsignedShort();
   long v = Integer.parseInt(c, radix);
   number.value = (int) (v & 0xFFFF);
   return number;
 }