3dphotoshoot
changeset 4:38377f54527a
having a whack at the camera api... at least the java crap compiles, we'll try calling it later
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Tue, 19 May 2015 06:05:51 +0300 |
parents | 9df99687a2ff |
children | 31cc6615428d |
files | src/android/MainActivity.java src/android/amain.c src/game.c |
diffstat | 3 files changed, 44 insertions(+), 80 deletions(-) [+] |
line diff
1.1 --- a/src/android/MainActivity.java Fri May 15 05:15:47 2015 +0300 1.2 +++ b/src/android/MainActivity.java Tue May 19 06:05:51 2015 +0300 1.3 @@ -2,99 +2,68 @@ 1.4 1.5 import android.app.NativeActivity; 1.6 import android.util.Log; 1.7 +import static android.opengl.GLES20.*; 1.8 +import android.hardware.Camera; 1.9 +import android.hardware.Camera.CameraInfo; 1.10 +import android.graphics.SurfaceTexture; 1.11 /* 1.12 import android.os.Bundle; 1.13 import android.content.Context; 1.14 -import android.hardware.Camera; 1.15 -import android.hardware.Camera.CameraInfo; 1.16 import android.hardware.camera2.*; 1.17 */ 1.18 1.19 public class MainActivity extends NativeActivity { 1.20 private static String tag = "photoshoot3d"; 1.21 1.22 - public static int foo(String s, int n) 1.23 + public static void foo() 1.24 { 1.25 - Log.i(tag, s + ": " + n); 1.26 - return 42; 1.27 + glClearColor(0.2f, 1.0f, 0.3f, 1.0f); 1.28 } 1.29 1.30 - /* 1.31 // old camera api (fallback) 1.32 - private Camera cam; 1.33 + private static Camera cam; 1.34 1.35 - // camera2 api (sdk version >= 21) 1.36 - private CameraManager cman; 1.37 - private CameraDevice cam2; 1.38 - private CameraCaptureSession cam_session; 1.39 + public static int start_video(int texid) 1.40 + { 1.41 + int num_cams = Camera.getNumberOfCameras(); 1.42 + Log.i(tag, "Found " + num_cams + " cameras"); 1.43 1.44 - @Override 1.45 - protected void onCreate(Bundle state) 1.46 - { 1.47 - super.onCreate(state); 1.48 + for(int i=0; i<num_cams; i++) { 1.49 + CameraInfo info = new CameraInfo(); 1.50 + Camera.getCameraInfo(i, info); 1.51 1.52 - if(android.os.Build.VERSION.SDK_INT >= 21) { 1.53 - Log.i(tag, "Using the new camera API"); 1.54 + String facing_str = info.facing == CameraInfo.CAMERA_FACING_FRONT ? "front" : "back"; 1.55 1.56 - cman = (CameraManager)getSystemService(Context.CAMERA_SERVICE); 1.57 - 1.58 - try { 1.59 - String [] clist = cman.getCameraIdList(); 1.60 - Log.i(tag, "Found " + clist.length + " cameras"); 1.61 - 1.62 - for(int i=0; i<clist.length; i++) { 1.63 - Log.i(tag, "camera[" + i + "]: " + clist[i]); 1.64 - } 1.65 - } 1.66 - catch(CameraAccessException e) { 1.67 - Log.e(tag, "camera access exception"); 1.68 - } 1.69 - 1.70 - } else { 1.71 - // fallback to the old Camera API 1.72 - Log.i(tag, "Using the old camera API"); 1.73 - 1.74 - int num_cams = Camera.getNumberOfCameras(); 1.75 - Log.i(tag, "Found " + num_cams + " cameras"); 1.76 - 1.77 - for(int i=0; i<num_cams; i++) { 1.78 - CameraInfo info = new CameraInfo(); 1.79 - Camera.getCameraInfo(i, info); 1.80 - 1.81 - String facing_str = info.facing == CameraInfo.CAMERA_FACING_FRONT ? "front" : "back"; 1.82 - 1.83 - Log.i(tag, "camera[" + i + "]: " + facing_str); 1.84 - } 1.85 + Log.i(tag, "camera[" + i + "]: " + facing_str); 1.86 } 1.87 1.88 - start_video(); 1.89 + SurfaceTexture surftex = new SurfaceTexture(texid); 1.90 + surftex.setOnFrameAvailableListener(new FrameHandler()); 1.91 + 1.92 + cam = Camera.open(); 1.93 + try { 1.94 + cam.setPreviewTexture(surftex); 1.95 + } 1.96 + catch(java.io.IOException e) { 1.97 + Log.e(tag, "failed to set preview texture"); 1.98 + cam = null; 1.99 + return -1; 1.100 + } 1.101 + cam.startPreview(); 1.102 + 1.103 + return 0; 1.104 } 1.105 1.106 - public void start_video() 1.107 + public static void stop_video() 1.108 { 1.109 - cam = Camera.open(); 1.110 - 1.111 - CamPreview preview = new CamPreview(this, cam); 1.112 - 1.113 + cam.stopPreview(); 1.114 + cam = null; 1.115 } 1.116 - */ 1.117 } 1.118 1.119 -/* 1.120 -class CamPreview extends ViewGroup implements SurfaceHolder.Callback { 1.121 - SurfaceView surf_view; 1.122 - SurfaceHolder surf_holder; 1.123 - 1.124 - CamPreview(Context ctx) 1.125 +class FrameHandler implements SurfaceTexture.OnFrameAvailableListener { 1.126 + public void onFrameAvailable(SurfaceTexture stex) 1.127 { 1.128 - super(ctx); 1.129 - 1.130 - surf_view = new SurfaceView(ctx); 1.131 - addView(surf_view); 1.132 - 1.133 - surf_holder = surf_view.getHolder(); 1.134 - surf_holder.addCallback(this); 1.135 - surf_holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); 1.136 + stex.updateTexImage(); 1.137 } 1.138 } 1.139 -*/
2.1 --- a/src/android/amain.c Fri May 15 05:15:47 2015 +0300 2.2 +++ b/src/android/amain.c Tue May 19 06:05:51 2015 +0300 2.3 @@ -26,24 +26,20 @@ 2.4 static JNIEnv *jni; 2.5 static jclass activity_class; 2.6 2.7 -static int call_foo(const char *s, int n) 2.8 +static int call_foo() 2.9 { 2.10 jmethodID foo_id; 2.11 - jstring jstr; 2.12 - int res; 2.13 2.14 printf("call_foo() [activity_class=%p]\n", (void*)activity_class); 2.15 2.16 - if(!(foo_id = (*jni)->GetStaticMethodID(jni, activity_class, "foo", "(Ljava/lang/String;I)I"))) { 2.17 + if(!(foo_id = (*jni)->GetStaticMethodID(jni, activity_class, "foo", "()V"))) { 2.18 fprintf(stderr, "static method foo not found\n"); 2.19 return -1; 2.20 } 2.21 2.22 - jstr = (*jni)->NewStringUTF(jni, s); 2.23 - res = (*jni)->CallStaticIntMethod(jni, activity_class, foo_id, jstr, n); 2.24 - (*jni)->DeleteLocalRef(jni, jstr); 2.25 + (*jni)->CallStaticIntMethod(jni, activity_class, foo_id); 2.26 2.27 - return res; 2.28 + return 0; 2.29 } 2.30 2.31 void android_main(struct android_app *app_ptr) 2.32 @@ -63,8 +59,6 @@ 2.33 } 2.34 activity_class = (*jni)->GetObjectClass(jni, app->activity->clazz); 2.35 2.36 - printf("JNI call returned: %d\n", call_foo("testing C->java jni calls", 42)); 2.37 - 2.38 for(;;) { 2.39 int num_events; 2.40 struct android_poll_source *pollsrc; 2.41 @@ -81,6 +75,7 @@ 2.42 } 2.43 2.44 if(init_done) { 2.45 + call_foo(); 2.46 game_display(get_time_msec()); 2.47 eglSwapBuffers(dpy, surf); 2.48 }
3.1 --- a/src/game.c Fri May 15 05:15:47 2015 +0300 3.2 +++ b/src/game.c Tue May 19 06:05:51 2015 +0300 3.3 @@ -23,9 +23,9 @@ 3.4 3.5 void game_display(unsigned long msec) 3.6 { 3.7 - float tsec = (float)msec / 1000.0f; 3.8 + //float tsec = (float)msec / 1000.0f; 3.9 3.10 - glClearColor(sin(tsec * 10.0), cos(tsec * 10.0), -sin(tsec * 10.0), 1.0); 3.11 + //glClearColor(sin(tsec * 10.0), cos(tsec * 10.0), -sin(tsec * 10.0), 1.0); 3.12 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 3.13 3.14 glMatrixMode(GL_MODELVIEW);