From 7b6da3c7a2cdc44a35f3af3b4110eabda6f6a4b7 Mon Sep 17 00:00:00 2001 From: Tyler Luu Date: Thu, 6 Oct 2011 00:00:03 -0500 Subject: Add initialize method to CameraHardwareInterface Add intialize() method to CameraHardwareInterface so we can return a proper error value to CameraService if open of camera hardware module fails. b/5405235 Change-Id: I09c627034ddd22a5753c5163392c4fcff301e0b9 Signed-off-by: Tyler Luu Signed-off-by: Iliyan Malchev --- .../libcameraservice/CameraHardwareInterface.h | 29 ++++++++++++++-------- services/camera/libcameraservice/CameraService.cpp | 13 +++++++--- 2 files changed, 28 insertions(+), 14 deletions(-) (limited to 'services/camera') diff --git a/services/camera/libcameraservice/CameraHardwareInterface.h b/services/camera/libcameraservice/CameraHardwareInterface.h index 31544b3..c3ced4c2 100644 --- a/services/camera/libcameraservice/CameraHardwareInterface.h +++ b/services/camera/libcameraservice/CameraHardwareInterface.h @@ -80,24 +80,33 @@ typedef void (*data_callback_timestamp)(nsecs_t timestamp, class CameraHardwareInterface : public virtual RefBase { public: - CameraHardwareInterface(hw_module_t *module, const char *name) + CameraHardwareInterface(const char *name) { mDevice = 0; mName = name; - LOGI("Opening camera %s, this %p", name, this); - int rc = module->methods->open(module, name, - (hw_device_t **)&mDevice); - if (rc != OK) - LOGE("Could not open camera %s: %d", name, rc); - initHalPreviewWindow(); } ~CameraHardwareInterface() { LOGI("Destroying camera %s", mName.string()); - int rc = mDevice->common.close(&mDevice->common); - if (rc != OK) - LOGE("Could not close camera %s: %d", mName.string(), rc); + if(mDevice) { + int rc = mDevice->common.close(&mDevice->common); + if (rc != OK) + LOGE("Could not close camera %s: %d", mName.string(), rc); + } + } + + status_t initialize(hw_module_t *module) + { + LOGI("Opening camera %s", mName.string()); + int rc = module->methods->open(module, mName.string(), + (hw_device_t **)&mDevice); + if (rc != OK) { + LOGE("Could not open camera %s: %d", mName.string(), rc); + return rc; + } + initHalPreviewWindow(); + return rc; } /** Set the ANativeWindow to which preview frames are sent */ diff --git a/services/camera/libcameraservice/CameraService.cpp b/services/camera/libcameraservice/CameraService.cpp index 05e7bcf..f306e4a 100644 --- a/services/camera/libcameraservice/CameraService.cpp +++ b/services/camera/libcameraservice/CameraService.cpp @@ -133,6 +133,8 @@ status_t CameraService::getCameraInfo(int cameraId, sp CameraService::connect( const sp& cameraClient, int cameraId) { int callingPid = getCallingPid(); + sp hardware = NULL; + LOG1("CameraService::connect E (pid %d, id %d)", callingPid, cameraId); if (!mModule) { @@ -187,10 +189,13 @@ sp CameraService::connect( 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); + hardware = new CameraHardwareInterface(camera_device_name); + if (hardware->initialize(&mModule->common) != OK) { + hardware.clear(); + return NULL; + } + + client = new Client(this, cameraClient, hardware, cameraId, info.facing, callingPid); mClient[cameraId] = client; LOG1("CameraService::connect X"); return client; -- cgit v1.1