/* Copyright (C) 2014, The CyanogenMod 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. */ /** * @file CameraWrapper.cpp * * This file wraps a vendor camera module. * */ //#define LOG_NDEBUG 0 #define LOG_TAG "CameraWrapper" #include #include #include #include #include static android::Mutex gCameraWrapperLock; static camera_module_t *gVendorModule = 0; static int camera_device_open(const hw_module_t *module, const char *name, hw_device_t **device); static int camera_get_number_of_cameras(void); static int camera_get_camera_info(int camera_id, struct camera_info *info); static struct hw_module_methods_t camera_module_methods = { .open = camera_device_open }; camera_module_t HAL_MODULE_INFO_SYM = { .common = { .tag = HARDWARE_MODULE_TAG, .module_api_version = CAMERA_MODULE_API_VERSION_1_0, .hal_api_version = HARDWARE_HAL_API_VERSION, .id = CAMERA_HARDWARE_MODULE_ID, .name = "Moto X Pure Camera Wrapper", .author = "The CyanogenMod Project", .methods = &camera_module_methods, .dso = NULL, /* remove compilation warnings */ .reserved = {0}, /* remove compilation warnings */ }, .get_number_of_cameras = camera_get_number_of_cameras, .get_camera_info = camera_get_camera_info, .set_callbacks = NULL, /* remove compilation warnings */ .get_vendor_tag_ops = NULL, /* remove compilation warnings */ .open_legacy = NULL, /* remove compilation warnings */ .set_torch_mode = NULL, /* remove compilation warnings */ .init = NULL, /* remove compilation warnings */ .reserved = {0}, /* remove compilation warnings */ }; static int check_vendor_module() { int rv = 0; ALOGV("%s", __FUNCTION__); if (gVendorModule) return 0; rv = hw_get_module_by_class("camera", "vendor", (const hw_module_t**)&gVendorModule); if (rv) ALOGE("failed to open vendor camera module"); return rv; } static int camera_device_open(const hw_module_t *module, const char *name, hw_device_t **device) { int rv = 0; int num_cameras = 0; int cameraid; int cameraretry = 0; android::Mutex::Autolock lock(gCameraWrapperLock); ALOGV("%s", __FUNCTION__); if (name == NULL || check_vendor_module() != android::NO_ERROR) { return -EINVAL; } while (cameraretry < 3) { rv = gVendorModule->common.methods->open( (const hw_module_t*)gVendorModule, name, device); if (!rv) break; cameraretry++; ALOGV("%s: open failed - retrying attempt %d",__FUNCTION__, cameraretry); sleep(2); } if (rv) ALOGE("vendor camera open fail"); return rv; } static int camera_get_number_of_cameras(void) { ALOGV("%s", __FUNCTION__); if (check_vendor_module()) return 0; return gVendorModule->get_number_of_cameras(); } static int camera_get_camera_info(int camera_id, struct camera_info *info) { ALOGV("%s", __FUNCTION__); if (check_vendor_module()) return 0; return gVendorModule->get_camera_info(camera_id, info); }