echo zeng

camera v or h flip with gpu(g2d)

Discussion created by echo zeng on Feb 6, 2017
Latest reply on Feb 7, 2017 by echo zeng

Dear all,

      I want to flip camera stream with g2d api when preview,but it does not work. where is wrong with my test code?

      I add g2d_blit test code in function processFrame in preivewStream.cpp, blow is my test code:

      

int PreviewStream::processFrame(CameraFrame *frame)
{
status_t ret = NO_ERROR;
#if 1
struct g2d_buf s_buf, d_buf;
struct g2d_surface src,dst;
int width,height;
int size;
int g2d_ret = 0;
#endif
if (mShowFps) {
showFps();
}
ret = renderBuffer(frame);
if (ret != NO_ERROR) {
FLOGE("%s renderBuffer failed", __FUNCTION__);
goto err_exit;
}
//the frame held in service.
frame->addReference();

StreamBuffer buffer;
ret = requestBuffer(&buffer);

if (ret != NO_ERROR) {
FLOGE("%s requestBuffer failed", __FUNCTION__);
goto err_exit;
}
#if 1
FLOG_TRACE("%s nwidth=%d, nheight:%d format:%d", __FUNCTION__, buffer.mWidth, buffer.mHeight,buffer.mFormat);
width = 720;
height = 576;
size = (frame->mSize > buffer.mSize) ? buffer.mSize : frame->mSize;
FLOG_TRACE("mSize=%d, size=%d", buffer.mSize,size);
FLOG_TRACE("f mPhyAddr=0x%08x, b mPhyAddr=0x%08x", frame->mPhyAddr, buffer.mPhyAddr);
FLOG_TRACE("f mPhyAddr=0x%08x, b mVirtAddr=0x%08x", frame->mVirtAddr, buffer.mVirtAddr);
s_buf.buf_paddr = frame->mPhyAddr;
s_buf.buf_vaddr = frame->mVirtAddr;
d_buf.buf_paddr = buffer.mPhyAddr;
d_buf.buf_vaddr = buffer.mVirtAddr;
g2d_ret = g2d_copy(g2dHandle, &d_buf, &s_buf, size);
if(g2d_ret){
FLOG_TRACE("g2d_copy fail!");
}
src.planes[0] = s_buf.buf_paddr;
//src.planes[1] = s_buf.buf_paddr+width+height;
//src.planes[2] = s_buf.buf_paddr+width+height*2;
src.left = 0;
src.top = 0;
src.right = width;
src.bottom = height;
src.stride = width;
src.width = width;
src.height = height;
src.format = G2D_RGBA8888;
src.rot = G2D_ROTATION_0;

dst.planes[0] = d_buf.buf_paddr;
dst.left = 0;
dst.top = 0;
dst.right = width;
dst.bottom = height;
dst.stride = width;
dst.width = width;
dst.height = height;
dst.format = G2D_RGBA8888;
dst.rot = G2D_FLIP_H;
g2d_ret = g2d_blit(g2dHandle, &src, &dst);
if(g2d_ret){
FLOG_TRACE("g2d_blit fail!");
}
g2d_finish(g2dHandle);
#endif

for (int i = 0; i < mTotalBuffers; i++) {
if (mCameraBuffer[i].mBufHandle == buffer.mBufHandle) {
//release frame from service.
mCameraBuffer[i].release();
break;
}
}

err_exit:
sem_post(&mRespondSem);

return ret;
}

Thanks!

Outcomes