FileDocCategorySizeDatePackage
ProcessEngine.javaAPI DocJMF 2.1.1e34188Mon May 12 12:20:50 BST 2003com.sun.media

ProcessEngine

public class ProcessEngine extends PlaybackEngine
ProcessEngine implements the media engine for processors.

Fields Summary
protected BasicMuxModule
muxModule
protected ContentDescriptor
outputContentDes
String
prefetchError
protected Vector
targetMuxNames
This is the Graph builder to generate the data flow graph for the media engine. It extends from the SimpleGraphBuilder to handle multiplexers, customized output formats, codecs and renderers. It contains 3 parts: 1) Routines to search for all the supported output formats; 2) Routines to build a default flow graph -- buildGraph; 3) Routines to build a custom flow graph -- buildCustomGraph. A default graph is such that no customised option is specified on the TrackControl.
protected GraphNode[]
targetMuxes
protected GraphNode
targetMux
protected Format[]
targetMuxFormats
Constructors Summary
public ProcessEngine(BasicProcessor p)



       
	super(p);
    
Methods Summary
booleanconnectMux()
Connect the multiplexer.


	/**
	 * The target Mux has already been determined.  We'll just
	 * hook it up.
	 */
	BasicTrackControl tcs[] = new BasicTrackControl[trackControls.length];
	int total = 0;
	Multiplexer mux = (Multiplexer)targetMux.plugin;

	for (int i = 0; i < trackControls.length; i++) {
	    if (trackControls[i].isEnabled()) {
		tcs[total++] = trackControls[i];
	    }
	}

	try {
	    mux.setContentDescriptor(outputContentDes);
	} catch (Exception e) {
	    Log.comment("Failed to set the output content descriptor on the multiplexer.");
	    return false;
	}

	boolean failed = false;
	
	if (mux.setNumTracks(targetMuxFormats.length) != targetMuxFormats.length) {
	    Log.comment("Failed  to set number of tracks on the multiplexer.");
	    return false;
	}

	for (int mf = 0; mf < targetMuxFormats.length; mf++) {
	    if (targetMuxFormats[mf] == null || 
		mux.setInputFormat(targetMuxFormats[mf], mf) == null) {
		Log.comment("Failed to set input format on the multiplexer.");
		failed = true;
		break;
	    }
	}
		
	if (failed)
	    return false;

	if (SimpleGraphBuilder.inspector != null && !SimpleGraphBuilder.inspector.verify(mux, targetMuxFormats))
	    return false;

	//Log.comment("Found multiplexer: " + mux);

	InputConnector ic;
	BasicMuxModule bmm = new BasicMuxModule(mux, targetMuxFormats);
	if (DEBUG) bmm.setJMD(jmd);
	String name;

	// Make the connections.
	for (int j = 0; j < targetMuxFormats.length; j++) {
	    ic = bmm.getInputConnector(BasicMuxModule.ConnectorNamePrefix + j);
	    if (ic == null) {
		// Something is terribly wrong.
		Log.comment("BasicMuxModule: connector mismatched.");
		return false;
	    }
	    ic.setFormat(targetMuxFormats[j]);
	    tcs[j].lastOC.setProtocol(ic.getProtocol());
	    tcs[j].lastOC.connectTo(ic, targetMuxFormats[j]);
	}

	if (!bmm.doRealize()) {
	    //Log.comment("Failed to open the multiplexer.");
	    return false;
	}

        bmm.setModuleListener(this);
        bmm.setController(this);
        modules.addElement(bmm);
	sinks.addElement(bmm);

	muxModule = bmm;

	return true;
    
protected booleandoConfigure()
Configuring the engine.


	if (!doConfigure1())
	    return false;

	// The indices to the connector names, tracks, and track controls
	// should all correspond to each other.
	String names[] = source.getOutputConnectorNames();
	trackControls = new BasicTrackControl[tracks.length];
	for (int i = 0; i < tracks.length; i++) {
	    trackControls[i] = new ProcTControl(this, tracks[i], 
				source.getOutputConnector(names[i]));
	}

	if (!doConfigure2())
	    return false;

	// By default a Processor generates RAW output.
	outputContentDes = new ContentDescriptor(ContentDescriptor.RAW);

	// The parser disables the hint tracks by default.  We'll 
	// re-enable them.
	reenableHintTracks();

	return true;
    
protected synchronized booleandoPrefetch()
The stub function to perform the steps to prefetch the controller.

return
true if successful.


                         
        

	if (prefetched)
	    return true;

	if (!doPrefetch1())
	    return false;

	// Fail if the mux module cannot be prefetched.
	if (muxModule != null && !muxModule.doPrefetch()) {
	    Log.error(prefetchError);
	    Log.error("  Cannot prefetch the multiplexer: " + 
			muxModule.getMultiplexer() + "\n");
	    return false;
	}

	return doPrefetch2();
    
protected synchronized booleandoRealize()

return
true if successful.


	// Reset the target multiplexers
	targetMuxes = null;

	if (!super.doRealize1())
	    return false;

	// Connect the tracks to a multiplexer, if there's one.
	if (targetMux != null && !connectMux()) {
	    Log.error(realizeError);
	    Log.error("  Cannot connect the multiplexer\n");
	    player.processError = genericProcessorError;
	    return false;
	}

	if (!super.doRealize2())
	    return false;

	return true;
    
protected synchronized voiddoStart()
Start immediately. Invoked from start(tbt) when the scheduled start time is reached. Use the public start(tbt) method for the public interface. Override this to implement subclass behavior.


	if (started) return;

	doStart1();

	if (muxModule != null)
	    muxModule.doStart();

	doStart2();
    
protected synchronized voiddoStop()
Invoked from stop(). Override this to implement subclass behavior.

	if (!started) return;

	doStop1();

	if (muxModule != null)
	    muxModule.doStop();

	doStop2();
    
protected com.sun.media.BasicSinkModulefindMasterSink()
Search and update the master time base.


	// Obtain a master time base from one of its SinkModules.

	if (muxModule != null && muxModule.getClock() != null) {
	    return muxModule;
	}

	return super.findMasterSink();
    
protected longgetBitRate()
Report the output bit rate if a mux is used.

	if (muxModule != null)
	    return muxModule.getBitsWritten();
	else
	    return source.getBitsRead();
    
public javax.media.protocol.ContentDescriptorgetContentDescriptor()
Return the output content-type.

	if (getState() < Configured)
	    throwError(new NotConfiguredError("getContentDescriptor " + 
					NOT_CONFIGURED_ERROR));
	return outputContentDes;
    
public javax.media.protocol.DataSourcegetDataOutput()
Return the output DataSource of the Processor.

	if (getState() < Controller.Realized)
	    throwError(new NotRealizedError("getDataOutput " + 
					NOT_REALIZED_ERROR));
	if (muxModule != null)
	    return muxModule.getDataOutput();
	else
	    return null;
    
com.sun.media.BasicMuxModulegetMuxModule()

	return muxModule;
    
protected javax.media.PlugIngetPlugIn(com.sun.media.BasicModule m)
Get the plugin from a module. For debugging.


	if (m instanceof BasicMuxModule)
	    return ((BasicMuxModule)m).getMultiplexer();

	return super.getPlugIn(m);
    
public javax.media.protocol.ContentDescriptor[]getSupportedContentDescriptors()
Return all the content-types which this Processor's output supports.

	if (getState() < Configured)
	    throwError(new NotConfiguredError("getSupportedContentDescriptors " + 
					NOT_CONFIGURED_ERROR));
	Vector names = PlugInManager.getPlugInList(null,
					null, PlugInManager.MULTIPLEXER);
	Vector fmts = new Vector();
	Format fs[];
	int i, j, k;
	boolean duplicate;

	for (i = 0; i < names.size(); i++) {
	    fs = PlugInManager.getSupportedOutputFormats(
					(String)names.elementAt(i),
					PlugInManager.MULTIPLEXER);
	    if (fs == null)
		continue;
	    for (j = 0; j < fs.length; j++) {
		if (!(fs[j] instanceof ContentDescriptor))
		   continue;
		duplicate = false;
		for (k = 0; k < fmts.size(); k++) {
		    if (fmts.elementAt(k).equals(fs[j])) {
			duplicate = true;
			break;
		    }
		}
		if (!duplicate)
		    fmts.addElement(fs[j]);
	    }
	}

	ContentDescriptor cds[] = new ContentDescriptor[fmts.size()];

	for (i = 0; i < fmts.size(); i++)
	    cds[i] = (ContentDescriptor)fmts.elementAt(i);

	return cds;
    
public javax.media.control.TrackControl[]getTrackControls()
Get the track controls.

	if (getState() < Configured)
	    throwError(new NotConfiguredError("getTrackControls " + NOT_CONFIGURED_ERROR));
	return trackControls;
    
booleanisRTPFormat(javax.media.Format fmt)
Return true if the given format is RTP related.

	return fmt != null && fmt.getEncoding() != null && 
		fmt.getEncoding().endsWith("rtp") || 
		fmt.getEncoding().endsWith("RTP");
    
voidreenableHintTracks()

	for (int i = 0; i < trackControls.length; i++) {
	    if (isRTPFormat(trackControls[i].getOriginalFormat())) {
		trackControls[i].setEnabled(true);
		break;
	    }
	}
    
protected voidresetBitRate()

	if (muxModule != null)
	    muxModule.resetBitsWritten();
	else
	    source.resetBitsRead();
    
public javax.media.protocol.ContentDescriptorsetContentDescriptor(javax.media.protocol.ContentDescriptor ocd)
Set the output content-type.


	if (getState() < Configured)
	    throwError(new NotConfiguredError("setContentDescriptor " + 
					NOT_CONFIGURED_ERROR));

	if (getState() > Configured)
	    return null;

	if (ocd != null) {
	    Vector cnames = PlugInManager.getPlugInList(null,
				ocd, PlugInManager.MULTIPLEXER);

	    if (cnames == null || cnames.size() == 0)
		return null;
	}

	outputContentDes = ocd;

	return outputContentDes;