Search in sources :

Example 76 with MediaCodecInfo

use of android.media.MediaCodecInfo in project aws-sdk-android by aws-amplify.

the class VideoEncoderUtils method getSystemSupportedEncoders.

/**
 * @return list of encoders supported by the system
 */
public static List<MediaCodecInfo> getSystemSupportedEncoders() {
    final MediaCodecList codecList = new MediaCodecList(MediaCodecList.REGULAR_CODECS);
    final List<MediaCodecInfo> codecInfoList = new ArrayList<MediaCodecInfo>();
    for (final MediaCodecInfo codecInfo : codecList.getCodecInfos()) {
        if (codecInfo.isEncoder()) {
            codecInfoList.add(codecInfo);
        }
    }
    return codecInfoList;
}
Also used : MediaCodecInfo(android.media.MediaCodecInfo) MediaCodecList(android.media.MediaCodecList) ArrayList(java.util.ArrayList)

Example 77 with MediaCodecInfo

use of android.media.MediaCodecInfo in project Telegram-FOSS by Telegram-FOSS-Team.

the class MediaController method selectCodec.

@SuppressLint("NewApi")
public static MediaCodecInfo selectCodec(String mimeType) {
    int numCodecs = MediaCodecList.getCodecCount();
    MediaCodecInfo lastCodecInfo = null;
    for (int i = 0; i < numCodecs; i++) {
        MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);
        if (!codecInfo.isEncoder()) {
            continue;
        }
        String[] types = codecInfo.getSupportedTypes();
        for (String type : types) {
            if (type.equalsIgnoreCase(mimeType)) {
                lastCodecInfo = codecInfo;
                String name = lastCodecInfo.getName();
                if (name != null) {
                    if (!name.equals("OMX.SEC.avc.enc")) {
                        return lastCodecInfo;
                    } else if (name.equals("OMX.SEC.AVC.Encoder")) {
                        return lastCodecInfo;
                    }
                }
            }
        }
    }
    return lastCodecInfo;
}
Also used : MediaCodecInfo(android.media.MediaCodecInfo) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) SuppressLint(android.annotation.SuppressLint)

Example 78 with MediaCodecInfo

use of android.media.MediaCodecInfo in project Telegram-FOSS by Telegram-FOSS-Team.

the class MediaCodecVideoDecoderFactory method getSupportedCodecs.

@Override
public VideoCodecInfo[] getSupportedCodecs() {
    List<VideoCodecInfo> supportedCodecInfos = new ArrayList<VideoCodecInfo>();
    // VP8, VP9, H.265(optional), H264 (high profile), and H264 (baseline profile).
    for (VideoCodecMimeType type : new VideoCodecMimeType[] { VideoCodecMimeType.VP8, VideoCodecMimeType.VP9, VideoCodecMimeType.H264, VideoCodecMimeType.H265 }) {
        MediaCodecInfo codec = findCodecForType(type);
        if (codec != null) {
            String name = type.name();
            if (type == VideoCodecMimeType.H264 && isH264HighProfileSupported(codec)) {
                supportedCodecInfos.add(new VideoCodecInfo(name, MediaCodecUtils.getCodecProperties(type, /* highProfile= */
                true)));
            }
            supportedCodecInfos.add(new VideoCodecInfo(name, MediaCodecUtils.getCodecProperties(type, /* highProfile= */
            false)));
        }
    }
    return supportedCodecInfos.toArray(new VideoCodecInfo[supportedCodecInfos.size()]);
}
Also used : MediaCodecInfo(android.media.MediaCodecInfo) ArrayList(java.util.ArrayList)

Example 79 with MediaCodecInfo

use of android.media.MediaCodecInfo in project Telegram-FOSS by Telegram-FOSS-Team.

the class MediaCodecVideoDecoderFactory method findCodecForType.

@Nullable
private MediaCodecInfo findCodecForType(VideoCodecMimeType type) {
    // HW decoding is not supported on builds before KITKAT.
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        return null;
    }
    ArrayList<MediaCodecInfo> infos = MediaCodecUtils.getSortedCodecsList();
    int codecCount = infos.size();
    for (int i = 0; i < codecCount; ++i) {
        MediaCodecInfo info = infos.get(i);
        if (info == null || info.isEncoder()) {
            continue;
        }
        if (isSupportedCodec(info, type)) {
            return info;
        }
    }
    // No support for this type.
    return null;
}
Also used : MediaCodecInfo(android.media.MediaCodecInfo) Nullable(androidx.annotation.Nullable)

Example 80 with MediaCodecInfo

use of android.media.MediaCodecInfo in project Telegram-FOSS by Telegram-FOSS-Team.

the class HardwareVideoEncoderFactory method createEncoder.

@Nullable
@Override
public VideoEncoder createEncoder(VideoCodecInfo input) {
    // HW encoding is not supported below Android Kitkat.
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        return null;
    }
    VideoCodecMimeType type = VideoCodecMimeType.valueOf(input.name);
    MediaCodecInfo info = findCodecForType(type);
    if (info == null) {
        return null;
    }
    String codecName = info.getName();
    String mime = type.mimeType();
    Integer surfaceColorFormat = MediaCodecUtils.selectColorFormat(MediaCodecUtils.TEXTURE_COLOR_FORMATS, info.getCapabilitiesForType(mime));
    Integer yuvColorFormat = MediaCodecUtils.selectColorFormat(MediaCodecUtils.ENCODER_COLOR_FORMATS, info.getCapabilitiesForType(mime));
    if (type == VideoCodecMimeType.H264) {
        boolean isHighProfile = H264Utils.isSameH264Profile(input.params, MediaCodecUtils.getCodecProperties(type, /* highProfile= */
        true));
        boolean isBaselineProfile = H264Utils.isSameH264Profile(input.params, MediaCodecUtils.getCodecProperties(type, /* highProfile= */
        false));
        if (!isHighProfile && !isBaselineProfile) {
            return null;
        }
        if (isHighProfile && !isH264HighProfileSupported(info)) {
            return null;
        }
    }
    return new HardwareVideoEncoder(new MediaCodecWrapperFactoryImpl(), codecName, type, surfaceColorFormat, yuvColorFormat, input.params, getKeyFrameIntervalSec(type), getForcedKeyFrameIntervalMs(type, codecName), createBitrateAdjuster(type, codecName), sharedContext);
}
Also used : MediaCodecInfo(android.media.MediaCodecInfo) Nullable(androidx.annotation.Nullable)

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