Search code examples
androidandroid-mediacodec

Can MediaCodec.releaseOutputBuffer() be used to assess the success of decoding


Code largely following the MediaCodec sample is not generating video.
Instead of asking a general question, let me ask a specific one: Does it mean the decoding is working if MediaCodec.releaseOutputBuffer() return successfully without generating an exception. I am trying to determine whether the problem is attributed to the decoder or the surface setup.

MediaCodec.BufferInfo bi = new MediaCodec.BufferInfo();
int iOutputBufferIndex = _mcDecoder.dequeueOutputBuffer(bi, TIMEOUT_USEC);
if (iOutputBufferIndex == MediaCodec.INFO_TRY_AGAIN_LATER) {
    // no output available yet
} else if (iOutputBufferIndex == MediaCodec.INFO_OUTPUT_BUFFERS_CHANGED) {
    _bbDecoderOutputBuffers = _mcDecoder.getOutputBuffers();
 } else if (iOutputBufferIndex == MediaCodec.INFO_OUTPUT_FORMAT_CHANGED) {
    MediaFormat newFormat = _mcDecoder.getOutputFormat();
} else if (iOutputBufferIndex < 0) {
    //log error;
} else {
    //Can the following statement be used to assess the success of the decoding?  
    _mcDecoder.releaseOutputBuffer(iOutputBufferIndex, true);
}

Solution

  • The contents of the buffer tell you if decoding is working. Releasing the buffer just tells the system that you're done looking at it.

    If you configured a Surface for output, you will appear to get zero-byte buffers of data. The actual data is rendered to the Surface when the render flag is set (which you appear to have done). You won't see actual contents unless the Surface is tied to the UI somehow. (Note the current set of examples largely don't try to display anything.)

    If you didn't configure a Surface, you should see nonzero quantities of data in each output buffer you dequeue.

    Update from the chat session: OP was setting an opaque background on a SurfaceView. SurfaceView is actually a transparent window with the Surface layered behind it, so making it opaque obscured the video.