cnrg.itx.datax.devices
Class StreamSource

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

public class StreamSource
extends java.lang.Object
implements Source, java.lang.Runnable

Class implementing a stream source. This class will take any InputStream and synchronize it to make it a valid Source.


Field Summary
private  int bufferSize
          How many buffers should the transfer thread keep?
private  int bytesWritten
          Attribute for storing the number of bytes written by this source.
private  Channel channel
          Attribute for storing the Channel reference.
static int DEFAULT_BUFFER_TIME
          Default buffer time
private  int iDevice
          Attribute for storing the device ID.
private  java.io.InputStream inputStream
          Attribute to store the input stream represented by this source.
private static int instances
          Attribute for storing the device instance number.
private  boolean mute
          Mute state
private  int numBuffered
          How many samples are currently buffered?
static int SAMPLE_SIZE
          File sample size
private  boolean start
          Thread start/stop flags
private  long startTime
          Record of last call to System.currentTimeMillis()
private  Stats streamStats
          Attribute for storing the stream statistics.
private  java.lang.Thread thread
          Attribute to store the thread object.
private  long waitTime
          How long should the transfer thread wait between writes?
 
Constructor Summary
StreamSource(java.io.InputStream inputStream, Channel channel)
          Constructor to make a StreamSource from any input stream (no flow control)
StreamSource(java.io.InputStream inputStream, Channel channel, long bufferTime)
          Constructor to make a StreamSource from any input stream (flow control)
 
Method Summary
 void close()
          Method to close the input stream.
 PropertiesCollection getProperties()
          Returns a collection of properties supported.
 Stats getStatistics()
          Method to get the statistics of the input stream.
 boolean mute(boolean mute)
          Method to mute the input stream.
 void run()
          Method which acts as a thread and pushes data to the channel.
 void setPeerProperties(PropertiesCollection pc)
          Interface to set the given properties collection into the device.
 void setProperties(PropertiesCollection pc)
          Sets the given properties collection into the device
 void start()
          Method to start the source thread.
 void stop()
          Method to stop the thread.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

start

private boolean start
Thread start/stop flags

inputStream

private java.io.InputStream inputStream
Attribute to store the input stream represented by this source.

streamStats

private Stats streamStats
Attribute for storing the stream statistics.

channel

private Channel channel
Attribute for storing the Channel reference.

instances

private static int instances
Attribute for storing the device instance number. This is a static attribute and will be incremented in the constructor. This represents the total number of instances of the stream source.

iDevice

private int iDevice
Attribute for storing the device ID. This is the value of the instance at the moment.

bytesWritten

private int bytesWritten
Attribute for storing the number of bytes written by this source.

thread

private java.lang.Thread thread
Attribute to store the thread object.

waitTime

private long waitTime
How long should the transfer thread wait between writes?

bufferSize

private int bufferSize
How many buffers should the transfer thread keep?

numBuffered

private int numBuffered
How many samples are currently buffered?

startTime

private long startTime
Record of last call to System.currentTimeMillis()

mute

private boolean mute
Mute state

SAMPLE_SIZE

public static final int SAMPLE_SIZE
File sample size

DEFAULT_BUFFER_TIME

public static final int DEFAULT_BUFFER_TIME
Default buffer time
Constructor Detail

StreamSource

public StreamSource(java.io.InputStream inputStream,
                    Channel channel)
Constructor to make a StreamSource from any input stream (no flow control)
Parameters:
inputStream - The input Stream
channel - The audio channel

StreamSource

public StreamSource(java.io.InputStream inputStream,
                    Channel channel,
                    long bufferTime)
Constructor to make a StreamSource from any input stream (flow control)
Parameters:
inputStream - The input Stream
channel - The audio channel
bufferTime - The amount of data to keep buffered on the output stream in ms
Method Detail

close

public void close()
Method to close the input stream.
Specified by:
close in interface Source

mute

public boolean mute(boolean mute)
Method to mute the input stream. This method will either block or resume the stream according to the value passed to it.
Specified by:
mute in interface Source
Parameters:
mute - true to mute and false to resume the stream
Returns:
boolean The previous mute state

getStatistics

public Stats getStatistics()
Method to get the statistics of the input stream.
Returns:
Stats The statistics object

start

public void start()
Method to start the source thread.
Specified by:
start in interface Source

run

public void run()
Method which acts as a thread and pushes data to the channel.
Specified by:
run in interface java.lang.Runnable

stop

public void stop()
Method to stop the thread.

getProperties

public PropertiesCollection getProperties()
                                   throws DataException
Returns a collection of properties supported.

setProperties

public void setProperties(PropertiesCollection pc)
                   throws DataException
Sets the given properties collection into the device

setPeerProperties

public void setPeerProperties(PropertiesCollection pc)
                       throws DataException
Interface to set the given properties collection into the device. WOrks under the assumption that this is the properties collection of the peer.