Android多媒体——MediaPlayer中Binder通信(五)

        上一篇文章通过 setDataSource() 函数的调用流程分析了 MediaPlayer 中的 C/S 架构,这里我们继续来分析 MediaPlayer 中的 Binder 通信机制。

一、Binder机制实现

  MediaPlayerService 中涉及到的 Binder 机制相关代码如下:

class BpMediaPlayerService: public BpInterface 
class BnMediaPlayerService: public BnInterface 
class IMediaPlayerService: public IInterface

        IMediaPlayerService 类中定义了 MediaPlayerService 中能够提供的服务函数,这个接口类定义在 IMediaPlayerService.h 中,并且需要通过 DECLARE_META_INTERFACE 宏来声明 asInterface() 这个函数。该函数又与 interface_cast() 相关联,而 interface_cast() 函数能够通过 asInterface() 函数创建一个 BpMediaPlayerService。当然,具体实现是在 asInterface() 函数中完成的,而 asInterface() 函数的实现是在 IMPLEMENT_META_INTE

你可能感兴趣的:(Android多媒体,android,多媒体)