blob: 5afa91a90b021a439a37a29593800d1190884d45 [file] [log] [blame]
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -08001/*
Shuzhen Wangc28189a2017-11-27 23:05:10 -08002 * Copyright (C) 2013-2018 The Android Open Source Project
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -08003 *
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 Yeh14ef48d2020-02-10 15:06:37 -080020#include <mutex>
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080021#include <utils/RefBase.h>
Zhijun He125684a2015-12-26 15:07:30 -080022#include <gui/IProducerListener.h>
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080023#include <gui/Surface.h>
Shuzhen Wang00abbeb2022-02-25 17:14:42 -080024#include <gui/DisplayEventReceiver.h>
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080025
Shuzhen Wang686f6442017-06-20 16:16:04 -070026#include "utils/LatencyHistogram.h"
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080027#include "Camera3Stream.h"
Igor Murashkine3a9f962013-05-08 18:03:15 -070028#include "Camera3IOStreamBase.h"
Igor Murashkin2fba5842013-04-22 14:03:54 -070029#include "Camera3OutputStreamInterface.h"
Zhijun He125684a2015-12-26 15:07:30 -080030#include "Camera3BufferManager.h"
Shuzhen Wangba92d772022-04-11 11:47:24 -070031#include "PreviewFrameSpacer.h"
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080032
33namespace android {
34
35namespace camera3 {
36
Zhijun He125684a2015-12-26 15:07:30 -080037class Camera3BufferManager;
38
39/**
40 * Stream info structure that holds the necessary stream info for buffer manager to use for
41 * buffer allocation and management.
42 */
43struct StreamInfo {
44 int streamId;
45 int streamSetId;
46 uint32_t width;
47 uint32_t height;
48 uint32_t format;
49 android_dataspace dataSpace;
Emilian Peev050f5dc2017-05-18 14:43:56 +010050 uint64_t combinedUsage;
Zhijun He125684a2015-12-26 15:07:30 -080051 size_t totalBufferCount;
52 bool isConfigured;
Shuzhen Wang83bff122020-11-20 15:51:39 -080053 bool isMultiRes;
Chih-Hung Hsiehd19d9942016-08-29 14:21:14 -070054 explicit StreamInfo(int id = CAMERA3_STREAM_ID_INVALID,
Zhijun He125684a2015-12-26 15:07:30 -080055 int setId = CAMERA3_STREAM_SET_ID_INVALID,
56 uint32_t w = 0,
57 uint32_t h = 0,
58 uint32_t fmt = 0,
59 android_dataspace ds = HAL_DATASPACE_UNKNOWN,
Emilian Peev050f5dc2017-05-18 14:43:56 +010060 uint64_t usage = 0,
Zhijun He125684a2015-12-26 15:07:30 -080061 size_t bufferCount = 0,
Shuzhen Wang83bff122020-11-20 15:51:39 -080062 bool configured = false,
63 bool multiRes = false) :
Zhijun He125684a2015-12-26 15:07:30 -080064 streamId(id),
65 streamSetId(setId),
66 width(w),
67 height(h),
68 format(fmt),
69 dataSpace(ds),
70 combinedUsage(usage),
71 totalBufferCount(bufferCount),
Shuzhen Wang83bff122020-11-20 15:51:39 -080072 isConfigured(configured),
73 isMultiRes(multiRes) {}
Zhijun He125684a2015-12-26 15:07:30 -080074};
75
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080076/**
77 * A class for managing a single stream of output data from the camera device.
78 */
Igor Murashkin2fba5842013-04-22 14:03:54 -070079class Camera3OutputStream :
Igor Murashkine3a9f962013-05-08 18:03:15 -070080 public Camera3IOStreamBase,
Igor Murashkin2fba5842013-04-22 14:03:54 -070081 public Camera3OutputStreamInterface {
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080082 public:
83 /**
84 * Set up a stream for formats that have 2 dimensions, such as RAW and YUV.
Zhijun He125684a2015-12-26 15:07:30 -080085 * A valid stream set id needs to be set to support buffer sharing between multiple
86 * streams.
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080087 */
Eino-Ville Talvala727d1722015-06-09 13:44:19 -070088 Camera3OutputStream(int id, sp<Surface> consumer,
Eino-Ville Talvala3d82c0d2015-02-23 15:19:19 -080089 uint32_t width, uint32_t height, int format,
Emilian Peevf4816702020-04-03 15:44:51 -070090 android_dataspace dataSpace, camera_stream_rotation_t rotation,
Shuzhen Wangc28189a2017-11-27 23:05:10 -080091 nsecs_t timestampOffset, const String8& physicalCameraId,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -080092 const std::unordered_set<int32_t> &sensorPixelModesUsed,
Emilian Peev2295df72021-11-12 18:14:10 -080093 int setId = CAMERA3_STREAM_SET_ID_INVALID, bool isMultiResolution = false,
Emilian Peevc81a7592022-02-14 17:38:18 -080094 int64_t dynamicProfile = ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD,
Shuzhen Wang8ed1e872022-03-08 16:34:33 -080095 int64_t streamUseCase = ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT,
Shuzhen Wange4208922022-02-01 16:52:48 -080096 bool deviceTimeBaseIsRealtime = false,
Shuzhen Wang610d7b82022-02-08 14:37:22 -080097 int timestampBase = OutputConfiguration::TIMESTAMP_BASE_DEFAULT,
98 int mirrorMode = OutputConfiguration::MIRROR_MODE_AUTO);
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080099 /**
100 * Set up a stream for formats that have a variable buffer size for the same
101 * dimensions, such as compressed JPEG.
Zhijun He125684a2015-12-26 15:07:30 -0800102 * A valid stream set id needs to be set to support buffer sharing between multiple
103 * streams.
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800104 */
Eino-Ville Talvala727d1722015-06-09 13:44:19 -0700105 Camera3OutputStream(int id, sp<Surface> consumer,
Eino-Ville Talvala3d82c0d2015-02-23 15:19:19 -0800106 uint32_t width, uint32_t height, size_t maxSize, int format,
Emilian Peevf4816702020-04-03 15:44:51 -0700107 android_dataspace dataSpace, camera_stream_rotation_t rotation,
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800108 nsecs_t timestampOffset, const String8& physicalCameraId,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800109 const std::unordered_set<int32_t> &sensorPixelModesUsed,
Emilian Peev2295df72021-11-12 18:14:10 -0800110 int setId = CAMERA3_STREAM_SET_ID_INVALID, bool isMultiResolution = false,
Emilian Peevc81a7592022-02-14 17:38:18 -0800111 int64_t dynamicProfile = ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD,
Shuzhen Wang8ed1e872022-03-08 16:34:33 -0800112 int64_t streamUseCase = ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT,
Shuzhen Wange4208922022-02-01 16:52:48 -0800113 bool deviceTimeBaseIsRealtime = false,
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800114 int timestampBase = OutputConfiguration::TIMESTAMP_BASE_DEFAULT,
115 int mirrorMode = OutputConfiguration::MIRROR_MODE_AUTO);
Zhijun He5d677d12016-05-29 16:52:39 -0700116 /**
117 * Set up a stream with deferred consumer for formats that have 2 dimensions, such as
118 * RAW and YUV. The consumer must be set before using this stream for output. A valid
119 * stream set id needs to be set to support buffer sharing between multiple streams.
120 */
121 Camera3OutputStream(int id, uint32_t width, uint32_t height, int format,
Emilian Peev050f5dc2017-05-18 14:43:56 +0100122 uint64_t consumerUsage, android_dataspace dataSpace,
Emilian Peevf4816702020-04-03 15:44:51 -0700123 camera_stream_rotation_t rotation, nsecs_t timestampOffset,
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800124 const String8& physicalCameraId,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800125 const std::unordered_set<int32_t> &sensorPixelModesUsed,
Emilian Peev2295df72021-11-12 18:14:10 -0800126 int setId = CAMERA3_STREAM_SET_ID_INVALID, bool isMultiResolution = false,
Emilian Peevc81a7592022-02-14 17:38:18 -0800127 int64_t dynamicProfile = ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD,
Shuzhen Wang8ed1e872022-03-08 16:34:33 -0800128 int64_t streamUseCase = ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT,
Shuzhen Wange4208922022-02-01 16:52:48 -0800129 bool deviceTimeBaseIsRealtime = false,
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800130 int timestampBase = OutputConfiguration::TIMESTAMP_BASE_DEFAULT,
131 int mirrorMode = OutputConfiguration::MIRROR_MODE_AUTO);
Zhijun He5d677d12016-05-29 16:52:39 -0700132
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800133 virtual ~Camera3OutputStream();
134
135 /**
136 * Camera3Stream interface
137 */
138
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800139 virtual void dump(int fd, const Vector<String16> &args) const;
140
141 /**
142 * Set the transform on the output stream; one of the
143 * HAL_TRANSFORM_* / NATIVE_WINDOW_TRANSFORM_* constants.
144 */
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800145 status_t setTransform(int transform, bool mayChangeMirror);
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800146
Chien-Yu Chen85a64552015-08-28 15:46:12 -0700147 /**
148 * Return if this output stream is for video encoding.
149 */
150 bool isVideoStream() const;
Shuzhen Wang13a69632016-01-26 09:51:07 -0800151 /**
152 * Return if this output stream is consumed by hardware composer.
153 */
154 bool isConsumedByHWComposer() const;
Chien-Yu Chen85a64552015-08-28 15:46:12 -0700155
Zhijun He5d677d12016-05-29 16:52:39 -0700156 /**
Zhijun Hef0645c12016-08-02 00:58:11 -0700157 * Return if this output stream is consumed by hardware texture.
158 */
159 bool isConsumedByHWTexture() const;
160
161 /**
Shuzhen Wang05ce6b52022-05-10 18:18:54 -0700162 * Return if this output stream is consumed by CPU.
163 */
164 bool isConsumedByCPU() const;
165
166 /**
Zhijun He5d677d12016-05-29 16:52:39 -0700167 * Return if the consumer configuration of this stream is deferred.
168 */
Shuzhen Wang0129d522016-10-30 22:43:41 -0700169 virtual bool isConsumerConfigurationDeferred(size_t surface_id) const;
Zhijun He5d677d12016-05-29 16:52:39 -0700170
171 /**
Shuzhen Wang758c2152017-01-10 18:26:18 -0800172 * Set the consumer surfaces to the output stream.
Zhijun He5d677d12016-05-29 16:52:39 -0700173 */
Shuzhen Wang758c2152017-01-10 18:26:18 -0800174 virtual status_t setConsumers(const std::vector<sp<Surface>>& consumers);
Zhijun He5d677d12016-05-29 16:52:39 -0700175
Shuzhen Wang0160ddd2019-08-15 09:11:56 -0700176 class BufferProducerListener : public SurfaceListener {
Zhijun He125684a2015-12-26 15:07:30 -0800177 public:
Shuzhen Wang0160ddd2019-08-15 09:11:56 -0700178 BufferProducerListener(wp<Camera3OutputStream> parent, bool needsReleaseNotify)
179 : mParent(parent), mNeedsReleaseNotify(needsReleaseNotify) {}
Zhijun He125684a2015-12-26 15:07:30 -0800180
Shuzhen Wang0160ddd2019-08-15 09:11:56 -0700181 /**
182 * Implementation of IProducerListener, used to notify this stream that the consumer
183 * has returned a buffer and it is ready to return to Camera3BufferManager for reuse.
184 */
185 virtual void onBufferReleased();
186 virtual bool needsReleaseNotify() { return mNeedsReleaseNotify; }
187 virtual void onBuffersDiscarded(const std::vector<sp<GraphicBuffer>>& buffers);
Zhijun He125684a2015-12-26 15:07:30 -0800188
189 private:
Shuzhen Wang0160ddd2019-08-15 09:11:56 -0700190 wp<Camera3OutputStream> mParent;
191 bool mNeedsReleaseNotify;
Zhijun He125684a2015-12-26 15:07:30 -0800192 };
193
Eino-Ville Talvala77c1a352016-06-13 12:32:43 -0700194 virtual status_t detachBuffer(sp<GraphicBuffer>* buffer, int* fenceFd);
195
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800196 /**
197 * Notify that the buffer is being released to the buffer queue instead of
198 * being queued to the consumer.
199 */
200 virtual status_t notifyBufferReleased(ANativeWindowBuffer *anwBuffer);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700201
Zhijun He125684a2015-12-26 15:07:30 -0800202 /**
Chien-Yu Chena936ac22017-10-23 15:59:49 -0700203 * Drop buffers if dropping is true. If dropping is false, do not drop buffers.
204 */
205 virtual status_t dropBuffers(bool dropping) override;
206
207 /**
Shuzhen Wang5c22c152017-12-31 17:12:25 -0800208 * Query the physical camera id for the output stream.
209 */
210 virtual const String8& getPhysicalCameraId() const override;
211
212 /**
Zhijun He125684a2015-12-26 15:07:30 -0800213 * Set the graphic buffer manager to get/return the stream buffers.
214 *
215 * It is only legal to call this method when stream is in STATE_CONSTRUCTED state.
216 */
217 status_t setBufferManager(sp<Camera3BufferManager> bufferManager);
218
Emilian Peev40ead602017-09-26 15:46:36 +0100219 /**
220 * Query the ouput surface id.
221 */
222 virtual ssize_t getSurfaceId(const sp<Surface> &/*surface*/) { return 0; }
223
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -0700224 virtual status_t getUniqueSurfaceIds(const std::vector<size_t>&,
225 /*out*/std::vector<size_t>*) { return INVALID_OPERATION; };
226
Emilian Peev40ead602017-09-26 15:46:36 +0100227 /**
228 * Update the stream output surfaces.
229 */
230 virtual status_t updateStream(const std::vector<sp<Surface>> &outputSurfaces,
231 const std::vector<OutputStreamInfo> &outputInfo,
232 const std::vector<size_t> &removedSurfaceIds,
233 KeyedVector<sp<Surface>, size_t> *outputMap/*out*/);
234
Emilian Peev35ae8262018-11-08 13:11:32 +0000235 /**
Yin-Chia Yeh14ef48d2020-02-10 15:06:37 -0800236 * Set the batch size for buffer operations. The output stream will request
237 * buffers from buffer queue on a batch basis. Currently only video streams
238 * are allowed to set the batch size. Also if the stream is managed by
239 * buffer manager (Surface group in Java API) then batching is also not
240 * supported. Changing batch size on the fly while there is already batched
241 * buffers in the stream is also not supported.
242 * If the batch size is larger than the max dequeue count set
243 * by the camera HAL, the batch size will be set to the max dequeue count
244 * instead.
245 */
246 virtual status_t setBatchSize(size_t batchSize = 1) override;
247
248 /**
Shuzhen Wang00abbeb2022-02-25 17:14:42 -0800249 * Notify the stream on change of min frame durations.
250 */
251 virtual void onMinDurationChanged(nsecs_t duration) override;
252
253 /**
Emilian Peev35ae8262018-11-08 13:11:32 +0000254 * Apply ZSL related consumer usage quirk.
255 */
256 static void applyZSLUsageQuirk(int format, uint64_t *consumerUsage /*inout*/);
257
Shuzhen Wangabbcb6b2020-12-09 22:32:44 -0800258 void setImageDumpMask(int mask) { mImageDumpMask = mask; }
Shuzhen Wangba92d772022-04-11 11:47:24 -0700259 bool shouldLogError(status_t res);
Shuzhen Wangabbcb6b2020-12-09 22:32:44 -0800260
Igor Murashkine3a9f962013-05-08 18:03:15 -0700261 protected:
Emilian Peevf4816702020-04-03 15:44:51 -0700262 Camera3OutputStream(int id, camera_stream_type_t type,
Eino-Ville Talvala3d82c0d2015-02-23 15:19:19 -0800263 uint32_t width, uint32_t height, int format,
Emilian Peevf4816702020-04-03 15:44:51 -0700264 android_dataspace dataSpace, camera_stream_rotation_t rotation,
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800265 const String8& physicalCameraId,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800266 const std::unordered_set<int32_t> &sensorPixelModesUsed,
Emilian Peev050f5dc2017-05-18 14:43:56 +0100267 uint64_t consumerUsage = 0, nsecs_t timestampOffset = 0,
Emilian Peev2295df72021-11-12 18:14:10 -0800268 int setId = CAMERA3_STREAM_SET_ID_INVALID, bool isMultiResolution = false,
Emilian Peevc81a7592022-02-14 17:38:18 -0800269 int64_t dynamicProfile = ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD,
Shuzhen Wang8ed1e872022-03-08 16:34:33 -0800270 int64_t streamUseCase = ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT,
Shuzhen Wange4208922022-02-01 16:52:48 -0800271 bool deviceTimeBaseIsRealtime = false,
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800272 int timestampBase = OutputConfiguration::TIMESTAMP_BASE_DEFAULT,
273 int mirrorMode = OutputConfiguration::MIRROR_MODE_AUTO);
Igor Murashkine3a9f962013-05-08 18:03:15 -0700274
Zhijun He124ccf42013-05-22 14:01:30 -0700275 /**
276 * Note that we release the lock briefly in this function
277 */
Igor Murashkine3a9f962013-05-08 18:03:15 -0700278 virtual status_t returnBufferCheckedLocked(
Emilian Peevf4816702020-04-03 15:44:51 -0700279 const camera_stream_buffer &buffer,
Igor Murashkine3a9f962013-05-08 18:03:15 -0700280 nsecs_t timestamp,
Shuzhen Wang90708ea2021-11-04 11:40:49 -0700281 nsecs_t readoutTimestamp,
Igor Murashkine3a9f962013-05-08 18:03:15 -0700282 bool output,
Emilian Peev5104fe92021-10-21 14:27:09 -0700283 int32_t transform,
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -0700284 const std::vector<size_t>& surface_ids,
Igor Murashkine3a9f962013-05-08 18:03:15 -0700285 /*out*/
286 sp<Fence> *releaseFenceOut);
287
Zhijun He0a210512014-07-24 13:45:15 -0700288 virtual status_t disconnectLocked();
289
Emilian Peev050f5dc2017-05-18 14:43:56 +0100290 status_t getEndpointUsageForSurface(uint64_t *usage,
Shuzhen Wang0129d522016-10-30 22:43:41 -0700291 const sp<Surface>& surface) const;
Shuzhen Wangba92d772022-04-11 11:47:24 -0700292 status_t configureConsumerQueueLocked(bool allowPreviewRespace);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700293
294 // Consumer as the output of camera HAL
Eino-Ville Talvala727d1722015-06-09 13:44:19 -0700295 sp<Surface> mConsumer;
Zhijun He5d677d12016-05-29 16:52:39 -0700296
Emilian Peev050f5dc2017-05-18 14:43:56 +0100297 uint64_t getPresetConsumerUsage() const { return mConsumerUsage; }
Zhijun Hef0645c12016-08-02 00:58:11 -0700298
299 static const nsecs_t kDequeueBufferTimeout = 1000000000; // 1 sec
300
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800301 status_t getBufferLockedCommon(ANativeWindowBuffer** anb, int* fenceFd);
302
303
Shuzhen Wang0129d522016-10-30 22:43:41 -0700304 private:
305
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800306 int mTransform;
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800307
Igor Murashkine3a9f962013-05-08 18:03:15 -0700308 virtual status_t setTransformLocked(int transform);
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800309
Ruchit Sharmae0711f22014-08-18 13:48:24 -0400310 bool mTraceFirstBuffer;
311
Eino-Ville Talvala727d1722015-06-09 13:44:19 -0700312 // Name of Surface consumer
313 String8 mConsumerName;
314
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800315 /**
Zhijun He125684a2015-12-26 15:07:30 -0800316 * GraphicBuffer manager this stream is registered to. Used to replace the buffer
317 * allocation/deallocation role of BufferQueue.
318 */
319 sp<Camera3BufferManager> mBufferManager;
320
321 /**
Shuzhen Wang0160ddd2019-08-15 09:11:56 -0700322 * Buffer producer listener, used to handle notification when a buffer is released
323 * from consumer side, or a set of buffers are discarded by the consumer.
Zhijun He125684a2015-12-26 15:07:30 -0800324 */
Shuzhen Wang0160ddd2019-08-15 09:11:56 -0700325 sp<BufferProducerListener> mBufferProducerListener;
Zhijun He125684a2015-12-26 15:07:30 -0800326
327 /**
328 * Flag indicating if the buffer manager is used to allocate the stream buffers
329 */
330 bool mUseBufferManager;
Shuzhen Wangc28dccc2016-02-11 23:48:46 -0800331
332 /**
Shuzhen Wange4208922022-02-01 16:52:48 -0800333 * Offset used to override camera HAL produced timestamps
334 *
335 * The offset is first initialized to bootTime - monotonicTime in
336 * constructor, and may later be updated based on the client's timestampBase
337 * setting.
Shuzhen Wangc28dccc2016-02-11 23:48:46 -0800338 */
339 nsecs_t mTimestampOffset;
340
Zhijun He125684a2015-12-26 15:07:30 -0800341 /**
Zhijun He5d677d12016-05-29 16:52:39 -0700342 * Consumer end point usage flag set by the constructor for the deferred
343 * consumer case.
344 */
Emilian Peev050f5dc2017-05-18 14:43:56 +0100345 uint64_t mConsumerUsage;
Zhijun He5d677d12016-05-29 16:52:39 -0700346
Chien-Yu Chena936ac22017-10-23 15:59:49 -0700347 // Whether to drop valid buffers.
348 bool mDropBuffers;
349
Yin-Chia Yeh14ef48d2020-02-10 15:06:37 -0800350
Yin-Chia Yeh14ef48d2020-02-10 15:06:37 -0800351
352 // The batch size for buffer operation
Shuzhen Wangc7629462021-07-12 15:02:58 -0700353 std::atomic_size_t mBatchSize = 1;
Yin-Chia Yeh14ef48d2020-02-10 15:06:37 -0800354
Shuzhen Wangc7629462021-07-12 15:02:58 -0700355 // Protecting batch states below, must be acquired after mLock
356 std::mutex mBatchLock;
Yin-Chia Yeh14ef48d2020-02-10 15:06:37 -0800357 // Prefetched buffers (ready to be handed to client)
358 std::vector<Surface::BatchBuffer> mBatchedBuffers;
Yin-Chia Yeh14ef48d2020-02-10 15:06:37 -0800359 // ---- End of mBatchLock protected scope ----
360
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800361 const int mMirrorMode;
362
Zhijun He5d677d12016-05-29 16:52:39 -0700363 /**
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800364 * Internal Camera3Stream interface
365 */
Emilian Peevf4816702020-04-03 15:44:51 -0700366 virtual status_t getBufferLocked(camera_stream_buffer *buffer,
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800367 const std::vector<size_t>& surface_ids);
368
Yin-Chia Yeh14ef48d2020-02-10 15:06:37 -0800369 virtual status_t getBuffersLocked(/*out*/std::vector<OutstandingBuffer>* buffers) override;
370
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800371 virtual status_t returnBufferLocked(
Emilian Peevf4816702020-04-03 15:44:51 -0700372 const camera_stream_buffer &buffer,
Shuzhen Wang90708ea2021-11-04 11:40:49 -0700373 nsecs_t timestamp, nsecs_t readoutTimestamp,
374 int32_t transform, const std::vector<size_t>& surface_ids);
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800375
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800376 virtual status_t queueBufferToConsumer(sp<ANativeWindow>& consumer,
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -0700377 ANativeWindowBuffer* buffer, int anwReleaseFence,
378 const std::vector<size_t>& surface_ids);
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800379
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800380 virtual status_t configureQueueLocked();
Eino-Ville Talvalab2f5b192013-07-30 14:36:03 -0700381
Emilian Peev050f5dc2017-05-18 14:43:56 +0100382 virtual status_t getEndpointUsage(uint64_t *usage) const;
Eino-Ville Talvalab2f5b192013-07-30 14:36:03 -0700383
Yin-Chia Yeh89954d92017-05-21 17:28:53 -0700384 /**
385 * Private methods
386 */
Yin-Chia Yeh017d49c2017-03-31 19:11:00 -0700387 void onBuffersRemovedLocked(const std::vector<sp<GraphicBuffer>>&);
Yin-Chia Yeh89954d92017-05-21 17:28:53 -0700388 status_t detachBufferLocked(sp<GraphicBuffer>* buffer, int* fenceFd);
Yin-Chia Yehbf1b8b92019-03-06 14:56:08 -0800389 // Call this after each dequeueBuffer/attachBuffer/detachNextBuffer call to get update on
390 // removed buffers. Set notifyBufferManager to false when the call is initiated by buffer
391 // manager so buffer manager doesn't need to be notified.
392 void checkRemovedBuffersLocked(bool notifyBufferManager = true);
393
394 // Check return status of IGBP calls and set abandoned state accordingly
395 void checkRetAndSetAbandonedLocked(status_t res);
Yin-Chia Yeh017d49c2017-03-31 19:11:00 -0700396
Yin-Chia Yeha1b56c82019-03-27 15:50:39 -0700397 // If the status indicates abandonded stream, only log when state hasn't been updated to
398 // STATE_ABANDONED
399 static bool shouldLogError(status_t res, StreamState state);
400
Shuzhen Wangabbcb6b2020-12-09 22:32:44 -0800401 // Dump images to disk before returning to consumer
402 void dumpImageToDisk(nsecs_t timestamp, ANativeWindowBuffer* anwBuffer, int fence);
403
Yin-Chia Yeh14ef48d2020-02-10 15:06:37 -0800404 void returnPrefetchedBuffersLocked();
405
Shuzhen Wang00abbeb2022-02-25 17:14:42 -0800406
Shuzhen Wang686f6442017-06-20 16:16:04 -0700407 static const int32_t kDequeueLatencyBinSize = 5; // in ms
408 CameraLatencyHistogram mDequeueBufferLatency;
409
Shuzhen Wangabbcb6b2020-12-09 22:32:44 -0800410 int mImageDumpMask = 0;
411
Shuzhen Wangba92d772022-04-11 11:47:24 -0700412 // Re-space frames by overriding timestamp to align with display Vsync.
413 // Default is on for SurfaceView bound streams.
Shuzhen Wang00abbeb2022-02-25 17:14:42 -0800414 nsecs_t mMinExpectedDuration = 0;
415 bool mSyncToDisplay = false;
416 DisplayEventReceiver mDisplayEventReceiver;
417 nsecs_t mLastCaptureTime = 0;
418 nsecs_t mLastPresentTime = 0;
419 nsecs_t mCaptureToPresentOffset = 0;
420 static constexpr size_t kDisplaySyncExtraBuffer = 2;
421 static constexpr nsecs_t kSpacingResetIntervalNs = 1000000000LL; // 1 second
422 static constexpr nsecs_t kTimelineThresholdNs = 1000000LL; // 1 millisecond
Shuzhen Wangba92d772022-04-11 11:47:24 -0700423 nsecs_t syncTimestampToDisplayLocked(nsecs_t t);
424
425 // Re-space frames by delaying queueBuffer so that frame delivery has
426 // the same cadence as capture. Default is on for SurfaceTexture bound
427 // streams.
428 sp<PreviewFrameSpacer> mPreviewFrameSpacer;
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800429}; // class Camera3OutputStream
430
431} // namespace camera3
432
433} // namespace android
434
435#endif