Ejemplo n.º 1
0
MBOOL
JpegCodec::
allocYuvMem(IImageBuffer **pBuf, MSize const & imgSize, int const format) 
{
    MUINT32 bufStridesInBytes[3] = {0};

using namespace NSCam::Utils::Format; 
    for (int i = 0; i < (int)queryPlaneCount(format); i++)
    { 
        bufStridesInBytes[i] = 
            (queryPlaneWidthInPixels(format,i, imgSize.w) * queryPlaneBitsPerPixel(format,i)) >> 3;
    }

    MINT32 bufBoundaryInBytes[3] = {0, 0, 0};
    //
    IImageBufferAllocator* allocator = IImageBufferAllocator::getInstance();
    IImageBufferAllocator::ImgParam imgParam(
        format, imgSize, bufStridesInBytes, bufBoundaryInBytes, Utils::Format::queryPlaneCount(format)
    );

    *pBuf = allocator->alloc_ion("allocYuvBuf", imgParam);
    if  ( *pBuf == 0 )
    {
        CAM_LOGE("NULL YUV Buffer\n");
        return  MFALSE;
    }
    //
    MY_LOGD("<YUV> ImgBitsPerPixel:%d BufSizeInBytes:%d", (*pBuf)->getImgBitsPerPixel(), (*pBuf)->getBufSizeInBytes(0));
    return  MTRUE;
}
Ejemplo n.º 2
0
static
MVOID allocImageBuffer(sp<IImageBuffer> * pImageBuffer, MUINT32 w, MUINT32 h, MUINT32 fmt)
{
    printf("alloc ImageBuffer %dx%d, fmt 0x%x\n", w, h, fmt);
    IImageBufferAllocator* allocator = IImageBufferAllocator::getInstance();
    sp<IImageBuffer> pBuf;
    //allocate buffer

    MUINT32 bufStridesInBytes[3] = {0};
    MUINT32 plane = queryPlaneCount(fmt);

    for (MUINT32 i = 0; i < plane; i++)
    {
        bufStridesInBytes[i] = 
            (queryPlaneWidthInPixels(fmt,i, w) * queryPlaneBitsPerPixel(fmt,i)) >> 3;
    }

    MINT32 bufBoundaryInBytes[3] = {0, 0, 0};
    //
    IImageBufferAllocator::ImgParam imgParam(
            fmt, MSize(w,h), bufStridesInBytes, bufBoundaryInBytes, plane
            );

    *pImageBuffer = allocator->alloc_ion(LOG_TAG, imgParam);
    if  ( pImageBuffer->get() == 0 )
    {
        MY_LOGE("NULL Buffer\n");
    }

    if ( !pImageBuffer->get()->lockBuf( LOG_TAG, eBUFFER_USAGE_SW_MASK | eBUFFER_USAGE_HW_MASK ) )
    {
        MY_LOGE("lock Buffer failed\n");
    }
}
Ejemplo n.º 3
0
MBOOL
JpegCodec::
freeYuvMem(IImageBuffer **pBuf) 
{
    IImageBufferAllocator* allocator = IImageBufferAllocator::getInstance();
    allocator->free(*pBuf);
    *pBuf = NULL;
    return  MTRUE;
}
Ejemplo n.º 4
0
MBOOL 
CapPass2::
freeMemory(sp<IImageBuffer>& targetBuf)
{
    MBOOL ret = MFALSE;
    if( targetBuf.get() != NULL ) {
        IImageBufferAllocator* allocator = IImageBufferAllocator::getInstance();
        if( !targetBuf->unlockBuf( LOG_TAG ) )
        {
            MY_LOGE("unlock Buffer failed\n");
            goto lbExit;
        }
        allocator->free(targetBuf.get());
        targetBuf = NULL;
    }

    ret = MTRUE;
lbExit:
    return ret;
}
Ejemplo n.º 5
0
MBOOL 
CapPass2::
allocMemory(IImageBuffer* srcbuf, MINT32 const fmt, sp<IImageBuffer>& targetBuf)
{
    MBOOL ret = MTRUE;
    // allocate internal memory
    IImageBufferAllocator* allocator = IImageBufferAllocator::getInstance();
    if( allocator == NULL ) {
        MY_LOGE("cannot get allocator");
        return MFALSE;
    }

    MSize const size = srcbuf->getImgSize();
    MUINT const planecount = queryPlaneCount(fmt);
    MINT32 bufBoundaryInBytes[3] = {0, 0, 0};
    MUINT32 bufStridesInBytes[3];

    if( fmt == eImgFmt_BAYER8  ||
        fmt == eImgFmt_BAYER10 ||
        fmt == eImgFmt_BAYER12 ||
        fmt == eImgFmt_BAYER14 )
    {
        for (MUINT i = 0; i < planecount; i++)
        {
            bufStridesInBytes[i] = srcbuf->getBufStridesInBytes(i);
        }
    }
    else
    {
        for (MUINT i = 0; i < planecount; i++)
        {
            bufStridesInBytes[i] = 
                (queryPlaneWidthInPixels(fmt,i, size.w)*queryPlaneBitsPerPixel(fmt,i))>>3;
        }
    }

    MY_LOGD("alloc %d x %d, fmt 0x%x", size.w, size.h, fmt);
    IImageBufferAllocator::ImgParam imgParam(
            fmt, 
            size,
            bufStridesInBytes, 
            bufBoundaryInBytes, 
            planecount
            );

    targetBuf = allocator->alloc_ion(LOG_TAG, imgParam);

    if( targetBuf.get() == NULL )
    {
        MY_LOGE("failed to allocate memory");
        goto lbExit;
    }

    if ( !targetBuf->lockBuf( LOG_TAG, eBUFFER_USAGE_SW_MASK | eBUFFER_USAGE_HW_MASK ) )
    {
        MY_LOGE("lock Buffer failed\n");
        goto lbExit;
    }

    if ( !targetBuf->syncCache( eCACHECTRL_INVALID ) )
    {
        MY_LOGE("syncCache failed");
        goto lbExit;
    }

    ret = MTRUE;
lbExit:
    return ret;
}
Ejemplo n.º 6
0
void
Test_ImageBufferAllocator()
{
    CAM_LOGD("++++++++++++++++ Test_ImageBufferAllocator ++++++++++++++++");
    //
    //
    size_t bufStridesInBytes[3] = {2000, 1920, 960};
    size_t bufBoundaryInBytes[3] = {0, 0, 0};
    IImageBufferAllocator::ImgParam imgParam(
        eImgFmt_YV12, MSize(1920, 1080), 
        bufStridesInBytes, bufBoundaryInBytes, 3
    );
    //
    MUINT32 size = 2048;
    IImageBufferAllocator::ImgParam imgParam_blob(size, 0);
    //
    MUINT32 buffer_size = 1280*720;
    IImageBufferAllocator::ImgParam imgParam_jpeg(
        MSize(1280, 720), buffer_size, 0
    );
    //
    //// raw pointer
    {
        //
        IImageBufferAllocator *allocator = IImageBufferAllocator::getInstance();
        //
        //// blob
        IImageBuffer* pImgBuf_blob = allocator->alloc("Test_Allocator_raw_blob", imgParam_blob);
        OBJ_CHECK(pImgBuf_blob);
        test_imgbuf_blob(pImgBuf_blob->getMagicName(), pImgBuf_blob, size);
        allocator->free(pImgBuf_blob);
        //
        //// yuv 3p
        IImageBuffer* pImgBuf = allocator->alloc("Test_Allocator_raw_yuv3p", imgParam);
        OBJ_CHECK(pImgBuf);
        test_imgbuf_yuv420_3p(pImgBuf->getMagicName(), pImgBuf, imgParam);
        allocator->free(pImgBuf);
        //
        //// jpeg 1p
        IImageBuffer* pImgBuf_jpeg = allocator->alloc("Test_Allocator_raw_jpeg1p", imgParam_jpeg);
        OBJ_CHECK(pImgBuf_jpeg);
        test_imgbuf_jpeg_1p(pImgBuf_jpeg->getMagicName(), pImgBuf_jpeg, imgParam_jpeg);
        //
        MY_CHECK(buffer_size==pImgBuf_jpeg->getBitstreamSize(), "%d", pImgBuf_jpeg->getBitstreamSize());
        MY_CHECK(!pImgBuf_jpeg->setBitstreamSize(7200000), "can not setBitstreamSize()");
        MY_CHECK(buffer_size==pImgBuf_jpeg->getBitstreamSize(), "%d", pImgBuf_jpeg->getBitstreamSize());
        MY_CHECK(pImgBuf_jpeg->setBitstreamSize(720000), "can setBitstreamSize()");
        MY_CHECK(720000==pImgBuf_jpeg->getBitstreamSize(), "%d", pImgBuf_jpeg->getBitstreamSize());
        allocator->free(pImgBuf_jpeg);
        //
    }
    //
    //// strong pointer
    {
        //
        IImageBufferAllocator *allocator = IImageBufferAllocator::getInstance();
        //
        //// blob
        sp<IImageBuffer> spImgBuf_blob = allocator->alloc("Test_Allocator_sp_blob", imgParam_blob);
        OBJ_CHECK(spImgBuf_blob);
        allocator->free(spImgBuf_blob.get());
        test_imgbuf_blob(spImgBuf_blob->getMagicName(), spImgBuf_blob.get(), size);
        //
        //// yuv 3p
        sp<IImageBuffer> spImgBuf = allocator->alloc("Test_Allocator_sp_yuv3p", imgParam);
        OBJ_CHECK(spImgBuf);
        allocator->free(spImgBuf.get());
        test_imgbuf_yuv420_3p(spImgBuf->getMagicName(), spImgBuf.get(), imgParam);
        //
    }

    //
    CAM_LOGD("---------------- Test_ImageBufferAllocator ----------------");
}