blob: 7d2d32ebb9729e02f5dc6c943843126b37e7c047 [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>
24
Shuzhen Wang686f6442017-06-20 16:16:04 -070025#include "utils/LatencyHistogram.h"
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080026#include "Camera3Stream.h"
Igor Murashkine3a9f962013-05-08 18:03:15 -070027#include "Camera3IOStreamBase.h"
Igor Murashkin2fba5842013-04-22 14:03:54 -070028#include "Camera3OutputStreamInterface.h"
Zhijun He125684a2015-12-26 15:07:30 -080029#include "Camera3BufferManager.h"
Shuzhen Wange4adddb2021-09-21 15:24:44 -070030#include "PreviewFrameScheduler.h"
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080031
32namespace android {
33
34namespace camera3 {
35
Zhijun He125684a2015-12-26 15:07:30 -080036class Camera3BufferManager;
37
38/**
39 * Stream info structure that holds the necessary stream info for buffer manager to use for
40 * buffer allocation and management.
41 */
42struct StreamInfo {
43 int streamId;
44 int streamSetId;
45 uint32_t width;
46 uint32_t height;
47 uint32_t format;
48 android_dataspace dataSpace;
Emilian Peev050f5dc2017-05-18 14:43:56 +010049 uint64_t combinedUsage;
Zhijun He125684a2015-12-26 15:07:30 -080050 size_t totalBufferCount;
51 bool isConfigured;
Shuzhen Wang83bff122020-11-20 15:51:39 -080052 bool isMultiRes;
Chih-Hung Hsiehd19d9942016-08-29 14:21:14 -070053 explicit StreamInfo(int id = CAMERA3_STREAM_ID_INVALID,
Zhijun He125684a2015-12-26 15:07:30 -080054 int setId = CAMERA3_STREAM_SET_ID_INVALID,
55 uint32_t w = 0,
56 uint32_t h = 0,
57 uint32_t fmt = 0,
58 android_dataspace ds = HAL_DATASPACE_UNKNOWN,
Emilian Peev050f5dc2017-05-18 14:43:56 +010059 uint64_t usage = 0,
Zhijun He125684a2015-12-26 15:07:30 -080060 size_t bufferCount = 0,
Shuzhen Wang83bff122020-11-20 15:51:39 -080061 bool configured = false,
62 bool multiRes = false) :
Zhijun He125684a2015-12-26 15:07:30 -080063 streamId(id),
64 streamSetId(setId),
65 width(w),
66 height(h),
67 format(fmt),
68 dataSpace(ds),
69 combinedUsage(usage),
70 totalBufferCount(bufferCount),
Shuzhen Wang83bff122020-11-20 15:51:39 -080071 isConfigured(configured),
72 isMultiRes(multiRes) {}
Zhijun He125684a2015-12-26 15:07:30 -080073};
74
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080075/**
76 * A class for managing a single stream of output data from the camera device.
77 */
Igor Murashkin2fba5842013-04-22 14:03:54 -070078class Camera3OutputStream :
Igor Murashkine3a9f962013-05-08 18:03:15 -070079 public Camera3IOStreamBase,
Igor Murashkin2fba5842013-04-22 14:03:54 -070080 public Camera3OutputStreamInterface {
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080081 public:
82 /**
83 * Set up a stream for formats that have 2 dimensions, such as RAW and YUV.
Zhijun He125684a2015-12-26 15:07:30 -080084 * A valid stream set id needs to be set to support buffer sharing between multiple
85 * streams.
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080086 */
Eino-Ville Talvala727d1722015-06-09 13:44:19 -070087 Camera3OutputStream(int id, sp<Surface> consumer,
Eino-Ville Talvala3d82c0d2015-02-23 15:19:19 -080088 uint32_t width, uint32_t height, int format,
Emilian Peevf4816702020-04-03 15:44:51 -070089 android_dataspace dataSpace, camera_stream_rotation_t rotation,
Shuzhen Wangc28189a2017-11-27 23:05:10 -080090 nsecs_t timestampOffset, const String8& physicalCameraId,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -080091 const std::unordered_set<int32_t> &sensorPixelModesUsed,
Emilian Peev2295df72021-11-12 18:14:10 -080092 int setId = CAMERA3_STREAM_SET_ID_INVALID, bool isMultiResolution = false,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -080093 int dynamicProfile = ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD,
94 int streamUseCase = ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT);
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080095 /**
96 * Set up a stream for formats that have a variable buffer size for the same
97 * dimensions, such as compressed JPEG.
Zhijun He125684a2015-12-26 15:07:30 -080098 * A valid stream set id needs to be set to support buffer sharing between multiple
99 * streams.
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800100 */
Eino-Ville Talvala727d1722015-06-09 13:44:19 -0700101 Camera3OutputStream(int id, sp<Surface> consumer,
Eino-Ville Talvala3d82c0d2015-02-23 15:19:19 -0800102 uint32_t width, uint32_t height, size_t maxSize, int format,
Emilian Peevf4816702020-04-03 15:44:51 -0700103 android_dataspace dataSpace, camera_stream_rotation_t rotation,
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800104 nsecs_t timestampOffset, const String8& physicalCameraId,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800105 const std::unordered_set<int32_t> &sensorPixelModesUsed,
Emilian Peev2295df72021-11-12 18:14:10 -0800106 int setId = CAMERA3_STREAM_SET_ID_INVALID, bool isMultiResolution = false,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800107 int dynamicProfile = ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD,
108 int streamUseCase = ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT);
Zhijun He5d677d12016-05-29 16:52:39 -0700109 /**
110 * Set up a stream with deferred consumer for formats that have 2 dimensions, such as
111 * RAW and YUV. The consumer must be set before using this stream for output. A valid
112 * stream set id needs to be set to support buffer sharing between multiple streams.
113 */
114 Camera3OutputStream(int id, uint32_t width, uint32_t height, int format,
Emilian Peev050f5dc2017-05-18 14:43:56 +0100115 uint64_t consumerUsage, android_dataspace dataSpace,
Emilian Peevf4816702020-04-03 15:44:51 -0700116 camera_stream_rotation_t rotation, nsecs_t timestampOffset,
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800117 const String8& physicalCameraId,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800118 const std::unordered_set<int32_t> &sensorPixelModesUsed,
Emilian Peev2295df72021-11-12 18:14:10 -0800119 int setId = CAMERA3_STREAM_SET_ID_INVALID, bool isMultiResolution = false,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800120 int dynamicProfile = ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD,
121 int streamUseCase = ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT);
Zhijun He5d677d12016-05-29 16:52:39 -0700122
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800123 virtual ~Camera3OutputStream();
124
125 /**
126 * Camera3Stream interface
127 */
128
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800129 virtual void dump(int fd, const Vector<String16> &args) const;
130
131 /**
132 * Set the transform on the output stream; one of the
133 * HAL_TRANSFORM_* / NATIVE_WINDOW_TRANSFORM_* constants.
134 */
135 status_t setTransform(int transform);
136
Chien-Yu Chen85a64552015-08-28 15:46:12 -0700137 /**
138 * Return if this output stream is for video encoding.
139 */
140 bool isVideoStream() const;
Shuzhen Wang13a69632016-01-26 09:51:07 -0800141 /**
142 * Return if this output stream is consumed by hardware composer.
143 */
144 bool isConsumedByHWComposer() const;
Chien-Yu Chen85a64552015-08-28 15:46:12 -0700145
Zhijun He5d677d12016-05-29 16:52:39 -0700146 /**
Zhijun Hef0645c12016-08-02 00:58:11 -0700147 * Return if this output stream is consumed by hardware texture.
148 */
149 bool isConsumedByHWTexture() const;
150
151 /**
Zhijun He5d677d12016-05-29 16:52:39 -0700152 * Return if the consumer configuration of this stream is deferred.
153 */
Shuzhen Wang0129d522016-10-30 22:43:41 -0700154 virtual bool isConsumerConfigurationDeferred(size_t surface_id) const;
Zhijun He5d677d12016-05-29 16:52:39 -0700155
156 /**
Shuzhen Wang758c2152017-01-10 18:26:18 -0800157 * Set the consumer surfaces to the output stream.
Zhijun He5d677d12016-05-29 16:52:39 -0700158 */
Shuzhen Wang758c2152017-01-10 18:26:18 -0800159 virtual status_t setConsumers(const std::vector<sp<Surface>>& consumers);
Zhijun He5d677d12016-05-29 16:52:39 -0700160
Shuzhen Wang0160ddd2019-08-15 09:11:56 -0700161 class BufferProducerListener : public SurfaceListener {
Zhijun He125684a2015-12-26 15:07:30 -0800162 public:
Shuzhen Wang0160ddd2019-08-15 09:11:56 -0700163 BufferProducerListener(wp<Camera3OutputStream> parent, bool needsReleaseNotify)
164 : mParent(parent), mNeedsReleaseNotify(needsReleaseNotify) {}
Zhijun He125684a2015-12-26 15:07:30 -0800165
Shuzhen Wang0160ddd2019-08-15 09:11:56 -0700166 /**
167 * Implementation of IProducerListener, used to notify this stream that the consumer
168 * has returned a buffer and it is ready to return to Camera3BufferManager for reuse.
169 */
170 virtual void onBufferReleased();
171 virtual bool needsReleaseNotify() { return mNeedsReleaseNotify; }
172 virtual void onBuffersDiscarded(const std::vector<sp<GraphicBuffer>>& buffers);
Zhijun He125684a2015-12-26 15:07:30 -0800173
174 private:
Shuzhen Wang0160ddd2019-08-15 09:11:56 -0700175 wp<Camera3OutputStream> mParent;
176 bool mNeedsReleaseNotify;
Zhijun He125684a2015-12-26 15:07:30 -0800177 };
178
Eino-Ville Talvala77c1a352016-06-13 12:32:43 -0700179 virtual status_t detachBuffer(sp<GraphicBuffer>* buffer, int* fenceFd);
180
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800181 /**
182 * Notify that the buffer is being released to the buffer queue instead of
183 * being queued to the consumer.
184 */
185 virtual status_t notifyBufferReleased(ANativeWindowBuffer *anwBuffer);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700186
Zhijun He125684a2015-12-26 15:07:30 -0800187 /**
Chien-Yu Chena936ac22017-10-23 15:59:49 -0700188 * Drop buffers if dropping is true. If dropping is false, do not drop buffers.
189 */
190 virtual status_t dropBuffers(bool dropping) override;
191
192 /**
Shuzhen Wang5c22c152017-12-31 17:12:25 -0800193 * Query the physical camera id for the output stream.
194 */
195 virtual const String8& getPhysicalCameraId() const override;
196
197 /**
Zhijun He125684a2015-12-26 15:07:30 -0800198 * Set the graphic buffer manager to get/return the stream buffers.
199 *
200 * It is only legal to call this method when stream is in STATE_CONSTRUCTED state.
201 */
202 status_t setBufferManager(sp<Camera3BufferManager> bufferManager);
203
Emilian Peev40ead602017-09-26 15:46:36 +0100204 /**
205 * Query the ouput surface id.
206 */
207 virtual ssize_t getSurfaceId(const sp<Surface> &/*surface*/) { return 0; }
208
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -0700209 virtual status_t getUniqueSurfaceIds(const std::vector<size_t>&,
210 /*out*/std::vector<size_t>*) { return INVALID_OPERATION; };
211
Emilian Peev40ead602017-09-26 15:46:36 +0100212 /**
213 * Update the stream output surfaces.
214 */
215 virtual status_t updateStream(const std::vector<sp<Surface>> &outputSurfaces,
216 const std::vector<OutputStreamInfo> &outputInfo,
217 const std::vector<size_t> &removedSurfaceIds,
218 KeyedVector<sp<Surface>, size_t> *outputMap/*out*/);
219
Emilian Peev35ae8262018-11-08 13:11:32 +0000220 /**
Yin-Chia Yeh14ef48d2020-02-10 15:06:37 -0800221 * Set the batch size for buffer operations. The output stream will request
222 * buffers from buffer queue on a batch basis. Currently only video streams
223 * are allowed to set the batch size. Also if the stream is managed by
224 * buffer manager (Surface group in Java API) then batching is also not
225 * supported. Changing batch size on the fly while there is already batched
226 * buffers in the stream is also not supported.
227 * If the batch size is larger than the max dequeue count set
228 * by the camera HAL, the batch size will be set to the max dequeue count
229 * instead.
230 */
231 virtual status_t setBatchSize(size_t batchSize = 1) override;
232
233 /**
Emilian Peev35ae8262018-11-08 13:11:32 +0000234 * Apply ZSL related consumer usage quirk.
235 */
236 static void applyZSLUsageQuirk(int format, uint64_t *consumerUsage /*inout*/);
237
Shuzhen Wangabbcb6b2020-12-09 22:32:44 -0800238 void setImageDumpMask(int mask) { mImageDumpMask = mask; }
Shuzhen Wange4adddb2021-09-21 15:24:44 -0700239 bool shouldLogError(status_t res);
Shuzhen Wangabbcb6b2020-12-09 22:32:44 -0800240
Igor Murashkine3a9f962013-05-08 18:03:15 -0700241 protected:
Emilian Peevf4816702020-04-03 15:44:51 -0700242 Camera3OutputStream(int id, camera_stream_type_t type,
Eino-Ville Talvala3d82c0d2015-02-23 15:19:19 -0800243 uint32_t width, uint32_t height, int format,
Emilian Peevf4816702020-04-03 15:44:51 -0700244 android_dataspace dataSpace, camera_stream_rotation_t rotation,
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800245 const String8& physicalCameraId,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800246 const std::unordered_set<int32_t> &sensorPixelModesUsed,
Emilian Peev050f5dc2017-05-18 14:43:56 +0100247 uint64_t consumerUsage = 0, nsecs_t timestampOffset = 0,
Emilian Peev2295df72021-11-12 18:14:10 -0800248 int setId = CAMERA3_STREAM_SET_ID_INVALID, bool isMultiResolution = false,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800249 int dynamicProfile = ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD,
250 int streamUseCase = ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT);
Igor Murashkine3a9f962013-05-08 18:03:15 -0700251
Zhijun He124ccf42013-05-22 14:01:30 -0700252 /**
253 * Note that we release the lock briefly in this function
254 */
Igor Murashkine3a9f962013-05-08 18:03:15 -0700255 virtual status_t returnBufferCheckedLocked(
Emilian Peevf4816702020-04-03 15:44:51 -0700256 const camera_stream_buffer &buffer,
Igor Murashkine3a9f962013-05-08 18:03:15 -0700257 nsecs_t timestamp,
Shuzhen Wang90708ea2021-11-04 11:40:49 -0700258 nsecs_t readoutTimestamp,
Igor Murashkine3a9f962013-05-08 18:03:15 -0700259 bool output,
Emilian Peev5104fe92021-10-21 14:27:09 -0700260 int32_t transform,
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -0700261 const std::vector<size_t>& surface_ids,
Igor Murashkine3a9f962013-05-08 18:03:15 -0700262 /*out*/
263 sp<Fence> *releaseFenceOut);
264
Zhijun He0a210512014-07-24 13:45:15 -0700265 virtual status_t disconnectLocked();
266
Emilian Peev050f5dc2017-05-18 14:43:56 +0100267 status_t getEndpointUsageForSurface(uint64_t *usage,
Shuzhen Wang0129d522016-10-30 22:43:41 -0700268 const sp<Surface>& surface) const;
Shuzhen Wange4adddb2021-09-21 15:24:44 -0700269 status_t configureConsumerQueueLocked(bool allowPreviewScheduler);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700270
271 // Consumer as the output of camera HAL
Eino-Ville Talvala727d1722015-06-09 13:44:19 -0700272 sp<Surface> mConsumer;
Zhijun He5d677d12016-05-29 16:52:39 -0700273
Emilian Peev050f5dc2017-05-18 14:43:56 +0100274 uint64_t getPresetConsumerUsage() const { return mConsumerUsage; }
Zhijun Hef0645c12016-08-02 00:58:11 -0700275
276 static const nsecs_t kDequeueBufferTimeout = 1000000000; // 1 sec
277
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800278 status_t getBufferLockedCommon(ANativeWindowBuffer** anb, int* fenceFd);
279
280
Shuzhen Wang0129d522016-10-30 22:43:41 -0700281 private:
282
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800283 int mTransform;
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800284
Igor Murashkine3a9f962013-05-08 18:03:15 -0700285 virtual status_t setTransformLocked(int transform);
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800286
Ruchit Sharmae0711f22014-08-18 13:48:24 -0400287 bool mTraceFirstBuffer;
288
Eino-Ville Talvala727d1722015-06-09 13:44:19 -0700289 // Name of Surface consumer
290 String8 mConsumerName;
291
Shuzhen Wangc28dccc2016-02-11 23:48:46 -0800292 // Whether consumer assumes MONOTONIC timestamp
293 bool mUseMonoTimestamp;
Shuzhen Wang13a69632016-01-26 09:51:07 -0800294
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800295 /**
Zhijun He125684a2015-12-26 15:07:30 -0800296 * GraphicBuffer manager this stream is registered to. Used to replace the buffer
297 * allocation/deallocation role of BufferQueue.
298 */
299 sp<Camera3BufferManager> mBufferManager;
300
301 /**
Shuzhen Wang0160ddd2019-08-15 09:11:56 -0700302 * Buffer producer listener, used to handle notification when a buffer is released
303 * from consumer side, or a set of buffers are discarded by the consumer.
Zhijun He125684a2015-12-26 15:07:30 -0800304 */
Shuzhen Wang0160ddd2019-08-15 09:11:56 -0700305 sp<BufferProducerListener> mBufferProducerListener;
Zhijun He125684a2015-12-26 15:07:30 -0800306
307 /**
308 * Flag indicating if the buffer manager is used to allocate the stream buffers
309 */
310 bool mUseBufferManager;
Shuzhen Wangc28dccc2016-02-11 23:48:46 -0800311
312 /**
313 * Timestamp offset for video and hardware composer consumed streams
314 */
315 nsecs_t mTimestampOffset;
316
Zhijun He125684a2015-12-26 15:07:30 -0800317 /**
Zhijun He5d677d12016-05-29 16:52:39 -0700318 * Consumer end point usage flag set by the constructor for the deferred
319 * consumer case.
320 */
Emilian Peev050f5dc2017-05-18 14:43:56 +0100321 uint64_t mConsumerUsage;
Zhijun He5d677d12016-05-29 16:52:39 -0700322
Chien-Yu Chena936ac22017-10-23 15:59:49 -0700323 // Whether to drop valid buffers.
324 bool mDropBuffers;
325
Yin-Chia Yeh14ef48d2020-02-10 15:06:37 -0800326
Yin-Chia Yeh14ef48d2020-02-10 15:06:37 -0800327
328 // The batch size for buffer operation
Shuzhen Wangc7629462021-07-12 15:02:58 -0700329 std::atomic_size_t mBatchSize = 1;
Yin-Chia Yeh14ef48d2020-02-10 15:06:37 -0800330
Shuzhen Wangc7629462021-07-12 15:02:58 -0700331 // Protecting batch states below, must be acquired after mLock
332 std::mutex mBatchLock;
Yin-Chia Yeh14ef48d2020-02-10 15:06:37 -0800333 // Prefetched buffers (ready to be handed to client)
334 std::vector<Surface::BatchBuffer> mBatchedBuffers;
Yin-Chia Yeh14ef48d2020-02-10 15:06:37 -0800335 // ---- End of mBatchLock protected scope ----
336
Zhijun He5d677d12016-05-29 16:52:39 -0700337 /**
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800338 * Internal Camera3Stream interface
339 */
Emilian Peevf4816702020-04-03 15:44:51 -0700340 virtual status_t getBufferLocked(camera_stream_buffer *buffer,
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800341 const std::vector<size_t>& surface_ids);
342
Yin-Chia Yeh14ef48d2020-02-10 15:06:37 -0800343 virtual status_t getBuffersLocked(/*out*/std::vector<OutstandingBuffer>* buffers) override;
344
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800345 virtual status_t returnBufferLocked(
Emilian Peevf4816702020-04-03 15:44:51 -0700346 const camera_stream_buffer &buffer,
Shuzhen Wang90708ea2021-11-04 11:40:49 -0700347 nsecs_t timestamp, nsecs_t readoutTimestamp,
348 int32_t transform, const std::vector<size_t>& surface_ids);
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800349
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800350 virtual status_t queueBufferToConsumer(sp<ANativeWindow>& consumer,
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -0700351 ANativeWindowBuffer* buffer, int anwReleaseFence,
352 const std::vector<size_t>& surface_ids);
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800353
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800354 virtual status_t configureQueueLocked();
Eino-Ville Talvalab2f5b192013-07-30 14:36:03 -0700355
Emilian Peev050f5dc2017-05-18 14:43:56 +0100356 virtual status_t getEndpointUsage(uint64_t *usage) const;
Eino-Ville Talvalab2f5b192013-07-30 14:36:03 -0700357
Yin-Chia Yeh89954d92017-05-21 17:28:53 -0700358 /**
359 * Private methods
360 */
Yin-Chia Yeh017d49c2017-03-31 19:11:00 -0700361 void onBuffersRemovedLocked(const std::vector<sp<GraphicBuffer>>&);
Yin-Chia Yeh89954d92017-05-21 17:28:53 -0700362 status_t detachBufferLocked(sp<GraphicBuffer>* buffer, int* fenceFd);
Yin-Chia Yehbf1b8b92019-03-06 14:56:08 -0800363 // Call this after each dequeueBuffer/attachBuffer/detachNextBuffer call to get update on
364 // removed buffers. Set notifyBufferManager to false when the call is initiated by buffer
365 // manager so buffer manager doesn't need to be notified.
366 void checkRemovedBuffersLocked(bool notifyBufferManager = true);
367
368 // Check return status of IGBP calls and set abandoned state accordingly
369 void checkRetAndSetAbandonedLocked(status_t res);
Yin-Chia Yeh017d49c2017-03-31 19:11:00 -0700370
Yin-Chia Yeha1b56c82019-03-27 15:50:39 -0700371 // If the status indicates abandonded stream, only log when state hasn't been updated to
372 // STATE_ABANDONED
373 static bool shouldLogError(status_t res, StreamState state);
374
Shuzhen Wangabbcb6b2020-12-09 22:32:44 -0800375 // Dump images to disk before returning to consumer
376 void dumpImageToDisk(nsecs_t timestamp, ANativeWindowBuffer* anwBuffer, int fence);
377
Yin-Chia Yeh14ef48d2020-02-10 15:06:37 -0800378 void returnPrefetchedBuffersLocked();
379
Shuzhen Wang686f6442017-06-20 16:16:04 -0700380 static const int32_t kDequeueLatencyBinSize = 5; // in ms
381 CameraLatencyHistogram mDequeueBufferLatency;
382
Shuzhen Wangabbcb6b2020-12-09 22:32:44 -0800383 int mImageDumpMask = 0;
384
Shuzhen Wange4adddb2021-09-21 15:24:44 -0700385 // The preview stream scheduler for re-timing frames
386 std::unique_ptr<PreviewFrameScheduler> mPreviewFrameScheduler;
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800387}; // class Camera3OutputStream
388
389} // namespace camera3
390
391} // namespace android
392
393#endif