1 package com.android.media.benchmark.library; 2 3 import android.media.MediaCodecInfo; 4 import android.media.MediaCodecList; 5 import android.os.Build; 6 7 import java.util.ArrayList; 8 9 public class CodecUtils { CodecUtils()10 private CodecUtils() {} 11 12 /** 13 * Queries the MediaCodecList and returns codec names of supported codecs. 14 * 15 * @param mimeType Mime type of input 16 * @param isEncoder Specifies encoder or decoder 17 * @return ArrayList of codec names 18 */ selectCodecs(String mimeType, boolean isEncoder)19 public static ArrayList<String> selectCodecs(String mimeType, boolean isEncoder) { 20 MediaCodecList codecList = new MediaCodecList(MediaCodecList.REGULAR_CODECS); 21 MediaCodecInfo[] codecInfos = codecList.getCodecInfos(); 22 ArrayList<String> supportedCodecs = new ArrayList<>(); 23 for (MediaCodecInfo codecInfo : codecInfos) { 24 if (isEncoder != codecInfo.isEncoder()) { 25 continue; 26 } 27 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && codecInfo.isAlias()) { 28 continue; 29 } 30 String[] types = codecInfo.getSupportedTypes(); 31 for (String type : types) { 32 if (type.equalsIgnoreCase(mimeType)) { 33 supportedCodecs.add(codecInfo.getName()); 34 } 35 } 36 } 37 return supportedCodecs; 38 } 39 } 40