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; 
}
示例#2
0
/*******************************************************************************
*  Cdp 1 IN / 2 Out 
********************************************************************************/
int main_testCDP(IMEM_BUF_INFO rInMem, int width, int height, int format) 
{
    MY_LOGD("+"); 
    // (1). Create Instance 
    ICdpPipe    *pCdpPipe = ICdpPipe::createInstance(eSWScenarioID_CAPTURE_NORMAL, eScenarioFmt_RAW); 
    if (pCdpPipe != NULL) 
    {
        MY_LOGD("Pipe (Name, ID, IDName) = (%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) = (%d, %d, %d)", rInPortProperty.at(i).type, rInPortProperty.at(i).index, rInPortProperty.at(i).inout); 
            MY_LOGD("IN: (fmt, rot, flip) = (%d, %d, %d)", rInPortProperty.at(i).u4SupportFmt,
                                         rInPortProperty.at(i).fgIsSupportRotate, rInPortProperty.at(i).fgIsSupportFlip); 
        }       
        for (MUINT32 i = 0; i < rOutPortProperty.size(); i++)
        {
            MY_LOGD("OUT: (type,index,inout) = (%d, %d, %d)", rOutPortProperty.at(i).type, rOutPortProperty.at(i).index, rOutPortProperty.at(i).inout); 
            MY_LOGD("OUT: (fmt, rot, flip) = (%d, %d, %d)", 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 
    // 
    MUINT32 u4YuvStride[3] = {width, 0, 0};
    MemoryInPortInfo rMemInPort(ImgInfo(eImgFmt_YUY2, width, height), 
                                0, u4YuvStride, Rect(0, 0, width, height)); 
    //
    MemoryOutPortInfo rDispPort(ImgInfo(eImgFmt_NV21, width, height), 
                               u4YuvStride, 0, 0); 
    MUINT32 u4VdoStride[3] = {320, 0, 0}; 
    MemoryOutPortInfo rVdoPort(ImgInfo(eImgFmt_NV21, 320, 240), 
                               u4VdoStride, 0, 0);   
    rVdoPort.index = 1;   
    //
    vector<PortInfo const*> vCdpInPorts;  
    vector<PortInfo const*> vCdpOutPorts; 
    //
    vCdpInPorts.push_back(&rMemInPort); 
    vCdpOutPorts.push_back(&rDispPort); 
    vCdpOutPorts.push_back(&rVdoPort); 
    //
    pCdpPipe->configPipe(vCdpInPorts, vCdpOutPorts); 

    // (6). Enqueue, In buf
    // 
    QBufInfo rInBuf; 
    rInBuf.vBufInfo.clear(); 
    BufInfo rBufInfo(rInMem.size, rInMem.virtAddr, rInMem.phyAddr, rInMem.memID);  
    rInBuf.vBufInfo.push_back(rBufInfo); 
    pCdpPipe->enqueBuf(PortID(EPortType_MemoryIn, 0, 0), rInBuf); 

    // (6.1) Enqueue, Out Buf
    // 
    IMEM_BUF_INFO rDispMem; 
    rDispMem.size = ((width * height * 2) + L1_CACHE_BYTES-1) & ~(L1_CACHE_BYTES-1);     
    allocMem(rDispMem);     
    // 
    QBufInfo rOutBuf; 
    rOutBuf.vBufInfo.clear(); 
    rBufInfo.u4BufSize = rDispMem.size; 
    rBufInfo.u4BufVA = rDispMem.virtAddr; 
    rBufInfo.u4BufPA = rDispMem.phyAddr; 
    rBufInfo.i4MemID = rDispMem.memID; 
    rOutBuf.vBufInfo.push_back(rBufInfo); 
    pCdpPipe->enqueBuf(PortID(EPortType_MemoryOut, 0, 1), rOutBuf); 

    //
    IMEM_BUF_INFO rVdoMem; 
    rVdoMem.size = ((320 * 240 * 2)+ L1_CACHE_BYTES - 1) & ~(L1_CACHE_BYTES - 1); 
    allocMem(rVdoMem);    
    //
    rOutBuf.vBufInfo.at(0).u4BufSize = rVdoMem.size; 
    rOutBuf.vBufInfo.at(0).u4BufVA = rVdoMem.virtAddr; 
    rOutBuf.vBufInfo.at(0).u4BufPA = rVdoMem.phyAddr; 
    rOutBuf.vBufInfo.at(0).i4MemID = rVdoMem.memID; 
    pCdpPipe->enqueBuf(PortID(EPortType_MemoryOut, 1, 1), rOutBuf); 


    // (7). start
    pCdpPipe->start(); 

    // (8). Dequeue
    QTimeStampBufInfo rQDispOutBuf;         
    QTimeStampBufInfo rQVdoOutBuf; 
    QTimeStampBufInfo rQInBuf; 
    pCdpPipe->dequeBuf(PortID(EPortType_MemoryOut, 0, 1), rQDispOutBuf); 
    pCdpPipe->dequeBuf(PortID(EPortType_MemoryOut, 1, 1), rQVdoOutBuf); 
    pCdpPipe->dequeBuf(PortID(EPortType_MemoryIn, 0, 0), rQInBuf);  

 
    // (9). Stop 
    pCdpPipe->stop();
    // (10). uninit 
    pCdpPipe->uninit(); 
    // (11). destory instance 
    pCdpPipe->destroyInstance(); 

    char filename[256]; 
    sprintf(filename, "/data/disp%dx%d.yuv", width, height);     
    saveBufToFile(filename, reinterpret_cast<MUINT8*>(rDispMem.virtAddr), width * height * 2); 
    deallocMem(rDispMem); 
    sprintf(filename, "/data/vdo%dx%d.yuv", 320, 240);     
    saveBufToFile(filename, reinterpret_cast<MUINT8*>(rVdoMem.virtAddr), 320 * 240 * 2); 
    deallocMem(rVdoMem); 

    //
    return 0; 
}