• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 "common/CameraDeviceBase.h"
28 
29 namespace android {
30 
31 namespace camera3 {
32 
33 typedef 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 
43 struct InFlightRequest {
44 
45     // 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;
55 
56     // The inflight request is considered complete if all buffers are returned
57 
58     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.
76     Vector<camera_stream_buffer_t> pendingOutputBuffers;
77 
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 
94     // 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 
98     // The physical camera ids being requested.
99     // For request on a physical camera stream, the inside set contains one Id
100     // For request on a stream group containing physical camera streams, the
101     // inside set contains all stream Ids in the group.
102     std::set<std::set<String8>> physicalCameraIds;
103 
104     // Map of physicalCameraId <-> Metadata
105     std::vector<PhysicalCaptureResultInfo> physicalMetadatas;
106 
107     // Indicates a still capture request.
108     bool stillCapture;
109 
110     // Indicates a ZSL capture request
111     bool zslCapture;
112 
113     // Indicates that ROTATE_AND_CROP was set to AUTO
114     bool rotateAndCropAuto;
115 
116     // Requested camera ids (both logical and physical) with zoomRatio != 1.0f
117     std::set<std::string> cameraIdsWithZoom;
118 
119     // Time of capture request (from systemTime) in Ns
120     nsecs_t requestTimeNs;
121 
122     // What shared surfaces an output should go to
123     SurfaceMap outputSurfaces;
124 
125     // TODO: dedupe
126     static const nsecs_t kDefaultExpectedDuration = 100000000; // 100 ms
127 
128     // Default constructor needed by KeyedVector
InFlightRequestInFlightRequest129     InFlightRequest() :
130             shutterTimestamp(0),
131             sensorTimestamp(0),
132             requestStatus(OK),
133             haveResultMetadata(false),
134             numBuffersLeft(0),
135             hasInputBuffer(false),
136             hasCallback(true),
137             maxExpectedDuration(kDefaultExpectedDuration),
138             skipResultMetadata(false),
139             errorBufStrategy(ERROR_BUF_CACHE),
140             stillCapture(false),
141             zslCapture(false),
142             rotateAndCropAuto(false),
143             requestTimeNs(0) {
144     }
145 
146     InFlightRequest(int numBuffers, CaptureResultExtras extras, bool hasInput,
147             bool hasAppCallback, nsecs_t maxDuration,
148             const std::set<std::set<String8>>& physicalCameraIdSet, bool isStillCapture,
149             bool isZslCapture, bool rotateAndCropAuto, const std::set<std::string>& idsWithZoom,
150             nsecs_t requestNs, const SurfaceMap& outSurfaces = SurfaceMap{}) :
151             shutterTimestamp(0),
152             sensorTimestamp(0),
153             requestStatus(OK),
154             haveResultMetadata(false),
155             numBuffersLeft(numBuffers),
156             resultExtras(extras),
157             hasInputBuffer(hasInput),
158             hasCallback(hasAppCallback),
159             maxExpectedDuration(maxDuration),
160             skipResultMetadata(false),
161             errorBufStrategy(ERROR_BUF_CACHE),
162             physicalCameraIds(physicalCameraIdSet),
163             stillCapture(isStillCapture),
164             zslCapture(isZslCapture),
165             rotateAndCropAuto(rotateAndCropAuto),
166             cameraIdsWithZoom(idsWithZoom),
167             requestTimeNs(requestNs),
168             outputSurfaces(outSurfaces) {
169     }
170 };
171 
172 // Map from frame number to the in-flight request state
173 typedef KeyedVector<uint32_t, InFlightRequest> InFlightRequestMap;
174 
175 } // namespace camera3
176 
177 } // namespace android
178 
179 #endif
180