FileDocCategorySizeDatePackage
CaptureDeviceManager.javaAPI DocJMF 2.1.1e5213Mon May 12 12:20:38 BST 2003javax.media.cdm

CaptureDeviceManager

public class CaptureDeviceManager extends CaptureDeviceManager
This is a manager class that fetches a list of devices available on the system. It uses a registry mechanism and/or query mechanism to locate devices and return CaptureDeviceInfo objects for each available device. The CaptureDeviceManager can also be used to register new devices by adding a device and calling commit().

since
JMF 2.0

Fields Summary
static Vector
devices
Constructors Summary
public CaptureDeviceManager()

    
     
	readFromRegistry();
    
	readFromRegistry();
    
Methods Summary
public static synchronized booleanaddDevice(javax.media.CaptureDeviceInfo newDevice)
Adds a CaptureDeviceInfo object to the list. This information is not stored permanently in any registry. If a similar CaptureDeviceInfo object is already registered, then the new device is not added.

see
#commit
return
true if the object could be added, false otherwise.

	if (newDevice != null) {
	    if (devices == null)
		devices = new Vector();
	    else {
		Enumeration enum = devices.elements();
		while (enum.hasMoreElements()) {
		    CaptureDeviceInfo cdi = (CaptureDeviceInfo) enum.nextElement();
		    if (cdi.equals(newDevice)) {
			return false;
		    }
		}
	    }
	    
	    devices.addElement(newDevice);
	    return true;
	}
	
	return false;
    
public static synchronized voidcommit()
Permanently store information about the list of devices in a registry.

return
false if the commit fails.

	Registry r = new Registry();

	r.removeGroup("CDM");

	if (devices == null) {
	    r.set("CDM.nDevices", new Integer(0));
	} else {
	    r.set("CDM.nDevices", new Integer(devices.size()));

	    int i = 0;
	    Enumeration enum = devices.elements();
	    while (enum.hasMoreElements()) {
		CaptureDeviceInfo cdi = (CaptureDeviceInfo) enum.nextElement();
		r.set("CDM." + i, cdi);

		i++;
	    }
	}
	try {
	    r.commit();
	} catch (Exception e) {
	    System.err.println("Exception on commit = " + e);
	}
    
public static synchronized javax.media.CaptureDeviceInfogetDevice(java.lang.String deviceName)
Returns the CaptureDeviceInfo corresponding to the specified name of the device. For example: "SunVideo". Returns null if the device could not be found.

return
the CaptureDeviceInfo corresponding to the specified name of theo * device.

	if (devices == null)
	    return null;
	
	Enumeration enum = devices.elements();
	while (enum.hasMoreElements()) {
	    CaptureDeviceInfo cdi = (CaptureDeviceInfo) enum.nextElement();
	    if (cdi.getName().equals(deviceName))
		return cdi;
	}
	
	return null;
    
public static synchronized java.util.VectorgetDeviceList()
Returns a list of CaptureDeviceInfo objects for each of the registered devices.

return
a list of CaptureDeviceInfo objects for each of the registered devices.

	return getDeviceList(null);
    
public static synchronized java.util.VectorgetDeviceList(javax.media.Format format)
Returns a list of CaptureDeviceInfo objects corresponding to devices that can capture data with the specified data format. If format is null then it returns all registered objects

return
a list of CaptureDeviceInfo objects for the given data format.

	if (devices == null)
	    return null;

	if (format == null)
	    return devices;
	
	Vector newList = new Vector();
	
	Enumeration enum = devices.elements();
	while (enum.hasMoreElements()) {
	    CaptureDeviceInfo cdi = (CaptureDeviceInfo) enum.nextElement();
	    Format [] formats = cdi.getFormats();
	    for (int i = 0; i < formats.length; i++) {
		if (formats[i].matches(format)) {
		    newList.addElement(cdi);
		    break;
		}
	    }
	}
	
	if (newList.size() > 0)
	    return newList;
	else
	    return null;
    
private static synchronized voidreadFromRegistry()

	if (devices != null)
	    return;
	devices = new Vector();
	Registry r = new Registry();
	Object size = r.get("CDM.nDevices");
	if (size == null || ((Integer)size).intValue() == 0)
	    return;
	for (int i = 0; i < ((Integer)size).intValue(); i++) {
	    Object cdi = r.get("CDM." + i);
	    if (cdi != null && cdi instanceof CaptureDeviceInfo)
		devices.addElement(cdi);
	}
    
public static synchronized booleanremoveDevice(javax.media.CaptureDeviceInfo device)
Removes a CaptureDeviceInfo object from the list.

see
#commit

	if ( devices == null ||
	     device == null ||
	     device.getName() == null)
	    return false;

	Enumeration enum = devices.elements();
	while (enum.hasMoreElements()) {
	    CaptureDeviceInfo cdi = (CaptureDeviceInfo) enum.nextElement();
	    if (cdi == device) {
		devices.removeElement(cdi);
		return true;
	    }
	}
	
	return false;