blob: 3dcaa37fd747f578cfc8f0d08a4f2f10dabbf7ab [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2**
3** Copyright 2008, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18//#define LOG_NDEBUG 0
19#define LOG_TAG "Camera-JNI"
20#include <utils/Log.h>
21
22#include "jni.h"
23#include "JNIHelp.h"
24#include "android_runtime/AndroidRuntime.h"
25
Andrew Harp94927df2009-10-20 01:47:05 -040026#include <utils/Vector.h>
27
Jamie Gennisfd6f39e2010-12-20 12:15:00 -080028#include <gui/SurfaceTexture.h>
Mathias Agopian000479f2010-02-09 17:46:37 -080029#include <surfaceflinger/Surface.h>
30#include <camera/Camera.h>
Mathias Agopian07952722009-05-19 19:08:10 -070031#include <binder/IMemory.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032
33using namespace android;
34
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035struct fields_t {
36 jfieldID context;
37 jfieldID surface;
Jamie Gennisfd6f39e2010-12-20 12:15:00 -080038 jfieldID surfaceTexture;
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +080039 jfieldID facing;
40 jfieldID orientation;
Wu-cheng Lif0d6a482011-07-28 05:30:59 +080041 jfieldID face_rect;
Wu-cheng Li4c2292e2011-07-22 02:37:11 +080042 jfieldID face_score;
43 jfieldID rect_left;
44 jfieldID rect_top;
45 jfieldID rect_right;
46 jfieldID rect_bottom;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047 jmethodID post_event;
48};
49
50static fields_t fields;
51static Mutex sLock;
52
Dave Sparks5e271152009-06-23 17:30:11 -070053// provides persistent context for calls from native code to Java
54class JNICameraContext: public CameraListener
55{
56public:
57 JNICameraContext(JNIEnv* env, jobject weak_this, jclass clazz, const sp<Camera>& camera);
58 ~JNICameraContext() { release(); }
59 virtual void notify(int32_t msgType, int32_t ext1, int32_t ext2);
60 virtual void postData(int32_t msgType, const sp<IMemory>& dataPtr);
Dave Sparks59c1a932009-07-08 15:56:53 -070061 virtual void postDataTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr);
James Donge00cab72011-02-17 16:38:06 -080062 void addCallbackBuffer(JNIEnv *env, jbyteArray cbb, int msgType);
Andrew Harp94927df2009-10-20 01:47:05 -040063 void setCallbackMode(JNIEnv *env, bool installed, bool manualMode);
Dave Sparks5e271152009-06-23 17:30:11 -070064 sp<Camera> getCamera() { Mutex::Autolock _l(mLock); return mCamera; }
James Donge00cab72011-02-17 16:38:06 -080065 bool isRawImageCallbackBufferAvailable() const;
Dave Sparks5e271152009-06-23 17:30:11 -070066 void release();
67
68private:
69 void copyAndPost(JNIEnv* env, const sp<IMemory>& dataPtr, int msgType);
James Donge00cab72011-02-17 16:38:06 -080070 void clearCallbackBuffers_l(JNIEnv *env, Vector<jbyteArray> *buffers);
Andrew Harp94927df2009-10-20 01:47:05 -040071 void clearCallbackBuffers_l(JNIEnv *env);
James Donge00cab72011-02-17 16:38:06 -080072 jbyteArray getCallbackBuffer(JNIEnv *env, Vector<jbyteArray> *buffers, size_t bufferSize);
Dave Sparks5e271152009-06-23 17:30:11 -070073
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080074 jobject mCameraJObjectWeak; // weak reference to java object
75 jclass mCameraJClass; // strong reference to java class
Wu-cheng Liffe1cf22009-09-10 16:49:17 +080076 sp<Camera> mCamera; // strong reference to native object
Dave Sparks5e271152009-06-23 17:30:11 -070077 Mutex mLock;
Andrew Harp94927df2009-10-20 01:47:05 -040078
James Donge00cab72011-02-17 16:38:06 -080079 /*
80 * Global reference application-managed raw image buffer queue.
81 *
82 * Manual-only mode is supported for raw image callbacks, which is
83 * set whenever method addCallbackBuffer() with msgType =
84 * CAMERA_MSG_RAW_IMAGE is called; otherwise, null is returned
85 * with raw image callbacks.
86 */
87 Vector<jbyteArray> mRawImageCallbackBuffers;
88
89 /*
90 * Application-managed preview buffer queue and the flags
91 * associated with the usage of the preview buffer callback.
92 */
Andrew Harp94927df2009-10-20 01:47:05 -040093 Vector<jbyteArray> mCallbackBuffers; // Global reference application managed byte[]
94 bool mManualBufferMode; // Whether to use application managed buffers.
James Donge00cab72011-02-17 16:38:06 -080095 bool mManualCameraCallbackSet; // Whether the callback has been set, used to
96 // reduce unnecessary calls to set the callback.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097};
98
James Donge00cab72011-02-17 16:38:06 -080099bool JNICameraContext::isRawImageCallbackBufferAvailable() const
100{
101 return !mRawImageCallbackBuffers.isEmpty();
102}
103
Dave Sparks5e271152009-06-23 17:30:11 -0700104sp<Camera> get_native_camera(JNIEnv *env, jobject thiz, JNICameraContext** pContext)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800105{
106 sp<Camera> camera;
107 Mutex::Autolock _l(sLock);
Dave Sparks5e271152009-06-23 17:30:11 -0700108 JNICameraContext* context = reinterpret_cast<JNICameraContext*>(env->GetIntField(thiz, fields.context));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800109 if (context != NULL) {
Dave Sparks5e271152009-06-23 17:30:11 -0700110 camera = context->getCamera();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800111 }
112 LOGV("get_native_camera: context=%p, camera=%p", context, camera.get());
113 if (camera == 0) {
Elliott Hughes69a017b2011-04-08 14:10:28 -0700114 jniThrowRuntimeException(env, "Method called after release()");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115 }
116
117 if (pContext != NULL) *pContext = context;
118 return camera;
119}
120
Dave Sparks5e271152009-06-23 17:30:11 -0700121JNICameraContext::JNICameraContext(JNIEnv* env, jobject weak_this, jclass clazz, const sp<Camera>& camera)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800122{
Dave Sparks5e271152009-06-23 17:30:11 -0700123 mCameraJObjectWeak = env->NewGlobalRef(weak_this);
124 mCameraJClass = (jclass)env->NewGlobalRef(clazz);
125 mCamera = camera;
Andrew Harp94927df2009-10-20 01:47:05 -0400126
127 mManualBufferMode = false;
128 mManualCameraCallbackSet = false;
Dave Sparks5e271152009-06-23 17:30:11 -0700129}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800130
Dave Sparks5e271152009-06-23 17:30:11 -0700131void JNICameraContext::release()
132{
133 LOGV("release");
134 Mutex::Autolock _l(mLock);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800135 JNIEnv *env = AndroidRuntime::getJNIEnv();
Dave Sparks5e271152009-06-23 17:30:11 -0700136
137 if (mCameraJObjectWeak != NULL) {
138 env->DeleteGlobalRef(mCameraJObjectWeak);
139 mCameraJObjectWeak = NULL;
140 }
141 if (mCameraJClass != NULL) {
142 env->DeleteGlobalRef(mCameraJClass);
143 mCameraJClass = NULL;
144 }
Andrew Harp94927df2009-10-20 01:47:05 -0400145 clearCallbackBuffers_l(env);
Dave Sparks5e271152009-06-23 17:30:11 -0700146 mCamera.clear();
147}
148
149void JNICameraContext::notify(int32_t msgType, int32_t ext1, int32_t ext2)
150{
151 LOGV("notify");
152
153 // VM pointer will be NULL if object is released
154 Mutex::Autolock _l(mLock);
155 if (mCameraJObjectWeak == NULL) {
156 LOGW("callback on dead camera object");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157 return;
158 }
Dave Sparks5e271152009-06-23 17:30:11 -0700159 JNIEnv *env = AndroidRuntime::getJNIEnv();
James Donge00cab72011-02-17 16:38:06 -0800160
161 /*
162 * If the notification or msgType is CAMERA_MSG_RAW_IMAGE_NOTIFY, change it
163 * to CAMERA_MSG_RAW_IMAGE since CAMERA_MSG_RAW_IMAGE_NOTIFY is not exposed
164 * to the Java app.
165 */
166 if (msgType == CAMERA_MSG_RAW_IMAGE_NOTIFY) {
167 msgType = CAMERA_MSG_RAW_IMAGE;
168 }
169
Dave Sparksc62f9bd2009-06-26 13:33:32 -0700170 env->CallStaticVoidMethod(mCameraJClass, fields.post_event,
Chih-Chung Chang6157de02009-09-24 15:29:35 -0700171 mCameraJObjectWeak, msgType, ext1, ext2, NULL);
Dave Sparks5e271152009-06-23 17:30:11 -0700172}
173
James Donge00cab72011-02-17 16:38:06 -0800174jbyteArray JNICameraContext::getCallbackBuffer(
175 JNIEnv* env, Vector<jbyteArray>* buffers, size_t bufferSize)
176{
177 jbyteArray obj = NULL;
178
179 // Vector access should be protected by lock in postData()
180 if (!buffers->isEmpty()) {
181 LOGV("Using callback buffer from queue of length %d", buffers->size());
182 jbyteArray globalBuffer = buffers->itemAt(0);
183 buffers->removeAt(0);
184
185 obj = (jbyteArray)env->NewLocalRef(globalBuffer);
186 env->DeleteGlobalRef(globalBuffer);
187
188 if (obj != NULL) {
189 jsize bufferLength = env->GetArrayLength(obj);
190 if ((int)bufferLength < (int)bufferSize) {
191 LOGE("Callback buffer was too small! Expected %d bytes, but got %d bytes!",
192 bufferSize, bufferLength);
193 env->DeleteLocalRef(obj);
194 return NULL;
195 }
196 }
197 }
198
199 return obj;
200}
201
Dave Sparks5e271152009-06-23 17:30:11 -0700202void JNICameraContext::copyAndPost(JNIEnv* env, const sp<IMemory>& dataPtr, int msgType)
203{
204 jbyteArray obj = NULL;
205
206 // allocate Java byte array and copy data
207 if (dataPtr != NULL) {
208 ssize_t offset;
209 size_t size;
210 sp<IMemoryHeap> heap = dataPtr->getMemory(&offset, &size);
James Donge00cab72011-02-17 16:38:06 -0800211 LOGV("copyAndPost: off=%ld, size=%d", offset, size);
Dave Sparks5e271152009-06-23 17:30:11 -0700212 uint8_t *heapBase = (uint8_t*)heap->base();
213
214 if (heapBase != NULL) {
Dave Sparksc4ca4202009-07-13 09:38:20 -0700215 const jbyte* data = reinterpret_cast<const jbyte*>(heapBase + offset);
Andrew Harp94927df2009-10-20 01:47:05 -0400216
217 if (!mManualBufferMode) {
218 LOGV("Allocating callback buffer");
219 obj = env->NewByteArray(size);
220 } else {
James Donge00cab72011-02-17 16:38:06 -0800221 switch (msgType) {
222 case CAMERA_MSG_PREVIEW_FRAME: {
223 obj = getCallbackBuffer(env, &mCallbackBuffers, size);
Andrew Harp94927df2009-10-20 01:47:05 -0400224
James Donge00cab72011-02-17 16:38:06 -0800225 if (mCallbackBuffers.isEmpty()) {
226 LOGV("Out of buffers, clearing callback!");
Iliyan Malchev9c7ac0d2011-04-14 16:51:21 -0700227 mCamera->setPreviewCallbackFlags(CAMERA_FRAME_CALLBACK_FLAG_NOOP);
James Donge00cab72011-02-17 16:38:06 -0800228 mManualCameraCallbackSet = false;
Andrew Harp94927df2009-10-20 01:47:05 -0400229
James Donge00cab72011-02-17 16:38:06 -0800230 if (obj == NULL) {
231 return;
232 }
Andrew Harp94927df2009-10-20 01:47:05 -0400233 }
James Donge00cab72011-02-17 16:38:06 -0800234 break;
Andrew Harp94927df2009-10-20 01:47:05 -0400235 }
James Donge00cab72011-02-17 16:38:06 -0800236 case CAMERA_MSG_RAW_IMAGE: {
237 obj = getCallbackBuffer(env, &mRawImageCallbackBuffers, size);
238 break;
239 }
240 default: {
Elliott Hughes69a017b2011-04-08 14:10:28 -0700241 jniThrowRuntimeException(env, "Unsupported message type");
Andrew Harp94927df2009-10-20 01:47:05 -0400242 return;
243 }
244 }
245 }
246
Dave Sparks5e271152009-06-23 17:30:11 -0700247 if (obj == NULL) {
248 LOGE("Couldn't allocate byte array for JPEG data");
249 env->ExceptionClear();
250 } else {
Dave Sparksa95f4952009-07-10 18:13:36 -0700251 env->SetByteArrayRegion(obj, 0, size, data);
Dave Sparks5e271152009-06-23 17:30:11 -0700252 }
253 } else {
254 LOGE("image heap is NULL");
255 }
256 }
257
258 // post image data to Java
259 env->CallStaticVoidMethod(mCameraJClass, fields.post_event,
260 mCameraJObjectWeak, msgType, 0, 0, obj);
261 if (obj) {
262 env->DeleteLocalRef(obj);
263 }
264}
265
266void JNICameraContext::postData(int32_t msgType, const sp<IMemory>& dataPtr)
267{
268 // VM pointer will be NULL if object is released
269 Mutex::Autolock _l(mLock);
270 JNIEnv *env = AndroidRuntime::getJNIEnv();
Dave Sparksd0cbb1a2009-06-29 19:03:33 -0700271 if (mCameraJObjectWeak == NULL) {
272 LOGW("callback on dead camera object");
273 return;
274 }
Dave Sparks5e271152009-06-23 17:30:11 -0700275
276 // return data based on callback type
James Donge00cab72011-02-17 16:38:06 -0800277 switch (msgType) {
278 case CAMERA_MSG_VIDEO_FRAME:
279 // should never happen
280 break;
281
282 // For backward-compatibility purpose, if there is no callback
283 // buffer for raw image, the callback returns null.
284 case CAMERA_MSG_RAW_IMAGE:
285 LOGV("rawCallback");
286 if (mRawImageCallbackBuffers.isEmpty()) {
287 env->CallStaticVoidMethod(mCameraJClass, fields.post_event,
288 mCameraJObjectWeak, msgType, 0, 0, NULL);
289 } else {
290 copyAndPost(env, dataPtr, msgType);
291 }
292 break;
293
294 default:
295 LOGV("dataCallback(%d, %p)", msgType, dataPtr.get());
296 copyAndPost(env, dataPtr, msgType);
297 break;
Dave Sparks5e271152009-06-23 17:30:11 -0700298 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800299}
300
Dave Sparks59c1a932009-07-08 15:56:53 -0700301void JNICameraContext::postDataTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr)
302{
303 // TODO: plumb up to Java. For now, just drop the timestamp
304 postData(msgType, dataPtr);
305}
306
Andrew Harp94927df2009-10-20 01:47:05 -0400307void JNICameraContext::setCallbackMode(JNIEnv *env, bool installed, bool manualMode)
308{
309 Mutex::Autolock _l(mLock);
310 mManualBufferMode = manualMode;
311 mManualCameraCallbackSet = false;
312
313 // In order to limit the over usage of binder threads, all non-manual buffer
Iliyan Malchev9c7ac0d2011-04-14 16:51:21 -0700314 // callbacks use CAMERA_FRAME_CALLBACK_FLAG_BARCODE_SCANNER mode now.
Andrew Harp94927df2009-10-20 01:47:05 -0400315 //
316 // Continuous callbacks will have the callback re-registered from handleMessage.
317 // Manual buffer mode will operate as fast as possible, relying on the finite supply
318 // of buffers for throttling.
319
320 if (!installed) {
Iliyan Malchev9c7ac0d2011-04-14 16:51:21 -0700321 mCamera->setPreviewCallbackFlags(CAMERA_FRAME_CALLBACK_FLAG_NOOP);
James Donge00cab72011-02-17 16:38:06 -0800322 clearCallbackBuffers_l(env, &mCallbackBuffers);
Andrew Harp94927df2009-10-20 01:47:05 -0400323 } else if (mManualBufferMode) {
324 if (!mCallbackBuffers.isEmpty()) {
Iliyan Malchev9c7ac0d2011-04-14 16:51:21 -0700325 mCamera->setPreviewCallbackFlags(CAMERA_FRAME_CALLBACK_FLAG_CAMERA);
Andrew Harp94927df2009-10-20 01:47:05 -0400326 mManualCameraCallbackSet = true;
327 }
328 } else {
Iliyan Malchev9c7ac0d2011-04-14 16:51:21 -0700329 mCamera->setPreviewCallbackFlags(CAMERA_FRAME_CALLBACK_FLAG_BARCODE_SCANNER);
James Donge00cab72011-02-17 16:38:06 -0800330 clearCallbackBuffers_l(env, &mCallbackBuffers);
Andrew Harp94927df2009-10-20 01:47:05 -0400331 }
332}
333
James Donge00cab72011-02-17 16:38:06 -0800334void JNICameraContext::addCallbackBuffer(
335 JNIEnv *env, jbyteArray cbb, int msgType)
Andrew Harp94927df2009-10-20 01:47:05 -0400336{
James Donge00cab72011-02-17 16:38:06 -0800337 LOGV("addCallbackBuffer: 0x%x", msgType);
Andrew Harp94927df2009-10-20 01:47:05 -0400338 if (cbb != NULL) {
339 Mutex::Autolock _l(mLock);
James Donge00cab72011-02-17 16:38:06 -0800340 switch (msgType) {
341 case CAMERA_MSG_PREVIEW_FRAME: {
342 jbyteArray callbackBuffer = (jbyteArray)env->NewGlobalRef(cbb);
343 mCallbackBuffers.push(callbackBuffer);
Andrew Harp94927df2009-10-20 01:47:05 -0400344
James Donge00cab72011-02-17 16:38:06 -0800345 LOGV("Adding callback buffer to queue, %d total",
346 mCallbackBuffers.size());
Andrew Harp94927df2009-10-20 01:47:05 -0400347
James Donge00cab72011-02-17 16:38:06 -0800348 // We want to make sure the camera knows we're ready for the
349 // next frame. This may have come unset had we not had a
350 // callbackbuffer ready for it last time.
351 if (mManualBufferMode && !mManualCameraCallbackSet) {
Iliyan Malchev9c7ac0d2011-04-14 16:51:21 -0700352 mCamera->setPreviewCallbackFlags(CAMERA_FRAME_CALLBACK_FLAG_CAMERA);
James Donge00cab72011-02-17 16:38:06 -0800353 mManualCameraCallbackSet = true;
354 }
355 break;
356 }
357 case CAMERA_MSG_RAW_IMAGE: {
358 jbyteArray callbackBuffer = (jbyteArray)env->NewGlobalRef(cbb);
359 mRawImageCallbackBuffers.push(callbackBuffer);
360 break;
361 }
362 default: {
363 jniThrowException(env,
364 "java/lang/IllegalArgumentException",
365 "Unsupported message type");
366 return;
367 }
Andrew Harp94927df2009-10-20 01:47:05 -0400368 }
369 } else {
370 LOGE("Null byte array!");
371 }
372}
373
374void JNICameraContext::clearCallbackBuffers_l(JNIEnv *env)
375{
James Donge00cab72011-02-17 16:38:06 -0800376 clearCallbackBuffers_l(env, &mCallbackBuffers);
377 clearCallbackBuffers_l(env, &mRawImageCallbackBuffers);
378}
379
380void JNICameraContext::clearCallbackBuffers_l(JNIEnv *env, Vector<jbyteArray> *buffers) {
381 LOGV("Clearing callback buffers, %d remained", buffers->size());
382 while (!buffers->isEmpty()) {
383 env->DeleteGlobalRef(buffers->top());
384 buffers->pop();
Andrew Harp94927df2009-10-20 01:47:05 -0400385 }
386}
387
Chih-Chung Change25cc652010-05-06 16:36:58 +0800388static jint android_hardware_Camera_getNumberOfCameras(JNIEnv *env, jobject thiz)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800389{
Chih-Chung Change25cc652010-05-06 16:36:58 +0800390 return Camera::getNumberOfCameras();
391}
392
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800393static void android_hardware_Camera_getCameraInfo(JNIEnv *env, jobject thiz,
394 jint cameraId, jobject info_obj)
395{
396 CameraInfo cameraInfo;
397 status_t rc = Camera::getCameraInfo(cameraId, &cameraInfo);
398 if (rc != NO_ERROR) {
Elliott Hughes69a017b2011-04-08 14:10:28 -0700399 jniThrowRuntimeException(env, "Fail to get camera info");
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800400 return;
401 }
402 env->SetIntField(info_obj, fields.facing, cameraInfo.facing);
403 env->SetIntField(info_obj, fields.orientation, cameraInfo.orientation);
404}
405
Chih-Chung Change25cc652010-05-06 16:36:58 +0800406// connect to camera service
407static void android_hardware_Camera_native_setup(JNIEnv *env, jobject thiz,
408 jobject weak_this, jint cameraId)
409{
410 sp<Camera> camera = Camera::connect(cameraId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800411
412 if (camera == NULL) {
Elliott Hughes69a017b2011-04-08 14:10:28 -0700413 jniThrowRuntimeException(env, "Fail to connect to camera service");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800414 return;
415 }
416
417 // make sure camera hardware is alive
418 if (camera->getStatus() != NO_ERROR) {
Elliott Hughes69a017b2011-04-08 14:10:28 -0700419 jniThrowRuntimeException(env, "Camera initialization failed");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800420 return;
421 }
422
423 jclass clazz = env->GetObjectClass(thiz);
424 if (clazz == NULL) {
Elliott Hughes69a017b2011-04-08 14:10:28 -0700425 jniThrowRuntimeException(env, "Can't find android/hardware/Camera");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800426 return;
427 }
428
429 // We use a weak reference so the Camera object can be garbage collected.
430 // The reference is only used as a proxy for callbacks.
Dave Sparks5e271152009-06-23 17:30:11 -0700431 sp<JNICameraContext> context = new JNICameraContext(env, weak_this, clazz, camera);
432 context->incStrong(thiz);
433 camera->setListener(context);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800434
435 // save context in opaque field
Dave Sparks5e271152009-06-23 17:30:11 -0700436 env->SetIntField(thiz, fields.context, (int)context.get());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800437}
438
439// disconnect from camera service
440// It's okay to call this when the native camera context is already null.
441// This handles the case where the user has called release() and the
442// finalizer is invoked later.
443static void android_hardware_Camera_release(JNIEnv *env, jobject thiz)
444{
Dave Sparksda578562009-07-21 08:43:29 -0700445 // TODO: Change to LOGV
Joe Onoratof5d95cb2010-01-07 21:48:32 -0500446 LOGV("release camera");
Dave Sparks5e271152009-06-23 17:30:11 -0700447 JNICameraContext* context = NULL;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800448 sp<Camera> camera;
449 {
450 Mutex::Autolock _l(sLock);
Dave Sparks5e271152009-06-23 17:30:11 -0700451 context = reinterpret_cast<JNICameraContext*>(env->GetIntField(thiz, fields.context));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800452
453 // Make sure we do not attempt to callback on a deleted Java object.
454 env->SetIntField(thiz, fields.context, 0);
455 }
456
457 // clean up if release has not been called before
458 if (context != NULL) {
Dave Sparks5e271152009-06-23 17:30:11 -0700459 camera = context->getCamera();
460 context->release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800461 LOGV("native_release: context=%p camera=%p", context, camera.get());
462
463 // clear callbacks
464 if (camera != NULL) {
Iliyan Malchev9c7ac0d2011-04-14 16:51:21 -0700465 camera->setPreviewCallbackFlags(CAMERA_FRAME_CALLBACK_FLAG_NOOP);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800466 camera->disconnect();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800467 }
468
469 // remove context to prevent further Java access
Dave Sparks5e271152009-06-23 17:30:11 -0700470 context->decStrong(thiz);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800471 }
472}
473
474static void android_hardware_Camera_setPreviewDisplay(JNIEnv *env, jobject thiz, jobject jSurface)
475{
476 LOGV("setPreviewDisplay");
477 sp<Camera> camera = get_native_camera(env, thiz, NULL);
478 if (camera == 0) return;
479
Wu-cheng Lib8a10fe2009-06-23 23:37:36 +0800480 sp<Surface> surface = NULL;
481 if (jSurface != NULL) {
482 surface = reinterpret_cast<Surface*>(env->GetIntField(jSurface, fields.surface));
483 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800484 if (camera->setPreviewDisplay(surface) != NO_ERROR) {
485 jniThrowException(env, "java/io/IOException", "setPreviewDisplay failed");
486 }
487}
488
Jamie Gennisfd6f39e2010-12-20 12:15:00 -0800489static void android_hardware_Camera_setPreviewTexture(JNIEnv *env,
490 jobject thiz, jobject jSurfaceTexture)
491{
492 LOGV("setPreviewTexture");
493 sp<Camera> camera = get_native_camera(env, thiz, NULL);
494 if (camera == 0) return;
495
496 sp<SurfaceTexture> surfaceTexture = NULL;
497 if (jSurfaceTexture != NULL) {
498 surfaceTexture = reinterpret_cast<SurfaceTexture*>(env->GetIntField(
499 jSurfaceTexture, fields.surfaceTexture));
500 }
501 if (camera->setPreviewTexture(surfaceTexture) != NO_ERROR) {
502 jniThrowException(env, "java/io/IOException",
503 "setPreviewTexture failed");
504 }
505}
506
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800507static void android_hardware_Camera_startPreview(JNIEnv *env, jobject thiz)
508{
509 LOGV("startPreview");
510 sp<Camera> camera = get_native_camera(env, thiz, NULL);
511 if (camera == 0) return;
512
513 if (camera->startPreview() != NO_ERROR) {
Elliott Hughes69a017b2011-04-08 14:10:28 -0700514 jniThrowRuntimeException(env, "startPreview failed");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800515 return;
516 }
517}
518
519static void android_hardware_Camera_stopPreview(JNIEnv *env, jobject thiz)
520{
521 LOGV("stopPreview");
522 sp<Camera> c = get_native_camera(env, thiz, NULL);
523 if (c == 0) return;
524
525 c->stopPreview();
526}
527
528static bool android_hardware_Camera_previewEnabled(JNIEnv *env, jobject thiz)
529{
530 LOGV("previewEnabled");
531 sp<Camera> c = get_native_camera(env, thiz, NULL);
532 if (c == 0) return false;
533
534 return c->previewEnabled();
535}
536
Andrew Harp94927df2009-10-20 01:47:05 -0400537static void android_hardware_Camera_setHasPreviewCallback(JNIEnv *env, jobject thiz, jboolean installed, jboolean manualBuffer)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800538{
Andrew Harp94927df2009-10-20 01:47:05 -0400539 LOGV("setHasPreviewCallback: installed:%d, manualBuffer:%d", (int)installed, (int)manualBuffer);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800540 // Important: Only install preview_callback if the Java code has called
541 // setPreviewCallback() with a non-null value, otherwise we'd pay to memcpy
542 // each preview frame for nothing.
Dave Sparks5e271152009-06-23 17:30:11 -0700543 JNICameraContext* context;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800544 sp<Camera> camera = get_native_camera(env, thiz, &context);
545 if (camera == 0) return;
546
Andrew Harp94927df2009-10-20 01:47:05 -0400547 // setCallbackMode will take care of setting the context flags and calling
548 // camera->setPreviewCallbackFlags within a mutex for us.
549 context->setCallbackMode(env, installed, manualBuffer);
550}
551
James Donge00cab72011-02-17 16:38:06 -0800552static void android_hardware_Camera_addCallbackBuffer(JNIEnv *env, jobject thiz, jbyteArray bytes, int msgType) {
553 LOGV("addCallbackBuffer: 0x%x", msgType);
Andrew Harp94927df2009-10-20 01:47:05 -0400554
555 JNICameraContext* context = reinterpret_cast<JNICameraContext*>(env->GetIntField(thiz, fields.context));
556
557 if (context != NULL) {
James Donge00cab72011-02-17 16:38:06 -0800558 context->addCallbackBuffer(env, bytes, msgType);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800559 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800560}
561
562static void android_hardware_Camera_autoFocus(JNIEnv *env, jobject thiz)
563{
564 LOGV("autoFocus");
Dave Sparks5e271152009-06-23 17:30:11 -0700565 JNICameraContext* context;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800566 sp<Camera> c = get_native_camera(env, thiz, &context);
567 if (c == 0) return;
568
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800569 if (c->autoFocus() != NO_ERROR) {
Elliott Hughes69a017b2011-04-08 14:10:28 -0700570 jniThrowRuntimeException(env, "autoFocus failed");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800571 }
572}
573
Chih-Chung Chang244f8c22009-09-15 14:51:56 +0800574static void android_hardware_Camera_cancelAutoFocus(JNIEnv *env, jobject thiz)
575{
576 LOGV("cancelAutoFocus");
577 JNICameraContext* context;
578 sp<Camera> c = get_native_camera(env, thiz, &context);
579 if (c == 0) return;
580
581 if (c->cancelAutoFocus() != NO_ERROR) {
Elliott Hughes69a017b2011-04-08 14:10:28 -0700582 jniThrowRuntimeException(env, "cancelAutoFocus failed");
Chih-Chung Chang244f8c22009-09-15 14:51:56 +0800583 }
584}
585
James Donge00cab72011-02-17 16:38:06 -0800586static void android_hardware_Camera_takePicture(JNIEnv *env, jobject thiz, int msgType)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800587{
588 LOGV("takePicture");
Dave Sparks5e271152009-06-23 17:30:11 -0700589 JNICameraContext* context;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800590 sp<Camera> camera = get_native_camera(env, thiz, &context);
591 if (camera == 0) return;
592
James Donge00cab72011-02-17 16:38:06 -0800593 /*
594 * When CAMERA_MSG_RAW_IMAGE is requested, if the raw image callback
595 * buffer is available, CAMERA_MSG_RAW_IMAGE is enabled to get the
596 * notification _and_ the data; otherwise, CAMERA_MSG_RAW_IMAGE_NOTIFY
597 * is enabled to receive the callback notification but no data.
598 *
599 * Note that CAMERA_MSG_RAW_IMAGE_NOTIFY is not exposed to the
600 * Java application.
601 */
602 if (msgType & CAMERA_MSG_RAW_IMAGE) {
603 LOGV("Enable raw image callback buffer");
604 if (!context->isRawImageCallbackBufferAvailable()) {
605 LOGV("Enable raw image notification, since no callback buffer exists");
606 msgType &= ~CAMERA_MSG_RAW_IMAGE;
607 msgType |= CAMERA_MSG_RAW_IMAGE_NOTIFY;
608 }
609 }
610
611 if (camera->takePicture(msgType) != NO_ERROR) {
Elliott Hughes69a017b2011-04-08 14:10:28 -0700612 jniThrowRuntimeException(env, "takePicture failed");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800613 return;
614 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800615}
616
617static void android_hardware_Camera_setParameters(JNIEnv *env, jobject thiz, jstring params)
618{
619 LOGV("setParameters");
620 sp<Camera> camera = get_native_camera(env, thiz, NULL);
621 if (camera == 0) return;
622
623 const jchar* str = env->GetStringCritical(params, 0);
624 String8 params8;
625 if (params) {
626 params8 = String8(str, env->GetStringLength(params));
627 env->ReleaseStringCritical(params, str);
628 }
629 if (camera->setParameters(params8) != NO_ERROR) {
Elliott Hughes69a017b2011-04-08 14:10:28 -0700630 jniThrowRuntimeException(env, "setParameters failed");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800631 return;
632 }
633}
634
635static jstring android_hardware_Camera_getParameters(JNIEnv *env, jobject thiz)
636{
637 LOGV("getParameters");
638 sp<Camera> camera = get_native_camera(env, thiz, NULL);
639 if (camera == 0) return 0;
640
641 return env->NewStringUTF(camera->getParameters().string());
642}
643
644static void android_hardware_Camera_reconnect(JNIEnv *env, jobject thiz)
645{
646 LOGV("reconnect");
647 sp<Camera> camera = get_native_camera(env, thiz, NULL);
648 if (camera == 0) return;
649
650 if (camera->reconnect() != NO_ERROR) {
651 jniThrowException(env, "java/io/IOException", "reconnect failed");
652 return;
653 }
654}
655
Wu-cheng Liffe1cf22009-09-10 16:49:17 +0800656static void android_hardware_Camera_lock(JNIEnv *env, jobject thiz)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800657{
658 LOGV("lock");
659 sp<Camera> camera = get_native_camera(env, thiz, NULL);
Wu-cheng Liffe1cf22009-09-10 16:49:17 +0800660 if (camera == 0) return;
661
662 if (camera->lock() != NO_ERROR) {
Elliott Hughes69a017b2011-04-08 14:10:28 -0700663 jniThrowRuntimeException(env, "lock failed");
Wu-cheng Liffe1cf22009-09-10 16:49:17 +0800664 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800665}
666
Wu-cheng Liffe1cf22009-09-10 16:49:17 +0800667static void android_hardware_Camera_unlock(JNIEnv *env, jobject thiz)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800668{
669 LOGV("unlock");
670 sp<Camera> camera = get_native_camera(env, thiz, NULL);
Wu-cheng Liffe1cf22009-09-10 16:49:17 +0800671 if (camera == 0) return;
672
673 if (camera->unlock() != NO_ERROR) {
Elliott Hughes69a017b2011-04-08 14:10:28 -0700674 jniThrowRuntimeException(env, "unlock failed");
Wu-cheng Liffe1cf22009-09-10 16:49:17 +0800675 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800676}
677
Wu-cheng Li36f68b82009-09-28 16:14:58 -0700678static void android_hardware_Camera_startSmoothZoom(JNIEnv *env, jobject thiz, jint value)
679{
Joe Onoratof5d95cb2010-01-07 21:48:32 -0500680 LOGV("startSmoothZoom");
Wu-cheng Li36f68b82009-09-28 16:14:58 -0700681 sp<Camera> camera = get_native_camera(env, thiz, NULL);
682 if (camera == 0) return;
683
Wu-cheng Li0ca25192010-03-29 16:21:12 +0800684 status_t rc = camera->sendCommand(CAMERA_CMD_START_SMOOTH_ZOOM, value, 0);
685 if (rc == BAD_VALUE) {
686 char msg[64];
687 sprintf(msg, "invalid zoom value=%d", value);
688 jniThrowException(env, "java/lang/IllegalArgumentException", msg);
689 } else if (rc != NO_ERROR) {
Elliott Hughes69a017b2011-04-08 14:10:28 -0700690 jniThrowRuntimeException(env, "start smooth zoom failed");
Wu-cheng Li36f68b82009-09-28 16:14:58 -0700691 }
692}
693
694static void android_hardware_Camera_stopSmoothZoom(JNIEnv *env, jobject thiz)
695{
Joe Onoratof5d95cb2010-01-07 21:48:32 -0500696 LOGV("stopSmoothZoom");
Wu-cheng Li36f68b82009-09-28 16:14:58 -0700697 sp<Camera> camera = get_native_camera(env, thiz, NULL);
698 if (camera == 0) return;
699
700 if (camera->sendCommand(CAMERA_CMD_STOP_SMOOTH_ZOOM, 0, 0) != NO_ERROR) {
Elliott Hughes69a017b2011-04-08 14:10:28 -0700701 jniThrowRuntimeException(env, "stop smooth zoom failed");
Wu-cheng Li36f68b82009-09-28 16:14:58 -0700702 }
703}
704
Chih-Chung Changd1d77062010-01-22 17:49:48 -0800705static void android_hardware_Camera_setDisplayOrientation(JNIEnv *env, jobject thiz,
706 jint value)
707{
708 LOGV("setDisplayOrientation");
709 sp<Camera> camera = get_native_camera(env, thiz, NULL);
710 if (camera == 0) return;
711
712 if (camera->sendCommand(CAMERA_CMD_SET_DISPLAY_ORIENTATION, value, 0) != NO_ERROR) {
Elliott Hughes69a017b2011-04-08 14:10:28 -0700713 jniThrowRuntimeException(env, "set display orientation failed");
Chih-Chung Changd1d77062010-01-22 17:49:48 -0800714 }
715}
716
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800717static void android_hardware_Camera_startFaceDetection(JNIEnv *env, jobject thiz,
718 jint type, jobjectArray face)
719{
720 LOGV("startFaceDetection");
721 JNICameraContext* context;
722 sp<Camera> camera = get_native_camera(env, thiz, &context);
723 if (camera == 0) return;
724
725 status_t rc = camera->sendCommand(CAMERA_CMD_START_FACE_DETECTION, type, 0);
726 if (rc == BAD_VALUE) {
727 char msg[64];
728 snprintf(msg, sizeof(msg), "invalid face detection type=%d", type);
729 jniThrowException(env, "java/lang/IllegalArgumentException", msg);
730 } else if (rc != NO_ERROR) {
731 jniThrowRuntimeException(env, "start face detection failed");
732 }
733}
734
735static void android_hardware_Camera_stopFaceDetection(JNIEnv *env, jobject thiz)
736{
737 LOGV("stopFaceDetection");
738 sp<Camera> camera = get_native_camera(env, thiz, NULL);
739 if (camera == 0) return;
740
741 if (camera->sendCommand(CAMERA_CMD_STOP_FACE_DETECTION, 0, 0) != NO_ERROR) {
742 jniThrowRuntimeException(env, "stop face detection failed");
743 }
744}
745
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800746//-------------------------------------------------
747
748static JNINativeMethod camMethods[] = {
Chih-Chung Change25cc652010-05-06 16:36:58 +0800749 { "getNumberOfCameras",
750 "()I",
751 (void *)android_hardware_Camera_getNumberOfCameras },
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800752 { "getCameraInfo",
753 "(ILandroid/hardware/Camera$CameraInfo;)V",
754 (void*)android_hardware_Camera_getCameraInfo },
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800755 { "native_setup",
Chih-Chung Change25cc652010-05-06 16:36:58 +0800756 "(Ljava/lang/Object;I)V",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800757 (void*)android_hardware_Camera_native_setup },
758 { "native_release",
759 "()V",
760 (void*)android_hardware_Camera_release },
761 { "setPreviewDisplay",
762 "(Landroid/view/Surface;)V",
763 (void *)android_hardware_Camera_setPreviewDisplay },
Jamie Gennisfd6f39e2010-12-20 12:15:00 -0800764 { "setPreviewTexture",
765 "(Landroid/graphics/SurfaceTexture;)V",
766 (void *)android_hardware_Camera_setPreviewTexture },
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800767 { "startPreview",
768 "()V",
769 (void *)android_hardware_Camera_startPreview },
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800770 { "_stopPreview",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800771 "()V",
772 (void *)android_hardware_Camera_stopPreview },
773 { "previewEnabled",
774 "()Z",
775 (void *)android_hardware_Camera_previewEnabled },
776 { "setHasPreviewCallback",
777 "(ZZ)V",
778 (void *)android_hardware_Camera_setHasPreviewCallback },
James Donge00cab72011-02-17 16:38:06 -0800779 { "_addCallbackBuffer",
780 "([BI)V",
Andrew Harp94927df2009-10-20 01:47:05 -0400781 (void *)android_hardware_Camera_addCallbackBuffer },
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800782 { "native_autoFocus",
783 "()V",
784 (void *)android_hardware_Camera_autoFocus },
Chih-Chung Chang244f8c22009-09-15 14:51:56 +0800785 { "native_cancelAutoFocus",
786 "()V",
787 (void *)android_hardware_Camera_cancelAutoFocus },
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800788 { "native_takePicture",
James Donge00cab72011-02-17 16:38:06 -0800789 "(I)V",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800790 (void *)android_hardware_Camera_takePicture },
791 { "native_setParameters",
792 "(Ljava/lang/String;)V",
793 (void *)android_hardware_Camera_setParameters },
794 { "native_getParameters",
795 "()Ljava/lang/String;",
796 (void *)android_hardware_Camera_getParameters },
797 { "reconnect",
798 "()V",
799 (void*)android_hardware_Camera_reconnect },
800 { "lock",
Wu-cheng Liffe1cf22009-09-10 16:49:17 +0800801 "()V",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800802 (void*)android_hardware_Camera_lock },
803 { "unlock",
Wu-cheng Liffe1cf22009-09-10 16:49:17 +0800804 "()V",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800805 (void*)android_hardware_Camera_unlock },
Wu-cheng Li36f68b82009-09-28 16:14:58 -0700806 { "startSmoothZoom",
807 "(I)V",
808 (void *)android_hardware_Camera_startSmoothZoom },
809 { "stopSmoothZoom",
810 "()V",
811 (void *)android_hardware_Camera_stopSmoothZoom },
Chih-Chung Changd1d77062010-01-22 17:49:48 -0800812 { "setDisplayOrientation",
813 "(I)V",
814 (void *)android_hardware_Camera_setDisplayOrientation },
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800815 { "_startFaceDetection",
816 "(I)V",
817 (void *)android_hardware_Camera_startFaceDetection },
818 { "_stopFaceDetection",
819 "()V",
820 (void *)android_hardware_Camera_stopFaceDetection},
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800821};
822
823struct field {
824 const char *class_name;
825 const char *field_name;
826 const char *field_type;
827 jfieldID *jfield;
828};
829
830static int find_fields(JNIEnv *env, field *fields, int count)
831{
832 for (int i = 0; i < count; i++) {
833 field *f = &fields[i];
834 jclass clazz = env->FindClass(f->class_name);
835 if (clazz == NULL) {
836 LOGE("Can't find %s", f->class_name);
837 return -1;
838 }
839
840 jfieldID field = env->GetFieldID(clazz, f->field_name, f->field_type);
841 if (field == NULL) {
842 LOGE("Can't find %s.%s", f->class_name, f->field_name);
843 return -1;
844 }
845
846 *(f->jfield) = field;
847 }
848
849 return 0;
850}
851
852// Get all the required offsets in java class and register native functions
853int register_android_hardware_Camera(JNIEnv *env)
854{
855 field fields_to_find[] = {
856 { "android/hardware/Camera", "mNativeContext", "I", &fields.context },
Chih-Chung Changb8bb78f2010-06-10 13:32:16 +0800857 { "android/view/Surface", ANDROID_VIEW_SURFACE_JNI_ID, "I", &fields.surface },
Jamie Gennisfd6f39e2010-12-20 12:15:00 -0800858 { "android/graphics/SurfaceTexture",
859 ANDROID_GRAPHICS_SURFACETEXTURE_JNI_ID, "I", &fields.surfaceTexture },
Wu-cheng Li3fd5fa42010-09-15 16:06:20 -0700860 { "android/hardware/Camera$CameraInfo", "facing", "I", &fields.facing },
861 { "android/hardware/Camera$CameraInfo", "orientation", "I", &fields.orientation },
Wu-cheng Lif0d6a482011-07-28 05:30:59 +0800862 { "android/hardware/Camera$Face", "rect", "Landroid/graphics/Rect;", &fields.face_rect },
863 { "android/hardware/Camera$Face", "score", "I", &fields.face_score },
Wu-cheng Li4c2292e2011-07-22 02:37:11 +0800864 { "android/graphics/Rect", "left", "I", &fields.rect_left },
865 { "android/graphics/Rect", "top", "I", &fields.rect_top },
866 { "android/graphics/Rect", "right", "I", &fields.rect_right },
867 { "android/graphics/Rect", "bottom", "I", &fields.rect_bottom },
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800868 };
869
870 if (find_fields(env, fields_to_find, NELEM(fields_to_find)) < 0)
871 return -1;
872
873 jclass clazz = env->FindClass("android/hardware/Camera");
874 fields.post_event = env->GetStaticMethodID(clazz, "postEventFromNative",
875 "(Ljava/lang/Object;IIILjava/lang/Object;)V");
876 if (fields.post_event == NULL) {
877 LOGE("Can't find android/hardware/Camera.postEventFromNative");
878 return -1;
879 }
880
881
882 // Register native functions
883 return AndroidRuntime::registerNativeMethods(env, "android/hardware/Camera",
884 camMethods, NELEM(camMethods));
885}