Android设备最大解码数量:getMaxSupportedInstances()

最近在适配一些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);
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值