Since it's a get()
call, I assume you're failing here:
ByteBuffer buffer = outputBuffers[outBufIndex];
buffer.get(decodedBuffer);
If you look at the CTS EncodeDecodeTest, which works with raw YUV data, you'll see an extra bit:
ByteBuffer outputFrame = decoderOutputBuffers[decoderStatus];
outputFrame.position(info.offset);
outputFrame.limit(info.offset + info.size);
The MediaCodec
code doesn't read or update the ByteBuffer
state, so you have to do it explicitly. This applies to the input side too.
The buffer-to-buffer and buffer-to-surface portions of EncodeDecodeTest will work with API 16, and are useful to examine. The surface-to-surface tests require API 18.
One thing you'll find is that the test doesn't extracting the buffer contents to a fixed-size array, because the decoded size of the frame is not knowable statically. You need to know the color-format of the output, and that will vary from one device to another. You'll also find that checkFrame()
gives up entirely on some devices because it doesn't understand the frame format.
If you can decode to a Surface, your code can work like checkSurfaceFrame()
instead, where you don't care about the buffer format because OpenGL ES does all the work. See also ExtractMpegFramesTest.