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 // Current output transformation 126 int32_t transform; 127 128 // TODO: dedupe 129 static const nsecs_t kDefaultExpectedDuration = 100000000; // 100 ms 130 131 // Default constructor needed by KeyedVector InFlightRequestInFlightRequest132 InFlightRequest() : 133 shutterTimestamp(0), 134 sensorTimestamp(0), 135 requestStatus(OK), 136 haveResultMetadata(false), 137 numBuffersLeft(0), 138 hasInputBuffer(false), 139 hasCallback(true), 140 maxExpectedDuration(kDefaultExpectedDuration), 141 skipResultMetadata(false), 142 errorBufStrategy(ERROR_BUF_CACHE), 143 stillCapture(false), 144 zslCapture(false), 145 rotateAndCropAuto(false), 146 requestTimeNs(0), 147 transform(-1) { 148 } 149 150 InFlightRequest(int numBuffers, CaptureResultExtras extras, bool hasInput, 151 bool hasAppCallback, nsecs_t maxDuration, 152 const std::set<std::set<String8>>& physicalCameraIdSet, bool isStillCapture, 153 bool isZslCapture, bool rotateAndCropAuto, const std::set<std::string>& idsWithZoom, 154 nsecs_t requestNs, const SurfaceMap& outSurfaces = SurfaceMap{}) : 155 shutterTimestamp(0), 156 sensorTimestamp(0), 157 requestStatus(OK), 158 haveResultMetadata(false), 159 numBuffersLeft(numBuffers), 160 resultExtras(extras), 161 hasInputBuffer(hasInput), 162 hasCallback(hasAppCallback), 163 maxExpectedDuration(maxDuration), 164 skipResultMetadata(false), 165 errorBufStrategy(ERROR_BUF_CACHE), 166 physicalCameraIds(physicalCameraIdSet), 167 stillCapture(isStillCapture), 168 zslCapture(isZslCapture), 169 rotateAndCropAuto(rotateAndCropAuto), 170 cameraIdsWithZoom(idsWithZoom), 171 requestTimeNs(requestNs), 172 outputSurfaces(outSurfaces), 173 transform(-1) { 174 } 175 }; 176 177 // Map from frame number to the in-flight request state 178 typedef KeyedVector<uint32_t, InFlightRequest> InFlightRequestMap; 179 180 } // namespace camera3 181 182 } // namespace android 183 184 #endif 185