3dphotoshoot

annotate 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
rev   line source
nuclear@0 1 package com.mutantstargoat.photoshoot3d;
nuclear@0 2
nuclear@0 3 import android.app.NativeActivity;
nuclear@0 4 import android.util.Log;
nuclear@4 5 import static android.opengl.GLES20.*;
nuclear@4 6 import android.hardware.Camera;
nuclear@4 7 import android.hardware.Camera.CameraInfo;
nuclear@4 8 import android.graphics.SurfaceTexture;
nuclear@7 9
nuclear@3 10 /*
nuclear@3 11 import android.os.Bundle;
nuclear@3 12 import android.content.Context;
nuclear@3 13 import android.hardware.camera2.*;
nuclear@3 14 */
nuclear@0 15
nuclear@0 16 public class MainActivity extends NativeActivity {
nuclear@6 17 public static String tag = "photoshoot3d";
nuclear@3 18
nuclear@4 19 public static void foo()
nuclear@0 20 {
nuclear@4 21 glClearColor(0.2f, 1.0f, 0.3f, 1.0f);
nuclear@0 22 }
nuclear@3 23
nuclear@3 24 // old camera api (fallback)
nuclear@4 25 private static Camera cam;
nuclear@7 26 private static SurfaceTexture surftex;
nuclear@3 27
nuclear@4 28 public static int start_video(int texid)
nuclear@4 29 {
nuclear@4 30 int num_cams = Camera.getNumberOfCameras();
nuclear@4 31 Log.i(tag, "Found " + num_cams + " cameras");
nuclear@3 32
nuclear@4 33 for(int i=0; i<num_cams; i++) {
nuclear@4 34 CameraInfo info = new CameraInfo();
nuclear@4 35 Camera.getCameraInfo(i, info);
nuclear@3 36
nuclear@4 37 String facing_str = info.facing == CameraInfo.CAMERA_FACING_FRONT ? "front" : "back";
nuclear@3 38
nuclear@4 39 Log.i(tag, "camera[" + i + "]: " + facing_str);
nuclear@3 40 }
nuclear@3 41
nuclear@7 42 surftex = new SurfaceTexture(texid);
nuclear@4 43 surftex.setOnFrameAvailableListener(new FrameHandler());
nuclear@4 44
nuclear@4 45 cam = Camera.open();
nuclear@4 46 try {
nuclear@4 47 cam.setPreviewTexture(surftex);
nuclear@4 48 }
nuclear@4 49 catch(java.io.IOException e) {
nuclear@4 50 Log.e(tag, "failed to set preview texture");
nuclear@4 51 cam = null;
nuclear@4 52 return -1;
nuclear@4 53 }
nuclear@4 54 cam.startPreview();
nuclear@4 55
nuclear@4 56 return 0;
nuclear@3 57 }
nuclear@3 58
nuclear@4 59 public static void stop_video()
nuclear@3 60 {
nuclear@4 61 cam.stopPreview();
nuclear@4 62 cam = null;
nuclear@7 63 surftex = null;
nuclear@7 64 }
nuclear@7 65
nuclear@7 66 public static void update()
nuclear@7 67 {
nuclear@7 68 if(cam != null && surftex != null) {
nuclear@7 69 surftex.updateTexImage();
nuclear@7 70 }
nuclear@3 71 }
nuclear@0 72 }
nuclear@3 73
nuclear@4 74 class FrameHandler implements SurfaceTexture.OnFrameAvailableListener {
nuclear@6 75 @Override
nuclear@6 76 public synchronized void onFrameAvailable(SurfaceTexture stex)
nuclear@3 77 {
nuclear@6 78 Log.i(MainActivity.tag, "new video frame");
nuclear@4 79 stex.updateTexImage();
nuclear@3 80 }
nuclear@3 81 }