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