blob: bbf47e8b99077d5ee3e840563122a4b71f3c6aff [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;
57 for (int i = 0; i < MAX_CAMERAS_PER_MODULE; i++) {
58 mCameraInfoCached[i] = false;
59 }
60}
61
62int CameraModule::getCameraInfo(int cameraId, struct camera_info *info) {
63 Mutex::Autolock lock(mCameraInfoLock);
64 if (cameraId < 0 || cameraId >= MAX_CAMERAS_PER_MODULE) {
65 ALOGE("%s: Invalid camera ID %d", __FUNCTION__, cameraId);
66 return -EINVAL;
67 }
68
69 camera_info &wrappedInfo = mCameraInfo[cameraId];
70 if (!mCameraInfoCached[cameraId]) {
71 camera_info rawInfo;
72 int ret = mModule->get_camera_info(cameraId, &rawInfo);
73 if (ret != 0) {
74 return ret;
75 }
76 CameraMetadata &m = mCameraCharacteristics[cameraId];
77 m = rawInfo.static_camera_characteristics;
78 int deviceVersion;
79 int apiVersion = mModule->common.module_api_version;
80 if (apiVersion >= CAMERA_MODULE_API_VERSION_2_0) {
81 deviceVersion = rawInfo.device_version;
82 } else {
83 deviceVersion = CAMERA_DEVICE_API_VERSION_1_0;
84 }
85 deriveCameraCharacteristicsKeys(deviceVersion, m);
86 wrappedInfo = rawInfo;
87 wrappedInfo.static_camera_characteristics = m.getAndLock();
88 mCameraInfoCached[cameraId] = true;
89 }
90 *info = wrappedInfo;
91 return 0;
92}
93
94int CameraModule::open(const char* id, struct hw_device_t** device) {
95 return mModule->common.methods->open(&mModule->common, id, device);
96}
97
98int CameraModule::openLegacy(
99 const char* id, uint32_t halVersion, struct hw_device_t** device) {
100 return mModule->open_legacy(&mModule->common, id, halVersion, device);
101}
102
103const hw_module_t* CameraModule::getRawModule() {
104 return &mModule->common;
105}
106
107int CameraModule::getNumberOfCameras() {
108 return mModule->get_number_of_cameras();
109}
110
111int CameraModule::setCallbacks(const camera_module_callbacks_t *callbacks) {
112 return mModule->set_callbacks(callbacks);
113}
114
115bool CameraModule::isVendorTagDefined() {
116 return mModule->get_vendor_tag_ops != NULL;
117}
118
119void CameraModule::getVendorTagOps(vendor_tag_ops_t* ops) {
120 if (mModule->get_vendor_tag_ops) {
121 mModule->get_vendor_tag_ops(ops);
122 }
123}
124
125int CameraModule::setTorchMode(const char* camera_id, bool enable) {
126 return mModule->set_torch_mode(camera_id, enable);
127}
128
129}; // namespace android
130