jlibrtp
Class RtpPkt

java.lang.Object
  extended by jlibrtp.RtpPkt

public class RtpPkt
extends java.lang.Object

RtpPkt is the basic class for creating and parsing RTP packets. There are two ways of instantiating an RtpPkt. One is for packets that you wish to send, which requires that you provide basic information about the packet and a payload. Upon calling encode() the fields of the structure are written into a bytebuffer, in the form that it would sent across the network, excluding the UDP headers. The other way is by passing a bytebuffer. The assumption is that this is a packet that has been received from the network, excluding UDP headers, and the bytebuffer will be parsed into the correct fields. The class keeps track of changes. Therefore, modifications are possible after calling encode(), if necessary, the raw version of the packet will be regenerated on subsequent requests.

Author:
Arne Kepp

Field Summary
private  long[] csrcArray
          SSRCs of contributing sources, 32xn bits, n<16
private  int extension
          Whether and extension is used, 1 bit
private  int marker
          Whether the packet is marked, 1 bit
private  int padding
          Whether the packet is padded, 1 bit
private  byte[] payload
          The actual data, without any RTP stuff
private  int payloadType
          What payload type is used, 7 bits
private  byte[] rawPkt
          Contains the actual data (eventually)
private  boolean rawPktCurrent
          Whether the packet has been changed since encode()
private  int seqNumber
          The sequence number, taken from RTP Session, 16 bits
private  long ssrc
          The SSRC of the packet sender, 32 bits
private  long timeStamp
          The RTP timestamp, 32bits
private  int version
          The version, always 2, 2 bits
 
Constructor Summary
protected RtpPkt(byte[] aRawPkt, int packetSize)
          Construct a packet-instance from an raw packet (believed to be RTP).
protected RtpPkt(long aTimeStamp, long syncSource, int seqNum, int plt, byte[] pl)
          Construct a packet-instance.
 
Method Summary
protected  int checkPkt()
          Reading stuff
protected  byte[] encode()
          Encodes the a
protected  long[] getCsrcArray()
           
protected  int getCsrcCount()
           
protected  int getHeaderLength()
           
protected  byte[] getPayload()
           
protected  int getPayloadLength()
           
protected  int getPayloadType()
           
protected  int getSeqNumber()
           
protected  long getSsrc()
           
protected  long getTimeStamp()
           
protected  int getVersion()
           
protected  boolean isMarked()
           
protected  void printPkt()
           
protected  int setCsrcs(long[] contributors)
           
protected  void setMarked(boolean mark)
          Setting stuff
protected  int setPayload(byte[] data)
           
protected  int setPayloadType(int plType)
           
protected  int setSeqNumber(int number)
           
protected  int setSsrc(long source)
           
protected  int setTimeStamp(long time)
           
private  void sliceCSRCs()
           
private  void sliceFirstLine()
           
private  void slicePayload(int bytes)
           
private  void sliceSSRC()
           
private  void sliceTimeStamp()
           
private  void writeFirstLine()
           
private  void writePkt()
          Private functions
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rawPktCurrent

private boolean rawPktCurrent
Whether the packet has been changed since encode()


version

private int version
The version, always 2, 2 bits


padding

private int padding
Whether the packet is padded, 1 bit


extension

private int extension
Whether and extension is used, 1 bit


marker

private int marker
Whether the packet is marked, 1 bit


payloadType

private int payloadType
What payload type is used, 7 bits


seqNumber

private int seqNumber
The sequence number, taken from RTP Session, 16 bits


timeStamp

private long timeStamp
The RTP timestamp, 32bits


ssrc

private long ssrc
The SSRC of the packet sender, 32 bits


csrcArray

private long[] csrcArray
SSRCs of contributing sources, 32xn bits, n<16


rawPkt

private byte[] rawPkt
Contains the actual data (eventually)


payload

private byte[] payload
The actual data, without any RTP stuff

Constructor Detail

RtpPkt

protected RtpPkt(long aTimeStamp,
                 long syncSource,
                 int seqNum,
                 int plt,
                 byte[] pl)
Construct a packet-instance. The ByteBuffer required for UDP transmission can afterwards be obtained from getRawPkt(). If you need to set additional parameters, such as the marker bit or contributing sources, you should do so before calling getRawPkt;

Parameters:
aTimeStamp - RTP timestamp for data
syncSource - the SSRC, usually taken from RTPSession
seqNum - Sequency number
plt - Type of payload
pl - Payload, the actual data

RtpPkt

protected RtpPkt(byte[] aRawPkt,
                 int packetSize)
Construct a packet-instance from an raw packet (believed to be RTP). The UDP-headers must be removed before invoking this method. Call checkPkt on the instance to verify that it was successfully parsed.

Parameters:
aRawPkt - The data-part of a UDP-packet believed to be RTP
packetSize - the number of valid octets in the packet, should be aRawPkt.length
Method Detail

checkPkt

protected int checkPkt()
Reading stuff


getHeaderLength

protected int getHeaderLength()

getPayloadLength

protected int getPayloadLength()

getVersion

protected int getVersion()

isMarked

protected boolean isMarked()

getPayloadType

protected int getPayloadType()

getSeqNumber

protected int getSeqNumber()

getTimeStamp

protected long getTimeStamp()

getSsrc

protected long getSsrc()

getCsrcCount

protected int getCsrcCount()

getCsrcArray

protected long[] getCsrcArray()

encode

protected byte[] encode()
Encodes the a


printPkt

protected void printPkt()

setMarked

protected void setMarked(boolean mark)
Setting stuff


setPayloadType

protected int setPayloadType(int plType)

setSeqNumber

protected int setSeqNumber(int number)

setTimeStamp

protected int setTimeStamp(long time)

setSsrc

protected int setSsrc(long source)

setCsrcs

protected int setCsrcs(long[] contributors)

setPayload

protected int setPayload(byte[] data)

getPayload

protected byte[] getPayload()

writePkt

private void writePkt()
Private functions


writeFirstLine

private void writeFirstLine()

sliceFirstLine

private void sliceFirstLine()

sliceTimeStamp

private void sliceTimeStamp()

sliceSSRC

private void sliceSSRC()

sliceCSRCs

private void sliceCSRCs()

slicePayload

private void slicePayload(int bytes)