android-ndkffmpeghardware-accelerationstagefright

H264 HW accelerated decoding in Android using stagefright library


I`m trying to decode h264 video using HW with Stagefright library.

i have used an example in here. Im getting decoded data in MedaBuffer. For rendering MediaBuffer->data() i tried AwesomeLocalRenderer in AwesomePlayer.cpp.

but picture in screen are distorted

Here is The Link of original and crashed picture.

And also tried this in example`

sp<MetaData> metaData = mVideoBuffer->meta_data();
int64_t timeUs = 0;
metaData->findInt64(kKeyTime, &timeUs);
native_window_set_buffers_timestamp(mNativeWindow.get(), timeUs * 1000);
err = mNativeWindow->queueBuffer(mNativeWindow.get(), 
mVideoBuffer->graphicBuffer().get(), -1);`

But my native code crashes. I can`t get real picture its or corrupted or it black screen.

Thanks in Advance.


Solution

  • If you are using a HW accelerated decoder, then the allocation on the output port of your component would have been based on a Native Window. In other words, the output buffer is basically a gralloc handle which has been passed by the Stagefright framework. (Ref: OMXCodec::allocateOutputBuffersFromNativeWindow). Hence, the MediaBuffer being returned shouldn't be interpreted as a plain YUV buffer.

    In case of AwesomeLocalRenderer, the framework performs a software color conversion when mTarget->render is invoked as shown here. If you trace the code flow, you will find that the MediaBuffer content is directly interpreted as YUV buffer.

    For HW accelerated codecs, you should be employing AwesomeNativeWindowRenderer. If you have any special conditions for employing AwesomeLocalRenderer, please do highlight the same. I can refine this response appropriately.

    P.S: For debug purposes, you could also refer to this question which captured the methods to dump the YUV data and analyze the same.