blob: 870825a3d7d9234aba980427b1f92f021e89bbef [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>
24#include <utils/String8.h>
25#include <utils/Timers.h>
26
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -080027#include "common/CameraDeviceBase.h"
28
29namespace android {
30
31namespace camera3 {
32
Jayant Chowdharyc30b4c32021-08-18 11:43:16 -070033typedef 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
40typedef 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
53typedef 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
65typedef struct camera_shutter_msg {
66 uint32_t frame_number;
67 uint64_t timestamp;
Shuzhen Wangffc4c012022-04-20 15:55:46 -070068 bool readout_timestamp_valid;
Shuzhen Wang90708ea2021-11-04 11:40:49 -070069 uint64_t readout_timestamp;
Jayant Chowdharyc30b4c32021-08-18 11:43:16 -070070} camera_shutter_msg_t;
71
72typedef struct camera_error_msg {
73 uint32_t frame_number;
74 camera_stream_t *error_stream;
75 int error_code;
76} camera_error_msg_t;
77
78typedef enum camera_error_msg_code {
79 CAMERA_MSG_ERROR_DEVICE = 1,
80 CAMERA_MSG_ERROR_REQUEST = 2,
81 CAMERA_MSG_ERROR_RESULT = 3,
82 CAMERA_MSG_ERROR_BUFFER = 4,
83 CAMERA_MSG_NUM_ERRORS
84} camera_error_msg_code_t;
85
86typedef struct camera_notify_msg {
87 int type;
88
89 union {
90 camera_error_msg_t error;
91 camera_shutter_msg_t shutter;
92 } message;
93} camera_notify_msg_t;
94
Shuzhen Wangb7b42652020-05-07 11:59:02 -070095typedef enum {
96 // Cache the buffers with STATUS_ERROR within InFlightRequest
97 ERROR_BUF_CACHE,
98 // Return the buffers with STATUS_ERROR to the buffer queue
99 ERROR_BUF_RETURN,
100 // Return the buffers with STATUS_ERROR to the buffer queue, and call
101 // notify(ERROR_BUFFER) as well
102 ERROR_BUF_RETURN_NOTIFY
103} ERROR_BUF_STRATEGY;
104
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800105struct InFlightRequest {
106 // Set by notify() SHUTTER call.
107 nsecs_t shutterTimestamp;
108 // Set by process_capture_result().
109 nsecs_t sensorTimestamp;
110 int requestStatus;
111 // Set by process_capture_result call with valid metadata
112 bool haveResultMetadata;
113 // Decremented by calls to process_capture_result with valid output
114 // and input buffers
115 int numBuffersLeft;
Shuzhen Wangb7b42652020-05-07 11:59:02 -0700116
117 // The inflight request is considered complete if all buffers are returned
118
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800119 CaptureResultExtras resultExtras;
120 // If this request has any input buffer
121 bool hasInputBuffer;
122
123 // The last metadata that framework receives from HAL and
124 // not yet send out because the shutter event hasn't arrived.
125 // It's added by process_capture_result and sent when framework
126 // receives the shutter event.
127 CameraMetadata pendingMetadata;
128
129 // The metadata of the partial results that framework receives from HAL so far
130 // and has sent out.
131 CameraMetadata collectedPartialResult;
132
133 // Buffers are added by process_capture_result when output buffers
134 // return from HAL but framework has not yet received the shutter
135 // event. They will be returned to the streams when framework receives
136 // the shutter event.
Emilian Peevf4816702020-04-03 15:44:51 -0700137 Vector<camera_stream_buffer_t> pendingOutputBuffers;
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800138
139 // Whether this inflight request's shutter and result callback are to be
140 // called. The policy is that if the request is the last one in the constrained
141 // high speed recording request list, this flag will be true. If the request list
142 // is not for constrained high speed recording, this flag will also be true.
143 bool hasCallback;
144
Shuzhen Wang00abbeb2022-02-25 17:14:42 -0800145 // Minimum expected frame duration for this request
146 // For manual captures, equal to the max of requested exposure time and frame duration
147 // For auto-exposure modes, equal to 1/(higher end of target FPS range)
148 nsecs_t minExpectedDuration;
149
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800150 // Maximum expected frame duration for this request.
151 // For manual captures, equal to the max of requested exposure time and frame duration
152 // For auto-exposure modes, equal to 1/(lower end of target FPS range)
153 nsecs_t maxExpectedDuration;
154
Shuzhen Wang696e4da2022-09-08 14:31:13 -0700155 // Whether the FPS range is fixed, aka, minFps == maxFps
156 bool isFixedFps;
157
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800158 // Whether the result metadata for this request is to be skipped. The
159 // result metadata should be skipped in the case of
160 // REQUEST/RESULT error.
161 bool skipResultMetadata;
162
Shuzhen Wangb7b42652020-05-07 11:59:02 -0700163 // Whether the buffers with STATUS_ERROR should be cached as pending buffers,
164 // returned to the buffer queue, or returned to the buffer queue and notify with ERROR_BUFFER.
165 ERROR_BUF_STRATEGY errorBufStrategy;
166
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800167 // The physical camera ids being requested.
Shuzhen Wang99080502021-03-07 21:08:20 -0800168 // For request on a physical camera stream, the inside set contains one Id
169 // For request on a stream group containing physical camera streams, the
170 // inside set contains all stream Ids in the group.
171 std::set<std::set<String8>> physicalCameraIds;
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800172
173 // Map of physicalCameraId <-> Metadata
174 std::vector<PhysicalCaptureResultInfo> physicalMetadatas;
175
176 // Indicates a still capture request.
177 bool stillCapture;
178
179 // Indicates a ZSL capture request
180 bool zslCapture;
181
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800182 // Indicates that ROTATE_AND_CROP was set to AUTO
183 bool rotateAndCropAuto;
184
Bharatt Kukreja7146ced2022-10-25 15:45:29 +0000185 // Indicates that AUTOFRAMING was set to AUTO
186 bool autoframingAuto;
187
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800188 // Requested camera ids (both logical and physical) with zoomRatio != 1.0f
189 std::set<std::string> cameraIdsWithZoom;
190
Shuzhen Wang316781a2020-08-18 18:11:01 -0700191 // Time of capture request (from systemTime) in Ns
192 nsecs_t requestTimeNs;
193
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800194 // What shared surfaces an output should go to
195 SurfaceMap outputSurfaces;
196
Emilian Peev5104fe92021-10-21 14:27:09 -0700197 // Current output transformation
198 int32_t transform;
199
Shuzhen Wang00abbeb2022-02-25 17:14:42 -0800200 static const nsecs_t kDefaultMinExpectedDuration = 33333333; // 33 ms
201 static const nsecs_t kDefaultMaxExpectedDuration = 100000000; // 100 ms
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800202
203 // Default constructor needed by KeyedVector
204 InFlightRequest() :
205 shutterTimestamp(0),
206 sensorTimestamp(0),
207 requestStatus(OK),
208 haveResultMetadata(false),
209 numBuffersLeft(0),
210 hasInputBuffer(false),
211 hasCallback(true),
Shuzhen Wang00abbeb2022-02-25 17:14:42 -0800212 minExpectedDuration(kDefaultMinExpectedDuration),
213 maxExpectedDuration(kDefaultMaxExpectedDuration),
Shuzhen Wang696e4da2022-09-08 14:31:13 -0700214 isFixedFps(false),
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800215 skipResultMetadata(false),
Shuzhen Wangb7b42652020-05-07 11:59:02 -0700216 errorBufStrategy(ERROR_BUF_CACHE),
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800217 stillCapture(false),
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800218 zslCapture(false),
Shuzhen Wang316781a2020-08-18 18:11:01 -0700219 rotateAndCropAuto(false),
Bharatt Kukreja7146ced2022-10-25 15:45:29 +0000220 autoframingAuto(false),
Emilian Peev5104fe92021-10-21 14:27:09 -0700221 requestTimeNs(0),
222 transform(-1) {
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800223 }
224
225 InFlightRequest(int numBuffers, CaptureResultExtras extras, bool hasInput,
Shuzhen Wang696e4da2022-09-08 14:31:13 -0700226 bool hasAppCallback, nsecs_t minDuration, nsecs_t maxDuration, bool fixedFps,
Shuzhen Wang99080502021-03-07 21:08:20 -0800227 const std::set<std::set<String8>>& physicalCameraIdSet, bool isStillCapture,
Bharatt Kukreja7146ced2022-10-25 15:45:29 +0000228 bool isZslCapture, bool rotateAndCropAuto, bool autoframingAuto,
229 const std::set<std::string>& idsWithZoom, nsecs_t requestNs,
230 const SurfaceMap& outSurfaces = SurfaceMap{}) :
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800231 shutterTimestamp(0),
232 sensorTimestamp(0),
233 requestStatus(OK),
234 haveResultMetadata(false),
235 numBuffersLeft(numBuffers),
236 resultExtras(extras),
237 hasInputBuffer(hasInput),
238 hasCallback(hasAppCallback),
Shuzhen Wang00abbeb2022-02-25 17:14:42 -0800239 minExpectedDuration(minDuration),
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800240 maxExpectedDuration(maxDuration),
Shuzhen Wang696e4da2022-09-08 14:31:13 -0700241 isFixedFps(fixedFps),
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800242 skipResultMetadata(false),
Shuzhen Wangb7b42652020-05-07 11:59:02 -0700243 errorBufStrategy(ERROR_BUF_CACHE),
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800244 physicalCameraIds(physicalCameraIdSet),
245 stillCapture(isStillCapture),
246 zslCapture(isZslCapture),
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800247 rotateAndCropAuto(rotateAndCropAuto),
Bharatt Kukreja7146ced2022-10-25 15:45:29 +0000248 autoframingAuto(autoframingAuto),
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800249 cameraIdsWithZoom(idsWithZoom),
Shuzhen Wang316781a2020-08-18 18:11:01 -0700250 requestTimeNs(requestNs),
Emilian Peev5104fe92021-10-21 14:27:09 -0700251 outputSurfaces(outSurfaces),
252 transform(-1) {
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800253 }
254};
255
256// Map from frame number to the in-flight request state
257typedef KeyedVector<uint32_t, InFlightRequest> InFlightRequestMap;
258
259} // namespace camera3
260
261} // namespace android
262
263#endif