mm-video-v4l2: Add support for AllocateNativeHandle extension

Add support for AllocateNativeHandle extension on
secure encoder's session output port.

Change-Id: Ie48a52dbc487634df9cf81d970c047cf1c930063
This commit is contained in:
Manikanta Kanamarlapudi 2016-10-20 12:06:18 +05:30 committed by Gerrit - the friendly Code Review server
parent 6d69567372
commit 05eb06b0b8
4 changed files with 101 additions and 39 deletions

View file

@ -691,6 +691,8 @@ class omx_video: public qc_omx_component
int pending_input_buffers;
int pending_output_buffers;
bool allocate_native_handle;
uint64_t m_out_bm_count;
uint64_t m_inp_bm_count;
uint64_t m_flags;

View file

@ -2467,6 +2467,12 @@ OMX_ERRORTYPE omx_video::get_extension_index(OMX_IN OMX_HANDLETYPE hComp,
*indexType = (OMX_INDEXTYPE)OMX_QTIIndexConfigDescribeColorAspects;
return OMX_ErrorNone;
}
if (extn_equals(paramName, "OMX.google.android.index.allocateNativeHandle")) {
*indexType = (OMX_INDEXTYPE)OMX_GoogleAndroidIndexAllocateNativeHandle;
return OMX_ErrorNone;
}
return OMX_ErrorNotImplemented;
}
@ -3043,6 +3049,12 @@ OMX_ERRORTYPE omx_video::free_output_buffer(OMX_BUFFERHEADERTYPE *bufferHdr)
if(!secure_session) {
munmap (m_pOutput_pmem[index].buffer,
m_pOutput_pmem[index].size);
} else {
if (allocate_native_handle) {
native_handle_t *handle = NULL;
handle = (native_handle_t *)m_pOutput_pmem[index].buffer;
native_handle_close(handle);
native_handle_delete(handle);
} else {
char *data = (char*) m_pOutput_pmem[index].buffer;
native_handle_t *handle = NULL;
@ -3050,6 +3062,7 @@ OMX_ERRORTYPE omx_video::free_output_buffer(OMX_BUFFERHEADERTYPE *bufferHdr)
native_handle_delete(handle);
free(m_pOutput_pmem[index].buffer);
}
}
close (m_pOutput_pmem[index].fd);
#ifdef USE_ION
free_ion_memory(&m_pOutput_ion[index]);
@ -3439,6 +3452,18 @@ OMX_ERRORTYPE omx_video::allocate_output_buffer(
else {
//This should only be used for passing reference to source type and
//secure handle fd struct native_handle_t*
if (allocate_native_handle) {
native_handle_t *nh = native_handle_create(1 /*numFds*/, 3 /*numInts*/);
if (!nh) {
DEBUG_PRINT_ERROR("Native handle create failed");
return OMX_ErrorInsufficientResources;
}
nh->data[0] = m_pOutput_pmem[i].fd;
nh->data[1] = 0;
nh->data[2] = 0;
nh->data[3] = ALIGN(m_sOutPortDef.nBufferSize, 4096);
m_pOutput_pmem[i].buffer = (OMX_U8 *)nh;
} else {
native_handle_t *handle = native_handle_create(1, 3); //fd, offset, size, alloc length
if (!handle) {
DEBUG_PRINT_ERROR("ERROR: native handle creation failed");
@ -3458,6 +3483,7 @@ OMX_ERRORTYPE omx_video::allocate_output_buffer(
buffer->type = 1;
buffer->nh = handle;
}
}
(*bufferHdr)->pBuffer = (OMX_U8 *)m_pOutput_pmem[i].buffer;
(*bufferHdr)->pAppPrivate = appData;

View file

@ -1148,6 +1148,31 @@ OMX_ERRORTYPE omx_venc::set_parameter(OMX_IN OMX_HANDLETYPE hComp,
break;
}
case OMX_GoogleAndroidIndexAllocateNativeHandle:
{
VALIDATE_OMX_PARAM_DATA(paramData, AllocateNativeHandleParams);
AllocateNativeHandleParams* allocateNativeHandleParams = (AllocateNativeHandleParams *) paramData;
if (!secure_session) {
DEBUG_PRINT_ERROR("Enable/Disable allocate-native-handle allowed only in secure session");
eRet = OMX_ErrorUnsupportedSetting;
break;
} else if (allocateNativeHandleParams->nPortIndex != PORT_INDEX_OUT) {
DEBUG_PRINT_ERROR("Enable/Disable allocate-native-handle allowed only on Output port!");
eRet = OMX_ErrorUnsupportedSetting;
break;
} else if (m_out_mem_ptr) {
DEBUG_PRINT_ERROR("Enable/Disable allocate-native-handle is not allowed since Output port is not free !");
eRet = OMX_ErrorInvalidState;
break;
}
if (allocateNativeHandleParams != NULL) {
allocate_native_handle = allocateNativeHandleParams->enable;
}
break;
}
case OMX_IndexParamVideoQuantization:
{
VALIDATE_OMX_PARAM_DATA(paramData, OMX_VIDEO_PARAM_QUANTIZATIONTYPE);
@ -1292,14 +1317,9 @@ OMX_ERRORTYPE omx_venc::set_parameter(OMX_IN OMX_HANDLETYPE hComp,
}
}
} else if (pParam->nPortIndex == PORT_INDEX_OUT && secure_session) {
if (pParam->bStoreMetaData != meta_mode_enable) {
if (!handle->venc_set_meta_mode(pParam->bStoreMetaData)) {
DEBUG_PRINT_ERROR("\nERROR: set Metabuffer mode %d fail",
pParam->bStoreMetaData);
DEBUG_PRINT_ERROR("set_parameter: metamode is "
"valid for input port only in secure session");
return OMX_ErrorUnsupportedSetting;
}
meta_mode_enable = pParam->bStoreMetaData;
}
} else {
DEBUG_PRINT_ERROR("set_parameter: metamode is "
"valid for input port only");
@ -2622,6 +2642,14 @@ int omx_venc::async_message_process (void *context, void* message)
m_sVenc_msg->buf.len);
}
} else if (omx->is_secure_session()) {
if (omx->allocate_native_handle) {
native_handle_t *nh = (native_handle_t *)(omxhdr->pBuffer);
nh->data[1] = m_sVenc_msg->buf.offset;
nh->data[2] = m_sVenc_msg->buf.len;
omxhdr->nFilledLen = m_sVenc_msg->buf.len;
omxhdr->nTimeStamp = m_sVenc_msg->buf.timestamp;
omxhdr->nFlags = m_sVenc_msg->buf.flags;
} else {
output_metabuffer *meta_buf = (output_metabuffer *)(omxhdr->pBuffer);
native_handle_t *nh = meta_buf->nh;
nh->data[1] = m_sVenc_msg->buf.offset;
@ -2629,6 +2657,7 @@ int omx_venc::async_message_process (void *context, void* message)
omxhdr->nFilledLen = sizeof(output_metabuffer);
omxhdr->nTimeStamp = m_sVenc_msg->buf.timestamp;
omxhdr->nFlags = m_sVenc_msg->buf.flags;
}
} else {
omxhdr->nFilledLen = 0;
}

View file

@ -4251,10 +4251,15 @@ bool venc_dev::venc_fill_buf(void *buffer, void *pmem_data_buf,unsigned index,un
buf.flags = 0;
if (venc_handle->is_secure_session()) {
if (venc_handle->allocate_native_handle) {
native_handle_t *handle_t = (native_handle_t *)(bufhdr->pBuffer);
plane[0].length = handle_t->data[3];
} else {
output_metabuffer *meta_buf = (output_metabuffer *)(bufhdr->pBuffer);
native_handle_t *handle_t = meta_buf->nh;
plane[0].length = handle_t->data[3];
}
}
if (mBatchSize) {
// Should always mark first buffer as DEFER, since 0 % anything is 0, just offset by 1