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