Search code examples
androidencodeandroid-mediacodec

Is it possible to malloc the Gralloc memory in Android Java layer?


I set the "csd-0" and "csd-1" into MediaCodec by MediaFormat as following:

byte[] sps = { 0, 0, 0, 1, 103, 100, 0, 40, -84, 52, -59, 1, -32, 17, 31, 120, 11, 80, 16, 16, 31, 0, 0, 3, 3, -23, 0, 0, -22, 96, -108 };
byte[] pps = { 0, 0, 0, 1, 104, -18, 60, -128 };
MediaFormat format = MediaFormat.createVideoFormat("video/avc", width, height);
format.setByteBuffer("csd-0", ByteBuffer.wrap(sps));
format.setByteBuffer("csd-1", ByteBuffer.wrap(pps));
...

But i got the error like this:

E/MtkOmxVenc( 6724): Error: BufferType is not Gralloc Source !!!!
F/libc    ( 6724): Fatal signal 11 (SIGSEGV) at 0x28006467 (code=1), thread 7500 (MtkOmxVencEncod)

So i want to try to set the Gralloc source to fix it. Any suggestions ?


Solution

  • gralloc is the memory allocator used to allocate graphics buffers. It's provided by a kernel driver. You pass in width, height, and color format, and it hands back a reference to a buffer with the necessary attributes, taking into account any platform-specific padding and alignment restrictions.

    The codec-specific data values should not be held in a gralloc buffer. The CTS EncodeDecodeTest does exercise setByteBuffer(), so I'd be surprised if it's entirely broken.

    My guess would be that MtkOmxVenc has a bug.