很明显,这里首先是考虑厂商的OMX组件(从高通->TI->三星),然后才是自带的软解码的。
多媒体文件经过解析后,需要根据mime寻找适合的codec,2.3的系统有两种方式 SoftwareCodec和omx的node codec,后者可以结合特殊硬件做优化处理,前者感觉就是比较标准的软解码。
下面是代码
omxcodec.cpp
omxcodec::create
Vector<String8> matchingCodecs;------系统对于某种mime的所有codec集合
findMatchingCodecs(
mime, createEncoder, matchComponentName, flags, &matchingCodecs);
if (matchingCodecs.isEmpty()) {
return NULL;
}
sp<OMXCodecObserver> observer = new OMXCodecObserver;
IOMX::node_id node = 0;
const char *componentName;
for (size_t i = 0; i < matchingCodecs.size(); ++i) {--------去其中遍历所有的codec,一般是omx的node先,然后是软解码
componentName = matchingCodecs[i].string();
sp<MediaSource> softwareCodec = createEncoder?
InstantiateSoftwareEncoder(componentName, source, meta):
InstantiateSoftwareCodec(componentName, source);
if (softwareCodec != NULL) {
LOGV("Successfully allocated software codec '%s'", componentName);
return softwareCodec;-----------------是软解码-返回codec
}
LOGV("Attempting to allocate OMX node '%s'", componentName);
uint32_t quirks = getComponentQuirks(componentName, createEncoder);
if (!createEncoder
&& (quirks & kOutputBuffersAreUnreadable)
&& (flags & kClientNeedsFramebuffer)) {
if (strncmp(componentName, "OMX.SEC.", 8)) {
// For OMX.SEC.* decoders we can enable a special mode that
// gives the client access to the framebuffer contents.
LOGW("Component '%s' does not give the client access to "
"the framebuffer contents. Skipping.",
componentName);
continue;
}
}
status_t err = omx->allocateNode(componentName, observer, &node);
if (err == OK) {
LOGV("Successfully allocated OMX node '%s'", componentName);
sp<OMXCodec> codec = new OMXCodec(
omx, node, quirks,
createEncoder, mime, componentName,
source);------------------------生成一个omxcodec,这个需要后面再细细研究
observer->setCodec(codec);
err = codec->configureCodec(meta, flags);
if (err == OK) {
return codec;
}
LOGV("Failed to configure codec '%s'", componentName);
}
}
最重要的还是openmax的处理,只是看了一天,很多东西还需要再细看一下
openmax 的IL层规定了一些接口,openmax分为core和instance,core加载instance,omax instance实现IL接口,提供给openmax框架调用,而omax instance就是特定平台实现自己codec的具体地方。
下面代码是qcom平台的建立自己omx具体方法的地方,omx 具体调用的就是component的方法,而具体的到底是什么方法是在omx il的api中规定好的。
void * qc_omx_create_component_wrapper(OMX_PTR obj_ptr)
{
qc_omx_component *pThis = (qc_omx_component *)obj_ptr;
OMX_COMPONENTTYPE* component = &(pThis->m_cmp);
memset(&pThis->m_cmp,0,sizeof(OMX_COMPONENTTYPE));
component->nSize = sizeof(OMX_COMPONENTTYPE);
component->nVersion.nVersion = OMX_SPEC_VERSION;
component->pApplicationPrivate = 0;
component->pComponentPrivate = obj_ptr;
component->AllocateBuffer = &qc_omx_component_allocate_buffer;
component->FreeBuffer = &qc_omx_component_free_buffer;
component->GetParameter = &qc_omx_component_get_parameter;
component->SetParameter = &qc_omx_component_set_parameter;
component->SendCommand = &qc_omx_component_send_command;
component->FillThisBuffer = &qc_omx_component_fill_this_buffer;
component->EmptyThisBuffer = &qc_omx_component_empty_this_buffer;
component->GetState = &qc_omx_component_get_state;
component->GetComponentVersion = &qc_omx_component_get_version;
component->GetConfig = &qc_omx_component_get_config;
component->SetConfig = &qc_omx_component_set_config;
component->GetExtensionIndex = &qc_omx_component_get_extension_index;
component->ComponentTunnelRequest = &qc_omx_component_tunnel_request;
component->UseBuffer = &qc_omx_component_use_buffer;
component->SetCallbacks = &qc_omx_component_set_callbacks;
component->UseEGLImage = &qc_omx_component_use_EGL_image;
component->ComponentRoleEnum = &qc_omx_component_role_enum;
component->ComponentDeInit = &qc_omx_component_deinit;
return (void *)component;
}
qcom平台会继续调用自己实现的omx方法