mm-video-v4l2: vdec: handle_extradata: map/unmap buffer everytime
Buffer address present on drv_ctx.ptr_outputbuffer will become
invalid with the arrival of more buffer with new fds. So instead
of relying on this field map the output buffer fd everytime while
handling extradata.
CRs-Fixed: 1021773
Change-Id: I0f4245953bcf35e89b9c84a4b5d5ae9cbc34da2e
diff --git a/mm-video-v4l2/vidc/common/inc/vidc_debug.h b/mm-video-v4l2/vidc/common/inc/vidc_debug.h
index 6355188..3d5bbb5 100644
--- a/mm-video-v4l2/vidc/common/inc/vidc_debug.h
+++ b/mm-video-v4l2/vidc/common/inc/vidc_debug.h
@@ -32,6 +32,7 @@
#ifdef _ANDROID_
#include <cstdio>
#include <pthread.h>
+#include <sys/mman.h>
enum {
PRIO_ERROR=0x1,
@@ -93,4 +94,20 @@
pthread_mutex_t &mLock;
};
+class AutoUnmap {
+ void *vaddr;
+ int size;
+
+ public:
+ AutoUnmap(void *vaddr, int size) {
+ this->vaddr = vaddr;
+ this->size = size;
+ }
+
+ ~AutoUnmap() {
+ if (vaddr)
+ munmap(vaddr, size);
+ }
+};
+
#endif
diff --git a/mm-video-v4l2/vidc/vdec/src/omx_vdec_v4l2.cpp b/mm-video-v4l2/vidc/vdec/src/omx_vdec_v4l2.cpp
index fcac9bf..a1a5765 100644
--- a/mm-video-v4l2/vidc/vdec/src/omx_vdec_v4l2.cpp
+++ b/mm-video-v4l2/vidc/vdec/src/omx_vdec_v4l2.cpp
@@ -10151,6 +10151,7 @@
void omx_vdec::handle_extradata(OMX_BUFFERHEADERTYPE *p_buf_hdr)
{
OMX_OTHER_EXTRADATATYPE *p_extra = NULL, *p_sei = NULL, *p_vui = NULL, *p_client_extra = NULL;
+ OMX_U8 *pBuffer = NULL;
OMX_U32 num_conceal_MB = 0;
OMX_TICKS time_stamp = 0;
OMX_U32 frame_rate = 0;
@@ -10175,9 +10176,6 @@
return;
}
- OMX_U8 *pBuffer = (OMX_U8 *)(drv_ctx.ptr_outputbuffer[buf_index].bufferaddr) +
- p_buf_hdr->nOffset;
-
if (!drv_ctx.extradata_info.uaddr) {
DEBUG_PRINT_HIGH("NULL drv_ctx.extradata_info.uaddr");
return;
@@ -10187,12 +10185,19 @@
p_extra = NULL;
return;
}
- if (!secure_mode)
+ if (!secure_mode) {
+ pBuffer = (OMX_U8*)mmap(0, drv_ctx.ptr_outputbuffer[buf_index].buffer_len,
+ PROT_READ|PROT_WRITE, MAP_SHARED, drv_ctx.ptr_outputbuffer[buf_index].pmem_fd, 0);
+ if (pBuffer == MAP_FAILED) {
+ DEBUG_PRINT_ERROR("handle_extradata output buffer mmap failed - errno: %d", errno);
+ return;
+ }
p_extra = (OMX_OTHER_EXTRADATATYPE *)
((unsigned long)(pBuffer + p_buf_hdr->nOffset + p_buf_hdr->nFilledLen + 3)&(~3));
- else
+ } else
p_extra = m_other_extradata;
+ AutoUnmap autounmap(pBuffer, drv_ctx.ptr_outputbuffer[buf_index].buffer_len);
if (m_client_extradata_info.getBase() &&
m_client_extradata_info.getSize() >= drv_ctx.extradata_info.buffer_size) {
p_client_extra = (OMX_OTHER_EXTRADATATYPE *) (m_client_extradata_info.getBase() +