diff options
author | Sven Gothel <[email protected]> | 2023-10-16 04:05:40 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-10-16 04:05:40 +0200 |
commit | dac49f32e09d61f5ba9be53a21d351843a48761b (patch) | |
tree | 7aa8990408bc0dd81c81172ba006859be6c29f10 | |
parent | ee29eaf770d0d3627e5989dcae58a87cf27184d3 (diff) |
Bug 1472: GLMediaPlayer: Handle setPlaySpeed() like setAudioVolume() if stream is not yet initialized or playing, cached clipped value and set at initGL(..)
-rw-r--r-- | src/demos/com/jogamp/opengl/demos/av/MovieSimple.java | 11 | ||||
-rw-r--r-- | src/jogl/classes/jogamp/opengl/util/av/GLMediaPlayerImpl.java | 33 |
2 files changed, 29 insertions, 15 deletions
diff --git a/src/demos/com/jogamp/opengl/demos/av/MovieSimple.java b/src/demos/com/jogamp/opengl/demos/av/MovieSimple.java index e754a0076..4e537c7e5 100644 --- a/src/demos/com/jogamp/opengl/demos/av/MovieSimple.java +++ b/src/demos/com/jogamp/opengl/demos/av/MovieSimple.java @@ -680,6 +680,7 @@ public class MovieSimple implements GLEventListener { public static void main(final String[] args) throws IOException, URISyntaxException { int swapInterval = 1; + float playSpeed = 1.0f; int width = 800; int height = 600; int textureCount = 3; // default - threaded @@ -692,6 +693,7 @@ public class MovieSimple implements GLEventListener { boolean forceGLDef = false; int vid = GLMediaPlayer.STREAM_ID_AUTO; int aid = GLMediaPlayer.STREAM_ID_AUTO; + float audioVolume = 1.0f; final int windowCount; { @@ -737,6 +739,11 @@ public class MovieSimple implements GLEventListener { } else if(args[i].equals("-vsync")) { i++; swapInterval = MiscUtils.atoi(args[i], swapInterval); + } else if(args[i].equals("-speed")) { + i++; + playSpeed = MiscUtils.atof(args[i], playSpeed); + } else if(args[i].equals("-mute")) { + audioVolume = 0.0f; } else if(args[i].equals("-projection")) { ortho=false; } else if(args[i].equals("-orig_scale")) { @@ -768,6 +775,8 @@ public class MovieSimple implements GLEventListener { System.err.println("forceGL3 "+forceGL3); System.err.println("forceGLDef "+forceGLDef); System.err.println("swapInterval "+swapInterval); + System.err.println("playSpeed "+playSpeed); + System.err.println("audioVolume "+audioVolume); final GLProfile glp; if(forceGLDef) { @@ -801,6 +810,8 @@ public class MovieSimple implements GLEventListener { mss[i].setSwapInterval(swapInterval); mss[i].setUseOriginalScale(useOrigScale); mss[i].setOrthoProjection(ortho); + mss[i].mPlayer.setPlaySpeed(playSpeed); + mss[i].mPlayer.setAudioVolume(audioVolume); mss[i].mPlayer.attachObject(WINDOW_KEY, windows[i]); mss[i].mPlayer.addEventListener(myGLMediaEventListener); diff --git a/src/jogl/classes/jogamp/opengl/util/av/GLMediaPlayerImpl.java b/src/jogl/classes/jogamp/opengl/util/av/GLMediaPlayerImpl.java index 106a374bf..793470a5e 100644 --- a/src/jogl/classes/jogamp/opengl/util/av/GLMediaPlayerImpl.java +++ b/src/jogl/classes/jogamp/opengl/util/av/GLMediaPlayerImpl.java @@ -539,21 +539,32 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { @Override public final float getPlaySpeed() { return playSpeed; } + private static final float clipZeroOneAllowMax(final float v) { + if( v < 0.01f ) { + return 0.0f; + } else if( Math.abs(1.0f - v) < 0.01f ) { + return 1.0f; + } + return v; + } + @Override public final boolean setPlaySpeed(float rate) { synchronized( stateLock ) { final float preSpeed = playSpeed; boolean res = false; - if(State.Uninitialized != state ) { - if( rate > 0.01f ) { - if( Math.abs(1.0f - rate) < 0.01f ) { - rate = 1.0f; - } + rate = clipZeroOneAllowMax(rate); + if( rate > 0.1f ) { + if(State.Uninitialized != state ) { if( setPlaySpeedImpl(rate) ) { resetAVPTS(); playSpeed = rate; res = true; } + } else { + // earmark .. + playSpeed = rate; + res = true; } } if(DEBUG) { logout.println("setPlaySpeed("+rate+"): "+state+", "+preSpeed+" -> "+playSpeed+", "+toString()); } @@ -596,21 +607,12 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { } } - private static final float clipAudioVolume(final float v) { - if( v < 0.01f ) { - return 0.0f; - } else if( Math.abs(1.0f - v) < 0.01f ) { - return 1.0f; - } - return v; - } - @Override public boolean setAudioVolume(float v) { synchronized( stateLock ) { final float preVolume = audioVolume; boolean res = false; - v = clipAudioVolume(v); + v = clipZeroOneAllowMax(v); if(State.Uninitialized != state ) { if( setAudioVolumeImpl(v) ) { audioVolume = v; @@ -754,6 +756,7 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { if( State.Uninitialized != state ) { initGLImpl(gl); setAudioVolume( audioVolume ); // update volume + setPlaySpeed( playSpeed ); // update playSpeed if(DEBUG) { logout.println("initGLImpl.X "+this); } |