blob: 50cece436ce2efa1df37444021d9a914742220ee [file] [log] [blame]
Yin-Chia Yehe074a932015-01-30 10:29:02 -08001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "CameraModule"
18//#define LOG_NDEBUG 0
19
20#include "CameraModule.h"
21
22namespace android {
23
24void CameraModule::deriveCameraCharacteristicsKeys(
25 uint32_t deviceVersion, CameraMetadata &chars) {
26 // HAL1 devices should not reach here
27 if (deviceVersion < CAMERA_DEVICE_API_VERSION_2_0) {
28 ALOGV("%s: Cannot derive keys for HAL version < 2.0");
29 return;
30 }
31
32 // Keys added in HAL3.3
33 if (deviceVersion < CAMERA_DEVICE_API_VERSION_3_3) {
34 Vector<uint8_t> controlModes;
35 uint8_t data = ANDROID_CONTROL_AE_LOCK_AVAILABLE_TRUE;
36 chars.update(ANDROID_CONTROL_AE_LOCK_AVAILABLE, &data, /*count*/1);
37 data = ANDROID_CONTROL_AWB_LOCK_AVAILABLE_TRUE;
38 chars.update(ANDROID_CONTROL_AWB_LOCK_AVAILABLE, &data, /*count*/1);
39 controlModes.push(ANDROID_CONTROL_MODE_OFF);
40 controlModes.push(ANDROID_CONTROL_MODE_AUTO);
41 camera_metadata_entry entry = chars.find(ANDROID_CONTROL_AVAILABLE_SCENE_MODES);
42 if (entry.count > 1 || entry.data.u8[0] != ANDROID_CONTROL_SCENE_MODE_DISABLED) {
43 controlModes.push(ANDROID_CONTROL_MODE_USE_SCENE_MODE);
44 }
45 chars.update(ANDROID_CONTROL_AVAILABLE_MODES, controlModes);
46 }
47 return;
48}
49
50CameraModule::CameraModule(camera_module_t *module) {
51 if (module == NULL) {
52 ALOGE("%s: camera hardware module must not be null", __FUNCTION__);
53 assert(0);
54 }
55
56 mModule = module;
Chien-Yu Chen676b21b2015-02-24 10:28:19 -080057 mCameraInfoMap.setCapacity(getNumberOfCameras());
Yin-Chia Yehe074a932015-01-30 10:29:02 -080058}
59
60int CameraModule::getCameraInfo(int cameraId, struct camera_info *info) {
61 Mutex::Autolock lock(mCameraInfoLock);
Chien-Yu Chen676b21b2015-02-24 10:28:19 -080062 if (cameraId < 0) {
Yin-Chia Yehe074a932015-01-30 10:29:02 -080063 ALOGE("%s: Invalid camera ID %d", __FUNCTION__, cameraId);
64 return -EINVAL;
65 }
66
Yin-Chia Yehb6dc0bf2015-02-18 14:42:16 -080067 // Only override static_camera_characteristics for API2 devices
68 int apiVersion = mModule->common.module_api_version;
69 if (apiVersion < CAMERA_MODULE_API_VERSION_2_0) {
70 return mModule->get_camera_info(cameraId, info);
71 }
72
Chien-Yu Chen676b21b2015-02-24 10:28:19 -080073 ssize_t index = mCameraInfoMap.indexOfKey(cameraId);
74 if (index == NAME_NOT_FOUND) {
75 // Get camera info from raw module and cache it
76 CameraInfo cameraInfo;
Yin-Chia Yehe074a932015-01-30 10:29:02 -080077 camera_info rawInfo;
78 int ret = mModule->get_camera_info(cameraId, &rawInfo);
79 if (ret != 0) {
80 return ret;
81 }
Chien-Yu Chen676b21b2015-02-24 10:28:19 -080082 CameraMetadata &m = cameraInfo.cameraCharacteristics;
Yin-Chia Yehe074a932015-01-30 10:29:02 -080083 m = rawInfo.static_camera_characteristics;
Yin-Chia Yehb6dc0bf2015-02-18 14:42:16 -080084 deriveCameraCharacteristicsKeys(rawInfo.device_version, m);
Chien-Yu Chen676b21b2015-02-24 10:28:19 -080085 cameraInfo.cameraInfo = rawInfo;
86 cameraInfo.cameraInfo.static_camera_characteristics = m.getAndLock();
87 mCameraInfoMap.add(cameraId, cameraInfo);
88 index = mCameraInfoMap.indexOfKey(cameraId);
Yin-Chia Yehe074a932015-01-30 10:29:02 -080089 }
Chien-Yu Chen676b21b2015-02-24 10:28:19 -080090
91 assert(index != NAME_NOT_FOUND);
92 // return the cached camera info
93 *info = mCameraInfoMap[index].cameraInfo;
Yin-Chia Yehe074a932015-01-30 10:29:02 -080094 return 0;
95}
96
97int CameraModule::open(const char* id, struct hw_device_t** device) {
Chien-Yu Chend231fd62015-02-25 16:04:22 -080098 return filterOpenErrorCode(mModule->common.methods->open(&mModule->common, id, device));
Yin-Chia Yehe074a932015-01-30 10:29:02 -080099}
100
101int CameraModule::openLegacy(
102 const char* id, uint32_t halVersion, struct hw_device_t** device) {
103 return mModule->open_legacy(&mModule->common, id, halVersion, device);
104}
105
Yin-Chia Yehe074a932015-01-30 10:29:02 -0800106int CameraModule::getNumberOfCameras() {
107 return mModule->get_number_of_cameras();
108}
109
110int CameraModule::setCallbacks(const camera_module_callbacks_t *callbacks) {
111 return mModule->set_callbacks(callbacks);
112}
113
114bool CameraModule::isVendorTagDefined() {
115 return mModule->get_vendor_tag_ops != NULL;
116}
117
118void CameraModule::getVendorTagOps(vendor_tag_ops_t* ops) {
119 if (mModule->get_vendor_tag_ops) {
120 mModule->get_vendor_tag_ops(ops);
121 }
122}
123
124int CameraModule::setTorchMode(const char* camera_id, bool enable) {
125 return mModule->set_torch_mode(camera_id, enable);
126}
127
Chien-Yu Chend231fd62015-02-25 16:04:22 -0800128status_t CameraModule::filterOpenErrorCode(status_t err) {
129 switch(err) {
130 case NO_ERROR:
131 case -EBUSY:
132 case -EINVAL:
133 case -EUSERS:
134 return err;
135 default:
136 break;
137 }
138 return -ENODEV;
139}
140
Chien-Yu Chen676b21b2015-02-24 10:28:19 -0800141uint16_t CameraModule::getModuleApiVersion() {
142 return mModule->common.module_api_version;
143}
144
145const char* CameraModule::getModuleName() {
146 return mModule->common.name;
147}
148
149uint16_t CameraModule::getHalApiVersion() {
150 return mModule->common.hal_api_version;
151}
152
153const char* CameraModule::getModuleAuthor() {
154 return mModule->common.author;
155}
156
157void* CameraModule::getDso() {
158 return mModule->common.dso;
159}
Chien-Yu Chend231fd62015-02-25 16:04:22 -0800160
Yin-Chia Yehe074a932015-01-30 10:29:02 -0800161}; // namespace android
162