blob: 7dff809afe4b2bbbf75bd34910c80c0fecfa5c7c [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
Ravneet98ffa752022-03-02 07:22:46 +000034#include "CameraServiceWatchdog.h"
Jayant Chowdharyc67af1b2022-04-07 18:05:04 +000035#include <aidl/android/hardware/camera/device/CameraBlob.h>
36
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070037#include "common/CameraDeviceBase.h"
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -080038#include "device3/BufferUtils.h"
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -070039#include "device3/StatusTracker.h"
Zhijun He125684a2015-12-26 15:07:30 -080040#include "device3/Camera3BufferManager.h"
Eino-Ville Talvala7b8a1fd2018-05-22 15:30:35 -070041#include "device3/DistortionMapper.h"
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -080042#include "device3/ZoomRatioMapper.h"
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -080043#include "device3/RotateAndCropMapper.h"
Jayant Chowdhary9255ce02021-07-15 11:18:17 -070044#include "device3/UHRCropAndMeteringRegionMapper.h"
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -080045#include "device3/InFlightRequest.h"
46#include "device3/Camera3OutputInterface.h"
47#include "device3/Camera3OfflineSession.h"
Shuzhen Wang83bff122020-11-20 15:51:39 -080048#include "device3/Camera3StreamInterface.h"
Eino-Ville Talvala4d453832016-07-15 11:56:53 -070049#include "utils/TagMonitor.h"
Jayant Chowdhary22441f32021-12-26 18:35:41 -080050#include "utils/IPCTransport.h"
Shuzhen Wang686f6442017-06-20 16:16:04 -070051#include "utils/LatencyHistogram.h"
Emilian Peev71c73a22017-03-21 16:35:51 +000052#include <camera_metadata_hidden.h>
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080053
Emilian Peevf4816702020-04-03 15:44:51 -070054using android::camera3::camera_capture_request_t;
Emilian Peevf4816702020-04-03 15:44:51 -070055using 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
Jayant Chowdharyc67af1b2022-04-07 18:05:04 +000092 virtual IPCTransport getTransportType() const override {
93 return mInterface->getTransportType();
94 }
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080095
96 /**
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -080097 * CameraDeviceBase interface
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080098 */
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -080099
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800100 const String8& getId() const override;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800101
Emilian Peev00420d22018-02-05 21:33:13 +0000102 metadata_vendor_id_t getVendorTagId() const override { return mVendorTagId; }
103
Ravneet98ffa752022-03-02 07:22:46 +0000104 // Watchdog thread
105 sp<CameraServiceWatchdog> mCameraServiceWatchdog;
106
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800107 // Transitions to idle state on success.
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800108 virtual status_t initialize(sp<CameraProviderManager> /*manager*/,
109 const String8& /*monitorTags*/) = 0;
110
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800111 status_t disconnect() override;
112 status_t dump(int fd, const Vector<String16> &args) override;
Avichal Rakesh7e53cad2021-10-05 13:46:30 -0700113 status_t startWatchingTags(const String8 &tags) override;
114 status_t stopWatchingTags() override;
115 status_t dumpWatchedEventsToVector(std::vector<std::string> &out) override;
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800116 const CameraMetadata& info() const override;
Emilian Peevfaa4bde2020-01-23 12:19:37 -0800117 const CameraMetadata& infoPhysical(const String8& physicalId) const override;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800118
119 // Capture and setStreamingRequest will configure streams if currently in
120 // idle state
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800121 status_t capture(CameraMetadata &request, int64_t *lastFrameNumber = NULL) override;
Emilian Peevaebbe412018-01-15 13:53:24 +0000122 status_t captureList(const List<const PhysicalCameraSettingsList> &requestsList,
Shuzhen Wang0129d522016-10-30 22:43:41 -0700123 const std::list<const SurfaceMap> &surfaceMaps,
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800124 int64_t *lastFrameNumber = NULL) override;
125 status_t setStreamingRequest(const CameraMetadata &request,
126 int64_t *lastFrameNumber = NULL) override;
Emilian Peevaebbe412018-01-15 13:53:24 +0000127 status_t setStreamingRequestList(const List<const PhysicalCameraSettingsList> &requestsList,
Shuzhen Wang0129d522016-10-30 22:43:41 -0700128 const std::list<const SurfaceMap> &surfaceMaps,
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800129 int64_t *lastFrameNumber = NULL) override;
130 status_t clearStreamingRequest(int64_t *lastFrameNumber = NULL) override;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800131
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800132 status_t waitUntilRequestReceived(int32_t requestId, nsecs_t timeout) override;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800133
134 // Actual stream creation/deletion is delayed until first request is submitted
135 // If adding streams while actively capturing, will pause device before adding
Zhijun He5d677d12016-05-29 16:52:39 -0700136 // stream, reconfiguring device, and unpausing. If the client create a stream
Shuzhen Wang758c2152017-01-10 18:26:18 -0800137 // with nullptr consumer surface, the client must then call setConsumers()
Zhijun He5d677d12016-05-29 16:52:39 -0700138 // and finish the stream configuration before starting output streaming.
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800139 status_t createStream(sp<Surface> consumer,
Eino-Ville Talvala3d82c0d2015-02-23 15:19:19 -0800140 uint32_t width, uint32_t height, int format,
Emilian Peevf4816702020-04-03 15:44:51 -0700141 android_dataspace dataSpace, camera_stream_rotation_t rotation, int *id,
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800142 const String8& physicalCameraId,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800143 const std::unordered_set<int32_t> &sensorPixelModesUsed,
Emilian Peev40ead602017-09-26 15:46:36 +0100144 std::vector<int> *surfaceIds = nullptr,
Zhijun He5d677d12016-05-29 16:52:39 -0700145 int streamSetId = camera3::CAMERA3_STREAM_SET_ID_INVALID,
Shuzhen Wang83bff122020-11-20 15:51:39 -0800146 bool isShared = false, bool isMultiResolution = false,
Emilian Peev2295df72021-11-12 18:14:10 -0800147 uint64_t consumerUsage = 0,
Emilian Peevc81a7592022-02-14 17:38:18 -0800148 int64_t dynamicRangeProfile =
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800149 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD,
Shuzhen Wang8ed1e872022-03-08 16:34:33 -0800150 int64_t streamUseCase = ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT,
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800151 int timestampBase = OutputConfiguration::TIMESTAMP_BASE_DEFAULT,
152 int mirrorMode = OutputConfiguration::MIRROR_MODE_AUTO) override;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800153
Shuzhen Wang0129d522016-10-30 22:43:41 -0700154 status_t createStream(const std::vector<sp<Surface>>& consumers,
155 bool hasDeferredConsumer, uint32_t width, uint32_t height, int format,
Emilian Peevf4816702020-04-03 15:44:51 -0700156 android_dataspace dataSpace, camera_stream_rotation_t rotation, int *id,
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800157 const String8& physicalCameraId,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800158 const std::unordered_set<int32_t> &sensorPixelModesUsed,
Emilian Peev40ead602017-09-26 15:46:36 +0100159 std::vector<int> *surfaceIds = nullptr,
Shuzhen Wang0129d522016-10-30 22:43:41 -0700160 int streamSetId = camera3::CAMERA3_STREAM_SET_ID_INVALID,
Shuzhen Wang83bff122020-11-20 15:51:39 -0800161 bool isShared = false, bool isMultiResolution = false,
Emilian Peev2295df72021-11-12 18:14:10 -0800162 uint64_t consumerUsage = 0,
Emilian Peevc81a7592022-02-14 17:38:18 -0800163 int64_t dynamicRangeProfile =
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800164 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD,
Shuzhen Wang8ed1e872022-03-08 16:34:33 -0800165 int64_t streamUseCase = ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT,
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800166 int timestampBase = OutputConfiguration::TIMESTAMP_BASE_DEFAULT,
167 int mirrorMode = OutputConfiguration::MIRROR_MODE_AUTO) override;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700168
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800169 status_t createInputStream(
Shuzhen Wang83bff122020-11-20 15:51:39 -0800170 uint32_t width, uint32_t height, int format, bool isMultiResolution,
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800171 int *id) override;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800172
Emilian Peev710c1422017-08-30 11:19:38 +0100173 status_t getStreamInfo(int id, StreamInfo *streamInfo) override;
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800174 status_t setStreamTransform(int id, int transform) override;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800175
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800176 status_t deleteStream(int id) override;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800177
Emilian Peev5fbe0ba2017-10-20 15:45:45 +0100178 status_t configureStreams(const CameraMetadata& sessionParams,
179 int operatingMode =
Emilian Peevf4816702020-04-03 15:44:51 -0700180 camera_stream_configuration_mode_t::CAMERA_STREAM_CONFIGURATION_NORMAL_MODE) override;
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800181 status_t getInputBufferProducer(
182 sp<IGraphicBufferProducer> *producer) override;
Igor Murashkine2d167e2014-08-19 16:19:59 -0700183
Emilian Peevcc0b7952020-01-07 13:54:47 -0800184 void getOfflineStreamIds(std::vector<int> *offlineStreamIds) override;
185
Emilian Peevf4816702020-04-03 15:44:51 -0700186 status_t createDefaultRequest(camera_request_template_t templateId,
187 CameraMetadata *request) override;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800188
189 // Transitions to the idle state on success
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800190 status_t waitUntilDrained() override;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800191
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800192 status_t setNotifyCallback(wp<NotificationListener> listener) override;
193 bool willNotify3A() override;
194 status_t waitForNextFrame(nsecs_t timeout) override;
195 status_t getNextResult(CaptureResult *frame) override;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800196
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800197 status_t triggerAutofocus(uint32_t id) override;
198 status_t triggerCancelAutofocus(uint32_t id) override;
199 status_t triggerPrecaptureMetering(uint32_t id) override;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800200
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800201 status_t flush(int64_t *lastFrameNumber = NULL) override;
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -0700202
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800203 status_t prepare(int streamId) override;
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700204
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800205 status_t tearDown(int streamId) override;
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -0700206
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800207 status_t addBufferListenerForStream(int streamId,
208 wp<camera3::Camera3StreamBufferListener> listener) override;
Shuzhen Wangb0fdc1e2016-03-20 23:21:39 -0700209
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800210 status_t prepare(int maxCount, int streamId) override;
Ruben Brunkc78ac262015-08-13 17:58:46 -0700211
Jayant Chowdhary6a6d3a82021-11-17 16:54:34 -0800212 ssize_t getJpegBufferSize(const CameraMetadata &info, uint32_t width,
213 uint32_t height) const override;
214 ssize_t getPointCloudBufferSize(const CameraMetadata &info) const;
215 ssize_t getRawOpaqueBufferSize(const CameraMetadata &info, int32_t width, int32_t height,
216 bool maxResolution) const;
Zhijun He28c9b6f2014-08-08 12:00:47 -0700217
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700218 // Methods called by subclasses
219 void notifyStatus(bool idle); // updates from StatusTracker
220
Zhijun He5d677d12016-05-29 16:52:39 -0700221 /**
Shuzhen Wang758c2152017-01-10 18:26:18 -0800222 * Set the deferred consumer surfaces to the output stream and finish the deferred
Zhijun He5d677d12016-05-29 16:52:39 -0700223 * consumer configuration.
224 */
Emilian Peev40ead602017-09-26 15:46:36 +0100225 status_t setConsumerSurfaces(
226 int streamId, const std::vector<sp<Surface>>& consumers,
227 std::vector<int> *surfaceIds /*out*/) override;
228
229 /**
230 * Update a given stream.
231 */
232 status_t updateStream(int streamId, const std::vector<sp<Surface>> &newSurfaces,
233 const std::vector<OutputStreamInfo> &outputInfo,
234 const std::vector<size_t> &removedSurfaceIds,
235 KeyedVector<sp<Surface>, size_t> *outputMap/*out*/);
Zhijun He5d677d12016-05-29 16:52:39 -0700236
Chien-Yu Chena936ac22017-10-23 15:59:49 -0700237 /**
238 * Drop buffers for stream of streamId if dropping is true. If dropping is false, do not
239 * drop buffers for stream of streamId.
240 */
241 status_t dropStreamBuffers(bool dropping, int streamId) override;
242
Emilian Peev2a8e2832019-08-23 13:00:31 -0700243 nsecs_t getExpectedInFlightDuration() override;
244
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800245 virtual status_t switchToOffline(const std::vector<int32_t>& ,
246 /*out*/ sp<CameraOfflineSessionBase>* ) override {
247 return INVALID_OPERATION;
248 };
Yin-Chia Yehb978c382019-10-30 00:22:37 -0700249
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800250 // RequestBufferInterface
251 bool startRequestBuffer() override;
252 void endRequestBuffer() override;
253 nsecs_t getWaitDuration() override;
254
255 // FlushBufferInterface
256 void getInflightBufferKeys(std::vector<std::pair<int32_t, int32_t>>* out) override;
257 void getInflightRequestBufferKeys(std::vector<uint64_t>* out) override;
258 std::vector<sp<camera3::Camera3StreamInterface>> getAllStreams() override;
259
Emilian Peev35ae8262018-11-08 13:11:32 +0000260 /**
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800261 * Set the current behavior for the ROTATE_AND_CROP control when in AUTO.
262 *
263 * The value must be one of the ROTATE_AND_CROP_* values besides AUTO,
264 * and defaults to NONE.
265 */
266 status_t setRotateAndCropAutoBehavior(
267 camera_metadata_enum_android_scaler_rotate_and_crop_t rotateAndCropValue);
268
Eino-Ville Talvala305cec62020-11-12 14:18:17 -0800269 /**
270 * Whether camera muting (producing black-only output) is supported.
271 *
272 * Calling setCameraMute(true) when this returns false will return an
273 * INVALID_OPERATION error.
274 */
275 bool supportsCameraMute();
276
277 /**
278 * Mute the camera.
279 *
280 * When muted, black image data is output on all output streams.
281 */
282 status_t setCameraMute(bool enabled);
283
Ravneet74cd3732022-03-30 05:33:03 +0000284 /**
285 * Enables/disables camera service watchdog
286 */
287 status_t setCameraServiceWatchdog(bool enabled);
288
Shuzhen Wange8675782019-12-05 09:12:14 -0800289 // Get the status trackeer for the camera device
290 wp<camera3::StatusTracker> getStatusTracker() { return mStatusTracker; }
291
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800292 /**
Cliff Wuc2ad9c82021-04-21 00:58:58 +0800293 * The injection camera session to replace the internal camera
294 * session.
295 */
296 status_t injectCamera(const String8& injectedCamId,
297 sp<CameraProviderManager> manager);
298
299 /**
300 * Stop the injection camera and restore to internal camera session.
301 */
302 status_t stopInjection();
303
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800304 protected:
Yin-Chia Yehc5248132018-08-15 12:19:20 -0700305 status_t disconnectImpl();
Jayant Chowdhary65c9bf02021-09-03 16:44:16 +0000306 static status_t removeFwkOnlyRegionKeys(CameraMetadata *request);
Yin-Chia Yehc5248132018-08-15 12:19:20 -0700307
Austin Borger4a870a32022-02-25 01:48:41 +0000308 float getMaxPreviewFps(sp<camera3::Camera3OutputStreamInterface> stream);
309
Igor Murashkin1e479c02013-09-06 16:55:14 -0700310 static const size_t kDumpLockAttempts = 10;
311 static const size_t kDumpSleepDuration = 100000; // 0.10 sec
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700312 static const nsecs_t kActiveTimeout = 500000000; // 500 ms
Yin-Chia Yeh99fd0972019-06-27 14:22:44 -0700313 static const nsecs_t kMinWarnInflightDuration = 5000000000; // 5 s
Yin-Chia Yeh90c0fdf2017-06-29 13:22:12 -0700314 static const size_t kInFlightWarnLimit = 30;
Chien-Yu Chenc96ac8d2015-08-12 16:46:24 -0700315 static const size_t kInFlightWarnLimitHighSpeed = 256; // batch size 32 * pipe depth 8
Eino-Ville Talvala10bd57e2017-06-23 16:22:44 -0700316 static const nsecs_t kMinInflightDuration = 5000000000; // 5 s
Yin-Chia Yehb3a80b12018-09-04 12:13:05 -0700317 static const nsecs_t kBaseGetBufferWait = 3000000000; // 3 sec.
Eino-Ville Talvalaf99498e2015-09-25 16:52:55 -0700318 // SCHED_FIFO priority for request submission thread in HFR mode
Zhijun He7ee4c072016-07-25 13:52:28 -0700319 static const int kRequestThreadPriority = 1;
Chien-Yu Chenc96ac8d2015-08-12 16:46:24 -0700320
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700321 struct RequestTrigger;
Zhijun Hef7da0962014-04-24 13:27:56 -0700322 // minimal jpeg buffer size: 256KB + blob header
Jayant Chowdharyc67af1b2022-04-07 18:05:04 +0000323 static const ssize_t kMinJpegBufferSize =
324 256 * 1024 + sizeof(aidl::android::hardware::camera::device::CameraBlob);
Eino-Ville Talvala16a2ada2014-08-27 14:41:33 -0700325 // Constant to use for stream ID when one doesn't exist
326 static const int NO_STREAM = -1;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800327
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700328 // A lock to enforce serialization on the input/configure side
329 // of the public interface.
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700330 // Not locked by methods guarded by mOutputLock, since they may act
331 // concurrently to the input/configure side of the interface.
332 // Must be locked before mLock if both will be locked by a method
333 Mutex mInterfaceLock;
334
335 // The main lock on internal state
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800336 Mutex mLock;
337
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700338 // Camera device ID
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800339 const String8 mId;
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700340
Emilian Peev5104fe92021-10-21 14:27:09 -0700341 // Legacy camera client flag
342 bool mLegacyClient;
343
Eino-Ville Talvalabbbbe842017-02-28 17:50:56 -0800344 // Current stream configuration mode;
345 int mOperatingMode;
Emilian Peev5fbe0ba2017-10-20 15:45:45 +0100346 // Current session wide parameters
347 hardware::camera2::impl::CameraMetadataNative mSessionParams;
348
Eino-Ville Talvalabbbbe842017-02-28 17:50:56 -0800349 // Constant to use for no set operating mode
350 static const int NO_MODE = -1;
351
Zhijun He1fa89992015-06-01 15:44:31 -0700352 // Flag indicating is the current active stream configuration is constrained high speed.
353 bool mIsConstrainedHighSpeedConfiguration;
354
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800355 /**** Scope for mLock ****/
356
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800357 class HalInterface : public camera3::Camera3StreamBufferFreedListener,
358 public camera3::BufferRecordsInterface {
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800359 public:
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800360 HalInterface(bool useHalBufManager, bool supportOfflineProcessing) :
361 mUseHalBufManager(useHalBufManager),
362 mIsReconfigurationQuerySupported(true),
363 mSupportOfflineProcessing(supportOfflineProcessing)
364 {};
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800365 HalInterface(const HalInterface &other);
366 HalInterface();
367
Jayant Chowdharyc67af1b2022-04-07 18:05:04 +0000368 virtual IPCTransport getTransportType() const = 0;
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800369
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800370 // Returns true if constructed with a valid device or session, and not yet cleared
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800371 virtual bool valid() = 0;
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800372
373 // Reset this HalInterface object (does not call close())
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800374 virtual void clear() = 0;
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800375
376 // Calls into the HAL interface
377
378 // Caller takes ownership of requestTemplate
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800379 virtual status_t constructDefaultRequestSettings(camera_request_template templateId,
380 /*out*/ camera_metadata_t **requestTemplate) = 0;
381
382 virtual status_t configureStreams(const camera_metadata_t * sessionParams,
383 /*inout*/ camera_stream_configuration_t * config,
384 const std::vector<uint32_t>& bufferSizes) = 0;
Yin-Chia Yeh11648852019-05-16 10:42:54 -0700385
Cliff Wuc2ad9c82021-04-21 00:58:58 +0800386 // The injection camera configures the streams to hal.
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800387 virtual status_t configureInjectedStreams(
Cliff Wuc2ad9c82021-04-21 00:58:58 +0800388 const camera_metadata_t* sessionParams,
389 /*inout*/ camera_stream_configuration_t* config,
390 const std::vector<uint32_t>& bufferSizes,
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800391 const CameraMetadata& cameraCharacteristics) = 0;
Cliff Wuc2ad9c82021-04-21 00:58:58 +0800392
Yin-Chia Yeh11648852019-05-16 10:42:54 -0700393 // When the call succeeds, the ownership of acquire fences in requests is transferred to
394 // HalInterface. More specifically, the current implementation will send the fence to
395 // HAL process and close the FD in cameraserver process. When the call fails, the ownership
396 // of the acquire fence still belongs to the caller.
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800397 virtual status_t processBatchCaptureRequests(
Emilian Peevf4816702020-04-03 15:44:51 -0700398 std::vector<camera_capture_request_t*>& requests,
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800399 /*out*/uint32_t* numRequestProcessed) = 0;
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800400
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800401 virtual status_t flush() = 0;
Yin-Chia Yeh7447f0f2018-10-11 15:28:12 -0700402
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800403 virtual status_t dump(int fd) = 0;
Yin-Chia Yehb978c382019-10-30 00:22:37 -0700404
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800405 virtual status_t close() = 0;
406
407 virtual void signalPipelineDrain(const std::vector<int>& streamIds) = 0;
408
409 virtual bool isReconfigurationRequired(CameraMetadata& oldSessionParams,
410 CameraMetadata& newSessionParams) = 0;
411
412 virtual status_t repeatingRequestEnd(uint32_t frameNumber,
413 const std::vector<int32_t> &streamIds) = 0;
Emilian Peev2295df72021-11-12 18:14:10 -0800414
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800415 /////////////////////////////////////////////////////////////////////
416 // Implements BufferRecordsInterface
Yin-Chia Yehd5cd5ff2018-10-01 14:43:04 -0700417
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800418 std::pair<bool, uint64_t> getBufferId(
419 const buffer_handle_t& buf, int streamId) override;
420
Shuzhen Wangcd5b1822021-09-07 11:52:48 -0700421 uint64_t removeOneBufferCache(int streamId, const native_handle_t* handle) override;
422
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800423 status_t popInflightBuffer(int32_t frameNumber, int32_t streamId,
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800424 /*out*/ buffer_handle_t **buffer) override;
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800425
Yin-Chia Yeh84be5782019-03-01 11:47:02 -0800426 status_t pushInflightRequestBuffer(
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800427 uint64_t bufferId, buffer_handle_t* buf, int32_t streamId) override;
Yin-Chia Yehd5cd5ff2018-10-01 14:43:04 -0700428
Yin-Chia Yeh84be5782019-03-01 11:47:02 -0800429 status_t popInflightRequestBuffer(uint64_t bufferId,
430 /*out*/ buffer_handle_t** buffer,
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800431 /*optional out*/ int32_t* streamId = nullptr) override;
432
433 /////////////////////////////////////////////////////////////////////
Yin-Chia Yehd5cd5ff2018-10-01 14:43:04 -0700434
Yin-Chia Yehf3fe36f2017-07-07 18:23:18 -0700435 // Get a vector of (frameNumber, streamId) pair of currently inflight
436 // buffers
437 void getInflightBufferKeys(std::vector<std::pair<int32_t, int32_t>>* out);
438
Yin-Chia Yeh84be5782019-03-01 11:47:02 -0800439 // Get a vector of bufferId of currently inflight buffers
440 void getInflightRequestBufferKeys(std::vector<uint64_t>* out);
441
Yin-Chia Yeh573a2702019-04-17 10:08:55 -0700442 void onStreamReConfigured(int streamId);
443
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800444 protected:
Yin-Chia Yehf8e28fb2019-05-16 11:46:54 -0700445
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800446 // Return true if the input caches match what we have; otherwise false
447 bool verifyBufferIds(int32_t streamId, std::vector<uint64_t>& inBufIds);
Yin-Chia Yehf8e28fb2019-05-16 11:46:54 -0700448
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800449 template <typename OfflineSessionInfoT>
450 status_t verifyBufferCaches(
451 const OfflineSessionInfoT *offlineSessionInfo, camera3::BufferRecords *bufferRecords) {
452 // Validate buffer caches
453 std::vector<int32_t> streams;
454 streams.reserve(offlineSessionInfo->offlineStreams.size());
455 for (auto offlineStream : offlineSessionInfo->offlineStreams) {
456 int32_t id = offlineStream.id;
457 streams.push_back(id);
458 // Verify buffer caches
459 std::vector<uint64_t> bufIds(offlineStream.circulatingBufferIds.begin(),
460 offlineStream.circulatingBufferIds.end());
Emilian Peev2b7ab9d2022-05-25 16:45:18 -0700461 {
462 // Due to timing it is possible that we may not have any remaining pending
463 // capture requests that can update the caches on Hal side. This can result in
464 // buffer cache mismatch between the service and the Hal and must be accounted
465 // for.
466 std::lock_guard<std::mutex> l(mFreedBuffersLock);
467 for (const auto& it : mFreedBuffers) {
468 if (it.first == id) {
469 ALOGV("%s: stream ID %d buffer id %" PRIu64 " cache removal still "
470 "pending", __FUNCTION__, id, it.second);
471 const auto& cachedEntry = std::find(bufIds.begin(), bufIds.end(),
472 it.second);
473 if (cachedEntry != bufIds.end()) {
474 bufIds.erase(cachedEntry);
475 } else {
476 ALOGE("%s: stream ID %d buffer id %" PRIu64 " cache removal still "
477 "pending however buffer is no longer in the offline stream "
478 "info!", __FUNCTION__, id, it.second);
479 }
480 }
481 }
482 }
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800483 if (!verifyBufferIds(id, bufIds)) {
484 ALOGE("%s: stream ID %d buffer cache records mismatch!", __FUNCTION__, id);
485 return UNKNOWN_ERROR;
486 }
487 }
488
489 // Move buffer records
490 bufferRecords->takeBufferCaches(mBufferRecords, streams);
491 bufferRecords->takeInflightBufferMap(mBufferRecords);
492 bufferRecords->takeRequestedBufferMap(mBufferRecords);
493 return OK;
494 }
495
Yin-Chia Yehbe83fa72017-03-30 13:35:36 -0700496 virtual void onBufferFreed(int streamId, const native_handle_t* handle) override;
497
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800498 std::mutex mFreedBuffersLock;
Yin-Chia Yehbe83fa72017-03-30 13:35:36 -0700499 std::vector<std::pair<int, uint64_t>> mFreedBuffers;
Yin-Chia Yehd5cd5ff2018-10-01 14:43:04 -0700500
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800501 // Keep track of buffer cache and inflight buffer records
502 camera3::BufferRecords mBufferRecords;
Yin-Chia Yeh7447f0f2018-10-11 15:28:12 -0700503
504 uint32_t mNextStreamConfigCounter = 1;
Yin-Chia Yeh651fe2e2018-11-13 11:49:31 -0800505
506 const bool mUseHalBufManager;
Emilian Peev4ec17882019-01-24 17:16:58 -0800507 bool mIsReconfigurationQuerySupported;
Yin-Chia Yehb978c382019-10-30 00:22:37 -0700508
509 const bool mSupportOfflineProcessing;
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800510 }; // class HalInterface
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800511
Yin-Chia Yehdb1e8642017-07-14 15:19:30 -0700512 sp<HalInterface> mInterface;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800513
514 CameraMetadata mDeviceInfo;
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -0800515 bool mSupportNativeZoomRatio;
Shuzhen Wang2e7f58f2018-07-11 14:00:29 -0700516 std::unordered_map<std::string, CameraMetadata> mPhysicalDeviceInfoMap;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800517
Emilian Peevf4816702020-04-03 15:44:51 -0700518 CameraMetadata mRequestTemplateCache[CAMERA_TEMPLATE_COUNT];
Zhijun Hea1530f12014-09-14 12:44:20 -0700519
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700520 struct Size {
521 uint32_t width;
522 uint32_t height;
Chih-Hung Hsieh8b0b9712016-08-09 14:25:53 -0700523 explicit Size(uint32_t w = 0, uint32_t h = 0) : width(w), height(h){}
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700524 };
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700525
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700526 enum Status {
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800527 STATUS_ERROR,
528 STATUS_UNINITIALIZED,
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700529 STATUS_UNCONFIGURED,
530 STATUS_CONFIGURED,
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800531 STATUS_ACTIVE
532 } mStatus;
Ruben Brunk183f0562015-08-12 12:55:02 -0700533
534 // Only clear mRecentStatusUpdates, mStatusWaiters from waitUntilStateThenRelock
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700535 Vector<Status> mRecentStatusUpdates;
Ruben Brunk183f0562015-08-12 12:55:02 -0700536 int mStatusWaiters;
537
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700538 Condition mStatusChanged;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800539
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700540 // Tracking cause of fatal errors when in STATUS_ERROR
541 String8 mErrorCause;
542
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800543 camera3::StreamSet mOutputStreams;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800544 sp<camera3::Camera3Stream> mInputStream;
Shuzhen Wang83bff122020-11-20 15:51:39 -0800545 bool mIsInputStreamMultiResolution;
Shuzhen Wang316781a2020-08-18 18:11:01 -0700546 SessionStatsBuilder mSessionStatsBuilder;
Shuzhen Wang99080502021-03-07 21:08:20 -0800547 // Map from stream group ID to physical cameras backing the stream group
548 std::map<int32_t, std::set<String8>> mGroupIdPhysicalCameraMap;
Shuzhen Wang316781a2020-08-18 18:11:01 -0700549
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800550 int mNextStreamId;
Eino-Ville Talvalaea26c772013-06-11 16:04:06 -0700551 bool mNeedConfig;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800552
Ivan Lozanoc0ad82f2020-07-30 09:32:57 -0400553 int mFakeStreamId;
Eino-Ville Talvala16a2ada2014-08-27 14:41:33 -0700554
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700555 // Whether to send state updates upstream
556 // Pause when doing transparent reconfiguration
557 bool mPauseStateNotify;
558
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800559 // Need to hold on to stream references until configure completes.
Igor Murashkin2fba5842013-04-22 14:03:54 -0700560 Vector<sp<camera3::Camera3StreamInterface> > mDeletedStreams;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800561
Zhijun He204e3292014-07-14 17:09:23 -0700562 // Whether the HAL will send partial result
563 bool mUsePartialResult;
564
565 // Number of partial results that will be delivered by the HAL.
566 uint32_t mNumPartialResults;
Eino-Ville Talvalafd6ecdd2013-10-11 09:51:09 -0700567
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800568 /**** End scope for mLock ****/
569
Shuzhen Wange4208922022-02-01 16:52:48 -0800570 bool mDeviceTimeBaseIsRealtime;
Shuzhen Wangc28dccc2016-02-11 23:48:46 -0800571 // The offset converting from clock domain of other subsystem
572 // (video/hardware composer) to that of camera. Assumption is that this
573 // offset won't change during the life cycle of the camera device. In other
574 // words, camera device shouldn't be open during CPU suspend.
575 nsecs_t mTimestampOffset;
576
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800577 class CaptureRequest : public LightRefBase<CaptureRequest> {
578 public:
Emilian Peevaebbe412018-01-15 13:53:24 +0000579 PhysicalCameraSettingsList mSettingsList;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800580 sp<camera3::Camera3Stream> mInputStream;
Emilian Peevf4816702020-04-03 15:44:51 -0700581 camera_stream_buffer_t mInputBuffer;
Shuzhen Wang83bff122020-11-20 15:51:39 -0800582 camera3::Size mInputBufferSize;
Igor Murashkin2fba5842013-04-22 14:03:54 -0700583 Vector<sp<camera3::Camera3OutputStreamInterface> >
584 mOutputStreams;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700585 SurfaceMap mOutputSurfaces;
Jianing Weicb0652e2014-03-12 18:29:36 -0700586 CaptureResultExtras mResultExtras;
Chien-Yu Chen85a64552015-08-28 15:46:12 -0700587 // The number of requests that should be submitted to HAL at a time.
588 // For example, if batch size is 8, this request and the following 7
589 // requests will be submitted to HAL at a time. The batch size for
590 // the following 7 requests will be ignored by the request thread.
591 int mBatchSize;
Shuzhen Wang9d066012016-09-30 11:30:20 -0700592 // Whether this request is from a repeating or repeating burst.
593 bool mRepeating;
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800594 // Whether this request has ROTATE_AND_CROP_AUTO set, so needs both
595 // overriding of ROTATE_AND_CROP value and adjustment of coordinates
596 // in several other controls in both the request and the result
597 bool mRotateAndCropAuto;
Eino-Ville Talvala305cec62020-11-12 14:18:17 -0800598
Shuzhen Wangd1d051a2020-08-20 15:42:23 -0700599 // Whether this capture request has its zoom ratio set to 1.0x before
600 // the framework overrides it for camera HAL consumption.
601 bool mZoomRatioIs1x;
Shuzhen Wang316781a2020-08-18 18:11:01 -0700602 // The systemTime timestamp when the request is created.
603 nsecs_t mRequestTimeNs;
Shuzhen Wangd1d051a2020-08-20 15:42:23 -0700604
Shuzhen Wangd1d051a2020-08-20 15:42:23 -0700605 // Whether this capture request's distortion correction update has
606 // been done.
607 bool mDistortionCorrectionUpdated = false;
608 // Whether this capture request's rotation and crop update has been
609 // done.
610 bool mRotationAndCropUpdated = false;
611 // Whether this capture request's zoom ratio update has been done.
612 bool mZoomRatioUpdated = false;
Jayant Chowdhary9255ce02021-07-15 11:18:17 -0700613 // Whether this max resolution capture request's crop / metering region update has been
614 // done.
615 bool mUHRCropAndMeteringRegionsUpdated = false;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800616 };
617 typedef List<sp<CaptureRequest> > RequestList;
618
Jianing Wei90e59c92014-03-12 18:29:36 -0700619 status_t checkStatusOkToCaptureLocked();
620
621 status_t convertMetadataListToRequestListLocked(
Emilian Peevaebbe412018-01-15 13:53:24 +0000622 const List<const PhysicalCameraSettingsList> &metadataList,
Shuzhen Wang0129d522016-10-30 22:43:41 -0700623 const std::list<const SurfaceMap> &surfaceMaps,
Shuzhen Wang316781a2020-08-18 18:11:01 -0700624 bool repeating, nsecs_t requestTimeNs,
Jianing Wei2d6bb3f2014-04-11 10:00:31 -0700625 /*out*/
626 RequestList *requestList);
Jianing Wei90e59c92014-03-12 18:29:36 -0700627
Emilian Peevaebbe412018-01-15 13:53:24 +0000628 void convertToRequestList(List<const PhysicalCameraSettingsList>& requestsList,
Shuzhen Wang0129d522016-10-30 22:43:41 -0700629 std::list<const SurfaceMap>& surfaceMaps,
630 const CameraMetadata& request);
631
Emilian Peevaebbe412018-01-15 13:53:24 +0000632 status_t submitRequestsHelper(const List<const PhysicalCameraSettingsList> &requestsList,
Shuzhen Wang0129d522016-10-30 22:43:41 -0700633 const std::list<const SurfaceMap> &surfaceMaps,
634 bool repeating,
Jianing Weicb0652e2014-03-12 18:29:36 -0700635 int64_t *lastFrameNumber = NULL);
Jianing Wei90e59c92014-03-12 18:29:36 -0700636
Yifan Honga640c5a2017-04-12 16:30:31 -0700637 // lock to ensure only one processCaptureResult is called at a time.
638 Mutex mProcessCaptureResultLock;
639
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800640 /**
641 * Common initialization code shared by both HAL paths
642 *
643 * Must be called with mLock and mInterfaceLock held.
644 */
645 status_t initializeCommonLocked();
646
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800647 /**
Igor Murashkin1e479c02013-09-06 16:55:14 -0700648 * Get the last request submitted to the hal by the request thread.
649 *
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800650 * Must be called with mLock held.
Igor Murashkin1e479c02013-09-06 16:55:14 -0700651 */
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700652 virtual CameraMetadata getLatestRequestLocked();
Igor Murashkin1e479c02013-09-06 16:55:14 -0700653
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800654 virtual status_t injectionCameraInitialize(const String8 &injectCamId,
655 sp<CameraProviderManager> manager) = 0;
656
Igor Murashkin1e479c02013-09-06 16:55:14 -0700657 /**
Ruben Brunk183f0562015-08-12 12:55:02 -0700658 * Update the current device status and wake all waiting threads.
659 *
660 * Must be called with mLock held.
661 */
662 void internalUpdateStatusLocked(Status status);
663
664 /**
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700665 * Pause processing and flush everything, but don't tell the clients.
666 * This is for reconfiguring outputs transparently when according to the
667 * CameraDeviceBase interface we shouldn't need to.
668 * Must be called with mLock and mInterfaceLock both held.
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800669 */
Yin-Chia Yeh598fc602017-07-24 11:37:23 -0700670 status_t internalPauseAndWaitLocked(nsecs_t maxExpectedDuration);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700671
672 /**
673 * Resume work after internalPauseAndWaitLocked()
674 * Must be called with mLock and mInterfaceLock both held.
675 */
676 status_t internalResumeLocked();
677
678 /**
679 * Wait until status tracker tells us we've transitioned to the target state
680 * set, which is either ACTIVE when active==true or IDLE (which is any
681 * non-ACTIVE state) when active==false.
682 *
683 * Needs to be called with mLock and mInterfaceLock held. This means there
684 * can ever only be one waiter at most.
685 *
686 * During the wait mLock is released.
687 *
688 */
689 status_t waitUntilStateThenRelock(bool active, nsecs_t timeout);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800690
691 /**
Zhijun He69a37482014-03-23 18:44:49 -0700692 * Implementation of waitUntilDrained. On success, will transition to IDLE state.
693 *
694 * Need to be called with mLock and mInterfaceLock held.
695 */
Yin-Chia Yeh598fc602017-07-24 11:37:23 -0700696 status_t waitUntilDrainedLocked(nsecs_t maxExpectedDuration);
Zhijun He69a37482014-03-23 18:44:49 -0700697
698 /**
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800699 * Do common work for setting up a streaming or single capture request.
700 * On success, will transition to ACTIVE if in IDLE.
701 */
Emilian Peevaebbe412018-01-15 13:53:24 +0000702 sp<CaptureRequest> setUpRequestLocked(const PhysicalCameraSettingsList &request,
Shuzhen Wang0129d522016-10-30 22:43:41 -0700703 const SurfaceMap &surfaceMap);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800704
705 /**
706 * Build a CaptureRequest request from the CameraDeviceBase request
707 * settings.
708 */
Emilian Peevaebbe412018-01-15 13:53:24 +0000709 sp<CaptureRequest> createCaptureRequest(const PhysicalCameraSettingsList &request,
Shuzhen Wang0129d522016-10-30 22:43:41 -0700710 const SurfaceMap &surfaceMap);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800711
712 /**
Emilian Peevac3ce6c2017-12-12 15:27:02 +0000713 * Internally re-configure camera device using new session parameters.
Emilian Peev3bead5f2020-05-28 17:29:08 -0700714 * This will get triggered by the request thread.
Emilian Peevac3ce6c2017-12-12 15:27:02 +0000715 */
Emilian Peev3bead5f2020-05-28 17:29:08 -0700716 bool reconfigureCamera(const CameraMetadata& sessionParams, int clientStatusId);
Emilian Peevac3ce6c2017-12-12 15:27:02 +0000717
718 /**
Emilian Peev0d0191e2020-04-21 17:01:18 -0700719 * Return true in case of any output or input abandoned streams,
720 * otherwise return false.
721 */
722 bool checkAbandonedStreamsLocked();
723
724 /**
Emilian Peevac3ce6c2017-12-12 15:27:02 +0000725 * Filter stream session parameters and configure camera HAL.
726 */
727 status_t filterParamsAndConfigureLocked(const CameraMetadata& sessionParams,
728 int operatingMode);
729
730 /**
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800731 * Take the currently-defined set of streams and configure the HAL to use
732 * them. This is a long-running operation (may be several hundered ms).
733 */
Emilian Peev5fbe0ba2017-10-20 15:45:45 +0100734 status_t configureStreamsLocked(int operatingMode,
Emilian Peevac3ce6c2017-12-12 15:27:02 +0000735 const CameraMetadata& sessionParams, bool notifyRequestThread = true);
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800736
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700737 /**
Chien-Yu Chen9b5860b2016-06-10 13:39:09 -0700738 * Cancel stream configuration that did not finish successfully.
739 */
740 void cancelStreamsConfigurationLocked();
741
742 /**
Ivan Lozanoc0ad82f2020-07-30 09:32:57 -0400743 * Add a fake stream to the current stream set as a workaround for
Eino-Ville Talvala16a2ada2014-08-27 14:41:33 -0700744 * not allowing 0 streams in the camera HAL spec.
745 */
Ivan Lozanoc0ad82f2020-07-30 09:32:57 -0400746 status_t addFakeStreamLocked();
Eino-Ville Talvala16a2ada2014-08-27 14:41:33 -0700747
748 /**
Ivan Lozanoc0ad82f2020-07-30 09:32:57 -0400749 * Remove a fake stream if the current config includes real streams.
Eino-Ville Talvala16a2ada2014-08-27 14:41:33 -0700750 */
Ivan Lozanoc0ad82f2020-07-30 09:32:57 -0400751 status_t tryRemoveFakeStreamLocked();
Eino-Ville Talvala16a2ada2014-08-27 14:41:33 -0700752
753 /**
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700754 * Set device into an error state due to some fatal failure, and set an
755 * error message to indicate why. Only the first call's message will be
756 * used. The message is also sent to the log.
757 */
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800758 void setErrorState(const char *fmt, ...) override;
759 void setErrorStateLocked(const char *fmt, ...) override;
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700760 void setErrorStateV(const char *fmt, va_list args);
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700761 void setErrorStateLockedV(const char *fmt, va_list args);
762
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800763 /////////////////////////////////////////////////////////////////////
764 // Implements InflightRequestUpdateInterface
765
766 void onInflightEntryRemovedLocked(nsecs_t duration) override;
767 void checkInflightMapLengthLocked() override;
768 void onInflightMapFlushedLocked() override;
769
770 /////////////////////////////////////////////////////////////////////
771
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700772 /**
773 * Debugging trylock/spin method
774 * Try to acquire a lock a few times with sleeps between before giving up.
775 */
776 bool tryLockSpinRightRound(Mutex& lock);
777
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700778 /**
Shuzhen Wangc28dccc2016-02-11 23:48:46 -0800779 * Helper function to get the offset between MONOTONIC and BOOTTIME
780 * timestamp.
781 */
782 static nsecs_t getMonoToBoottimeOffset();
783
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700784 struct RequestTrigger {
785 // Metadata tag number, e.g. android.control.aePrecaptureTrigger
786 uint32_t metadataTag;
787 // Metadata value, e.g. 'START' or the trigger ID
788 int32_t entryValue;
789
790 // The last part of the fully qualified path, e.g. afTrigger
791 const char *getTagName() const {
792 return get_camera_metadata_tag_name(metadataTag) ?: "NULL";
793 }
794
795 // e.g. TYPE_BYTE, TYPE_INT32, etc.
796 int getTagType() const {
797 return get_camera_metadata_tag_type(metadataTag);
798 }
799 };
800
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800801 /**
802 * Thread for managing capture request submission to HAL device.
803 */
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800804 class RequestThread : public Thread {
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800805
806 public:
807
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800808 RequestThread(wp<Camera3Device> parent,
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700809 sp<camera3::StatusTracker> statusTracker,
Yin-Chia Yehd5cd5ff2018-10-01 14:43:04 -0700810 sp<HalInterface> interface,
811 const Vector<int32_t>& sessionParamKeys,
Eino-Ville Talvala1646c3c2021-07-29 13:48:40 -0700812 bool useHalBufManager,
813 bool supportCameraMute);
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800814 ~RequestThread();
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800815
Yin-Chia Yehe1c80632016-08-08 14:48:05 -0700816 void setNotificationListener(wp<NotificationListener> listener);
Eino-Ville Talvala17543512014-08-06 14:32:02 -0700817
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800818 /**
819 * Call after stream (re)-configuration is completed.
820 */
Emilian Peevac3ce6c2017-12-12 15:27:02 +0000821 void configurationComplete(bool isConstrainedHighSpeed,
Shuzhen Wang99080502021-03-07 21:08:20 -0800822 const CameraMetadata& sessionParams,
823 const std::map<int32_t, std::set<String8>>& groupIdPhysicalCameraMap);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800824
825 /**
826 * Set or clear the list of repeating requests. Does not block
827 * on either. Use waitUntilPaused to wait until request queue
828 * has emptied out.
829 */
Jianing Wei2d6bb3f2014-04-11 10:00:31 -0700830 status_t setRepeatingRequests(const RequestList& requests,
831 /*out*/
832 int64_t *lastFrameNumber = NULL);
833 status_t clearRepeatingRequests(/*out*/
834 int64_t *lastFrameNumber = NULL);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800835
Jianing Wei2d6bb3f2014-04-11 10:00:31 -0700836 status_t queueRequestList(List<sp<CaptureRequest> > &requests,
837 /*out*/
838 int64_t *lastFrameNumber = NULL);
Jianing Wei90e59c92014-03-12 18:29:36 -0700839
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800840 /**
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -0700841 * Remove all queued and repeating requests, and pending triggers
842 */
Yin-Chia Yehe1c80632016-08-08 14:48:05 -0700843 status_t clear(/*out*/int64_t *lastFrameNumber = NULL);
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -0700844
845 /**
Chien-Yu Chen85a64552015-08-28 15:46:12 -0700846 * Flush all pending requests in HAL.
847 */
848 status_t flush();
849
850 /**
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700851 * Queue a trigger to be dispatched with the next outgoing
852 * process_capture_request. The settings for that request only
853 * will be temporarily rewritten to add the trigger tag/value.
854 * Subsequent requests will not be rewritten (for this tag).
855 */
856 status_t queueTrigger(RequestTrigger trigger[], size_t count);
857
858 /**
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800859 * Pause/unpause the capture thread. Doesn't block, so use
860 * waitUntilPaused to wait until the thread is paused.
861 */
862 void setPaused(bool paused);
863
Jayant Chowdharya93f3462022-11-01 23:32:45 +0000864 // set mRequestClearing - no new requests are expected to be queued to RequestThread
865 void setRequestClearing();
866
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800867 /**
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700868 * Wait until thread processes the capture request with settings'
869 * android.request.id == requestId.
870 *
871 * Returns TIMED_OUT in case the thread does not process the request
872 * within the timeout.
873 */
874 status_t waitUntilRequestProcessed(int32_t requestId, nsecs_t timeout);
875
Igor Murashkin1e479c02013-09-06 16:55:14 -0700876 /**
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700877 * Shut down the thread. Shutdown is asynchronous, so thread may
878 * still be running once this method returns.
879 */
880 virtual void requestExit();
881
882 /**
Igor Murashkin1e479c02013-09-06 16:55:14 -0700883 * Get the latest request that was sent to the HAL
884 * with process_capture_request.
885 */
886 CameraMetadata getLatestRequest() const;
887
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700888 /**
889 * Returns true if the stream is a target of any queued or repeating
890 * capture request
891 */
892 bool isStreamPending(sp<camera3::Camera3StreamInterface>& stream);
893
Emilian Peev40ead602017-09-26 15:46:36 +0100894 /**
895 * Returns true if the surface is a target of any queued or repeating
896 * capture request
897 */
898 bool isOutputSurfacePending(int streamId, size_t surfaceId);
899
Shuzhen Wang686f6442017-06-20 16:16:04 -0700900 // dump processCaptureRequest latency
901 void dumpCaptureRequestLatency(int fd, const char* name) {
902 mRequestLatency.dump(fd, name);
903 }
904
Yin-Chia Yeh7447f0f2018-10-11 15:28:12 -0700905 void signalPipelineDrain(const std::vector<int>& streamIds);
Yin-Chia Yehe52b8fa2020-07-28 00:17:58 -0700906 void resetPipelineDrain();
Yin-Chia Yeh7447f0f2018-10-11 15:28:12 -0700907
Emilian Peevc0fe54c2020-03-11 14:05:07 -0700908 void clearPreviousRequest();
909
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800910 status_t setRotateAndCropAutoBehavior(
911 camera_metadata_enum_android_scaler_rotate_and_crop_t rotateAndCropValue);
Emilian Peeve23f1d92021-09-20 14:56:01 -0700912 status_t setComposerSurface(bool composerSurfacePresent);
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800913
Eino-Ville Talvala11afe4f2021-05-27 14:45:31 -0700914 status_t setCameraMute(int32_t muteMode);
Cliff Wuc2ad9c82021-04-21 00:58:58 +0800915
916 status_t setHalInterface(sp<HalInterface> newHalInterface);
917
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800918 protected:
919
920 virtual bool threadLoop();
921
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800922 static const String8& getId(const wp<Camera3Device> &device);
Eino-Ville Talvala42368d92013-04-09 14:13:50 -0700923
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700924 status_t queueTriggerLocked(RequestTrigger trigger);
925 // Mix-in queued triggers into this request
926 int32_t insertTriggers(const sp<CaptureRequest> &request);
927 // Purge the queued triggers from this request,
928 // restoring the old field values for those tags.
929 status_t removeTriggers(const sp<CaptureRequest> &request);
930
Eino-Ville Talvala2f876f92013-09-13 11:39:24 -0700931 // HAL workaround: Make sure a trigger ID always exists if
932 // a trigger does
Ivan Lozanoc0ad82f2020-07-30 09:32:57 -0400933 status_t addFakeTriggerIds(const sp<CaptureRequest> &request);
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800934
935 // Override rotate_and_crop control if needed; returns true if the current value was changed
936 bool overrideAutoRotateAndCrop(const sp<CaptureRequest> &request);
Eino-Ville Talvala2f876f92013-09-13 11:39:24 -0700937
Eino-Ville Talvala305cec62020-11-12 14:18:17 -0800938 // Override test_pattern control if needed for camera mute; returns true
939 // if the current value was changed
940 bool overrideTestPattern(const sp<CaptureRequest> &request);
941
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800942 static const nsecs_t kRequestTimeout = 50e6; // 50 ms
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800943
Yin-Chia Yehb978c382019-10-30 00:22:37 -0700944 // TODO: does this need to be adjusted for long exposure requests?
945 static const nsecs_t kRequestSubmitTimeout = 200e6; // 200 ms
946
Chien-Yu Chen85a64552015-08-28 15:46:12 -0700947 // Used to prepare a batch of requests.
948 struct NextRequest {
949 sp<CaptureRequest> captureRequest;
Emilian Peevf4816702020-04-03 15:44:51 -0700950 camera_capture_request_t halRequest;
951 Vector<camera_stream_buffer_t> outputBuffers;
Chien-Yu Chen85a64552015-08-28 15:46:12 -0700952 bool submitted;
953 };
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800954
Chien-Yu Chen57ea2922015-09-04 12:58:56 -0700955 // Wait for the next batch of requests and put them in mNextRequests. mNextRequests will
956 // be empty if it times out.
957 void waitForNextRequestBatch();
Chien-Yu Chen85a64552015-08-28 15:46:12 -0700958
959 // Waits for a request, or returns NULL if times out. Must be called with mRequestLock hold.
960 sp<CaptureRequest> waitForNextRequestLocked();
961
Chien-Yu Chen57ea2922015-09-04 12:58:56 -0700962 // Prepare HAL requests and output buffers in mNextRequests. Return TIMED_OUT if getting any
963 // output buffer timed out. If an error is returned, the caller should clean up the pending
964 // request batch.
965 status_t prepareHalRequests();
Chien-Yu Chen85a64552015-08-28 15:46:12 -0700966
Chien-Yu Chen57ea2922015-09-04 12:58:56 -0700967 // Return buffers, etc, for requests in mNextRequests that couldn't be fully constructed and
968 // send request errors if sendRequestError is true. The buffers will be returned in the
969 // ERROR state to mark them as not having valid data. mNextRequests will be cleared.
970 void cleanUpFailedRequests(bool sendRequestError);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800971
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700972 // Stop the repeating request if any of its output streams is abandoned.
973 void checkAndStopRepeatingRequest();
974
Emilian Peevaebbe412018-01-15 13:53:24 +0000975 // Release physical camera settings and camera id resources.
976 void cleanupPhysicalSettings(sp<CaptureRequest> request,
Emilian Peevf4816702020-04-03 15:44:51 -0700977 /*out*/camera_capture_request_t *halRequest);
Emilian Peevaebbe412018-01-15 13:53:24 +0000978
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800979 // Pause handling
980 bool waitIfPaused();
Eino-Ville Talvala26fe6c72013-08-29 12:46:18 -0700981 void unpauseForNewRequests();
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800982
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700983 // Relay error to parent device object setErrorState
984 void setErrorState(const char *fmt, ...);
985
Yin-Chia Yeh8684b7f2014-06-13 14:53:05 -0700986 // If the input request is in mRepeatingRequests. Must be called with mRequestLock hold
Chih-Hung Hsieh8b0b9712016-08-09 14:25:53 -0700987 bool isRepeatingRequestLocked(const sp<CaptureRequest>&);
Yin-Chia Yeh8684b7f2014-06-13 14:53:05 -0700988
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700989 // Clear repeating requests. Must be called with mRequestLock held.
990 status_t clearRepeatingRequestsLocked(/*out*/ int64_t *lastFrameNumber = NULL);
991
Yin-Chia Yeh94c68e02017-03-06 14:09:44 -0800992 // send request in mNextRequests to HAL in a batch. Return true = sucssess
993 bool sendRequestsBatch();
994
Shuzhen Wang696e4da2022-09-08 14:31:13 -0700995 // Calculate the expected (minimum, maximum, isFixedFps) duration info for a request
996 struct ExpectedDurationInfo {
997 nsecs_t minDuration;
998 nsecs_t maxDuration;
999 bool isFixedFps;
1000 };
1001 ExpectedDurationInfo calculateExpectedDurationRange(
Shuzhen Wang00abbeb2022-02-25 17:14:42 -08001002 const camera_metadata_t *request);
Eino-Ville Talvala10bd57e2017-06-23 16:22:44 -07001003
Emilian Peevac3ce6c2017-12-12 15:27:02 +00001004 // Check and update latest session parameters based on the current request settings.
1005 bool updateSessionParameters(const CameraMetadata& settings);
1006
Emilian Peeva14b4dd2018-05-15 11:00:31 +01001007 // Check whether FPS range session parameter re-configuration is needed in constrained
1008 // high speed recording camera sessions.
1009 bool skipHFRTargetFPSUpdate(int32_t tag, const camera_metadata_ro_entry_t& newEntry,
1010 const camera_metadata_entry_t& currentEntry);
1011
Shuzhen Wangc2cba122018-05-17 18:10:24 -07001012 // Update next request sent to HAL
1013 void updateNextRequest(NextRequest& nextRequest);
Emilian Peevac3ce6c2017-12-12 15:27:02 +00001014
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001015 wp<Camera3Device> mParent;
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07001016 wp<camera3::StatusTracker> mStatusTracker;
Yin-Chia Yehdb1e8642017-07-14 15:19:30 -07001017 sp<HalInterface> mInterface;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001018
Yin-Chia Yehe1c80632016-08-08 14:48:05 -07001019 wp<NotificationListener> mListener;
Eino-Ville Talvala17543512014-08-06 14:32:02 -07001020
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -08001021 const String8& mId; // The camera ID
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07001022 int mStatusId; // The RequestThread's component ID for
1023 // status tracking
Eino-Ville Talvala42368d92013-04-09 14:13:50 -07001024
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001025 Mutex mRequestLock;
1026 Condition mRequestSignal;
Shuzhen Wangbb9b93d2022-04-07 13:22:48 -07001027 bool mRequestClearing;
1028
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001029 Condition mRequestSubmittedSignal;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001030 RequestList mRequestQueue;
1031 RequestList mRepeatingRequests;
Shuzhen Wang316781a2020-08-18 18:11:01 -07001032 bool mFirstRepeating;
Chien-Yu Chen57ea2922015-09-04 12:58:56 -07001033 // The next batch of requests being prepped for submission to the HAL, no longer
Eino-Ville Talvalae74c2282015-05-27 14:46:23 -07001034 // on the request queue. Read-only even with mRequestLock held, outside
1035 // of threadLoop
Chien-Yu Chen57ea2922015-09-04 12:58:56 -07001036 Vector<NextRequest> mNextRequests;
Chien-Yu Chen85a64552015-08-28 15:46:12 -07001037
1038 // To protect flush() and sending a request batch to HAL.
1039 Mutex mFlushLock;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001040
1041 bool mReconfigured;
1042
Yin-Chia Yeh7447f0f2018-10-11 15:28:12 -07001043 // Used by waitIfPaused, waitForNextRequest, waitUntilPaused, and signalPipelineDrain
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001044 Mutex mPauseLock;
1045 bool mDoPause;
1046 Condition mDoPauseSignal;
1047 bool mPaused;
Yin-Chia Yeh7447f0f2018-10-11 15:28:12 -07001048 bool mNotifyPipelineDrain;
1049 std::vector<int> mStreamIdsToBeDrained;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001050
1051 sp<CaptureRequest> mPrevRequest;
Igor Murashkin4d2f2e82013-04-01 17:29:07 -07001052 int32_t mPrevTriggers;
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -08001053 std::set<std::string> mPrevCameraIdsWithZoom;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001054
Eino-Ville Talvala42368d92013-04-09 14:13:50 -07001055 uint32_t mFrameNumber;
Igor Murashkin4d2f2e82013-04-01 17:29:07 -07001056
Igor Murashkin1e479c02013-09-06 16:55:14 -07001057 mutable Mutex mLatestRequestMutex;
Igor Murashkin4d2f2e82013-04-01 17:29:07 -07001058 Condition mLatestRequestSignal;
1059 // android.request.id for latest process_capture_request
1060 int32_t mLatestRequestId;
Igor Murashkin1e479c02013-09-06 16:55:14 -07001061 CameraMetadata mLatestRequest;
Shuzhen Wangc2cba122018-05-17 18:10:24 -07001062 std::unordered_map<std::string, CameraMetadata> mLatestPhysicalRequest;
Igor Murashkin4d2f2e82013-04-01 17:29:07 -07001063
1064 typedef KeyedVector<uint32_t/*tag*/, RequestTrigger> TriggerMap;
1065 Mutex mTriggerMutex;
1066 TriggerMap mTriggerMap;
1067 TriggerMap mTriggerRemovedMap;
1068 TriggerMap mTriggerReplacedMap;
Yin-Chia Yehc00a25c2014-08-21 14:27:44 -07001069 uint32_t mCurrentAfTriggerId;
1070 uint32_t mCurrentPreCaptureTriggerId;
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -08001071 camera_metadata_enum_android_scaler_rotate_and_crop_t mRotateAndCropOverride;
Emilian Peeve23f1d92021-09-20 14:56:01 -07001072 bool mComposerOutput;
Eino-Ville Talvala11afe4f2021-05-27 14:45:31 -07001073 int32_t mCameraMute; // 0 = no mute, otherwise the TEST_PATTERN_MODE to use
Eino-Ville Talvala305cec62020-11-12 14:18:17 -08001074 bool mCameraMuteChanged;
Jianing Weicb0652e2014-03-12 18:29:36 -07001075
Jianing Wei2d6bb3f2014-04-11 10:00:31 -07001076 int64_t mRepeatingLastFrameNumber;
Chien-Yu Chend196d612015-06-22 19:49:01 -07001077
Chien-Yu Chenc66969b2016-05-19 16:37:51 -07001078 // Flag indicating if we should prepare video stream for video requests.
1079 bool mPrepareVideoStream;
Shuzhen Wang686f6442017-06-20 16:16:04 -07001080
Emilian Peeva14b4dd2018-05-15 11:00:31 +01001081 bool mConstrainedMode;
1082
Shuzhen Wang686f6442017-06-20 16:16:04 -07001083 static const int32_t kRequestLatencyBinSize = 40; // in ms
1084 CameraLatencyHistogram mRequestLatency;
Emilian Peevac3ce6c2017-12-12 15:27:02 +00001085
1086 Vector<int32_t> mSessionParamKeys;
1087 CameraMetadata mLatestSessionParams;
Yin-Chia Yehd5cd5ff2018-10-01 14:43:04 -07001088
Shuzhen Wang99080502021-03-07 21:08:20 -08001089 std::map<int32_t, std::set<String8>> mGroupIdPhysicalCameraMap;
1090
Yin-Chia Yehd5cd5ff2018-10-01 14:43:04 -07001091 const bool mUseHalBufManager;
Eino-Ville Talvala1646c3c2021-07-29 13:48:40 -07001092 const bool mSupportCameraMute;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -08001093 };
Jayant Chowdhary22441f32021-12-26 18:35:41 -08001094
1095 virtual sp<RequestThread> createNewRequestThread(wp<Camera3Device> /*parent*/,
1096 sp<camera3::StatusTracker> /*statusTracker*/,
1097 sp<HalInterface> /*interface*/,
1098 const Vector<int32_t>& /*sessionParamKeys*/,
1099 bool /*useHalBufManager*/,
1100 bool /*supportCameraMute*/) = 0;
1101
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -08001102 sp<RequestThread> mRequestThread;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -08001103
1104 /**
Eino-Ville Talvala42368d92013-04-09 14:13:50 -07001105 * In-flight queue for tracking completion of capture requests.
1106 */
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -08001107 std::mutex mInFlightLock;
1108 camera3::InFlightRequestMap mInFlightMap;
1109 nsecs_t mExpectedInflightDuration = 0;
Shuzhen Wangb7b42652020-05-07 11:59:02 -07001110 int64_t mLastCompletedRegularFrameNumber = -1;
1111 int64_t mLastCompletedReprocessFrameNumber = -1;
1112 int64_t mLastCompletedZslFrameNumber = -1;
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -08001113 // End of mInFlightLock protection scope
Eino-Ville Talvala42368d92013-04-09 14:13:50 -07001114
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -08001115 int mInFlightStatusId; // const after initialize
Eino-Ville Talvala42368d92013-04-09 14:13:50 -07001116
Jianing Weicb0652e2014-03-12 18:29:36 -07001117 status_t registerInFlight(uint32_t frameNumber,
Chien-Yu Chend196d612015-06-22 19:49:01 -07001118 int32_t numBuffers, CaptureResultExtras resultExtras, bool hasInput,
Shuzhen Wang00abbeb2022-02-25 17:14:42 -08001119 bool callback, nsecs_t minExpectedDuration, nsecs_t maxExpectedDuration,
Shuzhen Wang696e4da2022-09-08 14:31:13 -07001120 bool isFixedFps, const std::set<std::set<String8>>& physicalCameraIds,
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -08001121 bool isStillCapture, bool isZslCapture, bool rotateAndCropAuto,
Shuzhen Wang316781a2020-08-18 18:11:01 -07001122 const std::set<std::string>& cameraIdsWithZoom, const SurfaceMap& outputSurfaces,
1123 nsecs_t requestTimeNs);
Eino-Ville Talvala10bd57e2017-06-23 16:22:44 -07001124
1125 /**
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07001126 * Tracking for idle detection
1127 */
1128 sp<camera3::StatusTracker> mStatusTracker;
Eino-Ville Talvala42368d92013-04-09 14:13:50 -07001129
1130 /**
Zhijun He125684a2015-12-26 15:07:30 -08001131 * Graphic buffer manager for output streams. Each device has a buffer manager, which is used
1132 * by the output streams to get and return buffers if these streams are registered to this
1133 * buffer manager.
1134 */
1135 sp<camera3::Camera3BufferManager> mBufferManager;
1136
1137 /**
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001138 * Thread for preparing streams
1139 */
1140 class PreparerThread : private Thread, public virtual RefBase {
1141 public:
1142 PreparerThread();
1143 ~PreparerThread();
1144
Yin-Chia Yehe1c80632016-08-08 14:48:05 -07001145 void setNotificationListener(wp<NotificationListener> listener);
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001146
1147 /**
Ruben Brunkc78ac262015-08-13 17:58:46 -07001148 * Queue up a stream to be prepared. Streams are processed by a background thread in FIFO
1149 * order. Pre-allocate up to maxCount buffers for the stream, or the maximum number needed
1150 * for the pipeline if maxCount is ALLOCATE_PIPELINE_MAX.
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001151 */
Ruben Brunkc78ac262015-08-13 17:58:46 -07001152 status_t prepare(int maxCount, sp<camera3::Camera3StreamInterface>& stream);
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001153
1154 /**
1155 * Cancel all current and pending stream preparation
1156 */
1157 status_t clear();
1158
Emilian Peevac3ce6c2017-12-12 15:27:02 +00001159 /**
1160 * Pause all preparation activities
1161 */
1162 void pause();
1163
1164 /**
1165 * Resume preparation activities
1166 */
1167 status_t resume();
1168
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001169 private:
1170 Mutex mLock;
Emilian Peevac3ce6c2017-12-12 15:27:02 +00001171 Condition mThreadActiveSignal;
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001172
1173 virtual bool threadLoop();
1174
1175 // Guarded by mLock
1176
Yin-Chia Yehe1c80632016-08-08 14:48:05 -07001177 wp<NotificationListener> mListener;
Emilian Peevac3ce6c2017-12-12 15:27:02 +00001178 std::unordered_map<int, sp<camera3::Camera3StreamInterface> > mPendingStreams;
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001179 bool mActive;
1180 bool mCancelNow;
1181
1182 // Only accessed by threadLoop and the destructor
1183
1184 sp<camera3::Camera3StreamInterface> mCurrentStream;
Emilian Peevac3ce6c2017-12-12 15:27:02 +00001185 int mCurrentMaxCount;
1186 bool mCurrentPrepareComplete;
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001187 };
1188 sp<PreparerThread> mPreparerThread;
1189
1190 /**
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -07001191 * Output result queue and current HAL device 3A state
1192 */
1193
1194 // Lock for output side of device
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -08001195 std::mutex mOutputLock;
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -07001196
1197 /**** Scope for mOutputLock ****/
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001198 // the minimal frame number of the next non-reprocess result
Eino-Ville Talvala42368d92013-04-09 14:13:50 -07001199 uint32_t mNextResultFrameNumber;
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001200 // the minimal frame number of the next reprocess result
1201 uint32_t mNextReprocessResultFrameNumber;
Shuzhen Wang5ee99842019-04-12 11:55:48 -07001202 // the minimal frame number of the next ZSL still capture result
1203 uint32_t mNextZslStillResultFrameNumber;
Chien-Yu Chen3df11ce2015-09-30 14:13:30 -07001204 // the minimal frame number of the next non-reprocess shutter
Eino-Ville Talvala42368d92013-04-09 14:13:50 -07001205 uint32_t mNextShutterFrameNumber;
Chien-Yu Chen3df11ce2015-09-30 14:13:30 -07001206 // the minimal frame number of the next reprocess shutter
1207 uint32_t mNextReprocessShutterFrameNumber;
Shuzhen Wang5ee99842019-04-12 11:55:48 -07001208 // the minimal frame number of the next ZSL still capture shutter
1209 uint32_t mNextZslStillShutterFrameNumber;
Jayant Chowdhary8a0be292020-01-08 13:10:38 -08001210 std::list<CaptureResult> mResultQueue;
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -08001211 std::condition_variable mResultSignal;
1212 wp<NotificationListener> mListener;
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -07001213
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -07001214 /**** End scope for mOutputLock ****/
1215
Chien-Yu Chen43e69a62014-11-25 16:38:33 -08001216 /**** Scope for mInFlightLock ****/
1217
Shuzhen Wangcadb3302016-11-04 14:17:56 -07001218 // Remove the in-flight map entry of the given index from mInFlightMap.
1219 // It must only be called with mInFlightLock held.
1220 void removeInFlightMapEntryLocked(int idx);
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -08001221
Yin-Chia Yehf3fe36f2017-07-07 18:23:18 -07001222 // Remove all in-flight requests and return all buffers.
1223 // This is used after HAL interface is closed to cleanup any request/buffers
1224 // not returned by HAL.
1225 void flushInflightRequests();
Chien-Yu Chen43e69a62014-11-25 16:38:33 -08001226
1227 /**** End scope for mInFlightLock ****/
1228
Eino-Ville Talvala7b8a1fd2018-05-22 15:30:35 -07001229 /**
1230 * Distortion correction support
1231 */
Shuzhen Wang4f6fa9d2019-03-29 10:40:35 -07001232 // Map from camera IDs to its corresponding distortion mapper. Only contains
1233 // 1 ID if the device isn't a logical multi-camera. Otherwise contains both
1234 // logical camera and its physical subcameras.
1235 std::unordered_map<std::string, camera3::DistortionMapper> mDistortionMappers;
Eino-Ville Talvala7b8a1fd2018-05-22 15:30:35 -07001236
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -08001237 /**
1238 * Zoom ratio mapper support
1239 */
1240 std::unordered_map<std::string, camera3::ZoomRatioMapper> mZoomRatioMappers;
1241
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -08001242 /**
Jayant Chowdhary9255ce02021-07-15 11:18:17 -07001243 * UHR request crop / metering region mapper support
1244 */
1245 std::unordered_map<std::string, camera3::UHRCropAndMeteringRegionMapper>
1246 mUHRCropAndMeteringRegionMappers;
1247
1248 /**
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -08001249 * RotateAndCrop mapper support
1250 */
1251 std::unordered_map<std::string, camera3::RotateAndCropMapper> mRotateAndCropMappers;
1252
Eino-Ville Talvala4d453832016-07-15 11:56:53 -07001253 // Debug tracker for metadata tag value changes
1254 // - Enabled with the -m <taglist> option to dumpsys, such as
1255 // dumpsys -m android.control.aeState,android.control.aeMode
1256 // - Disabled with -m off
1257 // - dumpsys -m 3a is a shortcut for ae/af/awbMode, State, and Triggers
1258 TagMonitor mTagMonitor;
1259
1260 void monitorMetadata(TagMonitor::eventSource source, int64_t frameNumber,
Shuzhen Wangc2cba122018-05-17 18:10:24 -07001261 nsecs_t timestamp, const CameraMetadata& metadata,
Jayant Chowdharycd277cd2021-08-11 15:48:40 -07001262 const std::unordered_map<std::string, CameraMetadata>& physicalMetadata,
Jayant Chowdharyc30b4c32021-08-18 11:43:16 -07001263 const camera_stream_buffer_t *outputBuffers, uint32_t numOutputBuffers,
1264 int32_t inputStreamId);
Eino-Ville Talvala4d453832016-07-15 11:56:53 -07001265
Emilian Peev71c73a22017-03-21 16:35:51 +00001266 metadata_vendor_id_t mVendorTagId;
1267
Emilian Peev811d2952018-05-25 11:08:40 +01001268 // Cached last requested template id
1269 int mLastTemplateId;
1270
Emilian Peev26d975d2018-07-05 14:52:57 +01001271 // Synchronizes access to status tracker between inflight updates and disconnect.
1272 // b/79972865
1273 Mutex mTrackerLock;
Yin-Chia Yehd5cd5ff2018-10-01 14:43:04 -07001274
Yin-Chia Yeh30ab5ed2018-10-12 15:57:04 -07001275 // Whether HAL request buffers through requestStreamBuffers API
Yin-Chia Yehd5cd5ff2018-10-01 14:43:04 -07001276 bool mUseHalBufManager = false;
1277
1278 // Lock to ensure requestStreamBuffers() callbacks are serialized
1279 std::mutex mRequestBufferInterfaceLock;
1280
Yin-Chia Yeh30ab5ed2018-10-12 15:57:04 -07001281 // The state machine to control when requestStreamBuffers should allow
1282 // HAL to request buffers.
1283 enum RequestBufferState {
1284 /**
1285 * This is the initial state.
1286 * requestStreamBuffers call will return FAILED_CONFIGURING in this state.
1287 * Will switch to RB_STATUS_READY after a successful configureStreams or
1288 * processCaptureRequest call.
1289 */
1290 RB_STATUS_STOPPED,
1291
1292 /**
1293 * requestStreamBuffers call will proceed in this state.
1294 * When device is asked to stay idle via waitUntilStateThenRelock() call:
1295 * - Switch to RB_STATUS_STOPPED if there is no inflight requests and
1296 * request thread is paused.
1297 * - Switch to RB_STATUS_PENDING_STOP otherwise
1298 */
1299 RB_STATUS_READY,
1300
1301 /**
1302 * requestStreamBuffers call will proceed in this state.
1303 * Switch to RB_STATUS_STOPPED when all inflight requests are fulfilled
1304 * and request thread is paused
1305 */
1306 RB_STATUS_PENDING_STOP,
1307 };
1308
1309 class RequestBufferStateMachine {
1310 public:
1311 status_t initialize(sp<camera3::StatusTracker> statusTracker);
1312
1313 // Return if the state machine currently allows for requestBuffers
1314 // If the state allows for it, mRequestBufferOngoing will be set to true
1315 // and caller must call endRequestBuffer() later to unset the flag
1316 bool startRequestBuffer();
1317 void endRequestBuffer();
1318
1319 // Events triggered by application API call
1320 void onStreamsConfigured();
1321 void onWaitUntilIdle();
1322
1323 // Events usually triggered by hwBinder processCaptureResult callback thread
1324 // But can also be triggered on request thread for failed request, or on
1325 // hwbinder notify callback thread for shutter/error callbacks
1326 void onInflightMapEmpty();
1327
1328 // Events triggered by RequestThread
Yin-Chia Yehcd333fe2019-02-08 13:45:41 -08001329 void onSubmittingRequest();
Yin-Chia Yeh30ab5ed2018-10-12 15:57:04 -07001330 void onRequestThreadPaused();
1331
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -08001332 // Events triggered by successful switchToOffline call
1333 // Return true is there is no ongoing requestBuffer call.
1334 bool onSwitchToOfflineSuccess();
1335
Yin-Chia Yeh30ab5ed2018-10-12 15:57:04 -07001336 private:
1337 void notifyTrackerLocked(bool active);
1338
1339 // Switch to STOPPED state and return true if all conditions allows for it.
1340 // Otherwise do nothing and return false.
1341 bool checkSwitchToStopLocked();
1342
1343 std::mutex mLock;
1344 RequestBufferState mStatus = RB_STATUS_STOPPED;
1345
1346 bool mRequestThreadPaused = true;
1347 bool mInflightMapEmpty = true;
1348 bool mRequestBufferOngoing = false;
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -08001349 bool mSwitchedToOffline = false;
Yin-Chia Yeh30ab5ed2018-10-12 15:57:04 -07001350
1351 wp<camera3::StatusTracker> mStatusTracker;
1352 int mRequestBufferStatusId;
1353 } mRequestBufferSM;
1354
Shuzhen Wang268a1362018-10-16 16:32:59 -07001355 // Fix up result metadata for monochrome camera.
1356 bool mNeedFixupMonochromeTags;
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001357
1358 // Whether HAL supports offline processing capability.
1359 bool mSupportOfflineProcessing = false;
Eino-Ville Talvala305cec62020-11-12 14:18:17 -08001360
1361 // Whether the HAL supports camera muting via test pattern
1362 bool mSupportCameraMute = false;
Eino-Ville Talvala11afe4f2021-05-27 14:45:31 -07001363 // Whether the HAL supports SOLID_COLOR or BLACK if mSupportCameraMute is true
1364 bool mSupportTestPatternSolidColor = false;
Eino-Ville Talvala305cec62020-11-12 14:18:17 -08001365
Shuzhen Wangd4abdf72021-05-28 11:22:50 -07001366 // Whether the camera framework overrides the device characteristics for
1367 // performance class.
1368 bool mOverrideForPerfClass;
1369
Shuzhen Wang00abbeb2022-02-25 17:14:42 -08001370 // The current minimum expected frame duration based on AE_TARGET_FPS_RANGE
1371 nsecs_t mMinExpectedDuration = 0;
Shuzhen Wang696e4da2022-09-08 14:31:13 -07001372 // Whether the camera device runs at fixed frame rate based on AE_MODE and
1373 // AE_TARGET_FPS_RANGE
1374 bool mIsFixedFps = false;
Shuzhen Wang00abbeb2022-02-25 17:14:42 -08001375
Cliff Wuc2ad9c82021-04-21 00:58:58 +08001376 // Injection camera related methods.
1377 class Camera3DeviceInjectionMethods : public virtual RefBase {
1378 public:
1379 Camera3DeviceInjectionMethods(wp<Camera3Device> parent);
1380
1381 ~Camera3DeviceInjectionMethods();
1382
Cliff Wuc2ad9c82021-04-21 00:58:58 +08001383 // Injection camera will replace the internal camera and configure streams
1384 // when device is IDLE and request thread is paused.
1385 status_t injectCamera(
1386 camera3::camera_stream_configuration& injectionConfig,
Cliff Wu3b268182021-07-06 15:44:43 +08001387 const std::vector<uint32_t>& injectionBufferSizes);
Cliff Wuc2ad9c82021-04-21 00:58:58 +08001388
1389 // Stop the injection camera and switch back to backup hal interface.
1390 status_t stopInjection();
1391
1392 bool isInjecting();
1393
Cliff Wu3b268182021-07-06 15:44:43 +08001394 bool isStreamConfigCompleteButNotInjected();
1395
Cliff Wuc2ad9c82021-04-21 00:58:58 +08001396 const String8& getInjectedCamId() const;
1397
1398 void getInjectionConfig(/*out*/ camera3::camera_stream_configuration* injectionConfig,
1399 /*out*/ std::vector<uint32_t>* injectionBufferSizes);
1400
Cliff Wu3b268182021-07-06 15:44:43 +08001401 // When the streaming configuration is completed and the camera device is active, but the
1402 // injection camera has not yet been injected, the streaming configuration of the internal
1403 // camera will be stored first.
1404 void storeInjectionConfig(
1405 const camera3::camera_stream_configuration& injectionConfig,
1406 const std::vector<uint32_t>& injectionBufferSizes);
1407
Jayant Chowdhary22441f32021-12-26 18:35:41 -08001408 protected:
Cliff Wuc2ad9c82021-04-21 00:58:58 +08001409 // Configure the streams of injection camera, it need wait until the
1410 // output streams are created and configured to the original camera before
1411 // proceeding.
1412 status_t injectionConfigureStreams(
1413 camera3::camera_stream_configuration& injectionConfig,
Cliff Wu3b268182021-07-06 15:44:43 +08001414 const std::vector<uint32_t>& injectionBufferSizes);
Cliff Wuc2ad9c82021-04-21 00:58:58 +08001415
1416 // Disconnect the injection camera and delete the hal interface.
1417 void injectionDisconnectImpl();
1418
1419 // Use injection camera hal interface to replace and backup original
1420 // camera hal interface.
Jayant Chowdhary22441f32021-12-26 18:35:41 -08001421 virtual status_t replaceHalInterface(sp<HalInterface> /*newHalInterface*/,
1422 bool /*keepBackup*/) = 0;
Cliff Wuc2ad9c82021-04-21 00:58:58 +08001423
1424 wp<Camera3Device> mParent;
1425
1426 // Backup of the original camera hal interface.
1427 sp<HalInterface> mBackupHalInterface;
1428
1429 // Generated injection camera hal interface.
1430 sp<HalInterface> mInjectedCamHalInterface;
1431
Cliff Wu3b268182021-07-06 15:44:43 +08001432 // The flag indicates that the stream configuration is complete, the camera device is
1433 // active, but the injection camera has not yet been injected.
1434 bool mIsStreamConfigCompleteButNotInjected = false;
1435
Cliff Wuc2ad9c82021-04-21 00:58:58 +08001436 // Copy the configuration of the internal camera.
1437 camera3::camera_stream_configuration mInjectionConfig;
1438
Cliff Wud0476312021-07-27 20:15:55 +08001439 // Copy the streams of the internal camera.
1440 Vector<camera3::camera_stream_t*> mInjectionStreams;
1441
Cliff Wuc2ad9c82021-04-21 00:58:58 +08001442 // Copy the bufferSizes of the output streams of the internal camera.
1443 std::vector<uint32_t> mInjectionBufferSizes;
1444
1445 // Synchronizes access to injection camera between initialize and
1446 // disconnect.
1447 Mutex mInjectionLock;
1448
1449 // The injection camera ID.
1450 String8 mInjectedCamId;
1451 };
Jayant Chowdhary22441f32021-12-26 18:35:41 -08001452
1453 virtual sp<Camera3DeviceInjectionMethods>
1454 createCamera3DeviceInjectionMethods(wp<Camera3Device>) = 0;
1455
Cliff Wuc2ad9c82021-04-21 00:58:58 +08001456 sp<Camera3DeviceInjectionMethods> mInjectionMethods;
1457
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -08001458}; // class Camera3Device
1459
1460}; // namespace android
1461
1462#endif