1 /* 2 * Copyright (C) 2014 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 android.hardware.camera2; 18 19 import android.annotation.NonNull; 20 import android.hardware.camera2.impl.CameraMetadataNative; 21 import android.hardware.camera2.impl.CaptureResultExtras; 22 import android.hardware.camera2.impl.PhysicalCaptureResultInfo; 23 24 import java.util.ArrayList; 25 import java.util.Collections; 26 import java.util.HashMap; 27 import java.util.List; 28 import java.util.Map; 29 30 /** 31 * <p>The total assembled results of a single image capture from the image sensor.</p> 32 * 33 * <p>Contains the final configuration for the capture hardware (sensor, lens, 34 * flash), the processing pipeline, the control algorithms, and the output 35 * buffers.</p> 36 * 37 * <p>A {@code TotalCaptureResult} is produced by a {@link CameraDevice} after processing a 38 * {@link CaptureRequest}. All properties listed for capture requests can also 39 * be queried on the capture result, to determine the final values used for 40 * capture. The result also includes additional metadata about the state of the 41 * camera device during the capture.</p> 42 * 43 * <p>All properties returned by {@link CameraCharacteristics#getAvailableCaptureResultKeys()} 44 * are available (that is {@link CaptureResult#get} will return non-{@code null}, if and only if 45 * that key that was enabled by the request. A few keys such as 46 * {@link CaptureResult#STATISTICS_FACES} are disabled by default unless enabled with a switch (such 47 * as {@link CaptureRequest#STATISTICS_FACE_DETECT_MODE}). Refer to each key documentation on 48 * a case-by-case basis.</p> 49 * 50 * <p>For a logical multi-camera device, if the CaptureRequest contains a surface for an underlying 51 * physical camera, the corresponding {@link TotalCaptureResult} object will include the metadata 52 * for that physical camera. And the mapping between the physical camera id and result metadata 53 * can be accessed via {@link #getPhysicalCameraResults}. If all requested surfaces are for the 54 * logical camera, no metadata for physical camera will be included.</p> 55 * 56 * <p>{@link TotalCaptureResult} objects are immutable.</p> 57 * 58 * @see CameraCaptureSession.CaptureCallback#onCaptureCompleted 59 */ 60 public final class TotalCaptureResult extends CaptureResult { 61 62 private final List<CaptureResult> mPartialResults; 63 private final int mSessionId; 64 // The map between physical camera ids and their total capture result 65 private final HashMap<String, TotalCaptureResult> mPhysicalCaptureResults; 66 67 /** 68 * Takes ownership of the passed-in camera metadata and the partial results 69 * 70 * @param partials a list of partial results; {@code null} will be substituted for an empty list 71 * @hide 72 */ TotalCaptureResult(String logicalCameraId, CameraMetadataNative results, CaptureRequest parent, CaptureResultExtras extras, List<CaptureResult> partials, int sessionId, PhysicalCaptureResultInfo[] physicalResults)73 public TotalCaptureResult(String logicalCameraId, CameraMetadataNative results, 74 CaptureRequest parent, CaptureResultExtras extras, List<CaptureResult> partials, 75 int sessionId, PhysicalCaptureResultInfo[] physicalResults) { 76 super(logicalCameraId, results, parent, extras); 77 78 if (partials == null) { 79 mPartialResults = new ArrayList<>(); 80 } else { 81 mPartialResults = partials; 82 } 83 84 mSessionId = sessionId; 85 86 mPhysicalCaptureResults = new HashMap<String, TotalCaptureResult>(); 87 for (PhysicalCaptureResultInfo onePhysicalResult : physicalResults) { 88 TotalCaptureResult physicalResult = new TotalCaptureResult( 89 onePhysicalResult.getCameraId(), onePhysicalResult.getCameraMetadata(), 90 parent, extras, /*partials*/null, sessionId, new PhysicalCaptureResultInfo[0]); 91 mPhysicalCaptureResults.put(onePhysicalResult.getCameraId(), 92 physicalResult); 93 } 94 } 95 96 /** 97 * Takes ownership of the passed-in camera metadata and the partial results 98 * 99 * @param partials a list of partial results; {@code null} will be substituted for an empty list 100 * @hide 101 */ TotalCaptureResult(String logicalCameraId, CameraMetadataNative results, CaptureRequest parent, int requestId, long frameNumber, List<CaptureResult> partials, int sessionId, PhysicalCaptureResultInfo[] physicalResults)102 public TotalCaptureResult(String logicalCameraId, CameraMetadataNative results, 103 CaptureRequest parent, int requestId, long frameNumber, List<CaptureResult> partials, 104 int sessionId, PhysicalCaptureResultInfo[] physicalResults) { 105 super(logicalCameraId, results, parent, requestId, frameNumber); 106 107 if (partials == null) { 108 mPartialResults = new ArrayList<>(); 109 } else { 110 mPartialResults = partials; 111 } 112 113 mSessionId = sessionId; 114 115 mPhysicalCaptureResults = new HashMap<String, TotalCaptureResult>(); 116 for (PhysicalCaptureResultInfo onePhysicalResult : physicalResults) { 117 TotalCaptureResult physicalResult = new TotalCaptureResult( 118 onePhysicalResult.getCameraId(), onePhysicalResult.getCameraMetadata(), 119 parent, requestId, frameNumber, /*partials*/null, sessionId, 120 new PhysicalCaptureResultInfo[0]); 121 mPhysicalCaptureResults.put(onePhysicalResult.getCameraId(), 122 physicalResult); 123 } 124 } 125 126 /** 127 * Creates a request-less result. 128 * 129 * <p><strong>For testing only.</strong></p> 130 * @hide 131 */ TotalCaptureResult(CameraMetadataNative results, int sequenceId)132 public TotalCaptureResult(CameraMetadataNative results, int sequenceId) { 133 super(results, sequenceId); 134 135 mPartialResults = new ArrayList<>(); 136 mSessionId = CameraCaptureSession.SESSION_ID_NONE; 137 mPhysicalCaptureResults = new HashMap<String, TotalCaptureResult>(); 138 } 139 140 /** 141 * Get the read-only list of partial results that compose this total result. 142 * 143 * <p>The list is returned is unmodifiable; attempting to modify it will result in a 144 * {@code UnsupportedOperationException} being thrown.</p> 145 * 146 * <p>The list size will be inclusive between {@code 0} and 147 * {@link CameraCharacteristics#REQUEST_PARTIAL_RESULT_COUNT}, with elements in ascending order 148 * of when {@link CameraCaptureSession.CaptureCallback#onCaptureProgressed} was invoked.</p> 149 * 150 * @return unmodifiable list of partial results 151 */ 152 @NonNull getPartialResults()153 public List<CaptureResult> getPartialResults() { 154 return Collections.unmodifiableList(mPartialResults); 155 } 156 157 /** 158 * Get the ID of the session where the capture request of this result was submitted. 159 * 160 * @return The session ID 161 * @hide 162 */ getSessionId()163 public int getSessionId() { 164 return mSessionId; 165 } 166 167 /** 168 * Get the map between physical camera ids and their capture result metadata 169 * 170 * <p>This function can be called for logical multi-camera devices, which are devices that have 171 * REQUEST_AVAILABLE_CAPABILITIES_LOGICAL_MULTI_CAMERA capability and calls to {@link 172 * CameraCharacteristics#getPhysicalCameraIds} return a non-empty set of physical devices that 173 * are backing the logical camera.</p> 174 * 175 * <p>If one or more streams from the underlying physical cameras were requested by the 176 * corresponding capture request, this function returns the result metadata for those physical 177 * cameras. Otherwise, an empty map is returned.</p> 178 179 * @return unmodifiable map between physical camera ids and their capture result metadata 180 * 181 * @deprecated 182 * <p>Please use {@link #getPhysicalCameraTotalResults()} instead to get the 183 * physical cameras' {@code TotalCaptureResult}.</p> 184 */ getPhysicalCameraResults()185 public Map<String, CaptureResult> getPhysicalCameraResults() { 186 return Collections.unmodifiableMap(mPhysicalCaptureResults); 187 } 188 189 /** 190 * Get the map between physical camera ids and their total capture result metadata 191 * 192 * <p>This function can be called for logical multi-camera devices, which are devices that have 193 * REQUEST_AVAILABLE_CAPABILITIES_LOGICAL_MULTI_CAMERA capability.</p> 194 * 195 * <p>If one or more streams from the underlying physical cameras were requested by the 196 * corresponding capture request, this function returns the total result metadata for those 197 * physical cameras. Otherwise, an empty map is returned.</p> 198 * 199 * <p>This function replaces the deprecated {@link #getPhysicalCameraResults}, and its return 200 * value is a map of TotalCaptureResult rather than CaptureResult. </p> 201 * 202 * <p>To reprocess an image from a physical camera stream, typically returned from a 203 * {@link MultiResolutionImageReader}, the application must look up this map to get the {@link 204 * TotalCaptureResult} from the physical camera and pass it to {@link 205 * CameraDevice#createReprocessCaptureRequest}.</p> 206 * 207 * @return unmodifiable map between physical camera ids and their total capture result metadata 208 */ 209 @NonNull getPhysicalCameraTotalResults()210 public Map<String, TotalCaptureResult> getPhysicalCameraTotalResults() { 211 return Collections.unmodifiableMap(mPhysicalCaptureResults); 212 } 213 } 214