Ejemplo n.º 1
0
Int32 SWOSD_open(SWOSD_Obj * pObj, SWOSD_OpenPrm *openPrm)
{
    Int32 status = SWOSD_SOK;
    Int32 scratchId = g_scratchIndex;

    SWOSD_Params prm;
	
    IALG_Fxns * algFxns = (IALG_Fxns *)&SWOSD_TI_IALG;
    IRES_Fxns * resFxns = &SWOSD_TI_IRES;

    if(openPrm==NULL || pObj==NULL)
        return SWOSD_EFAIL;

    if(   openPrm->maxWidth==0
         || openPrm->maxHeight==0
        || openPrm->maxWidth  > SWOSD_MAX_WIDTH
        || openPrm->maxHeight > 1080
        ) {
        return NULL;
    }

    memset(pObj, 0, sizeof(SWOSD_Obj));

    memcpy(&pObj->openPrm, openPrm, sizeof(SWOSD_OpenPrm));

    memset(&prm, 0, sizeof(prm));
    prm.size = sizeof(prm);
    prm.maxHeight = pObj->openPrm.maxHeight;
    prm.maxWidth  = pObj->openPrm.maxWidth;

    pObj->algHndl = DSKT2_createAlg((Int)scratchId,
            (IALG_Fxns *)algFxns, NULL,(IALG_Params *)&prm);

    if(pObj->algHndl==NULL)
    {
        status = SWOSD_EFAIL;
        return status;
    }

    /* Assign resources to the algorithm */
    status = RMAN_assignResources((IALG_Handle)pObj->algHndl, resFxns, scratchId);
    if (status != IRES_OK) {
        status = SWOSD_EFAIL;
        return status;
    }

	
    return status;
}
Ejemplo n.º 2
0
/*
 *  ======== Algorithm_create ========
 */
Algorithm_Handle Algorithm_create(IALG_Fxns *fxns, Void *idma3FxnsVoid,
        Void *iresFxnsVoid, IALG_Params *params, Algorithm_Attrs *attrs)
{
    Algorithm_Obj *pObject = NULL;
    IDMA3_Fxns *idma3Fxns = (IDMA3_Fxns *)idma3FxnsVoid;
    IRES_Fxns  *iresFxns = (IRES_Fxns *)iresFxnsVoid;
    IRES_Status iresStatus;

    Log_print5(Diags_ENTRY, "[+E] Algorithm_create> Enter("
            "fxns=0x%x, idma3Fxns=0x%x, iresFxns=0x%x, params=0x%x, "
            "attrs=0x%x)",
            (IArg)fxns, (IArg)idma3Fxns, (IArg)iresFxns, (IArg)params,
            (IArg)attrs);

    assert(attrs != NULL);

    pObject = Memory_alloc(sizeof(Algorithm_Obj), NULL);
    if (pObject == NULL) {
        Log_print0(Diags_USER7, "[+7] Algorithm_create> "
                "Alloc for a small object FAILED -- out of memory?");
        goto Algorithm_create_return;
    }

    /*
     * Note that we don't have to validate groupId as that's done at
     * config time.
     */
    pObject->idma3Fxns = NULL;
    pObject->iresFxns = NULL;
    pObject->groupId = attrs->groupId;

    /* Call appropriate DSKT2 function, depending on attrs->useExtHeap */
    if (attrs->useExtHeap == FALSE) {
        /*
         *  Create alg normally, attempting to allocate algorithm memory
         *  in the requested memory spaces.
         */
        pObject->alg = DSKT2_createAlg(attrs->groupId, fxns, NULL, params);
    }
    else {
        /*
         *  Create alg with all algorithm memory allocated in external memory.
         */
        pObject->alg = DSKT2_createAlgExt(attrs->groupId, fxns, NULL, params);
    }

    if (pObject->alg == NULL) {
        Log_print0(Diags_USER7, "[+7] Algorithm_create> "
                "Algorithm creation FAILED; make sure that 1) alg params are "
                "correct/appropriate, 2) there is enough internal and external "
                "algorithm memory available -- check DSKT2 settings for heap "
                "assignments and scratch allocation");
        Algorithm_delete(pObject);
        pObject = NULL;
        goto Algorithm_create_return;
    }

    /* If alg implements IRES, allocate resources */
    if (iresFxns != NULL) {
        iresStatus = RMAN_assignResources(pObject->alg, iresFxns,
                pObject->groupId);

        if (iresStatus != IRES_OK) {
            Log_print1(Diags_USER7, "[+7] Algorithm_create> Assignment of "
                    "alg resources through RMAN FAILED (0x%x)",
                    (IArg)iresStatus);

            Algorithm_delete(pObject);
            pObject = NULL;
            goto Algorithm_create_return;
        }
        pObject->iresFxns = iresFxns;
    }

Algorithm_create_return:

    Log_print1(Diags_EXIT, "[+X] Algorithm_create> return (0x%x)",
            (IArg)pObject);

    return (pObject);
}
Ejemplo n.º 3
0
/*
 *  ======== rmanTask ========
 */
Void rmanTask(UArg arg0, UArg arg1)
{
    Int            taskId = (Int)arg0;
    Int            index = (Int)arg1;  /* index into attrsTable */
    IALG_Fxns    * algFxns = (IALG_Fxns *)&DUMALG_TI_IDUMALG;
    IRES_Fxns    * resFxns = &DUMALG_TI_IRES;
    IDUMALG_Handle dumHandle = NULL;
    IDUMALG_Params params;
    Int            scratchId = attrsTable[index].scratchId;
    Int            yieldFlag = attrsTable[index].yieldFlag;
    Int            priority = attrsTable[index].priority;
    Arg            resourceId = (Arg)(&(attrsTable[index].id));
    Int            i;
    IRES_Status    status;

    Log_print0(Diags_ENTRY, "[+E] rmanTask> Enter ");

    params.size = sizeof(IDUMALG_Params);

    Log_print4(Diags_USER4, "[+4] rmanTask> "
            "Task #%d: ScratchId %d, Priority %d Yield %d",
            (IArg)taskId, (IArg)scratchId, (IArg)priority, (IArg)yieldFlag);

    params.yieldFlag  = yieldFlag;
    params.taskId = taskId;

    for (i = 0; i < NUM_RESOURCES; i++) {
        params.hdvicp[i] = *((IRES_HDVICP_RequestType *)resourceId + i);
        Log_print1(Diags_USER4, "[+4] rmanTask> "
                "Requesting resource %d (2 => ANY)",
                (IArg)((Int)params.hdvicp[i]));
    }

    /*
     * Create an instance of the algorithm using "algFxns"
     */
    SemThread_pend(mutex, SemThread_FOREVER, NULL);
    dumHandle = (IDUMALG_Handle)DSKT2_createAlg((Int)scratchId,
            (IALG_Fxns *)algFxns, NULL,(IALG_Params *)&params);

    if (dumHandle == NULL) {
        Log_print0(Diags_USER7, "[+7] rmanTask> Alg creation failed");
        System_abort("DSKT2_createAlg() failed, aborting...\n");
    }

    SemThread_post(mutex, NULL);

    /* Assign resources to the algorithm */
    status = RMAN_assignResources((IALG_Handle)dumHandle, resFxns, scratchId);
    if (status != IRES_OK) {
        Log_print1(Diags_USER7, "[+7] rmanTask> Assign resource failed [%d]",
                (IArg)status);
        System_abort("RMAN_assignResources() failed, aborting...\n");
    }


    /* Activate the Algorithm */
    DSKT2_activateAlg(scratchId, (IALG_Handle)dumHandle);

    /* Activate All Resources */
    RMAN_activateAllResources((IALG_Handle)dumHandle, resFxns, scratchId);

    /* Use IALG interfaces to do something */
    dumHandle->fxns->useHDVICP(dumHandle, taskId);

    /* Deactivate All Resources */
    RMAN_deactivateAllResources((IALG_Handle)dumHandle, resFxns, scratchId);

    /* Deactivate algorithm */
    DSKT2_deactivateAlg(scratchId, (IALG_Handle)dumHandle);

    /* Free resources assigned to this algorihtm */
    status = RMAN_freeResources((IALG_Handle)(dumHandle), resFxns, scratchId);
    if (status != IRES_OK) {
        Log_print1(Diags_USER7, "[+7] rmanTask> Free resource failed [%d]",
                (IArg)status);
        System_abort("RMAN_freeResources() failed, aborting...\n");
    }

    /*
     * Free instance of the algorithm created
     */
    SemThread_pend(mutex, SemThread_FOREVER, NULL);
    DSKT2_freeAlg(scratchId, (IALG_Handle)dumHandle);
    SemThread_post(mutex, NULL);

    SemThread_post(done, NULL);

    Log_print0(Diags_EXIT, "[+X] rmanTask> Exit ");
}
Ejemplo n.º 4
0
/* ARGSUSED - this line tells the compiler to not generate compiler warnings
 * for unused arguments */
Int smain(Int argc, Char * argv[])
{
    IRES_Status status;
    Int size = 0;
    Int scratchId = 2;
    IALG_Fxns * algFxns = (IALG_Fxns *)&TEMPLATE_TI_CODECIRES;
    IRES_Fxns * resFxns = &TEMPLATE_TI_IRES;
    IALG_Handle dumHandle = NULL;
    ITEMPLATE_Status algStatus;

    /*
     * Create an instance of the algorithm using "algFxns"
     */
    dumHandle = DSKT2_createAlg(scratchId, (IALG_Fxns *)algFxns, NULL,
            (IALG_Params *)NULL);

    if (dumHandle == NULL) {
        printf("Alg creation failed \n");
        return -1;
    }

    /*
     * Supply initialization information for the RESMAN while registering
     */
    size = sizeof(IRESMAN_Params);

    configParams.allocFxn = RMAN_PARAMS.allocFxn;
    configParams.freeFxn = RMAN_PARAMS.freeFxn;
    configParams.size = size;

    /*
     *  Register the NULL protocol/resource manager with the generic resource
     *  manager
     */
    status = RMAN_register(&IRESMAN_NULLRES, (IRESMAN_Params *)&configParams);

    if (IRES_EEXISTS == status) {
        printf("Protocol Already Registered\n");
    }

    /* Create an instance of an algorithm that implements IALG and IRES_Fxns */
    if (IRES_OK != RMAN_assignResources((IALG_Handle)dumHandle,
                resFxns,scratchId)) {
        printf("Assign Resource Failed \n");
        return (-1);
    }

    /* Activate the Algorithm */
    DSKT2_activateAlg(scratchId, (IALG_Handle)dumHandle);

    /* Activate All Resources */
    RMAN_activateAllResources((IALG_Handle)dumHandle, resFxns, -1);

    /* Use IALG interfaces to do something */
    ((ITEMPLATE_Handle)dumHandle)->fxns->process((ITEMPLATE_Handle)dumHandle,
            (ITEMPLATE_InArgs *)NULL, (ITEMPLATE_OutArgs *)NULL);

    ((ITEMPLATE_Handle)dumHandle)->fxns->control((ITEMPLATE_Handle)dumHandle,
            (ITEMPLATE_Cmd )0, (ITEMPLATE_DynamicParams *)NULL, &algStatus);

    /* Deactivate All Resources */
    RMAN_deactivateAllResources((IALG_Handle)dumHandle, resFxns, -1);

    /* Deactivate algorithm */
    DSKT2_deactivateAlg(scratchId, (IALG_Handle)dumHandle);

    /* Free resources assigned to this algorihtm */
    if (IRES_OK != RMAN_freeResources((IALG_Handle)(dumHandle),
                resFxns, -1)) {
        printf("Free Resource Failed\n");
        return (-1);
    }

    /* Free instance of the algorithm created */
    DSKT2_freeAlg(scratchId, (IALG_Handle)dumHandle);

    /* Unregister the protocol */
    if (IRES_OK != RMAN_unregister(&IRESMAN_NULLRES)) {
        printf("Unregister Protocol Failed\n");
        return (-1);
    }

    RMAN_exit();

    return (0);
}
Ejemplo n.º 5
0
Int rmanTask(Arg scratchId, Arg resourceId,  Arg priority, Arg taskId, 
        Arg yieldFlag)
{

    Int i;
    IALG_Fxns * algFxns = &DUMALG_TI_IALG;
    IRES_Fxns * resFxns = &DUMALG_TI_IRES;
    IDUMALG_Handle dumHandle = NULL; 
    IDUMALG_Params params;

    GT_0trace(ti_sdo_fc_rman_examples_hdvicp, GT_ENTER, "_rmanTask> Enter \n");

    params.size = sizeof(IDUMALG_Params);

    GT_4trace(ti_sdo_fc_rman_examples_hdvicp, GT_4CLASS, "_rmanTask> "
            "Task #%d: ScratchId %d, Priority %d Yield %d\n",taskId, scratchId,
            priority, yieldFlag);

    params.yieldFlag  = yieldFlag;
    params.taskId = taskId; 

    for (i = 0; i < NUM_RESOURCES; i++) {
        params.hdvicp[i] = *((IRES_HDVICP_RequestType *)resourceId + i);
        GT_1trace(ti_sdo_fc_rman_examples_hdvicp, GT_4CLASS, "_rmanTask> "
        "Requesting resource %d (2 => ANY)\n",(Int)params.hdvicp[i]);
    }
    /*
     * Create an instance of the algorithm using "algFxns" 
     */
    SEM_pend(mutex, SYS_FOREVER);
    dumHandle = (IDUMALG_Handle)DSKT2_createAlg((Int)scratchId, 
            (IALG_Fxns *)algFxns, NULL,(IALG_Params *)&params);
    if (dumHandle == NULL) {
        GT_0trace(ti_sdo_fc_rman_examples_hdvicp, GT_7CLASS, "_rmanTask> "
                "Alg creation failed\n");
        return -1;
    } 
    SEM_post(mutex);
    /* Assign resources to the algorithm */
    if (IRES_OK != RMAN_assignResources((IALG_Handle)dumHandle,
                resFxns, scratchId)) {
        GT_0trace(ti_sdo_fc_rman_examples_hdvicp, GT_7CLASS, "_rmanTask> "
                "Assign resource failed\n");
        return -1;
    }


    /*
     * Activate the Algorithm
     */
    DSKT2_activateAlg(scratchId, (IALG_Handle)dumHandle);

    /*
     * Activate All Resources
     */
    RMAN_activateAllResources((IALG_Handle)dumHandle, resFxns, scratchId);

    /*
     * Use IALG interfaces to do something 
     */
        dumHandle->fxns->useHDVICP(dumHandle, taskId);
    
    /*
     * Deactivate All Resources
     */
    RMAN_deactivateAllResources((IALG_Handle)dumHandle, resFxns, scratchId);

    /*
     * Deactivate algorithm 
     */
    DSKT2_deactivateAlg(scratchId, (IALG_Handle)dumHandle);

    /*
     * Free resources assigned to this algorihtm
     */
    if (IRES_OK != RMAN_freeResources((IALG_Handle)(dumHandle),
                resFxns, scratchId)) {
        GT_0trace(ti_sdo_fc_rman_examples_hdvicp, GT_7CLASS, "_rmanTask> "
                "Free resource failed\n");
        return -1;
    }

    /*
     * Free instance of the algorithm created
     */
    SEM_pend(mutex, SYS_FOREVER);
    DSKT2_freeAlg(scratchId, (IALG_Handle)dumHandle);
    SEM_post(mutex);

    SEM_post(done);

    GT_0trace(ti_sdo_fc_rman_examples_hdvicp, GT_ENTER, "_rmanTask> Exit \n");

    return 0;
}
Ejemplo n.º 6
0
Int32 AlgLink_ScdalgCreate(AlgLink_ScdObj * pObj)
{
    Int32               status, chId, scdChId;
    SCD_createPrm       algCreatePrm;
    SCD_chPrm           chDefaultParams[16];
    AlgLink_ScdChParams *pChLinkPrm;
    AlgLink_ScdchPrm    *pScdChPrm;
    IALG_Fxns           *algFxns = (IALG_Fxns *)&SCD_TI;
  //  IRES_Fxns *resFxns = &SCD_TI_IRES;

#ifdef SYSTEM_DEBUG_SCD
    Vps_printf(" %d: SCD    : Create in progress !!!\n",
               Utils_getCurTimeInMsec());
#endif

    pObj->totalFrameCount = 0;

    if(pObj->createArgs.numBufPerCh == 0)
        pObj->createArgs.numBufPerCh = ALG_LINK_SCD_MAX_OUT_FRAMES_PER_CH;

    if(pObj->createArgs.numBufPerCh > ALG_LINK_SCD_MAX_OUT_FRAMES_PER_CH)
    {
        Vps_printf("\n SCDLINK: WARNING: User is asking for %d buffers per CH. But max allowed is %d. \n"
            " Over riding user requested with max allowed \n\n",
            pObj->createArgs.numBufPerCh, ALG_LINK_SCD_MAX_OUT_FRAMES_PER_CH
            );

        pObj->createArgs.numBufPerCh = ALG_LINK_SCD_MAX_OUT_FRAMES_PER_CH;

    }


  
#ifdef SYSTEM_DEBUG_SCD
    Vps_printf(" %d: SCD    : Max WxH = %d x %d, Max CH = %d, FPS = %d !!!\n",
           Utils_getCurTimeInMsec(),
            pObj->createArgs.maxWidth,
            pObj->createArgs.maxHeight,
            //pObj->createArgs.startChNoForSCD,
            pObj->createArgs.numValidChForSCD,
            pObj->createArgs.outputFrameRate
        );
#endif

    if((/*pObj->createArgs.startChNoForSCD + */ pObj->createArgs.numValidChForSCD) > pObj->inQueInfo->numCh)
    {
#ifdef SYSTEM_DEBUG_SCD
        Vps_printf(" %d: SCD    : Create ERROR - SCD channels < InQueue Channels !!!\n",
               Utils_getCurTimeInMsec());
#endif

        return FVID2_EFAIL;
    }

    algCreatePrm.maxWidth    = pObj->createArgs.maxWidth;
    algCreatePrm.maxHeight   = pObj->createArgs.maxHeight;
    algCreatePrm.maxStride   = pObj->createArgs.maxStride;
    algCreatePrm.maxChannels = pObj->createArgs.numValidChForSCD;
    algCreatePrm.numSecs2WaitB4Init		= pObj->createArgs.numSecs2WaitB4Init;
    algCreatePrm.numSecs2WaitB4FrmAlert = pObj->createArgs.numSecs2WaitB4FrmAlert;
    algCreatePrm.fps                    = (SCD_Fps) pObj->createArgs.outputFrameRate;
    algCreatePrm.chDefaultParams        = (SCD_chPrm *)&chDefaultParams[0];

    for(chId=0; chId < algCreatePrm.maxChannels; chId++)
    {
        SCD_chPrm			* chl	= &(algCreatePrm.chDefaultParams[chId]);
        AlgLink_ScdChParams	* chPrm = &(pObj->createArgs.chDefaultParams[chId]);

        if ((chPrm->mode == SCD_DETECTMODE_MONITOR_BLOCKS) ||
             (chPrm->mode == SCD_DETECTMODE_MONITOR_BLOCKS_FRAME))
        {
          Vps_printf("Setting block configuration data \n");
          chl->blkConfig = (SCD_blkChngConfig *)chPrm->blkConfig;
    /*
          for (blk=0; blk < chPrm->blkNumBlksInFrame; blk++)
          {
            chl->blkConfig[blk].sensitivity = (SCD_Sensitivity) chPrm->blkConfig[blk].sensitivity;
            chl->blkConfig[blk].monitored	= (UInt32) chPrm->blkConfig[blk].monitored;
          }
    */
        }
        else
        {
          chl->blkConfig = NULL;
        }

        // The remaining parameter values filled in here do not really matter as
        // they will be over-written by calls to SCD_TI_setPrms. We'll fill in 
        // just a few
        chl->chId	= chPrm->chId;
        chl->mode	= (SCD_Mode)chPrm->mode;
        chl->width	= pObj->createArgs.maxWidth;
        chl->height = pObj->createArgs.maxHeight;
        chl->stride = pObj->createArgs.maxStride;
        chl->curFrame = NULL;
        chl->frmSensitivity = (SCD_Sensitivity)chPrm->frmSensitivity;
        chl->frmIgnoreLightsON = chPrm->frmIgnoreLightsON;
        chl->frmIgnoreLightsOFF = chPrm->frmIgnoreLightsOFF;
        chl->frmEdgeThreshold   = chPrm->frmEdgeThreshold;
    }
    
    /* Create algorithm instance and get algo handle  */
    pObj->algHndl = DSKT2_createAlg((Int)gScratchId,
            (IALG_Fxns *)algFxns, NULL,(IALG_Params *)&algCreatePrm);

    if(pObj->algHndl == NULL)
    {
        #ifdef SYSTEM_DEBUG_SCD
        Vps_printf(" %d: SCD    : Create ERROR !!!\n",
               Utils_getCurTimeInMsec());
        #endif

        return FVID2_EFAIL;
    }
#if 0
    /* Assign resources to the algorithm */
    status = RMAN_assignResources((IALG_Handle)pObj->algHndl, resFxns, gScratchId);
    if (status != IRES_OK) {
        return FVID2_EFAIL;
    }
#endif
    for(scdChId = 0;  scdChId<pObj->createArgs.numValidChForSCD; scdChId++)
    {
        pObj->chObj[scdChId].frameSkipCtx.firstTime = TRUE;
        pObj->chObj[scdChId].frameSkipCtx.inputFrameRate  = pObj->createArgs.inputFrameRate;
        pObj->chObj[scdChId].frameSkipCtx.outputFrameRate = pObj->createArgs.outputFrameRate;

        pScdChPrm = &pObj->chParams[scdChId];

        pChLinkPrm = &pObj->createArgs.chDefaultParams[scdChId];

        pScdChPrm->chId = pChLinkPrm->chId;
        pScdChPrm->chBlkConfigUpdate = FALSE;
        

        status = AlgLink_ScdalgSetChScdPrm(pScdChPrm, pChLinkPrm);
        UTILS_assert(status==0);

        pScdChPrm->width  = pObj->inQueInfo->chInfo[pScdChPrm->chId].width +
            pObj->inQueInfo->chInfo[pScdChPrm->chId].startX;
        pScdChPrm->height = pObj->inQueInfo->chInfo[pScdChPrm->chId].height +
            pObj->inQueInfo->chInfo[pScdChPrm->chId].startY;
        pScdChPrm->stride = pObj->inQueInfo->chInfo[pScdChPrm->chId].pitch[0];

#ifdef SYSTEM_DEBUG_SCD
        Vps_printf(" %d: SCD    : %d: %d x %d, In FPS = %d, Out FPS = %d!!!\n",
                   Utils_getCurTimeInMsec(),
                    pScdChPrm->chId,
                    pScdChPrm->width,
                    pScdChPrm->height,
                    pObj->chObj[scdChId].frameSkipCtx.inputFrameRate,
                    pObj->chObj[scdChId].frameSkipCtx.outputFrameRate
            );
#endif

    }
    AlgLink_ScdresetStatistics(pObj);


#ifdef SYSTEM_DEBUG_SCD
    Vps_printf(" %d: SCD    : Create Done !!!\n",
               Utils_getCurTimeInMsec());
#endif

 return FVID2_SOK;
}
/*
 *  ======== smain ========
 */
Int smain(Int argc, Char * argv[])
{
    ISHMALG_Handle     alg;
    ISHMALG_Fxns       fxns = SHMALG_TI_ISHMALG;
    ISHMALG_Params     params = ISHMALG_PARAMS;
    IRES_Fxns          iresFxns = SHMALG_TI_IRES;
    IRES_Status        status;
    Int                scratchId;
    Bool               passed = FALSE;
    Bool               retVal = TRUE;
    Int                fillVal = 1;

    if (argc > 1) {
        fillVal = atoi(argv[1]);
    }
    params.fillVal = fillVal;

    System_printf("shmbuf_test2> Started. buffer fill value: %d\n", fillVal);

    /* Initialize and register resource manager */
    System_printf("Calling RMAN_init()...\n");
    status = RMAN_init();

    if (status != IRES_OK) {
        /* Test failed */
        System_printf("RMAN_init() failed: %s [%d]\n", getError(status),
                status);
        goto done;
    }

    SHMBUF_PARAMS.bufsize = SHMBUFSIZE;
    SHMBUF_PARAMS.isScratch = TRUE;      /* Make the buffer sharable */

    System_printf("Calling RMAN_register()...\n");
    status = RMAN_register(&SHMBUF_MGRFXNS, (IRESMAN_Params *)&SHMBUF_PARAMS);
    if (status != IRES_OK) {
        /* Test failed */
        System_printf("RMAN_register() failed %s [%d]\n", getError(status),
                status);
        goto done;
    }

    scratchId = 1;
    System_printf("Calling DSKT2_createAlg()...\n");
    alg = (ISHMALG_Handle)DSKT2_createAlg(scratchId, (IALG_Fxns *)&fxns,
            NULL, (IALG_Params *)&params);
    if (alg == NULL) {
        System_printf("DSKT2_createAlg() failed\n");
        goto done;
    }

    /* Assign resources to the algorithm */
    System_printf("Calling RMAN_assignResources()...\n");
    status = RMAN_assignResources((IALG_Handle)alg, &iresFxns, scratchId);

    if (status != IRES_OK) {
        System_printf("RMAN_assignResources() failed %s [%d]\n",
                getError(status), status);
        goto done;
    }

    System_printf("Calling DSKT2_activateAlg()...\n");
    DSKT2_activateAlg(scratchId, (IALG_Handle)alg);

    /* Activate All Resources */
    System_printf("Calling RMAN_activateAllResources()...\n");
    status = RMAN_activateAllResources((IALG_Handle)alg, &iresFxns, scratchId);
    if (status != IRES_OK) {
        System_printf("RMAN_activateAllResourceRMAN_unregister(&SHMBUF_MGRFXNS);s() failed %s [%d]\n",
                getError(status), status);
        goto done;
    }

    /* Use the buffer */
    alg->fxns->useBufs(alg);

    /* Hold onto the resource for awhile */
    System_printf("Sleeping...\n");

    sleep(10);

    /* Check contents of the buffer */
    if (!(retVal = alg->fxns->checkBufs(alg))) {
        System_printf("Buffer overwritten by another alg.\n");
    }

    /* Deactivate All Resources */
    System_printf("Calling RMAN_deactivateAllResources()...\n");
    status = RMAN_deactivateAllResources((IALG_Handle)alg, &iresFxns,
            scratchId);
    if (status != IRES_OK) {
        System_printf("RMAN_deactivateAllResources() failed %s [%d]\n",
                getError(status), status);
        goto done;
    }

    /* Deactivate algorithm */
    System_printf("Calling DSKT2_deactivateAlg()...\n");
    DSKT2_deactivateAlg(scratchId, (IALG_Handle)alg);

    /* Free resources assigned to this algorihtm */
    System_printf("Calling RMAN_freeResources()...\n");
    status = RMAN_freeResources((IALG_Handle)(alg), &iresFxns, scratchId);
    if (status != IRES_OK) {
        System_printf("RMAN_freeResources() failed %s [%d]\n",
                getError(status), status);
        goto done;
    }

    /* Free instance of the algorithm created */
    System_printf("Calling DSKT2_freeAlg()...\n");
    DSKT2_freeAlg(scratchId, (IALG_Handle)alg);

    System_printf("Calling RMAN_unregister()...\n");
    status = RMAN_unregister(&SHMBUF_MGRFXNS);
    if (status != IRES_OK) {
        System_printf("RMAN_unregister() failed %s [%d]\n", getError(status),
                status);
        goto done;
    }

    System_printf("Calling RMAN_exit()...\n");
    status = RMAN_exit();
    if (status != IRES_OK) {
        System_printf("RMAN_exit() failed %s [%d]\n", getError(status),
                status);
        goto done;
    }
    else {
        if (retVal) {
            passed = TRUE;
        }
    }

done:

    RMAN_exit();

    if (passed) {
        System_printf("TEST PASSED\n");
    }
    else {
        System_printf("TEST FAILED\n");
    }

    return (0);
}
Ejemplo n.º 8
0
/* ARGSUSED - this line tells the compiler to not generate compiler warnings 
 * for unused arguments */ 
Int smain(Int argc, Char * argv[])
{

    Int scratchId1 = 0;
        Int scratchId2 = 0;
    IALG_Status algStatus;
    IALG_Fxns * algFxns = &DUMRES_TI_IALG;
    IRES_Fxns * resFxns = &DUMRES_TI_IRES;
    DUMRES_TI_Handle algHandle1 = NULL; 
    DUMRES_TI_Handle algHandle2 = NULL; 
    EDMA3_RM_Handle rmHandle = NULL;
    EDMA3_RM_ResDesc resObj;

    MEM_Stat stat;
    Bool retVal;
    Int i = 0;
    /*
     * Create 2 instances of the algorithm using "algFxns" 
     */
    algHandle1 = (DUMRES_TI_Handle)DSKT2_createAlg(scratchId1, 
            (IALG_Fxns *)algFxns, NULL,(IALG_Params *)NULL);
    if (algHandle1 == NULL) {
        printf("Alg creation failed for algHandle1\n");
        return -1;
    } 

    algHandle2 = (DUMRES_TI_Handle)DSKT2_createAlg(scratchId2, 
            (IALG_Fxns *)algFxns, NULL,(IALG_Params *)NULL);
    if (algHandle2 == NULL) {
        printf("Alg creation failed for algHandle2\n");
        return -1;
    } 

    /* Assign resources to the algorithm */
    if (IRES_OK != RMAN_assignResources((IALG_Handle)algHandle1,
                resFxns, scratchId1)) {
        GT_0trace(ti_sdo_fc_rman_examples_scratchEdma3_GTMask, GT_7CLASS,
                "Assign Resource Failed \n");
        goto AppEnd1;
    }

    /*
     * Activate the Algorithm
     */
    DSKT2_activateAlg(scratchId1, (IALG_Handle)algHandle1);

    /*
     * Activate All Resources
     */
    RMAN_activateAllResources((IALG_Handle)algHandle1, resFxns, scratchId1);

    /*
     * Use IALG interfaces to do something 
     */
    DSKT2_controlAlg((IALG_Handle)algHandle1, (IALG_Cmd)NULL, &algStatus);
    
    /* Assign resources to the second algorithm */
    if (IRES_OK != RMAN_assignResources((IALG_Handle)algHandle2,
                resFxns, scratchId2)) {
        printf("Assign Resource Failed \n");
        return -1;
    }

    /*
     * Deactivate All Resources
     */
    RMAN_deactivateAllResources((IALG_Handle)algHandle1, resFxns, scratchId1);

    /*
     * Deactivate algorithm 
     */
    DSKT2_deactivateAlg(scratchId1, (IALG_Handle)algHandle1);

    /*
     * Activate the Algorithm
     */
    DSKT2_activateAlg(scratchId2, (IALG_Handle)algHandle2);

    /*
     * Activate All Resources
     */
    RMAN_activateAllResources((IALG_Handle)algHandle2, resFxns, scratchId2);

    /*
     * Free resources assigned to this algorihtm
     */
    if (IRES_OK != RMAN_freeResources((IALG_Handle)(algHandle1),
                resFxns, scratchId1)) {
        printf("Free Resource Failed \n");
        return -1;
    }
    
    /* 
     * Acquire the EDMA3 handle first
     */           
    rmHandle = EDMA3_getResourceManager(NULL, -1);
    
    if (NULL == rmHandle) {
        printf("Error obtaining SYSTEM resource Manager Handle \n");
        return (-1);
    }

    resObj.resId = 151; 
    resObj.type = EDMA3_RM_RES_PARAM_SET;
    

    if (EDMA3_RM_SOK != EDMA3_RM_allocResource(rmHandle, &resObj)) {
        printf("Could not allocate this resource, as it is already owned by "
                "the algorithm\n");
    }

    resObj.resId = 256; 
    if (EDMA3_RM_SOK != EDMA3_RM_allocResource(rmHandle, &resObj)) {
        printf("Error, could not allocate resource %d\n"
                "ERROR for 6467, OK for 6446\n", resObj.resId);
    }
    
    if (EDMA3_RM_SOK != EDMA3_releaseResourceManager(NULL, -1)) {
        printf("Error releasing system resource manager handle\n");
    } 

    /*
     * Deactivate All Resources
     */
    RMAN_deactivateAllResources((IALG_Handle)algHandle2, resFxns, scratchId2);

    /*
     * Deactivate algorithm 
     */
    DSKT2_deactivateAlg(scratchId2, (IALG_Handle)algHandle2);

    /*
     * Free resources assigned to this algorihtm
     */
    if (IRES_OK != RMAN_freeResources((IALG_Handle)(algHandle2),
                resFxns, scratchId2)) {
        printf("Free Resource Failed \n");
        return -1;
    }

AppEnd1:
    /*
     * Free instance of the algorithm created
     */
    DSKT2_freeAlg(scratchId1, (IALG_Handle)algHandle1);

    /*
     * Free instance of the algorithm created
     */
    DSKT2_freeAlg(scratchId2, (IALG_Handle)algHandle2);

    /*
     * Unregister the protocol
     */
    if (IRES_OK != RMAN_unregister(&IRESMAN_EDMA3CHAN)) {
            printf("Unregister Protocol Failed \n");
            return -1;
    }
    for (i = 0; i < MAXMEMSEGMENTS; i++) {
        retVal = MEM_stat(i, &stat);
        if (!retVal) {
            GT_assert(ti_sdo_fc_rman_examples_scratchEdma3_GTMask, 
                    memStat[i].size == 0);
        }
        else {
            if (memStat[i].used != stat.used) {
                GT_3trace(ti_sdo_fc_rman_examples_scratchEdma3_GTMask,
                        GT_7CLASS, "MEM seg [%d]: orig used = 0x%x, "
                        "curr used = 0x%x", i, memStat[i].used, 
                        stat.used);
                return (-1);
            }
        }
    }

        RMAN_exit();

    return (0);
}
Ejemplo n.º 9
0
/* ARGSUSED */
Int rmanTask(Int argc, Char * argv[])
{
    Int i;
    IALG_Fxns * algFxns = (IALG_Fxns *)&DUMALG_TI_IDUMALG;
    IRES_Fxns * resFxns = &DUMALG_TI_IRES;
    IDUMALG_Handle dumHandle = NULL;
    IDUMALG_Params params;
    Int taskId = 1;
    Int scratchId = -1;

    GT_0trace(ti_sdo_fc_rman_examples_hdvicp, GT_ENTER, "_rmanTask> Enter\n");

    params.size = sizeof(IDUMALG_Params);

    params.yieldFlag  = FALSE;
    params.taskId = taskId;

    /* Configure the params to indicate the HDVICP requirements of each alg */
    for (i = 0; i < NUM_RESOURCES; i++) {
        params.hdvicp[i] = *((IRES_HDVICP_RequestType *)&attrsTable[0].id[i]);
        GT_1trace(ti_sdo_fc_rman_examples_hdvicp, GT_4CLASS, "_rmanTask> "
        "Requesting resource %d (2 => ANY)\n",(Int)params.hdvicp[i]);
    }

    ALG_init();

    /* Create an instance of the algorithm using "algFxns" */
    dumHandle = (IDUMALG_Handle)ALG_create((IALG_Fxns *)algFxns,
            (IALG_Handle)NULL, (IALG_Params *)&params);
    if (dumHandle == NULL) {
        GT_0trace(ti_sdo_fc_rman_examples_hdvicp, GT_7CLASS, "_rmanTask> "
                "Alg creation failed\n");
        printf("App failed\n");
        return (myIdle(argc, argv));
    }

    /* Assign resources to the algorithm */
    if (IRES_OK != RMAN_assignResources((IALG_Handle)dumHandle,
                resFxns, scratchId)) {
        GT_0trace(ti_sdo_fc_rman_examples_hdvicp, GT_7CLASS, "_rmanTask> "
                "Assign resource failed\n");
        return (myIdle(argc, argv));
    }


    /* Activate the Algorithm */
    ALG_activate((IALG_Handle)dumHandle);

    /* Activate All Resources */
    RMAN_activateAllResources((IALG_Handle)dumHandle, resFxns, scratchId);

    /* Use IALG interfaces to do something */
    dumHandle->fxns->useHDVICP(dumHandle, taskId);

    /* Deactivate All Resources */
    RMAN_deactivateAllResources((IALG_Handle)dumHandle, resFxns, scratchId);

    /* Deactivate the algorithm */
    ALG_deactivate((IALG_Handle)dumHandle);

    /* Free resources assigned to this algorithm */
    if (IRES_OK != RMAN_freeResources((IALG_Handle)(dumHandle),
                resFxns, scratchId)) {
        GT_0trace(ti_sdo_fc_rman_examples_hdvicp, GT_7CLASS, "_rmanTask> "
                "Free resource failed\n");
        return (myIdle(argc, argv));
    }

    /* Free instance of the algorithm created */
    ALG_delete((IALG_Handle)dumHandle);

    GT_0trace(ti_sdo_fc_rman_examples_hdvicp, GT_ENTER, "_rmanTask> Exit\n");

    return (myIdle(argc, argv));
}
Ejemplo n.º 10
0
/*
 *  ======== Algorithm_create ========
 */
Algorithm_Handle Algorithm_create(IALG_Fxns *fxns, Void *idma3FxnsVoid,
        Void *iresFxnsVoid, IALG_Params *params, Algorithm_Attrs *attrs)
{
    Algorithm_Obj *pObject = NULL;
    Int         groupId;
    IDMA3_Fxns *idma3Fxns = (IDMA3_Fxns *)idma3FxnsVoid;
    IRES_Fxns  *iresFxns = (IRES_Fxns *)iresFxnsVoid;
    IRES_Status iresStatus;
    UInt32      useCachedMem;

    Log_print5(Diags_ENTRY, "[+E] Algorithm_create> Enter("
            "fxns=0x%x, idma3Fxns=0x%x, iresFxns=0x%x, params=0x%x, "
            "attrs=0x%x)",
            (IArg)fxns, (IArg)idma3Fxns, (IArg)iresFxns, (IArg)params,
            (IArg)attrs);

    groupId = (attrs != NULL) ? attrs->groupId : -1;
    useCachedMem = (attrs != NULL) ? attrs->useCachedMem :
            Algorithm_USECACHEDMEM_DEFAULT;

    Log_print1(Diags_USER2, "Algorithm_create> useCachedMem = %d",
            (IArg)useCachedMem);

    /* if (attrs == NULL) use default groupId */
    if ((pObject = (Algorithm_Obj *)Memory_alloc(sizeof(Algorithm_Obj),
                 NULL)) == NULL) {
        Log_print0(Diags_USER7, "[+7] Algorithm_create> "
                "Alloc for a small object FAILED -- out of memory?");
        goto Algorithm_create_return;
    }

    pObject->alg = ALG_create(groupId, fxns, NULL, params, useCachedMem);
    pObject->idma3Fxns = NULL;
    pObject->iresFxns = NULL;
    pObject->groupId = groupId;

    if (pObject->alg == NULL) {
        Log_print0(Diags_USER7, "[+7] Algorithm_create> "
                "Algorithm creation FAILED; make sure that 1) alg params are "
                "correct/appropriate, 2) there is enough internal and external "
                "algorithm memory available -- check DSKT2 settings for heap "
                "assignments and scratch allocation");
        Algorithm_delete(pObject);
        pObject = NULL;
        goto Algorithm_create_return;
    }

    /* if the alg implements IDMA3, we need to negotiate DMA resources */
    if (idma3Fxns != NULL) {
        Int status;
        status = DMAN3_grantDmaChannels(pObject->groupId, &pObject->alg,
                &idma3Fxns, 1);

        if (status != DMAN3_SOK) {
            Log_print1(Diags_USER7, "[+7] Algorithm_create> "
                    "Granting DMA channels to algorithm through DMAN3 FAILED"
                    " (0x%x)", (IArg)status);
            Algorithm_delete(pObject);
            pObject = NULL;
            goto Algorithm_create_return;
        }

        pObject->idma3Fxns = idma3Fxns;  /* tell Algorithm_delete to release */
    }

    /* If alg implements IRES, allocate resources */
    if (iresFxns != NULL) {
        iresStatus = RMAN_assignResources(pObject->alg, iresFxns,
                pObject->groupId);

        if (iresStatus != IRES_OK) {
            Log_print1(Diags_USER7, "[+7] Algorithm_create> Assignment of "
                    "alg resources through RMAN FAILED (0x%x)",
                    (IArg)iresStatus);

            /* Free DMAN3 channels, if allocated */
            if (idma3Fxns != NULL) {
                DMAN3_releaseDmaChannels(&(pObject->alg),
                        &(pObject->idma3Fxns), 1);
            }

            Algorithm_delete(pObject);
            pObject = NULL;
            goto Algorithm_create_return;
        }
        pObject->iresFxns = iresFxns;
    }

Algorithm_create_return:

    Log_print1(Diags_EXIT, "[+X] Algorithm_create> return (0x%x)",
            (IArg)pObject);

    return (pObject);
}
Ejemplo n.º 11
0
/* ARGSUSED - this line tells the compiler to not generate compiler warnings
 * for unused arguments */
Int smain(UArg arg0, UArg arg1)
{
    IRES_Status         status;
    Int                 size = 0;
    Int                 scratchId = 2;
    IALG_Status         algStatus;
    IALG_Fxns         * algFxns = &DUMRES_TI_IALG;
    IRES_Fxns         * resFxns = &DUMRES_TI_IRES;
    DUMRES_TI_Handle    dumHandle = NULL;


    status = RMAN_init();
    if (IRES_OK != status) {
        System_abort("RMAN initialization Failed \n");
    }

    /*
     * Create an instance of the algorithm using "algFxns"
     */
    dumHandle = (DUMRES_TI_Handle)DSKT2_createAlg(scratchId,
            (IALG_Fxns *)algFxns, NULL, (IALG_Params *)NULL);
    if (dumHandle == NULL) {
        System_abort("Alg creation failed \n");
    }

    /* Create an instance of an algorithm that implements IALG and IRES_Fxns */
    status = RMAN_assignResources((IALG_Handle)dumHandle, resFxns, scratchId);
    if (status != IRES_OK) {
        System_printf("Assign Resource Failed [%d]\n", status);
        System_abort("Aborting...\n");
    }


    /* Activate the Algorithm */
    DSKT2_activateAlg(scratchId, (IALG_Handle)dumHandle);

    /* Activate All Resources */
    RMAN_activateAllResources((IALG_Handle)dumHandle, resFxns, scratchId);

    /* Use IALG interfaces to do something */
    DSKT2_controlAlg((IALG_Handle)dumHandle, (IALG_Cmd)NULL, &algStatus);

    /* Deactivate All Resources */
    RMAN_deactivateAllResources((IALG_Handle)dumHandle, resFxns, scratchId);

    /* Deactivate algorithm */
    DSKT2_deactivateAlg(scratchId, (IALG_Handle)dumHandle);

    /* Free resources assigned to this algorihtm */
    status = RMAN_freeResources((IALG_Handle)(dumHandle), resFxns, scratchId);
    if (status != IRES_OK) {
        System_printf("Free Resource Failed [%d]\n", status);
        System_abort("Aborting...\n");
    }

    /* Free instance of the algorithm created */
    DSKT2_freeAlg(scratchId, (IALG_Handle)dumHandle);

    RMAN_exit();
        
    return (1);
}
Ejemplo n.º 12
0
/* ARGSUSED - this line tells the compiler to not generate compiler warnings
 * for unused arguments */
Int smain(Int argc, Char * argv[])
{
    IRES_Status     status;
    Int             scratchId = 2;
    IALG_Fxns     * algFxns = (IALG_Fxns *)&DUMRES_TI_IDUMRES;
    IRES_Fxns     * resFxns = &DUMRES_TI_IRES;
    IDUMRES_Handle  dumHandle = NULL;
    IDUMRES_Params  params;
    Int             sleepTime = 0;

    if (argc > 1) {
        sleepTime = atoi(argv[1]);
    }

    if (argc > 2) {
        scratchId = atoi(argv[2]);
    }

    ALG_init();

    /* Create an instance of the algorithm using "algFxns" */
    //params.taskId = taskId;
    params.taskId = 6;
    dumHandle = (IDUMRES_Handle)ALG_create( (IALG_Fxns *)algFxns,
            (IALG_Handle)NULL, (IALG_Params *)&params);
    if (dumHandle == NULL) {
        printf("Alg creation failed \n");
        return (-1);
    }

    /* Create an instance of an algorithm that implements IALG and IRES_Fxns */
    status = RMAN_assignResources((IALG_Handle)dumHandle, resFxns,scratchId);
    if (IRES_OK != status) {
        printf("Assign Resource Failed \n");
        result = FALSE;
    }
    else {
        ALG_activate((IALG_Handle)dumHandle);

        /* Activate All Resources */
        RMAN_activateAllResources((IALG_Handle)dumHandle, resFxns, -1);

        SLEEP(sleepTime);

        /* Deactivate All Resources */
        RMAN_deactivateAllResources((IALG_Handle)dumHandle, resFxns, -1);

        ALG_deactivate((IALG_Handle)dumHandle);

        /* Free resources assigned to this algorihtm */
        status = RMAN_freeResources((IALG_Handle)(dumHandle), resFxns,
                scratchId);
        if (IRES_OK != status) {
            printf("Free Resource Failed \n");
            result = FALSE;
        }
    }

    ALG_delete((IALG_Handle)dumHandle);

    status = RMAN_exit();

    if (status != IRES_OK) {
        result = FALSE;
    }

    if (result) {
        printf("TEST PASSED\n");
    }
    else {
        printf("TEST FAILED.\n");
    }
}
Ejemplo n.º 13
0
/* ARGSUSED - this line tells the compiler to not generate compiler warnings 
 * for unused arguments */ 
Int smain(Int argc, String argv[])
{

    Int scratchId1 = 0;
        Int scratchId2 = 1;
/*      IALG_Status algStatus;*/
    IALG_Fxns * algFxns = &DUMRES_TI_IALG;
    IRES_Fxns * resFxns = &DUMRES_TI_IRES;
    DUMRES_TI_Handle dumHandle1 = NULL; 
    DUMRES_TI_Handle dumHandle2 = NULL; 
    EDMA3_Handle rmHandle = NULL;
    EDMA3_ResDesc resObj;
    Bool status = TRUE; 
    IDUMRES_Params params;

    if (argc > 1) {
        scratchId1 = atoi(argv[1]);
    }
 
    if (argc > 2) {
        scratchId2 = atoi(argv[2]);
    }
    ALG_init();
    /*
     * Create an instance of the algorithm using "algFxns" 
     */
    params.algNum = 1;
    dumHandle1 = (DUMRES_TI_Handle)ALG_create((IALG_Fxns *)algFxns,
            (IALG_Handle)NULL, (IALG_Params *)&params);
    if (dumHandle1 == NULL) {
        printf("Alg1 creation failed \n");
        return -1;
    } 

    params.algNum = 2;
    dumHandle2 = (DUMRES_TI_Handle)ALG_create((IALG_Fxns *)algFxns,
            (IALG_Handle)NULL, (IALG_Params *)&params);
    if (dumHandle2 == NULL) {
        printf("Alg2 creation failed \n");
        return -1;
    } 

    /* Create an instance of an algorithm that implements IALG and IRES_Fxns */
    if (IRES_OK != RMAN_assignResources((IALG_Handle)dumHandle1,
                resFxns,scratchId1)) {
        printf("Assign Resource Failed \n");
        status = FALSE;
        goto AppEnd1;
    }

    /*
     * Activate the Algorithm
     */
    ALG_activate((IALG_Handle)dumHandle1);

    /*
     * Activate All Resources
     */
    RMAN_activateAllResources((IALG_Handle)dumHandle1, resFxns, scratchId1);

    /*
     * Use IALG interfaces to do something 
     */
    //TODO: DSKT2_controlAlg((IALG_Handle)dumHandle, (IALG_Cmd)NULL, &algStatus);
    
    /* Assign resources to the second algorithm */
    if (IRES_OK != RMAN_assignResources((IALG_Handle)dumHandle2,
                resFxns, scratchId2)) {
        printf("Assign Resource Failed \n");
        return -1;
    }
    /*
     * Deactivate All Resources
     */
    RMAN_deactivateAllResources((IALG_Handle)dumHandle1, resFxns, scratchId1);

    /*
     * Deactivate algorithm 
     */
    ALG_deactivate((IALG_Handle)dumHandle1);

    /*
     * Activate the Algorithm
     */
    ALG_activate((IALG_Handle)dumHandle2);

    /*
     * Activate All Resources
     */
    RMAN_activateAllResources((IALG_Handle)dumHandle2, resFxns, scratchId2);

    /*
     * Free resources assigned to this algorihtm
     */
    if (IRES_OK != RMAN_freeResources((IALG_Handle)(dumHandle1),
                resFxns, scratchId1)) {
        printf("Free Resource Failed \n");
        return -1;
    }
    /* 
     * Acquire the EDMA3 handle first
     */           
    rmHandle = EDMA3_getResourceManager((IALG_Handle)NULL, (Int)-1);
    
    if (NULL == rmHandle) {
        printf("Error obtaining SYSTEM resource Manager Handle \n");
        return (-1);
    }

    resObj.resId = 65; 
    resObj.type = EDMA3_RES_PARAM_SET;
    

    if (EDMA3_SOK != EDMA3_allocResource(rmHandle, &resObj)) {
        printf("Note, could not allocate this resource.\n");
    }

    resObj.resId = 126; 
    if (EDMA3_SOK != EDMA3_allocResource(rmHandle, &resObj)) {
        printf("Note, could not allocate resource %d\n", resObj.resId);
    }
    
    if (EDMA3_SOK != EDMA3_releaseResourceManager(NULL, -1)) {
        printf("Note, releasing system resource manager handle\n");
    } 

    /*
     * Deactivate All Resources
     */
    RMAN_deactivateAllResources((IALG_Handle)dumHandle2, resFxns, scratchId2);

    /*
     * Deactivate algorithm 
     */
    ALG_deactivate((IALG_Handle)dumHandle2);

    /*
     * Free resources assigned to this algorihtm
     */
    if (IRES_OK != RMAN_freeResources((IALG_Handle)(dumHandle2),
                resFxns, scratchId2)) {
        printf("Free Resource Failed \n");
        return -1;
    }

AppEnd1:
    /*
     * Free instance of the algorithm created
     */
    ALG_delete((IALG_Handle)dumHandle1);

    /*
     * Free instance of the algorithm created
     */
    ALG_delete((IALG_Handle)dumHandle2);

    RMAN_exit();

    if (status)
        printf("Application exiting normally\n");

    return (0);
}
Ejemplo n.º 14
0
/* Main Function acting as a client for Image Encode Call*/
XDAS_Int32 main(int argc, char *argv[])
{

    /* File I/O variables */
    FILE *fConfigFile, /**ftestFile, *finFile,*/ *fparamsFile;

#ifdef LINUX
    CMEM_AllocParams memParams;
    memParams.type=CMEM_POOL;
    memParams.flags=CMEM_NONCACHED;
    memParams.alignment=256;
#endif

    char* colorf[]={"YUV422P", "YUV420P", "YUV422P", "YUV422IL", "YUV422IL", "YUV444", "YUV411", "GRAY", "RGB", "YUV420_LINE"};
#ifdef LINUX
    XDAS_Int8 *fname = "../TestVecs/Config/Testvecs.cfg";
#else
    XDAS_Int8 *fname = "..\\..\\Test\\TestVecs\\Config\\Testvecs_ccs.cfg";
#endif
    Int32 lTemp,countConfigSet;
    Int32 retVal;
    Uint32 numAU, totalAU,repeat;
    Uint32 bytesGenerated;
    Uint16 mbSizeX, mbSizeY,mbY;

    char *RefBuffPtr;
    FILE *fp_out;
    FILE *fp_in;
    int processTime = 0, processTimeTotal = 0,algActivateTime =0, algDeactivateTime =0,copctime=0;
    int val,queue_word,queue_num=0,i,k;
    char baseParams[STRING_SIZE];
    int baseParamsOnly;
    int Offset;
    int num_markers;
    IIMGENC1_Fxns            *iimgEncfxns;
    IIMGENC1_Status  imgencStatus;
    IIMGENC1_InArgs imgencInArgs;
    IIMGENC1_OutArgs imgencOutArgs;
    IJPEGENC_Status          status;
    IJPEGENC_InArgs          inArgs;
    IJPEGENC_OutArgs         outArgs;
    unsigned int lTemp1;

    /*Algorithm specific handle */
    IALG_Handle handle;

    /* Input/Output Buffer Descriptor variables */
    XDM1_BufDesc inputBufDesc, outputBufDesc;


#ifdef ENABLE_RMAN // IRES/RMAN Related declarations
    // temp_trace_init();
    IRES_Status iresStatus;
    Int size =0;
    Int scratchId =0;
    Bool result = TRUE;
    IRES_Fxns *resFxns = &JPEGENC_TI_IRES;
    IRESMAN_Edma3ChanParams configParams;
    IRESMAN_VicpParams iresmanConfigParams;
    IRESMAN_AddrSpaceParams addrspaceConfigParams;

    iresStatus = RMAN_init();
    if (IRES_OK != iresStatus) {
        printf("RMAN initialization Failed \n");
        return -1;
    }
    printf("RMAN initialization done \n");

#ifndef LINUX
        /* Call the functions to enable ARM926 FIQ and do some basic
         * setup to AINTC to accept KLD INTC (arm968) interupt in 
         * FIQ pin of Arm926  
         */
        ARM926_enable_FIQ();  /* SWI call to enable interrupts */
        ARM926_INTC_init();  /* Init AINTC */
#endif

    /*
     * Supply initialization information for the RESMAN while registering
     */
    size = sizeof(IRESMAN_VicpParams);

    iresmanConfigParams.baseConfig.allocFxn = RMAN_PARAMS.allocFxn;
    iresmanConfigParams.baseConfig.freeFxn = RMAN_PARAMS.freeFxn;
    iresmanConfigParams.baseConfig.size = size;

    /* Register the VICP protocol/resource manager with the
    *      * generic resource manager */

    iresStatus = RMAN_register(&IRESMAN_VICP2, (IRESMAN_Params *)&iresmanConfigParams);

    if (IRES_OK != iresStatus) {
        printf("VICP Protocol Registration Failed \n");
        return -1;
    }
    printf("VICP Protocol Registration Success \n");
    /*
     *      * Supply initialization information for the EDMA3 RESMAN while registering
     *           */
    size = sizeof(IRESMAN_Edma3ChanParams);

    configParams.baseConfig.allocFxn = RMAN_PARAMS.allocFxn;
    configParams.baseConfig.freeFxn = RMAN_PARAMS.freeFxn;
    configParams.baseConfig.size = size;

    iresStatus = RMAN_register(&IRESMAN_EDMA3CHAN, (IRESMAN_Params *)&configParams);

    if (IRES_OK != iresStatus) {
        printf("EDMA3 Protocol Registration Failed \n");
        return -1;
    }
    printf("EDMA3 Protocol Registration Success \n");

    /** Supply initialization information for the ADDRSPACE RESMAN while registering
    	* */
#if 1
    size = sizeof(IRESMAN_AddrSpaceParams);
    addrspaceConfigParams.baseConfig.allocFxn = RMAN_PARAMS.allocFxn;
    addrspaceConfigParams.baseConfig.freeFxn = RMAN_PARAMS.freeFxn;
    addrspaceConfigParams.baseConfig.size = size;

    iresStatus = RMAN_register(&IRESMAN_ADDRSPACE, (IRESMAN_Params *)&addrspaceConfigParams);

    if (IRES_OK != iresStatus) {
        printf("ADDRSPACE Protocol Registration Failed \n");
        return -1;
    }
#ifdef _DBG_MSG
    printf("ADDRSPACE Protocol Registration Success \n");
#endif
#endif


#endif //IRES/RMAN related code ends here  


#ifdef LINUX
    CMEM_init();

    ExternalGlobalMemPool = ExternalGlobalMemPoolBase = CMEM_alloc(EXTERNAL_DATA_MEM_SIZE,&memParams);
#ifdef ENABLE_RING_BUF_USAGE
    ringbuf = CMEM_alloc(RINGBUFSIZE, &memParams);
#endif
    OrgPictureY_0=CMEM_alloc( (LUMABUF_SIZE*2+ORGBUF_OFFSET), &memParams);
    OrgPictureCb_0=CMEM_alloc((CHROMABUF_SIZE+ORGBUF_OFFSET), &memParams);
    OrgPictureCr_0=CMEM_alloc((CHROMABUF_SIZE+ORGBUF_OFFSET), &memParams);
    media=CMEM_alloc((ENCODED_DATA_BUFFER_SIZE), &memParams);

//#ifdef LINUX
    //      DM350MM_init();
//#endif

    if (argc==2)
    {
        strncpy(baseParams,argv[1],256);
        if (!strcmp(baseParams,"-ext"))
        {
            printf("\n----- Running in extended parameter mode -----\n");
            baseParamsOnly=0;

        }
        else
        {
            printf("Argument  -ext needed to run in  extended param mode\n");
            exit(0);
        }
    }

    else
    {
        printf("\n----- Running in base parameter mode -----\n");
        baseParamsOnly=1;
    }


#else
    baseParamsOnly=0;
#endif


    //memset(ringbuf,0xaa,RINGBUFSIZE );
    memset(media, 0xaa, ENCODED_DATA_BUFFER_SIZE);
    memset(ExternalGlobalMemPool, 0xaa,EXTERNAL_DATA_MEM_SIZE );
    memset(OrgPictureY_0, 0xaa, (LUMABUF_SIZE*2+ORGBUF_OFFSET));
    memset(OrgPictureCb_0, 0xaa, (CHROMABUF_SIZE+ORGBUF_OFFSET));
    memset(OrgPictureCr_0, 0xaa, (CHROMABUF_SIZE+ORGBUF_OFFSET));

    OrgPictureY  = &OrgPictureY_0[ORGBUF_OFFSET];
    OrgPictureCb = &OrgPictureCb_0[ORGBUF_OFFSET];
    OrgPictureCr = &OrgPictureCr_0[ORGBUF_OFFSET];


    /* Open Test Config File   */
    fConfigFile = fopen(fname, "r");

    if (!fConfigFile)
    {
        printf("Couldn't open parameter file %s\n", fname);
        return XDM_EFAIL;
    }


    countConfigSet = 1;         /* Reset countConfigSet value to 1 */

    /* Read the Config File until it reaches the end of file                    */
    while (!feof(fConfigFile))
    {
        /* Read Compliance Checking parameter */
        if (fgets(line, 254, fConfigFile))
        {
            sscanf(line, "%d\n", &testCompliance);
            printf("\nTestcompliance = %d\n",testCompliance);
        } else {
            break;
        }
        /* Read Parameters file name */
        if (fgets(line, 254, fConfigFile))
        {
            sscanf(line, "%s", paramsFile);
            printf("\nParam file = %s\n",paramsFile);
        }
        else
        {
            break;
        }
        /* Read Input file name */
        if (fgets(line, 254, fConfigFile))
        {
            sscanf(line, "%s", inFile);
            printf("\nInput file = %s\n",inFile);
        }
        else
        {
            break;
        }

        /* Read Output/Reference file name */
        if (fgets(line, 254, fConfigFile))
        {
            sscanf(line, "%s", testFile);
            printf("\nOutput file = %s\n",testFile);
        }
        else
        {
            break;
        }

        printf("\n*******************************************");
        printf("\nRead Configuration Set %d", countConfigSet);
        printf("\n*******************************************");
        countConfigSet++;



        fp_out=fopen(testFile,"wb");
        fp_in = fopen(inFile,"rb");


        if ((fp_in == NULL) || (fp_out == NULL))
        {
            printf("'Input/out file cannot be opened\n");
            exit(0);
        }

        /** Set initialization parameters
         * Parameters in structure params are default image encode parameters required by XDM
         * Paraemters in extn_params are parameters specific to jpeg encoder,
         *
         */

        /* Open Parameters file */
        fparamsFile = fopen(paramsFile, "rb");
        //fparamsFile = fopen("Testparams.cfg", "rb");
        if (!fparamsFile)
        {
            printf("\nCouldn't open Parameters file...   %s\n ",
                   paramsFile);
            printf("Exiting for this configuration...\n");
            continue;
        }

        printf("\nParameter file read starts...\n");
        if (readparamfile(fparamsFile,baseParamsOnly) < 0)
        {
            printf("\nSyntax Error in %s\n ", paramsFile);
            printf("Exiting for this configuration...\n");
            continue;
        }

        /* Close Parameters File */
        fclose(fparamsFile);
        if (testCompliance)
        {
            printf("\nRunning in Compliance Mode");
        }
        else
        {
            printf("\nRunning in Output Dump Mode");
        }


        /** Call algorithm creation function
          * See file alg_create.
          * memory allocation functions are called inside alg_malloc file.
          * Modify _ALG_allocMemory in alg_malloc.c to suit the application need (static allocation vs dynamic through malloc())
          */

        if (baseParamsOnly==0)
        {
#ifdef ENABLE_RING_BUF_USAGE
            extn_params.halfBufCB =(XDAS_Void (*)(Uint32, XDAS_Void*))JPEGENC_TI_DM350_HalfBufCB;
            extn_params.halfBufCBarg= (void*)&ring2media;

#else
            extn_params.halfBufCB = (XDAS_Void (*))NULL;
#endif


            extn_params.imgencParams = params;
            extn_params.imgencParams.size = sizeof(IJPEGENC_Params);
        }
        else
        {
            params.size = sizeof(IIMGENC1_Params);
            dynamicParams.size =sizeof(IIMGENC1_DynamicParams);
        }
        if (baseParamsOnly==0)
        {
            if ((handle =  (IALG_Handle)ALG_create (
                               (IALG_Fxns *) &JPEGENC_TI_IJPEGENC,
                               (IALG_Handle) NULL,
                               (IALG_Params *)&extn_params)) == NULL)
            {
                printf("\nFailed to Create Instance... Exiting for this configuration..");
                exit(0);
            }

            printf("\nAlgorithm Instance Creation Done...\n");
        }
        else
        {
            if ((handle =  (IALG_Handle)ALG_create (
                               (IALG_Fxns *) &JPEGENC_TI_IJPEGENC,
                               (IALG_Handle) NULL,
                               (IALG_Params *)&params)) == NULL)
            {
                printf("\nFailed to Create Instance... Exiting for this configuration..");
                exit(0);
            }

            printf("\nAlgorithm Instance Creation Done...\n");
        }



#ifdef ENABLE_RMAN // IRES/RMAN Related code

        /* Create an instance of an algorithm that implements IALG and IRES_Fxns */
        iresStatus = RMAN_assignResources((IALG_Handle)handle, resFxns,scratchId);
        if (IRES_OK != iresStatus) {
            printf("Assign Resource Failed \n");
            result = FALSE;
        }

#endif //IRES/RMAN code ends here.

        /** Set up dynamic parameters (can be changed before each call to jpeg processing)
          * Parameters in structure dynamicParams are default image encode parameters required by XDM
          */
        if (baseParamsOnly==0)
        {
            extn_dynamicParams.imgencDynamicParams = dynamicParams;
            extn_dynamicParams.imgencDynamicParams.size  = sizeof(IJPEGENC_DynamicParams);
            extn_dynamicParams.disableEOI = 0;
            iimgEncfxns = (IIMGENC1_Fxns *)handle->fxns ;
            status.imgencStatus.size= sizeof(IJPEGENC_Status);
        }
        else
        {

            dynamicParams.size           = sizeof(IIMGENC1_DynamicParams);
            iimgEncfxns = (IIMGENC1_Fxns *)handle->fxns ;
            imgencStatus.size= sizeof(IIMGENC1_Status);

        }
        /** Request input and output buffer characteristics by calling control() function
         *  with command XDM_GETBUFINFO
         */


        // Call control function to setup dynamic params
        if (baseParamsOnly==0)
        {
            retVal=iimgEncfxns->control((IIMGENC1_Handle)handle,/*IJPEGENC_SETDEFAULT*/XDM_SETPARAMS,
                                        (IIMGENC1_DynamicParams *)&extn_dynamicParams, (IIMGENC1_Status *)&status);

            if (retVal== XDM_EFAIL) {
                printf("\n Error control SetParams  command1\n");
                exit(0);
            }

            retVal= iimgEncfxns->control((IIMGENC1_Handle)handle,
                                         XDM_GETBUFINFO,
                                         (IIMGENC1_DynamicParams *) &extn_dynamicParams,
                                         (IIMGENC1_Status *)&status);
	    if (retVal== XDM_EFAIL) {
		printf("\n Error control Getbuffinfo  command1\n");
		exit(0);
	     }


            inputBufDesc.numBufs = status.imgencStatus.bufInfo.minNumInBufs;
            Offset = 0;

            for (i=0;i<inputBufDesc.numBufs;i++)
            {
                inputBufDesc.descs[i].buf = (XDAS_Int8 *) ( (unsigned int)inputData +
                                            Offset);
                Offset +=  status.imgencStatus.bufInfo.minInBufSize[i];
                inputBufDesc.descs[i].bufSize = status.imgencStatus.bufInfo.minInBufSize[i];
            }

            outputBufDesc.numBufs = status.imgencStatus.bufInfo.minNumOutBufs;
            Offset = 0;

            for (i=0;i<outputBufDesc.numBufs;i++)
            {
                outputBufDesc.descs[i].buf = (XDAS_Int8 *) ( (unsigned int)outputData +
                                             Offset);
                Offset +=  status.imgencStatus.bufInfo.minOutBufSize[i];
                outputBufDesc.descs[i].bufSize = status.imgencStatus.bufInfo.minOutBufSize[i];

            }


            if (retVal== XDM_EFAIL) {
                printf("\n Error control GetInfo command\n");
                exit(0);
            }

        }
        else
        {
            retVal=iimgEncfxns->control((IIMGENC1_Handle)handle, XDM_SETPARAMS,
                                        (IIMGENC1_DynamicParams *)&dynamicParams, (IIMGENC1_Status *)&imgencStatus);

            if (retVal== XDM_EFAIL) {
                printf("\n Error control SetParams  command1\n");
                exit(0);
            }

            retVal= iimgEncfxns->control((IIMGENC1_Handle)handle,
                                         XDM_GETBUFINFO,
                                         (IIMGENC1_DynamicParams *)&dynamicParams,
                                         (IIMGENC1_Status *)&imgencStatus);
             if (retVal== XDM_EFAIL) 
	     {
		 printf("\n Error control GetBuffInfo  command1\n");
	         exit(0);
	      }

            inputBufDesc.numBufs = imgencStatus.bufInfo.minNumInBufs;
            Offset = 0;

            for (i=0;i<inputBufDesc.numBufs;i++)
            {
                inputBufDesc.descs[i].buf = (XDAS_Int8 *) ( (unsigned int)inputData +
                                            Offset);
                Offset +=  imgencStatus.bufInfo.minInBufSize[i];
                inputBufDesc.descs[i].bufSize = imgencStatus.bufInfo.minInBufSize[i];
            }

            outputBufDesc.numBufs = imgencStatus.bufInfo.minNumOutBufs;
            Offset = 0;

            for (i=0;i<outputBufDesc.numBufs;i++)
            {
                outputBufDesc.descs[i].buf = (XDAS_Int8 *) ( (unsigned int)outputData +
                                             Offset);
                Offset +=  imgencStatus.bufInfo.minOutBufSize[i];
                outputBufDesc.descs[i].bufSize = imgencStatus.bufInfo.minOutBufSize[i];
            }

            if (retVal== XDM_EFAIL) {
                printf("\n Error control GetInfo command\n");
                exit(0);
            }




        }
        if (baseParamsOnly==0)
        {
            /** Read input file.
               */
            printf("Number of Input bufs =%d\n",status.imgencStatus.bufInfo.minNumInBufs );
            if (status.imgencStatus.bufInfo.minNumInBufs == 3)
            {
                memset(OrgPictureY,0,(status.imgencStatus.bufInfo.minInBufSize[0]));
                memset(OrgPictureCb,0,(status.imgencStatus.bufInfo.minInBufSize[1]));
                memset(OrgPictureCr,0,(status.imgencStatus.bufInfo.minInBufSize[2]));
                printf("Input file read starts\n" );

                lTemp = fread(OrgPictureY,1,(status.imgencStatus.bufInfo.minInBufSize[0]),fp_in);
                if (dynamicParams.inputWidth < dynamicParams.captureWidth) {
                    fseek(fp_in,(dynamicParams.captureWidth*(params.maxHeight-dynamicParams.inputHeight)),SEEK_CUR);
                }
                printf("number of bytes read from input file = %d \n",lTemp);


                lTemp = fread(OrgPictureCb,1,((status.imgencStatus.bufInfo.minInBufSize[1])),fp_in);
                if (dynamicParams.inputWidth < dynamicParams.captureWidth) {
                    fseek(fp_in,(dynamicParams.captureWidth*(params.maxHeight-dynamicParams.inputHeight)/4),SEEK_CUR);
                }
                printf("number of bytes read from input file = %d \n",lTemp);
                lTemp = fread(OrgPictureCr,1,((status.imgencStatus.bufInfo.minInBufSize[2])),fp_in);
                printf("number of bytes read from input file = %d \n",lTemp);


            }
            else if (status.imgencStatus.bufInfo.minNumInBufs == 1)
            {
                printf("status.imgencStatus.bufInfo.minInBufSize[0]=%d\n",status.imgencStatus.bufInfo.minInBufSize[0]);
                memset(OrgPictureY,0,(status.imgencStatus.bufInfo.minInBufSize[0]));
                lTemp = fread(OrgPictureY,1,(status.imgencStatus.bufInfo.minInBufSize[0]),fp_in);
                printf("number of bytes read from input file = %d \n",lTemp);
            }
            else if (status.imgencStatus.bufInfo.minNumInBufs == 2) /* 420 semi planar*/
            {
                printf("status.imgencStatus.bufInfo.minInBufSize[0]=%d\n",status.imgencStatus.bufInfo.minInBufSize[0]);
                memset(OrgPictureY,0,(status.imgencStatus.bufInfo.minInBufSize[0]));
                printf("status.imgencStatus.bufInfo.minInBufSize[1]=%d\n",status.imgencStatus.bufInfo.minInBufSize[1]);
                memset(OrgPictureCb,'-',(status.imgencStatus.bufInfo.minInBufSize[1]));
                memset(OrgPictureCr,'-',(status.imgencStatus.bufInfo.minInBufSize[1]));

                lTemp = fread(OrgPictureY,1,(status.imgencStatus.bufInfo.minInBufSize[0]),fp_in);
                if (dynamicParams.inputWidth < dynamicParams.captureWidth) {
                    fseek(fp_in,(dynamicParams.captureWidth*(params.maxHeight-dynamicParams.inputHeight)),SEEK_CUR);
                }
                printf("number of bytes read from input file = %d \n",lTemp);

                if (dynamicParams.inputWidth < dynamicParams.captureWidth) {
                    lTemp = fread(OrgPictureCr,1,(status.imgencStatus.bufInfo.minInBufSize[1])/2,fp_in);
                    fseek(fp_in,(dynamicParams.captureWidth*(params.maxHeight-dynamicParams.inputHeight)/4),SEEK_CUR);

                    lTemp += fread((OrgPictureCr+(status.imgencStatus.bufInfo.minInBufSize[1])/2),1,(status.imgencStatus.bufInfo.minInBufSize[1])/2,fp_in);

                }
                else
                {
                    lTemp = fread(OrgPictureCr,1,(status.imgencStatus.bufInfo.minInBufSize[1]),fp_in);
                }

                printf("number of bytes read from input file = %d \n",lTemp);

                /* The input file is 420 planar, the following function converts the 420P to 420 semi planar
                   i.e CbCr will be interleaved. planar chrmoa data is read into OrgPictureCr buffer and
                   converted to interleaved. output is stored in OrgPictureCb buffer*/
                /*convert the 420 planar to 420 semi planar*/
                lTemp = Convert420Pto420Semi(OrgPictureCr,OrgPictureCb,status.imgencStatus.bufInfo.minInBufSize[1]);

            }
            else
            {
                printf("Unsupported number of input buffers \n");
            }
            fclose(fp_in);
        }
        else
        {
            /** Read input file.
               */
            printf("Number of Input bufs =%d\n",imgencStatus.bufInfo.minNumInBufs );
            if (imgencStatus.bufInfo.minNumInBufs == 3)
            {
                memset(OrgPictureY,0,(imgencStatus.bufInfo.minInBufSize[0]));
                memset(OrgPictureCb,0,(imgencStatus.bufInfo.minInBufSize[1]));
                memset(OrgPictureCr,0,(imgencStatus.bufInfo.minInBufSize[2]));
                printf("Input file read starts\n" );

                lTemp = fread(OrgPictureY,1,(imgencStatus.bufInfo.minInBufSize[0]),fp_in);
                if (dynamicParams.inputWidth < dynamicParams.captureWidth) {
                    fseek(fp_in,(dynamicParams.captureWidth*(params.maxHeight-dynamicParams.inputHeight)),SEEK_CUR);
                }
                printf("number of bytes read from input file = %d \n",lTemp);


                lTemp = fread(OrgPictureCb,1,((imgencStatus.bufInfo.minInBufSize[1])),fp_in);
                if (dynamicParams.inputWidth < dynamicParams.captureWidth) {
                    fseek(fp_in,(dynamicParams.captureWidth*(params.maxHeight-dynamicParams.inputHeight)/4),SEEK_CUR);
                }
                printf("number of bytes read from input file = %d \n",lTemp);
                lTemp = fread(OrgPictureCr,1,((imgencStatus.bufInfo.minInBufSize[2])),fp_in);
                printf("number of bytes read from input file = %d \n",lTemp);


            }
            else if (imgencStatus.bufInfo.minNumInBufs == 1)
            {
                printf("imgencStatus.bufInfo.minInBufSize[0]=%d\n",imgencStatus.bufInfo.minInBufSize[0]);
                memset(OrgPictureY,0,(imgencStatus.bufInfo.minInBufSize[0]));
                lTemp = fread(OrgPictureY,1,(imgencStatus.bufInfo.minInBufSize[0]),fp_in);
                printf("number of bytes read from input file = %d \n",lTemp);
            }
            else if (imgencStatus.bufInfo.minNumInBufs == 2) /* 420 semi planar*/
            {
                printf("imgencStatus.bufInfo.minInBufSize[0]=%d\n",imgencStatus.bufInfo.minInBufSize[0]);
                memset(OrgPictureY,0,(imgencStatus.bufInfo.minInBufSize[0]));
                printf("imgencStatus.bufInfo.minInBufSize[1]=%d\n",imgencStatus.bufInfo.minInBufSize[1]);
                memset(OrgPictureCb,'-',(imgencStatus.bufInfo.minInBufSize[1]));
                memset(OrgPictureCr,'-',(imgencStatus.bufInfo.minInBufSize[1]));

                lTemp = fread(OrgPictureY,1,(imgencStatus.bufInfo.minInBufSize[0]),fp_in);
                if (dynamicParams.inputWidth < dynamicParams.captureWidth) {
                    fseek(fp_in,(dynamicParams.captureWidth*(params.maxHeight-dynamicParams.inputHeight)),SEEK_CUR);
                }
                printf("number of bytes read from input file = %d \n",lTemp);

                if (dynamicParams.inputWidth < dynamicParams.captureWidth) {
                    lTemp = fread(OrgPictureCr,1,(imgencStatus.bufInfo.minInBufSize[1])/2,fp_in);
                    fseek(fp_in,(dynamicParams.captureWidth*(params.maxHeight-dynamicParams.inputHeight)/4),SEEK_CUR);

                    lTemp += fread((OrgPictureCr+(imgencStatus.bufInfo.minInBufSize[1])/2),1,(imgencStatus.bufInfo.minInBufSize[1])/2,fp_in);

                }
                else
                {
                    lTemp = fread(OrgPictureCr,1,(imgencStatus.bufInfo.minInBufSize[1]),fp_in);
                }

                printf("number of bytes read from input file = %d \n",lTemp);

                /* The input file is 420 planar, the following function converts the 420P to 420 semi planar
                   i.e CbCr will be interleaved. planar chrmoa data is read into OrgPictureCr buffer and
                   converted to interleaved. output is stored in OrgPictureCb buffer*/
                /*convert the 420 planar to 420 semi planar*/
                lTemp = Convert420Pto420Semi(OrgPictureCr,OrgPictureCb,imgencStatus.bufInfo.minInBufSize[1]);

                //	printf("OrgPictureCb=%x\n",OrgPictureCb);


            }
            else
            {
                printf("Unsupported number of input buffers \n");
            }
            fclose(fp_in);

        }

        /*Fill up the buffers as required by algorithm                            */
        if (baseParamsOnly==0) {
            inputBufDesc.numBufs  = status.imgencStatus.bufInfo.minNumInBufs ;
        }
        else
        {
            inputBufDesc.numBufs  = imgencStatus.bufInfo.minNumInBufs ;
        }
        inputBufDesc.descs[0].buf= (XDAS_Int8 *)OrgPictureY;

        if (dynamicParams.inputChromaFormat== IJPEGENC_YUV_420LINE)
        {
            inputBufDesc.descs[1].buf= (XDAS_Int8 *)OrgPictureY + dynamicParams.inputWidth;
            inputBufDesc.descs[2].buf= inputBufDesc.descs[1].buf + dynamicParams.inputWidth*3/2;
        }
        else if (dynamicParams.inputChromaFormat!= XDM_YUV_422ILE)
        {
            if (dynamicParams.inputChromaFormat== XDM_YUV_420SP)
            {
                inputBufDesc.descs[1].buf= (XDAS_Int8 *)OrgPictureCb;
            }
            else
            {
                inputBufDesc.descs[1].buf= (XDAS_Int8 *)OrgPictureCb;
                inputBufDesc.descs[2].buf= (XDAS_Int8 *)OrgPictureCr;
            }

        }
        if (baseParamsOnly==0) {
            inputBufDesc.descs[0].bufSize = status.imgencStatus.bufInfo.minInBufSize[0]; // actually ignored by codec

            outputBufDesc.numBufs     = status.imgencStatus.bufInfo.minNumOutBufs ;
        }
        else
        {
            inputBufDesc.descs[0].bufSize = imgencStatus.bufInfo.minInBufSize[0]; // actually ignored by codec

            outputBufDesc.numBufs     = imgencStatus.bufInfo.minNumOutBufs ;
        }

        if (baseParamsOnly==0)
        {
#ifdef ENABLE_RING_BUF_USAGE

            outputBufDesc.descs[0].buf     = (XDAS_Int8 *)ringbuf;
            outputBufDesc.descs[0].bufSize =  RINGBUFSIZE; // actually ignored by codec
            ring2media.mediaPtr= media;
            ring2media.ringCurPtr= ringbuf;
            ring2media.ringStartPtr=ringbuf;
            ring2media.ringEndPtr= (Uint8*)((Uint32)ringbuf +RINGBUFSIZE) ;
            inArgs.ringBufStart= (XDAS_UInt8*)ringbuf;
            inArgs.ringBufSize= RINGBUFSIZE;
            printf("RINGBUFSIZE %x\n", RINGBUFSIZE);
#else
            outputBufDesc.descs[0].buf     = (XDAS_Int8 *)media;
            outputBufDesc.descs[0].bufSize =  ENCODED_DATA_BUFFER_SIZE; // actually ignored by codec
            ring2media.mediaPtr= media;
            ring2media.ringCurPtr= media;
            ring2media.ringStartPtr=media;
            ring2media.ringEndPtr= (Uint8*)((Uint32)media +ENCODED_DATA_BUFFER_SIZE) ;
            inArgs.ringBufStart= (XDAS_UInt8*)media;
            inArgs.ringBufSize= ENCODED_DATA_BUFFER_SIZE;
#endif


            inArgs.imgencInArgs.size =  sizeof(IJPEGENC_InArgs);
            outArgs.imgencOutArgs.size= sizeof(IJPEGENC_OutArgs);
        }
        else
        {
            outputBufDesc.descs[0].buf     = (XDAS_Int8 *)media;
            outputBufDesc.descs[0].bufSize =  ENCODED_DATA_BUFFER_SIZE; // actually ignored by codec
            imgencInArgs.size = sizeof(IIMGENC1_InArgs);
            imgencOutArgs.size= sizeof(IIMGENC1_OutArgs);

        }

#ifdef LINUX
        algActStart.tv_sec = 0;
        algActStart.tv_usec = 0;
        gettimeofday(&algActStart, 0);
#endif

        handle->fxns->algActivate(handle);

#ifdef LINUX
        processStart.tv_sec = 0;
        processStart.tv_usec = 0;
        gettimeofday(&processStart, 0);
#endif



        if (baseParamsOnly==0)
        {
            inArgs.insertCommentMarker = 0;
            inArgs.appDataType =0;
            inArgs.commentSegLen = 0;

            retVal = iimgEncfxns->process((IIMGENC1_Handle)handle,
                                          (XDM1_BufDesc *)&inputBufDesc,
                                          (XDM1_BufDesc *)&outputBufDesc,
                                          (IIMGENC1_InArgs *)&inArgs,
                                          (IIMGENC1_OutArgs *)&outArgs);

            bytesGenerated= outArgs.imgencOutArgs.bytesGenerated;
        }
        else
        {
            retVal = iimgEncfxns->process((IIMGENC1_Handle)handle,
                                          (XDM1_BufDesc *)&inputBufDesc,
                                          (XDM1_BufDesc *)&outputBufDesc,
                                          (IIMGENC1_InArgs *)&imgencInArgs,
                                          (IIMGENC1_OutArgs *)&imgencOutArgs);
            bytesGenerated= imgencOutArgs.bytesGenerated;
        }

#ifdef SLICE_MODE_TEST
        /* SLICE_MODE_TEST*/
        // Call get status to get number of total AU
        if (baseParamsOnly==0)
        {
            
		
	    retVal=iimgEncfxns->control((IIMGENC1_Handle)handle, IJPEGENC_GETSTATUS,
                                        (IIMGENC1_DynamicParams *)&extn_dynamicParams, (IIMGENC1_Status *)&status);
	    
	    if (retVal== XDM_EFAIL) {
                printf("\n Error control in slice mode get status command\n");
                exit(0);
            }
            totalAU= status.imgencStatus.totalAU;

	    printf("totalAU = %d\n",totalAU);
            extn_dynamicParams.imgencDynamicParams.numAU= 50/*totalAU/5*/;
	    
            // Call control function to setup dynamic params
            retVal=iimgEncfxns->control((IIMGENC1_Handle)handle, XDM_SETPARAMS,
                                        (IIMGENC1_DynamicParams *)&extn_dynamicParams, (IIMGENC1_Status *)&status);
            numAU = status.numAU;
	    printf("numAU = %d\n",numAU);

	    if (retVal== XDM_EFAIL) {
                printf("\n Error control in slice mode SetParams command\n");
                exit(0);
            }          // Get real numAU computed by codec

            // In case of 270 rotation, must point to right most slice of the image
            
	    if (extn_dynamicParams.rotation== 90)
            {
                if (dynamicParams.inputChromaFormat==XDM_YUV_420SP)
                {
                    Uint16 sliceWidth= (numAU*16/dynamicParams.inputHeight)*(8<<(params.forceChromaFormat==XDM_YUV_420P));
                    inputBufDesc.descs[0].buf+= (dynamicParams.inputWidth - sliceWidth);
                    inputBufDesc.descs[1].buf+= (dynamicParams.inputWidth - sliceWidth);

                    //	inputBufDesc.descs[2].buf+= (dynamicParams.inputWidth - sliceWidth);//dynamicParams.inputWidth/2 - sliceWidth/2;
                }
                else
                {
                    Uint16 sliceWidth= (numAU*16/dynamicParams.inputHeight)*(8<<(params.forceChromaFormat==XDM_YUV_420P));
                    inputBufDesc.descs[0].buf+= (dynamicParams.inputChromaFormat== XDM_YUV_422ILE ? 2 : 1)*(dynamicParams.inputWidth - sliceWidth);
                    inputBufDesc.descs[1].buf+= dynamicParams.inputWidth/2 - sliceWidth/2;
                    inputBufDesc.descs[2].buf+= dynamicParams.inputWidth/2 - sliceWidth/2;
                }


            }
            else if (extn_dynamicParams.rotation== 180)
            {
                Uint16 sliceHeight = (numAU*16/dynamicParams.inputWidth)*(8<<(params.forceChromaFormat==XDM_YUV_420P));
                if (dynamicParams.inputChromaFormat != XDM_YUV_420SP)
                {
                    inputBufDesc.descs[0].buf+= dynamicParams.captureWidth*(dynamicParams.inputChromaFormat== XDM_YUV_422ILE ? 2 : 1)*(dynamicParams.inputHeight - sliceHeight);
                    inputBufDesc.descs[1].buf+= dynamicParams.captureWidth*(dynamicParams.inputHeight - sliceHeight)>>(1 + (dynamicParams.inputChromaFormat== XDM_YUV_420P));
                    inputBufDesc.descs[2].buf+= dynamicParams.captureWidth*(dynamicParams.inputHeight - sliceHeight)>>(1 + (dynamicParams.inputChromaFormat== XDM_YUV_420P));
                }
                else
                {