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