FileDocCategorySizeDatePackage
MediaCodecList.javaAPI DocAndroid 5.1 API8108Thu Mar 12 22:22:30 GMT 2015android.media

MediaCodecList

public final class MediaCodecList extends Object
Allows you to enumerate available codecs, each specified as a {@link MediaCodecInfo} object, find a codec supporting a given format and query the capabilities of a given codec.

See {@link MediaCodecInfo} for sample usage.

Fields Summary
private static final String
TAG
private static Object
sInitLock
private static android.media.MediaCodecInfo[]
sAllCodecInfos
private static android.media.MediaCodecInfo[]
sRegularCodecInfos
public static final int
REGULAR_CODECS
Use in {@link #MediaCodecList} to enumerate only codecs that are suitable for regular (buffer-to-buffer) decoding or encoding. NOTE: These are the codecs that are returned prior to API 21, using the now deprecated static methods.
public static final int
ALL_CODECS
Use in {@link #MediaCodecList} to enumerate all codecs, even ones that are not suitable for regular (buffer-to-buffer) decoding or encoding. These include codecs, for example, that only work with special input or output surfaces, such as secure-only or tunneled-only codecs.
private android.media.MediaCodecInfo[]
mCodecInfos
Constructors Summary
private MediaCodecList()


      
        this(REGULAR_CODECS);
    
public MediaCodecList(int kind)
Create a list of media-codecs of a specific kind.

param
kind Either {@code REGULAR_CODECS} or {@code ALL_CODECS}.

        initCodecList();
        if (kind == REGULAR_CODECS) {
            mCodecInfos = sRegularCodecInfos;
        } else {
            mCodecInfos = sAllCodecInfos;
        }
    
Methods Summary
static final native intfindCodecByName(java.lang.String codec)

private java.lang.StringfindCodecForFormat(boolean encoder, MediaFormat format)

        String mime = format.getString(MediaFormat.KEY_MIME);
        for (MediaCodecInfo info: mCodecInfos) {
            if (info.isEncoder() != encoder) {
                continue;
            }
            try {
                MediaCodecInfo.CodecCapabilities caps = info.getCapabilitiesForType(mime);
                if (caps != null && caps.isFormatSupported(format)) {
                    return info.getName();
                }
            } catch (IllegalArgumentException e) {
                // type is not supported
            }
        }
        return null;
    
public final java.lang.StringfindDecoderForFormat(MediaFormat format)
Find a decoder supporting a given {@link MediaFormat} in the list of media-codecs.

param
format A decoder media format with optional feature directives.
throws
IllegalArgumentException if format is not a valid media format.
throws
NullPointerException if format is null.
return
the name of a decoder that supports the given format and feature requests, or {@code null} if no such codec has been found.

        System.loadLibrary("media_jni");
        native_init();

        // mediaserver is not yet alive here
    
        return findCodecForFormat(false /* encoder */, format);
    
public final java.lang.StringfindEncoderForFormat(MediaFormat format)
Find an encoder supporting a given {@link MediaFormat} in the list of media-codecs.

param
format An encoder media format with optional feature directives.
throws
IllegalArgumentException if format is not a valid media format.
throws
NullPointerException if format is null.
return
the name of an encoder that supports the given format and feature requests, or {@code null} if no such codec has been found.

        return findCodecForFormat(true /* encoder */, format);
    
static final native android.media.MediaCodecInfo.CodecCapabilitiesgetCodecCapabilities(int index, java.lang.String type)

public static final intgetCodecCount()
Count the number of available (regular) codecs.

deprecated
Use {@link #getCodecInfos} instead.
see
#REGULAR_CODECS


                       
         
        initCodecList();
        return sRegularCodecInfos.length;
    
public static final android.media.MediaCodecInfogetCodecInfoAt(int index)
Return the {@link MediaCodecInfo} object for the codec at the given {@code index} in the regular list.

deprecated
Use {@link #getCodecInfos} instead.
see
#REGULAR_CODECS

        initCodecList();
        if (index < 0 || index > sRegularCodecInfos.length) {
            throw new IllegalArgumentException();
        }
        return sRegularCodecInfos[index];
    
public final android.media.MediaCodecInfo[]getCodecInfos()
Returns the list of {@link MediaCodecInfo} objects for the list of media-codecs.

        return Arrays.copyOf(mCodecInfos, mCodecInfos.length);
    
static final native java.lang.StringgetCodecName(int index)

public static android.media.MediaCodecInfogetInfoFor(java.lang.String codec)

hide

        initCodecList();
        return sAllCodecInfos[findCodecByName(codec)];
    
private static android.media.MediaCodecInfogetNewCodecInfoAt(int index)

        String[] supportedTypes = getSupportedTypes(index);
        MediaCodecInfo.CodecCapabilities[] caps =
            new MediaCodecInfo.CodecCapabilities[supportedTypes.length];
        int typeIx = 0;
        for (String type: supportedTypes) {
            caps[typeIx++] = getCodecCapabilities(index, type);
        }
        return new MediaCodecInfo(
                getCodecName(index), isEncoder(index), caps);
    
static final native java.lang.String[]getSupportedTypes(int index)

private static final voidinitCodecList()


         
        synchronized (sInitLock) {
            if (sRegularCodecInfos == null) {
                int count = native_getCodecCount();
                ArrayList<MediaCodecInfo> regulars = new ArrayList<MediaCodecInfo>();
                ArrayList<MediaCodecInfo> all = new ArrayList<MediaCodecInfo>();
                for (int index = 0; index < count; index++) {
                    try {
                        MediaCodecInfo info = getNewCodecInfoAt(index);
                        all.add(info);
                        info = info.makeRegular();
                        if (info != null) {
                            regulars.add(info);
                        }
                    } catch (Exception e) {
                        Log.e(TAG, "Could not get codec capabilities", e);
                    }
                }
                sRegularCodecInfos =
                    regulars.toArray(new MediaCodecInfo[regulars.size()]);
                sAllCodecInfos =
                    all.toArray(new MediaCodecInfo[all.size()]);
            }
        }
    
static final native booleanisEncoder(int index)

private static final native intnative_getCodecCount()

private static final native voidnative_init()