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

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

java.lang.Object
  extended by net.java.sip.communicator.impl.neomedia.RawPacket
Direct Known Subclasses:
DtmfRawPacket, 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), Emil Ivov, Damian Minkov

Field Summary
static int EXT_HEADER_SIZE
          The size of the extension header as defined by RFC 3550.
static int FIXED_HEADER_SIZE
          The size of the fixed part of the RTP header as defined by RFC 3550.
 
Constructor Summary
RawPacket()
          Construct an empty RawPacket
RawPacket(byte[] buffer, int offset, int length)
          Construct a RawPacket using specified value.
 
Method Summary
 void addExtension(byte[] extBuff, int newExtensionLen)
          Adds the extBuff buffer to as an extension of this packet according the rules specified in RFC 5285.
 void append(byte[] data, int len)
          Append a byte array to the end of the packet.
 long[][] extractCsrcLevels(byte csrcExtID)
          Returns a bi-dimensional byte array containing a map binding CSRC IDs to audio levels as reported by the remote party that sent this packet.
 long[] extractCsrcList()
          Returns the list of CSRC IDs, currently encapsulated in this packet.
 byte[] getBuffer()
          Get buffer containing the content of this packet
 int getCsrcCount()
          Returns the number of CSRC identifiers currently included in this packet.
 boolean getExtensionBit()
          Returns true if the extension bit of this packet has been set and false otherwise.
 int getExtensionLength()
          Returns the length of the extensions currently added to this packet.
 int getHeaderExtensionType()
          Return the define by profile part of the extension header.
 int getHeaderLength()
          Get RTP header length from a RTP 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
 int getPaddingSize()
          Get RTP padding size from a RTP packet
 byte[] getPayload()
          Get the RTP payload (bytes) of this RTP packet.
 int getPayloadLength()
          Get RTP payload length from a RTP packet
 byte getPayloadType()
          Get RTP payload type from a RTP packet
 int getSequenceNumber()
          Get RTP sequence number from a RTP packet
 int getSSRC()
          Get RTP SSRC from a RTP packet
 long getTimestamp()
          Returns the timestamp for this RTP RawPacket.
 boolean isPacketMarked()
          Test whether if a RTP packet is padded
 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
 byte[] readTimeStampIntoByteArray()
          Get RTP timestamp from a RTP packet
 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 removeExtension()
          Removes the extension from the packet and its header.
protected  void setBuffer(byte[] buffer)
           
 void setCsrcList(long[] newCsrcList)
          Replaces the existing CSRC list (even if empty) with newCsrcList and updates the CC (CSRC count) field of this RawPacket accordingly.
protected  void setLength(int length)
           
 void setMarker(boolean marker)
          Sets or resets the marker bit of this packet according to the marker parameter.
protected  void setOffset(int offset)
           
 void setPayload(byte payload)
          Sets the payload of this packet.
 void setTimestamp(long timestamp)
          Set the timestamp value of the RTP Packet
 void shrink(int len)
          Shrink the buffer of this packet by specified length
 void writeByte(int off, byte b)
          Write a byte to this packet at specified offset
 void writeInt(int off, int data)
          Set an integer at specified offset in network order.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FIXED_HEADER_SIZE

public static final int FIXED_HEADER_SIZE
The size of the fixed part of the RTP header as defined by RFC 3550.

See Also:
Constant Field Values

EXT_HEADER_SIZE

public static final int EXT_HEADER_SIZE
The size of the extension header as defined by RFC 3550.

See Also:
Constant Field Values
Constructor Detail

RawPacket

public RawPacket()
Construct an empty RawPacket


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

setBuffer

protected void setBuffer(byte[] buffer)
Parameters:
buffer - the buffer to set

setOffset

protected void setOffset(int offset)
Parameters:
offset - the offset to set

setLength

protected void setLength(int length)
Parameters:
length - the length to set

setMarker

public void setMarker(boolean marker)
Sets or resets the marker bit of this packet according to the marker parameter.

Parameters:
marker - true if we are to raise the marker bit and false otherwise.

setPayload

public void setPayload(byte payload)
Sets the payload of this packet.

Parameters:
payload - the RTP payload type describing the content of this packet.

getTimestamp

public long getTimestamp()
Returns the timestamp for this RTP RawPacket.

Returns:
the timestamp for this RTP RawPacket.

setTimestamp

public void setTimestamp(long timestamp)
Set the timestamp value of the RTP Packet

Parameters:
timestamp - : the RTP Timestamp

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

writeInt

public void writeInt(int off,
                     int data)
Set an integer at specified offset in network order.

Parameters:
off - Offset into the buffer
data - The integer to store in the packet

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

writeByte

public void writeByte(int off,
                      byte b)
Write a byte to this packet at specified offset

Parameters:
off - start offset of the byte
b - byte to write

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 the end of the packet. This may 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

getCsrcCount

public int getCsrcCount()
Returns the number of CSRC identifiers currently included in this packet.

Returns:
the CSRC count for this RawPacket.

setCsrcList

public void setCsrcList(long[] newCsrcList)
Replaces the existing CSRC list (even if empty) with newCsrcList and updates the CC (CSRC count) field of this RawPacket accordingly.

Parameters:
newCsrcList - the list of CSRC identifiers that we'd like to set for this RawPacket.

extractCsrcList

public long[] extractCsrcList()
Returns the list of CSRC IDs, currently encapsulated in this packet.

Returns:
an array containing the list of CSRC IDs, currently encapsulated in this packet.

getPaddingSize

public int getPaddingSize()
Get RTP padding size from a RTP packet

Returns:
RTP padding size from source RTP packet

getHeaderLength

public int getHeaderLength()
Get RTP header length from a RTP packet

Returns:
RTP header length from source RTP packet

getPayloadLength

public int getPayloadLength()
Get RTP payload length from a RTP packet

Returns:
RTP payload length from source RTP packet

getSSRC

public int getSSRC()
Get RTP SSRC from a RTP packet

Returns:
RTP SSRC from source RTP packet

getSequenceNumber

public int getSequenceNumber()
Get RTP sequence number from a RTP packet

Returns:
RTP sequence num from source packet

isPacketMarked

public boolean isPacketMarked()
Test whether if a RTP packet is padded

Returns:
whether if source RTP packet is padded

getPayloadType

public byte getPayloadType()
Get RTP payload type from a RTP packet

Returns:
RTP payload type of source RTP packet

getPayload

public byte[] getPayload()
Get the RTP payload (bytes) of this RTP packet.

Returns:
an array of bytes which represents the RTP payload of this RTP packet

readTimeStampIntoByteArray

public byte[] readTimeStampIntoByteArray()
Get RTP timestamp from a RTP packet

Returns:
RTP timestamp of source RTP packet

getExtensionBit

public boolean getExtensionBit()
Returns true if the extension bit of this packet has been set and false otherwise.

Returns:
true if the extension bit of this packet has been set and false otherwise.

getExtensionLength

public int getExtensionLength()
Returns the length of the extensions currently added to this packet.

Returns:
the length of the extensions currently added to this packet.

addExtension

public void addExtension(byte[] extBuff,
                         int newExtensionLen)
Adds the extBuff buffer to as an extension of this packet according the rules specified in RFC 5285. Note that this method does not replace extensions so if you add the same buffer twice it would be added as to separate extensions.

Parameters:
extBuff - the buffer that we'd like to add as an extension in this packet.
newExtensionLen - the length of the data in extBuff.

removeExtension

public void removeExtension()
Removes the extension from the packet and its header.


extractCsrcLevels

public long[][] extractCsrcLevels(byte csrcExtID)
Returns a bi-dimensional byte array containing a map binding CSRC IDs to audio levels as reported by the remote party that sent this packet.

Parameters:
csrcExtID - the ID of the extension that's transporting csrc audio levels in the session that this RawPacket belongs to.
Returns:
a bi-dimensional byte array containing a map binding CSRC IDs to audio levels as reported by the remote party that sent this packet.

getHeaderExtensionType

public int getHeaderExtensionType()
Return the define by profile part of the extension header.

Returns:
the starting two bytes of extension header.

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

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