blob: e3aaf44fc3f4a6019a215a64df2a0025a8fbe506 [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
Shuzhen Wangb7b42652020-05-07 11:59:02 -070033typedef enum {
34 // Cache the buffers with STATUS_ERROR within InFlightRequest
35 ERROR_BUF_CACHE,
36 // Return the buffers with STATUS_ERROR to the buffer queue
37 ERROR_BUF_RETURN,
38 // Return the buffers with STATUS_ERROR to the buffer queue, and call
39 // notify(ERROR_BUFFER) as well
40 ERROR_BUF_RETURN_NOTIFY
41} ERROR_BUF_STRATEGY;
42
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -080043struct InFlightRequest {
Shuzhen Wangb7b42652020-05-07 11:59:02 -070044
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -080045 // Set by notify() SHUTTER call.
46 nsecs_t shutterTimestamp;
47 // Set by process_capture_result().
48 nsecs_t sensorTimestamp;
49 int requestStatus;
50 // Set by process_capture_result call with valid metadata
51 bool haveResultMetadata;
52 // Decremented by calls to process_capture_result with valid output
53 // and input buffers
54 int numBuffersLeft;
Shuzhen Wangb7b42652020-05-07 11:59:02 -070055
56 // The inflight request is considered complete if all buffers are returned
57
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -080058 CaptureResultExtras resultExtras;
59 // If this request has any input buffer
60 bool hasInputBuffer;
61
62 // The last metadata that framework receives from HAL and
63 // not yet send out because the shutter event hasn't arrived.
64 // It's added by process_capture_result and sent when framework
65 // receives the shutter event.
66 CameraMetadata pendingMetadata;
67
68 // The metadata of the partial results that framework receives from HAL so far
69 // and has sent out.
70 CameraMetadata collectedPartialResult;
71
72 // Buffers are added by process_capture_result when output buffers
73 // return from HAL but framework has not yet received the shutter
74 // event. They will be returned to the streams when framework receives
75 // the shutter event.
Emilian Peevf4816702020-04-03 15:44:51 -070076 Vector<camera_stream_buffer_t> pendingOutputBuffers;
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -080077
78 // Whether this inflight request's shutter and result callback are to be
79 // called. The policy is that if the request is the last one in the constrained
80 // high speed recording request list, this flag will be true. If the request list
81 // is not for constrained high speed recording, this flag will also be true.
82 bool hasCallback;
83
84 // Maximum expected frame duration for this request.
85 // For manual captures, equal to the max of requested exposure time and frame duration
86 // For auto-exposure modes, equal to 1/(lower end of target FPS range)
87 nsecs_t maxExpectedDuration;
88
89 // Whether the result metadata for this request is to be skipped. The
90 // result metadata should be skipped in the case of
91 // REQUEST/RESULT error.
92 bool skipResultMetadata;
93
Shuzhen Wangb7b42652020-05-07 11:59:02 -070094 // Whether the buffers with STATUS_ERROR should be cached as pending buffers,
95 // returned to the buffer queue, or returned to the buffer queue and notify with ERROR_BUFFER.
96 ERROR_BUF_STRATEGY errorBufStrategy;
97
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -080098 // The physical camera ids being requested.
99 std::set<String8> physicalCameraIds;
100
101 // Map of physicalCameraId <-> Metadata
102 std::vector<PhysicalCaptureResultInfo> physicalMetadatas;
103
104 // Indicates a still capture request.
105 bool stillCapture;
106
107 // Indicates a ZSL capture request
108 bool zslCapture;
109
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800110 // Indicates that ROTATE_AND_CROP was set to AUTO
111 bool rotateAndCropAuto;
112
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800113 // Requested camera ids (both logical and physical) with zoomRatio != 1.0f
114 std::set<std::string> cameraIdsWithZoom;
115
Shuzhen Wang316781a2020-08-18 18:11:01 -0700116 // Time of capture request (from systemTime) in Ns
117 nsecs_t requestTimeNs;
118
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800119 // What shared surfaces an output should go to
120 SurfaceMap outputSurfaces;
121
122 // TODO: dedupe
123 static const nsecs_t kDefaultExpectedDuration = 100000000; // 100 ms
124
125 // Default constructor needed by KeyedVector
126 InFlightRequest() :
127 shutterTimestamp(0),
128 sensorTimestamp(0),
129 requestStatus(OK),
130 haveResultMetadata(false),
131 numBuffersLeft(0),
132 hasInputBuffer(false),
133 hasCallback(true),
134 maxExpectedDuration(kDefaultExpectedDuration),
135 skipResultMetadata(false),
Shuzhen Wangb7b42652020-05-07 11:59:02 -0700136 errorBufStrategy(ERROR_BUF_CACHE),
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800137 stillCapture(false),
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800138 zslCapture(false),
Shuzhen Wang316781a2020-08-18 18:11:01 -0700139 rotateAndCropAuto(false),
140 requestTimeNs(0) {
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800141 }
142
143 InFlightRequest(int numBuffers, CaptureResultExtras extras, bool hasInput,
144 bool hasAppCallback, nsecs_t maxDuration,
145 const std::set<String8>& physicalCameraIdSet, bool isStillCapture,
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800146 bool isZslCapture, bool rotateAndCropAuto, const std::set<std::string>& idsWithZoom,
Shuzhen Wang316781a2020-08-18 18:11:01 -0700147 nsecs_t requestNs, const SurfaceMap& outSurfaces = SurfaceMap{}) :
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800148 shutterTimestamp(0),
149 sensorTimestamp(0),
150 requestStatus(OK),
151 haveResultMetadata(false),
152 numBuffersLeft(numBuffers),
153 resultExtras(extras),
154 hasInputBuffer(hasInput),
155 hasCallback(hasAppCallback),
156 maxExpectedDuration(maxDuration),
157 skipResultMetadata(false),
Shuzhen Wangb7b42652020-05-07 11:59:02 -0700158 errorBufStrategy(ERROR_BUF_CACHE),
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800159 physicalCameraIds(physicalCameraIdSet),
160 stillCapture(isStillCapture),
161 zslCapture(isZslCapture),
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800162 rotateAndCropAuto(rotateAndCropAuto),
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800163 cameraIdsWithZoom(idsWithZoom),
Shuzhen Wang316781a2020-08-18 18:11:01 -0700164 requestTimeNs(requestNs),
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800165 outputSurfaces(outSurfaces) {
166 }
167};
168
169// Map from frame number to the in-flight request state
170typedef KeyedVector<uint32_t, InFlightRequest> InFlightRequestMap;
171
172} // namespace camera3
173
174} // namespace android
175
176#endif