MBOOL
CamIOPipe::
dequeBuf(PortID const ePortID, QTimeStampBufInfo& rQBufInfo, MUINT32 const u4TimeoutMs /*= 0xFFFFFFFF*/)
{
    //FUNCTION_LOG_START;
    MY_LOGD("+ tid(%d) type(%d, %d, %d, %d)", gettid(), ePortID.type, ePortID.index, ePortID.inout, u4TimeoutMs);
    // 
    // (1) check if the buffer already dequeue 
    // (2) if the buffer is not dequeue, dequeue from HW. 
    QTimeStampBufInfo *pQTBufInfo = NULL; 
    if (0 == ePortID.index)
    {
        pQTBufInfo = &mrRawQTBufInfo; 
    }
    else 
    {
        if (!mfgIsYUVPortON) 
        {
            MY_LOGE("The YUV por is not on \n");  
            return MFALSE; 
        }
        pQTBufInfo = &mrYuvQTBufInfo; 
    }
    
    if (pQTBufInfo->vBufInfo.size() == 0) 
    {
        dequeHWBuf(u4TimeoutMs); 
    }
    //
    rQBufInfo.u4User = pQTBufInfo->u4User; 
    rQBufInfo.u4Reserved = pQTBufInfo->u4Reserved;
    rQBufInfo.i4TimeStamp_sec = pQTBufInfo->i4TimeStamp_sec;
    rQBufInfo.i4TimeStamp_us = pQTBufInfo->i4TimeStamp_us; 
    for (MUINT32 i = 0; i < pQTBufInfo->vBufInfo.size(); i++) 
    {
        BufInfo rBufInfo(pQTBufInfo->vBufInfo.at(i).u4BufSize, 
                         pQTBufInfo->vBufInfo.at(i).u4BufVA, 
                         pQTBufInfo->vBufInfo.at(i).u4BufPA, 
                         pQTBufInfo->vBufInfo.at(i).i4MemID);  
        rQBufInfo.vBufInfo.push_back(rBufInfo); 
    }
    pQTBufInfo->vBufInfo.clear(); 

    for (MUINT32 i = 0; i < rQBufInfo.vBufInfo.size(); i++) 
    {
        MY_LOGD("(VA,PA,Size,ID)(0x%x,0x%x,%d,%d), ts(%d.%06d)", 
            rQBufInfo.vBufInfo.at(i).u4BufVA,
            rQBufInfo.vBufInfo.at(i).u4BufPA, rQBufInfo.vBufInfo.at(i).u4BufSize, rQBufInfo.vBufInfo.at(i).i4MemID,
            rQBufInfo.i4TimeStamp_sec, rQBufInfo.i4TimeStamp_us);
    }

    handleNotifyCallback( ECamPipe_NOTIFY_MSG_EOF, 0, 0 );

    FUNCTION_LOG_END;
    return  MTRUE;
}
MBOOL
Mhal_facebeauty::
createJpegImg(NSCamHW::ImgBufInfo const & rSrcImgBufInfo
      , NSCamShot::JpegParam const & rJpgParm
      , MUINT32 const u4Rot
      , MUINT32 const u4Flip
      , NSCamHW::ImgBufInfo const & rJpgImgBufInfo
      , MUINT32 & u4JpegSize)
{
    MBOOL ret = MTRUE;
    // (0). debug
    MY_LOGD("[createJpegImg] - E.");
    MY_LOGD("[createJpegImg] - rSrcImgBufInfo.eImgFmt=%d", rSrcImgBufInfo.eImgFmt);
    MY_LOGD("[createJpegImg] - u4Rot=%d", u4Rot);
    MY_LOGD("[createJpegImg] - u4Flip=%d", u4Flip);
    CPTLog(Event_FBShot_JpegEncodeImg, CPTFlagStart);
    //
    // (1). Create Instance
    NSCamShot::ISImager *pISImager = NSCamShot::ISImager::createInstance(rSrcImgBufInfo);
    if(!pISImager) {
    MY_LOGE("HdrShot::createJpegImg can't get ISImager instance.");
    return MFALSE;
    }
    
    // init setting
    NSCamHW::BufInfo rBufInfo(rJpgImgBufInfo.u4BufSize, rJpgImgBufInfo.u4BufVA, rJpgImgBufInfo.u4BufPA, rJpgImgBufInfo.i4MemID);
    //
    pISImager->setTargetBufInfo(rBufInfo);
    //
    pISImager->setFormat(eImgFmt_JPEG);
    //
    pISImager->setRotation(u4Rot);
    //
    pISImager->setFlip(u4Flip);
    //
    pISImager->setResize(rJpgImgBufInfo.u4ImgWidth, rJpgImgBufInfo.u4ImgHeight);
    //
    pISImager->setEncodeParam(rJpgParm.fgIsSOI, rJpgParm.u4Quality);
    //
    pISImager->setROI(Rect(0, 0, rSrcImgBufInfo.u4ImgWidth, rSrcImgBufInfo.u4ImgHeight));
    //
    pISImager->execute();
    //
    u4JpegSize = pISImager->getJpegSize();
    
    pISImager->destroyInstance();
    CPTLog(Event_FBShot_JpegEncodeImg, CPTFlagEnd);
    
    MY_LOGD("[init] - X. ret: %d.", ret);
    return ret;
}
/*******************************************************************************
*  Config CamIO Pipe /floria
********************************************************************************/
int
Ts_UT::
main_ts_IOPipe_ZSD(int count)
{
//    int count = 1000; //enque, deque loop iterations

    printf("[iopipetest] E\n");

    //for Enqueue, raw buf
    MUINT32 u4RawBufSize = (u4SensorWidth * u4SensorHeight * 2    + L1_CACHE_BYTES-1) & ~(L1_CACHE_BYTES-1);
    //for buffer per frame
    int BufIdx = BUF_NUM, nCt = BUF_NUM;
#ifdef USE_IMAGEBUF_HEAP
    MUINT32 bufStridesInBytes[3] = {1600, 0, 0};
    MINT32 bufBoundaryInBytes[3] = {0, 0, 0};
#endif


#if 0
    ringbuffer* mpRingImgo = new ringbuffer(
                                            2,//PASS1_FULLRAW
                                            PORT_IMGO,
                                            0//fakeResized ? PASS1_RESIZEDRAW : 0
                                            );
#endif
    MY_LOGD("+");
    /*------------------------------
    *    (1) Create Instance
    *-----------------------------*/
    /* eScenarioID_VSS, eScenarioFmt_RAW */
    MUINT mSensorIdx = 0;//0:MAIN
    const char Name = '1';
    MUINT mIspEnquePeriod = 1;

    prepareSensor();//test IHalSensor

    printf("[iopipetest] INormalPipe::createInstance\n");
    mpCamIO = (INormalPipe*)INormalPipe::createInstance(mSensorIdx, &Name, mIspEnquePeriod);

#if 0//camera 3.0, should create INormalPipe_FrmB class instance
    mpCamIO = (IHalCamIO*)INormalPipe_FrmB::createInstance(mSensorIdx, &Name, mIspEnquePeriod);
#endif

    /*------------------------------
        test 3A build pass
    ------------------------------*/
    #if 0
    MINT32 handle;
    MBOOL fgRet = mpCamIO->sendCommand(NSImageio_FrmB::NSIspio_FrmB::EPIPECmd_GET_MODULE_HANDLE,
                                       NSImageio_FrmB::NSIspio_FrmB::EModule_AF,
                                       (MINT32)&handle,
                                       (MINT32)(&("AFMgr::setFlkWinConfig()")));
    MINT32 wintmp;
    IOPIPE_SET_MODUL_REG(handle, CAM_AF_WINX01, wintmp);
    #endif

    /*------------------------------
    *    (2) init
    *-----------------------------*/
    printf("[iopipetest] mpCamIO->init\n");
    if(!mpCamIO->init())
    {
        printf("[iopipetest] mpCamIO->init failed!!\n");
    }

    /*------------------------------
    *    (3). Config pipe + RAW10
    *-----------------------------*/
    MSize mDstSize;
    mDstSize.w = u4SensorWidth;
    mDstSize.h = u4SensorHeight;

    //prepare sensor config
    vector<IHalSensor::ConfigParam> vSensorCfg;
    IHalSensor::ConfigParam sensorCfg =
    {
        mSensorIdx,                         /* index            */
        mDstSize,                           /* crop             no reference in NormalPipe */
        u4Scenario,                         /* scenarioId       */
        0,                                  /* isBypassScenario */
        1,                                  /* isContinuous     */
        0,                                  /* iHDROn           */
        0,                                  /* framerate        */
        0,                                  /* two pixel on     */
        0,                                  /* debugmode        */
    };
    vSensorCfg.push_back(sensorCfg);
    printf("[iopipetest] sensor %dx%d, sce %d, bypass %d, con %d, hdr %d, fps %d, twopxl %d\n",
                sensorCfg.crop.w,
                sensorCfg.crop.h,
                sensorCfg.scenarioId,
                sensorCfg.isBypassScenario,
                sensorCfg.isContinuous,
                sensorCfg.HDRMode,
                sensorCfg.framerate,
                sensorCfg.twopixelOn);
    //

    vector<portInfo> vPortInfo;
    //
    portInfo OutPort(
            PORT_IMGO,
            eImgFmt_BAYER10,
            mDstSize, //dst size
            0, //pPortCfg->mCrop, //crop
            u4SensorWidth, //pPortCfg->mStrideInByte[0],
            0, //pPortCfg->mStrideInByte[1],
            0, //pPortCfg->mStrideInByte[2],
            0, // pureraw
            MTRUE               //packed
            );
    vPortInfo.push_back(OutPort);
    printf("[iopipetest] config portID(0x%x), fmt(%u), size(%dx%d), crop(%u,%u,%u,%u)\n",
            OutPort.mPortID, OutPort.mFmt, OutPort.mDstSize.w, OutPort.mDstSize.h,
            OutPort.mCropRect.p.x, OutPort.mCropRect.p.y,
            OutPort.mCropRect.s.w, OutPort.mCropRect.s.h);
    printf("[iopipetest] stride(%u,%u,%u), pureRaw(%u), pack(%d)\n",
            OutPort.mStride[0], OutPort.mStride[1], OutPort.mStride[2],
            OutPort.mPureRaw, OutPort.mPureRawPak);
    //
    QInitParam halCamIOinitParam(
                0,
                u4Bitdepth,
                vSensorCfg,
                vPortInfo);

    printf("[iopipetest] mpCamIO->configPipe\n");
    if(!mpCamIO->configPipe(halCamIOinitParam, eScenarioID_VSS))
    {
        printf("[iopipetest] mpCamIO->configPipe failed!!\n");
        goto TEST_EXIT;
    }

    /*------------------------------
    *    (4). Enqueue
    *     4.1, raw buf
    *-----------------------------*/
#ifdef _USE_THREAD_QUE_
    if(vRawMem.size() > 0)
    {
        freeRawMem();
        TS_Thread_UnInit();
    }
    nCt--;
#else
    //
    int nReplace;
    printf("*****************************************\n");
    printf("Buffer per frame(1:y; else:n)\n");
    scanf("%d", &nReplace);
    printf("*****************************************\n");

    if(nReplace != 1)
    {
        nCt--;
    }
#endif

    /* * * * * * * * * * * *
     * buffer per frame
     * nReplace = 1
     * size = BUF_NUM + 1
     *(replace buffer)

     * * * * * * * * * * * *

     * sequential buffer
     * nReplace != 1
     * size = BUF_NUM
     *(no replace buffer)
     * * * * * * * * * * * */
    printf("[iopipetest] allocMem: RawBuff\n");
    for (int i = 0; i <= nCt; i++) //BUF_NUM=3
    {
        IMEM_BUF_INFO rBuf;
        rBuf.size = u4RawBufSize;
        allocMem(rBuf);
#ifdef USE_IMAGEBUF_HEAP
        PortBufInfo_v1 portBufInfo = PortBufInfo_v1( rBuf.memID,rBuf.virtAddr,0,rBuf.bufSecu, rBuf.bufCohe);
        IImageBufferAllocator::ImgParam imgParam = IImageBufferAllocator::ImgParam((eImgFmt_BAYER10),
                                                        MSize(1280, 720), bufStridesInBytes, bufBoundaryInBytes, 1);
        sp<ImageBufferHeap> pHeap = ImageBufferHeap::create( LOG_TAG, imgParam,portBufInfo,MTRUE);
        IImageBuffer* tempBuffer = pHeap->createImageBuffer();
        tempBuffer->incStrong(tempBuffer);
        tempBuffer->lockBuf(LOG_TAG,eBUFFER_USAGE_HW_CAMERA_READWRITE | eBUFFER_USAGE_SW_READ_OFTEN);
        //
        BufInfo rBufInfo;
        rBufInfo.mPortID = PORT_IMGO;
        rBufInfo.mBuffer = tempBuffer;
        rBufInfo.FrameBased.mMagicNum_tuning = 0;
        rBufInfo.FrameBased.mDstSize = mDstSize;
        rBufInfo.FrameBased.mCropRect = MRect(MPoint(0, 0), mDstSize);//no crop

        rRawBuf.mvOut.push_back(rBufInfo);
#endif
        vRawMem.push_back(rBuf);
        printf("[iopipetest] vRawMem(%d)PA(0x%x)VA(0x%x)\n", i, vRawMem.at(i).phyAddr,vRawMem.at(i).virtAddr);
    }

    //for deque
    for (int i = 0; i <= 0; i++)
    {
        IMEM_BUF_INFO rBuf;
        rBuf.size = u4RawBufSize;
        allocMem(rBuf);
#ifdef USE_IMAGEBUF_HEAP
        PortBufInfo_v1 portBufInfo = PortBufInfo_v1( rBuf.memID,rBuf.virtAddr,0,rBuf.bufSecu, rBuf.bufCohe);
        IImageBufferAllocator::ImgParam imgParam = IImageBufferAllocator::ImgParam((eImgFmt_BAYER10),
                                                        MSize(1280, 720), bufStridesInBytes, bufBoundaryInBytes, 1);
        sp<ImageBufferHeap> pHeap = ImageBufferHeap::create( LOG_TAG, imgParam,portBufInfo,MTRUE);
        IImageBuffer* tempBuffer = pHeap->createImageBuffer();
        tempBuffer->incStrong(tempBuffer);
        tempBuffer->lockBuf(LOG_TAG,eBUFFER_USAGE_HW_CAMERA_READWRITE | eBUFFER_USAGE_SW_READ_OFTEN);
        //
        BufInfo rBufInfo;
        rBufInfo.mPortID = PORT_IMGO;
        rBufInfo.mBuffer = tempBuffer;
        rDequeBuf.mvOut.push_back(rBufInfo);
#endif
        vDequeMem.push_back(rBuf);
        printf("[iopipetest] vDequeMem(%d)PA(0x%x)VA(0x%x)\n", i, vDequeMem.at(i).phyAddr, vDequeMem.at(i).virtAddr);
    }

    /* enque 3 buffers */
    for (int i = 0; i < BUF_NUM; i++)
    {
#if 1
        QBufInfo rInBuf;
        rInBuf.mvOut.clear();
    #ifdef USE_IMAGEBUF_HEAP
        BufInfo rBufInfo(PORT_IMGO, rRawBuf.mvOut.at(i).mBuffer, rRawBuf.mvOut.at(i).mSize, rRawBuf.mvOut.at(i).mVa, rRawBuf.mvOut.at(i).mPa);
    #else
        BufInfo rBufInfo(PORT_IMGO, NULL, vRawMem.at(i).size, vRawMem.at(i).virtAddr, vRawMem.at(i).phyAddr);
    #endif
        rInBuf.mvOut.push_back(rBufInfo);
        rInBuf.mvOut.at(0).FrameBased.mMagicNum_tuning = 0;
        rInBuf.mvOut.at(0).FrameBased.mDstSize = mDstSize;
        rInBuf.mvOut.at(0).FrameBased.mCropRect = MRect(MPoint(0, 0), mDstSize);//no crop

#ifdef USE_IMAGEBUF_HEAP
    printf("[iopipetest] enque.PA(0x%x)VA(0x%x)buf(0x%x)\n", rInBuf.mvOut.at(0).mBuffer->getBufPA(0), rInBuf.mvOut.at(0).mBuffer->getBufVA(0), rInBuf.mvOut.at(0).mBuffer);
#else
    printf("[iopipetest] enque.PA(0x%x)VA(0x%x)\n", rInBuf.mvOut.at(0).mPa, rInBuf.mvOut.at(0).mVa);
#endif

        printf("[iopipetest] enque(%d)\n", i);
        if(!mpCamIO->enque(rInBuf))
        {
            printf("[iopipetest] enque failed!!\n");
            goto TEST_EXIT;
        }
#else
        /* * * * * * * * * * * * * * * * * * * * * * * * * *
         * test:
         * if enque a buffer,and it's port is not IMGO,
         * mpCamIO->enque(rRawBuf)will return MFALSE
         * * * * * * * * * * * * * * * * * * * * * * * * * */
        QBufInfo rInBuf;
        rInBuf.mvOut.clear();
    #ifdef USE_IMAGEBUF_HEAP
        BufInfo rBufInfo2(PORT_IMGO, rRawBuf.mvOut.at(i).mBuffer, rRawBuf.mvOut.at(i).mSize, rRawBuf.mvOut.at(i).mVa, rRawBuf.mvOut.at(i).mPa);
    #else
        BufInfo rBufInfo2(PORT_IMG2O, NULL, vRawMem.at(i).size, vRawMem.at(i).virtAddr, vRawMem.at(i).phyAddr);
    #endif
        rInBuf.mvOut.push_back(rBufInfo2);

        printf("[iopipetest] enque(%d)\n", i);

        if(!mpCamIO->enque(rInBuf)){//try to enque IMGO port
            printf("[iopipetest] enque(%d) again\n", i);
            rInBuf.mvOut.clear();
            BufInfo rBufInfo(PORT_IMGO, NULL, vRawMem.at(i).size, vRawMem.at(i).virtAddr, vRawMem.at(i).phyAddr);
            rInBuf.mvOut.push_back(rBufInfo);
            if(!mpCamIO->enque(rInBuf))
            {
                printf("[iopipetest] enque failed!!\n");
                goto TEST_EXIT;
            }
        }
#endif
    }
    /*------------------------------
    *    (5). start
    *-----------------------------*/
    printf("[iopipetest] mpCamIO->start\n");
    if(!mpCamIO->start())
    {
        printf("[iopipetest] mpCamIO->start failed!!\n");
        goto TEST_EXIT;
    }
#if 0//for debug
    // test: wait VSYNC
    printf("[iopipetest] mpCamIO->irq(VSYNC)\n");
    if(!mpCamIO->wait(mSensorIdx, EPipeSignal_SOF))
    {
        printf("[iopipetest] wait VSYNC failed!!\n");
        goto TEST_EXIT;
    }
    // test: wait pass1 done
    printf("[iopipetest] mpCamIO->irq(p1done)\n");
    if(!mpCamIO->wait(mSensorIdx, EPipeSignal_EOF))
    {
        printf("[iopipetest] wait p1done failed!!\n");
        goto TEST_EXIT;
    }
#endif
    /*------------------------------
    *    (6). deque/enque loop
    *    --> dequeue
    *    --> enqueue
    *-----------------------------*/
#ifdef _USE_THREAD_QUE_
    TS_Thread_Init(count);
#else
    do
    {
        printf("-------------------------------------------\n");
        QBufInfo halCamIOOutQBuf;
        QBufInfo rEnBuf;
        //
        halCamIOOutQBuf.mvOut.clear();
    #ifdef USE_IMAGEBUF_HEAP
        BufInfo rDeBufInfo(PORT_IMGO, rDequeBuf.mvOut.at(0).mBuffer, rDequeBuf.mvOut.at(0).mSize, rDequeBuf.mvOut.at(0).mVa, rDequeBuf.mvOut.at(0).mPa);
    #else
        BufInfo rDeBufInfo(PORT_IMGO, NULL, vDequeMem.at(0).size, vDequeMem.at(0).virtAddr, vDequeMem.at(0).phyAddr);
    #endif
        halCamIOOutQBuf.mvOut.push_back(rDeBufInfo);

    #ifdef USE_IMAGEBUF_HEAP
        //do nothing
    #else
        printf("[iopipetest] dequeBuf.PA(0x%x)VA(0x%x)size(%d)\n", halCamIOOutQBuf.mvOut.at(0).mPa, halCamIOOutQBuf.mvOut.at(0).mVa, halCamIOOutQBuf.mvOut.size());
    #endif
        //
        printf("[iopipetest] dequeBuf count(%d)\n", count);
        if(!mpCamIO->deque(halCamIOOutQBuf))
        {
            printf("[iopipetest] deque failed!!\n");
            goto TEST_EXIT;
        }
    #ifdef USE_IMAGEBUF_HEAP
        printf("[iopipetest] dequeBuf.PA(0x%x)VA(0x%x)buf(0x%x)\n", halCamIOOutQBuf.mvOut.at(0).mBuffer->getBufPA(0), halCamIOOutQBuf.mvOut.at(0).mBuffer->getBufVA(0), halCamIOOutQBuf.mvOut.at(0).mBuffer);
    #else
        printf("[iopipetest] dequeBuf.PA(0x%x)VA(0x%x)\n", halCamIOOutQBuf.mvOut.at(0).mPa, halCamIOOutQBuf.mvOut.at(0).mVa);
    #endif
        /* * * * * * * * * * * *
         * get ResultMetadata
         * * * * * * * * * * * */
        ResultMetadata result = halCamIOOutQBuf.mvOut.at(0).mMetaData;
        /* * * * * * * * * * * *
         * check dummy frame
         * * * * * * * * * * * */
        if(halCamIOOutQBuf.mvOut.at(0).mMetaData.m_bDummyFrame == MTRUE)
        {
            printf("[iopipetest] this is a dummy frame\n");
        }
        /* * * * * * * * * * * *
         * sequential buffer
         *(no replace buffer)
         * * * * * * * * * * * */
        if(nReplace != 1)
        {
            rEnBuf.mvOut.clear();
            BufInfo rBufInfo(PORT_IMGO,
#ifdef USE_IMAGEBUF_HEAP
                             halCamIOOutQBuf.mvOut.at(0).mBuffer,
#else
                             NULL,
#endif
                             halCamIOOutQBuf.mvOut.at(0).mSize,
                             halCamIOOutQBuf.mvOut.at(0).mVa,
                             halCamIOOutQBuf.mvOut.at(0).mPa);

            rEnBuf.mvOut.push_back(rBufInfo);
        }
        /* * * * * * * * * * * *
         * buffer per frame
         *(replace buffer)
         * * * * * * * * * * * */
        else
        {
            rEnBuf.mvOut.clear();
        #ifdef USE_IMAGEBUF_HEAP
            BufInfo rBufInfo(PORT_IMGO, rRawBuf.mvOut.at(BufIdx).mBuffer, rRawBuf.mvOut.at(BufIdx).mSize, rRawBuf.mvOut.at(BufIdx).mVa, rRawBuf.mvOut.at(BufIdx).mPa);
        #else
            BufInfo rBufInfo(PORT_IMGO, NULL, vRawMem.at(BufIdx).size, vRawMem.at(BufIdx).virtAddr, vRawMem.at(BufIdx).phyAddr);
        #endif
            rEnBuf.mvOut.push_back(rBufInfo);
        }

    #ifdef USE_IMAGEBUF_HEAP
        printf("[iopipetest] enqueBuf.PA(0x%x)VA(0x%x),BufId(%d)\n", rEnBuf.mvOut.at(0).mBuffer->getBufPA(0), rEnBuf.mvOut.at(0).mBuffer->getBufVA(0), BufIdx);
    #else
        printf("[iopipetest] enqueBuf.PA(0x%x)VA(0x%x),BufId(%d)\n", rEnBuf.mvOut.at(0).mPa, rEnBuf.mvOut.at(0).mVa, BufIdx);
    #endif
        /* * * * * * * * * * * *
         * setting before enque
         * * * * * * * * * * * */
        rEnBuf.mvOut.at(0).FrameBased.mMagicNum_tuning = 0;
        rEnBuf.mvOut.at(0).FrameBased.mDstSize = mDstSize;
        rEnBuf.mvOut.at(0).FrameBased.mCropRect = MRect(MPoint(0, 0), mDstSize);//no crop
        //
        printf("[iopipetest] enque count(%d)\n", count);
        if(!mpCamIO->enque(rEnBuf))
        {
            printf("[iopipetest] enque failed!!\n");
            goto TEST_EXIT;
        }
        //
        if(++BufIdx > BUF_NUM) BufIdx = 0;
        //
    } while(--count > 0);
#endif

    /*------------------------------
    *    (7). Stop
    *-----------------------------*/
    printf("[iopipetest] mpCamIO->stop\n");
    mpCamIO->stop();

TEST_EXIT:
    /*------------------------------
    *    (8). uninit
    *-----------------------------*/
    printf("[iopipetest] mpCamIO->uninit\n");
    if( !mpCamIO->uninit() )
    {
        MY_LOGE("uninit failed");
    }

    /*------------------------------
    *    (9). destory instance
    *-----------------------------*/
    printf("[iopipetest] mpCamIO->destroyInstance\n");
    mpCamIO->destroyInstance(&Name);
    mpCamIO = NULL;



    printf("[iopipetest] X\n");
    return 0;
}
MVOID*
Ts_UT::
endeque_Thread(MVOID * arg)
{
    printf("[endeque_Thread] E\n");
    int count = (int)arg; //enque, deque loop iterations
    MSize mDstSize;
    mDstSize.w = pTestUT->u4SensorWidth;
    mDstSize.h = pTestUT->u4SensorHeight;

    //  detach thread => cannot be join
    ::pthread_detach(::pthread_self());
    do
    {
        printf("-----------------------------------\n");
        printf("[endeque_Thread] dequeBuf count(%d)\n", count);

        QBufInfo halCamIOOutQBuf;
        QBufInfo rEnBuf;
        /*
         * Deque
         */
        halCamIOOutQBuf.mvOut.clear();
#ifdef USE_IMAGEBUF_HEAP
        BufInfo rDeBufInfo(PORT_IMGO, pTestUT->rDequeBuf.mvOut.at(0).mBuffer, pTestUT->rDequeBuf.mvOut.at(0).mSize, pTestUT->rDequeBuf.mvOut.at(0).mVa, pTestUT->rDequeBuf.mvOut.at(0).mPa);
#else
        BufInfo rDeBufInfo(PORT_IMGO, NULL, pTestUT->vDequeMem.at(0).size, pTestUT->vDequeMem.at(0).virtAddr, pTestUT->vDequeMem.at(0).phyAddr);
#endif
        halCamIOOutQBuf.mvOut.push_back(rDeBufInfo);
        //
        if(!pTestUT->mpCamIO->deque(halCamIOOutQBuf))
        {
            printf("[endeque_Thread] deque failed!!\n");
            return NULL;
        }
        /*
         * Enque
         */
        rEnBuf.mvOut.clear();
        BufInfo rBufInfo(halCamIOOutQBuf.mvOut.at(0).mPortID,
#ifdef USE_IMAGEBUF_HEAP
                         halCamIOOutQBuf.mvOut.at(0).mBuffer,
#else
                         NULL,
#endif
                         halCamIOOutQBuf.mvOut.at(0).mSize,
                         halCamIOOutQBuf.mvOut.at(0).mVa,
                         halCamIOOutQBuf.mvOut.at(0).mPa);

        rEnBuf.mvOut.push_back(rBufInfo);

        /* * * * * * * * * * * *
         * setting before enque
         * * * * * * * * * * * */
        rEnBuf.mvOut.at(0).FrameBased.mMagicNum_tuning = 0;
        rEnBuf.mvOut.at(0).FrameBased.mDstSize = mDstSize;
        rEnBuf.mvOut.at(0).FrameBased.mCropRect = MRect(MPoint(0, 0), mDstSize);//no crop
        //
        printf("[endeque_Thread] enqueBuf count(%d)\n", count);
        if(MFALSE == pTestUT->mpCamIO->enque(rEnBuf))
        {
            printf("[endeque_Thread] enqueBuf failed\n");
            return NULL;
        }
    } while(--count > 0);
    printf("[endeque_Thread] X\n");
    printf("-----------------------------------\n");
    pthread_exit(0);
    return NULL;
}
MBOOL
ImageTransform::
execute(
    ImgBufInfo const rSrcBufInfo, 
    ImgBufInfo const rDstBufInfo, 
    Rect const rROI, 
    MUINT32 const u4Rotation, 
    MUINT32 const u4Flip, 
    MUINT32 const u4TimeOutInMs
)
{
#define CHECK_RET(x, str)                            \
    do{                                              \
        if ( !(ret) ){                               \
            MY_LOGE("fail at %s", str);              \
            if( bInit )                              \
            {                                        \
                pXdpPipe->uninit();                  \
            }                                        \
            if( pXdpPipe )                           \
            {                                        \
                pXdpPipe->destroyInstance();         \
            }                                        \
            unlock();                                \
            return MFALSE;                           \
        }                                            \
    }while(0)

    FUNCTION_LOG_START;
    MtkCamUtils::CamProfile profile("execute", "ImageTransform");
    if (!lock(u4TimeOutInMs)) 
    {
        MY_LOGE("[execute] lock fail "); 
        return MFALSE; 
    }
    MBOOL ret = MTRUE;
    MBOOL bInit = MFALSE;
    // (1). Create Instance 
#warning [TODO] sensor type ??? 
    IXdpPipe    *pXdpPipe = IXdpPipe::createInstance(eSWScenarioID_CAPTURE_NORMAL, eScenarioFmt_RAW); //eScenarioFmt_RAW is never used? 
    CHECK_OBJECT(pXdpPipe); 
    //
    if (pXdpPipe != NULL) 
    {
        MY_LOGD("Pipe (Name, ID) = (%s, %d)", pXdpPipe->getPipeName(), pXdpPipe->getPipeId()); 
    }
    
    // (2). Query port property
    //vector<PortProperty> rInPortProperty; 
    //vector<PortProperty> rOutPortProperty;     
    //if (pXdpPipe->queryPipeProperty(rInPortProperty,rOutPortProperty))
    //{
    //    MY_LOGD("Port Property (IN, OUT): (%d, %d)", rInPortProperty.size(), rOutPortProperty.size()); 
    //    for (MUINT32 i = 0; i < rInPortProperty.size(); i++)
    //    {
    //        MY_LOGD("IN: (type, index, inout, fmt, rot, flip) = (%d, %d, %d, %d, %d, %d)", 
    //                     rInPortProperty.at(i).type, rInPortProperty.at(i).index, rInPortProperty.at(i).inout,  
    //                     rInPortProperty.at(i).u4SupportFmt, rInPortProperty.at(i).fgIsSupportRotate, rInPortProperty.at(i).fgIsSupportFlip); 
    //    }       
    //    for (MUINT32 i = 0; i < rOutPortProperty.size(); i++)
    //    {
    //        MY_LOGD("IN: (type, index, inout, fmt, rot, flip) = (%d, %d, %d, %d, %d, %d)", 
    //                     rOutPortProperty.at(i).type, rOutPortProperty.at(i).index, rOutPortProperty.at(i).inout,  
    //                     rOutPortProperty.at(i).u4SupportFmt, rOutPortProperty.at(i).fgIsSupportRotate, rOutPortProperty.at(i).fgIsSupportFlip); 
    //    } 
    //}    

    // (3). init 
    ret = pXdpPipe->init(); 
    CHECK_RET(ret,"init");
    bInit = MTRUE;

    // (4). setCallback
    pXdpPipe->setCallbacks(NULL, NULL, NULL); 

    // (5). Config pipe 
    // 
    MemoryInPortInfo rMemInPort(ImgInfo(rSrcBufInfo.eImgFmt, rSrcBufInfo.u4ImgWidth, rSrcBufInfo.u4ImgHeight), 
                                0, rSrcBufInfo.u4Stride, Rect(rROI.x, rROI.y, rROI.w, rROI.h)); 
    //   
    MemoryOutPortInfo rVdoPort(ImgInfo(rDstBufInfo.eImgFmt, rDstBufInfo.u4ImgWidth, rDstBufInfo.u4ImgHeight), 
                               rDstBufInfo.u4Stride, u4Rotation, u4Flip);   
    rVdoPort.index = 1;   
    //
    vector<PortInfo const*> vXdpInPorts;  
    vector<PortInfo const*> vXdpOutPorts; 
    //
    vXdpInPorts.push_back(&rMemInPort); 
    vXdpOutPorts.push_back(&rVdoPort); 
    //
    ret = pXdpPipe->configPipe(vXdpInPorts, vXdpOutPorts); 
    CHECK_RET(ret,"config");

    // (6). Enqueue, In buf
    // 
    QBufInfo rInBuf; 
    rInBuf.vBufInfo.clear(); 
    BufInfo rBufInfo(rSrcBufInfo.u4BufSize, rSrcBufInfo.u4BufVA, rSrcBufInfo.u4BufPA, rSrcBufInfo.i4MemID);  
    rInBuf.vBufInfo.push_back(rBufInfo); 
    ret = pXdpPipe->enqueBuf(PortID(EPortType_MemoryIn, 0, 0), rInBuf); 
    // 
    QBufInfo rOutBuf; 
    rOutBuf.vBufInfo.clear(); 
    rBufInfo.u4BufSize = rDstBufInfo.u4BufSize; 
    rBufInfo.u4BufVA = rDstBufInfo.u4BufVA; 
    rBufInfo.u4BufPA = rDstBufInfo.u4BufPA; 
    rBufInfo.i4MemID = rDstBufInfo.i4MemID; 
    //rBufInfo.eMemType = rDstBufInfo.eMemType;
    rOutBuf.vBufInfo.push_back(rBufInfo); 
    ret = pXdpPipe->enqueBuf(PortID(EPortType_MemoryOut, 1, 1), rOutBuf); 
    CHECK_RET(ret,"enqueBuf");
    // 
    profile.print(); 
    // (7). start
    ret = pXdpPipe->start(); 
    CHECK_RET(ret,"start");

    // (8). Dequeue Vdo Out Buf 
    QTimeStampBufInfo rQVdoOutBuf; 
    ret = pXdpPipe->dequeBuf(PortID(EPortType_MemoryOut, 1, 1), rQVdoOutBuf); 
    CHECK_RET(ret,"dequeBuf");
    // (8.1) Dequeue In Buf 
    QTimeStampBufInfo rQInBUf; 
    ret = pXdpPipe->dequeBuf(PortID(EPortType_MemoryIn, 0, 0), rQInBUf); 
    CHECK_RET(ret,"dequeBuf");
 
    // (9). Stop 
    ret = pXdpPipe->stop();
    CHECK_RET(ret,"stop");
#undef CHECK_RET
    // (10). uninit 
    if( bInit )
    {
        ret = pXdpPipe->uninit(); 
        if( !ret )
        {
            if( pXdpPipe )
            {
                pXdpPipe->destroyInstance(); 
            }
            return MFALSE;
        }
    }
    // (11). destory instance 
    if( pXdpPipe )
    {
        pXdpPipe->destroyInstance(); 
    }

    ret = unlock(); 
    profile.print(); 
    //
    return ret; 
}
Example #6
0
/*******************************************************************************
*  Config CamIO Pipe /floria
********************************************************************************/
int
Ts_IT::
startPreview(int count)
{
    MY_LOGD("E");

    MUINT32 u4RawBufSize = (u4SensorWidth * u4SensorHeight * 10) / 8;
    MINT32 ret = 0;

    u4RawBufSize = ((u4RawBufSize + 0xFFF) & ~0xFFF); //align 4k

    /***************************************************
     * Pass 1 : CamIOPipe
     ***************************************************/
    MY_LOGD("ICamIOPipe::createInstance");
    //ICamIOPipe *pCamIOPipe = ICamIOPipe::createInstance(eScenarioID_VSS,//mapScenarioID(meSWScenarioID, ICamIOPipe::ePipeID)
    mpCamIOPipe = ICamIOPipe::createInstance(eScenarioID_VSS, eScenarioFmt_RAW);
    if (NULL == mpCamIOPipe)
    {
        return 0;
    }
    MY_LOGD("Pipe (Name, ID) = (%s, %d)", mpCamIOPipe->getPipeName(), mpCamIOPipe->getPipeId());

    MY_LOGD("mpCamIOPipe->init\n");
    if (!mpCamIOPipe->init())
    {
        MY_LOGD("mpCamIOPipe->init failed");
        return 0;
    }

    mpCamIOPipe->setCallbacks(NULL, NULL, NULL);

    MY_LOGD("setConfigPortInfo");
    if (setConfigPortInfo() == MFALSE)
    {
        goto TEST_EXIT;
    }

    if(vRawMem.size() > 0)
    {
        freeRawMem();
        TS_Thread_UnInit();
    }

    for (int i = 0; i < BUF_NUM; i++)
    {
        IMEM_BUF_INFO rBuf;
        rBuf.size = u4RawBufSize;
        allocMem(rBuf);
        vRawMem.push_back(rBuf);
    }

    for (int i = 0; i < BUF_NUM; i++)
    {
#if 1
        QBufInfo rOutBufInfo;
        PortID rPortID(EPortType_Memory, EPortIndex_IMGO, 1);
        NSImageio::NSIspio::BufInfo rBuf(vRawMem.at(i).size,
             vRawMem.at(i).virtAddr,
             vRawMem.at(i).phyAddr,
             vRawMem.at(i).memID,
             vRawMem.at(i).bufSecu,
             vRawMem.at(i).bufCohe);
        rOutBufInfo.vBufInfo.push_back(rBuf);

        mpCamIOPipe->enqueOutBuf(rPortID, rOutBufInfo);
#else
        rRawBuf.vBufInfo.clear();
        NSCamHW::BufInfo rBufInfo(vRawMem.at(i).size, vRawMem.at(i).virtAddr, vRawMem.at(i).phyAddr, vRawMem.at(i).memID);
        rRawBuf.vBufInfo.push_back(rBufInfo);
        MY_LOGD("enqueBuf(%d)", i);
        if (MFALSE == enqueBuf(NSCamPipe::PortID(NSCamPipe::EPortType_MemoryOut, 0, 1), rRawBuf))
        {
            goto TEST_EXIT;
        }
#endif
    }

    /***************************************************
     * Pass 2 : PostProc
     ***************************************************/
    mpPostProcPipe = IPostProcPipe::createInstance(eScenarioID_VSS, eScenarioFmt_RAW);
    if (NULL == mpPostProcPipe)
    {
        MY_LOGE("mpPostProcPipe create instance fail\n");
        goto TEST_EXIT;
    }
    ret = mpPostProcPipe->init();
    if (!mpPostProcPipe->init())
    {
        MY_LOGE("mpPostProcPipe init fail\n");
        goto TEST_EXIT;
    }

    dispoBuf.size = DISPO_WIDTH*DISPO_HEIGHT*2;
    allocMem(dispoBuf);
    vidoBuf.size = VIDO_WIDTH*VIDO_HEIGHT*2;
    allocMem(vidoBuf);

    ret = mpPostProcPipe->sendCommand((MINT32)NSImageio::NSIspio::EPIPECmd_SET_CQ_CHANNEL,
            (MINT32)NSImageio::NSIspio::EPIPE_PASS2_CQ1,0,0);
    ret = mpPostProcPipe->sendCommand((MINT32)NSImageio::NSIspio::EPIPECmd_SET_CONFIG_STAGE,
            (MINT32)NSImageio::NSIspio::eConfigSettingStage_Init,0,0);
    ret = mpPostProcPipe->sendCommand((MINT32)NSImageio::NSIspio::EPIPECmd_SET_CONFIG_STAGE,
            (MINT32)NSImageio::NSIspio::eConfigSettingStage_UpdateTrigger,0,0);

    start();

    TS_Thread_Init(count);

    if (!mpCamIOPipe->stop())
    {
       MY_LOGE("mpCamIOPipe->stop() fail");
    }

    //MY_LOGD("Preview stop, press to enter to exit");
    //getchar();

TEST_EXIT:

    if (NULL != mpCamIOPipe)
    {
        MY_LOGD("pCamIOPipe->uninit");
        if (MTRUE != mpCamIOPipe->uninit())
        {
            MY_LOGE("pCamIOPipe->uninit fail");
        }
        MY_LOGD("pCamIOPipe->destroyInstance");
        mpCamIOPipe->destroyInstance();
        mpCamIOPipe = NULL;
    }

    if (NULL != mpPostProcPipe)
    {
        if (MTRUE != mpPostProcPipe->uninit())
        {
            MY_LOGE("mpPostProcPipe uninit fail");
        }
        mpPostProcPipe->destroyInstance();
        mpPostProcPipe = NULL;
    }

    if (dispoBuf.size)
    {
        char filename[256];
        sprintf(filename, "/data/IT_%dx%d_dispo.yuv", DISPO_WIDTH, DISPO_HEIGHT);
        saveBufToFile(filename, reinterpret_cast<MUINT8*>(dispoBuf.virtAddr), dispoBuf.size);
        deallocMem(dispoBuf);
    }
    if (vidoBuf.size)
    {
        char filename[256];
        sprintf(filename, "/data/IT_%dx%d_vidio.yuv", VIDO_WIDTH, VIDO_HEIGHT);
        saveBufToFile(filename, reinterpret_cast<MUINT8*>(vidoBuf.virtAddr), vidoBuf.size);
        deallocMem(vidoBuf);
    }

    MY_LOGD("X");

    return 0;
}
MBOOL
ImageTransform::
execute(
    ImgBufInfo const rSrcBufInfo, 
    ImgBufInfo const rDstBufInfo, 
    Rect const rROI, 
    MUINT32 const u4Rotation, 
    MUINT32 const u4Flip, 
    MUINT32 const u4TimeOutInMs
)
{
    FUNCTION_LOG_START;
    MtkCamUtils::CamProfile profile("execute", "ImageTransform");
    if (!lock(u4TimeOutInMs)) 
    {
        MY_LOGE("[execute] lock fail "); 
        return MFALSE; 
    }
    // (1). Create Instance 
#warning [TODO] sensor type ??? 
    ICdpPipe    *pCdpPipe = ICdpPipe::createInstance(eSWScenarioID_CAPTURE_NORMAL, eScenarioFmt_RAW); 
    CHECK_OBJECT(pCdpPipe); 
    //
    if (pCdpPipe != NULL) 
    {
        MY_LOGD("Pipe (Name, ID) = (%s, %d)", pCdpPipe->getPipeName(), pCdpPipe->getPipeId()); 
    }
    
    // (2). Query port property
    vector<PortProperty> rInPortProperty; 
    vector<PortProperty> rOutPortProperty;     
    if (pCdpPipe->queryPipeProperty(rInPortProperty,rOutPortProperty))
    {
        MY_LOGD("Port Property (IN, OUT): (%d, %d)", rInPortProperty.size(), rOutPortProperty.size()); 
        for (MUINT32 i = 0; i < rInPortProperty.size(); i++)
        {
            MY_LOGD("IN: (type, index, inout, fmt, rot, flip) = (%d, %d, %d, %d, %d, %d)", 
                         rInPortProperty.at(i).type, rInPortProperty.at(i).index, rInPortProperty.at(i).inout,  
                         rInPortProperty.at(i).u4SupportFmt, rInPortProperty.at(i).fgIsSupportRotate, rInPortProperty.at(i).fgIsSupportFlip); 
        }       
        for (MUINT32 i = 0; i < rOutPortProperty.size(); i++)
        {
            MY_LOGD("IN: (type, index, inout, fmt, rot, flip) = (%d, %d, %d, %d, %d, %d)", 
                         rOutPortProperty.at(i).type, rOutPortProperty.at(i).index, rOutPortProperty.at(i).inout,  
                         rOutPortProperty.at(i).u4SupportFmt, rOutPortProperty.at(i).fgIsSupportRotate, rOutPortProperty.at(i).fgIsSupportFlip); 
        } 
    }    

    // (3). init 
    pCdpPipe->init(); 

    // (4). setCallback
    pCdpPipe->setCallbacks(NULL, NULL, NULL); 

    // (5). Config pipe 
    // 
    MemoryInPortInfo rMemInPort(ImgInfo(rSrcBufInfo.eImgFmt, rSrcBufInfo.u4ImgWidth, rSrcBufInfo.u4ImgHeight), 
                                0, rSrcBufInfo.u4Stride, Rect(rROI.x, rROI.y, rROI.w, rROI.h)); 
    //   
    MemoryOutPortInfo rVdoPort(ImgInfo(rDstBufInfo.eImgFmt, rDstBufInfo.u4ImgWidth, rDstBufInfo.u4ImgHeight), 
                               rDstBufInfo.u4Stride, u4Rotation, u4Flip);   
    rVdoPort.index = 1;   
    //
    vector<PortInfo const*> vCdpInPorts;  
    vector<PortInfo const*> vCdpOutPorts; 
    //
    vCdpInPorts.push_back(&rMemInPort); 
    vCdpOutPorts.push_back(&rVdoPort); 
    //
    pCdpPipe->configPipe(vCdpInPorts, vCdpOutPorts); 

    // (6). Enqueue, In buf
    // 
    QBufInfo rInBuf; 
    rInBuf.vBufInfo.clear(); 
    BufInfo rBufInfo(rSrcBufInfo.u4BufSize, rSrcBufInfo.u4BufVA, rSrcBufInfo.u4BufPA, rSrcBufInfo.i4MemID);  
    rInBuf.vBufInfo.push_back(rBufInfo); 
    pCdpPipe->enqueBuf(PortID(EPortType_MemoryIn, 0, 0), rInBuf); 
    // 
    QBufInfo rOutBuf; 
    rOutBuf.vBufInfo.clear(); 
    rBufInfo.u4BufSize = rDstBufInfo.u4BufSize; 
    rBufInfo.u4BufVA = rDstBufInfo.u4BufVA; 
    rBufInfo.u4BufPA = rDstBufInfo.u4BufPA; 
    rBufInfo.i4MemID = rDstBufInfo.i4MemID; 
    //rBufInfo.eMemType = rDstBufInfo.eMemType;
    rOutBuf.vBufInfo.push_back(rBufInfo); 
    pCdpPipe->enqueBuf(PortID(EPortType_MemoryOut, 1, 1), rOutBuf); 
    // 
    profile.print(); 
    // (7). start
    pCdpPipe->start(); 

    // (8). Dequeue Vdo Out Buf 
    QTimeStampBufInfo rQVdoOutBuf; 
    pCdpPipe->dequeBuf(PortID(EPortType_MemoryOut, 1, 1), rQVdoOutBuf); 
    // (8.1) Dequeue In Buf 
    QTimeStampBufInfo rQInBUf; 
    pCdpPipe->dequeBuf(PortID(EPortType_MemoryIn, 0, 0), rQInBUf); 
 
    // (9). Stop 
    pCdpPipe->stop();
    // (10). uninit 
    pCdpPipe->uninit(); 
    // (11). destory instance 
    pCdpPipe->destroyInstance(); 
    unlock(); 
    profile.print(); 
    //
    return 0; 
}