blob: 748d0631e9bcd2e1945dfa925bc92a64dda46f57 [file] [log] [blame]
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -08001/*
Shuzhen Wangc28189a2017-11-27 23:05:10 -08002 * Copyright (C) 2013-2018 The Android Open Source Project
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -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
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -080017#ifndef ANDROID_SERVERS_CAMERA3DEVICE_H
18#define ANDROID_SERVERS_CAMERA3DEVICE_H
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080019
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -080020#include <utility>
21#include <unordered_map>
Shuzhen Wang5c22c152017-12-31 17:12:25 -080022#include <set>
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -080023
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080024#include <utils/Condition.h>
25#include <utils/Errors.h>
26#include <utils/List.h>
27#include <utils/Mutex.h>
28#include <utils/Thread.h>
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070029#include <utils/KeyedVector.h>
Shuzhen Wangc28dccc2016-02-11 23:48:46 -080030#include <utils/Timers.h>
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -080031
Jianing Weicb0652e2014-03-12 18:29:36 -070032#include <camera/CaptureResult.h>
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080033
Emilian Peev2295df72021-11-12 18:14:10 -080034#include "android/hardware/camera/metadata/3.8/types.h"
Ravneet98ffa752022-03-02 07:22:46 +000035#include "CameraServiceWatchdog.h"
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070036#include "common/CameraDeviceBase.h"
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -080037#include "device3/BufferUtils.h"
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -070038#include "device3/StatusTracker.h"
Zhijun He125684a2015-12-26 15:07:30 -080039#include "device3/Camera3BufferManager.h"
Eino-Ville Talvala7b8a1fd2018-05-22 15:30:35 -070040#include "device3/DistortionMapper.h"
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -080041#include "device3/ZoomRatioMapper.h"
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -080042#include "device3/RotateAndCropMapper.h"
Jayant Chowdhary9255ce02021-07-15 11:18:17 -070043#include "device3/UHRCropAndMeteringRegionMapper.h"
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -080044#include "device3/InFlightRequest.h"
45#include "device3/Camera3OutputInterface.h"
46#include "device3/Camera3OfflineSession.h"
Shuzhen Wang83bff122020-11-20 15:51:39 -080047#include "device3/Camera3StreamInterface.h"
Eino-Ville Talvala4d453832016-07-15 11:56:53 -070048#include "utils/TagMonitor.h"
Jayant Chowdhary22441f32021-12-26 18:35:41 -080049#include "utils/IPCTransport.h"
Shuzhen Wang686f6442017-06-20 16:16:04 -070050#include "utils/LatencyHistogram.h"
Emilian Peev71c73a22017-03-21 16:35:51 +000051#include <camera_metadata_hidden.h>
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080052
Emilian Peevf4816702020-04-03 15:44:51 -070053using android::camera3::camera_capture_request_t;
54using android::camera3::camera_jpeg_blob_t;
55using android::camera3::camera_request_template;
56using android::camera3::camera_stream_buffer_t;
57using android::camera3::camera_stream_configuration_t;
58using android::camera3::camera_stream_configuration_mode_t;
59using android::camera3::CAMERA_TEMPLATE_COUNT;
Emilian Peev40ead602017-09-26 15:46:36 +010060using android::camera3::OutputStreamInfo;
61
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080062namespace android {
63
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070064namespace camera3 {
65
66class Camera3Stream;
67class Camera3ZslStream;
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070068class Camera3StreamInterface;
69
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -080070} // namespace camera3
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070071
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080072/**
Zhijun He95dd5ba2014-03-26 18:18:00 -070073 * CameraDevice for HAL devices with version CAMERA_DEVICE_API_VERSION_3_0 or higher.
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080074 */
75class Camera3Device :
76 public CameraDeviceBase,
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -080077 public camera3::SetErrorInterface,
78 public camera3::InflightRequestUpdateInterface,
79 public camera3::RequestBufferInterface,
80 public camera3::FlushBufferInterface {
Jayant Chowdhary22441f32021-12-26 18:35:41 -080081 friend class HidlCamera3Device;
Jayant Chowdhary35642f22022-01-08 00:39:39 +000082 friend class AidlCamera3Device;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080083 public:
Ruben Brunkc78ac262015-08-13 17:58:46 -070084
Emilian Peev5104fe92021-10-21 14:27:09 -070085 explicit Camera3Device(const String8& id, bool overrideForPerfClass, bool legacyClient = false);
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080086
87 virtual ~Camera3Device();
Jayant Chowdhary35642f22022-01-08 00:39:39 +000088 // Delete and optionally close native handles and clear the input vector afterward
89 static void cleanupNativeHandles(
90 std::vector<native_handle_t*> *handles, bool closeFd = false);
91
92 IPCTransport getTransportType() { return mInterface->getTransportType(); }
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080093
94 /**
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -080095 * CameraDeviceBase interface
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080096 */
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -080097
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -080098 const String8& getId() const override;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -080099
Emilian Peev00420d22018-02-05 21:33:13 +0000100 metadata_vendor_id_t getVendorTagId() const override { return mVendorTagId; }
101
Ravneet98ffa752022-03-02 07:22:46 +0000102 // Watchdog thread
103 sp<CameraServiceWatchdog> mCameraServiceWatchdog;
104
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800105 // Transitions to idle state on success.
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800106 virtual status_t initialize(sp<CameraProviderManager> /*manager*/,
107 const String8& /*monitorTags*/) = 0;
108
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800109 status_t disconnect() override;
110 status_t dump(int fd, const Vector<String16> &args) override;
Avichal Rakesh7e53cad2021-10-05 13:46:30 -0700111 status_t startWatchingTags(const String8 &tags) override;
112 status_t stopWatchingTags() override;
113 status_t dumpWatchedEventsToVector(std::vector<std::string> &out) override;
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800114 const CameraMetadata& info() const override;
Emilian Peevfaa4bde2020-01-23 12:19:37 -0800115 const CameraMetadata& infoPhysical(const String8& physicalId) const override;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800116
117 // Capture and setStreamingRequest will configure streams if currently in
118 // idle state
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800119 status_t capture(CameraMetadata &request, int64_t *lastFrameNumber = NULL) override;
Emilian Peevaebbe412018-01-15 13:53:24 +0000120 status_t captureList(const List<const PhysicalCameraSettingsList> &requestsList,
Shuzhen Wang0129d522016-10-30 22:43:41 -0700121 const std::list<const SurfaceMap> &surfaceMaps,
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800122 int64_t *lastFrameNumber = NULL) override;
123 status_t setStreamingRequest(const CameraMetadata &request,
124 int64_t *lastFrameNumber = NULL) override;
Emilian Peevaebbe412018-01-15 13:53:24 +0000125 status_t setStreamingRequestList(const List<const PhysicalCameraSettingsList> &requestsList,
Shuzhen Wang0129d522016-10-30 22:43:41 -0700126 const std::list<const SurfaceMap> &surfaceMaps,
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800127 int64_t *lastFrameNumber = NULL) override;
128 status_t clearStreamingRequest(int64_t *lastFrameNumber = NULL) override;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800129
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800130 status_t waitUntilRequestReceived(int32_t requestId, nsecs_t timeout) override;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800131
132 // Actual stream creation/deletion is delayed until first request is submitted
133 // If adding streams while actively capturing, will pause device before adding
Zhijun He5d677d12016-05-29 16:52:39 -0700134 // stream, reconfiguring device, and unpausing. If the client create a stream
Shuzhen Wang758c2152017-01-10 18:26:18 -0800135 // with nullptr consumer surface, the client must then call setConsumers()
Zhijun He5d677d12016-05-29 16:52:39 -0700136 // and finish the stream configuration before starting output streaming.
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800137 status_t createStream(sp<Surface> consumer,
Eino-Ville Talvala3d82c0d2015-02-23 15:19:19 -0800138 uint32_t width, uint32_t height, int format,
Emilian Peevf4816702020-04-03 15:44:51 -0700139 android_dataspace dataSpace, camera_stream_rotation_t rotation, int *id,
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800140 const String8& physicalCameraId,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800141 const std::unordered_set<int32_t> &sensorPixelModesUsed,
Emilian Peev40ead602017-09-26 15:46:36 +0100142 std::vector<int> *surfaceIds = nullptr,
Zhijun He5d677d12016-05-29 16:52:39 -0700143 int streamSetId = camera3::CAMERA3_STREAM_SET_ID_INVALID,
Shuzhen Wang83bff122020-11-20 15:51:39 -0800144 bool isShared = false, bool isMultiResolution = false,
Emilian Peev2295df72021-11-12 18:14:10 -0800145 uint64_t consumerUsage = 0,
Emilian Peevc81a7592022-02-14 17:38:18 -0800146 int64_t dynamicRangeProfile =
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800147 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD,
Shuzhen Wang8ed1e872022-03-08 16:34:33 -0800148 int64_t streamUseCase = ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT,
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800149 int timestampBase = OutputConfiguration::TIMESTAMP_BASE_DEFAULT,
150 int mirrorMode = OutputConfiguration::MIRROR_MODE_AUTO) override;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800151
Shuzhen Wang0129d522016-10-30 22:43:41 -0700152 status_t createStream(const std::vector<sp<Surface>>& consumers,
153 bool hasDeferredConsumer, uint32_t width, uint32_t height, int format,
Emilian Peevf4816702020-04-03 15:44:51 -0700154 android_dataspace dataSpace, camera_stream_rotation_t rotation, int *id,
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800155 const String8& physicalCameraId,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800156 const std::unordered_set<int32_t> &sensorPixelModesUsed,
Emilian Peev40ead602017-09-26 15:46:36 +0100157 std::vector<int> *surfaceIds = nullptr,
Shuzhen Wang0129d522016-10-30 22:43:41 -0700158 int streamSetId = camera3::CAMERA3_STREAM_SET_ID_INVALID,
Shuzhen Wang83bff122020-11-20 15:51:39 -0800159 bool isShared = false, bool isMultiResolution = false,
Emilian Peev2295df72021-11-12 18:14:10 -0800160 uint64_t consumerUsage = 0,
Emilian Peevc81a7592022-02-14 17:38:18 -0800161 int64_t dynamicRangeProfile =
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800162 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD,
Shuzhen Wang8ed1e872022-03-08 16:34:33 -0800163 int64_t streamUseCase = ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT,
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800164 int timestampBase = OutputConfiguration::TIMESTAMP_BASE_DEFAULT,
165 int mirrorMode = OutputConfiguration::MIRROR_MODE_AUTO) override;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700166
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800167 status_t createInputStream(
Shuzhen Wang83bff122020-11-20 15:51:39 -0800168 uint32_t width, uint32_t height, int format, bool isMultiResolution,
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800169 int *id) override;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800170
Emilian Peev710c1422017-08-30 11:19:38 +0100171 status_t getStreamInfo(int id, StreamInfo *streamInfo) override;
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800172 status_t setStreamTransform(int id, int transform) override;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800173
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800174 status_t deleteStream(int id) override;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800175
Emilian Peev5fbe0ba2017-10-20 15:45:45 +0100176 status_t configureStreams(const CameraMetadata& sessionParams,
177 int operatingMode =
Emilian Peevf4816702020-04-03 15:44:51 -0700178 camera_stream_configuration_mode_t::CAMERA_STREAM_CONFIGURATION_NORMAL_MODE) override;
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800179 status_t getInputBufferProducer(
180 sp<IGraphicBufferProducer> *producer) override;
Igor Murashkine2d167e2014-08-19 16:19:59 -0700181
Emilian Peevcc0b7952020-01-07 13:54:47 -0800182 void getOfflineStreamIds(std::vector<int> *offlineStreamIds) override;
183
Emilian Peevf4816702020-04-03 15:44:51 -0700184 status_t createDefaultRequest(camera_request_template_t templateId,
185 CameraMetadata *request) override;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800186
187 // Transitions to the idle state on success
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800188 status_t waitUntilDrained() override;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800189
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800190 status_t setNotifyCallback(wp<NotificationListener> listener) override;
191 bool willNotify3A() override;
192 status_t waitForNextFrame(nsecs_t timeout) override;
193 status_t getNextResult(CaptureResult *frame) override;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800194
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800195 status_t triggerAutofocus(uint32_t id) override;
196 status_t triggerCancelAutofocus(uint32_t id) override;
197 status_t triggerPrecaptureMetering(uint32_t id) override;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800198
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800199 status_t flush(int64_t *lastFrameNumber = NULL) override;
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -0700200
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800201 status_t prepare(int streamId) override;
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700202
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800203 status_t tearDown(int streamId) override;
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -0700204
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800205 status_t addBufferListenerForStream(int streamId,
206 wp<camera3::Camera3StreamBufferListener> listener) override;
Shuzhen Wangb0fdc1e2016-03-20 23:21:39 -0700207
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800208 status_t prepare(int maxCount, int streamId) override;
Ruben Brunkc78ac262015-08-13 17:58:46 -0700209
Jayant Chowdhary6a6d3a82021-11-17 16:54:34 -0800210 ssize_t getJpegBufferSize(const CameraMetadata &info, uint32_t width,
211 uint32_t height) const override;
212 ssize_t getPointCloudBufferSize(const CameraMetadata &info) const;
213 ssize_t getRawOpaqueBufferSize(const CameraMetadata &info, int32_t width, int32_t height,
214 bool maxResolution) const;
Zhijun He28c9b6f2014-08-08 12:00:47 -0700215
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700216 // Methods called by subclasses
217 void notifyStatus(bool idle); // updates from StatusTracker
218
Zhijun He5d677d12016-05-29 16:52:39 -0700219 /**
Shuzhen Wang758c2152017-01-10 18:26:18 -0800220 * Set the deferred consumer surfaces to the output stream and finish the deferred
Zhijun He5d677d12016-05-29 16:52:39 -0700221 * consumer configuration.
222 */
Emilian Peev40ead602017-09-26 15:46:36 +0100223 status_t setConsumerSurfaces(
224 int streamId, const std::vector<sp<Surface>>& consumers,
225 std::vector<int> *surfaceIds /*out*/) override;
226
227 /**
228 * Update a given stream.
229 */
230 status_t updateStream(int streamId, const std::vector<sp<Surface>> &newSurfaces,
231 const std::vector<OutputStreamInfo> &outputInfo,
232 const std::vector<size_t> &removedSurfaceIds,
233 KeyedVector<sp<Surface>, size_t> *outputMap/*out*/);
Zhijun He5d677d12016-05-29 16:52:39 -0700234
Chien-Yu Chena936ac22017-10-23 15:59:49 -0700235 /**
236 * Drop buffers for stream of streamId if dropping is true. If dropping is false, do not
237 * drop buffers for stream of streamId.
238 */
239 status_t dropStreamBuffers(bool dropping, int streamId) override;
240
Emilian Peev2a8e2832019-08-23 13:00:31 -0700241 nsecs_t getExpectedInFlightDuration() override;
242
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800243 virtual status_t switchToOffline(const std::vector<int32_t>& ,
244 /*out*/ sp<CameraOfflineSessionBase>* ) override {
245 return INVALID_OPERATION;
246 };
Yin-Chia Yehb978c382019-10-30 00:22:37 -0700247
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800248 // RequestBufferInterface
249 bool startRequestBuffer() override;
250 void endRequestBuffer() override;
251 nsecs_t getWaitDuration() override;
252
253 // FlushBufferInterface
254 void getInflightBufferKeys(std::vector<std::pair<int32_t, int32_t>>* out) override;
255 void getInflightRequestBufferKeys(std::vector<uint64_t>* out) override;
256 std::vector<sp<camera3::Camera3StreamInterface>> getAllStreams() override;
257
Emilian Peev35ae8262018-11-08 13:11:32 +0000258 /**
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800259 * Set the current behavior for the ROTATE_AND_CROP control when in AUTO.
260 *
261 * The value must be one of the ROTATE_AND_CROP_* values besides AUTO,
262 * and defaults to NONE.
263 */
264 status_t setRotateAndCropAutoBehavior(
265 camera_metadata_enum_android_scaler_rotate_and_crop_t rotateAndCropValue);
266
Eino-Ville Talvala305cec62020-11-12 14:18:17 -0800267 /**
268 * Whether camera muting (producing black-only output) is supported.
269 *
270 * Calling setCameraMute(true) when this returns false will return an
271 * INVALID_OPERATION error.
272 */
273 bool supportsCameraMute();
274
275 /**
276 * Mute the camera.
277 *
278 * When muted, black image data is output on all output streams.
279 */
280 status_t setCameraMute(bool enabled);
281
Shuzhen Wange8675782019-12-05 09:12:14 -0800282 // Get the status trackeer for the camera device
283 wp<camera3::StatusTracker> getStatusTracker() { return mStatusTracker; }
284
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800285 /**
Cliff Wuc2ad9c82021-04-21 00:58:58 +0800286 * The injection camera session to replace the internal camera
287 * session.
288 */
289 status_t injectCamera(const String8& injectedCamId,
290 sp<CameraProviderManager> manager);
291
292 /**
293 * Stop the injection camera and restore to internal camera session.
294 */
295 status_t stopInjection();
296
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800297 protected:
Yin-Chia Yehc5248132018-08-15 12:19:20 -0700298 status_t disconnectImpl();
Jayant Chowdhary65c9bf02021-09-03 16:44:16 +0000299 static status_t removeFwkOnlyRegionKeys(CameraMetadata *request);
Yin-Chia Yehc5248132018-08-15 12:19:20 -0700300
Austin Borger4a870a32022-02-25 01:48:41 +0000301 float getMaxPreviewFps(sp<camera3::Camera3OutputStreamInterface> stream);
302
Igor Murashkin1e479c02013-09-06 16:55:14 -0700303 static const size_t kDumpLockAttempts = 10;
304 static const size_t kDumpSleepDuration = 100000; // 0.10 sec
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700305 static const nsecs_t kActiveTimeout = 500000000; // 500 ms
Yin-Chia Yeh99fd0972019-06-27 14:22:44 -0700306 static const nsecs_t kMinWarnInflightDuration = 5000000000; // 5 s
Yin-Chia Yeh90c0fdf2017-06-29 13:22:12 -0700307 static const size_t kInFlightWarnLimit = 30;
Chien-Yu Chenc96ac8d2015-08-12 16:46:24 -0700308 static const size_t kInFlightWarnLimitHighSpeed = 256; // batch size 32 * pipe depth 8
Eino-Ville Talvala10bd57e2017-06-23 16:22:44 -0700309 static const nsecs_t kMinInflightDuration = 5000000000; // 5 s
Yin-Chia Yehb3a80b12018-09-04 12:13:05 -0700310 static const nsecs_t kBaseGetBufferWait = 3000000000; // 3 sec.
Eino-Ville Talvalaf99498e2015-09-25 16:52:55 -0700311 // SCHED_FIFO priority for request submission thread in HFR mode
Zhijun He7ee4c072016-07-25 13:52:28 -0700312 static const int kRequestThreadPriority = 1;
Chien-Yu Chenc96ac8d2015-08-12 16:46:24 -0700313
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700314 struct RequestTrigger;
Zhijun Hef7da0962014-04-24 13:27:56 -0700315 // minimal jpeg buffer size: 256KB + blob header
Emilian Peevf4816702020-04-03 15:44:51 -0700316 static const ssize_t kMinJpegBufferSize = 256 * 1024 + sizeof(camera_jpeg_blob_t);
Eino-Ville Talvala16a2ada2014-08-27 14:41:33 -0700317 // Constant to use for stream ID when one doesn't exist
318 static const int NO_STREAM = -1;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800319
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700320 // A lock to enforce serialization on the input/configure side
321 // of the public interface.
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700322 // Not locked by methods guarded by mOutputLock, since they may act
323 // concurrently to the input/configure side of the interface.
324 // Must be locked before mLock if both will be locked by a method
325 Mutex mInterfaceLock;
326
327 // The main lock on internal state
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800328 Mutex mLock;
329
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700330 // Camera device ID
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800331 const String8 mId;
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700332
Emilian Peev5104fe92021-10-21 14:27:09 -0700333 // Legacy camera client flag
334 bool mLegacyClient;
335
Eino-Ville Talvalabbbbe842017-02-28 17:50:56 -0800336 // Current stream configuration mode;
337 int mOperatingMode;
Emilian Peev5fbe0ba2017-10-20 15:45:45 +0100338 // Current session wide parameters
339 hardware::camera2::impl::CameraMetadataNative mSessionParams;
340
Eino-Ville Talvalabbbbe842017-02-28 17:50:56 -0800341 // Constant to use for no set operating mode
342 static const int NO_MODE = -1;
343
Zhijun He1fa89992015-06-01 15:44:31 -0700344 // Flag indicating is the current active stream configuration is constrained high speed.
345 bool mIsConstrainedHighSpeedConfiguration;
346
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800347 /**** Scope for mLock ****/
348
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800349 class HalInterface : public camera3::Camera3StreamBufferFreedListener,
350 public camera3::BufferRecordsInterface {
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800351 public:
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800352 HalInterface(bool useHalBufManager, bool supportOfflineProcessing) :
353 mUseHalBufManager(useHalBufManager),
354 mIsReconfigurationQuerySupported(true),
355 mSupportOfflineProcessing(supportOfflineProcessing)
356 {};
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800357 HalInterface(const HalInterface &other);
358 HalInterface();
359
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800360 virtual IPCTransport getTransportType() = 0;
361
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800362 // Returns true if constructed with a valid device or session, and not yet cleared
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800363 virtual bool valid() = 0;
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800364
365 // Reset this HalInterface object (does not call close())
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800366 virtual void clear() = 0;
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800367
368 // Calls into the HAL interface
369
370 // Caller takes ownership of requestTemplate
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800371 virtual status_t constructDefaultRequestSettings(camera_request_template templateId,
372 /*out*/ camera_metadata_t **requestTemplate) = 0;
373
374 virtual status_t configureStreams(const camera_metadata_t * sessionParams,
375 /*inout*/ camera_stream_configuration_t * config,
376 const std::vector<uint32_t>& bufferSizes) = 0;
Yin-Chia Yeh11648852019-05-16 10:42:54 -0700377
Cliff Wuc2ad9c82021-04-21 00:58:58 +0800378 // The injection camera configures the streams to hal.
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800379 virtual status_t configureInjectedStreams(
Cliff Wuc2ad9c82021-04-21 00:58:58 +0800380 const camera_metadata_t* sessionParams,
381 /*inout*/ camera_stream_configuration_t* config,
382 const std::vector<uint32_t>& bufferSizes,
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800383 const CameraMetadata& cameraCharacteristics) = 0;
Cliff Wuc2ad9c82021-04-21 00:58:58 +0800384
Yin-Chia Yeh11648852019-05-16 10:42:54 -0700385 // When the call succeeds, the ownership of acquire fences in requests is transferred to
386 // HalInterface. More specifically, the current implementation will send the fence to
387 // HAL process and close the FD in cameraserver process. When the call fails, the ownership
388 // of the acquire fence still belongs to the caller.
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800389 virtual status_t processBatchCaptureRequests(
Emilian Peevf4816702020-04-03 15:44:51 -0700390 std::vector<camera_capture_request_t*>& requests,
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800391 /*out*/uint32_t* numRequestProcessed) = 0;
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800392
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800393 virtual status_t flush() = 0;
Yin-Chia Yeh7447f0f2018-10-11 15:28:12 -0700394
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800395 virtual status_t dump(int fd) = 0;
Yin-Chia Yehb978c382019-10-30 00:22:37 -0700396
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800397 virtual status_t close() = 0;
398
399 virtual void signalPipelineDrain(const std::vector<int>& streamIds) = 0;
400
401 virtual bool isReconfigurationRequired(CameraMetadata& oldSessionParams,
402 CameraMetadata& newSessionParams) = 0;
403
404 virtual status_t repeatingRequestEnd(uint32_t frameNumber,
405 const std::vector<int32_t> &streamIds) = 0;
Emilian Peev2295df72021-11-12 18:14:10 -0800406
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800407 /////////////////////////////////////////////////////////////////////
408 // Implements BufferRecordsInterface
Yin-Chia Yehd5cd5ff2018-10-01 14:43:04 -0700409
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800410 std::pair<bool, uint64_t> getBufferId(
411 const buffer_handle_t& buf, int streamId) override;
412
Shuzhen Wangcd5b1822021-09-07 11:52:48 -0700413 uint64_t removeOneBufferCache(int streamId, const native_handle_t* handle) override;
414
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800415 status_t popInflightBuffer(int32_t frameNumber, int32_t streamId,
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800416 /*out*/ buffer_handle_t **buffer) override;
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800417
Yin-Chia Yeh84be5782019-03-01 11:47:02 -0800418 status_t pushInflightRequestBuffer(
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800419 uint64_t bufferId, buffer_handle_t* buf, int32_t streamId) override;
Yin-Chia Yehd5cd5ff2018-10-01 14:43:04 -0700420
Yin-Chia Yeh84be5782019-03-01 11:47:02 -0800421 status_t popInflightRequestBuffer(uint64_t bufferId,
422 /*out*/ buffer_handle_t** buffer,
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800423 /*optional out*/ int32_t* streamId = nullptr) override;
424
425 /////////////////////////////////////////////////////////////////////
Yin-Chia Yehd5cd5ff2018-10-01 14:43:04 -0700426
Yin-Chia Yehf3fe36f2017-07-07 18:23:18 -0700427 // Get a vector of (frameNumber, streamId) pair of currently inflight
428 // buffers
429 void getInflightBufferKeys(std::vector<std::pair<int32_t, int32_t>>* out);
430
Yin-Chia Yeh84be5782019-03-01 11:47:02 -0800431 // Get a vector of bufferId of currently inflight buffers
432 void getInflightRequestBufferKeys(std::vector<uint64_t>* out);
433
Yin-Chia Yeh573a2702019-04-17 10:08:55 -0700434 void onStreamReConfigured(int streamId);
435
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800436 protected:
Yin-Chia Yehf8e28fb2019-05-16 11:46:54 -0700437
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800438 // Return true if the input caches match what we have; otherwise false
439 bool verifyBufferIds(int32_t streamId, std::vector<uint64_t>& inBufIds);
Yin-Chia Yehf8e28fb2019-05-16 11:46:54 -0700440
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800441 template <typename OfflineSessionInfoT>
442 status_t verifyBufferCaches(
443 const OfflineSessionInfoT *offlineSessionInfo, camera3::BufferRecords *bufferRecords) {
444 // Validate buffer caches
445 std::vector<int32_t> streams;
446 streams.reserve(offlineSessionInfo->offlineStreams.size());
447 for (auto offlineStream : offlineSessionInfo->offlineStreams) {
448 int32_t id = offlineStream.id;
449 streams.push_back(id);
450 // Verify buffer caches
451 std::vector<uint64_t> bufIds(offlineStream.circulatingBufferIds.begin(),
452 offlineStream.circulatingBufferIds.end());
453 if (!verifyBufferIds(id, bufIds)) {
454 ALOGE("%s: stream ID %d buffer cache records mismatch!", __FUNCTION__, id);
455 return UNKNOWN_ERROR;
456 }
457 }
458
459 // Move buffer records
460 bufferRecords->takeBufferCaches(mBufferRecords, streams);
461 bufferRecords->takeInflightBufferMap(mBufferRecords);
462 bufferRecords->takeRequestedBufferMap(mBufferRecords);
463 return OK;
464 }
465
Yin-Chia Yehbe83fa72017-03-30 13:35:36 -0700466 virtual void onBufferFreed(int streamId, const native_handle_t* handle) override;
467
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800468 std::mutex mFreedBuffersLock;
Yin-Chia Yehbe83fa72017-03-30 13:35:36 -0700469 std::vector<std::pair<int, uint64_t>> mFreedBuffers;
Yin-Chia Yehd5cd5ff2018-10-01 14:43:04 -0700470
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800471 // Keep track of buffer cache and inflight buffer records
472 camera3::BufferRecords mBufferRecords;
Yin-Chia Yeh7447f0f2018-10-11 15:28:12 -0700473
474 uint32_t mNextStreamConfigCounter = 1;
Yin-Chia Yeh651fe2e2018-11-13 11:49:31 -0800475
476 const bool mUseHalBufManager;
Emilian Peev4ec17882019-01-24 17:16:58 -0800477 bool mIsReconfigurationQuerySupported;
Yin-Chia Yehb978c382019-10-30 00:22:37 -0700478
479 const bool mSupportOfflineProcessing;
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800480 }; // class HalInterface
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800481
Yin-Chia Yehdb1e8642017-07-14 15:19:30 -0700482 sp<HalInterface> mInterface;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800483
484 CameraMetadata mDeviceInfo;
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -0800485 bool mSupportNativeZoomRatio;
Shuzhen Wang2e7f58f2018-07-11 14:00:29 -0700486 std::unordered_map<std::string, CameraMetadata> mPhysicalDeviceInfoMap;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800487
Emilian Peevf4816702020-04-03 15:44:51 -0700488 CameraMetadata mRequestTemplateCache[CAMERA_TEMPLATE_COUNT];
Zhijun Hea1530f12014-09-14 12:44:20 -0700489
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700490 struct Size {
491 uint32_t width;
492 uint32_t height;
Chih-Hung Hsieh8b0b9712016-08-09 14:25:53 -0700493 explicit Size(uint32_t w = 0, uint32_t h = 0) : width(w), height(h){}
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700494 };
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700495
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700496 enum Status {
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800497 STATUS_ERROR,
498 STATUS_UNINITIALIZED,
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700499 STATUS_UNCONFIGURED,
500 STATUS_CONFIGURED,
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800501 STATUS_ACTIVE
502 } mStatus;
Ruben Brunk183f0562015-08-12 12:55:02 -0700503
504 // Only clear mRecentStatusUpdates, mStatusWaiters from waitUntilStateThenRelock
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700505 Vector<Status> mRecentStatusUpdates;
Ruben Brunk183f0562015-08-12 12:55:02 -0700506 int mStatusWaiters;
507
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700508 Condition mStatusChanged;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800509
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700510 // Tracking cause of fatal errors when in STATUS_ERROR
511 String8 mErrorCause;
512
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800513 camera3::StreamSet mOutputStreams;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800514 sp<camera3::Camera3Stream> mInputStream;
Shuzhen Wang83bff122020-11-20 15:51:39 -0800515 bool mIsInputStreamMultiResolution;
Shuzhen Wang316781a2020-08-18 18:11:01 -0700516 SessionStatsBuilder mSessionStatsBuilder;
Shuzhen Wang99080502021-03-07 21:08:20 -0800517 // Map from stream group ID to physical cameras backing the stream group
518 std::map<int32_t, std::set<String8>> mGroupIdPhysicalCameraMap;
Shuzhen Wang316781a2020-08-18 18:11:01 -0700519
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800520 int mNextStreamId;
Eino-Ville Talvalaea26c772013-06-11 16:04:06 -0700521 bool mNeedConfig;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800522
Ivan Lozanoc0ad82f2020-07-30 09:32:57 -0400523 int mFakeStreamId;
Eino-Ville Talvala16a2ada2014-08-27 14:41:33 -0700524
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700525 // Whether to send state updates upstream
526 // Pause when doing transparent reconfiguration
527 bool mPauseStateNotify;
528
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800529 // Need to hold on to stream references until configure completes.
Igor Murashkin2fba5842013-04-22 14:03:54 -0700530 Vector<sp<camera3::Camera3StreamInterface> > mDeletedStreams;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800531
Zhijun He204e3292014-07-14 17:09:23 -0700532 // Whether the HAL will send partial result
533 bool mUsePartialResult;
534
535 // Number of partial results that will be delivered by the HAL.
536 uint32_t mNumPartialResults;
Eino-Ville Talvalafd6ecdd2013-10-11 09:51:09 -0700537
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800538 /**** End scope for mLock ****/
539
Shuzhen Wange4208922022-02-01 16:52:48 -0800540 bool mDeviceTimeBaseIsRealtime;
Shuzhen Wangc28dccc2016-02-11 23:48:46 -0800541 // The offset converting from clock domain of other subsystem
542 // (video/hardware composer) to that of camera. Assumption is that this
543 // offset won't change during the life cycle of the camera device. In other
544 // words, camera device shouldn't be open during CPU suspend.
545 nsecs_t mTimestampOffset;
546
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800547 class CaptureRequest : public LightRefBase<CaptureRequest> {
548 public:
Emilian Peevaebbe412018-01-15 13:53:24 +0000549 PhysicalCameraSettingsList mSettingsList;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800550 sp<camera3::Camera3Stream> mInputStream;
Emilian Peevf4816702020-04-03 15:44:51 -0700551 camera_stream_buffer_t mInputBuffer;
Shuzhen Wang83bff122020-11-20 15:51:39 -0800552 camera3::Size mInputBufferSize;
Igor Murashkin2fba5842013-04-22 14:03:54 -0700553 Vector<sp<camera3::Camera3OutputStreamInterface> >
554 mOutputStreams;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700555 SurfaceMap mOutputSurfaces;
Jianing Weicb0652e2014-03-12 18:29:36 -0700556 CaptureResultExtras mResultExtras;
Chien-Yu Chen85a64552015-08-28 15:46:12 -0700557 // The number of requests that should be submitted to HAL at a time.
558 // For example, if batch size is 8, this request and the following 7
559 // requests will be submitted to HAL at a time. The batch size for
560 // the following 7 requests will be ignored by the request thread.
561 int mBatchSize;
Shuzhen Wang9d066012016-09-30 11:30:20 -0700562 // Whether this request is from a repeating or repeating burst.
563 bool mRepeating;
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800564 // Whether this request has ROTATE_AND_CROP_AUTO set, so needs both
565 // overriding of ROTATE_AND_CROP value and adjustment of coordinates
566 // in several other controls in both the request and the result
567 bool mRotateAndCropAuto;
Eino-Ville Talvala305cec62020-11-12 14:18:17 -0800568
Shuzhen Wangd1d051a2020-08-20 15:42:23 -0700569 // Whether this capture request has its zoom ratio set to 1.0x before
570 // the framework overrides it for camera HAL consumption.
571 bool mZoomRatioIs1x;
Shuzhen Wang316781a2020-08-18 18:11:01 -0700572 // The systemTime timestamp when the request is created.
573 nsecs_t mRequestTimeNs;
Shuzhen Wangd1d051a2020-08-20 15:42:23 -0700574
Shuzhen Wangd1d051a2020-08-20 15:42:23 -0700575 // Whether this capture request's distortion correction update has
576 // been done.
577 bool mDistortionCorrectionUpdated = false;
578 // Whether this capture request's rotation and crop update has been
579 // done.
580 bool mRotationAndCropUpdated = false;
581 // Whether this capture request's zoom ratio update has been done.
582 bool mZoomRatioUpdated = false;
Jayant Chowdhary9255ce02021-07-15 11:18:17 -0700583 // Whether this max resolution capture request's crop / metering region update has been
584 // done.
585 bool mUHRCropAndMeteringRegionsUpdated = false;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800586 };
587 typedef List<sp<CaptureRequest> > RequestList;
588
Jianing Wei90e59c92014-03-12 18:29:36 -0700589 status_t checkStatusOkToCaptureLocked();
590
591 status_t convertMetadataListToRequestListLocked(
Emilian Peevaebbe412018-01-15 13:53:24 +0000592 const List<const PhysicalCameraSettingsList> &metadataList,
Shuzhen Wang0129d522016-10-30 22:43:41 -0700593 const std::list<const SurfaceMap> &surfaceMaps,
Shuzhen Wang316781a2020-08-18 18:11:01 -0700594 bool repeating, nsecs_t requestTimeNs,
Jianing Wei2d6bb3f2014-04-11 10:00:31 -0700595 /*out*/
596 RequestList *requestList);
Jianing Wei90e59c92014-03-12 18:29:36 -0700597
Emilian Peevaebbe412018-01-15 13:53:24 +0000598 void convertToRequestList(List<const PhysicalCameraSettingsList>& requestsList,
Shuzhen Wang0129d522016-10-30 22:43:41 -0700599 std::list<const SurfaceMap>& surfaceMaps,
600 const CameraMetadata& request);
601
Emilian Peevaebbe412018-01-15 13:53:24 +0000602 status_t submitRequestsHelper(const List<const PhysicalCameraSettingsList> &requestsList,
Shuzhen Wang0129d522016-10-30 22:43:41 -0700603 const std::list<const SurfaceMap> &surfaceMaps,
604 bool repeating,
Jianing Weicb0652e2014-03-12 18:29:36 -0700605 int64_t *lastFrameNumber = NULL);
Jianing Wei90e59c92014-03-12 18:29:36 -0700606
Yifan Honga640c5a2017-04-12 16:30:31 -0700607 // lock to ensure only one processCaptureResult is called at a time.
608 Mutex mProcessCaptureResultLock;
609
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800610 /**
611 * Common initialization code shared by both HAL paths
612 *
613 * Must be called with mLock and mInterfaceLock held.
614 */
615 status_t initializeCommonLocked();
616
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800617 /**
Igor Murashkin1e479c02013-09-06 16:55:14 -0700618 * Get the last request submitted to the hal by the request thread.
619 *
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800620 * Must be called with mLock held.
Igor Murashkin1e479c02013-09-06 16:55:14 -0700621 */
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700622 virtual CameraMetadata getLatestRequestLocked();
Igor Murashkin1e479c02013-09-06 16:55:14 -0700623
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800624 virtual status_t injectionCameraInitialize(const String8 &injectCamId,
625 sp<CameraProviderManager> manager) = 0;
626
Igor Murashkin1e479c02013-09-06 16:55:14 -0700627 /**
Ruben Brunk183f0562015-08-12 12:55:02 -0700628 * Update the current device status and wake all waiting threads.
629 *
630 * Must be called with mLock held.
631 */
632 void internalUpdateStatusLocked(Status status);
633
634 /**
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700635 * Pause processing and flush everything, but don't tell the clients.
636 * This is for reconfiguring outputs transparently when according to the
637 * CameraDeviceBase interface we shouldn't need to.
638 * Must be called with mLock and mInterfaceLock both held.
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800639 */
Yin-Chia Yeh598fc602017-07-24 11:37:23 -0700640 status_t internalPauseAndWaitLocked(nsecs_t maxExpectedDuration);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700641
642 /**
643 * Resume work after internalPauseAndWaitLocked()
644 * Must be called with mLock and mInterfaceLock both held.
645 */
646 status_t internalResumeLocked();
647
648 /**
649 * Wait until status tracker tells us we've transitioned to the target state
650 * set, which is either ACTIVE when active==true or IDLE (which is any
651 * non-ACTIVE state) when active==false.
652 *
653 * Needs to be called with mLock and mInterfaceLock held. This means there
654 * can ever only be one waiter at most.
655 *
656 * During the wait mLock is released.
657 *
658 */
659 status_t waitUntilStateThenRelock(bool active, nsecs_t timeout);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800660
661 /**
Zhijun He69a37482014-03-23 18:44:49 -0700662 * Implementation of waitUntilDrained. On success, will transition to IDLE state.
663 *
664 * Need to be called with mLock and mInterfaceLock held.
665 */
Yin-Chia Yeh598fc602017-07-24 11:37:23 -0700666 status_t waitUntilDrainedLocked(nsecs_t maxExpectedDuration);
Zhijun He69a37482014-03-23 18:44:49 -0700667
668 /**
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800669 * Do common work for setting up a streaming or single capture request.
670 * On success, will transition to ACTIVE if in IDLE.
671 */
Emilian Peevaebbe412018-01-15 13:53:24 +0000672 sp<CaptureRequest> setUpRequestLocked(const PhysicalCameraSettingsList &request,
Shuzhen Wang0129d522016-10-30 22:43:41 -0700673 const SurfaceMap &surfaceMap);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800674
675 /**
676 * Build a CaptureRequest request from the CameraDeviceBase request
677 * settings.
678 */
Emilian Peevaebbe412018-01-15 13:53:24 +0000679 sp<CaptureRequest> createCaptureRequest(const PhysicalCameraSettingsList &request,
Shuzhen Wang0129d522016-10-30 22:43:41 -0700680 const SurfaceMap &surfaceMap);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800681
682 /**
Emilian Peevac3ce6c2017-12-12 15:27:02 +0000683 * Internally re-configure camera device using new session parameters.
Emilian Peev3bead5f2020-05-28 17:29:08 -0700684 * This will get triggered by the request thread.
Emilian Peevac3ce6c2017-12-12 15:27:02 +0000685 */
Emilian Peev3bead5f2020-05-28 17:29:08 -0700686 bool reconfigureCamera(const CameraMetadata& sessionParams, int clientStatusId);
Emilian Peevac3ce6c2017-12-12 15:27:02 +0000687
688 /**
Emilian Peev0d0191e2020-04-21 17:01:18 -0700689 * Return true in case of any output or input abandoned streams,
690 * otherwise return false.
691 */
692 bool checkAbandonedStreamsLocked();
693
694 /**
Emilian Peevac3ce6c2017-12-12 15:27:02 +0000695 * Filter stream session parameters and configure camera HAL.
696 */
697 status_t filterParamsAndConfigureLocked(const CameraMetadata& sessionParams,
698 int operatingMode);
699
700 /**
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800701 * Take the currently-defined set of streams and configure the HAL to use
702 * them. This is a long-running operation (may be several hundered ms).
703 */
Emilian Peev5fbe0ba2017-10-20 15:45:45 +0100704 status_t configureStreamsLocked(int operatingMode,
Emilian Peevac3ce6c2017-12-12 15:27:02 +0000705 const CameraMetadata& sessionParams, bool notifyRequestThread = true);
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800706
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700707 /**
Chien-Yu Chen9b5860b2016-06-10 13:39:09 -0700708 * Cancel stream configuration that did not finish successfully.
709 */
710 void cancelStreamsConfigurationLocked();
711
712 /**
Ivan Lozanoc0ad82f2020-07-30 09:32:57 -0400713 * Add a fake stream to the current stream set as a workaround for
Eino-Ville Talvala16a2ada2014-08-27 14:41:33 -0700714 * not allowing 0 streams in the camera HAL spec.
715 */
Ivan Lozanoc0ad82f2020-07-30 09:32:57 -0400716 status_t addFakeStreamLocked();
Eino-Ville Talvala16a2ada2014-08-27 14:41:33 -0700717
718 /**
Ivan Lozanoc0ad82f2020-07-30 09:32:57 -0400719 * Remove a fake stream if the current config includes real streams.
Eino-Ville Talvala16a2ada2014-08-27 14:41:33 -0700720 */
Ivan Lozanoc0ad82f2020-07-30 09:32:57 -0400721 status_t tryRemoveFakeStreamLocked();
Eino-Ville Talvala16a2ada2014-08-27 14:41:33 -0700722
723 /**
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700724 * Set device into an error state due to some fatal failure, and set an
725 * error message to indicate why. Only the first call's message will be
726 * used. The message is also sent to the log.
727 */
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800728 void setErrorState(const char *fmt, ...) override;
729 void setErrorStateLocked(const char *fmt, ...) override;
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700730 void setErrorStateV(const char *fmt, va_list args);
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700731 void setErrorStateLockedV(const char *fmt, va_list args);
732
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800733 /////////////////////////////////////////////////////////////////////
734 // Implements InflightRequestUpdateInterface
735
736 void onInflightEntryRemovedLocked(nsecs_t duration) override;
737 void checkInflightMapLengthLocked() override;
738 void onInflightMapFlushedLocked() override;
739
740 /////////////////////////////////////////////////////////////////////
741
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700742 /**
743 * Debugging trylock/spin method
744 * Try to acquire a lock a few times with sleeps between before giving up.
745 */
746 bool tryLockSpinRightRound(Mutex& lock);
747
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700748 /**
Shuzhen Wangc28dccc2016-02-11 23:48:46 -0800749 * Helper function to get the offset between MONOTONIC and BOOTTIME
750 * timestamp.
751 */
752 static nsecs_t getMonoToBoottimeOffset();
753
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700754 struct RequestTrigger {
755 // Metadata tag number, e.g. android.control.aePrecaptureTrigger
756 uint32_t metadataTag;
757 // Metadata value, e.g. 'START' or the trigger ID
758 int32_t entryValue;
759
760 // The last part of the fully qualified path, e.g. afTrigger
761 const char *getTagName() const {
762 return get_camera_metadata_tag_name(metadataTag) ?: "NULL";
763 }
764
765 // e.g. TYPE_BYTE, TYPE_INT32, etc.
766 int getTagType() const {
767 return get_camera_metadata_tag_type(metadataTag);
768 }
769 };
770
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800771 /**
772 * Thread for managing capture request submission to HAL device.
773 */
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800774 class RequestThread : public Thread {
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800775
776 public:
777
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800778 RequestThread(wp<Camera3Device> parent,
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700779 sp<camera3::StatusTracker> statusTracker,
Yin-Chia Yehd5cd5ff2018-10-01 14:43:04 -0700780 sp<HalInterface> interface,
781 const Vector<int32_t>& sessionParamKeys,
Eino-Ville Talvala1646c3c2021-07-29 13:48:40 -0700782 bool useHalBufManager,
783 bool supportCameraMute);
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800784 ~RequestThread();
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800785
Yin-Chia Yehe1c80632016-08-08 14:48:05 -0700786 void setNotificationListener(wp<NotificationListener> listener);
Eino-Ville Talvala17543512014-08-06 14:32:02 -0700787
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800788 /**
789 * Call after stream (re)-configuration is completed.
790 */
Emilian Peevac3ce6c2017-12-12 15:27:02 +0000791 void configurationComplete(bool isConstrainedHighSpeed,
Shuzhen Wang99080502021-03-07 21:08:20 -0800792 const CameraMetadata& sessionParams,
793 const std::map<int32_t, std::set<String8>>& groupIdPhysicalCameraMap);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800794
795 /**
796 * Set or clear the list of repeating requests. Does not block
797 * on either. Use waitUntilPaused to wait until request queue
798 * has emptied out.
799 */
Jianing Wei2d6bb3f2014-04-11 10:00:31 -0700800 status_t setRepeatingRequests(const RequestList& requests,
801 /*out*/
802 int64_t *lastFrameNumber = NULL);
803 status_t clearRepeatingRequests(/*out*/
804 int64_t *lastFrameNumber = NULL);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800805
Jianing Wei2d6bb3f2014-04-11 10:00:31 -0700806 status_t queueRequestList(List<sp<CaptureRequest> > &requests,
807 /*out*/
808 int64_t *lastFrameNumber = NULL);
Jianing Wei90e59c92014-03-12 18:29:36 -0700809
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800810 /**
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -0700811 * Remove all queued and repeating requests, and pending triggers
812 */
Yin-Chia Yehe1c80632016-08-08 14:48:05 -0700813 status_t clear(/*out*/int64_t *lastFrameNumber = NULL);
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -0700814
815 /**
Chien-Yu Chen85a64552015-08-28 15:46:12 -0700816 * Flush all pending requests in HAL.
817 */
818 status_t flush();
819
820 /**
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700821 * Queue a trigger to be dispatched with the next outgoing
822 * process_capture_request. The settings for that request only
823 * will be temporarily rewritten to add the trigger tag/value.
824 * Subsequent requests will not be rewritten (for this tag).
825 */
826 status_t queueTrigger(RequestTrigger trigger[], size_t count);
827
828 /**
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800829 * Pause/unpause the capture thread. Doesn't block, so use
830 * waitUntilPaused to wait until the thread is paused.
831 */
832 void setPaused(bool paused);
833
834 /**
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700835 * Wait until thread processes the capture request with settings'
836 * android.request.id == requestId.
837 *
838 * Returns TIMED_OUT in case the thread does not process the request
839 * within the timeout.
840 */
841 status_t waitUntilRequestProcessed(int32_t requestId, nsecs_t timeout);
842
Igor Murashkin1e479c02013-09-06 16:55:14 -0700843 /**
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700844 * Shut down the thread. Shutdown is asynchronous, so thread may
845 * still be running once this method returns.
846 */
847 virtual void requestExit();
848
849 /**
Igor Murashkin1e479c02013-09-06 16:55:14 -0700850 * Get the latest request that was sent to the HAL
851 * with process_capture_request.
852 */
853 CameraMetadata getLatestRequest() const;
854
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700855 /**
856 * Returns true if the stream is a target of any queued or repeating
857 * capture request
858 */
859 bool isStreamPending(sp<camera3::Camera3StreamInterface>& stream);
860
Emilian Peev40ead602017-09-26 15:46:36 +0100861 /**
862 * Returns true if the surface is a target of any queued or repeating
863 * capture request
864 */
865 bool isOutputSurfacePending(int streamId, size_t surfaceId);
866
Shuzhen Wang686f6442017-06-20 16:16:04 -0700867 // dump processCaptureRequest latency
868 void dumpCaptureRequestLatency(int fd, const char* name) {
869 mRequestLatency.dump(fd, name);
870 }
871
Yin-Chia Yeh7447f0f2018-10-11 15:28:12 -0700872 void signalPipelineDrain(const std::vector<int>& streamIds);
Yin-Chia Yehe52b8fa2020-07-28 00:17:58 -0700873 void resetPipelineDrain();
Yin-Chia Yeh7447f0f2018-10-11 15:28:12 -0700874
Emilian Peevc0fe54c2020-03-11 14:05:07 -0700875 void clearPreviousRequest();
876
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800877 status_t setRotateAndCropAutoBehavior(
878 camera_metadata_enum_android_scaler_rotate_and_crop_t rotateAndCropValue);
Emilian Peeve23f1d92021-09-20 14:56:01 -0700879 status_t setComposerSurface(bool composerSurfacePresent);
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800880
Eino-Ville Talvala11afe4f2021-05-27 14:45:31 -0700881 status_t setCameraMute(int32_t muteMode);
Cliff Wuc2ad9c82021-04-21 00:58:58 +0800882
883 status_t setHalInterface(sp<HalInterface> newHalInterface);
884
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800885 protected:
886
887 virtual bool threadLoop();
888
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800889 static const String8& getId(const wp<Camera3Device> &device);
Eino-Ville Talvala42368d92013-04-09 14:13:50 -0700890
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700891 status_t queueTriggerLocked(RequestTrigger trigger);
892 // Mix-in queued triggers into this request
893 int32_t insertTriggers(const sp<CaptureRequest> &request);
894 // Purge the queued triggers from this request,
895 // restoring the old field values for those tags.
896 status_t removeTriggers(const sp<CaptureRequest> &request);
897
Eino-Ville Talvala2f876f92013-09-13 11:39:24 -0700898 // HAL workaround: Make sure a trigger ID always exists if
899 // a trigger does
Ivan Lozanoc0ad82f2020-07-30 09:32:57 -0400900 status_t addFakeTriggerIds(const sp<CaptureRequest> &request);
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800901
902 // Override rotate_and_crop control if needed; returns true if the current value was changed
903 bool overrideAutoRotateAndCrop(const sp<CaptureRequest> &request);
Eino-Ville Talvala2f876f92013-09-13 11:39:24 -0700904
Eino-Ville Talvala305cec62020-11-12 14:18:17 -0800905 // Override test_pattern control if needed for camera mute; returns true
906 // if the current value was changed
907 bool overrideTestPattern(const sp<CaptureRequest> &request);
908
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800909 static const nsecs_t kRequestTimeout = 50e6; // 50 ms
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800910
Yin-Chia Yehb978c382019-10-30 00:22:37 -0700911 // TODO: does this need to be adjusted for long exposure requests?
912 static const nsecs_t kRequestSubmitTimeout = 200e6; // 200 ms
913
Chien-Yu Chen85a64552015-08-28 15:46:12 -0700914 // Used to prepare a batch of requests.
915 struct NextRequest {
916 sp<CaptureRequest> captureRequest;
Emilian Peevf4816702020-04-03 15:44:51 -0700917 camera_capture_request_t halRequest;
918 Vector<camera_stream_buffer_t> outputBuffers;
Chien-Yu Chen85a64552015-08-28 15:46:12 -0700919 bool submitted;
920 };
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800921
Chien-Yu Chen57ea2922015-09-04 12:58:56 -0700922 // Wait for the next batch of requests and put them in mNextRequests. mNextRequests will
923 // be empty if it times out.
924 void waitForNextRequestBatch();
Chien-Yu Chen85a64552015-08-28 15:46:12 -0700925
926 // Waits for a request, or returns NULL if times out. Must be called with mRequestLock hold.
927 sp<CaptureRequest> waitForNextRequestLocked();
928
Chien-Yu Chen57ea2922015-09-04 12:58:56 -0700929 // Prepare HAL requests and output buffers in mNextRequests. Return TIMED_OUT if getting any
930 // output buffer timed out. If an error is returned, the caller should clean up the pending
931 // request batch.
932 status_t prepareHalRequests();
Chien-Yu Chen85a64552015-08-28 15:46:12 -0700933
Chien-Yu Chen57ea2922015-09-04 12:58:56 -0700934 // Return buffers, etc, for requests in mNextRequests that couldn't be fully constructed and
935 // send request errors if sendRequestError is true. The buffers will be returned in the
936 // ERROR state to mark them as not having valid data. mNextRequests will be cleared.
937 void cleanUpFailedRequests(bool sendRequestError);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800938
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700939 // Stop the repeating request if any of its output streams is abandoned.
940 void checkAndStopRepeatingRequest();
941
Emilian Peevaebbe412018-01-15 13:53:24 +0000942 // Release physical camera settings and camera id resources.
943 void cleanupPhysicalSettings(sp<CaptureRequest> request,
Emilian Peevf4816702020-04-03 15:44:51 -0700944 /*out*/camera_capture_request_t *halRequest);
Emilian Peevaebbe412018-01-15 13:53:24 +0000945
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800946 // Pause handling
947 bool waitIfPaused();
Eino-Ville Talvala26fe6c72013-08-29 12:46:18 -0700948 void unpauseForNewRequests();
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800949
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700950 // Relay error to parent device object setErrorState
951 void setErrorState(const char *fmt, ...);
952
Yin-Chia Yeh8684b7f2014-06-13 14:53:05 -0700953 // If the input request is in mRepeatingRequests. Must be called with mRequestLock hold
Chih-Hung Hsieh8b0b9712016-08-09 14:25:53 -0700954 bool isRepeatingRequestLocked(const sp<CaptureRequest>&);
Yin-Chia Yeh8684b7f2014-06-13 14:53:05 -0700955
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700956 // Clear repeating requests. Must be called with mRequestLock held.
957 status_t clearRepeatingRequestsLocked(/*out*/ int64_t *lastFrameNumber = NULL);
958
Yin-Chia Yeh94c68e02017-03-06 14:09:44 -0800959 // send request in mNextRequests to HAL in a batch. Return true = sucssess
960 bool sendRequestsBatch();
961
Shuzhen Wang00abbeb2022-02-25 17:14:42 -0800962 // Calculate the expected (minimum, maximum) duration range for a request
963 std::pair<nsecs_t, nsecs_t> calculateExpectedDurationRange(
964 const camera_metadata_t *request);
Eino-Ville Talvala10bd57e2017-06-23 16:22:44 -0700965
Emilian Peevac3ce6c2017-12-12 15:27:02 +0000966 // Check and update latest session parameters based on the current request settings.
967 bool updateSessionParameters(const CameraMetadata& settings);
968
Emilian Peeva14b4dd2018-05-15 11:00:31 +0100969 // Check whether FPS range session parameter re-configuration is needed in constrained
970 // high speed recording camera sessions.
971 bool skipHFRTargetFPSUpdate(int32_t tag, const camera_metadata_ro_entry_t& newEntry,
972 const camera_metadata_entry_t& currentEntry);
973
Shuzhen Wangc2cba122018-05-17 18:10:24 -0700974 // Update next request sent to HAL
975 void updateNextRequest(NextRequest& nextRequest);
Emilian Peevac3ce6c2017-12-12 15:27:02 +0000976
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800977 wp<Camera3Device> mParent;
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700978 wp<camera3::StatusTracker> mStatusTracker;
Yin-Chia Yehdb1e8642017-07-14 15:19:30 -0700979 sp<HalInterface> mInterface;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800980
Yin-Chia Yehe1c80632016-08-08 14:48:05 -0700981 wp<NotificationListener> mListener;
Eino-Ville Talvala17543512014-08-06 14:32:02 -0700982
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800983 const String8& mId; // The camera ID
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700984 int mStatusId; // The RequestThread's component ID for
985 // status tracking
Eino-Ville Talvala42368d92013-04-09 14:13:50 -0700986
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800987 Mutex mRequestLock;
988 Condition mRequestSignal;
Shuzhen Wangbb9b93d2022-04-07 13:22:48 -0700989 bool mRequestClearing;
990
Yin-Chia Yehb978c382019-10-30 00:22:37 -0700991 Condition mRequestSubmittedSignal;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800992 RequestList mRequestQueue;
993 RequestList mRepeatingRequests;
Shuzhen Wang316781a2020-08-18 18:11:01 -0700994 bool mFirstRepeating;
Chien-Yu Chen57ea2922015-09-04 12:58:56 -0700995 // The next batch of requests being prepped for submission to the HAL, no longer
Eino-Ville Talvalae74c2282015-05-27 14:46:23 -0700996 // on the request queue. Read-only even with mRequestLock held, outside
997 // of threadLoop
Chien-Yu Chen57ea2922015-09-04 12:58:56 -0700998 Vector<NextRequest> mNextRequests;
Chien-Yu Chen85a64552015-08-28 15:46:12 -0700999
1000 // To protect flush() and sending a request batch to HAL.
1001 Mutex mFlushLock;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001002
1003 bool mReconfigured;
1004
Yin-Chia Yeh7447f0f2018-10-11 15:28:12 -07001005 // Used by waitIfPaused, waitForNextRequest, waitUntilPaused, and signalPipelineDrain
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001006 Mutex mPauseLock;
1007 bool mDoPause;
1008 Condition mDoPauseSignal;
1009 bool mPaused;
Yin-Chia Yeh7447f0f2018-10-11 15:28:12 -07001010 bool mNotifyPipelineDrain;
1011 std::vector<int> mStreamIdsToBeDrained;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001012
1013 sp<CaptureRequest> mPrevRequest;
Igor Murashkin4d2f2e82013-04-01 17:29:07 -07001014 int32_t mPrevTriggers;
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -08001015 std::set<std::string> mPrevCameraIdsWithZoom;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001016
Eino-Ville Talvala42368d92013-04-09 14:13:50 -07001017 uint32_t mFrameNumber;
Igor Murashkin4d2f2e82013-04-01 17:29:07 -07001018
Igor Murashkin1e479c02013-09-06 16:55:14 -07001019 mutable Mutex mLatestRequestMutex;
Igor Murashkin4d2f2e82013-04-01 17:29:07 -07001020 Condition mLatestRequestSignal;
1021 // android.request.id for latest process_capture_request
1022 int32_t mLatestRequestId;
Igor Murashkin1e479c02013-09-06 16:55:14 -07001023 CameraMetadata mLatestRequest;
Shuzhen Wangc2cba122018-05-17 18:10:24 -07001024 std::unordered_map<std::string, CameraMetadata> mLatestPhysicalRequest;
Igor Murashkin4d2f2e82013-04-01 17:29:07 -07001025
1026 typedef KeyedVector<uint32_t/*tag*/, RequestTrigger> TriggerMap;
1027 Mutex mTriggerMutex;
1028 TriggerMap mTriggerMap;
1029 TriggerMap mTriggerRemovedMap;
1030 TriggerMap mTriggerReplacedMap;
Yin-Chia Yehc00a25c2014-08-21 14:27:44 -07001031 uint32_t mCurrentAfTriggerId;
1032 uint32_t mCurrentPreCaptureTriggerId;
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -08001033 camera_metadata_enum_android_scaler_rotate_and_crop_t mRotateAndCropOverride;
Emilian Peeve23f1d92021-09-20 14:56:01 -07001034 bool mComposerOutput;
Eino-Ville Talvala11afe4f2021-05-27 14:45:31 -07001035 int32_t mCameraMute; // 0 = no mute, otherwise the TEST_PATTERN_MODE to use
Eino-Ville Talvala305cec62020-11-12 14:18:17 -08001036 bool mCameraMuteChanged;
Jianing Weicb0652e2014-03-12 18:29:36 -07001037
Jianing Wei2d6bb3f2014-04-11 10:00:31 -07001038 int64_t mRepeatingLastFrameNumber;
Chien-Yu Chend196d612015-06-22 19:49:01 -07001039
Chien-Yu Chenc66969b2016-05-19 16:37:51 -07001040 // Flag indicating if we should prepare video stream for video requests.
1041 bool mPrepareVideoStream;
Shuzhen Wang686f6442017-06-20 16:16:04 -07001042
Emilian Peeva14b4dd2018-05-15 11:00:31 +01001043 bool mConstrainedMode;
1044
Shuzhen Wang686f6442017-06-20 16:16:04 -07001045 static const int32_t kRequestLatencyBinSize = 40; // in ms
1046 CameraLatencyHistogram mRequestLatency;
Emilian Peevac3ce6c2017-12-12 15:27:02 +00001047
1048 Vector<int32_t> mSessionParamKeys;
1049 CameraMetadata mLatestSessionParams;
Yin-Chia Yehd5cd5ff2018-10-01 14:43:04 -07001050
Shuzhen Wang99080502021-03-07 21:08:20 -08001051 std::map<int32_t, std::set<String8>> mGroupIdPhysicalCameraMap;
1052
Yin-Chia Yehd5cd5ff2018-10-01 14:43:04 -07001053 const bool mUseHalBufManager;
Eino-Ville Talvala1646c3c2021-07-29 13:48:40 -07001054 const bool mSupportCameraMute;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -08001055 };
Jayant Chowdhary22441f32021-12-26 18:35:41 -08001056
1057 virtual sp<RequestThread> createNewRequestThread(wp<Camera3Device> /*parent*/,
1058 sp<camera3::StatusTracker> /*statusTracker*/,
1059 sp<HalInterface> /*interface*/,
1060 const Vector<int32_t>& /*sessionParamKeys*/,
1061 bool /*useHalBufManager*/,
1062 bool /*supportCameraMute*/) = 0;
1063
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001064 sp<RequestThread> mRequestThread;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -08001065
1066 /**
Eino-Ville Talvala42368d92013-04-09 14:13:50 -07001067 * In-flight queue for tracking completion of capture requests.
1068 */
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -08001069 std::mutex mInFlightLock;
1070 camera3::InFlightRequestMap mInFlightMap;
1071 nsecs_t mExpectedInflightDuration = 0;
Shuzhen Wangb7b42652020-05-07 11:59:02 -07001072 int64_t mLastCompletedRegularFrameNumber = -1;
1073 int64_t mLastCompletedReprocessFrameNumber = -1;
1074 int64_t mLastCompletedZslFrameNumber = -1;
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -08001075 // End of mInFlightLock protection scope
Eino-Ville Talvala42368d92013-04-09 14:13:50 -07001076
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -08001077 int mInFlightStatusId; // const after initialize
Eino-Ville Talvala42368d92013-04-09 14:13:50 -07001078
Jianing Weicb0652e2014-03-12 18:29:36 -07001079 status_t registerInFlight(uint32_t frameNumber,
Chien-Yu Chend196d612015-06-22 19:49:01 -07001080 int32_t numBuffers, CaptureResultExtras resultExtras, bool hasInput,
Shuzhen Wang00abbeb2022-02-25 17:14:42 -08001081 bool callback, nsecs_t minExpectedDuration, nsecs_t maxExpectedDuration,
Shuzhen Wang99080502021-03-07 21:08:20 -08001082 const std::set<std::set<String8>>& physicalCameraIds,
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -08001083 bool isStillCapture, bool isZslCapture, bool rotateAndCropAuto,
Shuzhen Wang316781a2020-08-18 18:11:01 -07001084 const std::set<std::string>& cameraIdsWithZoom, const SurfaceMap& outputSurfaces,
1085 nsecs_t requestTimeNs);
Eino-Ville Talvala10bd57e2017-06-23 16:22:44 -07001086
1087 /**
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07001088 * Tracking for idle detection
1089 */
1090 sp<camera3::StatusTracker> mStatusTracker;
Eino-Ville Talvala42368d92013-04-09 14:13:50 -07001091
1092 /**
Zhijun He125684a2015-12-26 15:07:30 -08001093 * Graphic buffer manager for output streams. Each device has a buffer manager, which is used
1094 * by the output streams to get and return buffers if these streams are registered to this
1095 * buffer manager.
1096 */
1097 sp<camera3::Camera3BufferManager> mBufferManager;
1098
1099 /**
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001100 * Thread for preparing streams
1101 */
1102 class PreparerThread : private Thread, public virtual RefBase {
1103 public:
1104 PreparerThread();
1105 ~PreparerThread();
1106
Yin-Chia Yehe1c80632016-08-08 14:48:05 -07001107 void setNotificationListener(wp<NotificationListener> listener);
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001108
1109 /**
Ruben Brunkc78ac262015-08-13 17:58:46 -07001110 * Queue up a stream to be prepared. Streams are processed by a background thread in FIFO
1111 * order. Pre-allocate up to maxCount buffers for the stream, or the maximum number needed
1112 * for the pipeline if maxCount is ALLOCATE_PIPELINE_MAX.
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001113 */
Ruben Brunkc78ac262015-08-13 17:58:46 -07001114 status_t prepare(int maxCount, sp<camera3::Camera3StreamInterface>& stream);
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001115
1116 /**
1117 * Cancel all current and pending stream preparation
1118 */
1119 status_t clear();
1120
Emilian Peevac3ce6c2017-12-12 15:27:02 +00001121 /**
1122 * Pause all preparation activities
1123 */
1124 void pause();
1125
1126 /**
1127 * Resume preparation activities
1128 */
1129 status_t resume();
1130
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001131 private:
1132 Mutex mLock;
Emilian Peevac3ce6c2017-12-12 15:27:02 +00001133 Condition mThreadActiveSignal;
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001134
1135 virtual bool threadLoop();
1136
1137 // Guarded by mLock
1138
Yin-Chia Yehe1c80632016-08-08 14:48:05 -07001139 wp<NotificationListener> mListener;
Emilian Peevac3ce6c2017-12-12 15:27:02 +00001140 std::unordered_map<int, sp<camera3::Camera3StreamInterface> > mPendingStreams;
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001141 bool mActive;
1142 bool mCancelNow;
1143
1144 // Only accessed by threadLoop and the destructor
1145
1146 sp<camera3::Camera3StreamInterface> mCurrentStream;
Emilian Peevac3ce6c2017-12-12 15:27:02 +00001147 int mCurrentMaxCount;
1148 bool mCurrentPrepareComplete;
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001149 };
1150 sp<PreparerThread> mPreparerThread;
1151
1152 /**
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -07001153 * Output result queue and current HAL device 3A state
1154 */
1155
1156 // Lock for output side of device
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -08001157 std::mutex mOutputLock;
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -07001158
1159 /**** Scope for mOutputLock ****/
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001160 // the minimal frame number of the next non-reprocess result
Eino-Ville Talvala42368d92013-04-09 14:13:50 -07001161 uint32_t mNextResultFrameNumber;
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001162 // the minimal frame number of the next reprocess result
1163 uint32_t mNextReprocessResultFrameNumber;
Shuzhen Wang5ee99842019-04-12 11:55:48 -07001164 // the minimal frame number of the next ZSL still capture result
1165 uint32_t mNextZslStillResultFrameNumber;
Chien-Yu Chen3df11ce2015-09-30 14:13:30 -07001166 // the minimal frame number of the next non-reprocess shutter
Eino-Ville Talvala42368d92013-04-09 14:13:50 -07001167 uint32_t mNextShutterFrameNumber;
Chien-Yu Chen3df11ce2015-09-30 14:13:30 -07001168 // the minimal frame number of the next reprocess shutter
1169 uint32_t mNextReprocessShutterFrameNumber;
Shuzhen Wang5ee99842019-04-12 11:55:48 -07001170 // the minimal frame number of the next ZSL still capture shutter
1171 uint32_t mNextZslStillShutterFrameNumber;
Jayant Chowdhary8a0be292020-01-08 13:10:38 -08001172 std::list<CaptureResult> mResultQueue;
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -08001173 std::condition_variable mResultSignal;
1174 wp<NotificationListener> mListener;
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -07001175
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -07001176 /**** End scope for mOutputLock ****/
1177
Chien-Yu Chen43e69a62014-11-25 16:38:33 -08001178 /**** Scope for mInFlightLock ****/
1179
Shuzhen Wangcadb3302016-11-04 14:17:56 -07001180 // Remove the in-flight map entry of the given index from mInFlightMap.
1181 // It must only be called with mInFlightLock held.
1182 void removeInFlightMapEntryLocked(int idx);
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -08001183
Yin-Chia Yehf3fe36f2017-07-07 18:23:18 -07001184 // Remove all in-flight requests and return all buffers.
1185 // This is used after HAL interface is closed to cleanup any request/buffers
1186 // not returned by HAL.
1187 void flushInflightRequests();
Chien-Yu Chen43e69a62014-11-25 16:38:33 -08001188
1189 /**** End scope for mInFlightLock ****/
1190
Eino-Ville Talvala7b8a1fd2018-05-22 15:30:35 -07001191 /**
1192 * Distortion correction support
1193 */
Shuzhen Wang4f6fa9d2019-03-29 10:40:35 -07001194 // Map from camera IDs to its corresponding distortion mapper. Only contains
1195 // 1 ID if the device isn't a logical multi-camera. Otherwise contains both
1196 // logical camera and its physical subcameras.
1197 std::unordered_map<std::string, camera3::DistortionMapper> mDistortionMappers;
Eino-Ville Talvala7b8a1fd2018-05-22 15:30:35 -07001198
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -08001199 /**
1200 * Zoom ratio mapper support
1201 */
1202 std::unordered_map<std::string, camera3::ZoomRatioMapper> mZoomRatioMappers;
1203
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -08001204 /**
Jayant Chowdhary9255ce02021-07-15 11:18:17 -07001205 * UHR request crop / metering region mapper support
1206 */
1207 std::unordered_map<std::string, camera3::UHRCropAndMeteringRegionMapper>
1208 mUHRCropAndMeteringRegionMappers;
1209
1210 /**
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -08001211 * RotateAndCrop mapper support
1212 */
1213 std::unordered_map<std::string, camera3::RotateAndCropMapper> mRotateAndCropMappers;
1214
Eino-Ville Talvala4d453832016-07-15 11:56:53 -07001215 // Debug tracker for metadata tag value changes
1216 // - Enabled with the -m <taglist> option to dumpsys, such as
1217 // dumpsys -m android.control.aeState,android.control.aeMode
1218 // - Disabled with -m off
1219 // - dumpsys -m 3a is a shortcut for ae/af/awbMode, State, and Triggers
1220 TagMonitor mTagMonitor;
1221
1222 void monitorMetadata(TagMonitor::eventSource source, int64_t frameNumber,
Shuzhen Wangc2cba122018-05-17 18:10:24 -07001223 nsecs_t timestamp, const CameraMetadata& metadata,
Jayant Chowdharycd277cd2021-08-11 15:48:40 -07001224 const std::unordered_map<std::string, CameraMetadata>& physicalMetadata,
Jayant Chowdharyc30b4c32021-08-18 11:43:16 -07001225 const camera_stream_buffer_t *outputBuffers, uint32_t numOutputBuffers,
1226 int32_t inputStreamId);
Eino-Ville Talvala4d453832016-07-15 11:56:53 -07001227
Emilian Peev71c73a22017-03-21 16:35:51 +00001228 metadata_vendor_id_t mVendorTagId;
1229
Emilian Peev811d2952018-05-25 11:08:40 +01001230 // Cached last requested template id
1231 int mLastTemplateId;
1232
Emilian Peev26d975d2018-07-05 14:52:57 +01001233 // Synchronizes access to status tracker between inflight updates and disconnect.
1234 // b/79972865
1235 Mutex mTrackerLock;
Yin-Chia Yehd5cd5ff2018-10-01 14:43:04 -07001236
Yin-Chia Yeh30ab5ed2018-10-12 15:57:04 -07001237 // Whether HAL request buffers through requestStreamBuffers API
Yin-Chia Yehd5cd5ff2018-10-01 14:43:04 -07001238 bool mUseHalBufManager = false;
1239
1240 // Lock to ensure requestStreamBuffers() callbacks are serialized
1241 std::mutex mRequestBufferInterfaceLock;
1242
Yin-Chia Yeh30ab5ed2018-10-12 15:57:04 -07001243 // The state machine to control when requestStreamBuffers should allow
1244 // HAL to request buffers.
1245 enum RequestBufferState {
1246 /**
1247 * This is the initial state.
1248 * requestStreamBuffers call will return FAILED_CONFIGURING in this state.
1249 * Will switch to RB_STATUS_READY after a successful configureStreams or
1250 * processCaptureRequest call.
1251 */
1252 RB_STATUS_STOPPED,
1253
1254 /**
1255 * requestStreamBuffers call will proceed in this state.
1256 * When device is asked to stay idle via waitUntilStateThenRelock() call:
1257 * - Switch to RB_STATUS_STOPPED if there is no inflight requests and
1258 * request thread is paused.
1259 * - Switch to RB_STATUS_PENDING_STOP otherwise
1260 */
1261 RB_STATUS_READY,
1262
1263 /**
1264 * requestStreamBuffers call will proceed in this state.
1265 * Switch to RB_STATUS_STOPPED when all inflight requests are fulfilled
1266 * and request thread is paused
1267 */
1268 RB_STATUS_PENDING_STOP,
1269 };
1270
1271 class RequestBufferStateMachine {
1272 public:
1273 status_t initialize(sp<camera3::StatusTracker> statusTracker);
1274
1275 // Return if the state machine currently allows for requestBuffers
1276 // If the state allows for it, mRequestBufferOngoing will be set to true
1277 // and caller must call endRequestBuffer() later to unset the flag
1278 bool startRequestBuffer();
1279 void endRequestBuffer();
1280
1281 // Events triggered by application API call
1282 void onStreamsConfigured();
1283 void onWaitUntilIdle();
1284
1285 // Events usually triggered by hwBinder processCaptureResult callback thread
1286 // But can also be triggered on request thread for failed request, or on
1287 // hwbinder notify callback thread for shutter/error callbacks
1288 void onInflightMapEmpty();
1289
1290 // Events triggered by RequestThread
Yin-Chia Yehcd333fe2019-02-08 13:45:41 -08001291 void onSubmittingRequest();
Yin-Chia Yeh30ab5ed2018-10-12 15:57:04 -07001292 void onRequestThreadPaused();
1293
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -08001294 // Events triggered by successful switchToOffline call
1295 // Return true is there is no ongoing requestBuffer call.
1296 bool onSwitchToOfflineSuccess();
1297
Yin-Chia Yeh30ab5ed2018-10-12 15:57:04 -07001298 private:
1299 void notifyTrackerLocked(bool active);
1300
1301 // Switch to STOPPED state and return true if all conditions allows for it.
1302 // Otherwise do nothing and return false.
1303 bool checkSwitchToStopLocked();
1304
1305 std::mutex mLock;
1306 RequestBufferState mStatus = RB_STATUS_STOPPED;
1307
1308 bool mRequestThreadPaused = true;
1309 bool mInflightMapEmpty = true;
1310 bool mRequestBufferOngoing = false;
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -08001311 bool mSwitchedToOffline = false;
Yin-Chia Yeh30ab5ed2018-10-12 15:57:04 -07001312
1313 wp<camera3::StatusTracker> mStatusTracker;
1314 int mRequestBufferStatusId;
1315 } mRequestBufferSM;
1316
Shuzhen Wang268a1362018-10-16 16:32:59 -07001317 // Fix up result metadata for monochrome camera.
1318 bool mNeedFixupMonochromeTags;
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001319
1320 // Whether HAL supports offline processing capability.
1321 bool mSupportOfflineProcessing = false;
Eino-Ville Talvala305cec62020-11-12 14:18:17 -08001322
1323 // Whether the HAL supports camera muting via test pattern
1324 bool mSupportCameraMute = false;
Eino-Ville Talvala11afe4f2021-05-27 14:45:31 -07001325 // Whether the HAL supports SOLID_COLOR or BLACK if mSupportCameraMute is true
1326 bool mSupportTestPatternSolidColor = false;
Eino-Ville Talvala305cec62020-11-12 14:18:17 -08001327
Shuzhen Wangd4abdf72021-05-28 11:22:50 -07001328 // Whether the camera framework overrides the device characteristics for
1329 // performance class.
1330 bool mOverrideForPerfClass;
1331
Shuzhen Wang00abbeb2022-02-25 17:14:42 -08001332 // The current minimum expected frame duration based on AE_TARGET_FPS_RANGE
1333 nsecs_t mMinExpectedDuration = 0;
1334
Cliff Wuc2ad9c82021-04-21 00:58:58 +08001335 // Injection camera related methods.
1336 class Camera3DeviceInjectionMethods : public virtual RefBase {
1337 public:
1338 Camera3DeviceInjectionMethods(wp<Camera3Device> parent);
1339
1340 ~Camera3DeviceInjectionMethods();
1341
Cliff Wuc2ad9c82021-04-21 00:58:58 +08001342 // Injection camera will replace the internal camera and configure streams
1343 // when device is IDLE and request thread is paused.
1344 status_t injectCamera(
1345 camera3::camera_stream_configuration& injectionConfig,
Cliff Wu3b268182021-07-06 15:44:43 +08001346 const std::vector<uint32_t>& injectionBufferSizes);
Cliff Wuc2ad9c82021-04-21 00:58:58 +08001347
1348 // Stop the injection camera and switch back to backup hal interface.
1349 status_t stopInjection();
1350
1351 bool isInjecting();
1352
Cliff Wu3b268182021-07-06 15:44:43 +08001353 bool isStreamConfigCompleteButNotInjected();
1354
Cliff Wuc2ad9c82021-04-21 00:58:58 +08001355 const String8& getInjectedCamId() const;
1356
1357 void getInjectionConfig(/*out*/ camera3::camera_stream_configuration* injectionConfig,
1358 /*out*/ std::vector<uint32_t>* injectionBufferSizes);
1359
Cliff Wu3b268182021-07-06 15:44:43 +08001360 // When the streaming configuration is completed and the camera device is active, but the
1361 // injection camera has not yet been injected, the streaming configuration of the internal
1362 // camera will be stored first.
1363 void storeInjectionConfig(
1364 const camera3::camera_stream_configuration& injectionConfig,
1365 const std::vector<uint32_t>& injectionBufferSizes);
1366
Jayant Chowdhary22441f32021-12-26 18:35:41 -08001367 protected:
Cliff Wuc2ad9c82021-04-21 00:58:58 +08001368 // Configure the streams of injection camera, it need wait until the
1369 // output streams are created and configured to the original camera before
1370 // proceeding.
1371 status_t injectionConfigureStreams(
1372 camera3::camera_stream_configuration& injectionConfig,
Cliff Wu3b268182021-07-06 15:44:43 +08001373 const std::vector<uint32_t>& injectionBufferSizes);
Cliff Wuc2ad9c82021-04-21 00:58:58 +08001374
1375 // Disconnect the injection camera and delete the hal interface.
1376 void injectionDisconnectImpl();
1377
1378 // Use injection camera hal interface to replace and backup original
1379 // camera hal interface.
Jayant Chowdhary22441f32021-12-26 18:35:41 -08001380 virtual status_t replaceHalInterface(sp<HalInterface> /*newHalInterface*/,
1381 bool /*keepBackup*/) = 0;
Cliff Wuc2ad9c82021-04-21 00:58:58 +08001382
1383 wp<Camera3Device> mParent;
1384
1385 // Backup of the original camera hal interface.
1386 sp<HalInterface> mBackupHalInterface;
1387
1388 // Generated injection camera hal interface.
1389 sp<HalInterface> mInjectedCamHalInterface;
1390
Cliff Wu3b268182021-07-06 15:44:43 +08001391 // The flag indicates that the stream configuration is complete, the camera device is
1392 // active, but the injection camera has not yet been injected.
1393 bool mIsStreamConfigCompleteButNotInjected = false;
1394
Cliff Wuc2ad9c82021-04-21 00:58:58 +08001395 // Copy the configuration of the internal camera.
1396 camera3::camera_stream_configuration mInjectionConfig;
1397
Cliff Wud0476312021-07-27 20:15:55 +08001398 // Copy the streams of the internal camera.
1399 Vector<camera3::camera_stream_t*> mInjectionStreams;
1400
Cliff Wuc2ad9c82021-04-21 00:58:58 +08001401 // Copy the bufferSizes of the output streams of the internal camera.
1402 std::vector<uint32_t> mInjectionBufferSizes;
1403
1404 // Synchronizes access to injection camera between initialize and
1405 // disconnect.
1406 Mutex mInjectionLock;
1407
1408 // The injection camera ID.
1409 String8 mInjectedCamId;
1410 };
Jayant Chowdhary22441f32021-12-26 18:35:41 -08001411
1412 virtual sp<Camera3DeviceInjectionMethods>
1413 createCamera3DeviceInjectionMethods(wp<Camera3Device>) = 0;
1414
Cliff Wuc2ad9c82021-04-21 00:58:58 +08001415 sp<Camera3DeviceInjectionMethods> mInjectionMethods;
1416
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -08001417}; // class Camera3Device
1418
1419}; // namespace android
1420
1421#endif