com.cloudgarden.audio
Class AudioServer

java.lang.Object
  |
  +--java.rmi.server.RemoteObject
        |
        +--java.rmi.server.RemoteServer
              |
              +--java.rmi.server.UnicastRemoteObject
                    |
                    +--com.cloudgarden.audio.AudioServer
All Implemented Interfaces:
AudioServerI, java.rmi.Remote, java.io.Serializable
Direct Known Subclasses:
AudioServerSink, AudioServerSource

public class AudioServer
extends java.rmi.server.UnicastRemoteObject
implements AudioServerI

This class allows an AudioSink (eg a Recognizer's CGAudioManager) to receive audio input from a remote 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  java.net.InetAddress clientAddress
           
protected static java.util.Vector clientListeners
           
protected static java.util.Hashtable clients
           
protected  boolean closed
           
protected  java.lang.String contentType
           
protected  javax.sound.sampled.AudioFormat format
           
protected  java.util.Vector listeners
           
protected  boolean open
           
protected  int port
           
protected static java.rmi.registry.Registry registry
           
protected  java.lang.String remoteName
           
 
Fields inherited from class java.rmi.server.RemoteObject
ref
 
Constructor Summary
protected AudioServer()
           
  AudioServer(java.lang.String remoteName, java.net.InetAddress clientAddress, int port)
          Creates, initializes and binds an AudioSocket to the given remoteName in the local registry.
 
Method Summary
protected  void addClient(java.lang.String client)
           
 void addClientListener(ClientListener listener)
           
 void addTransferListener(TransferListener listener)
           
protected  void bytesTransferred(byte[] data, int offset, int numBytes, int direction)
           
protected  void bytesTransferred(java.lang.String client, byte[] data, int offset, int numBytes, int direction)
           
 boolean canSetAudioFormat()
           
protected  void checkClient()
           
 void closeConnection()
           
 void closeServer()
          Closes the socket and unbinds it from the registry.
 javax.sound.sampled.AudioFormat getAudioFormat()
           
 int getChannels()
           
static java.util.Hashtable getClients()
           
 java.lang.String getContentType()
           
 int getSampleRate()
           
 int getSampleSizeInBits()
           
 boolean isBigEndian()
           
 boolean isOpen()
           
 boolean isSigned()
           
 boolean openConnection()
           
protected  void removeClient(java.lang.String client)
           
 void removeClientListener(ClientListener listener)
           
 void removeTransferListener(TransferListener listener)
           
 void setAudioFormat(javax.sound.sampled.AudioFormat format)
           
 void setAudioFormat(int sps, int bits, int chans, boolean signed, boolean be)
           
 void setContentType(java.lang.String contentType)
           
 
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
 

Field Detail

closed

protected boolean closed

format

protected javax.sound.sampled.AudioFormat format

port

protected int port

clientAddress

protected java.net.InetAddress clientAddress

remoteName

protected java.lang.String remoteName

contentType

protected java.lang.String contentType

clients

protected static java.util.Hashtable clients

clientListeners

protected static java.util.Vector clientListeners

registry

protected static java.rmi.registry.Registry registry

listeners

protected java.util.Vector listeners

open

protected boolean open
Constructor Detail

AudioServer

protected AudioServer()
               throws java.rmi.RemoteException

AudioServer

public AudioServer(java.lang.String remoteName,
                   java.net.InetAddress clientAddress,
                   int port)
            throws java.rmi.RemoteException
Creates, initializes and binds an AudioSocket 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 AudioSocket 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

checkClient

protected void checkClient()
                    throws java.rmi.RemoteException

closeServer

public void closeServer()
Closes the socket and unbinds it from the registry. When the socket is closed, and clients connected to the socket will be notified that it is closed next time they try to send data to the acceptBytes method.

getChannels

public int getChannels()
                throws java.rmi.RemoteException
Specified by:
getChannels in interface AudioServerI

getSampleRate

public int getSampleRate()
                  throws java.rmi.RemoteException
Specified by:
getSampleRate in interface AudioServerI

getSampleSizeInBits

public int getSampleSizeInBits()
                        throws java.rmi.RemoteException
Specified by:
getSampleSizeInBits in interface AudioServerI

addClientListener

public void addClientListener(ClientListener listener)

removeClientListener

public void removeClientListener(ClientListener listener)

addClient

protected void addClient(java.lang.String client)

removeClient

protected void removeClient(java.lang.String client)

bytesTransferred

protected void bytesTransferred(java.lang.String client,
                                byte[] data,
                                int offset,
                                int numBytes,
                                int direction)

addTransferListener

public void addTransferListener(TransferListener listener)

removeTransferListener

public void removeTransferListener(TransferListener listener)

bytesTransferred

protected void bytesTransferred(byte[] data,
                                int offset,
                                int numBytes,
                                int direction)

getClients

public static java.util.Hashtable getClients()

setAudioFormat

public void setAudioFormat(int sps,
                           int bits,
                           int chans,
                           boolean signed,
                           boolean be)
                    throws java.rmi.RemoteException
Specified by:
setAudioFormat in interface AudioServerI

setAudioFormat

public void setAudioFormat(javax.sound.sampled.AudioFormat format)
                    throws java.io.IOException

canSetAudioFormat

public boolean canSetAudioFormat()

getAudioFormat

public javax.sound.sampled.AudioFormat getAudioFormat()

setContentType

public void setContentType(java.lang.String contentType)
Specified by:
setContentType in interface AudioServerI

getContentType

public java.lang.String getContentType()
Specified by:
getContentType in interface AudioServerI

isBigEndian

public boolean isBigEndian()
                    throws java.rmi.RemoteException
Specified by:
isBigEndian in interface AudioServerI

isSigned

public boolean isSigned()
                 throws java.rmi.RemoteException
Specified by:
isSigned in interface AudioServerI

isOpen

public boolean isOpen()

openConnection

public boolean openConnection()
                       throws java.rmi.RemoteException
Specified by:
openConnection in interface AudioServerI

closeConnection

public void closeConnection()
                     throws java.rmi.RemoteException
Specified by:
closeConnection in interface AudioServerI