Ejemplo n.º 1
0
/** Create a thread given the thread function, a data parameter to pass 
 *  to the thread, and the thread priority (higher values=higher priority).
 *  The thread is created and executed immediately calling the thread 
 *  function with the supplied data parameter. */
OMX_ERRORTYPE OMX_OSAL_ThreadCreate( OMX_IN OMX_U32 (*pFunc)(OMX_PTR pParam), 
                                     OMX_IN OMX_PTR pParam, 
                                     OMX_IN OMX_U32 nPriority, 
                                     OMX_OUT OMX_HANDLETYPE *phThread )
{
    OMX_CONF_THREADDATATYPE *pThreadData;

    pThreadData = (OMX_CONF_THREADDATATYPE*)OMX_OSAL_Malloc(sizeof(OMX_CONF_THREADDATATYPE));
    pThreadData->pFunc = pFunc;
    pThreadData->pParam = pParam;
    
    pThreadData->hActualThread = CreateThread(NULL, 0, ThreadProc, pThreadData, 0, 0);
    if (pThreadData->hActualThread == NULL) {
        *phThread = NULL;
        OMX_OSAL_Free(pThreadData);
        return OMX_ErrorInsufficientResources;
    }

    if (nPriority) {
        SetThreadPriority(*phThread, nPriority);
    }

    *phThread = (OMX_HANDLETYPE)pThreadData;

    return OMX_ErrorNone;       
}
    OMX_ERRORTYPE ResourceExhaustionTest_AllocateAllBuffers(ResourceExhaustionTestContext *pCtxt)
    {
        OMX_ERRORTYPE eError = OMX_ErrorNone;
        OMX_PARAM_PORTDEFINITIONTYPE sPortDef;
        OMX_U32 i, j, k;
        OMX_BUFFERHEADERTYPE *pBufferHdr = NULL;
        BufferList *pBufferListObj;
        BufferList *pTemp;

        /* for all ports */
        for (j = 0; j < NUM_DOMAINS; j++)
        {
            for (i = pCtxt->sPortParam[j].nStartPortNumber;
                    i < pCtxt->sPortParam[j].nStartPortNumber +
                    pCtxt->sPortParam[j].nPorts; i++)
            {

                OMX_CONF_INIT_STRUCT(sPortDef, OMX_PARAM_PORTDEFINITIONTYPE);
                sPortDef.nPortIndex = i;
                OMX_CONF_BAIL_IF_ERROR(OMX_GetParameter(pCtxt->hWComp[pCtxt->nInst],
                                                        OMX_IndexParamPortDefinition,
                                                        (OMX_PTR)&sPortDef));
                if (sPortDef.nBufferCountActual == 0x0 ||
                        sPortDef.nBufferCountActual < sPortDef.nBufferCountMin)
                    OMX_CONF_SET_ERROR_BAIL("Incorrect nBufferCountActual\n", OMX_ErrorUndefined);

                for (k = 0x0; k < sPortDef.nBufferCountActual; k++)
                {
                    pBufferListObj = (BufferList *)OMX_OSAL_Malloc(sizeof(BufferList));
                    if (!pBufferListObj)
                    {
                        OMX_CONF_SET_ERROR_BAIL("Malloc internal list failed\n", OMX_ErrorInsufficientResources);
                    }
                    OMX_CONF_BAIL_IF_ERROR(OMX_AllocateBuffer(pCtxt->hWComp[pCtxt->nInst], &pBufferHdr,
                                           sPortDef.nPortIndex, 0, sPortDef.nBufferSize));
                    pBufferListObj->pNextBuf = NULL;
                    pBufferListObj->pBufHdr = pBufferHdr;

                    if (sPortDef.eDir == OMX_DirInput)
                        pBufferListObj->pBufHdr->nOutputPortIndex = OMX_NOPORT;
                    else
                        pBufferListObj->pBufHdr->nInputPortIndex = OMX_NOPORT;

                    if (pCtxt->pBufferList[pCtxt->nInst] == NULL)
                        pCtxt->pBufferList[pCtxt->nInst] = pBufferListObj;
                    else
                    {
                        pTemp = pCtxt->pBufferList[pCtxt->nInst];
                        while (pTemp->pNextBuf)
                        {
                            pTemp = pTemp->pNextBuf;
                        }
                        pTemp->pNextBuf = pBufferListObj;
                    }
                }
            }
        }
OMX_CONF_TEST_BAIL:
        return eError;
    }
    OMX_ERRORTYPE BufferTest_AllocatePortStructures(
        TEST_CTXTYPE *pCtx)
    {
        OMX_ERRORTYPE eError = OMX_ErrorNone;
        TEST_PORTTYPE *pPort;
        OMX_U32 nSize;
        OMX_U32 i, j;
        OMX_U32 nPortIndex;

        /* allocate port structures */
        nSize = (sizeof(TEST_PORTTYPE) * pCtx->nNumPorts);
        pCtx->aPorts = (TEST_PORTTYPE*)OMX_OSAL_Malloc(nSize);
        if (0x0 == pCtx->aPorts)
        {
            OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUndefined, "OMX_OSAL_Malloc failed\n");
        }

        memset(pCtx->aPorts, 0x0, nSize);

        pPort = pCtx->aPorts;
        /* initialize port structures */
        for (i = 0; i < NUM_DOMAINS; i++)
        {
            for (j = 0x0; j < pCtx->sPortParam[i].nPorts; j++)
            {
                nPortIndex = pCtx->sPortParam[i].nStartPortNumber + j;
                OMX_CONF_INIT_STRUCT(pPort->sPortDef, OMX_PARAM_PORTDEFINITIONTYPE);
                pPort->sPortDef.nPortIndex = nPortIndex;
                eError = OMX_GetParameter(pCtx->hWrappedComp, OMX_IndexParamPortDefinition, (OMX_PTR) & pPort->sPortDef);
                OMX_CONF_BAIL_ON_ERROR(eError);

                if (0x0 == pPort->sPortDef.nBufferCountMin)
                {
                    /* a buffer count of 0x0 is not allowed */
                    OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUndefined,
                                            "PortDefinition nBufferCountMin incorrect\n");
                }

                if (pPort->sPortDef.nBufferCountMin > pPort->sPortDef.nBufferCountActual)
                {
                    /* a buffer count of 0x0 is not allowed */
                    OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUndefined,
                                            "PortDefinition nBufferCountActual incorrect\n");
                }

                /* set the actual buffer count to min + 1 */
                pPort->sPortDef.nBufferCountActual = pPort->sPortDef.nBufferCountMin + 1;

                /* set actual buffer count on the port */
                eError = OMX_SetParameter(pCtx->hWrappedComp, OMX_IndexParamPortDefinition, (OMX_PTR) & pPort->sPortDef);
                OMX_CONF_BAIL_ON_ERROR(eError);

                /* allocate LIFO with one more entry that the required minimum
                   as the test will allocate 1 more than needed to exercise
                   allocating buffers during the IDLE state */
                LIFO_ALLOC(pPort->pLifo, (pPort->sPortDef.nBufferCountActual));
                if (0x0 == pPort->pLifo)
                {
                    OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUndefined,
                                            "memory allocation failure\n");
                }

                pPort++;
            }

        }


OMX_CONF_TEST_BAIL:

        return(eError);
    }
    OMX_ERRORTYPE PortCommTest_AllocateBuffers(PortCommTestCtxt *pContext,
            OMX_PARAM_PORTDEFINITIONTYPE *pPortDef)
    {
        OMX_BUFFERHEADERTYPE *pBufferHdr = NULL;
        OMX_U8 *pBuffer = NULL;
        BufferList *pBufferList;
        BufferList *pTemp;
        OMX_ERRORTYPE eError = OMX_ErrorNone;
        OMX_U32 i;

        OMX_OSAL_Trace(OMX_OSAL_TRACE_INFO, "Allocate buffers for port %d\n", pPortDef->nPortIndex);
        for (i = 0x0; i < pPortDef->nBufferCountActual; i++)
        {
            pBufferList = (BufferList *)OMX_OSAL_Malloc(sizeof(BufferList));
            if (!pBufferList)
                OMX_CONF_SET_ERROR_BAIL("malloc failed\n", OMX_ErrorInsufficientResources);

            if (pContext->bClientAllocBuf)
            {
                pBuffer = (OMX_U8*)OMX_OSAL_Malloc(pPortDef->nBufferSize);
                if (!pBuffer)
                    OMX_CONF_SET_ERROR_BAIL("malloc failed\n", OMX_ErrorInsufficientResources);
                OMX_CONF_BAIL_IF_ERROR(OMX_UseBuffer(pContext->hWComp, &pBufferHdr, pPortDef->nPortIndex,
                                                     0, pPortDef->nBufferSize, pBuffer));
            }
            else
            {
                OMX_CONF_BAIL_IF_ERROR(OMX_AllocateBuffer(pContext->hWComp, &pBufferHdr, pPortDef->nPortIndex,
                                       0, pPortDef->nBufferSize));
            }
            pBufferList->pNextBuf = NULL;
            pBufferList->pBufHdr = pBufferHdr;
            pBufferList->pOrigBufHdr = pBufferHdr;

            if (pPortDef->eDir == OMX_DirInput)
            {
                /* check if buffer header is as expected */
                if (pBufferHdr->nAllocLen != pPortDef->nBufferSize || !pBufferHdr->pBuffer ||
                        pBufferHdr->nInputPortIndex != pPortDef->nPortIndex)
                    OMX_CONF_SET_ERROR_BAIL("Buffer header incorrect\n", OMX_ErrorUndefined);

                pBufferHdr->nOutputPortIndex = OMX_NOPORT;

                /* put it in internal list */
                if (pContext->pInBufferList == NULL)
                    pContext->pInBufferList = pBufferList;
                else
                {
                    pTemp = pContext->pInBufferList;
                    while (pTemp->pNextBuf)
                        pTemp = pTemp->pNextBuf;
                    pTemp->pNextBuf = pBufferList;
                }
                pContext->nInBuf++;
            }
            else
            {
                /* check if buffer header is as expected */
                if (pBufferHdr->nAllocLen != pPortDef->nBufferSize || !pBufferHdr->pBuffer ||
                        pBufferHdr->nOutputPortIndex != pPortDef->nPortIndex)
                    OMX_CONF_SET_ERROR_BAIL("Buffer header incorrect\n", OMX_ErrorUndefined);

                pBufferHdr->nInputPortIndex = OMX_NOPORT;

                /* put it in internal list */
                if (pContext->pOutBufferList  == NULL)
                    pContext->pOutBufferList = pBufferList;
                else
                {
                    pTemp = pContext->pOutBufferList;
                    while (pTemp->pNextBuf)
                        pTemp = pTemp->pNextBuf;
                    pTemp->pNextBuf = pBufferList;
                }
                pContext->nOutBuf++;
            }
        }

OMX_CONF_TEST_BAIL:
        return eError;
    }