From 1032d3d4332b1677ca64dfcdf12c5d841ed00212 Mon Sep 17 00:00:00 2001 From: LuK1337 Date: Tue, 5 Sep 2017 09:41:33 +0200 Subject: Camera: zuk: Add support for non-treble camera blobs * Camera HALs before Treble used to pass camera id in user field, in Treble they are meant to pass pointer to CameraDevice. * This patch workarounds this by storing local pointer to CameraDevice and not relying on user field. * Similar to demon000's CameraWrapper solution but it doesn't require wrapping the HAL which could theoretically break HAL3 compatibility. Change-Id: Iadf0359878f71f4da0a3f952b3af5b914bd49fa8 --- camera/zuk/CameraDevice.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'camera/zuk/CameraDevice.cpp') diff --git a/camera/zuk/CameraDevice.cpp b/camera/zuk/CameraDevice.cpp index 81bc215..02c1b02 100644 --- a/camera/zuk/CameraDevice.cpp +++ b/camera/zuk/CameraDevice.cpp @@ -36,6 +36,8 @@ using ::android::hardware::graphics::common::V1_0::PixelFormat; HandleImporter CameraDevice::sHandleImporter; +CameraDevice* sCameraDevice; + Status CameraDevice::getHidlStatus(const int& status) { switch (status) { case 0: return Status::OK; @@ -361,7 +363,8 @@ CameraDevice::CameraHeapMemory::~CameraHeapMemory() { // shared memory methods camera_memory_t* CameraDevice::sGetMemory(int fd, size_t buf_size, uint_t num_bufs, void *user) { ALOGV("%s", __FUNCTION__); - CameraDevice* object = static_cast(user); + CameraDevice* object = sCameraDevice; + (void)(user); if (object->mDeviceCallback == nullptr) { ALOGE("%s: camera HAL request memory while camera is not opened!", __FUNCTION__); return nullptr; @@ -405,7 +408,8 @@ void CameraDevice::sPutMemory(camera_memory_t *data) { // Callback forwarding methods void CameraDevice::sNotifyCb(int32_t msg_type, int32_t ext1, int32_t ext2, void *user) { ALOGV("%s", __FUNCTION__); - CameraDevice* object = static_cast(user); + CameraDevice* object = sCameraDevice; + (void)(user); if (object->mDeviceCallback != nullptr) { object->mDeviceCallback->notifyCallback((NotifyCallbackMsg) msg_type, ext1, ext2); } @@ -414,7 +418,8 @@ void CameraDevice::sNotifyCb(int32_t msg_type, int32_t ext1, int32_t ext2, void void CameraDevice::sDataCb(int32_t msg_type, const camera_memory_t *data, unsigned int index, camera_frame_metadata_t *metadata, void *user) { ALOGV("%s", __FUNCTION__); - CameraDevice* object = static_cast(user); + CameraDevice* object = sCameraDevice; + (void)(user); sp mem(static_cast(data->handle)); if (index >= mem->mNumBufs) { ALOGE("%s: invalid buffer index %d, max allowed is %d", __FUNCTION__, @@ -484,7 +489,8 @@ void CameraDevice::handleCallbackTimestamp( void CameraDevice::sDataCbTimestamp(nsecs_t timestamp, int32_t msg_type, const camera_memory_t *data, unsigned index, void *user) { ALOGV("%s", __FUNCTION__); - CameraDevice* object = static_cast(user); + CameraDevice* object = sCameraDevice; + (void)(user); // Start refcounting the heap object from here on. When the clients // drop all references, it will be destroyed (as well as the enclosed // MemoryHeapBase. @@ -661,6 +667,8 @@ Return CameraDevice::open(const sp& callback) { initHalPreviewWindow(); mDeviceCallback = callback; + sCameraDevice = this; + if (mDevice->ops->set_callbacks) { mDevice->ops->set_callbacks(mDevice, sNotifyCb, sDataCb, sDataCbTimestamp, sGetMemory, this); -- cgit v1.2.3