From the MediaBuffer
, I feel that the following should be functional. I haven't tried the same yet and have worked with rg2's solution i.e. directly based on gralloc
handle, but feel that the following should also be functional.
sp<GraphicBuffer> mCurrGraphicBuffer;
void *vaddr;
err = source->read(&buffer, &options); // Where buffer is of MediaBuffer type
mCurrGraphicBuffer = buffer->graphicBuffer();
width = mCurrGraphicBuffer->getWidth();
height = mCurrGraphicBuffer->getWidth();
format = mCurrGraphicBuffer->getFormat();
mCurrGraphicBuffer->lock(GRALLOC_USAGE_SW_READ_OFTEN, &vaddr);
//Dump the YUV file based on the vaddr, width, height, format
mCurrGraphicBuffer->unlock();
EDIT:
In order for the aforementioned solution to work, the actual GraphicBuffer
should be created or allocated with appropriate usage flags i.e. the buffer should be created with a hint that CPU would be accessing the same. Else, -EINVAL
would be returned as per the documentation in gralloc
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…