以下代码流程为一个媒体文件解码时找到对应插件的流程:
函数 status_t NuPlayer::instantiateDecoder(boolaudio, sp<DecoderBase> *decoder) 函数初始化创建解码器
status_t NuPlayer::instantiateDecoder(boolaudio, sp<DecoderBase> *decoder) {
if (*decoder != NULL) {
return OK;
}
……
if (audio) {
sp<AMessage> notify = new AMessage(kWhatAudioNotify, id());
++mAudioDecoderGeneration;
notify->setInt32("generation", mAudioDecoderGeneration);
if (mOffloadAudio) {
*decoder = new DecoderPassThrough(notify, mSource, mRenderer);
} else {
*decoder = new Decoder(notify, mSource, mRenderer);
}
}else {
sp<AMessage> notify = new AMessage(kWhatVideoNotify, id());
++mVideoDecoderGeneration;
notify->setInt32("generation", mVideoDecoderGeneration);
*decoder = new Decoder(
notify, mSource, mRenderer,mNativeWindow, mCCDecoder);
// enable FRC if high-quality AV sync isrequested, even if not
// queuing to native window, as this will even improve textureview
// playback.
{
char value[PROPERTY_VALUE_MAX];
if (property_get("persist.sys.media.avsync", value, NULL)&&
(!strcmp("1",value) || !strcasecmp("true", value))) {
format->setInt32("auto-frc", 1);
}
}
}
if (mPlayerExtendedStats != NULL) {
format->setObject(MEDIA_EXTENDED_STATS, mPlayerExtendedStats);
}
(*decoder)->init();
(*decoder)->configure(format, mIsStreaming);
……
……
}
void NuPlayer::DecoderBase::configure(constsp<AMessage> &format, bool isStreaming) {
sp<AMessage> msg = new AMessage(kWhatConfigure, id());
msg->setMessage("format", format);
msg->setInt32("isStreaming", isStreaming);
sp<AMessage> response;
PostAndAwaitResponse(msg, &response);
}
voidNuPlayer::DecoderBase::onMessageReceived(const sp<AMessage> &msg) {
switch (msg->what()) {
case kWhatConfigure:
{
uint32_t replyID;
CHECK(msg->senderAwaitsResponse(&replyID));
sp<AMessage> format;
uint32_t isStreaming;
CHECK(msg->findMessage("format", &format));
CHECK(msg->findInt32("isStreaming", (int32_t*)&isStreaming));
onConfigure(format