//static
void MediaCodecList::findMatchingCodecs(
const char *mime, bool encoder, uint32_t flags,
Vector *matches, Vector *owners) {
matches->clear();
if (owners != nullptr) {
owners->clear();
}
const sp list = getInstance();
if (list == nullptr) {
return;
}
size_t index = 0;
for (;;) {
ssize_t matchIndex =
list->findCodecByType(mime, encoder, index);
if (matchIndex < 0) {
break;
}
index = matchIndex + 1;
const sp info = list->getCodecInfo(matchIndex);
CHECK(info != nullptr);
AString componentName = info->getCodecName();
if ((flags & kHardwareCodecsOnly) && isSoftwareCodec(componentName)) {
ALOGV("skipping SW codec '%s'", componentName.c_str());
} else {
matches->push(componentName);
if (owners != nullptr) {
owners->push(AString(info->getOwnerName()));
}
ALOGV("matching '%s'", componentName.c_str());
}
}
if (flags & kPreferSoftwareCodecs ||
property_get_bool("debug.stagefright.swcodec", false)) {
matches->sort(compareSoftwareCodecsFirst);
}
}
如上截图: 核心方法findMatchingCodecs
可以过滤软编码:
if ((flags & kHardwareCodecsOnly) && isSoftwareCodec(componentName)) {
}else{
. . .
}
在MediaCodecSource.cpp 以及 ACodec.cpp 都会调用findMatchingCodecs
status_t MediaCodecSource::initEncoder() {
mReflector = new AHandlerReflector
mLooper->registerHandler(mReflector);
mCodecLooper = new ALooper;
mCodecLooper->setName("codec_looper");
mCodecLooper->start();
if (mFlags & FLAG_USE_SURFACE_INPUT) {
mOutputFormat->setInt32("create-input-buffers-suspended", 1);
}
AString outputMIME;
CHECK(mOutputFormat->findString("mime", &outputMIME));
Vector
ALOGD("-[TIM]- mFlags & FLAG_PREFER_SOFTWARE_CODEC:%d, MiME-NAME:%s .", mFlags & FLAG_PREFER_SOFTWARE_CODEC,outputMIME.c_str());
MediaCodecList::findMatchingCodecs(
outputMIME.c_str(),
true, /* encoder */
((mFlags & FLAG_PREFER_SOFTWARE_CODEC) ? MediaCodecList::kPreferSoftwareCodecs : 0),//
&matchingCodecs);
bool ACodec::UninitializedState::onAllocateComponent(const sp
ALOGV("onAllocateComponent");
CHECK(mCodec->mOMXNode == NULL);
sp
Vector
Vector
AString mime;
AString componentName;
int32_t encoder = false;
if (msg->findString("componentName", &componentName)) {
. . .
} else {
ALOGW("-[TIM]-findString componentName is null");
CHECK(msg->findString("mime", &mime));
if (!msg->findInt32("encoder", &encoder)) {
encoder = false;
}
MediaCodecList::findMatchingCodecs(
mime.c_str(),
encoder, // createEncoder
0, // flags
&matchingCodecs,
&owners);
}