Android4.0.1中各个Player的功能

时间:2021-06-28 13:34:55

1. Android4.0.1中默认定义了4个真正的Player,具体情况如下:

static sp<MediaPlayerBase> createPlayer(player_type playerType, void* cookie,
notify_callback_f notifyFunc)
{
sp<MediaPlayerBase> p;
switch (playerType) {
case SONIVOX_PLAYER:
LOGV(" create MidiFile");
p = new MidiFile();
break;
case STAGEFRIGHT_PLAYER:
LOGV(" create StagefrightPlayer");
p = new StagefrightPlayer;
break;
case NU_PLAYER:
LOGV(" create NuPlayer");
p = new NuPlayerDriver;
break;
case TEST_PLAYER:
LOGV("Create Test Player stub");
p = new TestPlayerStub();
break;
default:
LOGE("Unknown player type: %d", playerType);
return NULL;
}
if (p != NULL) {
if (p->initCheck() == NO_ERROR) {
p->setNotifyCallback(cookie, notifyFunc);
} else {
p.clear();
}
}
if (p == NULL) {
LOGE("Failed to create player object");
}
return p;
}


2. 每个Player的专长是什么呢?

Player Type Feature Description
TEST_PLAYER url以test:开始的。如test:xxx
NU_PLAYER url以http://或https://开始的,且url以.m3u8结束或url中包含有m3u8字符串
SONIVOX_PLAYER 处理url中扩展名为:.mid,.midi,.smf,.xmf,.imy,.rtttl,.rtx,.ota的媒体文件
STAGEFRIGHT_PLAYER 它是一个大好人,前面三位不能处理的都交给它来处理,不知能力是否有如此强大

以上言论以代码为证,获取player type的代码如下:

player_type getPlayerType(const char* url)
{
if (TestPlayerStub::canBeUsed(url)) {
return TEST_PLAYER;
}

if (!strncasecmp("http://", url, 7)
|| !strncasecmp("https://", url, 8)) {
size_t len = strlen(url);
if (len >= 5 && !strcasecmp(".m3u8", &url[len - 5])) {
return NU_PLAYER;
}

if (strstr(url,"m3u8")) {
return NU_PLAYER;
}
}

// use MidiFile for MIDI extensions
int lenURL = strlen(url);
for (int i = 0; i < NELEM(FILE_EXTS); ++i) {
int len = strlen(FILE_EXTS[i].extension);
int start = lenURL - len;
if (start > 0) {
if (!strncasecmp(url + start, FILE_EXTS[i].extension, len)) {
return FILE_EXTS[i].playertype;
}
}
}

return getDefaultPlayerType();
}

如果你想增加自己的player,以上两个函数都需要修改。

现在对整个媒体系统基本上有一个清晰的框架了,就突发奇想,到底在StagefrightPlayer如何增加自己的硬件解码呢? 很好奇,想一探究竟...