Android MultiMedia框架——mediaserver启动
Posted VNanyesheshou
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android MultiMedia框架——mediaserver启动相关的知识,希望对你有一定的参考价值。
基于Andorid9.0源码
一 mediaserver进程
mediaserver进程由mediaserver.rc文件启动
mediaserver.rc文件
service media /system/bin/mediaserver
class main
user media
group audio camera inet net_bt net_bt_admin net_bw_acct drmrpc mediadrm
ioprio rt 4
writepid /dev/cpuset/foreground/tasks /dev/stune/foreground/tasks
目录frameworks/av/media/mediaserver
main_mediaserver.cpp对应入口,main函数
int main(int argc __unused, char **argv __unused)
signal(SIGPIPE, SIG_IGN);
sp<ProcessState> proc(ProcessState::self());
sp<IServiceManager> sm(defaultServiceManager());
ALOGI("ServiceManager: %p", sm.get());
InitializeIcuOrDie();
MediaPlayerService::instantiate();
ResourceManagerService::instantiate();
registerExtensions();
ProcessState::self()->startThreadPool();
IPCThreadState::self()->joinThreadPool();
- 创建ProcessState对象,开启binder驱动,分配内存供后续传输数据;
- 创建IServiceManager对象。通过这个对象,可以与servicemanager进行跨进程通信。
- InitializeIcuOrDie 初始化icu, icu是对应icu4C国际化库
- 创建MediaPlayerService,并初始化
- 创建并初始化ResourceManagerService
- startThreadPool -》启动binder线程池
- joinThreadPool-》把主线程加入到线程池中
二 MediaPlayerService
MediaPlayerService该服务负责管理MediaRecorder和MediaPlayer的创建、销毁,具体录像和播放由MediaRecorderClient、MediaPlayerService::Client等实现
目录frameworks/av/media/libmediaplayerservice/
void MediaPlayerService::instantiate()
defaultServiceManager()->addService(
String16("media.player"), new MediaPlayerService());
MediaPlayerService::MediaPlayerService()
mNextConnId = 1;
MediaPlayerFactory::registerBuiltinFactories();
MediaPlayerService::instantiate过程
- 创建MediaPlayerService对象;
- 将服务注册到ServiceManager中,服务名称为“media.player”,便于其他进程使用该服务;
接着看MediaPlayerFactory::registerBuiltinFactories()
void MediaPlayerFactory::registerBuiltinFactories()
Mutex::Autolock lock_(&sLock);
if (sInitComplete)
return;
IFactory* factory = new NuPlayerFactory();
if (registerFactory_l(factory, NU_PLAYER) != OK)
delete factory;
factory = new TestPlayerFactory();
if (registerFactory_l(factory, TEST_PLAYER) != OK)
delete factory;
sInitComplete = true;
创建NuPlayerFactory、TestPlayerFactory对象,分别添加注册到FactoryMap中。
NuPlayerFactory、TestPlayerFactory工厂类,用于创建Player
以上是关于Android MultiMedia框架——mediaserver启动的主要内容,如果未能解决你的问题,请参考以下文章
Android MultiMedia框架——OMXPlugin
Android MultiMedia框架——ACodec加载OMX
Android MultiMedia框架——ALooper AHandler AMessage
Android MultiMedia框架——MediaCodec编码(下)