SIP Communicator: the OpenSource Java VoIP and Instant Messaging client.

net.java.sip.communicator.impl.media
Class RawPacket

java.lang.Object
  extended by net.java.sip.communicator.impl.media.RawPacket
Direct Known Subclasses:
ZrtpRawPacket

public class RawPacket
extends Object

When using TransformConnector, a RTP/RTCP packet is represented using RawPacket. RawPacket stores the buffer holding the RTP/RTCP packet, as well as the inner offset and length of RTP/RTCP packet data. After transformation, data is also store in RawPacket objects, either the original RawPacket (in place transformation), or a newly created RawPacket. Besides packet info storage, RawPacket also provides some other operations such as readInt() to ease the development process.

Author:
Werner Dittmann (Werner.Dittmann@t-online.de), Bing SU (nova.su@gmail.com)

Field Summary
protected  byte[] buffer
          Byte array storing the content of this Packet
protected  int length
          Length of this packet's data
protected  int offset
          Start offset of the packet data inside buffer.
 
Constructor Summary
RawPacket(byte[] buffer, int offset, int length)
          Construct a RawPacket using specified value.
 
Method Summary
 void append(byte[] data, int len)
          Append a byte array to then end of the packet.
 byte[] getBuffer()
          Get buffer containing the content of this packet
 int getLength()
          Get the length of this packet's data
 int getOffset()
          Get the start offset of this packet's data inside storing buffer
 byte readByte(int off)
          Read a byte from this packet at specified offset
 int readInt(int off)
          Read a integer from this packet at specified offset
 byte[] readRegion(int off, int len)
          Read a byte region from specified offset with specified length
 void readRegionToBuff(int off, int len, byte[] outBuff)
          Read a byte region from specified offset with specified length in given buffer
 short readShort(int off)
          Read a short from this packet at specified offset
 long readUnsignedIntAsLong(int off)
          Read an unsigned integer as long at specified offset
 int readUnsignedShortAsInt(int off)
          Read an unsigned short at specified offset as a int
 void shrink(int len)
          Shrink the buffer of this packet by specified length
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

buffer

protected byte[] buffer
Byte array storing the content of this Packet


offset

protected int offset
Start offset of the packet data inside buffer. Usually this value would be 0. But in order to be compatible with RTPManager we store this info. (Not assuming the offset is always zero)


length

protected int length
Length of this packet's data

Constructor Detail

RawPacket

public RawPacket(byte[] buffer,
                 int offset,
                 int length)
Construct a RawPacket using specified value.

Parameters:
buffer - Byte array holding the content of this Packet
offset - Start offset of packet content inside buffer
length - Length of the packet's data
Method Detail

getBuffer

public byte[] getBuffer()
Get buffer containing the content of this packet

Returns:
buffer containing the content of this packet

getLength

public int getLength()
Get the length of this packet's data

Returns:
length of this packet's data

getOffset

public int getOffset()
Get the start offset of this packet's data inside storing buffer

Returns:
start offset of this packet's data inside storing buffer

readInt

public int readInt(int off)
Read a integer from this packet at specified offset

Parameters:
off - start offset of the integer to be read
Returns:
the integer to be read

readShort

public short readShort(int off)
Read a short from this packet at specified offset

Parameters:
off - start offset of this short
Returns:
short value at offset

readUnsignedShortAsInt

public int readUnsignedShortAsInt(int off)
Read an unsigned short at specified offset as a int

Parameters:
off - start offset of the unsigned short
Returns:
the int value of the unsigned short at offset

readByte

public byte readByte(int off)
Read a byte from this packet at specified offset

Parameters:
off - start offset of the byte
Returns:
byte at offset

readUnsignedIntAsLong

public long readUnsignedIntAsLong(int off)
Read an unsigned integer as long at specified offset

Parameters:
off - start offset of this unsigned integer
Returns:
unsigned integer as long at offset

readRegion

public byte[] readRegion(int off,
                         int len)
Read a byte region from specified offset with specified length

Parameters:
off - start offset of the region to be read
len - length of the region to be read
Returns:
byte array of [offset, offset + length)

readRegionToBuff

public void readRegionToBuff(int off,
                             int len,
                             byte[] outBuff)
Read a byte region from specified offset with specified length in given buffer

Parameters:
off - start offset of the region to be read
len - length of the region to be read
outBuff - output buffer

append

public void append(byte[] data,
                   int len)
Append a byte array to then end of the packet. This will change the data buffer of this packet.

Parameters:
data - byte array to append
len - the number of bytes to append

shrink

public void shrink(int len)
Shrink the buffer of this packet by specified length

Parameters:
len - length to shrink

SIP Communicator: the OpenSource Java VoIP and Instant Messaging client.

SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
Distributable under LGPL license.