QCamera2:HAL1: Close duplicated FD's for media extension.

In video metadata mode, framework allocates native handle
resource and needs to be freed in release recording.
This change is to free framework resources in case of media
extension use cases.

Change-Id: I1bac10740130d506d71ec1275dd7d75f66c263c8
This commit is contained in:
Guruprasad Gaonkar 2016-04-19 19:42:09 -07:00 committed by Prateek Chaubey
parent 3dd1d4cba8
commit bacb43c44d
4 changed files with 37 additions and 11 deletions

View file

@ -703,6 +703,7 @@ void QCamera2HardwareInterface::stop_recording(struct camera_device *device)
// Disable power hint for video encoding
hw->m_perfLock.powerHint(POWER_HINT_VIDEO_ENCODE, false);
mVideoMem = NULL;
hw->lockAPI();
qcamera_api_result_t apiResult;
@ -764,6 +765,7 @@ void QCamera2HardwareInterface::release_recording_frame(
struct camera_device *device, const void *opaque)
{
ATRACE_CALL();
int32_t ret = NO_ERROR;
QCamera2HardwareInterface *hw =
reinterpret_cast<QCamera2HardwareInterface *>(device->priv);
if (!hw) {
@ -777,11 +779,20 @@ void QCamera2HardwareInterface::release_recording_frame(
LOGD("E camera id %d", hw->getCameraId());
//Close and delete duplicated native handle and FD's.
QCameraVideoMemory::closeNativeHandle(opaque, hw->mStoreMetaDataInFrame > 0);
if (hw->mVideoMem != NULL) {
ret = hw->mVideoMem->closeNativeHandle(opaque,
hw->mStoreMetaDataInFrame > 0);
if (ret != NO_ERROR) {
LOGE("Invalid video metadata");
return;
}
} else {
LOGW("Possible FD leak. Release recording called after stop");
}
hw->lockAPI();
qcamera_api_result_t apiResult;
int32_t ret = hw->processAPI(QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME, (void *)opaque);
ret = hw->processAPI(QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME, (void *)opaque);
if (ret == NO_ERROR) {
hw->waitAPIResult(QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME, &apiResult);
}
@ -1671,6 +1682,7 @@ QCamera2HardwareInterface::QCamera2HardwareInterface(uint32_t cameraId)
mJpegClientHandle(0),
mJpegHandleOwner(false),
mMetadataMem(NULL),
mVideoMem(NULL),
mCACDoneReceived(false),
m_bNeedRestart(false),
mIgnoredPreviewCount(0)
@ -2811,6 +2823,7 @@ QCameraMemory *QCamera2HardwareInterface::allocateStreamBuf(
}
videoMemory->setVideoInfo(usage, fmt);
mem = videoMemory;
mVideoMem = videoMemory;
}
break;
case CAM_STREAM_TYPE_CALLBACK:
@ -3142,6 +3155,7 @@ QCameraMemory *QCamera2HardwareInterface::allocateStreamUserBuf(
}
video_mem->setVideoInfo(usage, fmt);
mem = static_cast<QCameraMemory *>(video_mem);
mVideoMem = video_mem;
}
break;
@ -3578,6 +3592,7 @@ int QCamera2HardwareInterface::startRecording()
int32_t rc = NO_ERROR;
LOGI("E");
mVideoMem = NULL;
//link meta stream with video channel if low power mode.
if (isLowPowerMode()) {
// Find and try to link a metadata stream from preview channel

View file

@ -745,6 +745,7 @@ private:
bool TsMakeupProcess(mm_camera_buf_def_t *frame,QCameraStream * stream,TSRect& faceRect);
#endif
QCameraMemory *mMetadataMem;
QCameraVideoMemory *mVideoMem;
static uint32_t sNextJobId;

View file

@ -1601,21 +1601,31 @@ native_handle_t *QCameraVideoMemory::updateNativeHandle(uint32_t index, bool met
int QCameraVideoMemory::closeNativeHandle(const void *data, bool metadata)
{
int32_t rc = NO_ERROR;
int32_t index = -1;
#ifdef USE_MEDIA_EXTENSIONS
camera_memory_t *video_mem = (camera_memory_t *)data;
camera_memory_t *video_mem = NULL;
if(video_mem == NULL) {
LOGE("video_mem NULL. Failed");
if (metadata) {
index = getMatchBufIndex(data, metadata);
if (index < 0) {
LOGE("Invalid buffer");
return BAD_VALUE;
}
if (metadata) {
media_metadata_buffer *packet =
(media_metadata_buffer *)video_mem->data;
if (packet->eType == kMetadataBufferTypeNativeHandleSource) {
video_mem = getMemory(index, metadata);
media_metadata_buffer * packet = NULL;
if (video_mem) {
packet = (media_metadata_buffer *)video_mem->data;
}
if (packet != NULL && packet->eType ==
kMetadataBufferTypeNativeHandleSource) {
native_handle_close(packet->pHandle);
native_handle_delete(packet->pHandle);
packet->pHandle = NULL;
} else {
LOGE("Invalid Data. Could not release");
return BAD_VALUE;
}
} else {
LOGE("Not of type video meta buffer. Failed");

View file

@ -232,7 +232,7 @@ public:
int getFormat(){return mFormat;};
int convCamtoOMXFormat(cam_format_t format);
native_handle_t *updateNativeHandle(uint32_t index, bool metadata = true);
static int closeNativeHandle(const void *data, bool metadata = true);
int closeNativeHandle(const void *data, bool metadata = true);
private:
camera_memory_t *mMetadata[MM_CAMERA_MAX_NUM_FRAMES];
uint8_t mMetaBufCount;