From 323476249dd94e605b6627582ad0dbcaede0159e Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sun, 26 Jan 2014 03:00:36 +0100 Subject: GLMediaPlayer: Add user attached objects, similar to GLContext - Allowing GLMediaEventListener impl. to access GLMediaPlayer associated objects --- .../com/jogamp/opengl/util/av/GLMediaPlayer.java | 20 +++++++++++++++++++- .../jogamp/opengl/util/av/GLMediaPlayerImpl.java | 19 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) (limited to 'src') 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 22a5cfb32..9957f2093 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/av/GLMediaPlayer.java +++ b/src/jogl/classes/com/jogamp/opengl/util/av/GLMediaPlayer.java @@ -391,7 +391,7 @@ public interface GLMediaPlayer extends TextureSequence { public AudioSink getAudioSink(); /** - * Releases the GL and stream resources. + * Releases the GL, stream and other resources, including {@link #attachObject(String, Object) attached user objects}. *

* Lifecycle: ANY -> {@link State#Uninitialized} *

@@ -626,4 +626,22 @@ public interface GLMediaPlayer extends TextureSequence { /** Return all {@link GLMediaEventListener} of this player. */ public GLMediaEventListener[] getEventListeners(); + + /** + * Returns the attached user object for the given name. + */ + public Object getAttachedObject(String name); + + /** + * Attaches the user object for the given name. + * Returns the previously set object, may be null. + */ + public Object attachObject(String name, Object obj); + + /** + * Detaches the user object for the given name. + * Returns the previously set object, may be null. + */ + public Object detachObject(String name); + } diff --git a/src/jogl/classes/jogamp/opengl/util/av/GLMediaPlayerImpl.java b/src/jogl/classes/jogamp/opengl/util/av/GLMediaPlayerImpl.java index 0bd1aa932..7cea51dc8 100644 --- a/src/jogl/classes/jogamp/opengl/util/av/GLMediaPlayerImpl.java +++ b/src/jogl/classes/jogamp/opengl/util/av/GLMediaPlayerImpl.java @@ -30,6 +30,7 @@ package jogamp.opengl.util.av; import java.io.IOException; import java.net.URI; import java.util.ArrayList; +import java.util.HashMap; import java.util.Iterator; import java.util.Map; @@ -374,6 +375,7 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { removeAllTextureFrames(gl); textureCount=0; changeState(event_mask, State.Uninitialized); + attachedObjects.clear(); return state; } } @@ -1594,6 +1596,23 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { private final Object eventListenersLock = new Object(); + @Override + public final Object getAttachedObject(String name) { + return attachedObjects.get(name); + } + + @Override + public final Object attachObject(String name, Object obj) { + return attachedObjects.put(name, obj); + } + + @Override + public final Object detachObject(String name) { + return attachedObjects.remove(name); + } + + private final HashMap attachedObjects = new HashMap(); + protected static final String toHexString(long v) { return "0x"+Long.toHexString(v); } -- cgit v1.2.3