FileDocCategorySizeDatePackage
SunRayRenderer.javaAPI DocJMF 2.1.1e10970Mon May 12 12:21:24 BST 2003com.sun.media.renderer.video

SunRayRenderer

public class SunRayRenderer extends BasicVideoRenderer implements DynamicPlugIn

Fields Summary
private static boolean
available
private static int
jawtAvail
private static boolean
debug
private int
blitter
protected Object
data
private int
offsetX
private int
offsetY
private int
yuvType
private int
yOff
private int
uOff
private int
vOff
private int
yStride
private int
uvStride
private int
lastOutWidth
private int
lastOutHeight
private boolean
firstTime
private EventThread
xeventThread
Constructors Summary
public SunRayRenderer()

    
        
        
        
         
           
						        
						      
						      
           
         
        
        

     
	if (debug) {
	    System.err.println("SunRayRenderer static entered");
	}
	try {
	    Object jmfSecurity = JMFSecurityManager.getJMFSecurity();
	    if (jmfSecurity != null &&
    jmfSecurity.getClass().getName().equals("com.sun.media.NetscapeSecurity")) {
		// Netscape only supports green threads and libutmedia
		// uses pthread_mutex so requires native threads.
		if (debug) {
		    System.err.println("SunRayRenderer under Netscape");
		}
		available = false;
	    } else {
		// avoid load failed messages on non-SunRay systems.
		// Note: doesn't work if Sun Ray server installed in
		// non-standard directory.
		File lib = new File("/opt/SUNWut/lib/libutmedia.so");
		if (lib.exists()) {
		    JMFSecurityManager.loadLibrary("jmutil");
		    JMFSecurityManager.loadLibrary("jmsunray");
		    available = true;
		} else {
		    if (debug) {
			System.err.println("SunRayRenderer no libutmedia");
		    }
		    available = false;
		}
	    }
	} catch (UnsatisfiedLinkError ule) {
	    if (debug) {
		System.err.println("SunRayRenderer load libjmsunray failed");
	    }
	    available = false;
	} catch (SecurityException se) {
	    if (debug) {
		System.err.println("SunRayRenderer security exception");
	    }
	    available = false;
	} catch (NullPointerException npe) {
	    if (debug) {
		System.err.println("SunRayRenderer null pointer exception");
	    }
	    available = false;
	} catch (Exception e) {
	    System.err.println("SunRayRenderer exception: " + e);
	    e.printStackTrace();
	    available = false;
	}
    
	super("SunRay Renderer");
	if (debug) {
	    System.err.println("SunRayRenderer <init>() entered");
	}
	supportedFormats = new VideoFormat[] {
				new YUVFormat(YUVFormat.YUV_411),
				new YUVFormat(YUVFormat.YUV_420),
				new YUVFormat(YUVFormat.YUV_422),
				new YUVFormat(YUVFormat.YUV_111)
	};
	if (!available) {
//	    throw new RuntimeException("Could not load jmsunray library");
	    return;
	}

	srSetJAWT(jawtAvail);

	if (!srDisplayIsSunRay()) {
	    if (debug) {
		System.err.println("SunRayRenderer display is not a Sun Ray ");
	    }
	    available = false;
//	    throw new RuntimeException("Display is not a Sun Ray");
	    return;
	}
	if (!srInitialize()) {
	    available = false;
	}
	if (debug) {
	    System.err.println("SunRayRenderer <init>() completed");
	}
    
Methods Summary
public synchronized voidclose()

	if (debug) {
	    System.err.println("SunRayRenderer close() entered");
	}
	if (xeventThread != null) {
	    xeventThread.stopChecking();
	    xeventThread.interrupt();
	    while (xeventThread.isAlive()) {
		try {
		    Thread.currentThread().sleep(5);
		} catch (InterruptedException ex) {
		}
	    }
	    xeventThread = null;
	}
	if (available && blitter != 0)
	    srFree();
	if (debug) {
	    System.err.println("SunRayRenderer close() complete");
	}
    
protected intdoProcess(javax.media.Buffer buffer)

	return doProcess(buffer, false);
    
protected intdoProcess(javax.media.Buffer buffer, boolean repaint)

//	if (debug) {
//	    System.err.println("SunRayRenderer doProcess() entered");
//	}
	if (!available || component == null)
	    return BUFFER_PROCESSED_OK;
	synchronized (this) {
	    if (!componentAvailable)
		return BUFFER_PROCESSED_OK;
	    if (blitter == 0 || firstTime) {
		firstTime = false;
		if (blitter == 0)
		    srInitialize();
		int handle = com.sun.media.util.WindowUtil.getWindowHandle(component);
		if (handle != 0) {
		    srSetComponent(component);
		    // Reset it to force calling setInputFormat
		    inputFormat = new VideoFormat(null);
		}
		if (blitter == 0) {
		    if (debug) {
			System.err.println("Could not create blitter");
		    }
		    return BUFFER_PROCESSED_FAILED;
		}
	    }

	    if (!repaint) {
		if (!buffer.getFormat().equals(inputFormat)) {
		    if (setInputFormat(buffer.getFormat()) == null)
			return BUFFER_PROCESSED_FAILED;
		}
		
		data = buffer.getData();
	    } else
		if (data == null)
		    return BUFFER_PROCESSED_FAILED;
	    
	    if (outWidth > 0 && outHeight > 0) {
		if (outWidth != lastOutWidth || outHeight != lastOutHeight) {
		    outWidth &= ~1;
		    lastOutWidth = outWidth;
		    lastOutHeight = outHeight;
		    
		    srSetOutputSize(outWidth, outHeight);
		    if (debug) {
			System.err.println("SunRayRenderer srSetOutputSize() "
					+ outWidth + "x" + outHeight);
		    }
		}
		return (srDraw(data))?
		    BUFFER_PROCESSED_OK : BUFFER_PROCESSED_FAILED;
	    } else
		return BUFFER_PROCESSED_FAILED;
	}
    
public javax.media.Format[]getBaseInputFormats()

	if (debug) {
	    System.err.println("SunRayRenderer getBaseInputFormats() entered");
	}
	Format [] formats = new Format[1];
	formats[0] = new YUVFormat();
	return formats;
    
public javax.media.Format[]getBaseOutputFormats()

	if (debug) {
	    System.err.println("SunRayRenderer getBaseOutputFormats() entered");
	}
	Format [] formats = new Format[0];
	return formats;
    
public voidopen()


	if (debug) {
	    System.err.println("SunRayRenderer open() entered");
	}
	if (!available) {
	    if (debug) {
		System.err.println("SunRayRenderer Sun Ray not available");
	    }
	    throw new ResourceUnavailableException("Sun Ray not available");
	}
    
protected synchronized voidremovingComponent()

	if (debug) {
	    System.err.println("SunRayRenderer removingComponent() entered");
	}
	if (blitter != 0) {
	    srFree();
	}
    
protected synchronized voidrepaint()

	if (debug) {
	    System.err.println("SunRayRenderer repaint() entered");
	}
	if (!isStarted() && data != null)
	    doProcess(null, true);
    
public voidreset()

    
protected voidsetAvailable(boolean on)

	if (debug) {
	    System.err.println("SunRayRenderer setAvailable() entered");
	}
	Thread xevt = null;
	super.setAvailable(on);
	synchronized (this) {
	    if (on) {
		if (xeventThread == null) {
		    xeventThread = new EventThread(this);
		    xeventThread.start();
		}
	    } else {
		if (xeventThread != null) {
		    xeventThread.stopChecking();
		    xeventThread.interrupt();
		    xevt = xeventThread;
		    xeventThread = null;
		    data = null;
		}
	    }
	}
	// wait for the thread to end outside the synchronized block
	// to avoid a deadlock
	if (xevt != null) {
	    while (xevt.isAlive()) {
		try {
		    Thread.currentThread().sleep(5);
		} catch (InterruptedException ex) {
		}
	    }
	}
    
public javax.media.FormatsetInputFormat(javax.media.Format format)
Set the data input format.

return
false if the format is not supported.

	if (debug) {
	    System.err.println("SunRayRenderer setInputFormat() entered");
	}
	if (!available) {
	    if (debug) {
		System.err.println("SunRayRenderer setInputFormat !available");
	    }
	    return null;
	}

	if (!(format instanceof YUVFormat))
	    return null;
	if (super.setInputFormat(format) != null) {
	    if (inputFormat instanceof YUVFormat) {
		YUVFormat yuvf = (YUVFormat) inputFormat;
		yuvType = yuvf.getYuvType();
		yOff = yuvf.getOffsetY();
		uOff = yuvf.getOffsetU();
		vOff = yuvf.getOffsetV();
		yStride = yuvf.getStrideY();
		uvStride = yuvf.getStrideUV();
	    } else
		return null;

	    int subx = 4;	// assume 411
	    int suby = 4;
	    if (yuvType == YUVFormat.YUV_422) {
		subx = 2;
	        suby = 2;
	    } else if (yuvType == YUVFormat.YUV_111) {
		subx = 1;
		suby = 1;
	    } else if (yuvType == YUVFormat.YUV_420) {
		subx = 2;
	        suby = 2;
	    }

	    // Inform the native code of the input format change
	    srSetInputFormat(inWidth, inHeight,
				yOff, uOff, vOff,
				yStride, uvStride,
				subx, suby);
	    
	    if (outWidth == -1 || outHeight == -1) {
		outWidth = inWidth;
		outHeight = inHeight;
	    }

	    if (component != null)
		component.setSize(outWidth, outHeight);
	    // All's well
	    if (debug) {
		System.err.println("SunRayRenderer setInputFormat() returned "
								+ format);
	    }
	    return format;
	} else {
	    // Unsupported format
	    return null;
	}
    
private native synchronized booleansrDisplayIsSunRay()

private native synchronized booleansrDraw(java.lang.Object data)

private native synchronized booleansrEventCheck()

private native synchronized booleansrFree()

private native synchronized booleansrInitialize()

private native synchronized booleansrSetComponent(java.lang.Object component)

private native synchronized booleansrSetInputFormat(int width, int height, int offY, int offU, int offV, int strideY, int strideUV, int subX, int subY)

private native voidsrSetJAWT(int jawt)

private native synchronized booleansrSetOutputSize(int width, int height)