FileDocCategorySizeDatePackage
BasicModule.javaAPI DocJMF 2.1.1e11651Mon May 12 12:20:48 BST 2003com.sun.media

BasicModule

public abstract class BasicModule extends Object implements StateTransistor, Module
BasicModule Implements a basic JMF Module.

Fields Summary
protected Registry
inputConnectors
registry of all input connectors created by this module.
protected Registry
outputConnectors
registry of all output connectors created by this module.
protected InputConnector[]
inputConnectorsArray
protected OutputConnector[]
outputConnectorsArray
protected int
protocol
protected String
name
the instance name of the module, declared in the manager
protected ModuleListener
moduleListener
protected BasicController
controller
protected boolean
resetted
protected boolean
prefetchFailed
protected JMD
jmd
Constructors Summary
Methods Summary
public voidabortPrefetch()
Called when the prefetch() is aborted, i.e. deallocate() was called while prefetching. Release all resources claimed previously by the prefetch call.

 
public voidabortRealize()
Called when the realize() is aborted, i.e. deallocate() was called while realizing. Release all resources claimed previously by the realize() call.

 
public booleancanRun()
return if data is available on all inputConnectors and there is room in all outputConnectors.

        for (int i=0;i<inputConnectorsArray.length;i++)
         if (!inputConnectorsArray[i].isValidBufferAvailable() )
            return false;
        for (int i=0;i<outputConnectorsArray.length;i++)
         if (!outputConnectorsArray[i].isEmptyBufferAvailable() )
            return false;

        return true;
    
public voidconnectorPushed(com.sun.media.InputConnector inputConnector)

        process();
    
public voiddoClose()
This function performs the steps to close a module or Player.

 
public voiddoDealloc()
This function performs the steps to deallocate a module or Player, and return to the realized state.

 
public voiddoFailedPrefetch()
Called when prefetch fails.

 
public voiddoFailedRealize()
Called when realize fails.

 
public booleandoPrefetch()
This function performs the steps to prefetch a module or Player.

return
true if successful.

        // commit connectors to array
	resetted = false;
        return true; 
    
public booleandoRealize()
This function performs the steps of realizing a module or a Player.

return
true if successful.

    
                         
        
	return true;
    
public voiddoSetMediaTime(javax.media.Time t)
This function notifies the module that the media time has changed.

 
public floatdoSetRate(float r)
This function notifies the module that the playback rate has changed.

 
	return r; 
    
public voiddoStart()
This function performs the steps to start a module or Player.

 
	resetted = false;
    
public voiddoStop()
This function performs the steps to stop a module or Player, and return to the prefetched state.

 
protected voiderror()

        throw new RuntimeException(getClass().getName()+" error");
    
public java.lang.ObjectgetControl(java.lang.String s)

	return null;
    
public final com.sun.media.BasicControllergetController()

return
the Controller that maintains this module.

        return controller;
    
public java.lang.Object[]getControls()
Return a list of module controls.

	return null;
    
public com.sun.media.InputConnectorgetInputConnector(java.lang.String connectorName)
Return the InputConnector given the connector name.

        return (InputConnector)inputConnectors.get(connectorName);
    
public java.lang.String[]getInputConnectorNames()
Return an array of strings containing this media module's input port names.

        return inputConnectors.getNames();
    
public longgetLatency()

	return ((PlaybackEngine)controller).getLatency();
    
public longgetMediaNanoseconds()
Return the current time in nanoseconds.

	return controller.getMediaNanoseconds();
    
public javax.media.TimegetMediaTime()
Return the current Media time.

	return controller.getMediaTime();
    
public final java.lang.StringgetName()
returns the name of this Module in the Player

        return name;
    
public com.sun.media.OutputConnectorgetOutputConnector(java.lang.String connectorName)
Return the OutputConnector given the connector name.

        return (OutputConnector)outputConnectors.get(connectorName);

    
public java.lang.String[]getOutputConnectorNames()
Return an array of strings containing this media module's output port names.

        return outputConnectors.getNames();

    
public intgetProtocol()
return the data transfer protocol

        return protocol;
    
public final intgetState()
Return the state of the controller.

	return controller.getState();
    
public final booleanisInterrupted()

return
true if the module has been interrupted.

	return (controller == null ? false : controller.isInterrupted());
    
public booleanisThreaded()
return if this module create threads (so it run on Safe protocol) like Rendering module or not (as a codec module).

        return true;
    
public booleanprefetchFailed()

	return prefetchFailed;
    
protected abstract voidprocess()
function which does the real processing.
if canRun {
for (all inputConnectors)
ic.getValidBuffer()
for (all outputConnectors)
oc.getEmptyBuffer()

for (all inputConnectors)
ic.readReport()
for (all outputConnectors)
oc.writeReport()
}

public voidregisterInputConnector(java.lang.String name, com.sun.media.InputConnector inputConnector)
For each of the inputConnectables to this node, it needs to be registered with this function.

       inputConnectors.put(name , inputConnector);
       inputConnector.setModule(this);
    
public voidregisterOutputConnector(java.lang.String name, com.sun.media.OutputConnector outputConnector)
For each of the outputConnectables from this node, it needs to be registered with this function.

       outputConnectors.put(name , outputConnector);
       outputConnector.setModule(this);

    
public voidreset()
reset this module only.
if (state== Started)
throw Exception()
for (all connectors)
connector.reset()
The resetted flag is falsified only when the module is later restarted.

	resetted = true;
    
public final voidsetController(com.sun.media.BasicController c)
Set the Controller that maintains this module.

	controller = c;
    
public voidsetFormat(com.sun.media.Connector connector, javax.media.Format format)
Selects a format for this Connector (the default is null). The setFormat() method is typically called by the Manager as part of the Connector connection method call. Typically the connector would delegate this call to its owning Module.

public voidsetJMD(com.sun.media.JMD jmd)

	this.jmd = jmd;
    
public voidsetModuleListener(com.sun.media.ModuleListener listener)
Specify a ModuleListener to which this Module will send events.

param
listener The listener to which the Module will post events.

	moduleListener = listener;
    
public voidsetName(java.lang.String name)
sets the name of this Module. Called by the owning Player registerModule() method

        this.name=name;
    
public voidsetProtocol(int protocol)
sets the protocol for all the connectors

        this.protocol=protocol;
        Connector[] connectors= inputConnectors.getConnectors();
        for (int i=0; i<connectors.length; i++)
           connectors[i].setProtocol(protocol);
                    connectors= outputConnectors.getConnectors();
        for (int i=0; i<connectors.length ; i++)
           connectors[i].setProtocol(protocol);

    
protected booleanverifyBuffer(javax.media.Buffer buffer)
Verify to see if the given buffer has valid data sizes.

	if (buffer.isDiscard())
	    return true;
	Object data = buffer.getData();
	if (buffer.getLength() < 0) {
	    System.err.println("warning: data length shouldn't be negative: " + buffer.getLength());
	}
	if (data == null) {
	    System.err.println("warning: data buffer is null");
	    if (buffer.getLength() != 0) {
		System.err.println("buffer advertized length = " + buffer.getLength() + " but data buffer is null!"); 
		return false;
	    }
	} else if (data instanceof byte[]) {
	    if (buffer.getLength() > ((byte[])data).length) {
		System.err.println("buffer advertized length = " + buffer.getLength() + " but actual length = " + ((byte[])data).length); 
		return false;
	    }
	} else if (data instanceof int[]) {
	    if (buffer.getLength() > ((int[])data).length) {
		System.err.println("buffer advertized length = " + buffer.getLength() + " but actual length = " + ((int[])data).length); 
		return false;
	    }
	}
	return true;