Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## cnrg.itx.datax.devices
Class BufferQueue

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

public class BufferQueue
extends java.lang.Object
implements Statistics

This class will implement a buffered queue for reordering incoming RTP Packetes. The class will allow packets to be removed in a blocking read which waits until "packet boundries" until serving out the data.

RTP packets are put into the queue via the `put()<\code> method. It will check to see whether we already have the sample's data (via a FEC packet). If so, we don't need to do anything. Otherwise, we should depack the packet and add it into the queue in the proper order. We should fill in any preceeding sample "holes" -- places where we should have received a packet but didn't -- with silence samples. If we later find this packet, the silence sample should be replaced with the real data. Finally, the put method should check whether the queue is growing too large (which indicates that data isn't being read) and "clean" out old samples by deleting them.`

Data samples are removed from the queue via the get method. The get method will block until a packet boundary, and then return a sample. The sample will either be the "correct" sample for that time period, or a silence sample if the correct sample is not available (and FEC could not fill in the missing information. For smooth playback, `get()` should be called in succession with minimal processing.

Field Summary
`private FECBuffer` | `fecBuffer` Attribute for storing a FECBuffer object
`(package private) static int` | `HALF_SEQUENCE_SPACE`
`private int` | `iBufferLatency` Amount of latency to build into the buffer.
`private int` | `iDeltaTime` The difference between our time and the other time in milliseconds.
`private int` | `iLastPacket` The sequence number of the last sample that was read
`private int` | `iMyInstance` Instance number of the current buffer queue; used for stat output numbering.
`(package private) static int` | `INITIAL_BUFFER_LATENCY` The starting buffer size.
`(package private) static int` | `instances` Number of instances of the buffer queue; used for statistics output numbering.
`private int` | `iNullSamples` Number of null packets delivered.
`private int` | `iNumOldPacketsReceived` Number of samples removed (because too old).
`private int` | `iRemovedSamples` Number of samples removed (because too old).
`private int` | `iReordered` Number of samples inserted that had to be reordered
`private int` | `iSampleTime` The amount of TIME in millisecodns that each sample represents.
`private int` | `iSize` The current size of the queue (number of samples)
`(package private) static int` | `SEQUENCE_SPACE` one half of the sequence number space.
`private SampleNode` | `snHead` Head of the queue
`private SampleNode` | `snTail` Tail of the queue

Constructor Summary
`BufferQueue(int iSampleTime, int iSampleSize, int iLastPacket)` Constructor for the BufferQueue.

Method Summary
`private void` | `addToQueue(byte[] sample, int iRTPSequence, long lTimeStamp)` Adds a buffer to the queue.
`void` | `dump(java.io.OutputStream os)`
`byte[]` | `get()` Gets the next sample from the queue.
`Stats` | `getStatistics()`
`private boolean` | `isOlder(int iA, int iB)` Returns whether sequence iB is older than or equal to iA.
`private SampleNode` | `needToAdd(int iSequenceNumber)` Checks if a particular sample should be put into the queue.
`void` | `put(RTPPacket rtp)` Puts a buffer into the queue.

Methods inherited from class java.lang.Object
`, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait`

Field Detail

### iLastPacket

    private int iLastPacket

  The sequence number of the last sample that was read

### iDeltaTime

    private int iDeltaTime

  The difference between our time and the other time in milliseconds.

  DELTA is calculated by taking the other guy's time - our time

### iBufferLatency

    private int iBufferLatency

  Amount of latency to build into the buffer.

### iSampleTime

    private int iSampleTime

  The amount of TIME in millisecodns that each sample represents.

### iSize

    private int iSize

  The current size of the queue (number of samples)

### snHead

    private SampleNode snHead

  Head of the queue

### snTail

    private SampleNode snTail

  Tail of the queue

### fecBuffer

    private FECBuffer fecBuffer

  Attribute for storing a FECBuffer object

### INITIAL_BUFFER_LATENCY

    static final int INITIAL_BUFFER_LATENCY

  The starting buffer size.

### SEQUENCE_SPACE

    static final int SEQUENCE_SPACE

  one half of the sequence number space.

### HALF_SEQUENCE_SPACE

    static final int HALF_SEQUENCE_SPACE

### instances

    static int instances

  Number of instances of the buffer queue; used for statistics output numbering.

### iMyInstance

    private int iMyInstance

  Instance number of the current buffer queue; used for stat output numbering.

### iNullSamples

    private int iNullSamples

  Number of null packets delivered.

### iRemovedSamples

    private int iRemovedSamples

  Number of samples removed (because too old).

### iNumOldPacketsReceived

    private int iNumOldPacketsReceived

  Number of samples removed (because too old).

### iReordered

    private int iReordered

  Number of samples inserted that had to be reordered

Constructor Detail

### BufferQueue

    public BufferQueue(int iSampleTime,
                       int iSampleSize,
                       int iLastPacket)

  Constructor for the BufferQueue.
  Parameters:
    `iSampleTime` - the reference sample time for the buffer queue

Method Detail

### isOlder

    private boolean isOlder(int iA,
                            int iB)

  Returns whether sequence iB is older than or equal to iA. This method takes care of the fact that sequence numbers can wrap around and then a smaller sequence number can be newer than a larger sequence number.
  Parameters:
    `iA` - the first sequence number
    `iB` - the second sequence number

### needToAdd

    private SampleNode needToAdd(int iSequenceNumber)

  Checks if a particular sample should be put into the queue.
  Parameters:
    `iSequenceNumber` - the sequence number of the packet to check
  Returns:
    SampleNode returns a null if the node shouldn't be added or else it returns the location where to insert it

### addToQueue

    private void addToQueue(byte[] sample,
                            int iRTPSequence,
                            long lTimeStamp)

  Adds a buffer to the queue.
  Parameters:
    `sample` - byte array of the actual data
    `iRTPSequence` - sequence number of the sample
    `lTimeStamp` - time stamp that the sample was generated.

### put

    public void put(RTPPacket rtp)

  Puts a buffer into the queue. Forward error correction is performed on the buffer and then it is put in the queue.
  Parameters:
    `rtp` - the RTPPacket to be inserted into the queue

### get

    public byte[] get()

  Gets the next sample from the queue. Blocks until a time boundary unless we are "behind". returns null for silence;

### getStatistics

    public Stats getStatistics()

  Specified by:
    getStatistics in interface Statistics

### dump

    public void dump(java.io.OutputStream os)

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD