public class

CamcorderProfileResolutionQuirk

extends java.lang.Object

implements Quirk

 java.lang.Object

↳androidx.camera.camera2.internal.compat.quirk.CamcorderProfileResolutionQuirk

Gradle dependencies

compile group: 'androidx.camera', name: 'camera-camera2', version: '1.2.0-alpha01'

  • groupId: androidx.camera
  • artifactId: camera-camera2
  • version: 1.2.0-alpha01

Artifact androidx.camera:camera-camera2:1.2.0-alpha01 it located at Google repository (https://maven.google.com/)

Overview

QuirkSummary Bug Id: 180819729 Description: Quirk that should validate the video resolution of on legacy camera. When using the Camera 2 API in LEGACY mode (i.e. when CameraCharacteristics is set to CameraCharacteristics), may return true for unsupported resolutions. To ensure a given resolution is supported in LEGACY mode, the configuration given in CameraCharacteristics must contain the resolution in the supported output sizes. The recommended way to check this is with with the class of the desired recording endpoint, and check that the desired resolution is contained in the list returned. Device(s): All legacy devices

Summary

Constructors
publicCamcorderProfileResolutionQuirk(CameraCharacteristicsCompat characteristicsCompat)

Methods
public java.util.List<Size>getSupportedResolutions()

Returns the supported video resolutions.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public CamcorderProfileResolutionQuirk(CameraCharacteristicsCompat characteristicsCompat)

Methods

public java.util.List<Size> getSupportedResolutions()

Returns the supported video resolutions.

Source

/*
 * Copyright 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.camera.camera2.internal.compat.quirk;

import android.graphics.SurfaceTexture;
import android.hardware.camera2.CameraCharacteristics;
import android.hardware.camera2.params.StreamConfigurationMap;
import android.media.CamcorderProfile;
import android.os.Build;
import android.util.Size;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.camera.camera2.internal.compat.CameraCharacteristicsCompat;
import androidx.camera.camera2.internal.compat.workaround.CamcorderProfileResolutionValidator;
import androidx.camera.core.Logger;
import androidx.camera.core.impl.ImageFormatConstants;
import androidx.camera.core.impl.Quirk;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * <p>QuirkSummary
 *     Bug Id: 180819729
 *     Description: Quirk that should validate the video resolution of {@link CamcorderProfile}
 *                  on legacy camera. When using the Camera 2 API in {@code LEGACY} mode (i.e.
 *                  when {@link CameraCharacteristics#INFO_SUPPORTED_HARDWARE_LEVEL} is set to
 *                  {@link CameraCharacteristics#INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY}),
 *                  {@link CamcorderProfile#hasProfile} may return {@code true} for unsupported
 *                  resolutions. To ensure a given resolution is supported in LEGACY mode, the
 *                  configuration given in
 *                  {@link CameraCharacteristics#SCALER_STREAM_CONFIGURATION_MAP} must contain
 *                  the resolution in the supported output sizes. The recommended way to check
 *                  this is with {@link StreamConfigurationMap#getOutputSizes(Class)} with the
 *                  class of the desired recording endpoint, and check that the desired
 *                  resolution is contained in the list returned.
 *     Device(s): All legacy devices
 *     @see CamcorderProfile#hasProfile
 *     @see CamcorderProfileResolutionValidator
 */
@RequiresApi(21) // TODO(b/200306659): Remove and replace with annotation on package-info.java
public class CamcorderProfileResolutionQuirk implements Quirk {
    private static final String TAG = "CamcorderProfileResolutionQuirk";

    static boolean load(@NonNull CameraCharacteristicsCompat characteristicsCompat) {
        final Integer level = characteristicsCompat.get(
                CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);
        return level != null && level == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY;
    }

    private final List<Size> mSupportedResolutions;

    public CamcorderProfileResolutionQuirk(
            @NonNull CameraCharacteristicsCompat characteristicsCompat) {
        StreamConfigurationMap map =
                characteristicsCompat.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
        if (map == null) {
            Logger.e(TAG, "StreamConfigurationMap is null");
        }
        Size[] sizes;
        // Before Android 23, use {@link SurfaceTexture} will finally mapped to 0x22 in
        // StreamConfigurationMap to retrieve the output sizes information.
        if (Build.VERSION.SDK_INT < 23) {
            sizes = map != null ? map.getOutputSizes(SurfaceTexture.class) : null;
        } else {
            sizes = map != null ? map.getOutputSizes(
                    ImageFormatConstants.INTERNAL_DEFINED_IMAGE_FORMAT_PRIVATE) : null;
        }

        mSupportedResolutions = sizes != null ? Arrays.asList(sizes.clone())
                : Collections.emptyList();

        Logger.d(TAG, "mSupportedResolutions = " + mSupportedResolutions);
    }

    /** Returns the supported video resolutions. */
    @NonNull
    public List<Size> getSupportedResolutions() {
        return new ArrayList<>(mSupportedResolutions);
    }
}