【Android多媒体】Android5.0 NuPlayer多媒体框架【1】

时间:2021-04-14 20:34:40

Android流媒体框架在Gingerbread Android2.3版本的时候加入的,其中实现的核心就是NuPlayer。在之前的版本中一般认为Local Playback就用Stagefrightplayer+Awesomeplayer,流媒体用NuPlayer。从现在来看,NuPlayer大有替换掉StagefrightPlayer+AwesomePlayer的趋势,现在NuPlayer也可以完美地实现本地播放。

在实现上NuPlayer和Awesomeplayer不同,NuPlayer基于StagefrightPlayer的基础类构建,利用了更底层的ALooper/AHandler机制来异步地处理请求,ALooper列队消息请求,AHandler中去处理,所以有更少的Mutex/Lock在NuPlayer中。AHnadler机制请参考前面的一篇文章,AHandler机制
Awesomeplayer中利用了omxcodec而NuPlayer中利用了Acodec。

Android流媒体在5.0上资源文件主要分为HTTPLiveSource、RTSPSource GenericSource,其中GenericSource是4.1版本加入的。其中RTSP和HLS流是最主要的,两者本别基于RTSP协议和HLS协议。
【Android多媒体】Android5.0 NuPlayer多媒体框架【1】
NuPlayer整体架构图

NuPlayer::Source is the parser module. Actually its interface looks like a combination of MediaExtractor and MediaSource, and it also makes seekTo as an explicit API now.

NuPlayer::Decoder connects to ACodec for AVC decoding, and to DecoderWrapper for AAC decoding, which in turn wrapps AAC software decoder in the OpenMAX style. ACodec is functionally similar as OMXCodec in Stagefright, besides the application of State pattern and passing MediaBuffers around with messages.

NuPlayer::Render is responsible for rendering audio and also controls when to post video buffers back to NativeWindow for A/V sync.