这篇文章介绍Android multimedia框架中分配用于存储压缩的视频数据的input port buffers、提取视频文件中的压缩数据、复制提取后的视频压缩数据到input port buffer,之后exynos H.264解码器解码input port buffer中的压缩数据。
在OMXCodec::allocateBuffersOnPort中分配input port buffers
status_t OMXCodec::allocateBuffersOnPort(OMX_U32 portIndex) {
1.
err = mOMX->getParameter(
mNode, OMX_IndexParamPortDefinition, &def, sizeof(def));
上面mOMX->getParameter函数调用中有一个binder进程间通讯,它最终会调用:
#define OMX_GetParameter( \
hComponent, \
nParamIndex, \
pComponentParameterStructure) \
((OMX_COMPONENTTYPE*)hComponent)->GetParameter( \
hComponent, \
nParamIndex, \
pComponentParameterStructure) /* Macro End */
hComponent(handle)在allocateNode函数调用中确定,对于三星exynos、h.264的情况,GetParameter指向Exynos_H264Dec_GetParameter,这个
指针同样是在allocateNode函数调用中确定。下面看一下这个函数调用:
OMX_ERRORTYPE Exynos_OMX_GetParameter(
case OMX_IndexParamPortDefinition:
Exynos_OSAL_Memcpy(portDefinition, &pExynosPort->portDefinition, portDefinition->nSize);
上面pExynosPort->portDefinition结构在allocateNode函数调用中执行如下函数设置:
OSCL_EXPORT_REF OMX_ERRORTYPE Exynos_OMX_ComponentInit(OMX_HANDLETYPE hComponent, OMX_STRING componentName)
/* Input port */
pExynosPort = &pExynosComponent->pExynosPort[INPUT_PORT_INDEX];
pExynosPort->portDefinition.format.video.nFrameWidth = DEFAULT_FRAME_WIDTH;
pExynosPort->portDefinition.format.video.nFrameHeight= DEFAULT_FRAME_HEIGHT;
/* Output port */
pExynosPort = &pExynosComponent->pExynosPort[OUTPUT_PORT_INDEX];
pExynosPort->portDefinition.format.video.nFrameWidth = DEFAULT_FRAME_WIDTH;
pExynosPort->portDefinition.format.video.nFrameHeight= DEFAULT_FRAME_HEIGHT;
2.
返回到OMXCodec::allocateBuffersOnPort,通过mOMX->getParameter函数调用得到了一个OMX_PARAM_PORTDEFINITIONTYPE结构后,计算totalSize:
size_t totalSize = def.nBufferCountActual * def.nBufferSize;
def.nBufferCountActual在allocateNode函数调用中被初始化为0. 这个变量表示buffer的数量,现在暂时还不知道这个变量是怎么设置的。
def.nBufferSize的值是DEFAULT_VIDEO_INPUT_BU