The Android platform includes native support for video codecs. When developing video applications for Android, it is recommended to use the platform tools available for fast and reliable operation. One of the tools is the MediaCodec API which is part of the Android NDK. This API provides generic methods that allow native libraries to use any of the video codecs supported by an Android device with minimal development work. Many devices implement video codecs in specialized hardware, and the MediaCodec API allows applications to use that hardware.
Using a codec through the MediaCodec API starts with creating an AMediaCodec object (create). An AMediaFormat object must also be created, and that is used to configure the codec (configure). After this, the codec can be started (start). Android MediaCodec codecs allocate all of their input and output buffers themselves. Once the codec is started, input buffers can be requested (getInputBuffer) and filled with input data. (The input data will be raw video frames for an encoder, and encoded bytes for a decoder.) After the buffer is filled, it is queued for processing (queueInputBuffer). The input buffers are processed asynchronously, so the user application can continue to run during processing. To get the output data, the user application can poll for output buffers (dequeueOutputBuffer). When an output buffer is ready, its data can be retrieved from the buffer and processed by the user application. Then the buffer is returned to the codec (releaseOutputBuffer). When the codec is no longer needed, it’s resources should be freed (delete).