3dphotoshoot

view src/android/camera.c @ 6:e31e23ead56f

GAMO TO XRISTO KAI TIN PANAGIA TOU ANDROID
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 21 May 2015 19:03:00 +0300
parents
children 7f6e6eb3d20e
line source
1 #include <stdio.h>
2 #include <assert.h>
3 #include <jni.h>
4 #include "opengl.h"
5 #include "camera.h"
8 static JavaVM *jvm;
9 static JNIEnv *jni;
10 static jclass activity_class;
11 static unsigned int tex;
12 static int capturing;
14 int cam_init(void *platform_data)
15 {
16 int glerr;
17 struct cam_android_platform_data *pdata = platform_data;
19 jvm = pdata->vm;
20 jni = pdata->jni;
21 activity_class = pdata->activity_class;
23 // create the camera texture
24 assert(glGetError() == GL_NO_ERROR);
25 glGenTextures(1, &tex);
26 glBindTexture(GL_TEXTURE_EXTERNAL_OES, tex);
27 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
28 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
30 glerr = glGetError();
31 assert(glerr == GL_NO_ERROR);
32 return glerr == GL_NO_ERROR ? 0 : -1;
33 }
35 void cam_shutdown(void)
36 {
37 cam_stop_video();
38 glDeleteTextures(1, &tex);
39 tex = 0;
40 }
42 unsigned int cam_texture(void)
43 {
44 return tex;
45 }
47 void cam_texture_size(int *w, int *h)
48 {
49 /* TODO */
50 }
52 int cam_start_video(void)
53 {
54 jmethodID method;
56 if(!jvm) {
57 fprintf(stderr, "failed to start video, camera not initialized\n");
58 return -1;
59 }
60 if(cam_is_capturing()) {
61 return 0;
62 }
64 if(!(method = (*jni)->GetStaticMethodID(jni, activity_class, "start_video", "(I)I"))) {
65 fprintf(stderr, "failed to find static method: start_video\n");
66 return -1;
67 }
68 if((*jni)->CallStaticIntMethod(jni, activity_class, method, tex) == -1) {
69 fprintf(stderr, "failed to start video capture\n");
70 capturing = 0;
71 return -1;
72 }
73 capturing = 1;
75 printf("video started\n");
77 return 1;
78 }
80 int cam_stop_video(void)
81 {
82 jmethodID method;
84 if(!jvm) {
85 fprintf(stderr, "failed to stop video, camera not initialized\n");
86 return -1;
87 }
89 if(!cam_is_capturing()) {
90 return 0;
91 }
93 if(!(method = (*jni)->GetStaticMethodID(jni, activity_class, "stop_video", "()V"))) {
94 fprintf(stderr, "failed to find static method: stop_video\n");
95 return -1;
96 }
97 (*jni)->CallStaticVoidMethod(jni, activity_class, method);
98 capturing = 0;
100 printf("video stopped\n");
102 return 0;
103 }
105 int cam_is_capturing(void)
106 {
107 return capturing; // XXX is it better to do this properly through JNI?
108 }
110 int cam_take_picture(void)
111 {
112 return -1; // TODO
113 }