最近在适配一些Android盒子的时候,遇到一款Amlogic芯片的盒子(金属外观),在上面尝试硬解码第二路H.264视频流的时候发生崩溃。最后编写了一段测试代码,调用MediaCodecInfo.CodecCapabilities的getMaxSupportedInstances()方法才发现,这款盒子返回的数值只有1。而在其他盒子以及Android手机上,最少的6,最大的有32。看来是因为平台限制了。这里记录一下。
下方是官网的说明:
getMaxSupportedInstances
added in API level 23
public int getMaxSupportedInstances ()
Returns the max number of the supported concurrent codec instances.
This is a hint for an upper bound. Applications should not expect to successfully operate more instances than the returned value, but the actual number of concurrently operable instances may be less as it depends on the available resources at time of use.
附测试代码:
public static void printMediaCodecInfo() {
int CodecCount = 0;
try {
CodecCount = MediaCodecList.getCodecCount();
}catch (Exception e) {
Log.e(TAG, "##### Failed to get codec count!");
e.printStackTrace();
return;
}
for (int i = 0; i < CodecCount; ++i) {
MediaCodecInfo info = null;
try {
info = MediaCodecList.getCodecInfoAt(i);
} catch (IllegalArgumentException e) {
Log.e(TAG, "Cannot retrieve decoder codec info", e);
}
if (info == null) {
continue;
}
String codecInfo = "MediaCodec, name="+info.getName()+", [";
for (String mimeType : info.getSupportedTypes()) {
codecInfo += mimeType + ",";
MediaCodecInfo.CodecCapabilities capabilities;
try {
capabilities = info.getCapabilitiesForType(mimeType);
} catch (IllegalArgumentException e) {
Log.e(TAG, "Cannot retrieve decoder capabilities", e);
continue;
}
codecInfo += " max inst:"+capabilities.getMaxSupportedInstances()+",";
String strColorFormatList = "";
for (int colorFormat : capabilities.colorFormats) {
strColorFormatList += " 0x" + Integer.toHexString(colorFormat);
}
codecInfo += strColorFormatList + "] [";
}
Log.w(TAG, codecInfo);
}
boolean bSupportHwVP8 = MediaCodecVideoEncoder.isVp8HwSupported();
boolean bSupportHwVP9 = MediaCodecVideoEncoder.isVp9HwSupported();
boolean bSupportHwH264 = MediaCodecVideoEncoder.isH264HwSupported();
String webrtcCodecInfo = "WebRTC codec support: HwVP8=" + bSupportHwVP8 + ", HwVP9=" + bSupportHwVP9
+ ", Hw264=" + bSupportHwH264;
if(bSupportHwH264) {
webrtcCodecInfo += ", Hw264HighProfile=" + MediaCodecVideoEncoder.isH264HighProfileHwSupported();
}
Log.w(TAG, webrtcCodecInfo);
}