Search in sources :

Example 1 with MediaCodecList

use of android.media.MediaCodecList in project acra by ACRA.

the class MediaCodecListCollector method collectMediaCodecList.

/**
     * Builds an Element describing the list of available codecs on the device
     * with their capabilities (supported Color Formats, Codec Profiles et
     * Levels).
     *
     * @return The media codecs information
     */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@NonNull
private Element collectMediaCodecList() throws JSONException {
    prepare();
    final MediaCodecInfo[] infos;
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        //noinspection deprecation
        final int codecCount = MediaCodecList.getCodecCount();
        infos = new MediaCodecInfo[codecCount];
        for (int codecIdx = 0; codecIdx < codecCount; codecIdx++) {
            //noinspection deprecation
            infos[codecIdx] = MediaCodecList.getCodecInfoAt(codecIdx);
        }
    } else {
        infos = new MediaCodecList(MediaCodecList.ALL_CODECS).getCodecInfos();
    }
    final ComplexElement result = new ComplexElement();
    for (int i = 0; i < infos.length; i++) {
        final MediaCodecInfo codecInfo = infos[i];
        JSONObject codec = new JSONObject();
        final String[] supportedTypes = codecInfo.getSupportedTypes();
        codec.put("name", codecInfo.getName()).put("isEncoder", codecInfo.isEncoder());
        JSONObject supportedTypesJson = new JSONObject();
        for (String type : supportedTypes) {
            supportedTypesJson.put(type, collectCapabilitiesForType(codecInfo, type));
        }
        codec.put("supportedTypes", supportedTypesJson);
        result.put(String.valueOf(i), codec);
    }
    return result;
}
Also used : JSONObject(org.json.JSONObject) MediaCodecInfo(android.media.MediaCodecInfo) MediaCodecList(android.media.MediaCodecList) ComplexElement(org.acra.model.ComplexElement) NonNull(android.support.annotation.NonNull) TargetApi(android.annotation.TargetApi)

Example 2 with MediaCodecList

use of android.media.MediaCodecList in project speechutils by Kaljurand.

the class AudioUtils method getAvailableEncoders.

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static List<String> getAvailableEncoders(int sampleRate) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        MediaFormat format = MediaFormatFactory.createMediaFormat(MediaFormatFactory.Type.FLAC, sampleRate);
        MediaCodecList mcl = new MediaCodecList(MediaCodecList.REGULAR_CODECS);
        String encoderAsStr = mcl.findEncoderForFormat(format);
        List<String> encoders = new ArrayList<>();
        for (MediaCodecInfo info : mcl.getCodecInfos()) {
            if (info.isEncoder()) {
                if (info.getName().equals(encoderAsStr)) {
                    encoders.add("*** " + info.getName() + ": " + TextUtils.join(", ", info.getSupportedTypes()));
                } else {
                    encoders.add(info.getName() + ": " + TextUtils.join(", ", info.getSupportedTypes()));
                }
            }
        }
        return encoders;
    }
    return Collections.emptyList();
}
Also used : MediaFormat(android.media.MediaFormat) MediaCodecInfo(android.media.MediaCodecInfo) MediaCodecList(android.media.MediaCodecList) ArrayList(java.util.ArrayList) TargetApi(android.annotation.TargetApi)

Example 3 with MediaCodecList

use of android.media.MediaCodecList in project robolectric by robolectric.

the class ShadowMediaCodecListTest method aacEncoderInfo.

@Test
public void aacEncoderInfo() {
    MediaCodecList mediaCodecList = new MediaCodecList(MediaCodecList.ALL_CODECS);
    assertThat(mediaCodecList.getCodecInfos()[0]).isEqualTo(AAC_ENCODER_INFO);
}
Also used : MediaCodecList(android.media.MediaCodecList) Test(org.junit.Test)

Example 4 with MediaCodecList

use of android.media.MediaCodecList in project ExoPlayer by google.

the class EncoderUtil method maybePopulateEncoderInfos.

private static synchronized void maybePopulateEncoderInfos() {
    if (encoders.isEmpty()) {
        MediaCodecList mediaCodecList = new MediaCodecList(MediaCodecList.ALL_CODECS);
        MediaCodecInfo[] allCodecInfos = mediaCodecList.getCodecInfos();
        for (MediaCodecInfo mediaCodecInfo : allCodecInfos) {
            if (!mediaCodecInfo.isEncoder()) {
                continue;
            }
            encoders.add(mediaCodecInfo);
        }
    }
}
Also used : MediaCodecInfo(android.media.MediaCodecInfo) MediaCodecList(android.media.MediaCodecList)

Example 5 with MediaCodecList

use of android.media.MediaCodecList in project speechutils by Kaljurand.

the class AudioUtils method getAvailableEncoders.

// TODO: use MediaFormat.MIMETYPE_AUDIO_FLAC) on API>=21
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static List<String> getAvailableEncoders(String mime, int sampleRate) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        MediaFormat format = MediaFormatFactory.createMediaFormat(mime, sampleRate);
        MediaCodecList mcl = new MediaCodecList(MediaCodecList.REGULAR_CODECS);
        String encoderAsStr = mcl.findEncoderForFormat(format);
        List<String> encoders = new ArrayList<>();
        for (MediaCodecInfo info : mcl.getCodecInfos()) {
            if (info.isEncoder()) {
                String name = info.getName();
                String infoAsStr = name + ": " + TextUtils.join(", ", info.getSupportedTypes());
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
                    infoAsStr += String.format(": %s/%s/%s/%s", info.isHardwareAccelerated(), info.isSoftwareOnly(), info.isAlias(), info.isVendor());
                }
                if (name.equals(encoderAsStr)) {
                    infoAsStr = '#' + infoAsStr;
                }
                encoders.add(infoAsStr);
            }
        }
        return encoders;
    }
    return Collections.emptyList();
}
Also used : MediaFormat(android.media.MediaFormat) MediaCodecInfo(android.media.MediaCodecInfo) MediaCodecList(android.media.MediaCodecList) ArrayList(java.util.ArrayList) TargetApi(android.annotation.TargetApi)

Aggregations

MediaCodecList (android.media.MediaCodecList)8 MediaCodecInfo (android.media.MediaCodecInfo)4 Test (org.junit.Test)4 TargetApi (android.annotation.TargetApi)3 MediaFormat (android.media.MediaFormat)2 ArrayList (java.util.ArrayList)2 NonNull (android.support.annotation.NonNull)1 ComplexElement (org.acra.model.ComplexElement)1 JSONObject (org.json.JSONObject)1