Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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_STREAM_INTERFACE_H |
| 18 | #define ANDROID_SERVERS_CAMERA3_STREAM_INTERFACE_H |
| 19 | |
| 20 | #include <utils/RefBase.h> |
Shuzhen Wang | 68ac7ad | 2019-01-30 14:03:28 -0800 | [diff] [blame] | 21 | |
Shuzhen Wang | e420892 | 2022-02-01 16:52:48 -0800 | [diff] [blame] | 22 | #include <camera/camera2/OutputConfiguration.h> |
Shuzhen Wang | 68ac7ad | 2019-01-30 14:03:28 -0800 | [diff] [blame] | 23 | #include <camera/CameraMetadata.h> |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 24 | #include "Camera3StreamBufferListener.h" |
Yin-Chia Yeh | be83fa7 | 2017-03-30 13:35:36 -0700 | [diff] [blame] | 25 | #include "Camera3StreamBufferFreedListener.h" |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 26 | |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 27 | namespace android { |
| 28 | |
| 29 | namespace camera3 { |
| 30 | |
Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 31 | typedef enum camera_buffer_status { |
| 32 | CAMERA_BUFFER_STATUS_OK = 0, |
| 33 | CAMERA_BUFFER_STATUS_ERROR = 1 |
| 34 | } camera_buffer_status_t; |
| 35 | |
| 36 | typedef enum camera_stream_type { |
| 37 | CAMERA_STREAM_OUTPUT = 0, |
| 38 | CAMERA_STREAM_INPUT = 1, |
| 39 | CAMERA_NUM_STREAM_TYPES |
| 40 | } camera_stream_type_t; |
| 41 | |
| 42 | typedef enum camera_stream_rotation { |
| 43 | /* No rotation */ |
| 44 | CAMERA_STREAM_ROTATION_0 = 0, |
| 45 | |
| 46 | /* Rotate by 90 degree counterclockwise */ |
| 47 | CAMERA_STREAM_ROTATION_90 = 1, |
| 48 | |
| 49 | /* Rotate by 180 degree counterclockwise */ |
| 50 | CAMERA_STREAM_ROTATION_180 = 2, |
| 51 | |
| 52 | /* Rotate by 270 degree counterclockwise */ |
| 53 | CAMERA_STREAM_ROTATION_270 = 3 |
| 54 | } camera_stream_rotation_t; |
| 55 | |
| 56 | typedef struct camera_stream { |
| 57 | camera_stream_type_t stream_type; |
| 58 | uint32_t width; |
| 59 | uint32_t height; |
| 60 | int format; |
| 61 | uint32_t usage; |
| 62 | uint32_t max_buffers; |
| 63 | android_dataspace_t data_space; |
| 64 | camera_stream_rotation_t rotation; |
Austin Borger | ed99f64 | 2023-06-01 16:51:35 -0700 | [diff] [blame^] | 65 | std::string physical_camera_id; |
Jayant Chowdhary | 13f9b2f | 2020-12-02 22:46:15 -0800 | [diff] [blame] | 66 | |
| 67 | std::unordered_set<int32_t> sensor_pixel_modes_used; |
Emilian Peev | c81a759 | 2022-02-14 17:38:18 -0800 | [diff] [blame] | 68 | int64_t dynamic_range_profile; |
Shuzhen Wang | 8ed1e87 | 2022-03-08 16:34:33 -0800 | [diff] [blame] | 69 | int64_t use_case; |
Austin Borger | 9e2b27c | 2022-07-15 11:27:24 -0700 | [diff] [blame] | 70 | int32_t color_space; |
Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 71 | } camera_stream_t; |
| 72 | |
| 73 | typedef struct camera_stream_buffer { |
| 74 | camera_stream_t *stream; |
| 75 | buffer_handle_t *buffer; |
| 76 | camera_buffer_status_t status; |
| 77 | int acquire_fence; |
| 78 | int release_fence; |
| 79 | } camera_stream_buffer_t; |
| 80 | |
Shuzhen Wang | 83bff12 | 2020-11-20 15:51:39 -0800 | [diff] [blame] | 81 | struct Size { |
| 82 | uint32_t width; |
| 83 | uint32_t height; |
| 84 | explicit Size(uint32_t w = 0, uint32_t h = 0) : width(w), height(h){} |
| 85 | }; |
| 86 | |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 87 | enum { |
| 88 | /** |
| 89 | * This stream set ID indicates that the set ID is invalid, and this stream doesn't intend to |
| 90 | * share buffers with any other stream. It is illegal to register this kind of stream to |
| 91 | * Camera3BufferManager. |
| 92 | */ |
| 93 | CAMERA3_STREAM_SET_ID_INVALID = -1, |
| 94 | |
| 95 | /** |
| 96 | * Invalid output stream ID. |
| 97 | */ |
| 98 | CAMERA3_STREAM_ID_INVALID = -1, |
| 99 | }; |
| 100 | |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 101 | class StatusTracker; |
| 102 | |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 103 | // OutputStreamInfo describes the property of a camera stream. |
| 104 | class OutputStreamInfo { |
| 105 | public: |
| 106 | int width; |
| 107 | int height; |
| 108 | int format; |
| 109 | android_dataspace dataSpace; |
| 110 | uint64_t consumerUsage; |
| 111 | bool finalized = false; |
Emilian Peev | cc0b795 | 2020-01-07 13:54:47 -0800 | [diff] [blame] | 112 | bool supportsOffline = false; |
Jayant Chowdhary | 13f9b2f | 2020-12-02 22:46:15 -0800 | [diff] [blame] | 113 | std::unordered_set<int32_t> sensorPixelModesUsed; |
Emilian Peev | c81a759 | 2022-02-14 17:38:18 -0800 | [diff] [blame] | 114 | int64_t dynamicRangeProfile; |
Shuzhen Wang | 8ed1e87 | 2022-03-08 16:34:33 -0800 | [diff] [blame] | 115 | int64_t streamUseCase; |
Shuzhen Wang | e420892 | 2022-02-01 16:52:48 -0800 | [diff] [blame] | 116 | int timestampBase; |
Shuzhen Wang | 610d7b8 | 2022-02-08 14:37:22 -0800 | [diff] [blame] | 117 | int mirrorMode; |
Austin Borger | 9e2b27c | 2022-07-15 11:27:24 -0700 | [diff] [blame] | 118 | int32_t colorSpace; |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 119 | OutputStreamInfo() : |
| 120 | width(-1), height(-1), format(-1), dataSpace(HAL_DATASPACE_UNKNOWN), |
Emilian Peev | 2295df7 | 2021-11-12 18:14:10 -0800 | [diff] [blame] | 121 | consumerUsage(0), |
Shuzhen Wang | c8ab452 | 2021-12-14 20:12:42 -0800 | [diff] [blame] | 122 | dynamicRangeProfile(ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD), |
Shuzhen Wang | e420892 | 2022-02-01 16:52:48 -0800 | [diff] [blame] | 123 | streamUseCase(ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT), |
Shuzhen Wang | 610d7b8 | 2022-02-08 14:37:22 -0800 | [diff] [blame] | 124 | timestampBase(OutputConfiguration::TIMESTAMP_BASE_DEFAULT), |
Austin Borger | 9e2b27c | 2022-07-15 11:27:24 -0700 | [diff] [blame] | 125 | mirrorMode(OutputConfiguration::MIRROR_MODE_AUTO), |
| 126 | colorSpace(ANDROID_REQUEST_AVAILABLE_COLOR_SPACE_PROFILES_MAP_UNSPECIFIED) {} |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 127 | OutputStreamInfo(int _width, int _height, int _format, android_dataspace _dataSpace, |
Emilian Peev | 2295df7 | 2021-11-12 18:14:10 -0800 | [diff] [blame] | 128 | uint64_t _consumerUsage, const std::unordered_set<int32_t>& _sensorPixelModesUsed, |
Austin Borger | 9e2b27c | 2022-07-15 11:27:24 -0700 | [diff] [blame] | 129 | int64_t _dynamicRangeProfile, int _streamUseCase, int _timestampBase, int _mirrorMode, |
| 130 | int32_t _colorSpace) : |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 131 | width(_width), height(_height), format(_format), |
Jayant Chowdhary | 13f9b2f | 2020-12-02 22:46:15 -0800 | [diff] [blame] | 132 | dataSpace(_dataSpace), consumerUsage(_consumerUsage), |
Shuzhen Wang | c8ab452 | 2021-12-14 20:12:42 -0800 | [diff] [blame] | 133 | sensorPixelModesUsed(_sensorPixelModesUsed), dynamicRangeProfile(_dynamicRangeProfile), |
Austin Borger | 9e2b27c | 2022-07-15 11:27:24 -0700 | [diff] [blame] | 134 | streamUseCase(_streamUseCase), timestampBase(_timestampBase), mirrorMode(_mirrorMode), |
| 135 | colorSpace(_colorSpace) {} |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 136 | }; |
| 137 | |
Jayant Chowdhary | c67af1b | 2022-04-07 18:05:04 +0000 | [diff] [blame] | 138 | // Utility class to lock and unlock a GraphicBuffer |
| 139 | class GraphicBufferLocker { |
| 140 | public: |
| 141 | GraphicBufferLocker(sp<GraphicBuffer> buffer) : _buffer(buffer) {} |
| 142 | |
| 143 | status_t lockAsync(uint32_t usage, void** dstBuffer, int fenceFd) { |
| 144 | if (_buffer == nullptr) return BAD_VALUE; |
| 145 | |
| 146 | status_t res = OK; |
| 147 | if (!_locked) { |
| 148 | status_t res = _buffer->lockAsync(usage, dstBuffer, fenceFd); |
| 149 | if (res == OK) { |
| 150 | _locked = true; |
| 151 | } |
| 152 | } |
| 153 | return res; |
| 154 | } |
| 155 | |
| 156 | status_t lockAsync(void** dstBuffer, int fenceFd) { |
| 157 | return lockAsync(GRALLOC_USAGE_SW_WRITE_OFTEN, dstBuffer, fenceFd); |
| 158 | } |
| 159 | |
| 160 | ~GraphicBufferLocker() { |
| 161 | if (_locked && _buffer != nullptr) { |
| 162 | auto res = _buffer->unlock(); |
| 163 | if (res != OK) { |
| 164 | ALOGE("%s: Error trying to unlock buffer: %s (%d)", __FUNCTION__, |
| 165 | strerror(-res), res); |
| 166 | } |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | private: |
| 171 | sp<GraphicBuffer> _buffer; |
| 172 | bool _locked = false; |
| 173 | }; |
| 174 | |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 175 | /** |
| 176 | * An interface for managing a single stream of input and/or output data from |
| 177 | * the camera device. |
| 178 | */ |
| 179 | class Camera3StreamInterface : public virtual RefBase { |
| 180 | public: |
Ruben Brunk | c78ac26 | 2015-08-13 17:58:46 -0700 | [diff] [blame] | 181 | |
| 182 | enum { |
| 183 | ALLOCATE_PIPELINE_MAX = 0, // Allocate max buffers used by a given surface |
| 184 | }; |
| 185 | |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 186 | /** |
| 187 | * Get the stream's ID |
| 188 | */ |
| 189 | virtual int getId() const = 0; |
| 190 | |
| 191 | /** |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 192 | * Get the output stream set id. |
| 193 | */ |
| 194 | virtual int getStreamSetId() const = 0; |
| 195 | |
| 196 | /** |
Shuzhen Wang | 9908050 | 2021-03-07 21:08:20 -0800 | [diff] [blame] | 197 | * Is this stream part of a multi-resolution stream set |
| 198 | */ |
| 199 | virtual bool isMultiResolution() const = 0; |
| 200 | |
| 201 | /** |
| 202 | * Get the HAL stream group id for a multi-resolution stream set |
| 203 | */ |
| 204 | virtual int getHalStreamGroupId() const = 0; |
| 205 | |
| 206 | /** |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 207 | * Get the stream's dimensions and format |
| 208 | */ |
| 209 | virtual uint32_t getWidth() const = 0; |
| 210 | virtual uint32_t getHeight() const = 0; |
| 211 | virtual int getFormat() const = 0; |
Emilian Peev | c81a759 | 2022-02-14 17:38:18 -0800 | [diff] [blame] | 212 | virtual int64_t getDynamicRangeProfile() const = 0; |
Eino-Ville Talvala | d46a6b9 | 2015-05-14 17:26:24 -0700 | [diff] [blame] | 213 | virtual android_dataspace getDataSpace() const = 0; |
Austin Borger | 9e2b27c | 2022-07-15 11:27:24 -0700 | [diff] [blame] | 214 | virtual int32_t getColorSpace() const = 0; |
Emilian Peev | 710c142 | 2017-08-30 11:19:38 +0100 | [diff] [blame] | 215 | virtual void setFormatOverride(bool formatOverriden) = 0; |
Eino-Ville Talvala | 91cd3f8 | 2017-08-21 16:12:50 -0700 | [diff] [blame] | 216 | virtual bool isFormatOverridden() const = 0; |
| 217 | virtual int getOriginalFormat() const = 0; |
| 218 | virtual void setDataSpaceOverride(bool dataSpaceOverriden) = 0; |
| 219 | virtual bool isDataSpaceOverridden() const = 0; |
| 220 | virtual android_dataspace getOriginalDataSpace() const = 0; |
Shuzhen Wang | 316781a | 2020-08-18 18:11:01 -0700 | [diff] [blame] | 221 | virtual int getMaxHalBuffers() const = 0; |
| 222 | virtual int getMaxTotalBuffers() const = 0; |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 223 | |
| 224 | /** |
Yin-Chia Yeh | 5fd603e | 2019-11-20 11:22:27 -0800 | [diff] [blame] | 225 | * Offline processing |
| 226 | */ |
| 227 | virtual void setOfflineProcessingSupport(bool support) = 0; |
| 228 | virtual bool getOfflineProcessingSupport() const = 0; |
| 229 | |
| 230 | /** |
Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 231 | * Get a handle for the stream, without starting stream configuration. |
Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 232 | */ |
Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 233 | virtual camera_stream* asHalStream() = 0; |
Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 234 | |
| 235 | /** |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 236 | * Start the stream configuration process. Returns a handle to the stream's |
Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 237 | * information to be passed into the device's configure_streams call. |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 238 | * |
| 239 | * Until finishConfiguration() is called, no other methods on the stream may |
Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 240 | * be called. The usage and max_buffers fields of camera_stream may be |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 241 | * modified between start/finishConfiguration, but may not be changed after |
Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 242 | * that. The priv field of camera_stream may be modified at any time after |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 243 | * startConfiguration. |
| 244 | * |
| 245 | * Returns NULL in case of error starting configuration. |
| 246 | */ |
Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 247 | virtual camera_stream* startConfiguration() = 0; |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 248 | |
| 249 | /** |
| 250 | * Check if the stream is mid-configuration (start has been called, but not |
| 251 | * finish). Used for lazy completion of configuration. |
| 252 | */ |
| 253 | virtual bool isConfiguring() const = 0; |
| 254 | |
| 255 | /** |
| 256 | * Completes the stream configuration process. During this call, the stream |
| 257 | * may call the device's register_stream_buffers() method. The stream |
| 258 | * information structure returned by startConfiguration() may no longer be |
| 259 | * modified after this call, but can still be read until the destruction of |
| 260 | * the stream. |
| 261 | * |
Yin-Chia Yeh | 573a270 | 2019-04-17 10:08:55 -0700 | [diff] [blame] | 262 | * streamReconfigured: set to true when a stream is being reconfigured. |
| 263 | * |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 264 | * Returns: |
| 265 | * OK on a successful configuration |
| 266 | * NO_INIT in case of a serious error from the HAL device |
| 267 | * NO_MEMORY in case of an error registering buffers |
| 268 | * INVALID_OPERATION in case connecting to the consumer failed |
| 269 | */ |
Yin-Chia Yeh | 573a270 | 2019-04-17 10:08:55 -0700 | [diff] [blame] | 270 | virtual status_t finishConfiguration(/*out*/bool* streamReconfigured = nullptr) = 0; |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 271 | |
| 272 | /** |
Eino-Ville Talvala | 1754351 | 2014-08-06 14:32:02 -0700 | [diff] [blame] | 273 | * Cancels the stream configuration process. This returns the stream to the |
| 274 | * initial state, allowing it to be configured again later. |
| 275 | * This is done if the HAL rejects the proposed combined stream configuration |
| 276 | */ |
| 277 | virtual status_t cancelConfiguration() = 0; |
| 278 | |
| 279 | /** |
Eino-Ville Talvala | 4d44cad | 2015-04-11 13:15:45 -0700 | [diff] [blame] | 280 | * Determine whether the stream has already become in-use (has received |
| 281 | * a valid filled buffer), which determines if a stream can still have |
| 282 | * prepareNextBuffer called on it. |
| 283 | */ |
| 284 | virtual bool isUnpreparable() = 0; |
| 285 | |
| 286 | /** |
Emilian Peev | f0348ae | 2021-01-13 13:39:45 -0800 | [diff] [blame] | 287 | * Mark the stream as unpreparable. |
| 288 | */ |
| 289 | virtual void markUnpreparable() = 0; |
| 290 | |
| 291 | /** |
Eino-Ville Talvala | 4d44cad | 2015-04-11 13:15:45 -0700 | [diff] [blame] | 292 | * Start stream preparation. May only be called in the CONFIGURED state, |
Ruben Brunk | c78ac26 | 2015-08-13 17:58:46 -0700 | [diff] [blame] | 293 | * when no valid buffers have yet been returned to this stream. Prepares |
| 294 | * up to maxCount buffers, or the maximum number of buffers needed by the |
| 295 | * pipeline if maxCount is ALLOCATE_PIPELINE_MAX. |
Eino-Ville Talvala | 4d44cad | 2015-04-11 13:15:45 -0700 | [diff] [blame] | 296 | * |
| 297 | * If no prepartion is necessary, returns OK and does not transition to |
| 298 | * PREPARING state. Otherwise, returns NOT_ENOUGH_DATA and transitions |
| 299 | * to PREPARING. |
| 300 | * |
Shuzhen Wang | b3a0fb5 | 2018-09-13 17:24:08 -0700 | [diff] [blame] | 301 | * blockRequest specifies whether prepare will block upcoming capture |
| 302 | * request. This flag should only be set to false if the caller guarantees |
| 303 | * the whole buffer preparation process is done before capture request |
| 304 | * comes in. |
| 305 | * |
Eino-Ville Talvala | 4d44cad | 2015-04-11 13:15:45 -0700 | [diff] [blame] | 306 | * Returns: |
| 307 | * OK if no more buffers need to be preallocated |
| 308 | * NOT_ENOUGH_DATA if calls to prepareNextBuffer are needed to finish |
| 309 | * buffer pre-allocation, and transitions to the PREPARING state. |
| 310 | * NO_INIT in case of a serious error from the HAL device |
| 311 | * INVALID_OPERATION if called when not in CONFIGURED state, or a |
| 312 | * valid buffer has already been returned to this stream. |
| 313 | */ |
Shuzhen Wang | b3a0fb5 | 2018-09-13 17:24:08 -0700 | [diff] [blame] | 314 | virtual status_t startPrepare(int maxCount, bool blockRequest) = 0; |
Eino-Ville Talvala | 4d44cad | 2015-04-11 13:15:45 -0700 | [diff] [blame] | 315 | |
| 316 | /** |
Shuzhen Wang | b3a0fb5 | 2018-09-13 17:24:08 -0700 | [diff] [blame] | 317 | * Check if the request on a stream is blocked by prepare. |
Eino-Ville Talvala | 4d44cad | 2015-04-11 13:15:45 -0700 | [diff] [blame] | 318 | */ |
Shuzhen Wang | b3a0fb5 | 2018-09-13 17:24:08 -0700 | [diff] [blame] | 319 | virtual bool isBlockedByPrepare() const = 0; |
Eino-Ville Talvala | 4d44cad | 2015-04-11 13:15:45 -0700 | [diff] [blame] | 320 | |
| 321 | /** |
| 322 | * Continue stream buffer preparation by allocating the next |
| 323 | * buffer for this stream. May only be called in the PREPARED state. |
| 324 | * |
| 325 | * Returns OK and transitions to the CONFIGURED state if all buffers |
| 326 | * are allocated after the call concludes. Otherwise returns NOT_ENOUGH_DATA. |
| 327 | * |
| 328 | * Returns: |
| 329 | * OK if no more buffers need to be preallocated, and transitions |
| 330 | * to the CONFIGURED state. |
| 331 | * NOT_ENOUGH_DATA if more calls to prepareNextBuffer are needed to finish |
| 332 | * buffer pre-allocation. |
| 333 | * NO_INIT in case of a serious error from the HAL device |
| 334 | * INVALID_OPERATION if called when not in CONFIGURED state, or a |
| 335 | * valid buffer has already been returned to this stream. |
| 336 | */ |
| 337 | virtual status_t prepareNextBuffer() = 0; |
| 338 | |
| 339 | /** |
| 340 | * Cancel stream preparation early. In case allocation needs to be |
| 341 | * stopped, this method transitions the stream back to the CONFIGURED state. |
| 342 | * Buffers that have been allocated with prepareNextBuffer remain that way, |
| 343 | * but a later use of prepareNextBuffer will require just as many |
| 344 | * calls as if the earlier prepare attempt had not existed. |
| 345 | * |
| 346 | * Returns: |
| 347 | * OK if cancellation succeeded, and transitions to the CONFIGURED state |
| 348 | * INVALID_OPERATION if not in the PREPARING state |
| 349 | * NO_INIT in case of a serious error from the HAL device |
| 350 | */ |
| 351 | virtual status_t cancelPrepare() = 0; |
| 352 | |
| 353 | /** |
Eino-Ville Talvala | b25e3c8 | 2015-07-15 16:04:27 -0700 | [diff] [blame] | 354 | * Tear down memory for this stream. This frees all unused gralloc buffers |
| 355 | * allocated for this stream, but leaves it ready for operation afterward. |
| 356 | * |
| 357 | * May only be called in the CONFIGURED state, and keeps the stream in |
| 358 | * the CONFIGURED state. |
| 359 | * |
| 360 | * Returns: |
| 361 | * OK if teardown succeeded. |
| 362 | * INVALID_OPERATION if not in the CONFIGURED state |
| 363 | * NO_INIT in case of a serious error from the HAL device |
| 364 | */ |
| 365 | virtual status_t tearDown() = 0; |
| 366 | |
| 367 | /** |
Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 368 | * Fill in the camera_stream_buffer with the next valid buffer for this |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 369 | * stream, to hand over to the HAL. |
| 370 | * |
Shuzhen Wang | bee0f0a | 2017-01-24 14:51:37 -0800 | [diff] [blame] | 371 | * Multiple surfaces could share the same HAL stream, but a request may |
| 372 | * be only for a subset of surfaces. In this case, the |
| 373 | * Camera3StreamInterface object needs the surface ID information to acquire |
| 374 | * buffers for those surfaces. For the case of single surface for a HAL |
| 375 | * stream, surface_ids parameter has no effect. |
| 376 | * |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 377 | * This method may only be called once finishConfiguration has been called. |
| 378 | * For bidirectional streams, this method applies to the output-side |
| 379 | * buffers. |
| 380 | * |
| 381 | */ |
Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 382 | virtual status_t getBuffer(camera_stream_buffer *buffer, |
Yin-Chia Yeh | b3a80b1 | 2018-09-04 12:13:05 -0700 | [diff] [blame] | 383 | nsecs_t waitBufferTimeout, |
Shuzhen Wang | bee0f0a | 2017-01-24 14:51:37 -0800 | [diff] [blame] | 384 | const std::vector<size_t>& surface_ids = std::vector<size_t>()) = 0; |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 385 | |
Yin-Chia Yeh | 14ef48d | 2020-02-10 15:06:37 -0800 | [diff] [blame] | 386 | struct OutstandingBuffer { |
| 387 | camera_stream_buffer* outBuffer; |
| 388 | |
| 389 | /** |
| 390 | * Multiple surfaces could share the same HAL stream, but a request may |
| 391 | * be only for a subset of surfaces. In this case, the |
| 392 | * Camera3StreamInterface object needs the surface ID information to acquire |
| 393 | * buffers for those surfaces. For the case of single surface for a HAL |
| 394 | * stream, surface_ids parameter has no effect. |
| 395 | */ |
| 396 | std::vector<size_t> surface_ids; |
| 397 | }; |
| 398 | /** |
| 399 | * Similar to getBuffer() except this method fills multiple buffers. |
| 400 | */ |
| 401 | virtual status_t getBuffers(std::vector<OutstandingBuffer>* buffers, |
| 402 | nsecs_t waitBufferTimeout) = 0; |
| 403 | |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 404 | /** |
| 405 | * Return a buffer to the stream after use by the HAL. |
| 406 | * |
Yin-Chia Yeh | 58b1b4e | 2018-10-15 12:18:36 -0700 | [diff] [blame] | 407 | * Multiple surfaces could share the same HAL stream, but a request may |
| 408 | * be only for a subset of surfaces. In this case, the |
| 409 | * Camera3StreamInterface object needs the surface ID information to attach |
| 410 | * buffers for those surfaces. For the case of single surface for a HAL |
| 411 | * stream, surface_ids parameter has no effect. |
| 412 | * |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 413 | * This method may only be called for buffers provided by getBuffer(). |
| 414 | * For bidirectional streams, this method applies to the output-side buffers |
| 415 | */ |
Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 416 | virtual status_t returnBuffer(const camera_stream_buffer &buffer, |
Shuzhen Wang | 90708ea | 2021-11-04 11:40:49 -0700 | [diff] [blame] | 417 | nsecs_t timestamp, nsecs_t readoutTimestamp, bool timestampIncreasing = true, |
Emilian Peev | 538c90e | 2018-12-17 18:03:19 +0000 | [diff] [blame] | 418 | const std::vector<size_t>& surface_ids = std::vector<size_t>(), |
Emilian Peev | 5104fe9 | 2021-10-21 14:27:09 -0700 | [diff] [blame] | 419 | uint64_t frameNumber = 0, int32_t transform = -1) = 0; |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 420 | |
| 421 | /** |
Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 422 | * Fill in the camera_stream_buffer with the next valid buffer for this |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 423 | * stream, to hand over to the HAL. |
| 424 | * |
| 425 | * This method may only be called once finishConfiguration has been called. |
| 426 | * For bidirectional streams, this method applies to the input-side |
| 427 | * buffers. |
| 428 | * |
Eino-Ville Talvala | ba43525 | 2017-06-21 16:07:25 -0700 | [diff] [blame] | 429 | * Normally this call will block until the handed out buffer count is less than the stream |
| 430 | * max buffer count; if respectHalLimit is set to false, this is ignored. |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 431 | */ |
Shuzhen Wang | 83bff12 | 2020-11-20 15:51:39 -0800 | [diff] [blame] | 432 | virtual status_t getInputBuffer(camera_stream_buffer *buffer, |
| 433 | Size *size, bool respectHalLimit = true) = 0; |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 434 | |
| 435 | /** |
| 436 | * Return a buffer to the stream after use by the HAL. |
| 437 | * |
| 438 | * This method may only be called for buffers provided by getBuffer(). |
| 439 | * For bidirectional streams, this method applies to the input-side buffers |
| 440 | */ |
Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 441 | virtual status_t returnInputBuffer(const camera_stream_buffer &buffer) = 0; |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 442 | |
| 443 | /** |
Chien-Yu Chen | 618ff8a | 2015-03-13 11:27:17 -0700 | [diff] [blame] | 444 | * Get the buffer producer of the input buffer queue. |
| 445 | * |
| 446 | * This method only applies to input streams. |
| 447 | */ |
| 448 | virtual status_t getInputBufferProducer(sp<IGraphicBufferProducer> *producer) = 0; |
| 449 | |
| 450 | /** |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 451 | * Whether any of the stream's buffers are currently in use by the HAL, |
| 452 | * including buffers that have been returned but not yet had their |
| 453 | * release fence signaled. |
| 454 | */ |
| 455 | virtual bool hasOutstandingBuffers() const = 0; |
| 456 | |
Yin-Chia Yeh | d5cd5ff | 2018-10-01 14:43:04 -0700 | [diff] [blame] | 457 | /** |
| 458 | * Get number of buffers currently handed out to HAL |
| 459 | */ |
| 460 | virtual size_t getOutstandingBuffersCount() const = 0; |
| 461 | |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 462 | enum { |
| 463 | TIMEOUT_NEVER = -1 |
| 464 | }; |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 465 | |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 466 | /** |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 467 | * Set the state tracker to use for signaling idle transitions. |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 468 | */ |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 469 | virtual status_t setStatusTracker(sp<StatusTracker> statusTracker) = 0; |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 470 | |
| 471 | /** |
| 472 | * Disconnect stream from its non-HAL endpoint. After this, |
| 473 | * start/finishConfiguration must be called before the stream can be used |
| 474 | * again. This cannot be called if the stream has outstanding dequeued |
| 475 | * buffers. |
| 476 | */ |
| 477 | virtual status_t disconnect() = 0; |
| 478 | |
| 479 | /** |
Chien-Yu Chen | e8c535e | 2016-04-14 12:18:26 -0700 | [diff] [blame] | 480 | * Return if the buffer queue of the stream is abandoned. |
| 481 | */ |
| 482 | virtual bool isAbandoned() const = 0; |
| 483 | |
| 484 | /** |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 485 | * Debug dump of the stream's state. |
| 486 | */ |
| 487 | virtual void dump(int fd, const Vector<String16> &args) const = 0; |
| 488 | |
| 489 | virtual void addBufferListener( |
| 490 | wp<Camera3StreamBufferListener> listener) = 0; |
| 491 | virtual void removeBufferListener( |
| 492 | const sp<Camera3StreamBufferListener>& listener) = 0; |
Yin-Chia Yeh | be83fa7 | 2017-03-30 13:35:36 -0700 | [diff] [blame] | 493 | |
| 494 | /** |
| 495 | * Setting listner will remove previous listener (if exists) |
| 496 | * Only allow set listener during stream configuration because stream is guaranteed to be IDLE |
| 497 | * at this state, so setBufferFreedListener won't collide with onBufferFreed callbacks. |
| 498 | * Client is responsible to keep the listener object alive throughout the lifecycle of this |
| 499 | * Camera3Stream. |
| 500 | */ |
Yin-Chia Yeh | db1e864 | 2017-07-14 15:19:30 -0700 | [diff] [blame] | 501 | virtual void setBufferFreedListener(wp<Camera3StreamBufferFreedListener> listener) = 0; |
Emilian Peev | 538c90e | 2018-12-17 18:03:19 +0000 | [diff] [blame] | 502 | |
| 503 | /** |
| 504 | * Notify buffer stream listeners about incoming request with particular frame number. |
| 505 | */ |
Shuzhen Wang | 68ac7ad | 2019-01-30 14:03:28 -0800 | [diff] [blame] | 506 | virtual void fireBufferRequestForFrameNumber(uint64_t frameNumber, |
| 507 | const CameraMetadata& settings) = 0; |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 508 | }; |
| 509 | |
| 510 | } // namespace camera3 |
| 511 | |
| 512 | } // namespace android |
| 513 | |
| 514 | #endif |