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