The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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" |
| 24 | #include "android_runtime/AndroidRuntime.h" |
| 25 | |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 26 | #include <utils/Vector.h> |
| 27 | |
Jamie Gennis | fd6f39e | 2010-12-20 12:15:00 -0800 | [diff] [blame] | 28 | #include <gui/SurfaceTexture.h> |
Mathias Agopian | 000479f | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 29 | #include <surfaceflinger/Surface.h> |
| 30 | #include <camera/Camera.h> |
Mathias Agopian | 0795272 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 31 | #include <binder/IMemory.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | |
| 33 | using namespace android; |
| 34 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | struct fields_t { |
| 36 | jfieldID context; |
| 37 | jfieldID surface; |
Jamie Gennis | fd6f39e | 2010-12-20 12:15:00 -0800 | [diff] [blame] | 38 | jfieldID surfaceTexture; |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 39 | jfieldID facing; |
| 40 | jfieldID orientation; |
Wu-cheng Li | f0d6a48 | 2011-07-28 05:30:59 +0800 | [diff] [blame] | 41 | jfieldID face_rect; |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 42 | jfieldID face_score; |
| 43 | jfieldID rect_left; |
| 44 | jfieldID rect_top; |
| 45 | jfieldID rect_right; |
| 46 | jfieldID rect_bottom; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | jmethodID post_event; |
Wu-cheng Li | bb1e275 | 2011-07-30 05:00:37 +0800 | [diff] [blame^] | 48 | jmethodID rect_constructor; |
| 49 | jmethodID face_constructor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | static fields_t fields; |
| 53 | static Mutex sLock; |
| 54 | |
Dave Sparks | 5e27115 | 2009-06-23 17:30:11 -0700 | [diff] [blame] | 55 | // provides persistent context for calls from native code to Java |
| 56 | class JNICameraContext: public CameraListener |
| 57 | { |
| 58 | public: |
| 59 | JNICameraContext(JNIEnv* env, jobject weak_this, jclass clazz, const sp<Camera>& camera); |
| 60 | ~JNICameraContext() { release(); } |
| 61 | virtual void notify(int32_t msgType, int32_t ext1, int32_t ext2); |
Wu-cheng Li | bb1e275 | 2011-07-30 05:00:37 +0800 | [diff] [blame^] | 62 | virtual void postData(int32_t msgType, const sp<IMemory>& dataPtr, |
| 63 | camera_frame_metadata_t *metadata); |
Dave Sparks | 59c1a93 | 2009-07-08 15:56:53 -0700 | [diff] [blame] | 64 | virtual void postDataTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr); |
Wu-cheng Li | bb1e275 | 2011-07-30 05:00:37 +0800 | [diff] [blame^] | 65 | void postMetadata(JNIEnv *env, int32_t msgType, camera_frame_metadata_t *metadata); |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 66 | void addCallbackBuffer(JNIEnv *env, jbyteArray cbb, int msgType); |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 67 | void setCallbackMode(JNIEnv *env, bool installed, bool manualMode); |
Dave Sparks | 5e27115 | 2009-06-23 17:30:11 -0700 | [diff] [blame] | 68 | sp<Camera> getCamera() { Mutex::Autolock _l(mLock); return mCamera; } |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 69 | bool isRawImageCallbackBufferAvailable() const; |
Dave Sparks | 5e27115 | 2009-06-23 17:30:11 -0700 | [diff] [blame] | 70 | void release(); |
| 71 | |
| 72 | private: |
| 73 | void copyAndPost(JNIEnv* env, const sp<IMemory>& dataPtr, int msgType); |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 74 | void clearCallbackBuffers_l(JNIEnv *env, Vector<jbyteArray> *buffers); |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 75 | void clearCallbackBuffers_l(JNIEnv *env); |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 76 | jbyteArray getCallbackBuffer(JNIEnv *env, Vector<jbyteArray> *buffers, size_t bufferSize); |
Dave Sparks | 5e27115 | 2009-06-23 17:30:11 -0700 | [diff] [blame] | 77 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 78 | jobject mCameraJObjectWeak; // weak reference to java object |
| 79 | jclass mCameraJClass; // strong reference to java class |
Wu-cheng Li | ffe1cf2 | 2009-09-10 16:49:17 +0800 | [diff] [blame] | 80 | sp<Camera> mCamera; // strong reference to native object |
Wu-cheng Li | bb1e275 | 2011-07-30 05:00:37 +0800 | [diff] [blame^] | 81 | jclass mFaceClass; // strong reference to Face class |
| 82 | jclass mRectClass; // strong reference to Rect class |
Dave Sparks | 5e27115 | 2009-06-23 17:30:11 -0700 | [diff] [blame] | 83 | Mutex mLock; |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 84 | |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 85 | /* |
| 86 | * Global reference application-managed raw image buffer queue. |
| 87 | * |
| 88 | * Manual-only mode is supported for raw image callbacks, which is |
| 89 | * set whenever method addCallbackBuffer() with msgType = |
| 90 | * CAMERA_MSG_RAW_IMAGE is called; otherwise, null is returned |
| 91 | * with raw image callbacks. |
| 92 | */ |
| 93 | Vector<jbyteArray> mRawImageCallbackBuffers; |
| 94 | |
| 95 | /* |
| 96 | * Application-managed preview buffer queue and the flags |
| 97 | * associated with the usage of the preview buffer callback. |
| 98 | */ |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 99 | Vector<jbyteArray> mCallbackBuffers; // Global reference application managed byte[] |
| 100 | bool mManualBufferMode; // Whether to use application managed buffers. |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 101 | bool mManualCameraCallbackSet; // Whether the callback has been set, used to |
| 102 | // reduce unnecessary calls to set the callback. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 103 | }; |
| 104 | |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 105 | bool JNICameraContext::isRawImageCallbackBufferAvailable() const |
| 106 | { |
| 107 | return !mRawImageCallbackBuffers.isEmpty(); |
| 108 | } |
| 109 | |
Dave Sparks | 5e27115 | 2009-06-23 17:30:11 -0700 | [diff] [blame] | 110 | sp<Camera> get_native_camera(JNIEnv *env, jobject thiz, JNICameraContext** pContext) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 111 | { |
| 112 | sp<Camera> camera; |
| 113 | Mutex::Autolock _l(sLock); |
Dave Sparks | 5e27115 | 2009-06-23 17:30:11 -0700 | [diff] [blame] | 114 | JNICameraContext* context = reinterpret_cast<JNICameraContext*>(env->GetIntField(thiz, fields.context)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 | if (context != NULL) { |
Dave Sparks | 5e27115 | 2009-06-23 17:30:11 -0700 | [diff] [blame] | 116 | camera = context->getCamera(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 117 | } |
| 118 | LOGV("get_native_camera: context=%p, camera=%p", context, camera.get()); |
| 119 | if (camera == 0) { |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 120 | jniThrowRuntimeException(env, "Method called after release()"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | if (pContext != NULL) *pContext = context; |
| 124 | return camera; |
| 125 | } |
| 126 | |
Dave Sparks | 5e27115 | 2009-06-23 17:30:11 -0700 | [diff] [blame] | 127 | JNICameraContext::JNICameraContext(JNIEnv* env, jobject weak_this, jclass clazz, const sp<Camera>& camera) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 128 | { |
Dave Sparks | 5e27115 | 2009-06-23 17:30:11 -0700 | [diff] [blame] | 129 | mCameraJObjectWeak = env->NewGlobalRef(weak_this); |
| 130 | mCameraJClass = (jclass)env->NewGlobalRef(clazz); |
| 131 | mCamera = camera; |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 132 | |
Wu-cheng Li | bb1e275 | 2011-07-30 05:00:37 +0800 | [diff] [blame^] | 133 | jclass faceClazz = env->FindClass("android/hardware/Camera$Face"); |
| 134 | mFaceClass = (jclass) env->NewGlobalRef(faceClazz); |
| 135 | |
| 136 | jclass rectClazz = env->FindClass("android/graphics/Rect"); |
| 137 | mRectClass = (jclass) env->NewGlobalRef(rectClazz); |
| 138 | |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 139 | mManualBufferMode = false; |
| 140 | mManualCameraCallbackSet = false; |
Dave Sparks | 5e27115 | 2009-06-23 17:30:11 -0700 | [diff] [blame] | 141 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 142 | |
Dave Sparks | 5e27115 | 2009-06-23 17:30:11 -0700 | [diff] [blame] | 143 | void JNICameraContext::release() |
| 144 | { |
| 145 | LOGV("release"); |
| 146 | Mutex::Autolock _l(mLock); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 147 | JNIEnv *env = AndroidRuntime::getJNIEnv(); |
Dave Sparks | 5e27115 | 2009-06-23 17:30:11 -0700 | [diff] [blame] | 148 | |
| 149 | if (mCameraJObjectWeak != NULL) { |
| 150 | env->DeleteGlobalRef(mCameraJObjectWeak); |
| 151 | mCameraJObjectWeak = NULL; |
| 152 | } |
| 153 | if (mCameraJClass != NULL) { |
| 154 | env->DeleteGlobalRef(mCameraJClass); |
| 155 | mCameraJClass = NULL; |
| 156 | } |
Wu-cheng Li | bb1e275 | 2011-07-30 05:00:37 +0800 | [diff] [blame^] | 157 | if (mFaceClass != NULL) { |
| 158 | env->DeleteGlobalRef(mFaceClass); |
| 159 | mFaceClass = NULL; |
| 160 | } |
| 161 | if (mRectClass != NULL) { |
| 162 | env->DeleteGlobalRef(mRectClass); |
| 163 | mRectClass = NULL; |
| 164 | } |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 165 | clearCallbackBuffers_l(env); |
Dave Sparks | 5e27115 | 2009-06-23 17:30:11 -0700 | [diff] [blame] | 166 | mCamera.clear(); |
| 167 | } |
| 168 | |
| 169 | void JNICameraContext::notify(int32_t msgType, int32_t ext1, int32_t ext2) |
| 170 | { |
| 171 | LOGV("notify"); |
| 172 | |
| 173 | // VM pointer will be NULL if object is released |
| 174 | Mutex::Autolock _l(mLock); |
| 175 | if (mCameraJObjectWeak == NULL) { |
| 176 | LOGW("callback on dead camera object"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 177 | return; |
| 178 | } |
Dave Sparks | 5e27115 | 2009-06-23 17:30:11 -0700 | [diff] [blame] | 179 | JNIEnv *env = AndroidRuntime::getJNIEnv(); |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 180 | |
| 181 | /* |
| 182 | * If the notification or msgType is CAMERA_MSG_RAW_IMAGE_NOTIFY, change it |
| 183 | * to CAMERA_MSG_RAW_IMAGE since CAMERA_MSG_RAW_IMAGE_NOTIFY is not exposed |
| 184 | * to the Java app. |
| 185 | */ |
| 186 | if (msgType == CAMERA_MSG_RAW_IMAGE_NOTIFY) { |
| 187 | msgType = CAMERA_MSG_RAW_IMAGE; |
| 188 | } |
| 189 | |
Dave Sparks | c62f9bd | 2009-06-26 13:33:32 -0700 | [diff] [blame] | 190 | env->CallStaticVoidMethod(mCameraJClass, fields.post_event, |
Chih-Chung Chang | 6157de0 | 2009-09-24 15:29:35 -0700 | [diff] [blame] | 191 | mCameraJObjectWeak, msgType, ext1, ext2, NULL); |
Dave Sparks | 5e27115 | 2009-06-23 17:30:11 -0700 | [diff] [blame] | 192 | } |
| 193 | |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 194 | jbyteArray JNICameraContext::getCallbackBuffer( |
| 195 | JNIEnv* env, Vector<jbyteArray>* buffers, size_t bufferSize) |
| 196 | { |
| 197 | jbyteArray obj = NULL; |
| 198 | |
| 199 | // Vector access should be protected by lock in postData() |
| 200 | if (!buffers->isEmpty()) { |
| 201 | LOGV("Using callback buffer from queue of length %d", buffers->size()); |
| 202 | jbyteArray globalBuffer = buffers->itemAt(0); |
| 203 | buffers->removeAt(0); |
| 204 | |
| 205 | obj = (jbyteArray)env->NewLocalRef(globalBuffer); |
| 206 | env->DeleteGlobalRef(globalBuffer); |
| 207 | |
| 208 | if (obj != NULL) { |
| 209 | jsize bufferLength = env->GetArrayLength(obj); |
| 210 | if ((int)bufferLength < (int)bufferSize) { |
| 211 | LOGE("Callback buffer was too small! Expected %d bytes, but got %d bytes!", |
| 212 | bufferSize, bufferLength); |
| 213 | env->DeleteLocalRef(obj); |
| 214 | return NULL; |
| 215 | } |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | return obj; |
| 220 | } |
| 221 | |
Dave Sparks | 5e27115 | 2009-06-23 17:30:11 -0700 | [diff] [blame] | 222 | void JNICameraContext::copyAndPost(JNIEnv* env, const sp<IMemory>& dataPtr, int msgType) |
| 223 | { |
| 224 | jbyteArray obj = NULL; |
| 225 | |
| 226 | // allocate Java byte array and copy data |
| 227 | if (dataPtr != NULL) { |
| 228 | ssize_t offset; |
| 229 | size_t size; |
| 230 | sp<IMemoryHeap> heap = dataPtr->getMemory(&offset, &size); |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 231 | LOGV("copyAndPost: off=%ld, size=%d", offset, size); |
Dave Sparks | 5e27115 | 2009-06-23 17:30:11 -0700 | [diff] [blame] | 232 | uint8_t *heapBase = (uint8_t*)heap->base(); |
| 233 | |
| 234 | if (heapBase != NULL) { |
Dave Sparks | c4ca420 | 2009-07-13 09:38:20 -0700 | [diff] [blame] | 235 | const jbyte* data = reinterpret_cast<const jbyte*>(heapBase + offset); |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 236 | |
| 237 | if (!mManualBufferMode) { |
| 238 | LOGV("Allocating callback buffer"); |
| 239 | obj = env->NewByteArray(size); |
| 240 | } else { |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 241 | switch (msgType) { |
| 242 | case CAMERA_MSG_PREVIEW_FRAME: { |
| 243 | obj = getCallbackBuffer(env, &mCallbackBuffers, size); |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 244 | |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 245 | if (mCallbackBuffers.isEmpty()) { |
| 246 | LOGV("Out of buffers, clearing callback!"); |
Iliyan Malchev | 9c7ac0d | 2011-04-14 16:51:21 -0700 | [diff] [blame] | 247 | mCamera->setPreviewCallbackFlags(CAMERA_FRAME_CALLBACK_FLAG_NOOP); |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 248 | mManualCameraCallbackSet = false; |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 249 | |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 250 | if (obj == NULL) { |
| 251 | return; |
| 252 | } |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 253 | } |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 254 | break; |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 255 | } |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 256 | case CAMERA_MSG_RAW_IMAGE: { |
| 257 | obj = getCallbackBuffer(env, &mRawImageCallbackBuffers, size); |
| 258 | break; |
| 259 | } |
| 260 | default: { |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 261 | jniThrowRuntimeException(env, "Unsupported message type"); |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 262 | return; |
| 263 | } |
| 264 | } |
| 265 | } |
| 266 | |
Dave Sparks | 5e27115 | 2009-06-23 17:30:11 -0700 | [diff] [blame] | 267 | if (obj == NULL) { |
| 268 | LOGE("Couldn't allocate byte array for JPEG data"); |
| 269 | env->ExceptionClear(); |
| 270 | } else { |
Dave Sparks | a95f495 | 2009-07-10 18:13:36 -0700 | [diff] [blame] | 271 | env->SetByteArrayRegion(obj, 0, size, data); |
Dave Sparks | 5e27115 | 2009-06-23 17:30:11 -0700 | [diff] [blame] | 272 | } |
| 273 | } else { |
| 274 | LOGE("image heap is NULL"); |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | // post image data to Java |
| 279 | env->CallStaticVoidMethod(mCameraJClass, fields.post_event, |
| 280 | mCameraJObjectWeak, msgType, 0, 0, obj); |
| 281 | if (obj) { |
| 282 | env->DeleteLocalRef(obj); |
| 283 | } |
| 284 | } |
| 285 | |
Wu-cheng Li | bb1e275 | 2011-07-30 05:00:37 +0800 | [diff] [blame^] | 286 | void JNICameraContext::postData(int32_t msgType, const sp<IMemory>& dataPtr, |
| 287 | camera_frame_metadata_t *metadata) |
Dave Sparks | 5e27115 | 2009-06-23 17:30:11 -0700 | [diff] [blame] | 288 | { |
| 289 | // VM pointer will be NULL if object is released |
| 290 | Mutex::Autolock _l(mLock); |
| 291 | JNIEnv *env = AndroidRuntime::getJNIEnv(); |
Dave Sparks | d0cbb1a | 2009-06-29 19:03:33 -0700 | [diff] [blame] | 292 | if (mCameraJObjectWeak == NULL) { |
| 293 | LOGW("callback on dead camera object"); |
| 294 | return; |
| 295 | } |
Dave Sparks | 5e27115 | 2009-06-23 17:30:11 -0700 | [diff] [blame] | 296 | |
Wu-cheng Li | bb1e275 | 2011-07-30 05:00:37 +0800 | [diff] [blame^] | 297 | int32_t dataMsgType = msgType & ~CAMERA_MSG_PREVIEW_METADATA; |
| 298 | |
Dave Sparks | 5e27115 | 2009-06-23 17:30:11 -0700 | [diff] [blame] | 299 | // return data based on callback type |
Wu-cheng Li | bb1e275 | 2011-07-30 05:00:37 +0800 | [diff] [blame^] | 300 | switch (dataMsgType) { |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 301 | case CAMERA_MSG_VIDEO_FRAME: |
| 302 | // should never happen |
| 303 | break; |
| 304 | |
| 305 | // For backward-compatibility purpose, if there is no callback |
| 306 | // buffer for raw image, the callback returns null. |
| 307 | case CAMERA_MSG_RAW_IMAGE: |
| 308 | LOGV("rawCallback"); |
| 309 | if (mRawImageCallbackBuffers.isEmpty()) { |
| 310 | env->CallStaticVoidMethod(mCameraJClass, fields.post_event, |
Wu-cheng Li | bb1e275 | 2011-07-30 05:00:37 +0800 | [diff] [blame^] | 311 | mCameraJObjectWeak, dataMsgType, 0, 0, NULL); |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 312 | } else { |
Wu-cheng Li | bb1e275 | 2011-07-30 05:00:37 +0800 | [diff] [blame^] | 313 | copyAndPost(env, dataPtr, dataMsgType); |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 314 | } |
| 315 | break; |
| 316 | |
Wu-cheng Li | bb1e275 | 2011-07-30 05:00:37 +0800 | [diff] [blame^] | 317 | // There is no data. |
| 318 | case 0: |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 319 | break; |
Wu-cheng Li | bb1e275 | 2011-07-30 05:00:37 +0800 | [diff] [blame^] | 320 | |
| 321 | default: |
| 322 | LOGV("dataCallback(%d, %p)", dataMsgType, dataPtr.get()); |
| 323 | copyAndPost(env, dataPtr, dataMsgType); |
| 324 | break; |
| 325 | } |
| 326 | |
| 327 | // post frame metadata to Java |
| 328 | if (metadata && (msgType & CAMERA_MSG_PREVIEW_METADATA)) { |
| 329 | postMetadata(env, CAMERA_MSG_PREVIEW_METADATA, metadata); |
Dave Sparks | 5e27115 | 2009-06-23 17:30:11 -0700 | [diff] [blame] | 330 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 331 | } |
| 332 | |
Dave Sparks | 59c1a93 | 2009-07-08 15:56:53 -0700 | [diff] [blame] | 333 | void JNICameraContext::postDataTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr) |
| 334 | { |
| 335 | // TODO: plumb up to Java. For now, just drop the timestamp |
Wu-cheng Li | bb1e275 | 2011-07-30 05:00:37 +0800 | [diff] [blame^] | 336 | postData(msgType, dataPtr, NULL); |
| 337 | } |
| 338 | |
| 339 | void JNICameraContext::postMetadata(JNIEnv *env, int32_t msgType, camera_frame_metadata_t *metadata) |
| 340 | { |
| 341 | jobjectArray obj = NULL; |
| 342 | obj = (jobjectArray) env->NewObjectArray(metadata->number_of_faces, |
| 343 | mFaceClass, NULL); |
| 344 | if (obj == NULL) { |
| 345 | LOGE("Couldn't allocate face metadata array"); |
| 346 | return; |
| 347 | } |
| 348 | |
| 349 | for (int i = 0; i < metadata->number_of_faces; i++) { |
| 350 | jobject face = env->NewObject(mFaceClass, fields.face_constructor); |
| 351 | env->SetObjectArrayElement(obj, i, face); |
| 352 | |
| 353 | jobject rect = env->NewObject(mRectClass, fields.rect_constructor); |
| 354 | env->SetIntField(rect, fields.rect_left, metadata->faces[i].rect[0]); |
| 355 | env->SetIntField(rect, fields.rect_top, metadata->faces[i].rect[1]); |
| 356 | env->SetIntField(rect, fields.rect_right, metadata->faces[i].rect[2]); |
| 357 | env->SetIntField(rect, fields.rect_bottom, metadata->faces[i].rect[3]); |
| 358 | |
| 359 | env->SetObjectField(face, fields.face_rect, rect); |
| 360 | env->SetIntField(face, fields.face_score, metadata->faces[i].score); |
| 361 | |
| 362 | env->DeleteLocalRef(face); |
| 363 | env->DeleteLocalRef(rect); |
| 364 | } |
| 365 | env->CallStaticVoidMethod(mCameraJClass, fields.post_event, |
| 366 | mCameraJObjectWeak, msgType, 0, 0, obj); |
| 367 | env->DeleteLocalRef(obj); |
Dave Sparks | 59c1a93 | 2009-07-08 15:56:53 -0700 | [diff] [blame] | 368 | } |
| 369 | |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 370 | void JNICameraContext::setCallbackMode(JNIEnv *env, bool installed, bool manualMode) |
| 371 | { |
| 372 | Mutex::Autolock _l(mLock); |
| 373 | mManualBufferMode = manualMode; |
| 374 | mManualCameraCallbackSet = false; |
| 375 | |
| 376 | // In order to limit the over usage of binder threads, all non-manual buffer |
Iliyan Malchev | 9c7ac0d | 2011-04-14 16:51:21 -0700 | [diff] [blame] | 377 | // callbacks use CAMERA_FRAME_CALLBACK_FLAG_BARCODE_SCANNER mode now. |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 378 | // |
| 379 | // Continuous callbacks will have the callback re-registered from handleMessage. |
| 380 | // Manual buffer mode will operate as fast as possible, relying on the finite supply |
| 381 | // of buffers for throttling. |
| 382 | |
| 383 | if (!installed) { |
Iliyan Malchev | 9c7ac0d | 2011-04-14 16:51:21 -0700 | [diff] [blame] | 384 | mCamera->setPreviewCallbackFlags(CAMERA_FRAME_CALLBACK_FLAG_NOOP); |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 385 | clearCallbackBuffers_l(env, &mCallbackBuffers); |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 386 | } else if (mManualBufferMode) { |
| 387 | if (!mCallbackBuffers.isEmpty()) { |
Iliyan Malchev | 9c7ac0d | 2011-04-14 16:51:21 -0700 | [diff] [blame] | 388 | mCamera->setPreviewCallbackFlags(CAMERA_FRAME_CALLBACK_FLAG_CAMERA); |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 389 | mManualCameraCallbackSet = true; |
| 390 | } |
| 391 | } else { |
Iliyan Malchev | 9c7ac0d | 2011-04-14 16:51:21 -0700 | [diff] [blame] | 392 | mCamera->setPreviewCallbackFlags(CAMERA_FRAME_CALLBACK_FLAG_BARCODE_SCANNER); |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 393 | clearCallbackBuffers_l(env, &mCallbackBuffers); |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 394 | } |
| 395 | } |
| 396 | |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 397 | void JNICameraContext::addCallbackBuffer( |
| 398 | JNIEnv *env, jbyteArray cbb, int msgType) |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 399 | { |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 400 | LOGV("addCallbackBuffer: 0x%x", msgType); |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 401 | if (cbb != NULL) { |
| 402 | Mutex::Autolock _l(mLock); |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 403 | switch (msgType) { |
| 404 | case CAMERA_MSG_PREVIEW_FRAME: { |
| 405 | jbyteArray callbackBuffer = (jbyteArray)env->NewGlobalRef(cbb); |
| 406 | mCallbackBuffers.push(callbackBuffer); |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 407 | |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 408 | LOGV("Adding callback buffer to queue, %d total", |
| 409 | mCallbackBuffers.size()); |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 410 | |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 411 | // We want to make sure the camera knows we're ready for the |
| 412 | // next frame. This may have come unset had we not had a |
| 413 | // callbackbuffer ready for it last time. |
| 414 | if (mManualBufferMode && !mManualCameraCallbackSet) { |
Iliyan Malchev | 9c7ac0d | 2011-04-14 16:51:21 -0700 | [diff] [blame] | 415 | mCamera->setPreviewCallbackFlags(CAMERA_FRAME_CALLBACK_FLAG_CAMERA); |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 416 | mManualCameraCallbackSet = true; |
| 417 | } |
| 418 | break; |
| 419 | } |
| 420 | case CAMERA_MSG_RAW_IMAGE: { |
| 421 | jbyteArray callbackBuffer = (jbyteArray)env->NewGlobalRef(cbb); |
| 422 | mRawImageCallbackBuffers.push(callbackBuffer); |
| 423 | break; |
| 424 | } |
| 425 | default: { |
| 426 | jniThrowException(env, |
| 427 | "java/lang/IllegalArgumentException", |
| 428 | "Unsupported message type"); |
| 429 | return; |
| 430 | } |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 431 | } |
| 432 | } else { |
| 433 | LOGE("Null byte array!"); |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | void JNICameraContext::clearCallbackBuffers_l(JNIEnv *env) |
| 438 | { |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 439 | clearCallbackBuffers_l(env, &mCallbackBuffers); |
| 440 | clearCallbackBuffers_l(env, &mRawImageCallbackBuffers); |
| 441 | } |
| 442 | |
| 443 | void JNICameraContext::clearCallbackBuffers_l(JNIEnv *env, Vector<jbyteArray> *buffers) { |
| 444 | LOGV("Clearing callback buffers, %d remained", buffers->size()); |
| 445 | while (!buffers->isEmpty()) { |
| 446 | env->DeleteGlobalRef(buffers->top()); |
| 447 | buffers->pop(); |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 448 | } |
| 449 | } |
| 450 | |
Chih-Chung Chang | e25cc65 | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 451 | static jint android_hardware_Camera_getNumberOfCameras(JNIEnv *env, jobject thiz) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 452 | { |
Chih-Chung Chang | e25cc65 | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 453 | return Camera::getNumberOfCameras(); |
| 454 | } |
| 455 | |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 456 | static void android_hardware_Camera_getCameraInfo(JNIEnv *env, jobject thiz, |
| 457 | jint cameraId, jobject info_obj) |
| 458 | { |
| 459 | CameraInfo cameraInfo; |
| 460 | status_t rc = Camera::getCameraInfo(cameraId, &cameraInfo); |
| 461 | if (rc != NO_ERROR) { |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 462 | jniThrowRuntimeException(env, "Fail to get camera info"); |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 463 | return; |
| 464 | } |
| 465 | env->SetIntField(info_obj, fields.facing, cameraInfo.facing); |
| 466 | env->SetIntField(info_obj, fields.orientation, cameraInfo.orientation); |
| 467 | } |
| 468 | |
Chih-Chung Chang | e25cc65 | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 469 | // connect to camera service |
| 470 | static void android_hardware_Camera_native_setup(JNIEnv *env, jobject thiz, |
| 471 | jobject weak_this, jint cameraId) |
| 472 | { |
| 473 | sp<Camera> camera = Camera::connect(cameraId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 474 | |
| 475 | if (camera == NULL) { |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 476 | jniThrowRuntimeException(env, "Fail to connect to camera service"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 477 | return; |
| 478 | } |
| 479 | |
| 480 | // make sure camera hardware is alive |
| 481 | if (camera->getStatus() != NO_ERROR) { |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 482 | jniThrowRuntimeException(env, "Camera initialization failed"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 483 | return; |
| 484 | } |
| 485 | |
| 486 | jclass clazz = env->GetObjectClass(thiz); |
| 487 | if (clazz == NULL) { |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 488 | jniThrowRuntimeException(env, "Can't find android/hardware/Camera"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 489 | return; |
| 490 | } |
| 491 | |
| 492 | // We use a weak reference so the Camera object can be garbage collected. |
| 493 | // The reference is only used as a proxy for callbacks. |
Dave Sparks | 5e27115 | 2009-06-23 17:30:11 -0700 | [diff] [blame] | 494 | sp<JNICameraContext> context = new JNICameraContext(env, weak_this, clazz, camera); |
| 495 | context->incStrong(thiz); |
| 496 | camera->setListener(context); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 497 | |
| 498 | // save context in opaque field |
Dave Sparks | 5e27115 | 2009-06-23 17:30:11 -0700 | [diff] [blame] | 499 | env->SetIntField(thiz, fields.context, (int)context.get()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | // disconnect from camera service |
| 503 | // It's okay to call this when the native camera context is already null. |
| 504 | // This handles the case where the user has called release() and the |
| 505 | // finalizer is invoked later. |
| 506 | static void android_hardware_Camera_release(JNIEnv *env, jobject thiz) |
| 507 | { |
Dave Sparks | da57856 | 2009-07-21 08:43:29 -0700 | [diff] [blame] | 508 | // TODO: Change to LOGV |
Joe Onorato | f5d95cb | 2010-01-07 21:48:32 -0500 | [diff] [blame] | 509 | LOGV("release camera"); |
Dave Sparks | 5e27115 | 2009-06-23 17:30:11 -0700 | [diff] [blame] | 510 | JNICameraContext* context = NULL; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 511 | sp<Camera> camera; |
| 512 | { |
| 513 | Mutex::Autolock _l(sLock); |
Dave Sparks | 5e27115 | 2009-06-23 17:30:11 -0700 | [diff] [blame] | 514 | context = reinterpret_cast<JNICameraContext*>(env->GetIntField(thiz, fields.context)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 515 | |
| 516 | // Make sure we do not attempt to callback on a deleted Java object. |
| 517 | env->SetIntField(thiz, fields.context, 0); |
| 518 | } |
| 519 | |
| 520 | // clean up if release has not been called before |
| 521 | if (context != NULL) { |
Dave Sparks | 5e27115 | 2009-06-23 17:30:11 -0700 | [diff] [blame] | 522 | camera = context->getCamera(); |
| 523 | context->release(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 524 | LOGV("native_release: context=%p camera=%p", context, camera.get()); |
| 525 | |
| 526 | // clear callbacks |
| 527 | if (camera != NULL) { |
Iliyan Malchev | 9c7ac0d | 2011-04-14 16:51:21 -0700 | [diff] [blame] | 528 | camera->setPreviewCallbackFlags(CAMERA_FRAME_CALLBACK_FLAG_NOOP); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 529 | camera->disconnect(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | // remove context to prevent further Java access |
Dave Sparks | 5e27115 | 2009-06-23 17:30:11 -0700 | [diff] [blame] | 533 | context->decStrong(thiz); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 534 | } |
| 535 | } |
| 536 | |
| 537 | static void android_hardware_Camera_setPreviewDisplay(JNIEnv *env, jobject thiz, jobject jSurface) |
| 538 | { |
| 539 | LOGV("setPreviewDisplay"); |
| 540 | sp<Camera> camera = get_native_camera(env, thiz, NULL); |
| 541 | if (camera == 0) return; |
| 542 | |
Wu-cheng Li | b8a10fe | 2009-06-23 23:37:36 +0800 | [diff] [blame] | 543 | sp<Surface> surface = NULL; |
| 544 | if (jSurface != NULL) { |
| 545 | surface = reinterpret_cast<Surface*>(env->GetIntField(jSurface, fields.surface)); |
| 546 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 547 | if (camera->setPreviewDisplay(surface) != NO_ERROR) { |
| 548 | jniThrowException(env, "java/io/IOException", "setPreviewDisplay failed"); |
| 549 | } |
| 550 | } |
| 551 | |
Jamie Gennis | fd6f39e | 2010-12-20 12:15:00 -0800 | [diff] [blame] | 552 | static void android_hardware_Camera_setPreviewTexture(JNIEnv *env, |
| 553 | jobject thiz, jobject jSurfaceTexture) |
| 554 | { |
| 555 | LOGV("setPreviewTexture"); |
| 556 | sp<Camera> camera = get_native_camera(env, thiz, NULL); |
| 557 | if (camera == 0) return; |
| 558 | |
| 559 | sp<SurfaceTexture> surfaceTexture = NULL; |
| 560 | if (jSurfaceTexture != NULL) { |
| 561 | surfaceTexture = reinterpret_cast<SurfaceTexture*>(env->GetIntField( |
| 562 | jSurfaceTexture, fields.surfaceTexture)); |
| 563 | } |
| 564 | if (camera->setPreviewTexture(surfaceTexture) != NO_ERROR) { |
| 565 | jniThrowException(env, "java/io/IOException", |
| 566 | "setPreviewTexture failed"); |
| 567 | } |
| 568 | } |
| 569 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 570 | static void android_hardware_Camera_startPreview(JNIEnv *env, jobject thiz) |
| 571 | { |
| 572 | LOGV("startPreview"); |
| 573 | sp<Camera> camera = get_native_camera(env, thiz, NULL); |
| 574 | if (camera == 0) return; |
| 575 | |
| 576 | if (camera->startPreview() != NO_ERROR) { |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 577 | jniThrowRuntimeException(env, "startPreview failed"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 578 | return; |
| 579 | } |
| 580 | } |
| 581 | |
| 582 | static void android_hardware_Camera_stopPreview(JNIEnv *env, jobject thiz) |
| 583 | { |
| 584 | LOGV("stopPreview"); |
| 585 | sp<Camera> c = get_native_camera(env, thiz, NULL); |
| 586 | if (c == 0) return; |
| 587 | |
| 588 | c->stopPreview(); |
| 589 | } |
| 590 | |
| 591 | static bool android_hardware_Camera_previewEnabled(JNIEnv *env, jobject thiz) |
| 592 | { |
| 593 | LOGV("previewEnabled"); |
| 594 | sp<Camera> c = get_native_camera(env, thiz, NULL); |
| 595 | if (c == 0) return false; |
| 596 | |
| 597 | return c->previewEnabled(); |
| 598 | } |
| 599 | |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 600 | static void android_hardware_Camera_setHasPreviewCallback(JNIEnv *env, jobject thiz, jboolean installed, jboolean manualBuffer) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 601 | { |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 602 | LOGV("setHasPreviewCallback: installed:%d, manualBuffer:%d", (int)installed, (int)manualBuffer); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 603 | // Important: Only install preview_callback if the Java code has called |
| 604 | // setPreviewCallback() with a non-null value, otherwise we'd pay to memcpy |
| 605 | // each preview frame for nothing. |
Dave Sparks | 5e27115 | 2009-06-23 17:30:11 -0700 | [diff] [blame] | 606 | JNICameraContext* context; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 607 | sp<Camera> camera = get_native_camera(env, thiz, &context); |
| 608 | if (camera == 0) return; |
| 609 | |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 610 | // setCallbackMode will take care of setting the context flags and calling |
| 611 | // camera->setPreviewCallbackFlags within a mutex for us. |
| 612 | context->setCallbackMode(env, installed, manualBuffer); |
| 613 | } |
| 614 | |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 615 | static void android_hardware_Camera_addCallbackBuffer(JNIEnv *env, jobject thiz, jbyteArray bytes, int msgType) { |
| 616 | LOGV("addCallbackBuffer: 0x%x", msgType); |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 617 | |
| 618 | JNICameraContext* context = reinterpret_cast<JNICameraContext*>(env->GetIntField(thiz, fields.context)); |
| 619 | |
| 620 | if (context != NULL) { |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 621 | context->addCallbackBuffer(env, bytes, msgType); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 622 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | static void android_hardware_Camera_autoFocus(JNIEnv *env, jobject thiz) |
| 626 | { |
| 627 | LOGV("autoFocus"); |
Dave Sparks | 5e27115 | 2009-06-23 17:30:11 -0700 | [diff] [blame] | 628 | JNICameraContext* context; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 629 | sp<Camera> c = get_native_camera(env, thiz, &context); |
| 630 | if (c == 0) return; |
| 631 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 632 | if (c->autoFocus() != NO_ERROR) { |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 633 | jniThrowRuntimeException(env, "autoFocus failed"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 634 | } |
| 635 | } |
| 636 | |
Chih-Chung Chang | 244f8c2 | 2009-09-15 14:51:56 +0800 | [diff] [blame] | 637 | static void android_hardware_Camera_cancelAutoFocus(JNIEnv *env, jobject thiz) |
| 638 | { |
| 639 | LOGV("cancelAutoFocus"); |
| 640 | JNICameraContext* context; |
| 641 | sp<Camera> c = get_native_camera(env, thiz, &context); |
| 642 | if (c == 0) return; |
| 643 | |
| 644 | if (c->cancelAutoFocus() != NO_ERROR) { |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 645 | jniThrowRuntimeException(env, "cancelAutoFocus failed"); |
Chih-Chung Chang | 244f8c2 | 2009-09-15 14:51:56 +0800 | [diff] [blame] | 646 | } |
| 647 | } |
| 648 | |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 649 | static void android_hardware_Camera_takePicture(JNIEnv *env, jobject thiz, int msgType) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 650 | { |
| 651 | LOGV("takePicture"); |
Dave Sparks | 5e27115 | 2009-06-23 17:30:11 -0700 | [diff] [blame] | 652 | JNICameraContext* context; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 653 | sp<Camera> camera = get_native_camera(env, thiz, &context); |
| 654 | if (camera == 0) return; |
| 655 | |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 656 | /* |
| 657 | * When CAMERA_MSG_RAW_IMAGE is requested, if the raw image callback |
| 658 | * buffer is available, CAMERA_MSG_RAW_IMAGE is enabled to get the |
| 659 | * notification _and_ the data; otherwise, CAMERA_MSG_RAW_IMAGE_NOTIFY |
| 660 | * is enabled to receive the callback notification but no data. |
| 661 | * |
| 662 | * Note that CAMERA_MSG_RAW_IMAGE_NOTIFY is not exposed to the |
| 663 | * Java application. |
| 664 | */ |
| 665 | if (msgType & CAMERA_MSG_RAW_IMAGE) { |
| 666 | LOGV("Enable raw image callback buffer"); |
| 667 | if (!context->isRawImageCallbackBufferAvailable()) { |
| 668 | LOGV("Enable raw image notification, since no callback buffer exists"); |
| 669 | msgType &= ~CAMERA_MSG_RAW_IMAGE; |
| 670 | msgType |= CAMERA_MSG_RAW_IMAGE_NOTIFY; |
| 671 | } |
| 672 | } |
| 673 | |
| 674 | if (camera->takePicture(msgType) != NO_ERROR) { |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 675 | jniThrowRuntimeException(env, "takePicture failed"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 676 | return; |
| 677 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | static void android_hardware_Camera_setParameters(JNIEnv *env, jobject thiz, jstring params) |
| 681 | { |
| 682 | LOGV("setParameters"); |
| 683 | sp<Camera> camera = get_native_camera(env, thiz, NULL); |
| 684 | if (camera == 0) return; |
| 685 | |
| 686 | const jchar* str = env->GetStringCritical(params, 0); |
| 687 | String8 params8; |
| 688 | if (params) { |
| 689 | params8 = String8(str, env->GetStringLength(params)); |
| 690 | env->ReleaseStringCritical(params, str); |
| 691 | } |
| 692 | if (camera->setParameters(params8) != NO_ERROR) { |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 693 | jniThrowRuntimeException(env, "setParameters failed"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 694 | return; |
| 695 | } |
| 696 | } |
| 697 | |
| 698 | static jstring android_hardware_Camera_getParameters(JNIEnv *env, jobject thiz) |
| 699 | { |
| 700 | LOGV("getParameters"); |
| 701 | sp<Camera> camera = get_native_camera(env, thiz, NULL); |
| 702 | if (camera == 0) return 0; |
| 703 | |
| 704 | return env->NewStringUTF(camera->getParameters().string()); |
| 705 | } |
| 706 | |
| 707 | static void android_hardware_Camera_reconnect(JNIEnv *env, jobject thiz) |
| 708 | { |
| 709 | LOGV("reconnect"); |
| 710 | sp<Camera> camera = get_native_camera(env, thiz, NULL); |
| 711 | if (camera == 0) return; |
| 712 | |
| 713 | if (camera->reconnect() != NO_ERROR) { |
| 714 | jniThrowException(env, "java/io/IOException", "reconnect failed"); |
| 715 | return; |
| 716 | } |
| 717 | } |
| 718 | |
Wu-cheng Li | ffe1cf2 | 2009-09-10 16:49:17 +0800 | [diff] [blame] | 719 | static void android_hardware_Camera_lock(JNIEnv *env, jobject thiz) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 720 | { |
| 721 | LOGV("lock"); |
| 722 | sp<Camera> camera = get_native_camera(env, thiz, NULL); |
Wu-cheng Li | ffe1cf2 | 2009-09-10 16:49:17 +0800 | [diff] [blame] | 723 | if (camera == 0) return; |
| 724 | |
| 725 | if (camera->lock() != NO_ERROR) { |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 726 | jniThrowRuntimeException(env, "lock failed"); |
Wu-cheng Li | ffe1cf2 | 2009-09-10 16:49:17 +0800 | [diff] [blame] | 727 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 728 | } |
| 729 | |
Wu-cheng Li | ffe1cf2 | 2009-09-10 16:49:17 +0800 | [diff] [blame] | 730 | static void android_hardware_Camera_unlock(JNIEnv *env, jobject thiz) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 731 | { |
| 732 | LOGV("unlock"); |
| 733 | sp<Camera> camera = get_native_camera(env, thiz, NULL); |
Wu-cheng Li | ffe1cf2 | 2009-09-10 16:49:17 +0800 | [diff] [blame] | 734 | if (camera == 0) return; |
| 735 | |
| 736 | if (camera->unlock() != NO_ERROR) { |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 737 | jniThrowRuntimeException(env, "unlock failed"); |
Wu-cheng Li | ffe1cf2 | 2009-09-10 16:49:17 +0800 | [diff] [blame] | 738 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 739 | } |
| 740 | |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 741 | static void android_hardware_Camera_startSmoothZoom(JNIEnv *env, jobject thiz, jint value) |
| 742 | { |
Joe Onorato | f5d95cb | 2010-01-07 21:48:32 -0500 | [diff] [blame] | 743 | LOGV("startSmoothZoom"); |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 744 | sp<Camera> camera = get_native_camera(env, thiz, NULL); |
| 745 | if (camera == 0) return; |
| 746 | |
Wu-cheng Li | 0ca2519 | 2010-03-29 16:21:12 +0800 | [diff] [blame] | 747 | status_t rc = camera->sendCommand(CAMERA_CMD_START_SMOOTH_ZOOM, value, 0); |
| 748 | if (rc == BAD_VALUE) { |
| 749 | char msg[64]; |
| 750 | sprintf(msg, "invalid zoom value=%d", value); |
| 751 | jniThrowException(env, "java/lang/IllegalArgumentException", msg); |
| 752 | } else if (rc != NO_ERROR) { |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 753 | jniThrowRuntimeException(env, "start smooth zoom failed"); |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 754 | } |
| 755 | } |
| 756 | |
| 757 | static void android_hardware_Camera_stopSmoothZoom(JNIEnv *env, jobject thiz) |
| 758 | { |
Joe Onorato | f5d95cb | 2010-01-07 21:48:32 -0500 | [diff] [blame] | 759 | LOGV("stopSmoothZoom"); |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 760 | sp<Camera> camera = get_native_camera(env, thiz, NULL); |
| 761 | if (camera == 0) return; |
| 762 | |
| 763 | if (camera->sendCommand(CAMERA_CMD_STOP_SMOOTH_ZOOM, 0, 0) != NO_ERROR) { |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 764 | jniThrowRuntimeException(env, "stop smooth zoom failed"); |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 765 | } |
| 766 | } |
| 767 | |
Chih-Chung Chang | d1d7706 | 2010-01-22 17:49:48 -0800 | [diff] [blame] | 768 | static void android_hardware_Camera_setDisplayOrientation(JNIEnv *env, jobject thiz, |
| 769 | jint value) |
| 770 | { |
| 771 | LOGV("setDisplayOrientation"); |
| 772 | sp<Camera> camera = get_native_camera(env, thiz, NULL); |
| 773 | if (camera == 0) return; |
| 774 | |
| 775 | if (camera->sendCommand(CAMERA_CMD_SET_DISPLAY_ORIENTATION, value, 0) != NO_ERROR) { |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 776 | jniThrowRuntimeException(env, "set display orientation failed"); |
Chih-Chung Chang | d1d7706 | 2010-01-22 17:49:48 -0800 | [diff] [blame] | 777 | } |
| 778 | } |
| 779 | |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 780 | static void android_hardware_Camera_startFaceDetection(JNIEnv *env, jobject thiz, |
Wu-cheng Li | bb1e275 | 2011-07-30 05:00:37 +0800 | [diff] [blame^] | 781 | jint type) |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 782 | { |
| 783 | LOGV("startFaceDetection"); |
| 784 | JNICameraContext* context; |
| 785 | sp<Camera> camera = get_native_camera(env, thiz, &context); |
| 786 | if (camera == 0) return; |
| 787 | |
| 788 | status_t rc = camera->sendCommand(CAMERA_CMD_START_FACE_DETECTION, type, 0); |
| 789 | if (rc == BAD_VALUE) { |
| 790 | char msg[64]; |
| 791 | snprintf(msg, sizeof(msg), "invalid face detection type=%d", type); |
| 792 | jniThrowException(env, "java/lang/IllegalArgumentException", msg); |
| 793 | } else if (rc != NO_ERROR) { |
| 794 | jniThrowRuntimeException(env, "start face detection failed"); |
| 795 | } |
| 796 | } |
| 797 | |
| 798 | static void android_hardware_Camera_stopFaceDetection(JNIEnv *env, jobject thiz) |
| 799 | { |
| 800 | LOGV("stopFaceDetection"); |
| 801 | sp<Camera> camera = get_native_camera(env, thiz, NULL); |
| 802 | if (camera == 0) return; |
| 803 | |
| 804 | if (camera->sendCommand(CAMERA_CMD_STOP_FACE_DETECTION, 0, 0) != NO_ERROR) { |
| 805 | jniThrowRuntimeException(env, "stop face detection failed"); |
| 806 | } |
| 807 | } |
| 808 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 809 | //------------------------------------------------- |
| 810 | |
| 811 | static JNINativeMethod camMethods[] = { |
Chih-Chung Chang | e25cc65 | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 812 | { "getNumberOfCameras", |
| 813 | "()I", |
| 814 | (void *)android_hardware_Camera_getNumberOfCameras }, |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 815 | { "getCameraInfo", |
| 816 | "(ILandroid/hardware/Camera$CameraInfo;)V", |
| 817 | (void*)android_hardware_Camera_getCameraInfo }, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 818 | { "native_setup", |
Chih-Chung Chang | e25cc65 | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 819 | "(Ljava/lang/Object;I)V", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 820 | (void*)android_hardware_Camera_native_setup }, |
| 821 | { "native_release", |
| 822 | "()V", |
| 823 | (void*)android_hardware_Camera_release }, |
| 824 | { "setPreviewDisplay", |
| 825 | "(Landroid/view/Surface;)V", |
| 826 | (void *)android_hardware_Camera_setPreviewDisplay }, |
Jamie Gennis | fd6f39e | 2010-12-20 12:15:00 -0800 | [diff] [blame] | 827 | { "setPreviewTexture", |
| 828 | "(Landroid/graphics/SurfaceTexture;)V", |
| 829 | (void *)android_hardware_Camera_setPreviewTexture }, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 830 | { "startPreview", |
| 831 | "()V", |
| 832 | (void *)android_hardware_Camera_startPreview }, |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 833 | { "_stopPreview", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 834 | "()V", |
| 835 | (void *)android_hardware_Camera_stopPreview }, |
| 836 | { "previewEnabled", |
| 837 | "()Z", |
| 838 | (void *)android_hardware_Camera_previewEnabled }, |
| 839 | { "setHasPreviewCallback", |
| 840 | "(ZZ)V", |
| 841 | (void *)android_hardware_Camera_setHasPreviewCallback }, |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 842 | { "_addCallbackBuffer", |
| 843 | "([BI)V", |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 844 | (void *)android_hardware_Camera_addCallbackBuffer }, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 845 | { "native_autoFocus", |
| 846 | "()V", |
| 847 | (void *)android_hardware_Camera_autoFocus }, |
Chih-Chung Chang | 244f8c2 | 2009-09-15 14:51:56 +0800 | [diff] [blame] | 848 | { "native_cancelAutoFocus", |
| 849 | "()V", |
| 850 | (void *)android_hardware_Camera_cancelAutoFocus }, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 851 | { "native_takePicture", |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 852 | "(I)V", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 853 | (void *)android_hardware_Camera_takePicture }, |
| 854 | { "native_setParameters", |
| 855 | "(Ljava/lang/String;)V", |
| 856 | (void *)android_hardware_Camera_setParameters }, |
| 857 | { "native_getParameters", |
| 858 | "()Ljava/lang/String;", |
| 859 | (void *)android_hardware_Camera_getParameters }, |
| 860 | { "reconnect", |
| 861 | "()V", |
| 862 | (void*)android_hardware_Camera_reconnect }, |
| 863 | { "lock", |
Wu-cheng Li | ffe1cf2 | 2009-09-10 16:49:17 +0800 | [diff] [blame] | 864 | "()V", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 865 | (void*)android_hardware_Camera_lock }, |
| 866 | { "unlock", |
Wu-cheng Li | ffe1cf2 | 2009-09-10 16:49:17 +0800 | [diff] [blame] | 867 | "()V", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 868 | (void*)android_hardware_Camera_unlock }, |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 869 | { "startSmoothZoom", |
| 870 | "(I)V", |
| 871 | (void *)android_hardware_Camera_startSmoothZoom }, |
| 872 | { "stopSmoothZoom", |
| 873 | "()V", |
| 874 | (void *)android_hardware_Camera_stopSmoothZoom }, |
Chih-Chung Chang | d1d7706 | 2010-01-22 17:49:48 -0800 | [diff] [blame] | 875 | { "setDisplayOrientation", |
| 876 | "(I)V", |
| 877 | (void *)android_hardware_Camera_setDisplayOrientation }, |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 878 | { "_startFaceDetection", |
| 879 | "(I)V", |
| 880 | (void *)android_hardware_Camera_startFaceDetection }, |
| 881 | { "_stopFaceDetection", |
| 882 | "()V", |
| 883 | (void *)android_hardware_Camera_stopFaceDetection}, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 884 | }; |
| 885 | |
| 886 | struct field { |
| 887 | const char *class_name; |
| 888 | const char *field_name; |
| 889 | const char *field_type; |
| 890 | jfieldID *jfield; |
| 891 | }; |
| 892 | |
| 893 | static int find_fields(JNIEnv *env, field *fields, int count) |
| 894 | { |
| 895 | for (int i = 0; i < count; i++) { |
| 896 | field *f = &fields[i]; |
| 897 | jclass clazz = env->FindClass(f->class_name); |
| 898 | if (clazz == NULL) { |
| 899 | LOGE("Can't find %s", f->class_name); |
| 900 | return -1; |
| 901 | } |
| 902 | |
| 903 | jfieldID field = env->GetFieldID(clazz, f->field_name, f->field_type); |
| 904 | if (field == NULL) { |
| 905 | LOGE("Can't find %s.%s", f->class_name, f->field_name); |
| 906 | return -1; |
| 907 | } |
| 908 | |
| 909 | *(f->jfield) = field; |
| 910 | } |
| 911 | |
| 912 | return 0; |
| 913 | } |
| 914 | |
| 915 | // Get all the required offsets in java class and register native functions |
| 916 | int register_android_hardware_Camera(JNIEnv *env) |
| 917 | { |
| 918 | field fields_to_find[] = { |
| 919 | { "android/hardware/Camera", "mNativeContext", "I", &fields.context }, |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 920 | { "android/view/Surface", ANDROID_VIEW_SURFACE_JNI_ID, "I", &fields.surface }, |
Jamie Gennis | fd6f39e | 2010-12-20 12:15:00 -0800 | [diff] [blame] | 921 | { "android/graphics/SurfaceTexture", |
| 922 | ANDROID_GRAPHICS_SURFACETEXTURE_JNI_ID, "I", &fields.surfaceTexture }, |
Wu-cheng Li | 3fd5fa4 | 2010-09-15 16:06:20 -0700 | [diff] [blame] | 923 | { "android/hardware/Camera$CameraInfo", "facing", "I", &fields.facing }, |
| 924 | { "android/hardware/Camera$CameraInfo", "orientation", "I", &fields.orientation }, |
Wu-cheng Li | f0d6a48 | 2011-07-28 05:30:59 +0800 | [diff] [blame] | 925 | { "android/hardware/Camera$Face", "rect", "Landroid/graphics/Rect;", &fields.face_rect }, |
| 926 | { "android/hardware/Camera$Face", "score", "I", &fields.face_score }, |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 927 | { "android/graphics/Rect", "left", "I", &fields.rect_left }, |
| 928 | { "android/graphics/Rect", "top", "I", &fields.rect_top }, |
| 929 | { "android/graphics/Rect", "right", "I", &fields.rect_right }, |
| 930 | { "android/graphics/Rect", "bottom", "I", &fields.rect_bottom }, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 931 | }; |
| 932 | |
| 933 | if (find_fields(env, fields_to_find, NELEM(fields_to_find)) < 0) |
| 934 | return -1; |
| 935 | |
| 936 | jclass clazz = env->FindClass("android/hardware/Camera"); |
| 937 | fields.post_event = env->GetStaticMethodID(clazz, "postEventFromNative", |
| 938 | "(Ljava/lang/Object;IIILjava/lang/Object;)V"); |
| 939 | if (fields.post_event == NULL) { |
| 940 | LOGE("Can't find android/hardware/Camera.postEventFromNative"); |
| 941 | return -1; |
| 942 | } |
| 943 | |
Wu-cheng Li | bb1e275 | 2011-07-30 05:00:37 +0800 | [diff] [blame^] | 944 | clazz = env->FindClass("android/graphics/Rect"); |
| 945 | fields.rect_constructor = env->GetMethodID(clazz, "<init>", "()V"); |
| 946 | if (fields.rect_constructor == NULL) { |
| 947 | LOGE("Can't find android/graphics/Rect.Rect()"); |
| 948 | return -1; |
| 949 | } |
| 950 | |
| 951 | clazz = env->FindClass("android/hardware/Camera$Face"); |
| 952 | fields.face_constructor = env->GetMethodID(clazz, "<init>", "()V"); |
| 953 | if (fields.face_constructor == NULL) { |
| 954 | LOGE("Can't find android/hardware/Camera$Face.Face()"); |
| 955 | return -1; |
| 956 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 957 | |
| 958 | // Register native functions |
| 959 | return AndroidRuntime::registerNativeMethods(env, "android/hardware/Camera", |
| 960 | camMethods, NELEM(camMethods)); |
| 961 | } |