blob: 91f003d59c4647b8da471bf17eada56004c56a18 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2**
3** Copyright 2008, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18//#define LOG_NDEBUG 0
19#define LOG_TAG "Camera-JNI"
20#include <utils/Log.h>
21
22#include "jni.h"
23#include "JNIHelp.h"
Andreas Gampeed6b9df2014-11-20 22:02:20 -080024#include "core_jni_helpers.h"
Igor Murashkinc99db2b2012-10-29 13:38:10 -070025#include <android_runtime/android_graphics_SurfaceTexture.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080026#include <android_runtime/android_view_Surface.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027
Eino-Ville Talvalaf7c6c5a2012-09-19 11:46:11 -070028#include <cutils/properties.h>
Andrew Harp94927df2009-10-20 01:47:05 -040029#include <utils/Vector.h>
Ruben Brunkfeb50af2014-05-09 19:58:49 -070030#include <utils/Errors.h>
Andrew Harp94927df2009-10-20 01:47:05 -040031
Andy McFaddend47f7d82012-12-18 09:48:38 -080032#include <gui/GLConsumer.h>
Mathias Agopian8335f1c2012-02-25 18:48:35 -080033#include <gui/Surface.h>
Mathias Agopian000479f2010-02-09 17:46:37 -080034#include <camera/Camera.h>
Mathias Agopian07952722009-05-19 19:08:10 -070035#include <binder/IMemory.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036
37using namespace android;
38
Igor Murashkina1d66272014-06-20 11:22:11 -070039enum {
40 // Keep up to date with Camera.java
41 CAMERA_HAL_API_VERSION_NORMAL_CONNECT = -2,
42};
43
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044struct fields_t {
45 jfieldID context;
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +080046 jfieldID facing;
47 jfieldID orientation;
Eino-Ville Talvalaf7c6c5a2012-09-19 11:46:11 -070048 jfieldID canDisableShutterSound;
Wu-cheng Lif0d6a482011-07-28 05:30:59 +080049 jfieldID face_rect;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +080050 jfieldID face_score;
Igor Murashkin0601ab12014-09-18 15:17:20 -070051 jfieldID face_id;
52 jfieldID face_left_eye;
53 jfieldID face_right_eye;
54 jfieldID face_mouth;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +080055 jfieldID rect_left;
56 jfieldID rect_top;
57 jfieldID rect_right;
58 jfieldID rect_bottom;
Igor Murashkin0601ab12014-09-18 15:17:20 -070059 jfieldID point_x;
60 jfieldID point_y;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061 jmethodID post_event;
Wu-cheng Libb1e2752011-07-30 05:00:37 +080062 jmethodID rect_constructor;
63 jmethodID face_constructor;
Igor Murashkin0601ab12014-09-18 15:17:20 -070064 jmethodID point_constructor;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065};
66
67static fields_t fields;
68static Mutex sLock;
69
Dave Sparks5e271152009-06-23 17:30:11 -070070// provides persistent context for calls from native code to Java
71class JNICameraContext: public CameraListener
72{
73public:
74 JNICameraContext(JNIEnv* env, jobject weak_this, jclass clazz, const sp<Camera>& camera);
75 ~JNICameraContext() { release(); }
76 virtual void notify(int32_t msgType, int32_t ext1, int32_t ext2);
Wu-cheng Libb1e2752011-07-30 05:00:37 +080077 virtual void postData(int32_t msgType, const sp<IMemory>& dataPtr,
78 camera_frame_metadata_t *metadata);
Dave Sparks59c1a932009-07-08 15:56:53 -070079 virtual void postDataTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr);
Wu-cheng Libb1e2752011-07-30 05:00:37 +080080 void postMetadata(JNIEnv *env, int32_t msgType, camera_frame_metadata_t *metadata);
James Donge00cab72011-02-17 16:38:06 -080081 void addCallbackBuffer(JNIEnv *env, jbyteArray cbb, int msgType);
Andrew Harp94927df2009-10-20 01:47:05 -040082 void setCallbackMode(JNIEnv *env, bool installed, bool manualMode);
Dave Sparks5e271152009-06-23 17:30:11 -070083 sp<Camera> getCamera() { Mutex::Autolock _l(mLock); return mCamera; }
James Donge00cab72011-02-17 16:38:06 -080084 bool isRawImageCallbackBufferAvailable() const;
Dave Sparks5e271152009-06-23 17:30:11 -070085 void release();
86
87private:
88 void copyAndPost(JNIEnv* env, const sp<IMemory>& dataPtr, int msgType);
James Donge00cab72011-02-17 16:38:06 -080089 void clearCallbackBuffers_l(JNIEnv *env, Vector<jbyteArray> *buffers);
Andrew Harp94927df2009-10-20 01:47:05 -040090 void clearCallbackBuffers_l(JNIEnv *env);
James Donge00cab72011-02-17 16:38:06 -080091 jbyteArray getCallbackBuffer(JNIEnv *env, Vector<jbyteArray> *buffers, size_t bufferSize);
Dave Sparks5e271152009-06-23 17:30:11 -070092
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093 jobject mCameraJObjectWeak; // weak reference to java object
94 jclass mCameraJClass; // strong reference to java class
Wu-cheng Liffe1cf22009-09-10 16:49:17 +080095 sp<Camera> mCamera; // strong reference to native object
Wu-cheng Libb1e2752011-07-30 05:00:37 +080096 jclass mFaceClass; // strong reference to Face class
97 jclass mRectClass; // strong reference to Rect class
Igor Murashkin0601ab12014-09-18 15:17:20 -070098 jclass mPointClass; // strong reference to Point class
Dave Sparks5e271152009-06-23 17:30:11 -070099 Mutex mLock;
Andrew Harp94927df2009-10-20 01:47:05 -0400100
James Donge00cab72011-02-17 16:38:06 -0800101 /*
102 * Global reference application-managed raw image buffer queue.
103 *
104 * Manual-only mode is supported for raw image callbacks, which is
105 * set whenever method addCallbackBuffer() with msgType =
106 * CAMERA_MSG_RAW_IMAGE is called; otherwise, null is returned
107 * with raw image callbacks.
108 */
109 Vector<jbyteArray> mRawImageCallbackBuffers;
110
111 /*
112 * Application-managed preview buffer queue and the flags
113 * associated with the usage of the preview buffer callback.
114 */
Andrew Harp94927df2009-10-20 01:47:05 -0400115 Vector<jbyteArray> mCallbackBuffers; // Global reference application managed byte[]
116 bool mManualBufferMode; // Whether to use application managed buffers.
James Donge00cab72011-02-17 16:38:06 -0800117 bool mManualCameraCallbackSet; // Whether the callback has been set, used to
118 // reduce unnecessary calls to set the callback.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800119};
120
James Donge00cab72011-02-17 16:38:06 -0800121bool JNICameraContext::isRawImageCallbackBufferAvailable() const
122{
123 return !mRawImageCallbackBuffers.isEmpty();
124}
125
Dave Sparks5e271152009-06-23 17:30:11 -0700126sp<Camera> get_native_camera(JNIEnv *env, jobject thiz, JNICameraContext** pContext)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800127{
128 sp<Camera> camera;
129 Mutex::Autolock _l(sLock);
Ashok Bhat4838e332014-01-03 14:37:19 +0000130 JNICameraContext* context = reinterpret_cast<JNICameraContext*>(env->GetLongField(thiz, fields.context));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800131 if (context != NULL) {
Dave Sparks5e271152009-06-23 17:30:11 -0700132 camera = context->getCamera();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800133 }
Steve Block71f2cf12011-10-20 11:56:00 +0100134 ALOGV("get_native_camera: context=%p, camera=%p", context, camera.get());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800135 if (camera == 0) {
Eino-Ville Talvalaf9133342015-01-12 17:01:11 -0800136 jniThrowRuntimeException(env,
137 "Camera is being used after Camera.release() was called");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800138 }
139
140 if (pContext != NULL) *pContext = context;
141 return camera;
142}
143
Dave Sparks5e271152009-06-23 17:30:11 -0700144JNICameraContext::JNICameraContext(JNIEnv* env, jobject weak_this, jclass clazz, const sp<Camera>& camera)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145{
Dave Sparks5e271152009-06-23 17:30:11 -0700146 mCameraJObjectWeak = env->NewGlobalRef(weak_this);
147 mCameraJClass = (jclass)env->NewGlobalRef(clazz);
148 mCamera = camera;
Andrew Harp94927df2009-10-20 01:47:05 -0400149
Wu-cheng Libb1e2752011-07-30 05:00:37 +0800150 jclass faceClazz = env->FindClass("android/hardware/Camera$Face");
151 mFaceClass = (jclass) env->NewGlobalRef(faceClazz);
152
153 jclass rectClazz = env->FindClass("android/graphics/Rect");
154 mRectClass = (jclass) env->NewGlobalRef(rectClazz);
155
Igor Murashkin0601ab12014-09-18 15:17:20 -0700156 jclass pointClazz = env->FindClass("android/graphics/Point");
157 mPointClass = (jclass) env->NewGlobalRef(pointClazz);
158
Andrew Harp94927df2009-10-20 01:47:05 -0400159 mManualBufferMode = false;
160 mManualCameraCallbackSet = false;
Dave Sparks5e271152009-06-23 17:30:11 -0700161}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162
Dave Sparks5e271152009-06-23 17:30:11 -0700163void JNICameraContext::release()
164{
Steve Block71f2cf12011-10-20 11:56:00 +0100165 ALOGV("release");
Dave Sparks5e271152009-06-23 17:30:11 -0700166 Mutex::Autolock _l(mLock);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800167 JNIEnv *env = AndroidRuntime::getJNIEnv();
Dave Sparks5e271152009-06-23 17:30:11 -0700168
169 if (mCameraJObjectWeak != NULL) {
170 env->DeleteGlobalRef(mCameraJObjectWeak);
171 mCameraJObjectWeak = NULL;
172 }
173 if (mCameraJClass != NULL) {
174 env->DeleteGlobalRef(mCameraJClass);
175 mCameraJClass = NULL;
176 }
Wu-cheng Libb1e2752011-07-30 05:00:37 +0800177 if (mFaceClass != NULL) {
178 env->DeleteGlobalRef(mFaceClass);
179 mFaceClass = NULL;
180 }
181 if (mRectClass != NULL) {
182 env->DeleteGlobalRef(mRectClass);
183 mRectClass = NULL;
184 }
Igor Murashkin0601ab12014-09-18 15:17:20 -0700185 if (mPointClass != NULL) {
186 env->DeleteGlobalRef(mPointClass);
187 mPointClass = NULL;
188 }
Andrew Harp94927df2009-10-20 01:47:05 -0400189 clearCallbackBuffers_l(env);
Dave Sparks5e271152009-06-23 17:30:11 -0700190 mCamera.clear();
191}
192
193void JNICameraContext::notify(int32_t msgType, int32_t ext1, int32_t ext2)
194{
Steve Block71f2cf12011-10-20 11:56:00 +0100195 ALOGV("notify");
Dave Sparks5e271152009-06-23 17:30:11 -0700196
197 // VM pointer will be NULL if object is released
198 Mutex::Autolock _l(mLock);
199 if (mCameraJObjectWeak == NULL) {
Steve Block8564c8d2012-01-05 23:22:43 +0000200 ALOGW("callback on dead camera object");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800201 return;
202 }
Dave Sparks5e271152009-06-23 17:30:11 -0700203 JNIEnv *env = AndroidRuntime::getJNIEnv();
James Donge00cab72011-02-17 16:38:06 -0800204
205 /*
206 * If the notification or msgType is CAMERA_MSG_RAW_IMAGE_NOTIFY, change it
207 * to CAMERA_MSG_RAW_IMAGE since CAMERA_MSG_RAW_IMAGE_NOTIFY is not exposed
208 * to the Java app.
209 */
210 if (msgType == CAMERA_MSG_RAW_IMAGE_NOTIFY) {
211 msgType = CAMERA_MSG_RAW_IMAGE;
212 }
213
Dave Sparksc62f9bd2009-06-26 13:33:32 -0700214 env->CallStaticVoidMethod(mCameraJClass, fields.post_event,
Chih-Chung Chang6157de02009-09-24 15:29:35 -0700215 mCameraJObjectWeak, msgType, ext1, ext2, NULL);
Dave Sparks5e271152009-06-23 17:30:11 -0700216}
217
James Donge00cab72011-02-17 16:38:06 -0800218jbyteArray JNICameraContext::getCallbackBuffer(
219 JNIEnv* env, Vector<jbyteArray>* buffers, size_t bufferSize)
220{
221 jbyteArray obj = NULL;
222
223 // Vector access should be protected by lock in postData()
224 if (!buffers->isEmpty()) {
Dan Albert46d84442014-11-18 16:07:51 -0800225 ALOGV("Using callback buffer from queue of length %zu", buffers->size());
James Donge00cab72011-02-17 16:38:06 -0800226 jbyteArray globalBuffer = buffers->itemAt(0);
227 buffers->removeAt(0);
228
229 obj = (jbyteArray)env->NewLocalRef(globalBuffer);
230 env->DeleteGlobalRef(globalBuffer);
231
232 if (obj != NULL) {
233 jsize bufferLength = env->GetArrayLength(obj);
234 if ((int)bufferLength < (int)bufferSize) {
Dan Albert46d84442014-11-18 16:07:51 -0800235 ALOGE("Callback buffer was too small! Expected %zu bytes, but got %d bytes!",
James Donge00cab72011-02-17 16:38:06 -0800236 bufferSize, bufferLength);
237 env->DeleteLocalRef(obj);
238 return NULL;
239 }
240 }
241 }
242
243 return obj;
244}
245
Dave Sparks5e271152009-06-23 17:30:11 -0700246void JNICameraContext::copyAndPost(JNIEnv* env, const sp<IMemory>& dataPtr, int msgType)
247{
248 jbyteArray obj = NULL;
249
250 // allocate Java byte array and copy data
251 if (dataPtr != NULL) {
252 ssize_t offset;
253 size_t size;
254 sp<IMemoryHeap> heap = dataPtr->getMemory(&offset, &size);
Glenn Kasten2fbf25b2014-03-28 15:41:58 -0700255 ALOGV("copyAndPost: off=%zd, size=%zu", offset, size);
Dave Sparks5e271152009-06-23 17:30:11 -0700256 uint8_t *heapBase = (uint8_t*)heap->base();
257
258 if (heapBase != NULL) {
Dave Sparksc4ca4202009-07-13 09:38:20 -0700259 const jbyte* data = reinterpret_cast<const jbyte*>(heapBase + offset);
Andrew Harp94927df2009-10-20 01:47:05 -0400260
Wu-cheng Li5f0ef5f2011-09-21 16:40:23 +0800261 if (msgType == CAMERA_MSG_RAW_IMAGE) {
262 obj = getCallbackBuffer(env, &mRawImageCallbackBuffers, size);
263 } else if (msgType == CAMERA_MSG_PREVIEW_FRAME && mManualBufferMode) {
264 obj = getCallbackBuffer(env, &mCallbackBuffers, size);
Andrew Harp94927df2009-10-20 01:47:05 -0400265
Wu-cheng Li5f0ef5f2011-09-21 16:40:23 +0800266 if (mCallbackBuffers.isEmpty()) {
Steve Block71f2cf12011-10-20 11:56:00 +0100267 ALOGV("Out of buffers, clearing callback!");
Wu-cheng Li5f0ef5f2011-09-21 16:40:23 +0800268 mCamera->setPreviewCallbackFlags(CAMERA_FRAME_CALLBACK_FLAG_NOOP);
269 mManualCameraCallbackSet = false;
Andrew Harp94927df2009-10-20 01:47:05 -0400270
Wu-cheng Li5f0ef5f2011-09-21 16:40:23 +0800271 if (obj == NULL) {
Andrew Harp94927df2009-10-20 01:47:05 -0400272 return;
273 }
274 }
Wu-cheng Li5f0ef5f2011-09-21 16:40:23 +0800275 } else {
Steve Block71f2cf12011-10-20 11:56:00 +0100276 ALOGV("Allocating callback buffer");
Wu-cheng Li5f0ef5f2011-09-21 16:40:23 +0800277 obj = env->NewByteArray(size);
Andrew Harp94927df2009-10-20 01:47:05 -0400278 }
279
Dave Sparks5e271152009-06-23 17:30:11 -0700280 if (obj == NULL) {
Steve Block3762c312012-01-06 19:20:56 +0000281 ALOGE("Couldn't allocate byte array for JPEG data");
Dave Sparks5e271152009-06-23 17:30:11 -0700282 env->ExceptionClear();
283 } else {
Dave Sparksa95f4952009-07-10 18:13:36 -0700284 env->SetByteArrayRegion(obj, 0, size, data);
Dave Sparks5e271152009-06-23 17:30:11 -0700285 }
286 } else {
Steve Block3762c312012-01-06 19:20:56 +0000287 ALOGE("image heap is NULL");
Dave Sparks5e271152009-06-23 17:30:11 -0700288 }
289 }
290
291 // post image data to Java
292 env->CallStaticVoidMethod(mCameraJClass, fields.post_event,
293 mCameraJObjectWeak, msgType, 0, 0, obj);
294 if (obj) {
295 env->DeleteLocalRef(obj);
296 }
297}
298
Wu-cheng Libb1e2752011-07-30 05:00:37 +0800299void JNICameraContext::postData(int32_t msgType, const sp<IMemory>& dataPtr,
300 camera_frame_metadata_t *metadata)
Dave Sparks5e271152009-06-23 17:30:11 -0700301{
302 // VM pointer will be NULL if object is released
303 Mutex::Autolock _l(mLock);
304 JNIEnv *env = AndroidRuntime::getJNIEnv();
Dave Sparksd0cbb1a2009-06-29 19:03:33 -0700305 if (mCameraJObjectWeak == NULL) {
Steve Block8564c8d2012-01-05 23:22:43 +0000306 ALOGW("callback on dead camera object");
Dave Sparksd0cbb1a2009-06-29 19:03:33 -0700307 return;
308 }
Dave Sparks5e271152009-06-23 17:30:11 -0700309
Wu-cheng Libb1e2752011-07-30 05:00:37 +0800310 int32_t dataMsgType = msgType & ~CAMERA_MSG_PREVIEW_METADATA;
311
Dave Sparks5e271152009-06-23 17:30:11 -0700312 // return data based on callback type
Wu-cheng Libb1e2752011-07-30 05:00:37 +0800313 switch (dataMsgType) {
James Donge00cab72011-02-17 16:38:06 -0800314 case CAMERA_MSG_VIDEO_FRAME:
315 // should never happen
316 break;
317
318 // For backward-compatibility purpose, if there is no callback
319 // buffer for raw image, the callback returns null.
320 case CAMERA_MSG_RAW_IMAGE:
Steve Block71f2cf12011-10-20 11:56:00 +0100321 ALOGV("rawCallback");
James Donge00cab72011-02-17 16:38:06 -0800322 if (mRawImageCallbackBuffers.isEmpty()) {
323 env->CallStaticVoidMethod(mCameraJClass, fields.post_event,
Wu-cheng Libb1e2752011-07-30 05:00:37 +0800324 mCameraJObjectWeak, dataMsgType, 0, 0, NULL);
James Donge00cab72011-02-17 16:38:06 -0800325 } else {
Wu-cheng Libb1e2752011-07-30 05:00:37 +0800326 copyAndPost(env, dataPtr, dataMsgType);
James Donge00cab72011-02-17 16:38:06 -0800327 }
328 break;
329
Wu-cheng Libb1e2752011-07-30 05:00:37 +0800330 // There is no data.
331 case 0:
James Donge00cab72011-02-17 16:38:06 -0800332 break;
Wu-cheng Libb1e2752011-07-30 05:00:37 +0800333
334 default:
Steve Block71f2cf12011-10-20 11:56:00 +0100335 ALOGV("dataCallback(%d, %p)", dataMsgType, dataPtr.get());
Wu-cheng Libb1e2752011-07-30 05:00:37 +0800336 copyAndPost(env, dataPtr, dataMsgType);
337 break;
338 }
339
340 // post frame metadata to Java
341 if (metadata && (msgType & CAMERA_MSG_PREVIEW_METADATA)) {
342 postMetadata(env, CAMERA_MSG_PREVIEW_METADATA, metadata);
Dave Sparks5e271152009-06-23 17:30:11 -0700343 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800344}
345
Dave Sparks59c1a932009-07-08 15:56:53 -0700346void JNICameraContext::postDataTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr)
347{
348 // TODO: plumb up to Java. For now, just drop the timestamp
Wu-cheng Libb1e2752011-07-30 05:00:37 +0800349 postData(msgType, dataPtr, NULL);
350}
351
352void JNICameraContext::postMetadata(JNIEnv *env, int32_t msgType, camera_frame_metadata_t *metadata)
353{
354 jobjectArray obj = NULL;
355 obj = (jobjectArray) env->NewObjectArray(metadata->number_of_faces,
356 mFaceClass, NULL);
357 if (obj == NULL) {
Steve Block3762c312012-01-06 19:20:56 +0000358 ALOGE("Couldn't allocate face metadata array");
Wu-cheng Libb1e2752011-07-30 05:00:37 +0800359 return;
360 }
361
362 for (int i = 0; i < metadata->number_of_faces; i++) {
363 jobject face = env->NewObject(mFaceClass, fields.face_constructor);
364 env->SetObjectArrayElement(obj, i, face);
365
366 jobject rect = env->NewObject(mRectClass, fields.rect_constructor);
367 env->SetIntField(rect, fields.rect_left, metadata->faces[i].rect[0]);
368 env->SetIntField(rect, fields.rect_top, metadata->faces[i].rect[1]);
369 env->SetIntField(rect, fields.rect_right, metadata->faces[i].rect[2]);
370 env->SetIntField(rect, fields.rect_bottom, metadata->faces[i].rect[3]);
371
372 env->SetObjectField(face, fields.face_rect, rect);
373 env->SetIntField(face, fields.face_score, metadata->faces[i].score);
374
Igor Murashkin0601ab12014-09-18 15:17:20 -0700375 bool optionalFields = metadata->faces[i].id != 0
376 && metadata->faces[i].left_eye[0] != -2000 && metadata->faces[i].left_eye[1] != -2000
377 && metadata->faces[i].right_eye[0] != -2000 && metadata->faces[i].right_eye[1] != -2000
378 && metadata->faces[i].mouth[0] != -2000 && metadata->faces[i].mouth[1] != -2000;
379 if (optionalFields) {
380 int32_t id = metadata->faces[i].id;
381 env->SetIntField(face, fields.face_id, id);
382
383 jobject leftEye = env->NewObject(mPointClass, fields.point_constructor);
384 env->SetIntField(leftEye, fields.point_x, metadata->faces[i].left_eye[0]);
385 env->SetIntField(leftEye, fields.point_y, metadata->faces[i].left_eye[1]);
386 env->SetObjectField(face, fields.face_left_eye, leftEye);
387 env->DeleteLocalRef(leftEye);
388
389 jobject rightEye = env->NewObject(mPointClass, fields.point_constructor);
390 env->SetIntField(rightEye, fields.point_x, metadata->faces[i].right_eye[0]);
391 env->SetIntField(rightEye, fields.point_y, metadata->faces[i].right_eye[1]);
392 env->SetObjectField(face, fields.face_right_eye, rightEye);
393 env->DeleteLocalRef(rightEye);
394
395 jobject mouth = env->NewObject(mPointClass, fields.point_constructor);
396 env->SetIntField(mouth, fields.point_x, metadata->faces[i].mouth[0]);
397 env->SetIntField(mouth, fields.point_y, metadata->faces[i].mouth[1]);
398 env->SetObjectField(face, fields.face_mouth, mouth);
399 env->DeleteLocalRef(mouth);
400 }
401
Wu-cheng Libb1e2752011-07-30 05:00:37 +0800402 env->DeleteLocalRef(face);
403 env->DeleteLocalRef(rect);
404 }
405 env->CallStaticVoidMethod(mCameraJClass, fields.post_event,
406 mCameraJObjectWeak, msgType, 0, 0, obj);
407 env->DeleteLocalRef(obj);
Dave Sparks59c1a932009-07-08 15:56:53 -0700408}
409
Andrew Harp94927df2009-10-20 01:47:05 -0400410void JNICameraContext::setCallbackMode(JNIEnv *env, bool installed, bool manualMode)
411{
412 Mutex::Autolock _l(mLock);
413 mManualBufferMode = manualMode;
414 mManualCameraCallbackSet = false;
415
416 // In order to limit the over usage of binder threads, all non-manual buffer
Iliyan Malchev9c7ac0d2011-04-14 16:51:21 -0700417 // callbacks use CAMERA_FRAME_CALLBACK_FLAG_BARCODE_SCANNER mode now.
Andrew Harp94927df2009-10-20 01:47:05 -0400418 //
419 // Continuous callbacks will have the callback re-registered from handleMessage.
420 // Manual buffer mode will operate as fast as possible, relying on the finite supply
421 // of buffers for throttling.
422
423 if (!installed) {
Iliyan Malchev9c7ac0d2011-04-14 16:51:21 -0700424 mCamera->setPreviewCallbackFlags(CAMERA_FRAME_CALLBACK_FLAG_NOOP);
James Donge00cab72011-02-17 16:38:06 -0800425 clearCallbackBuffers_l(env, &mCallbackBuffers);
Andrew Harp94927df2009-10-20 01:47:05 -0400426 } else if (mManualBufferMode) {
427 if (!mCallbackBuffers.isEmpty()) {
Iliyan Malchev9c7ac0d2011-04-14 16:51:21 -0700428 mCamera->setPreviewCallbackFlags(CAMERA_FRAME_CALLBACK_FLAG_CAMERA);
Andrew Harp94927df2009-10-20 01:47:05 -0400429 mManualCameraCallbackSet = true;
430 }
431 } else {
Iliyan Malchev9c7ac0d2011-04-14 16:51:21 -0700432 mCamera->setPreviewCallbackFlags(CAMERA_FRAME_CALLBACK_FLAG_BARCODE_SCANNER);
James Donge00cab72011-02-17 16:38:06 -0800433 clearCallbackBuffers_l(env, &mCallbackBuffers);
Andrew Harp94927df2009-10-20 01:47:05 -0400434 }
435}
436
James Donge00cab72011-02-17 16:38:06 -0800437void JNICameraContext::addCallbackBuffer(
438 JNIEnv *env, jbyteArray cbb, int msgType)
Andrew Harp94927df2009-10-20 01:47:05 -0400439{
Steve Block71f2cf12011-10-20 11:56:00 +0100440 ALOGV("addCallbackBuffer: 0x%x", msgType);
Andrew Harp94927df2009-10-20 01:47:05 -0400441 if (cbb != NULL) {
442 Mutex::Autolock _l(mLock);
James Donge00cab72011-02-17 16:38:06 -0800443 switch (msgType) {
444 case CAMERA_MSG_PREVIEW_FRAME: {
445 jbyteArray callbackBuffer = (jbyteArray)env->NewGlobalRef(cbb);
446 mCallbackBuffers.push(callbackBuffer);
Andrew Harp94927df2009-10-20 01:47:05 -0400447
Dan Albert46d84442014-11-18 16:07:51 -0800448 ALOGV("Adding callback buffer to queue, %zu total",
James Donge00cab72011-02-17 16:38:06 -0800449 mCallbackBuffers.size());
Andrew Harp94927df2009-10-20 01:47:05 -0400450
James Donge00cab72011-02-17 16:38:06 -0800451 // We want to make sure the camera knows we're ready for the
452 // next frame. This may have come unset had we not had a
453 // callbackbuffer ready for it last time.
454 if (mManualBufferMode && !mManualCameraCallbackSet) {
Iliyan Malchev9c7ac0d2011-04-14 16:51:21 -0700455 mCamera->setPreviewCallbackFlags(CAMERA_FRAME_CALLBACK_FLAG_CAMERA);
James Donge00cab72011-02-17 16:38:06 -0800456 mManualCameraCallbackSet = true;
457 }
458 break;
459 }
460 case CAMERA_MSG_RAW_IMAGE: {
461 jbyteArray callbackBuffer = (jbyteArray)env->NewGlobalRef(cbb);
462 mRawImageCallbackBuffers.push(callbackBuffer);
463 break;
464 }
465 default: {
466 jniThrowException(env,
467 "java/lang/IllegalArgumentException",
468 "Unsupported message type");
469 return;
470 }
Andrew Harp94927df2009-10-20 01:47:05 -0400471 }
472 } else {
Steve Block3762c312012-01-06 19:20:56 +0000473 ALOGE("Null byte array!");
Andrew Harp94927df2009-10-20 01:47:05 -0400474 }
475}
476
477void JNICameraContext::clearCallbackBuffers_l(JNIEnv *env)
478{
James Donge00cab72011-02-17 16:38:06 -0800479 clearCallbackBuffers_l(env, &mCallbackBuffers);
480 clearCallbackBuffers_l(env, &mRawImageCallbackBuffers);
481}
482
483void JNICameraContext::clearCallbackBuffers_l(JNIEnv *env, Vector<jbyteArray> *buffers) {
Dan Albert46d84442014-11-18 16:07:51 -0800484 ALOGV("Clearing callback buffers, %zu remained", buffers->size());
James Donge00cab72011-02-17 16:38:06 -0800485 while (!buffers->isEmpty()) {
486 env->DeleteGlobalRef(buffers->top());
487 buffers->pop();
Andrew Harp94927df2009-10-20 01:47:05 -0400488 }
489}
490
Chih-Chung Change25cc652010-05-06 16:36:58 +0800491static jint android_hardware_Camera_getNumberOfCameras(JNIEnv *env, jobject thiz)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800492{
Chih-Chung Change25cc652010-05-06 16:36:58 +0800493 return Camera::getNumberOfCameras();
494}
495
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800496static void android_hardware_Camera_getCameraInfo(JNIEnv *env, jobject thiz,
497 jint cameraId, jobject info_obj)
498{
499 CameraInfo cameraInfo;
Eino-Ville Talvala57176122015-08-14 13:11:16 -0700500 if (cameraId >= Camera::getNumberOfCameras() || cameraId < 0) {
501 ALOGE("%s: Unknown camera ID %d", __FUNCTION__, cameraId);
502 jniThrowRuntimeException(env, "Unknown camera ID");
503 return;
504 }
505
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800506 status_t rc = Camera::getCameraInfo(cameraId, &cameraInfo);
507 if (rc != NO_ERROR) {
Elliott Hughes69a017b2011-04-08 14:10:28 -0700508 jniThrowRuntimeException(env, "Fail to get camera info");
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800509 return;
510 }
511 env->SetIntField(info_obj, fields.facing, cameraInfo.facing);
512 env->SetIntField(info_obj, fields.orientation, cameraInfo.orientation);
Eino-Ville Talvalaf7c6c5a2012-09-19 11:46:11 -0700513
514 char value[PROPERTY_VALUE_MAX];
515 property_get("ro.camera.sound.forced", value, "0");
516 jboolean canDisableShutterSound = (strncmp(value, "0", 2) == 0);
517 env->SetBooleanField(info_obj, fields.canDisableShutterSound,
518 canDisableShutterSound);
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800519}
520
Chih-Chung Change25cc652010-05-06 16:36:58 +0800521// connect to camera service
Ruben Brunkfeb50af2014-05-09 19:58:49 -0700522static jint android_hardware_Camera_native_setup(JNIEnv *env, jobject thiz,
Zhijun He4c913802014-06-16 16:42:35 -0700523 jobject weak_this, jint cameraId, jint halVersion, jstring clientPackageName)
Chih-Chung Change25cc652010-05-06 16:36:58 +0800524{
Eino-Ville Talvala788717c2013-02-15 18:30:15 -0800525 // Convert jstring to String16
Dan Albert66987492014-11-20 11:41:21 -0800526 const char16_t *rawClientName = reinterpret_cast<const char16_t*>(
527 env->GetStringChars(clientPackageName, NULL));
Eino-Ville Talvala788717c2013-02-15 18:30:15 -0800528 jsize rawClientNameLen = env->GetStringLength(clientPackageName);
529 String16 clientName(rawClientName, rawClientNameLen);
Dan Albert66987492014-11-20 11:41:21 -0800530 env->ReleaseStringChars(clientPackageName,
531 reinterpret_cast<const jchar*>(rawClientName));
Eino-Ville Talvala788717c2013-02-15 18:30:15 -0800532
Zhijun He4c913802014-06-16 16:42:35 -0700533 sp<Camera> camera;
Igor Murashkina1d66272014-06-20 11:22:11 -0700534 if (halVersion == CAMERA_HAL_API_VERSION_NORMAL_CONNECT) {
535 // Default path: hal version is don't care, do normal camera connect.
Zhijun He4c913802014-06-16 16:42:35 -0700536 camera = Camera::connect(cameraId, clientName,
Chien-Yu Chen225257a2015-12-18 14:20:46 -0800537 Camera::USE_CALLING_UID, Camera::USE_CALLING_PID);
Zhijun He4c913802014-06-16 16:42:35 -0700538 } else {
539 jint status = Camera::connectLegacy(cameraId, halVersion, clientName,
540 Camera::USE_CALLING_UID, camera);
541 if (status != NO_ERROR) {
542 return status;
543 }
544 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800545
546 if (camera == NULL) {
Ruben Brunkfeb50af2014-05-09 19:58:49 -0700547 return -EACCES;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800548 }
549
550 // make sure camera hardware is alive
551 if (camera->getStatus() != NO_ERROR) {
Ruben Brunkfeb50af2014-05-09 19:58:49 -0700552 return NO_INIT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800553 }
554
555 jclass clazz = env->GetObjectClass(thiz);
556 if (clazz == NULL) {
Ruben Brunkfeb50af2014-05-09 19:58:49 -0700557 // This should never happen
Elliott Hughes69a017b2011-04-08 14:10:28 -0700558 jniThrowRuntimeException(env, "Can't find android/hardware/Camera");
Ruben Brunkfeb50af2014-05-09 19:58:49 -0700559 return INVALID_OPERATION;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800560 }
561
562 // We use a weak reference so the Camera object can be garbage collected.
563 // The reference is only used as a proxy for callbacks.
Dave Sparks5e271152009-06-23 17:30:11 -0700564 sp<JNICameraContext> context = new JNICameraContext(env, weak_this, clazz, camera);
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800565 context->incStrong((void*)android_hardware_Camera_native_setup);
Dave Sparks5e271152009-06-23 17:30:11 -0700566 camera->setListener(context);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800567
568 // save context in opaque field
Ashok Bhat4838e332014-01-03 14:37:19 +0000569 env->SetLongField(thiz, fields.context, (jlong)context.get());
Eino-Ville Talvala6c91e2c2016-03-25 11:54:39 -0700570
571 // Update default display orientation in case the sensor is reverse-landscape
572 CameraInfo cameraInfo;
573 status_t rc = Camera::getCameraInfo(cameraId, &cameraInfo);
574 if (rc != NO_ERROR) {
575 return rc;
576 }
577 int defaultOrientation = 0;
578 switch (cameraInfo.orientation) {
579 case 0:
580 break;
581 case 90:
582 if (cameraInfo.facing == CAMERA_FACING_FRONT) {
583 defaultOrientation = 180;
584 }
585 break;
586 case 180:
587 defaultOrientation = 180;
588 break;
589 case 270:
590 if (cameraInfo.facing != CAMERA_FACING_FRONT) {
591 defaultOrientation = 180;
592 }
593 break;
594 default:
595 ALOGE("Unexpected camera orientation %d!", cameraInfo.orientation);
596 break;
597 }
598 if (defaultOrientation != 0) {
599 ALOGV("Setting default display orientation to %d", defaultOrientation);
600 rc = camera->sendCommand(CAMERA_CMD_SET_DISPLAY_ORIENTATION,
601 defaultOrientation, 0);
602 if (rc != NO_ERROR) {
603 ALOGE("Unable to update default orientation: %s (%d)",
604 strerror(-rc), rc);
605 return rc;
606 }
607 }
608
Ruben Brunkfeb50af2014-05-09 19:58:49 -0700609 return NO_ERROR;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800610}
611
612// disconnect from camera service
613// It's okay to call this when the native camera context is already null.
614// This handles the case where the user has called release() and the
615// finalizer is invoked later.
616static void android_hardware_Camera_release(JNIEnv *env, jobject thiz)
617{
Steve Block71f2cf12011-10-20 11:56:00 +0100618 ALOGV("release camera");
Dave Sparks5e271152009-06-23 17:30:11 -0700619 JNICameraContext* context = NULL;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800620 sp<Camera> camera;
621 {
622 Mutex::Autolock _l(sLock);
Ashok Bhat4838e332014-01-03 14:37:19 +0000623 context = reinterpret_cast<JNICameraContext*>(env->GetLongField(thiz, fields.context));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800624
625 // Make sure we do not attempt to callback on a deleted Java object.
Ashok Bhat4838e332014-01-03 14:37:19 +0000626 env->SetLongField(thiz, fields.context, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800627 }
628
629 // clean up if release has not been called before
630 if (context != NULL) {
Dave Sparks5e271152009-06-23 17:30:11 -0700631 camera = context->getCamera();
632 context->release();
Steve Block71f2cf12011-10-20 11:56:00 +0100633 ALOGV("native_release: context=%p camera=%p", context, camera.get());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800634
635 // clear callbacks
636 if (camera != NULL) {
Iliyan Malchev9c7ac0d2011-04-14 16:51:21 -0700637 camera->setPreviewCallbackFlags(CAMERA_FRAME_CALLBACK_FLAG_NOOP);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800638 camera->disconnect();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800639 }
640
641 // remove context to prevent further Java access
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800642 context->decStrong((void*)android_hardware_Camera_native_setup);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800643 }
644}
645
Ruben Brunkfeb50af2014-05-09 19:58:49 -0700646static void android_hardware_Camera_setPreviewSurface(JNIEnv *env, jobject thiz, jobject jSurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800647{
Ruben Brunkfeb50af2014-05-09 19:58:49 -0700648 ALOGV("setPreviewSurface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800649 sp<Camera> camera = get_native_camera(env, thiz, NULL);
650 if (camera == 0) return;
651
Mathias Agopian4a05f432013-03-12 18:43:34 -0700652 sp<IGraphicBufferProducer> gbp;
Jesse Hallaa70f222013-02-21 15:06:27 -0800653 sp<Surface> surface;
654 if (jSurface) {
655 surface = android_view_Surface_getSurface(env, jSurface);
Mathias Agopian4a05f432013-03-12 18:43:34 -0700656 if (surface != NULL) {
657 gbp = surface->getIGraphicBufferProducer();
658 }
Jesse Hallaa70f222013-02-21 15:06:27 -0800659 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800660
Eino-Ville Talvala7b297792013-08-21 14:39:22 -0700661 if (camera->setPreviewTarget(gbp) != NO_ERROR) {
Mathias Agopian4a05f432013-03-12 18:43:34 -0700662 jniThrowException(env, "java/io/IOException", "setPreviewTexture failed");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800663 }
664}
665
Jamie Gennisfd6f39e2010-12-20 12:15:00 -0800666static void android_hardware_Camera_setPreviewTexture(JNIEnv *env,
667 jobject thiz, jobject jSurfaceTexture)
668{
Steve Block71f2cf12011-10-20 11:56:00 +0100669 ALOGV("setPreviewTexture");
Jamie Gennisfd6f39e2010-12-20 12:15:00 -0800670 sp<Camera> camera = get_native_camera(env, thiz, NULL);
671 if (camera == 0) return;
672
Mathias Agopian52a9a102013-08-02 01:38:38 -0700673 sp<IGraphicBufferProducer> producer = NULL;
Jamie Gennisfd6f39e2010-12-20 12:15:00 -0800674 if (jSurfaceTexture != NULL) {
Mathias Agopian52a9a102013-08-02 01:38:38 -0700675 producer = SurfaceTexture_getProducer(env, jSurfaceTexture);
676 if (producer == NULL) {
Daniel Lam2e76c992012-02-23 14:35:13 -0800677 jniThrowException(env, "java/lang/IllegalArgumentException",
678 "SurfaceTexture already released in setPreviewTexture");
679 return;
680 }
681
Jamie Gennisfd6f39e2010-12-20 12:15:00 -0800682 }
Daniel Lam2e76c992012-02-23 14:35:13 -0800683
Eino-Ville Talvala7b297792013-08-21 14:39:22 -0700684 if (camera->setPreviewTarget(producer) != NO_ERROR) {
Jamie Gennisfd6f39e2010-12-20 12:15:00 -0800685 jniThrowException(env, "java/io/IOException",
686 "setPreviewTexture failed");
687 }
688}
689
Eino-Ville Talvala7005b672013-04-02 15:46:38 -0700690static void android_hardware_Camera_setPreviewCallbackSurface(JNIEnv *env,
691 jobject thiz, jobject jSurface)
692{
693 ALOGV("setPreviewCallbackSurface");
694 JNICameraContext* context;
695 sp<Camera> camera = get_native_camera(env, thiz, &context);
696 if (camera == 0) return;
697
698 sp<IGraphicBufferProducer> gbp;
699 sp<Surface> surface;
700 if (jSurface) {
701 surface = android_view_Surface_getSurface(env, jSurface);
702 if (surface != NULL) {
703 gbp = surface->getIGraphicBufferProducer();
704 }
705 }
706 // Clear out normal preview callbacks
707 context->setCallbackMode(env, false, false);
708 // Then set up callback surface
709 if (camera->setPreviewCallbackTarget(gbp) != NO_ERROR) {
710 jniThrowException(env, "java/io/IOException", "setPreviewCallbackTarget failed");
711 }
712}
713
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800714static void android_hardware_Camera_startPreview(JNIEnv *env, jobject thiz)
715{
Steve Block71f2cf12011-10-20 11:56:00 +0100716 ALOGV("startPreview");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800717 sp<Camera> camera = get_native_camera(env, thiz, NULL);
718 if (camera == 0) return;
719
720 if (camera->startPreview() != NO_ERROR) {
Elliott Hughes69a017b2011-04-08 14:10:28 -0700721 jniThrowRuntimeException(env, "startPreview failed");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800722 return;
723 }
724}
725
726static void android_hardware_Camera_stopPreview(JNIEnv *env, jobject thiz)
727{
Steve Block71f2cf12011-10-20 11:56:00 +0100728 ALOGV("stopPreview");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800729 sp<Camera> c = get_native_camera(env, thiz, NULL);
730 if (c == 0) return;
731
732 c->stopPreview();
733}
734
Ashok Bhat4838e332014-01-03 14:37:19 +0000735static jboolean android_hardware_Camera_previewEnabled(JNIEnv *env, jobject thiz)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800736{
Steve Block71f2cf12011-10-20 11:56:00 +0100737 ALOGV("previewEnabled");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800738 sp<Camera> c = get_native_camera(env, thiz, NULL);
Ashok Bhat4838e332014-01-03 14:37:19 +0000739 if (c == 0) return JNI_FALSE;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800740
Ashok Bhat4838e332014-01-03 14:37:19 +0000741 return c->previewEnabled() ? JNI_TRUE : JNI_FALSE;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800742}
743
Andrew Harp94927df2009-10-20 01:47:05 -0400744static void android_hardware_Camera_setHasPreviewCallback(JNIEnv *env, jobject thiz, jboolean installed, jboolean manualBuffer)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800745{
Steve Block71f2cf12011-10-20 11:56:00 +0100746 ALOGV("setHasPreviewCallback: installed:%d, manualBuffer:%d", (int)installed, (int)manualBuffer);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800747 // Important: Only install preview_callback if the Java code has called
748 // setPreviewCallback() with a non-null value, otherwise we'd pay to memcpy
749 // each preview frame for nothing.
Dave Sparks5e271152009-06-23 17:30:11 -0700750 JNICameraContext* context;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800751 sp<Camera> camera = get_native_camera(env, thiz, &context);
752 if (camera == 0) return;
753
Andrew Harp94927df2009-10-20 01:47:05 -0400754 // setCallbackMode will take care of setting the context flags and calling
755 // camera->setPreviewCallbackFlags within a mutex for us.
756 context->setCallbackMode(env, installed, manualBuffer);
757}
758
Ashok Bhat4838e332014-01-03 14:37:19 +0000759static void android_hardware_Camera_addCallbackBuffer(JNIEnv *env, jobject thiz, jbyteArray bytes, jint msgType) {
Steve Block71f2cf12011-10-20 11:56:00 +0100760 ALOGV("addCallbackBuffer: 0x%x", msgType);
Andrew Harp94927df2009-10-20 01:47:05 -0400761
Ashok Bhat4838e332014-01-03 14:37:19 +0000762 JNICameraContext* context = reinterpret_cast<JNICameraContext*>(env->GetLongField(thiz, fields.context));
Andrew Harp94927df2009-10-20 01:47:05 -0400763
764 if (context != NULL) {
James Donge00cab72011-02-17 16:38:06 -0800765 context->addCallbackBuffer(env, bytes, msgType);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800766 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800767}
768
769static void android_hardware_Camera_autoFocus(JNIEnv *env, jobject thiz)
770{
Steve Block71f2cf12011-10-20 11:56:00 +0100771 ALOGV("autoFocus");
Dave Sparks5e271152009-06-23 17:30:11 -0700772 JNICameraContext* context;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800773 sp<Camera> c = get_native_camera(env, thiz, &context);
774 if (c == 0) return;
775
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800776 if (c->autoFocus() != NO_ERROR) {
Elliott Hughes69a017b2011-04-08 14:10:28 -0700777 jniThrowRuntimeException(env, "autoFocus failed");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800778 }
779}
780
Chih-Chung Chang244f8c22009-09-15 14:51:56 +0800781static void android_hardware_Camera_cancelAutoFocus(JNIEnv *env, jobject thiz)
782{
Steve Block71f2cf12011-10-20 11:56:00 +0100783 ALOGV("cancelAutoFocus");
Chih-Chung Chang244f8c22009-09-15 14:51:56 +0800784 JNICameraContext* context;
785 sp<Camera> c = get_native_camera(env, thiz, &context);
786 if (c == 0) return;
787
788 if (c->cancelAutoFocus() != NO_ERROR) {
Elliott Hughes69a017b2011-04-08 14:10:28 -0700789 jniThrowRuntimeException(env, "cancelAutoFocus failed");
Chih-Chung Chang244f8c22009-09-15 14:51:56 +0800790 }
791}
792
Ashok Bhat4838e332014-01-03 14:37:19 +0000793static void android_hardware_Camera_takePicture(JNIEnv *env, jobject thiz, jint msgType)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800794{
Steve Block71f2cf12011-10-20 11:56:00 +0100795 ALOGV("takePicture");
Dave Sparks5e271152009-06-23 17:30:11 -0700796 JNICameraContext* context;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800797 sp<Camera> camera = get_native_camera(env, thiz, &context);
798 if (camera == 0) return;
799
James Donge00cab72011-02-17 16:38:06 -0800800 /*
801 * When CAMERA_MSG_RAW_IMAGE is requested, if the raw image callback
802 * buffer is available, CAMERA_MSG_RAW_IMAGE is enabled to get the
803 * notification _and_ the data; otherwise, CAMERA_MSG_RAW_IMAGE_NOTIFY
804 * is enabled to receive the callback notification but no data.
805 *
806 * Note that CAMERA_MSG_RAW_IMAGE_NOTIFY is not exposed to the
807 * Java application.
808 */
809 if (msgType & CAMERA_MSG_RAW_IMAGE) {
Steve Block71f2cf12011-10-20 11:56:00 +0100810 ALOGV("Enable raw image callback buffer");
James Donge00cab72011-02-17 16:38:06 -0800811 if (!context->isRawImageCallbackBufferAvailable()) {
Steve Block71f2cf12011-10-20 11:56:00 +0100812 ALOGV("Enable raw image notification, since no callback buffer exists");
James Donge00cab72011-02-17 16:38:06 -0800813 msgType &= ~CAMERA_MSG_RAW_IMAGE;
814 msgType |= CAMERA_MSG_RAW_IMAGE_NOTIFY;
815 }
816 }
817
818 if (camera->takePicture(msgType) != NO_ERROR) {
Elliott Hughes69a017b2011-04-08 14:10:28 -0700819 jniThrowRuntimeException(env, "takePicture failed");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800820 return;
821 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800822}
823
824static void android_hardware_Camera_setParameters(JNIEnv *env, jobject thiz, jstring params)
825{
Steve Block71f2cf12011-10-20 11:56:00 +0100826 ALOGV("setParameters");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800827 sp<Camera> camera = get_native_camera(env, thiz, NULL);
828 if (camera == 0) return;
829
830 const jchar* str = env->GetStringCritical(params, 0);
831 String8 params8;
832 if (params) {
Dan Albert66987492014-11-20 11:41:21 -0800833 params8 = String8(reinterpret_cast<const char16_t*>(str),
834 env->GetStringLength(params));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800835 env->ReleaseStringCritical(params, str);
836 }
837 if (camera->setParameters(params8) != NO_ERROR) {
Elliott Hughes69a017b2011-04-08 14:10:28 -0700838 jniThrowRuntimeException(env, "setParameters failed");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800839 return;
840 }
841}
842
843static jstring android_hardware_Camera_getParameters(JNIEnv *env, jobject thiz)
844{
Steve Block71f2cf12011-10-20 11:56:00 +0100845 ALOGV("getParameters");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800846 sp<Camera> camera = get_native_camera(env, thiz, NULL);
847 if (camera == 0) return 0;
848
Wu-cheng Lia1c41e12012-02-23 19:01:00 -0800849 String8 params8 = camera->getParameters();
850 if (params8.isEmpty()) {
851 jniThrowRuntimeException(env, "getParameters failed (empty parameters)");
852 return 0;
853 }
854 return env->NewStringUTF(params8.string());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800855}
856
857static void android_hardware_Camera_reconnect(JNIEnv *env, jobject thiz)
858{
Steve Block71f2cf12011-10-20 11:56:00 +0100859 ALOGV("reconnect");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800860 sp<Camera> camera = get_native_camera(env, thiz, NULL);
861 if (camera == 0) return;
862
863 if (camera->reconnect() != NO_ERROR) {
864 jniThrowException(env, "java/io/IOException", "reconnect failed");
865 return;
866 }
867}
868
Wu-cheng Liffe1cf22009-09-10 16:49:17 +0800869static void android_hardware_Camera_lock(JNIEnv *env, jobject thiz)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800870{
Steve Block71f2cf12011-10-20 11:56:00 +0100871 ALOGV("lock");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800872 sp<Camera> camera = get_native_camera(env, thiz, NULL);
Wu-cheng Liffe1cf22009-09-10 16:49:17 +0800873 if (camera == 0) return;
874
875 if (camera->lock() != NO_ERROR) {
Elliott Hughes69a017b2011-04-08 14:10:28 -0700876 jniThrowRuntimeException(env, "lock failed");
Wu-cheng Liffe1cf22009-09-10 16:49:17 +0800877 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800878}
879
Wu-cheng Liffe1cf22009-09-10 16:49:17 +0800880static void android_hardware_Camera_unlock(JNIEnv *env, jobject thiz)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800881{
Steve Block71f2cf12011-10-20 11:56:00 +0100882 ALOGV("unlock");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800883 sp<Camera> camera = get_native_camera(env, thiz, NULL);
Wu-cheng Liffe1cf22009-09-10 16:49:17 +0800884 if (camera == 0) return;
885
886 if (camera->unlock() != NO_ERROR) {
Elliott Hughes69a017b2011-04-08 14:10:28 -0700887 jniThrowRuntimeException(env, "unlock failed");
Wu-cheng Liffe1cf22009-09-10 16:49:17 +0800888 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800889}
890
Wu-cheng Li36f68b82009-09-28 16:14:58 -0700891static void android_hardware_Camera_startSmoothZoom(JNIEnv *env, jobject thiz, jint value)
892{
Steve Block71f2cf12011-10-20 11:56:00 +0100893 ALOGV("startSmoothZoom");
Wu-cheng Li36f68b82009-09-28 16:14:58 -0700894 sp<Camera> camera = get_native_camera(env, thiz, NULL);
895 if (camera == 0) return;
896
Wu-cheng Li0ca25192010-03-29 16:21:12 +0800897 status_t rc = camera->sendCommand(CAMERA_CMD_START_SMOOTH_ZOOM, value, 0);
898 if (rc == BAD_VALUE) {
899 char msg[64];
900 sprintf(msg, "invalid zoom value=%d", value);
901 jniThrowException(env, "java/lang/IllegalArgumentException", msg);
902 } else if (rc != NO_ERROR) {
Elliott Hughes69a017b2011-04-08 14:10:28 -0700903 jniThrowRuntimeException(env, "start smooth zoom failed");
Wu-cheng Li36f68b82009-09-28 16:14:58 -0700904 }
905}
906
907static void android_hardware_Camera_stopSmoothZoom(JNIEnv *env, jobject thiz)
908{
Steve Block71f2cf12011-10-20 11:56:00 +0100909 ALOGV("stopSmoothZoom");
Wu-cheng Li36f68b82009-09-28 16:14:58 -0700910 sp<Camera> camera = get_native_camera(env, thiz, NULL);
911 if (camera == 0) return;
912
913 if (camera->sendCommand(CAMERA_CMD_STOP_SMOOTH_ZOOM, 0, 0) != NO_ERROR) {
Elliott Hughes69a017b2011-04-08 14:10:28 -0700914 jniThrowRuntimeException(env, "stop smooth zoom failed");
Wu-cheng Li36f68b82009-09-28 16:14:58 -0700915 }
916}
917
Chih-Chung Changd1d77062010-01-22 17:49:48 -0800918static void android_hardware_Camera_setDisplayOrientation(JNIEnv *env, jobject thiz,
919 jint value)
920{
Steve Block71f2cf12011-10-20 11:56:00 +0100921 ALOGV("setDisplayOrientation");
Chih-Chung Changd1d77062010-01-22 17:49:48 -0800922 sp<Camera> camera = get_native_camera(env, thiz, NULL);
923 if (camera == 0) return;
924
925 if (camera->sendCommand(CAMERA_CMD_SET_DISPLAY_ORIENTATION, value, 0) != NO_ERROR) {
Elliott Hughes69a017b2011-04-08 14:10:28 -0700926 jniThrowRuntimeException(env, "set display orientation failed");
Chih-Chung Changd1d77062010-01-22 17:49:48 -0800927 }
928}
929
Eino-Ville Talvala69fe5272012-09-07 12:26:40 -0700930static jboolean android_hardware_Camera_enableShutterSound(JNIEnv *env, jobject thiz,
931 jboolean enabled)
932{
933 ALOGV("enableShutterSound");
934 sp<Camera> camera = get_native_camera(env, thiz, NULL);
935 if (camera == 0) return JNI_FALSE;
936
937 int32_t value = (enabled == JNI_TRUE) ? 1 : 0;
938 status_t rc = camera->sendCommand(CAMERA_CMD_ENABLE_SHUTTER_SOUND, value, 0);
939 if (rc == NO_ERROR) {
940 return JNI_TRUE;
941 } else if (rc == PERMISSION_DENIED) {
942 return JNI_FALSE;
943 } else {
944 jniThrowRuntimeException(env, "enable shutter sound failed");
945 return JNI_FALSE;
946 }
947}
948
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800949static void android_hardware_Camera_startFaceDetection(JNIEnv *env, jobject thiz,
Wu-cheng Libb1e2752011-07-30 05:00:37 +0800950 jint type)
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800951{
Steve Block71f2cf12011-10-20 11:56:00 +0100952 ALOGV("startFaceDetection");
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800953 JNICameraContext* context;
954 sp<Camera> camera = get_native_camera(env, thiz, &context);
955 if (camera == 0) return;
956
957 status_t rc = camera->sendCommand(CAMERA_CMD_START_FACE_DETECTION, type, 0);
958 if (rc == BAD_VALUE) {
959 char msg[64];
960 snprintf(msg, sizeof(msg), "invalid face detection type=%d", type);
961 jniThrowException(env, "java/lang/IllegalArgumentException", msg);
962 } else if (rc != NO_ERROR) {
963 jniThrowRuntimeException(env, "start face detection failed");
964 }
965}
966
967static void android_hardware_Camera_stopFaceDetection(JNIEnv *env, jobject thiz)
968{
Steve Block71f2cf12011-10-20 11:56:00 +0100969 ALOGV("stopFaceDetection");
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800970 sp<Camera> camera = get_native_camera(env, thiz, NULL);
971 if (camera == 0) return;
972
973 if (camera->sendCommand(CAMERA_CMD_STOP_FACE_DETECTION, 0, 0) != NO_ERROR) {
974 jniThrowRuntimeException(env, "stop face detection failed");
975 }
976}
977
Wu-cheng Li9d062cf2011-11-14 20:30:14 +0800978static void android_hardware_Camera_enableFocusMoveCallback(JNIEnv *env, jobject thiz, jint enable)
979{
Wu-cheng Li02097522011-11-30 11:06:04 +0800980 ALOGV("enableFocusMoveCallback");
Wu-cheng Li9d062cf2011-11-14 20:30:14 +0800981 sp<Camera> camera = get_native_camera(env, thiz, NULL);
982 if (camera == 0) return;
983
984 if (camera->sendCommand(CAMERA_CMD_ENABLE_FOCUS_MOVE_MSG, enable, 0) != NO_ERROR) {
985 jniThrowRuntimeException(env, "enable focus move callback failed");
986 }
987}
988
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800989//-------------------------------------------------
990
Daniel Micay76f6a862015-09-19 17:31:01 -0400991static const JNINativeMethod camMethods[] = {
Chih-Chung Change25cc652010-05-06 16:36:58 +0800992 { "getNumberOfCameras",
993 "()I",
994 (void *)android_hardware_Camera_getNumberOfCameras },
Eino-Ville Talvala4f8e5ce2012-10-08 18:16:35 -0700995 { "_getCameraInfo",
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800996 "(ILandroid/hardware/Camera$CameraInfo;)V",
997 (void*)android_hardware_Camera_getCameraInfo },
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800998 { "native_setup",
Zhijun He4c913802014-06-16 16:42:35 -0700999 "(Ljava/lang/Object;IILjava/lang/String;)I",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001000 (void*)android_hardware_Camera_native_setup },
1001 { "native_release",
1002 "()V",
1003 (void*)android_hardware_Camera_release },
Ruben Brunkfeb50af2014-05-09 19:58:49 -07001004 { "setPreviewSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001005 "(Landroid/view/Surface;)V",
Ruben Brunkfeb50af2014-05-09 19:58:49 -07001006 (void *)android_hardware_Camera_setPreviewSurface },
Jamie Gennisfd6f39e2010-12-20 12:15:00 -08001007 { "setPreviewTexture",
1008 "(Landroid/graphics/SurfaceTexture;)V",
1009 (void *)android_hardware_Camera_setPreviewTexture },
Eino-Ville Talvala7005b672013-04-02 15:46:38 -07001010 { "setPreviewCallbackSurface",
1011 "(Landroid/view/Surface;)V",
1012 (void *)android_hardware_Camera_setPreviewCallbackSurface },
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001013 { "startPreview",
1014 "()V",
1015 (void *)android_hardware_Camera_startPreview },
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001016 { "_stopPreview",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001017 "()V",
1018 (void *)android_hardware_Camera_stopPreview },
1019 { "previewEnabled",
1020 "()Z",
1021 (void *)android_hardware_Camera_previewEnabled },
1022 { "setHasPreviewCallback",
1023 "(ZZ)V",
1024 (void *)android_hardware_Camera_setHasPreviewCallback },
James Donge00cab72011-02-17 16:38:06 -08001025 { "_addCallbackBuffer",
1026 "([BI)V",
Andrew Harp94927df2009-10-20 01:47:05 -04001027 (void *)android_hardware_Camera_addCallbackBuffer },
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001028 { "native_autoFocus",
1029 "()V",
1030 (void *)android_hardware_Camera_autoFocus },
Chih-Chung Chang244f8c22009-09-15 14:51:56 +08001031 { "native_cancelAutoFocus",
1032 "()V",
1033 (void *)android_hardware_Camera_cancelAutoFocus },
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001034 { "native_takePicture",
James Donge00cab72011-02-17 16:38:06 -08001035 "(I)V",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001036 (void *)android_hardware_Camera_takePicture },
1037 { "native_setParameters",
1038 "(Ljava/lang/String;)V",
1039 (void *)android_hardware_Camera_setParameters },
1040 { "native_getParameters",
1041 "()Ljava/lang/String;",
1042 (void *)android_hardware_Camera_getParameters },
1043 { "reconnect",
1044 "()V",
1045 (void*)android_hardware_Camera_reconnect },
1046 { "lock",
Wu-cheng Liffe1cf22009-09-10 16:49:17 +08001047 "()V",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001048 (void*)android_hardware_Camera_lock },
1049 { "unlock",
Wu-cheng Liffe1cf22009-09-10 16:49:17 +08001050 "()V",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001051 (void*)android_hardware_Camera_unlock },
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001052 { "startSmoothZoom",
1053 "(I)V",
1054 (void *)android_hardware_Camera_startSmoothZoom },
1055 { "stopSmoothZoom",
1056 "()V",
1057 (void *)android_hardware_Camera_stopSmoothZoom },
Chih-Chung Changd1d77062010-01-22 17:49:48 -08001058 { "setDisplayOrientation",
1059 "(I)V",
1060 (void *)android_hardware_Camera_setDisplayOrientation },
Eino-Ville Talvala4f8e5ce2012-10-08 18:16:35 -07001061 { "_enableShutterSound",
Eino-Ville Talvala69fe5272012-09-07 12:26:40 -07001062 "(Z)Z",
1063 (void *)android_hardware_Camera_enableShutterSound },
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001064 { "_startFaceDetection",
1065 "(I)V",
1066 (void *)android_hardware_Camera_startFaceDetection },
1067 { "_stopFaceDetection",
1068 "()V",
1069 (void *)android_hardware_Camera_stopFaceDetection},
Wu-cheng Li9d062cf2011-11-14 20:30:14 +08001070 { "enableFocusMoveCallback",
1071 "(I)V",
1072 (void *)android_hardware_Camera_enableFocusMoveCallback},
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001073};
1074
1075struct field {
1076 const char *class_name;
1077 const char *field_name;
1078 const char *field_type;
1079 jfieldID *jfield;
1080};
1081
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001082static void find_fields(JNIEnv *env, field *fields, int count)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001083{
1084 for (int i = 0; i < count; i++) {
1085 field *f = &fields[i];
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001086 jclass clazz = FindClassOrDie(env, f->class_name);
1087 jfieldID field = GetFieldIDOrDie(env, clazz, f->field_name, f->field_type);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001088 *(f->jfield) = field;
1089 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001090}
1091
1092// Get all the required offsets in java class and register native functions
1093int register_android_hardware_Camera(JNIEnv *env)
1094{
1095 field fields_to_find[] = {
Ashok Bhat4838e332014-01-03 14:37:19 +00001096 { "android/hardware/Camera", "mNativeContext", "J", &fields.context },
Wu-cheng Li3fd5fa42010-09-15 16:06:20 -07001097 { "android/hardware/Camera$CameraInfo", "facing", "I", &fields.facing },
1098 { "android/hardware/Camera$CameraInfo", "orientation", "I", &fields.orientation },
Eino-Ville Talvalaf7c6c5a2012-09-19 11:46:11 -07001099 { "android/hardware/Camera$CameraInfo", "canDisableShutterSound", "Z",
1100 &fields.canDisableShutterSound },
Wu-cheng Lif0d6a482011-07-28 05:30:59 +08001101 { "android/hardware/Camera$Face", "rect", "Landroid/graphics/Rect;", &fields.face_rect },
Igor Murashkin0601ab12014-09-18 15:17:20 -07001102 { "android/hardware/Camera$Face", "leftEye", "Landroid/graphics/Point;", &fields.face_left_eye},
1103 { "android/hardware/Camera$Face", "rightEye", "Landroid/graphics/Point;", &fields.face_right_eye},
1104 { "android/hardware/Camera$Face", "mouth", "Landroid/graphics/Point;", &fields.face_mouth},
Wu-cheng Lif0d6a482011-07-28 05:30:59 +08001105 { "android/hardware/Camera$Face", "score", "I", &fields.face_score },
Igor Murashkin0601ab12014-09-18 15:17:20 -07001106 { "android/hardware/Camera$Face", "id", "I", &fields.face_id},
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001107 { "android/graphics/Rect", "left", "I", &fields.rect_left },
1108 { "android/graphics/Rect", "top", "I", &fields.rect_top },
1109 { "android/graphics/Rect", "right", "I", &fields.rect_right },
1110 { "android/graphics/Rect", "bottom", "I", &fields.rect_bottom },
Igor Murashkin0601ab12014-09-18 15:17:20 -07001111 { "android/graphics/Point", "x", "I", &fields.point_x},
1112 { "android/graphics/Point", "y", "I", &fields.point_y},
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001113 };
1114
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001115 find_fields(env, fields_to_find, NELEM(fields_to_find));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001116
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001117 jclass clazz = FindClassOrDie(env, "android/hardware/Camera");
1118 fields.post_event = GetStaticMethodIDOrDie(env, clazz, "postEventFromNative",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001119 "(Ljava/lang/Object;IIILjava/lang/Object;)V");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001120
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001121 clazz = FindClassOrDie(env, "android/graphics/Rect");
1122 fields.rect_constructor = GetMethodIDOrDie(env, clazz, "<init>", "()V");
Wu-cheng Libb1e2752011-07-30 05:00:37 +08001123
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001124 clazz = FindClassOrDie(env, "android/hardware/Camera$Face");
1125 fields.face_constructor = GetMethodIDOrDie(env, clazz, "<init>", "()V");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001126
Igor Murashkin0601ab12014-09-18 15:17:20 -07001127 clazz = env->FindClass("android/graphics/Point");
1128 fields.point_constructor = env->GetMethodID(clazz, "<init>", "()V");
1129 if (fields.point_constructor == NULL) {
1130 ALOGE("Can't find android/graphics/Point()");
1131 return -1;
1132 }
1133
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001134 // Register native functions
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001135 return RegisterMethodsOrDie(env, "android/hardware/Camera", camMethods, NELEM(camMethods));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001136}