Jitsi: the OpenSource Java VoIP and Instant Messaging client.

net.java.sip.communicator.impl.neomedia.conference
Class AudioMixerPushBufferStream

java.lang.Object
  extended by net.java.sip.communicator.impl.neomedia.control.AbstractControls
      extended by net.java.sip.communicator.impl.neomedia.control.ControlsAdapter
          extended by net.java.sip.communicator.impl.neomedia.conference.AudioMixerPushBufferStream
All Implemented Interfaces:
javax.media.Controls, javax.media.protocol.PushBufferStream, javax.media.protocol.SourceStream

 class AudioMixerPushBufferStream
extends ControlsAdapter
implements javax.media.protocol.PushBufferStream

Represents a PushBufferStream which reads data from the SourceStreams of the input DataSources of the associated AudioMixer and pushes it to AudioMixingPushBufferStreams for audio mixing.

Pretty much private to AudioMixer but extracted into its own file for the sake of clarity.

Author:
Lyubomir Marinov

Field Summary
 
Fields inherited from class net.java.sip.communicator.impl.neomedia.control.ControlsAdapter
EMPTY_CONTROLS
 
Fields inherited from interface javax.media.protocol.SourceStream
LENGTH_UNKNOWN
 
Constructor Summary
AudioMixerPushBufferStream(AudioMixer audioMixer, javax.media.format.AudioFormat outputFormat)
          Initializes a new AudioMixerPushBufferStream instance to output data in a specific AudioFormat for a specific AudioMixer.
 
Method Summary
(package private)  void addOutputStream(AudioMixingPushBufferStream outputStream)
          Adds a specific AudioMixingPushBufferStream to the collection of such streams to which this instance is to push the data for audio mixing it reads from its input SourceStreams.
 int[] allocateIntArray(int minSize)
           
 void deallocateIntArray(int[] intArray)
           
 boolean endOfStream()
          Implements SourceStream.endOfStream().
(package private)  void equalizeInputStreamBufferLength()
          Attempts to equalize the length in milliseconds of the buffering performed by the inputStreams in order to always read and mix one and the same length in milliseconds.
 javax.media.protocol.ContentDescriptor getContentDescriptor()
          Implements SourceStream.getContentDescriptor().
 long getContentLength()
          Implements SourceStream.getContentLength().
 javax.media.format.AudioFormat getFormat()
          Implements PushBufferStream.getFormat().
(package private)  InputStreamDesc[] getInputStreams()
          Gets the SourceStreams (in the form of InputStreamDescs) from which this instance reads audio samples.
 void read(javax.media.Buffer buffer)
          Implements PushBufferStream.read(Buffer).
(package private)  void removeOutputStream(AudioMixingPushBufferStream outputStream)
          Removes a specific AudioMixingPushBufferStream from the collection of such streams to which this instance pushes the data for audio mixing it reads from its input SourceStreams.
(package private)  void setInputStreams(Collection<InputStreamDesc> inputStreams)
          Sets the SourceStreams (in the form of InputStreamDesc) from which this instance is to read audio samples and push them to the AudioMixingPushBufferStreams for audio mixing.
 void setTransferHandler(javax.media.protocol.BufferTransferHandler transferHandler)
          Implements PushBufferStream.setTransferHandler(BufferTransferHandler).
protected  void transferData(javax.media.Buffer buffer)
          Reads audio samples from the input SourceStreams of this instance and pushes them to its output AudioMixingPushBufferStreams for audio mixing.
 
Methods inherited from class net.java.sip.communicator.impl.neomedia.control.ControlsAdapter
getControls
 
Methods inherited from class net.java.sip.communicator.impl.neomedia.control.AbstractControls
getControl, getControl
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.media.Controls
getControl, getControls
 

Constructor Detail

AudioMixerPushBufferStream

public AudioMixerPushBufferStream(AudioMixer audioMixer,
                                  javax.media.format.AudioFormat outputFormat)
Initializes a new AudioMixerPushBufferStream instance to output data in a specific AudioFormat for a specific AudioMixer.

Parameters:
audioMixer - the AudioMixer which creates this instance and for which it is to output data
outputFormat - the AudioFormat in which the new instance is to output data
Method Detail

addOutputStream

void addOutputStream(AudioMixingPushBufferStream outputStream)
               throws IOException
Adds a specific AudioMixingPushBufferStream to the collection of such streams to which this instance is to push the data for audio mixing it reads from its input SourceStreams.

Parameters:
outputStream - the AudioMixingPushBufferStream to add to the collection of such streams to which this instance is to push the data for audio mixing it reads from its input SourceStreams
Throws:
IOException - if outputStream was the first AudioMixingPushBufferStream and the AudioMixer failed to start

allocateIntArray

public int[] allocateIntArray(int minSize)

deallocateIntArray

public void deallocateIntArray(int[] intArray)

endOfStream

public boolean endOfStream()
Implements SourceStream.endOfStream(). Delegates to the input SourceStreams of this instance.

Specified by:
endOfStream in interface javax.media.protocol.SourceStream
Returns:
true if all input SourceStreams of this instance have reached the end of their content; false, otherwise

equalizeInputStreamBufferLength

void equalizeInputStreamBufferLength()
Attempts to equalize the length in milliseconds of the buffering performed by the inputStreams in order to always read and mix one and the same length in milliseconds.


getContentDescriptor

public javax.media.protocol.ContentDescriptor getContentDescriptor()
Implements SourceStream.getContentDescriptor(). Returns a ContentDescriptor which describes the content type of this instance.

Specified by:
getContentDescriptor in interface javax.media.protocol.SourceStream
Returns:
a ContentDescriptor which describes the content type of this instance

getContentLength

public long getContentLength()
Implements SourceStream.getContentLength(). Delegates to the input SourceStreams of this instance.

Specified by:
getContentLength in interface javax.media.protocol.SourceStream
Returns:
the length of the content made available by this instance which is the maximum length of the contents made available by its input StreamSources

getFormat

public javax.media.format.AudioFormat getFormat()
Implements PushBufferStream.getFormat(). Returns the AudioFormat in which this instance was configured to output its data.

Specified by:
getFormat in interface javax.media.protocol.PushBufferStream
Returns:
the AudioFormat in which this instance was configured to output its data

getInputStreams

InputStreamDesc[] getInputStreams()
Gets the SourceStreams (in the form of InputStreamDescs) from which this instance reads audio samples.

Returns:
an array of InputStreamDescs which describe the input SourceStreams from which this instance reads audio samples

read

public void read(javax.media.Buffer buffer)
          throws IOException
Implements PushBufferStream.read(Buffer). Reads audio samples from the input SourceStreams of this instance in various formats, converts the read audio samples to one and the same format and pushes them to the output AudioMixingPushBufferStreams for the very audio mixing.

Specified by:
read in interface javax.media.protocol.PushBufferStream
Parameters:
buffer - the Buffer in which the audio samples read from the input SourceStreams are to be returned to the caller
Throws:
IOException - if any of the input SourceStreams throws such an exception while reading from them or anything else goes wrong

removeOutputStream

void removeOutputStream(AudioMixingPushBufferStream outputStream)
                  throws IOException
Removes a specific AudioMixingPushBufferStream from the collection of such streams to which this instance pushes the data for audio mixing it reads from its input SourceStreams.

Parameters:
outputStream - the AudioMixingPushBufferStream to remove from the collection of such streams to which this instance pushes the data for audio mixing it reads from its input SourceStreams
Throws:
IOException - if outputStream was the last AudioMixingPushBufferStream and the AudioMixer failed to stop

setInputStreams

void setInputStreams(Collection<InputStreamDesc> inputStreams)
Sets the SourceStreams (in the form of InputStreamDesc) from which this instance is to read audio samples and push them to the AudioMixingPushBufferStreams for audio mixing.

Parameters:
inputStreams - the SourceStreams (in the form of InputStreamDesc) from which this instance is to read audio samples and push them to the AudioMixingPushBufferStreams for audio mixing

setTransferHandler

public void setTransferHandler(javax.media.protocol.BufferTransferHandler transferHandler)
Implements PushBufferStream.setTransferHandler(BufferTransferHandler). Because this instance pushes data to multiple output AudioMixingPushBufferStreams, a single BufferTransferHandler is not sufficient and thus this method is unsupported and throws UnsupportedOperationException.

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

transferData

protected void transferData(javax.media.Buffer buffer)
Reads audio samples from the input SourceStreams of this instance and pushes them to its output AudioMixingPushBufferStreams for audio mixing.

Parameters:
buffer - the cached Buffer instance to be used during the execution of the method in order to reduce garbage collection. The length of the buffer will be reset to 0 before and after the execution of the method.

Jitsi: the OpenSource Java VoIP and Instant Messaging client.

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