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 "hardware/camera3.h" 28 29 #include "common/CameraDeviceBase.h" 30 31 namespace android { 32 33 namespace camera3 { 34 35 typedef 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 45 struct InFlightRequest { 46 47 // 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; 57 58 // The inflight request is considered complete if all buffers are returned 59 60 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 96 // 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 100 // 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 112 // Indicates that ROTATE_AND_CROP was set to AUTO 113 bool rotateAndCropAuto; 114 115 // Requested camera ids (both logical and physical) with zoomRatio != 1.0f 116 std::set<std::string> cameraIdsWithZoom; 117 118 // What shared surfaces an output should go to 119 SurfaceMap outputSurfaces; 120 121 // TODO: dedupe 122 static const nsecs_t kDefaultExpectedDuration = 100000000; // 100 ms 123 124 // Default constructor needed by KeyedVector InFlightRequestInFlightRequest125 InFlightRequest() : 126 shutterTimestamp(0), 127 sensorTimestamp(0), 128 requestStatus(OK), 129 haveResultMetadata(false), 130 numBuffersLeft(0), 131 hasInputBuffer(false), 132 hasCallback(true), 133 maxExpectedDuration(kDefaultExpectedDuration), 134 skipResultMetadata(false), 135 errorBufStrategy(ERROR_BUF_CACHE), 136 stillCapture(false), 137 zslCapture(false), 138 rotateAndCropAuto(false) { 139 } 140 141 InFlightRequest(int numBuffers, CaptureResultExtras extras, bool hasInput, 142 bool hasAppCallback, nsecs_t maxDuration, 143 const std::set<String8>& physicalCameraIdSet, bool isStillCapture, 144 bool isZslCapture, bool rotateAndCropAuto, const std::set<std::string>& idsWithZoom, 145 const SurfaceMap& outSurfaces = SurfaceMap{}) : 146 shutterTimestamp(0), 147 sensorTimestamp(0), 148 requestStatus(OK), 149 haveResultMetadata(false), 150 numBuffersLeft(numBuffers), 151 resultExtras(extras), 152 hasInputBuffer(hasInput), 153 hasCallback(hasAppCallback), 154 maxExpectedDuration(maxDuration), 155 skipResultMetadata(false), 156 errorBufStrategy(ERROR_BUF_CACHE), 157 physicalCameraIds(physicalCameraIdSet), 158 stillCapture(isStillCapture), 159 zslCapture(isZslCapture), 160 rotateAndCropAuto(rotateAndCropAuto), 161 cameraIdsWithZoom(idsWithZoom), 162 outputSurfaces(outSurfaces) { 163 } 164 }; 165 166 // Map from frame number to the in-flight request state 167 typedef KeyedVector<uint32_t, InFlightRequest> InFlightRequestMap; 168 169 } // namespace camera3 170 171 } // namespace android 172 173 #endif 174