blob: c7b7475f9f1ba85196e867d4b06e3092531f9714 [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
27#include "hardware/camera3.h"
28
29#include "common/CameraDeviceBase.h"
30
31namespace android {
32
33namespace camera3 {
34
Shuzhen Wangb7b42652020-05-07 11:59:02 -070035typedef enum {
36 // Cache the buffers with STATUS_ERROR within InFlightRequest
37 ERROR_BUF_CACHE,
38 // Return the buffers with STATUS_ERROR to the buffer queue
39 ERROR_BUF_RETURN,
40 // Return the buffers with STATUS_ERROR to the buffer queue, and call
41 // notify(ERROR_BUFFER) as well
42 ERROR_BUF_RETURN_NOTIFY
43} ERROR_BUF_STRATEGY;
44
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -080045struct InFlightRequest {
Shuzhen Wangb7b42652020-05-07 11:59:02 -070046
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -080047 // Set by notify() SHUTTER call.
48 nsecs_t shutterTimestamp;
49 // Set by process_capture_result().
50 nsecs_t sensorTimestamp;
51 int requestStatus;
52 // Set by process_capture_result call with valid metadata
53 bool haveResultMetadata;
54 // Decremented by calls to process_capture_result with valid output
55 // and input buffers
56 int numBuffersLeft;
Shuzhen Wangb7b42652020-05-07 11:59:02 -070057
58 // The inflight request is considered complete if all buffers are returned
59
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -080060 CaptureResultExtras resultExtras;
61 // If this request has any input buffer
62 bool hasInputBuffer;
63
64 // The last metadata that framework receives from HAL and
65 // not yet send out because the shutter event hasn't arrived.
66 // It's added by process_capture_result and sent when framework
67 // receives the shutter event.
68 CameraMetadata pendingMetadata;
69
70 // The metadata of the partial results that framework receives from HAL so far
71 // and has sent out.
72 CameraMetadata collectedPartialResult;
73
74 // Buffers are added by process_capture_result when output buffers
75 // return from HAL but framework has not yet received the shutter
76 // event. They will be returned to the streams when framework receives
77 // the shutter event.
78 Vector<camera3_stream_buffer_t> pendingOutputBuffers;
79
80 // Whether this inflight request's shutter and result callback are to be
81 // called. The policy is that if the request is the last one in the constrained
82 // high speed recording request list, this flag will be true. If the request list
83 // is not for constrained high speed recording, this flag will also be true.
84 bool hasCallback;
85
86 // Maximum expected frame duration for this request.
87 // For manual captures, equal to the max of requested exposure time and frame duration
88 // For auto-exposure modes, equal to 1/(lower end of target FPS range)
89 nsecs_t maxExpectedDuration;
90
91 // Whether the result metadata for this request is to be skipped. The
92 // result metadata should be skipped in the case of
93 // REQUEST/RESULT error.
94 bool skipResultMetadata;
95
Shuzhen Wangb7b42652020-05-07 11:59:02 -070096 // Whether the buffers with STATUS_ERROR should be cached as pending buffers,
97 // returned to the buffer queue, or returned to the buffer queue and notify with ERROR_BUFFER.
98 ERROR_BUF_STRATEGY errorBufStrategy;
99
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800100 // The physical camera ids being requested.
101 std::set<String8> physicalCameraIds;
102
103 // Map of physicalCameraId <-> Metadata
104 std::vector<PhysicalCaptureResultInfo> physicalMetadatas;
105
106 // Indicates a still capture request.
107 bool stillCapture;
108
109 // Indicates a ZSL capture request
110 bool zslCapture;
111
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800112 // Indicates that ROTATE_AND_CROP was set to AUTO
113 bool rotateAndCropAuto;
114
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800115 // Requested camera ids (both logical and physical) with zoomRatio != 1.0f
116 std::set<std::string> cameraIdsWithZoom;
117
Shuzhen Wang316781a2020-08-18 18:11:01 -0700118 // Time of capture request (from systemTime) in Ns
119 nsecs_t requestTimeNs;
120
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800121 // What shared surfaces an output should go to
122 SurfaceMap outputSurfaces;
123
124 // TODO: dedupe
125 static const nsecs_t kDefaultExpectedDuration = 100000000; // 100 ms
126
127 // Default constructor needed by KeyedVector
128 InFlightRequest() :
129 shutterTimestamp(0),
130 sensorTimestamp(0),
131 requestStatus(OK),
132 haveResultMetadata(false),
133 numBuffersLeft(0),
134 hasInputBuffer(false),
135 hasCallback(true),
136 maxExpectedDuration(kDefaultExpectedDuration),
137 skipResultMetadata(false),
Shuzhen Wangb7b42652020-05-07 11:59:02 -0700138 errorBufStrategy(ERROR_BUF_CACHE),
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800139 stillCapture(false),
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800140 zslCapture(false),
Shuzhen Wang316781a2020-08-18 18:11:01 -0700141 rotateAndCropAuto(false),
142 requestTimeNs(0) {
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800143 }
144
145 InFlightRequest(int numBuffers, CaptureResultExtras extras, bool hasInput,
146 bool hasAppCallback, nsecs_t maxDuration,
147 const std::set<String8>& physicalCameraIdSet, bool isStillCapture,
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800148 bool isZslCapture, bool rotateAndCropAuto, const std::set<std::string>& idsWithZoom,
Shuzhen Wang316781a2020-08-18 18:11:01 -0700149 nsecs_t requestNs, const SurfaceMap& outSurfaces = SurfaceMap{}) :
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800150 shutterTimestamp(0),
151 sensorTimestamp(0),
152 requestStatus(OK),
153 haveResultMetadata(false),
154 numBuffersLeft(numBuffers),
155 resultExtras(extras),
156 hasInputBuffer(hasInput),
157 hasCallback(hasAppCallback),
158 maxExpectedDuration(maxDuration),
159 skipResultMetadata(false),
Shuzhen Wangb7b42652020-05-07 11:59:02 -0700160 errorBufStrategy(ERROR_BUF_CACHE),
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800161 physicalCameraIds(physicalCameraIdSet),
162 stillCapture(isStillCapture),
163 zslCapture(isZslCapture),
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800164 rotateAndCropAuto(rotateAndCropAuto),
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800165 cameraIdsWithZoom(idsWithZoom),
Shuzhen Wang316781a2020-08-18 18:11:01 -0700166 requestTimeNs(requestNs),
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800167 outputSurfaces(outSurfaces) {
168 }
169};
170
171// Map from frame number to the in-flight request state
172typedef KeyedVector<uint32_t, InFlightRequest> InFlightRequestMap;
173
174} // namespace camera3
175
176} // namespace android
177
178#endif