| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 1 | /* | 
| Shuzhen Wang | c28189a | 2017-11-27 23:05:10 -0800 | [diff] [blame] | 2 |  * Copyright (C) 2013-2018 The Android Open Source Project | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 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_H | 
 | 18 | #define ANDROID_SERVERS_CAMERA3_STREAM_H | 
 | 19 |  | 
 | 20 | #include <gui/Surface.h> | 
 | 21 | #include <utils/RefBase.h> | 
 | 22 | #include <utils/String8.h> | 
 | 23 | #include <utils/String16.h> | 
| Igor Murashkin | 2fba584 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 24 | #include <utils/List.h> | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 25 |  | 
| Shuzhen Wang | 686f644 | 2017-06-20 16:16:04 -0700 | [diff] [blame] | 26 | #include "utils/LatencyHistogram.h" | 
| Igor Murashkin | 2fba584 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 27 | #include "Camera3StreamBufferListener.h" | 
 | 28 | #include "Camera3StreamInterface.h" | 
 | 29 |  | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 30 | namespace android { | 
 | 31 |  | 
 | 32 | namespace camera3 { | 
 | 33 |  | 
 | 34 | /** | 
 | 35 |  * A class for managing a single stream of input or output data from the camera | 
 | 36 |  * device. | 
 | 37 |  * | 
 | 38 |  * The stream has an internal state machine to track whether it's | 
 | 39 |  * connected/configured/etc. | 
 | 40 |  * | 
 | 41 |  * States: | 
 | 42 |  * | 
 | 43 |  *  STATE_ERROR: A serious error has occurred, stream is unusable. Outstanding | 
 | 44 |  *    buffers may still be returned. | 
 | 45 |  * | 
 | 46 |  *  STATE_CONSTRUCTED: The stream is ready for configuration, but buffers cannot | 
 | 47 |  *    be gotten yet. Not connected to any endpoint, no buffers are registered | 
 | 48 |  *    with the HAL. | 
 | 49 |  * | 
 | 50 |  *  STATE_IN_CONFIG: Configuration has started, but not yet concluded. During this | 
| Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 51 |  *    time, the usage, max_buffers, and priv fields of camera_stream returned by | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 52 |  *    startConfiguration() may be modified. | 
 | 53 |  * | 
 | 54 |  *  STATE_IN_RE_CONFIG: Configuration has started, and the stream has been | 
 | 55 |  *    configured before. Need to track separately from IN_CONFIG to avoid | 
 | 56 |  *    re-registering buffers with HAL. | 
 | 57 |  * | 
 | 58 |  *  STATE_CONFIGURED: Stream is configured, and has registered buffers with the | 
| Eino-Ville Talvala | 4d44cad | 2015-04-11 13:15:45 -0700 | [diff] [blame] | 59 |  *    HAL (if necessary). The stream's getBuffer/returnBuffer work. The priv | 
 | 60 |  *    pointer may still be modified. | 
 | 61 |  * | 
 | 62 |  *  STATE_PREPARING: The stream's buffers are being pre-allocated for use.  On | 
 | 63 |  *    older HALs, this is done as part of configuration, but in newer HALs | 
 | 64 |  *    buffers may be allocated at time of first use. But some use cases require | 
 | 65 |  *    buffer allocation upfront, to minmize disruption due to lengthy allocation | 
 | 66 |  *    duration.  In this state, only prepareNextBuffer() and cancelPrepare() | 
 | 67 |  *    may be called. | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 68 |  * | 
| Emilian Peev | ac3ce6c | 2017-12-12 15:27:02 +0000 | [diff] [blame] | 69 |  *  STATE_IN_IDLE: This is a temporary state only intended to be used for input | 
 | 70 |  *    streams and only for the case where we need to re-configure the camera device | 
 | 71 |  *    while the input stream has an outstanding buffer. All other streams should not | 
 | 72 |  *    be able to switch to this state. For them this is invalid and should be handled | 
 | 73 |  *    as an unknown state. | 
 | 74 |  * | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 75 |  * Transition table: | 
 | 76 |  * | 
 | 77 |  *    <none>               => STATE_CONSTRUCTED: | 
 | 78 |  *        When constructed with valid arguments | 
 | 79 |  *    <none>               => STATE_ERROR: | 
 | 80 |  *        When constructed with invalid arguments | 
 | 81 |  *    STATE_CONSTRUCTED    => STATE_IN_CONFIG: | 
 | 82 |  *        When startConfiguration() is called | 
 | 83 |  *    STATE_IN_CONFIG      => STATE_CONFIGURED: | 
 | 84 |  *        When finishConfiguration() is called | 
 | 85 |  *    STATE_IN_CONFIG      => STATE_ERROR: | 
 | 86 |  *        When finishConfiguration() fails to allocate or register buffers. | 
 | 87 |  *    STATE_CONFIGURED     => STATE_IN_RE_CONFIG:  * | 
 | 88 |  *        When startConfiguration() is called again, after making sure stream is | 
 | 89 |  *        idle with waitUntilIdle(). | 
 | 90 |  *    STATE_IN_RE_CONFIG   => STATE_CONFIGURED: | 
 | 91 |  *        When finishConfiguration() is called. | 
 | 92 |  *    STATE_IN_RE_CONFIG   => STATE_ERROR: | 
 | 93 |  *        When finishConfiguration() fails to allocate or register buffers. | 
 | 94 |  *    STATE_CONFIGURED     => STATE_CONSTRUCTED: | 
 | 95 |  *        When disconnect() is called after making sure stream is idle with | 
 | 96 |  *        waitUntilIdle(). | 
| Eino-Ville Talvala | 4d44cad | 2015-04-11 13:15:45 -0700 | [diff] [blame] | 97 |  *    STATE_CONFIGURED     => STATE_PREPARING: | 
 | 98 |  *        When startPrepare is called before the stream has a buffer | 
 | 99 |  *        queued back into it for the first time. | 
 | 100 |  *    STATE_PREPARING      => STATE_CONFIGURED: | 
 | 101 |  *        When sufficient prepareNextBuffer calls have been made to allocate | 
 | 102 |  *        all stream buffers, or cancelPrepare is called. | 
| Chien-Yu Chen | e8c535e | 2016-04-14 12:18:26 -0700 | [diff] [blame] | 103 |  *    STATE_CONFIGURED     => STATE_ABANDONED: | 
 | 104 |  *        When the buffer queue of the stream is abandoned. | 
| Emilian Peev | ac3ce6c | 2017-12-12 15:27:02 +0000 | [diff] [blame] | 105 |  *    STATE_CONFIGURED     => STATE_IN_IDLE: | 
 | 106 |  *        Only for an input stream which has an outstanding buffer. | 
 | 107 |  *    STATE_IN_IDLE     => STATE_CONFIGURED: | 
 | 108 |  *        After the internal re-configuration, the input should revert back to | 
 | 109 |  *        the configured state. | 
| Igor Murashkin | 13d315e | 2014-04-03 18:09:04 -0700 | [diff] [blame] | 110 |  * | 
 | 111 |  * Status Tracking: | 
 | 112 |  *    Each stream is tracked by StatusTracker as a separate component, | 
 | 113 |  *    depending on the handed out buffer count. The state must be STATE_CONFIGURED | 
 | 114 |  *    in order for the component to be marked. | 
 | 115 |  * | 
 | 116 |  *    It's marked in one of two ways: | 
 | 117 |  * | 
 | 118 |  *    - ACTIVE: One or more buffers have been handed out (with #getBuffer). | 
 | 119 |  *    - IDLE: All buffers have been returned (with #returnBuffer), and their | 
| Emilian Peev | ac3ce6c | 2017-12-12 15:27:02 +0000 | [diff] [blame] | 120 |  *          respective release_fence(s) have been signaled. The only exception to this | 
 | 121 |  *          rule is an input stream that moves to "STATE_IN_IDLE" during internal | 
 | 122 |  *          re-configuration. | 
| Igor Murashkin | 13d315e | 2014-04-03 18:09:04 -0700 | [diff] [blame] | 123 |  * | 
 | 124 |  *    A typical use case is output streams. When the HAL has any buffers | 
 | 125 |  *    dequeued, the stream is marked ACTIVE. When the HAL returns all buffers | 
 | 126 |  *    (e.g. if no capture requests are active), the stream is marked IDLE. | 
 | 127 |  *    In this use case, the app consumer does not affect the component status. | 
 | 128 |  * | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 129 |  */ | 
 | 130 | class Camera3Stream : | 
| Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 131 |         protected camera_stream, | 
| Igor Murashkin | 2fba584 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 132 |         public virtual Camera3StreamInterface, | 
 | 133 |         public virtual RefBase { | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 134 |   public: | 
 | 135 |  | 
 | 136 |     virtual ~Camera3Stream(); | 
 | 137 |  | 
| Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 138 |     static Camera3Stream*       cast(camera_stream *stream); | 
 | 139 |     static const Camera3Stream* cast(const camera_stream *stream); | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 140 |  | 
 | 141 |     /** | 
 | 142 |      * Get the stream's ID | 
 | 143 |      */ | 
 | 144 |     int              getId() const; | 
 | 145 |  | 
 | 146 |     /** | 
| Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 147 |      * Get the output stream set id. | 
 | 148 |      */ | 
 | 149 |     int              getStreamSetId() const; | 
 | 150 |  | 
 | 151 |     /** | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 152 |      * Get the stream's dimensions and format | 
 | 153 |      */ | 
| Eino-Ville Talvala | 3d82c0d | 2015-02-23 15:19:19 -0800 | [diff] [blame] | 154 |     uint32_t          getWidth() const; | 
 | 155 |     uint32_t          getHeight() const; | 
 | 156 |     int               getFormat() const; | 
 | 157 |     android_dataspace getDataSpace() const; | 
| Emilian Peev | 050f5dc | 2017-05-18 14:43:56 +0100 | [diff] [blame] | 158 |     uint64_t          getUsage() const; | 
 | 159 |     void              setUsage(uint64_t usage); | 
| Emilian Peev | 710c142 | 2017-08-30 11:19:38 +0100 | [diff] [blame] | 160 |     void              setFormatOverride(bool formatOverriden); | 
| Eino-Ville Talvala | 91cd3f8 | 2017-08-21 16:12:50 -0700 | [diff] [blame] | 161 |     bool              isFormatOverridden() const; | 
 | 162 |     int               getOriginalFormat() const; | 
 | 163 |     void              setDataSpaceOverride(bool dataSpaceOverriden); | 
 | 164 |     bool              isDataSpaceOverridden() const; | 
 | 165 |     android_dataspace getOriginalDataSpace() const; | 
| Shuzhen Wang | 316781a | 2020-08-18 18:11:01 -0700 | [diff] [blame] | 166 |     int               getMaxHalBuffers() const; | 
| Shuzhen Wang | 5c22c15 | 2017-12-31 17:12:25 -0800 | [diff] [blame] | 167 |     const String8&    physicalCameraId() const; | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 168 |  | 
| Yin-Chia Yeh | 5fd603e | 2019-11-20 11:22:27 -0800 | [diff] [blame] | 169 |     void              setOfflineProcessingSupport(bool) override; | 
 | 170 |     bool              getOfflineProcessingSupport() const override; | 
 | 171 |  | 
| Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 172 |     camera_stream*   asHalStream() override { | 
| Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 173 |         return this; | 
 | 174 |     } | 
 | 175 |  | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 176 |     /** | 
 | 177 |      * Start the stream configuration process. Returns a handle to the stream's | 
 | 178 |      * information to be passed into the HAL device's configure_streams call. | 
 | 179 |      * | 
 | 180 |      * Until finishConfiguration() is called, no other methods on the stream may be | 
| Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 181 |      * called. The usage and max_buffers fields of camera_stream may be modified | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 182 |      * between start/finishConfiguration, but may not be changed after that. | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 183 |      * | 
 | 184 |      * Returns NULL in case of error starting configuration. | 
 | 185 |      */ | 
| Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 186 |     camera_stream*  startConfiguration(); | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 187 |  | 
 | 188 |     /** | 
 | 189 |      * Check if the stream is mid-configuration (start has been called, but not | 
 | 190 |      * finish).  Used for lazy completion of configuration. | 
 | 191 |      */ | 
 | 192 |     bool             isConfiguring() const; | 
 | 193 |  | 
 | 194 |     /** | 
| Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 195 |      * Completes the stream configuration process. The stream information | 
 | 196 |      * structure returned by startConfiguration() may no longer be modified | 
 | 197 |      * after this call, but can still be read until the destruction of the | 
 | 198 |      * stream. | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 199 |      * | 
| Yin-Chia Yeh | 573a270 | 2019-04-17 10:08:55 -0700 | [diff] [blame] | 200 |      * streamReconfigured: set to true when a stream is being reconfigured. | 
 | 201 |      * | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 202 |      * Returns: | 
 | 203 |      *   OK on a successful configuration | 
 | 204 |      *   NO_INIT in case of a serious error from the HAL device | 
 | 205 |      *   NO_MEMORY in case of an error registering buffers | 
| Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 206 |      *   INVALID_OPERATION in case connecting to the consumer failed or consumer | 
 | 207 |      *       doesn't exist yet. | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 208 |      */ | 
| Yin-Chia Yeh | 573a270 | 2019-04-17 10:08:55 -0700 | [diff] [blame] | 209 |     status_t         finishConfiguration(/*out*/bool* streamReconfigured = nullptr); | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 210 |  | 
 | 211 |     /** | 
| Eino-Ville Talvala | 1754351 | 2014-08-06 14:32:02 -0700 | [diff] [blame] | 212 |      * Cancels the stream configuration process. This returns the stream to the | 
 | 213 |      * initial state, allowing it to be configured again later. | 
 | 214 |      * This is done if the HAL rejects the proposed combined stream configuration | 
 | 215 |      */ | 
 | 216 |     status_t         cancelConfiguration(); | 
 | 217 |  | 
 | 218 |     /** | 
| Eino-Ville Talvala | 4d44cad | 2015-04-11 13:15:45 -0700 | [diff] [blame] | 219 |      * Determine whether the stream has already become in-use (has received | 
 | 220 |      * a valid filled buffer), which determines if a stream can still have | 
 | 221 |      * prepareNextBuffer called on it. | 
 | 222 |      */ | 
 | 223 |     bool             isUnpreparable(); | 
 | 224 |  | 
 | 225 |     /** | 
| Emilian Peev | f0348ae | 2021-01-13 13:39:45 -0800 | [diff] [blame] | 226 |      * Mark the stream as unpreparable. | 
 | 227 |      */ | 
 | 228 |     void             markUnpreparable() override; | 
 | 229 |  | 
 | 230 |     /** | 
| Eino-Ville Talvala | 4d44cad | 2015-04-11 13:15:45 -0700 | [diff] [blame] | 231 |      * Start stream preparation. May only be called in the CONFIGURED state, | 
| Ruben Brunk | c78ac26 | 2015-08-13 17:58:46 -0700 | [diff] [blame] | 232 |      * when no valid buffers have yet been returned to this stream. Prepares | 
 | 233 |      * up to maxCount buffers, or the maximum number of buffers needed by the | 
 | 234 |      * pipeline if maxCount is ALLOCATE_PIPELINE_MAX. | 
| Eino-Ville Talvala | 4d44cad | 2015-04-11 13:15:45 -0700 | [diff] [blame] | 235 |      * | 
 | 236 |      * If no prepartion is necessary, returns OK and does not transition to | 
 | 237 |      * PREPARING state. Otherwise, returns NOT_ENOUGH_DATA and transitions | 
 | 238 |      * to PREPARING. | 
 | 239 |      * | 
 | 240 |      * This call performs no allocation, so is quick to call. | 
 | 241 |      * | 
| Shuzhen Wang | b3a0fb5 | 2018-09-13 17:24:08 -0700 | [diff] [blame] | 242 |      * blockRequest specifies whether prepare will block upcoming capture | 
 | 243 |      * request. This flag should only be set to false if the caller guarantees | 
 | 244 |      * the whole buffer preparation process is done before capture request | 
 | 245 |      * comes in. | 
 | 246 |      * | 
| Eino-Ville Talvala | 4d44cad | 2015-04-11 13:15:45 -0700 | [diff] [blame] | 247 |      * Returns: | 
 | 248 |      *    OK if no more buffers need to be preallocated | 
 | 249 |      *    NOT_ENOUGH_DATA if calls to prepareNextBuffer are needed to finish | 
 | 250 |      *        buffer pre-allocation, and transitions to the PREPARING state. | 
 | 251 |      *    NO_INIT in case of a serious error from the HAL device | 
 | 252 |      *    INVALID_OPERATION if called when not in CONFIGURED state, or a | 
 | 253 |      *        valid buffer has already been returned to this stream. | 
 | 254 |      */ | 
| Shuzhen Wang | b3a0fb5 | 2018-09-13 17:24:08 -0700 | [diff] [blame] | 255 |     status_t         startPrepare(int maxCount, bool blockRequest); | 
| Eino-Ville Talvala | 4d44cad | 2015-04-11 13:15:45 -0700 | [diff] [blame] | 256 |  | 
 | 257 |     /** | 
| Shuzhen Wang | b3a0fb5 | 2018-09-13 17:24:08 -0700 | [diff] [blame] | 258 |      * Check if the request on a stream is blocked by prepare. | 
| Eino-Ville Talvala | 4d44cad | 2015-04-11 13:15:45 -0700 | [diff] [blame] | 259 |      */ | 
| Shuzhen Wang | b3a0fb5 | 2018-09-13 17:24:08 -0700 | [diff] [blame] | 260 |     bool             isBlockedByPrepare() const; | 
| Eino-Ville Talvala | 4d44cad | 2015-04-11 13:15:45 -0700 | [diff] [blame] | 261 |  | 
 | 262 |     /** | 
 | 263 |      * Continue stream buffer preparation by allocating the next | 
 | 264 |      * buffer for this stream.  May only be called in the PREPARED state. | 
 | 265 |      * | 
 | 266 |      * Returns OK and transitions to the CONFIGURED state if all buffers | 
 | 267 |      * are allocated after the call concludes. Otherwise returns NOT_ENOUGH_DATA. | 
 | 268 |      * | 
 | 269 |      * This call allocates one buffer, which may take several milliseconds for | 
 | 270 |      * large buffers. | 
 | 271 |      * | 
 | 272 |      * Returns: | 
 | 273 |      *    OK if no more buffers need to be preallocated, and transitions | 
 | 274 |      *        to the CONFIGURED state. | 
 | 275 |      *    NOT_ENOUGH_DATA if more calls to prepareNextBuffer are needed to finish | 
 | 276 |      *        buffer pre-allocation. | 
 | 277 |      *    NO_INIT in case of a serious error from the HAL device | 
 | 278 |      *    INVALID_OPERATION if called when not in CONFIGURED state, or a | 
 | 279 |      *        valid buffer has already been returned to this stream. | 
 | 280 |      */ | 
 | 281 |     status_t         prepareNextBuffer(); | 
 | 282 |  | 
 | 283 |     /** | 
 | 284 |      * Cancel stream preparation early. In case allocation needs to be | 
 | 285 |      * stopped, this method transitions the stream back to the CONFIGURED state. | 
 | 286 |      * Buffers that have been allocated with prepareNextBuffer remain that way, | 
 | 287 |      * but a later use of prepareNextBuffer will require just as many | 
 | 288 |      * calls as if the earlier prepare attempt had not existed. | 
 | 289 |      * | 
 | 290 |      * Returns: | 
 | 291 |      *    OK if cancellation succeeded, and transitions to the CONFIGURED state | 
 | 292 |      *    INVALID_OPERATION if not in the PREPARING state | 
 | 293 |      *    NO_INIT in case of a serious error from the HAL device | 
 | 294 |      */ | 
 | 295 |     status_t        cancelPrepare(); | 
 | 296 |  | 
 | 297 |     /** | 
| Eino-Ville Talvala | b25e3c8 | 2015-07-15 16:04:27 -0700 | [diff] [blame] | 298 |      * Tear down memory for this stream. This frees all unused gralloc buffers | 
 | 299 |      * allocated for this stream, but leaves it ready for operation afterward. | 
 | 300 |      * | 
 | 301 |      * May only be called in the CONFIGURED state, and keeps the stream in | 
 | 302 |      * the CONFIGURED state. | 
 | 303 |      * | 
 | 304 |      * Returns: | 
 | 305 |      *    OK if teardown succeeded. | 
 | 306 |      *    INVALID_OPERATION if not in the CONFIGURED state | 
 | 307 |      *    NO_INIT in case of a serious error from the HAL device | 
 | 308 |      */ | 
 | 309 |     status_t       tearDown(); | 
 | 310 |  | 
 | 311 |     /** | 
| Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 312 |      * Fill in the camera_stream_buffer with the next valid buffer for this | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 313 |      * stream, to hand over to the HAL. | 
 | 314 |      * | 
| Shuzhen Wang | bee0f0a | 2017-01-24 14:51:37 -0800 | [diff] [blame] | 315 |      * Multiple surfaces could share the same HAL stream, but a request may | 
 | 316 |      * be only for a subset of surfaces. In this case, the | 
 | 317 |      * Camera3StreamInterface object needs the surface ID information to acquire | 
 | 318 |      * buffers for those surfaces. | 
 | 319 |      * | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 320 |      * This method may only be called once finishConfiguration has been called. | 
 | 321 |      * For bidirectional streams, this method applies to the output-side | 
 | 322 |      * buffers. | 
 | 323 |      * | 
 | 324 |      */ | 
| Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 325 |     status_t         getBuffer(camera_stream_buffer *buffer, | 
| Yin-Chia Yeh | b3a80b1 | 2018-09-04 12:13:05 -0700 | [diff] [blame] | 326 |             nsecs_t waitBufferTimeout, | 
| Shuzhen Wang | bee0f0a | 2017-01-24 14:51:37 -0800 | [diff] [blame] | 327 |             const std::vector<size_t>& surface_ids = std::vector<size_t>()); | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 328 |  | 
 | 329 |     /** | 
 | 330 |      * Return a buffer to the stream after use by the HAL. | 
 | 331 |      * | 
| Yin-Chia Yeh | 58b1b4e | 2018-10-15 12:18:36 -0700 | [diff] [blame] | 332 |      * Multiple surfaces could share the same HAL stream, but a request may | 
 | 333 |      * be only for a subset of surfaces. In this case, the | 
 | 334 |      * Camera3StreamInterface object needs the surface ID information to attach | 
 | 335 |      * buffers for those surfaces. | 
 | 336 |      * | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 337 |      * This method may only be called for buffers provided by getBuffer(). | 
 | 338 |      * For bidirectional streams, this method applies to the output-side buffers | 
 | 339 |      */ | 
| Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 340 |     status_t         returnBuffer(const camera_stream_buffer &buffer, | 
| Yin-Chia Yeh | 58b1b4e | 2018-10-15 12:18:36 -0700 | [diff] [blame] | 341 |             nsecs_t timestamp, bool timestampIncreasing, | 
| Emilian Peev | 538c90e | 2018-12-17 18:03:19 +0000 | [diff] [blame] | 342 |             const std::vector<size_t>& surface_ids = std::vector<size_t>(), | 
 | 343 |             uint64_t frameNumber = 0); | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 344 |  | 
 | 345 |     /** | 
| Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 346 |      * Fill in the camera_stream_buffer with the next valid buffer for this | 
| Igor Murashkin | 5a269fa | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 347 |      * stream, to hand over to the HAL. | 
 | 348 |      * | 
 | 349 |      * This method may only be called once finishConfiguration has been called. | 
 | 350 |      * For bidirectional streams, this method applies to the input-side | 
 | 351 |      * buffers. | 
 | 352 |      * | 
| Eino-Ville Talvala | ba43525 | 2017-06-21 16:07:25 -0700 | [diff] [blame] | 353 |      * Normally this call will block until the handed out buffer count is less than the stream | 
 | 354 |      * max buffer count; if respectHalLimit is set to false, this is ignored. | 
| Igor Murashkin | 5a269fa | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 355 |      */ | 
| Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 356 |     status_t         getInputBuffer(camera_stream_buffer *buffer, bool respectHalLimit = true); | 
| Igor Murashkin | 5a269fa | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 357 |  | 
 | 358 |     /** | 
 | 359 |      * Return a buffer to the stream after use by the HAL. | 
 | 360 |      * | 
 | 361 |      * This method may only be called for buffers provided by getBuffer(). | 
 | 362 |      * For bidirectional streams, this method applies to the input-side buffers | 
 | 363 |      */ | 
| Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 364 |     status_t         returnInputBuffer(const camera_stream_buffer &buffer); | 
| Igor Murashkin | 5a269fa | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 365 |  | 
| Chien-Yu Chen | 618ff8a | 2015-03-13 11:27:17 -0700 | [diff] [blame] | 366 |     // get the buffer producer of the input buffer queue. | 
 | 367 |     // only apply to input streams. | 
 | 368 |     status_t         getInputBufferProducer(sp<IGraphicBufferProducer> *producer); | 
 | 369 |  | 
| Igor Murashkin | 5a269fa | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 370 |     /** | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 371 |      * Whether any of the stream's buffers are currently in use by the HAL, | 
 | 372 |      * including buffers that have been returned but not yet had their | 
 | 373 |      * release fence signaled. | 
 | 374 |      */ | 
 | 375 |     bool             hasOutstandingBuffers() const; | 
 | 376 |  | 
| Yin-Chia Yeh | d5cd5ff | 2018-10-01 14:43:04 -0700 | [diff] [blame] | 377 |     /** | 
 | 378 |      * Get number of buffers currently handed out to HAL | 
 | 379 |      */ | 
 | 380 |     size_t           getOutstandingBuffersCount() const; | 
 | 381 |  | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 382 |     enum { | 
 | 383 |         TIMEOUT_NEVER = -1 | 
 | 384 |     }; | 
| Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 385 |  | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 386 |     /** | 
| Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 387 |      * Set the status tracker to notify about idle transitions | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 388 |      */ | 
| Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 389 |     virtual status_t setStatusTracker(sp<StatusTracker> statusTracker); | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 390 |  | 
 | 391 |     /** | 
 | 392 |      * Disconnect stream from its non-HAL endpoint. After this, | 
 | 393 |      * start/finishConfiguration must be called before the stream can be used | 
 | 394 |      * again. This cannot be called if the stream has outstanding dequeued | 
 | 395 |      * buffers. | 
 | 396 |      */ | 
 | 397 |     status_t         disconnect(); | 
 | 398 |  | 
 | 399 |     /** | 
 | 400 |      * Debug dump of the stream's state. | 
 | 401 |      */ | 
| Shuzhen Wang | 686f644 | 2017-06-20 16:16:04 -0700 | [diff] [blame] | 402 |     virtual void     dump(int fd, const Vector<String16> &args) const; | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 403 |  | 
| Zhijun He | f0d962a | 2014-06-30 10:24:11 -0700 | [diff] [blame] | 404 |     /** | 
 | 405 |      * Add a camera3 buffer listener. Adding the same listener twice has | 
 | 406 |      * no effect. | 
 | 407 |      */ | 
| Igor Murashkin | 2fba584 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 408 |     void             addBufferListener( | 
 | 409 |             wp<Camera3StreamBufferListener> listener); | 
| Zhijun He | f0d962a | 2014-06-30 10:24:11 -0700 | [diff] [blame] | 410 |  | 
 | 411 |     /** | 
 | 412 |      * Remove a camera3 buffer listener. Removing the same listener twice | 
 | 413 |      * or the listener that was never added has no effect. | 
 | 414 |      */ | 
| Igor Murashkin | 2fba584 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 415 |     void             removeBufferListener( | 
 | 416 |             const sp<Camera3StreamBufferListener>& listener); | 
 | 417 |  | 
| Yin-Chia Yeh | be83fa7 | 2017-03-30 13:35:36 -0700 | [diff] [blame] | 418 |  | 
 | 419 |     // Setting listener will remove previous listener (if exists) | 
 | 420 |     virtual void     setBufferFreedListener( | 
| Yin-Chia Yeh | db1e864 | 2017-07-14 15:19:30 -0700 | [diff] [blame] | 421 |             wp<Camera3StreamBufferFreedListener> listener) override; | 
| Yin-Chia Yeh | be83fa7 | 2017-03-30 13:35:36 -0700 | [diff] [blame] | 422 |  | 
| Chien-Yu Chen | e8c535e | 2016-04-14 12:18:26 -0700 | [diff] [blame] | 423 |     /** | 
 | 424 |      * Return if the buffer queue of the stream is abandoned. | 
 | 425 |      */ | 
 | 426 |     bool             isAbandoned() const; | 
 | 427 |  | 
| Emilian Peev | ac3ce6c | 2017-12-12 15:27:02 +0000 | [diff] [blame] | 428 |     /** | 
 | 429 |      * Switch a configured stream with possibly outstanding buffers in idle | 
 | 430 |      * state. Configuration for such streams will be skipped assuming there | 
 | 431 |      * are no changes to the stream parameters. | 
 | 432 |      */ | 
 | 433 |     status_t         forceToIdle(); | 
 | 434 |  | 
 | 435 |     /** | 
 | 436 |      * Restore a forced idle stream to configured state, marking it active | 
 | 437 |      * in case it contains outstanding buffers. | 
 | 438 |      */ | 
 | 439 |     status_t         restoreConfiguredState(); | 
 | 440 |  | 
| Emilian Peev | 538c90e | 2018-12-17 18:03:19 +0000 | [diff] [blame] | 441 |     /** | 
 | 442 |      * Notify buffer stream listeners about incoming request with particular frame number. | 
 | 443 |      */ | 
| Shuzhen Wang | 68ac7ad | 2019-01-30 14:03:28 -0800 | [diff] [blame] | 444 |     void fireBufferRequestForFrameNumber(uint64_t frameNumber, | 
 | 445 |             const CameraMetadata& settings) override; | 
| Emilian Peev | 538c90e | 2018-12-17 18:03:19 +0000 | [diff] [blame] | 446 |  | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 447 |   protected: | 
 | 448 |     const int mId; | 
| Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 449 |     /** | 
 | 450 |      * Stream set id, used to indicate which group of this stream belongs to for buffer sharing | 
 | 451 |      * across multiple streams. | 
 | 452 |      * | 
 | 453 |      * The default value is set to CAMERA3_STREAM_SET_ID_INVALID, which indicates that this stream | 
 | 454 |      * doesn't intend to share buffers with any other streams, and this stream will fall back to | 
 | 455 |      * the existing BufferQueue mechanism to manage the buffer allocations and buffer circulation. | 
 | 456 |      * When a valid stream set id is set, this stream intends to use the Camera3BufferManager to | 
 | 457 |      * manage the buffer allocations; the BufferQueue will only handle the buffer transaction | 
 | 458 |      * between the producer and consumer. For this case, upon successfully registration, the streams | 
 | 459 |      * with the same stream set id will potentially share the buffers allocated by | 
 | 460 |      * Camera3BufferManager. | 
 | 461 |      */ | 
 | 462 |     const int mSetId; | 
 | 463 |  | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 464 |     const String8 mName; | 
 | 465 |     // Zero for formats with fixed buffer size for given dimensions. | 
 | 466 |     const size_t mMaxSize; | 
 | 467 |  | 
| Yin-Chia Yeh | a1b56c8 | 2019-03-27 15:50:39 -0700 | [diff] [blame] | 468 |     enum StreamState { | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 469 |         STATE_ERROR, | 
 | 470 |         STATE_CONSTRUCTED, | 
 | 471 |         STATE_IN_CONFIG, | 
 | 472 |         STATE_IN_RECONFIG, | 
| Eino-Ville Talvala | 4d44cad | 2015-04-11 13:15:45 -0700 | [diff] [blame] | 473 |         STATE_CONFIGURED, | 
| Chien-Yu Chen | e8c535e | 2016-04-14 12:18:26 -0700 | [diff] [blame] | 474 |         STATE_PREPARING, | 
| Emilian Peev | ac3ce6c | 2017-12-12 15:27:02 +0000 | [diff] [blame] | 475 |         STATE_ABANDONED, | 
 | 476 |         STATE_IN_IDLE | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 477 |     } mState; | 
 | 478 |  | 
 | 479 |     mutable Mutex mLock; | 
 | 480 |  | 
| Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 481 |     Camera3Stream(int id, camera_stream_type type, | 
| Eino-Ville Talvala | 3d82c0d | 2015-02-23 15:19:19 -0800 | [diff] [blame] | 482 |             uint32_t width, uint32_t height, size_t maxSize, int format, | 
| Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 483 |             android_dataspace dataSpace, camera_stream_rotation_t rotation, | 
| Shuzhen Wang | c28189a | 2017-11-27 23:05:10 -0800 | [diff] [blame] | 484 |             const String8& physicalCameraId, int setId); | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 485 |  | 
| Yin-Chia Yeh | db1e864 | 2017-07-14 15:19:30 -0700 | [diff] [blame] | 486 |     wp<Camera3StreamBufferFreedListener> mBufferFreedListener; | 
| Yin-Chia Yeh | be83fa7 | 2017-03-30 13:35:36 -0700 | [diff] [blame] | 487 |  | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 488 |     /** | 
 | 489 |      * Interface to be implemented by derived classes | 
 | 490 |      */ | 
 | 491 |  | 
 | 492 |     // getBuffer / returnBuffer implementations | 
 | 493 |  | 
| Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 494 |     // Since camera_stream_buffer includes a raw pointer to the stream, | 
 | 495 |     // cast to camera_stream*, implementations must increment the | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 496 |     // refcount of the stream manually in getBufferLocked, and decrement it in | 
 | 497 |     // returnBufferLocked. | 
| Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 498 |     virtual status_t getBufferLocked(camera_stream_buffer *buffer, | 
| Shuzhen Wang | bee0f0a | 2017-01-24 14:51:37 -0800 | [diff] [blame] | 499 |             const std::vector<size_t>& surface_ids = std::vector<size_t>()); | 
| Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 500 |     virtual status_t returnBufferLocked(const camera_stream_buffer &buffer, | 
| Yin-Chia Yeh | 58b1b4e | 2018-10-15 12:18:36 -0700 | [diff] [blame] | 501 |             nsecs_t timestamp, | 
 | 502 |             const std::vector<size_t>& surface_ids = std::vector<size_t>()); | 
| Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 503 |     virtual status_t getInputBufferLocked(camera_stream_buffer *buffer); | 
| Igor Murashkin | 5a269fa | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 504 |     virtual status_t returnInputBufferLocked( | 
| Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 505 |             const camera_stream_buffer &buffer); | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 506 |     virtual bool     hasOutstandingBuffersLocked() const = 0; | 
| Chien-Yu Chen | 618ff8a | 2015-03-13 11:27:17 -0700 | [diff] [blame] | 507 |     // Get the buffer producer of the input buffer queue. Only apply to input streams. | 
 | 508 |     virtual status_t getInputBufferProducerLocked(sp<IGraphicBufferProducer> *producer); | 
 | 509 |  | 
| Igor Murashkin | e2172be | 2013-05-28 15:31:39 -0700 | [diff] [blame] | 510 |     // Can return -ENOTCONN when we are already disconnected (not an error) | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 511 |     virtual status_t disconnectLocked() = 0; | 
 | 512 |  | 
 | 513 |     // Configure the buffer queue interface to the other end of the stream, | 
 | 514 |     // after the HAL has provided usage and max_buffers values. After this call, | 
 | 515 |     // the stream must be ready to produce all buffers for registration with | 
 | 516 |     // HAL. | 
| Shuzhen Wang | 210ba5c | 2018-07-25 16:47:40 -0700 | [diff] [blame] | 517 |     // Returns NO_INIT or DEAD_OBJECT if the queue has been abandoned. | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 518 |     virtual status_t configureQueueLocked() = 0; | 
 | 519 |  | 
 | 520 |     // Get the total number of buffers in the queue | 
 | 521 |     virtual size_t   getBufferCountLocked() = 0; | 
 | 522 |  | 
| Zhijun He | 6adc9cc | 2014-04-15 14:09:55 -0700 | [diff] [blame] | 523 |     // Get handout output buffer count. | 
| Yin-Chia Yeh | d5cd5ff | 2018-10-01 14:43:04 -0700 | [diff] [blame] | 524 |     virtual size_t   getHandoutOutputBufferCountLocked() const = 0; | 
| Zhijun He | 6adc9cc | 2014-04-15 14:09:55 -0700 | [diff] [blame] | 525 |  | 
 | 526 |     // Get handout input buffer count. | 
 | 527 |     virtual size_t   getHandoutInputBufferCountLocked() = 0; | 
 | 528 |  | 
| Eino-Ville Talvala | b2f5b19 | 2013-07-30 14:36:03 -0700 | [diff] [blame] | 529 |     // Get the usage flags for the other endpoint, or return | 
 | 530 |     // INVALID_OPERATION if they cannot be obtained. | 
| Emilian Peev | 050f5dc | 2017-05-18 14:43:56 +0100 | [diff] [blame] | 531 |     virtual status_t getEndpointUsage(uint64_t *usage) const = 0; | 
| Eino-Ville Talvala | b2f5b19 | 2013-07-30 14:36:03 -0700 | [diff] [blame] | 532 |  | 
| Emilian Peev | 889234d | 2017-07-18 18:21:26 -0700 | [diff] [blame] | 533 |     // Return whether the buffer is in the list of outstanding buffers. | 
| Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 534 |     bool isOutstandingBuffer(const camera_stream_buffer& buffer) const; | 
| Emilian Peev | 889234d | 2017-07-18 18:21:26 -0700 | [diff] [blame] | 535 |  | 
| Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 536 |     // Tracking for idle state | 
 | 537 |     wp<StatusTracker> mStatusTracker; | 
 | 538 |     // Status tracker component ID | 
 | 539 |     int mStatusId; | 
 | 540 |  | 
| Eino-Ville Talvala | 4d44cad | 2015-04-11 13:15:45 -0700 | [diff] [blame] | 541 |     // Tracking for stream prepare - whether this stream can still have | 
 | 542 |     // prepareNextBuffer called on it. | 
 | 543 |     bool mStreamUnpreparable; | 
 | 544 |  | 
| Emilian Peev | 050f5dc | 2017-05-18 14:43:56 +0100 | [diff] [blame] | 545 |     uint64_t mUsage; | 
 | 546 |  | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 547 |   private: | 
| Shuzhen Wang | f9b4eb9 | 2019-06-10 11:06:01 -0700 | [diff] [blame] | 548 |     // Previously configured stream properties (post HAL override) | 
| Emilian Peev | 050f5dc | 2017-05-18 14:43:56 +0100 | [diff] [blame] | 549 |     uint64_t mOldUsage; | 
| Eino-Ville Talvala | 02bf032 | 2016-02-18 12:41:10 -0800 | [diff] [blame] | 550 |     uint32_t mOldMaxBuffers; | 
| Shuzhen Wang | f9b4eb9 | 2019-06-10 11:06:01 -0700 | [diff] [blame] | 551 |     int mOldFormat; | 
 | 552 |     android_dataspace mOldDataSpace; | 
 | 553 |  | 
| Zhijun He | 6adc9cc | 2014-04-15 14:09:55 -0700 | [diff] [blame] | 554 |     Condition mOutputBufferReturnedSignal; | 
 | 555 |     Condition mInputBufferReturnedSignal; | 
 | 556 |     static const nsecs_t kWaitForBufferDuration = 3000000000LL; // 3000 ms | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 557 |  | 
| Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 558 |     void fireBufferListenersLocked(const camera_stream_buffer& buffer, | 
| Emilian Peev | 538c90e | 2018-12-17 18:03:19 +0000 | [diff] [blame] | 559 |             bool acquired, bool output, nsecs_t timestamp = 0, uint64_t frameNumber = 0); | 
| Igor Murashkin | 2fba584 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 560 |     List<wp<Camera3StreamBufferListener> > mBufferListenerList; | 
 | 561 |  | 
| Eino-Ville Talvala | 4d44cad | 2015-04-11 13:15:45 -0700 | [diff] [blame] | 562 |     status_t        cancelPrepareLocked(); | 
 | 563 |  | 
| Chien-Yu Chen | e02e932 | 2016-04-11 16:59:33 -0700 | [diff] [blame] | 564 |     // Remove the buffer from the list of outstanding buffers. | 
| Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 565 |     void removeOutstandingBuffer(const camera_stream_buffer& buffer); | 
| Chien-Yu Chen | e02e932 | 2016-04-11 16:59:33 -0700 | [diff] [blame] | 566 |  | 
| Eino-Ville Talvala | 4d44cad | 2015-04-11 13:15:45 -0700 | [diff] [blame] | 567 |     // Tracking for PREPARING state | 
 | 568 |  | 
 | 569 |     // State of buffer preallocation. Only true if either prepareNextBuffer | 
 | 570 |     // has been called sufficient number of times, or stream configuration | 
 | 571 |     // had to register buffers with the HAL | 
 | 572 |     bool mPrepared; | 
| Shuzhen Wang | b3a0fb5 | 2018-09-13 17:24:08 -0700 | [diff] [blame] | 573 |     bool mPrepareBlockRequest; | 
| Eino-Ville Talvala | 4d44cad | 2015-04-11 13:15:45 -0700 | [diff] [blame] | 574 |  | 
| Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 575 |     Vector<camera_stream_buffer_t> mPreparedBuffers; | 
| Eino-Ville Talvala | 4d44cad | 2015-04-11 13:15:45 -0700 | [diff] [blame] | 576 |     size_t mPreparedBufferIdx; | 
 | 577 |  | 
| Ruben Brunk | c78ac26 | 2015-08-13 17:58:46 -0700 | [diff] [blame] | 578 |     // Number of buffers allocated on last prepare call. | 
| Eino-Ville Talvala | 02bf032 | 2016-02-18 12:41:10 -0800 | [diff] [blame] | 579 |     size_t mLastMaxCount; | 
| Ruben Brunk | c78ac26 | 2015-08-13 17:58:46 -0700 | [diff] [blame] | 580 |  | 
| Emilian Peev | 889234d | 2017-07-18 18:21:26 -0700 | [diff] [blame] | 581 |     mutable Mutex mOutstandingBuffersLock; | 
| Chien-Yu Chen | e02e932 | 2016-04-11 16:59:33 -0700 | [diff] [blame] | 582 |     // Outstanding buffers dequeued from the stream's buffer queue. | 
 | 583 |     List<buffer_handle_t> mOutstandingBuffers; | 
 | 584 |  | 
| Shuzhen Wang | 686f644 | 2017-06-20 16:16:04 -0700 | [diff] [blame] | 585 |     // Latency histogram of the wait time for handout buffer count to drop below | 
 | 586 |     // max_buffers. | 
 | 587 |     static const int32_t kBufferLimitLatencyBinSize = 33; //in ms | 
 | 588 |     CameraLatencyHistogram mBufferLimitLatency; | 
| Emilian Peev | 710c142 | 2017-08-30 11:19:38 +0100 | [diff] [blame] | 589 |  | 
| Yin-Chia Yeh | 9066766 | 2019-07-01 15:45:00 -0700 | [diff] [blame] | 590 |     //Keep track of original format when the stream is created in case it gets overridden | 
| Emilian Peev | 710c142 | 2017-08-30 11:19:38 +0100 | [diff] [blame] | 591 |     bool mFormatOverridden; | 
| Yin-Chia Yeh | 9066766 | 2019-07-01 15:45:00 -0700 | [diff] [blame] | 592 |     const int mOriginalFormat; | 
| Eino-Ville Talvala | 91cd3f8 | 2017-08-21 16:12:50 -0700 | [diff] [blame] | 593 |  | 
 | 594 |     //Keep track of original dataSpace in case it gets overridden | 
 | 595 |     bool mDataSpaceOverridden; | 
| Shuzhen Wang | 2f5010d | 2019-08-22 12:41:12 -0700 | [diff] [blame] | 596 |     const android_dataspace mOriginalDataSpace; | 
| Eino-Ville Talvala | 91cd3f8 | 2017-08-21 16:12:50 -0700 | [diff] [blame] | 597 |  | 
| Shuzhen Wang | c28189a | 2017-11-27 23:05:10 -0800 | [diff] [blame] | 598 |     String8 mPhysicalCameraId; | 
| Shuzhen Wang | 26abaf4 | 2018-08-28 15:41:20 -0700 | [diff] [blame] | 599 |     nsecs_t mLastTimestamp; | 
| Yin-Chia Yeh | 5fd603e | 2019-11-20 11:22:27 -0800 | [diff] [blame] | 600 |  | 
 | 601 |     bool mSupportOfflineProcessing = false; | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 602 | }; // class Camera3Stream | 
 | 603 |  | 
 | 604 | }; // namespace camera3 | 
 | 605 |  | 
 | 606 | }; // namespace android | 
 | 607 |  | 
 | 608 | #endif |