Fix 2083478: Camera needs an auto-focus cancel API

Change-Id: I13bda991b32aee47e82b5cf9d43b3021c416a9a2
This commit is contained in:
Chih-Chung Chang
2009-09-15 14:51:56 +08:00
parent 54c06152e0
commit 244f8c2636
11 changed files with 94 additions and 3 deletions

View File

@@ -265,6 +265,11 @@ status_t CameraHardwareStub::autoFocus()
return NO_ERROR;
}
status_t CameraHardwareStub::cancelAutoFocus()
{
return NO_ERROR;
}
/*static*/ int CameraHardwareStub::beginPictureThread(void *cookie)
{
CameraHardwareStub *c = (CameraHardwareStub *)cookie;

View File

@@ -51,6 +51,7 @@ public:
virtual void releaseRecordingFrame(const sp<IMemory>& mem);
virtual status_t autoFocus();
virtual status_t cancelAutoFocus();
virtual status_t takePicture();
virtual status_t cancelPicture();
virtual status_t dump(int fd, const Vector<String16>& args) const;

View File

@@ -798,7 +798,6 @@ static void dump_to_file(const char *fname,
}
#endif
// take a picture - image is returned in callback
status_t CameraService::Client::autoFocus()
{
LOGD("autoFocus (pid %d)", getCallingPid());
@@ -815,6 +814,22 @@ status_t CameraService::Client::autoFocus()
return mHardware->autoFocus();
}
status_t CameraService::Client::cancelAutoFocus()
{
LOGD("cancelAutoFocus (pid %d)", getCallingPid());
Mutex::Autolock lock(mLock);
status_t result = checkPid();
if (result != NO_ERROR) return result;
if (mHardware == 0) {
LOGE("mHardware is NULL, returning.");
return INVALID_OPERATION;
}
return mHardware->cancelAutoFocus();
}
// take a picture - image is returned in callback
status_t CameraService::Client::takePicture()
{

View File

@@ -110,6 +110,9 @@ private:
// auto focus
virtual status_t autoFocus();
// cancel auto focus
virtual status_t cancelAutoFocus();
// take a picture - returns an IMemory (ref-counted mmap)
virtual status_t takePicture();

View File

@@ -382,6 +382,20 @@ public class Camera {
}
private native final void native_autoFocus();
/**
* Cancels auto-focus function. If the auto-focus is still in progress,
* this function will cancel it. Whether the auto-focus is in progress
* or not, this function will return the focus position to the default.
* If the camera does not support auto-focus, this is a no-op.
* @hide
*/
public final void cancelAutoFocus()
{
mAutoFocusCallback = null;
native_cancelAutoFocus();
}
private native final void native_cancelAutoFocus();
/**
* An interface which contains a callback for the shutter closing after taking a picture.
*/
@@ -1338,5 +1352,3 @@ public class Camera {
}
};
}

View File

@@ -327,6 +327,18 @@ static void android_hardware_Camera_autoFocus(JNIEnv *env, jobject thiz)
}
}
static void android_hardware_Camera_cancelAutoFocus(JNIEnv *env, jobject thiz)
{
LOGV("cancelAutoFocus");
JNICameraContext* context;
sp<Camera> c = get_native_camera(env, thiz, &context);
if (c == 0) return;
if (c->cancelAutoFocus() != NO_ERROR) {
jniThrowException(env, "java/lang/RuntimeException", "cancelAutoFocus failed");
}
}
static void android_hardware_Camera_takePicture(JNIEnv *env, jobject thiz)
{
LOGV("takePicture");
@@ -422,6 +434,9 @@ static JNINativeMethod camMethods[] = {
{ "native_autoFocus",
"()V",
(void *)android_hardware_Camera_autoFocus },
{ "native_cancelAutoFocus",
"()V",
(void *)android_hardware_Camera_cancelAutoFocus },
{ "native_takePicture",
"()V",
(void *)android_hardware_Camera_takePicture },

View File

@@ -143,6 +143,9 @@ public:
// autoFocus - status returned from callback
status_t autoFocus();
// cancel auto focus
status_t cancelAutoFocus();
// take a picture - picture returned from callback
status_t takePicture();

View File

@@ -160,6 +160,14 @@ public:
*/
virtual status_t autoFocus() = 0;
/**
* Cancels auto-focus function. If the auto-focus is still in progress,
* this function will cancel it. Whether the auto-focus is in progress
* or not, this function will return the focus position to the default.
* If the camera does not support auto-focus, this is a no-op.
*/
virtual status_t cancelAutoFocus() = 0;
/**
* Take a picture.
*/

View File

@@ -76,6 +76,9 @@ public:
// auto focus
virtual status_t autoFocus() = 0;
// cancel auto focus
virtual status_t cancelAutoFocus() = 0;
// take a picture
virtual status_t takePicture() = 0;

View File

@@ -242,6 +242,14 @@ status_t Camera::autoFocus()
return c->autoFocus();
}
status_t Camera::cancelAutoFocus()
{
LOGV("cancelAutoFocus");
sp <ICamera> c = mCamera;
if (c == 0) return NO_INIT;
return c->cancelAutoFocus();
}
// take a picture
status_t Camera::takePicture()
{

View File

@@ -32,6 +32,7 @@ enum {
START_PREVIEW,
STOP_PREVIEW,
AUTO_FOCUS,
CANCEL_AUTO_FOCUS,
TAKE_PICTURE,
SET_PARAMETERS,
GET_PARAMETERS,
@@ -162,6 +163,17 @@ public:
return ret;
}
// cancel focus
status_t cancelAutoFocus()
{
LOGV("cancelAutoFocus");
Parcel data, reply;
data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
remote()->transact(CANCEL_AUTO_FOCUS, data, &reply);
status_t ret = reply.readInt32();
return ret;
}
// take a picture - returns an IMemory (ref-counted mmap)
status_t takePicture()
{
@@ -294,6 +306,12 @@ status_t BnCamera::onTransact(
reply->writeInt32(autoFocus());
return NO_ERROR;
} break;
case CANCEL_AUTO_FOCUS: {
LOGV("CANCEL_AUTO_FOCUS");
CHECK_INTERFACE(ICamera, data, reply);
reply->writeInt32(cancelAutoFocus());
return NO_ERROR;
} break;
case TAKE_PICTURE: {
LOGV("TAKE_PICTURE");
CHECK_INTERFACE(ICamera, data, reply);