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 --- .../com/jogamp/opengl/util/av/GLMediaPlayer.java | 151 +++++++++++++++------ 1 file changed, 112 insertions(+), 39 deletions(-) (limited to 'src/jogl/classes/com/jogamp/opengl/util') 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; + } } /** -- cgit v1.2.3