Yin-Chia Yeh | 5fd603e | 2019-11-20 11:22:27 -0800 | [diff] [blame] | 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/String8.h> |
| 25 | #include <utils/Timers.h> |
| 26 | |
Yin-Chia Yeh | 5fd603e | 2019-11-20 11:22:27 -0800 | [diff] [blame] | 27 | #include "common/CameraDeviceBase.h" |
| 28 | |
| 29 | namespace android { |
| 30 | |
| 31 | namespace camera3 { |
| 32 | |
Jayant Chowdhary | c30b4c3 | 2021-08-18 11:43:16 -0700 | [diff] [blame] | 33 | typedef struct camera_stream_configuration { |
| 34 | uint32_t num_streams; |
| 35 | camera_stream_t **streams; |
| 36 | uint32_t operation_mode; |
| 37 | bool input_is_multi_resolution; |
| 38 | } camera_stream_configuration_t; |
| 39 | |
| 40 | typedef struct camera_capture_request { |
| 41 | uint32_t frame_number; |
| 42 | const camera_metadata_t *settings; |
| 43 | camera_stream_buffer_t *input_buffer; |
| 44 | uint32_t num_output_buffers; |
| 45 | const camera_stream_buffer_t *output_buffers; |
| 46 | uint32_t num_physcam_settings; |
| 47 | const char **physcam_id; |
| 48 | const camera_metadata_t **physcam_settings; |
| 49 | int32_t input_width; |
| 50 | int32_t input_height; |
| 51 | } camera_capture_request_t; |
| 52 | |
| 53 | typedef struct camera_capture_result { |
| 54 | uint32_t frame_number; |
| 55 | const camera_metadata_t *result; |
| 56 | uint32_t num_output_buffers; |
| 57 | const camera_stream_buffer_t *output_buffers; |
| 58 | const camera_stream_buffer_t *input_buffer; |
| 59 | uint32_t partial_result; |
| 60 | uint32_t num_physcam_metadata; |
| 61 | const char **physcam_ids; |
| 62 | const camera_metadata_t **physcam_metadata; |
| 63 | } camera_capture_result_t; |
| 64 | |
| 65 | typedef struct camera_shutter_msg { |
| 66 | uint32_t frame_number; |
| 67 | uint64_t timestamp; |
Shuzhen Wang | 90708ea | 2021-11-04 11:40:49 -0700 | [diff] [blame] | 68 | uint64_t readout_timestamp; |
Jayant Chowdhary | c30b4c3 | 2021-08-18 11:43:16 -0700 | [diff] [blame] | 69 | } camera_shutter_msg_t; |
| 70 | |
| 71 | typedef struct camera_error_msg { |
| 72 | uint32_t frame_number; |
| 73 | camera_stream_t *error_stream; |
| 74 | int error_code; |
| 75 | } camera_error_msg_t; |
| 76 | |
| 77 | typedef enum camera_error_msg_code { |
| 78 | CAMERA_MSG_ERROR_DEVICE = 1, |
| 79 | CAMERA_MSG_ERROR_REQUEST = 2, |
| 80 | CAMERA_MSG_ERROR_RESULT = 3, |
| 81 | CAMERA_MSG_ERROR_BUFFER = 4, |
| 82 | CAMERA_MSG_NUM_ERRORS |
| 83 | } camera_error_msg_code_t; |
| 84 | |
| 85 | typedef struct camera_notify_msg { |
| 86 | int type; |
| 87 | |
| 88 | union { |
| 89 | camera_error_msg_t error; |
| 90 | camera_shutter_msg_t shutter; |
| 91 | } message; |
| 92 | } camera_notify_msg_t; |
| 93 | |
Shuzhen Wang | b7b4265 | 2020-05-07 11:59:02 -0700 | [diff] [blame] | 94 | typedef enum { |
| 95 | // Cache the buffers with STATUS_ERROR within InFlightRequest |
| 96 | ERROR_BUF_CACHE, |
| 97 | // Return the buffers with STATUS_ERROR to the buffer queue |
| 98 | ERROR_BUF_RETURN, |
| 99 | // Return the buffers with STATUS_ERROR to the buffer queue, and call |
| 100 | // notify(ERROR_BUFFER) as well |
| 101 | ERROR_BUF_RETURN_NOTIFY |
| 102 | } ERROR_BUF_STRATEGY; |
| 103 | |
Yin-Chia Yeh | 5fd603e | 2019-11-20 11:22:27 -0800 | [diff] [blame] | 104 | struct InFlightRequest { |
| 105 | // Set by notify() SHUTTER call. |
| 106 | nsecs_t shutterTimestamp; |
Shuzhen Wang | 90708ea | 2021-11-04 11:40:49 -0700 | [diff] [blame] | 107 | // Set by notify() SHUTTER call with readout time. |
| 108 | nsecs_t shutterReadoutTimestamp; |
Yin-Chia Yeh | 5fd603e | 2019-11-20 11:22:27 -0800 | [diff] [blame] | 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; |
Shuzhen Wang | b7b4265 | 2020-05-07 11:59:02 -0700 | [diff] [blame] | 117 | |
| 118 | // The inflight request is considered complete if all buffers are returned |
| 119 | |
Yin-Chia Yeh | 5fd603e | 2019-11-20 11:22:27 -0800 | [diff] [blame] | 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. |
Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 138 | Vector<camera_stream_buffer_t> pendingOutputBuffers; |
Yin-Chia Yeh | 5fd603e | 2019-11-20 11:22:27 -0800 | [diff] [blame] | 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 | |
Shuzhen Wang | 00abbeb | 2022-02-25 17:14:42 -0800 | [diff] [blame^] | 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 | |
Yin-Chia Yeh | 5fd603e | 2019-11-20 11:22:27 -0800 | [diff] [blame] | 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 result metadata for this request is to be skipped. The |
| 157 | // result metadata should be skipped in the case of |
| 158 | // REQUEST/RESULT error. |
| 159 | bool skipResultMetadata; |
| 160 | |
Shuzhen Wang | b7b4265 | 2020-05-07 11:59:02 -0700 | [diff] [blame] | 161 | // Whether the buffers with STATUS_ERROR should be cached as pending buffers, |
| 162 | // returned to the buffer queue, or returned to the buffer queue and notify with ERROR_BUFFER. |
| 163 | ERROR_BUF_STRATEGY errorBufStrategy; |
| 164 | |
Yin-Chia Yeh | 5fd603e | 2019-11-20 11:22:27 -0800 | [diff] [blame] | 165 | // The physical camera ids being requested. |
Shuzhen Wang | 9908050 | 2021-03-07 21:08:20 -0800 | [diff] [blame] | 166 | // For request on a physical camera stream, the inside set contains one Id |
| 167 | // For request on a stream group containing physical camera streams, the |
| 168 | // inside set contains all stream Ids in the group. |
| 169 | std::set<std::set<String8>> physicalCameraIds; |
Yin-Chia Yeh | 5fd603e | 2019-11-20 11:22:27 -0800 | [diff] [blame] | 170 | |
| 171 | // Map of physicalCameraId <-> Metadata |
| 172 | std::vector<PhysicalCaptureResultInfo> physicalMetadatas; |
| 173 | |
| 174 | // Indicates a still capture request. |
| 175 | bool stillCapture; |
| 176 | |
| 177 | // Indicates a ZSL capture request |
| 178 | bool zslCapture; |
| 179 | |
Eino-Ville Talvala | f2e3709 | 2020-01-07 15:32:32 -0800 | [diff] [blame] | 180 | // Indicates that ROTATE_AND_CROP was set to AUTO |
| 181 | bool rotateAndCropAuto; |
| 182 | |
Yin-Chia Yeh | 5fd603e | 2019-11-20 11:22:27 -0800 | [diff] [blame] | 183 | // Requested camera ids (both logical and physical) with zoomRatio != 1.0f |
| 184 | std::set<std::string> cameraIdsWithZoom; |
| 185 | |
Shuzhen Wang | 316781a | 2020-08-18 18:11:01 -0700 | [diff] [blame] | 186 | // Time of capture request (from systemTime) in Ns |
| 187 | nsecs_t requestTimeNs; |
| 188 | |
Yin-Chia Yeh | 5fd603e | 2019-11-20 11:22:27 -0800 | [diff] [blame] | 189 | // What shared surfaces an output should go to |
| 190 | SurfaceMap outputSurfaces; |
| 191 | |
Emilian Peev | 5104fe9 | 2021-10-21 14:27:09 -0700 | [diff] [blame] | 192 | // Current output transformation |
| 193 | int32_t transform; |
| 194 | |
Shuzhen Wang | 00abbeb | 2022-02-25 17:14:42 -0800 | [diff] [blame^] | 195 | static const nsecs_t kDefaultMinExpectedDuration = 33333333; // 33 ms |
| 196 | static const nsecs_t kDefaultMaxExpectedDuration = 100000000; // 100 ms |
Yin-Chia Yeh | 5fd603e | 2019-11-20 11:22:27 -0800 | [diff] [blame] | 197 | |
| 198 | // Default constructor needed by KeyedVector |
| 199 | InFlightRequest() : |
| 200 | shutterTimestamp(0), |
| 201 | sensorTimestamp(0), |
| 202 | requestStatus(OK), |
| 203 | haveResultMetadata(false), |
| 204 | numBuffersLeft(0), |
| 205 | hasInputBuffer(false), |
| 206 | hasCallback(true), |
Shuzhen Wang | 00abbeb | 2022-02-25 17:14:42 -0800 | [diff] [blame^] | 207 | minExpectedDuration(kDefaultMinExpectedDuration), |
| 208 | maxExpectedDuration(kDefaultMaxExpectedDuration), |
Yin-Chia Yeh | 5fd603e | 2019-11-20 11:22:27 -0800 | [diff] [blame] | 209 | skipResultMetadata(false), |
Shuzhen Wang | b7b4265 | 2020-05-07 11:59:02 -0700 | [diff] [blame] | 210 | errorBufStrategy(ERROR_BUF_CACHE), |
Yin-Chia Yeh | 5fd603e | 2019-11-20 11:22:27 -0800 | [diff] [blame] | 211 | stillCapture(false), |
Eino-Ville Talvala | f2e3709 | 2020-01-07 15:32:32 -0800 | [diff] [blame] | 212 | zslCapture(false), |
Shuzhen Wang | 316781a | 2020-08-18 18:11:01 -0700 | [diff] [blame] | 213 | rotateAndCropAuto(false), |
Emilian Peev | 5104fe9 | 2021-10-21 14:27:09 -0700 | [diff] [blame] | 214 | requestTimeNs(0), |
| 215 | transform(-1) { |
Yin-Chia Yeh | 5fd603e | 2019-11-20 11:22:27 -0800 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | InFlightRequest(int numBuffers, CaptureResultExtras extras, bool hasInput, |
Shuzhen Wang | 00abbeb | 2022-02-25 17:14:42 -0800 | [diff] [blame^] | 219 | bool hasAppCallback, nsecs_t minDuration, nsecs_t maxDuration, |
Shuzhen Wang | 9908050 | 2021-03-07 21:08:20 -0800 | [diff] [blame] | 220 | const std::set<std::set<String8>>& physicalCameraIdSet, bool isStillCapture, |
Eino-Ville Talvala | f2e3709 | 2020-01-07 15:32:32 -0800 | [diff] [blame] | 221 | bool isZslCapture, bool rotateAndCropAuto, const std::set<std::string>& idsWithZoom, |
Shuzhen Wang | 316781a | 2020-08-18 18:11:01 -0700 | [diff] [blame] | 222 | nsecs_t requestNs, const SurfaceMap& outSurfaces = SurfaceMap{}) : |
Yin-Chia Yeh | 5fd603e | 2019-11-20 11:22:27 -0800 | [diff] [blame] | 223 | shutterTimestamp(0), |
| 224 | sensorTimestamp(0), |
| 225 | requestStatus(OK), |
| 226 | haveResultMetadata(false), |
| 227 | numBuffersLeft(numBuffers), |
| 228 | resultExtras(extras), |
| 229 | hasInputBuffer(hasInput), |
| 230 | hasCallback(hasAppCallback), |
Shuzhen Wang | 00abbeb | 2022-02-25 17:14:42 -0800 | [diff] [blame^] | 231 | minExpectedDuration(minDuration), |
Yin-Chia Yeh | 5fd603e | 2019-11-20 11:22:27 -0800 | [diff] [blame] | 232 | maxExpectedDuration(maxDuration), |
| 233 | skipResultMetadata(false), |
Shuzhen Wang | b7b4265 | 2020-05-07 11:59:02 -0700 | [diff] [blame] | 234 | errorBufStrategy(ERROR_BUF_CACHE), |
Yin-Chia Yeh | 5fd603e | 2019-11-20 11:22:27 -0800 | [diff] [blame] | 235 | physicalCameraIds(physicalCameraIdSet), |
| 236 | stillCapture(isStillCapture), |
| 237 | zslCapture(isZslCapture), |
Eino-Ville Talvala | f2e3709 | 2020-01-07 15:32:32 -0800 | [diff] [blame] | 238 | rotateAndCropAuto(rotateAndCropAuto), |
Yin-Chia Yeh | 5fd603e | 2019-11-20 11:22:27 -0800 | [diff] [blame] | 239 | cameraIdsWithZoom(idsWithZoom), |
Shuzhen Wang | 316781a | 2020-08-18 18:11:01 -0700 | [diff] [blame] | 240 | requestTimeNs(requestNs), |
Emilian Peev | 5104fe9 | 2021-10-21 14:27:09 -0700 | [diff] [blame] | 241 | outputSurfaces(outSurfaces), |
| 242 | transform(-1) { |
Yin-Chia Yeh | 5fd603e | 2019-11-20 11:22:27 -0800 | [diff] [blame] | 243 | } |
| 244 | }; |
| 245 | |
| 246 | // Map from frame number to the in-flight request state |
| 247 | typedef KeyedVector<uint32_t, InFlightRequest> InFlightRequestMap; |
| 248 | |
| 249 | } // namespace camera3 |
| 250 | |
| 251 | } // namespace android |
| 252 | |
| 253 | #endif |