在Android4.1以后google就提供了MediaCodec这个类来为用户提供音视频的编码解码功能(虽然支持的格式不是很多)。
对于MediaCodec类,我们需要大致介绍一下:
官网提供的概述:
In broad terms, a codec processes input data to generate output data. It processes data asynchronously and uses a set of input and output buffers. At a simplistic level, you request (or receive) an empty input buffer, fill it up with data and send it to the codec for processing. The codec uses up the data and transforms it into one of its empty output buffers. Finally, you request (or receive) a filled output buffer, consume its contents and release it back to the codec.
大致的意思是:MediaCodec处理输入数据然后产生输出数据,它异步处理数据,使用了一组输入和输入缓存。你请求到了一个空的输入缓存,将数据填满后,发送给编解码器进行处理。编解码器处理完后,将处理的结果输出到一个空的输出缓存中,我们能请求到这个输出缓存,并将缓存的数据使用。
MediaCode可以处理的数据类型:(1)压缩后的数据(2)原始音频数据(3)原始视频数据
再来了解一下它的状态:
从这个图中我们可以知道:MediaCodec有三种状态(1)Stopped 停止(2)Released释放(3)Executing执行
(1)Stopped停止状态:Error,Uninitialized,configured
(2)