FileDocCategorySizeDatePackage
MediaCodecInfo.javaAPI DocAndroid 5.1 API100793Thu Mar 12 22:22:30 GMT 2015android.media

MediaCodecInfo

public final class MediaCodecInfo extends Object
Provides information about a given media codec available on the device. You can iterate through all codecs available by querying {@link MediaCodecList}. For example, here's how to find an encoder that supports a given MIME type:
private static MediaCodecInfo selectCodec(String mimeType) {
int numCodecs = MediaCodecList.getCodecCount();
for (int i = 0; i < numCodecs; i++) {
MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);

if (!codecInfo.isEncoder()) {
continue;
}

String[] types = codecInfo.getSupportedTypes();
for (int j = 0; j < types.length; j++) {
if (types[j].equalsIgnoreCase(mimeType)) {
return codecInfo;
}
}
}
return null;
}

Fields Summary
private boolean
mIsEncoder
private String
mName
private Map
mCaps
private static final android.util.Range
POSITIVE_INTEGERS
private static final android.util.Range
POSITIVE_LONGS
private static final android.util.Range
POSITIVE_RATIONALS
private static final android.util.Range
SIZE_RANGE
private static final android.util.Range
FRAME_RATE_RANGE
private static final android.util.Range
BITRATE_RANGE
private static final int
ERROR_UNRECOGNIZED
private static final int
ERROR_UNSUPPORTED
private static final int
ERROR_NONE_SUPPORTED
Constructors Summary
MediaCodecInfo(String name, boolean isEncoder, CodecCapabilities[] caps)

        mName = name;
        mIsEncoder = isEncoder;
        mCaps = new HashMap<String, CodecCapabilities>();
        for (CodecCapabilities c: caps) {
            mCaps.put(c.getMimeType(), c);
        }
    
Methods Summary
private static intcheckPowerOfTwo(int value, java.lang.String message)

        if ((value & (value - 1)) != 0) {
            throw new IllegalArgumentException(message);
        }
        return value;
    
public final android.media.MediaCodecInfo$CodecCapabilitiesgetCapabilitiesForType(java.lang.String type)
Enumerates the capabilities of the codec component. Since a single component can support data of a variety of types, the type has to be specified to yield a meaningful result.

param
type The MIME type to query

    

                                              
       
              
        CodecCapabilities caps = mCaps.get(type);
        if (caps == null) {
            throw new IllegalArgumentException("codec does not support type");
        }
        // clone writable object
        return caps.dup();
    
public final java.lang.StringgetName()
Retrieve the codec name.

        return mName;
    
public final java.lang.String[]getSupportedTypes()
Query the media types supported by the codec.

        Set<String> typeSet = mCaps.keySet();
        String[] types = typeSet.toArray(new String[typeSet.size()]);
        Arrays.sort(types);
        return types;
    
public final booleanisEncoder()
Query if the codec is an encoder.

        return mIsEncoder;
    
public android.media.MediaCodecInfomakeRegular()

hide

        ArrayList<CodecCapabilities> caps = new ArrayList<CodecCapabilities>();
        for (CodecCapabilities c: mCaps.values()) {
            if (c.isRegular()) {
                caps.add(c);
            }
        }
        if (caps.size() == 0) {
            return null;
        } else if (caps.size() == mCaps.size()) {
            return this;
        }

        return new MediaCodecInfo(
                mName, mIsEncoder,
                caps.toArray(new CodecCapabilities[caps.size()]));