blob: 3cb83241d41156c3f87fc3ace3854bf0c51d9964 [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
35struct InFlightRequest {
36 // Set by notify() SHUTTER call.
37 nsecs_t shutterTimestamp;
38 // Set by process_capture_result().
39 nsecs_t sensorTimestamp;
40 int requestStatus;
41 // Set by process_capture_result call with valid metadata
42 bool haveResultMetadata;
43 // Decremented by calls to process_capture_result with valid output
44 // and input buffers
45 int numBuffersLeft;
Shuzhen Wang730a7912020-05-07 11:59:02 -070046 // Total number of output buffers for this request
47 int numOutputBuffers;
48
49 // The inflight request is considered complete if all buffers are returned
50 // and numErrorBuffersReturned == numErrorBuffersNotified.
51
52 // The number of buffers returned with STATUS_ERROR;
53 int numErrorBuffersReturned;
54 // The number of buffers that are notified as error:
55 // +1 for each notifyError(ERROR_BUFFER), and
56 // +numOutputBuffers for notifyError(ERROR_REQUEST)
57 int numErrorBuffersNotified;
58
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -080059 CaptureResultExtras resultExtras;
60 // If this request has any input buffer
61 bool hasInputBuffer;
62
63 // The last metadata that framework receives from HAL and
64 // not yet send out because the shutter event hasn't arrived.
65 // It's added by process_capture_result and sent when framework
66 // receives the shutter event.
67 CameraMetadata pendingMetadata;
68
69 // The metadata of the partial results that framework receives from HAL so far
70 // and has sent out.
71 CameraMetadata collectedPartialResult;
72
73 // Buffers are added by process_capture_result when output buffers
74 // return from HAL but framework has not yet received the shutter
75 // event. They will be returned to the streams when framework receives
76 // the shutter event.
77 Vector<camera3_stream_buffer_t> pendingOutputBuffers;
78
79 // Whether this inflight request's shutter and result callback are to be
80 // called. The policy is that if the request is the last one in the constrained
81 // high speed recording request list, this flag will be true. If the request list
82 // is not for constrained high speed recording, this flag will also be true.
83 bool hasCallback;
84
85 // Maximum expected frame duration for this request.
86 // For manual captures, equal to the max of requested exposure time and frame duration
87 // For auto-exposure modes, equal to 1/(lower end of target FPS range)
88 nsecs_t maxExpectedDuration;
89
90 // Whether the result metadata for this request is to be skipped. The
91 // result metadata should be skipped in the case of
92 // REQUEST/RESULT error.
93 bool skipResultMetadata;
94
95 // The physical camera ids being requested.
96 std::set<String8> physicalCameraIds;
97
98 // Map of physicalCameraId <-> Metadata
99 std::vector<PhysicalCaptureResultInfo> physicalMetadatas;
100
101 // Indicates a still capture request.
102 bool stillCapture;
103
104 // Indicates a ZSL capture request
105 bool zslCapture;
106
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800107 // Indicates that ROTATE_AND_CROP was set to AUTO
108 bool rotateAndCropAuto;
109
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800110 // Requested camera ids (both logical and physical) with zoomRatio != 1.0f
111 std::set<std::string> cameraIdsWithZoom;
112
113 // What shared surfaces an output should go to
114 SurfaceMap outputSurfaces;
115
116 // TODO: dedupe
117 static const nsecs_t kDefaultExpectedDuration = 100000000; // 100 ms
118
119 // Default constructor needed by KeyedVector
120 InFlightRequest() :
121 shutterTimestamp(0),
122 sensorTimestamp(0),
123 requestStatus(OK),
124 haveResultMetadata(false),
125 numBuffersLeft(0),
Shuzhen Wang730a7912020-05-07 11:59:02 -0700126 numOutputBuffers(0),
127 numErrorBuffersReturned(0),
128 numErrorBuffersNotified(0),
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800129 hasInputBuffer(false),
130 hasCallback(true),
131 maxExpectedDuration(kDefaultExpectedDuration),
132 skipResultMetadata(false),
133 stillCapture(false),
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800134 zslCapture(false),
135 rotateAndCropAuto(false) {
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800136 }
137
138 InFlightRequest(int numBuffers, CaptureResultExtras extras, bool hasInput,
139 bool hasAppCallback, nsecs_t maxDuration,
140 const std::set<String8>& physicalCameraIdSet, bool isStillCapture,
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800141 bool isZslCapture, bool rotateAndCropAuto, const std::set<std::string>& idsWithZoom,
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800142 const SurfaceMap& outSurfaces = SurfaceMap{}) :
143 shutterTimestamp(0),
144 sensorTimestamp(0),
145 requestStatus(OK),
146 haveResultMetadata(false),
147 numBuffersLeft(numBuffers),
Shuzhen Wang730a7912020-05-07 11:59:02 -0700148 numOutputBuffers(hasInput ? numBuffers-1 : numBuffers),
149 numErrorBuffersReturned(0),
150 numErrorBuffersNotified(0),
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800151 resultExtras(extras),
152 hasInputBuffer(hasInput),
153 hasCallback(hasAppCallback),
154 maxExpectedDuration(maxDuration),
155 skipResultMetadata(false),
156 physicalCameraIds(physicalCameraIdSet),
157 stillCapture(isStillCapture),
158 zslCapture(isZslCapture),
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800159 rotateAndCropAuto(rotateAndCropAuto),
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800160 cameraIdsWithZoom(idsWithZoom),
161 outputSurfaces(outSurfaces) {
162 }
163};
164
165// Map from frame number to the in-flight request state
166typedef KeyedVector<uint32_t, InFlightRequest> InFlightRequestMap;
167
168} // namespace camera3
169
170} // namespace android
171
172#endif