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/GLMediaPlayerImpl.java | 135 ++++++++++----------- 1 file changed, 64 insertions(+), 71 deletions(-) (limited to 'src/jogl/classes/jogamp/opengl/av/GLMediaPlayerImpl.java') 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 -- cgit v1.2.3