cnrg.itx.datax.devices
Class RTPHeader

java.lang.Object
  |
  +--cnrg.itx.datax.devices.RTPHeader

class RTPHeader
extends java.lang.Object

Class defining the RFC 1889 implementation of an RTP header. 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |V=2|P|X| CC |M| PT | sequence number | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | timestamp | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | synchronization source (SSRC) identifier | +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ | contributing source (CSRC) identifiers | | .... | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+


Field Summary
private  int[] csrc
          Contributing source identifiers.
static int G721_8000
           
private  int marker
          Marker bit.
private  int numCSources
          Number of contributing sources.
private  int packetExtension
          Packet header extension flag.
private  int padding
          Padding flag.
private  int payloadType
          Payload type.
static int PCMA_8000
           
static int PCMU_8000
          Constants defining some of the standard media formats for the RTP payload types.
private  short sequence
          Packet sequence number.
private  int ssrc
          Synchronization source.
private  int timeStamp
          Packet timestamp.
private  int version
          Attribute for the RTP packet version.
 
Constructor Summary
RTPHeader(byte[] rtpData)
          Constructor to extract the RTP header from a RTP byte array.
RTPHeader(int ssrc, int payloadType)
          Constructor for an RTP header taking the 32 bit source identifier and the payload type.
 
Method Summary
 void copyHeader(byte[] packet)
          Method to copy the RTP header into the byte array provided.
 int[] getCSRC()
          Accessor to get the list of contributing sources.
 int getExtension()
          Accessor to get the packet extension.
 int getHeaderSize()
          Accessor for the current size of the header in bytes.
private  int getInt(byte[] packet, int pos)
          Method to get an integer(32 bit) value from a position in a byte array.
 int getMarker()
          Accessor to get the packet marker.
 int getPadding()
          Accessor for the current state of padding.
 int getPayLoadType()
          Accessor for the current payloadtype.
 int getSequence()
          Accessor to get the packet sequence number.
private  short getShort(byte[] packet, int pos)
          Method to get a short(16 bit) value from a position in a byte array.
 int getSSRC()
          Accessor to get the current synchronization source.
 int getTimeStamp()
          Accessor to get the current timestamp of the packet.
 int getVersion()
          Accessor to get the version of the RTP header.
private  void setInt(byte[] packet, int pos, int value)
          Method to put an integer(32 bits) value in the header.
 void setSequence(short sequence)
          Mutator to set the sequence number of the packet.
private  void setShort(byte[] packet, int pos, short value)
          Method to set a short(16 bit) value in a byte array.
 void setTimeStamp(int timeStamp)
          Mutator to set the packet timestamp.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

PCMU_8000

public static final int PCMU_8000
Constants defining some of the standard media formats for the RTP payload types. Not all have been implemented but the complete list is as follows: Payload encoding audio/video clock rate channels Type name (A/V) (Hz) (audio) _______________________________________________________________ 0 PCMU A 8000 1 [RFC1890] 1 1016 A 8000 1 [RFC1890] 2 G721 A 8000 1 [RFC1890] 3 GSM A 8000 1 [RFC1890] 4 G723 A 8000 1 [Kumar] 5 DVI4 A 8000 1 [RFC1890] 6 DVI4 A 16000 1 [RFC1890] 7 LPC A 8000 1 [RFC1890] 8 PCMA A 8000 1 [RFC1890] 9 G722 A 8000 1 [RFC1890] 10 L16 A 44100 2 [RFC1890] 11 L16 A 44100 1 [RFC1890] 12 reserved A 13 reserved A 14 MPA A 90000 ?[RFC1890,2250] 15 G728 A 8000 1 [RFC1890] 16 DVI4 A 11025 1 [DiPol] 17 DVI4 A 22050 1 [DiPol] 18--22 unassigned A 23 reserved A 24 reserved V 25 CelB V 90000 [RFC2029] 26 JPEG V 90000 [RFC2435] 27 reserved V 28 nv V 90000 [RFC1890] 29 reserved V 30 reserved V 31 H261 V 90000 [RFC2032] 32 MPV V 90000 [RFC2250] 33 MP2T AV 90000 [RFC2250] 34 H263 V 90000 [Zhu] 35--71 unassigned ? 72--76 reserved for RTCP conflict avoidance [RFC1889] 77--95 unassigned ? 96--127 dynamic ? [RFC1890] The constants should be defined as given below for some of the payload types.

G721_8000

public static final int G721_8000

PCMA_8000

public static final int PCMA_8000

version

private int version
Attribute for the RTP packet version.

padding

private int padding
Padding flag.

packetExtension

private int packetExtension
Packet header extension flag.

numCSources

private int numCSources
Number of contributing sources.

marker

private int marker
Marker bit.

payloadType

private int payloadType
Payload type.

sequence

private short sequence
Packet sequence number.

timeStamp

private int timeStamp
Packet timestamp.

ssrc

private int ssrc
Synchronization source.

csrc

private int[] csrc
Contributing source identifiers.
Constructor Detail

RTPHeader

public RTPHeader(int ssrc,
                 int payloadType)
Constructor for an RTP header taking the 32 bit source identifier and the payload type.
Parameters:
ssrc - the 32 bit source ID
payloadType - the kind of real time data contained in the packet

RTPHeader

public RTPHeader(byte[] rtpData)
Constructor to extract the RTP header from a RTP byte array.
Parameters:
rtpData - the byte array of RTP data
Method Detail

copyHeader

public void copyHeader(byte[] packet)
Method to copy the RTP header into the byte array provided.
Parameters:
packet - the byte array to copy the header into

getHeaderSize

public int getHeaderSize()
Accessor for the current size of the header in bytes. The size depends on the version and the amount of csrc identifiers.
Returns:
int the size of the header in bytes

getVersion

public int getVersion()
Accessor to get the version of the RTP header.
Returns:
int the version for the RTP header

getPadding

public int getPadding()
Accessor for the current state of padding.
Returns:
int the current state of the padding

getExtension

public int getExtension()
Accessor to get the packet extension. This is the current state of extension. If the extension bit is set, the fixed header is followed by exactly one header extension as defined rfc 1889 Section 5.3.1.
Returns:
int the value of the the extension bit

getMarker

public int getMarker()
Accessor to get the packet marker. This is the current state of marker. The meaning of this bit should be interpreted by the protocol. Could for example mean silence will follow.
Returns:
int the state of the packet marker

getSequence

public int getSequence()
Accessor to get the packet sequence number. This is used to detect gaps in the packets.
Returns:
int the sequence number of the packet.

setSequence

public void setSequence(short sequence)
Mutator to set the sequence number of the packet.
Parameters:
sequence - the packet sequence number

getTimeStamp

public int getTimeStamp()
Accessor to get the current timestamp of the packet. This is used to know which rtp packets belong together. Mainly used for video where multiple packets can have the same timestamp.
Returns:
int the value of the packet timestamp

setTimeStamp

public void setTimeStamp(int timeStamp)
Mutator to set the packet timestamp.
Parameters:
timeStamp - the timestamp of the packet

getCSRC

public int[] getCSRC()
Accessor to get the list of contributing sources. The rtp packet can contain between 0 and 15 sources including the zero and fifteen.
Returns:
int[] the array of source IDs

getSSRC

public int getSSRC()
Accessor to get the current synchronization source. This should be an unique identifier as we could listen to multiple sources.
Returns:
int the synchronization source number

getPayLoadType

public int getPayLoadType()
Accessor for the current payloadtype. This is essentially the current encoding used. For a defined list see RFC1890, page 14.
Returns:
int the current payload type

setInt

private void setInt(byte[] packet,
                    int pos,
                    int value)
Method to put an integer(32 bits) value in the header.
Parameters:
packet - the byte array to put the value in
pos - the position at which the bytes need to be put
value - the integer value to be put

getInt

private int getInt(byte[] packet,
                   int pos)
Method to get an integer(32 bit) value from a position in a byte array.
Parameters:
packet - the byte array to get the value from
pos - the position from which to get the 32 bit value

setShort

private void setShort(byte[] packet,
                      int pos,
                      short value)
Method to set a short(16 bit) value in a byte array.
Parameters:
packet - the byte array to put the value in
pos - the position at which the bytes need to be put
value - the short value to be put

getShort

private short getShort(byte[] packet,
                       int pos)
Method to get a short(16 bit) value from a position in a byte array.
Parameters:
packet - the byte array to get the value from
pos - the position from which to get the 16 bit value