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> |
| 18 | #include <pthread.h> |
Alex Ray | a0ed4be | 2013-02-25 15:02:16 -0800 | [diff] [blame] | 19 | #include <hardware/camera3.h> |
Alex Ray | 083315c | 2013-04-26 19:32:29 -0700 | [diff] [blame] | 20 | #include <sync/sync.h> |
Alex Ray | bfcbd95 | 2013-03-20 13:20:02 -0700 | [diff] [blame] | 21 | #include <system/camera_metadata.h> |
Alex Ray | b0be103 | 2013-05-28 15:52:47 -0700 | [diff] [blame] | 22 | #include <system/graphics.h> |
Alex Ray | a0ed4be | 2013-02-25 15:02:16 -0800 | [diff] [blame] | 23 | #include "CameraHAL.h" |
Alex Ray | b0be103 | 2013-05-28 15:52:47 -0700 | [diff] [blame] | 24 | #include "Metadata.h" |
Alex Ray | bcaf788 | 2013-02-28 16:04:35 -0800 | [diff] [blame] | 25 | #include "Stream.h" |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 26 | |
Alex Ray | ed6b8a7 | 2012-12-27 10:42:22 -0800 | [diff] [blame] | 27 | //#define LOG_NDEBUG 0 |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 28 | #define LOG_TAG "Camera" |
| 29 | #include <cutils/log.h> |
| 30 | |
Alex Ray | ed6b8a7 | 2012-12-27 10:42:22 -0800 | [diff] [blame] | 31 | #define ATRACE_TAG (ATRACE_TAG_CAMERA | ATRACE_TAG_HAL) |
Alex Ray | ea80382 | 2013-10-14 15:56:43 -0700 | [diff] [blame] | 32 | #include <utils/Trace.h> |
Alex Ray | ed6b8a7 | 2012-12-27 10:42:22 -0800 | [diff] [blame] | 33 | |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 34 | #include "Camera.h" |
| 35 | |
Alex Ray | 083315c | 2013-04-26 19:32:29 -0700 | [diff] [blame] | 36 | #define CAMERA_SYNC_TIMEOUT 5000 // in msecs |
| 37 | |
Alex Ray | b0be103 | 2013-05-28 15:52:47 -0700 | [diff] [blame] | 38 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) |
| 39 | |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 40 | namespace default_camera_hal { |
| 41 | |
| 42 | extern "C" { |
| 43 | // Shim passed to the framework to close an opened device. |
| 44 | static int close_device(hw_device_t* dev) |
| 45 | { |
Alex Ray | a0ed4be | 2013-02-25 15:02:16 -0800 | [diff] [blame] | 46 | camera3_device_t* cam_dev = reinterpret_cast<camera3_device_t*>(dev); |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 47 | Camera* cam = static_cast<Camera*>(cam_dev->priv); |
| 48 | return cam->close(); |
| 49 | } |
| 50 | } // extern "C" |
| 51 | |
Alex Ray | a0ed4be | 2013-02-25 15:02:16 -0800 | [diff] [blame] | 52 | Camera::Camera(int id) |
| 53 | : mId(id), |
Alex Ray | b0be103 | 2013-05-28 15:52:47 -0700 | [diff] [blame] | 54 | mStaticInfo(NULL), |
Alex Ray | a0ed4be | 2013-02-25 15:02:16 -0800 | [diff] [blame] | 55 | mBusy(false), |
Alex Ray | bcaf788 | 2013-02-28 16:04:35 -0800 | [diff] [blame] | 56 | mCallbackOps(NULL), |
| 57 | mStreams(NULL), |
Alex Ray | bfcbd95 | 2013-03-20 13:20:02 -0700 | [diff] [blame] | 58 | mNumStreams(0), |
| 59 | mSettings(NULL) |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 60 | { |
Alex Ray | 0f82f5a | 2013-07-17 14:23:04 -0700 | [diff] [blame] | 61 | pthread_mutex_init(&mMutex, NULL); |
| 62 | pthread_mutex_init(&mStaticInfoMutex, NULL); |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 63 | |
Alex Ray | a0ed4be | 2013-02-25 15:02:16 -0800 | [diff] [blame] | 64 | memset(&mDevice, 0, sizeof(mDevice)); |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 65 | mDevice.common.tag = HARDWARE_DEVICE_TAG; |
Alex Ray | b0be103 | 2013-05-28 15:52:47 -0700 | [diff] [blame] | 66 | mDevice.common.version = CAMERA_DEVICE_API_VERSION_3_0; |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 67 | mDevice.common.close = close_device; |
Alex Ray | a0ed4be | 2013-02-25 15:02:16 -0800 | [diff] [blame] | 68 | mDevice.ops = const_cast<camera3_device_ops_t*>(&sOps); |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 69 | mDevice.priv = this; |
| 70 | } |
| 71 | |
| 72 | Camera::~Camera() |
| 73 | { |
Alex Ray | 0f82f5a | 2013-07-17 14:23:04 -0700 | [diff] [blame] | 74 | pthread_mutex_destroy(&mMutex); |
| 75 | pthread_mutex_destroy(&mStaticInfoMutex); |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 76 | } |
| 77 | |
Alex Ray | a0ed4be | 2013-02-25 15:02:16 -0800 | [diff] [blame] | 78 | int Camera::open(const hw_module_t *module, hw_device_t **device) |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 79 | { |
Alex Ray | a0ed4be | 2013-02-25 15:02:16 -0800 | [diff] [blame] | 80 | ALOGI("%s:%d: Opening camera device", __func__, mId); |
Alex Ray | ea80382 | 2013-10-14 15:56:43 -0700 | [diff] [blame] | 81 | ATRACE_CALL(); |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 82 | pthread_mutex_lock(&mMutex); |
| 83 | if (mBusy) { |
| 84 | pthread_mutex_unlock(&mMutex); |
Alex Ray | a0ed4be | 2013-02-25 15:02:16 -0800 | [diff] [blame] | 85 | ALOGE("%s:%d: Error! Camera device already opened", __func__, mId); |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 86 | return -EBUSY; |
| 87 | } |
| 88 | |
| 89 | // TODO: open camera dev nodes, etc |
| 90 | mBusy = true; |
Alex Ray | a0ed4be | 2013-02-25 15:02:16 -0800 | [diff] [blame] | 91 | mDevice.common.module = const_cast<hw_module_t*>(module); |
| 92 | *device = &mDevice.common; |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 93 | |
| 94 | pthread_mutex_unlock(&mMutex); |
| 95 | return 0; |
| 96 | } |
| 97 | |
Alex Ray | b0be103 | 2013-05-28 15:52:47 -0700 | [diff] [blame] | 98 | int Camera::getInfo(struct camera_info *info) |
| 99 | { |
Alex Ray | b0be103 | 2013-05-28 15:52:47 -0700 | [diff] [blame] | 100 | info->facing = CAMERA_FACING_FRONT; |
| 101 | info->orientation = 0; |
| 102 | info->device_version = mDevice.common.version; |
| 103 | |
Alex Ray | 0f82f5a | 2013-07-17 14:23:04 -0700 | [diff] [blame] | 104 | pthread_mutex_lock(&mStaticInfoMutex); |
Alex Ray | b0be103 | 2013-05-28 15:52:47 -0700 | [diff] [blame] | 105 | if (mStaticInfo == NULL) { |
Alex Ray | 0f82f5a | 2013-07-17 14:23:04 -0700 | [diff] [blame] | 106 | mStaticInfo = initStaticInfo(); |
Alex Ray | b0be103 | 2013-05-28 15:52:47 -0700 | [diff] [blame] | 107 | } |
Alex Ray | 0f82f5a | 2013-07-17 14:23:04 -0700 | [diff] [blame] | 108 | pthread_mutex_unlock(&mStaticInfoMutex); |
Alex Ray | b0be103 | 2013-05-28 15:52:47 -0700 | [diff] [blame] | 109 | |
| 110 | info->static_camera_characteristics = mStaticInfo; |
| 111 | |
Alex Ray | 0f82f5a | 2013-07-17 14:23:04 -0700 | [diff] [blame] | 112 | return 0; |
Alex Ray | b0be103 | 2013-05-28 15:52:47 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 115 | int Camera::close() |
| 116 | { |
Alex Ray | a0ed4be | 2013-02-25 15:02:16 -0800 | [diff] [blame] | 117 | ALOGI("%s:%d: Closing camera device", __func__, mId); |
Alex Ray | ea80382 | 2013-10-14 15:56:43 -0700 | [diff] [blame] | 118 | ATRACE_CALL(); |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 119 | pthread_mutex_lock(&mMutex); |
| 120 | if (!mBusy) { |
| 121 | pthread_mutex_unlock(&mMutex); |
Alex Ray | a0ed4be | 2013-02-25 15:02:16 -0800 | [diff] [blame] | 122 | ALOGE("%s:%d: Error! Camera device not open", __func__, mId); |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 123 | return -EINVAL; |
| 124 | } |
| 125 | |
| 126 | // TODO: close camera dev nodes, etc |
| 127 | mBusy = false; |
| 128 | |
| 129 | pthread_mutex_unlock(&mMutex); |
| 130 | return 0; |
| 131 | } |
| 132 | |
Alex Ray | a0ed4be | 2013-02-25 15:02:16 -0800 | [diff] [blame] | 133 | int Camera::initialize(const camera3_callback_ops_t *callback_ops) |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 134 | { |
Alex Ray | a0ed4be | 2013-02-25 15:02:16 -0800 | [diff] [blame] | 135 | ALOGV("%s:%d: callback_ops=%p", __func__, mId, callback_ops); |
| 136 | mCallbackOps = callback_ops; |
Alex Ray | 89a8266 | 2013-05-28 20:32:48 -0700 | [diff] [blame] | 137 | // Create standard settings templates |
| 138 | // 0 is invalid as template |
| 139 | mTemplates[0] = NULL; |
| 140 | // CAMERA3_TEMPLATE_PREVIEW = 1 |
| 141 | mTemplates[1] = new Metadata(ANDROID_CONTROL_MODE_OFF, |
| 142 | ANDROID_CONTROL_CAPTURE_INTENT_PREVIEW); |
| 143 | // CAMERA3_TEMPLATE_STILL_CAPTURE = 2 |
| 144 | mTemplates[2] = new Metadata(ANDROID_CONTROL_MODE_OFF, |
| 145 | ANDROID_CONTROL_CAPTURE_INTENT_STILL_CAPTURE); |
| 146 | // CAMERA3_TEMPLATE_VIDEO_RECORD = 3 |
| 147 | mTemplates[3] = new Metadata(ANDROID_CONTROL_MODE_OFF, |
| 148 | ANDROID_CONTROL_CAPTURE_INTENT_VIDEO_RECORD); |
| 149 | // CAMERA3_TEMPLATE_VIDEO_SNAPSHOT = 4 |
| 150 | mTemplates[4] = new Metadata(ANDROID_CONTROL_MODE_OFF, |
| 151 | ANDROID_CONTROL_CAPTURE_INTENT_VIDEO_SNAPSHOT); |
| 152 | // CAMERA3_TEMPLATE_STILL_ZERO_SHUTTER_LAG = 5 |
| 153 | mTemplates[5] = new Metadata(ANDROID_CONTROL_MODE_OFF, |
| 154 | ANDROID_CONTROL_CAPTURE_INTENT_ZERO_SHUTTER_LAG); |
| 155 | // Pre-generate metadata structures |
| 156 | for (int i = 1; i < CAMERA3_TEMPLATE_COUNT; i++) { |
| 157 | mTemplates[i]->generate(); |
| 158 | } |
| 159 | // TODO: create vendor templates |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 160 | return 0; |
| 161 | } |
| 162 | |
Alex Ray | 0f82f5a | 2013-07-17 14:23:04 -0700 | [diff] [blame] | 163 | camera_metadata_t *Camera::initStaticInfo() |
Alex Ray | b0be103 | 2013-05-28 15:52:47 -0700 | [diff] [blame] | 164 | { |
| 165 | /* |
| 166 | * Setup static camera info. This will have to customized per camera |
| 167 | * device. |
| 168 | */ |
Alex Ray | 0f82f5a | 2013-07-17 14:23:04 -0700 | [diff] [blame] | 169 | Metadata m; |
Alex Ray | b0be103 | 2013-05-28 15:52:47 -0700 | [diff] [blame] | 170 | |
| 171 | /* android.control */ |
| 172 | int32_t android_control_ae_available_target_fps_ranges[] = {30, 30}; |
Alex Ray | 0f82f5a | 2013-07-17 14:23:04 -0700 | [diff] [blame] | 173 | m.addInt32(ANDROID_CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES, |
Alex Ray | b0be103 | 2013-05-28 15:52:47 -0700 | [diff] [blame] | 174 | ARRAY_SIZE(android_control_ae_available_target_fps_ranges), |
| 175 | android_control_ae_available_target_fps_ranges); |
| 176 | |
| 177 | int32_t android_control_ae_compensation_range[] = {-4, 4}; |
Alex Ray | 0f82f5a | 2013-07-17 14:23:04 -0700 | [diff] [blame] | 178 | m.addInt32(ANDROID_CONTROL_AE_COMPENSATION_RANGE, |
Alex Ray | b0be103 | 2013-05-28 15:52:47 -0700 | [diff] [blame] | 179 | ARRAY_SIZE(android_control_ae_compensation_range), |
| 180 | android_control_ae_compensation_range); |
| 181 | |
| 182 | camera_metadata_rational_t android_control_ae_compensation_step[] = {{2,1}}; |
Alex Ray | 0f82f5a | 2013-07-17 14:23:04 -0700 | [diff] [blame] | 183 | m.addRational(ANDROID_CONTROL_AE_COMPENSATION_STEP, |
Alex Ray | b0be103 | 2013-05-28 15:52:47 -0700 | [diff] [blame] | 184 | ARRAY_SIZE(android_control_ae_compensation_step), |
| 185 | android_control_ae_compensation_step); |
| 186 | |
| 187 | int32_t android_control_max_regions[] = {1}; |
Alex Ray | 0f82f5a | 2013-07-17 14:23:04 -0700 | [diff] [blame] | 188 | m.addInt32(ANDROID_CONTROL_MAX_REGIONS, |
Alex Ray | b0be103 | 2013-05-28 15:52:47 -0700 | [diff] [blame] | 189 | ARRAY_SIZE(android_control_max_regions), |
| 190 | android_control_max_regions); |
| 191 | |
| 192 | /* android.jpeg */ |
| 193 | int32_t android_jpeg_available_thumbnail_sizes[] = {0, 0, 128, 96}; |
Alex Ray | 0f82f5a | 2013-07-17 14:23:04 -0700 | [diff] [blame] | 194 | m.addInt32(ANDROID_JPEG_AVAILABLE_THUMBNAIL_SIZES, |
Alex Ray | b0be103 | 2013-05-28 15:52:47 -0700 | [diff] [blame] | 195 | ARRAY_SIZE(android_jpeg_available_thumbnail_sizes), |
| 196 | android_jpeg_available_thumbnail_sizes); |
| 197 | |
Alex Ray | 3e8a9fe | 2013-10-14 15:58:02 -0700 | [diff] [blame^] | 198 | int32_t android_jpeg_max_size[] = {13 * 1024 * 1024}; // 13MB |
| 199 | m.addInt32(ANDROID_JPEG_MAX_SIZE, |
| 200 | ARRAY_SIZE(android_jpeg_max_size), |
| 201 | android_jpeg_max_size); |
| 202 | |
Alex Ray | b0be103 | 2013-05-28 15:52:47 -0700 | [diff] [blame] | 203 | /* android.lens */ |
| 204 | float android_lens_info_available_focal_lengths[] = {1.0}; |
Alex Ray | 0f82f5a | 2013-07-17 14:23:04 -0700 | [diff] [blame] | 205 | m.addFloat(ANDROID_LENS_INFO_AVAILABLE_FOCAL_LENGTHS, |
Alex Ray | b0be103 | 2013-05-28 15:52:47 -0700 | [diff] [blame] | 206 | ARRAY_SIZE(android_lens_info_available_focal_lengths), |
| 207 | android_lens_info_available_focal_lengths); |
| 208 | |
| 209 | /* android.request */ |
| 210 | int32_t android_request_max_num_output_streams[] = {0, 3, 1}; |
Alex Ray | 0f82f5a | 2013-07-17 14:23:04 -0700 | [diff] [blame] | 211 | m.addInt32(ANDROID_REQUEST_MAX_NUM_OUTPUT_STREAMS, |
Alex Ray | b0be103 | 2013-05-28 15:52:47 -0700 | [diff] [blame] | 212 | ARRAY_SIZE(android_request_max_num_output_streams), |
| 213 | android_request_max_num_output_streams); |
| 214 | |
| 215 | /* android.scaler */ |
| 216 | int32_t android_scaler_available_formats[] = { |
| 217 | HAL_PIXEL_FORMAT_RAW_SENSOR, |
| 218 | HAL_PIXEL_FORMAT_BLOB, |
| 219 | HAL_PIXEL_FORMAT_RGBA_8888, |
| 220 | HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, |
| 221 | // These are handled by YCbCr_420_888 |
| 222 | // HAL_PIXEL_FORMAT_YV12, |
| 223 | // HAL_PIXEL_FORMAT_YCrCb_420_SP, |
| 224 | HAL_PIXEL_FORMAT_YCbCr_420_888}; |
Alex Ray | 0f82f5a | 2013-07-17 14:23:04 -0700 | [diff] [blame] | 225 | m.addInt32(ANDROID_SCALER_AVAILABLE_FORMATS, |
Alex Ray | b0be103 | 2013-05-28 15:52:47 -0700 | [diff] [blame] | 226 | ARRAY_SIZE(android_scaler_available_formats), |
| 227 | android_scaler_available_formats); |
| 228 | |
| 229 | int64_t android_scaler_available_jpeg_min_durations[] = {1}; |
Alex Ray | 0f82f5a | 2013-07-17 14:23:04 -0700 | [diff] [blame] | 230 | m.addInt64(ANDROID_SCALER_AVAILABLE_JPEG_MIN_DURATIONS, |
Alex Ray | b0be103 | 2013-05-28 15:52:47 -0700 | [diff] [blame] | 231 | ARRAY_SIZE(android_scaler_available_jpeg_min_durations), |
| 232 | android_scaler_available_jpeg_min_durations); |
| 233 | |
| 234 | int32_t android_scaler_available_jpeg_sizes[] = {640, 480}; |
Alex Ray | 0f82f5a | 2013-07-17 14:23:04 -0700 | [diff] [blame] | 235 | m.addInt32(ANDROID_SCALER_AVAILABLE_JPEG_SIZES, |
Alex Ray | b0be103 | 2013-05-28 15:52:47 -0700 | [diff] [blame] | 236 | ARRAY_SIZE(android_scaler_available_jpeg_sizes), |
| 237 | android_scaler_available_jpeg_sizes); |
| 238 | |
| 239 | float android_scaler_available_max_digital_zoom[] = {1}; |
Alex Ray | 0f82f5a | 2013-07-17 14:23:04 -0700 | [diff] [blame] | 240 | m.addFloat(ANDROID_SCALER_AVAILABLE_MAX_DIGITAL_ZOOM, |
Alex Ray | b0be103 | 2013-05-28 15:52:47 -0700 | [diff] [blame] | 241 | ARRAY_SIZE(android_scaler_available_max_digital_zoom), |
| 242 | android_scaler_available_max_digital_zoom); |
| 243 | |
| 244 | int64_t android_scaler_available_processed_min_durations[] = {1}; |
Alex Ray | 0f82f5a | 2013-07-17 14:23:04 -0700 | [diff] [blame] | 245 | m.addInt64(ANDROID_SCALER_AVAILABLE_PROCESSED_MIN_DURATIONS, |
Alex Ray | b0be103 | 2013-05-28 15:52:47 -0700 | [diff] [blame] | 246 | ARRAY_SIZE(android_scaler_available_processed_min_durations), |
| 247 | android_scaler_available_processed_min_durations); |
| 248 | |
| 249 | int32_t android_scaler_available_processed_sizes[] = {640, 480}; |
Alex Ray | 0f82f5a | 2013-07-17 14:23:04 -0700 | [diff] [blame] | 250 | m.addInt32(ANDROID_SCALER_AVAILABLE_PROCESSED_SIZES, |
Alex Ray | b0be103 | 2013-05-28 15:52:47 -0700 | [diff] [blame] | 251 | ARRAY_SIZE(android_scaler_available_processed_sizes), |
| 252 | android_scaler_available_processed_sizes); |
| 253 | |
| 254 | int64_t android_scaler_available_raw_min_durations[] = {1}; |
Alex Ray | 0f82f5a | 2013-07-17 14:23:04 -0700 | [diff] [blame] | 255 | m.addInt64(ANDROID_SCALER_AVAILABLE_RAW_MIN_DURATIONS, |
Alex Ray | b0be103 | 2013-05-28 15:52:47 -0700 | [diff] [blame] | 256 | ARRAY_SIZE(android_scaler_available_raw_min_durations), |
| 257 | android_scaler_available_raw_min_durations); |
| 258 | |
| 259 | int32_t android_scaler_available_raw_sizes[] = {640, 480}; |
Alex Ray | 0f82f5a | 2013-07-17 14:23:04 -0700 | [diff] [blame] | 260 | m.addInt32(ANDROID_SCALER_AVAILABLE_RAW_SIZES, |
Alex Ray | b0be103 | 2013-05-28 15:52:47 -0700 | [diff] [blame] | 261 | ARRAY_SIZE(android_scaler_available_raw_sizes), |
| 262 | android_scaler_available_raw_sizes); |
| 263 | |
| 264 | /* android.sensor */ |
| 265 | |
| 266 | int32_t android_sensor_info_active_array_size[] = {0, 0, 640, 480}; |
Alex Ray | 0f82f5a | 2013-07-17 14:23:04 -0700 | [diff] [blame] | 267 | m.addInt32(ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE, |
Alex Ray | b0be103 | 2013-05-28 15:52:47 -0700 | [diff] [blame] | 268 | ARRAY_SIZE(android_sensor_info_active_array_size), |
| 269 | android_sensor_info_active_array_size); |
| 270 | |
Zhijun He | bd14689 | 2013-07-18 17:59:30 -0700 | [diff] [blame] | 271 | int32_t android_sensor_info_sensitivity_range[] = |
| 272 | {100, 1600}; |
Alex Ray | 0f82f5a | 2013-07-17 14:23:04 -0700 | [diff] [blame] | 273 | m.addInt32(ANDROID_SENSOR_INFO_SENSITIVITY_RANGE, |
Zhijun He | bd14689 | 2013-07-18 17:59:30 -0700 | [diff] [blame] | 274 | ARRAY_SIZE(android_sensor_info_sensitivity_range), |
| 275 | android_sensor_info_sensitivity_range); |
Alex Ray | b0be103 | 2013-05-28 15:52:47 -0700 | [diff] [blame] | 276 | |
| 277 | int64_t android_sensor_info_max_frame_duration[] = {30000000000}; |
Alex Ray | 0f82f5a | 2013-07-17 14:23:04 -0700 | [diff] [blame] | 278 | m.addInt64(ANDROID_SENSOR_INFO_MAX_FRAME_DURATION, |
Alex Ray | b0be103 | 2013-05-28 15:52:47 -0700 | [diff] [blame] | 279 | ARRAY_SIZE(android_sensor_info_max_frame_duration), |
| 280 | android_sensor_info_max_frame_duration); |
| 281 | |
| 282 | float android_sensor_info_physical_size[] = {3.2, 2.4}; |
Alex Ray | 0f82f5a | 2013-07-17 14:23:04 -0700 | [diff] [blame] | 283 | m.addFloat(ANDROID_SENSOR_INFO_PHYSICAL_SIZE, |
Alex Ray | b0be103 | 2013-05-28 15:52:47 -0700 | [diff] [blame] | 284 | ARRAY_SIZE(android_sensor_info_physical_size), |
| 285 | android_sensor_info_physical_size); |
| 286 | |
| 287 | int32_t android_sensor_info_pixel_array_size[] = {640, 480}; |
Alex Ray | 0f82f5a | 2013-07-17 14:23:04 -0700 | [diff] [blame] | 288 | m.addInt32(ANDROID_SENSOR_INFO_PIXEL_ARRAY_SIZE, |
Alex Ray | b0be103 | 2013-05-28 15:52:47 -0700 | [diff] [blame] | 289 | ARRAY_SIZE(android_sensor_info_pixel_array_size), |
| 290 | android_sensor_info_pixel_array_size); |
| 291 | |
| 292 | int32_t android_sensor_orientation[] = {0}; |
Alex Ray | 0f82f5a | 2013-07-17 14:23:04 -0700 | [diff] [blame] | 293 | m.addInt32(ANDROID_SENSOR_ORIENTATION, |
Alex Ray | b0be103 | 2013-05-28 15:52:47 -0700 | [diff] [blame] | 294 | ARRAY_SIZE(android_sensor_orientation), |
| 295 | android_sensor_orientation); |
| 296 | |
| 297 | /* End of static camera characteristics */ |
| 298 | |
Alex Ray | 0f82f5a | 2013-07-17 14:23:04 -0700 | [diff] [blame] | 299 | return clone_camera_metadata(m.generate()); |
Alex Ray | b0be103 | 2013-05-28 15:52:47 -0700 | [diff] [blame] | 300 | } |
| 301 | |
Alex Ray | bcaf788 | 2013-02-28 16:04:35 -0800 | [diff] [blame] | 302 | int Camera::configureStreams(camera3_stream_configuration_t *stream_config) |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 303 | { |
Alex Ray | bcaf788 | 2013-02-28 16:04:35 -0800 | [diff] [blame] | 304 | camera3_stream_t *astream; |
| 305 | Stream **newStreams = NULL; |
| 306 | |
Alex Ray | ea80382 | 2013-10-14 15:56:43 -0700 | [diff] [blame] | 307 | ATRACE_CALL(); |
Alex Ray | bcaf788 | 2013-02-28 16:04:35 -0800 | [diff] [blame] | 308 | ALOGV("%s:%d: stream_config=%p", __func__, mId, stream_config); |
| 309 | |
| 310 | if (stream_config == NULL) { |
| 311 | ALOGE("%s:%d: NULL stream configuration array", __func__, mId); |
| 312 | return -EINVAL; |
| 313 | } |
| 314 | if (stream_config->num_streams == 0) { |
| 315 | ALOGE("%s:%d: Empty stream configuration array", __func__, mId); |
| 316 | return -EINVAL; |
| 317 | } |
| 318 | |
| 319 | // Create new stream array |
| 320 | newStreams = new Stream*[stream_config->num_streams]; |
| 321 | ALOGV("%s:%d: Number of Streams: %d", __func__, mId, |
| 322 | stream_config->num_streams); |
| 323 | |
| 324 | pthread_mutex_lock(&mMutex); |
| 325 | |
| 326 | // Mark all current streams unused for now |
| 327 | for (int i = 0; i < mNumStreams; i++) |
| 328 | mStreams[i]->mReuse = false; |
| 329 | // Fill new stream array with reused streams and new streams |
Alex Ray | c6bf2f2 | 2013-05-28 15:52:04 -0700 | [diff] [blame] | 330 | for (unsigned int i = 0; i < stream_config->num_streams; i++) { |
Alex Ray | bcaf788 | 2013-02-28 16:04:35 -0800 | [diff] [blame] | 331 | astream = stream_config->streams[i]; |
Alex Ray | 2b286da | 2013-05-29 15:08:29 -0700 | [diff] [blame] | 332 | if (astream->max_buffers > 0) { |
| 333 | ALOGV("%s:%d: Reusing stream %d", __func__, mId, i); |
Alex Ray | bcaf788 | 2013-02-28 16:04:35 -0800 | [diff] [blame] | 334 | newStreams[i] = reuseStream(astream); |
Alex Ray | 2b286da | 2013-05-29 15:08:29 -0700 | [diff] [blame] | 335 | } else { |
| 336 | ALOGV("%s:%d: Creating new stream %d", __func__, mId, i); |
Alex Ray | bcaf788 | 2013-02-28 16:04:35 -0800 | [diff] [blame] | 337 | newStreams[i] = new Stream(mId, astream); |
Alex Ray | 2b286da | 2013-05-29 15:08:29 -0700 | [diff] [blame] | 338 | } |
Alex Ray | bcaf788 | 2013-02-28 16:04:35 -0800 | [diff] [blame] | 339 | |
| 340 | if (newStreams[i] == NULL) { |
| 341 | ALOGE("%s:%d: Error processing stream %d", __func__, mId, i); |
| 342 | goto err_out; |
| 343 | } |
| 344 | astream->priv = newStreams[i]; |
| 345 | } |
| 346 | |
| 347 | // Verify the set of streams in aggregate |
| 348 | if (!isValidStreamSet(newStreams, stream_config->num_streams)) { |
| 349 | ALOGE("%s:%d: Invalid stream set", __func__, mId); |
| 350 | goto err_out; |
| 351 | } |
| 352 | |
| 353 | // Set up all streams (calculate usage/max_buffers for each) |
| 354 | setupStreams(newStreams, stream_config->num_streams); |
| 355 | |
| 356 | // Destroy all old streams and replace stream array with new one |
| 357 | destroyStreams(mStreams, mNumStreams); |
| 358 | mStreams = newStreams; |
| 359 | mNumStreams = stream_config->num_streams; |
| 360 | |
Alex Ray | bfcbd95 | 2013-03-20 13:20:02 -0700 | [diff] [blame] | 361 | // Clear out last seen settings metadata |
| 362 | setSettings(NULL); |
| 363 | |
Alex Ray | bcaf788 | 2013-02-28 16:04:35 -0800 | [diff] [blame] | 364 | pthread_mutex_unlock(&mMutex); |
Alex Ray | a0ed4be | 2013-02-25 15:02:16 -0800 | [diff] [blame] | 365 | return 0; |
Alex Ray | bcaf788 | 2013-02-28 16:04:35 -0800 | [diff] [blame] | 366 | |
| 367 | err_out: |
| 368 | // Clean up temporary streams, preserve existing mStreams/mNumStreams |
| 369 | destroyStreams(newStreams, stream_config->num_streams); |
| 370 | pthread_mutex_unlock(&mMutex); |
| 371 | return -EINVAL; |
| 372 | } |
| 373 | |
| 374 | void Camera::destroyStreams(Stream **streams, int count) |
| 375 | { |
| 376 | if (streams == NULL) |
| 377 | return; |
| 378 | for (int i = 0; i < count; i++) { |
| 379 | // Only destroy streams that weren't reused |
| 380 | if (streams[i] != NULL && !streams[i]->mReuse) |
| 381 | delete streams[i]; |
| 382 | } |
| 383 | delete [] streams; |
| 384 | } |
| 385 | |
| 386 | Stream *Camera::reuseStream(camera3_stream_t *astream) |
| 387 | { |
| 388 | Stream *priv = reinterpret_cast<Stream*>(astream->priv); |
| 389 | // Verify the re-used stream's parameters match |
| 390 | if (!priv->isValidReuseStream(mId, astream)) { |
| 391 | ALOGE("%s:%d: Mismatched parameter in reused stream", __func__, mId); |
| 392 | return NULL; |
| 393 | } |
| 394 | // Mark stream to be reused |
| 395 | priv->mReuse = true; |
| 396 | return priv; |
| 397 | } |
| 398 | |
| 399 | bool Camera::isValidStreamSet(Stream **streams, int count) |
| 400 | { |
| 401 | int inputs = 0; |
| 402 | int outputs = 0; |
| 403 | |
| 404 | if (streams == NULL) { |
| 405 | ALOGE("%s:%d: NULL stream configuration streams", __func__, mId); |
| 406 | return false; |
| 407 | } |
| 408 | if (count == 0) { |
| 409 | ALOGE("%s:%d: Zero count stream configuration streams", __func__, mId); |
| 410 | return false; |
| 411 | } |
| 412 | // Validate there is at most one input stream and at least one output stream |
| 413 | for (int i = 0; i < count; i++) { |
| 414 | // A stream may be both input and output (bidirectional) |
| 415 | if (streams[i]->isInputType()) |
| 416 | inputs++; |
| 417 | if (streams[i]->isOutputType()) |
| 418 | outputs++; |
| 419 | } |
Alex Ray | 768216e | 2013-07-02 16:56:14 -0700 | [diff] [blame] | 420 | ALOGV("%s:%d: Configuring %d output streams and %d input streams", |
| 421 | __func__, mId, outputs, inputs); |
Alex Ray | bcaf788 | 2013-02-28 16:04:35 -0800 | [diff] [blame] | 422 | if (outputs < 1) { |
| 423 | ALOGE("%s:%d: Stream config must have >= 1 output", __func__, mId); |
| 424 | return false; |
| 425 | } |
| 426 | if (inputs > 1) { |
| 427 | ALOGE("%s:%d: Stream config must have <= 1 input", __func__, mId); |
| 428 | return false; |
| 429 | } |
| 430 | // TODO: check for correct number of Bayer/YUV/JPEG/Encoder streams |
| 431 | return true; |
| 432 | } |
| 433 | |
| 434 | void Camera::setupStreams(Stream **streams, int count) |
| 435 | { |
| 436 | /* |
| 437 | * This is where the HAL has to decide internally how to handle all of the |
| 438 | * streams, and then produce usage and max_buffer values for each stream. |
| 439 | * Note, the stream array has been checked before this point for ALL invalid |
| 440 | * conditions, so it must find a successful configuration for this stream |
| 441 | * array. The HAL may not return an error from this point. |
| 442 | * |
| 443 | * In this demo HAL, we just set all streams to be the same dummy values; |
| 444 | * real implementations will want to avoid USAGE_SW_{READ|WRITE}_OFTEN. |
| 445 | */ |
| 446 | for (int i = 0; i < count; i++) { |
| 447 | uint32_t usage = 0; |
| 448 | |
| 449 | if (streams[i]->isOutputType()) |
| 450 | usage |= GRALLOC_USAGE_SW_WRITE_OFTEN | |
| 451 | GRALLOC_USAGE_HW_CAMERA_WRITE; |
| 452 | if (streams[i]->isInputType()) |
| 453 | usage |= GRALLOC_USAGE_SW_READ_OFTEN | |
| 454 | GRALLOC_USAGE_HW_CAMERA_READ; |
| 455 | |
| 456 | streams[i]->setUsage(usage); |
| 457 | streams[i]->setMaxBuffers(1); |
| 458 | } |
Alex Ray | a0ed4be | 2013-02-25 15:02:16 -0800 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | int Camera::registerStreamBuffers(const camera3_stream_buffer_set_t *buf_set) |
| 462 | { |
| 463 | ALOGV("%s:%d: buffer_set=%p", __func__, mId, buf_set); |
Alex Ray | 8a8f86b | 2013-03-01 01:32:21 -0800 | [diff] [blame] | 464 | if (buf_set == NULL) { |
| 465 | ALOGE("%s:%d: NULL buffer set", __func__, mId); |
| 466 | return -EINVAL; |
| 467 | } |
| 468 | if (buf_set->stream == NULL) { |
| 469 | ALOGE("%s:%d: NULL stream handle", __func__, mId); |
| 470 | return -EINVAL; |
| 471 | } |
| 472 | Stream *stream = reinterpret_cast<Stream*>(buf_set->stream->priv); |
| 473 | return stream->registerBuffers(buf_set); |
Alex Ray | a0ed4be | 2013-02-25 15:02:16 -0800 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | const camera_metadata_t* Camera::constructDefaultRequestSettings(int type) |
| 477 | { |
| 478 | ALOGV("%s:%d: type=%d", __func__, mId, type); |
Alex Ray | 89a8266 | 2013-05-28 20:32:48 -0700 | [diff] [blame] | 479 | |
| 480 | if (type < 1 || type >= CAMERA3_TEMPLATE_COUNT) { |
| 481 | ALOGE("%s:%d: Invalid template request type: %d", __func__, mId, type); |
| 482 | return NULL; |
| 483 | } |
| 484 | return mTemplates[type]->generate(); |
Alex Ray | a0ed4be | 2013-02-25 15:02:16 -0800 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | int Camera::processCaptureRequest(camera3_capture_request_t *request) |
| 488 | { |
Alex Ray | 083315c | 2013-04-26 19:32:29 -0700 | [diff] [blame] | 489 | camera3_capture_result result; |
| 490 | |
Alex Ray | a0ed4be | 2013-02-25 15:02:16 -0800 | [diff] [blame] | 491 | ALOGV("%s:%d: request=%p", __func__, mId, request); |
Alex Ray | ea80382 | 2013-10-14 15:56:43 -0700 | [diff] [blame] | 492 | ATRACE_CALL(); |
Alex Ray | a0ed4be | 2013-02-25 15:02:16 -0800 | [diff] [blame] | 493 | |
| 494 | if (request == NULL) { |
| 495 | ALOGE("%s:%d: NULL request recieved", __func__, mId); |
Alex Ray | a0ed4be | 2013-02-25 15:02:16 -0800 | [diff] [blame] | 496 | return -EINVAL; |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 497 | } |
| 498 | |
Alex Ray | bfcbd95 | 2013-03-20 13:20:02 -0700 | [diff] [blame] | 499 | ALOGV("%s:%d: Request Frame:%d Settings:%p", __func__, mId, |
| 500 | request->frame_number, request->settings); |
| 501 | |
| 502 | // NULL indicates use last settings |
| 503 | if (request->settings == NULL) { |
| 504 | if (mSettings == NULL) { |
| 505 | ALOGE("%s:%d: NULL settings without previous set Frame:%d Req:%p", |
| 506 | __func__, mId, request->frame_number, request); |
| 507 | return -EINVAL; |
| 508 | } |
| 509 | } else { |
| 510 | setSettings(request->settings); |
| 511 | } |
| 512 | |
Alex Ray | 11bbeef | 2013-04-26 14:47:08 -0700 | [diff] [blame] | 513 | if (request->input_buffer != NULL) { |
| 514 | ALOGV("%s:%d: Reprocessing input buffer %p", __func__, mId, |
| 515 | request->input_buffer); |
| 516 | |
| 517 | if (!isValidReprocessSettings(request->settings)) { |
| 518 | ALOGE("%s:%d: Invalid settings for reprocess request: %p", |
| 519 | __func__, mId, request->settings); |
| 520 | return -EINVAL; |
| 521 | } |
| 522 | } else { |
| 523 | ALOGV("%s:%d: Capturing new frame.", __func__, mId); |
| 524 | |
| 525 | if (!isValidCaptureSettings(request->settings)) { |
| 526 | ALOGE("%s:%d: Invalid settings for capture request: %p", |
| 527 | __func__, mId, request->settings); |
| 528 | return -EINVAL; |
| 529 | } |
| 530 | } |
| 531 | |
Alex Ray | 083315c | 2013-04-26 19:32:29 -0700 | [diff] [blame] | 532 | if (request->num_output_buffers <= 0) { |
| 533 | ALOGE("%s:%d: Invalid number of output buffers: %d", __func__, mId, |
| 534 | request->num_output_buffers); |
| 535 | return -EINVAL; |
| 536 | } |
| 537 | result.num_output_buffers = request->num_output_buffers; |
| 538 | result.output_buffers = new camera3_stream_buffer_t[result.num_output_buffers]; |
| 539 | for (unsigned int i = 0; i < request->num_output_buffers; i++) { |
| 540 | int res = processCaptureBuffer(&request->output_buffers[i], |
| 541 | const_cast<camera3_stream_buffer_t*>(&result.output_buffers[i])); |
| 542 | if (res) |
| 543 | goto err_out; |
| 544 | } |
| 545 | |
| 546 | result.frame_number = request->frame_number; |
| 547 | // TODO: return actual captured/reprocessed settings |
| 548 | result.result = request->settings; |
| 549 | // TODO: asynchronously return results |
Alex Ray | 764e442 | 2013-06-04 12:38:07 -0700 | [diff] [blame] | 550 | notifyShutter(request->frame_number, 0); |
Alex Ray | 083315c | 2013-04-26 19:32:29 -0700 | [diff] [blame] | 551 | mCallbackOps->process_capture_result(mCallbackOps, &result); |
| 552 | |
Alex Ray | a0ed4be | 2013-02-25 15:02:16 -0800 | [diff] [blame] | 553 | return 0; |
Alex Ray | 083315c | 2013-04-26 19:32:29 -0700 | [diff] [blame] | 554 | |
| 555 | err_out: |
| 556 | delete [] result.output_buffers; |
| 557 | // TODO: this should probably be a total device failure; transient for now |
| 558 | return -EINVAL; |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 559 | } |
| 560 | |
Alex Ray | bfcbd95 | 2013-03-20 13:20:02 -0700 | [diff] [blame] | 561 | void Camera::setSettings(const camera_metadata_t *new_settings) |
| 562 | { |
| 563 | if (mSettings != NULL) { |
| 564 | free_camera_metadata(mSettings); |
| 565 | mSettings = NULL; |
| 566 | } |
| 567 | |
| 568 | if (new_settings != NULL) |
| 569 | mSettings = clone_camera_metadata(new_settings); |
| 570 | } |
| 571 | |
Alex Ray | c6bf2f2 | 2013-05-28 15:52:04 -0700 | [diff] [blame] | 572 | bool Camera::isValidCaptureSettings(const camera_metadata_t* /*settings*/) |
Alex Ray | 11bbeef | 2013-04-26 14:47:08 -0700 | [diff] [blame] | 573 | { |
| 574 | // TODO: reject settings that cannot be captured |
| 575 | return true; |
| 576 | } |
| 577 | |
Alex Ray | c6bf2f2 | 2013-05-28 15:52:04 -0700 | [diff] [blame] | 578 | bool Camera::isValidReprocessSettings(const camera_metadata_t* /*settings*/) |
Alex Ray | 11bbeef | 2013-04-26 14:47:08 -0700 | [diff] [blame] | 579 | { |
| 580 | // TODO: reject settings that cannot be reprocessed |
| 581 | // input buffers unimplemented, use this to reject reprocessing requests |
| 582 | ALOGE("%s:%d: Input buffer reprocessing not implemented", __func__, mId); |
| 583 | return false; |
| 584 | } |
| 585 | |
Alex Ray | 083315c | 2013-04-26 19:32:29 -0700 | [diff] [blame] | 586 | int Camera::processCaptureBuffer(const camera3_stream_buffer_t *in, |
| 587 | camera3_stream_buffer_t *out) |
| 588 | { |
Alex Ray | 77ecfd7 | 2013-05-30 00:19:04 -0700 | [diff] [blame] | 589 | if (in->acquire_fence != -1) { |
| 590 | int res = sync_wait(in->acquire_fence, CAMERA_SYNC_TIMEOUT); |
| 591 | if (res == -ETIME) { |
| 592 | ALOGE("%s:%d: Timeout waiting on buffer acquire fence", |
| 593 | __func__, mId); |
| 594 | return res; |
| 595 | } else if (res) { |
| 596 | ALOGE("%s:%d: Error waiting on buffer acquire fence: %s(%d)", |
| 597 | __func__, mId, strerror(-res), res); |
| 598 | return res; |
| 599 | } |
Alex Ray | 083315c | 2013-04-26 19:32:29 -0700 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | out->stream = in->stream; |
| 603 | out->buffer = in->buffer; |
| 604 | out->status = CAMERA3_BUFFER_STATUS_OK; |
| 605 | // TODO: use driver-backed release fences |
| 606 | out->acquire_fence = -1; |
| 607 | out->release_fence = -1; |
| 608 | |
| 609 | // TODO: lock and software-paint buffer |
| 610 | return 0; |
| 611 | } |
| 612 | |
Alex Ray | 764e442 | 2013-06-04 12:38:07 -0700 | [diff] [blame] | 613 | void Camera::notifyShutter(uint32_t frame_number, uint64_t timestamp) |
| 614 | { |
| 615 | int res; |
| 616 | struct timespec ts; |
| 617 | |
| 618 | // If timestamp is 0, get timestamp from right now instead |
| 619 | if (timestamp == 0) { |
| 620 | ALOGW("%s:%d: No timestamp provided, using CLOCK_BOOTTIME", |
| 621 | __func__, mId); |
| 622 | res = clock_gettime(CLOCK_BOOTTIME, &ts); |
| 623 | if (res == 0) { |
| 624 | timestamp = ts.tv_sec * 1000000000ULL + ts.tv_nsec; |
| 625 | } else { |
| 626 | ALOGE("%s:%d: No timestamp and failed to get CLOCK_BOOTTIME %s(%d)", |
| 627 | __func__, mId, strerror(errno), errno); |
| 628 | } |
| 629 | } |
| 630 | camera3_notify_msg_t m; |
| 631 | memset(&m, 0, sizeof(m)); |
| 632 | m.type = CAMERA3_MSG_SHUTTER; |
| 633 | m.message.shutter.frame_number = frame_number; |
| 634 | m.message.shutter.timestamp = timestamp; |
| 635 | mCallbackOps->notify(mCallbackOps, &m); |
| 636 | } |
| 637 | |
Alex Ray | a0ed4be | 2013-02-25 15:02:16 -0800 | [diff] [blame] | 638 | void Camera::getMetadataVendorTagOps(vendor_tag_query_ops_t *ops) |
| 639 | { |
| 640 | ALOGV("%s:%d: ops=%p", __func__, mId, ops); |
| 641 | // TODO: return vendor tag ops |
| 642 | } |
| 643 | |
| 644 | void Camera::dump(int fd) |
| 645 | { |
Alex Ray | af3a461 | 2013-04-29 14:16:10 -0700 | [diff] [blame] | 646 | ALOGV("%s:%d: Dumping to fd %d", __func__, mId, fd); |
Alex Ray | a0ed4be | 2013-02-25 15:02:16 -0800 | [diff] [blame] | 647 | // TODO: dprintf all relevant state to fd |
| 648 | } |
| 649 | |
| 650 | extern "C" { |
| 651 | // Get handle to camera from device priv data |
| 652 | static Camera *camdev_to_camera(const camera3_device_t *dev) |
| 653 | { |
| 654 | return reinterpret_cast<Camera*>(dev->priv); |
| 655 | } |
| 656 | |
| 657 | static int initialize(const camera3_device_t *dev, |
| 658 | const camera3_callback_ops_t *callback_ops) |
| 659 | { |
| 660 | return camdev_to_camera(dev)->initialize(callback_ops); |
| 661 | } |
| 662 | |
| 663 | static int configure_streams(const camera3_device_t *dev, |
| 664 | camera3_stream_configuration_t *stream_list) |
| 665 | { |
| 666 | return camdev_to_camera(dev)->configureStreams(stream_list); |
| 667 | } |
| 668 | |
| 669 | static int register_stream_buffers(const camera3_device_t *dev, |
| 670 | const camera3_stream_buffer_set_t *buffer_set) |
| 671 | { |
| 672 | return camdev_to_camera(dev)->registerStreamBuffers(buffer_set); |
| 673 | } |
| 674 | |
| 675 | static const camera_metadata_t *construct_default_request_settings( |
| 676 | const camera3_device_t *dev, int type) |
| 677 | { |
| 678 | return camdev_to_camera(dev)->constructDefaultRequestSettings(type); |
| 679 | } |
| 680 | |
| 681 | static int process_capture_request(const camera3_device_t *dev, |
| 682 | camera3_capture_request_t *request) |
| 683 | { |
| 684 | return camdev_to_camera(dev)->processCaptureRequest(request); |
| 685 | } |
| 686 | |
| 687 | static void get_metadata_vendor_tag_ops(const camera3_device_t *dev, |
| 688 | vendor_tag_query_ops_t *ops) |
| 689 | { |
| 690 | camdev_to_camera(dev)->getMetadataVendorTagOps(ops); |
| 691 | } |
| 692 | |
| 693 | static void dump(const camera3_device_t *dev, int fd) |
| 694 | { |
| 695 | camdev_to_camera(dev)->dump(fd); |
| 696 | } |
| 697 | } // extern "C" |
| 698 | |
| 699 | const camera3_device_ops_t Camera::sOps = { |
| 700 | .initialize = default_camera_hal::initialize, |
| 701 | .configure_streams = default_camera_hal::configure_streams, |
| 702 | .register_stream_buffers = default_camera_hal::register_stream_buffers, |
| 703 | .construct_default_request_settings = |
| 704 | default_camera_hal::construct_default_request_settings, |
| 705 | .process_capture_request = default_camera_hal::process_capture_request, |
| 706 | .get_metadata_vendor_tag_ops = |
| 707 | default_camera_hal::get_metadata_vendor_tag_ops, |
| 708 | .dump = default_camera_hal::dump |
| 709 | }; |
| 710 | |
Alex Ray | 7ee0b7a | 2012-11-06 00:12:49 -0800 | [diff] [blame] | 711 | } // namespace default_camera_hal |