FileDocCategorySizeDatePackage
PlugInManager.javaAPI DocJMF 2.1.1e11502Mon May 12 12:20:36 BST 2003javax.media

PlugInManager

public class PlugInManager extends Object
The PlugInManager is used to search for installed plug-ins and register new plug-ins.

Plug-in Types

JMF defines several types of plug-ins, such as codecs, demultiplexers, and renderers. Custom plug-in types can also be registered. The predefined plug-in types are:
  • DEMULTIPLEXER = 1
  • CODEC = 2
  • EFFECT = 3
  • RENDERER = 4
  • MULTIPLEXER = 5

This PlugInManager is a wrapper for the actual implementation, which it expects to find in javax.media.pim.PlugInManager. If this implementation exists and is an instance of javax.media.PlugInManager, all calls to javax.media.PlugInManager are redirected to javax.media.pim.PlugInManager. If the implementation is not found, all calls to javax.media.PlugInManager methods will fail and return null or invalid data.

since
JMF 2.0

Fields Summary
private static PlugInManager
pim
public static final int
DEMULTIPLEXER
Demultiplexer plug-in type.
public static final int
CODEC
Codec plug-in type.
public static final int
EFFECT
Effect plug-in type.
public static final int
RENDERER
Renderer plug-in type.
public static final int
MULTIPLEXER
Multiplexer plug-in type.
private static Method
mGetPlugInList
private static Method
mSetPlugInList
private static Method
mCommit
private static Method
mAddPlugIn
private static Method
mRemovePlugIn
private static Method
mGetSupportedInputFormats
private static Method
mGetSupportedOutputFormats
private static Format[]
emptyFormat
Constructors Summary
Methods Summary
public static booleanaddPlugIn(java.lang.String classname, javax.media.Format[] in, javax.media.Format[] out, int type)
Registers a new plug-in. This plug-in is automatically appended to the list of plug-ins searched when a Processor is created. Registration will fail if a plug-in of the same name already exists. The commit method has to be called to make the addition permanent.

param
classname A String that contains the class name of the new plug-in.
param
in A Format array that contains the input formats that the plug-in supports.
param
out A Format array that contains the output formats that the plug-in supports.
param
type The type of the new plug-in, for example: DEMULTIPLEXER, CODEC, EFFECT, MULTIPLEXER, or RENDERER.
return
true if the plug-in is registered successfully, false if it could not be registered.

	if (pim != null && mAddPlugIn != null) {
	    Object params[] = new Object[4];
	    params[0] = classname;
	    params[1] = in;
	    params[2] = out;
	    params[3] = new Integer(type);
	    Object result = runMethod(mAddPlugIn, params);
	    if (result != null)
		return ((Boolean)result).booleanValue();
	    else
		return false;
	} else
	    return false;
    
public static voidcommit()
Commits any changes made to the plug-in list. The commit method must be called when a plug-in is added or removed to make the change permanent. Changes to the search order can also be made permanent by calling commit.

	if (pim != null && mCommit != null) {
	    runMethod(mCommit, null);
	}
    
public static java.util.VectorgetPlugInList(javax.media.Format input, javax.media.Format output, int type)
Builds a list of plug-ins that satisfy the specified plug-in type and input and output formats. Either or both of the formats can be null. If input is null, getPlugInList returns a list of plug-ins of the specified type that match the output format. If output is null, getPlugInList returns a list of plug-ins of the specified type that match the input format. If both parameters are null, getPlugInList returns a list of all of the plug-ins of the specified type.

param
input The input Format to be supported by the plug-in.
param
output The output Format to be generated by the plug-in.
param
type The type of plug-in to search for, for example: DEMULTIPLEXER, CODEC, EFFECT, MULTIPLEXER, or RENDERER.
return
A Vector that contains the plug-in list.

	if (pim != null && mGetPlugInList != null) {
	    Object params[] = new Object[3];
	    params[0] = input;
	    params[1] = output;
	    params[2] = new Integer(type);
	    return (Vector) runMethod(mGetPlugInList, params);
	} else
	    return new Vector(1);
    
public static javax.media.Format[]getSupportedInputFormats(java.lang.String className, int type)
Gets a list of the input formats that the specified plug-in supports.

param
className The plug-in class name. For example: com.sun.media.codec.MPEG
param
type The type of the specified plug-in, for example: DEMULTIPLEXER, CODEC, EFFECT, MULTIPLEXER, or RENDERER.
return
An array of Format objects that the specified plug-in can accept as input. Returns an array of zero elements if specified plug-in is not registered or has no inputs.

	if (pim != null && mGetSupportedInputFormats != null) {
	    Object params[] = new Object[2];
	    params[0] = className;
	    params[1] = new Integer(type);
	    Object result = runMethod(mGetSupportedInputFormats, params);
	    return (Format[]) result;
	} else
	    return emptyFormat;
    
public static javax.media.Format[]getSupportedOutputFormats(java.lang.String className, int type)
Gets a list of the output formats that the specified plug-in supports.

param
className The plug-in class name. For example: com.sun.media.codec.MPEG
param
type The type of the specified plug-in, for example: DEMULTIPLEXER, CODEC, EFFECT, MULTIPLEXER, or RENDERER.
return
An array of Format objects that the specified plug-in can generate as output. Returns an array of zero elements if specified plug-in is not registered or has no outputs.

	if (pim != null && mGetSupportedOutputFormats != null) {
	    Object params[] = new Object[2];
	    params[0] = className;
	    params[1] = new Integer(type);
	    Object result = runMethod(mGetSupportedOutputFormats, params);
	    return (Format[]) result;
	} else
	    return emptyFormat;
    
public static booleanremovePlugIn(java.lang.String classname, int type)
Removes an existing plug-in from the registry. The commit method has to be called to make this change permanent.

param
classname A String that contains the class name of the plug-in to be removed.
param
type The type of the new plug-in, for example: DEMULTIPLEXER, CODEC, EFFECT, MULTIPLEXER, or RENDERER.
return
true if the plug-in is succesfully removed, false if no plug-in with the specified name could be found.

	if (pim != null && mRemovePlugIn != null) {
	    Object params[] = new Object[2];
	    params[0] = classname;
	    params[1] = new Integer(type);
	    Object result = runMethod(mRemovePlugIn, params);
	    if (result != null)
		return ((Boolean)result).booleanValue();
	    else
		return false;
	} else
	    return false;
    
static java.lang.ObjectrunMethod(java.lang.reflect.Method m, java.lang.Object[] params)


     
	// Look for javax.media.pim.PlugInManager
	Class classPIM = null;
	try {
	    classPIM = Class.forName("javax.media.pim.PlugInManager");
	    if (classPIM != null) {
		Object tryPIM = classPIM.newInstance();
		if (tryPIM instanceof PlugInManager) {
		    pim = (PlugInManager) tryPIM;

 		    mGetSupportedInputFormats =
 			PackageManager.getDeclaredMethod(classPIM, "getSupportedInputFormats",
 				     new Class[] {String.class, int.class});


 		    mGetSupportedOutputFormats =
 			PackageManager.getDeclaredMethod(classPIM, "getSupportedOutputFormats",
 				     new Class[] {String.class, int.class});



		    mGetPlugInList =
			PackageManager.getDeclaredMethod(classPIM, "getPlugInList",
				     new Class[] { Format.class,
						   Format.class,
						  int.class} );

		    mSetPlugInList = 
			PackageManager.getDeclaredMethod(classPIM, "setPlugInList",
				     new Class[] {Vector.class, int.class});

 		    mAddPlugIn =
 			PackageManager.getDeclaredMethod(classPIM, "addPlugIn",
 				     new Class[] {String.class,
						  Format.formatArray,
						  Format.formatArray,
						  int.class});

 		    mRemovePlugIn =
 			PackageManager.getDeclaredMethod(classPIM, "removePlugIn",
 				     new Class[] {String.class, int.class});

		    mCommit =
 			PackageManager.getDeclaredMethod(classPIM, "commit", null);
		}
	    }
	} catch (ClassNotFoundException e) {
	    System.err.println(e);
	} catch (InstantiationException e) {
	    System.err.println(e);
	} catch (IllegalAccessException e) {
	    System.err.println(e);
	} catch (SecurityException e) {
	    System.err.println(e);
	} catch (NoSuchMethodException e) {
	    System.err.println(e);
	}
    
	try {
	    return m.invoke(null, params);
	} catch (IllegalAccessException iae) {
	    System.err.println(iae);
	} catch (IllegalArgumentException iare) {
	    System.err.println(iare);
	} catch (InvocationTargetException ite) {
	    System.err.println(ite);
	}
	return null;
    
public static voidsetPlugInList(java.util.Vector plugins, int type)
Sets the search order for the plug-ins of the specified type. This enables you to control what plug-in is selected when multiple plug-ins of a particular type support the same input and output formats. (The first match is selected by the Processor.) This list is valid for the duration of the session only, unless commit is called.

param
plugins A Vector that lists the plug-ins in the order that they should be searched.
param
type The type of plug-in contained in the search list, for example: DEMULTIPLEXER, CODEC, EFFECT, MULTIPLEXER, or RENDERER.
see
#commit

	if (pim != null && mSetPlugInList != null) {
	    Object params[] = new Object[2];
	    params[0] = plugins;
	    params[1] = new Integer(type);
	    runMethod(mSetPlugInList, params);
	}