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 | |
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')
7 files changed, 227 insertions, 185 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/av/GLMediaEventListener.java b/src/jogl/classes/com/jogamp/opengl/av/GLMediaEventListener.java index a02c8a362..9887a417c 100644 --- a/src/jogl/classes/com/jogamp/opengl/av/GLMediaEventListener.java +++ b/src/jogl/classes/com/jogamp/opengl/av/GLMediaEventListener.java @@ -1,7 +1,7 @@ package com.jogamp.opengl.av; -import com.jogamp.opengl.av.GLMediaPlayer.TextureFrame; +import javax.media.opengl.GL; public interface GLMediaEventListener { @@ -10,8 +10,19 @@ public interface GLMediaEventListener { static final int EVENT_CHANGE_BPS = 1<<2; static final int EVENT_CHANGE_LENGTH = 1<<3; - public void attributesChanges(GLMediaPlayer mp, int event_mask); - public void newFrameAvailable(GLMediaPlayer mp, TextureFrame frame); + /** + * @param mp the event source + * @param event_mask the changes attributes + * @param when system time in msec. + */ + public void attributesChanges(GLMediaPlayer mp, int event_mask, long when); + + /** + * Signaling listeners that {@link GLMediaPlayer#getNextTexture(GL, boolean)} is able to deliver a new frame. + * @param mp the event source + * @param when system time in msec. + **/ + public void newFrameAvailable(GLMediaPlayer mp, long when); } diff --git a/src/jogl/classes/com/jogamp/opengl/av/GLMediaPlayer.java b/src/jogl/classes/com/jogamp/opengl/av/GLMediaPlayer.java index e5f69b6de..b3827d520 100644 --- a/src/jogl/classes/com/jogamp/opengl/av/GLMediaPlayer.java +++ b/src/jogl/classes/com/jogamp/opengl/av/GLMediaPlayer.java @@ -36,24 +36,24 @@ import javax.media.opengl.GLException; import jogamp.opengl.Debug; import com.jogamp.opengl.util.texture.Texture; +import com.jogamp.opengl.util.texture.TextureCoords; /** * Lifecycle of an GLMediaPlayer: * <table border="1"> - * <tr><th>action</th> <th>state before</th> <th>state after</th></tr> - * <tr><td>{@link #initStream(URLConnection)}</td> <td>UninitializedStream</td> <td>UninitializedGL</td></tr> - * <tr><td>{@link #initGL(GL)}</td> <td>UninitializedGL</td> <td>Stopped</td></tr> - * <tr><td>{@link #start()}</td> <td>Stopped, Paused</td> <td>Playing</td></tr> - * <tr><td>{@link #stop()}</td> <td>Playing, Paused</td> <td>Stopped</td></tr> - * <tr><td>{@link #pause()}</td> <td>Playing</td> <td>Paused</td></tr> - * <tr><td>{@link #destroy(GL)}</td> <td>ANY</td> <td>UninitializedStream</td></tr> + * <tr><th>action</th> <th>state before</th> <th>state after</th></tr> + * <tr><td>{@link #initGLStream(GL, URLConnection)}</td> <td>Uninitialized</td> <td>Stopped</td></tr> + * <tr><td>{@link #start()}</td> <td>Stopped, Paused</td> <td>Playing</td></tr> + * <tr><td>{@link #stop()}</td> <td>Playing, Paused</td> <td>Stopped</td></tr> + * <tr><td>{@link #pause()}</td> <td>Playing</td> <td>Paused</td></tr> + * <tr><td>{@link #destroy(GL)}</td> <td>ANY</td> <td>Uninitialized</td></tr> * </table> */ public interface GLMediaPlayer { public static final boolean DEBUG = Debug.debug("GLMediaPlayer"); public enum State { - UninitializedStream(0), UninitializedGL(1), Stopped(2), Playing(3), Paused(4); + Uninitialized(0), Stopped(1), Playing(2), Paused(3); public final int id; @@ -83,6 +83,10 @@ public interface GLMediaPlayer { public int getTextureTarget(); + /** Defaults to 0 */ + public void setTextureUnit(int u); + public int getTextureUnit(); + /** Sets the texture min-mag filter, defaults to {@link GL#GL_NEAREST}. */ public void setTextureMinMagFilter(int[] minMagFilter); public int[] getTextureMinMagFilter(); @@ -92,24 +96,20 @@ public interface GLMediaPlayer { public int[] getTextureWrapST(); /** - * Sets the stream to be used. Initializes all stream related states. + * Sets the stream to be used. Initializes all stream related states inclusive OpenGL ones, + * if <code>gl</code> is not null. * <p> - * UninitializedStream -> UninitializedGL + * Uninitialized -> Stopped * </p> + * @param gl current GL object. If null, no video output and textures will be available. + * @param urlConn the stream connection + * @return the new state + * + * @throws IllegalStateException if not invoked in state Uninitialized * @throws IOException in case of difficulties to open or process the stream - * @throws IllegalStateException if not invoked in state UninitializedStream - */ - public State initStream(URLConnection urlConn) throws IllegalStateException, IOException; - - /** - * Initializes all GL related resources. - * <p> - * UninitializedGL -> Stopped - * </p> * @throws GLException in case of difficulties to initialize the GL resources - * @throws IllegalStateException if not invoked in state UninitializedGL */ - public State initGL(GL gl) throws IllegalStateException, GLException; + public State initGLStream(GL gl, URLConnection urlConn) throws IllegalStateException, GLException, IOException; /** * Releases the GL and stream resources. @@ -157,17 +157,27 @@ public interface GLMediaPlayer { public long seek(long msec); /** - * @return the last updated texture. Not blocking. + * @return the last updated texture. Maybe <code>null</code> in case no last frame is available. + * Not blocking. */ public TextureFrame getLastTexture(); /** - * @return the next texture, which should be rendered. May block, depending on implementation. + * Returns the next texture to be rendered. + * <p> + * Implementation shall block until next frame is available if <code>blocking</code> is <code>true</code>, + * otherwise it shall return the last frame in case a new frame is not available. + * </p> + * <p> + * Shall return <code>null</code> in case <i>no</i> frame is available. + * </p> * * @see #addEventListener(GLMediaEventListener) - * @see GLMediaEventListener#newFrameAvailable(GLMediaPlayer, TextureFrame) + * @see GLMediaEventListener#newFrameAvailable(GLMediaPlayer, long) */ - public TextureFrame getNextTexture(); + public TextureFrame getNextTexture(GL gl, boolean blocking); + + public TextureCoords getTextureCoords(); public URLConnection getURLConnection(); 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); } |