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> |
| 21 | #include "Camera3StreamBufferListener.h" |
Yin-Chia Yeh | be83fa7 | 2017-03-30 13:35:36 -0700 | [diff] [blame] | 22 | #include "Camera3StreamBufferFreedListener.h" |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 23 | |
| 24 | struct camera3_stream_buffer; |
| 25 | |
| 26 | namespace android { |
| 27 | |
| 28 | namespace camera3 { |
| 29 | |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 30 | enum { |
| 31 | /** |
| 32 | * This stream set ID indicates that the set ID is invalid, and this stream doesn't intend to |
| 33 | * share buffers with any other stream. It is illegal to register this kind of stream to |
| 34 | * Camera3BufferManager. |
| 35 | */ |
| 36 | CAMERA3_STREAM_SET_ID_INVALID = -1, |
| 37 | |
| 38 | /** |
| 39 | * Invalid output stream ID. |
| 40 | */ |
| 41 | CAMERA3_STREAM_ID_INVALID = -1, |
| 42 | }; |
| 43 | |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 44 | class StatusTracker; |
| 45 | |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 46 | // OutputStreamInfo describes the property of a camera stream. |
| 47 | class OutputStreamInfo { |
| 48 | public: |
| 49 | int width; |
| 50 | int height; |
| 51 | int format; |
| 52 | android_dataspace dataSpace; |
| 53 | uint64_t consumerUsage; |
| 54 | bool finalized = false; |
| 55 | OutputStreamInfo() : |
| 56 | width(-1), height(-1), format(-1), dataSpace(HAL_DATASPACE_UNKNOWN), |
| 57 | consumerUsage(0) {} |
| 58 | OutputStreamInfo(int _width, int _height, int _format, android_dataspace _dataSpace, |
| 59 | uint64_t _consumerUsage) : |
| 60 | width(_width), height(_height), format(_format), |
| 61 | dataSpace(_dataSpace), consumerUsage(_consumerUsage) {} |
| 62 | }; |
| 63 | |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 64 | /** |
| 65 | * An interface for managing a single stream of input and/or output data from |
| 66 | * the camera device. |
| 67 | */ |
| 68 | class Camera3StreamInterface : public virtual RefBase { |
| 69 | public: |
Ruben Brunk | c78ac26 | 2015-08-13 17:58:46 -0700 | [diff] [blame] | 70 | |
| 71 | enum { |
| 72 | ALLOCATE_PIPELINE_MAX = 0, // Allocate max buffers used by a given surface |
| 73 | }; |
| 74 | |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 75 | /** |
| 76 | * Get the stream's ID |
| 77 | */ |
| 78 | virtual int getId() const = 0; |
| 79 | |
| 80 | /** |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 81 | * Get the output stream set id. |
| 82 | */ |
| 83 | virtual int getStreamSetId() const = 0; |
| 84 | |
| 85 | /** |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 86 | * Get the stream's dimensions and format |
| 87 | */ |
| 88 | virtual uint32_t getWidth() const = 0; |
| 89 | virtual uint32_t getHeight() const = 0; |
| 90 | virtual int getFormat() const = 0; |
Eino-Ville Talvala | d46a6b9 | 2015-05-14 17:26:24 -0700 | [diff] [blame] | 91 | virtual android_dataspace getDataSpace() const = 0; |
Emilian Peev | 710c142 | 2017-08-30 11:19:38 +0100 | [diff] [blame] | 92 | virtual void setFormatOverride(bool formatOverriden) = 0; |
Eino-Ville Talvala | 91cd3f8 | 2017-08-21 16:12:50 -0700 | [diff] [blame] | 93 | virtual bool isFormatOverridden() const = 0; |
| 94 | virtual int getOriginalFormat() const = 0; |
| 95 | virtual void setDataSpaceOverride(bool dataSpaceOverriden) = 0; |
| 96 | virtual bool isDataSpaceOverridden() const = 0; |
| 97 | virtual android_dataspace getOriginalDataSpace() const = 0; |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 98 | |
| 99 | /** |
Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 100 | * Get a HAL3 handle for the stream, without starting stream configuration. |
| 101 | */ |
| 102 | virtual camera3_stream* asHalStream() = 0; |
| 103 | |
| 104 | /** |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 105 | * Start the stream configuration process. Returns a handle to the stream's |
| 106 | * information to be passed into the HAL device's configure_streams call. |
| 107 | * |
| 108 | * Until finishConfiguration() is called, no other methods on the stream may |
| 109 | * be called. The usage and max_buffers fields of camera3_stream may be |
| 110 | * modified between start/finishConfiguration, but may not be changed after |
| 111 | * that. The priv field of camera3_stream may be modified at any time after |
| 112 | * startConfiguration. |
| 113 | * |
| 114 | * Returns NULL in case of error starting configuration. |
| 115 | */ |
| 116 | virtual camera3_stream* startConfiguration() = 0; |
| 117 | |
| 118 | /** |
| 119 | * Check if the stream is mid-configuration (start has been called, but not |
| 120 | * finish). Used for lazy completion of configuration. |
| 121 | */ |
| 122 | virtual bool isConfiguring() const = 0; |
| 123 | |
| 124 | /** |
| 125 | * Completes the stream configuration process. During this call, the stream |
| 126 | * may call the device's register_stream_buffers() method. The stream |
| 127 | * information structure returned by startConfiguration() may no longer be |
| 128 | * modified after this call, but can still be read until the destruction of |
| 129 | * the stream. |
| 130 | * |
| 131 | * Returns: |
| 132 | * OK on a successful configuration |
| 133 | * NO_INIT in case of a serious error from the HAL device |
| 134 | * NO_MEMORY in case of an error registering buffers |
| 135 | * INVALID_OPERATION in case connecting to the consumer failed |
| 136 | */ |
Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 137 | virtual status_t finishConfiguration() = 0; |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 138 | |
| 139 | /** |
Eino-Ville Talvala | 1754351 | 2014-08-06 14:32:02 -0700 | [diff] [blame] | 140 | * Cancels the stream configuration process. This returns the stream to the |
| 141 | * initial state, allowing it to be configured again later. |
| 142 | * This is done if the HAL rejects the proposed combined stream configuration |
| 143 | */ |
| 144 | virtual status_t cancelConfiguration() = 0; |
| 145 | |
| 146 | /** |
Eino-Ville Talvala | 4d44cad | 2015-04-11 13:15:45 -0700 | [diff] [blame] | 147 | * Determine whether the stream has already become in-use (has received |
| 148 | * a valid filled buffer), which determines if a stream can still have |
| 149 | * prepareNextBuffer called on it. |
| 150 | */ |
| 151 | virtual bool isUnpreparable() = 0; |
| 152 | |
| 153 | /** |
| 154 | * Start stream preparation. May only be called in the CONFIGURED state, |
Ruben Brunk | c78ac26 | 2015-08-13 17:58:46 -0700 | [diff] [blame] | 155 | * when no valid buffers have yet been returned to this stream. Prepares |
| 156 | * up to maxCount buffers, or the maximum number of buffers needed by the |
| 157 | * pipeline if maxCount is ALLOCATE_PIPELINE_MAX. |
Eino-Ville Talvala | 4d44cad | 2015-04-11 13:15:45 -0700 | [diff] [blame] | 158 | * |
| 159 | * If no prepartion is necessary, returns OK and does not transition to |
| 160 | * PREPARING state. Otherwise, returns NOT_ENOUGH_DATA and transitions |
| 161 | * to PREPARING. |
| 162 | * |
Shuzhen Wang | b3a0fb5 | 2018-09-13 17:24:08 -0700 | [diff] [blame^] | 163 | * blockRequest specifies whether prepare will block upcoming capture |
| 164 | * request. This flag should only be set to false if the caller guarantees |
| 165 | * the whole buffer preparation process is done before capture request |
| 166 | * comes in. |
| 167 | * |
Eino-Ville Talvala | 4d44cad | 2015-04-11 13:15:45 -0700 | [diff] [blame] | 168 | * Returns: |
| 169 | * OK if no more buffers need to be preallocated |
| 170 | * NOT_ENOUGH_DATA if calls to prepareNextBuffer are needed to finish |
| 171 | * buffer pre-allocation, and transitions to the PREPARING state. |
| 172 | * NO_INIT in case of a serious error from the HAL device |
| 173 | * INVALID_OPERATION if called when not in CONFIGURED state, or a |
| 174 | * valid buffer has already been returned to this stream. |
| 175 | */ |
Shuzhen Wang | b3a0fb5 | 2018-09-13 17:24:08 -0700 | [diff] [blame^] | 176 | virtual status_t startPrepare(int maxCount, bool blockRequest) = 0; |
Eino-Ville Talvala | 4d44cad | 2015-04-11 13:15:45 -0700 | [diff] [blame] | 177 | |
| 178 | /** |
Shuzhen Wang | b3a0fb5 | 2018-09-13 17:24:08 -0700 | [diff] [blame^] | 179 | * Check if the request on a stream is blocked by prepare. |
Eino-Ville Talvala | 4d44cad | 2015-04-11 13:15:45 -0700 | [diff] [blame] | 180 | */ |
Shuzhen Wang | b3a0fb5 | 2018-09-13 17:24:08 -0700 | [diff] [blame^] | 181 | virtual bool isBlockedByPrepare() const = 0; |
Eino-Ville Talvala | 4d44cad | 2015-04-11 13:15:45 -0700 | [diff] [blame] | 182 | |
| 183 | /** |
| 184 | * Continue stream buffer preparation by allocating the next |
| 185 | * buffer for this stream. May only be called in the PREPARED state. |
| 186 | * |
| 187 | * Returns OK and transitions to the CONFIGURED state if all buffers |
| 188 | * are allocated after the call concludes. Otherwise returns NOT_ENOUGH_DATA. |
| 189 | * |
| 190 | * Returns: |
| 191 | * OK if no more buffers need to be preallocated, and transitions |
| 192 | * to the CONFIGURED state. |
| 193 | * NOT_ENOUGH_DATA if more calls to prepareNextBuffer are needed to finish |
| 194 | * buffer pre-allocation. |
| 195 | * NO_INIT in case of a serious error from the HAL device |
| 196 | * INVALID_OPERATION if called when not in CONFIGURED state, or a |
| 197 | * valid buffer has already been returned to this stream. |
| 198 | */ |
| 199 | virtual status_t prepareNextBuffer() = 0; |
| 200 | |
| 201 | /** |
| 202 | * Cancel stream preparation early. In case allocation needs to be |
| 203 | * stopped, this method transitions the stream back to the CONFIGURED state. |
| 204 | * Buffers that have been allocated with prepareNextBuffer remain that way, |
| 205 | * but a later use of prepareNextBuffer will require just as many |
| 206 | * calls as if the earlier prepare attempt had not existed. |
| 207 | * |
| 208 | * Returns: |
| 209 | * OK if cancellation succeeded, and transitions to the CONFIGURED state |
| 210 | * INVALID_OPERATION if not in the PREPARING state |
| 211 | * NO_INIT in case of a serious error from the HAL device |
| 212 | */ |
| 213 | virtual status_t cancelPrepare() = 0; |
| 214 | |
| 215 | /** |
Eino-Ville Talvala | b25e3c8 | 2015-07-15 16:04:27 -0700 | [diff] [blame] | 216 | * Tear down memory for this stream. This frees all unused gralloc buffers |
| 217 | * allocated for this stream, but leaves it ready for operation afterward. |
| 218 | * |
| 219 | * May only be called in the CONFIGURED state, and keeps the stream in |
| 220 | * the CONFIGURED state. |
| 221 | * |
| 222 | * Returns: |
| 223 | * OK if teardown succeeded. |
| 224 | * INVALID_OPERATION if not in the CONFIGURED state |
| 225 | * NO_INIT in case of a serious error from the HAL device |
| 226 | */ |
| 227 | virtual status_t tearDown() = 0; |
| 228 | |
| 229 | /** |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 230 | * Fill in the camera3_stream_buffer with the next valid buffer for this |
| 231 | * stream, to hand over to the HAL. |
| 232 | * |
Shuzhen Wang | bee0f0a | 2017-01-24 14:51:37 -0800 | [diff] [blame] | 233 | * Multiple surfaces could share the same HAL stream, but a request may |
| 234 | * be only for a subset of surfaces. In this case, the |
| 235 | * Camera3StreamInterface object needs the surface ID information to acquire |
| 236 | * buffers for those surfaces. For the case of single surface for a HAL |
| 237 | * stream, surface_ids parameter has no effect. |
| 238 | * |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 239 | * This method may only be called once finishConfiguration has been called. |
| 240 | * For bidirectional streams, this method applies to the output-side |
| 241 | * buffers. |
| 242 | * |
| 243 | */ |
Shuzhen Wang | bee0f0a | 2017-01-24 14:51:37 -0800 | [diff] [blame] | 244 | virtual status_t getBuffer(camera3_stream_buffer *buffer, |
Yin-Chia Yeh | b3a80b1 | 2018-09-04 12:13:05 -0700 | [diff] [blame] | 245 | nsecs_t waitBufferTimeout, |
Shuzhen Wang | bee0f0a | 2017-01-24 14:51:37 -0800 | [diff] [blame] | 246 | const std::vector<size_t>& surface_ids = std::vector<size_t>()) = 0; |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 247 | |
| 248 | /** |
| 249 | * Return a buffer to the stream after use by the HAL. |
| 250 | * |
| 251 | * This method may only be called for buffers provided by getBuffer(). |
| 252 | * For bidirectional streams, this method applies to the output-side buffers |
| 253 | */ |
| 254 | virtual status_t returnBuffer(const camera3_stream_buffer &buffer, |
| 255 | nsecs_t timestamp) = 0; |
| 256 | |
| 257 | /** |
| 258 | * Fill in the camera3_stream_buffer with the next valid buffer for this |
| 259 | * stream, to hand over to the HAL. |
| 260 | * |
| 261 | * This method may only be called once finishConfiguration has been called. |
| 262 | * For bidirectional streams, this method applies to the input-side |
| 263 | * buffers. |
| 264 | * |
Eino-Ville Talvala | ba43525 | 2017-06-21 16:07:25 -0700 | [diff] [blame] | 265 | * Normally this call will block until the handed out buffer count is less than the stream |
| 266 | * max buffer count; if respectHalLimit is set to false, this is ignored. |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 267 | */ |
Eino-Ville Talvala | ba43525 | 2017-06-21 16:07:25 -0700 | [diff] [blame] | 268 | virtual status_t getInputBuffer(camera3_stream_buffer *buffer, bool respectHalLimit = true) = 0; |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 269 | |
| 270 | /** |
| 271 | * Return a buffer to the stream after use by the HAL. |
| 272 | * |
| 273 | * This method may only be called for buffers provided by getBuffer(). |
| 274 | * For bidirectional streams, this method applies to the input-side buffers |
| 275 | */ |
| 276 | virtual status_t returnInputBuffer(const camera3_stream_buffer &buffer) = 0; |
| 277 | |
| 278 | /** |
Chien-Yu Chen | 618ff8a | 2015-03-13 11:27:17 -0700 | [diff] [blame] | 279 | * Get the buffer producer of the input buffer queue. |
| 280 | * |
| 281 | * This method only applies to input streams. |
| 282 | */ |
| 283 | virtual status_t getInputBufferProducer(sp<IGraphicBufferProducer> *producer) = 0; |
| 284 | |
| 285 | /** |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 286 | * Whether any of the stream's buffers are currently in use by the HAL, |
| 287 | * including buffers that have been returned but not yet had their |
| 288 | * release fence signaled. |
| 289 | */ |
| 290 | virtual bool hasOutstandingBuffers() const = 0; |
| 291 | |
| 292 | enum { |
| 293 | TIMEOUT_NEVER = -1 |
| 294 | }; |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 295 | |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 296 | /** |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 297 | * Set the state tracker to use for signaling idle transitions. |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 298 | */ |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 299 | virtual status_t setStatusTracker(sp<StatusTracker> statusTracker) = 0; |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 300 | |
| 301 | /** |
| 302 | * Disconnect stream from its non-HAL endpoint. After this, |
| 303 | * start/finishConfiguration must be called before the stream can be used |
| 304 | * again. This cannot be called if the stream has outstanding dequeued |
| 305 | * buffers. |
| 306 | */ |
| 307 | virtual status_t disconnect() = 0; |
| 308 | |
| 309 | /** |
Chien-Yu Chen | e8c535e | 2016-04-14 12:18:26 -0700 | [diff] [blame] | 310 | * Return if the buffer queue of the stream is abandoned. |
| 311 | */ |
| 312 | virtual bool isAbandoned() const = 0; |
| 313 | |
| 314 | /** |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 315 | * Debug dump of the stream's state. |
| 316 | */ |
| 317 | virtual void dump(int fd, const Vector<String16> &args) const = 0; |
| 318 | |
| 319 | virtual void addBufferListener( |
| 320 | wp<Camera3StreamBufferListener> listener) = 0; |
| 321 | virtual void removeBufferListener( |
| 322 | const sp<Camera3StreamBufferListener>& listener) = 0; |
Yin-Chia Yeh | be83fa7 | 2017-03-30 13:35:36 -0700 | [diff] [blame] | 323 | |
| 324 | /** |
| 325 | * Setting listner will remove previous listener (if exists) |
| 326 | * Only allow set listener during stream configuration because stream is guaranteed to be IDLE |
| 327 | * at this state, so setBufferFreedListener won't collide with onBufferFreed callbacks. |
| 328 | * Client is responsible to keep the listener object alive throughout the lifecycle of this |
| 329 | * Camera3Stream. |
| 330 | */ |
Yin-Chia Yeh | db1e864 | 2017-07-14 15:19:30 -0700 | [diff] [blame] | 331 | virtual void setBufferFreedListener(wp<Camera3StreamBufferFreedListener> listener) = 0; |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 332 | }; |
| 333 | |
| 334 | } // namespace camera3 |
| 335 | |
| 336 | } // namespace android |
| 337 | |
| 338 | #endif |