1 /* 2 * Copyright 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package androidx.camera.core.impl; 18 19 import android.graphics.ImageFormat; 20 import android.graphics.PixelFormat; 21 import android.hardware.camera2.CaptureRequest; 22 import android.util.Range; 23 import android.util.Size; 24 25 import androidx.camera.core.CameraInfo; 26 import androidx.camera.core.CameraSelector; 27 import androidx.camera.core.DynamicRange; 28 import androidx.core.util.Preconditions; 29 30 import org.jspecify.annotations.NonNull; 31 import org.jspecify.annotations.Nullable; 32 33 import java.util.Collections; 34 import java.util.List; 35 import java.util.Set; 36 import java.util.concurrent.Executor; 37 38 /** 39 * An interface for retrieving camera information. 40 * 41 * <p>Contains methods for retrieving characteristics for a specific camera. 42 * 43 * <p>{@link #getImplementation()} returns a {@link CameraInfoInternal} instance 44 * that contains the actual implementation and can be cast to an implementation specific class. 45 * If the instance itself is the implementation instance, then it should return <code>this</code>. 46 */ 47 public interface CameraInfoInternal extends CameraInfo { 48 49 /** 50 * Returns the camera id of this camera. 51 * 52 * @return the camera id 53 */ getCameraId()54 @NonNull String getCameraId(); 55 56 /** 57 * Returns the camera characteristics of this camera. The actual type is determined by the 58 * underlying camera implementation. For camera2 implementation, the actual type of the 59 * returned object is {@link android.hardware.camera2.CameraCharacteristics}. 60 */ getCameraCharacteristics()61 @NonNull Object getCameraCharacteristics(); 62 63 /** 64 * Returns the camera characteristics of the specified physical camera id associated with 65 * the current camera. 66 * 67 * <p>It returns {@code null} if the physical camera id does not belong to 68 * the current logical camera. The actual type is determined by the underlying camera 69 * implementation. For camera2 implementation, the actual type of the returned object is 70 * {@link android.hardware.camera2.CameraCharacteristics}. 71 */ getPhysicalCameraCharacteristics(@onNull String physicalCameraId)72 @Nullable Object getPhysicalCameraCharacteristics(@NonNull String physicalCameraId); 73 74 /** 75 * Adds a {@link CameraCaptureCallback} which will be invoked when session capture request is 76 * completed, failed or cancelled. 77 * 78 * <p>The callback will be invoked on the specified {@link Executor}. 79 */ addSessionCaptureCallback(@onNull Executor executor, @NonNull CameraCaptureCallback callback)80 void addSessionCaptureCallback(@NonNull Executor executor, 81 @NonNull CameraCaptureCallback callback); 82 83 /** 84 * Removes the {@link CameraCaptureCallback} which was added in 85 * {@link #addSessionCaptureCallback(Executor, CameraCaptureCallback)}. 86 */ removeSessionCaptureCallback(@onNull CameraCaptureCallback callback)87 void removeSessionCaptureCallback(@NonNull CameraCaptureCallback callback); 88 89 /** Returns a list of quirks related to the camera. */ getCameraQuirks()90 @NonNull Quirks getCameraQuirks(); 91 92 /** Returns the {@link EncoderProfilesProvider} associated with this camera. */ getEncoderProfilesProvider()93 @NonNull EncoderProfilesProvider getEncoderProfilesProvider(); 94 95 /** Returns the {@link Timebase} of frame output by this camera. */ getTimebase()96 @NonNull Timebase getTimebase(); 97 98 /** 99 * Returns the supported output formats of this camera. 100 * 101 * @return a set of supported output format, or an empty set if no output format is supported. 102 */ getSupportedOutputFormats()103 @NonNull Set<Integer> getSupportedOutputFormats(); 104 105 /** 106 * Returns the supported resolutions of this camera based on the input image format. 107 * 108 * @param format an image format from {@link ImageFormat} or {@link PixelFormat}. 109 * @return a list of supported resolutions, or an empty list if the format is not supported. 110 */ getSupportedResolutions(int format)111 @NonNull List<Size> getSupportedResolutions(int format); 112 113 /** 114 * Returns the supported high resolutions of this camera based on the input image format. 115 * 116 * @param format an image format from {@link ImageFormat} or {@link PixelFormat}. 117 * @return a list of supported resolutions, or an empty list if the format is not supported. 118 */ getSupportedHighResolutions(int format)119 @NonNull List<Size> getSupportedHighResolutions(int format); 120 121 /** 122 * Returns the supported dynamic ranges of this camera. 123 * 124 * @return a set of supported dynamic range, or an empty set if no dynamic range is supported. 125 */ getSupportedDynamicRanges()126 @NonNull Set<DynamicRange> getSupportedDynamicRanges(); 127 128 /** Returns if high speed capturing is supported on the device. */ isHighSpeedSupported()129 boolean isHighSpeedSupported(); 130 131 /** Returns the supported high speed frame rate ranges. */ 132 @NonNull getSupportedHighSpeedFrameRateRanges()133 Set<Range<Integer>> getSupportedHighSpeedFrameRateRanges(); 134 135 /** 136 * Returns the supported high speed frame rate ranges for a given size. 137 * 138 * @param size one of the sizes returned by {@link #getSupportedHighSpeedResolutions()}. 139 * @return a set of supported high speed frame rate ranges for a given size, or an empty set 140 * if the size is not supported. 141 */ 142 @NonNull getSupportedHighSpeedFrameRateRangesFor(@onNull Size size)143 Set<Range<Integer>> getSupportedHighSpeedFrameRateRangesFor(@NonNull Size size); 144 145 /** Returns the supported high speed resolutions. */ 146 @NonNull getSupportedHighSpeedResolutions()147 List<Size> getSupportedHighSpeedResolutions(); 148 149 /** 150 * Returns the supported high speed resolutions for a given frame rate range. 151 * 152 * @param fpsRange one of the frame rate ranges returned by 153 * {@link #getSupportedHighSpeedFrameRateRanges()}. 154 * @return a list of supported high speed resolutions for the given frame rate range, or an 155 * empty list if the frame rate range is not supported. 156 */ 157 @NonNull getSupportedHighSpeedResolutionsFor(@onNull Range<Integer> fpsRange)158 List<Size> getSupportedHighSpeedResolutionsFor(@NonNull Range<Integer> fpsRange); 159 160 /** 161 * Returns if preview stabilization is supported on the device. 162 * 163 * @return true if 164 * {@link CaptureRequest#CONTROL_VIDEO_STABILIZATION_MODE_PREVIEW_STABILIZATION} is supported, 165 * otherwise false. 166 * 167 * @see CaptureRequest#CONTROL_VIDEO_STABILIZATION_MODE 168 */ isPreviewStabilizationSupported()169 boolean isPreviewStabilizationSupported(); 170 171 /** 172 * Returns if video stabilization is supported on the device. 173 * 174 * @return true if {@link CaptureRequest#CONTROL_VIDEO_STABILIZATION_MODE_ON} is supported, 175 * otherwise false. 176 * 177 * @see CaptureRequest#CONTROL_VIDEO_STABILIZATION_MODE 178 */ isVideoStabilizationSupported()179 boolean isVideoStabilizationSupported(); 180 181 /** 182 * Gets the underlying implementation instance which could be cast into an implementation 183 * specific class for further use in implementation module. Returns <code>this</code> if this 184 * instance is the implementation instance. 185 */ getImplementation()186 default @NonNull CameraInfoInternal getImplementation() { 187 return this; 188 } 189 190 /** 191 * Returns if postview is supported or not. 192 */ isPostviewSupported()193 default boolean isPostviewSupported() { 194 return false; 195 } 196 197 /** 198 * Returns if capture process progress is supported or not. 199 */ isCaptureProcessProgressSupported()200 default boolean isCaptureProcessProgressSupported() { 201 return false; 202 } 203 204 /** {@inheritDoc} */ 205 @Override getCameraSelector()206 default @NonNull CameraSelector getCameraSelector() { 207 return new CameraSelector.Builder() 208 .addCameraFilter(cameraInfos -> { 209 final String cameraId = getCameraId(); 210 for (CameraInfo cameraInfo : cameraInfos) { 211 Preconditions.checkArgument(cameraInfo instanceof CameraInfoInternal); 212 final CameraInfoInternal cameraInfoInternal = 213 (CameraInfoInternal) cameraInfo; 214 if (cameraInfoInternal.getCameraId().equals(cameraId)) { 215 return Collections.singletonList(cameraInfo); 216 } 217 } 218 throw new IllegalStateException("Unable to find camera with id " + cameraId 219 + " from list of available cameras."); 220 }) 221 .addCameraFilter(new LensFacingCameraFilter(getLensFacing())) 222 .build(); 223 } 224 } 225