Access StageFright.so directly to decode H.264 stream from JNIlayer in Android

こ雲淡風輕ζ 提交于 2019-11-29 00:17:01

If your objective is to decode an elementary H.264 stream, then your code will have to ensure that the stream is extracted, the codec-specific-data is provided to the codec which is primarily SPS and PPS data and frame data along with time-stamps is provided to the codec. Across all Android versions, the most common interface would be OMXCodec which is an abstraction over an underlying OMX component.

In Gingerbread (Android 2.3) and ICS (Android 4.0.0), if you would like to create a decoder, the best method would be to create an OMXCodec component and abstract your code through a MediaSource interface i.e. your wrapper code is modeled as MediaSource and OMXCodec reads from this source and performs the decoding.

Link to Android 2.3 Video decoder creation: http://androidxref.com/2.3.6/xref/frameworks/base/media/libstagefright/AwesomePlayer.cpp#1094

Link to Android 4.0.0 Video decoder creation: http://androidxref.com/4.0.4/xref/frameworks/base/media/libstagefright/AwesomePlayer.cpp#1474

The main challenges would be the following:

  1. Model the input as a MediaSource.

  2. Read a wrapper code to read the buffer from the codec and handle the same and release it back to the codec.

For simplification, you could look stagefright command line executable code as in http://androidxref.com/4.0.4/xref/frameworks/base/cmds/stagefright/stagefright.cpp#233

However, if your program is based on JellyBean (Android 4.1.x, 4.2.x) onwards, then these are slightly more simplified. From your JNI code, you could create a MediaCodec component and employ the same for decoding. To integrate the same into your program, you could refer to the SimplePlayer implementation as in http://androidxref.com/4.2.2_r1/xref/frameworks/av/cmds/stagefright/SimplePlayer.cpp#316

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!