FileDocCategorySizeDatePackage
DSSourceStream.javaAPI DocJMF 2.1.1e5255Mon May 12 12:21:22 BST 2003com.ibm.media.protocol.ds

DSSourceStream

public class DSSourceStream extends Object implements PushBufferStream, Runnable

Fields Summary
private BufferTransferHandler
transferHandler
private Thread
triggerThread
private boolean
started
private VideoFormat
format
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.

	return false;
    
public javax.media.protocol.ContentDescriptorgetContentDescriptor()
Get the current content type for this stream.

return
The current ContentDescriptor for this stream.

 
  
                         
       
	return new ContentDescriptor(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.

	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

	return new Object[0];
    
public javax.media.FormatgetFormat()
Get the format tupe of the data that this source stream provides.

return
A Format object that describes the data in this stream.

    
	if (format == null) {
	  BitMapInfo bmi = new BitMapInfo();
	  getVideoFormat(bmi);
	  float frameRate = getFrameRate();
	  Format directShowFormat = bmi.createVideoFormat(Format.byteArray,
							  frameRate);
	    if (directShowFormat instanceof VideoFormat)
		format = (VideoFormat)directShowFormat;
	    else
		return new Format("DirectShowUnknown");
	}
    
	return format;
    
private native floatgetFrameRate()
Get the DirectShow reported frame rate

private native voidgetVideoFormat(com.sun.media.vfw.BitMapInfo bmi)
Fill the BitMapInfo object

private native booleanisFilled()
Checks if buffer was filled with data

public voidread(javax.media.Buffer buffer)
Read from the stream without blocking.

throws
IOException Thrown if an error occurs while reading

    
	//    System.out.println("read");
    
	Object data = buffer.getData();
	int length = format.getMaxDataLength();
    
	if (data == null || !(data instanceof byte[]) || ((byte[])data).length != length)
	    data = new byte[length];
    
	buffer.setFormat(format);    
	setBuffer((byte[])data, buffer.getOffset());
	try {
	    while (!isFilled())
		Thread.sleep(50);
	}
	catch (InterruptedException e) {
	    System.out.println("Exception: " + e);
	}
    
	buffer.setData(data);
	buffer.setOffset(0);
	buffer.setLength(length);
	buffer.setTimeStamp(Buffer.TIME_UNKNOWN);
    
public voidrun()
Runnable implementation


	while (started) {
	    transferHandler.transferData(this);
      
	    /* WE ASSUME transferData IS A BLOCKING CALL - THIS MAY NOT BE THE 
	       CASE FOR DIFFERENT IMPLEMENTATIONS OF Processors */
	}
	synchronized(this) {
	    notify(); // notify the stop method that the triggerThread has finished
	}
    
private native voidsetBuffer(byte[] data, int offset)
Sets a buffer

public voidsetTransferHandler(javax.media.protocol.BufferTransferHandler 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.

	this.transferHandler = transferHandler;
    
voidstart()
Start a thread to generate the transferData calls

    
	if (started) 
	    return;

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

    
	if (!started)
	    return;

	synchronized(this) {
	    started = false;
	    try {
		wait(); // wait till the triggerThread ended
	    }
	    catch (InterruptedException e) {
		System.out.println("Exception: " + e);
	    }
	}