Yin-Chia Yeh | 4717c47 | 2017-02-13 10:56:40 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 | #define LOG_TAG "CameraHardwareInterface" |
| 17 | //#define LOG_NDEBUG 0 |
| 18 | |
| 19 | #include <inttypes.h> |
Eino-Ville Talvala | 1a2f15d | 2017-03-23 15:37:22 -0700 | [diff] [blame^] | 20 | #include <grallocusage/GrallocUsageConversion.h> |
| 21 | |
Yin-Chia Yeh | 4717c47 | 2017-02-13 10:56:40 -0800 | [diff] [blame] | 22 | #include "CameraHardwareInterface.h" |
| 23 | |
| 24 | namespace android { |
| 25 | |
| 26 | using namespace hardware::camera::device::V1_0; |
| 27 | using namespace hardware::camera::common::V1_0; |
| 28 | using hardware::hidl_handle; |
| 29 | |
| 30 | CameraHardwareInterface::~CameraHardwareInterface() |
| 31 | { |
| 32 | ALOGI("Destroying camera %s", mName.string()); |
| 33 | if (mDevice) { |
| 34 | int rc = mDevice->common.close(&mDevice->common); |
| 35 | if (rc != OK) |
| 36 | ALOGE("Could not close camera %s: %d", mName.string(), rc); |
| 37 | } |
| 38 | if (mHidlDevice != nullptr) { |
| 39 | mHidlDevice->close(); |
| 40 | mHidlDevice.clear(); |
| 41 | cleanupCirculatingBuffers(); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | status_t CameraHardwareInterface::initialize(CameraModule *module) |
| 46 | { |
| 47 | if (mHidlDevice != nullptr) { |
| 48 | ALOGE("%s: camera hardware interface has been initialized to HIDL path!", __FUNCTION__); |
| 49 | return INVALID_OPERATION; |
| 50 | } |
| 51 | ALOGI("Opening camera %s", mName.string()); |
| 52 | camera_info info; |
| 53 | status_t res = module->getCameraInfo(atoi(mName.string()), &info); |
| 54 | if (res != OK) { |
| 55 | return res; |
| 56 | } |
| 57 | |
| 58 | int rc = OK; |
| 59 | if (module->getModuleApiVersion() >= CAMERA_MODULE_API_VERSION_2_3 && |
| 60 | info.device_version > CAMERA_DEVICE_API_VERSION_1_0) { |
| 61 | // Open higher version camera device as HAL1.0 device. |
| 62 | rc = module->openLegacy(mName.string(), |
| 63 | CAMERA_DEVICE_API_VERSION_1_0, |
| 64 | (hw_device_t **)&mDevice); |
| 65 | } else { |
| 66 | rc = module->open(mName.string(), (hw_device_t **)&mDevice); |
| 67 | } |
| 68 | if (rc != OK) { |
| 69 | ALOGE("Could not open camera %s: %d", mName.string(), rc); |
| 70 | return rc; |
| 71 | } |
| 72 | initHalPreviewWindow(); |
| 73 | return rc; |
| 74 | } |
| 75 | |
| 76 | status_t CameraHardwareInterface::initialize(sp<CameraProviderManager> manager) { |
| 77 | if (mDevice) { |
| 78 | ALOGE("%s: camera hardware interface has been initialized to libhardware path!", |
| 79 | __FUNCTION__); |
| 80 | return INVALID_OPERATION; |
| 81 | } |
| 82 | |
| 83 | ALOGI("Opening camera %s", mName.string()); |
| 84 | |
Steven Moreland | 5ff9c91 | 2017-03-09 23:13:00 -0800 | [diff] [blame] | 85 | status_t ret = manager->openSession(mName.string(), this, &mHidlDevice); |
Yin-Chia Yeh | 4717c47 | 2017-02-13 10:56:40 -0800 | [diff] [blame] | 86 | if (ret != OK) { |
| 87 | ALOGE("%s: openSession failed! %s (%d)", __FUNCTION__, strerror(-ret), ret); |
| 88 | } |
| 89 | return ret; |
| 90 | } |
| 91 | |
| 92 | status_t CameraHardwareInterface::setPreviewScalingMode(int scalingMode) |
| 93 | { |
| 94 | int rc = OK; |
| 95 | mPreviewScalingMode = scalingMode; |
| 96 | if (mPreviewWindow != nullptr) { |
| 97 | rc = native_window_set_scaling_mode(mPreviewWindow.get(), |
| 98 | scalingMode); |
| 99 | } |
| 100 | return rc; |
| 101 | } |
| 102 | |
| 103 | status_t CameraHardwareInterface::setPreviewTransform(int transform) { |
| 104 | int rc = OK; |
| 105 | mPreviewTransform = transform; |
| 106 | if (mPreviewWindow != nullptr) { |
| 107 | rc = native_window_set_buffers_transform(mPreviewWindow.get(), |
| 108 | mPreviewTransform); |
| 109 | } |
| 110 | return rc; |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Implementation of android::hardware::camera::device::V1_0::ICameraDeviceCallback |
| 115 | */ |
| 116 | hardware::Return<void> CameraHardwareInterface::notifyCallback( |
| 117 | NotifyCallbackMsg msgType, int32_t ext1, int32_t ext2) { |
| 118 | sNotifyCb((int32_t) msgType, ext1, ext2, (void*) this); |
| 119 | return hardware::Void(); |
| 120 | } |
| 121 | |
| 122 | hardware::Return<uint32_t> CameraHardwareInterface::registerMemory( |
| 123 | const hardware::hidl_handle& descriptor, |
| 124 | uint32_t bufferSize, uint32_t bufferCount) { |
| 125 | if (descriptor->numFds != 1) { |
| 126 | ALOGE("%s: camera memory descriptor has numFds %d (expect 1)", |
| 127 | __FUNCTION__, descriptor->numFds); |
| 128 | return 0; |
| 129 | } |
| 130 | if (descriptor->data[0] < 0) { |
| 131 | ALOGE("%s: camera memory descriptor has FD %d (expect >= 0)", |
| 132 | __FUNCTION__, descriptor->data[0]); |
| 133 | return 0; |
| 134 | } |
| 135 | |
| 136 | camera_memory_t* mem = sGetMemory(descriptor->data[0], bufferSize, bufferCount, this); |
| 137 | sp<CameraHeapMemory> camMem(static_cast<CameraHeapMemory *>(mem->handle)); |
| 138 | int memPoolId = camMem->mHeap->getHeapID(); |
| 139 | if (memPoolId < 0) { |
| 140 | ALOGE("%s: CameraHeapMemory has FD %d (expect >= 0)", __FUNCTION__, memPoolId); |
| 141 | return 0; |
| 142 | } |
| 143 | mHidlMemPoolMap.insert(std::make_pair(memPoolId, mem)); |
| 144 | return memPoolId; |
| 145 | } |
| 146 | |
| 147 | hardware::Return<void> CameraHardwareInterface::unregisterMemory(uint32_t memId) { |
| 148 | if (mHidlMemPoolMap.count(memId) == 0) { |
| 149 | ALOGE("%s: memory pool ID %d not found", __FUNCTION__, memId); |
| 150 | return hardware::Void(); |
| 151 | } |
| 152 | camera_memory_t* mem = mHidlMemPoolMap.at(memId); |
| 153 | sPutMemory(mem); |
| 154 | mHidlMemPoolMap.erase(memId); |
| 155 | return hardware::Void(); |
| 156 | } |
| 157 | |
| 158 | hardware::Return<void> CameraHardwareInterface::dataCallback( |
| 159 | DataCallbackMsg msgType, uint32_t data, uint32_t bufferIndex, |
| 160 | const hardware::camera::device::V1_0::CameraFrameMetadata& metadata) { |
| 161 | if (mHidlMemPoolMap.count(data) == 0) { |
| 162 | ALOGE("%s: memory pool ID %d not found", __FUNCTION__, data); |
| 163 | return hardware::Void(); |
| 164 | } |
| 165 | camera_frame_metadata_t md; |
| 166 | md.number_of_faces = metadata.faces.size(); |
| 167 | md.faces = (camera_face_t*) metadata.faces.data(); |
| 168 | sDataCb((int32_t) msgType, mHidlMemPoolMap.at(data), bufferIndex, &md, this); |
| 169 | return hardware::Void(); |
| 170 | } |
| 171 | |
| 172 | hardware::Return<void> CameraHardwareInterface::dataCallbackTimestamp( |
| 173 | DataCallbackMsg msgType, uint32_t data, |
| 174 | uint32_t bufferIndex, int64_t timestamp) { |
| 175 | if (mHidlMemPoolMap.count(data) == 0) { |
| 176 | ALOGE("%s: memory pool ID %d not found", __FUNCTION__, data); |
| 177 | return hardware::Void(); |
| 178 | } |
| 179 | sDataCbTimestamp(timestamp, (int32_t) msgType, mHidlMemPoolMap.at(data), bufferIndex, this); |
| 180 | return hardware::Void(); |
| 181 | } |
| 182 | |
| 183 | hardware::Return<void> CameraHardwareInterface::handleCallbackTimestamp( |
| 184 | DataCallbackMsg msgType, const hidl_handle& frameData, uint32_t data, |
| 185 | uint32_t bufferIndex, int64_t timestamp) { |
| 186 | if (mHidlMemPoolMap.count(data) == 0) { |
| 187 | ALOGE("%s: memory pool ID %d not found", __FUNCTION__, data); |
| 188 | return hardware::Void(); |
| 189 | } |
| 190 | sp<CameraHeapMemory> mem(static_cast<CameraHeapMemory *>(mHidlMemPoolMap.at(data)->handle)); |
| 191 | VideoNativeHandleMetadata* md = (VideoNativeHandleMetadata*) |
| 192 | mem->mBuffers[bufferIndex]->pointer(); |
| 193 | md->pHandle = const_cast<native_handle_t*>(frameData.getNativeHandle()); |
| 194 | sDataCbTimestamp(timestamp, (int32_t) msgType, mHidlMemPoolMap.at(data), bufferIndex, this); |
| 195 | return hardware::Void(); |
| 196 | } |
| 197 | |
| 198 | std::pair<bool, uint64_t> CameraHardwareInterface::getBufferId( |
| 199 | ANativeWindowBuffer* anb) { |
| 200 | std::lock_guard<std::mutex> lock(mBufferIdMapLock); |
| 201 | |
| 202 | buffer_handle_t& buf = anb->handle; |
| 203 | auto it = mBufferIdMap.find(buf); |
| 204 | if (it == mBufferIdMap.end()) { |
| 205 | uint64_t bufId = mNextBufferId++; |
| 206 | mBufferIdMap[buf] = bufId; |
| 207 | mReversedBufMap[bufId] = anb; |
| 208 | return std::make_pair(true, bufId); |
| 209 | } else { |
| 210 | return std::make_pair(false, it->second); |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | void CameraHardwareInterface::cleanupCirculatingBuffers() { |
| 215 | std::lock_guard<std::mutex> lock(mBufferIdMapLock); |
| 216 | mBufferIdMap.clear(); |
| 217 | mReversedBufMap.clear(); |
| 218 | } |
| 219 | |
| 220 | hardware::Return<void> |
| 221 | CameraHardwareInterface::dequeueBuffer(dequeueBuffer_cb _hidl_cb) { |
| 222 | ANativeWindow *a = mPreviewWindow.get(); |
| 223 | if (a == nullptr) { |
| 224 | ALOGE("%s: preview window is null", __FUNCTION__); |
| 225 | return hardware::Void(); |
| 226 | } |
| 227 | ANativeWindowBuffer* anb; |
| 228 | int rc = native_window_dequeue_buffer_and_wait(a, &anb); |
| 229 | Status s = Status::INTERNAL_ERROR; |
| 230 | uint64_t bufferId = 0; |
| 231 | uint32_t stride = 0; |
| 232 | hidl_handle buf = nullptr; |
| 233 | if (rc == OK) { |
| 234 | s = Status::OK; |
| 235 | auto pair = getBufferId(anb); |
| 236 | buf = (pair.first) ? anb->handle : nullptr; |
| 237 | bufferId = pair.second; |
| 238 | stride = anb->stride; |
| 239 | } |
| 240 | |
| 241 | _hidl_cb(s, bufferId, buf, stride); |
| 242 | return hardware::Void(); |
| 243 | } |
| 244 | |
| 245 | hardware::Return<Status> |
| 246 | CameraHardwareInterface::enqueueBuffer(uint64_t bufferId) { |
| 247 | ANativeWindow *a = mPreviewWindow.get(); |
| 248 | if (a == nullptr) { |
| 249 | ALOGE("%s: preview window is null", __FUNCTION__); |
| 250 | return Status::INTERNAL_ERROR; |
| 251 | } |
| 252 | if (mReversedBufMap.count(bufferId) == 0) { |
| 253 | ALOGE("%s: bufferId %" PRIu64 " not found", __FUNCTION__, bufferId); |
| 254 | return Status::ILLEGAL_ARGUMENT; |
| 255 | } |
| 256 | int rc = a->queueBuffer(a, mReversedBufMap.at(bufferId), -1); |
| 257 | if (rc == 0) { |
| 258 | return Status::OK; |
| 259 | } |
| 260 | return Status::INTERNAL_ERROR; |
| 261 | } |
| 262 | |
| 263 | hardware::Return<Status> |
| 264 | CameraHardwareInterface::cancelBuffer(uint64_t bufferId) { |
| 265 | ANativeWindow *a = mPreviewWindow.get(); |
| 266 | if (a == nullptr) { |
| 267 | ALOGE("%s: preview window is null", __FUNCTION__); |
| 268 | return Status::INTERNAL_ERROR; |
| 269 | } |
| 270 | if (mReversedBufMap.count(bufferId) == 0) { |
| 271 | ALOGE("%s: bufferId %" PRIu64 " not found", __FUNCTION__, bufferId); |
| 272 | return Status::ILLEGAL_ARGUMENT; |
| 273 | } |
| 274 | int rc = a->cancelBuffer(a, mReversedBufMap.at(bufferId), -1); |
| 275 | if (rc == 0) { |
| 276 | return Status::OK; |
| 277 | } |
| 278 | return Status::INTERNAL_ERROR; |
| 279 | } |
| 280 | |
| 281 | hardware::Return<Status> |
| 282 | CameraHardwareInterface::setBufferCount(uint32_t count) { |
| 283 | ANativeWindow *a = mPreviewWindow.get(); |
| 284 | if (a != nullptr) { |
| 285 | // Workaround for b/27039775 |
| 286 | // Previously, setting the buffer count would reset the buffer |
| 287 | // queue's flag that allows for all buffers to be dequeued on the |
| 288 | // producer side, instead of just the producer's declared max count, |
| 289 | // if no filled buffers have yet been queued by the producer. This |
| 290 | // reset no longer happens, but some HALs depend on this behavior, |
| 291 | // so it needs to be maintained for HAL backwards compatibility. |
| 292 | // Simulate the prior behavior by disconnecting/reconnecting to the |
| 293 | // window and setting the values again. This has the drawback of |
| 294 | // actually causing memory reallocation, which may not have happened |
| 295 | // in the past. |
| 296 | native_window_api_disconnect(a, NATIVE_WINDOW_API_CAMERA); |
| 297 | native_window_api_connect(a, NATIVE_WINDOW_API_CAMERA); |
| 298 | if (mPreviewScalingMode != NOT_SET) { |
| 299 | native_window_set_scaling_mode(a, mPreviewScalingMode); |
| 300 | } |
| 301 | if (mPreviewTransform != NOT_SET) { |
| 302 | native_window_set_buffers_transform(a, mPreviewTransform); |
| 303 | } |
| 304 | if (mPreviewWidth != NOT_SET) { |
| 305 | native_window_set_buffers_dimensions(a, |
| 306 | mPreviewWidth, mPreviewHeight); |
| 307 | native_window_set_buffers_format(a, mPreviewFormat); |
| 308 | } |
| 309 | if (mPreviewUsage != 0) { |
| 310 | native_window_set_usage(a, mPreviewUsage); |
| 311 | } |
| 312 | if (mPreviewSwapInterval != NOT_SET) { |
| 313 | a->setSwapInterval(a, mPreviewSwapInterval); |
| 314 | } |
| 315 | if (mPreviewCrop.left != NOT_SET) { |
| 316 | native_window_set_crop(a, &(mPreviewCrop)); |
| 317 | } |
| 318 | } |
| 319 | int rc = native_window_set_buffer_count(a, count); |
| 320 | if (rc == OK) { |
| 321 | cleanupCirculatingBuffers(); |
| 322 | return Status::OK; |
| 323 | } |
| 324 | return Status::INTERNAL_ERROR; |
| 325 | } |
| 326 | |
| 327 | hardware::Return<Status> |
| 328 | CameraHardwareInterface::setBuffersGeometry( |
| 329 | uint32_t w, uint32_t h, hardware::graphics::common::V1_0::PixelFormat format) { |
| 330 | Status s = Status::INTERNAL_ERROR; |
| 331 | ANativeWindow *a = mPreviewWindow.get(); |
| 332 | if (a == nullptr) { |
| 333 | ALOGE("%s: preview window is null", __FUNCTION__); |
| 334 | return s; |
| 335 | } |
| 336 | mPreviewWidth = w; |
| 337 | mPreviewHeight = h; |
| 338 | mPreviewFormat = (int) format; |
| 339 | int rc = native_window_set_buffers_dimensions(a, w, h); |
| 340 | if (rc == OK) { |
| 341 | rc = native_window_set_buffers_format(a, mPreviewFormat); |
| 342 | } |
| 343 | if (rc == OK) { |
| 344 | cleanupCirculatingBuffers(); |
| 345 | s = Status::OK; |
| 346 | } |
| 347 | return s; |
| 348 | } |
| 349 | |
| 350 | hardware::Return<Status> |
| 351 | CameraHardwareInterface::setCrop(int32_t left, int32_t top, int32_t right, int32_t bottom) { |
| 352 | Status s = Status::INTERNAL_ERROR; |
| 353 | ANativeWindow *a = mPreviewWindow.get(); |
| 354 | if (a == nullptr) { |
| 355 | ALOGE("%s: preview window is null", __FUNCTION__); |
| 356 | return s; |
| 357 | } |
| 358 | mPreviewCrop.left = left; |
| 359 | mPreviewCrop.top = top; |
| 360 | mPreviewCrop.right = right; |
| 361 | mPreviewCrop.bottom = bottom; |
| 362 | int rc = native_window_set_crop(a, &mPreviewCrop); |
| 363 | if (rc == OK) { |
| 364 | s = Status::OK; |
| 365 | } |
| 366 | return s; |
| 367 | } |
| 368 | |
| 369 | hardware::Return<Status> |
Eino-Ville Talvala | 1a2f15d | 2017-03-23 15:37:22 -0700 | [diff] [blame^] | 370 | CameraHardwareInterface::setUsage(hardware::camera::device::V1_0::ProducerUsageFlags usage) { |
Yin-Chia Yeh | 4717c47 | 2017-02-13 10:56:40 -0800 | [diff] [blame] | 371 | Status s = Status::INTERNAL_ERROR; |
| 372 | ANativeWindow *a = mPreviewWindow.get(); |
| 373 | if (a == nullptr) { |
| 374 | ALOGE("%s: preview window is null", __FUNCTION__); |
| 375 | return s; |
| 376 | } |
Eino-Ville Talvala | 1a2f15d | 2017-03-23 15:37:22 -0700 | [diff] [blame^] | 377 | mPreviewUsage = ::android_convertGralloc1To0Usage(usage, /*consumerUsage*/ 0); |
Yin-Chia Yeh | 4717c47 | 2017-02-13 10:56:40 -0800 | [diff] [blame] | 378 | int rc = native_window_set_usage(a, mPreviewUsage); |
| 379 | if (rc == OK) { |
| 380 | cleanupCirculatingBuffers(); |
| 381 | s = Status::OK; |
| 382 | } |
| 383 | return s; |
| 384 | } |
| 385 | |
| 386 | hardware::Return<Status> |
| 387 | CameraHardwareInterface::setSwapInterval(int32_t interval) { |
| 388 | Status s = Status::INTERNAL_ERROR; |
| 389 | ANativeWindow *a = mPreviewWindow.get(); |
| 390 | if (a == nullptr) { |
| 391 | ALOGE("%s: preview window is null", __FUNCTION__); |
| 392 | return s; |
| 393 | } |
| 394 | mPreviewSwapInterval = interval; |
| 395 | int rc = a->setSwapInterval(a, interval); |
| 396 | if (rc == OK) { |
| 397 | s = Status::OK; |
| 398 | } |
| 399 | return s; |
| 400 | } |
| 401 | |
| 402 | hardware::Return<void> |
| 403 | CameraHardwareInterface::getMinUndequeuedBufferCount(getMinUndequeuedBufferCount_cb _hidl_cb) { |
| 404 | ANativeWindow *a = mPreviewWindow.get(); |
| 405 | if (a == nullptr) { |
| 406 | ALOGE("%s: preview window is null", __FUNCTION__); |
| 407 | return hardware::Void(); |
| 408 | } |
| 409 | int count = 0; |
| 410 | int rc = a->query(a, NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS, &count); |
| 411 | Status s = Status::INTERNAL_ERROR; |
| 412 | if (rc == OK) { |
| 413 | s = Status::OK; |
| 414 | } |
| 415 | _hidl_cb(s, count); |
| 416 | return hardware::Void(); |
| 417 | } |
| 418 | |
| 419 | hardware::Return<Status> |
| 420 | CameraHardwareInterface::setTimestamp(int64_t timestamp) { |
| 421 | Status s = Status::INTERNAL_ERROR; |
| 422 | ANativeWindow *a = mPreviewWindow.get(); |
| 423 | if (a == nullptr) { |
| 424 | ALOGE("%s: preview window is null", __FUNCTION__); |
| 425 | return s; |
| 426 | } |
| 427 | int rc = native_window_set_buffers_timestamp(a, timestamp); |
| 428 | if (rc == OK) { |
| 429 | s = Status::OK; |
| 430 | } |
| 431 | return s; |
| 432 | } |
| 433 | |
| 434 | status_t CameraHardwareInterface::setPreviewWindow(const sp<ANativeWindow>& buf) |
| 435 | { |
| 436 | ALOGV("%s(%s) buf %p", __FUNCTION__, mName.string(), buf.get()); |
| 437 | if (CC_LIKELY(mHidlDevice != nullptr)) { |
| 438 | mPreviewWindow = buf; |
| 439 | if (buf != nullptr) { |
| 440 | if (mPreviewScalingMode != NOT_SET) { |
| 441 | setPreviewScalingMode(mPreviewScalingMode); |
| 442 | } |
| 443 | if (mPreviewTransform != NOT_SET) { |
| 444 | setPreviewTransform(mPreviewTransform); |
| 445 | } |
| 446 | } |
| 447 | return CameraProviderManager::mapToStatusT( |
| 448 | mHidlDevice->setPreviewWindow(buf.get() ? this : nullptr)); |
| 449 | } else if (mDevice) { |
| 450 | if (mDevice->ops->set_preview_window) { |
| 451 | mPreviewWindow = buf; |
| 452 | if (buf != nullptr) { |
| 453 | if (mPreviewScalingMode != NOT_SET) { |
| 454 | setPreviewScalingMode(mPreviewScalingMode); |
| 455 | } |
| 456 | if (mPreviewTransform != NOT_SET) { |
| 457 | setPreviewTransform(mPreviewTransform); |
| 458 | } |
| 459 | } |
| 460 | mHalPreviewWindow.user = this; |
| 461 | ALOGV("%s &mHalPreviewWindow %p mHalPreviewWindow.user %p",__FUNCTION__, |
| 462 | &mHalPreviewWindow, mHalPreviewWindow.user); |
| 463 | return mDevice->ops->set_preview_window(mDevice, |
| 464 | buf.get() ? &mHalPreviewWindow.nw : 0); |
| 465 | } |
| 466 | } |
| 467 | return INVALID_OPERATION; |
| 468 | } |
| 469 | |
| 470 | void CameraHardwareInterface::setCallbacks(notify_callback notify_cb, |
| 471 | data_callback data_cb, |
| 472 | data_callback_timestamp data_cb_timestamp, |
| 473 | void* user) |
| 474 | { |
| 475 | mNotifyCb = notify_cb; |
| 476 | mDataCb = data_cb; |
| 477 | mDataCbTimestamp = data_cb_timestamp; |
| 478 | mCbUser = user; |
| 479 | |
| 480 | ALOGV("%s(%s)", __FUNCTION__, mName.string()); |
| 481 | |
| 482 | if (mDevice && mDevice->ops->set_callbacks) { |
| 483 | mDevice->ops->set_callbacks(mDevice, |
| 484 | sNotifyCb, |
| 485 | sDataCb, |
| 486 | sDataCbTimestamp, |
| 487 | sGetMemory, |
| 488 | this); |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | void CameraHardwareInterface::enableMsgType(int32_t msgType) |
| 493 | { |
| 494 | ALOGV("%s(%s)", __FUNCTION__, mName.string()); |
| 495 | if (CC_LIKELY(mHidlDevice != nullptr)) { |
| 496 | mHidlDevice->enableMsgType(msgType); |
| 497 | } else if (mDevice && mDevice->ops->enable_msg_type) { |
| 498 | mDevice->ops->enable_msg_type(mDevice, msgType); |
| 499 | } |
| 500 | } |
| 501 | |
| 502 | void CameraHardwareInterface::disableMsgType(int32_t msgType) |
| 503 | { |
| 504 | ALOGV("%s(%s)", __FUNCTION__, mName.string()); |
| 505 | if (CC_LIKELY(mHidlDevice != nullptr)) { |
| 506 | mHidlDevice->disableMsgType(msgType); |
| 507 | } else if (mDevice && mDevice->ops->disable_msg_type) { |
| 508 | mDevice->ops->disable_msg_type(mDevice, msgType); |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | int CameraHardwareInterface::msgTypeEnabled(int32_t msgType) |
| 513 | { |
| 514 | ALOGV("%s(%s)", __FUNCTION__, mName.string()); |
| 515 | if (CC_LIKELY(mHidlDevice != nullptr)) { |
| 516 | return mHidlDevice->msgTypeEnabled(msgType); |
| 517 | } else if (mDevice && mDevice->ops->msg_type_enabled) { |
| 518 | return mDevice->ops->msg_type_enabled(mDevice, msgType); |
| 519 | } |
| 520 | return false; |
| 521 | } |
| 522 | |
| 523 | status_t CameraHardwareInterface::startPreview() |
| 524 | { |
| 525 | ALOGV("%s(%s)", __FUNCTION__, mName.string()); |
| 526 | if (CC_LIKELY(mHidlDevice != nullptr)) { |
| 527 | return CameraProviderManager::mapToStatusT( |
| 528 | mHidlDevice->startPreview()); |
| 529 | } else if (mDevice && mDevice->ops->start_preview) { |
| 530 | return mDevice->ops->start_preview(mDevice); |
| 531 | } |
| 532 | return INVALID_OPERATION; |
| 533 | } |
| 534 | |
| 535 | void CameraHardwareInterface::stopPreview() |
| 536 | { |
| 537 | ALOGV("%s(%s)", __FUNCTION__, mName.string()); |
| 538 | if (CC_LIKELY(mHidlDevice != nullptr)) { |
| 539 | mHidlDevice->stopPreview(); |
| 540 | } else if (mDevice && mDevice->ops->stop_preview) { |
| 541 | mDevice->ops->stop_preview(mDevice); |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | int CameraHardwareInterface::previewEnabled() |
| 546 | { |
| 547 | ALOGV("%s(%s)", __FUNCTION__, mName.string()); |
| 548 | if (CC_LIKELY(mHidlDevice != nullptr)) { |
| 549 | return mHidlDevice->previewEnabled(); |
| 550 | } else if (mDevice && mDevice->ops->preview_enabled) { |
| 551 | return mDevice->ops->preview_enabled(mDevice); |
| 552 | } |
| 553 | return false; |
| 554 | } |
| 555 | |
| 556 | status_t CameraHardwareInterface::storeMetaDataInBuffers(int enable) |
| 557 | { |
| 558 | ALOGV("%s(%s)", __FUNCTION__, mName.string()); |
| 559 | if (CC_LIKELY(mHidlDevice != nullptr)) { |
| 560 | return CameraProviderManager::mapToStatusT( |
| 561 | mHidlDevice->storeMetaDataInBuffers(enable)); |
| 562 | } else if (mDevice && mDevice->ops->store_meta_data_in_buffers) { |
| 563 | return mDevice->ops->store_meta_data_in_buffers(mDevice, enable); |
| 564 | } |
| 565 | return enable ? INVALID_OPERATION: OK; |
| 566 | } |
| 567 | |
| 568 | status_t CameraHardwareInterface::startRecording() |
| 569 | { |
| 570 | ALOGV("%s(%s)", __FUNCTION__, mName.string()); |
| 571 | if (CC_LIKELY(mHidlDevice != nullptr)) { |
| 572 | return CameraProviderManager::mapToStatusT( |
| 573 | mHidlDevice->startRecording()); |
| 574 | } else if (mDevice && mDevice->ops->start_recording) { |
| 575 | return mDevice->ops->start_recording(mDevice); |
| 576 | } |
| 577 | return INVALID_OPERATION; |
| 578 | } |
| 579 | |
| 580 | /** |
| 581 | * Stop a previously started recording. |
| 582 | */ |
| 583 | void CameraHardwareInterface::stopRecording() |
| 584 | { |
| 585 | ALOGV("%s(%s)", __FUNCTION__, mName.string()); |
| 586 | if (CC_LIKELY(mHidlDevice != nullptr)) { |
| 587 | mHidlDevice->stopRecording(); |
| 588 | } else if (mDevice && mDevice->ops->stop_recording) { |
| 589 | mDevice->ops->stop_recording(mDevice); |
| 590 | } |
| 591 | } |
| 592 | |
| 593 | /** |
| 594 | * Returns true if recording is enabled. |
| 595 | */ |
| 596 | int CameraHardwareInterface::recordingEnabled() |
| 597 | { |
| 598 | ALOGV("%s(%s)", __FUNCTION__, mName.string()); |
| 599 | if (CC_LIKELY(mHidlDevice != nullptr)) { |
| 600 | return mHidlDevice->recordingEnabled(); |
| 601 | } else if (mDevice && mDevice->ops->recording_enabled) { |
| 602 | return mDevice->ops->recording_enabled(mDevice); |
| 603 | } |
| 604 | return false; |
| 605 | } |
| 606 | |
| 607 | void CameraHardwareInterface::releaseRecordingFrame(const sp<IMemory>& mem) |
| 608 | { |
| 609 | ALOGV("%s(%s)", __FUNCTION__, mName.string()); |
| 610 | ssize_t offset; |
| 611 | size_t size; |
| 612 | sp<IMemoryHeap> heap = mem->getMemory(&offset, &size); |
| 613 | int heapId = heap->getHeapID(); |
| 614 | int bufferIndex = offset / size; |
| 615 | if (CC_LIKELY(mHidlDevice != nullptr)) { |
| 616 | if (size == sizeof(VideoNativeHandleMetadata)) { |
| 617 | VideoNativeHandleMetadata* md = (VideoNativeHandleMetadata*) mem->pointer(); |
| 618 | // Caching the handle here because md->pHandle will be subject to HAL's edit |
| 619 | native_handle_t* nh = md->pHandle; |
| 620 | hidl_handle frame = nh; |
| 621 | mHidlDevice->releaseRecordingFrameHandle(heapId, bufferIndex, frame); |
| 622 | native_handle_close(nh); |
| 623 | native_handle_delete(nh); |
| 624 | } else { |
| 625 | mHidlDevice->releaseRecordingFrame(heapId, bufferIndex); |
| 626 | } |
| 627 | } else if (mDevice && mDevice->ops->release_recording_frame) { |
| 628 | void *data = ((uint8_t *)heap->base()) + offset; |
| 629 | return mDevice->ops->release_recording_frame(mDevice, data); |
| 630 | } |
| 631 | } |
| 632 | |
| 633 | status_t CameraHardwareInterface::autoFocus() |
| 634 | { |
| 635 | ALOGV("%s(%s)", __FUNCTION__, mName.string()); |
| 636 | if (CC_LIKELY(mHidlDevice != nullptr)) { |
| 637 | return CameraProviderManager::mapToStatusT( |
| 638 | mHidlDevice->autoFocus()); |
| 639 | } else if (mDevice && mDevice->ops->auto_focus) { |
| 640 | return mDevice->ops->auto_focus(mDevice); |
| 641 | } |
| 642 | return INVALID_OPERATION; |
| 643 | } |
| 644 | |
| 645 | status_t CameraHardwareInterface::cancelAutoFocus() |
| 646 | { |
| 647 | ALOGV("%s(%s)", __FUNCTION__, mName.string()); |
| 648 | if (CC_LIKELY(mHidlDevice != nullptr)) { |
| 649 | return CameraProviderManager::mapToStatusT( |
| 650 | mHidlDevice->cancelAutoFocus()); |
| 651 | } else if (mDevice && mDevice->ops->cancel_auto_focus) { |
| 652 | return mDevice->ops->cancel_auto_focus(mDevice); |
| 653 | } |
| 654 | return INVALID_OPERATION; |
| 655 | } |
| 656 | |
| 657 | status_t CameraHardwareInterface::takePicture() |
| 658 | { |
| 659 | ALOGV("%s(%s)", __FUNCTION__, mName.string()); |
| 660 | if (CC_LIKELY(mHidlDevice != nullptr)) { |
| 661 | return CameraProviderManager::mapToStatusT( |
| 662 | mHidlDevice->takePicture()); |
| 663 | } else if (mDevice && mDevice->ops->take_picture) { |
| 664 | return mDevice->ops->take_picture(mDevice); |
| 665 | } |
| 666 | return INVALID_OPERATION; |
| 667 | } |
| 668 | |
| 669 | status_t CameraHardwareInterface::cancelPicture() |
| 670 | { |
| 671 | ALOGV("%s(%s)", __FUNCTION__, mName.string()); |
| 672 | if (CC_LIKELY(mHidlDevice != nullptr)) { |
| 673 | return CameraProviderManager::mapToStatusT( |
| 674 | mHidlDevice->cancelPicture()); |
| 675 | } else if (mDevice && mDevice->ops->cancel_picture) { |
| 676 | return mDevice->ops->cancel_picture(mDevice); |
| 677 | } |
| 678 | return INVALID_OPERATION; |
| 679 | } |
| 680 | |
| 681 | status_t CameraHardwareInterface::setParameters(const CameraParameters ¶ms) |
| 682 | { |
| 683 | ALOGV("%s(%s)", __FUNCTION__, mName.string()); |
| 684 | if (CC_LIKELY(mHidlDevice != nullptr)) { |
| 685 | return CameraProviderManager::mapToStatusT( |
| 686 | mHidlDevice->setParameters(params.flatten().string())); |
| 687 | } else if (mDevice && mDevice->ops->set_parameters) { |
| 688 | return mDevice->ops->set_parameters(mDevice, params.flatten().string()); |
| 689 | } |
| 690 | return INVALID_OPERATION; |
| 691 | } |
| 692 | |
| 693 | CameraParameters CameraHardwareInterface::getParameters() const |
| 694 | { |
| 695 | ALOGV("%s(%s)", __FUNCTION__, mName.string()); |
| 696 | CameraParameters parms; |
| 697 | if (CC_LIKELY(mHidlDevice != nullptr)) { |
| 698 | hardware::hidl_string outParam; |
| 699 | mHidlDevice->getParameters( |
| 700 | [&outParam](const auto& outStr) { |
| 701 | outParam = outStr; |
| 702 | }); |
| 703 | String8 tmp(outParam.c_str()); |
| 704 | parms.unflatten(tmp); |
| 705 | } else if (mDevice && mDevice->ops->get_parameters) { |
| 706 | char *temp = mDevice->ops->get_parameters(mDevice); |
| 707 | String8 str_parms(temp); |
| 708 | if (mDevice->ops->put_parameters) |
| 709 | mDevice->ops->put_parameters(mDevice, temp); |
| 710 | else |
| 711 | free(temp); |
| 712 | parms.unflatten(str_parms); |
| 713 | } |
| 714 | return parms; |
| 715 | } |
| 716 | |
| 717 | status_t CameraHardwareInterface::sendCommand(int32_t cmd, int32_t arg1, int32_t arg2) |
| 718 | { |
| 719 | ALOGV("%s(%s)", __FUNCTION__, mName.string()); |
| 720 | if (CC_LIKELY(mHidlDevice != nullptr)) { |
| 721 | return CameraProviderManager::mapToStatusT( |
| 722 | mHidlDevice->sendCommand((CommandType) cmd, arg1, arg2)); |
| 723 | } else if (mDevice && mDevice->ops->send_command) { |
| 724 | return mDevice->ops->send_command(mDevice, cmd, arg1, arg2); |
| 725 | } |
| 726 | return INVALID_OPERATION; |
| 727 | } |
| 728 | |
| 729 | /** |
| 730 | * Release the hardware resources owned by this object. Note that this is |
| 731 | * *not* done in the destructor. |
| 732 | */ |
| 733 | void CameraHardwareInterface::release() { |
| 734 | ALOGV("%s(%s)", __FUNCTION__, mName.string()); |
| 735 | if (CC_LIKELY(mHidlDevice != nullptr)) { |
| 736 | mHidlDevice->close(); |
| 737 | mHidlDevice.clear(); |
| 738 | } else if (mDevice && mDevice->ops->release) { |
| 739 | mDevice->ops->release(mDevice); |
| 740 | } |
| 741 | } |
| 742 | |
| 743 | /** |
| 744 | * Dump state of the camera hardware |
| 745 | */ |
| 746 | status_t CameraHardwareInterface::dump(int fd, const Vector<String16>& /*args*/) const |
| 747 | { |
| 748 | ALOGV("%s(%s)", __FUNCTION__, mName.string()); |
| 749 | if (CC_LIKELY(mHidlDevice != nullptr)) { |
| 750 | native_handle_t* handle = native_handle_create(1,0); |
| 751 | handle->data[0] = fd; |
| 752 | Status s = mHidlDevice->dumpState(handle); |
| 753 | native_handle_delete(handle); |
| 754 | return CameraProviderManager::mapToStatusT(s); |
| 755 | } else if (mDevice && mDevice->ops->dump) { |
| 756 | return mDevice->ops->dump(mDevice, fd); |
| 757 | } |
| 758 | return OK; // It's fine if the HAL doesn't implement dump() |
| 759 | } |
| 760 | |
| 761 | /** |
| 762 | * Methods for legacy (non-HIDL) path follows |
| 763 | */ |
| 764 | void CameraHardwareInterface::sNotifyCb(int32_t msg_type, int32_t ext1, |
| 765 | int32_t ext2, void *user) |
| 766 | { |
| 767 | ALOGV("%s", __FUNCTION__); |
| 768 | CameraHardwareInterface *object = |
| 769 | static_cast<CameraHardwareInterface *>(user); |
| 770 | object->mNotifyCb(msg_type, ext1, ext2, object->mCbUser); |
| 771 | } |
| 772 | |
| 773 | void CameraHardwareInterface::sDataCb(int32_t msg_type, |
| 774 | const camera_memory_t *data, unsigned int index, |
| 775 | camera_frame_metadata_t *metadata, |
| 776 | void *user) |
| 777 | { |
| 778 | ALOGV("%s", __FUNCTION__); |
| 779 | CameraHardwareInterface *object = |
| 780 | static_cast<CameraHardwareInterface *>(user); |
| 781 | sp<CameraHeapMemory> mem(static_cast<CameraHeapMemory *>(data->handle)); |
| 782 | if (index >= mem->mNumBufs) { |
| 783 | ALOGE("%s: invalid buffer index %d, max allowed is %d", __FUNCTION__, |
| 784 | index, mem->mNumBufs); |
| 785 | return; |
| 786 | } |
| 787 | object->mDataCb(msg_type, mem->mBuffers[index], metadata, object->mCbUser); |
| 788 | } |
| 789 | |
| 790 | void CameraHardwareInterface::sDataCbTimestamp(nsecs_t timestamp, int32_t msg_type, |
| 791 | const camera_memory_t *data, unsigned index, |
| 792 | void *user) |
| 793 | { |
| 794 | ALOGV("%s", __FUNCTION__); |
| 795 | CameraHardwareInterface *object = |
| 796 | static_cast<CameraHardwareInterface *>(user); |
| 797 | // Start refcounting the heap object from here on. When the clients |
| 798 | // drop all references, it will be destroyed (as well as the enclosed |
| 799 | // MemoryHeapBase. |
| 800 | sp<CameraHeapMemory> mem(static_cast<CameraHeapMemory *>(data->handle)); |
| 801 | if (index >= mem->mNumBufs) { |
| 802 | ALOGE("%s: invalid buffer index %d, max allowed is %d", __FUNCTION__, |
| 803 | index, mem->mNumBufs); |
| 804 | return; |
| 805 | } |
| 806 | object->mDataCbTimestamp(timestamp, msg_type, mem->mBuffers[index], object->mCbUser); |
| 807 | } |
| 808 | |
| 809 | camera_memory_t* CameraHardwareInterface::sGetMemory( |
| 810 | int fd, size_t buf_size, uint_t num_bufs, |
| 811 | void *user __attribute__((unused))) |
| 812 | { |
| 813 | CameraHeapMemory *mem; |
| 814 | if (fd < 0) { |
| 815 | mem = new CameraHeapMemory(buf_size, num_bufs); |
| 816 | } else { |
| 817 | mem = new CameraHeapMemory(fd, buf_size, num_bufs); |
| 818 | } |
| 819 | mem->incStrong(mem); |
| 820 | return &mem->handle; |
| 821 | } |
| 822 | |
| 823 | void CameraHardwareInterface::sPutMemory(camera_memory_t *data) |
| 824 | { |
| 825 | if (!data) { |
| 826 | return; |
| 827 | } |
| 828 | |
| 829 | CameraHeapMemory *mem = static_cast<CameraHeapMemory *>(data->handle); |
| 830 | mem->decStrong(mem); |
| 831 | } |
| 832 | |
| 833 | ANativeWindow* CameraHardwareInterface::sToAnw(void *user) |
| 834 | { |
| 835 | CameraHardwareInterface *object = |
| 836 | reinterpret_cast<CameraHardwareInterface *>(user); |
| 837 | return object->mPreviewWindow.get(); |
| 838 | } |
| 839 | #define anw(n) sToAnw(((struct camera_preview_window *)(n))->user) |
| 840 | #define hwi(n) reinterpret_cast<CameraHardwareInterface *>(\ |
| 841 | ((struct camera_preview_window *)(n))->user) |
| 842 | |
| 843 | int CameraHardwareInterface::sDequeueBuffer(struct preview_stream_ops* w, |
| 844 | buffer_handle_t** buffer, int *stride) |
| 845 | { |
| 846 | int rc; |
| 847 | ANativeWindow *a = anw(w); |
| 848 | ANativeWindowBuffer* anb; |
| 849 | rc = native_window_dequeue_buffer_and_wait(a, &anb); |
| 850 | if (rc == OK) { |
| 851 | *buffer = &anb->handle; |
| 852 | *stride = anb->stride; |
| 853 | } |
| 854 | return rc; |
| 855 | } |
| 856 | |
| 857 | #ifndef container_of |
| 858 | #define container_of(ptr, type, member) ({ \ |
| 859 | const __typeof__(((type *) 0)->member) *__mptr = (ptr); \ |
| 860 | (type *) ((char *) __mptr - (char *)(&((type *)0)->member)); }) |
| 861 | #endif |
| 862 | |
| 863 | int CameraHardwareInterface::sLockBuffer(struct preview_stream_ops* w, |
| 864 | buffer_handle_t* /*buffer*/) |
| 865 | { |
| 866 | ANativeWindow *a = anw(w); |
| 867 | (void)a; |
| 868 | return 0; |
| 869 | } |
| 870 | |
| 871 | int CameraHardwareInterface::sEnqueueBuffer(struct preview_stream_ops* w, |
| 872 | buffer_handle_t* buffer) |
| 873 | { |
| 874 | ANativeWindow *a = anw(w); |
| 875 | return a->queueBuffer(a, |
| 876 | container_of(buffer, ANativeWindowBuffer, handle), -1); |
| 877 | } |
| 878 | |
| 879 | int CameraHardwareInterface::sCancelBuffer(struct preview_stream_ops* w, |
| 880 | buffer_handle_t* buffer) |
| 881 | { |
| 882 | ANativeWindow *a = anw(w); |
| 883 | return a->cancelBuffer(a, |
| 884 | container_of(buffer, ANativeWindowBuffer, handle), -1); |
| 885 | } |
| 886 | |
| 887 | int CameraHardwareInterface::sSetBufferCount(struct preview_stream_ops* w, int count) |
| 888 | { |
| 889 | ANativeWindow *a = anw(w); |
| 890 | |
| 891 | if (a != nullptr) { |
| 892 | // Workaround for b/27039775 |
| 893 | // Previously, setting the buffer count would reset the buffer |
| 894 | // queue's flag that allows for all buffers to be dequeued on the |
| 895 | // producer side, instead of just the producer's declared max count, |
| 896 | // if no filled buffers have yet been queued by the producer. This |
| 897 | // reset no longer happens, but some HALs depend on this behavior, |
| 898 | // so it needs to be maintained for HAL backwards compatibility. |
| 899 | // Simulate the prior behavior by disconnecting/reconnecting to the |
| 900 | // window and setting the values again. This has the drawback of |
| 901 | // actually causing memory reallocation, which may not have happened |
| 902 | // in the past. |
| 903 | CameraHardwareInterface *hw = hwi(w); |
| 904 | native_window_api_disconnect(a, NATIVE_WINDOW_API_CAMERA); |
| 905 | native_window_api_connect(a, NATIVE_WINDOW_API_CAMERA); |
| 906 | if (hw->mPreviewScalingMode != NOT_SET) { |
| 907 | native_window_set_scaling_mode(a, hw->mPreviewScalingMode); |
| 908 | } |
| 909 | if (hw->mPreviewTransform != NOT_SET) { |
| 910 | native_window_set_buffers_transform(a, hw->mPreviewTransform); |
| 911 | } |
| 912 | if (hw->mPreviewWidth != NOT_SET) { |
| 913 | native_window_set_buffers_dimensions(a, |
| 914 | hw->mPreviewWidth, hw->mPreviewHeight); |
| 915 | native_window_set_buffers_format(a, hw->mPreviewFormat); |
| 916 | } |
| 917 | if (hw->mPreviewUsage != 0) { |
| 918 | native_window_set_usage(a, hw->mPreviewUsage); |
| 919 | } |
| 920 | if (hw->mPreviewSwapInterval != NOT_SET) { |
| 921 | a->setSwapInterval(a, hw->mPreviewSwapInterval); |
| 922 | } |
| 923 | if (hw->mPreviewCrop.left != NOT_SET) { |
| 924 | native_window_set_crop(a, &(hw->mPreviewCrop)); |
| 925 | } |
| 926 | } |
| 927 | |
| 928 | return native_window_set_buffer_count(a, count); |
| 929 | } |
| 930 | |
| 931 | int CameraHardwareInterface::sSetBuffersGeometry(struct preview_stream_ops* w, |
| 932 | int width, int height, int format) |
| 933 | { |
| 934 | int rc; |
| 935 | ANativeWindow *a = anw(w); |
| 936 | CameraHardwareInterface *hw = hwi(w); |
| 937 | hw->mPreviewWidth = width; |
| 938 | hw->mPreviewHeight = height; |
| 939 | hw->mPreviewFormat = format; |
| 940 | rc = native_window_set_buffers_dimensions(a, width, height); |
| 941 | if (rc == OK) { |
| 942 | rc = native_window_set_buffers_format(a, format); |
| 943 | } |
| 944 | return rc; |
| 945 | } |
| 946 | |
| 947 | int CameraHardwareInterface::sSetCrop(struct preview_stream_ops *w, |
| 948 | int left, int top, int right, int bottom) |
| 949 | { |
| 950 | ANativeWindow *a = anw(w); |
| 951 | CameraHardwareInterface *hw = hwi(w); |
| 952 | hw->mPreviewCrop.left = left; |
| 953 | hw->mPreviewCrop.top = top; |
| 954 | hw->mPreviewCrop.right = right; |
| 955 | hw->mPreviewCrop.bottom = bottom; |
| 956 | return native_window_set_crop(a, &(hw->mPreviewCrop)); |
| 957 | } |
| 958 | |
| 959 | int CameraHardwareInterface::sSetTimestamp(struct preview_stream_ops *w, |
| 960 | int64_t timestamp) { |
| 961 | ANativeWindow *a = anw(w); |
| 962 | return native_window_set_buffers_timestamp(a, timestamp); |
| 963 | } |
| 964 | |
| 965 | int CameraHardwareInterface::sSetUsage(struct preview_stream_ops* w, int usage) |
| 966 | { |
| 967 | ANativeWindow *a = anw(w); |
| 968 | CameraHardwareInterface *hw = hwi(w); |
| 969 | hw->mPreviewUsage = usage; |
| 970 | return native_window_set_usage(a, usage); |
| 971 | } |
| 972 | |
| 973 | int CameraHardwareInterface::sSetSwapInterval(struct preview_stream_ops *w, int interval) |
| 974 | { |
| 975 | ANativeWindow *a = anw(w); |
| 976 | CameraHardwareInterface *hw = hwi(w); |
| 977 | hw->mPreviewSwapInterval = interval; |
| 978 | return a->setSwapInterval(a, interval); |
| 979 | } |
| 980 | |
| 981 | int CameraHardwareInterface::sGetMinUndequeuedBufferCount( |
| 982 | const struct preview_stream_ops *w, |
| 983 | int *count) |
| 984 | { |
| 985 | ANativeWindow *a = anw(w); |
| 986 | return a->query(a, NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS, count); |
| 987 | } |
| 988 | |
| 989 | void CameraHardwareInterface::initHalPreviewWindow() |
| 990 | { |
| 991 | mHalPreviewWindow.nw.cancel_buffer = sCancelBuffer; |
| 992 | mHalPreviewWindow.nw.lock_buffer = sLockBuffer; |
| 993 | mHalPreviewWindow.nw.dequeue_buffer = sDequeueBuffer; |
| 994 | mHalPreviewWindow.nw.enqueue_buffer = sEnqueueBuffer; |
| 995 | mHalPreviewWindow.nw.set_buffer_count = sSetBufferCount; |
| 996 | mHalPreviewWindow.nw.set_buffers_geometry = sSetBuffersGeometry; |
| 997 | mHalPreviewWindow.nw.set_crop = sSetCrop; |
| 998 | mHalPreviewWindow.nw.set_timestamp = sSetTimestamp; |
| 999 | mHalPreviewWindow.nw.set_usage = sSetUsage; |
| 1000 | mHalPreviewWindow.nw.set_swap_interval = sSetSwapInterval; |
| 1001 | |
| 1002 | mHalPreviewWindow.nw.get_min_undequeued_buffer_count = |
| 1003 | sGetMinUndequeuedBufferCount; |
| 1004 | } |
| 1005 | |
| 1006 | }; // namespace android |