public final class

Camera2CameraInfo

extends java.lang.Object

 java.lang.Object

↳androidx.camera.camera2.interop.Camera2CameraInfo

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

An interface for retrieving Camera2-related camera information.

Summary

Constructors
publicCamera2CameraInfo(Camera2CameraInfoImpl camera2CameraInfoImpl)

Creates a new camera information with Camera2 implementation.

Methods
public static CameraCharacteristicsextractCameraCharacteristics(CameraInfo cameraInfo)

Returns the CameraCharacteristics for this camera.

public static Camera2CameraInfofrom(CameraInfo cameraInfo)

Gets the Camera2CameraInfo from a CameraInfo.

public java.lang.ObjectgetCameraCharacteristic(<any> key)

Gets a camera characteristic value.

public java.util.Map<java.lang.String, CameraCharacteristics>getCameraCharacteristicsMap()

Returns a map consisting of the camera ids and the CameraCharacteristicss.

public java.lang.StringgetCameraId()

Gets the string camera ID.

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

Constructors

public Camera2CameraInfo(Camera2CameraInfoImpl camera2CameraInfoImpl)

Creates a new camera information with Camera2 implementation.

Methods

public static Camera2CameraInfo from(CameraInfo cameraInfo)

Gets the Camera2CameraInfo from a CameraInfo.

Parameters:

cameraInfo: The CameraInfo to get from.

Returns:

The camera information with Camera2 implementation.

public java.lang.String getCameraId()

Gets the string camera ID.

The camera ID is the same as the camera ID that would be obtained from . The ID that is retrieved is not static and can change depending on the current internal configuration of the Camera from which the CameraInfo was retrieved. The Camera is a logical camera which can be backed by multiple android.hardware.camera2.CameraDevice. However, only one CameraDevice is active at one time. When the CameraDevice changes then the camera id will change.

Returns:

the camera ID.

public java.lang.Object getCameraCharacteristic(<any> key)

Gets a camera characteristic value.

The characteristic value is the same as the value in the CameraCharacteristics that would be obtained from .

Parameters:

key: The of the characteristic.

Returns:

the value of the characteristic.

public static CameraCharacteristics extractCameraCharacteristics(CameraInfo cameraInfo)

Returns the CameraCharacteristics for this camera.

The CameraCharacteristics will be the ones that would be obtained by . The CameraCharacteristics that are retrieved are not static and can change depending on the current internal configuration of the camera.

Parameters:

cameraInfo: The CameraInfo to extract the CameraCharacteristics from.

public java.util.Map<java.lang.String, CameraCharacteristics> getCameraCharacteristicsMap()

Returns a map consisting of the camera ids and the CameraCharacteristicss.

For every camera, the map contains at least the CameraCharacteristics for the camera id. If the camera is logical camera, it will also contain associated physical camera ids and their CameraCharacteristics.

Source

/*
 * Copyright 2019 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.interop;

import android.hardware.camera2.CameraCharacteristics;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.annotation.RestrictTo;
import androidx.annotation.RestrictTo.Scope;
import androidx.camera.camera2.internal.Camera2CameraInfoImpl;
import androidx.camera.core.CameraInfo;
import androidx.core.util.Preconditions;

import java.util.Map;

/**
 * An interface for retrieving Camera2-related camera information.
 */
@ExperimentalCamera2Interop
@RequiresApi(21) // TODO(b/200306659): Remove and replace with annotation on package-info.java
public final class Camera2CameraInfo {
    private static final String TAG = "Camera2CameraInfo";
    private final Camera2CameraInfoImpl mCamera2CameraInfoImpl;

    /**
     * Creates a new camera information with Camera2 implementation.
     *
     * @hide
     */
    @RestrictTo(Scope.LIBRARY)
    public Camera2CameraInfo(@NonNull Camera2CameraInfoImpl camera2CameraInfoImpl) {
        mCamera2CameraInfoImpl = camera2CameraInfoImpl;
    }

    /**
     * Gets the {@link Camera2CameraInfo} from a {@link CameraInfo}.
     *
     * @param cameraInfo The {@link CameraInfo} to get from.
     * @return The camera information with Camera2 implementation.
     * @throws IllegalArgumentException if the camera info does not contain the camera2 information
     *                                  (e.g., if CameraX was not initialized with a
     *                                  {@link androidx.camera.camera2.Camera2Config}).
     */
    @NonNull
    public static Camera2CameraInfo from(@NonNull CameraInfo cameraInfo) {
        Preconditions.checkArgument(cameraInfo instanceof Camera2CameraInfoImpl,
                "CameraInfo doesn't contain Camera2 implementation.");
        return ((Camera2CameraInfoImpl) cameraInfo).getCamera2CameraInfo();
    }

    /**
     * Gets the string camera ID.
     *
     * <p>The camera ID is the same as the camera ID that would be obtained from
     * {@link android.hardware.camera2.CameraManager#getCameraIdList()}. The ID that is retrieved
     * is not static and can change depending on the current internal configuration of the
     * {@link androidx.camera.core.Camera} from which the CameraInfo was retrieved.
     *
     * The Camera is a logical camera which can be backed by multiple
     * {@link android.hardware.camera2.CameraDevice}. However, only one CameraDevice is active at
     * one time. When the CameraDevice changes then the camera id will change.
     *
     * @return the camera ID.
     * @throws IllegalStateException if the camera info does not contain the camera 2 camera ID
     *                               (e.g., if CameraX was not initialized with a
     *                               {@link androidx.camera.camera2.Camera2Config}).
     */
    @NonNull
    public String getCameraId() {
        return mCamera2CameraInfoImpl.getCameraId();
    }

    /**
     * Gets a camera characteristic value.
     *
     * <p>The characteristic value is the same as the value in the {@link CameraCharacteristics}
     * that would be obtained from
     * {@link android.hardware.camera2.CameraManager#getCameraCharacteristics(String)}.
     *
     * @param <T> The type of the characteristic value.
     * @param key The {@link CameraCharacteristics.Key} of the characteristic.
     * @return the value of the characteristic.
     */
    @Nullable
    public <T> T getCameraCharacteristic(@NonNull CameraCharacteristics.Key<T> key) {
        return mCamera2CameraInfoImpl.getCameraCharacteristicsCompat().get(key);
    }

    /**
     * Returns the {@link CameraCharacteristics} for this camera.
     *
     * <p>The CameraCharacteristics will be the ones that would be obtained by
     * {@link android.hardware.camera2.CameraManager#getCameraCharacteristics(String)}. The
     * CameraCharacteristics that are retrieved are not static and can change depending on the
     * current internal configuration of the camera.
     *
     * @param cameraInfo The {@link CameraInfo} to extract the CameraCharacteristics from.
     * @throws IllegalStateException if the camera info does not contain the camera 2
     *                               characteristics(e.g., if CameraX was not initialized with a
     *                               {@link androidx.camera.camera2.Camera2Config}).
     * @hide
     */
    // TODO: Hidden until new extensions API released.
    @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
    @NonNull
    public static CameraCharacteristics extractCameraCharacteristics(
            @NonNull CameraInfo cameraInfo) {
        Preconditions.checkState(cameraInfo instanceof Camera2CameraInfoImpl, "CameraInfo does "
                + "not contain any Camera2 information.");
        Camera2CameraInfoImpl impl = (Camera2CameraInfoImpl) cameraInfo;
        return impl.getCameraCharacteristicsCompat().toCameraCharacteristics();
    }

    /**
     * Returns a map consisting of the camera ids and the {@link CameraCharacteristics}s.
     *
     * <p>For every camera, the map contains at least the CameraCharacteristics for the camera id.
     * If the camera is logical camera, it will also contain associated physical camera ids and
     * their CameraCharacteristics.
     *
     * @hide
     */
    @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
    @NonNull
    public Map<String, CameraCharacteristics> getCameraCharacteristicsMap() {
        return mCamera2CameraInfoImpl.getCameraCharacteristicsMap();
    }
}