Search in sources :

Example 46 with MediaCodecInfo

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

the class SettingsManager method getSupportedPictureSize.

private List<String> getSupportedPictureSize(int cameraId) {
    StreamConfigurationMap map = mCharacteristics.get(cameraId).get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
    Size[] sizes = map.getOutputSizes(ImageFormat.JPEG);
    List<String> res = new ArrayList<>();
    boolean isDeepportrait = getDeepportraitEnabled();
    boolean isHeifEnabled = getSavePictureFormat() == HEIF_FORMAT;
    if (getQcfaPrefEnabled() && getIsSupportedQcfa(cameraId)) {
        res.add(getSupportedQcfaDimension(cameraId));
    }
    VideoCapabilities heifCap = null;
    if (isHeifEnabled) {
        MediaCodecList list = new MediaCodecList(MediaCodecList.REGULAR_CODECS);
        for (MediaCodecInfo info : list.getCodecInfos()) {
            if (info.isEncoder() && info.getName().contains("heic")) {
                heifCap = info.getCapabilitiesForType(MediaFormat.MIMETYPE_IMAGE_ANDROID_HEIC).getVideoCapabilities();
                Log.d(TAG, "supported heif height range =" + heifCap.getSupportedHeights().toString() + " width range =" + heifCap.getSupportedWidths().toString());
            }
        }
    }
    if (sizes != null) {
        for (int i = 0; i < sizes.length; i++) {
            if (isHeifEnabled && heifCap != null) {
                if (!heifCap.getSupportedWidths().contains(sizes[i].getWidth()) || !heifCap.getSupportedHeights().contains(sizes[i].getHeight())) {
                    continue;
                }
            }
            if (isDeepportrait && (Math.min(sizes[i].getWidth(), sizes[i].getHeight()) < 720 || Math.max(sizes[i].getWidth(), sizes[i].getHeight()) <= 1024)) {
                // some reslutions are not supported in deepportrait
                continue;
            }
            res.add(sizes[i].toString());
        }
    }
    Size[] highResSizes = map.getHighResolutionOutputSizes(ImageFormat.JPEG);
    if (highResSizes != null) {
        for (int i = 0; i < highResSizes.length; i++) {
            if (isHeifEnabled && heifCap != null) {
                if (!heifCap.getSupportedWidths().contains(highResSizes[i].getWidth()) || !heifCap.getSupportedHeights().contains(highResSizes[i].getHeight())) {
                    continue;
                }
            }
            res.add(highResSizes[i].toString());
        }
    }
    return res;
}
Also used : Size(android.util.Size) MediaCodecInfo(android.media.MediaCodecInfo) ArrayList(java.util.ArrayList) MediaCodecList(android.media.MediaCodecList) StreamConfigurationMap(android.hardware.camera2.params.StreamConfigurationMap) VideoCapabilities(android.media.MediaCodecInfo.VideoCapabilities) Point(android.graphics.Point)

Example 47 with MediaCodecInfo

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

the class DefaultCodecFactory method getVideoEncoderSupportedFormat.

@RequiresNonNull("#1.sampleMimeType")
private static Format getVideoEncoderSupportedFormat(Format requestedFormat, List<String> allowedMimeTypes) throws TransformationException {
    String mimeType = requestedFormat.sampleMimeType;
    Format.Builder formatBuilder = requestedFormat.buildUpon();
    // TODO(b/210591626) Implement encoder filtering.
    if (!allowedMimeTypes.contains(mimeType) || EncoderUtil.getSupportedEncoders(mimeType).isEmpty()) {
        mimeType = allowedMimeTypes.contains(DEFAULT_FALLBACK_MIME_TYPE) ? DEFAULT_FALLBACK_MIME_TYPE : allowedMimeTypes.get(0);
        if (EncoderUtil.getSupportedEncoders(mimeType).isEmpty()) {
            throw createTransformationException(new IllegalArgumentException("No encoder is found for requested MIME type " + requestedFormat.sampleMimeType), requestedFormat, /* isVideo= */
            true, /* isDecoder= */
            false, /* mediaCodecName= */
            null);
        }
    }
    formatBuilder.setSampleMimeType(mimeType);
    MediaCodecInfo encoderInfo = EncoderUtil.getSupportedEncoders(mimeType).get(0);
    int width = requestedFormat.width;
    int height = requestedFormat.height;
    @Nullable Pair<Integer, Integer> encoderSupportedResolution = EncoderUtil.getClosestSupportedResolution(encoderInfo, mimeType, width, height);
    if (encoderSupportedResolution == null) {
        throw createTransformationException(new IllegalArgumentException("Cannot find fallback resolution for resolution " + width + " x " + height), requestedFormat, /* isVideo= */
        true, /* isDecoder= */
        false, /* mediaCodecName= */
        null);
    }
    width = encoderSupportedResolution.first;
    height = encoderSupportedResolution.second;
    formatBuilder.setWidth(width).setHeight(height);
    // The frameRate does not affect the resulting frame rate. It affects the encoder's rate control
    // algorithm. Setting it too high may lead to video quality degradation.
    float frameRate = requestedFormat.frameRate != Format.NO_VALUE ? requestedFormat.frameRate : DEFAULT_FRAME_RATE;
    int bitrate = EncoderUtil.getClosestSupportedBitrate(encoderInfo, mimeType, /* bitrate= */
    requestedFormat.averageBitrate != Format.NO_VALUE ? requestedFormat.averageBitrate : getSuggestedBitrate(width, height, frameRate));
    formatBuilder.setFrameRate(frameRate).setAverageBitrate(bitrate);
    @Nullable Pair<Integer, Integer> profileLevel = MediaCodecUtil.getCodecProfileAndLevel(requestedFormat);
    if (profileLevel == null || // Transcoding to another MIME type.
    !requestedFormat.sampleMimeType.equals(mimeType) || !EncoderUtil.isProfileLevelSupported(encoderInfo, mimeType, /* profile= */
    profileLevel.first, /* level= */
    profileLevel.second)) {
        formatBuilder.setCodecs(null);
    }
    return formatBuilder.build();
}
Also used : MediaFormat(android.media.MediaFormat) Format(com.google.android.exoplayer2.Format) MediaCodecInfo(android.media.MediaCodecInfo) SuppressLint(android.annotation.SuppressLint) Nullable(androidx.annotation.Nullable) RequiresNonNull(org.checkerframework.checker.nullness.qual.RequiresNonNull)

Example 48 with MediaCodecInfo

use of android.media.MediaCodecInfo 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 49 with MediaCodecInfo

use of android.media.MediaCodecInfo in project Signal-Android by WhisperSystems.

the class MediaConverter method selectCodec.

/**
 * Returns the first codec capable of encoding the specified MIME type, or null if no match was
 * found.
 */
static MediaCodecInfo selectCodec(final String mimeType) {
    final int numCodecs = MediaCodecList.getCodecCount();
    for (int i = 0; i < numCodecs; i++) {
        final MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);
        if (!codecInfo.isEncoder()) {
            continue;
        }
        final String[] types = codecInfo.getSupportedTypes();
        for (String type : types) {
            if (type.equalsIgnoreCase(mimeType)) {
                return codecInfo;
            }
        }
    }
    return null;
}
Also used : MediaCodecInfo(android.media.MediaCodecInfo)

Example 50 with MediaCodecInfo

use of android.media.MediaCodecInfo in project Signal-Android by signalapp.

the class MediaConverter method selectCodec.

/**
 * Returns the first codec capable of encoding the specified MIME type, or null if no match was
 * found.
 */
static MediaCodecInfo selectCodec(final String mimeType) {
    final int numCodecs = MediaCodecList.getCodecCount();
    for (int i = 0; i < numCodecs; i++) {
        final MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);
        if (!codecInfo.isEncoder()) {
            continue;
        }
        final String[] types = codecInfo.getSupportedTypes();
        for (String type : types) {
            if (type.equalsIgnoreCase(mimeType)) {
                return codecInfo;
            }
        }
    }
    return null;
}
Also used : MediaCodecInfo(android.media.MediaCodecInfo)

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