blob: a2f16d4341861d369a043411634a5ea55eacda0e [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
Jayant Chowdharyc67af1b2022-04-07 18:05:04 +000026#include "utils/IPCTransport.h"
Shuzhen Wang686f6442017-06-20 16:16:04 -070027#include "utils/LatencyHistogram.h"
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080028#include "Camera3Stream.h"
Igor Murashkine3a9f962013-05-08 18:03:15 -070029#include "Camera3IOStreamBase.h"
Igor Murashkin2fba5842013-04-22 14:03:54 -070030#include "Camera3OutputStreamInterface.h"
Zhijun He125684a2015-12-26 15:07:30 -080031#include "Camera3BufferManager.h"
Shuzhen Wangba92d772022-04-11 11:47:24 -070032#include "PreviewFrameSpacer.h"
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080033
34namespace android {
35
36namespace camera3 {
37
Zhijun He125684a2015-12-26 15:07:30 -080038class 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 */
44struct StreamInfo {
45 int streamId;
46 int streamSetId;
47 uint32_t width;
48 uint32_t height;
49 uint32_t format;
50 android_dataspace dataSpace;
Emilian Peev050f5dc2017-05-18 14:43:56 +010051 uint64_t combinedUsage;
Zhijun He125684a2015-12-26 15:07:30 -080052 size_t totalBufferCount;
53 bool isConfigured;
Shuzhen Wang83bff122020-11-20 15:51:39 -080054 bool isMultiRes;
Chih-Hung Hsiehd19d9942016-08-29 14:21:14 -070055 explicit StreamInfo(int id = CAMERA3_STREAM_ID_INVALID,
Zhijun He125684a2015-12-26 15:07:30 -080056 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 Peev050f5dc2017-05-18 14:43:56 +010061 uint64_t usage = 0,
Zhijun He125684a2015-12-26 15:07:30 -080062 size_t bufferCount = 0,
Shuzhen Wang83bff122020-11-20 15:51:39 -080063 bool configured = false,
64 bool multiRes = false) :
Zhijun He125684a2015-12-26 15:07:30 -080065 streamId(id),
66 streamSetId(setId),
67 width(w),
68 height(h),
69 format(fmt),
70 dataSpace(ds),
71 combinedUsage(usage),
72 totalBufferCount(bufferCount),
Shuzhen Wang83bff122020-11-20 15:51:39 -080073 isConfigured(configured),
74 isMultiRes(multiRes) {}
Zhijun He125684a2015-12-26 15:07:30 -080075};
76
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080077/**
78 * A class for managing a single stream of output data from the camera device.
79 */
Igor Murashkin2fba5842013-04-22 14:03:54 -070080class Camera3OutputStream :
Igor Murashkine3a9f962013-05-08 18:03:15 -070081 public Camera3IOStreamBase,
Igor Murashkin2fba5842013-04-22 14:03:54 -070082 public Camera3OutputStreamInterface {
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080083 public:
84 /**
85 * Set up a stream for formats that have 2 dimensions, such as RAW and YUV.
Zhijun He125684a2015-12-26 15:07:30 -080086 * A valid stream set id needs to be set to support buffer sharing between multiple
87 * streams.
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080088 */
Eino-Ville Talvala727d1722015-06-09 13:44:19 -070089 Camera3OutputStream(int id, sp<Surface> consumer,
Eino-Ville Talvala3d82c0d2015-02-23 15:19:19 -080090 uint32_t width, uint32_t height, int format,
Emilian Peevf4816702020-04-03 15:44:51 -070091 android_dataspace dataSpace, camera_stream_rotation_t rotation,
Shuzhen Wangc28189a2017-11-27 23:05:10 -080092 nsecs_t timestampOffset, const String8& physicalCameraId,
Jayant Chowdharyc67af1b2022-04-07 18:05:04 +000093 const std::unordered_set<int32_t> &sensorPixelModesUsed, IPCTransport transport,
Emilian Peev2295df72021-11-12 18:14:10 -080094 int setId = CAMERA3_STREAM_SET_ID_INVALID, bool isMultiResolution = false,
Emilian Peevc81a7592022-02-14 17:38:18 -080095 int64_t dynamicProfile = ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD,
Shuzhen Wang8ed1e872022-03-08 16:34:33 -080096 int64_t streamUseCase = ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT,
Shuzhen Wange4208922022-02-01 16:52:48 -080097 bool deviceTimeBaseIsRealtime = false,
Shuzhen Wang610d7b82022-02-08 14:37:22 -080098 int timestampBase = OutputConfiguration::TIMESTAMP_BASE_DEFAULT,
Austin Borger9e2b27c2022-07-15 11:27:24 -070099 int mirrorMode = OutputConfiguration::MIRROR_MODE_AUTO,
Shuzhen Wangbce53db2022-12-03 00:38:20 +0000100 int32_t colorSpace = ANDROID_REQUEST_AVAILABLE_COLOR_SPACE_PROFILES_MAP_UNSPECIFIED,
101 bool useReadoutTimestamp = false);
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800102 /**
103 * Set up a stream for formats that have a variable buffer size for the same
104 * dimensions, such as compressed JPEG.
Zhijun He125684a2015-12-26 15:07:30 -0800105 * A valid stream set id needs to be set to support buffer sharing between multiple
106 * streams.
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800107 */
Eino-Ville Talvala727d1722015-06-09 13:44:19 -0700108 Camera3OutputStream(int id, sp<Surface> consumer,
Eino-Ville Talvala3d82c0d2015-02-23 15:19:19 -0800109 uint32_t width, uint32_t height, size_t maxSize, int format,
Emilian Peevf4816702020-04-03 15:44:51 -0700110 android_dataspace dataSpace, camera_stream_rotation_t rotation,
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800111 nsecs_t timestampOffset, const String8& physicalCameraId,
Jayant Chowdharyc67af1b2022-04-07 18:05:04 +0000112 const std::unordered_set<int32_t> &sensorPixelModesUsed, IPCTransport transport,
Emilian Peev2295df72021-11-12 18:14:10 -0800113 int setId = CAMERA3_STREAM_SET_ID_INVALID, bool isMultiResolution = false,
Emilian Peevc81a7592022-02-14 17:38:18 -0800114 int64_t dynamicProfile = ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD,
Shuzhen Wang8ed1e872022-03-08 16:34:33 -0800115 int64_t streamUseCase = ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT,
Shuzhen Wange4208922022-02-01 16:52:48 -0800116 bool deviceTimeBaseIsRealtime = false,
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800117 int timestampBase = OutputConfiguration::TIMESTAMP_BASE_DEFAULT,
Austin Borger9e2b27c2022-07-15 11:27:24 -0700118 int mirrorMode = OutputConfiguration::MIRROR_MODE_AUTO,
Shuzhen Wangbce53db2022-12-03 00:38:20 +0000119 int32_t colorSpace = ANDROID_REQUEST_AVAILABLE_COLOR_SPACE_PROFILES_MAP_UNSPECIFIED,
120 bool useReadoutTimestamp = false);
Zhijun He5d677d12016-05-29 16:52:39 -0700121 /**
122 * Set up a stream with deferred consumer for formats that have 2 dimensions, such as
123 * RAW and YUV. The consumer must be set before using this stream for output. A valid
124 * stream set id needs to be set to support buffer sharing between multiple streams.
125 */
126 Camera3OutputStream(int id, uint32_t width, uint32_t height, int format,
Emilian Peev050f5dc2017-05-18 14:43:56 +0100127 uint64_t consumerUsage, android_dataspace dataSpace,
Emilian Peevf4816702020-04-03 15:44:51 -0700128 camera_stream_rotation_t rotation, nsecs_t timestampOffset,
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800129 const String8& physicalCameraId,
Jayant Chowdharyc67af1b2022-04-07 18:05:04 +0000130 const std::unordered_set<int32_t> &sensorPixelModesUsed, IPCTransport transport,
Emilian Peev2295df72021-11-12 18:14:10 -0800131 int setId = CAMERA3_STREAM_SET_ID_INVALID, bool isMultiResolution = false,
Emilian Peevc81a7592022-02-14 17:38:18 -0800132 int64_t dynamicProfile = ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD,
Shuzhen Wang8ed1e872022-03-08 16:34:33 -0800133 int64_t streamUseCase = ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT,
Shuzhen Wange4208922022-02-01 16:52:48 -0800134 bool deviceTimeBaseIsRealtime = false,
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800135 int timestampBase = OutputConfiguration::TIMESTAMP_BASE_DEFAULT,
Austin Borger9e2b27c2022-07-15 11:27:24 -0700136 int mirrorMode = OutputConfiguration::MIRROR_MODE_AUTO,
Shuzhen Wangbce53db2022-12-03 00:38:20 +0000137 int32_t colorSpace = ANDROID_REQUEST_AVAILABLE_COLOR_SPACE_PROFILES_MAP_UNSPECIFIED,
138 bool useReadoutTimestamp = false);
Zhijun He5d677d12016-05-29 16:52:39 -0700139
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800140 virtual ~Camera3OutputStream();
141
142 /**
143 * Camera3Stream interface
144 */
145
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800146 virtual void dump(int fd, const Vector<String16> &args) const;
147
148 /**
149 * Set the transform on the output stream; one of the
150 * HAL_TRANSFORM_* / NATIVE_WINDOW_TRANSFORM_* constants.
151 */
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800152 status_t setTransform(int transform, bool mayChangeMirror);
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800153
Chien-Yu Chen85a64552015-08-28 15:46:12 -0700154 /**
155 * Return if this output stream is for video encoding.
156 */
157 bool isVideoStream() const;
Shuzhen Wang13a69632016-01-26 09:51:07 -0800158 /**
159 * Return if this output stream is consumed by hardware composer.
160 */
161 bool isConsumedByHWComposer() const;
Chien-Yu Chen85a64552015-08-28 15:46:12 -0700162
Zhijun He5d677d12016-05-29 16:52:39 -0700163 /**
Zhijun Hef0645c12016-08-02 00:58:11 -0700164 * Return if this output stream is consumed by hardware texture.
165 */
166 bool isConsumedByHWTexture() const;
167
168 /**
Shuzhen Wangfe8a2a32022-05-10 18:18:54 -0700169 * Return if this output stream is consumed by CPU.
170 */
171 bool isConsumedByCPU() const;
172
173 /**
Zhijun He5d677d12016-05-29 16:52:39 -0700174 * Return if the consumer configuration of this stream is deferred.
175 */
Shuzhen Wang0129d522016-10-30 22:43:41 -0700176 virtual bool isConsumerConfigurationDeferred(size_t surface_id) const;
Zhijun He5d677d12016-05-29 16:52:39 -0700177
178 /**
Shuzhen Wang758c2152017-01-10 18:26:18 -0800179 * Set the consumer surfaces to the output stream.
Zhijun He5d677d12016-05-29 16:52:39 -0700180 */
Shuzhen Wang758c2152017-01-10 18:26:18 -0800181 virtual status_t setConsumers(const std::vector<sp<Surface>>& consumers);
Zhijun He5d677d12016-05-29 16:52:39 -0700182
Shuzhen Wang0160ddd2019-08-15 09:11:56 -0700183 class BufferProducerListener : public SurfaceListener {
Zhijun He125684a2015-12-26 15:07:30 -0800184 public:
Shuzhen Wang0160ddd2019-08-15 09:11:56 -0700185 BufferProducerListener(wp<Camera3OutputStream> parent, bool needsReleaseNotify)
186 : mParent(parent), mNeedsReleaseNotify(needsReleaseNotify) {}
Zhijun He125684a2015-12-26 15:07:30 -0800187
Shuzhen Wang0160ddd2019-08-15 09:11:56 -0700188 /**
189 * Implementation of IProducerListener, used to notify this stream that the consumer
190 * has returned a buffer and it is ready to return to Camera3BufferManager for reuse.
191 */
192 virtual void onBufferReleased();
193 virtual bool needsReleaseNotify() { return mNeedsReleaseNotify; }
194 virtual void onBuffersDiscarded(const std::vector<sp<GraphicBuffer>>& buffers);
Zhijun He125684a2015-12-26 15:07:30 -0800195
196 private:
Shuzhen Wang0160ddd2019-08-15 09:11:56 -0700197 wp<Camera3OutputStream> mParent;
198 bool mNeedsReleaseNotify;
Zhijun He125684a2015-12-26 15:07:30 -0800199 };
200
Eino-Ville Talvala77c1a352016-06-13 12:32:43 -0700201 virtual status_t detachBuffer(sp<GraphicBuffer>* buffer, int* fenceFd);
202
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800203 /**
204 * Notify that the buffer is being released to the buffer queue instead of
205 * being queued to the consumer.
206 */
207 virtual status_t notifyBufferReleased(ANativeWindowBuffer *anwBuffer);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700208
Zhijun He125684a2015-12-26 15:07:30 -0800209 /**
Chien-Yu Chena936ac22017-10-23 15:59:49 -0700210 * Drop buffers if dropping is true. If dropping is false, do not drop buffers.
211 */
212 virtual status_t dropBuffers(bool dropping) override;
213
214 /**
Shuzhen Wang5c22c152017-12-31 17:12:25 -0800215 * Query the physical camera id for the output stream.
216 */
217 virtual const String8& getPhysicalCameraId() const override;
218
219 /**
Zhijun He125684a2015-12-26 15:07:30 -0800220 * Set the graphic buffer manager to get/return the stream buffers.
221 *
222 * It is only legal to call this method when stream is in STATE_CONSTRUCTED state.
223 */
224 status_t setBufferManager(sp<Camera3BufferManager> bufferManager);
225
Emilian Peev40ead602017-09-26 15:46:36 +0100226 /**
227 * Query the ouput surface id.
228 */
229 virtual ssize_t getSurfaceId(const sp<Surface> &/*surface*/) { return 0; }
230
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -0700231 virtual status_t getUniqueSurfaceIds(const std::vector<size_t>&,
232 /*out*/std::vector<size_t>*) { return INVALID_OPERATION; };
233
Emilian Peev40ead602017-09-26 15:46:36 +0100234 /**
235 * Update the stream output surfaces.
236 */
237 virtual status_t updateStream(const std::vector<sp<Surface>> &outputSurfaces,
238 const std::vector<OutputStreamInfo> &outputInfo,
239 const std::vector<size_t> &removedSurfaceIds,
240 KeyedVector<sp<Surface>, size_t> *outputMap/*out*/);
241
Emilian Peev35ae8262018-11-08 13:11:32 +0000242 /**
Yin-Chia Yeh14ef48d2020-02-10 15:06:37 -0800243 * Set the batch size for buffer operations. The output stream will request
244 * buffers from buffer queue on a batch basis. Currently only video streams
245 * are allowed to set the batch size. Also if the stream is managed by
246 * buffer manager (Surface group in Java API) then batching is also not
247 * supported. Changing batch size on the fly while there is already batched
248 * buffers in the stream is also not supported.
249 * If the batch size is larger than the max dequeue count set
250 * by the camera HAL, the batch size will be set to the max dequeue count
251 * instead.
252 */
253 virtual status_t setBatchSize(size_t batchSize = 1) override;
254
255 /**
Shuzhen Wang696e4da2022-09-08 14:31:13 -0700256 * Notify the stream on change of min frame durations or variable/fixed
257 * frame rate.
Shuzhen Wang00abbeb2022-02-25 17:14:42 -0800258 */
Shuzhen Wang696e4da2022-09-08 14:31:13 -0700259 virtual void onMinDurationChanged(nsecs_t duration, bool fixedFps) override;
Shuzhen Wang00abbeb2022-02-25 17:14:42 -0800260
261 /**
Emilian Peev35ae8262018-11-08 13:11:32 +0000262 * Apply ZSL related consumer usage quirk.
263 */
264 static void applyZSLUsageQuirk(int format, uint64_t *consumerUsage /*inout*/);
265
Shuzhen Wangabbcb6b2020-12-09 22:32:44 -0800266 void setImageDumpMask(int mask) { mImageDumpMask = mask; }
Shuzhen Wangba92d772022-04-11 11:47:24 -0700267 bool shouldLogError(status_t res);
Shuzhen Wangc2352702022-09-06 18:36:31 -0700268 void onCachedBufferQueued();
Shuzhen Wangabbcb6b2020-12-09 22:32:44 -0800269
Igor Murashkine3a9f962013-05-08 18:03:15 -0700270 protected:
Emilian Peevf4816702020-04-03 15:44:51 -0700271 Camera3OutputStream(int id, camera_stream_type_t type,
Eino-Ville Talvala3d82c0d2015-02-23 15:19:19 -0800272 uint32_t width, uint32_t height, int format,
Emilian Peevf4816702020-04-03 15:44:51 -0700273 android_dataspace dataSpace, camera_stream_rotation_t rotation,
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800274 const String8& physicalCameraId,
Jayant Chowdharyc67af1b2022-04-07 18:05:04 +0000275 const std::unordered_set<int32_t> &sensorPixelModesUsed, IPCTransport transport,
Emilian Peev050f5dc2017-05-18 14:43:56 +0100276 uint64_t consumerUsage = 0, nsecs_t timestampOffset = 0,
Emilian Peev2295df72021-11-12 18:14:10 -0800277 int setId = CAMERA3_STREAM_SET_ID_INVALID, bool isMultiResolution = false,
Emilian Peevc81a7592022-02-14 17:38:18 -0800278 int64_t dynamicProfile = ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD,
Shuzhen Wang8ed1e872022-03-08 16:34:33 -0800279 int64_t streamUseCase = ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT,
Shuzhen Wange4208922022-02-01 16:52:48 -0800280 bool deviceTimeBaseIsRealtime = false,
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800281 int timestampBase = OutputConfiguration::TIMESTAMP_BASE_DEFAULT,
Austin Borger9e2b27c2022-07-15 11:27:24 -0700282 int mirrorMode = OutputConfiguration::MIRROR_MODE_AUTO,
Shuzhen Wangbce53db2022-12-03 00:38:20 +0000283 int32_t colorSpace = ANDROID_REQUEST_AVAILABLE_COLOR_SPACE_PROFILES_MAP_UNSPECIFIED,
284 bool useReadoutTimestamp = false);
Igor Murashkine3a9f962013-05-08 18:03:15 -0700285
Zhijun He124ccf42013-05-22 14:01:30 -0700286 /**
287 * Note that we release the lock briefly in this function
288 */
Igor Murashkine3a9f962013-05-08 18:03:15 -0700289 virtual status_t returnBufferCheckedLocked(
Emilian Peevf4816702020-04-03 15:44:51 -0700290 const camera_stream_buffer &buffer,
Igor Murashkine3a9f962013-05-08 18:03:15 -0700291 nsecs_t timestamp,
Shuzhen Wang90708ea2021-11-04 11:40:49 -0700292 nsecs_t readoutTimestamp,
Igor Murashkine3a9f962013-05-08 18:03:15 -0700293 bool output,
Emilian Peev5104fe92021-10-21 14:27:09 -0700294 int32_t transform,
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -0700295 const std::vector<size_t>& surface_ids,
Igor Murashkine3a9f962013-05-08 18:03:15 -0700296 /*out*/
297 sp<Fence> *releaseFenceOut);
298
Zhijun He0a210512014-07-24 13:45:15 -0700299 virtual status_t disconnectLocked();
Jayant Chowdharyc67af1b2022-04-07 18:05:04 +0000300 status_t fixUpHidlJpegBlobHeader(ANativeWindowBuffer* anwBuffer, int fence);
Zhijun He0a210512014-07-24 13:45:15 -0700301
Emilian Peev050f5dc2017-05-18 14:43:56 +0100302 status_t getEndpointUsageForSurface(uint64_t *usage,
Shuzhen Wang0129d522016-10-30 22:43:41 -0700303 const sp<Surface>& surface) const;
Shuzhen Wangba92d772022-04-11 11:47:24 -0700304 status_t configureConsumerQueueLocked(bool allowPreviewRespace);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700305
306 // Consumer as the output of camera HAL
Eino-Ville Talvala727d1722015-06-09 13:44:19 -0700307 sp<Surface> mConsumer;
Zhijun He5d677d12016-05-29 16:52:39 -0700308
Emilian Peev050f5dc2017-05-18 14:43:56 +0100309 uint64_t getPresetConsumerUsage() const { return mConsumerUsage; }
Zhijun Hef0645c12016-08-02 00:58:11 -0700310
311 static const nsecs_t kDequeueBufferTimeout = 1000000000; // 1 sec
312
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800313 status_t getBufferLockedCommon(ANativeWindowBuffer** anb, int* fenceFd);
314
315
Shuzhen Wang0129d522016-10-30 22:43:41 -0700316 private:
317
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800318 int mTransform;
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800319
Igor Murashkine3a9f962013-05-08 18:03:15 -0700320 virtual status_t setTransformLocked(int transform);
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800321
Ruchit Sharmae0711f22014-08-18 13:48:24 -0400322 bool mTraceFirstBuffer;
323
Eino-Ville Talvala727d1722015-06-09 13:44:19 -0700324 // Name of Surface consumer
325 String8 mConsumerName;
326
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800327 /**
Zhijun He125684a2015-12-26 15:07:30 -0800328 * GraphicBuffer manager this stream is registered to. Used to replace the buffer
329 * allocation/deallocation role of BufferQueue.
330 */
331 sp<Camera3BufferManager> mBufferManager;
332
333 /**
Shuzhen Wang0160ddd2019-08-15 09:11:56 -0700334 * Buffer producer listener, used to handle notification when a buffer is released
335 * from consumer side, or a set of buffers are discarded by the consumer.
Zhijun He125684a2015-12-26 15:07:30 -0800336 */
Shuzhen Wang0160ddd2019-08-15 09:11:56 -0700337 sp<BufferProducerListener> mBufferProducerListener;
Zhijun He125684a2015-12-26 15:07:30 -0800338
339 /**
340 * Flag indicating if the buffer manager is used to allocate the stream buffers
341 */
342 bool mUseBufferManager;
Shuzhen Wangc28dccc2016-02-11 23:48:46 -0800343
344 /**
Shuzhen Wange4208922022-02-01 16:52:48 -0800345 * Offset used to override camera HAL produced timestamps
346 *
347 * The offset is first initialized to bootTime - monotonicTime in
348 * constructor, and may later be updated based on the client's timestampBase
349 * setting.
Shuzhen Wangc28dccc2016-02-11 23:48:46 -0800350 */
351 nsecs_t mTimestampOffset;
352
Zhijun He125684a2015-12-26 15:07:30 -0800353 /**
Shuzhen Wangffc4c012022-04-20 15:55:46 -0700354 * If camera readout time is used rather than the start-of-exposure time.
355 */
356 bool mUseReadoutTime;
357
358 /**
Zhijun He5d677d12016-05-29 16:52:39 -0700359 * Consumer end point usage flag set by the constructor for the deferred
360 * consumer case.
361 */
Emilian Peev050f5dc2017-05-18 14:43:56 +0100362 uint64_t mConsumerUsage;
Zhijun He5d677d12016-05-29 16:52:39 -0700363
Chien-Yu Chena936ac22017-10-23 15:59:49 -0700364 // Whether to drop valid buffers.
365 bool mDropBuffers;
366
Yin-Chia Yeh14ef48d2020-02-10 15:06:37 -0800367
Yin-Chia Yeh14ef48d2020-02-10 15:06:37 -0800368
369 // The batch size for buffer operation
Shuzhen Wangc7629462021-07-12 15:02:58 -0700370 std::atomic_size_t mBatchSize = 1;
Yin-Chia Yeh14ef48d2020-02-10 15:06:37 -0800371
Shuzhen Wangc7629462021-07-12 15:02:58 -0700372 // Protecting batch states below, must be acquired after mLock
373 std::mutex mBatchLock;
Yin-Chia Yeh14ef48d2020-02-10 15:06:37 -0800374 // Prefetched buffers (ready to be handed to client)
375 std::vector<Surface::BatchBuffer> mBatchedBuffers;
Yin-Chia Yeh14ef48d2020-02-10 15:06:37 -0800376 // ---- End of mBatchLock protected scope ----
377
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800378 const int mMirrorMode;
379
Zhijun He5d677d12016-05-29 16:52:39 -0700380 /**
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800381 * Internal Camera3Stream interface
382 */
Emilian Peevf4816702020-04-03 15:44:51 -0700383 virtual status_t getBufferLocked(camera_stream_buffer *buffer,
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800384 const std::vector<size_t>& surface_ids);
385
Yin-Chia Yeh14ef48d2020-02-10 15:06:37 -0800386 virtual status_t getBuffersLocked(/*out*/std::vector<OutstandingBuffer>* buffers) override;
387
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800388 virtual status_t returnBufferLocked(
Emilian Peevf4816702020-04-03 15:44:51 -0700389 const camera_stream_buffer &buffer,
Shuzhen Wang90708ea2021-11-04 11:40:49 -0700390 nsecs_t timestamp, nsecs_t readoutTimestamp,
391 int32_t transform, const std::vector<size_t>& surface_ids);
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800392
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800393 virtual status_t queueBufferToConsumer(sp<ANativeWindow>& consumer,
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -0700394 ANativeWindowBuffer* buffer, int anwReleaseFence,
395 const std::vector<size_t>& surface_ids);
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800396
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800397 virtual status_t configureQueueLocked();
Eino-Ville Talvalab2f5b192013-07-30 14:36:03 -0700398
Emilian Peev050f5dc2017-05-18 14:43:56 +0100399 virtual status_t getEndpointUsage(uint64_t *usage) const;
Eino-Ville Talvalab2f5b192013-07-30 14:36:03 -0700400
Yin-Chia Yeh89954d92017-05-21 17:28:53 -0700401 /**
402 * Private methods
403 */
Yin-Chia Yeh017d49c2017-03-31 19:11:00 -0700404 void onBuffersRemovedLocked(const std::vector<sp<GraphicBuffer>>&);
Yin-Chia Yeh89954d92017-05-21 17:28:53 -0700405 status_t detachBufferLocked(sp<GraphicBuffer>* buffer, int* fenceFd);
Yin-Chia Yehbf1b8b92019-03-06 14:56:08 -0800406 // Call this after each dequeueBuffer/attachBuffer/detachNextBuffer call to get update on
407 // removed buffers. Set notifyBufferManager to false when the call is initiated by buffer
408 // manager so buffer manager doesn't need to be notified.
409 void checkRemovedBuffersLocked(bool notifyBufferManager = true);
410
411 // Check return status of IGBP calls and set abandoned state accordingly
412 void checkRetAndSetAbandonedLocked(status_t res);
Yin-Chia Yeh017d49c2017-03-31 19:11:00 -0700413
Yin-Chia Yeha1b56c82019-03-27 15:50:39 -0700414 // If the status indicates abandonded stream, only log when state hasn't been updated to
415 // STATE_ABANDONED
416 static bool shouldLogError(status_t res, StreamState state);
417
Shuzhen Wangabbcb6b2020-12-09 22:32:44 -0800418 // Dump images to disk before returning to consumer
419 void dumpImageToDisk(nsecs_t timestamp, ANativeWindowBuffer* anwBuffer, int fence);
420
Yin-Chia Yeh14ef48d2020-02-10 15:06:37 -0800421 void returnPrefetchedBuffersLocked();
422
Shuzhen Wang00abbeb2022-02-25 17:14:42 -0800423
Shuzhen Wang686f6442017-06-20 16:16:04 -0700424 static const int32_t kDequeueLatencyBinSize = 5; // in ms
425 CameraLatencyHistogram mDequeueBufferLatency;
Jayant Chowdharyc67af1b2022-04-07 18:05:04 +0000426 IPCTransport mIPCTransport = IPCTransport::INVALID;
Shuzhen Wang686f6442017-06-20 16:16:04 -0700427
Shuzhen Wangabbcb6b2020-12-09 22:32:44 -0800428 int mImageDumpMask = 0;
429
Shuzhen Wangba92d772022-04-11 11:47:24 -0700430 // Re-space frames by overriding timestamp to align with display Vsync.
431 // Default is on for SurfaceView bound streams.
Shuzhen Wang696e4da2022-09-08 14:31:13 -0700432 bool mFixedFps = false;
Shuzhen Wang00abbeb2022-02-25 17:14:42 -0800433 nsecs_t mMinExpectedDuration = 0;
434 bool mSyncToDisplay = false;
435 DisplayEventReceiver mDisplayEventReceiver;
436 nsecs_t mLastCaptureTime = 0;
437 nsecs_t mLastPresentTime = 0;
438 nsecs_t mCaptureToPresentOffset = 0;
439 static constexpr size_t kDisplaySyncExtraBuffer = 2;
Shuzhen Wanged08fbe2022-06-21 01:00:50 -0700440 static constexpr nsecs_t kSpacingResetIntervalNs = 50000000LL; // 50 millisecond
Shuzhen Wang00abbeb2022-02-25 17:14:42 -0800441 static constexpr nsecs_t kTimelineThresholdNs = 1000000LL; // 1 millisecond
Shuzhen Wang34a5e282022-06-17 14:48:35 -0700442 static constexpr float kMaxIntervalRatioDeviation = 0.05f;
Shuzhen Wang35bd3552022-09-21 16:56:04 -0700443 static constexpr int kMaxTimelines = 2;
Shuzhen Wangba92d772022-04-11 11:47:24 -0700444 nsecs_t syncTimestampToDisplayLocked(nsecs_t t);
445
446 // Re-space frames by delaying queueBuffer so that frame delivery has
447 // the same cadence as capture. Default is on for SurfaceTexture bound
448 // streams.
449 sp<PreviewFrameSpacer> mPreviewFrameSpacer;
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800450}; // class Camera3OutputStream
451
452} // namespace camera3
453
454} // namespace android
455
456#endif