如何知道Android解码器MediaCodec.createDecoderByType(类型)是硬件解码器还是软件解码



有没有办法找出使用MediaCodec.createDecoderByType(类型)接收的解码器是硬件解码器还是软件解码器?

没有真正的正式标志来指示编解码器是硬件编解码器还是软件编解码器。然而,在实践中,你可以这样做:

MediaCodec codec = MediaCodec.createDecoderByType(type);
if (codec.getName().startsWith("OMX.google.")) {
// Is a software codec
}

(MediaCodec.getName()方法自API级别18起可用。对于较低的API级别,您需要对MediaCodecList中的条目进行迭代,并手动选择适合您需求的正确编解码器。)

把它放在这里对任何人都有帮助。根据libstagefright的代码,任何以OMX.google.c2.android.开头或不以(OMX.c2.)开头的编解码器都是软件编解码器。

//static
bool MediaCodecList::isSoftwareCodec(const AString &componentName) {
return componentName.startsWithIgnoreCase("OMX.google.")
|| componentName.startsWithIgnoreCase("c2.android.")
|| (!componentName.startsWithIgnoreCase("OMX.")
&& !componentName.startsWithIgnoreCase("c2."));
}

来源:
https://android.googlesource.com/platform/frameworks/av/+/master/media/libstagefright/MediaCodecList.cpp#320

最新更新