blob: 665ac73528a346dbd2ffc163341b43242ee1d204 [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
Bharatt Kukreja7146ced2022-10-25 15:45:29 +0000184 // Indicates that AUTOFRAMING was set to AUTO
185 bool autoframingAuto;
186
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800187 // Requested camera ids (both logical and physical) with zoomRatio != 1.0f
188 std::set<std::string> cameraIdsWithZoom;
189
Shuzhen Wang316781a2020-08-18 18:11:01 -0700190 // Time of capture request (from systemTime) in Ns
191 nsecs_t requestTimeNs;
192
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800193 // What shared surfaces an output should go to
194 SurfaceMap outputSurfaces;
195
Emilian Peev5104fe92021-10-21 14:27:09 -0700196 // Current output transformation
197 int32_t transform;
198
Shuzhen Wang00abbeb2022-02-25 17:14:42 -0800199 static const nsecs_t kDefaultMinExpectedDuration = 33333333; // 33 ms
200 static const nsecs_t kDefaultMaxExpectedDuration = 100000000; // 100 ms
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800201
202 // Default constructor needed by KeyedVector
203 InFlightRequest() :
204 shutterTimestamp(0),
205 sensorTimestamp(0),
206 requestStatus(OK),
207 haveResultMetadata(false),
208 numBuffersLeft(0),
209 hasInputBuffer(false),
210 hasCallback(true),
Shuzhen Wang00abbeb2022-02-25 17:14:42 -0800211 minExpectedDuration(kDefaultMinExpectedDuration),
212 maxExpectedDuration(kDefaultMaxExpectedDuration),
Shuzhen Wang696e4da2022-09-08 14:31:13 -0700213 isFixedFps(false),
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800214 skipResultMetadata(false),
Shuzhen Wangb7b42652020-05-07 11:59:02 -0700215 errorBufStrategy(ERROR_BUF_CACHE),
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800216 stillCapture(false),
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800217 zslCapture(false),
Shuzhen Wang316781a2020-08-18 18:11:01 -0700218 rotateAndCropAuto(false),
Bharatt Kukreja7146ced2022-10-25 15:45:29 +0000219 autoframingAuto(false),
Emilian Peev5104fe92021-10-21 14:27:09 -0700220 requestTimeNs(0),
221 transform(-1) {
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800222 }
223
224 InFlightRequest(int numBuffers, CaptureResultExtras extras, bool hasInput,
Shuzhen Wang696e4da2022-09-08 14:31:13 -0700225 bool hasAppCallback, nsecs_t minDuration, nsecs_t maxDuration, bool fixedFps,
Austin Borger0fb3ad92023-06-01 16:51:35 -0700226 const std::set<std::set<std::string>>& physicalCameraIdSet, bool isStillCapture,
Bharatt Kukreja7146ced2022-10-25 15:45:29 +0000227 bool isZslCapture, bool rotateAndCropAuto, bool autoframingAuto,
228 const std::set<std::string>& idsWithZoom, nsecs_t requestNs,
229 const SurfaceMap& outSurfaces = SurfaceMap{}) :
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800230 shutterTimestamp(0),
231 sensorTimestamp(0),
232 requestStatus(OK),
233 haveResultMetadata(false),
234 numBuffersLeft(numBuffers),
235 resultExtras(extras),
236 hasInputBuffer(hasInput),
237 hasCallback(hasAppCallback),
Shuzhen Wang00abbeb2022-02-25 17:14:42 -0800238 minExpectedDuration(minDuration),
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800239 maxExpectedDuration(maxDuration),
Shuzhen Wang696e4da2022-09-08 14:31:13 -0700240 isFixedFps(fixedFps),
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800241 skipResultMetadata(false),
Shuzhen Wangb7b42652020-05-07 11:59:02 -0700242 errorBufStrategy(ERROR_BUF_CACHE),
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800243 physicalCameraIds(physicalCameraIdSet),
244 stillCapture(isStillCapture),
245 zslCapture(isZslCapture),
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800246 rotateAndCropAuto(rotateAndCropAuto),
Bharatt Kukreja7146ced2022-10-25 15:45:29 +0000247 autoframingAuto(autoframingAuto),
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800248 cameraIdsWithZoom(idsWithZoom),
Shuzhen Wang316781a2020-08-18 18:11:01 -0700249 requestTimeNs(requestNs),
Emilian Peev5104fe92021-10-21 14:27:09 -0700250 outputSurfaces(outSurfaces),
251 transform(-1) {
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800252 }
253};
254
255// Map from frame number to the in-flight request state
256typedef KeyedVector<uint32_t, InFlightRequest> InFlightRequestMap;
257
258} // namespace camera3
259
260} // namespace android
261
262#endif