3dphotoshoot

view src/android/MainActivity.java @ 9:d1b456d08713

texture matrix and video size from JNI
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 25 May 2015 05:27:26 +0300
parents 9fc7d52f578d
children dccbd7d65517
line source
1 package com.mutantstargoat.photoshoot3d;
3 import android.app.NativeActivity;
4 import android.util.Log;
5 import static android.opengl.GLES20.*;
6 import android.hardware.Camera;
7 import android.hardware.Camera.CameraInfo;
8 import android.graphics.SurfaceTexture;
10 /*
11 import android.os.Bundle;
12 import android.content.Context;
13 import android.hardware.camera2.*;
14 */
16 public class MainActivity extends NativeActivity {
17 public static String tag = "photoshoot3d";
18 public static boolean frame_pending;
20 public static void foo()
21 {
22 glClearColor(0.2f, 1.0f, 0.3f, 1.0f);
23 }
25 // old camera api (fallback)
26 private static Camera cam;
27 private static Camera.Parameters params;
28 private static int preview_width, preview_height;
29 private static SurfaceTexture surftex;
31 public static int start_video(int texid)
32 {
33 int num_cams = Camera.getNumberOfCameras();
34 Log.i(tag, "Found " + num_cams + " cameras");
36 if(num_cams < 1) {
37 return -1;
38 }
40 for(int i=0; i<num_cams; i++) {
41 CameraInfo info = new CameraInfo();
42 Camera.getCameraInfo(i, info);
44 String facing_str = info.facing == CameraInfo.CAMERA_FACING_FRONT ? "front" : "back";
46 Log.i(tag, "camera[" + i + "]: " + facing_str);
47 }
49 surftex = new SurfaceTexture(texid);
50 surftex.setOnFrameAvailableListener(new FrameHandler());
52 cam = Camera.open(0);
54 params = cam.getParameters();
55 params.set("orientation", "landscape");
56 cam.setParameters(params);
58 preview_width = params.getPreviewSize().width;
59 preview_height = params.getPreviewSize().height;
61 try {
62 cam.setPreviewTexture(surftex);
63 }
64 catch(java.io.IOException e) {
65 Log.e(tag, "failed to set preview texture");
66 cam = null;
67 return -1;
68 }
69 cam.startPreview();
71 return 0;
72 }
74 public static void stop_video()
75 {
76 cam.stopPreview();
77 cam = null;
78 params = null;
79 surftex = null;
80 }
82 public static synchronized void update(float [] matrix)
83 {
84 if(cam != null && surftex != null) {
85 if(frame_pending) {
86 surftex.updateTexImage();
87 frame_pending = false;
88 }
89 surftex.getTransformMatrix(matrix);
90 }
91 }
92 }
94 class FrameHandler implements SurfaceTexture.OnFrameAvailableListener {
95 @Override
96 public synchronized void onFrameAvailable(SurfaceTexture stex)
97 {
98 MainActivity.frame_pending = true;
99 }
100 }