blob: b9262701005986101c3f872a5e6c2f6497a741e4 [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);
Chien-Yu Chene2592712016-04-28 12:14:32 -070080 virtual void postRecordingFrameHandleTimestamp(nsecs_t timestamp, native_handle_t* handle);
Wu-cheng Libb1e2752011-07-30 05:00:37 +080081 void postMetadata(JNIEnv *env, int32_t msgType, camera_frame_metadata_t *metadata);
James Donge00cab72011-02-17 16:38:06 -080082 void addCallbackBuffer(JNIEnv *env, jbyteArray cbb, int msgType);
Andrew Harp94927df2009-10-20 01:47:05 -040083 void setCallbackMode(JNIEnv *env, bool installed, bool manualMode);
Dave Sparks5e271152009-06-23 17:30:11 -070084 sp<Camera> getCamera() { Mutex::Autolock _l(mLock); return mCamera; }
James Donge00cab72011-02-17 16:38:06 -080085 bool isRawImageCallbackBufferAvailable() const;
Dave Sparks5e271152009-06-23 17:30:11 -070086 void release();
87
88private:
89 void copyAndPost(JNIEnv* env, const sp<IMemory>& dataPtr, int msgType);
James Donge00cab72011-02-17 16:38:06 -080090 void clearCallbackBuffers_l(JNIEnv *env, Vector<jbyteArray> *buffers);
Andrew Harp94927df2009-10-20 01:47:05 -040091 void clearCallbackBuffers_l(JNIEnv *env);
James Donge00cab72011-02-17 16:38:06 -080092 jbyteArray getCallbackBuffer(JNIEnv *env, Vector<jbyteArray> *buffers, size_t bufferSize);
Dave Sparks5e271152009-06-23 17:30:11 -070093
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094 jobject mCameraJObjectWeak; // weak reference to java object
95 jclass mCameraJClass; // strong reference to java class
Wu-cheng Liffe1cf22009-09-10 16:49:17 +080096 sp<Camera> mCamera; // strong reference to native object
Wu-cheng Libb1e2752011-07-30 05:00:37 +080097 jclass mFaceClass; // strong reference to Face class
98 jclass mRectClass; // strong reference to Rect class
Igor Murashkin0601ab12014-09-18 15:17:20 -070099 jclass mPointClass; // strong reference to Point class
Dave Sparks5e271152009-06-23 17:30:11 -0700100 Mutex mLock;
Andrew Harp94927df2009-10-20 01:47:05 -0400101
James Donge00cab72011-02-17 16:38:06 -0800102 /*
103 * Global reference application-managed raw image buffer queue.
104 *
105 * Manual-only mode is supported for raw image callbacks, which is
106 * set whenever method addCallbackBuffer() with msgType =
107 * CAMERA_MSG_RAW_IMAGE is called; otherwise, null is returned
108 * with raw image callbacks.
109 */
110 Vector<jbyteArray> mRawImageCallbackBuffers;
111
112 /*
113 * Application-managed preview buffer queue and the flags
114 * associated with the usage of the preview buffer callback.
115 */
Andrew Harp94927df2009-10-20 01:47:05 -0400116 Vector<jbyteArray> mCallbackBuffers; // Global reference application managed byte[]
117 bool mManualBufferMode; // Whether to use application managed buffers.
James Donge00cab72011-02-17 16:38:06 -0800118 bool mManualCameraCallbackSet; // Whether the callback has been set, used to
119 // reduce unnecessary calls to set the callback.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800120};
121
James Donge00cab72011-02-17 16:38:06 -0800122bool JNICameraContext::isRawImageCallbackBufferAvailable() const
123{
124 return !mRawImageCallbackBuffers.isEmpty();
125}
126
Dave Sparks5e271152009-06-23 17:30:11 -0700127sp<Camera> get_native_camera(JNIEnv *env, jobject thiz, JNICameraContext** pContext)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800128{
129 sp<Camera> camera;
130 Mutex::Autolock _l(sLock);
Ashok Bhat4838e332014-01-03 14:37:19 +0000131 JNICameraContext* context = reinterpret_cast<JNICameraContext*>(env->GetLongField(thiz, fields.context));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132 if (context != NULL) {
Dave Sparks5e271152009-06-23 17:30:11 -0700133 camera = context->getCamera();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800134 }
Steve Block71f2cf12011-10-20 11:56:00 +0100135 ALOGV("get_native_camera: context=%p, camera=%p", context, camera.get());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800136 if (camera == 0) {
Eino-Ville Talvalaf9133342015-01-12 17:01:11 -0800137 jniThrowRuntimeException(env,
138 "Camera is being used after Camera.release() was called");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800139 }
140
141 if (pContext != NULL) *pContext = context;
142 return camera;
143}
144
Dave Sparks5e271152009-06-23 17:30:11 -0700145JNICameraContext::JNICameraContext(JNIEnv* env, jobject weak_this, jclass clazz, const sp<Camera>& camera)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800146{
Dave Sparks5e271152009-06-23 17:30:11 -0700147 mCameraJObjectWeak = env->NewGlobalRef(weak_this);
148 mCameraJClass = (jclass)env->NewGlobalRef(clazz);
149 mCamera = camera;
Andrew Harp94927df2009-10-20 01:47:05 -0400150
Wu-cheng Libb1e2752011-07-30 05:00:37 +0800151 jclass faceClazz = env->FindClass("android/hardware/Camera$Face");
152 mFaceClass = (jclass) env->NewGlobalRef(faceClazz);
153
154 jclass rectClazz = env->FindClass("android/graphics/Rect");
155 mRectClass = (jclass) env->NewGlobalRef(rectClazz);
156
Igor Murashkin0601ab12014-09-18 15:17:20 -0700157 jclass pointClazz = env->FindClass("android/graphics/Point");
158 mPointClass = (jclass) env->NewGlobalRef(pointClazz);
159
Andrew Harp94927df2009-10-20 01:47:05 -0400160 mManualBufferMode = false;
161 mManualCameraCallbackSet = false;
Dave Sparks5e271152009-06-23 17:30:11 -0700162}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800163
Dave Sparks5e271152009-06-23 17:30:11 -0700164void JNICameraContext::release()
165{
Steve Block71f2cf12011-10-20 11:56:00 +0100166 ALOGV("release");
Dave Sparks5e271152009-06-23 17:30:11 -0700167 Mutex::Autolock _l(mLock);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800168 JNIEnv *env = AndroidRuntime::getJNIEnv();
Dave Sparks5e271152009-06-23 17:30:11 -0700169
170 if (mCameraJObjectWeak != NULL) {
171 env->DeleteGlobalRef(mCameraJObjectWeak);
172 mCameraJObjectWeak = NULL;
173 }
174 if (mCameraJClass != NULL) {
175 env->DeleteGlobalRef(mCameraJClass);
176 mCameraJClass = NULL;
177 }
Wu-cheng Libb1e2752011-07-30 05:00:37 +0800178 if (mFaceClass != NULL) {
179 env->DeleteGlobalRef(mFaceClass);
180 mFaceClass = NULL;
181 }
182 if (mRectClass != NULL) {
183 env->DeleteGlobalRef(mRectClass);
184 mRectClass = NULL;
185 }
Igor Murashkin0601ab12014-09-18 15:17:20 -0700186 if (mPointClass != NULL) {
187 env->DeleteGlobalRef(mPointClass);
188 mPointClass = NULL;
189 }
Andrew Harp94927df2009-10-20 01:47:05 -0400190 clearCallbackBuffers_l(env);
Dave Sparks5e271152009-06-23 17:30:11 -0700191 mCamera.clear();
192}
193
194void JNICameraContext::notify(int32_t msgType, int32_t ext1, int32_t ext2)
195{
Steve Block71f2cf12011-10-20 11:56:00 +0100196 ALOGV("notify");
Dave Sparks5e271152009-06-23 17:30:11 -0700197
198 // VM pointer will be NULL if object is released
199 Mutex::Autolock _l(mLock);
200 if (mCameraJObjectWeak == NULL) {
Steve Block8564c8d2012-01-05 23:22:43 +0000201 ALOGW("callback on dead camera object");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800202 return;
203 }
Dave Sparks5e271152009-06-23 17:30:11 -0700204 JNIEnv *env = AndroidRuntime::getJNIEnv();
James Donge00cab72011-02-17 16:38:06 -0800205
206 /*
207 * If the notification or msgType is CAMERA_MSG_RAW_IMAGE_NOTIFY, change it
208 * to CAMERA_MSG_RAW_IMAGE since CAMERA_MSG_RAW_IMAGE_NOTIFY is not exposed
209 * to the Java app.
210 */
211 if (msgType == CAMERA_MSG_RAW_IMAGE_NOTIFY) {
212 msgType = CAMERA_MSG_RAW_IMAGE;
213 }
214
Dave Sparksc62f9bd2009-06-26 13:33:32 -0700215 env->CallStaticVoidMethod(mCameraJClass, fields.post_event,
Chih-Chung Chang6157de02009-09-24 15:29:35 -0700216 mCameraJObjectWeak, msgType, ext1, ext2, NULL);
Dave Sparks5e271152009-06-23 17:30:11 -0700217}
218
James Donge00cab72011-02-17 16:38:06 -0800219jbyteArray JNICameraContext::getCallbackBuffer(
220 JNIEnv* env, Vector<jbyteArray>* buffers, size_t bufferSize)
221{
222 jbyteArray obj = NULL;
223
224 // Vector access should be protected by lock in postData()
225 if (!buffers->isEmpty()) {
Dan Albert46d84442014-11-18 16:07:51 -0800226 ALOGV("Using callback buffer from queue of length %zu", buffers->size());
James Donge00cab72011-02-17 16:38:06 -0800227 jbyteArray globalBuffer = buffers->itemAt(0);
228 buffers->removeAt(0);
229
230 obj = (jbyteArray)env->NewLocalRef(globalBuffer);
231 env->DeleteGlobalRef(globalBuffer);
232
233 if (obj != NULL) {
234 jsize bufferLength = env->GetArrayLength(obj);
235 if ((int)bufferLength < (int)bufferSize) {
Dan Albert46d84442014-11-18 16:07:51 -0800236 ALOGE("Callback buffer was too small! Expected %zu bytes, but got %d bytes!",
James Donge00cab72011-02-17 16:38:06 -0800237 bufferSize, bufferLength);
238 env->DeleteLocalRef(obj);
239 return NULL;
240 }
241 }
242 }
243
244 return obj;
245}
246
Dave Sparks5e271152009-06-23 17:30:11 -0700247void JNICameraContext::copyAndPost(JNIEnv* env, const sp<IMemory>& dataPtr, int msgType)
248{
249 jbyteArray obj = NULL;
250
251 // allocate Java byte array and copy data
252 if (dataPtr != NULL) {
253 ssize_t offset;
254 size_t size;
255 sp<IMemoryHeap> heap = dataPtr->getMemory(&offset, &size);
Glenn Kasten2fbf25b2014-03-28 15:41:58 -0700256 ALOGV("copyAndPost: off=%zd, size=%zu", offset, size);
Dave Sparks5e271152009-06-23 17:30:11 -0700257 uint8_t *heapBase = (uint8_t*)heap->base();
258
259 if (heapBase != NULL) {
Dave Sparksc4ca4202009-07-13 09:38:20 -0700260 const jbyte* data = reinterpret_cast<const jbyte*>(heapBase + offset);
Andrew Harp94927df2009-10-20 01:47:05 -0400261
Wu-cheng Li5f0ef5f2011-09-21 16:40:23 +0800262 if (msgType == CAMERA_MSG_RAW_IMAGE) {
263 obj = getCallbackBuffer(env, &mRawImageCallbackBuffers, size);
264 } else if (msgType == CAMERA_MSG_PREVIEW_FRAME && mManualBufferMode) {
265 obj = getCallbackBuffer(env, &mCallbackBuffers, size);
Andrew Harp94927df2009-10-20 01:47:05 -0400266
Wu-cheng Li5f0ef5f2011-09-21 16:40:23 +0800267 if (mCallbackBuffers.isEmpty()) {
Steve Block71f2cf12011-10-20 11:56:00 +0100268 ALOGV("Out of buffers, clearing callback!");
Wu-cheng Li5f0ef5f2011-09-21 16:40:23 +0800269 mCamera->setPreviewCallbackFlags(CAMERA_FRAME_CALLBACK_FLAG_NOOP);
270 mManualCameraCallbackSet = false;
Andrew Harp94927df2009-10-20 01:47:05 -0400271
Wu-cheng Li5f0ef5f2011-09-21 16:40:23 +0800272 if (obj == NULL) {
Andrew Harp94927df2009-10-20 01:47:05 -0400273 return;
274 }
275 }
Wu-cheng Li5f0ef5f2011-09-21 16:40:23 +0800276 } else {
Steve Block71f2cf12011-10-20 11:56:00 +0100277 ALOGV("Allocating callback buffer");
Wu-cheng Li5f0ef5f2011-09-21 16:40:23 +0800278 obj = env->NewByteArray(size);
Andrew Harp94927df2009-10-20 01:47:05 -0400279 }
280
Dave Sparks5e271152009-06-23 17:30:11 -0700281 if (obj == NULL) {
Steve Block3762c312012-01-06 19:20:56 +0000282 ALOGE("Couldn't allocate byte array for JPEG data");
Dave Sparks5e271152009-06-23 17:30:11 -0700283 env->ExceptionClear();
284 } else {
Dave Sparksa95f4952009-07-10 18:13:36 -0700285 env->SetByteArrayRegion(obj, 0, size, data);
Dave Sparks5e271152009-06-23 17:30:11 -0700286 }
287 } else {
Steve Block3762c312012-01-06 19:20:56 +0000288 ALOGE("image heap is NULL");
Dave Sparks5e271152009-06-23 17:30:11 -0700289 }
290 }
291
292 // post image data to Java
293 env->CallStaticVoidMethod(mCameraJClass, fields.post_event,
294 mCameraJObjectWeak, msgType, 0, 0, obj);
295 if (obj) {
296 env->DeleteLocalRef(obj);
297 }
298}
299
Wu-cheng Libb1e2752011-07-30 05:00:37 +0800300void JNICameraContext::postData(int32_t msgType, const sp<IMemory>& dataPtr,
301 camera_frame_metadata_t *metadata)
Dave Sparks5e271152009-06-23 17:30:11 -0700302{
303 // VM pointer will be NULL if object is released
304 Mutex::Autolock _l(mLock);
305 JNIEnv *env = AndroidRuntime::getJNIEnv();
Dave Sparksd0cbb1a2009-06-29 19:03:33 -0700306 if (mCameraJObjectWeak == NULL) {
Steve Block8564c8d2012-01-05 23:22:43 +0000307 ALOGW("callback on dead camera object");
Dave Sparksd0cbb1a2009-06-29 19:03:33 -0700308 return;
309 }
Dave Sparks5e271152009-06-23 17:30:11 -0700310
Wu-cheng Libb1e2752011-07-30 05:00:37 +0800311 int32_t dataMsgType = msgType & ~CAMERA_MSG_PREVIEW_METADATA;
312
Dave Sparks5e271152009-06-23 17:30:11 -0700313 // return data based on callback type
Wu-cheng Libb1e2752011-07-30 05:00:37 +0800314 switch (dataMsgType) {
James Donge00cab72011-02-17 16:38:06 -0800315 case CAMERA_MSG_VIDEO_FRAME:
316 // should never happen
317 break;
318
319 // For backward-compatibility purpose, if there is no callback
320 // buffer for raw image, the callback returns null.
321 case CAMERA_MSG_RAW_IMAGE:
Steve Block71f2cf12011-10-20 11:56:00 +0100322 ALOGV("rawCallback");
James Donge00cab72011-02-17 16:38:06 -0800323 if (mRawImageCallbackBuffers.isEmpty()) {
324 env->CallStaticVoidMethod(mCameraJClass, fields.post_event,
Wu-cheng Libb1e2752011-07-30 05:00:37 +0800325 mCameraJObjectWeak, dataMsgType, 0, 0, NULL);
James Donge00cab72011-02-17 16:38:06 -0800326 } else {
Wu-cheng Libb1e2752011-07-30 05:00:37 +0800327 copyAndPost(env, dataPtr, dataMsgType);
James Donge00cab72011-02-17 16:38:06 -0800328 }
329 break;
330
Wu-cheng Libb1e2752011-07-30 05:00:37 +0800331 // There is no data.
332 case 0:
James Donge00cab72011-02-17 16:38:06 -0800333 break;
Wu-cheng Libb1e2752011-07-30 05:00:37 +0800334
335 default:
Steve Block71f2cf12011-10-20 11:56:00 +0100336 ALOGV("dataCallback(%d, %p)", dataMsgType, dataPtr.get());
Wu-cheng Libb1e2752011-07-30 05:00:37 +0800337 copyAndPost(env, dataPtr, dataMsgType);
338 break;
339 }
340
341 // post frame metadata to Java
342 if (metadata && (msgType & CAMERA_MSG_PREVIEW_METADATA)) {
343 postMetadata(env, CAMERA_MSG_PREVIEW_METADATA, metadata);
Dave Sparks5e271152009-06-23 17:30:11 -0700344 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800345}
346
Dave Sparks59c1a932009-07-08 15:56:53 -0700347void JNICameraContext::postDataTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr)
348{
349 // TODO: plumb up to Java. For now, just drop the timestamp
Wu-cheng Libb1e2752011-07-30 05:00:37 +0800350 postData(msgType, dataPtr, NULL);
351}
352
Akhila musunuri44a59492016-07-21 13:33:11 +0530353void JNICameraContext::postRecordingFrameHandleTimestamp(nsecs_t, native_handle_t* handle) {
354 // Video buffers are not needed at app layer so just return the video buffers here.
355 // This may be called when stagefright just releases camera but there are still outstanding
356 // video buffers.
357 if (mCamera != nullptr) {
358 mCamera->releaseRecordingFrameHandle(handle);
359 } else {
360 native_handle_close(handle);
361 native_handle_delete(handle);
362 }
Chien-Yu Chene2592712016-04-28 12:14:32 -0700363}
364
Wu-cheng Libb1e2752011-07-30 05:00:37 +0800365void JNICameraContext::postMetadata(JNIEnv *env, int32_t msgType, camera_frame_metadata_t *metadata)
366{
367 jobjectArray obj = NULL;
368 obj = (jobjectArray) env->NewObjectArray(metadata->number_of_faces,
369 mFaceClass, NULL);
370 if (obj == NULL) {
Steve Block3762c312012-01-06 19:20:56 +0000371 ALOGE("Couldn't allocate face metadata array");
Wu-cheng Libb1e2752011-07-30 05:00:37 +0800372 return;
373 }
374
375 for (int i = 0; i < metadata->number_of_faces; i++) {
376 jobject face = env->NewObject(mFaceClass, fields.face_constructor);
377 env->SetObjectArrayElement(obj, i, face);
378
379 jobject rect = env->NewObject(mRectClass, fields.rect_constructor);
380 env->SetIntField(rect, fields.rect_left, metadata->faces[i].rect[0]);
381 env->SetIntField(rect, fields.rect_top, metadata->faces[i].rect[1]);
382 env->SetIntField(rect, fields.rect_right, metadata->faces[i].rect[2]);
383 env->SetIntField(rect, fields.rect_bottom, metadata->faces[i].rect[3]);
384
385 env->SetObjectField(face, fields.face_rect, rect);
386 env->SetIntField(face, fields.face_score, metadata->faces[i].score);
387
Igor Murashkin0601ab12014-09-18 15:17:20 -0700388 bool optionalFields = metadata->faces[i].id != 0
389 && metadata->faces[i].left_eye[0] != -2000 && metadata->faces[i].left_eye[1] != -2000
390 && metadata->faces[i].right_eye[0] != -2000 && metadata->faces[i].right_eye[1] != -2000
391 && metadata->faces[i].mouth[0] != -2000 && metadata->faces[i].mouth[1] != -2000;
392 if (optionalFields) {
393 int32_t id = metadata->faces[i].id;
394 env->SetIntField(face, fields.face_id, id);
395
396 jobject leftEye = env->NewObject(mPointClass, fields.point_constructor);
397 env->SetIntField(leftEye, fields.point_x, metadata->faces[i].left_eye[0]);
398 env->SetIntField(leftEye, fields.point_y, metadata->faces[i].left_eye[1]);
399 env->SetObjectField(face, fields.face_left_eye, leftEye);
400 env->DeleteLocalRef(leftEye);
401
402 jobject rightEye = env->NewObject(mPointClass, fields.point_constructor);
403 env->SetIntField(rightEye, fields.point_x, metadata->faces[i].right_eye[0]);
404 env->SetIntField(rightEye, fields.point_y, metadata->faces[i].right_eye[1]);
405 env->SetObjectField(face, fields.face_right_eye, rightEye);
406 env->DeleteLocalRef(rightEye);
407
408 jobject mouth = env->NewObject(mPointClass, fields.point_constructor);
409 env->SetIntField(mouth, fields.point_x, metadata->faces[i].mouth[0]);
410 env->SetIntField(mouth, fields.point_y, metadata->faces[i].mouth[1]);
411 env->SetObjectField(face, fields.face_mouth, mouth);
412 env->DeleteLocalRef(mouth);
413 }
414
Wu-cheng Libb1e2752011-07-30 05:00:37 +0800415 env->DeleteLocalRef(face);
416 env->DeleteLocalRef(rect);
417 }
418 env->CallStaticVoidMethod(mCameraJClass, fields.post_event,
419 mCameraJObjectWeak, msgType, 0, 0, obj);
420 env->DeleteLocalRef(obj);
Dave Sparks59c1a932009-07-08 15:56:53 -0700421}
422
Andrew Harp94927df2009-10-20 01:47:05 -0400423void JNICameraContext::setCallbackMode(JNIEnv *env, bool installed, bool manualMode)
424{
425 Mutex::Autolock _l(mLock);
426 mManualBufferMode = manualMode;
427 mManualCameraCallbackSet = false;
428
429 // In order to limit the over usage of binder threads, all non-manual buffer
Iliyan Malchev9c7ac0d2011-04-14 16:51:21 -0700430 // callbacks use CAMERA_FRAME_CALLBACK_FLAG_BARCODE_SCANNER mode now.
Andrew Harp94927df2009-10-20 01:47:05 -0400431 //
432 // Continuous callbacks will have the callback re-registered from handleMessage.
433 // Manual buffer mode will operate as fast as possible, relying on the finite supply
434 // of buffers for throttling.
435
436 if (!installed) {
Iliyan Malchev9c7ac0d2011-04-14 16:51:21 -0700437 mCamera->setPreviewCallbackFlags(CAMERA_FRAME_CALLBACK_FLAG_NOOP);
James Donge00cab72011-02-17 16:38:06 -0800438 clearCallbackBuffers_l(env, &mCallbackBuffers);
Andrew Harp94927df2009-10-20 01:47:05 -0400439 } else if (mManualBufferMode) {
440 if (!mCallbackBuffers.isEmpty()) {
Iliyan Malchev9c7ac0d2011-04-14 16:51:21 -0700441 mCamera->setPreviewCallbackFlags(CAMERA_FRAME_CALLBACK_FLAG_CAMERA);
Andrew Harp94927df2009-10-20 01:47:05 -0400442 mManualCameraCallbackSet = true;
443 }
444 } else {
Iliyan Malchev9c7ac0d2011-04-14 16:51:21 -0700445 mCamera->setPreviewCallbackFlags(CAMERA_FRAME_CALLBACK_FLAG_BARCODE_SCANNER);
James Donge00cab72011-02-17 16:38:06 -0800446 clearCallbackBuffers_l(env, &mCallbackBuffers);
Andrew Harp94927df2009-10-20 01:47:05 -0400447 }
448}
449
James Donge00cab72011-02-17 16:38:06 -0800450void JNICameraContext::addCallbackBuffer(
451 JNIEnv *env, jbyteArray cbb, int msgType)
Andrew Harp94927df2009-10-20 01:47:05 -0400452{
Steve Block71f2cf12011-10-20 11:56:00 +0100453 ALOGV("addCallbackBuffer: 0x%x", msgType);
Andrew Harp94927df2009-10-20 01:47:05 -0400454 if (cbb != NULL) {
455 Mutex::Autolock _l(mLock);
James Donge00cab72011-02-17 16:38:06 -0800456 switch (msgType) {
457 case CAMERA_MSG_PREVIEW_FRAME: {
458 jbyteArray callbackBuffer = (jbyteArray)env->NewGlobalRef(cbb);
459 mCallbackBuffers.push(callbackBuffer);
Andrew Harp94927df2009-10-20 01:47:05 -0400460
Dan Albert46d84442014-11-18 16:07:51 -0800461 ALOGV("Adding callback buffer to queue, %zu total",
James Donge00cab72011-02-17 16:38:06 -0800462 mCallbackBuffers.size());
Andrew Harp94927df2009-10-20 01:47:05 -0400463
James Donge00cab72011-02-17 16:38:06 -0800464 // We want to make sure the camera knows we're ready for the
465 // next frame. This may have come unset had we not had a
466 // callbackbuffer ready for it last time.
467 if (mManualBufferMode && !mManualCameraCallbackSet) {
Iliyan Malchev9c7ac0d2011-04-14 16:51:21 -0700468 mCamera->setPreviewCallbackFlags(CAMERA_FRAME_CALLBACK_FLAG_CAMERA);
James Donge00cab72011-02-17 16:38:06 -0800469 mManualCameraCallbackSet = true;
470 }
471 break;
472 }
473 case CAMERA_MSG_RAW_IMAGE: {
474 jbyteArray callbackBuffer = (jbyteArray)env->NewGlobalRef(cbb);
475 mRawImageCallbackBuffers.push(callbackBuffer);
476 break;
477 }
478 default: {
479 jniThrowException(env,
480 "java/lang/IllegalArgumentException",
481 "Unsupported message type");
482 return;
483 }
Andrew Harp94927df2009-10-20 01:47:05 -0400484 }
485 } else {
Steve Block3762c312012-01-06 19:20:56 +0000486 ALOGE("Null byte array!");
Andrew Harp94927df2009-10-20 01:47:05 -0400487 }
488}
489
490void JNICameraContext::clearCallbackBuffers_l(JNIEnv *env)
491{
James Donge00cab72011-02-17 16:38:06 -0800492 clearCallbackBuffers_l(env, &mCallbackBuffers);
493 clearCallbackBuffers_l(env, &mRawImageCallbackBuffers);
494}
495
496void JNICameraContext::clearCallbackBuffers_l(JNIEnv *env, Vector<jbyteArray> *buffers) {
Dan Albert46d84442014-11-18 16:07:51 -0800497 ALOGV("Clearing callback buffers, %zu remained", buffers->size());
James Donge00cab72011-02-17 16:38:06 -0800498 while (!buffers->isEmpty()) {
499 env->DeleteGlobalRef(buffers->top());
500 buffers->pop();
Andrew Harp94927df2009-10-20 01:47:05 -0400501 }
502}
503
Chih-Chung Change25cc652010-05-06 16:36:58 +0800504static jint android_hardware_Camera_getNumberOfCameras(JNIEnv *env, jobject thiz)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800505{
Chih-Chung Change25cc652010-05-06 16:36:58 +0800506 return Camera::getNumberOfCameras();
507}
508
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800509static void android_hardware_Camera_getCameraInfo(JNIEnv *env, jobject thiz,
510 jint cameraId, jobject info_obj)
511{
512 CameraInfo cameraInfo;
Eino-Ville Talvala57176122015-08-14 13:11:16 -0700513 if (cameraId >= Camera::getNumberOfCameras() || cameraId < 0) {
514 ALOGE("%s: Unknown camera ID %d", __FUNCTION__, cameraId);
515 jniThrowRuntimeException(env, "Unknown camera ID");
516 return;
517 }
518
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800519 status_t rc = Camera::getCameraInfo(cameraId, &cameraInfo);
520 if (rc != NO_ERROR) {
Elliott Hughes69a017b2011-04-08 14:10:28 -0700521 jniThrowRuntimeException(env, "Fail to get camera info");
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800522 return;
523 }
524 env->SetIntField(info_obj, fields.facing, cameraInfo.facing);
525 env->SetIntField(info_obj, fields.orientation, cameraInfo.orientation);
Eino-Ville Talvalaf7c6c5a2012-09-19 11:46:11 -0700526
527 char value[PROPERTY_VALUE_MAX];
528 property_get("ro.camera.sound.forced", value, "0");
529 jboolean canDisableShutterSound = (strncmp(value, "0", 2) == 0);
530 env->SetBooleanField(info_obj, fields.canDisableShutterSound,
531 canDisableShutterSound);
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800532}
533
Chih-Chung Change25cc652010-05-06 16:36:58 +0800534// connect to camera service
Ruben Brunkfeb50af2014-05-09 19:58:49 -0700535static jint android_hardware_Camera_native_setup(JNIEnv *env, jobject thiz,
Zhijun He4c913802014-06-16 16:42:35 -0700536 jobject weak_this, jint cameraId, jint halVersion, jstring clientPackageName)
Chih-Chung Change25cc652010-05-06 16:36:58 +0800537{
Eino-Ville Talvala788717c2013-02-15 18:30:15 -0800538 // Convert jstring to String16
Dan Albert66987492014-11-20 11:41:21 -0800539 const char16_t *rawClientName = reinterpret_cast<const char16_t*>(
540 env->GetStringChars(clientPackageName, NULL));
Eino-Ville Talvala788717c2013-02-15 18:30:15 -0800541 jsize rawClientNameLen = env->GetStringLength(clientPackageName);
542 String16 clientName(rawClientName, rawClientNameLen);
Dan Albert66987492014-11-20 11:41:21 -0800543 env->ReleaseStringChars(clientPackageName,
544 reinterpret_cast<const jchar*>(rawClientName));
Eino-Ville Talvala788717c2013-02-15 18:30:15 -0800545
Zhijun He4c913802014-06-16 16:42:35 -0700546 sp<Camera> camera;
Igor Murashkina1d66272014-06-20 11:22:11 -0700547 if (halVersion == CAMERA_HAL_API_VERSION_NORMAL_CONNECT) {
548 // Default path: hal version is don't care, do normal camera connect.
Zhijun He4c913802014-06-16 16:42:35 -0700549 camera = Camera::connect(cameraId, clientName,
Chien-Yu Chen225257a2015-12-18 14:20:46 -0800550 Camera::USE_CALLING_UID, Camera::USE_CALLING_PID);
Zhijun He4c913802014-06-16 16:42:35 -0700551 } else {
552 jint status = Camera::connectLegacy(cameraId, halVersion, clientName,
553 Camera::USE_CALLING_UID, camera);
554 if (status != NO_ERROR) {
555 return status;
556 }
557 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800558
559 if (camera == NULL) {
Ruben Brunkfeb50af2014-05-09 19:58:49 -0700560 return -EACCES;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800561 }
562
563 // make sure camera hardware is alive
564 if (camera->getStatus() != NO_ERROR) {
Ruben Brunkfeb50af2014-05-09 19:58:49 -0700565 return NO_INIT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800566 }
567
568 jclass clazz = env->GetObjectClass(thiz);
569 if (clazz == NULL) {
Ruben Brunkfeb50af2014-05-09 19:58:49 -0700570 // This should never happen
Elliott Hughes69a017b2011-04-08 14:10:28 -0700571 jniThrowRuntimeException(env, "Can't find android/hardware/Camera");
Ruben Brunkfeb50af2014-05-09 19:58:49 -0700572 return INVALID_OPERATION;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800573 }
574
575 // We use a weak reference so the Camera object can be garbage collected.
576 // The reference is only used as a proxy for callbacks.
Dave Sparks5e271152009-06-23 17:30:11 -0700577 sp<JNICameraContext> context = new JNICameraContext(env, weak_this, clazz, camera);
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800578 context->incStrong((void*)android_hardware_Camera_native_setup);
Dave Sparks5e271152009-06-23 17:30:11 -0700579 camera->setListener(context);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800580
581 // save context in opaque field
Ashok Bhat4838e332014-01-03 14:37:19 +0000582 env->SetLongField(thiz, fields.context, (jlong)context.get());
Eino-Ville Talvala6c91e2c2016-03-25 11:54:39 -0700583
584 // Update default display orientation in case the sensor is reverse-landscape
585 CameraInfo cameraInfo;
586 status_t rc = Camera::getCameraInfo(cameraId, &cameraInfo);
587 if (rc != NO_ERROR) {
588 return rc;
589 }
590 int defaultOrientation = 0;
591 switch (cameraInfo.orientation) {
592 case 0:
593 break;
594 case 90:
595 if (cameraInfo.facing == CAMERA_FACING_FRONT) {
596 defaultOrientation = 180;
597 }
598 break;
599 case 180:
600 defaultOrientation = 180;
601 break;
602 case 270:
603 if (cameraInfo.facing != CAMERA_FACING_FRONT) {
604 defaultOrientation = 180;
605 }
606 break;
607 default:
608 ALOGE("Unexpected camera orientation %d!", cameraInfo.orientation);
609 break;
610 }
611 if (defaultOrientation != 0) {
612 ALOGV("Setting default display orientation to %d", defaultOrientation);
613 rc = camera->sendCommand(CAMERA_CMD_SET_DISPLAY_ORIENTATION,
614 defaultOrientation, 0);
615 if (rc != NO_ERROR) {
616 ALOGE("Unable to update default orientation: %s (%d)",
617 strerror(-rc), rc);
618 return rc;
619 }
620 }
621
Ruben Brunkfeb50af2014-05-09 19:58:49 -0700622 return NO_ERROR;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800623}
624
625// disconnect from camera service
626// It's okay to call this when the native camera context is already null.
627// This handles the case where the user has called release() and the
628// finalizer is invoked later.
629static void android_hardware_Camera_release(JNIEnv *env, jobject thiz)
630{
Steve Block71f2cf12011-10-20 11:56:00 +0100631 ALOGV("release camera");
Dave Sparks5e271152009-06-23 17:30:11 -0700632 JNICameraContext* context = NULL;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800633 sp<Camera> camera;
634 {
635 Mutex::Autolock _l(sLock);
Ashok Bhat4838e332014-01-03 14:37:19 +0000636 context = reinterpret_cast<JNICameraContext*>(env->GetLongField(thiz, fields.context));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800637
638 // Make sure we do not attempt to callback on a deleted Java object.
Ashok Bhat4838e332014-01-03 14:37:19 +0000639 env->SetLongField(thiz, fields.context, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800640 }
641
642 // clean up if release has not been called before
643 if (context != NULL) {
Dave Sparks5e271152009-06-23 17:30:11 -0700644 camera = context->getCamera();
645 context->release();
Steve Block71f2cf12011-10-20 11:56:00 +0100646 ALOGV("native_release: context=%p camera=%p", context, camera.get());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800647
648 // clear callbacks
649 if (camera != NULL) {
Iliyan Malchev9c7ac0d2011-04-14 16:51:21 -0700650 camera->setPreviewCallbackFlags(CAMERA_FRAME_CALLBACK_FLAG_NOOP);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800651 camera->disconnect();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800652 }
653
654 // remove context to prevent further Java access
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800655 context->decStrong((void*)android_hardware_Camera_native_setup);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800656 }
657}
658
Ruben Brunkfeb50af2014-05-09 19:58:49 -0700659static void android_hardware_Camera_setPreviewSurface(JNIEnv *env, jobject thiz, jobject jSurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800660{
Ruben Brunkfeb50af2014-05-09 19:58:49 -0700661 ALOGV("setPreviewSurface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800662 sp<Camera> camera = get_native_camera(env, thiz, NULL);
663 if (camera == 0) return;
664
Mathias Agopian4a05f432013-03-12 18:43:34 -0700665 sp<IGraphicBufferProducer> gbp;
Jesse Hallaa70f222013-02-21 15:06:27 -0800666 sp<Surface> surface;
667 if (jSurface) {
668 surface = android_view_Surface_getSurface(env, jSurface);
Mathias Agopian4a05f432013-03-12 18:43:34 -0700669 if (surface != NULL) {
670 gbp = surface->getIGraphicBufferProducer();
671 }
Jesse Hallaa70f222013-02-21 15:06:27 -0800672 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800673
Eino-Ville Talvala7b297792013-08-21 14:39:22 -0700674 if (camera->setPreviewTarget(gbp) != NO_ERROR) {
Mathias Agopian4a05f432013-03-12 18:43:34 -0700675 jniThrowException(env, "java/io/IOException", "setPreviewTexture failed");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800676 }
677}
678
Jamie Gennisfd6f39e2010-12-20 12:15:00 -0800679static void android_hardware_Camera_setPreviewTexture(JNIEnv *env,
680 jobject thiz, jobject jSurfaceTexture)
681{
Steve Block71f2cf12011-10-20 11:56:00 +0100682 ALOGV("setPreviewTexture");
Jamie Gennisfd6f39e2010-12-20 12:15:00 -0800683 sp<Camera> camera = get_native_camera(env, thiz, NULL);
684 if (camera == 0) return;
685
Mathias Agopian52a9a102013-08-02 01:38:38 -0700686 sp<IGraphicBufferProducer> producer = NULL;
Jamie Gennisfd6f39e2010-12-20 12:15:00 -0800687 if (jSurfaceTexture != NULL) {
Mathias Agopian52a9a102013-08-02 01:38:38 -0700688 producer = SurfaceTexture_getProducer(env, jSurfaceTexture);
689 if (producer == NULL) {
Daniel Lam2e76c992012-02-23 14:35:13 -0800690 jniThrowException(env, "java/lang/IllegalArgumentException",
691 "SurfaceTexture already released in setPreviewTexture");
692 return;
693 }
694
Jamie Gennisfd6f39e2010-12-20 12:15:00 -0800695 }
Daniel Lam2e76c992012-02-23 14:35:13 -0800696
Eino-Ville Talvala7b297792013-08-21 14:39:22 -0700697 if (camera->setPreviewTarget(producer) != NO_ERROR) {
Jamie Gennisfd6f39e2010-12-20 12:15:00 -0800698 jniThrowException(env, "java/io/IOException",
699 "setPreviewTexture failed");
700 }
701}
702
Eino-Ville Talvala7005b672013-04-02 15:46:38 -0700703static void android_hardware_Camera_setPreviewCallbackSurface(JNIEnv *env,
704 jobject thiz, jobject jSurface)
705{
706 ALOGV("setPreviewCallbackSurface");
707 JNICameraContext* context;
708 sp<Camera> camera = get_native_camera(env, thiz, &context);
709 if (camera == 0) return;
710
711 sp<IGraphicBufferProducer> gbp;
712 sp<Surface> surface;
713 if (jSurface) {
714 surface = android_view_Surface_getSurface(env, jSurface);
715 if (surface != NULL) {
716 gbp = surface->getIGraphicBufferProducer();
717 }
718 }
719 // Clear out normal preview callbacks
720 context->setCallbackMode(env, false, false);
721 // Then set up callback surface
722 if (camera->setPreviewCallbackTarget(gbp) != NO_ERROR) {
723 jniThrowException(env, "java/io/IOException", "setPreviewCallbackTarget failed");
724 }
725}
726
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800727static void android_hardware_Camera_startPreview(JNIEnv *env, jobject thiz)
728{
Steve Block71f2cf12011-10-20 11:56:00 +0100729 ALOGV("startPreview");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800730 sp<Camera> camera = get_native_camera(env, thiz, NULL);
731 if (camera == 0) return;
732
733 if (camera->startPreview() != NO_ERROR) {
Elliott Hughes69a017b2011-04-08 14:10:28 -0700734 jniThrowRuntimeException(env, "startPreview failed");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800735 return;
736 }
737}
738
739static void android_hardware_Camera_stopPreview(JNIEnv *env, jobject thiz)
740{
Steve Block71f2cf12011-10-20 11:56:00 +0100741 ALOGV("stopPreview");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800742 sp<Camera> c = get_native_camera(env, thiz, NULL);
743 if (c == 0) return;
744
745 c->stopPreview();
746}
747
Ashok Bhat4838e332014-01-03 14:37:19 +0000748static jboolean android_hardware_Camera_previewEnabled(JNIEnv *env, jobject thiz)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800749{
Steve Block71f2cf12011-10-20 11:56:00 +0100750 ALOGV("previewEnabled");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800751 sp<Camera> c = get_native_camera(env, thiz, NULL);
Ashok Bhat4838e332014-01-03 14:37:19 +0000752 if (c == 0) return JNI_FALSE;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800753
Ashok Bhat4838e332014-01-03 14:37:19 +0000754 return c->previewEnabled() ? JNI_TRUE : JNI_FALSE;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800755}
756
Andrew Harp94927df2009-10-20 01:47:05 -0400757static void android_hardware_Camera_setHasPreviewCallback(JNIEnv *env, jobject thiz, jboolean installed, jboolean manualBuffer)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800758{
Steve Block71f2cf12011-10-20 11:56:00 +0100759 ALOGV("setHasPreviewCallback: installed:%d, manualBuffer:%d", (int)installed, (int)manualBuffer);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800760 // Important: Only install preview_callback if the Java code has called
761 // setPreviewCallback() with a non-null value, otherwise we'd pay to memcpy
762 // each preview frame for nothing.
Dave Sparks5e271152009-06-23 17:30:11 -0700763 JNICameraContext* context;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800764 sp<Camera> camera = get_native_camera(env, thiz, &context);
765 if (camera == 0) return;
766
Andrew Harp94927df2009-10-20 01:47:05 -0400767 // setCallbackMode will take care of setting the context flags and calling
768 // camera->setPreviewCallbackFlags within a mutex for us.
769 context->setCallbackMode(env, installed, manualBuffer);
770}
771
Ashok Bhat4838e332014-01-03 14:37:19 +0000772static void android_hardware_Camera_addCallbackBuffer(JNIEnv *env, jobject thiz, jbyteArray bytes, jint msgType) {
Steve Block71f2cf12011-10-20 11:56:00 +0100773 ALOGV("addCallbackBuffer: 0x%x", msgType);
Andrew Harp94927df2009-10-20 01:47:05 -0400774
Ashok Bhat4838e332014-01-03 14:37:19 +0000775 JNICameraContext* context = reinterpret_cast<JNICameraContext*>(env->GetLongField(thiz, fields.context));
Andrew Harp94927df2009-10-20 01:47:05 -0400776
777 if (context != NULL) {
James Donge00cab72011-02-17 16:38:06 -0800778 context->addCallbackBuffer(env, bytes, msgType);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800779 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800780}
781
782static void android_hardware_Camera_autoFocus(JNIEnv *env, jobject thiz)
783{
Steve Block71f2cf12011-10-20 11:56:00 +0100784 ALOGV("autoFocus");
Dave Sparks5e271152009-06-23 17:30:11 -0700785 JNICameraContext* context;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800786 sp<Camera> c = get_native_camera(env, thiz, &context);
787 if (c == 0) return;
788
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800789 if (c->autoFocus() != NO_ERROR) {
Elliott Hughes69a017b2011-04-08 14:10:28 -0700790 jniThrowRuntimeException(env, "autoFocus failed");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800791 }
792}
793
Chih-Chung Chang244f8c22009-09-15 14:51:56 +0800794static void android_hardware_Camera_cancelAutoFocus(JNIEnv *env, jobject thiz)
795{
Steve Block71f2cf12011-10-20 11:56:00 +0100796 ALOGV("cancelAutoFocus");
Chih-Chung Chang244f8c22009-09-15 14:51:56 +0800797 JNICameraContext* context;
798 sp<Camera> c = get_native_camera(env, thiz, &context);
799 if (c == 0) return;
800
801 if (c->cancelAutoFocus() != NO_ERROR) {
Elliott Hughes69a017b2011-04-08 14:10:28 -0700802 jniThrowRuntimeException(env, "cancelAutoFocus failed");
Chih-Chung Chang244f8c22009-09-15 14:51:56 +0800803 }
804}
805
Ashok Bhat4838e332014-01-03 14:37:19 +0000806static void android_hardware_Camera_takePicture(JNIEnv *env, jobject thiz, jint msgType)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800807{
Steve Block71f2cf12011-10-20 11:56:00 +0100808 ALOGV("takePicture");
Dave Sparks5e271152009-06-23 17:30:11 -0700809 JNICameraContext* context;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800810 sp<Camera> camera = get_native_camera(env, thiz, &context);
811 if (camera == 0) return;
812
James Donge00cab72011-02-17 16:38:06 -0800813 /*
814 * When CAMERA_MSG_RAW_IMAGE is requested, if the raw image callback
815 * buffer is available, CAMERA_MSG_RAW_IMAGE is enabled to get the
816 * notification _and_ the data; otherwise, CAMERA_MSG_RAW_IMAGE_NOTIFY
817 * is enabled to receive the callback notification but no data.
818 *
819 * Note that CAMERA_MSG_RAW_IMAGE_NOTIFY is not exposed to the
820 * Java application.
821 */
822 if (msgType & CAMERA_MSG_RAW_IMAGE) {
Steve Block71f2cf12011-10-20 11:56:00 +0100823 ALOGV("Enable raw image callback buffer");
James Donge00cab72011-02-17 16:38:06 -0800824 if (!context->isRawImageCallbackBufferAvailable()) {
Steve Block71f2cf12011-10-20 11:56:00 +0100825 ALOGV("Enable raw image notification, since no callback buffer exists");
James Donge00cab72011-02-17 16:38:06 -0800826 msgType &= ~CAMERA_MSG_RAW_IMAGE;
827 msgType |= CAMERA_MSG_RAW_IMAGE_NOTIFY;
828 }
829 }
830
831 if (camera->takePicture(msgType) != NO_ERROR) {
Elliott Hughes69a017b2011-04-08 14:10:28 -0700832 jniThrowRuntimeException(env, "takePicture failed");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800833 return;
834 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800835}
836
837static void android_hardware_Camera_setParameters(JNIEnv *env, jobject thiz, jstring params)
838{
Steve Block71f2cf12011-10-20 11:56:00 +0100839 ALOGV("setParameters");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800840 sp<Camera> camera = get_native_camera(env, thiz, NULL);
841 if (camera == 0) return;
842
843 const jchar* str = env->GetStringCritical(params, 0);
844 String8 params8;
845 if (params) {
Dan Albert66987492014-11-20 11:41:21 -0800846 params8 = String8(reinterpret_cast<const char16_t*>(str),
847 env->GetStringLength(params));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800848 env->ReleaseStringCritical(params, str);
849 }
850 if (camera->setParameters(params8) != NO_ERROR) {
Elliott Hughes69a017b2011-04-08 14:10:28 -0700851 jniThrowRuntimeException(env, "setParameters failed");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800852 return;
853 }
854}
855
856static jstring android_hardware_Camera_getParameters(JNIEnv *env, jobject thiz)
857{
Steve Block71f2cf12011-10-20 11:56:00 +0100858 ALOGV("getParameters");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800859 sp<Camera> camera = get_native_camera(env, thiz, NULL);
860 if (camera == 0) return 0;
861
Wu-cheng Lia1c41e12012-02-23 19:01:00 -0800862 String8 params8 = camera->getParameters();
863 if (params8.isEmpty()) {
864 jniThrowRuntimeException(env, "getParameters failed (empty parameters)");
865 return 0;
866 }
867 return env->NewStringUTF(params8.string());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800868}
869
870static void android_hardware_Camera_reconnect(JNIEnv *env, jobject thiz)
871{
Steve Block71f2cf12011-10-20 11:56:00 +0100872 ALOGV("reconnect");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800873 sp<Camera> camera = get_native_camera(env, thiz, NULL);
874 if (camera == 0) return;
875
876 if (camera->reconnect() != NO_ERROR) {
877 jniThrowException(env, "java/io/IOException", "reconnect failed");
878 return;
879 }
880}
881
Wu-cheng Liffe1cf22009-09-10 16:49:17 +0800882static void android_hardware_Camera_lock(JNIEnv *env, jobject thiz)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800883{
Steve Block71f2cf12011-10-20 11:56:00 +0100884 ALOGV("lock");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800885 sp<Camera> camera = get_native_camera(env, thiz, NULL);
Wu-cheng Liffe1cf22009-09-10 16:49:17 +0800886 if (camera == 0) return;
887
888 if (camera->lock() != NO_ERROR) {
Elliott Hughes69a017b2011-04-08 14:10:28 -0700889 jniThrowRuntimeException(env, "lock failed");
Wu-cheng Liffe1cf22009-09-10 16:49:17 +0800890 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800891}
892
Wu-cheng Liffe1cf22009-09-10 16:49:17 +0800893static void android_hardware_Camera_unlock(JNIEnv *env, jobject thiz)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800894{
Steve Block71f2cf12011-10-20 11:56:00 +0100895 ALOGV("unlock");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800896 sp<Camera> camera = get_native_camera(env, thiz, NULL);
Wu-cheng Liffe1cf22009-09-10 16:49:17 +0800897 if (camera == 0) return;
898
899 if (camera->unlock() != NO_ERROR) {
Elliott Hughes69a017b2011-04-08 14:10:28 -0700900 jniThrowRuntimeException(env, "unlock failed");
Wu-cheng Liffe1cf22009-09-10 16:49:17 +0800901 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800902}
903
Wu-cheng Li36f68b82009-09-28 16:14:58 -0700904static void android_hardware_Camera_startSmoothZoom(JNIEnv *env, jobject thiz, jint value)
905{
Steve Block71f2cf12011-10-20 11:56:00 +0100906 ALOGV("startSmoothZoom");
Wu-cheng Li36f68b82009-09-28 16:14:58 -0700907 sp<Camera> camera = get_native_camera(env, thiz, NULL);
908 if (camera == 0) return;
909
Wu-cheng Li0ca25192010-03-29 16:21:12 +0800910 status_t rc = camera->sendCommand(CAMERA_CMD_START_SMOOTH_ZOOM, value, 0);
911 if (rc == BAD_VALUE) {
912 char msg[64];
913 sprintf(msg, "invalid zoom value=%d", value);
914 jniThrowException(env, "java/lang/IllegalArgumentException", msg);
915 } else if (rc != NO_ERROR) {
Elliott Hughes69a017b2011-04-08 14:10:28 -0700916 jniThrowRuntimeException(env, "start smooth zoom failed");
Wu-cheng Li36f68b82009-09-28 16:14:58 -0700917 }
918}
919
920static void android_hardware_Camera_stopSmoothZoom(JNIEnv *env, jobject thiz)
921{
Steve Block71f2cf12011-10-20 11:56:00 +0100922 ALOGV("stopSmoothZoom");
Wu-cheng Li36f68b82009-09-28 16:14:58 -0700923 sp<Camera> camera = get_native_camera(env, thiz, NULL);
924 if (camera == 0) return;
925
926 if (camera->sendCommand(CAMERA_CMD_STOP_SMOOTH_ZOOM, 0, 0) != NO_ERROR) {
Elliott Hughes69a017b2011-04-08 14:10:28 -0700927 jniThrowRuntimeException(env, "stop smooth zoom failed");
Wu-cheng Li36f68b82009-09-28 16:14:58 -0700928 }
929}
930
Chih-Chung Changd1d77062010-01-22 17:49:48 -0800931static void android_hardware_Camera_setDisplayOrientation(JNIEnv *env, jobject thiz,
932 jint value)
933{
Steve Block71f2cf12011-10-20 11:56:00 +0100934 ALOGV("setDisplayOrientation");
Chih-Chung Changd1d77062010-01-22 17:49:48 -0800935 sp<Camera> camera = get_native_camera(env, thiz, NULL);
936 if (camera == 0) return;
937
938 if (camera->sendCommand(CAMERA_CMD_SET_DISPLAY_ORIENTATION, value, 0) != NO_ERROR) {
Elliott Hughes69a017b2011-04-08 14:10:28 -0700939 jniThrowRuntimeException(env, "set display orientation failed");
Chih-Chung Changd1d77062010-01-22 17:49:48 -0800940 }
941}
942
Eino-Ville Talvala69fe5272012-09-07 12:26:40 -0700943static jboolean android_hardware_Camera_enableShutterSound(JNIEnv *env, jobject thiz,
944 jboolean enabled)
945{
946 ALOGV("enableShutterSound");
947 sp<Camera> camera = get_native_camera(env, thiz, NULL);
948 if (camera == 0) return JNI_FALSE;
949
950 int32_t value = (enabled == JNI_TRUE) ? 1 : 0;
951 status_t rc = camera->sendCommand(CAMERA_CMD_ENABLE_SHUTTER_SOUND, value, 0);
952 if (rc == NO_ERROR) {
953 return JNI_TRUE;
954 } else if (rc == PERMISSION_DENIED) {
955 return JNI_FALSE;
956 } else {
957 jniThrowRuntimeException(env, "enable shutter sound failed");
958 return JNI_FALSE;
959 }
960}
961
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800962static void android_hardware_Camera_startFaceDetection(JNIEnv *env, jobject thiz,
Wu-cheng Libb1e2752011-07-30 05:00:37 +0800963 jint type)
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800964{
Steve Block71f2cf12011-10-20 11:56:00 +0100965 ALOGV("startFaceDetection");
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800966 JNICameraContext* context;
967 sp<Camera> camera = get_native_camera(env, thiz, &context);
968 if (camera == 0) return;
969
970 status_t rc = camera->sendCommand(CAMERA_CMD_START_FACE_DETECTION, type, 0);
971 if (rc == BAD_VALUE) {
972 char msg[64];
973 snprintf(msg, sizeof(msg), "invalid face detection type=%d", type);
974 jniThrowException(env, "java/lang/IllegalArgumentException", msg);
975 } else if (rc != NO_ERROR) {
976 jniThrowRuntimeException(env, "start face detection failed");
977 }
978}
979
980static void android_hardware_Camera_stopFaceDetection(JNIEnv *env, jobject thiz)
981{
Steve Block71f2cf12011-10-20 11:56:00 +0100982 ALOGV("stopFaceDetection");
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800983 sp<Camera> camera = get_native_camera(env, thiz, NULL);
984 if (camera == 0) return;
985
986 if (camera->sendCommand(CAMERA_CMD_STOP_FACE_DETECTION, 0, 0) != NO_ERROR) {
987 jniThrowRuntimeException(env, "stop face detection failed");
988 }
989}
990
Wu-cheng Li9d062cf2011-11-14 20:30:14 +0800991static void android_hardware_Camera_enableFocusMoveCallback(JNIEnv *env, jobject thiz, jint enable)
992{
Wu-cheng Li02097522011-11-30 11:06:04 +0800993 ALOGV("enableFocusMoveCallback");
Wu-cheng Li9d062cf2011-11-14 20:30:14 +0800994 sp<Camera> camera = get_native_camera(env, thiz, NULL);
995 if (camera == 0) return;
996
997 if (camera->sendCommand(CAMERA_CMD_ENABLE_FOCUS_MOVE_MSG, enable, 0) != NO_ERROR) {
998 jniThrowRuntimeException(env, "enable focus move callback failed");
999 }
1000}
1001
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001002//-------------------------------------------------
1003
Daniel Micay76f6a862015-09-19 17:31:01 -04001004static const JNINativeMethod camMethods[] = {
Chih-Chung Change25cc652010-05-06 16:36:58 +08001005 { "getNumberOfCameras",
1006 "()I",
1007 (void *)android_hardware_Camera_getNumberOfCameras },
Eino-Ville Talvala4f8e5ce2012-10-08 18:16:35 -07001008 { "_getCameraInfo",
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +08001009 "(ILandroid/hardware/Camera$CameraInfo;)V",
1010 (void*)android_hardware_Camera_getCameraInfo },
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001011 { "native_setup",
Zhijun He4c913802014-06-16 16:42:35 -07001012 "(Ljava/lang/Object;IILjava/lang/String;)I",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001013 (void*)android_hardware_Camera_native_setup },
1014 { "native_release",
1015 "()V",
1016 (void*)android_hardware_Camera_release },
Ruben Brunkfeb50af2014-05-09 19:58:49 -07001017 { "setPreviewSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001018 "(Landroid/view/Surface;)V",
Ruben Brunkfeb50af2014-05-09 19:58:49 -07001019 (void *)android_hardware_Camera_setPreviewSurface },
Jamie Gennisfd6f39e2010-12-20 12:15:00 -08001020 { "setPreviewTexture",
1021 "(Landroid/graphics/SurfaceTexture;)V",
1022 (void *)android_hardware_Camera_setPreviewTexture },
Eino-Ville Talvala7005b672013-04-02 15:46:38 -07001023 { "setPreviewCallbackSurface",
1024 "(Landroid/view/Surface;)V",
1025 (void *)android_hardware_Camera_setPreviewCallbackSurface },
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001026 { "startPreview",
1027 "()V",
1028 (void *)android_hardware_Camera_startPreview },
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001029 { "_stopPreview",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001030 "()V",
1031 (void *)android_hardware_Camera_stopPreview },
1032 { "previewEnabled",
1033 "()Z",
1034 (void *)android_hardware_Camera_previewEnabled },
1035 { "setHasPreviewCallback",
1036 "(ZZ)V",
1037 (void *)android_hardware_Camera_setHasPreviewCallback },
James Donge00cab72011-02-17 16:38:06 -08001038 { "_addCallbackBuffer",
1039 "([BI)V",
Andrew Harp94927df2009-10-20 01:47:05 -04001040 (void *)android_hardware_Camera_addCallbackBuffer },
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001041 { "native_autoFocus",
1042 "()V",
1043 (void *)android_hardware_Camera_autoFocus },
Chih-Chung Chang244f8c22009-09-15 14:51:56 +08001044 { "native_cancelAutoFocus",
1045 "()V",
1046 (void *)android_hardware_Camera_cancelAutoFocus },
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001047 { "native_takePicture",
James Donge00cab72011-02-17 16:38:06 -08001048 "(I)V",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001049 (void *)android_hardware_Camera_takePicture },
1050 { "native_setParameters",
1051 "(Ljava/lang/String;)V",
1052 (void *)android_hardware_Camera_setParameters },
1053 { "native_getParameters",
1054 "()Ljava/lang/String;",
1055 (void *)android_hardware_Camera_getParameters },
1056 { "reconnect",
1057 "()V",
1058 (void*)android_hardware_Camera_reconnect },
1059 { "lock",
Wu-cheng Liffe1cf22009-09-10 16:49:17 +08001060 "()V",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001061 (void*)android_hardware_Camera_lock },
1062 { "unlock",
Wu-cheng Liffe1cf22009-09-10 16:49:17 +08001063 "()V",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001064 (void*)android_hardware_Camera_unlock },
Wu-cheng Li36f68b82009-09-28 16:14:58 -07001065 { "startSmoothZoom",
1066 "(I)V",
1067 (void *)android_hardware_Camera_startSmoothZoom },
1068 { "stopSmoothZoom",
1069 "()V",
1070 (void *)android_hardware_Camera_stopSmoothZoom },
Chih-Chung Changd1d77062010-01-22 17:49:48 -08001071 { "setDisplayOrientation",
1072 "(I)V",
1073 (void *)android_hardware_Camera_setDisplayOrientation },
Eino-Ville Talvala4f8e5ce2012-10-08 18:16:35 -07001074 { "_enableShutterSound",
Eino-Ville Talvala69fe5272012-09-07 12:26:40 -07001075 "(Z)Z",
1076 (void *)android_hardware_Camera_enableShutterSound },
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001077 { "_startFaceDetection",
1078 "(I)V",
1079 (void *)android_hardware_Camera_startFaceDetection },
1080 { "_stopFaceDetection",
1081 "()V",
1082 (void *)android_hardware_Camera_stopFaceDetection},
Wu-cheng Li9d062cf2011-11-14 20:30:14 +08001083 { "enableFocusMoveCallback",
1084 "(I)V",
1085 (void *)android_hardware_Camera_enableFocusMoveCallback},
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001086};
1087
1088struct field {
1089 const char *class_name;
1090 const char *field_name;
1091 const char *field_type;
1092 jfieldID *jfield;
1093};
1094
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001095static void find_fields(JNIEnv *env, field *fields, int count)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001096{
1097 for (int i = 0; i < count; i++) {
1098 field *f = &fields[i];
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001099 jclass clazz = FindClassOrDie(env, f->class_name);
1100 jfieldID field = GetFieldIDOrDie(env, clazz, f->field_name, f->field_type);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001101 *(f->jfield) = field;
1102 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001103}
1104
1105// Get all the required offsets in java class and register native functions
1106int register_android_hardware_Camera(JNIEnv *env)
1107{
1108 field fields_to_find[] = {
Ashok Bhat4838e332014-01-03 14:37:19 +00001109 { "android/hardware/Camera", "mNativeContext", "J", &fields.context },
Wu-cheng Li3fd5fa42010-09-15 16:06:20 -07001110 { "android/hardware/Camera$CameraInfo", "facing", "I", &fields.facing },
1111 { "android/hardware/Camera$CameraInfo", "orientation", "I", &fields.orientation },
Eino-Ville Talvalaf7c6c5a2012-09-19 11:46:11 -07001112 { "android/hardware/Camera$CameraInfo", "canDisableShutterSound", "Z",
1113 &fields.canDisableShutterSound },
Wu-cheng Lif0d6a482011-07-28 05:30:59 +08001114 { "android/hardware/Camera$Face", "rect", "Landroid/graphics/Rect;", &fields.face_rect },
Igor Murashkin0601ab12014-09-18 15:17:20 -07001115 { "android/hardware/Camera$Face", "leftEye", "Landroid/graphics/Point;", &fields.face_left_eye},
1116 { "android/hardware/Camera$Face", "rightEye", "Landroid/graphics/Point;", &fields.face_right_eye},
1117 { "android/hardware/Camera$Face", "mouth", "Landroid/graphics/Point;", &fields.face_mouth},
Wu-cheng Lif0d6a482011-07-28 05:30:59 +08001118 { "android/hardware/Camera$Face", "score", "I", &fields.face_score },
Igor Murashkin0601ab12014-09-18 15:17:20 -07001119 { "android/hardware/Camera$Face", "id", "I", &fields.face_id},
Wu-cheng Li4c2292e2011-07-22 02:37:11 +08001120 { "android/graphics/Rect", "left", "I", &fields.rect_left },
1121 { "android/graphics/Rect", "top", "I", &fields.rect_top },
1122 { "android/graphics/Rect", "right", "I", &fields.rect_right },
1123 { "android/graphics/Rect", "bottom", "I", &fields.rect_bottom },
Igor Murashkin0601ab12014-09-18 15:17:20 -07001124 { "android/graphics/Point", "x", "I", &fields.point_x},
1125 { "android/graphics/Point", "y", "I", &fields.point_y},
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001126 };
1127
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001128 find_fields(env, fields_to_find, NELEM(fields_to_find));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001129
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001130 jclass clazz = FindClassOrDie(env, "android/hardware/Camera");
1131 fields.post_event = GetStaticMethodIDOrDie(env, clazz, "postEventFromNative",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001132 "(Ljava/lang/Object;IIILjava/lang/Object;)V");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001133
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001134 clazz = FindClassOrDie(env, "android/graphics/Rect");
1135 fields.rect_constructor = GetMethodIDOrDie(env, clazz, "<init>", "()V");
Wu-cheng Libb1e2752011-07-30 05:00:37 +08001136
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001137 clazz = FindClassOrDie(env, "android/hardware/Camera$Face");
1138 fields.face_constructor = GetMethodIDOrDie(env, clazz, "<init>", "()V");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001139
Igor Murashkin0601ab12014-09-18 15:17:20 -07001140 clazz = env->FindClass("android/graphics/Point");
1141 fields.point_constructor = env->GetMethodID(clazz, "<init>", "()V");
1142 if (fields.point_constructor == NULL) {
1143 ALOGE("Can't find android/graphics/Point()");
1144 return -1;
1145 }
1146
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001147 // Register native functions
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001148 return RegisterMethodsOrDie(env, "android/hardware/Camera", camMethods, NELEM(camMethods));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001149}