Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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 "Camera3-Device" |
| 18 | #define ATRACE_TAG ATRACE_TAG_CAMERA |
| 19 | //#define LOG_NDEBUG 0 |
| 20 | //#define LOG_NNDEBUG 0 // Per-frame verbose logging |
| 21 | |
| 22 | #ifdef LOG_NNDEBUG |
| 23 | #define ALOGVV(...) ALOGV(__VA_ARGS__) |
| 24 | #else |
| 25 | #define ALOGVV(...) ((void)0) |
| 26 | #endif |
| 27 | |
| 28 | #include <utils/Log.h> |
| 29 | #include <utils/Trace.h> |
| 30 | #include <utils/Timers.h> |
| 31 | #include "Camera3Device.h" |
| 32 | |
| 33 | namespace android { |
| 34 | |
| 35 | |
| 36 | Camera3Device::Camera3Device(int id): |
| 37 | mId(id), |
| 38 | mHal3Device(NULL) |
| 39 | { |
| 40 | ATRACE_CALL(); |
| 41 | camera3_callback_ops::notify = &sNotify; |
| 42 | camera3_callback_ops::process_capture_result = &sProcessCaptureResult; |
| 43 | ALOGV("%s: Created device for camera %d", __FUNCTION__, id); |
| 44 | } |
| 45 | |
| 46 | Camera3Device::~Camera3Device() |
| 47 | { |
| 48 | ATRACE_CALL(); |
| 49 | ALOGV("%s: Tearing down for camera id %d", __FUNCTION__, mId); |
| 50 | disconnect(); |
| 51 | } |
| 52 | |
Igor Murashkin | 7138105 | 2013-03-04 14:53:08 -0800 | [diff] [blame] | 53 | int Camera3Device::getId() const { |
| 54 | return mId; |
| 55 | } |
| 56 | |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 57 | status_t Camera3Device::initialize(camera_module_t *module) |
| 58 | { |
| 59 | ATRACE_CALL(); |
| 60 | ALOGV("%s: Initializing device for camera %d", __FUNCTION__, mId); |
| 61 | if (mHal3Device != NULL) { |
| 62 | ALOGE("%s: Already initialized!", __FUNCTION__); |
| 63 | return INVALID_OPERATION; |
| 64 | } |
| 65 | |
| 66 | /** Open HAL device */ |
| 67 | |
| 68 | status_t res; |
| 69 | String8 deviceName = String8::format("%d", mId); |
| 70 | |
| 71 | camera3_device_t *device; |
| 72 | |
| 73 | res = module->common.methods->open(&module->common, deviceName.string(), |
| 74 | reinterpret_cast<hw_device_t**>(&device)); |
| 75 | |
| 76 | if (res != OK) { |
| 77 | ALOGE("%s: Could not open camera %d: %s (%d)", __FUNCTION__, |
| 78 | mId, strerror(-res), res); |
| 79 | return res; |
| 80 | } |
| 81 | |
| 82 | /** Cross-check device version */ |
| 83 | |
| 84 | if (device->common.version != CAMERA_DEVICE_API_VERSION_3_0) { |
| 85 | ALOGE("%s: Could not open camera %d: " |
| 86 | "Camera device is not version %x, reports %x instead", |
| 87 | __FUNCTION__, mId, CAMERA_DEVICE_API_VERSION_3_0, |
| 88 | device->common.version); |
| 89 | device->common.close(&device->common); |
| 90 | return BAD_VALUE; |
| 91 | } |
| 92 | |
| 93 | camera_info info; |
| 94 | res = module->get_camera_info(mId, &info); |
| 95 | if (res != OK) return res; |
| 96 | |
| 97 | if (info.device_version != device->common.version) { |
| 98 | ALOGE("%s: HAL reporting mismatched camera_info version (%x)" |
| 99 | " and device version (%x).", __FUNCTION__, |
| 100 | device->common.version, info.device_version); |
| 101 | device->common.close(&device->common); |
| 102 | return BAD_VALUE; |
| 103 | } |
| 104 | |
| 105 | /** Initialize device with callback functions */ |
| 106 | |
| 107 | res = device->ops->initialize(device, this); |
| 108 | if (res != OK) { |
| 109 | ALOGE("%s: Camera %d: Unable to initialize HAL device: %s (%d)", |
| 110 | __FUNCTION__, mId, strerror(-res), res); |
| 111 | device->common.close(&device->common); |
| 112 | return BAD_VALUE; |
| 113 | } |
| 114 | |
| 115 | /** Get vendor metadata tags */ |
| 116 | |
| 117 | mVendorTagOps.get_camera_vendor_section_name = NULL; |
| 118 | |
| 119 | device->ops->get_metadata_vendor_tag_ops(device, &mVendorTagOps); |
| 120 | |
| 121 | if (mVendorTagOps.get_camera_vendor_section_name != NULL) { |
| 122 | res = set_camera_metadata_vendor_tag_ops(&mVendorTagOps); |
| 123 | if (res != OK) { |
| 124 | ALOGE("%s: Camera %d: Unable to set tag ops: %s (%d)", |
| 125 | __FUNCTION__, mId, strerror(-res), res); |
| 126 | device->common.close(&device->common); |
| 127 | return res; |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | /** Start up request queue thread */ |
| 132 | |
| 133 | requestThread = new RequestThread(this); |
| 134 | res = requestThread->run(String8::format("C3Dev-%d-ReqQueue", mId).string()); |
| 135 | if (res != OK) { |
| 136 | ALOGE("%s: Camera %d: Unable to start request queue thread: %s (%d)", |
| 137 | __FUNCTION__, mId, strerror(-res), res); |
| 138 | device->common.close(&device->common); |
| 139 | return res; |
| 140 | } |
| 141 | |
| 142 | /** Everything is good to go */ |
| 143 | |
| 144 | mDeviceInfo = info.static_camera_characteristics; |
| 145 | mHal3Device = device; |
| 146 | |
| 147 | return OK; |
| 148 | } |
| 149 | |
| 150 | status_t Camera3Device::disconnect() { |
| 151 | ATRACE_CALL(); |
| 152 | |
| 153 | ALOGE("%s: Unimplemented", __FUNCTION__); |
| 154 | return INVALID_OPERATION; |
| 155 | } |
| 156 | |
| 157 | status_t Camera3Device::dump(int fd, const Vector<String16> &args) { |
| 158 | ATRACE_CALL(); |
| 159 | (void)args; |
| 160 | |
| 161 | mHal3Device->ops->dump(mHal3Device, fd); |
| 162 | |
| 163 | return OK; |
| 164 | } |
| 165 | |
| 166 | const CameraMetadata& Camera3Device::info() const { |
| 167 | ALOGVV("%s: E", __FUNCTION__); |
| 168 | |
| 169 | return mDeviceInfo; |
| 170 | } |
| 171 | |
| 172 | status_t Camera3Device::capture(CameraMetadata &request) { |
| 173 | ATRACE_CALL(); |
| 174 | (void)request; |
| 175 | |
| 176 | ALOGE("%s: Unimplemented", __FUNCTION__); |
| 177 | return INVALID_OPERATION; |
| 178 | } |
| 179 | |
| 180 | |
| 181 | status_t Camera3Device::setStreamingRequest(const CameraMetadata &request) { |
| 182 | ATRACE_CALL(); |
| 183 | (void)request; |
| 184 | |
| 185 | ALOGE("%s: Unimplemented", __FUNCTION__); |
| 186 | return INVALID_OPERATION; |
| 187 | } |
| 188 | |
| 189 | status_t Camera3Device::clearStreamingRequest() { |
| 190 | ATRACE_CALL(); |
| 191 | |
| 192 | ALOGE("%s: Unimplemented", __FUNCTION__); |
| 193 | return INVALID_OPERATION; |
| 194 | } |
| 195 | |
| 196 | status_t Camera3Device::waitUntilRequestReceived(int32_t requestId, nsecs_t timeout) { |
| 197 | ATRACE_CALL(); |
| 198 | (void)requestId; (void)timeout; |
| 199 | |
| 200 | ALOGE("%s: Unimplemented", __FUNCTION__); |
| 201 | return INVALID_OPERATION; |
| 202 | } |
| 203 | |
| 204 | status_t Camera3Device::createStream(sp<ANativeWindow> consumer, |
| 205 | uint32_t width, uint32_t height, int format, size_t size, int *id) { |
| 206 | ATRACE_CALL(); |
| 207 | (void)consumer; (void)width; (void)height; (void)format; |
| 208 | (void)size; (void)id; |
| 209 | |
| 210 | ALOGE("%s: Unimplemented", __FUNCTION__); |
| 211 | return INVALID_OPERATION; |
| 212 | } |
| 213 | |
| 214 | status_t Camera3Device::createReprocessStreamFromStream(int outputId, int *id) { |
| 215 | ATRACE_CALL(); |
| 216 | (void)outputId; (void)id; |
| 217 | |
| 218 | ALOGE("%s: Unimplemented", __FUNCTION__); |
| 219 | return INVALID_OPERATION; |
| 220 | } |
| 221 | |
| 222 | |
| 223 | status_t Camera3Device::getStreamInfo(int id, |
| 224 | uint32_t *width, uint32_t *height, uint32_t *format) { |
| 225 | ATRACE_CALL(); |
| 226 | (void)id; (void)width; (void)height; (void)format; |
| 227 | |
| 228 | ALOGE("%s: Unimplemented", __FUNCTION__); |
| 229 | return INVALID_OPERATION; |
| 230 | } |
| 231 | |
| 232 | status_t Camera3Device::setStreamTransform(int id, |
| 233 | int transform) { |
| 234 | ATRACE_CALL(); |
| 235 | (void)id; (void)transform; |
| 236 | |
| 237 | ALOGE("%s: Unimplemented", __FUNCTION__); |
| 238 | return INVALID_OPERATION; |
| 239 | } |
| 240 | |
| 241 | status_t Camera3Device::deleteStream(int id) { |
| 242 | ATRACE_CALL(); |
| 243 | (void)id; |
| 244 | |
| 245 | ALOGE("%s: Unimplemented", __FUNCTION__); |
| 246 | return INVALID_OPERATION; |
| 247 | } |
| 248 | |
| 249 | status_t Camera3Device::deleteReprocessStream(int id) { |
| 250 | ATRACE_CALL(); |
| 251 | (void)id; |
| 252 | |
| 253 | ALOGE("%s: Unimplemented", __FUNCTION__); |
| 254 | return INVALID_OPERATION; |
| 255 | } |
| 256 | |
| 257 | |
| 258 | status_t Camera3Device::createDefaultRequest(int templateId, |
| 259 | CameraMetadata *request) { |
| 260 | ATRACE_CALL(); |
| 261 | ALOGV("%s: E", __FUNCTION__); |
| 262 | |
| 263 | const camera_metadata_t *rawRequest; |
| 264 | rawRequest = mHal3Device->ops->construct_default_request_settings( |
| 265 | mHal3Device, templateId); |
| 266 | if (rawRequest == NULL) return DEAD_OBJECT; |
| 267 | *request = rawRequest; |
| 268 | |
| 269 | return OK; |
| 270 | } |
| 271 | |
| 272 | status_t Camera3Device::waitUntilDrained() { |
| 273 | ATRACE_CALL(); |
| 274 | |
| 275 | ALOGE("%s: Unimplemented", __FUNCTION__); |
| 276 | return INVALID_OPERATION; |
| 277 | } |
| 278 | |
| 279 | status_t Camera3Device::setNotifyCallback(NotificationListener *listener) { |
| 280 | ATRACE_CALL(); |
| 281 | (void)listener; |
| 282 | |
| 283 | ALOGE("%s: Unimplemented", __FUNCTION__); |
| 284 | return INVALID_OPERATION; |
| 285 | } |
| 286 | |
| 287 | status_t Camera3Device::waitForNextFrame(nsecs_t timeout) { |
| 288 | (void)timeout; |
| 289 | |
| 290 | ALOGE("%s: Unimplemented", __FUNCTION__); |
| 291 | return INVALID_OPERATION; |
| 292 | } |
| 293 | |
| 294 | status_t Camera3Device::getNextFrame(CameraMetadata *frame) { |
| 295 | ATRACE_CALL(); |
| 296 | (void)frame; |
| 297 | |
| 298 | ALOGE("%s: Unimplemented", __FUNCTION__); |
| 299 | return INVALID_OPERATION; |
| 300 | } |
| 301 | |
| 302 | status_t Camera3Device::triggerAutofocus(uint32_t id) { |
| 303 | ATRACE_CALL(); |
| 304 | (void)id; |
| 305 | |
| 306 | |
| 307 | ALOGE("%s: Unimplemented", __FUNCTION__); |
| 308 | return INVALID_OPERATION; |
| 309 | } |
| 310 | |
| 311 | status_t Camera3Device::triggerCancelAutofocus(uint32_t id) { |
| 312 | ATRACE_CALL(); |
| 313 | (void)id; |
| 314 | |
| 315 | ALOGE("%s: Unimplemented", __FUNCTION__); |
| 316 | return INVALID_OPERATION; |
| 317 | |
| 318 | } |
| 319 | |
| 320 | status_t Camera3Device::triggerPrecaptureMetering(uint32_t id) { |
| 321 | ATRACE_CALL(); |
| 322 | (void)id; |
| 323 | |
| 324 | ALOGE("%s: Unimplemented", __FUNCTION__); |
| 325 | return INVALID_OPERATION; |
| 326 | |
| 327 | } |
| 328 | |
| 329 | status_t Camera3Device::pushReprocessBuffer(int reprocessStreamId, |
| 330 | buffer_handle_t *buffer, wp<BufferReleasedListener> listener) { |
| 331 | ATRACE_CALL(); |
| 332 | (void)reprocessStreamId; (void)buffer; (void)listener; |
| 333 | |
| 334 | ALOGE("%s: Unimplemented", __FUNCTION__); |
| 335 | return INVALID_OPERATION; |
| 336 | } |
| 337 | |
| 338 | Camera3Device::RequestThread::RequestThread(wp<Camera3Device> parent) : |
| 339 | Thread(false), |
| 340 | mParent(parent) { |
| 341 | } |
| 342 | |
| 343 | bool Camera3Device::RequestThread::threadLoop() { |
| 344 | ALOGE("%s: Unimplemented", __FUNCTION__); |
| 345 | |
| 346 | return false; |
| 347 | } |
| 348 | |
| 349 | void Camera3Device::processCaptureResult(const camera3_capture_result *result) { |
| 350 | (void)result; |
| 351 | |
| 352 | ALOGE("%s: Unimplemented", __FUNCTION__); |
| 353 | } |
| 354 | |
| 355 | void Camera3Device::notify(const camera3_notify_msg *msg) { |
| 356 | (void)msg; |
| 357 | |
| 358 | ALOGE("%s: Unimplemented", __FUNCTION__); |
| 359 | } |
| 360 | |
| 361 | /** |
| 362 | * Static callback forwarding methods from HAL to instance |
| 363 | */ |
| 364 | |
| 365 | void Camera3Device::sProcessCaptureResult(const camera3_callback_ops *cb, |
| 366 | const camera3_capture_result *result) { |
| 367 | Camera3Device *d = |
| 368 | const_cast<Camera3Device*>(static_cast<const Camera3Device*>(cb)); |
| 369 | d->processCaptureResult(result); |
| 370 | } |
| 371 | |
| 372 | void Camera3Device::sNotify(const camera3_callback_ops *cb, |
| 373 | const camera3_notify_msg *msg) { |
| 374 | Camera3Device *d = |
| 375 | const_cast<Camera3Device*>(static_cast<const Camera3Device*>(cb)); |
| 376 | d->notify(msg); |
| 377 | } |
| 378 | |
| 379 | }; // namespace android |