1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
/*
* Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistribution of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* Neither the name of Sun Microsystems, Inc. or the names of
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind. ALL
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
* INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
* MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
* ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
* ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
* DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
* DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
* SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
*/
package demos.es2.openmax;
// import demos.es1.cube.Cube;
import javax.media.opengl.*;
import com.jogamp.opengl.util.glsl.fixedfunc.*;
import com.jogamp.openmax.*;
import java.net.*;
import com.jogamp.newt.*;
import com.jogamp.newt.event.*;
import com.jogamp.newt.opengl.*;
public class MovieCube implements MouseListener, GLEventListener, OMXEventListener {
GLWindow window;
boolean quit = false;
Cube cube=null;
String stream;
OMXInstance movie=null;
public void changedAttributes(OMXInstance omx, int event_mask) {
System.out.println("changed stream attr ("+event_mask+"): "+omx);
}
public void mouseClicked(MouseEvent e) {
switch(e.getClickCount()) {
case 2:
quit=true;
break;
}
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mousePressed(MouseEvent e) {
}
public void mouseReleased(MouseEvent e) {
}
public void mouseMoved(MouseEvent e) {
}
public void mouseDragged(MouseEvent e) {
}
public void mouseWheelMoved(MouseEvent e) {
}
public MovieCube (String stream) {
cube = new Cube(true, false);
this.stream = stream;
}
private void run() {
System.err.println("MovieCube.run()");
try {
GLCapabilities caps = new GLCapabilities(GLProfile.getGL2ES2());
// For emulation library, use 16 bpp
caps.setRedBits(5);
caps.setGreenBits(6);
caps.setBlueBits(5);
caps.setDepthBits(16);
window = GLWindow.create(caps);
window.addMouseListener(this);
window.addGLEventListener(this);
// window.setEventHandlerMode(GLWindow.EVENT_HANDLER_GL_CURRENT); // default
// window.setEventHandlerMode(GLWindow.EVENT_HANDLER_GL_NONE); // no current ..
// Size OpenGL to Video Surface
window.setFullscreen(true);
window.setVisible(true);
while (!quit) {
window.display();
}
// Shut things down cooperatively
if(null!=movie) {
movie.destroy(window.getGL());
movie=null;
}
window.destroy();
System.out.println("MovieCube shut down cleanly.");
} catch (Throwable t) {
t.printStackTrace();
}
}
public void init(GLAutoDrawable drawable) {
GL2ES1 gl = FixedFuncUtil.wrapFixedFuncEmul(drawable.getGL());
System.out.println(gl);
gl.glGetError(); // flush error ..
gl.glActiveTexture(GL.GL_TEXTURE0);
try {
movie = new OMXInstance();
movie.addEventListener(this);
movie.setStream(4, new URL(stream));
System.out.println("p0 "+movie);
} catch (MalformedURLException mue) { mue.printStackTrace(); }
if(null!=movie) {
movie.setStreamAllEGLImageTexture2D(gl);
movie.activateStream();
System.out.println("p1 "+movie);
movie.play();
}
cube.init(drawable);
/*
if(gl.isGLES2()) {
GLES2 gles2 = gl.getGLES2();
// Debug ..
//DebugGLES2 gldbg = new DebugGLES2(gles2);
//gles2.getContext().setGL(gldbg);
//gles2 = gldbg;
// Trace ..
//TraceGLES2 gltrace = new TraceGLES2(gles2, System.err);
gles2.getContext().setGL(gltrace);
gl = gltrace;
}*/
}
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
cube.reshape(drawable, x, y, width, height);
System.out.println("reshape "+width+"x"+height);
}
public void dispose(GLAutoDrawable drawable) {
GL2ES2 gl = drawable.getGL().getGL2ES2();
movie.destroy(gl);
movie=null;
cube.dispose(drawable);
cube=null;
quit=true;
}
public void display(GLAutoDrawable drawable) {
GL2ES1 gl = drawable.getGL().getGL2ES1();
com.jogamp.opengl.util.texture.Texture tex = null;
if(null!=movie) {
tex=movie.getNextTextureID();
if(null!=tex) {
System.out.println("Use: "+tex);
tex.enable(gl);
tex.bind(gl);
}
}
cube.display(drawable);
if(null!=tex) {
tex.disable(gl);
}
}
public void displayChanged(javax.media.opengl.GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
}
public static void main(String[] args) {
String fname="file:///Storage Card/resources/a.mp4";
if(args.length>0) fname=args[0];
new MovieCube(fname).run();
System.exit(0);
}
}
|