FileDocCategorySizeDatePackage
DataSource.javaAPI DocJMF 2.1.1e3136Mon May 12 12:21:30 BST 2003com.sun.media.protocol.v4l

DataSource

public class DataSource extends PushBufferDataSource implements CaptureDevice

Fields Summary
protected Object[]
controls
protected boolean
started
protected String
contentType
protected boolean
connected
protected Time
duration
protected V4LSourceStream[]
streams
protected V4LSourceStream
stream
Constructors Summary
public DataSource()

    
      
    
Methods Summary
public voidconnect()

	// Dont connect a second time
	if (connected)
	    return;

	// Create a new V4LSourceStream array
	streams = new V4LSourceStream[1];
	// Try to open the stream for the specified locator
	// The locator has information such as cardno, format, size...
	try {
	    stream = new V4LSourceStream(getLocator());
	    controls = stream.getControls();
	} catch (Exception ex) {
	    throw new IOException(ex.toString());
	} catch (Error er) {
	    throw new IOException(er.toString());
	}
	streams[0] = stream;
	
	connected = true;
    
public voiddisconnect()

	if (!connected)
	    return;

	synchronized (stream) {	    
	    try {
		if (started)
		    stop();
	    } catch (IOException e) {}
	    stream.close();
	    
	    connected = false;
	}
    
public javax.media.CaptureDeviceInfogetCaptureDeviceInfo()

	return stream.getCaptureDeviceInfo();
    
public java.lang.StringgetContentType()

	if (!connected){
            throw new Error("DataSource not connected yet!");
        }
	return contentType;
    
public java.lang.ObjectgetControl(java.lang.String controlType)

       try {
          Class  cls = Class.forName(controlType);
          Object cs[] = getControls();
          for (int i = 0; i < cs.length; i++) {
             if (cls.isInstance(cs[i]))
                return cs[i];
          }
          return null;

       } catch (Exception e) {   // no such controlType or such control
         return null;
       }
    
public java.lang.Object[]getControls()

	return controls;
    
public javax.media.TimegetDuration()

	// Unbounded
	return duration;
    
public javax.media.control.FormatControl[]getFormatControls()

	return stream.getFormatControls();
    
public javax.media.protocol.PushBufferStream[]getStreams()

	return streams;
    
public voidstart()

	// we need to throw error if connect() has not been called
        if (!connected)
            throw new java.lang.Error("DataSource must be connected before it can be started");
	synchronized (stream) {
	    if (started)
		return;
	    started = true;
	    stream.start(true);
	}
    
public voidstop()

	synchronized (stream) {
	    if ((!connected) || (!started))
		return;
	    started = false;
	    stream.start(false);
	}