3dphotoshoot
annotate src/android/MainActivity.java @ 22:d7fe157c402d
fonts
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 13 Jun 2015 05:32:07 +0300 |
parents | d1b456d08713 |
children |
rev | line source |
---|---|
nuclear@0 | 1 package com.mutantstargoat.photoshoot3d; |
nuclear@0 | 2 |
nuclear@18 | 3 import android.os.Bundle; |
nuclear@0 | 4 import android.app.NativeActivity; |
nuclear@0 | 5 import android.util.Log; |
nuclear@4 | 6 import static android.opengl.GLES20.*; |
nuclear@4 | 7 import android.hardware.Camera; |
nuclear@4 | 8 import android.hardware.Camera.CameraInfo; |
nuclear@4 | 9 import android.graphics.SurfaceTexture; |
nuclear@7 | 10 |
nuclear@3 | 11 /* |
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@8 | 18 public static boolean frame_pending; |
nuclear@3 | 19 |
nuclear@18 | 20 /* |
nuclear@18 | 21 static { |
nuclear@18 | 22 System.loadLibrary("photoshoot3d"); |
nuclear@18 | 23 } |
nuclear@18 | 24 */ |
nuclear@18 | 25 |
nuclear@18 | 26 @Override |
nuclear@18 | 27 protected void onCreate( Bundle savedInstanceState ) |
nuclear@18 | 28 { |
nuclear@18 | 29 super.onCreate( savedInstanceState ); |
nuclear@18 | 30 } |
nuclear@18 | 31 |
nuclear@4 | 32 public static void foo() |
nuclear@0 | 33 { |
nuclear@4 | 34 glClearColor(0.2f, 1.0f, 0.3f, 1.0f); |
nuclear@0 | 35 } |
nuclear@3 | 36 |
nuclear@3 | 37 // old camera api (fallback) |
nuclear@4 | 38 private static Camera cam; |
nuclear@9 | 39 private static Camera.Parameters params; |
nuclear@9 | 40 private static int preview_width, preview_height; |
nuclear@7 | 41 private static SurfaceTexture surftex; |
nuclear@3 | 42 |
nuclear@4 | 43 public static int start_video(int texid) |
nuclear@4 | 44 { |
nuclear@4 | 45 int num_cams = Camera.getNumberOfCameras(); |
nuclear@4 | 46 Log.i(tag, "Found " + num_cams + " cameras"); |
nuclear@3 | 47 |
nuclear@8 | 48 if(num_cams < 1) { |
nuclear@8 | 49 return -1; |
nuclear@8 | 50 } |
nuclear@8 | 51 |
nuclear@4 | 52 for(int i=0; i<num_cams; i++) { |
nuclear@4 | 53 CameraInfo info = new CameraInfo(); |
nuclear@4 | 54 Camera.getCameraInfo(i, info); |
nuclear@3 | 55 |
nuclear@4 | 56 String facing_str = info.facing == CameraInfo.CAMERA_FACING_FRONT ? "front" : "back"; |
nuclear@3 | 57 |
nuclear@4 | 58 Log.i(tag, "camera[" + i + "]: " + facing_str); |
nuclear@3 | 59 } |
nuclear@3 | 60 |
nuclear@7 | 61 surftex = new SurfaceTexture(texid); |
nuclear@4 | 62 surftex.setOnFrameAvailableListener(new FrameHandler()); |
nuclear@4 | 63 |
nuclear@8 | 64 cam = Camera.open(0); |
nuclear@8 | 65 |
nuclear@9 | 66 params = cam.getParameters(); |
nuclear@8 | 67 params.set("orientation", "landscape"); |
nuclear@8 | 68 cam.setParameters(params); |
nuclear@8 | 69 |
nuclear@9 | 70 preview_width = params.getPreviewSize().width; |
nuclear@9 | 71 preview_height = params.getPreviewSize().height; |
nuclear@9 | 72 |
nuclear@4 | 73 try { |
nuclear@4 | 74 cam.setPreviewTexture(surftex); |
nuclear@4 | 75 } |
nuclear@4 | 76 catch(java.io.IOException e) { |
nuclear@4 | 77 Log.e(tag, "failed to set preview texture"); |
nuclear@4 | 78 cam = null; |
nuclear@4 | 79 return -1; |
nuclear@4 | 80 } |
nuclear@4 | 81 cam.startPreview(); |
nuclear@4 | 82 |
nuclear@4 | 83 return 0; |
nuclear@3 | 84 } |
nuclear@3 | 85 |
nuclear@4 | 86 public static void stop_video() |
nuclear@3 | 87 { |
nuclear@4 | 88 cam.stopPreview(); |
nuclear@4 | 89 cam = null; |
nuclear@9 | 90 params = null; |
nuclear@7 | 91 surftex = null; |
nuclear@7 | 92 } |
nuclear@7 | 93 |
nuclear@9 | 94 public static synchronized void update(float [] matrix) |
nuclear@7 | 95 { |
nuclear@9 | 96 if(cam != null && surftex != null) { |
nuclear@9 | 97 if(frame_pending) { |
nuclear@9 | 98 surftex.updateTexImage(); |
nuclear@9 | 99 frame_pending = false; |
nuclear@9 | 100 } |
nuclear@9 | 101 surftex.getTransformMatrix(matrix); |
nuclear@7 | 102 } |
nuclear@3 | 103 } |
nuclear@0 | 104 } |
nuclear@3 | 105 |
nuclear@4 | 106 class FrameHandler implements SurfaceTexture.OnFrameAvailableListener { |
nuclear@6 | 107 @Override |
nuclear@6 | 108 public synchronized void onFrameAvailable(SurfaceTexture stex) |
nuclear@3 | 109 { |
nuclear@8 | 110 MainActivity.frame_pending = true; |
nuclear@3 | 111 } |
nuclear@3 | 112 } |