jlibrtp
Class PktBuffer

java.lang.Object
  extended by jlibrtp.PktBuffer

public class PktBuffer
extends java.lang.Object

A PktBuffer stores packets either for buffering purposes, or because they need to be assimilated to create a complete frame. This behavior can be controlled through rtpSession.pktBufBehavior() It optionally drops duplicate packets. Note that newest is the most recently received, i.e. highest timeStamp Next means new to old (from recently received to previously received)

Author:
Arne Kepp

Field Summary
(package private)  int lastSeqNumber
          The last sequence number received
(package private)  long lastTimestamp
          The last timestamp
(package private)  int length
          The length of the buffer
(package private)  PktBufNode newest
          The newest, most recently received, packet
(package private)  PktBufNode oldest
          The oldest, least recently received, packet
(package private)  Participant p
          The parent participant
(package private)  RTPSession rtpSession
          The RTPSession holds information common to all packetBuffers, such as max size
(package private)  long SSRC
          SSRC of the the participant that this buffer is for
 
Constructor Summary
protected PktBuffer(RTPSession rtpSession, Participant p, RtpPkt aPkt)
          Creates a new PktBuffer, a linked list of PktBufNode
 
Method Summary
protected  int addPkt(RtpPkt aPkt)
          Adds a packet, this happens in constant time if they arrive in order.
private  int addToFrame(PktBufNode frameNode, PktBufNode newNode)
           
private  int bufferedAddPkt(PktBufNode newNode)
          Does most of the packet organization for the application.
private  DataFrame bufferedPopFrame()
          Only returns if the buffer is full, i.e.
protected  void debugPrint()
          Prints out the packet buffer, oldest node first (on top).
private  int filteredAddPkt(PktBufNode newNode)
          Takes care of duplicate packets
protected  int getLength()
          Returns the length of the packetbuffer.
protected  boolean pktOnTime(long timeStamp, int seqNum)
          Checks whether a packet is not too late, i.e.
private  void popFrameQueueCleanup(PktBufNode retNode, int highestSeq)
          Cleans the packet buffer before returning the frame, i.e.
protected  DataFrame popOldestFrame()
          Checks the oldest frame, if there is one, sees whether it is complete.
private  DataFrame unbufferedPopFrame()
          Will return the oldest frame without checking whether it is in the right order, or whether we should wate for late arrivals.
private  int unfilteredAddPkt(PktBufNode newNode)
          Adds packets in the same order that they arrive, doesn't do any filering or processing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rtpSession

RTPSession rtpSession
The RTPSession holds information common to all packetBuffers, such as max size


SSRC

long SSRC
SSRC of the the participant that this buffer is for


p

Participant p
The parent participant


length

int length
The length of the buffer


oldest

PktBufNode oldest
The oldest, least recently received, packet


newest

PktBufNode newest
The newest, most recently received, packet


lastSeqNumber

int lastSeqNumber
The last sequence number received


lastTimestamp

long lastTimestamp
The last timestamp

Constructor Detail

PktBuffer

protected PktBuffer(RTPSession rtpSession,
                    Participant p,
                    RtpPkt aPkt)
Creates a new PktBuffer, a linked list of PktBufNode

Parameters:
rtpSession - the parent RTPSession
p - the participant to which this packetbuffer belongs.
aPkt - The first RTP packet, to be added to the buffer
Method Detail

addPkt

protected int addPkt(RtpPkt aPkt)
Adds a packet, this happens in constant time if they arrive in order. Optimized for the case where each pkt is a complete frame.

Parameters:
aPkt - the packet to be added to the buffer.
Returns:
integer, negative if operation failed (see code)

unfilteredAddPkt

private int unfilteredAddPkt(PktBufNode newNode)
Adds packets in the same order that they arrive, doesn't do any filering or processing.

Parameters:
newNode - the node to add to the packet buffer
Returns:
0 if everything is okay, -1 otherwise

filteredAddPkt

private int filteredAddPkt(PktBufNode newNode)
Takes care of duplicate packets

Parameters:
newNode - the node to add to the packet buffer
Returns:
0 if everything is okay, -1 otherwise

bufferedAddPkt

private int bufferedAddPkt(PktBufNode newNode)
Does most of the packet organization for the application. Packets are put in order, duplicate packets or late arrivals are discarded If multiple packets make up a frame, these will also be organized by RTP timestamp and sequence number, and returned as a complete frame.

Parameters:
newNode - the node to add to the packet buffer
Returns:
0 if everything is okay, -1 otherwise

addToFrame

private int addToFrame(PktBufNode frameNode,
                       PktBufNode newNode)
Parameters:
frameNode - the node currently representing the frame in the packet buffer
newNode - the new node to be added to the frame
Returns:
0 if no error, -2 if this is a duplicate packet

popOldestFrame

protected DataFrame popOldestFrame()
Checks the oldest frame, if there is one, sees whether it is complete.

Returns:
Returns null if there are no complete frames available.

unbufferedPopFrame

private DataFrame unbufferedPopFrame()
Will return the oldest frame without checking whether it is in the right order, or whether we should wate for late arrivals.

Returns:
the first frame on the queue, null otherwise

bufferedPopFrame

private DataFrame bufferedPopFrame()
Only returns if the buffer is full, i.e. length exceeds rtpSession.pktBufBehavior, or if the next packet directly follows the previous one returned to the application.

Returns:
first frame in order, null otherwise

popFrameQueueCleanup

private void popFrameQueueCleanup(PktBufNode retNode,
                                  int highestSeq)
Cleans the packet buffer before returning the frame, i.e. making sure the queue has a head etc.

Parameters:
retNode - the node that is about to be popped
highestSeq - the highest sequence number returned to the application

getLength

protected int getLength()
Returns the length of the packetbuffer.

Returns:
number of frames (complete or not) in packetbuffer.

pktOnTime

protected boolean pktOnTime(long timeStamp,
                            int seqNum)
Checks whether a packet is not too late, i.e. the next packet has already been returned.

Parameters:
timeStamp - the RTP timestamp of the packet under consideration
seqNum - the sequence number of the packet under consideration
Returns:
true if newer packets have not been handed to the application

debugPrint

protected void debugPrint()
Prints out the packet buffer, oldest node first (on top).