3dphotoshoot

view src/android/MainActivity.java @ 7:7f6e6eb3d20e

some progress...
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 23 May 2015 23:14:44 +0300
parents e31e23ead56f
children 9fc7d52f578d
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";
19 public static void foo()
20 {
21 glClearColor(0.2f, 1.0f, 0.3f, 1.0f);
22 }
24 // old camera api (fallback)
25 private static Camera cam;
26 private static SurfaceTexture surftex;
28 public static int start_video(int texid)
29 {
30 int num_cams = Camera.getNumberOfCameras();
31 Log.i(tag, "Found " + num_cams + " cameras");
33 for(int i=0; i<num_cams; i++) {
34 CameraInfo info = new CameraInfo();
35 Camera.getCameraInfo(i, info);
37 String facing_str = info.facing == CameraInfo.CAMERA_FACING_FRONT ? "front" : "back";
39 Log.i(tag, "camera[" + i + "]: " + facing_str);
40 }
42 surftex = new SurfaceTexture(texid);
43 surftex.setOnFrameAvailableListener(new FrameHandler());
45 cam = Camera.open();
46 try {
47 cam.setPreviewTexture(surftex);
48 }
49 catch(java.io.IOException e) {
50 Log.e(tag, "failed to set preview texture");
51 cam = null;
52 return -1;
53 }
54 cam.startPreview();
56 return 0;
57 }
59 public static void stop_video()
60 {
61 cam.stopPreview();
62 cam = null;
63 surftex = null;
64 }
66 public static void update()
67 {
68 if(cam != null && surftex != null) {
69 surftex.updateTexImage();
70 }
71 }
72 }
74 class FrameHandler implements SurfaceTexture.OnFrameAvailableListener {
75 @Override
76 public synchronized void onFrameAvailable(SurfaceTexture stex)
77 {
78 Log.i(MainActivity.tag, "new video frame");
79 stex.updateTexImage();
80 }
81 }