From 0dd2b17f1dd484d22d68828bfb61558be09a4bfa Mon Sep 17 00:00:00 2001 From: Sven Göthel Date: Fri, 2 Feb 2024 08:31:29 +0100 Subject: GLMediaPlayerImpl: Allow one frame to be shown paused when issuing seek(), i.e. 'oneVideoFrameOnce'. This allows a player to see the current seek'ed position while paused. --- .../jogamp/opengl/util/av/GLMediaPlayerImpl.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src/jogl') diff --git a/src/jogl/classes/jogamp/opengl/util/av/GLMediaPlayerImpl.java b/src/jogl/classes/jogamp/opengl/util/av/GLMediaPlayerImpl.java index a52efe2ac..6d71dd43e 100644 --- a/src/jogl/classes/jogamp/opengl/util/av/GLMediaPlayerImpl.java +++ b/src/jogl/classes/jogamp/opengl/util/av/GLMediaPlayerImpl.java @@ -35,6 +35,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.atomic.AtomicBoolean; import com.jogamp.nativewindow.AbstractGraphicsDevice; import com.jogamp.nativewindow.DefaultGraphicsDevice; @@ -107,6 +108,7 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { private volatile State state; private final Object stateLock = new Object(); + private final AtomicBoolean oneVideoFrameOnce = new AtomicBoolean(false); private int textureCount; private int textureTarget; @@ -548,9 +550,10 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { @Override public final int seek(int msec) { + final int pts1; + final State preState; synchronized( stateLock ) { - final State preState = state; - final int pts1; + preState = state; switch(state) { case Playing: case Paused: @@ -577,14 +580,16 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { streamWorker.resume(); } setState( _state ); + attributesUpdated(new GLMediaPlayer.EventMask(GLMediaPlayer.EventMask.Bit.Seek)); break; default: pending_seek = msec; pts1 = 0; } - if(DEBUG) { logout.println("Seek("+msec+"): "+preState+" -> "+state+", "+toString()); } - return pts1; } + oneVideoFrameOnce.set(true); + if(DEBUG) { logout.println("Seek("+msec+"): "+preState+" -> "+state+", "+toString()); } + return pts1; } protected int pending_seek = -1; protected abstract int seekImpl(int msec); @@ -1173,7 +1178,8 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { @Override public final TextureFrame getNextTexture(final GL gl) throws IllegalStateException { synchronized( stateLock ) { - if(State.Playing == state) { + final boolean oneVideoFrame = oneVideoFrameOnce.compareAndSet(true, false); + if( oneVideoFrame || State.Playing == state ) { boolean dropFrame = false; try { do { @@ -1265,6 +1271,9 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { hasVideoFrame = stGotVFrame[0]; } } + if( !hasVideoFrame && oneVideoFrame ) { + oneVideoFrameOnce.set(true); + } if( hasVideoFrame && video_pts.isValid() ) { final int frame_period_last = video_pts.diffLast(video_pts_last); // rendering loop interrupted ? -- cgit v1.2.3