The image stream may come from either video playback or camera preview. A SurfaceTexture may + * be used in place of a SurfaceHolder when specifying the output destination of a MediaPlayer or + * Camera object. This will cause all the frames from that image stream to be sent to the + * SurfaceTexture object rather than to the device's display. When {@link #updateTexImage} is + * called, the contents of the texture object specified when the SurfaceTexture was created is + * updated to contain the most recent image from the image stream. This may cause some frames of + * the stream to be skipped. + * + *
The texture object uses the GL_TEXTURE_EXTERNAL_OES texture target, which is defined by the + * OES_EGL_image_external OpenGL ES extension. This limits how the texture may be used. + */ +public class SurfaceTexture { + + @SuppressWarnings("unused") + private int mSurfaceTexture; + + /** + * Callback interface for being notified that a new stream frame is available. + */ + public interface OnFrameAvailableListener { + void onFrameAvailable(SurfaceTexture surfaceTexture); + } + + /** + * Exception thrown when a surface couldn't be created or resized + */ + public static class OutOfResourcesException extends Exception { + public OutOfResourcesException() { + } + public OutOfResourcesException(String name) { + super(name); + } + } + + /** + * Construct a new SurfaceTexture to stream images to a given OpenGL texture. + * + * @param texName the OpenGL texture object name (e.g. generated via glGenTextures) + */ + public SurfaceTexture(int texName) { + init(texName); + } + + /** + * Register a callback to be invoked when a new image frame becomes available to the + * SurfaceTexture. Note that this callback may be called on an arbitrary thread, so it is not + * safe to call {@link #updateTexImage} without first binding the OpenGL ES context to the + * thread invoking the callback. + */ + public void setOnFrameAvailableListener(OnFrameAvailableListener l) { + // TODO: Implement this! + } + + /** + * Update the texture image to the most recent frame from the image stream. This may only be + * called while the OpenGL ES context that owns the texture is bound to the thread. It will + * implicitly bind its texture to the GL_TEXTURE_EXTERNAL_OES texture target. + */ + public native void updateTexImage(); + + private native void init(int texName); + + /* + * We use a class initializer to allow the native code to cache some + * field offsets. + */ + private static native void nativeClassInit(); + static { nativeClassInit(); } +}