diff options
author | Sven Gothel <[email protected]> | 2012-04-09 04:49:41 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2012-04-09 04:49:41 +0200 |
commit | 3a26aa701b4a1a0991cd997a0d295a1b83cd12f3 (patch) | |
tree | 0bbf0c79127ab8329220e2766177c3073244277b /src/jogl/classes/jogamp | |
parent | 1e61021a062b1403f7eed948ac9d2ea0c04ea951 (diff) |
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'
Diffstat (limited to 'src/jogl/classes/jogamp')
5 files changed, 178 insertions, 157 deletions
diff --git a/src/jogl/classes/jogamp/opengl/android/av/AndroidGLMediaPlayerAPI14.java b/src/jogl/classes/jogamp/opengl/android/av/AndroidGLMediaPlayerAPI14.java index 7e94d3cc5..ae45662db 100644 --- a/src/jogl/classes/jogamp/opengl/android/av/AndroidGLMediaPlayerAPI14.java +++ b/src/jogl/classes/jogamp/opengl/android/av/AndroidGLMediaPlayerAPI14.java @@ -30,9 +30,10 @@ package jogamp.opengl.android.av; import java.io.IOException; import javax.media.opengl.GL; -import javax.media.opengl.GLContext; import javax.media.opengl.GLES2; +import com.jogamp.opengl.util.texture.TextureCoords; + import jogamp.common.os.android.StaticContext; import jogamp.opengl.av.GLMediaPlayerImpl; @@ -42,31 +43,21 @@ import android.media.MediaPlayer; import android.net.Uri; import android.view.Surface; -import com.jogamp.opengl.util.texture.Texture; - /*** * Android API Level 14: {@link MediaPlayer#setSurface(Surface)} * Android API Level 14: {@link Surface#Surface(android.graphics.SurfaceTexture)} */ public class AndroidGLMediaPlayerAPI14 extends GLMediaPlayerImpl { MediaPlayer mp; - boolean updateSurface = false; + volatile boolean updateSurface = false; Object updateSurfaceLock = new Object(); - AndroidTextureFrame atex = null; - - public static class AndroidTextureFrame extends TextureFrame { - public AndroidTextureFrame(Texture t, SurfaceTexture stex) { - super(t); - this.stex = stex; - } - - public final SurfaceTexture getSurfaceTexture() { return stex; } - - public String toString() { - return "AndroidTextureFrame[" + texture + ", "+ stex + "]"; - } - protected SurfaceTexture stex; - } + TextureFrame lastTexFrame = null; + + /** + private static String toString(MediaPlayer m) { + if(null == m) return "<nil>"; + return "MediaPlayer[playing "+m.isPlaying()+", pos "+m.getCurrentPosition()/1000.0f+"s, "+m.getVideoWidth()+"x"+m.getVideoHeight()+"]"; + } */ public AndroidGLMediaPlayerAPI14() { super(); @@ -103,6 +94,7 @@ public class AndroidGLMediaPlayerAPI14 extends GLMediaPlayerImpl { @Override protected boolean pauseImpl() { if(null != mp) { + wakeUp(false); try { mp.pause(); return true; @@ -118,6 +110,7 @@ public class AndroidGLMediaPlayerAPI14 extends GLMediaPlayerImpl { @Override protected boolean stopImpl() { if(null != mp) { + wakeUp(false); try { mp.stop(); return true; @@ -141,24 +134,49 @@ public class AndroidGLMediaPlayerAPI14 extends GLMediaPlayerImpl { @Override public TextureFrame getLastTexture() { - return atex; + return lastTexFrame; } @Override - public TextureFrame getNextTexture() { - if(null != atex && null != mp) { - final boolean _updateSurface; - synchronized(updateSurfaceLock) { - _updateSurface = updateSurface; - updateSurface = false; + public TextureFrame getNextTexture(GL gl, boolean blocking) { + if(null != stex && null != mp) { + // Only block once, no while-loop. + // This relaxes locking code of non crucial resources/events. + boolean update = updateSurface; + if(!update && blocking) { + synchronized(updateSurfaceLock) { + if(!updateSurface) { // volatile OK. + try { + updateSurfaceLock.wait(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + updateSurface = false; + update = true; + } } - if(_updateSurface) { - atex.getSurfaceTexture().updateTexImage(); - // atex.getSurfaceTexture().getTransformMatrix(atex.getSTMatrix()); + if(update) { + stex.updateTexImage(); + // stex.getTransformMatrix(atex.getSTMatrix()); + lastTexFrame=texFrames[0]; } - return atex; - } else { - return null; + + } + return lastTexFrame; + } + + @Override + public TextureCoords getTextureCoords() { + return texFrames[0].getTexture().getImageTexCoords(); + } + + private void wakeUp(boolean newFrame) { + synchronized(updateSurfaceLock) { + if(newFrame) { + updateSurface = true; + } + updateSurfaceLock.notifyAll(); } } @@ -170,13 +188,16 @@ public class AndroidGLMediaPlayerAPI14 extends GLMediaPlayerImpl { @Override protected void destroyImpl(GL gl) { if(null != mp) { + wakeUp(false); mp.release(); mp = null; } } + SurfaceTexture stex = null; + @Override - protected void initStreamImplPreGL() throws IOException { + protected void initGLStreamImpl(GL gl, int[] texNames) throws IOException { if(null!=mp && null!=urlConn) { try { final Uri uri = Uri.parse(urlConn.getURL().toExternalForm()); @@ -188,12 +209,16 @@ public class AndroidGLMediaPlayerAPI14 extends GLMediaPlayerImpl { } catch (IllegalStateException e) { throw new RuntimeException(e); } + stex = new SurfaceTexture(texNames[0]); // only 1 texture + stex.setOnFrameAvailableListener(onFrameAvailableListener); + final Surface surf = new Surface(stex); + mp.setSurface(surf); + surf.release(); try { mp.prepare(); } catch (IOException ioe) { throw new IOException("MediaPlayer failed to process stream <"+urlConn.getURL().toExternalForm()+">: "+ioe.getMessage(), ioe); } - width = mp.getVideoWidth(); height = mp.getVideoHeight(); fps = 0; @@ -206,34 +231,20 @@ public class AndroidGLMediaPlayerAPI14 extends GLMediaPlayerImpl { } @Override - protected void destroyTexImage(GLContext ctx, TextureFrame imgTex) { - final AndroidTextureFrame atf = (AndroidTextureFrame) imgTex; - atf.getSurfaceTexture().release(); - atex = null; - super.destroyTexImage(ctx, imgTex); + protected void destroyTexImage(GL gl, TextureFrame imgTex) { + if(null != stex) { + stex.release(); + stex = null; + } + lastTexFrame = null; + super.destroyTexImage(gl, imgTex); } - @Override - protected TextureFrame createTexImage(GLContext ctx, int idx, int[] tex) { - final Texture texture = super.createTexImageImpl(ctx, idx, tex, true); - - final SurfaceTexture stex = new SurfaceTexture(tex[idx]); - stex.setOnFrameAvailableListener(onFrameAvailableListener); - final Surface surf = new Surface(stex); - mp.setSurface(surf); - surf.release(); - - atex = new AndroidTextureFrame( texture, stex ); - return atex; - } - protected OnFrameAvailableListener onFrameAvailableListener = new OnFrameAvailableListener() { @Override public void onFrameAvailable(SurfaceTexture surfaceTexture) { - synchronized(updateSurfaceLock) { - updateSurface = true; - } - AndroidGLMediaPlayerAPI14.this.newFrameAvailable(atex); + wakeUp(true); + AndroidGLMediaPlayerAPI14.this.newFrameAvailable(); } }; } 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<Integer, TextureFrame> texFrameMap = new HashMap<Integer, TextureFrame>(); private ArrayList<GLMediaEventListener> eventListeners = new ArrayList<GLMediaEventListener>(); 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<textureCount; i++) { + final TextureFrame tf = createTexImage(gl, i, tex); + texFrames[i] = tf; + texFrameMap.put(tex[i], tf); + } + state = State.Stopped; + return state; + } catch (Throwable t) { + throw new GLException("Error initializing GL resources", t); + } } - return state; + return state; } /** - * Implementation shall set the following set of data here or at {@link #setStreamImplPostGL()} + * Implementation shall set the following set of data here + * @param gl TODO + * @param texNames TODO * @see #width * @see #height * @see #fps @@ -184,52 +215,13 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { * @see #acodec * @see #vcodec */ - protected abstract void initStreamImplPreGL() throws IOException; - - @Override - public final State initGL(GL gl) throws IllegalStateException, GLException { - if(State.UninitializedGL != state) { - throw new IllegalStateException("Instance not in state "+State.UninitializedGL+", but "+state+", "+this); - } - final GLContext ctx = gl.getContext(); - if(!ctx.isCurrent()) { - throw new GLException("Not current: "+ctx); - } + protected abstract void initGLStreamImpl(GL gl, int[] texNames) throws IOException; - try { - if(null!=texFrames) { - removeAllImageTextures(ctx); - } 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)); - } - } - - for(int i=0; i<textureCount; i++) { - final TextureFrame tf = createTexImage(ctx, i, tex); - texFrames[i] = tf; - texFrameMap.put(tex[i], tf); - } - state = State.Stopped; - return state; - } catch (Throwable t) { - throw new GLException("Error initializing GL resources", t); - } - } - - protected TextureFrame createTexImage(GLContext ctx, int idx, int[] tex) { - return new TextureFrame( createTexImageImpl(ctx, idx, tex, true) ); + protected TextureFrame createTexImage(GL gl, int idx, int[] tex) { + return new TextureFrame( createTexImageImpl(gl, idx, tex, true) ); } - protected Texture createTexImageImpl(GLContext ctx, int idx, int[] tex, boolean mustFlipVertically) { - final GL gl = ctx.getGL(); + protected Texture createTexImageImpl(GL gl, int idx, int[] tex, boolean mustFlipVertically) { if( 0 > 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<textureCount; i++) { final TextureFrame imgTex = texFrames[i]; if(null != imgTex) { - destroyTexImage(ctx, imgTex); + destroyTexImage(gl, imgTex); texFrames[i] = null; } } @@ -292,15 +284,15 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { protected void attributesUpdated(int event_mask) { synchronized(eventListenersLock) { for(Iterator<GLMediaEventListener> 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<GLMediaEventListener> 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() : "<undefined stream>" ; + 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,11 +96,16 @@ 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; validatePos(); @@ -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; diff --git a/src/jogl/classes/jogamp/opengl/omx/OMXGLMediaPlayer.java b/src/jogl/classes/jogamp/opengl/omx/OMXGLMediaPlayer.java index 99639ae62..7c775dd9f 100644 --- a/src/jogl/classes/jogamp/opengl/omx/OMXGLMediaPlayer.java +++ b/src/jogl/classes/jogamp/opengl/omx/OMXGLMediaPlayer.java @@ -5,10 +5,10 @@ import java.io.IOException; import java.net.URL; import javax.media.opengl.GL; -import javax.media.opengl.GLContext; import javax.media.opengl.GLException; import com.jogamp.opengl.av.GLMediaEventListener; +import com.jogamp.opengl.util.texture.TextureCoords; import jogamp.opengl.av.EGLMediaPlayerImpl; import jogamp.opengl.egl.EGL; @@ -41,16 +41,16 @@ public class OMXGLMediaPlayer extends EGLMediaPlayerImpl { } @Override - protected TextureFrame createTexImage(GLContext ctx, int idx, int[] tex) { - final EGLTextureFrame eglTex = (EGLTextureFrame) super.createTexImage(ctx, idx, tex); + protected TextureFrame createTexImage(GL gl, int idx, int[] tex) { + final EGLTextureFrame eglTex = (EGLTextureFrame) super.createTexImage(gl, idx, tex); _setStreamEGLImageTexture2D(moviePtr, idx, tex[idx], eglTex.getImage(), eglTex.getSync()); lastTex = eglTex; return eglTex; } @Override - protected void destroyTexImage(GLContext ctx, TextureFrame imgTex) { - super.destroyTexImage(ctx, imgTex); + protected void destroyTexImage(GL gl, TextureFrame imgTex) { + super.destroyTexImage(gl, imgTex); } @Override @@ -63,7 +63,7 @@ public class OMXGLMediaPlayer extends EGLMediaPlayerImpl { } @Override - protected void initStreamImplPreGL() throws IOException { + protected void initGLStreamImpl(GL gl, int[] texNames) throws IOException { if(0==moviePtr) { throw new GLException("OMX native instance null"); } @@ -140,17 +140,25 @@ public class OMXGLMediaPlayer extends EGLMediaPlayerImpl { } @Override - public synchronized TextureFrame getNextTexture() { + public synchronized TextureFrame getNextTexture(GL gl, boolean blocking) { if(0==moviePtr) { throw new GLException("OMX native instance null"); } - lastTex=null; - TextureFrame eglImgTex = texFrameMap.get(new Integer(_getNextTextureID(moviePtr))); - if(null!=eglImgTex) { - lastTex = eglImgTex; + final int nextTex = _getNextTextureID(moviePtr, blocking); + if(0 < nextTex) { + final TextureFrame eglImgTex = texFrameMap.get(new Integer(_getNextTextureID(moviePtr, blocking))); + if(null!=eglImgTex) { + lastTex = eglImgTex; + } } return lastTex; } + + @Override + public TextureCoords getTextureCoords() { + return lastTex.getTexture().getImageTexCoords(); + } + protected void attributesUpdated() { int event_mask = 0; @@ -222,7 +230,7 @@ public class OMXGLMediaPlayer extends EGLMediaPlayerImpl { native void _play(long moviePtr); native void _pause(long moviePtr); native void _stop(long moviePtr); - native int _getNextTextureID(long moviePtr); + native int _getNextTextureID(long moviePtr, boolean blocking); native long _getCurrentPosition(long moviePtr); } |