Package org.jitsi.impl.neomedia.protocol
Class CachingPushBufferStream
- java.lang.Object
-
- org.jitsi.impl.neomedia.protocol.CachingPushBufferStream
-
- All Implemented Interfaces:
javax.media.Controls,javax.media.protocol.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
Fields Modifier and Type Field Description static longDEFAULT_BUFFER_LENGTHThe default length in milliseconds of the buffering to be performed by CachePushBufferStreams.
-
Constructor Summary
Constructors Constructor Description 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanendOfStream()ImplementsSourceStream.endOfStream().javax.media.protocol.ContentDescriptorgetContentDescriptor()ImplementsSourceStream.getContentDescriptor().longgetContentLength()ImplementsSourceStream.getContentLength().ObjectgetControl(String controlType)ImplementsControls.getControl(String).Object[]getControls()ImplementsControls.getControls().javax.media.FormatgetFormat()ImplementsPushBufferStream.getFormat().javax.media.protocol.PushBufferStreamgetStream()Gets the PushBufferStream wrapped by this instance.voidread(javax.media.Buffer buffer)ImplementsPushBufferStream.read(Buffer).voidsetTransferHandler(javax.media.protocol.BufferTransferHandler transferHandler)ImplementsPushBufferStream.setTransferHandler(BufferTransferHandler).protected voidtransferData(javax.media.protocol.BufferTransferHandler transferHandler)Reads data from the wrapped/input PushBufferStream into the cache of this stream if the cache accepts it.
-
-
-
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()
ImplementsSourceStream.endOfStream(). Delegates to the wrapped PushBufferStream when the cache of this instance is fully read; otherwise, returns false.- Specified by:
endOfStreamin interfacejavax.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()
ImplementsSourceStream.getContentDescriptor(). Delegates to the wrapped PushBufferStream.- Specified by:
getContentDescriptorin interfacejavax.media.protocol.SourceStream- Returns:
- a ContentDescriptor which describes the type of the content made available by the wrapped PushBufferStream
-
getContentLength
public long getContentLength()
ImplementsSourceStream.getContentLength(). Delegates to the wrapped PushBufferStream.- Specified by:
getContentLengthin interfacejavax.media.protocol.SourceStream- Returns:
- the length of the content made available by the wrapped PushBufferStream
-
getControl
public Object getControl(String controlType)
ImplementsControls.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:
getControlin interfacejavax.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()
ImplementsControls.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:
getControlsin interfacejavax.media.Controls- Returns:
- an array of Objects which represent the control available for the wrapped PushBufferStream
-
getFormat
public javax.media.Format getFormat()
ImplementsPushBufferStream.getFormat(). Delegates to the wrapped PushBufferStream.- Specified by:
getFormatin interfacejavax.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 IOExceptionImplementsPushBufferStream.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:
readin interfacejavax.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)
ImplementsPushBufferStream.setTransferHandler(BufferTransferHandler). Delegates to the wrapped PushBufferStream but wraps the specified BufferTransferHandler in order to intercept the calls toBufferTransferHandler.transferData(PushBufferStream)and read data from the wrapped PushBufferStream into the cache during the calls in question.- Specified by:
setTransferHandlerin interfacejavax.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
-
-