From 3a26aa701b4a1a0991cd997a0d295a1b83cd12f3 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Mon, 9 Apr 2012 04:49:41 +0200 Subject: GLMediaPlayer*: Revised - Working on buggy MediaPlayer impl. (Android ICS Tegra) GLMediaPlayer: Merging 'initStream()' and 'initGL()' to 'initGLStream()' due to incompatible/buggy implementations (Android/Tegra) requiring the GL texture being setup before preparing the stream. This also implies that w/o an GL context we cannot fetch the stream information (size, ..) hence we need to evaluate this detail (FIXME). 'getNextTexture(GL gl, boolean blocking)' can request the impl. to block GLMediaEventListener: The TextureFrame not yet available, adding 'when' --- .../jogamp/opengl/av/EGLMediaPlayerImpl.java | 22 ++-- .../jogamp/opengl/av/GLMediaPlayerImpl.java | 135 ++++++++++----------- .../jogamp/opengl/av/NullGLMediaPlayer.java | 21 ++-- 3 files changed, 90 insertions(+), 88 deletions(-) (limited to 'src/jogl/classes/jogamp/opengl/av') diff --git a/src/jogl/classes/jogamp/opengl/av/EGLMediaPlayerImpl.java b/src/jogl/classes/jogamp/opengl/av/EGLMediaPlayerImpl.java index abc5d5912..2f6744fc5 100644 --- a/src/jogl/classes/jogamp/opengl/av/EGLMediaPlayerImpl.java +++ b/src/jogl/classes/jogamp/opengl/av/EGLMediaPlayerImpl.java @@ -27,8 +27,11 @@ */ package jogamp.opengl.av; -import javax.media.opengl.GLContext; +import java.nio.IntBuffer; +import javax.media.opengl.GL; + +import com.jogamp.common.nio.Buffers; import com.jogamp.opengl.util.texture.Texture; import jogamp.opengl.egl.EGL; @@ -80,22 +83,23 @@ public abstract class EGLMediaPlayerImpl extends GLMediaPlayerImpl { } @Override - protected TextureFrame createTexImage(GLContext ctx, int idx, int[] tex) { - final Texture texture = super.createTexImageImpl(ctx, idx, tex, true); + protected TextureFrame createTexImage(GL gl, int idx, int[] tex) { + final Texture texture = super.createTexImageImpl(gl, idx, tex, true); final long image; final long sync; - final EGLContext eglCtx = (EGLContext) ctx; + final EGLContext eglCtx = (EGLContext) gl.getContext(); final EGLExt eglExt = eglCtx.getEGLExt(); final EGLDrawable eglDrawable = (EGLDrawable) eglCtx.getGLDrawable(); int[] tmp = new int[1]; + IntBuffer nioTmp = Buffers.newDirectIntBuffer(1); if(TextureType.KHRImage == texType) { // create EGLImage from texture - tmp[0] = EGL.EGL_NONE; + nioTmp.put(0, EGL.EGL_NONE); image = eglExt.eglCreateImageKHR( eglDrawable.getDisplay(), eglCtx.getHandle(), EGLExt.EGL_GL_TEXTURE_2D_KHR, - tex[idx], tmp, 0); + null /* buffer */, nioTmp); if (0==image) { throw new RuntimeException("EGLImage creation failed: "+EGL.eglGetError()+", ctx "+eglCtx+", tex "+tex[idx]+", err "+toHexString(EGL.eglGetError())); } @@ -119,8 +123,8 @@ public abstract class EGLMediaPlayerImpl extends GLMediaPlayerImpl { } @Override - protected void destroyTexImage(GLContext ctx, TextureFrame imgTex) { - final EGLContext eglCtx = (EGLContext) ctx; + protected void destroyTexImage(GL gl, TextureFrame imgTex) { + final EGLContext eglCtx = (EGLContext) gl.getContext(); final EGLExt eglExt = eglCtx.getEGLExt(); final EGLDrawable eglDrawable = (EGLDrawable) eglCtx.getGLDrawable(); final EGLTextureFrame eglTex = (EGLTextureFrame) imgTex; @@ -131,6 +135,6 @@ public abstract class EGLMediaPlayerImpl extends GLMediaPlayerImpl { if(0!=eglTex.getSync()) { eglExt.eglDestroySyncKHR(eglDrawable.getDisplay(), eglTex.getSync()); } - super.destroyTexImage(ctx, imgTex); + super.destroyTexImage(gl, imgTex); } } diff --git a/src/jogl/classes/jogamp/opengl/av/GLMediaPlayerImpl.java b/src/jogl/classes/jogamp/opengl/av/GLMediaPlayerImpl.java index f6fc20afe..acd707288 100644 --- a/src/jogl/classes/jogamp/opengl/av/GLMediaPlayerImpl.java +++ b/src/jogl/classes/jogamp/opengl/av/GLMediaPlayerImpl.java @@ -34,7 +34,6 @@ import java.util.HashMap; import java.util.Iterator; import javax.media.opengl.GL; -import javax.media.opengl.GLContext; import javax.media.opengl.GLES2; import javax.media.opengl.GLException; @@ -59,6 +58,7 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { protected State state; protected int textureCount; protected int textureTarget; + protected int texUnit; protected int[] texMinMagFilter = { GL.GL_NEAREST, GL.GL_NEAREST }; protected int[] texWrapST = { GL.GL_CLAMP_TO_EDGE, GL.GL_CLAMP_TO_EDGE }; @@ -67,35 +67,39 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { protected float playSpeed = 1.0f; - /** Shall be set by the {@link #initStreamImplPreGL()} method implementation. */ + /** Shall be set by the {@link #initGLStreamImpl(GL, int[])} method implementation. */ protected int width = 0; - /** Shall be set by the {@link #initStreamImplPreGL()} method implementation. */ + /** Shall be set by the {@link #initGLStreamImpl(GL, int[])} method implementation. */ protected int height = 0; - /** Shall be set by the {@link #initStreamImplPreGL()} method implementation. */ + /** Shall be set by the {@link #initGLStreamImpl(GL, int[])} method implementation. */ protected int fps = 0; - /** Shall be set by the {@link #initStreamImplPreGL()} method implementation. */ + /** Shall be set by the {@link #initGLStreamImpl(GL, int[])} method implementation. */ protected long bps = 0; - /** In frames. Shall be set by the {@link #initStreamImplPreGL()} method implementation. */ + /** In frames. Shall be set by the {@link #initGLStreamImpl(GL, int[])} method implementation. */ protected long totalFrames = 0; - /** In ms. Shall be set by the {@link #initStreamImplPreGL()} method implementation. */ + /** In ms. Shall be set by the {@link #initGLStreamImpl(GL, int[])} method implementation. */ protected long duration = 0; - /** Shall be set by the {@link #initStreamImplPreGL()} method implementation. */ + /** Shall be set by the {@link #initGLStreamImpl(GL, int[])} method implementation. */ protected String acodec = null; - /** Shall be set by the {@link #initStreamImplPreGL()} method implementation. */ + /** Shall be set by the {@link #initGLStreamImpl(GL, int[])} method implementation. */ protected String vcodec = null; protected long frameNumber = 0; - private TextureFrame[] texFrames = null; + protected TextureFrame[] texFrames = null; protected HashMap texFrameMap = new HashMap(); private ArrayList eventListeners = new ArrayList(); protected GLMediaPlayerImpl() { this.textureCount=3; this.textureTarget=GL.GL_TEXTURE_2D; - this.state = State.UninitializedStream; + this.texUnit = 0; + this.state = State.Uninitialized; } + public void setTextureUnit(int u) { texUnit = u; } + public int getTextureUnit() { return texUnit; } + protected final void setTextureCount(int textureCount) { this.textureCount=textureCount; } @@ -162,20 +166,47 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { public final State getState() { return state; } @Override - public final State initStream(URLConnection urlConn) throws IllegalStateException, IOException { - if(State.UninitializedStream != state) { - throw new IllegalStateException("Instance not in state "+State.UninitializedStream+", but "+state+", "+this); + public State initGLStream(GL gl, URLConnection urlConn) throws IllegalStateException, GLException, IOException { + if(State.Uninitialized != state) { + throw new IllegalStateException("Instance not in state "+State.Uninitialized+", but "+state+", "+this); } this.urlConn = urlConn; if (this.urlConn != null) { - initStreamImplPreGL(); - state = State.UninitializedGL; + try { + if(null!=texFrames) { + removeAllImageTextures(gl); + } else { + texFrames = new TextureFrame[textureCount]; + } + + final int[] tex = new int[textureCount]; + { + gl.glGenTextures(textureCount, tex, 0); + final int err = gl.glGetError(); + if( GL.GL_NO_ERROR != err ) { + throw new RuntimeException("TextureNames creation failed (num: "+textureCount+"): err "+toHexString(err)); + } + } + initGLStreamImpl(gl, tex); + + for(int i=0; i tex[idx] ) { throw new RuntimeException("TextureName "+toHexString(tex[idx])+" invalid."); } @@ -272,16 +264,16 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { mustFlipVertically); } - protected void destroyTexImage(GLContext ctx, TextureFrame imgTex) { - imgTex.getTexture().destroy(ctx.getGL()); + protected void destroyTexImage(GL gl, TextureFrame imgTex) { + imgTex.getTexture().destroy(gl); } - protected void removeAllImageTextures(GLContext ctx) { + protected void removeAllImageTextures(GL gl) { if(null != texFrames) { for(int i=0; i i = eventListeners.iterator(); i.hasNext(); ) { - i.next().attributesChanges(this, event_mask); + i.next().attributesChanges(this, event_mask, System.currentTimeMillis()); } } } - protected void newFrameAvailable(TextureFrame frame) { + protected void newFrameAvailable() { frameNumber++; synchronized(eventListenersLock) { for(Iterator i = eventListeners.iterator(); i.hasNext(); ) { - i.next().newFrameAvailable(this, frame); + i.next().newFrameAvailable(this, System.currentTimeMillis()); } } } @@ -313,8 +305,8 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { @Override public synchronized State destroy(GL gl) { destroyImpl(gl); - removeAllImageTextures(gl.getContext()); - state = State.UninitializedStream; + removeAllImageTextures(gl); + state = State.Uninitialized; return state; } protected abstract void destroyImpl(GL gl); @@ -367,7 +359,8 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { @Override public synchronized String toString() { final float ct = getCurrentPosition() / 1000.0f, tt = getDuration() / 1000.0f; - return "GLMediaPlayer ["+state+", "+frameNumber+"/"+totalFrames+" frames, "+ct+"/"+tt+"s, stream [video ["+vcodec+", "+width+"x"+height+", "+fps+"fps, "+bps+"bsp], "+urlConn.getURL().toExternalForm()+"]]"; + final String loc = ( null != urlConn ) ? urlConn.getURL().toExternalForm() : "" ; + return "GLMediaPlayer ["+state+", "+frameNumber+"/"+totalFrames+" frames, "+ct+"/"+tt+"s, stream [video ["+vcodec+", "+width+"x"+height+", "+fps+"fps, "+bps+"bsp], "+loc+"]]"; } @Override diff --git a/src/jogl/classes/jogamp/opengl/av/NullGLMediaPlayer.java b/src/jogl/classes/jogamp/opengl/av/NullGLMediaPlayer.java index c7eb2722c..a5d41bc9c 100644 --- a/src/jogl/classes/jogamp/opengl/av/NullGLMediaPlayer.java +++ b/src/jogl/classes/jogamp/opengl/av/NullGLMediaPlayer.java @@ -32,7 +32,6 @@ import java.net.URLConnection; import java.nio.ByteBuffer; import javax.media.opengl.GL; -import javax.media.opengl.GLContext; import javax.media.opengl.GLProfile; import jogamp.opengl.av.GLMediaPlayerImpl; @@ -40,6 +39,7 @@ import jogamp.opengl.av.GLMediaPlayerImpl; import com.jogamp.common.nio.Buffers; import com.jogamp.common.util.IOUtil; import com.jogamp.opengl.util.texture.Texture; +import com.jogamp.opengl.util.texture.TextureCoords; import com.jogamp.opengl.util.texture.TextureData; import com.jogamp.opengl.util.texture.TextureIO; @@ -96,10 +96,15 @@ public class NullGLMediaPlayer extends GLMediaPlayerImpl { } @Override - public TextureFrame getNextTexture() { + public TextureFrame getNextTexture(GL gl, boolean blocking) { return frame; } + @Override + public TextureCoords getTextureCoords() { + return frame.getTexture().getImageTexCoords(); + } + @Override public long getCurrentPosition() { pos_ms = System.currentTimeMillis() - pos_start; @@ -112,7 +117,7 @@ public class NullGLMediaPlayer extends GLMediaPlayerImpl { } @Override - protected void initStreamImplPreGL() throws IOException { + protected void initGLStreamImpl(GL gl, int[] texNames) throws IOException { try { URLConnection urlConn = IOUtil.getResource("jogl/util/data/av/test-ntsc01-160x90.png", NullGLMediaPlayer.class.getClassLoader()); if(null != urlConn) { @@ -146,15 +151,15 @@ public class NullGLMediaPlayer extends GLMediaPlayerImpl { } @Override - protected void destroyTexImage(GLContext ctx, TextureFrame imgTex) { - super.destroyTexImage(ctx, imgTex); + protected void destroyTexImage(GL gl, TextureFrame imgTex) { + super.destroyTexImage(gl, imgTex); } @Override - protected TextureFrame createTexImage(GLContext ctx, int idx, int[] tex) { - Texture texture = super.createTexImageImpl(ctx, idx, tex, false); + protected TextureFrame createTexImage(GL gl, int idx, int[] tex) { + Texture texture = super.createTexImageImpl(gl, idx, tex, false); if(null != texData) { - texture.updateImage(ctx.getGL(), texData); + texture.updateImage(gl, texData); } frame = new TextureFrame( texture ); return frame; -- cgit v1.2.3