FileDocCategorySizeDatePackage
BasicTrackControl.javaAPI DocJMF 2.1.1e7213Mon May 12 12:20:50 BST 2003com.sun.media

BasicTrackControl

public class BasicTrackControl extends Object implements TrackControl
Basic track control for use with a Processor or Player.

Fields Summary
static final String
realizeErr
static final String
connectErr
PlaybackEngine
engine
Track
track
OutputConnector
firstOC
OutputConnector
lastOC
protected Vector
modules
protected BasicRendererModule
rendererModule
protected BasicMuxModule
muxModule
protected boolean
prefetchFailed
protected boolean
rendererFailed
float
lastFrameRate
long
lastStatsTime
Constructors Summary
public BasicTrackControl(PlaybackEngine engine, Track track, OutputConnector oc)



         
				  
	this.engine = engine;
  	this.track = track;
	this.firstOC = oc;
	this.lastOC = oc;
	setEnabled(track.isEnabled());
    
Methods Summary
public booleanbuildTrack(int trackID, int numTracks)
Top level routine to build a single track.

	return false;
    
protected javax.media.control.FrameRateControlframeRateControl()

	return null;
    
public java.lang.ObjectgetControl(java.lang.String type)

	Class cls;
	try {
	    // cls = Class.forName(type);
	    cls = BasicPlugIn.getClassForName(type);
	} catch (ClassNotFoundException e) {
	    return null;
	}
	Object cs[] = getControls();
	for (int i = 0; i < cs.length; i++) {
	    if (cls.isInstance(cs[i]))
		return cs[i];
	}
	return null;
    
public java.awt.ComponentgetControlComponent()

	return null;
    
public java.lang.Object[]getControls()

	if (engine.getState() < Controller.Realized)
		throw (new NotRealizedError(realizeErr));

	InputConnector ic;
	OutputConnector oc = firstOC;
	Module m;
	PlugIn p = null;

	Control controls[];
	Vector cv = new Vector();
	Control c;
	Object cs[];
	int i, size;

	while (oc != null && (ic = oc.getInputConnector()) != null) {
	    m = ic.getModule();
	    cs = m.getControls();
	    if (cs != null) {
	        for (i = 0; i < cs.length; i++) {
		    cv.addElement(cs[i]);
	        }
	    }
	    oc = m.getOutputConnector(null);
	}

	size = cv.size();
	controls = new Control[size];
	for (i = 0; i < size; i++)
	    controls[i] = (Control)cv.elementAt(i);

	return controls;
    
public javax.media.FormatgetFormat()

	return track.getFormat();
    
public javax.media.FormatgetOriginalFormat()

	return track.getFormat();
    
public javax.media.Format[]getSupportedFormats()

	return new Format[] {track.getFormat()};
    
public booleanisCustomized()

	return false;
    
public booleanisEnabled()

	return track.isEnabled();
    
public booleanisTimeBase()
Returns true if this track holds the master time base.

	return false;
    
public voidprError()

	Log.error("  Unable to handle format: " + getOriginalFormat());
	Log.write("\n");
    
public booleanprefetchTrack()
Prefetch the modules for this track.

	BasicModule bm;
	for (int j = 0; j < modules.size(); j++) {
	    bm = (BasicModule)modules.elementAt(j);
	    if (!bm.doPrefetch()) {
		setEnabled(false);
		prefetchFailed = true;
		if (bm instanceof BasicRendererModule)
		    rendererFailed = true;
		return false;
	    }
	}
	// If it failed to prefetch before but now it's alright again,
	// we'll re-enable the track.
	if (prefetchFailed) {
	    setEnabled(true);
	    prefetchFailed = false;
	    rendererFailed = false;
	}
	return true;
    
protected com.sun.media.controls.ProgressControlprogressControl()

	return null;
    
public voidsetCodecChain(javax.media.Codec[] codec)

	if (engine.getState() > engine.Configured)
	    throw new NotConfiguredError(connectErr);
	if (codec.length < 1)
	    throw new UnsupportedPlugInException("No codec specified in the array.");
    
public voidsetEnabled(boolean enabled)

	track.setEnabled(enabled);
    
public javax.media.FormatsetFormat(javax.media.Format format)

	if (format != null && format.matches(getFormat()))
		return getFormat();
	return null;
    
public voidsetRenderer(javax.media.Renderer renderer)

	if (engine.getState() > engine.Configured)
	    throw new NotConfiguredError(connectErr);
    
public voidstartTrack()
Start the modules for this track.

	for (int j = 0; j < modules.size(); j++) {
	    ((BasicModule)modules.elementAt(j)).doStart();
	}
    
public voidstopTrack()
Start the modules for this track.

	for (int j = 0; j < modules.size(); j++) {
	    ((BasicModule)modules.elementAt(j)).doStop();
	}
    
public voidupdateFormat()
Update the format per track on the progress control.

	if (!track.isEnabled())
	    return;

	ProgressControl pc;

	if ((pc = progressControl()) == null)
	    return;

	StringControl sc;
	if (track.getFormat() instanceof AudioFormat) {
	    String channel = "";
	    AudioFormat afmt = (AudioFormat)track.getFormat();
	    sc = pc.getAudioCodec();
	    sc.setValue(afmt.getEncoding());
	    sc = pc.getAudioProperties();
	    if (afmt.getChannels() == 1)
		channel = JMFI18N.getResource("mediaengine.mono");
	    else
		channel = JMFI18N.getResource("mediaengine.stereo");
	    sc.setValue(afmt.getSampleRate()/1000.0 +
		JMFI18N.getResource("mediaengine.khz") + ", " +
		afmt.getSampleSizeInBits() +
		JMFI18N.getResource("mediaengine.-bit") + ", " +
		channel);
	}
	if (track.getFormat() instanceof VideoFormat) {
	    VideoFormat vfmt = (VideoFormat)track.getFormat();
	    sc = pc.getVideoCodec();
	    sc.setValue(vfmt.getEncoding());
	    sc = pc.getVideoProperties();
	    if (vfmt.getSize() != null)
		sc.setValue(vfmt.getSize().width + " X " + vfmt.getSize().height);
	}
    
public voidupdateRates(long now)
Update the frame rate per track on the progress control.

  // so now - lastStatsTime will not be 0.

                   
        
	FrameRateControl prc;

	if ((prc = frameRateControl()) == null)
	    return;
	
	if (!track.isEnabled() || 
		!(track.getFormat() instanceof VideoFormat) || 
		(rendererModule == null && muxModule == null))
	    return;

	float rate, avg;

	if (now == lastStatsTime)
	    rate = lastFrameRate;
	else {
	    int framesPlayed;
	    if (rendererModule != null)
		framesPlayed = rendererModule.getFramesPlayed();
	    else
		framesPlayed = muxModule.getFramesPlayed();
	    rate = (float)((float)framesPlayed /
			   (now - lastStatsTime) * 1000.0f);
	}
	avg = (float)((int)(((lastFrameRate + rate)/2) * 10))/10.f;
	prc.setFrameRate(avg);
	lastFrameRate = rate;
	lastStatsTime = now;
	if (rendererModule != null)
	    rendererModule.resetFramesPlayed();
	else
	    muxModule.resetFramesPlayed();