blob: 85e809c3defc6d1199babfb1dad660fc91c6cdd9 [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;
68} camera_shutter_msg_t;
69
70typedef struct camera_error_msg {
71 uint32_t frame_number;
72 camera_stream_t *error_stream;
73 int error_code;
74} camera_error_msg_t;
75
76typedef enum camera_error_msg_code {
77 CAMERA_MSG_ERROR_DEVICE = 1,
78 CAMERA_MSG_ERROR_REQUEST = 2,
79 CAMERA_MSG_ERROR_RESULT = 3,
80 CAMERA_MSG_ERROR_BUFFER = 4,
81 CAMERA_MSG_NUM_ERRORS
82} camera_error_msg_code_t;
83
84typedef struct camera_notify_msg {
85 int type;
86
87 union {
88 camera_error_msg_t error;
89 camera_shutter_msg_t shutter;
90 } message;
91} camera_notify_msg_t;
92
Shuzhen Wangb7b42652020-05-07 11:59:02 -070093typedef enum {
94 // Cache the buffers with STATUS_ERROR within InFlightRequest
95 ERROR_BUF_CACHE,
96 // Return the buffers with STATUS_ERROR to the buffer queue
97 ERROR_BUF_RETURN,
98 // Return the buffers with STATUS_ERROR to the buffer queue, and call
99 // notify(ERROR_BUFFER) as well
100 ERROR_BUF_RETURN_NOTIFY
101} ERROR_BUF_STRATEGY;
102
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800103struct InFlightRequest {
Shuzhen Wangb7b42652020-05-07 11:59:02 -0700104
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800105 // 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
144 // Maximum 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/(lower end of target FPS range)
147 nsecs_t maxExpectedDuration;
148
149 // Whether the result metadata for this request is to be skipped. The
150 // result metadata should be skipped in the case of
151 // REQUEST/RESULT error.
152 bool skipResultMetadata;
153
Shuzhen Wangb7b42652020-05-07 11:59:02 -0700154 // Whether the buffers with STATUS_ERROR should be cached as pending buffers,
155 // returned to the buffer queue, or returned to the buffer queue and notify with ERROR_BUFFER.
156 ERROR_BUF_STRATEGY errorBufStrategy;
157
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800158 // The physical camera ids being requested.
Shuzhen Wang99080502021-03-07 21:08:20 -0800159 // For request on a physical camera stream, the inside set contains one Id
160 // For request on a stream group containing physical camera streams, the
161 // inside set contains all stream Ids in the group.
162 std::set<std::set<String8>> physicalCameraIds;
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800163
164 // Map of physicalCameraId <-> Metadata
165 std::vector<PhysicalCaptureResultInfo> physicalMetadatas;
166
167 // Indicates a still capture request.
168 bool stillCapture;
169
170 // Indicates a ZSL capture request
171 bool zslCapture;
172
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800173 // Indicates that ROTATE_AND_CROP was set to AUTO
174 bool rotateAndCropAuto;
175
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800176 // Requested camera ids (both logical and physical) with zoomRatio != 1.0f
177 std::set<std::string> cameraIdsWithZoom;
178
Shuzhen Wang316781a2020-08-18 18:11:01 -0700179 // Time of capture request (from systemTime) in Ns
180 nsecs_t requestTimeNs;
181
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800182 // What shared surfaces an output should go to
183 SurfaceMap outputSurfaces;
184
185 // TODO: dedupe
186 static const nsecs_t kDefaultExpectedDuration = 100000000; // 100 ms
187
188 // Default constructor needed by KeyedVector
189 InFlightRequest() :
190 shutterTimestamp(0),
191 sensorTimestamp(0),
192 requestStatus(OK),
193 haveResultMetadata(false),
194 numBuffersLeft(0),
195 hasInputBuffer(false),
196 hasCallback(true),
197 maxExpectedDuration(kDefaultExpectedDuration),
198 skipResultMetadata(false),
Shuzhen Wangb7b42652020-05-07 11:59:02 -0700199 errorBufStrategy(ERROR_BUF_CACHE),
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800200 stillCapture(false),
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800201 zslCapture(false),
Shuzhen Wang316781a2020-08-18 18:11:01 -0700202 rotateAndCropAuto(false),
203 requestTimeNs(0) {
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800204 }
205
206 InFlightRequest(int numBuffers, CaptureResultExtras extras, bool hasInput,
207 bool hasAppCallback, nsecs_t maxDuration,
Shuzhen Wang99080502021-03-07 21:08:20 -0800208 const std::set<std::set<String8>>& physicalCameraIdSet, bool isStillCapture,
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800209 bool isZslCapture, bool rotateAndCropAuto, const std::set<std::string>& idsWithZoom,
Shuzhen Wang316781a2020-08-18 18:11:01 -0700210 nsecs_t requestNs, const SurfaceMap& outSurfaces = SurfaceMap{}) :
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800211 shutterTimestamp(0),
212 sensorTimestamp(0),
213 requestStatus(OK),
214 haveResultMetadata(false),
215 numBuffersLeft(numBuffers),
216 resultExtras(extras),
217 hasInputBuffer(hasInput),
218 hasCallback(hasAppCallback),
219 maxExpectedDuration(maxDuration),
220 skipResultMetadata(false),
Shuzhen Wangb7b42652020-05-07 11:59:02 -0700221 errorBufStrategy(ERROR_BUF_CACHE),
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800222 physicalCameraIds(physicalCameraIdSet),
223 stillCapture(isStillCapture),
224 zslCapture(isZslCapture),
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800225 rotateAndCropAuto(rotateAndCropAuto),
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800226 cameraIdsWithZoom(idsWithZoom),
Shuzhen Wang316781a2020-08-18 18:11:01 -0700227 requestTimeNs(requestNs),
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800228 outputSurfaces(outSurfaces) {
229 }
230};
231
232// Map from frame number to the in-flight request state
233typedef KeyedVector<uint32_t, InFlightRequest> InFlightRequestMap;
234
235} // namespace camera3
236
237} // namespace android
238
239#endif