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_OUTPUT_STREAM_H |
| 18 | #define ANDROID_SERVERS_CAMERA3_OUTPUT_STREAM_H |
| 19 | |
| 20 | #include <utils/RefBase.h> |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 21 | #include <gui/IProducerListener.h> |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 22 | #include <gui/Surface.h> |
| 23 | |
Shuzhen Wang | 686f644 | 2017-06-20 16:16:04 -0700 | [diff] [blame] | 24 | #include "utils/LatencyHistogram.h" |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 25 | #include "Camera3Stream.h" |
Igor Murashkin | e3a9f96 | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 26 | #include "Camera3IOStreamBase.h" |
Igor Murashkin | 2fba584 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 27 | #include "Camera3OutputStreamInterface.h" |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 28 | #include "Camera3BufferManager.h" |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 29 | |
| 30 | namespace android { |
| 31 | |
| 32 | namespace camera3 { |
| 33 | |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 34 | class Camera3BufferManager; |
| 35 | |
| 36 | /** |
| 37 | * Stream info structure that holds the necessary stream info for buffer manager to use for |
| 38 | * buffer allocation and management. |
| 39 | */ |
| 40 | struct StreamInfo { |
| 41 | int streamId; |
| 42 | int streamSetId; |
| 43 | uint32_t width; |
| 44 | uint32_t height; |
| 45 | uint32_t format; |
| 46 | android_dataspace dataSpace; |
Emilian Peev | 050f5dc | 2017-05-18 14:43:56 +0100 | [diff] [blame] | 47 | uint64_t combinedUsage; |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 48 | size_t totalBufferCount; |
| 49 | bool isConfigured; |
Chih-Hung Hsieh | d19d994 | 2016-08-29 14:21:14 -0700 | [diff] [blame] | 50 | explicit StreamInfo(int id = CAMERA3_STREAM_ID_INVALID, |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 51 | int setId = CAMERA3_STREAM_SET_ID_INVALID, |
| 52 | uint32_t w = 0, |
| 53 | uint32_t h = 0, |
| 54 | uint32_t fmt = 0, |
| 55 | android_dataspace ds = HAL_DATASPACE_UNKNOWN, |
Emilian Peev | 050f5dc | 2017-05-18 14:43:56 +0100 | [diff] [blame] | 56 | uint64_t usage = 0, |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 57 | size_t bufferCount = 0, |
| 58 | bool configured = false) : |
| 59 | streamId(id), |
| 60 | streamSetId(setId), |
| 61 | width(w), |
| 62 | height(h), |
| 63 | format(fmt), |
| 64 | dataSpace(ds), |
| 65 | combinedUsage(usage), |
| 66 | totalBufferCount(bufferCount), |
| 67 | isConfigured(configured){} |
| 68 | }; |
| 69 | |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 70 | /** |
| 71 | * A class for managing a single stream of output data from the camera device. |
| 72 | */ |
Igor Murashkin | 2fba584 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 73 | class Camera3OutputStream : |
Igor Murashkin | e3a9f96 | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 74 | public Camera3IOStreamBase, |
Igor Murashkin | 2fba584 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 75 | public Camera3OutputStreamInterface { |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 76 | public: |
| 77 | /** |
| 78 | * Set up a stream for formats that have 2 dimensions, such as RAW and YUV. |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 79 | * A valid stream set id needs to be set to support buffer sharing between multiple |
| 80 | * streams. |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 81 | */ |
Eino-Ville Talvala | 727d172 | 2015-06-09 13:44:19 -0700 | [diff] [blame] | 82 | Camera3OutputStream(int id, sp<Surface> consumer, |
Eino-Ville Talvala | 3d82c0d | 2015-02-23 15:19:19 -0800 | [diff] [blame] | 83 | uint32_t width, uint32_t height, int format, |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 84 | android_dataspace dataSpace, camera3_stream_rotation_t rotation, |
Shuzhen Wang | c28189a | 2017-11-27 23:05:10 -0800 | [diff] [blame] | 85 | nsecs_t timestampOffset, const String8& physicalCameraId, |
| 86 | int setId = CAMERA3_STREAM_SET_ID_INVALID); |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 87 | |
| 88 | /** |
| 89 | * Set up a stream for formats that have a variable buffer size for the same |
| 90 | * dimensions, such as compressed JPEG. |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 91 | * A valid stream set id needs to be set to support buffer sharing between multiple |
| 92 | * streams. |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 93 | */ |
Eino-Ville Talvala | 727d172 | 2015-06-09 13:44:19 -0700 | [diff] [blame] | 94 | Camera3OutputStream(int id, sp<Surface> consumer, |
Eino-Ville Talvala | 3d82c0d | 2015-02-23 15:19:19 -0800 | [diff] [blame] | 95 | uint32_t width, uint32_t height, size_t maxSize, int format, |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 96 | android_dataspace dataSpace, camera3_stream_rotation_t rotation, |
Shuzhen Wang | c28189a | 2017-11-27 23:05:10 -0800 | [diff] [blame] | 97 | nsecs_t timestampOffset, const String8& physicalCameraId, |
| 98 | int setId = CAMERA3_STREAM_SET_ID_INVALID); |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 99 | |
Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 100 | /** |
| 101 | * Set up a stream with deferred consumer for formats that have 2 dimensions, such as |
| 102 | * RAW and YUV. The consumer must be set before using this stream for output. A valid |
| 103 | * stream set id needs to be set to support buffer sharing between multiple streams. |
| 104 | */ |
| 105 | Camera3OutputStream(int id, uint32_t width, uint32_t height, int format, |
Emilian Peev | 050f5dc | 2017-05-18 14:43:56 +0100 | [diff] [blame] | 106 | uint64_t consumerUsage, android_dataspace dataSpace, |
Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 107 | camera3_stream_rotation_t rotation, nsecs_t timestampOffset, |
Shuzhen Wang | c28189a | 2017-11-27 23:05:10 -0800 | [diff] [blame] | 108 | const String8& physicalCameraId, |
Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 109 | int setId = CAMERA3_STREAM_SET_ID_INVALID); |
| 110 | |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 111 | virtual ~Camera3OutputStream(); |
| 112 | |
| 113 | /** |
| 114 | * Camera3Stream interface |
| 115 | */ |
| 116 | |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 117 | virtual void dump(int fd, const Vector<String16> &args) const; |
| 118 | |
| 119 | /** |
| 120 | * Set the transform on the output stream; one of the |
| 121 | * HAL_TRANSFORM_* / NATIVE_WINDOW_TRANSFORM_* constants. |
| 122 | */ |
| 123 | status_t setTransform(int transform); |
| 124 | |
Chien-Yu Chen | 85a6455 | 2015-08-28 15:46:12 -0700 | [diff] [blame] | 125 | /** |
| 126 | * Return if this output stream is for video encoding. |
| 127 | */ |
| 128 | bool isVideoStream() const; |
Shuzhen Wang | 13a6963 | 2016-01-26 09:51:07 -0800 | [diff] [blame] | 129 | /** |
| 130 | * Return if this output stream is consumed by hardware composer. |
| 131 | */ |
| 132 | bool isConsumedByHWComposer() const; |
Chien-Yu Chen | 85a6455 | 2015-08-28 15:46:12 -0700 | [diff] [blame] | 133 | |
Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 134 | /** |
Zhijun He | f0645c1 | 2016-08-02 00:58:11 -0700 | [diff] [blame] | 135 | * Return if this output stream is consumed by hardware texture. |
| 136 | */ |
| 137 | bool isConsumedByHWTexture() const; |
| 138 | |
| 139 | /** |
Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 140 | * Return if the consumer configuration of this stream is deferred. |
| 141 | */ |
Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 142 | virtual bool isConsumerConfigurationDeferred(size_t surface_id) const; |
Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 143 | |
| 144 | /** |
Shuzhen Wang | 758c215 | 2017-01-10 18:26:18 -0800 | [diff] [blame] | 145 | * Set the consumer surfaces to the output stream. |
Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 146 | */ |
Shuzhen Wang | 758c215 | 2017-01-10 18:26:18 -0800 | [diff] [blame] | 147 | virtual status_t setConsumers(const std::vector<sp<Surface>>& consumers); |
Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 148 | |
Shuzhen Wang | 0160ddd | 2019-08-15 09:11:56 -0700 | [diff] [blame] | 149 | class BufferProducerListener : public SurfaceListener { |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 150 | public: |
Shuzhen Wang | 0160ddd | 2019-08-15 09:11:56 -0700 | [diff] [blame] | 151 | BufferProducerListener(wp<Camera3OutputStream> parent, bool needsReleaseNotify) |
| 152 | : mParent(parent), mNeedsReleaseNotify(needsReleaseNotify) {} |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 153 | |
Shuzhen Wang | 0160ddd | 2019-08-15 09:11:56 -0700 | [diff] [blame] | 154 | /** |
| 155 | * Implementation of IProducerListener, used to notify this stream that the consumer |
| 156 | * has returned a buffer and it is ready to return to Camera3BufferManager for reuse. |
| 157 | */ |
| 158 | virtual void onBufferReleased(); |
| 159 | virtual bool needsReleaseNotify() { return mNeedsReleaseNotify; } |
| 160 | virtual void onBuffersDiscarded(const std::vector<sp<GraphicBuffer>>& buffers); |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 161 | |
| 162 | private: |
Shuzhen Wang | 0160ddd | 2019-08-15 09:11:56 -0700 | [diff] [blame] | 163 | wp<Camera3OutputStream> mParent; |
| 164 | bool mNeedsReleaseNotify; |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 165 | }; |
| 166 | |
Eino-Ville Talvala | 77c1a35 | 2016-06-13 12:32:43 -0700 | [diff] [blame] | 167 | virtual status_t detachBuffer(sp<GraphicBuffer>* buffer, int* fenceFd); |
| 168 | |
Shuzhen Wang | bee0f0a | 2017-01-24 14:51:37 -0800 | [diff] [blame] | 169 | /** |
| 170 | * Notify that the buffer is being released to the buffer queue instead of |
| 171 | * being queued to the consumer. |
| 172 | */ |
| 173 | virtual status_t notifyBufferReleased(ANativeWindowBuffer *anwBuffer); |
Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 174 | |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 175 | /** |
Chien-Yu Chen | a936ac2 | 2017-10-23 15:59:49 -0700 | [diff] [blame] | 176 | * Drop buffers if dropping is true. If dropping is false, do not drop buffers. |
| 177 | */ |
| 178 | virtual status_t dropBuffers(bool dropping) override; |
| 179 | |
| 180 | /** |
Shuzhen Wang | 5c22c15 | 2017-12-31 17:12:25 -0800 | [diff] [blame] | 181 | * Query the physical camera id for the output stream. |
| 182 | */ |
| 183 | virtual const String8& getPhysicalCameraId() const override; |
| 184 | |
| 185 | /** |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 186 | * Set the graphic buffer manager to get/return the stream buffers. |
| 187 | * |
| 188 | * It is only legal to call this method when stream is in STATE_CONSTRUCTED state. |
| 189 | */ |
| 190 | status_t setBufferManager(sp<Camera3BufferManager> bufferManager); |
| 191 | |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 192 | /** |
| 193 | * Query the ouput surface id. |
| 194 | */ |
| 195 | virtual ssize_t getSurfaceId(const sp<Surface> &/*surface*/) { return 0; } |
| 196 | |
Yin-Chia Yeh | 58b1b4e | 2018-10-15 12:18:36 -0700 | [diff] [blame] | 197 | virtual status_t getUniqueSurfaceIds(const std::vector<size_t>&, |
| 198 | /*out*/std::vector<size_t>*) { return INVALID_OPERATION; }; |
| 199 | |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 200 | /** |
| 201 | * Update the stream output surfaces. |
| 202 | */ |
| 203 | virtual status_t updateStream(const std::vector<sp<Surface>> &outputSurfaces, |
| 204 | const std::vector<OutputStreamInfo> &outputInfo, |
| 205 | const std::vector<size_t> &removedSurfaceIds, |
| 206 | KeyedVector<sp<Surface>, size_t> *outputMap/*out*/); |
| 207 | |
Emilian Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 208 | /** |
| 209 | * Apply ZSL related consumer usage quirk. |
| 210 | */ |
| 211 | static void applyZSLUsageQuirk(int format, uint64_t *consumerUsage /*inout*/); |
| 212 | |
Shuzhen Wang | abbcb6b | 2020-12-09 22:32:44 -0800 | [diff] [blame] | 213 | void setImageDumpMask(int mask) { mImageDumpMask = mask; } |
| 214 | |
Igor Murashkin | e3a9f96 | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 215 | protected: |
| 216 | Camera3OutputStream(int id, camera3_stream_type_t type, |
Eino-Ville Talvala | 3d82c0d | 2015-02-23 15:19:19 -0800 | [diff] [blame] | 217 | uint32_t width, uint32_t height, int format, |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 218 | android_dataspace dataSpace, camera3_stream_rotation_t rotation, |
Shuzhen Wang | c28189a | 2017-11-27 23:05:10 -0800 | [diff] [blame] | 219 | const String8& physicalCameraId, |
Emilian Peev | 050f5dc | 2017-05-18 14:43:56 +0100 | [diff] [blame] | 220 | uint64_t consumerUsage = 0, nsecs_t timestampOffset = 0, |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 221 | int setId = CAMERA3_STREAM_SET_ID_INVALID); |
Igor Murashkin | e3a9f96 | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 222 | |
Zhijun He | 124ccf4 | 2013-05-22 14:01:30 -0700 | [diff] [blame] | 223 | /** |
| 224 | * Note that we release the lock briefly in this function |
| 225 | */ |
Igor Murashkin | e3a9f96 | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 226 | virtual status_t returnBufferCheckedLocked( |
| 227 | const camera3_stream_buffer &buffer, |
| 228 | nsecs_t timestamp, |
| 229 | bool output, |
Yin-Chia Yeh | 58b1b4e | 2018-10-15 12:18:36 -0700 | [diff] [blame] | 230 | const std::vector<size_t>& surface_ids, |
Igor Murashkin | e3a9f96 | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 231 | /*out*/ |
| 232 | sp<Fence> *releaseFenceOut); |
| 233 | |
Zhijun He | 0a21051 | 2014-07-24 13:45:15 -0700 | [diff] [blame] | 234 | virtual status_t disconnectLocked(); |
| 235 | |
Emilian Peev | 050f5dc | 2017-05-18 14:43:56 +0100 | [diff] [blame] | 236 | status_t getEndpointUsageForSurface(uint64_t *usage, |
Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 237 | const sp<Surface>& surface) const; |
| 238 | status_t configureConsumerQueueLocked(); |
| 239 | |
| 240 | // Consumer as the output of camera HAL |
Eino-Ville Talvala | 727d172 | 2015-06-09 13:44:19 -0700 | [diff] [blame] | 241 | sp<Surface> mConsumer; |
Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 242 | |
Emilian Peev | 050f5dc | 2017-05-18 14:43:56 +0100 | [diff] [blame] | 243 | uint64_t getPresetConsumerUsage() const { return mConsumerUsage; } |
Zhijun He | f0645c1 | 2016-08-02 00:58:11 -0700 | [diff] [blame] | 244 | |
| 245 | static const nsecs_t kDequeueBufferTimeout = 1000000000; // 1 sec |
| 246 | |
Shuzhen Wang | bee0f0a | 2017-01-24 14:51:37 -0800 | [diff] [blame] | 247 | status_t getBufferLockedCommon(ANativeWindowBuffer** anb, int* fenceFd); |
| 248 | |
| 249 | |
Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 250 | private: |
| 251 | |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 252 | int mTransform; |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 253 | |
Igor Murashkin | e3a9f96 | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 254 | virtual status_t setTransformLocked(int transform); |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 255 | |
Ruchit Sharma | e0711f2 | 2014-08-18 13:48:24 -0400 | [diff] [blame] | 256 | bool mTraceFirstBuffer; |
| 257 | |
Eino-Ville Talvala | 727d172 | 2015-06-09 13:44:19 -0700 | [diff] [blame] | 258 | // Name of Surface consumer |
| 259 | String8 mConsumerName; |
| 260 | |
Shuzhen Wang | c28dccc | 2016-02-11 23:48:46 -0800 | [diff] [blame] | 261 | // Whether consumer assumes MONOTONIC timestamp |
| 262 | bool mUseMonoTimestamp; |
Shuzhen Wang | 13a6963 | 2016-01-26 09:51:07 -0800 | [diff] [blame] | 263 | |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 264 | /** |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 265 | * GraphicBuffer manager this stream is registered to. Used to replace the buffer |
| 266 | * allocation/deallocation role of BufferQueue. |
| 267 | */ |
| 268 | sp<Camera3BufferManager> mBufferManager; |
| 269 | |
| 270 | /** |
Shuzhen Wang | 0160ddd | 2019-08-15 09:11:56 -0700 | [diff] [blame] | 271 | * Buffer producer listener, used to handle notification when a buffer is released |
| 272 | * from consumer side, or a set of buffers are discarded by the consumer. |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 273 | */ |
Shuzhen Wang | 0160ddd | 2019-08-15 09:11:56 -0700 | [diff] [blame] | 274 | sp<BufferProducerListener> mBufferProducerListener; |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 275 | |
| 276 | /** |
| 277 | * Flag indicating if the buffer manager is used to allocate the stream buffers |
| 278 | */ |
| 279 | bool mUseBufferManager; |
Shuzhen Wang | c28dccc | 2016-02-11 23:48:46 -0800 | [diff] [blame] | 280 | |
| 281 | /** |
| 282 | * Timestamp offset for video and hardware composer consumed streams |
| 283 | */ |
| 284 | nsecs_t mTimestampOffset; |
| 285 | |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 286 | /** |
Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 287 | * Consumer end point usage flag set by the constructor for the deferred |
| 288 | * consumer case. |
| 289 | */ |
Emilian Peev | 050f5dc | 2017-05-18 14:43:56 +0100 | [diff] [blame] | 290 | uint64_t mConsumerUsage; |
Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 291 | |
Chien-Yu Chen | a936ac2 | 2017-10-23 15:59:49 -0700 | [diff] [blame] | 292 | // Whether to drop valid buffers. |
| 293 | bool mDropBuffers; |
| 294 | |
Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 295 | /** |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 296 | * Internal Camera3Stream interface |
| 297 | */ |
Shuzhen Wang | bee0f0a | 2017-01-24 14:51:37 -0800 | [diff] [blame] | 298 | virtual status_t getBufferLocked(camera3_stream_buffer *buffer, |
| 299 | const std::vector<size_t>& surface_ids); |
| 300 | |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 301 | virtual status_t returnBufferLocked( |
| 302 | const camera3_stream_buffer &buffer, |
Yin-Chia Yeh | 58b1b4e | 2018-10-15 12:18:36 -0700 | [diff] [blame] | 303 | nsecs_t timestamp, const std::vector<size_t>& surface_ids); |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 304 | |
Shuzhen Wang | bee0f0a | 2017-01-24 14:51:37 -0800 | [diff] [blame] | 305 | virtual status_t queueBufferToConsumer(sp<ANativeWindow>& consumer, |
Yin-Chia Yeh | 58b1b4e | 2018-10-15 12:18:36 -0700 | [diff] [blame] | 306 | ANativeWindowBuffer* buffer, int anwReleaseFence, |
| 307 | const std::vector<size_t>& surface_ids); |
Shuzhen Wang | bee0f0a | 2017-01-24 14:51:37 -0800 | [diff] [blame] | 308 | |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 309 | virtual status_t configureQueueLocked(); |
Eino-Ville Talvala | b2f5b19 | 2013-07-30 14:36:03 -0700 | [diff] [blame] | 310 | |
Emilian Peev | 050f5dc | 2017-05-18 14:43:56 +0100 | [diff] [blame] | 311 | virtual status_t getEndpointUsage(uint64_t *usage) const; |
Eino-Ville Talvala | b2f5b19 | 2013-07-30 14:36:03 -0700 | [diff] [blame] | 312 | |
Yin-Chia Yeh | 89954d9 | 2017-05-21 17:28:53 -0700 | [diff] [blame] | 313 | /** |
| 314 | * Private methods |
| 315 | */ |
Yin-Chia Yeh | 017d49c | 2017-03-31 19:11:00 -0700 | [diff] [blame] | 316 | void onBuffersRemovedLocked(const std::vector<sp<GraphicBuffer>>&); |
Yin-Chia Yeh | 89954d9 | 2017-05-21 17:28:53 -0700 | [diff] [blame] | 317 | status_t detachBufferLocked(sp<GraphicBuffer>* buffer, int* fenceFd); |
Yin-Chia Yeh | bf1b8b9 | 2019-03-06 14:56:08 -0800 | [diff] [blame] | 318 | // Call this after each dequeueBuffer/attachBuffer/detachNextBuffer call to get update on |
| 319 | // removed buffers. Set notifyBufferManager to false when the call is initiated by buffer |
| 320 | // manager so buffer manager doesn't need to be notified. |
| 321 | void checkRemovedBuffersLocked(bool notifyBufferManager = true); |
| 322 | |
| 323 | // Check return status of IGBP calls and set abandoned state accordingly |
| 324 | void checkRetAndSetAbandonedLocked(status_t res); |
Yin-Chia Yeh | 017d49c | 2017-03-31 19:11:00 -0700 | [diff] [blame] | 325 | |
Yin-Chia Yeh | a1b56c8 | 2019-03-27 15:50:39 -0700 | [diff] [blame] | 326 | // If the status indicates abandonded stream, only log when state hasn't been updated to |
| 327 | // STATE_ABANDONED |
| 328 | static bool shouldLogError(status_t res, StreamState state); |
| 329 | |
Shuzhen Wang | abbcb6b | 2020-12-09 22:32:44 -0800 | [diff] [blame] | 330 | // Dump images to disk before returning to consumer |
| 331 | void dumpImageToDisk(nsecs_t timestamp, ANativeWindowBuffer* anwBuffer, int fence); |
| 332 | |
Shuzhen Wang | 686f644 | 2017-06-20 16:16:04 -0700 | [diff] [blame] | 333 | static const int32_t kDequeueLatencyBinSize = 5; // in ms |
| 334 | CameraLatencyHistogram mDequeueBufferLatency; |
| 335 | |
Shuzhen Wang | abbcb6b | 2020-12-09 22:32:44 -0800 | [diff] [blame] | 336 | int mImageDumpMask = 0; |
| 337 | |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 338 | }; // class Camera3OutputStream |
| 339 | |
| 340 | } // namespace camera3 |
| 341 | |
| 342 | } // namespace android |
| 343 | |
| 344 | #endif |