diff options
author | Iliyan Malchev <malchev@google.com> | 2011-04-14 16:55:59 -0700 |
---|---|---|
committer | Iliyan Malchev <malchev@google.com> | 2011-05-03 15:49:40 -0700 |
commit | a269b87bd7fecbd977c6c2a054ea333d40408bfb (patch) | |
tree | f9ee8843a8c38b4926ca8d50d4cec76a9668538a /services/camera/libcameraservice/CameraService.cpp | |
parent | 4d7c1ce651bd5e283e694fa34641e1dc080613c0 (diff) | |
download | frameworks_base-a269b87bd7fecbd977c6c2a054ea333d40408bfb.zip frameworks_base-a269b87bd7fecbd977c6c2a054ea333d40408bfb.tar.gz frameworks_base-a269b87bd7fecbd977c6c2a054ea333d40408bfb.tar.bz2 |
frameworks/base: switch CameraService to a HAL module
This patch changes CameraService to load a camera HAL module, instead of
linking directly against a library that implements the CameraHardwareInterface
class.
CameraHardwareInterface no longer defines the API to the camera HAL. Instead,
this is now in HAL header hardware/camera.h. We keep CamerHardwareInterface as
a class local to CameraService, which wraps around the new HAL calls. In the
future, we may remove this class entirely and have CameraService call the HAL
methods directly.
Change-Id: I5c61ac40078fc0b50bbac5881a556fe6c8837641
Signed-off-by: Iliyan Malchev <malchev@google.com>
Diffstat (limited to 'services/camera/libcameraservice/CameraService.cpp')
-rw-r--r-- | services/camera/libcameraservice/CameraService.cpp | 70 |
1 files changed, 49 insertions, 21 deletions
diff --git a/services/camera/libcameraservice/CameraService.cpp b/services/camera/libcameraservice/CameraService.cpp index 56c9246..1e8c30b 100644 --- a/services/camera/libcameraservice/CameraService.cpp +++ b/services/camera/libcameraservice/CameraService.cpp @@ -16,6 +16,7 @@ */ #define LOG_TAG "CameraService" +//#define LOG_NDEBUG 0 #include <stdio.h> #include <sys/types.h> @@ -37,6 +38,7 @@ #include <utils/String16.h> #include "CameraService.h" +#include "CameraHardwareInterface.h" namespace android { @@ -69,22 +71,32 @@ static int getCallingUid() { static CameraService *gCameraService; CameraService::CameraService() -:mSoundRef(0) +:mSoundRef(0), mModule(0) { LOGI("CameraService started (pid=%d)", getpid()); + gCameraService = this; +} - mNumberOfCameras = HAL_getNumberOfCameras(); - if (mNumberOfCameras > MAX_CAMERAS) { - LOGE("Number of cameras(%d) > MAX_CAMERAS(%d).", - mNumberOfCameras, MAX_CAMERAS); - mNumberOfCameras = MAX_CAMERAS; - } - - for (int i = 0; i < mNumberOfCameras; i++) { - setCameraFree(i); +void CameraService::onFirstRef() +{ + BnCameraService::onFirstRef(); + + if (hw_get_module(CAMERA_HARDWARE_MODULE_ID, + (const hw_module_t **)&mModule) < 0) { + LOGE("Could not load camera HAL module"); + mNumberOfCameras = 0; + } + else { + mNumberOfCameras = mModule->get_number_of_cameras(); + if (mNumberOfCameras > MAX_CAMERAS) { + LOGE("Number of cameras(%d) > MAX_CAMERAS(%d).", + mNumberOfCameras, MAX_CAMERAS); + mNumberOfCameras = MAX_CAMERAS; + } + for (int i = 0; i < mNumberOfCameras; i++) { + setCameraFree(i); + } } - - gCameraService = this; } CameraService::~CameraService() { @@ -103,12 +115,19 @@ int32_t CameraService::getNumberOfCameras() { status_t CameraService::getCameraInfo(int cameraId, struct CameraInfo* cameraInfo) { + if (!mModule) { + return NO_INIT; + } + if (cameraId < 0 || cameraId >= mNumberOfCameras) { return BAD_VALUE; } - HAL_getCameraInfo(cameraId, cameraInfo); - return OK; + struct camera_info info; + status_t rc = mModule->get_camera_info(cameraId, &info); + cameraInfo->facing = info.facing; + cameraInfo->orientation = info.orientation; + return rc; } sp<ICamera> CameraService::connect( @@ -116,6 +135,11 @@ sp<ICamera> CameraService::connect( int callingPid = getCallingPid(); LOG1("CameraService::connect E (pid %d, id %d)", callingPid, cameraId); + if (!mModule) { + LOGE("Camera HAL module not loaded"); + return NULL; + } + sp<Client> client; if (cameraId < 0 || cameraId >= mNumberOfCameras) { LOGE("CameraService::connect X (pid %d) rejected (invalid cameraId %d).", @@ -146,15 +170,19 @@ sp<ICamera> CameraService::connect( return NULL; } - sp<CameraHardwareInterface> hardware = HAL_openCameraHardware(cameraId); - if (hardware == NULL) { - LOGE("Fail to open camera hardware (id=%d)", cameraId); + struct camera_info info; + if (mModule->get_camera_info(cameraId, &info) != OK) { + LOGE("Invalid camera id %d", cameraId); return NULL; } - CameraInfo info; - HAL_getCameraInfo(cameraId, &info); - client = new Client(this, cameraClient, hardware, cameraId, info.facing, - callingPid); + + char camera_device_name[10]; + snprintf(camera_device_name, sizeof(camera_device_name), "%d", cameraId); + + client = new Client(this, cameraClient, + new CameraHardwareInterface(&mModule->common, + camera_device_name), + cameraId, info.facing, callingPid); mClient[cameraId] = client; LOG1("CameraService::connect X"); return client; |