summaryrefslogtreecommitdiffstats
path: root/modules/camera
diff options
context:
space:
mode:
authorAlex Ray <aray@google.com>2013-02-20 17:46:41 -0800
committerAlex Ray <aray@google.com>2013-02-26 15:26:26 -0800
commit819cfd87bad560fbd89747371088ad35aaef8d43 (patch)
tree7eae39183a2104a7f9b7fd1fbfcb7cbfe4247fda /modules/camera
parentbb13a3231d24bf640e7060fee3a18643f7a9f0db (diff)
downloadhardware_libhardware-819cfd87bad560fbd89747371088ad35aaef8d43.zip
hardware_libhardware-819cfd87bad560fbd89747371088ad35aaef8d43.tar.gz
hardware_libhardware-819cfd87bad560fbd89747371088ad35aaef8d43.tar.bz2
modules: camera: Update to v2.1 camera module API
Refactor the camera module into a single CameraHAL object. Adds set_callbacks, new in the v2.1 module API. Change-Id: I4da677c28d7425f545f68998844fcfa4caf0feb9
Diffstat (limited to 'modules/camera')
-rw-r--r--modules/camera/CameraHAL.cpp98
-rw-r--r--modules/camera/CameraHAL.h47
2 files changed, 111 insertions, 34 deletions
diff --git a/modules/camera/CameraHAL.cpp b/modules/camera/CameraHAL.cpp
index abc3278..9880908 100644
--- a/modules/camera/CameraHAL.cpp
+++ b/modules/camera/CameraHAL.cpp
@@ -15,13 +15,17 @@
*/
#include <cstdlib>
-#include <hardware/camera2.h>
+#include <hardware/camera_common.h>
+#include <hardware/hardware.h>
//#define LOG_NDEBUG 0
-#define LOG_TAG "CameraHAL"
+#define LOG_TAG "DefaultCameraHAL"
#include <cutils/log.h>
-#include "Camera.h"
+#define ATRACE_TAG (ATRACE_TAG_CAMERA | ATRACE_TAG_HAL)
+#include <cutils/trace.h>
+
+#include "CameraHAL.h"
/*
* This file serves as the entry point to the HAL. It contains the module
@@ -31,60 +35,85 @@
namespace default_camera_hal {
-enum camera_id_t {
- CAMERA_A,
- CAMERA_B,
- NUM_CAMERAS
-};
-
-// Symbol used by the framework when loading the HAL, defined below.
-extern "C" camera_module_t HAL_MODULE_INFO_SYM;
+// Default Camera HAL has 2 cameras, front and rear.
+static CameraHAL gCameraHAL(2);
-// Camera devices created when the module is loaded. See Camera.h
-static Camera gCameras[NUM_CAMERAS] = {
- Camera(CAMERA_A, &HAL_MODULE_INFO_SYM.common),
- Camera(CAMERA_B, &HAL_MODULE_INFO_SYM.common)
-};
+CameraHAL::CameraHAL(int num_cameras)
+ : mNumberOfCameras(num_cameras),
+ mCallbacks(NULL)
+{
+}
-extern "C" {
+CameraHAL::~CameraHAL()
+{
+}
-static int get_number_of_cameras()
+int CameraHAL::getNumberOfCameras()
{
- ALOGV("%s", __func__);
- return NUM_CAMERAS;
+ ALOGV("%s: %d", __func__, mNumberOfCameras);
+ return mNumberOfCameras;
}
-static int get_camera_info(int id, struct camera_info* info)
+int CameraHAL::getCameraInfo(int id, struct camera_info* info)
{
ALOGV("%s: camera id %d: info=%p", __func__, id, info);
- if (id < 0 || id >= NUM_CAMERAS) {
+ if (id < 0 || id >= mNumberOfCameras) {
ALOGE("%s: Invalid camera id %d", __func__, id);
return -ENODEV;
}
- return gCameras[id].getCameraInfo(info);
+ // TODO: return device-specific static metadata
+ return 0;
}
-static int open_device(const hw_module_t* module, const char* name,
- hw_device_t** device)
+int CameraHAL::setCallbacks(const camera_module_callbacks_t *callbacks)
+{
+ ALOGV("%s : callbacks=%p", __func__, callbacks);
+ mCallbacks = callbacks;
+ return 0;
+}
+
+int CameraHAL::open(const hw_module_t* mod, const char* name, hw_device_t** dev)
{
- ALOGV("%s: module=%p, name=%s, device=%p", __func__, module, name, device);
- char *nameEnd;
int id;
+ char *nameEnd;
+ ALOGV("%s: module=%p, name=%s, device=%p", __func__, mod, name, dev);
id = strtol(name, &nameEnd, 10);
if (nameEnd != NULL) {
ALOGE("%s: Invalid camera id name %s", __func__, name);
return -EINVAL;
- } else if (id < 0 || id >= NUM_CAMERAS) {
+ } else if (id < 0 || id >= mNumberOfCameras) {
ALOGE("%s: Invalid camera id %d", __func__, id);
return -ENODEV;
}
- *device = &gCameras[id].mDevice.common;
- return gCameras[id].open();
+ // TODO: check for existing use; allocate and return new camera device
+ return 0;
+}
+
+extern "C" {
+
+static int get_number_of_cameras()
+{
+ return gCameraHAL.getNumberOfCameras();
+}
+
+static int get_camera_info(int id, struct camera_info* info)
+{
+ return gCameraHAL.getCameraInfo(id, info);
+}
+
+static int set_callbacks(const camera_module_callbacks_t *callbacks)
+{
+ return gCameraHAL.setCallbacks(callbacks);
+}
+
+static int open_dev(const hw_module_t* mod, const char* name, hw_device_t** dev)
+{
+ return gCameraHAL.open(mod, name, dev);
}
static hw_module_methods_t gCameraModuleMethods = {
- open : open_device
+ open : open_dev
};
camera_module_t HAL_MODULE_INFO_SYM __attribute__ ((visibility("default"))) = {
@@ -93,15 +122,16 @@ camera_module_t HAL_MODULE_INFO_SYM __attribute__ ((visibility("default"))) = {
module_api_version : CAMERA_MODULE_API_VERSION_2_0,
hal_api_version : HARDWARE_HAL_API_VERSION,
id : CAMERA_HARDWARE_MODULE_ID,
- name : "Reference Camera v2 HAL",
+ name : "Default Camera HAL",
author : "The Android Open Source Project",
methods : &gCameraModuleMethods,
dso : NULL,
reserved : {0},
},
get_number_of_cameras : get_number_of_cameras,
- get_camera_info : get_camera_info
+ get_camera_info : get_camera_info,
+ set_callbacks : set_callbacks
};
-
} // extern "C"
+
} // namespace default_camera_hal
diff --git a/modules/camera/CameraHAL.h b/modules/camera/CameraHAL.h
new file mode 100644
index 0000000..b53ab31
--- /dev/null
+++ b/modules/camera/CameraHAL.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef CAMERA_HAL_H_
+#define CAMERA_HAL_H_
+
+#include <hardware/hardware.h>
+#include <hardware/camera_common.h>
+
+namespace default_camera_hal {
+// CameraHAL contains all module state that isn't specific to an individual
+// camera device.
+class CameraHAL {
+ public:
+ CameraHAL(int num_cameras);
+ ~CameraHAL();
+
+ // Camera Module Interface (see <hardware/camera_common.h>)
+ int getNumberOfCameras();
+ int getCameraInfo(int camera_id, struct camera_info *info);
+ int setCallbacks(const camera_module_callbacks_t *callbacks);
+
+ // Hardware Module Interface (see <hardware/hardware.h>)
+ int open(const hw_module_t* mod, const char* name, hw_device_t** dev);
+
+ private:
+ // Number of cameras
+ const int mNumberOfCameras;
+ // Callback handle
+ const camera_module_callbacks_t *mCallbacks;
+};
+} // namespace default_camera_hal
+
+#endif // CAMERA_HAL_H_