FileDocCategorySizeDatePackage
DevicePushSourceStream.javaAPI DocJMF 2.1.1e5079Mon May 12 12:21:22 BST 2003com.ibm.media.protocol.device

DevicePushSourceStream

public class DevicePushSourceStream extends Object implements Runnable, PushSourceStream

Fields Summary
private SourceTransferHandler
handler
The Handler to service data transfers to this stream
Thread
triggerThread
The thread which responsible on generating the transferData call
boolean
started
Indicates the stream was started
Constructors Summary
Methods Summary
public booleanendOfStream()
Find out if the end of the stream has been reached.

return
Returns true if there is no more data.

	// currently we just return false but it should be changed 
	return false;
    
public javax.media.protocol.ContentDescriptorgetContentDescriptor()
Get the current content type for this stream.

return
The current ContentDescriptor for this stream.


	// temporary implemantation
	return new ContentDescriptor("raw");
    
public longgetContentLength()
Get the size, in bytes, of the content on this stream. LENGTH_UNKNOWN is returned if the length is not known.

return
The content length in bytes.

	return LENGTH_UNKNOWN;
    
public java.lang.ObjectgetControl(java.lang.String controlType)
Obtain the object that implements the specified Class or Interface The full class or interface name must be used.

If the control is not supported then null is returned.

return
the object that implements the control, or null.

	// no control implemented
	return null;
    
public java.lang.Object[]getControls()
Obtain the collection of objects that control the object that implements this interface.

If no controls are supported, a zero length array is returned.

return
the collection of object controls

    
	// no controls implemented
	return new Object[0];
    
public javax.media.FormatgetFormat()
Obtain the format that this object is set to.

return
the current format.

  
     
	com.sun.media.JMFSecurityManager.loadLibrary("jmdevice");
    
    
	// TEMPORARY IMPLEMENTATION
	return new AudioFormat(AudioFormat.LINEAR, 22050, 16, 1);
    
public intgetMinimumTransferSize()
Determine the size of the buffer needed for the data transfer. This method is provided so that a transfer handler can determine how much data, at a minimum, will be available to transfer from the source. Overflow and data loss is likely to occur if this much data isn't read at transfer time.

return
The size of the data transfer.

	/* NOT IMPLEMENTED YET */
	return 128;
    
private native booleanisBufferFilled()
Checks a the bufferFilled flag in the native code

public native synchronized intread(byte[] buffer, int offset, int length)
Read from the stream without blocking. Returns -1 when the end of the media is reached.

param
buffer The buffer to read bytes into.
param
offset The offset into the buffer at which to begin writing data.
param
length The number of bytes to read.
return
The number of bytes read or -1 when the end of stream is reached.

public voidrun()
Runnable's method implementation

	while (started) {
	    handler.transferData(this);
	    while (!isBufferFilled()) {
		try {
		    synchronized(this) {
			wait();
		    }
		}
		catch (InterruptedException e) {
		    System.out.println("Exception: " + e);
		}
	    }
	}
	started = true; // this is a temporary solution for signaling the thead exit
    
public voidsetTransferHandler(javax.media.protocol.SourceTransferHandler transferHandler)
Register an object to service data transfers to this stream.

If a handler is already registered when setTransferHandler is called, the handler is replaced; there can only be one handler at a time.

param
transferHandler The handler to transfer data to.

	handler = transferHandler;
    
voidstart()
Starts a thread to initiate trasferData called on the Handler. The thread will wait untill the buffer sent to the device is full and than will call trasferData again

	triggerThread = new Thread(this);
	started = true;
	triggerThread.start();
    
voidstop()
Stops the thread

	started = false;
	while (!started); // TEMPORARY SOLUTION, TO BE REPLACED