summaryrefslogtreecommitdiffstats
path: root/services/camera/libcameraservice/common
diff options
context:
space:
mode:
authorChien-Yu Chen <cychen@google.com>2015-02-24 10:28:19 -0800
committerYin-Chia Yeh <yinchiayeh@google.com>2015-03-24 11:52:20 -0700
commit676b21b30edbd74d7b9aae247961a1ffde1b8993 (patch)
treeb75567ef13d0c3b235e94fcf3e38d576ab505f96 /services/camera/libcameraservice/common
parent0e4421286b92a81e952f53210227adbf05d97c25 (diff)
downloadframeworks_av-676b21b30edbd74d7b9aae247961a1ffde1b8993.zip
frameworks_av-676b21b30edbd74d7b9aae247961a1ffde1b8993.tar.gz
frameworks_av-676b21b30edbd74d7b9aae247961a1ffde1b8993.tar.bz2
camera: update CameraModule
1. Add more accessor methods to CameraModule to prevent exposing raw module pointer 2. Use KeyedVector to replace array Bug: 19897963 Change-Id: I111cc093f09f5fb3c4b13693d5d0687e1f441058
Diffstat (limited to 'services/camera/libcameraservice/common')
-rw-r--r--services/camera/libcameraservice/common/CameraModule.cpp50
-rw-r--r--services/camera/libcameraservice/common/CameraModule.h21
2 files changed, 47 insertions, 24 deletions
diff --git a/services/camera/libcameraservice/common/CameraModule.cpp b/services/camera/libcameraservice/common/CameraModule.cpp
index 5f767ad..50cece4 100644
--- a/services/camera/libcameraservice/common/CameraModule.cpp
+++ b/services/camera/libcameraservice/common/CameraModule.cpp
@@ -54,14 +54,12 @@ CameraModule::CameraModule(camera_module_t *module) {
}
mModule = module;
- for (int i = 0; i < MAX_CAMERAS_PER_MODULE; i++) {
- mCameraInfoCached[i] = false;
- }
+ mCameraInfoMap.setCapacity(getNumberOfCameras());
}
int CameraModule::getCameraInfo(int cameraId, struct camera_info *info) {
Mutex::Autolock lock(mCameraInfoLock);
- if (cameraId < 0 || cameraId >= MAX_CAMERAS_PER_MODULE) {
+ if (cameraId < 0) {
ALOGE("%s: Invalid camera ID %d", __FUNCTION__, cameraId);
return -EINVAL;
}
@@ -72,21 +70,27 @@ int CameraModule::getCameraInfo(int cameraId, struct camera_info *info) {
return mModule->get_camera_info(cameraId, info);
}
- camera_info &wrappedInfo = mCameraInfo[cameraId];
- if (!mCameraInfoCached[cameraId]) {
+ ssize_t index = mCameraInfoMap.indexOfKey(cameraId);
+ if (index == NAME_NOT_FOUND) {
+ // Get camera info from raw module and cache it
+ CameraInfo cameraInfo;
camera_info rawInfo;
int ret = mModule->get_camera_info(cameraId, &rawInfo);
if (ret != 0) {
return ret;
}
- CameraMetadata &m = mCameraCharacteristics[cameraId];
+ CameraMetadata &m = cameraInfo.cameraCharacteristics;
m = rawInfo.static_camera_characteristics;
deriveCameraCharacteristicsKeys(rawInfo.device_version, m);
- wrappedInfo = rawInfo;
- wrappedInfo.static_camera_characteristics = m.getAndLock();
- mCameraInfoCached[cameraId] = true;
+ cameraInfo.cameraInfo = rawInfo;
+ cameraInfo.cameraInfo.static_camera_characteristics = m.getAndLock();
+ mCameraInfoMap.add(cameraId, cameraInfo);
+ index = mCameraInfoMap.indexOfKey(cameraId);
}
- *info = wrappedInfo;
+
+ assert(index != NAME_NOT_FOUND);
+ // return the cached camera info
+ *info = mCameraInfoMap[index].cameraInfo;
return 0;
}
@@ -99,10 +103,6 @@ int CameraModule::openLegacy(
return mModule->open_legacy(&mModule->common, id, halVersion, device);
}
-const hw_module_t* CameraModule::getRawModule() {
- return &mModule->common;
-}
-
int CameraModule::getNumberOfCameras() {
return mModule->get_number_of_cameras();
}
@@ -125,7 +125,6 @@ int CameraModule::setTorchMode(const char* camera_id, bool enable) {
return mModule->set_torch_mode(camera_id, enable);
}
-
status_t CameraModule::filterOpenErrorCode(status_t err) {
switch(err) {
case NO_ERROR:
@@ -139,6 +138,25 @@ status_t CameraModule::filterOpenErrorCode(status_t err) {
return -ENODEV;
}
+uint16_t CameraModule::getModuleApiVersion() {
+ return mModule->common.module_api_version;
+}
+
+const char* CameraModule::getModuleName() {
+ return mModule->common.name;
+}
+
+uint16_t CameraModule::getHalApiVersion() {
+ return mModule->common.hal_api_version;
+}
+
+const char* CameraModule::getModuleAuthor() {
+ return mModule->common.author;
+}
+
+void* CameraModule::getDso() {
+ return mModule->common.dso;
+}
}; // namespace android
diff --git a/services/camera/libcameraservice/common/CameraModule.h b/services/camera/libcameraservice/common/CameraModule.h
index 16207aa..ecc5b2d 100644
--- a/services/camera/libcameraservice/common/CameraModule.h
+++ b/services/camera/libcameraservice/common/CameraModule.h
@@ -20,10 +20,7 @@
#include <hardware/camera.h>
#include <camera/CameraMetadata.h>
#include <utils/Mutex.h>
-
-/* This needs to be increased if we can have more cameras */
-#define MAX_CAMERAS_PER_MODULE 2
-
+#include <utils/KeyedVector.h>
namespace android {
/**
@@ -37,7 +34,6 @@ class CameraModule {
public:
CameraModule(camera_module_t *module);
- const hw_module_t* getRawModule();
int getCameraInfo(int cameraId, struct camera_info *info);
int getNumberOfCameras(void);
int open(const char* id, struct hw_device_t** device);
@@ -46,16 +42,25 @@ public:
bool isVendorTagDefined();
void getVendorTagOps(vendor_tag_ops_t* ops);
int setTorchMode(const char* camera_id, bool enable);
+ uint16_t getModuleApiVersion();
+ const char* getModuleName();
+ uint16_t getHalApiVersion();
+ const char* getModuleAuthor();
+ // Only used by CameraModuleFixture native test. Do NOT use elsewhere.
+ void *getDso();
private:
// Derive camera characteristics keys defined after HAL device version
static void deriveCameraCharacteristicsKeys(uint32_t deviceVersion, CameraMetadata &chars);
status_t filterOpenErrorCode(status_t err);
+ struct CameraInfo {
+ CameraMetadata cameraCharacteristics;
+ camera_info cameraInfo;
+ };
+
camera_module_t *mModule;
- CameraMetadata mCameraCharacteristics[MAX_CAMERAS_PER_MODULE];
- camera_info mCameraInfo[MAX_CAMERAS_PER_MODULE];
- bool mCameraInfoCached[MAX_CAMERAS_PER_MODULE];
+ KeyedVector<int, CameraInfo> mCameraInfoMap;
Mutex mCameraInfoLock;
};