From b92a813063212130d6205a25b1f84662e8c4c0f9 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sun, 26 Jan 2014 04:55:37 +0100 Subject: Bug 927 - Enhance GLMediaPlayer/FFMPEGMediaPlayer MovieSimple to run multiple instances in parallel Tested on GNU/Linux x86_64, Result: Plays well here audio and video, i.e. audio is actually mixed from both movies. Even if one movie (below) stops and restarts (AL buffer reset), it didn't crash. +++ LIB_AV Codec : 54.92.100 [cc 54] LIB_AV Format : 54.63.104 [cc 54] LIB_AV Util : 52.18.100 [cc 52] LIB_AV Resample: 1.0.1 [cc 1, loaded true] LIB_SW Resample: 0.17.102 [cc 0, loaded true] LIB_AV Device : [loaded true] LIB_AV Class : FFMPEGv09Natives +++ (enable MovieSimple in scripts/tests.sh) bash scripts/tests-x64.sh -loop -windows 2 \ -urlN 0 http://download.blender.org/peach/bigbuckbunny_movies/big_buck_bunny_720p_surround.avi \ -urlN 1 http://video.webmfiles.org/elephants-dream.webm +++ 2 Streaming threads, i.e. decoder threads: "Thread-5-StreamWorker_1" daemon prio=10 tid=0x00007f994c102000 nid=0x5826 in Object.wait() [0x00007f996fa37000] at jogamp.opengl.util.av.GLMediaPlayerImpl$StreamWorker.run(GLMediaPlayerImpl.java:1231) "Thread-4-StreamWorker_0" daemon prio=10 tid=0x00007f99600ed000 nid=0x5825 in Object.wait() [0x00007f996cd09000] at jogamp.opengl.util.av.GLMediaPlayerImpl$StreamWorker.run(GLMediaPlayerImpl.java:1231) --- .../test/junit/jogl/demos/es2/av/MovieSimple.java | 287 ++++++++++++--------- 1 file changed, 166 insertions(+), 121 deletions(-) (limited to 'src') diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieSimple.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieSimple.java index ddf5c709c..fcf1cd2ef 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieSimple.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieSimple.java @@ -36,6 +36,7 @@ import java.nio.FloatBuffer; import javax.media.opengl.GL; import javax.media.opengl.GL2ES2; +import javax.media.opengl.GLAnimatorControl; import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLES2; @@ -84,6 +85,9 @@ public class MovieSimple implements GLEventListener { public static final int EFFECT_GRADIENT_BOTTOM2TOP = 1<<1; public static final int EFFECT_TRANSPARENT = 1<<3; + private static final String WINDOW_KEY = "window"; + private static final String PLAYER = "player"; + private static boolean waitForKey = false; private int winWidth, winHeight; private int prevMouseX; // , prevMouseY; @@ -286,6 +290,7 @@ public class MovieSimple implements GLEventListener { mPlayerShared = null != mPlayer; if( !mPlayerShared ) { mPlayer = GLMediaPlayerFactory.createDefault(); + mPlayer.attachObject(PLAYER, this); } System.out.println("pC.1a shared "+mPlayerShared+", "+mPlayer); } @@ -701,6 +706,94 @@ public class MovieSimple implements GLEventListener { st.useProgram(gl, false); } + static class MyGLMediaEventListener implements GLMediaEventListener { + void destroyWindow(final Window window) { + new Thread() { + public void run() { + window.destroy(); + } }.start(); + } + + @Override + public void newFrameAvailable(GLMediaPlayer ts, TextureFrame newFrame, long when) { + } + + @Override + public void attributesChanged(final GLMediaPlayer mp, int event_mask, long when) { + System.err.println("MovieSimple AttributesChanges: events_mask 0x"+Integer.toHexString(event_mask)+", 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( origSize ) { + window.setSize(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"); + // Use GLEventListener in all cases [A+V, V, A] + window.addGLEventListener(ms); + final GLAnimatorControl anim = window.getAnimator(); + anim.setUpdateFPSFrames(60, System.err); + anim.resetFPSCounter(); + + /** + * Kick off player w/o GLEventListener, i.e. for audio only. + * + try { + ms.mPlayer.initGL(null); + } catch (Exception e) { + e.printStackTrace(); + destroyWindow(); + return; + } + ms.mPlayer.play(); + System.out.println("play.1 "+ms.mPlayer); + */ + } + boolean destroy = false; + Throwable err = null; + + if( 0 != ( GLMediaEventListener.EVENT_CHANGE_EOS & event_mask ) ) { + err = ms.mPlayer.getStreamException(); + if( null != err ) { + System.err.println("MovieSimple State: EOS + Exception"); + destroy = true; + } else { + System.err.println("MovieSimple State: EOS"); + if( loopEOS ) { + ms.mPlayer.seek(0); + ms.mPlayer.play(); + } else { + destroy = true; + } + } + } + if( 0 != ( GLMediaEventListener.EVENT_CHANGE_ERR & event_mask ) ) { + err = ms.mPlayer.getStreamException(); + if( null != err ) { + System.err.println("MovieSimple State: ERR + Exception"); + } else { + System.err.println("MovieSimple State: ERR"); + } + destroy = true; + } + if( destroy ) { + if( null != err ) { + err.printStackTrace(); + } + destroyWindow(window); + } + } + }; + final static MyGLMediaEventListener myGLMediaEventListener = new MyGLMediaEventListener(); + + static boolean loopEOS = false; + static boolean origSize; + public static void main(String[] args) throws IOException, URISyntaxException { int swapInterval = 1; int width = 640; @@ -708,7 +801,6 @@ public class MovieSimple implements GLEventListener { int textureCount = 3; // default - threaded boolean ortho = true; boolean zoom = false; - boolean _loopEOS = false; boolean forceES2 = false; boolean forceES3 = false; @@ -716,9 +808,20 @@ public class MovieSimple implements GLEventListener { boolean forceGLDef = false; int vid = GLMediaPlayer.STREAM_ID_AUTO; int aid = GLMediaPlayer.STREAM_ID_AUTO; - final boolean origSize; - String url_s=null, file_s1=null, file_s2=null; + final int windowCount; + { + int _windowCount = 1; + for(int i=0; i