1
1
package in .omerjerk .processing .video .android ;
2
2
3
+ import java .lang .reflect .Method ;
3
4
import java .nio .IntBuffer ;
4
5
5
6
import in .omerjerk .processing .video .android .helpers .FullFrameRect ;
@@ -29,6 +30,9 @@ public static void log(String log) {
29
30
if (DEBUG )
30
31
System .out .println (log );
31
32
}
33
+
34
+ private Method eventMethod ;
35
+ private Object eventHandler ;
32
36
33
37
protected GLSurfaceView glView ;
34
38
protected SurfaceTexture mSurfaceTexture ;
@@ -49,6 +53,7 @@ public static void log(String log) {
49
53
50
54
public abstract void onResume ();
51
55
public abstract void onPause ();
56
+ public abstract String getEventName ();
52
57
53
58
public VideoBase (PApplet parent ) {
54
59
super ();
@@ -57,6 +62,8 @@ public VideoBase(PApplet parent) {
57
62
parent .registerMethod ("pause" , this );
58
63
parent .registerMethod ("resume" , this );
59
64
65
+ setEventHandlerObject (parent );
66
+
60
67
glView = (GLSurfaceView ) parent .getSurfaceView ();
61
68
pg = (PGraphicsOpenGL )parent .g ;
62
69
// customTexture = new Texture(pg, width, height);
@@ -69,6 +76,10 @@ public VideoBase(PApplet parent) {
69
76
public boolean available () {
70
77
return isAvailable ;
71
78
}
79
+
80
+ public void read () {
81
+ getImage (false );
82
+ }
72
83
73
84
protected void createSurfaceTexture () {
74
85
mFullScreen = new FullFrameRect (new Texture2dProgram (
@@ -160,7 +171,7 @@ public void run() {
160
171
surfaceTexture .getTransformMatrix (mSTMatrix );
161
172
mFullScreen .drawFrame (mTextureId , mSTMatrix );
162
173
163
- getImage ( false );
174
+ fireEvent ( );
164
175
165
176
/*
166
177
* pixelBuffer.position(0); GLES20.glReadPixels(0, 0, width,
@@ -237,4 +248,37 @@ public void loadPixels() {
237
248
pixelBuffer .position (0 );
238
249
pixelBuffer .get (this .pixels );
239
250
}
251
+
252
+ private void setEventHandlerObject (Object obj ) {
253
+ eventHandler = obj ;
254
+
255
+ try {
256
+ eventMethod = obj .getClass ().getMethod (getEventName (), Capture .class );
257
+ return ;
258
+ } catch (Exception e ) {
259
+ // no such method, or an error.. which is fine, just ignore
260
+ }
261
+
262
+ // The captureEvent method may be declared as receiving Object, rather
263
+ // than Capture.
264
+ try {
265
+ eventMethod = obj .getClass ().getMethod (getEventName (), Object .class );
266
+ return ;
267
+ } catch (Exception e ) {
268
+ // no such method, or an error.. which is fine, just ignore
269
+ }
270
+ }
271
+
272
+ private void fireEvent () {
273
+ if (eventMethod != null ) {
274
+ try {
275
+ eventMethod .invoke (eventHandler , this );
276
+
277
+ } catch (Exception e ) {
278
+ System .err .println ("error, disabling " + getEventName () + "()" );
279
+ e .printStackTrace ();
280
+ eventMethod = null ;
281
+ }
282
+ }
283
+ }
240
284
}
0 commit comments