blob: 4c193491eae1694370402f39052ce58cd2741e21 [file] [log] [blame]
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -08001/*
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>
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -080024#include <utils/Timers.h>
25
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -080026#include "common/CameraDeviceBase.h"
27
28namespace android {
29
30namespace camera3 {
31
Jayant Chowdharyc30b4c32021-08-18 11:43:16 -070032typedef 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} camera_stream_configuration_t;
38
39typedef struct camera_capture_request {
40 uint32_t frame_number;
41 const camera_metadata_t *settings;
42 camera_stream_buffer_t *input_buffer;
43 uint32_t num_output_buffers;
44 const camera_stream_buffer_t *output_buffers;
45 uint32_t num_physcam_settings;
46 const char **physcam_id;
47 const camera_metadata_t **physcam_settings;
48 int32_t input_width;
49 int32_t input_height;
50} camera_capture_request_t;
51
52typedef struct camera_capture_result {
53 uint32_t frame_number;
54 const camera_metadata_t *result;
55 uint32_t num_output_buffers;
56 const camera_stream_buffer_t *output_buffers;
57 const camera_stream_buffer_t *input_buffer;
58 uint32_t partial_result;
59 uint32_t num_physcam_metadata;
60 const char **physcam_ids;
61 const camera_metadata_t **physcam_metadata;
62} camera_capture_result_t;
63
64typedef struct camera_shutter_msg {
65 uint32_t frame_number;
66 uint64_t timestamp;
Shuzhen Wangffc4c012022-04-20 15:55:46 -070067 bool readout_timestamp_valid;
Shuzhen Wang90708ea2021-11-04 11:40:49 -070068 uint64_t readout_timestamp;
Jayant Chowdharyc30b4c32021-08-18 11:43:16 -070069} camera_shutter_msg_t;
70
71typedef 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
77typedef 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
85typedef 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 Wangb7b42652020-05-07 11:59:02 -070094typedef 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 Yeh5fd603e2019-11-20 11:22:27 -0800104struct InFlightRequest {
105 // Set by notify() SHUTTER call.
106 nsecs_t shutterTimestamp;
107 // Set by process_capture_result().
108 nsecs_t sensorTimestamp;
109 int requestStatus;
110 // Set by process_capture_result call with valid metadata
111 bool haveResultMetadata;
112 // Decremented by calls to process_capture_result with valid output
113 // and input buffers
114 int numBuffersLeft;
Shuzhen Wangb7b42652020-05-07 11:59:02 -0700115
116 // The inflight request is considered complete if all buffers are returned
117
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800118 CaptureResultExtras resultExtras;
119 // If this request has any input buffer
120 bool hasInputBuffer;
121
122 // The last metadata that framework receives from HAL and
123 // not yet send out because the shutter event hasn't arrived.
124 // It's added by process_capture_result and sent when framework
125 // receives the shutter event.
126 CameraMetadata pendingMetadata;
127
128 // The metadata of the partial results that framework receives from HAL so far
129 // and has sent out.
130 CameraMetadata collectedPartialResult;
131
132 // Buffers are added by process_capture_result when output buffers
133 // return from HAL but framework has not yet received the shutter
134 // event. They will be returned to the streams when framework receives
135 // the shutter event.
Emilian Peevf4816702020-04-03 15:44:51 -0700136 Vector<camera_stream_buffer_t> pendingOutputBuffers;
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800137
138 // Whether this inflight request's shutter and result callback are to be
139 // called. The policy is that if the request is the last one in the constrained
140 // high speed recording request list, this flag will be true. If the request list
141 // is not for constrained high speed recording, this flag will also be true.
142 bool hasCallback;
143
Shuzhen Wang00abbeb2022-02-25 17:14:42 -0800144 // Minimum expected frame duration for this request
145 // For manual captures, equal to the max of requested exposure time and frame duration
146 // For auto-exposure modes, equal to 1/(higher end of target FPS range)
147 nsecs_t minExpectedDuration;
148
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800149 // Maximum expected frame duration for this request.
150 // For manual captures, equal to the max of requested exposure time and frame duration
151 // For auto-exposure modes, equal to 1/(lower end of target FPS range)
152 nsecs_t maxExpectedDuration;
153
Shuzhen Wang696e4da2022-09-08 14:31:13 -0700154 // Whether the FPS range is fixed, aka, minFps == maxFps
155 bool isFixedFps;
156
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800157 // Whether the result metadata for this request is to be skipped. The
158 // result metadata should be skipped in the case of
159 // REQUEST/RESULT error.
160 bool skipResultMetadata;
161
Shuzhen Wangb7b42652020-05-07 11:59:02 -0700162 // Whether the buffers with STATUS_ERROR should be cached as pending buffers,
163 // returned to the buffer queue, or returned to the buffer queue and notify with ERROR_BUFFER.
164 ERROR_BUF_STRATEGY errorBufStrategy;
165
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800166 // The physical camera ids being requested.
Shuzhen Wang99080502021-03-07 21:08:20 -0800167 // For request on a physical camera stream, the inside set contains one Id
168 // For request on a stream group containing physical camera streams, the
169 // inside set contains all stream Ids in the group.
Austin Borger0fb3ad92023-06-01 16:51:35 -0700170 std::set<std::set<std::string>> physicalCameraIds;
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800171
172 // Map of physicalCameraId <-> Metadata
173 std::vector<PhysicalCaptureResultInfo> physicalMetadatas;
174
175 // Indicates a still capture request.
176 bool stillCapture;
177
178 // Indicates a ZSL capture request
179 bool zslCapture;
180
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800181 // Indicates that ROTATE_AND_CROP was set to AUTO
182 bool rotateAndCropAuto;
183
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800184 // Requested camera ids (both logical and physical) with zoomRatio != 1.0f
185 std::set<std::string> cameraIdsWithZoom;
186
Shuzhen Wang316781a2020-08-18 18:11:01 -0700187 // Time of capture request (from systemTime) in Ns
188 nsecs_t requestTimeNs;
189
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800190 // What shared surfaces an output should go to
191 SurfaceMap outputSurfaces;
192
Emilian Peev5104fe92021-10-21 14:27:09 -0700193 // Current output transformation
194 int32_t transform;
195
Shuzhen Wang00abbeb2022-02-25 17:14:42 -0800196 static const nsecs_t kDefaultMinExpectedDuration = 33333333; // 33 ms
197 static const nsecs_t kDefaultMaxExpectedDuration = 100000000; // 100 ms
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800198
199 // Default constructor needed by KeyedVector
200 InFlightRequest() :
201 shutterTimestamp(0),
202 sensorTimestamp(0),
203 requestStatus(OK),
204 haveResultMetadata(false),
205 numBuffersLeft(0),
206 hasInputBuffer(false),
207 hasCallback(true),
Shuzhen Wang00abbeb2022-02-25 17:14:42 -0800208 minExpectedDuration(kDefaultMinExpectedDuration),
209 maxExpectedDuration(kDefaultMaxExpectedDuration),
Shuzhen Wang696e4da2022-09-08 14:31:13 -0700210 isFixedFps(false),
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800211 skipResultMetadata(false),
Shuzhen Wangb7b42652020-05-07 11:59:02 -0700212 errorBufStrategy(ERROR_BUF_CACHE),
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800213 stillCapture(false),
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800214 zslCapture(false),
Shuzhen Wang316781a2020-08-18 18:11:01 -0700215 rotateAndCropAuto(false),
Emilian Peev5104fe92021-10-21 14:27:09 -0700216 requestTimeNs(0),
217 transform(-1) {
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800218 }
219
220 InFlightRequest(int numBuffers, CaptureResultExtras extras, bool hasInput,
Shuzhen Wang696e4da2022-09-08 14:31:13 -0700221 bool hasAppCallback, nsecs_t minDuration, nsecs_t maxDuration, bool fixedFps,
Austin Borger0fb3ad92023-06-01 16:51:35 -0700222 const std::set<std::set<std::string>>& physicalCameraIdSet, bool isStillCapture,
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800223 bool isZslCapture, bool rotateAndCropAuto, const std::set<std::string>& idsWithZoom,
Shuzhen Wang316781a2020-08-18 18:11:01 -0700224 nsecs_t requestNs, const SurfaceMap& outSurfaces = SurfaceMap{}) :
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800225 shutterTimestamp(0),
226 sensorTimestamp(0),
227 requestStatus(OK),
228 haveResultMetadata(false),
229 numBuffersLeft(numBuffers),
230 resultExtras(extras),
231 hasInputBuffer(hasInput),
232 hasCallback(hasAppCallback),
Shuzhen Wang00abbeb2022-02-25 17:14:42 -0800233 minExpectedDuration(minDuration),
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800234 maxExpectedDuration(maxDuration),
Shuzhen Wang696e4da2022-09-08 14:31:13 -0700235 isFixedFps(fixedFps),
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800236 skipResultMetadata(false),
Shuzhen Wangb7b42652020-05-07 11:59:02 -0700237 errorBufStrategy(ERROR_BUF_CACHE),
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800238 physicalCameraIds(physicalCameraIdSet),
239 stillCapture(isStillCapture),
240 zslCapture(isZslCapture),
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800241 rotateAndCropAuto(rotateAndCropAuto),
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800242 cameraIdsWithZoom(idsWithZoom),
Shuzhen Wang316781a2020-08-18 18:11:01 -0700243 requestTimeNs(requestNs),
Emilian Peev5104fe92021-10-21 14:27:09 -0700244 outputSurfaces(outSurfaces),
245 transform(-1) {
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800246 }
247};
248
249// Map from frame number to the in-flight request state
250typedef KeyedVector<uint32_t, InFlightRequest> InFlightRequestMap;
251
252} // namespace camera3
253
254} // namespace android
255
256#endif