stagefright 架构分析(五) 初始化 VideoDecoder
来源:互联网 发布:原油钻井数据 编辑:程序博客网 时间:2024/05/12 09:40
VideoDecoder的初始化实际就是OMX的创建,Stagefright提供了OMX的封装OMXCodec
在平台上stagefright -l 可以看到所有的组件
VideoDecoder的创建流程
status_t AwesomePlayer::initVideoDecoder(uint32_t flags) {
//最重要的创建mVideoSource
sp<MediaSource> decoder = OMXCodec::Create(
mClient.interface(), mVideoTrack->getFormat(),
false, // createEncoder
mVideoTrack,
NULL, flags, USE_SURFACE_ALLOC ? mNativeWindow : NULL);
status_t err = mVideoSource->start();
}
sp<MediaSource> OMXCodec::Create(
const sp<IOMX> &omx,
const sp<MetaData> &meta, bool createEncoder,
const sp<MediaSource> &source,
const char *matchComponentName,
uint32_t flags,
const sp<ANativeWindow> &nativeWindow) {
//得到MediaExtractor解析的MIME
bool success = meta->findCString(kKeyMIMEType, &mime);
//找到对应的decoder name
findMatchingCodecs(
mime, createEncoder, matchComponentName, flags,
&matchingCodecs, &matchingCodecQuirks);
//可能会找到多个匹配的codec
for (size_t i = 0; i < matchingCodecs.size(); ++i) {
//得到对应的component name
const char *componentNameBase = matchingCodecs[i].string();
//创建软件codec
softwareCodec = InstantiateSoftwareDecoder(componentName, source);
//根据component name创建OMX NODE
status_t err = omx->allocateNode(componentName, observer, &node);
//创建OMXCodec
sp<OMXCodec> codec = new OMXCodec(
omx, node, quirks, flags,
createEncoder, mime, componentName,
source, nativeWindow);
observer->setCodec(codec);
//根据meta配置codec
err = codec->configureCodec(meta);
//最终返回的是OMXCodec
return codec;
}
如何找到对应的codec name?
void OMXCodec::findMatchingCodecs(
const char *mime,
bool createEncoder, const char *matchComponentName,
uint32_t flags,
Vector<String8> *matchingCodecs,
Vector<uint32_t> *matchingCodecQuirks) {
//得到codec list
const MediaCodecList *list = MediaCodecList::getInstance();
for (;;) {
//从list中找到一个对应的codec name
ssize_t matchIndex =
list->findCodecByType(mime, createEncoder, index);
if (matchIndex < 0) {
break;
}
//找到后,就从找到的index的下一个继续查找
index = matchIndex + 1;
//得到ComponentName,并把其放到matchingCodecs中
const char *componentName = list->getCodecName(matchIndex);
matchingCodecs->push(String8(componentName));
}
}
MediaCodecList是怎么创建的?
Mutex::Autolock autoLock(sInitMutex);
if (sCodecList == NULL) {
sCodecList = new MediaCodecList;
}
return sCodecList->initCheck() == OK ? sCodecList : NULL;
}
: mInitCheck(NO_INIT) {
FILE *file = fopen("/etc/media_codecs.xml", "r");
if (file == NULL) {
ALOGW("unable to open media codecs configuration xml file.");
return;
}
parseXMLFile(file);
if (mInitCheck == OK) {
// These are currently still used by the video editing suite.
addMediaCodec(true /* encoder */, "AACEncoder", "audio/mp4a-latm");
addMediaCodec(
false /* encoder */, "OMX.google.raw.decoder", "audio/raw");
Vector<AString> QcomAACQuirks;
QcomAACQuirks.push(AString("requires-allocate-on-input-ports"));
QcomAACQuirks.push(AString("requires-allocate-on-output-ports"));
addMediaCodec(false, "OMX.qcom.audio.decoder.multiaac",
"audio/mp4a-latm", getCodecSpecificQuirks(QcomAACQuirks));
}
OMXCodec::Create中的OMX是哪来的?
public:
OMXClient();
status_t connect();
void disconnect();
sp<IOMX> interface() {
return mOMX;
}
private:
sp<IOMX> mOMX;
OMXClient(const OMXClient &);
OMXClient &operator=(const OMXClient &);
};
mOMX = service->getOMX();
Mutex::Autolock autoLock(mLock);
if (mOMX.get() == NULL) {
mOMX = new OMX;
}
return mOMX;
}
OMX如何创建codec对应的component
const char *name, const sp<IOMXObserver> &observer, node_id *node) {
//得到实际的ComponentInstance
name, &OMXNodeInstance::kCallbacks,
instance, &handle);
const char *name,
const OMX_CALLBACKTYPE *callbacks,
OMX_PTR appData,
OMX_COMPONENTTYPE **component) {
//根据name得到list中的index
ssize_t index = mPluginByComponentName.indexOfKey(String8(name));
//得到对应的plugin
OMXPluginBase *plugin = mPluginByComponentName.valueAt(index);
//创建ComponentInstance
plugin->makeComponentInstance(name, callbacks, appData, component);
if (err != OMX_ErrorNone) {
return err;
}
mPluginByInstance.add(*component, plugin);
return err;
}
codec 参数配置
ESDS esds((const char *)data, size);
CHECK_EQ(esds.InitCheck(), (status_t)OK);
const void *codec_specific_data;
size_t codec_specific_data_size;
esds.getCodecSpecificInfo(
&codec_specific_data, &codec_specific_data_size);
meta->findCString(kKeyMIMEType, &mime_type);
if (strncmp(mime_type, MEDIA_MIMETYPE_AUDIO_MPEG, 10)) {
addCodecSpecificData(
codec_specific_data, codec_specific_data_size);
}
int32_t numChannels, sampleRate;
CHECK(meta->findInt32(kKeyChannelCount, &numChannels));
CHECK(meta->findInt32(kKeySampleRate, &sampleRate));
setAC3Format(numChannels, sampleRate);
}
&& !mIsEncoder
&& !strncasecmp(mMIME, "video/", 6)
&& !strncmp(mComponentName, "OMX.", 4)) {
status_t err = initNativeWindow();
if (err != OK) {
return err;
}
}
- stagefright 架构分析(五) 初始化 VideoDecoder
- [StageFright分析] StageFright的总体架构
- stagefright 架构分析(一) stagefright 介绍
- stagefright 架构分析(二) TimedEventQueue
- stagefright 架构分析(四) MediaExtractor
- stagefright 架构分析(三) stagefright 功能和调用流程
- stagefright架构
- stagefright 架构分析(六) 创建一个 Soft Decoder
- stagefright 架构分析(七) 动态加载libstagefrighthw.so
- mips架构linux启动分析(五)(bootmem和blockmem机制的初始化)(prom_init_numa_memory)
- stagefright extactor 分析
- Android Stagefright MPEG4Extractor分析
- Android Stagefright MPEG4Extractor分析
- Android Stagefright MPEG4Writer分析
- stagefright 源码分析
- Android Stagefright MPEG4Writer分析
- Android Stagefright MPEG4Extractor分析
- Android Stagefright MPEG4Extractor分析
- 我父亲是一个收棒子的
- .net4.0本地缓存
- javaWeb_14-request实现请求转发和mvc设计模式
- 合理使用搜索引擎更重要
- 提升HBase写性能
- stagefright 架构分析(五) 初始化 VideoDecoder
- NOR flash和NAND flash区别,RAM 和ROM区别
- VC编译选项MT,MTd..
- Linux patch补丁
- 腾讯微信技术架构
- ubuntu窗口最小化消失,任务栏上无法找到的解决方法
- speex开源库的编译与简要介绍
- 云计算总体架构及其应用与商业模式探讨
- python 火车票订票系统(12306)