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