Yin-Chia Yeh | 5fd603e | 2019-11-20 11:22:27 -0800 | [diff] [blame] | 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 | |
Shuzhen Wang | b7b4265 | 2020-05-07 11:59:02 -0700 | [diff] [blame] | 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 | |
Yin-Chia Yeh | 5fd603e | 2019-11-20 11:22:27 -0800 | [diff] [blame] | 45 | struct InFlightRequest { |
Shuzhen Wang | b7b4265 | 2020-05-07 11:59:02 -0700 | [diff] [blame] | 46 | |
Yin-Chia Yeh | 5fd603e | 2019-11-20 11:22:27 -0800 | [diff] [blame] | 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; |
Shuzhen Wang | b7b4265 | 2020-05-07 11:59:02 -0700 | [diff] [blame] | 57 | |
| 58 | // The inflight request is considered complete if all buffers are returned |
| 59 | |
Yin-Chia Yeh | 5fd603e | 2019-11-20 11:22:27 -0800 | [diff] [blame] | 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 | |
Shuzhen Wang | b7b4265 | 2020-05-07 11:59:02 -0700 | [diff] [blame] | 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 | |
Yin-Chia Yeh | 5fd603e | 2019-11-20 11:22:27 -0800 | [diff] [blame] | 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 | |
Eino-Ville Talvala | f2e3709 | 2020-01-07 15:32:32 -0800 | [diff] [blame] | 112 | // Indicates that ROTATE_AND_CROP was set to AUTO |
| 113 | bool rotateAndCropAuto; |
| 114 | |
Yin-Chia Yeh | 5fd603e | 2019-11-20 11:22:27 -0800 | [diff] [blame] | 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 |
| 125 | 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), |
Shuzhen Wang | b7b4265 | 2020-05-07 11:59:02 -0700 | [diff] [blame] | 135 | errorBufStrategy(ERROR_BUF_CACHE), |
Yin-Chia Yeh | 5fd603e | 2019-11-20 11:22:27 -0800 | [diff] [blame] | 136 | stillCapture(false), |
Eino-Ville Talvala | f2e3709 | 2020-01-07 15:32:32 -0800 | [diff] [blame] | 137 | zslCapture(false), |
| 138 | rotateAndCropAuto(false) { |
Yin-Chia Yeh | 5fd603e | 2019-11-20 11:22:27 -0800 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | InFlightRequest(int numBuffers, CaptureResultExtras extras, bool hasInput, |
| 142 | bool hasAppCallback, nsecs_t maxDuration, |
| 143 | const std::set<String8>& physicalCameraIdSet, bool isStillCapture, |
Eino-Ville Talvala | f2e3709 | 2020-01-07 15:32:32 -0800 | [diff] [blame] | 144 | bool isZslCapture, bool rotateAndCropAuto, const std::set<std::string>& idsWithZoom, |
Yin-Chia Yeh | 5fd603e | 2019-11-20 11:22:27 -0800 | [diff] [blame] | 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), |
Shuzhen Wang | b7b4265 | 2020-05-07 11:59:02 -0700 | [diff] [blame] | 156 | errorBufStrategy(ERROR_BUF_CACHE), |
Yin-Chia Yeh | 5fd603e | 2019-11-20 11:22:27 -0800 | [diff] [blame] | 157 | physicalCameraIds(physicalCameraIdSet), |
| 158 | stillCapture(isStillCapture), |
| 159 | zslCapture(isZslCapture), |
Eino-Ville Talvala | f2e3709 | 2020-01-07 15:32:32 -0800 | [diff] [blame] | 160 | rotateAndCropAuto(rotateAndCropAuto), |
Yin-Chia Yeh | 5fd603e | 2019-11-20 11:22:27 -0800 | [diff] [blame] | 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 |