From e6a550d02ff02f465d7dbb6e862671462866f024 Mon Sep 17 00:00:00 2001 From: Wu-cheng Li Date: Mon, 28 Sep 2009 16:14:58 -0700 Subject: [PATCH] Add zoom functions and sendCommand. b2060030 --- .../libcameraservice/CameraHardwareStub.cpp | 6 ++++++ camera/libcameraservice/CameraHardwareStub.h | 2 ++ camera/libcameraservice/CameraService.cpp | 21 ++++++++++++++++--- camera/libcameraservice/CameraService.h | 3 +++ include/ui/Camera.h | 9 ++++++++ include/ui/CameraHardwareInterface.h | 9 ++++++-- include/ui/ICamera.h | 3 +++ libs/ui/Camera.cpp | 9 ++++++++ libs/ui/ICamera.cpp | 21 +++++++++++++++++++ 9 files changed, 78 insertions(+), 5 deletions(-) diff --git a/camera/libcameraservice/CameraHardwareStub.cpp b/camera/libcameraservice/CameraHardwareStub.cpp index 35f4846f9..8ad1f692b 100644 --- a/camera/libcameraservice/CameraHardwareStub.cpp +++ b/camera/libcameraservice/CameraHardwareStub.cpp @@ -368,6 +368,12 @@ CameraParameters CameraHardwareStub::getParameters() const return mParameters; } +status_t CameraHardwareStub::sendCommand(int32_t command, int32_t arg1, + int32_t arg2) +{ + return BAD_VALUE; +} + void CameraHardwareStub::release() { } diff --git a/camera/libcameraservice/CameraHardwareStub.h b/camera/libcameraservice/CameraHardwareStub.h index f957fa87a..8a6702495 100644 --- a/camera/libcameraservice/CameraHardwareStub.h +++ b/camera/libcameraservice/CameraHardwareStub.h @@ -57,6 +57,8 @@ public: virtual status_t dump(int fd, const Vector& args) const; virtual status_t setParameters(const CameraParameters& params); virtual CameraParameters getParameters() const; + virtual status_t sendCommand(int32_t command, int32_t arg1, + int32_t arg2); virtual void release(); static sp createInstance(); diff --git a/camera/libcameraservice/CameraService.cpp b/camera/libcameraservice/CameraService.cpp index bab7d086a..8279914f9 100644 --- a/camera/libcameraservice/CameraService.cpp +++ b/camera/libcameraservice/CameraService.cpp @@ -195,7 +195,7 @@ void CameraService::decUsers() { android_atomic_dec(&mUsers); } -static sp newMediaPlayer(const char *file) +static sp newMediaPlayer(const char *file) { sp mp = new MediaPlayer(); if (mp->setDataSource(file) == NO_ERROR) { @@ -267,7 +267,7 @@ status_t CameraService::Client::lock() status_t CameraService::Client::unlock() { int callingPid = getCallingPid(); - LOGD("unlock from pid %d (mClientPid %d)", callingPid, mClientPid); + LOGD("unlock from pid %d (mClientPid %d)", callingPid, mClientPid); Mutex::Autolock _l(mLock); // allow anyone to use camera status_t result = checkPid(); @@ -648,7 +648,7 @@ status_t CameraService::Client::startPreviewMode() status_t CameraService::Client::startPreview() { LOGD("startPreview (pid %d)", getCallingPid()); - + return startCameraMode(CAMERA_PREVIEW_MODE); } @@ -1134,6 +1134,21 @@ String8 CameraService::Client::getParameters() const return params; } +status_t CameraService::Client::sendCommand(int32_t cmd, int32_t arg1, int32_t arg2) +{ + LOGD("sendCommand (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->sendCommand(cmd, arg1, arg2); +} + void CameraService::Client::copyFrameAndPostCopiedFrame(sp heap, size_t offset, size_t size) { LOGV("copyFrameAndPostCopiedFrame"); diff --git a/camera/libcameraservice/CameraService.h b/camera/libcameraservice/CameraService.h index 0a909cf01..2e3597f11 100644 --- a/camera/libcameraservice/CameraService.h +++ b/camera/libcameraservice/CameraService.h @@ -122,6 +122,9 @@ private: // get preview/capture parameters - key/value pairs virtual String8 getParameters() const; + // send command to camera driver + virtual status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2); + // our client... const sp& getCameraClient() const { return mCameraClient; } diff --git a/include/ui/Camera.h b/include/ui/Camera.h index 9ceb8fd43..5219772a1 100644 --- a/include/ui/Camera.h +++ b/include/ui/Camera.h @@ -78,6 +78,12 @@ enum { CAMERA_MSG_ALL_MSGS = 0x1FF }; +// cmdType in sendCommand functions +enum { + CAMERA_CMD_START_SMOOTH_ZOOM = 1, + CAMERA_CMD_STOP_SMOOTH_ZOOM = 2, +}; + // camera fatal errors enum { CAMERA_ERROR_UKNOWN = 1, @@ -155,6 +161,9 @@ public: // get preview/capture parameters - key/value pairs String8 getParameters() const; + // send command to camera driver + status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2); + void setListener(const sp& listener); void setPreviewCallbackFlags(int preview_callback_flag); diff --git a/include/ui/CameraHardwareInterface.h b/include/ui/CameraHardwareInterface.h index 5fbb7d80c..af40f31ed 100644 --- a/include/ui/CameraHardwareInterface.h +++ b/include/ui/CameraHardwareInterface.h @@ -147,7 +147,7 @@ public: * Returns true if recording is enabled. */ virtual bool recordingEnabled() = 0; - + /** * Release a record frame previously returned by CAMERA_MSG_VIDEO_FRAME. */ @@ -185,12 +185,17 @@ public: /** Return the camera parameters. */ virtual CameraParameters getParameters() const = 0; + /** + * Send command to camera driver. + */ + virtual status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2) = 0; + /** * Release the hardware resources owned by this object. Note that this is * *not* done in the destructor. */ virtual void release() = 0; - + /** * Dump state of the camera hardware */ diff --git a/include/ui/ICamera.h b/include/ui/ICamera.h index 7595e36e5..564269139 100644 --- a/include/ui/ICamera.h +++ b/include/ui/ICamera.h @@ -87,6 +87,9 @@ public: // get preview/capture parameters - key/value pairs virtual String8 getParameters() const = 0; + + // send command to camera driver + virtual status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2) = 0; }; // ---------------------------------------------------------------------------- diff --git a/libs/ui/Camera.cpp b/libs/ui/Camera.cpp index 0c6d3408a..09a36f18a 100644 --- a/libs/ui/Camera.cpp +++ b/libs/ui/Camera.cpp @@ -278,6 +278,15 @@ String8 Camera::getParameters() const return params; } +// send command to camera driver +status_t Camera::sendCommand(int32_t cmd, int32_t arg1, int32_t arg2) +{ + LOGD("sendCommand"); + sp c = mCamera; + if (c == 0) return NO_INIT; + return c->sendCommand(cmd, arg1, arg2); +} + void Camera::setListener(const sp& listener) { Mutex::Autolock _l(mLock); diff --git a/libs/ui/ICamera.cpp b/libs/ui/ICamera.cpp index fd7e084d2..e1b3ec7fa 100644 --- a/libs/ui/ICamera.cpp +++ b/libs/ui/ICamera.cpp @@ -36,6 +36,7 @@ enum { TAKE_PICTURE, SET_PARAMETERS, GET_PARAMETERS, + SEND_COMMAND, CONNECT, LOCK, UNLOCK, @@ -205,6 +206,17 @@ public: remote()->transact(GET_PARAMETERS, data, &reply); return reply.readString8(); } + virtual status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2) + { + LOGD("sendCommand"); + Parcel data, reply; + data.writeInterfaceToken(ICamera::getInterfaceDescriptor()); + data.writeInt32(cmd); + data.writeInt32(arg1); + data.writeInt32(arg2); + remote()->transact(SEND_COMMAND, data, &reply); + return reply.readInt32(); + } virtual status_t connect(const sp& cameraClient) { Parcel data, reply; @@ -331,6 +343,15 @@ status_t BnCamera::onTransact( reply->writeString8(getParameters()); return NO_ERROR; } break; + case SEND_COMMAND: { + LOGD("SEND_COMMAND"); + CHECK_INTERFACE(ICamera, data, reply); + int command = data.readInt32(); + int arg1 = data.readInt32(); + int arg2 = data.readInt32(); + reply->writeInt32(sendCommand(command, arg1, arg2)); + return NO_ERROR; + } break; case CONNECT: { CHECK_INTERFACE(ICamera, data, reply); sp cameraClient = interface_cast(data.readStrongBinder());