Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 | #include <cstdlib> |
Alex Ray | 819cfd8 | 2013-02-20 17:46:41 -0800 | [diff] [blame] | 18 | #include <hardware/camera_common.h> |
| 19 | #include <hardware/hardware.h> |
Alex Ray | 61f7a0c | 2013-07-03 17:54:19 -0700 | [diff] [blame] | 20 | #include "ExampleCamera.h" |
Alex Ray | 7915e97 | 2013-10-17 21:52:03 -0700 | [diff] [blame] | 21 | #include "VendorTags.h" |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 22 | |
| 23 | //#define LOG_NDEBUG 0 |
Alex Ray | 819cfd8 | 2013-02-20 17:46:41 -0800 | [diff] [blame] | 24 | #define LOG_TAG "DefaultCameraHAL" |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 25 | #include <cutils/log.h> |
| 26 | |
Alex Ray | 819cfd8 | 2013-02-20 17:46:41 -0800 | [diff] [blame] | 27 | #define ATRACE_TAG (ATRACE_TAG_CAMERA | ATRACE_TAG_HAL) |
| 28 | #include <cutils/trace.h> |
| 29 | |
| 30 | #include "CameraHAL.h" |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 31 | |
| 32 | /* |
| 33 | * This file serves as the entry point to the HAL. It contains the module |
| 34 | * structure and functions used by the framework to load and interface to this |
| 35 | * HAL, as well as the handles to the individual camera devices. |
| 36 | */ |
| 37 | |
| 38 | namespace default_camera_hal { |
| 39 | |
Alex Ray | 819cfd8 | 2013-02-20 17:46:41 -0800 | [diff] [blame] | 40 | // Default Camera HAL has 2 cameras, front and rear. |
| 41 | static CameraHAL gCameraHAL(2); |
Alex Ray | 7915e97 | 2013-10-17 21:52:03 -0700 | [diff] [blame] | 42 | // Handle containing vendor tag functionality |
| 43 | static VendorTags gVendorTags; |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 44 | |
Alex Ray | 819cfd8 | 2013-02-20 17:46:41 -0800 | [diff] [blame] | 45 | CameraHAL::CameraHAL(int num_cameras) |
| 46 | : mNumberOfCameras(num_cameras), |
| 47 | mCallbacks(NULL) |
| 48 | { |
Alex Ray | a0ed4be | 2013-02-25 15:02:16 -0800 | [diff] [blame] | 49 | // Allocate camera array and instantiate camera devices |
| 50 | mCameras = new Camera*[mNumberOfCameras]; |
Alex Ray | 61f7a0c | 2013-07-03 17:54:19 -0700 | [diff] [blame] | 51 | // Rear camera |
| 52 | mCameras[0] = new ExampleCamera(0); |
| 53 | // Front camera |
| 54 | mCameras[1] = new ExampleCamera(1); |
Alex Ray | 819cfd8 | 2013-02-20 17:46:41 -0800 | [diff] [blame] | 55 | } |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 56 | |
Alex Ray | 819cfd8 | 2013-02-20 17:46:41 -0800 | [diff] [blame] | 57 | CameraHAL::~CameraHAL() |
| 58 | { |
Alex Ray | 61f7a0c | 2013-07-03 17:54:19 -0700 | [diff] [blame] | 59 | for (int i = 0; i < mNumberOfCameras; i++) { |
Alex Ray | a0ed4be | 2013-02-25 15:02:16 -0800 | [diff] [blame] | 60 | delete mCameras[i]; |
| 61 | } |
| 62 | delete [] mCameras; |
Alex Ray | 819cfd8 | 2013-02-20 17:46:41 -0800 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | int CameraHAL::getNumberOfCameras() |
| 66 | { |
| 67 | ALOGV("%s: %d", __func__, mNumberOfCameras); |
| 68 | return mNumberOfCameras; |
| 69 | } |
| 70 | |
| 71 | int CameraHAL::getCameraInfo(int id, struct camera_info* info) |
| 72 | { |
| 73 | ALOGV("%s: camera id %d: info=%p", __func__, id, info); |
| 74 | if (id < 0 || id >= mNumberOfCameras) { |
| 75 | ALOGE("%s: Invalid camera id %d", __func__, id); |
| 76 | return -ENODEV; |
| 77 | } |
| 78 | // TODO: return device-specific static metadata |
Alex Ray | b0be103 | 2013-05-28 15:52:47 -0700 | [diff] [blame] | 79 | return mCameras[id]->getInfo(info); |
Alex Ray | 819cfd8 | 2013-02-20 17:46:41 -0800 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | int CameraHAL::setCallbacks(const camera_module_callbacks_t *callbacks) |
| 83 | { |
| 84 | ALOGV("%s : callbacks=%p", __func__, callbacks); |
| 85 | mCallbacks = callbacks; |
| 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | int CameraHAL::open(const hw_module_t* mod, const char* name, hw_device_t** dev) |
| 90 | { |
| 91 | int id; |
| 92 | char *nameEnd; |
| 93 | |
| 94 | ALOGV("%s: module=%p, name=%s, device=%p", __func__, mod, name, dev); |
Alex Ray | c6bf2f2 | 2013-05-28 15:52:04 -0700 | [diff] [blame] | 95 | if (*name == '\0') { |
| 96 | ALOGE("%s: Invalid camera id name is NULL", __func__); |
| 97 | return -EINVAL; |
| 98 | } |
Alex Ray | 819cfd8 | 2013-02-20 17:46:41 -0800 | [diff] [blame] | 99 | id = strtol(name, &nameEnd, 10); |
Alex Ray | b0be103 | 2013-05-28 15:52:47 -0700 | [diff] [blame] | 100 | if (*nameEnd != '\0') { |
Alex Ray | 819cfd8 | 2013-02-20 17:46:41 -0800 | [diff] [blame] | 101 | ALOGE("%s: Invalid camera id name %s", __func__, name); |
| 102 | return -EINVAL; |
| 103 | } else if (id < 0 || id >= mNumberOfCameras) { |
| 104 | ALOGE("%s: Invalid camera id %d", __func__, id); |
| 105 | return -ENODEV; |
| 106 | } |
Alex Ray | a0ed4be | 2013-02-25 15:02:16 -0800 | [diff] [blame] | 107 | return mCameras[id]->open(mod, dev); |
Alex Ray | 819cfd8 | 2013-02-20 17:46:41 -0800 | [diff] [blame] | 108 | } |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 109 | |
| 110 | extern "C" { |
| 111 | |
| 112 | static int get_number_of_cameras() |
| 113 | { |
Alex Ray | 819cfd8 | 2013-02-20 17:46:41 -0800 | [diff] [blame] | 114 | return gCameraHAL.getNumberOfCameras(); |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | static int get_camera_info(int id, struct camera_info* info) |
| 118 | { |
Alex Ray | 819cfd8 | 2013-02-20 17:46:41 -0800 | [diff] [blame] | 119 | return gCameraHAL.getCameraInfo(id, info); |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 120 | } |
| 121 | |
Alex Ray | 819cfd8 | 2013-02-20 17:46:41 -0800 | [diff] [blame] | 122 | static int set_callbacks(const camera_module_callbacks_t *callbacks) |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 123 | { |
Alex Ray | 819cfd8 | 2013-02-20 17:46:41 -0800 | [diff] [blame] | 124 | return gCameraHAL.setCallbacks(callbacks); |
| 125 | } |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 126 | |
Alex Ray | 7915e97 | 2013-10-17 21:52:03 -0700 | [diff] [blame] | 127 | static int get_tag_count(const vendor_tag_ops_t* ops) |
| 128 | { |
| 129 | return gVendorTags.getTagCount(ops); |
| 130 | } |
| 131 | |
| 132 | static void get_all_tags(const vendor_tag_ops_t* ops, uint32_t* tag_array) |
| 133 | { |
| 134 | gVendorTags.getAllTags(ops, tag_array); |
| 135 | } |
| 136 | |
| 137 | static const char* get_section_name(const vendor_tag_ops_t* ops, uint32_t tag) |
| 138 | { |
| 139 | return gVendorTags.getSectionName(ops, tag); |
| 140 | } |
| 141 | |
| 142 | static const char* get_tag_name(const vendor_tag_ops_t* ops, uint32_t tag) |
| 143 | { |
| 144 | return gVendorTags.getTagName(ops, tag); |
| 145 | } |
| 146 | |
| 147 | static int get_tag_type(const vendor_tag_ops_t* ops, uint32_t tag) |
| 148 | { |
| 149 | return gVendorTags.getTagType(ops, tag); |
| 150 | } |
| 151 | |
| 152 | static void get_vendor_tag_ops(vendor_tag_ops_t* ops) |
| 153 | { |
| 154 | ALOGV("%s : ops=%p", __func__, ops); |
| 155 | ops->get_tag_count = get_tag_count; |
| 156 | ops->get_all_tags = get_all_tags; |
| 157 | ops->get_section_name = get_section_name; |
| 158 | ops->get_tag_name = get_tag_name; |
| 159 | ops->get_tag_type = get_tag_type; |
| 160 | } |
| 161 | |
Alex Ray | 819cfd8 | 2013-02-20 17:46:41 -0800 | [diff] [blame] | 162 | static int open_dev(const hw_module_t* mod, const char* name, hw_device_t** dev) |
| 163 | { |
| 164 | return gCameraHAL.open(mod, name, dev); |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | static hw_module_methods_t gCameraModuleMethods = { |
Alex Ray | 819cfd8 | 2013-02-20 17:46:41 -0800 | [diff] [blame] | 168 | open : open_dev |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 169 | }; |
| 170 | |
Alex Ray | bb13a32 | 2013-02-18 15:38:05 -0800 | [diff] [blame] | 171 | camera_module_t HAL_MODULE_INFO_SYM __attribute__ ((visibility("default"))) = { |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 172 | common : { |
| 173 | tag : HARDWARE_MODULE_TAG, |
Alex Ray | 7915e97 | 2013-10-17 21:52:03 -0700 | [diff] [blame] | 174 | module_api_version : CAMERA_MODULE_API_VERSION_2_2, |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 175 | hal_api_version : HARDWARE_HAL_API_VERSION, |
| 176 | id : CAMERA_HARDWARE_MODULE_ID, |
Alex Ray | 819cfd8 | 2013-02-20 17:46:41 -0800 | [diff] [blame] | 177 | name : "Default Camera HAL", |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 178 | author : "The Android Open Source Project", |
| 179 | methods : &gCameraModuleMethods, |
| 180 | dso : NULL, |
| 181 | reserved : {0}, |
| 182 | }, |
| 183 | get_number_of_cameras : get_number_of_cameras, |
Alex Ray | 819cfd8 | 2013-02-20 17:46:41 -0800 | [diff] [blame] | 184 | get_camera_info : get_camera_info, |
Alex Ray | 7915e97 | 2013-10-17 21:52:03 -0700 | [diff] [blame] | 185 | set_callbacks : set_callbacks, |
Sasha Levitskiy | a82f456 | 2014-04-21 17:20:17 -0700 | [diff] [blame] | 186 | get_vendor_tag_ops : get_vendor_tag_ops, |
Zhijun He | bcdebf3 | 2014-06-06 15:42:17 -0700 | [diff] [blame] | 187 | open_legacy : NULL, |
Chien-Yu Chen | 3015917 | 2015-01-08 11:06:38 -0800 | [diff] [blame] | 188 | set_torch_mode : NULL, |
Eino-Ville Talvala | aee4782 | 2015-04-07 13:47:46 -0700 | [diff] [blame^] | 189 | init : NULL, |
Sasha Levitskiy | a82f456 | 2014-04-21 17:20:17 -0700 | [diff] [blame] | 190 | reserved : {0}, |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 191 | }; |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 192 | } // extern "C" |
Alex Ray | 819cfd8 | 2013-02-20 17:46:41 -0800 | [diff] [blame] | 193 | |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 194 | } // namespace default_camera_hal |