summaryrefslogtreecommitdiffstats
path: root/src/test/com/jogamp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2012-04-03 22:39:27 +0200
committerSven Gothel <[email protected]>2012-04-03 22:39:27 +0200
commit9e680fe86cd5b64aa758ce32666a6efa19118d3d (patch)
treea7d8b78d6c4b05f3e0321133004bc5eb746258f7 /src/test/com/jogamp
parent081404e20ac6055244408c6a4a7e7c2089183983 (diff)
GLMediaPlayer/MovieSimple: Refine API (split setStream(GL, URL) -> initStream(URL) + initGL(GL)) .. IllegalStateException if wrong. Using internet streams of BigBuckBunny, if avail.
- Splitting the initialization in stream and GL allows using the stream information (eg: size, ..) for setting the GLDrawable properties .. - Make the impl. more bullet proof ..
Diffstat (limited to 'src/test/com/jogamp')
-rw-r--r--src/test/com/jogamp/opengl/test/android/MovieSimpleActivity.java98
-rw-r--r--src/test/com/jogamp/opengl/test/android/MovieSimpleActivityLauncher.java5
-rwxr-xr-xsrc/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieSimple.java46
3 files changed, 103 insertions, 46 deletions
diff --git a/src/test/com/jogamp/opengl/test/android/MovieSimpleActivity.java b/src/test/com/jogamp/opengl/test/android/MovieSimpleActivity.java
index 7505d4659..8d8a80bad 100644
--- a/src/test/com/jogamp/opengl/test/android/MovieSimpleActivity.java
+++ b/src/test/com/jogamp/opengl/test/android/MovieSimpleActivity.java
@@ -27,8 +27,9 @@
*/
package com.jogamp.opengl.test.android;
-import java.net.MalformedURLException;
-import java.net.URL;
+import java.io.IOException;
+import java.net.URLConnection;
+import java.util.Arrays;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLProfile;
@@ -36,11 +37,14 @@ import javax.media.opengl.GLProfile;
import jogamp.newt.driver.android.AndroidWindow;
import jogamp.newt.driver.android.NewtBaseActivity;
+import com.jogamp.common.util.IOUtil;
import com.jogamp.newt.NewtFactory;
import com.jogamp.newt.event.MouseAdapter;
import com.jogamp.newt.event.MouseEvent;
import com.jogamp.newt.opengl.GLWindow;
+import com.jogamp.opengl.av.GLMediaPlayer;
+import com.jogamp.opengl.av.GLMediaPlayerFactory;
import com.jogamp.opengl.test.junit.jogl.demos.es2.av.MovieSimple;
import com.jogamp.opengl.util.Animator;
@@ -63,6 +67,15 @@ public class MovieSimpleActivity extends NewtBaseActivity {
Log.d(TAG, "onCreate - 0");
super.onCreate(savedInstanceState);
+ String[] urls = new String[] {
+ System.getProperty("jnlp.media0_url2"),
+ System.getProperty("jnlp.media0_url1"),
+ System.getProperty("jnlp.media0_url0") };
+ final URLConnection ucH = getResource(urls, 0);
+ if(null == ucH) { throw new RuntimeException("no media reachable: "+Arrays.asList(urls)); }
+ URLConnection ucL = null; // getResource(urls, 1);
+ if(null == ucL) { ucL = ucH; }
+
setTransparencyTheme();
setFullscreenFeature(getWindow(), true);
@@ -72,59 +85,78 @@ public class MovieSimpleActivity extends NewtBaseActivity {
// also initializes JOGL
final GLCapabilities capsMain = new GLCapabilities(GLProfile.getGL2ES2());
capsMain.setBackgroundOpaque(false);
+ final GLCapabilities capsHUD = new GLCapabilities(GLProfile.getGL2ES2());
// screen for layout params ..
final com.jogamp.newt.Display dpy = NewtFactory.createDisplay(null);
final com.jogamp.newt.Screen scrn = NewtFactory.createScreen(dpy, 0);
scrn.addReference();
- final GLWindow glWindowMain = GLWindow.create(scrn, capsMain);
- glWindowMain.addMouseListener(demoMouseListener);
- glWindowMain.setFullscreen(true);
- // setContentView(getWindow(), glWindowMain);
- viewGroup.addView(((AndroidWindow)glWindowMain.getDelegatedWindow()).getAndroidView(), 0);
- registerNEWTWindow(glWindowMain);
-
- final GLCapabilities capsHUD = new GLCapabilities(GLProfile.getGL2ES2());
-
- final GLWindow glWindowHUD = GLWindow.create(scrn, capsHUD);
- glWindowHUD.addMouseListener(demoMouseListener);
- {
- int x2 = scrn.getX();
- int y2 = scrn.getY();
- int w2 = scrn.getWidth()/4;
- int h2 = scrn.getHeight()/4;
- glWindowHUD.setPosition(x2, y2);
- glWindowHUD.setSize(w2, h2);
- }
- // addContentView(getWindow(), glWindowHUD, new android.view.ViewGroup.LayoutParams(glWindowHUD.getWidth(), glWindowHUD.getHeight()));
- viewGroup.addView(((AndroidWindow)glWindowHUD.getDelegatedWindow()).getAndroidView(), 1, new android.view.ViewGroup.LayoutParams(glWindowHUD.getWidth(), glWindowHUD.getHeight()));
- registerNEWTWindow(glWindowHUD);
-
try {
Animator animator = new Animator();
setAnimator(animator);
- final MovieSimple demoMain = new MovieSimple(new URL("file:///mnt/sdcard/Movies/BigBuckBunny_320x180.mp4"));
+ // Main
+ final MovieSimple demoMain = new MovieSimple(ucH.getURL());
demoMain.setEffects(MovieSimple.EFFECT_GRADIENT_BOTTOM2TOP);
- demoMain.setTransparency(0.9f);
+ demoMain.setTransparency(0.9f);
+ final GLWindow glWindowMain = GLWindow.create(scrn, capsMain);
+ glWindowMain.addMouseListener(demoMouseListener);
+ glWindowMain.setFullscreen(true);
+ // setContentView(getWindow(), glWindowMain);
+ viewGroup.addView(((AndroidWindow)glWindowMain.getDelegatedWindow()).getAndroidView(), 0);
+ registerNEWTWindow(glWindowMain);
glWindowMain.addGLEventListener(demoMain);
animator.add(glWindowMain);
glWindowMain.setVisible(true);
-
- final MovieSimple demoHUD = new MovieSimple(new URL("file:///mnt/sdcard/Movies/BigBuckBunny_320x180.mp4"));
+
+ final GLMediaPlayer demoMP = GLMediaPlayerFactory.create();
+ demoMP.initStream(ucL.getURL());
+ final MovieSimple demoHUD = new MovieSimple(demoMP);
+ final GLWindow glWindowHUD = GLWindow.create(scrn, capsHUD);
+ glWindowHUD.addMouseListener(demoMouseListener);
+ {
+ int x2 = scrn.getX();
+ int y2 = scrn.getY();
+ int w2 = scrn.getWidth()/2;
+ int h2 = scrn.getHeight()/2;
+ if(0 < demoMP.getWidth() && demoMP.getWidth()<w2) {
+ w2 = demoMP.getWidth();
+ }
+ if(0 < demoMP.getHeight() && demoMP.getHeight()<h2) {
+ h2 = demoMP.getHeight();
+ }
+ glWindowHUD.setPosition(x2, y2);
+ glWindowHUD.setSize(w2, h2);
+ System.err.println("HUD: "+demoMP);
+ System.err.println("HUD: "+w2+"x"+h2);
+ }
+ // addContentView(getWindow(), glWindowHUD, new android.view.ViewGroup.LayoutParams(glWindowHUD.getWidth(), glWindowHUD.getHeight()));
+ viewGroup.addView(((AndroidWindow)glWindowHUD.getDelegatedWindow()).getAndroidView(), 1, new android.view.ViewGroup.LayoutParams(glWindowHUD.getWidth(), glWindowHUD.getHeight()));
+ registerNEWTWindow(glWindowHUD);
glWindowHUD.addGLEventListener(demoHUD);
- animator.add(glWindowHUD);
+ animator.add(glWindowHUD);
glWindowHUD.setVisible(true);
- // animator.setUpdateFPSFrames(60, System.err);
+ animator.setUpdateFPSFrames(60, System.err);
animator.resetFPSCounter();
- } catch (MalformedURLException e) {
+ } catch (IOException e) {
e.printStackTrace();
}
scrn.removeReference();
Log.d(TAG, "onCreate - X");
- }
+ }
+
+ static URLConnection getResource(String path[], int off) {
+ URLConnection uc = null;
+ for(int i=off; null==uc && i<path.length; i++) {
+ if(null != path[i]) {
+ uc = IOUtil.getResource(path[i], null);
+ Log.d(TAG, "Stream: <"+path[i]+">: "+(null!=uc));
+ }
+ }
+ return uc;
+ }
}
diff --git a/src/test/com/jogamp/opengl/test/android/MovieSimpleActivityLauncher.java b/src/test/com/jogamp/opengl/test/android/MovieSimpleActivityLauncher.java
index 36bdd2921..474e523e4 100644
--- a/src/test/com/jogamp/opengl/test/android/MovieSimpleActivityLauncher.java
+++ b/src/test/com/jogamp/opengl/test/android/MovieSimpleActivityLauncher.java
@@ -40,7 +40,10 @@ public class MovieSimpleActivityLauncher extends LauncherUtil.BaseActivityLaunch
@Override
public void init() {
- final OrderedProperties props = getProperties();
+ final OrderedProperties props = getProperties();
+ props.setProperty("jnlp.media0_url2", "http://download.blender.org/peach/bigbuckbunny_movies/BigBuckBunny_640x360.m4v");
+ props.setProperty("jnlp.media0_url1", "http://download.blender.org/peach/bigbuckbunny_movies/BigBuckBunny_320x180.mp4");
+ props.setProperty("jnlp.media0_url0", "file:///mnt/sdcard/Movies/BigBuckBunny_320x180.mp4");
// props.setProperty("jogamp.debug.JNILibLoader", "true");
// props.setProperty("jogamp.debug.NativeLibrary", "true");
// props.setProperty("jogamp.debug.NativeLibrary.Lookup", "true");
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 9730a16c5..4c156b8f0 100755
--- 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
@@ -76,7 +76,6 @@ public class MovieSimple implements MouseListener, GLEventListener, GLMediaEvent
private float ang = 0f;
private long startTime;
private long curTime;
- private URL stream;
private int effects = EFFECT_NORMAL;
private float alpha = 1.0f;
@@ -144,10 +143,27 @@ public class MovieSimple implements MouseListener, GLEventListener, GLMediaEvent
public void mouseWheelMoved(MouseEvent e) {
}
- public MovieSimple(URL stream) {
- this.stream = stream ;
+ GLMediaPlayer mPlayer;
+ boolean mPlayerExternal;
+
+ public MovieSimple(URL stream) throws IOException {
+ mPlayerExternal = false;
+ mPlayer = GLMediaPlayerFactory.create();
+ mPlayer.addEventListener(this);
+ mPlayer.initStream(stream);
+ System.out.println("p0.1 "+mPlayer);
}
+ public MovieSimple(GLMediaPlayer mediaPlayer) throws IllegalStateException {
+ if(GLMediaPlayer.State.UninitializedGL != mediaPlayer.getState()) {
+ throw new IllegalStateException("Given GLMediaPlayer not in state "+GLMediaPlayer.State.UninitializedGL+": "+mediaPlayer);
+ }
+ mPlayerExternal = true;
+ mPlayer = mediaPlayer;
+ mPlayer.addEventListener(this);
+ System.out.println("p0.2 "+mPlayer);
+ }
+
private void run() {
System.err.println("MovieSimple.run()");
try {
@@ -203,8 +219,6 @@ public class MovieSimple implements MouseListener, GLEventListener, GLMediaEvent
st.attachShaderProgram(gl, sp, false);
}
- GLMediaPlayer mPlayer=null;
-
public void init(GLAutoDrawable drawable) {
GL2ES2 gl = drawable.getGL().getGL2ES2();
System.err.println("Entering initialization");
@@ -216,14 +230,17 @@ public class MovieSimple implements MouseListener, GLEventListener, GLMediaEvent
boolean useExternalTexture = false;
try {
- mPlayer = GLMediaPlayerFactory.create();
- mPlayer.addEventListener(this);
- // movie.setStream(4, new URL(stream));
- mPlayer.setStream(gl, stream);
- System.out.println("p0 "+mPlayer);
+ mPlayer.initGL(gl);
+ System.out.println("p1 "+mPlayer);
useExternalTexture = GLES2.GL_TEXTURE_EXTERNAL_OES == mPlayer.getTextureTarget();
mPlayer.setTextureMinMagFilter( new int[] { GL.GL_NEAREST, GL.GL_LINEAR } );
- } catch (IOException ioe) { ioe.printStackTrace(); }
+ } catch (GLException glex) {
+ if(null != mPlayer) {
+ mPlayer.destroy(gl);
+ mPlayer = null;
+ }
+ throw new GLException(glex);
+ }
pmvMatrix = new PMVMatrix();
@@ -331,6 +348,7 @@ public class MovieSimple implements MouseListener, GLEventListener, GLMediaEvent
}
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
+ if(null == mPlayer) { return; }
winWidth = width;
winHeight = height;
@@ -355,6 +373,8 @@ public class MovieSimple implements MouseListener, GLEventListener, GLMediaEvent
}
public void dispose(GLAutoDrawable drawable) {
+ if(null == mPlayer) { return; }
+
GL2ES2 gl = drawable.getGL().getGL2ES2();
mPlayer.destroy(gl);
@@ -368,6 +388,8 @@ public class MovieSimple implements MouseListener, GLEventListener, GLMediaEvent
}
public void display(GLAutoDrawable drawable) {
+ if(null == mPlayer) { return; }
+
GL2ES2 gl = drawable.getGL().getGL2ES2();
st.useProgram(gl, true);
@@ -412,7 +434,7 @@ public class MovieSimple implements MouseListener, GLEventListener, GLMediaEvent
public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
}
- public static void main(String[] args) throws MalformedURLException {
+ public static void main(String[] args) throws IOException, MalformedURLException {
String fname="file:///mnt/sdcard/Movies/BigBuckBunny_320x180.mp4";
if(args.length>0) fname=args[0];
new MovieSimple(new URL(fname)).run();