diff --git a/camera/QCamera2/HAL/QCamera2HWI.cpp b/camera/QCamera2/HAL/QCamera2HWI.cpp index 95227f2..3199311 100644 --- a/camera/QCamera2/HAL/QCamera2HWI.cpp +++ b/camera/QCamera2/HAL/QCamera2HWI.cpp @@ -2666,14 +2666,16 @@ QCameraMemory *QCamera2HardwareInterface::allocateStreamBuf( { if (isNoDisplayMode()) { mem = new QCameraStreamMemory(mGetMemory, + mCallbackCookie, bCachedMem, (bPoolMem) ? &m_memoryPool : NULL, stream_type); } else { cam_dimension_t dim; int minFPS, maxFPS; - QCameraGrallocMemory *grallocMemory = - new QCameraGrallocMemory(mGetMemory); + QCameraGrallocMemory *grallocMemory = NULL; + + grallocMemory = new QCameraGrallocMemory(mGetMemory, mCallbackCookie); mParameters.getStreamDimension(stream_type, dim); /* we are interested only in maxfps here */ @@ -2709,12 +2711,12 @@ QCameraMemory *QCamera2HardwareInterface::allocateStreamBuf( case CAM_STREAM_TYPE_POSTVIEW: { if (isNoDisplayMode() || isPreviewRestartEnabled()) { - mem = new QCameraStreamMemory(mGetMemory, bCachedMem); + mem = new QCameraStreamMemory(mGetMemory, mCallbackCookie, bCachedMem); } else { cam_dimension_t dim; int minFPS, maxFPS; QCameraGrallocMemory *grallocMemory = - new QCameraGrallocMemory(mGetMemory); + new QCameraGrallocMemory(mGetMemory, mCallbackCookie); mParameters.getStreamDimension(stream_type, dim); /* we are interested only in maxfps here */ @@ -2733,6 +2735,7 @@ QCameraMemory *QCamera2HardwareInterface::allocateStreamBuf( case CAM_STREAM_TYPE_RAW: case CAM_STREAM_TYPE_OFFLINE_PROC: mem = new QCameraStreamMemory(mGetMemory, + mCallbackCookie, bCachedMem, (bPoolMem) ? &m_memoryPool : NULL, stream_type); @@ -2774,7 +2777,7 @@ QCameraMemory *QCamera2HardwareInterface::allocateStreamBuf( QCameraVideoMemory *videoMemory = NULL; if (mParameters.getVideoBatchSize()) { videoMemory = new QCameraVideoMemory( - mGetMemory, FALSE, QCAMERA_MEM_TYPE_BATCH); + mGetMemory, mCallbackCookie, FALSE, QCAMERA_MEM_TYPE_BATCH); if (videoMemory == NULL) { LOGE("Out of memory for video batching obj"); return NULL; @@ -2793,7 +2796,7 @@ QCameraMemory *QCamera2HardwareInterface::allocateStreamBuf( } } else { videoMemory = - new QCameraVideoMemory(mGetMemory, bCachedMem); + new QCameraVideoMemory(mGetMemory, mCallbackCookie, bCachedMem); if (videoMemory == NULL) { LOGE("Out of memory for video obj"); return NULL; @@ -2812,6 +2815,7 @@ QCameraMemory *QCamera2HardwareInterface::allocateStreamBuf( break; case CAM_STREAM_TYPE_CALLBACK: mem = new QCameraStreamMemory(mGetMemory, + mCallbackCookie, bCachedMem, (bPoolMem) ? &m_memoryPool : NULL, stream_type); @@ -3114,7 +3118,7 @@ QCameraMemory *QCamera2HardwareInterface::allocateStreamUserBuf( switch (streamInfo->stream_type) { case CAM_STREAM_TYPE_VIDEO: { QCameraVideoMemory *video_mem = new QCameraVideoMemory( - mGetMemory, FALSE, QCAMERA_MEM_TYPE_BATCH); + mGetMemory, mCallbackCookie, FALSE, QCAMERA_MEM_TYPE_BATCH); if (video_mem == NULL) { LOGE("Out of memory for video obj"); return NULL; diff --git a/camera/QCamera2/HAL/QCameraMem.cpp b/camera/QCamera2/HAL/QCameraMem.cpp index e117047..5244e27 100644 --- a/camera/QCamera2/HAL/QCameraMem.cpp +++ b/camera/QCamera2/HAL/QCameraMem.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2012-2016, The Linux Foundation. All rights reserved. +/* Copyright (c) 2012-2017, The Linux Foundation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -1050,11 +1050,13 @@ int QCameraMetadataStreamMemory::getRegFlags(uint8_t *regFlags) const * RETURN : none *==========================================================================*/ QCameraStreamMemory::QCameraStreamMemory(camera_request_memory memory, + void* cbCookie, bool cached, QCameraMemoryPool *pool, cam_stream_type_t streamType, __unused cam_stream_buf_type bufType) :QCameraMemory(cached, pool, streamType), - mGetMemory(memory) + mGetMemory(memory), + mCallbackCookie(cbCookie) { for (int i = 0; i < MM_CAMERA_MAX_NUM_FRAMES; i ++) mCameraMemory[i] = NULL; @@ -1100,7 +1102,7 @@ int QCameraStreamMemory::allocate(uint8_t count, size_t size, uint32_t isSecure) if (isSecure == SECURE) { mCameraMemory[i] = 0; } else { - mCameraMemory[i] = mGetMemory(mMemInfo[i].fd, mMemInfo[i].size, 1, this); + mCameraMemory[i] = mGetMemory(mMemInfo[i].fd, mMemInfo[i].size, 1, mCallbackCookie); } } mBufferCount = count; @@ -1132,7 +1134,7 @@ int QCameraStreamMemory::allocateMore(uint8_t count, size_t size) } for (int i = mBufferCount; i < mBufferCount + count; i++) { - mCameraMemory[i] = mGetMemory(mMemInfo[i].fd, mMemInfo[i].size, 1, this); + mCameraMemory[i] = mGetMemory(mMemInfo[i].fd, mMemInfo[i].size, 1, mCallbackCookie); } mBufferCount = (uint8_t)(mBufferCount + count); ATRACE_END(); @@ -1280,9 +1282,9 @@ void *QCameraStreamMemory::getPtr(uint32_t index) const * * RETURN : none *==========================================================================*/ -QCameraVideoMemory::QCameraVideoMemory(camera_request_memory memory, +QCameraVideoMemory::QCameraVideoMemory(camera_request_memory memory, void* cbCookie, bool cached, QCameraMemType bufType) - : QCameraStreamMemory(memory, cached) + : QCameraStreamMemory(memory, cbCookie, cached) { memset(mMetadata, 0, sizeof(mMetadata)); memset(mNativeHandle, 0, sizeof(mNativeHandle)); @@ -1385,7 +1387,7 @@ int QCameraVideoMemory::allocateMore(uint8_t count, size_t size) if (!(mBufType & QCAMERA_MEM_TYPE_BATCH)) { for (int i = mBufferCount; i < count + mBufferCount; i ++) { mMetadata[i] = mGetMemory(-1, - sizeof(media_metadata_buffer), 1, this); + sizeof(media_metadata_buffer), 1, mCallbackCookie); if (!mMetadata[i]) { LOGE("allocation of video metadata failed."); for (int j = mBufferCount; j <= i-1; j ++) { @@ -1450,7 +1452,7 @@ int QCameraVideoMemory::allocateMeta(uint8_t buf_cnt, int numFDs, int numInts) for (int i = 0; i < buf_cnt; i++) { mMetadata[i] = mGetMemory(-1, - sizeof(media_metadata_buffer), 1, this); + sizeof(media_metadata_buffer), 1, mCallbackCookie); if (!mMetadata[i]) { LOGE("allocation of video metadata failed."); for (int j = (i - 1); j >= 0; j--) { @@ -1790,7 +1792,7 @@ int QCameraVideoMemory::convCamtoOMXFormat(cam_format_t format) * * RETURN : none *==========================================================================*/ -QCameraGrallocMemory::QCameraGrallocMemory(camera_request_memory memory) +QCameraGrallocMemory::QCameraGrallocMemory(camera_request_memory memory, void* cbCookie) : QCameraMemory(true), mColorSpace(ITU_R_601_FR) { mMinUndequeuedBuffers = 0; @@ -1798,6 +1800,7 @@ QCameraGrallocMemory::QCameraGrallocMemory(camera_request_memory memory) mWindow = NULL; mWidth = mHeight = mStride = mScanline = mUsage = 0; mFormat = HAL_PIXEL_FORMAT_YCrCb_420_SP; + mCallbackCookie = cbCookie; mGetMemory = memory; for (int i = 0; i < MM_CAMERA_MAX_NUM_FRAMES; i ++) { mBufferHandle[i] = NULL; @@ -1948,7 +1951,7 @@ int QCameraGrallocMemory::displayBuffer(uint32_t index) mGetMemory(mPrivateHandle[dequeuedIdx]->fd, (size_t)mPrivateHandle[dequeuedIdx]->size, 1, - (void *)this); + mCallbackCookie); LOGH("idx = %d, fd = %d, size = %d, offset = %d", dequeuedIdx, mPrivateHandle[dequeuedIdx]->fd, mPrivateHandle[dequeuedIdx]->size, @@ -2069,7 +2072,7 @@ int32_t QCameraGrallocMemory::dequeueBuffer() mGetMemory(mPrivateHandle[dequeuedIdx]->fd, (size_t)mPrivateHandle[dequeuedIdx]->size, 1, - (void *)this); + mCallbackCookie); LOGH("idx = %d, fd = %d, size = %d, offset = %d", dequeuedIdx, mPrivateHandle[dequeuedIdx]->fd, mPrivateHandle[dequeuedIdx]->size, @@ -2268,7 +2271,7 @@ int QCameraGrallocMemory::allocate(uint8_t count, size_t /*size*/, mGetMemory(mPrivateHandle[cnt]->fd, (size_t)mPrivateHandle[cnt]->size, 1, - (void *)this); + mCallbackCookie); LOGH("idx = %d, fd = %d, size = %d, offset = %d", cnt, mPrivateHandle[cnt]->fd, mPrivateHandle[cnt]->size, diff --git a/camera/QCamera2/HAL/QCameraMem.h b/camera/QCamera2/HAL/QCameraMem.h index c5139d5..36f4a23 100644 --- a/camera/QCamera2/HAL/QCameraMem.h +++ b/camera/QCamera2/HAL/QCameraMem.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2012-2016, The Linux Foundation. All rights reserved. +/* Copyright (c) 2012-2017, The Linux Foundation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -194,6 +194,7 @@ public: class QCameraStreamMemory : public QCameraMemory { public: QCameraStreamMemory(camera_request_memory getMemory, + void* cbCookie, bool cached, QCameraMemoryPool *pool = NULL, cam_stream_type_t streamType = CAM_STREAM_TYPE_DEFAULT, @@ -212,13 +213,14 @@ public: protected: camera_request_memory mGetMemory; camera_memory_t *mCameraMemory[MM_CAMERA_MAX_NUM_FRAMES]; + void* mCallbackCookie; }; // Externel heap memory is used for memories shared with // framework. They are allocated from /dev/ion or gralloc. class QCameraVideoMemory : public QCameraStreamMemory { public: - QCameraVideoMemory(camera_request_memory getMemory, bool cached, + QCameraVideoMemory(camera_request_memory getMemory, void* cbCookie, bool cached, QCameraMemType bufType = QCAMERA_MEM_TYPE_DEFAULT); virtual ~QCameraVideoMemory(); @@ -251,7 +253,7 @@ class QCameraGrallocMemory : public QCameraMemory { BUFFER_OWNED, }; public: - QCameraGrallocMemory(camera_request_memory getMemory); + QCameraGrallocMemory(camera_request_memory getMemory, void* cbCookie); void setNativeWindow(preview_stream_ops_t *anw); virtual ~QCameraGrallocMemory(); @@ -285,6 +287,7 @@ private: int mWidth, mHeight, mFormat, mStride, mScanline, mUsage; typeof (MetaData_t::refreshrate) mMaxFPS; camera_request_memory mGetMemory; + void* mCallbackCookie; camera_memory_t *mCameraMemory[MM_CAMERA_MAX_NUM_FRAMES]; int mMinUndequeuedBuffers; enum ColorSpace_t mColorSpace;