Skip to content

Commit

Permalink
ido: camera: Fix HAL1 callback cookie
Browse files Browse the repository at this point in the history
Test: HIDL HAL1 preview up and running
Bug: 30985004
Change-Id: I085f163de6c1c6552925c8241e744c723697d544
  • Loading branch information
Yin-Chia Yeh authored and Anik1199 committed Feb 4, 2018
1 parent 9303e49 commit 6ce726d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
10 changes: 6 additions & 4 deletions camera/QCamera2/HAL/QCamera2HWI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1731,14 +1731,15 @@ 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);
new QCameraGrallocMemory(mGetMemory, mCallbackCookie);

mParameters.getStreamDimension(stream_type, dim);
/* we are interested only in maxfps here */
Expand All @@ -1754,12 +1755,12 @@ QCameraMemory *QCamera2HardwareInterface::allocateStreamBuf(
case CAM_STREAM_TYPE_POSTVIEW:
{
if (isPreviewRestartEnabled() || isNoDisplayMode()) {
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 */
Expand All @@ -1781,6 +1782,7 @@ QCameraMemory *QCamera2HardwareInterface::allocateStreamBuf(
case CAM_STREAM_TYPE_METADATA:
case CAM_STREAM_TYPE_OFFLINE_PROC:
mem = new QCameraStreamMemory(mGetMemory,
mCallbackCookie,
bCachedMem,
(bPoolMem) ? &m_memoryPool : NULL,
stream_type);
Expand All @@ -1791,7 +1793,7 @@ QCameraMemory *QCamera2HardwareInterface::allocateStreamBuf(
bCachedMem = mParameters.isVideoBuffersCached();
CDBG_HIGH("%s: %s video buf allocated ", __func__,
(bCachedMem == 0) ? "Uncached" : "Cached" );
QCameraVideoMemory *videoMemory = new QCameraVideoMemory(mGetMemory, bCachedMem);
QCameraVideoMemory *videoMemory = new QCameraVideoMemory(mGetMemory, mCallbackCookie, bCachedMem);
mem = videoMemory;
mVideoMem = videoMemory;
}
Expand Down
22 changes: 13 additions & 9 deletions camera/QCamera2/HAL/QCameraMem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1007,11 +1007,13 @@ int QCameraHeapMemory::getMatchBufIndex(const void *opaque,
* RETURN : none
*==========================================================================*/
QCameraStreamMemory::QCameraStreamMemory(camera_request_memory getMemory,
void* cbCookie,
bool cached,
QCameraMemoryPool *pool,
cam_stream_type_t streamType)
:QCameraMemory(cached, pool, streamType),
mGetMemory(getMemory)
mGetMemory(getMemory),
mCallbackCookie(cbCookie)
{
for (int i = 0; i < MM_CAMERA_MAX_NUM_FRAMES; i ++)
mCameraMemory[i] = NULL;
Expand Down Expand Up @@ -1052,7 +1054,7 @@ int QCameraStreamMemory::allocate(uint8_t count, size_t size)
return rc;

for (int i = 0; i < 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 = count;
traceLogAllocEnd((size * count));
Expand Down Expand Up @@ -1081,7 +1083,7 @@ int QCameraStreamMemory::allocateMore(uint8_t count, size_t size)
return rc;

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);
traceLogAllocEnd((size * count));
Expand Down Expand Up @@ -1225,9 +1227,10 @@ void *QCameraStreamMemory::getPtr(uint32_t index) const
*
* RETURN : none
*==========================================================================*/
QCameraVideoMemory::QCameraVideoMemory(camera_request_memory getMemory,
QCameraVideoMemory::QCameraVideoMemory(camera_request_memory memory,
void* cbCookie,
bool cached)
: QCameraStreamMemory(getMemory, cached)
: QCameraStreamMemory(memory, cbCookie, cached)
{
memset(mMetadata, 0, sizeof(mMetadata));
memset(mNativeHandle, 0, sizeof(mNativeHandle));
Expand Down Expand Up @@ -1269,7 +1272,7 @@ int QCameraVideoMemory::allocate(uint8_t count, size_t size)

for (int i = 0; i < count; i ++) {
mMetadata[i] = mGetMemory(-1,
sizeof(media_metadata_buffer), 1, this);
sizeof(media_metadata_buffer), 1, mCallbackCookie);
if (!mMetadata[i]) {
ALOGE("allocation of video metadata failed.");
for (int j = 0; j <= i-1; j ++)
Expand Down Expand Up @@ -1337,7 +1340,7 @@ int QCameraVideoMemory::allocateMore(uint8_t count, size_t size)

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]) {
ALOGE("allocation of video metadata failed.");
for (int j = mBufferCount; j <= i-1; j ++) {
Expand Down Expand Up @@ -1466,14 +1469,15 @@ int QCameraVideoMemory::getMatchBufIndex(const void *opaque,
*
* RETURN : none
*==========================================================================*/
QCameraGrallocMemory::QCameraGrallocMemory(camera_request_memory getMemory)
QCameraGrallocMemory::QCameraGrallocMemory(camera_request_memory getMemory, void* cbCookie)
: QCameraMemory(true)
{
mMinUndequeuedBuffers = 0;
mWindow = NULL;
mWidth = mHeight = mStride = mScanline = 0;
mFormat = HAL_PIXEL_FORMAT_YCrCb_420_SP;
mGetMemory = getMemory;
mCallbackCookie = cbCookie;
for (int i = 0; i < MM_CAMERA_MAX_NUM_FRAMES; i ++) {
mBufferHandle[i] = NULL;
mLocalFlag[i] = BUFFER_NOT_OWNED;
Expand Down Expand Up @@ -1763,7 +1767,7 @@ int QCameraGrallocMemory::allocate(uint8_t count, size_t /*size*/)
mGetMemory(mPrivateHandle[cnt]->fd,
(size_t)mPrivateHandle[cnt]->size,
1,
(void *)this);
mCallbackCookie);
CDBG("%s: idx = %d, fd = %d, size = %d, offset = %d",
__func__, cnt, mPrivateHandle[cnt]->fd,
mPrivateHandle[cnt]->size,
Expand Down
8 changes: 6 additions & 2 deletions camera/QCamera2/HAL/QCameraMem.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ class QCameraHeapMemory : public QCameraMemory {
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);
Expand All @@ -180,14 +181,16 @@ class QCameraStreamMemory : public QCameraMemory {

protected:
camera_request_memory mGetMemory;
void* mCallbackCookie;
camera_memory_t *mCameraMemory[MM_CAMERA_MAX_NUM_FRAMES];
};

// 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);
virtual ~QCameraVideoMemory();

virtual int allocate(uint8_t count, size_t size);
Expand All @@ -212,7 +215,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();

Expand Down Expand Up @@ -240,6 +243,7 @@ class QCameraGrallocMemory : public QCameraMemory {
preview_stream_ops_t *mWindow;
int mWidth, mHeight, mFormat, mStride, mScanline, mMaxFPS;
camera_request_memory mGetMemory;
void* mCallbackCookie;
camera_memory_t *mCameraMemory[MM_CAMERA_MAX_NUM_FRAMES];
int mMinUndequeuedBuffers;
};
Expand Down

0 comments on commit 6ce726d

Please sign in to comment.