com.cloudgarden.audio
Class AudioServerSource

java.lang.Object
  |
  +--java.rmi.server.RemoteObject
        |
        +--java.rmi.server.RemoteServer
              |
              +--java.rmi.server.UnicastRemoteObject
                    |
                    +--com.cloudgarden.audio.AudioServer
                          |
                          +--com.cloudgarden.audio.AudioServerSource
All Implemented Interfaces:
AudioInputServerI, AudioObject, AudioServerI, AudioSource, java.rmi.Remote, java.io.Serializable

public class AudioServerSource
extends AudioServer
implements AudioInputServerI, AudioSource

This class receives audio input from a remote (client) machine. The port it uses, it's remote name and (optionally) the IP address of the client permitted to send the audio data, are specified in the constructor.

See Also:
Serialized Form

Field Summary
protected  boolean paused
           
protected  boolean waiting
           
 
Fields inherited from class com.cloudgarden.audio.AudioServer
clientAddress, clientListeners, clients, closed, contentType, format, listeners, open, port, registry, remoteName
 
Fields inherited from class java.rmi.server.RemoteObject
ref
 
Fields inherited from interface com.cloudgarden.audio.AudioObject
END_OF_DATA
 
Constructor Summary
AudioServerSource(java.lang.String remoteName, java.net.InetAddress clientAddress, int port)
          Creates, initializes and binds an AudioInputSocket to the given remoteName in the local registry.
 
Method Summary
 int acceptBytes(byte[] bytes, int offset, int len)
          An RMI method called by the remote client to send data to this class.
 boolean canSetAudioFormat()
          Returns false if the AudioFormat cannot be set - eg some Recognizers may not be able to change their input format, so the CGAudioManager (which is an AudioSink) for that Recognizer will return false here.
 void drain()
          Blocks until END_OF_DATA is written to or read from this AudioObject.
 AudioSink getSink()
          Returns the AudioSink set using setSink
 boolean isPaused()
           
 boolean isSending()
          Returns true if the thread started by the startSending method is still writing data to the AudioSink.
 boolean isWaiting()
          Returns true if no data has yet been written or read from this AudioObject
 int read(byte[] data, int len)
          Convenience method - should call read(data, 0, len)
 int read(byte[] data, int offset, int len)
          Used to read data from this source - called by the AudioSink which this source is connected to (if its startGetting method is used) so need not be called explicitly by an application.
 void setAudioFormat(javax.sound.sampled.AudioFormat format)
          Sets the AudioFormat for this AudioObject.
 void setBufferSize(int size)
          Sets the buffer size of the internal AudioPipe
 void setContentType(java.lang.String contentType)
          Sets the content type for this AudioObject - contentType must be one of the FileTypeDescriptor String fields, eg MPEG_AUDIO.
 void setPaused(boolean paused)
          If paused is true, writing or reading data to or from this AudioObject will block until setPaused(false) is called.
 void setSink(AudioSink sink)
          Sets the sink for this source - this method should also call the setSource method on the sink object (making sure to avaoid an endless loop) to ensure that source and sink are connected to each other (and not to different sinks/sources).
 void startSending()
          This method should start a thread which repeatedly writes data to the AudioSink object which this object is connected to, until it writes data with length END_OF_DATA, or until the stopSending method is called.
 void stopSending()
           
 
Methods inherited from class com.cloudgarden.audio.AudioServer
addClient, addClientListener, addTransferListener, bytesTransferred, bytesTransferred, checkClient, closeConnection, closeServer, getAudioFormat, getChannels, getClients, getContentType, getSampleRate, getSampleSizeInBits, isBigEndian, isOpen, isSigned, openConnection, removeClient, removeClientListener, removeTransferListener, setAudioFormat
 
Methods inherited from class java.rmi.server.UnicastRemoteObject
clone, exportObject, exportObject, exportObject, unexportObject
 
Methods inherited from class java.rmi.server.RemoteServer
getClientHost, getLog, setLog
 
Methods inherited from class java.rmi.server.RemoteObject
equals, getRef, hashCode, toString, toStub
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.cloudgarden.audio.AudioServerI
closeConnection, getChannels, getContentType, getSampleRate, getSampleSizeInBits, isBigEndian, isSigned, openConnection, setAudioFormat
 
Methods inherited from interface com.cloudgarden.audio.AudioObject
addTransferListener, getAudioFormat, getContentType, removeTransferListener
 

Field Detail

waiting

protected boolean waiting

paused

protected boolean paused
Constructor Detail

AudioServerSource

public AudioServerSource(java.lang.String remoteName,
                         java.net.InetAddress clientAddress,
                         int port)
                  throws java.rmi.RemoteException
Creates, initializes and binds an AudioInputSocket to the given remoteName in the local registry. If a local registry does not exist on the specified port, this method will create it.
Parameters:
remoteName - is the name with which this object is registered in the registry and so must be unique to this machine. Note that multiple Recognizers can each have an AudioInputSocket on the same machine.
clientAddress - may be null for no restriction on allowed IP address
port - may be set to -1 to use the default port (Registry.REGISTRY_PORT)
Method Detail

setBufferSize

public void setBufferSize(int size)
Sets the buffer size of the internal AudioPipe

setSink

public void setSink(AudioSink sink)
             throws java.io.IOException
Description copied from interface: AudioSource
Sets the sink for this source - this method should also call the setSource method on the sink object (making sure to avaoid an endless loop) to ensure that source and sink are connected to each other (and not to different sinks/sources). Also ensures continuity of the AudioFormat and ContentType (as described below).

If the sink's AudioFormat is null or the sink's format differs from this AudioSource's format, then the sink's format is set equal to that of this AudioSource.

If the sink's AudioFormat is not null and this AudioSource's format is null then this AudioSource's format is set equal to the sink's.

The same is done for the ContentType as described above for the AudioFormat.

Note: if the sink is an AudioConverter then the get/setIncomingAudioFormat method is called instead of get/setAudioFormat.

Specified by:
setSink in interface AudioSource
Following copied from interface: com.cloudgarden.audio.AudioSource
See Also:
AudioSource.getSink()

getSink

public AudioSink getSink()
Description copied from interface: AudioSource
Returns the AudioSink set using setSink
Specified by:
getSink in interface AudioSource
Following copied from interface: com.cloudgarden.audio.AudioSource
See Also:
AudioSource.setSink(com.cloudgarden.audio.AudioSink)

acceptBytes

public int acceptBytes(byte[] bytes,
                       int offset,
                       int len)
                throws java.rmi.RemoteException
An RMI method called by the remote client to send data to this class.
Specified by:
acceptBytes in interface AudioInputServerI

stopSending

public void stopSending()
Specified by:
stopSending in interface AudioSource
Following copied from interface: com.cloudgarden.audio.AudioSource
See Also:
AudioSource.startSending()

startSending

public void startSending()
                  throws java.io.IOException
Description copied from interface: AudioSource
This method should start a thread which repeatedly writes data to the AudioSink object which this object is connected to, until it writes data with length END_OF_DATA, or until the stopSending method is called. If an error occurs while the thread is sending data it could be detected by calling the drain method.
Specified by:
startSending in interface AudioSource
Following copied from interface: com.cloudgarden.audio.AudioSource
Throws:
an - IOException if the source is unable to start sending data - for example, if an audio file is unable to be opened to supply the data to be sent.
See Also:
AudioSource.setSink(com.cloudgarden.audio.AudioSink), AudioObject.drain()

isSending

public boolean isSending()
Description copied from interface: AudioSource
Returns true if the thread started by the startSending method is still writing data to the AudioSink.
Specified by:
isSending in interface AudioSource
Following copied from interface: com.cloudgarden.audio.AudioSource
See Also:
AudioSource.startSending()

drain

public void drain()
           throws java.io.IOException
Description copied from interface: AudioObject
Blocks until END_OF_DATA is written to or read from this AudioObject. For sinks such as an AudioLineSink, or sources such as AudioLineSource should also drain the line.
Specified by:
drain in interface AudioObject

read

public int read(byte[] data,
                int len)
         throws java.io.IOException
Description copied from interface: AudioSource
Convenience method - should call read(data, 0, len)
Specified by:
read in interface AudioSource

read

public int read(byte[] data,
                int offset,
                int len)
         throws java.io.IOException
Description copied from interface: AudioSource
Used to read data from this source - called by the AudioSink which this source is connected to (if its startGetting method is used) so need not be called explicitly by an application. Blocks if this source is paused. Returns the number of bytes read, or END_OF_DATA if all the available data has been read - eg if the end of a file has been reached, or if the stopSending() method has been called.
Specified by:
read in interface AudioSource
Following copied from interface: com.cloudgarden.audio.AudioSource
See Also:
AudioSource.setSink(com.cloudgarden.audio.AudioSink), AudioSink#startGetting, AudioObject.setPaused(boolean)

isWaiting

public boolean isWaiting()
Description copied from interface: AudioObject
Returns true if no data has yet been written or read from this AudioObject
Specified by:
isWaiting in interface AudioObject

setPaused

public void setPaused(boolean paused)
Description copied from interface: AudioObject
If paused is true, writing or reading data to or from this AudioObject will block until setPaused(false) is called.
Specified by:
setPaused in interface AudioObject

isPaused

public boolean isPaused()
Specified by:
isPaused in interface AudioObject

setAudioFormat

public void setAudioFormat(javax.sound.sampled.AudioFormat format)
                    throws java.io.IOException
Description copied from interface: AudioObject
Sets the AudioFormat for this AudioObject. If this object is connected to an AudioSource or an AudioSink, then the source/sink's AudioFormat is set equal to that of this AudioObject. Note: if the sink is an AudioConverter then the setIncomingAudioFormat method is called instead of setAudioFormat.

This ensures that the AudioFormat is uniform along a set of connected AudioObjects until the format is changed by an AudioConverter.

Specified by:
setAudioFormat in interface AudioObject
Overrides:
setAudioFormat in class AudioServer
Following copied from interface: com.cloudgarden.audio.AudioObject
Throws:
java.io.IOException - if unable to set the AudioFormat for any reason (eg. if canSetAudioFormat returns false and setAudioFormat is used to try to change the AudioFormat).
See Also:
AudioObject.getAudioFormat()

setContentType

public void setContentType(java.lang.String contentType)
Description copied from interface: AudioObject
Sets the content type for this AudioObject - contentType must be one of the FileTypeDescriptor String fields, eg MPEG_AUDIO.
Specified by:
setContentType in interface AudioServerI
Overrides:
setContentType in class AudioServer

canSetAudioFormat

public boolean canSetAudioFormat()
Description copied from interface: AudioObject
Returns false if the AudioFormat cannot be set - eg some Recognizers may not be able to change their input format, so the CGAudioManager (which is an AudioSink) for that Recognizer will return false here.
Specified by:
canSetAudioFormat in interface AudioObject
Overrides:
canSetAudioFormat in class AudioServer