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