FileDocCategorySizeDatePackage
BasicVideoRenderer.javaAPI DocJMF 2.1.1e8809Mon May 12 12:20:48 BST 2003com.sun.media.renderer.video

BasicVideoRenderer

public abstract class BasicVideoRenderer extends BasicPlugIn implements VideoRenderer, FrameGrabbingControl
A base implementation for a VideoRenderer
since
JMF 2.0

Fields Summary
protected String
name
Variables and Constants
protected transient VideoFormat[]
supportedFormats
protected VideoFormat
inputFormat
protected int
outWidth
protected int
outHeight
protected int
inWidth
protected int
inHeight
protected Component
component
protected ComponentListener
compListener
protected boolean
componentAvailable
protected Rectangle
bounds
protected boolean
started
protected Control[]
controls
protected FrameGrabbingControl
frameGrabber
protected ExtBuffer
lastBuffer
protected Object
lastData
protected Object
lastHdr
Constructors Summary
public BasicVideoRenderer(String name)
Constructor


          
    
       
	this.name = name;
    
Methods Summary
public voidclose()
Closes the plug-in component and releases resources. No more data will be accepted by the plug-in after a call to this method. The plug-in can be reinstated after being closed by calling open.

	// sub class can override
    
protected abstract intdoProcess(javax.media.Buffer buffer)

public java.awt.RectanglegetBounds()
Returns the region in the component where the video will be rendered to. Returns null if the entire component is being used.

	return bounds;
    
public java.awt.ComponentgetComponent()
Returns an AWT component that it will render to. Returns null if it is not rendering to an AWT component.

	if (component == null) {
	    // TODO: Try MSHeavyComponent for MS VM
	    try {
		Class mshc = Class.forName("com.sun.media.renderer.video.MSHeavyComponent");
		if (mshc != null)
		    component = (Component) mshc.newInstance();
	    } catch (Throwable t) {
		component = new HeavyComponent();
	    }
	    ((HeavyComponent)component).setRenderer( this );
	    component.setBackground(getPreferredBackground());
	    if (compListener == null)
		compListener = new CompListener();
	    component.addComponentListener(compListener);
	}
	return component;
    
public java.awt.ComponentgetControlComponent()

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

	if (controls != null)
	    return controls;

	frameGrabber = (FrameGrabbingControl) this;
	controls = new Control[1];
	controls[0] = frameGrabber;
	return controls;
    
public java.lang.StringgetName()
Returns a descriptive name for the plug-in. This is a user readable string.

	return name;
    
protected java.awt.ColorgetPreferredBackground()
Local methods

	return Color.black;
    
public javax.media.Format[]getSupportedInputFormats()
Lists the possible input formats supported by this plug-in.

	return supportedFormats;
    
public javax.media.BuffergrabFrame()

	synchronized (lastBuffer) {
	    Buffer newBuffer = new Buffer();
	    newBuffer.setFormat(lastBuffer.getFormat());
	    newBuffer.setFlags(lastBuffer.getFlags());
	    newBuffer.setLength(lastBuffer.getLength());
	    newBuffer.setOffset(0);
	    newBuffer.setHeader(lastBuffer.getHeader());
	    newBuffer.setData(lastBuffer.getData());
	    
	    Object data = lastBuffer.getData();
	    int length = lastBuffer.getLength();
	    Object newData;
	    if (data instanceof byte[])
		newData = new byte[length];
	    else if (data instanceof short[])
		newData = new short[length];
	    else if (data instanceof int[])
		newData = new int[length];
	    else
		return newBuffer;
	    System.arraycopy(data, lastBuffer.getOffset(),
			     newData, 0,
			     length);
	    newBuffer.setData(newData);
	    return newBuffer;
	}
    
protected booleanisStarted()

	return started;
    
protected java.awt.DimensionmyPreferredSize()

	return new Dimension(inWidth, inHeight);
    
public voidopen()
Opens the plug-in software or hardware component and acquires necessary resources. If all the needed resources could not be acquired, it throws a ResourceUnavailableException. Data should not be passed into the plug-in without first calling this method.

	// sub class can override
    
public intprocess(javax.media.Buffer inbuffer)


	if (inbuffer.getLength() == 0)
	    return BUFFER_PROCESSED_OK;

	int result;
	//System.err.println("BasicVideoRenderer.process() not implemented");
	synchronized (lastBuffer) {
	    result = doProcess(inbuffer);
	    // Keep the last buffer
	    if (  result == BUFFER_PROCESSED_OK ) {
		lastBuffer.copy(inbuffer, true);
	    }
	}
	return result;
    
protected voidremovingComponent()

    
protected voidrepaint()

	System.err.println("repaint call not implemented on this renderer");
    
public voidreset()
Resets the state of the plug-in. Typically at end of media or when media is repositioned.

	// sub class can override
    
voidresized(java.awt.Component c)

	if (c != null && c == component) {
	    Dimension d = component.getSize();
	    outWidth = d.width;
	    outHeight = d.height;
	    //repaint();
	}
    
protected synchronized voidsetAvailable(boolean on)

	componentAvailable = on;
	if (!componentAvailable)
	    removingComponent();
    
public voidsetBounds(java.awt.Rectangle rect)
Sets the region in the component where the video is to be rendered to. Video is to be scaled if necessary. If rect is null, then the video occupies the entire component.

	bounds = rect;
    
public synchronized booleansetComponent(java.awt.Component comp)
Requests the renderer to draw into a specified AWT component. Returns false if the renderer cannot draw into the specified component.

	reset();
	component = comp;
	if (compListener == null)
	    compListener = new CompListener();
	component.addComponentListener(compListener);
	return true;
    
public javax.media.FormatsetInputFormat(javax.media.Format format)
Set the data input format.

return
null if the format is not supported.

	if (matches(format, supportedFormats) != null) {
	    inputFormat = (VideoFormat) format;
	    Dimension size = inputFormat.getSize();
	    if (size != null) {
		inWidth = size.width;
		inHeight = size.height;
	    }
	    return format;
	} else
	    return null;
    
public voidstart()

	started = true;
    
public voidstop()

	started = false;