Skip to content

Commit 5253b43

Browse files
c_sridurkhusika
authored andcommitted
mm-video-legacy: vdec: add YUV420SP support in surface-mode
Allow Semiplanar format in surface-mode and deploy C2D for conversion. This is required to support at least one flexible-YUV since TILE cannot possibly be described as linear. Change-Id: Ic788c9c803cd18966d7625054c565758ea068e13
1 parent b3b0673 commit 5253b43

File tree

2 files changed

+122
-6
lines changed

2 files changed

+122
-6
lines changed

mm-video/vidc/vdec/inc/omx_vdec.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,12 +874,17 @@ class omx_vdec: public qc_omx_component
874874
OMX_ERRORTYPE allocate_buffers_color_convert(OMX_HANDLETYPE hComp,
875875
OMX_BUFFERHEADERTYPE **bufferHdr,OMX_U32 port,OMX_PTR appData,
876876
OMX_U32 bytes);
877+
OMX_ERRORTYPE use_output_buffer(OMX_HANDLETYPE hComp,
878+
OMX_BUFFERHEADERTYPE **bufferHdr, OMX_U32 port, OMX_PTR appData,
879+
OMX_U32 bytes, OMX_U8 *buffer);
877880
OMX_ERRORTYPE free_output_buffer(OMX_BUFFERHEADERTYPE *bufferHdr);
881+
void enable_native_buffers(bool enable) {m_native_buffers_enabled = enable;}
878882
#define MAX_COUNT 32
879883
OMX_BUFFERHEADERTYPE m_out_mem_ptr_client[MAX_COUNT];
880884
private:
881885
omx_vdec *omx;
882886
bool enabled;
887+
bool m_native_buffers_enabled;
883888
OMX_COLOR_FORMATTYPE ColorFormat;
884889
void init_members();
885890
bool color_convert_mode;

mm-video/vidc/vdec/src/omx_vdec.cpp

Lines changed: 117 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3873,6 +3873,7 @@ OMX_ERRORTYPE omx_vdec::set_parameter(OMX_IN OMX_HANDLETYPE hComp,
38733873
EnableAndroidNativeBuffersParams* enableNativeBuffers = (EnableAndroidNativeBuffersParams *) paramData;
38743874
if(enableNativeBuffers) {
38753875
m_enable_android_native_buffers = enableNativeBuffers->enable;
3876+
client_buffers.enable_native_buffers(m_enable_android_native_buffers);
38763877
}
38773878
}
38783879
break;
@@ -4784,8 +4785,9 @@ OMX_ERRORTYPE omx_vdec::use_buffer(
47844785
}
47854786
if(port == OMX_CORE_INPUT_PORT_INDEX)
47864787
error = use_input_heap_buffers(hComp, bufferHdr, port, appData, bytes, buffer);
4787-
else if(port == OMX_CORE_OUTPUT_PORT_INDEX)
4788-
error = use_output_buffer(hComp,bufferHdr,port,appData,bytes,buffer); //not tested
4788+
else if(port == OMX_CORE_OUTPUT_PORT_INDEX){
4789+
error = client_buffers.use_output_buffer(hComp,bufferHdr,port,appData,bytes,buffer); //not tested
4790+
}
47894791
else
47904792
{
47914793
DEBUG_PRINT_ERROR("Error: Invalid Port Index received %d\n",(int)port);
@@ -10158,6 +10160,7 @@ void omx_vdec::allocate_color_convert_buf::init_members() {
1015810160
memset(op_buf_ion_info,0,sizeof(m_platform_entry_client));
1015910161
for (int i = 0; i < MAX_COUNT;i++)
1016010162
pmem_fd[i] = -1;
10163+
m_native_buffers_enabled = false;
1016110164
}
1016210165

1016310166
omx_vdec::allocate_color_convert_buf::~allocate_color_convert_buf() {
@@ -10291,6 +10294,20 @@ OMX_BUFFERHEADERTYPE* omx_vdec::allocate_color_convert_buf::get_il_buf_hdr
1029110294
status = c2d.convert(omx->drv_ctx.ptr_outputbuffer[index].pmem_fd,
1029210295
bufadd->pBuffer,pmem_fd[index],pmem_baseaddress[index]);
1029310296
m_out_mem_ptr_client[index].nFilledLen = buffer_size_req;
10297+
// DEBUG: dump converted output
10298+
#if 0
10299+
{
10300+
FILE* fp = fopen("/data/misc/media/out.yuv","ab");
10301+
if (fp) {
10302+
ALOGI("c2d: dumped: %dx%d",omx->drv_ctx.video_resolution.frame_height,
10303+
omx->drv_ctx.video_resolution.frame_width);
10304+
fwrite(pmem_baseaddress[index],
10305+
(omx->drv_ctx.video_resolution.frame_height *
10306+
omx->drv_ctx.video_resolution.frame_width * 3)/2, 1, fp);
10307+
fclose(fp);
10308+
}
10309+
}
10310+
#endif
1029410311
pthread_mutex_unlock(&omx->c_lock);
1029510312
if (!status){
1029610313
DEBUG_PRINT_ERROR("\n Failed color conversion %d", status);
@@ -10358,11 +10375,32 @@ OMX_ERRORTYPE omx_vdec::allocate_color_convert_buf::free_output_buffer(
1035810375
DEBUG_PRINT_ERROR("\n Incorrect index color convert free_output_buffer");
1035910376
return OMX_ErrorBadParameter;
1036010377
}
10361-
if (pmem_fd[index] > 0) {
10362-
munmap(pmem_baseaddress[index], buffer_size_req);
10378+
if (m_native_buffers_enabled) {
10379+
// unmap client's fd
10380+
if (pmem_fd[index] > 0 && pmem_baseaddress[index]) {
10381+
munmap(pmem_baseaddress[index], buffer_size_req);
10382+
pmem_baseaddress[index] = 0;
10383+
}
10384+
// free from internal set
10385+
// Do this explicitly as omx->free_output_buffer() does not free
10386+
// the memory when native-buffers are enabled
10387+
if (omx->drv_ctx.ptr_outputbuffer[index].pmem_fd > 0) {
10388+
ALOGI("free_buffer(conversion): free ion mem[%d] fd=%d size=%d",
10389+
index, omx->drv_ctx.ptr_outputbuffer[index].pmem_fd,
10390+
omx->drv_ctx.ptr_outputbuffer[index].mmaped_size);
10391+
munmap (omx->drv_ctx.ptr_outputbuffer[index].bufferaddr,
10392+
omx->drv_ctx.ptr_outputbuffer[index].mmaped_size);
10393+
omx->free_ion_memory(&(omx->drv_ctx.op_buf_ion_info[index]));
10394+
close (omx->drv_ctx.ptr_outputbuffer[index].pmem_fd);
10395+
omx->drv_ctx.ptr_outputbuffer[index].pmem_fd = -1;
10396+
}
10397+
} else {
10398+
if (pmem_fd[index] > 0) {
10399+
munmap(pmem_baseaddress[index], buffer_size_req);
10400+
}
10401+
omx->free_ion_memory(&op_buf_ion_info[index]);
10402+
pmem_fd[index] = -1;
1036310403
}
10364-
omx->free_ion_memory(&op_buf_ion_info[index]);
10365-
pmem_fd[index] = -1;
1036610404
m_heap_ptr[index].video_heap_ptr = NULL;
1036710405
if (allocated_count > 0)
1036810406
allocated_count--;
@@ -10457,6 +10495,79 @@ OMX_ERRORTYPE omx_vdec::allocate_color_convert_buf::allocate_buffers_color_conve
1045710495
return eRet;
1045810496
}
1045910497

10498+
OMX_ERRORTYPE omx_vdec::allocate_color_convert_buf::use_output_buffer(OMX_HANDLETYPE hComp,
10499+
OMX_BUFFERHEADERTYPE **bufferHdr, OMX_U32 port, OMX_PTR appData,
10500+
OMX_U32 bytes, OMX_U8 *buffer)
10501+
{
10502+
OMX_ERRORTYPE eRet = OMX_ErrorNone;
10503+
const char *func = "use_buf(conversion)";
10504+
if (!enabled) {
10505+
return omx->use_output_buffer(hComp, bufferHdr, port, appData, bytes, buffer);
10506+
}
10507+
// assert native-buffer-mode is enabled
10508+
if (!m_native_buffers_enabled) {
10509+
DEBUG_PRINT_ERROR("%s: use_buffer called in non-surface mode", func);
10510+
return OMX_ErrorUnsupportedSetting;
10511+
}
10512+
if (omx->is_component_secure()) {
10513+
DEBUG_PRINT_ERROR("%s: Cannot color-convert secure buffers", func);
10514+
return OMX_ErrorUnsupportedSetting;
10515+
}
10516+
if (!bufferHdr || bytes > buffer_size_req) {
10517+
DEBUG_PRINT_ERROR("%s: Invalid params hdr=%p requested-size=%d passed-size=%d",
10518+
func, bufferHdr, buffer_size_req, bytes);
10519+
return OMX_ErrorBadParameter;
10520+
}
10521+
if (allocated_count >= omx->drv_ctx.op_buf.actualcount) {
10522+
DEBUG_PRINT_ERROR("%s: all buffers (%d) already allocated", func, allocated_count);
10523+
return OMX_ErrorInsufficientResources;
10524+
}
10525+
// Allocate pixel buffer for the decoder
10526+
OMX_BUFFERHEADERTYPE *temp_bufferHdr = NULL;
10527+
eRet = omx->allocate_output_buffer(hComp, &temp_bufferHdr,
10528+
port, appData, omx->drv_ctx.op_buf.buffer_size);
10529+
if (eRet != OMX_ErrorNone || !temp_bufferHdr){
10530+
DEBUG_PRINT_ERROR("%s: decoder's o/p allocation failed", func);
10531+
return eRet;
10532+
}
10533+
if ((temp_bufferHdr - omx->m_out_mem_ptr) >= omx->drv_ctx.op_buf.actualcount) {
10534+
DEBUG_PRINT_ERROR("%s: Invalid header index %d",
10535+
func, (temp_bufferHdr - omx->m_out_mem_ptr));
10536+
return OMX_ErrorUndefined;
10537+
}
10538+
unsigned int i = allocated_count;
10539+
private_handle_t *handle = (private_handle_t *)buffer;
10540+
pmem_fd[i] = handle->fd;
10541+
pmem_baseaddress[i] = (OMX_U8*)mmap(0, handle->size,
10542+
PROT_READ|PROT_WRITE, MAP_SHARED, handle->fd, 0);
10543+
if (pmem_baseaddress[i] == MAP_FAILED) {
10544+
DEBUG_PRINT_ERROR("%s: Failed to map native handle fd=%d size=%d",
10545+
func, handle->fd, handle->size);
10546+
return OMX_ErrorInsufficientResources;
10547+
}
10548+
m_heap_ptr[i].video_heap_ptr = NULL; //not used
10549+
m_pmem_info_client[i].pmem_fd = handle->fd;
10550+
m_pmem_info_client[i].offset = 0;
10551+
m_platform_entry_client[i].entry = (void *)&m_pmem_info_client[i];
10552+
m_platform_entry_client[i].type = OMX_QCOM_PLATFORM_PRIVATE_PMEM;
10553+
m_platform_list_client[i].nEntries = 1;
10554+
m_platform_list_client[i].entryList = &m_platform_entry_client[i];
10555+
m_out_mem_ptr_client[i].pOutputPortPrivate = NULL;
10556+
m_out_mem_ptr_client[i].nAllocLen = handle->size;
10557+
m_out_mem_ptr_client[i].nFilledLen = 0;
10558+
m_out_mem_ptr_client[i].nFlags = 0;
10559+
m_out_mem_ptr_client[i].nOutputPortIndex = OMX_CORE_OUTPUT_PORT_INDEX;
10560+
m_out_mem_ptr_client[i].nSize = sizeof(OMX_BUFFERHEADERTYPE);
10561+
m_out_mem_ptr_client[i].nVersion.nVersion = OMX_SPEC_VERSION;
10562+
m_out_mem_ptr_client[i].pPlatformPrivate = &m_platform_list_client[i];
10563+
m_out_mem_ptr_client[i].pBuffer = buffer;
10564+
m_out_mem_ptr_client[i].pAppPrivate = appData;
10565+
*bufferHdr = &m_out_mem_ptr_client[i];
10566+
ALOGI("%s: allocated header[%d]=%p for native handle[fd=%d size=%d]",
10567+
func, i, *bufferHdr, handle->fd, handle->size);
10568+
allocated_count++;
10569+
return eRet;
10570+
}
1046010571
bool omx_vdec::is_component_secure()
1046110572
{
1046210573
return secure_mode;

0 commit comments

Comments
 (0)