1 /* 2 * Copyright (C) 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 #ifndef ANDROID_SERVERS_CAMERA3_INFLIGHT_REQUEST_H 18 #define ANDROID_SERVERS_CAMERA3_INFLIGHT_REQUEST_H 19 20 #include <set> 21 22 #include <camera/CaptureResult.h> 23 #include <camera/CameraMetadata.h> 24 #include <utils/Timers.h> 25 26 #include "common/CameraDeviceBase.h" 27 28 namespace android { 29 30 namespace camera3 { 31 32 typedef struct camera_stream_configuration { 33 uint32_t num_streams; 34 camera_stream_t **streams; 35 uint32_t operation_mode; 36 bool input_is_multi_resolution; 37 bool use_hal_buf_manager = false; 38 std::set<int32_t> hal_buffer_managed_streams; 39 } camera_stream_configuration_t; 40 41 typedef struct camera_capture_request { 42 uint32_t frame_number; 43 const camera_metadata_t *settings; 44 camera_stream_buffer_t *input_buffer; 45 uint32_t num_output_buffers; 46 const camera_stream_buffer_t *output_buffers; 47 uint32_t num_physcam_settings; 48 const char **physcam_id; 49 const camera_metadata_t **physcam_settings; 50 int32_t input_width; 51 int32_t input_height; 52 } camera_capture_request_t; 53 54 typedef struct camera_capture_result { 55 uint32_t frame_number; 56 const camera_metadata_t *result; 57 uint32_t num_output_buffers; 58 const camera_stream_buffer_t *output_buffers; 59 const camera_stream_buffer_t *input_buffer; 60 uint32_t partial_result; 61 uint32_t num_physcam_metadata; 62 const char **physcam_ids; 63 const camera_metadata_t **physcam_metadata; 64 } camera_capture_result_t; 65 66 typedef struct camera_shutter_msg { 67 uint32_t frame_number; 68 uint64_t timestamp; 69 bool readout_timestamp_valid; 70 uint64_t readout_timestamp; 71 } camera_shutter_msg_t; 72 73 typedef struct camera_error_msg { 74 uint32_t frame_number; 75 camera_stream_t *error_stream; 76 int error_code; 77 } camera_error_msg_t; 78 79 typedef enum camera_error_msg_code { 80 CAMERA_MSG_ERROR_DEVICE = 1, 81 CAMERA_MSG_ERROR_REQUEST = 2, 82 CAMERA_MSG_ERROR_RESULT = 3, 83 CAMERA_MSG_ERROR_BUFFER = 4, 84 CAMERA_MSG_NUM_ERRORS 85 } camera_error_msg_code_t; 86 87 typedef struct camera_notify_msg { 88 int type; 89 90 union { 91 camera_error_msg_t error; 92 camera_shutter_msg_t shutter; 93 } message; 94 } camera_notify_msg_t; 95 96 typedef enum { 97 // Cache the buffers with STATUS_ERROR within InFlightRequest 98 ERROR_BUF_CACHE, 99 // Return the buffers with STATUS_ERROR to the buffer queue 100 ERROR_BUF_RETURN, 101 // Return the buffers with STATUS_ERROR to the buffer queue, and call 102 // notify(ERROR_BUFFER) as well 103 ERROR_BUF_RETURN_NOTIFY 104 } ERROR_BUF_STRATEGY; 105 106 struct InFlightRequest { 107 // Set by notify() SHUTTER call. 108 nsecs_t shutterTimestamp; 109 // Set by process_capture_result(). 110 nsecs_t sensorTimestamp; 111 int requestStatus; 112 // Set by process_capture_result call with valid metadata 113 bool haveResultMetadata; 114 // Decremented by calls to process_capture_result with valid output 115 // and input buffers 116 int numBuffersLeft; 117 118 // The inflight request is considered complete if all buffers are returned 119 120 CaptureResultExtras resultExtras; 121 // If this request has any input buffer 122 bool hasInputBuffer; 123 124 // The last metadata that framework receives from HAL and 125 // not yet send out because the shutter event hasn't arrived. 126 // It's added by process_capture_result and sent when framework 127 // receives the shutter event. 128 CameraMetadata pendingMetadata; 129 130 // The metadata of the partial results that framework receives from HAL so far 131 // and has sent out. 132 CameraMetadata collectedPartialResult; 133 134 // Buffers are added by process_capture_result when output buffers 135 // return from HAL but framework has not yet received the shutter 136 // event. They will be returned to the streams when framework receives 137 // the shutter event. 138 Vector<camera_stream_buffer_t> pendingOutputBuffers; 139 140 // Whether this inflight request's shutter and result callback are to be 141 // called. The policy is that if the request is the last one in the constrained 142 // high speed recording request list, this flag will be true. If the request list 143 // is not for constrained high speed recording, this flag will also be true. 144 bool hasCallback; 145 146 // Minimum expected frame duration for this request 147 // For manual captures, equal to the max of requested exposure time and frame duration 148 // For auto-exposure modes, equal to 1/(higher end of target FPS range) 149 nsecs_t minExpectedDuration; 150 151 // Maximum expected frame duration for this request. 152 // For manual captures, equal to the max of requested exposure time and frame duration 153 // For auto-exposure modes, equal to 1/(lower end of target FPS range) 154 nsecs_t maxExpectedDuration; 155 156 // Whether the FPS range is fixed, aka, minFps == maxFps 157 bool isFixedFps; 158 159 // Whether the result metadata for this request is to be skipped. The 160 // result metadata should be skipped in the case of 161 // REQUEST/RESULT error. 162 bool skipResultMetadata; 163 164 // Whether the buffers with STATUS_ERROR should be cached as pending buffers, 165 // returned to the buffer queue, or returned to the buffer queue and notify with ERROR_BUFFER. 166 ERROR_BUF_STRATEGY errorBufStrategy; 167 168 // The physical camera ids being requested. 169 // For request on a physical camera stream, the inside set contains one Id 170 // For request on a stream group containing physical camera streams, the 171 // inside set contains all stream Ids in the group. 172 std::set<std::set<std::string>> physicalCameraIds; 173 174 // Map of physicalCameraId <-> Metadata 175 std::vector<PhysicalCaptureResultInfo> physicalMetadatas; 176 177 // Indicates a still capture request. 178 bool stillCapture; 179 180 // Indicates a ZSL capture request 181 bool zslCapture; 182 183 // Indicates that ROTATE_AND_CROP was set to AUTO 184 bool rotateAndCropAuto; 185 186 // Indicates that AUTOFRAMING was set to AUTO 187 bool autoframingAuto; 188 189 // Requested camera ids (both logical and physical) with zoomRatio != 1.0f 190 std::set<std::string> cameraIdsWithZoom; 191 192 // Time of capture request (from systemTime) in Ns 193 nsecs_t requestTimeNs; 194 195 // What shared surfaces an output should go to 196 SurfaceMap outputSurfaces; 197 198 // Current output transformation 199 int32_t transform; 200 201 static const nsecs_t kDefaultMinExpectedDuration = 33333333; // 33 ms 202 static const nsecs_t kDefaultMaxExpectedDuration = 100000000; // 100 ms 203 204 // Default constructor needed by KeyedVector InFlightRequestInFlightRequest205 InFlightRequest() : 206 shutterTimestamp(0), 207 sensorTimestamp(0), 208 requestStatus(OK), 209 haveResultMetadata(false), 210 numBuffersLeft(0), 211 hasInputBuffer(false), 212 hasCallback(true), 213 minExpectedDuration(kDefaultMinExpectedDuration), 214 maxExpectedDuration(kDefaultMaxExpectedDuration), 215 isFixedFps(false), 216 skipResultMetadata(false), 217 errorBufStrategy(ERROR_BUF_CACHE), 218 stillCapture(false), 219 zslCapture(false), 220 rotateAndCropAuto(false), 221 autoframingAuto(false), 222 requestTimeNs(0), 223 transform(-1) { 224 } 225 226 InFlightRequest(int numBuffers, CaptureResultExtras extras, bool hasInput, 227 bool hasAppCallback, nsecs_t minDuration, nsecs_t maxDuration, bool fixedFps, 228 const std::set<std::set<std::string>>& physicalCameraIdSet, bool isStillCapture, 229 bool isZslCapture, bool rotateAndCropAuto, bool autoframingAuto, 230 const std::set<std::string>& idsWithZoom, nsecs_t requestNs, 231 const SurfaceMap& outSurfaces = SurfaceMap{}) : 232 shutterTimestamp(0), 233 sensorTimestamp(0), 234 requestStatus(OK), 235 haveResultMetadata(false), 236 numBuffersLeft(numBuffers), 237 resultExtras(extras), 238 hasInputBuffer(hasInput), 239 hasCallback(hasAppCallback), 240 minExpectedDuration(minDuration), 241 maxExpectedDuration(maxDuration), 242 isFixedFps(fixedFps), 243 skipResultMetadata(false), 244 errorBufStrategy(ERROR_BUF_CACHE), 245 physicalCameraIds(physicalCameraIdSet), 246 stillCapture(isStillCapture), 247 zslCapture(isZslCapture), 248 rotateAndCropAuto(rotateAndCropAuto), 249 autoframingAuto(autoframingAuto), 250 cameraIdsWithZoom(idsWithZoom), 251 requestTimeNs(requestNs), 252 outputSurfaces(outSurfaces), 253 transform(-1) { 254 } 255 }; 256 257 // Map from frame number to the in-flight request state 258 typedef KeyedVector<uint32_t, InFlightRequest> InFlightRequestMap; 259 260 } // namespace camera3 261 262 } // namespace android 263 264 #endif 265