Search in sources :

Example 61 with MediaCodecInfo

use of android.media.MediaCodecInfo in project edx-app-android by edx.

the class MediaCodecUtil method getMediaCodecInfo.

/**
 * Returns the best decoder and its capabilities for the given mimeType. If there's no decoder
 * returns null.
 */
private static synchronized Pair<MediaCodecInfo, CodecCapabilities> getMediaCodecInfo(String mimeType) {
    Pair<MediaCodecInfo, CodecCapabilities> result = codecs.get(mimeType);
    if (result != null) {
        return result;
    }
    int numberOfCodecs = MediaCodecList.getCodecCount();
    // Note: MediaCodecList is sorted by the framework such that the best decoders come first.
    for (int i = 0; i < numberOfCodecs; i++) {
        MediaCodecInfo info = MediaCodecList.getCodecInfoAt(i);
        String codecName = info.getName();
        if (!info.isEncoder() && isOmxCodec(codecName)) {
            String[] supportedTypes = info.getSupportedTypes();
            for (int j = 0; j < supportedTypes.length; j++) {
                String supportedType = supportedTypes[j];
                if (supportedType.equalsIgnoreCase(mimeType)) {
                    result = Pair.create(info, info.getCapabilitiesForType(supportedType));
                    codecs.put(mimeType, result);
                    return result;
                }
            }
        }
    }
    return null;
}
Also used : MediaCodecInfo(android.media.MediaCodecInfo) CodecCapabilities(android.media.MediaCodecInfo.CodecCapabilities)

Example 62 with MediaCodecInfo

use of android.media.MediaCodecInfo in project libstreaming by fyhertz.

the class CodecManager method findEncodersForMimeType.

/**
 * Lists all encoders that claim to support a color format that we know how to use.
 * @return A list of those encoders
 */
@SuppressLint("NewApi")
public static synchronized Codec[] findEncodersForMimeType(String mimeType) {
    if (sEncoders != null)
        return sEncoders;
    ArrayList<Codec> encoders = new ArrayList<>();
    // We loop through the encoders, apparently this can take up to a sec (testes on a GS3)
    for (int j = MediaCodecList.getCodecCount() - 1; j >= 0; j--) {
        MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(j);
        if (!codecInfo.isEncoder())
            continue;
        String[] types = codecInfo.getSupportedTypes();
        for (int i = 0; i < types.length; i++) {
            if (types[i].equalsIgnoreCase(mimeType)) {
                try {
                    MediaCodecInfo.CodecCapabilities capabilities = codecInfo.getCapabilitiesForType(mimeType);
                    Set<Integer> formats = new HashSet<>();
                    // And through the color formats supported
                    for (int k = 0; k < capabilities.colorFormats.length; k++) {
                        int format = capabilities.colorFormats[k];
                        for (int l = 0; l < SUPPORTED_COLOR_FORMATS.length; l++) {
                            if (format == SUPPORTED_COLOR_FORMATS[l]) {
                                formats.add(format);
                            }
                        }
                    }
                    Codec codec = new Codec(codecInfo.getName(), (Integer[]) formats.toArray(new Integer[formats.size()]));
                    encoders.add(codec);
                } catch (Exception e) {
                    Log.wtf(TAG, e);
                }
            }
        }
    }
    sEncoders = (Codec[]) encoders.toArray(new Codec[encoders.size()]);
    return sEncoders;
}
Also used : MediaCodecInfo(android.media.MediaCodecInfo) ArrayList(java.util.ArrayList) SuppressLint(android.annotation.SuppressLint) HashSet(java.util.HashSet) SuppressLint(android.annotation.SuppressLint)

Example 63 with MediaCodecInfo

use of android.media.MediaCodecInfo in project android_packages_apps_Snap by LineageOS.

the class MFNRDrawer method updateBitrateForNonHFR.

private void updateBitrateForNonHFR(int videoEncoder, int bitRate, int height, int width) {
    MediaCodecList allCodecs = new MediaCodecList(MediaCodecList.ALL_CODECS);
    for (MediaCodecInfo info : allCodecs.getCodecInfos()) {
        if (!info.isEncoder() || info.getName().contains("google"))
            continue;
        for (String type : info.getSupportedTypes()) {
            if ((videoEncoder == MediaRecorder.VideoEncoder.MPEG_4_SP && type.equalsIgnoreCase(MediaFormat.MIMETYPE_VIDEO_MPEG4)) || (videoEncoder == MediaRecorder.VideoEncoder.H263 && type.equalsIgnoreCase(MediaFormat.MIMETYPE_VIDEO_H263))) {
                CodecCapabilities codecCapabilities = info.getCapabilitiesForType(type);
                VideoCapabilities videoCapabilities = codecCapabilities.getVideoCapabilities();
                try {
                    if (videoCapabilities != null) {
                        Log.d(TAG, "updateBitrate type is " + type + " " + info.getName());
                        int maxBitRate = videoCapabilities.getBitrateRange().getUpper().intValue();
                        Log.d(TAG, "maxBitRate is " + maxBitRate + ", profileBitRate is " + bitRate);
                        mMediaRecorder.setVideoEncodingBitRate(Math.min(bitRate, maxBitRate));
                        return;
                    }
                } catch (IllegalArgumentException e) {
                }
            }
        }
    }
    Log.i(TAG, "updateBitrate video bitrate: " + bitRate);
    mMediaRecorder.setVideoEncodingBitRate(bitRate);
}
Also used : MediaCodecInfo(android.media.MediaCodecInfo) MediaCodecList(android.media.MediaCodecList) CodecCapabilities(android.media.MediaCodecInfo.CodecCapabilities) VideoCapabilities(android.media.MediaCodecInfo.VideoCapabilities) Paint(android.graphics.Paint) Point(android.graphics.Point)

Example 64 with MediaCodecInfo

use of android.media.MediaCodecInfo in project android_packages_apps_Snap by LineageOS.

the class SettingsManager method isCurrentVideoResolutionSupportedByEncoder.

private boolean isCurrentVideoResolutionSupportedByEncoder(MediaCodecInfo info) {
    boolean supported = false;
    ListPreference videoQuality = mPreferenceGroup.findPreference(KEY_VIDEO_QUALITY);
    if (videoQuality == null)
        return supported;
    String videoSizeStr = videoQuality.getValue();
    if (videoSizeStr != null) {
        Size videoSize = parseSize(videoSizeStr);
        String[] supportedTypes = info.getSupportedTypes();
        MediaCodecInfo.VideoCapabilities capabilities = null;
        for (String type : supportedTypes) {
            if (type.equalsIgnoreCase(MediaFormat.MIMETYPE_VIDEO_MPEG4) || type.equalsIgnoreCase(MediaFormat.MIMETYPE_VIDEO_H263) || type.equalsIgnoreCase(MediaFormat.MIMETYPE_VIDEO_AVC) || type.equalsIgnoreCase(MediaFormat.MIMETYPE_VIDEO_HEVC)) {
                capabilities = info.getCapabilitiesForType(type).getVideoCapabilities();
                if (capabilities == null || !capabilities.getSupportedWidths().contains(videoSize.getWidth()) || !capabilities.getSupportedWidths().contains(videoSize.getHeight())) {
                    return false;
                } else {
                    supported = true;
                }
            }
        }
    }
    return supported;
}
Also used : Size(android.util.Size) MediaCodecInfo(android.media.MediaCodecInfo) VideoCapabilities(android.media.MediaCodecInfo.VideoCapabilities)

Example 65 with MediaCodecInfo

use of android.media.MediaCodecInfo in project android_packages_apps_Snap by LineageOS.

the class SettingsManager method getSupportedVideoEncoderForAutoTest.

private List<String> getSupportedVideoEncoderForAutoTest(String videoSizeStr) {
    ArrayList<String> supported = new ArrayList<String>();
    ListPreference videoEncoder = mPreferenceGroup.findPreference(KEY_VIDEO_ENCODER);
    if (videoEncoder == null)
        return supported;
    if (videoEncoder != null) {
        String str = null;
        MediaCodecList list = new MediaCodecList(MediaCodecList.ALL_CODECS);
        MediaCodecInfo[] codecInfos = list.getCodecInfos();
        for (MediaCodecInfo info : codecInfos) {
            if (info.isEncoder()) {
                int type = SettingTranslation.getVideoEncoderType(info.getSupportedTypes()[0]);
                if (type != -1) {
                    str = SettingTranslation.getVideoEncoder(type);
                    if (isCurrentVideoResolutionSupportedByEncoder(info)) {
                        supported.add(str);
                    }
                }
            }
        }
    }
    return supported;
}
Also used : MediaCodecInfo(android.media.MediaCodecInfo) ArrayList(java.util.ArrayList) MediaCodecList(android.media.MediaCodecList) Point(android.graphics.Point)

Aggregations

MediaCodecInfo (android.media.MediaCodecInfo)108 ArrayList (java.util.ArrayList)33 MediaCodecList (android.media.MediaCodecList)22 SuppressLint (android.annotation.SuppressLint)20 MediaFormat (android.media.MediaFormat)17 CodecCapabilities (android.media.MediaCodecInfo.CodecCapabilities)15 IOException (java.io.IOException)14 TargetApi (android.annotation.TargetApi)10 Point (android.graphics.Point)9 VideoCapabilities (android.media.MediaCodecInfo.VideoCapabilities)6 Size (android.util.Size)6 Nullable (androidx.annotation.Nullable)6 HashSet (java.util.HashSet)6 Test (org.junit.Test)6 Config (org.robolectric.annotation.Config)5 SparseIntArray (android.util.SparseIntArray)4 NonNull (androidx.annotation.NonNull)4 TreeMap (java.util.TreeMap)4 MediaCodec (android.media.MediaCodec)3 Bundle (android.os.Bundle)3