diff options
author | Igor Murashkin <iam@google.com> | 2014-06-17 12:03:20 -0700 |
---|---|---|
committer | Igor Murashkin <iam@google.com> | 2014-06-17 15:09:16 -0700 |
commit | 65d14b9825311f9d1847cf282bd0419e71bac666 (patch) | |
tree | d9e217cd626f62010b17274929e8425f59e5c09a | |
parent | 3a227969f604d7c6a24a795661a13f70a5f37e1f (diff) | |
download | frameworks_av-65d14b9825311f9d1847cf282bd0419e71bac666.zip frameworks_av-65d14b9825311f9d1847cf282bd0419e71bac666.tar.gz frameworks_av-65d14b9825311f9d1847cf282bd0419e71bac666.tar.bz2 |
camera: Add #getLegacyParameters, #supportsCameraApi to ICameraService
Change-Id: Ic86c8df3d703e7cf89caa856387e2c0a1b977401
-rw-r--r-- | camera/ICameraService.cpp | 59 | ||||
-rw-r--r-- | include/camera/ICameraService.h | 20 | ||||
-rw-r--r-- | services/camera/libcameraservice/CameraService.cpp | 151 | ||||
-rw-r--r-- | services/camera/libcameraservice/CameraService.h | 17 |
4 files changed, 224 insertions, 23 deletions
diff --git a/camera/ICameraService.cpp b/camera/ICameraService.cpp index b86651f..79c33f9 100644 --- a/camera/ICameraService.cpp +++ b/camera/ICameraService.cpp @@ -18,6 +18,7 @@ #define LOG_TAG "BpCameraService" #include <utils/Log.h> #include <utils/Errors.h> +#include <utils/String16.h> #include <stdint.h> #include <sys/types.h> @@ -253,6 +254,41 @@ public: if (readExceptionCode(reply)) return -EPROTO; return reply.readInt32(); } + + virtual status_t getLegacyParameters(int cameraId, String16* parameters) { + if (parameters == NULL) { + ALOGE("%s: parameters must not be null", __FUNCTION__); + return BAD_VALUE; + } + + Parcel data, reply; + + data.writeInt32(cameraId); + remote()->transact(BnCameraService::GET_LEGACY_PARAMETERS, data, &reply); + if (readExceptionCode(reply)) return -EPROTO; + + status_t res = data.readInt32(); + int32_t length = data.readInt32(); // -1 means null + if (length > 0) { + *parameters = data.readString16(); + } else { + *parameters = String16(); + } + + return res; + } + + virtual status_t supportsCameraApi(int cameraId, int apiVersion) { + Parcel data, reply; + + data.writeInt32(cameraId); + data.writeInt32(apiVersion); + remote()->transact(BnCameraService::SUPPORTS_CAMERA_API, data, &reply); + if (readExceptionCode(reply)) return -EPROTO; + + status_t res = data.readInt32(); + return res; + } }; IMPLEMENT_META_INTERFACE(CameraService, "android.hardware.ICameraService"); @@ -387,6 +423,29 @@ status_t BnCameraService::onTransact( reply->writeInt32(removeListener(listener)); return NO_ERROR; } break; + case GET_LEGACY_PARAMETERS: { + CHECK_INTERFACE(ICameraService, data, reply); + int cameraId = data.readInt32(); + String16 parameters; + + reply->writeNoException(); + // return value + reply->writeInt32(getLegacyParameters(cameraId, ¶meters)); + // out parameters + reply->writeInt32(1); // parameters is always available + reply->writeString16(parameters); + return NO_ERROR; + } break; + case SUPPORTS_CAMERA_API: { + CHECK_INTERFACE(ICameraService, data, reply); + int cameraId = data.readInt32(); + int apiVersion = data.readInt32(); + + reply->writeNoException(); + // return value + reply->writeInt32(supportsCameraApi(cameraId, apiVersion)); + return NO_ERROR; + } break; default: return BBinder::onTransact(code, data, reply, flags); } diff --git a/include/camera/ICameraService.h b/include/camera/ICameraService.h index 6e48f22..d7e5dac 100644 --- a/include/camera/ICameraService.h +++ b/include/camera/ICameraService.h @@ -32,6 +32,7 @@ class ICameraDeviceUser; class ICameraDeviceCallbacks; class CameraMetadata; class VendorTagDescriptor; +class String16; class ICameraService : public IInterface { @@ -49,12 +50,19 @@ public: REMOVE_LISTENER, GET_CAMERA_CHARACTERISTICS, GET_CAMERA_VENDOR_TAG_DESCRIPTOR, + GET_LEGACY_PARAMETERS, + SUPPORTS_CAMERA_API, }; enum { USE_CALLING_UID = -1 }; + enum { + API_VERSION_1 = 1, + API_VERSION_2 = 2, + }; + public: DECLARE_META_INTERFACE(CameraService); @@ -105,6 +113,18 @@ public: int clientUid, /*out*/ sp<ICameraDeviceUser>& device) = 0; + + virtual status_t getLegacyParameters( + int cameraId, + /*out*/ + String16* parameters) = 0; + + /** + * Returns OK if device supports camera2 api, + * returns -EOPNOTSUPP if it doesn't. + */ + virtual status_t supportsCameraApi( + int cameraId, int apiVersion) = 0; }; // ---------------------------------------------------------------------------- diff --git a/services/camera/libcameraservice/CameraService.cpp b/services/camera/libcameraservice/CameraService.cpp index 280478c..18299dc 100644 --- a/services/camera/libcameraservice/CameraService.cpp +++ b/services/camera/libcameraservice/CameraService.cpp @@ -261,35 +261,20 @@ status_t CameraService::generateShimMetadata(int cameraId, /*out*/CameraMetadata return ret; } - ssize_t index = -1; - { // Scope for service lock - Mutex::Autolock lock(mServiceLock); - index = mShimParams.indexOfKey(cameraId); - // Release service lock so initializeShimMetadata can be called correctly. - } - - if (index < 0) { - int64_t token = IPCThreadState::self()->clearCallingIdentity(); - ret = initializeShimMetadata(cameraId); - IPCThreadState::self()->restoreCallingIdentity(token); - if (ret != OK) { - return ret; - } + CameraParameters shimParams; + if ((ret = getLegacyParametersLazy(cameraId, /*out*/&shimParams)) != OK) { + // Error logged by callee + return ret; } Vector<Size> sizes; Vector<Size> jpegSizes; Vector<int32_t> formats; const char* supportedPreviewFormats; - { // Scope for service lock - Mutex::Autolock lock(mServiceLock); - index = mShimParams.indexOfKey(cameraId); - - mShimParams[index].getSupportedPreviewSizes(/*out*/sizes); - - mShimParams[index].getSupportedPreviewFormats(/*out*/formats); - - mShimParams[index].getSupportedPictureSizes(/*out*/jpegSizes); + { + shimParams.getSupportedPreviewSizes(/*out*/sizes); + shimParams.getSupportedPreviewFormats(/*out*/formats); + shimParams.getSupportedPictureSizes(/*out*/jpegSizes); } // Always include IMPLEMENTATION_DEFINED @@ -481,6 +466,7 @@ status_t CameraService::initializeShimMetadata(int cameraId) { int uid = getCallingUid(); status_t ret = validateConnect(cameraId, uid); if (ret != OK) { + // Error already logged by callee return ret; } @@ -503,6 +489,7 @@ status_t CameraService::initializeShimMetadata(int cameraId) { client); if (ret != OK) { + // Error already logged by callee return ret; } } @@ -524,6 +511,52 @@ status_t CameraService::initializeShimMetadata(int cameraId) { return OK; } +status_t CameraService::getLegacyParametersLazy(int cameraId, + /*out*/ + CameraParameters* parameters) { + + ALOGV("%s: for cameraId: %d", __FUNCTION__, cameraId); + + status_t ret = 0; + + if (parameters == NULL) { + ALOGE("%s: parameters must not be null", __FUNCTION__); + return BAD_VALUE; + } + + ssize_t index = -1; + { // Scope for service lock + Mutex::Autolock lock(mServiceLock); + index = mShimParams.indexOfKey(cameraId); + // Release service lock so initializeShimMetadata can be called correctly. + + if (index >= 0) { + *parameters = mShimParams[index]; + } + } + + if (index < 0) { + int64_t token = IPCThreadState::self()->clearCallingIdentity(); + ret = initializeShimMetadata(cameraId); + IPCThreadState::self()->restoreCallingIdentity(token); + if (ret != OK) { + // Error already logged by callee + return ret; + } + + { // Scope for service lock + Mutex::Autolock lock(mServiceLock); + index = mShimParams.indexOfKey(cameraId); + + LOG_ALWAYS_FATAL_IF(index < 0, "index should have been initialized"); + + *parameters = mShimParams[index]; + } + } + + return OK; +} + status_t CameraService::validateConnect(int cameraId, /*inout*/ int& clientUid) const { @@ -961,6 +994,78 @@ status_t CameraService::removeListener( return BAD_VALUE; } +status_t CameraService::getLegacyParameters( + int cameraId, + /*out*/ + String16* parameters) { + ALOGV("%s: for camera ID = %d", __FUNCTION__, cameraId); + + if (parameters == NULL) { + ALOGE("%s: parameters must not be null", __FUNCTION__); + return BAD_VALUE; + } + + status_t ret = 0; + + CameraParameters shimParams; + if ((ret = getLegacyParametersLazy(cameraId, /*out*/&shimParams)) != OK) { + // Error logged by caller + return ret; + } + + String8 shimParamsString8 = shimParams.flatten(); + String16 shimParamsString16 = String16(shimParamsString8); + + *parameters = shimParamsString16; + + return OK; +} + +status_t CameraService::supportsCameraApi(int cameraId, int apiVersion) { + ALOGV("%s: for camera ID = %d", __FUNCTION__, cameraId); + + switch (apiVersion) { + case API_VERSION_1: + case API_VERSION_2: + break; + default: + ALOGE("%s: Bad API version %d", __FUNCTION__, apiVersion); + return BAD_VALUE; + } + + int facing = -1; + int deviceVersion = getDeviceVersion(cameraId, &facing); + + switch(deviceVersion) { + case CAMERA_DEVICE_API_VERSION_1_0: + case CAMERA_DEVICE_API_VERSION_2_0: + case CAMERA_DEVICE_API_VERSION_2_1: + case CAMERA_DEVICE_API_VERSION_3_0: + case CAMERA_DEVICE_API_VERSION_3_1: + if (apiVersion == API_VERSION_2) { + ALOGV("%s: Camera id %d uses HAL prior to HAL3.2, doesn't support api2 without shim", + __FUNCTION__, cameraId); + return -EOPNOTSUPP; + } else { // if (apiVersion == API_VERSION_1) { + ALOGV("%s: Camera id %d uses older HAL before 3.2, but api1 is always supported", + __FUNCTION__, cameraId); + return OK; + } + case CAMERA_DEVICE_API_VERSION_3_2: + ALOGV("%s: Camera id %d uses HAL3.2 or newer, supports api1/api2 directly", + __FUNCTION__, cameraId); + return OK; + case -1: + ALOGE("%s: Invalid camera id %d", __FUNCTION__, cameraId); + return BAD_VALUE; + default: + ALOGE("%s: Unknown camera device HAL version: %d", __FUNCTION__, deviceVersion); + return INVALID_OPERATION; + } + + return OK; +} + void CameraService::removeClientByRemote(const wp<IBinder>& remoteBinder) { int callingPid = getCallingPid(); LOG1("CameraService::removeClientByRemote E (pid %d)", callingPid); diff --git a/services/camera/libcameraservice/CameraService.h b/services/camera/libcameraservice/CameraService.h index ee39d52..b2b65b8 100644 --- a/services/camera/libcameraservice/CameraService.h +++ b/services/camera/libcameraservice/CameraService.h @@ -100,6 +100,15 @@ public: virtual status_t removeListener( const sp<ICameraServiceListener>& listener); + virtual status_t getLegacyParameters( + int cameraId, + /*out*/ + String16* parameters); + + // OK = supports api of that version, -EOPNOTSUPP = does not support + virtual status_t supportsCameraApi( + int cameraId, int apiVersion); + // Extra permissions checks virtual status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags); @@ -414,6 +423,14 @@ private: status_t initializeShimMetadata(int cameraId); /** + * Get the cached CameraParameters for the camera. If they haven't been + * cached yet, then initialize them for the first time. + * + * Returns OK on success, or a negative error code. + */ + status_t getLegacyParametersLazy(int cameraId, /*out*/CameraParameters* parameters); + + /** * Generate the CameraCharacteristics metadata required by the Camera2 API * from the available HAL1 CameraParameters and CameraInfo. * |