com.cloudgarden.audio
Class AudioServerSink

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

public class AudioServerSink
extends AudioServer
implements AudioOutputServerI, AudioSink

This class sends audio output to a remote (client) machine. The port it uses, it's remote name and (optionally) the IP address of the client permitted to receive 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
AudioServerSink()
           
AudioServerSink(java.lang.String remoteName, java.net.InetAddress clientAddress, int port)
          Creates, initializes and binds an AudioOutputSocket to the given remoteName in the local registry.
 
Method Summary
 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.
 byte[] getBytes(int len)
          An RMI method called by the remote client to receive audio data from this class.
 AudioSource getSource()
          Returns the AudioSource set by setSource
 boolean isPaused()
           
 boolean isWaiting()
          Returns true if no data has yet been written or read from this AudioObject
 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 setPaused(boolean paused)
          If paused is true, writing or reading data to or from this AudioObject will block until setPaused(false) is called.
 void setSource(AudioSource src)
          Sets the source for this sink - this method should also call the setSink method on the source object (while avoiding an endless loop) to ensure that sink and source are connected to each other (and not to different sinks/sources).
 int write(byte[] data, int len)
          Convenience method - should call write(data, 0, len)
 int write(byte[] data, int offset, int len)
          Used to write data to this sink - called by the AudioSource which this sink is connected to (if its startSending method is used) so need not be called explicitly by an application.
 
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, setContentType
 
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, setContentType
 
Methods inherited from interface com.cloudgarden.audio.AudioObject
addTransferListener, getAudioFormat, getContentType, removeTransferListener, setContentType
 

Field Detail

paused

protected boolean paused

waiting

protected boolean waiting
Constructor Detail

AudioServerSink

public AudioServerSink()
                throws java.rmi.RemoteException

AudioServerSink

public AudioServerSink(java.lang.String remoteName,
                       java.net.InetAddress clientAddress,
                       int port)
                throws java.rmi.RemoteException
Creates, initializes and binds an AudioOutputSocket 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 Synthesizers can each have an AudioOutputSocket 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

setSource

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

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

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

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

Specified by:
setSource in interface AudioSink
Following copied from interface: com.cloudgarden.audio.AudioSink
See Also:
AudioSink.getSource()

getSource

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

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

getBytes

public byte[] getBytes(int len)
                throws java.rmi.RemoteException
An RMI method called by the remote client to receive audio data from this class. Will block till there is data to be read.
Specified by:
getBytes in interface AudioOutputServerI

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

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

write

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

write

public int write(byte[] data,
                 int offset,
                 int len)
          throws java.io.IOException
Description copied from interface: AudioSink
Used to write data to this sink - called by the AudioSource which this sink is connected to (if its startSending method is used) so need not be called explicitly by an application. Blocks if this sink is paused.
Specified by:
write in interface AudioSink
Following copied from interface: com.cloudgarden.audio.AudioSink
See Also:
AudioSink.setSource(com.cloudgarden.audio.AudioSource), AudioSource.startSending(), AudioObject.setPaused(boolean)

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()

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