Jitsi: the OpenSource Java VoIP and Instant Messaging client.

net.java.sip.communicator.impl.neomedia.protocol
Class CachingPushBufferStream

java.lang.Object
  extended by net.java.sip.communicator.impl.neomedia.protocol.CachingPushBufferStream
All Implemented Interfaces:
javax.media.Controls, javax.media.protocol.PushBufferStream, javax.media.protocol.SourceStream

public class CachingPushBufferStream
extends Object
implements javax.media.protocol.PushBufferStream

Enables reading from a PushBufferStream a certain maximum number of data units (e.g. bytes, shorts, ints) even if the PushBufferStream itself pushes a larger number of data units.

An example use of this functionality is pacing a PushBufferStream which pushes more data units in a single step than a CaptureDevice. When these two undergo audio mixing, the different numbers of per-push data units will cause the PushBufferStream "play" itself faster than the CaptureDevice.

Author:
Lyubomir Marinov

Field Summary
static long DEFAULT_BUFFER_LENGTH
          The default length in milliseconds of the buffering to be performed by CachePushBufferStreams.
 
Fields inherited from interface javax.media.protocol.SourceStream
LENGTH_UNKNOWN
 
Constructor Summary
CachingPushBufferStream(javax.media.protocol.PushBufferStream stream)
          Initializes a new CachingPushBufferStream instance which is to pace the number of per-push data units a specific PushBufferStream provides.
 
Method Summary
 boolean endOfStream()
          Implements SourceStream.endOfStream().
 javax.media.protocol.ContentDescriptor getContentDescriptor()
          Implements SourceStream.getContentDescriptor().
 long getContentLength()
          Implements SourceStream.getContentLength().
 Object getControl(String controlType)
          Implements Controls.getControl(String).
 Object[] getControls()
          Implements Controls.getControls().
 javax.media.Format getFormat()
          Implements PushBufferStream.getFormat().
 javax.media.protocol.PushBufferStream getStream()
          Gets the PushBufferStream wrapped by this instance.
 void read(javax.media.Buffer buffer)
          Implements PushBufferStream.read(Buffer).
 void setTransferHandler(javax.media.protocol.BufferTransferHandler transferHandler)
          Implements PushBufferStream.setTransferHandler(BufferTransferHandler).
protected  void transferData(javax.media.protocol.BufferTransferHandler transferHandler)
          Reads data from the wrapped/input PushBufferStream into the cache of this stream if the cache accepts it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_BUFFER_LENGTH

public static final long DEFAULT_BUFFER_LENGTH
The default length in milliseconds of the buffering to be performed by CachePushBufferStreams.

See Also:
Constant Field Values
Constructor Detail

CachingPushBufferStream

public CachingPushBufferStream(javax.media.protocol.PushBufferStream stream)
Initializes a new CachingPushBufferStream instance which is to pace the number of per-push data units a specific PushBufferStream provides.

Parameters:
stream - the PushBufferStream to be paced with respect to the number of per-push data units it provides
Method Detail

endOfStream

public boolean endOfStream()
Implements SourceStream.endOfStream(). Delegates to the wrapped PushBufferStream when the cache of this instance is fully read; otherwise, returns false.

Specified by:
endOfStream in interface javax.media.protocol.SourceStream
Returns:
true if this PushBufferStream has reached the end of the content it makes available; otherwise, false

getContentDescriptor

public javax.media.protocol.ContentDescriptor getContentDescriptor()
Implements SourceStream.getContentDescriptor(). Delegates to the wrapped PushBufferStream.

Specified by:
getContentDescriptor in interface javax.media.protocol.SourceStream
Returns:
a ContentDescriptor which describes the type of the content made available by the wrapped PushBufferStream

getContentLength

public long getContentLength()
Implements SourceStream.getContentLength(). Delegates to the wrapped PushBufferStream.

Specified by:
getContentLength in interface javax.media.protocol.SourceStream
Returns:
the length of the content made available by the wrapped PushBufferStream

getControl

public Object getControl(String controlType)
Implements Controls.getControl(String). Delegates to the wrapped PushBufferStream and gives access to the BufferControl of this instance if such a controlType is specified and the wrapped PushBufferStream does not have such a control available.

Specified by:
getControl in interface javax.media.Controls
Parameters:
controlType - a String value which names the type of the control of the wrapped PushBufferStream to be retrieved
Returns:
an Object which represents the control of the wrapped PushBufferStream with the specified type if such a control is available; otherwise, null

getControls

public Object[] getControls()
Implements Controls.getControls(). Delegates to the wrapped PushBufferStream and adds the BufferControl of this instance if the wrapped PushBufferStream does not have a control of such type available.

Specified by:
getControls in interface javax.media.Controls
Returns:
an array of Objects which represent the control available for the wrapped PushBufferStream

getFormat

public javax.media.Format getFormat()
Implements PushBufferStream.getFormat(). Delegates to the wrapped PushBufferStream.

Specified by:
getFormat in interface javax.media.protocol.PushBufferStream
Returns:
the Format of the media data available for reading in this PushBufferStream

getStream

public javax.media.protocol.PushBufferStream getStream()
Gets the PushBufferStream wrapped by this instance.

Returns:
the PushBufferStream wrapped by this instance

read

public void read(javax.media.Buffer buffer)
          throws IOException
Implements PushBufferStream.read(Buffer). If an IOException has been thrown by the wrapped stream when data was last read from it, re-throws it. If there has been no such exception, reads from the cache of this instance.

Specified by:
read in interface javax.media.protocol.PushBufferStream
Parameters:
buffer - the Buffer to receive the read media data
Throws:
IOException - if the wrapped stream has thrown such an exception when data was last read from it

setTransferHandler

public void setTransferHandler(javax.media.protocol.BufferTransferHandler transferHandler)
Implements PushBufferStream.setTransferHandler(BufferTransferHandler). Delegates to the wrapped PushBufferStream but wraps the specified BufferTransferHandler in order to intercept the calls to BufferTransferHandler.transferData(PushBufferStream) and read data from the wrapped PushBufferStream into the cache during the calls in question.

Specified by:
setTransferHandler in interface javax.media.protocol.PushBufferStream
Parameters:
transferHandler - the BufferTransferHandler to be notified by this PushBufferStream when media data is available for reading

transferData

protected void transferData(javax.media.protocol.BufferTransferHandler transferHandler)
Reads data from the wrapped/input PushBufferStream into the cache of this stream if the cache accepts it. If the cache does not accept a new read, blocks the calling thread until the cache accepts a new read and data is read from the wrapped PushBufferStream into the cache.

Parameters:
transferHandler - the BufferTransferHandler which has been notified

Jitsi: the OpenSource Java VoIP and Instant Messaging client.

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