From 9a7b9768e2e018a33ca44a170f372fee84c26a27 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Tue, 9 May 2023 06:48:29 +0200 Subject: GLMediaPlayer: Replace GLMediaEventListener.EVENT_CHANGE_* 'int event_mask' with EventMask.Bit/EventMask --- .../opengl/demos/android/MovieCubeActivity0a.java | 10 +- .../opengl/demos/android/MovieCubeActivity0b.java | 10 +- .../opengl/demos/android/MovieSimpleActivity0.java | 12 +- .../jogamp/opengl/demos/av/CrossFadePlayer.java | 25 ++-- .../com/jogamp/opengl/demos/av/MovieCube.java | 20 +-- .../com/jogamp/opengl/demos/av/MovieSBSStereo.java | 23 ++-- .../com/jogamp/opengl/demos/av/MovieSimple.java | 29 ++-- .../com/jogamp/graph/ui/shapes/MediaButton.java | 12 +- .../com/jogamp/opengl/util/av/GLMediaPlayer.java | 151 +++++++++++++++------ .../jogamp/opengl/util/av/GLMediaPlayerImpl.java | 85 ++++++------ 10 files changed, 221 insertions(+), 156 deletions(-) diff --git a/src/demos/com/jogamp/opengl/demos/android/MovieCubeActivity0a.java b/src/demos/com/jogamp/opengl/demos/android/MovieCubeActivity0a.java index dfd0c94dc..cdaf39f2b 100644 --- a/src/demos/com/jogamp/opengl/demos/android/MovieCubeActivity0a.java +++ b/src/demos/com/jogamp/opengl/demos/android/MovieCubeActivity0a.java @@ -105,18 +105,18 @@ public class MovieCubeActivity0a extends NewtBaseActivity { } @Override - public void attributesChanged(final GLMediaPlayer mp, final int event_mask, final long when) { - System.err.println("MovieCubeActivity0 AttributesChanges: events_mask 0x"+Integer.toHexString(event_mask)+", when "+when); + public void attributesChanged(final GLMediaPlayer mp, final GLMediaPlayer.EventMask eventMask, final long when) { + System.err.println("MovieCubeActivity0 AttributesChanges: "+eventMask+", when "+when); System.err.println("MovieCubeActivity0 State: "+mp); - if( 0 != ( GLMediaEventListener.EVENT_CHANGE_INIT & event_mask ) ) { + if( eventMask.isSet(GLMediaPlayer.EventMask.Bit.Init) ) { glWindowMain.addGLEventListener(demoMain); anim.setUpdateFPSFrames(60*5, null); anim.resetFPSCounter(); } - if( 0 != ( GLMediaEventListener.EVENT_CHANGE_PLAY & event_mask ) ) { + if( eventMask.isSet(GLMediaPlayer.EventMask.Bit.Play) ) { anim.resetFPSCounter(); } - if( 0 != ( ( GLMediaEventListener.EVENT_CHANGE_ERR | GLMediaEventListener.EVENT_CHANGE_EOS ) & event_mask ) ) { + if( eventMask.isSet(GLMediaPlayer.EventMask.Bit.Error) || eventMask.isSet(GLMediaPlayer.EventMask.Bit.EOS) ) { final StreamException se = mPlayer.getStreamException(); if( null != se ) { se.printStackTrace(); diff --git a/src/demos/com/jogamp/opengl/demos/android/MovieCubeActivity0b.java b/src/demos/com/jogamp/opengl/demos/android/MovieCubeActivity0b.java index 649739e09..1b4696180 100644 --- a/src/demos/com/jogamp/opengl/demos/android/MovieCubeActivity0b.java +++ b/src/demos/com/jogamp/opengl/demos/android/MovieCubeActivity0b.java @@ -107,18 +107,18 @@ public class MovieCubeActivity0b extends NewtBaseActivity { } @Override - public void attributesChanged(final GLMediaPlayer mp, final int event_mask, final long when) { - System.err.println("MovieCubeActivity0 AttributesChanges: events_mask 0x"+Integer.toHexString(event_mask)+", when "+when); + public void attributesChanged(final GLMediaPlayer mp, final GLMediaPlayer.EventMask eventMask, final long when) { + System.err.println("MovieCubeActivity0 AttributesChanges: "+eventMask+", when "+when); System.err.println("MovieCubeActivity0 State: "+mp); - if( 0 != ( GLMediaEventListener.EVENT_CHANGE_INIT & event_mask ) ) { + if( eventMask.isSet(GLMediaPlayer.EventMask.Bit.Init) ) { glWindowMain.addGLEventListener(demoMain); anim.setUpdateFPSFrames(60*5, null); anim.resetFPSCounter(); } - if( 0 != ( GLMediaEventListener.EVENT_CHANGE_PLAY & event_mask ) ) { + if( eventMask.isSet(GLMediaPlayer.EventMask.Bit.Play) ) { anim.resetFPSCounter(); } - if( 0 != ( ( GLMediaEventListener.EVENT_CHANGE_ERR | GLMediaEventListener.EVENT_CHANGE_EOS ) & event_mask ) ) { + if( eventMask.isSet(GLMediaPlayer.EventMask.Bit.Error) || eventMask.isSet(GLMediaPlayer.EventMask.Bit.EOS) ) { final StreamException se = mPlayer.getStreamException(); if( null != se ) { se.printStackTrace(); diff --git a/src/demos/com/jogamp/opengl/demos/android/MovieSimpleActivity0.java b/src/demos/com/jogamp/opengl/demos/android/MovieSimpleActivity0.java index ecc417bb8..c80afab89 100644 --- a/src/demos/com/jogamp/opengl/demos/android/MovieSimpleActivity0.java +++ b/src/demos/com/jogamp/opengl/demos/android/MovieSimpleActivity0.java @@ -47,7 +47,6 @@ import com.jogamp.newt.event.MouseEvent; import com.jogamp.newt.opengl.GLWindow; import com.jogamp.opengl.util.Animator; import com.jogamp.opengl.util.av.GLMediaPlayer; -import com.jogamp.opengl.util.av.GLMediaPlayer.GLMediaEventListener; import com.jogamp.opengl.util.av.GLMediaPlayer.StreamException; import com.jogamp.opengl.util.texture.TextureSequence.TextureFrame; @@ -58,7 +57,8 @@ public class MovieSimpleActivity0 extends NewtBaseActivity { static String TAG = "MovieSimpleActivity0"; MouseAdapter toFrontMouseListener = new MouseAdapter() { - public void mouseClicked(final MouseEvent e) { + @Override + public void mouseClicked(final MouseEvent e) { final Object src = e.getSource(); if(src instanceof Window) { ((Window)src).requestFocus(false); @@ -104,15 +104,15 @@ public class MovieSimpleActivity0 extends NewtBaseActivity { public void newFrameAvailable(final GLMediaPlayer ts, final TextureFrame newFrame, final long when) { } @Override - public void attributesChanged(final GLMediaPlayer mp, final int event_mask, final long when) { - System.err.println("MovieSimpleActivity0 AttributesChanges: events_mask 0x"+Integer.toHexString(event_mask)+", when "+when); + public void attributesChanged(final GLMediaPlayer mp, final GLMediaPlayer.EventMask eventMask, final long when) { + System.err.println("MovieSimpleActivity0 AttributesChanges: "+eventMask+", when "+when); System.err.println("MovieSimpleActivity0 State: "+mp); - if( 0 != ( GLMediaEventListener.EVENT_CHANGE_INIT & event_mask ) ) { + if( eventMask.isSet(GLMediaPlayer.EventMask.Bit.Init) ) { glWindowMain.addGLEventListener(demoMain); anim.setUpdateFPSFrames(60*5, System.err); anim.resetFPSCounter(); } - if( 0 != ( ( GLMediaEventListener.EVENT_CHANGE_ERR | GLMediaEventListener.EVENT_CHANGE_EOS ) & event_mask ) ) { + if( eventMask.isSet(GLMediaPlayer.EventMask.Bit.Error) || eventMask.isSet(GLMediaPlayer.EventMask.Bit.EOS) ) { final StreamException se = mPlayer.getStreamException(); if( null != se ) { se.printStackTrace(); diff --git a/src/demos/com/jogamp/opengl/demos/av/CrossFadePlayer.java b/src/demos/com/jogamp/opengl/demos/av/CrossFadePlayer.java index 0e028279c..0270ee709 100644 --- a/src/demos/com/jogamp/opengl/demos/av/CrossFadePlayer.java +++ b/src/demos/com/jogamp/opengl/demos/av/CrossFadePlayer.java @@ -64,17 +64,17 @@ public class CrossFadePlayer public void newFrameAvailable(final GLMediaPlayer ts, final TextureFrame newFrame, final long when) { } @Override - public void attributesChanged(final GLMediaPlayer mp, final int event_mask, final long when) + public void attributesChanged(final GLMediaPlayer mp, final GLMediaPlayer.EventMask eventMask, final long when) { - System.out.println("\n***\nEvent mask changed: " + event_mask); - System.out.println("Timestamp: "+ when); + System.out.println("\n***\nAttributesChanges: "+eventMask+", when "+when); System.out.println("State of player: " + mp.getState().toString() +"\n"); - if ((event_mask & GLMediaEventListener.EVENT_CHANGE_INIT) !=0) { + if ( eventMask.isSet(GLMediaPlayer.EventMask.Bit.Init) ) { System.out.println("Duration: " + mp.getDuration() + "ms"); System.out.println("Volume: " + mp.getAudioVolume()); System.out.println("player.initGL()..."); new InterruptSource.Thread() { + @Override public void run() { try { mp.initGL(null); @@ -86,20 +86,18 @@ public class CrossFadePlayer } } }.start(); - } else if ((event_mask & GLMediaEventListener.EVENT_CHANGE_PAUSE) !=0) { - System.out.println("player.paused()..."); - } else if ((event_mask & GLMediaEventListener.EVENT_CHANGE_PLAY) !=0) { - System.out.println("playing..."); + } else if ( eventMask.isSet(GLMediaPlayer.EventMask.Bit.Pause) ) { + } else if ( eventMask.isSet(GLMediaPlayer.EventMask.Bit.Play) ) { System.out.println(mp.toString()); System.out.println(mp.getAudioSink().toString()); - } else if( 0 != ( GLMediaEventListener.EVENT_CHANGE_EOS & event_mask ) ) { + } else if( eventMask.isSet(GLMediaPlayer.EventMask.Bit.EOS) ) { final StreamException se = mp.getStreamException(); if( null != se ) { - System.err.println("Player State: EOS + Exception"); + System.err.println("Player State: Exception"); stop = true; } else { - System.err.println("Player State: EOS"); new InterruptSource.Thread() { + @Override public void run() { System.out.println("mp.setPlaySpeed(1f) returned: " + mp.setPlaySpeed(1f)); mp.seek(0); @@ -108,13 +106,14 @@ public class CrossFadePlayer }.start(); } } - if( 0 != ( ( GLMediaEventListener.EVENT_CHANGE_ERR | GLMediaEventListener.EVENT_CHANGE_EOS ) & event_mask ) ) { + if( eventMask.isSet(GLMediaPlayer.EventMask.Bit.Error) || eventMask.isSet(GLMediaPlayer.EventMask.Bit.EOS) ) { final StreamException se = mp.getStreamException(); if( null != se ) { se.printStackTrace(); } new InterruptSource.Thread() { - public void run() { + @Override + public void run() { System.out.println("terminating..."); stop = true; } diff --git a/src/demos/com/jogamp/opengl/demos/av/MovieCube.java b/src/demos/com/jogamp/opengl/demos/av/MovieCube.java index 0be2c35ba..6fafc6dc7 100644 --- a/src/demos/com/jogamp/opengl/demos/av/MovieCube.java +++ b/src/demos/com/jogamp/opengl/demos/av/MovieCube.java @@ -112,13 +112,13 @@ public class MovieCube implements GLEventListener { public void newFrameAvailable(final GLMediaPlayer ts, final TextureFrame newFrame, final long when) { } @Override - public void attributesChanged(final GLMediaPlayer mp, final int event_mask, final long when) { - System.err.println("MovieCube AttributesChanges: events_mask 0x"+Integer.toHexString(event_mask)+", when "+when); + public void attributesChanged(final GLMediaPlayer mp, final GLMediaPlayer.EventMask eventMask, final long when) { + System.err.println("MovieCube AttributesChanges: "+eventMask+", when "+when); System.err.println("MovieCube State: "+mp); - if( 0 != ( GLMediaEventListener.EVENT_CHANGE_SIZE & event_mask ) ) { + if( eventMask.isSet(GLMediaPlayer.EventMask.Bit.Size) ) { resetGLState(); } - if( 0 != ( GLMediaEventListener.EVENT_CHANGE_EOS & event_mask ) ) { + if( eventMask.isSet(GLMediaPlayer.EventMask.Bit.EOS) ) { new InterruptSource.Thread() { @Override public void run() { @@ -602,24 +602,24 @@ public class MovieCube implements GLEventListener { } @Override - public void attributesChanged(final GLMediaPlayer mp, final int event_mask, final long when) { - System.err.println("MovieCube AttributesChanges: events_mask 0x"+Integer.toHexString(event_mask)+", when "+when); + public void attributesChanged(final GLMediaPlayer mp, final GLMediaPlayer.EventMask event_mask, final long when) { + System.err.println("MovieCube AttributesChanges: events_mask "+event_mask+", when "+when); System.err.println("MovieCube State: "+mp); - if( 0 != ( GLMediaEventListener.EVENT_CHANGE_SIZE & event_mask ) ) { + if( event_mask.isSet(GLMediaPlayer.EventMask.Bit.Size) ) { if( origSize ) { window.setSurfaceSize(mp.getWidth(), mp.getHeight()); } // window.disposeGLEventListener(ms, false /* remove */ ); } - if( 0 != ( GLMediaEventListener.EVENT_CHANGE_INIT & event_mask ) ) { + if( event_mask.isSet(GLMediaPlayer.EventMask.Bit.Init) ) { anim.setUpdateFPSFrames(60, null); anim.resetFPSCounter(); mc.resetGLState(); } - if( 0 != ( GLMediaEventListener.EVENT_CHANGE_PLAY & event_mask ) ) { + if( event_mask.isSet(GLMediaPlayer.EventMask.Bit.Play) ) { anim.resetFPSCounter(); } - if( 0 != ( ( GLMediaEventListener.EVENT_CHANGE_ERR | GLMediaEventListener.EVENT_CHANGE_EOS ) & event_mask ) ) { + if( event_mask.isSet(GLMediaPlayer.EventMask.Bit.Error) || event_mask.isSet(GLMediaPlayer.EventMask.Bit.EOS) ) { final StreamException se = mc.mPlayer.getStreamException(); if( null != se ) { se.printStackTrace(); diff --git a/src/demos/com/jogamp/opengl/demos/av/MovieSBSStereo.java b/src/demos/com/jogamp/opengl/demos/av/MovieSBSStereo.java index 3c3350061..49a6b6fbb 100644 --- a/src/demos/com/jogamp/opengl/demos/av/MovieSBSStereo.java +++ b/src/demos/com/jogamp/opengl/demos/av/MovieSBSStereo.java @@ -829,20 +829,18 @@ public class MovieSBSStereo implements StereoGLEventListener { } @Override - public void attributesChanged(final GLMediaPlayer mp, final int event_mask, final long when) { - System.err.println("MovieSimple AttributesChanges: events_mask 0x"+Integer.toHexString(event_mask)+", when "+when); + public void attributesChanged(final GLMediaPlayer mp, final GLMediaPlayer.EventMask eventMask, final long when) { + System.err.println("MovieSimple AttributesChanges: "+eventMask+", when "+when); System.err.println("MovieSimple State: "+mp); final GLWindow window = (GLWindow) mp.getAttachedObject(WINDOW_KEY); final MovieSBSStereo ms = (MovieSBSStereo)mp.getAttachedObject(PLAYER); final StereoClientRenderer stereoClientRenderer = (StereoClientRenderer) mp.getAttachedObject(STEREO_RENDERER_KEY); - if( 0 != ( GLMediaEventListener.EVENT_CHANGE_SIZE & event_mask ) ) { - System.err.println("MovieSimple State: CHANGE_SIZE"); + if( eventMask.isSet(GLMediaPlayer.EventMask.Bit.Size) ) { // window.disposeGLEventListener(ms, false /* remove */ ); ms.resetGLState(); } - if( 0 != ( GLMediaEventListener.EVENT_CHANGE_INIT & event_mask ) ) { - System.err.println("MovieSimple State: INIT"); + if( eventMask.isSet(GLMediaPlayer.EventMask.Bit.Init) ) { // Use GLEventListener in all cases [A+V, V, A] stereoClientRenderer.addGLEventListener(ms); final GLAnimatorControl anim = window.getAnimator(); @@ -850,20 +848,19 @@ public class MovieSBSStereo implements StereoGLEventListener { anim.resetFPSCounter(); ms.setStereoClientRenderer(stereoClientRenderer); } - if( 0 != ( GLMediaEventListener.EVENT_CHANGE_PLAY & event_mask ) ) { + if( eventMask.isSet(GLMediaPlayer.EventMask.Bit.Play) ) { window.getAnimator().resetFPSCounter(); } boolean destroy = false; Throwable err = null; - if( 0 != ( GLMediaEventListener.EVENT_CHANGE_EOS & event_mask ) ) { + if( eventMask.isSet(GLMediaPlayer.EventMask.Bit.EOS) ) { err = ms.mPlayer.getStreamException(); if( null != err ) { - System.err.println("MovieSimple State: EOS + Exception"); + System.err.println("MovieSimple State: Exception"); destroy = true; } else { - System.err.println("MovieSimple State: EOS"); new InterruptSource.Thread() { @Override public void run() { @@ -874,12 +871,10 @@ public class MovieSBSStereo implements StereoGLEventListener { }.start(); } } - if( 0 != ( GLMediaEventListener.EVENT_CHANGE_ERR & event_mask ) ) { + if( eventMask.isSet(GLMediaPlayer.EventMask.Bit.Error) ) { err = ms.mPlayer.getStreamException(); if( null != err ) { - System.err.println("MovieSimple State: ERR + Exception"); - } else { - System.err.println("MovieSimple State: ERR"); + System.err.println("MovieSimple State: Exception"); } destroy = true; } diff --git a/src/demos/com/jogamp/opengl/demos/av/MovieSimple.java b/src/demos/com/jogamp/opengl/demos/av/MovieSimple.java index deed019d1..f851cc4e7 100644 --- a/src/demos/com/jogamp/opengl/demos/av/MovieSimple.java +++ b/src/demos/com/jogamp/opengl/demos/av/MovieSimple.java @@ -378,10 +378,10 @@ public class MovieSimple implements GLEventListener { public void newFrameAvailable(final GLMediaPlayer ts, final TextureFrame newFrame, final long when) { } @Override - public void attributesChanged(final GLMediaPlayer mp, final int event_mask, final long when) { - System.err.println("MovieSimple AttributesChanges: events_mask 0x"+Integer.toHexString(event_mask)+", when "+when); + public void attributesChanged(final GLMediaPlayer mp, final GLMediaPlayer.EventMask eventMask, final long when) { + System.err.println("MovieSimple AttributesChanges: "+eventMask+", when "+when); System.err.println("MovieSimple State: "+mp); - if( 0 != ( GLMediaEventListener.EVENT_CHANGE_EOS & event_mask ) ) { + if( eventMask.isSet(GLMediaPlayer.EventMask.Bit.EOS) ) { new InterruptSource.Thread() { @Override public void run() { @@ -577,21 +577,19 @@ public class MovieSimple implements GLEventListener { } @Override - public void attributesChanged(final GLMediaPlayer mp, final int event_mask, final long when) { - System.err.println("MovieSimple AttributesChanges: events_mask 0x"+Integer.toHexString(event_mask)+", when "+when); + public void attributesChanged(final GLMediaPlayer mp, final GLMediaPlayer.EventMask eventMask, final long when) { + System.err.println("MovieSimple AttributesChanges: "+eventMask+", when "+when); System.err.println("MovieSimple State: "+mp); final GLWindow window = (GLWindow) mp.getAttachedObject(WINDOW_KEY); final MovieSimple ms = (MovieSimple)mp.getAttachedObject(PLAYER); - if( 0 != ( GLMediaEventListener.EVENT_CHANGE_SIZE & event_mask ) ) { - System.err.println("MovieSimple State: CHANGE_SIZE"); + if( eventMask.isSet(GLMediaPlayer.EventMask.Bit.Size) ) { if( origSize ) { window.setSurfaceSize(mp.getWidth(), mp.getHeight()); } // window.disposeGLEventListener(ms, false /* remove */ ); // ms.resetGLState(); } - if( 0 != ( GLMediaEventListener.EVENT_CHANGE_INIT & event_mask ) ) { - System.err.println("MovieSimple State: INIT"); + if( eventMask.isSet(GLMediaPlayer.EventMask.Bit.Init) ) { // Use GLEventListener in all cases [A+V, V, A] final GLAnimatorControl anim = window.getAnimator(); anim.setUpdateFPSFrames(60, null); @@ -618,20 +616,19 @@ public class MovieSimple implements GLEventListener { }.start(); */ } - if( 0 != ( GLMediaEventListener.EVENT_CHANGE_PLAY & event_mask ) ) { + if( eventMask.isSet(GLMediaPlayer.EventMask.Bit.Play) ) { window.getAnimator().resetFPSCounter(); } boolean destroy = false; Throwable err = null; - if( 0 != ( GLMediaEventListener.EVENT_CHANGE_EOS & event_mask ) ) { + if( eventMask.isSet(GLMediaPlayer.EventMask.Bit.EOS) ) { err = ms.mPlayer.getStreamException(); if( null != err ) { - System.err.println("MovieSimple State: EOS + Exception"); + System.err.println("MovieSimple State: Exception"); destroy = true; } else { - System.err.println("MovieSimple State: EOS"); if( loopEOS ) { new InterruptSource.Thread() { @Override @@ -646,12 +643,10 @@ public class MovieSimple implements GLEventListener { } } } - if( 0 != ( GLMediaEventListener.EVENT_CHANGE_ERR & event_mask ) ) { + if( eventMask.isSet(GLMediaPlayer.EventMask.Bit.Error) ) { err = ms.mPlayer.getStreamException(); if( null != err ) { - System.err.println("MovieSimple State: ERR + Exception"); - } else { - System.err.println("MovieSimple State: ERR"); + System.err.println("MovieSimple State: Exception"); } destroy = true; } diff --git a/src/graphui/classes/com/jogamp/graph/ui/shapes/MediaButton.java b/src/graphui/classes/com/jogamp/graph/ui/shapes/MediaButton.java index c6a0bf99c..9461b3c83 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/shapes/MediaButton.java +++ b/src/graphui/classes/com/jogamp/graph/ui/shapes/MediaButton.java @@ -91,18 +91,18 @@ public class MediaButton extends TexSeqButton { } @Override - public void attributesChanged(final GLMediaPlayer mp, final int event_mask, final long when) { + public void attributesChanged(final GLMediaPlayer mp, final GLMediaPlayer.EventMask eventMask, final long when) { if( verbose ) { - System.err.println("MediaButton AttributesChanges: events_mask 0x"+Integer.toHexString(event_mask)+", when "+when); + System.err.println("MediaButton AttributesChanges: "+eventMask+", when "+when); System.err.println("MediaButton State: "+mp); } - if( 0 != ( GLMediaEventListener.EVENT_CHANGE_INIT & event_mask ) ) { + if( eventMask.isSet(GLMediaPlayer.EventMask.Bit.Init) ) { resetGL = true; } - if( 0 != ( GLMediaEventListener.EVENT_CHANGE_SIZE & event_mask ) ) { + if( eventMask.isSet(GLMediaPlayer.EventMask.Bit.Size) ) { // FIXME: mPlayer.resetGLState(); } - if( 0 != ( GLMediaEventListener.EVENT_CHANGE_EOS & event_mask ) ) { + if( eventMask.isSet(GLMediaPlayer.EventMask.Bit.EOS) ) { new InterruptSource.Thread() { @Override public void run() { @@ -110,7 +110,7 @@ public class MediaButton extends TexSeqButton { mp.seek(0); mp.resume(); } }.start(); - } else if( 0 != ( GLMediaEventListener.EVENT_CHANGE_ERR & event_mask ) ) { + } else if( eventMask.isSet(GLMediaPlayer.EventMask.Bit.Error) ) { final StreamException se = mp.getStreamException(); if( null != se ) { se.printStackTrace(); diff --git a/src/jogl/classes/com/jogamp/opengl/util/av/GLMediaPlayer.java b/src/jogl/classes/com/jogamp/opengl/util/av/GLMediaPlayer.java index 5740dae4b..82951ab54 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/av/GLMediaPlayer.java +++ b/src/jogl/classes/com/jogamp/opengl/util/av/GLMediaPlayer.java @@ -33,6 +33,8 @@ import com.jogamp.opengl.GLException; import jogamp.opengl.Debug; +import java.util.List; + import com.jogamp.common.net.Uri; import com.jogamp.opengl.util.texture.Texture; import com.jogamp.opengl.util.texture.TextureSequence; @@ -82,18 +84,18 @@ import com.jogamp.opengl.util.av.GLMediaPlayer.State; *
GLMediaPlayer Lifecycle
*

* - * - * - * - * - * - * + * + * + * + * + * + * * * * - * - * - * + * + * + * *
Action {@link State} Before {@link State} After {@link GLMediaEventListener Event}
{@link #playStream(Uri, int, int, int)} {@link State#Uninitialized Uninitialized} {@link State#Initialized Initialized}1, {@link State#Uninitialized Uninitialized} {@link GLMediaEventListener#EVENT_CHANGE_INIT EVENT_CHANGE_INIT} or ( {@link GLMediaEventListener#EVENT_CHANGE_ERR EVENT_CHANGE_ERR} + {@link GLMediaEventListener#EVENT_CHANGE_UNINIT EVENT_CHANGE_UNINIT} )
{@link #initGL(GL)} {@link State#Initialized Initialized}, {@link State#Uninitialized Uninitialized} {@link State#Playing Playing}, {@link State#Uninitialized Uninitialized} {@link GLMediaEventListener#EVENT_CHANGE_PLAY EVENT_CHANGE_PLAY} or ( {@link GLMediaEventListener#EVENT_CHANGE_ERR EVENT_CHANGE_ERR} + {@link GLMediaEventListener#EVENT_CHANGE_UNINIT EVENT_CHANGE_UNINIT} )
{@link #pause(boolean)} {@link State#Playing Playing} {@link State#Paused Paused} {@link GLMediaEventListener#EVENT_CHANGE_PAUSE EVENT_CHANGE_PAUSE}
{@link #resume()} {@link State#Paused Paused} {@link State#Playing Playing} {@link GLMediaEventListener#EVENT_CHANGE_PLAY EVENT_CHANGE_PLAY}
{@link #stop()} {@link State#Playing Playing}, {@link State#Paused Paused} {@link State#Uninitialized Uninitialized} {@link GLMediaEventListener#EVENT_CHANGE_PAUSE EVENT_CHANGE_PAUSE}
Action {@link State} Before {@link State} After {@link EventMask#Bit Event}
{@link #playStream(Uri, int, int, int)} {@link State#Uninitialized Uninitialized} {@link State#Initialized Initialized}1, {@link State#Uninitialized Uninitialized} {@link EventMask.Bit#Init Init} or ( {@link EventMask.Bit#Error Error} + {@link EventMask.Bit#Uninit Uninit} )
{@link #initGL(GL)} {@link State#Initialized Initialized}, {@link State#Uninitialized Uninitialized} {@link State#Playing Playing}, {@link State#Uninitialized Uninitialized} {@link EventMask.Bit#Play Play} or ( {@link EventMask.Bit#Error Error} + {@link EventMask.Bit#Uninit Uninit} )
{@link #pause(boolean)} {@link State#Playing Playing} {@link State#Paused Paused} {@link EventMask.Bit#Pause Pause}
{@link #resume()} {@link State#Paused Paused} {@link State#Playing Playing} {@link EventMask.Bit#Play Play}
{@link #stop()} {@link State#Playing Playing}, {@link State#Paused Paused} {@link State#Uninitialized Uninitialized} {@link EventMask.Bit#Pause Pause}
{@link #seek(int)} {@link State#Paused Paused}, {@link State#Playing Playing} {@link State#Paused Paused}, {@link State#Playing Playing} none
{@link #getNextTexture(GL)} any same none
{@link #getLastTexture()} any same none
{@link TextureFrame#END_OF_STREAM_PTS END_OF_STREAM} {@link State#Playing Playing} {@link State#Paused Paused} {@link GLMediaEventListener#EVENT_CHANGE_EOS EVENT_CHANGE_EOS} + {@link GLMediaEventListener#EVENT_CHANGE_PAUSE EVENT_CHANGE_PAUSE}
{@link StreamException} any {@link State#Paused Paused}, {@link State#Uninitialized Uninitialized} {@link GLMediaEventListener#EVENT_CHANGE_ERR EVENT_CHANGE_ERR} + ( {@link GLMediaEventListener#EVENT_CHANGE_PAUSE EVENT_CHANGE_PAUSE} or {@link GLMediaEventListener#EVENT_CHANGE_UNINIT EVENT_CHANGE_UNINIT} )
{@link #destroy(GL)} any {@link State#Uninitialized Uninitialized} {@link GLMediaEventListener#EVENT_CHANGE_UNINIT EVENT_CHANGE_UNINIT}
{@link TextureFrame#END_OF_STREAM_PTS END_OF_STREAM} {@link State#Playing Playing} {@link State#Paused Paused} {@link EventMask.Bit#EOS EOS} + {@link EventMask.Bit#Pause Pause}
{@link StreamException} any {@link State#Paused Paused}, {@link State#Uninitialized Uninitialized} {@link EventMask.Bit#Error Error} + ( {@link EventMask.Bit#Pause Pause} or {@link EventMask.Bit#Uninit Uninit} )
{@link #destroy(GL)} any {@link State#Uninitialized Uninitialized} {@link EventMask.Bit#Uninit Uninit}
*

* @@ -278,41 +280,112 @@ public interface GLMediaPlayer extends TextureSequence { *

*/ public interface GLMediaEventListener extends TexSeqEventListener { - - /** State changed to {@link State#Initialized}. See Lifecycle.*/ - static final int EVENT_CHANGE_INIT = 1<<0; - /** State changed to {@link State#Uninitialized}. See Lifecycle.*/ - static final int EVENT_CHANGE_UNINIT = 1<<1; - /** State changed to {@link State#Playing}. See Lifecycle.*/ - static final int EVENT_CHANGE_PLAY = 1<<2; - /** State changed to {@link State#Paused}. See Lifecycle.*/ - static final int EVENT_CHANGE_PAUSE = 1<<3; - /** End of stream reached. See Lifecycle.*/ - static final int EVENT_CHANGE_EOS = 1<<4; - /** An error occurred, e.g. during off-thread initialization. See {@link StreamException} and Lifecycle. */ - static final int EVENT_CHANGE_ERR = 1<<5; - - /** Stream video id change. */ - static final int EVENT_CHANGE_VID = 1<<16; - /** Stream audio id change. */ - static final int EVENT_CHANGE_AID = 1<<17; - /** TextureFrame size or vertical flip change. */ - static final int EVENT_CHANGE_SIZE = 1<<18; - /** Stream fps change. */ - static final int EVENT_CHANGE_FPS = 1<<19; - /** Stream bps change. */ - static final int EVENT_CHANGE_BPS = 1<<20; - /** Stream length change. */ - static final int EVENT_CHANGE_LENGTH = 1<<21; - /** Stream codec change. */ - static final int EVENT_CHANGE_CODEC = 1<<22; - /** * @param mp the event source * @param event_mask the changes attributes * @param when system time in msec. */ - public void attributesChanged(GLMediaPlayer mp, int event_mask, long when); + public void attributesChanged(GLMediaPlayer mp, EventMask event_mask, long when); + } + + /** Changes attributes event mask */ + public static final class EventMask { + + /** Attribute change bits */ + public static enum Bit { + /** State changed to {@link State#Initialized}. See Lifecycle.*/ + Init ( 1<<0 ), + /** State changed to {@link State#Uninitialized}. See Lifecycle.*/ + Uninit ( 1<<1 ), + /** State changed to {@link State#Playing}. See Lifecycle.*/ + Play ( 1<<2 ), + /** State changed to {@link State#Paused}. See Lifecycle.*/ + Pause ( 1<<3 ), + /** End of stream reached. See Lifecycle.*/ + EOS ( 1<<4 ), + /** An error occurred, e.g. during off-thread initialization. See {@link StreamException} and Lifecycle. */ + Error ( 1<<5 ), + + /** Stream video id change. */ + VID ( 1<<16 ), + /** Stream audio id change. */ + AID ( 1<<17 ), + /** TextureFrame size or vertical flip change. */ + Size ( 1<<18 ), + /** Stream fps change. */ + FPS ( 1<<19 ), + /** Stream bps change. */ + BPS ( 1<<20 ), + /** Stream length change. */ + Length ( 1<<21 ), + /** Stream codec change. */ + Codec ( 1<<22 ); + + Bit(final int v) { value = v; } + public final int value; + } + public int mask; + + public static int getBits(final List v) { + int res = 0; + for(final Bit b : v) { + res |= b.value; + } + return res; + } + public EventMask(final List v) { + mask = getBits(v); + } + public EventMask(final Bit v) { + mask = v.value; + } + public EventMask(final int v) { + mask = v; + } + public EventMask() { + mask = 0; + } + + public boolean isSet(final Bit bit) { return bit.value == ( mask & bit.value ); } + public boolean isSet(final List bits) { final int bits_i = getBits(bits); return bits_i == ( mask & bits_i ); } + public boolean isSet(final int bits) { return bits == ( mask & bits ); } + public boolean isZero() { return 0 == mask; } + + public EventMask setBit(final Bit v) { mask |= v.value; return this; } + public EventMask setBits(final List v) { + for(final Bit b : v) { + mask |= b.value; + } + return this; + } + + @Override + public String toString() { + int count = 0; + final StringBuilder out = new StringBuilder(); + for (final Bit dt : Bit.values()) { + if( isSet(dt) ) { + if( 0 < count ) { out.append(", "); } + out.append(dt.name()); count++; + } + } + if( 0 == count ) { + out.append("None"); + } else if( 1 < count ) { + out.insert(0, "["); + out.append("]"); + } + return out.toString(); + } + + @Override + public boolean equals(final Object other) { + if (this == other) { + return true; + } + return (other instanceof EventMask) && + this.mask == ((EventMask)other).mask; + } } /** diff --git a/src/jogl/classes/jogamp/opengl/util/av/GLMediaPlayerImpl.java b/src/jogl/classes/jogamp/opengl/util/av/GLMediaPlayerImpl.java index 6408e3d6f..de949bbd6 100644 --- a/src/jogl/classes/jogamp/opengl/util/av/GLMediaPlayerImpl.java +++ b/src/jogl/classes/jogamp/opengl/util/av/GLMediaPlayerImpl.java @@ -363,7 +363,7 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { if( null != streamWorker ) { streamWorker.doResume(); } - changeState(0, State.Playing); + changeState(new GLMediaPlayer.EventMask(), State.Playing); } default: } @@ -375,13 +375,13 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { @Override public final State pause(final boolean flush) { - return pauseImpl(flush, 0); + return pauseImpl(flush, new GLMediaPlayer.EventMask()); } - private final State pauseImpl(final boolean flush, int event_mask) { + private final State pauseImpl(final boolean flush, GLMediaPlayer.EventMask eventMask) { synchronized( stateLock ) { final State preState = state; if( State.Playing == state ) { - event_mask = addStateEventMask(event_mask, GLMediaPlayer.State.Paused); + eventMask = addStateEventMask(eventMask, GLMediaPlayer.State.Paused); setState( State.Paused ); if( null != streamWorker ) { streamWorker.doPause(true); @@ -391,7 +391,7 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { } else if( null != audioSink ) { audioSink.pause(); } - attributesUpdated( event_mask ); + attributesUpdated( eventMask ); if( !pauseImpl() ) { resume(); } @@ -412,7 +412,7 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { } resetAVPTSAndFlush(); stopImpl(); - changeState(0, State.Uninitialized); + changeState(new GLMediaPlayer.EventMask(), State.Uninitialized); // attachedObjects.clear(); if(DEBUG) { System.err.println("Stop: "+preState+" -> "+state+", "+toString()); } return state; @@ -422,9 +422,9 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { @Override public final State destroy(final GL gl) { - return destroyImpl(gl, 0, true); + return destroyImpl(gl, new GLMediaPlayer.EventMask(), true); } - private final State destroyImpl(final GL gl, final int event_mask, final boolean wait) { + private final State destroyImpl(final GL gl, final GLMediaPlayer.EventMask eventMask, final boolean wait) { synchronized( stateLock ) { if( null != streamWorker ) { streamWorker.doStopImpl(wait); @@ -435,7 +435,7 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { removeAllTextureFrames(gl); lastFrame = null; textureCount=0; - changeState(event_mask, State.Uninitialized); + changeState(eventMask, State.Uninitialized); attachedObjects.clear(); return state; } @@ -619,7 +619,7 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { initStreamImpl(vid, aid); } catch (final Throwable t) { streamErr = new StreamException(t.getClass().getSimpleName()+" while initializing: "+GLMediaPlayerImpl.this.toString(), t); - changeState(GLMediaEventListener.EVENT_CHANGE_ERR, GLMediaPlayer.State.Uninitialized); + changeState(new GLMediaPlayer.EventMask(GLMediaPlayer.EventMask.Bit.Error), GLMediaPlayer.State.Uninitialized); } // also initializes width, height, .. etc } }.start(); @@ -689,7 +689,7 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { } streamWorker.initGL(gl); streamWorker.doResume(); - changeState(0, State.Paused); + changeState(new GLMediaPlayer.EventMask(), State.Paused); resume(); } else { resetAVPTSAndFlush(); @@ -717,7 +717,7 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { // changeState(0, State.Paused); } } catch (final Throwable t) { - destroyImpl(gl, GLMediaEventListener.EVENT_CHANGE_ERR, false /* wait */); // -> GLMediaPlayer.State.Uninitialized + destroyImpl(gl, new GLMediaPlayer.EventMask(GLMediaPlayer.EventMask.Bit.Error), false /* wait */); // -> GLMediaPlayer.State.Uninitialized throw new GLException("Error initializing GL resources", t); } } @@ -959,7 +959,7 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { if( DEBUG ) { System.err.println( "AV-EOS (getNextTexture): EOS_PTS "+(TimeFrameI.END_OF_STREAM_PTS == video_pts)+", "+this); } - pauseImpl(true, GLMediaEventListener.EVENT_CHANGE_EOS); + pauseImpl(true, new GLMediaPlayer.EventMask(GLMediaPlayer.EventMask.Bit.EOS)); } else if( TimeFrameI.INVALID_PTS == video_pts ) { // no audio or video frame if( null == videoFramesDecoded || !videoFramesDecoded.isEmpty() ) { @@ -1413,7 +1413,7 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { if( DEBUG ) { System.err.println( "AV-EOS (StreamWorker): EOS_PTS "+(TimeFrameI.END_OF_STREAM_PTS == vPTS)+", "+GLMediaPlayerImpl.this); } - pauseImpl(true, GLMediaEventListener.EVENT_CHANGE_EOS); + pauseImpl(true, new GLMediaPlayer.EventMask(GLMediaPlayer.EventMask.Bit.EOS)); } } } catch (final InterruptedException e) { @@ -1438,7 +1438,7 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { isActive = false; this.notifyAll(); // wake-up potential do*() } - pauseImpl(true, GLMediaEventListener.EVENT_CHANGE_ERR); + pauseImpl(true, new GLMediaPlayer.EventMask(GLMediaPlayer.EventMask.Bit.Error)); } } } @@ -1457,46 +1457,49 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { private volatile StreamWorker streamWorker = null; private volatile StreamException streamErr = null; - protected final int addStateEventMask(int event_mask, final State newState) { + protected final GLMediaPlayer.EventMask addStateEventMask(final GLMediaPlayer.EventMask eventMask, final State newState) { if( state != newState ) { switch( newState ) { case Uninitialized: - event_mask |= GLMediaEventListener.EVENT_CHANGE_UNINIT; + eventMask.setBit(GLMediaPlayer.EventMask.Bit.Uninit); break; case Initialized: - event_mask |= GLMediaEventListener.EVENT_CHANGE_INIT; + eventMask.setBit(GLMediaPlayer.EventMask.Bit.Init); break; case Playing: - event_mask |= GLMediaEventListener.EVENT_CHANGE_PLAY; + eventMask.setBit(GLMediaPlayer.EventMask.Bit.Play); break; case Paused: - event_mask |= GLMediaEventListener.EVENT_CHANGE_PAUSE; + eventMask.setBit(GLMediaPlayer.EventMask.Bit.Pause); break; } } - return event_mask; + return eventMask; } - protected final void attributesUpdated(final int event_mask) { - if( 0 != event_mask ) { + protected final void attributesUpdated(final GLMediaPlayer.EventMask eventMask) { + if( !eventMask.isZero() ) { final long now = Platform.currentTimeMillis(); + if( DEBUG ) { + System.err.println("GLMediaPlayer.AttributesChanged: "+eventMask+", state "+state+", when "+now); + } synchronized(eventListenersLock) { for(final Iterator i = eventListeners.iterator(); i.hasNext(); ) { - i.next().attributesChanged(this, event_mask, now); + i.next().attributesChanged(this, eventMask, now); } } } } - protected final void changeState(int event_mask, final State newState) { - event_mask = addStateEventMask(event_mask, newState); - if( 0 != event_mask ) { + protected final void changeState(GLMediaPlayer.EventMask eventMask, final State newState) { + eventMask = addStateEventMask(eventMask, newState); + if( !eventMask.isZero() ) { setState( newState ); if(State.Uninitialized == state) { textureLookupFunctionName = "texture2D"; textureFragmentShaderHashCode = 0; } - attributesUpdated( event_mask ); + attributesUpdated( eventMask ); } } @@ -1513,34 +1516,34 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { protected final void updateAttributes(int vid, final int aid, final int width, final int height, final int bps_stream, final int bps_video, final int bps_audio, final float fps, final int videoFrames, final int audioFrames, final int duration, final String vcodec, final String acodec) { - int event_mask = 0; + final GLMediaPlayer.EventMask eventMask = new GLMediaPlayer.EventMask(); final boolean wasUninitialized = state == State.Uninitialized; if( wasUninitialized ) { - event_mask |= GLMediaEventListener.EVENT_CHANGE_INIT; + eventMask.setBit(GLMediaPlayer.EventMask.Bit.Init); setState( State.Initialized ); } if( STREAM_ID_AUTO == vid ) { vid = STREAM_ID_NONE; } if( this.vid != vid ) { - event_mask |= GLMediaEventListener.EVENT_CHANGE_VID; + eventMask.setBit(GLMediaPlayer.EventMask.Bit.VID); this.vid = vid; } if( STREAM_ID_AUTO == vid ) { vid = STREAM_ID_NONE; } if( this.aid != aid ) { - event_mask |= GLMediaEventListener.EVENT_CHANGE_AID; + eventMask.setBit(GLMediaPlayer.EventMask.Bit.AID); this.aid = aid; } if( this.width != width || this.height != height ) { - event_mask |= GLMediaEventListener.EVENT_CHANGE_SIZE; + eventMask.setBit(GLMediaPlayer.EventMask.Bit.Size); this.width = width; this.height = height; } if( this.fps != fps ) { - event_mask |= GLMediaEventListener.EVENT_CHANGE_FPS; + eventMask.setBit(GLMediaPlayer.EventMask.Bit.FPS); this.fps = fps; if( 0 != fps ) { this.frame_duration = 1000f / fps; @@ -1556,26 +1559,26 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { } } if( this.bps_stream != bps_stream || this.bps_video != bps_video || this.bps_audio != bps_audio ) { - event_mask |= GLMediaEventListener.EVENT_CHANGE_BPS; + eventMask.setBit(GLMediaPlayer.EventMask.Bit.BPS); this.bps_stream = bps_stream; this.bps_video = bps_video; this.bps_audio = bps_audio; } if( this.videoFrames != videoFrames || this.audioFrames != audioFrames || this.duration != duration ) { - event_mask |= GLMediaEventListener.EVENT_CHANGE_LENGTH; + eventMask.setBit(GLMediaPlayer.EventMask.Bit.Length); this.videoFrames = videoFrames; this.audioFrames = audioFrames; this.duration = duration; } if( (null!=acodec && acodec.length()>0 && !this.acodec.equals(acodec)) ) { - event_mask |= GLMediaEventListener.EVENT_CHANGE_CODEC; + eventMask.setBit(GLMediaPlayer.EventMask.Bit.Codec); this.acodec = acodec; } if( (null!=vcodec && vcodec.length()>0 && !this.vcodec.equals(vcodec)) ) { - event_mask |= GLMediaEventListener.EVENT_CHANGE_CODEC; + eventMask.setBit(GLMediaPlayer.EventMask.Bit.Codec); this.vcodec = vcodec; } - if(0==event_mask) { + if( eventMask.isZero() ) { return; } if( wasUninitialized ) { @@ -1583,7 +1586,7 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { System.err.println("XXX Initialize @ updateAttributes: "+this); } } - attributesUpdated(event_mask); + attributesUpdated(eventMask); } protected void setIsGLOriented(final boolean isGLOriented) { @@ -1596,7 +1599,7 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { for(int i=0; i