FileDocCategorySizeDatePackage
DSoundST.javaAPI DocJMF 2.1.1e2647Mon May 12 12:21:20 BST 2003com.sun.media.protocol.dsound

DSoundST

public class DSoundST extends DSound implements Runnable

Fields Summary
private static final int
REQ_OPEN
private static final int
REQ_FLUSH
private static final int
REQ_START
private static final int
REQ_STOP
private static final int
REQ_CLOSE
private static final int
REQ_READ
protected boolean
failure
protected Thread
requestThread
protected Integer
requestLock
protected int
request
protected int
result
protected byte[]
data
protected int
offset
protected int
len
Constructors Summary
public DSoundST(AudioFormat format, int bufferSize)


    
         
	super(format, bufferSize);
    
Methods Summary
public voidclose()

	waitForRequest(REQ_CLOSE);
    
public voidflush()

	waitForRequest(REQ_FLUSH);
    
public voidopen()

	if (requestThread == null) {
	    requestThread = new Thread(this);
	    requestThread.start();
	}

	waitForRequest(REQ_OPEN);

	if (failure)
	    throw new Error("Error opening DSound for capture");
    
public intread(byte[] data, int offset, int len)

	this.data = data;
	this.offset = offset;
	this.len = len;
	waitForRequest(REQ_READ);
	return result;
    
public voidrun()

	boolean done = false;
	while (!done) {
	    synchronized (requestLock) {
		while (request == 0) {
		    try {
			requestLock.wait();
		    } catch (InterruptedException ie) {
		    }
		}
	    }
	    if (request > 0) {
		switch (request) {
		case REQ_OPEN:
		    try {
			super.open();
		    } catch (Error e) {
			failure = true;
		    }
		    break;
		case REQ_START:
		    super.start();
		    break;
		case REQ_STOP:
		    super.stop();
		    break;
		case REQ_READ:
		    result = super.read(data, offset, len);
		    break;
		case REQ_FLUSH:
		    super.flush();
		    break;
		case REQ_CLOSE:
		    super.close();
		    done = true;
		}
	    }
	    synchronized (requestLock) {
		request = 0;
		requestLock.notifyAll();
	    }
	}
    
public voidstart()

	waitForRequest(REQ_START);
    
public voidstop()

	waitForRequest(REQ_STOP);
    
private voidwaitForRequest(int req)

	synchronized (requestLock) {
	    request = req;
	    requestLock.notifyAll();
	    while (request > 0) {
		try {
		    requestLock.wait(100);
		} catch (InterruptedException ie) {
		}
	    }
	}