blob: ac710bf4f7c65b2746c82a2baa6afaf3c78711f0 [file] [log] [blame]
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_SERVERS_CAMERA_CAMERAPROVIDER_H
18#define ANDROID_SERVERS_CAMERA_CAMERAPROVIDER_H
19
20#include <vector>
Peter Kalauskasa29c1352018-10-10 12:05:42 -070021#include <unordered_map>
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -080022#include <unordered_set>
Shuzhen Wangd4abdf72021-05-28 11:22:50 -070023#include <set>
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080024#include <string>
25#include <mutex>
Shuzhen Wang394ad702020-07-23 13:01:54 -070026#include <future>
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080027
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -080028#include <camera/camera2/ConcurrentCamera.h>
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080029#include <camera/CameraParameters2.h>
30#include <camera/CameraMetadata.h>
31#include <camera/CameraBase.h>
Valentin Iftime29e2e152021-08-13 15:17:33 +020032#include <utils/Condition.h>
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080033#include <utils/Errors.h>
Valentin Iftime29e2e152021-08-13 15:17:33 +020034#include <android/hardware/ICameraService.h>
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080035#include <android/hardware/camera/common/1.0/types.h>
Eino-Ville Talvala63f36112018-12-06 14:57:03 -080036#include <android/hardware/camera/provider/2.5/ICameraProvider.h>
Shuzhen Wang43858162020-01-10 13:42:15 -080037#include <android/hardware/camera/provider/2.6/ICameraProviderCallback.h>
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -080038#include <android/hardware/camera/provider/2.6/ICameraProvider.h>
Shuzhen Wang83bff122020-11-20 15:51:39 -080039#include <android/hardware/camera/provider/2.7/ICameraProvider.h>
40#include <android/hardware/camera/device/3.7/types.h>
Emilian Peev2295df72021-11-12 18:14:10 -080041#include <android/hardware/camera/device/3.8/types.h>
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080042#include <android/hidl/manager/1.0/IServiceNotification.h>
Yin-Chia Yeh067428c2017-01-13 15:19:24 -080043#include <camera/VendorTagDescriptor.h>
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080044
45namespace android {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080046/**
Yin-Chia Yeh067428c2017-01-13 15:19:24 -080047 * The vendor tag descriptor class that takes HIDL vendor tag information as
48 * input. Not part of VendorTagDescriptor class because that class is used
49 * in AIDL generated sources which don't have access to HIDL headers.
50 */
51class HidlVendorTagDescriptor : public VendorTagDescriptor {
52public:
53 /**
54 * Create a VendorTagDescriptor object from the HIDL VendorTagSection
55 * vector.
56 *
57 * Returns OK on success, or a negative error code.
58 */
59 static status_t createDescriptorFromHidl(
60 const hardware::hidl_vec<hardware::camera::common::V1_0::VendorTagSection>& vts,
61 /*out*/
62 sp<VendorTagDescriptor>& descriptor);
63};
64
Jayant Chowdhary5216b212019-07-17 09:26:23 -070065enum SystemCameraKind {
66 /**
67 * These camera devices are visible to all apps and system components alike
68 */
69 PUBLIC = 0,
70
71 /**
72 * These camera devices are visible only to processes having the
73 * android.permission.SYSTEM_CAMERA permission. They are not exposed to 3P
74 * apps.
75 */
76 SYSTEM_ONLY_CAMERA,
77
78 /**
79 * These camera devices are visible only to HAL clients (that try to connect
80 * on a hwbinder thread).
81 */
82 HIDDEN_SECURE_CAMERA
83};
84
Shuzhen Wang83bff122020-11-20 15:51:39 -080085#define CAMERA_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION(1, 0)
86#define CAMERA_DEVICE_API_VERSION_3_0 HARDWARE_DEVICE_API_VERSION(3, 0)
87#define CAMERA_DEVICE_API_VERSION_3_1 HARDWARE_DEVICE_API_VERSION(3, 1)
88#define CAMERA_DEVICE_API_VERSION_3_2 HARDWARE_DEVICE_API_VERSION(3, 2)
89#define CAMERA_DEVICE_API_VERSION_3_3 HARDWARE_DEVICE_API_VERSION(3, 3)
90#define CAMERA_DEVICE_API_VERSION_3_4 HARDWARE_DEVICE_API_VERSION(3, 4)
91#define CAMERA_DEVICE_API_VERSION_3_5 HARDWARE_DEVICE_API_VERSION(3, 5)
92#define CAMERA_DEVICE_API_VERSION_3_6 HARDWARE_DEVICE_API_VERSION(3, 6)
93#define CAMERA_DEVICE_API_VERSION_3_7 HARDWARE_DEVICE_API_VERSION(3, 7)
Shuzhen Wang90708ea2021-11-04 11:40:49 -070094#define CAMERA_DEVICE_API_VERSION_3_8 HARDWARE_DEVICE_API_VERSION(3, 8)
Shuzhen Wang83bff122020-11-20 15:51:39 -080095
Yin-Chia Yeh067428c2017-01-13 15:19:24 -080096/**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080097 * A manager for all camera providers available on an Android device.
98 *
99 * Responsible for enumerating providers and the individual camera devices
100 * they export, both at startup and as providers and devices are added/removed.
101 *
102 * Provides methods for requesting information about individual devices and for
103 * opening them for active use.
104 *
105 */
106class CameraProviderManager : virtual public hidl::manager::V1_0::IServiceNotification {
107public:
108
109 ~CameraProviderManager();
110
111 // Tiny proxy for the static methods in a HIDL interface that communicate with the hardware
112 // service manager, to be replacable in unit tests with a fake.
113 struct ServiceInteractionProxy {
114 virtual bool registerForNotifications(
115 const std::string &serviceName,
116 const sp<hidl::manager::V1_0::IServiceNotification>
117 &notification) = 0;
Eino-Ville Talvalaec960602019-10-15 11:46:16 -0700118 // Will not wait for service to start if it's not already running
119 virtual sp<hardware::camera::provider::V2_4::ICameraProvider> tryGetService(
120 const std::string &serviceName) = 0;
121 // Will block for service if it exists but isn't running
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800122 virtual sp<hardware::camera::provider::V2_4::ICameraProvider> getService(
123 const std::string &serviceName) = 0;
Yin-Chia Yeh177b0c12019-06-25 10:53:03 -0700124 virtual hardware::hidl_vec<hardware::hidl_string> listServices() = 0;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800125 virtual ~ServiceInteractionProxy() {}
126 };
127
128 // Standard use case - call into the normal generated static methods which invoke
129 // the real hardware service manager
130 struct HardwareServiceInteractionProxy : public ServiceInteractionProxy {
131 virtual bool registerForNotifications(
132 const std::string &serviceName,
133 const sp<hidl::manager::V1_0::IServiceNotification>
134 &notification) override {
135 return hardware::camera::provider::V2_4::ICameraProvider::registerForNotifications(
136 serviceName, notification);
137 }
Eino-Ville Talvalaec960602019-10-15 11:46:16 -0700138 virtual sp<hardware::camera::provider::V2_4::ICameraProvider> tryGetService(
139 const std::string &serviceName) override {
140 return hardware::camera::provider::V2_4::ICameraProvider::tryGetService(serviceName);
141 }
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800142 virtual sp<hardware::camera::provider::V2_4::ICameraProvider> getService(
143 const std::string &serviceName) override {
144 return hardware::camera::provider::V2_4::ICameraProvider::getService(serviceName);
145 }
Yin-Chia Yeh177b0c12019-06-25 10:53:03 -0700146
147 virtual hardware::hidl_vec<hardware::hidl_string> listServices() override;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800148 };
149
150 /**
151 * Listener interface for device/torch status changes
152 */
153 struct StatusListener : virtual public RefBase {
154 ~StatusListener() {}
155
156 virtual void onDeviceStatusChanged(const String8 &cameraId,
157 hardware::camera::common::V1_0::CameraDeviceStatus newStatus) = 0;
Shuzhen Wang43858162020-01-10 13:42:15 -0800158 virtual void onDeviceStatusChanged(const String8 &cameraId,
159 const String8 &physicalCameraId,
160 hardware::camera::common::V1_0::CameraDeviceStatus newStatus) = 0;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800161 virtual void onTorchStatusChanged(const String8 &cameraId,
Jayant Chowdhary46ef0f52021-10-05 14:36:13 -0700162 hardware::camera::common::V1_0::TorchModeStatus newStatus,
163 SystemCameraKind kind) = 0;
164 virtual void onTorchStatusChanged(const String8 &cameraId,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800165 hardware::camera::common::V1_0::TorchModeStatus newStatus) = 0;
Emilian Peevaee727d2017-05-04 16:35:48 +0100166 virtual void onNewProviderRegistered() = 0;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800167 };
168
169 /**
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700170 * Represents the mode a camera device is currently in
171 */
172 enum class DeviceMode {
173 TORCH,
174 CAMERA
175 };
176
177 /**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800178 * Initialize the manager and give it a status listener; optionally accepts a service
179 * interaction proxy.
180 *
181 * The default proxy communicates via the hardware service manager; alternate proxies can be
182 * used for testing. The lifetime of the proxy must exceed the lifetime of the manager.
183 */
184 status_t initialize(wp<StatusListener> listener,
185 ServiceInteractionProxy *proxy = &sHardwareServiceInteractionProxy);
186
187 /**
Jayant Chowdhary847947d2019-08-30 18:02:59 -0700188 * Retrieve the total number of available cameras.
189 * This value may change dynamically as cameras are added or removed.
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800190 */
Jayant Chowdhary847947d2019-08-30 18:02:59 -0700191 std::pair<int, int> getCameraCount() const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800192
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -0800193 std::vector<std::string> getCameraDeviceIds() const;
194
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800195 /**
Emilian Peevf53f66e2017-04-11 14:29:43 +0100196 * Retrieve the number of API1 compatible cameras; these are internal and
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800197 * backwards-compatible. This is the set of cameras that will be
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -0800198 * accessible via the old camera API.
199 * The return value may change dynamically due to external camera hotplug.
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800200 */
Emilian Peevf53f66e2017-04-11 14:29:43 +0100201 std::vector<std::string> getAPI1CompatibleCameraDeviceIds() const;
Yin-Chia Yehdc3134e2017-03-23 15:26:59 -0700202
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800203 /**
204 * Return true if a device with a given ID and major version exists
205 */
206 bool isValidDevice(const std::string &id, uint16_t majorVersion) const;
207
208 /**
209 * Return true if a device with a given ID has a flash unit. Returns false
210 * for devices that are unknown.
211 */
212 bool hasFlashUnit(const std::string &id) const;
213
214 /**
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -0800215 * Return true if the camera device has native zoom ratio support.
216 */
217 bool supportNativeZoomRatio(const std::string &id) const;
218
219 /**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800220 * Return the resource cost of this camera device
221 */
222 status_t getResourceCost(const std::string &id,
223 hardware::camera::common::V1_0::CameraResourceCost* cost) const;
224
225 /**
226 * Return the old camera API camera info
227 */
228 status_t getCameraInfo(const std::string &id,
229 hardware::CameraInfo* info) const;
230
231 /**
232 * Return API2 camera characteristics - returns NAME_NOT_FOUND if a device ID does
233 * not have a v3 or newer HAL version.
234 */
235 status_t getCameraCharacteristics(const std::string &id,
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700236 bool overrideForPerfClass, CameraMetadata* characteristics) const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800237
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800238 status_t isConcurrentSessionConfigurationSupported(
239 const std::vector<hardware::camera2::utils::CameraIdAndSessionConfiguration>
240 &cameraIdsAndSessionConfigs,
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700241 const std::set<std::string>& perfClassPrimaryCameraIds,
242 int targetSdkVersion, bool *isSupported);
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800243
Jayant Chowdharycad23c22020-03-10 15:04:59 -0700244 std::vector<std::unordered_set<std::string>> getConcurrentCameraIds() const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800245 /**
Emilian Peev35ae8262018-11-08 13:11:32 +0000246 * Check for device support of specific stream combination.
247 */
248 status_t isSessionConfigurationSupported(const std::string& id,
Emilian Peev2295df72021-11-12 18:14:10 -0800249 const hardware::camera::device::V3_8::StreamConfiguration &configuration,
Emilian Peev35ae8262018-11-08 13:11:32 +0000250 bool *status /*out*/) const;
251
252 /**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800253 * Return the highest supported device interface version for this ID
254 */
255 status_t getHighestSupportedVersion(const std::string &id,
256 hardware::hidl_version *v);
257
258 /**
Yin-Chia Yehdc3134e2017-03-23 15:26:59 -0700259 * Check if a given camera device support setTorchMode API.
260 */
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700261 bool supportSetTorchMode(const std::string &id) const;
Yin-Chia Yehdc3134e2017-03-23 15:26:59 -0700262
263 /**
Rucha Katakwar38284522021-11-10 11:25:21 -0800264 * Check if torch strength update should be skipped or not.
265 */
266 bool shouldSkipTorchStrengthUpdate(const std::string &id, int32_t torchStrength) const;
267
268 /**
269 * Return the default torch strength level if the torch strength control
270 * feature is supported.
271 */
272 int32_t getTorchDefaultStrengthLevel(const std::string &id) const;
273
274 /**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800275 * Turn on or off the flashlight on a given camera device.
Yin-Chia Yehdc3134e2017-03-23 15:26:59 -0700276 * May fail if the device does not support this API, is in active use, or if the device
277 * doesn't exist, etc.
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800278 */
279 status_t setTorchMode(const std::string &id, bool enabled);
280
281 /**
Rucha Katakwar38284522021-11-10 11:25:21 -0800282 * Change the brightness level of the flash unit associated with the cameraId and
283 * set it to the value in torchStrength.
284 * If the torch is OFF and torchStrength > 0, the torch will be turned ON with the
285 * specified strength level. If the torch is ON, only the brightness level will be
286 * changed.
287 *
288 * This operation will fail if the device does not have flash unit, has flash unit
289 * but does not support this API, torchStrength is invalid or if the device doesn't
290 * exist etc.
291 */
292 status_t turnOnTorchWithStrengthLevel(const std::string &id, int32_t torchStrength);
293
294 /**
295 * Return the torch strength level of this camera device.
296 */
297 status_t getTorchStrengthLevel(const std::string &id, int32_t* torchStrength);
298
299 /**
Yin-Chia Yeh067428c2017-01-13 15:19:24 -0800300 * Setup vendor tags for all registered providers
301 */
302 status_t setUpVendorTags();
303
304 /**
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800305 * Inform registered providers about a device state change, such as folding or unfolding
306 */
307 status_t notifyDeviceStateChange(
308 android::hardware::hidl_bitfield<hardware::camera::provider::V2_5::DeviceState> newState);
309
310 /**
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800311 * Open an active session to a camera device.
312 *
313 * This fully powers on the camera device hardware, and returns a handle to a
314 * session to be used for hardware configuration and operation.
315 */
316 status_t openSession(const std::string &id,
317 const sp<hardware::camera::device::V3_2::ICameraDeviceCallback>& callback,
318 /*out*/
319 sp<hardware::camera::device::V3_2::ICameraDeviceSession> *session);
320
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800321 /**
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700322 * Notify that the camera or torch is no longer being used by a camera client
323 */
324 void removeRef(DeviceMode usageType, const std::string &cameraId);
325
326 /**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800327 * IServiceNotification::onRegistration
328 * Invoked by the hardware service manager when a new camera provider is registered
329 */
330 virtual hardware::Return<void> onRegistration(const hardware::hidl_string& fqName,
331 const hardware::hidl_string& name,
332 bool preexisting) override;
333
334 /**
335 * Dump out information about available providers and devices
336 */
337 status_t dump(int fd, const Vector<String16>& args);
338
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800339 /**
340 * Conversion methods between HAL Status and status_t and strings
341 */
342 static status_t mapToStatusT(const hardware::camera::common::V1_0::Status& s);
343 static const char* statusToString(const hardware::camera::common::V1_0::Status& s);
344
Emilian Peev71c73a22017-03-21 16:35:51 +0000345 /*
346 * Return provider type for a specific device.
347 */
348 metadata_vendor_id_t getProviderTagIdLocked(const std::string& id,
349 hardware::hidl_version minVersion = hardware::hidl_version{0,0},
350 hardware::hidl_version maxVersion = hardware::hidl_version{1000,0}) const;
351
Shuzhen Wange8aceb52018-05-21 12:00:56 -0700352 /*
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700353 * Check if a camera is a logical camera. And if yes, return
Shuzhen Wange8aceb52018-05-21 12:00:56 -0700354 * the physical camera ids.
355 */
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700356 bool isLogicalCamera(const std::string& id, std::vector<std::string>* physicalCameraIds);
Shuzhen Wange8aceb52018-05-21 12:00:56 -0700357
Jayant Chowdhary33e8ef82019-09-27 09:20:42 -0700358 status_t getSystemCameraKind(const std::string& id, SystemCameraKind *kind) const;
359 bool isHiddenPhysicalCamera(const std::string& cameraId) const;
Emilian Peev538c90e2018-12-17 18:03:19 +0000360
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700361 status_t filterSmallJpegSizes(const std::string& cameraId);
Shuzhen Wang89db2992021-05-20 13:09:48 -0700362
Valentin Iftime29e2e152021-08-13 15:17:33 +0200363 status_t notifyUsbDeviceEvent(int32_t eventId, const std::string &usbDeviceId);
364
Emilian Peev538c90e2018-12-17 18:03:19 +0000365 static const float kDepthARTolerance;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800366private:
367 // All private members, unless otherwise noted, expect mInterfaceMutex to be locked before use
368 mutable std::mutex mInterfaceMutex;
369
370 wp<StatusListener> mListener;
371 ServiceInteractionProxy* mServiceProxy;
372
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800373 // Current overall Android device physical status
374 android::hardware::hidl_bitfield<hardware::camera::provider::V2_5::DeviceState> mDeviceState;
375
Shuzhen Wang6ba8eb22018-07-08 13:10:44 -0700376 // mProviderLifecycleLock is locked during onRegistration and removeProvider
377 mutable std::mutex mProviderLifecycleLock;
378
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800379 static HardwareServiceInteractionProxy sHardwareServiceInteractionProxy;
380
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700381 // Mapping from CameraDevice IDs to CameraProviders. This map is used to keep the
382 // ICameraProvider alive while it is in use by the camera with the given ID for camera
383 // capabilities
384 std::unordered_map<std::string, sp<hardware::camera::provider::V2_4::ICameraProvider>>
385 mCameraProviderByCameraId;
386
387 // Mapping from CameraDevice IDs to CameraProviders. This map is used to keep the
388 // ICameraProvider alive while it is in use by the camera with the given ID for torch
389 // capabilities
390 std::unordered_map<std::string, sp<hardware::camera::provider::V2_4::ICameraProvider>>
391 mTorchProviderByCameraId;
392
393 // Lock for accessing mCameraProviderByCameraId and mTorchProviderByCameraId
394 std::mutex mProviderInterfaceMapLock;
395
Eino-Ville Talvala8d942f92017-03-13 10:09:51 -0700396 struct ProviderInfo :
Shuzhen Wang43858162020-01-10 13:42:15 -0800397 virtual public hardware::camera::provider::V2_6::ICameraProviderCallback,
Eino-Ville Talvala8d942f92017-03-13 10:09:51 -0700398 virtual public hardware::hidl_death_recipient
399 {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800400 const std::string mProviderName;
Emilian Peevc93cac22020-08-17 16:00:10 -0700401 const std::string mProviderInstance;
Emilian Peev71c73a22017-03-21 16:35:51 +0000402 const metadata_vendor_id_t mProviderTagid;
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800403 int mMinorVersion;
Peter Kalauskas1b3c9072018-11-07 12:41:53 -0800404 sp<VendorTagDescriptor> mVendorTagDescriptor;
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700405 bool mSetTorchModeSupported;
406 bool mIsRemote;
407
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800408 // Current overall Android device physical status
409 hardware::hidl_bitfield<hardware::camera::provider::V2_5::DeviceState> mDeviceState;
410
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700411 // This pointer is used to keep a reference to the ICameraProvider that was last accessed.
412 wp<hardware::camera::provider::V2_4::ICameraProvider> mActiveInterface;
413
414 sp<hardware::camera::provider::V2_4::ICameraProvider> mSavedInterface;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800415
Emilian Peevc93cac22020-08-17 16:00:10 -0700416 ProviderInfo(const std::string &providerName, const std::string &providerInstance,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800417 CameraProviderManager *manager);
418 ~ProviderInfo();
419
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800420 status_t initialize(sp<hardware::camera::provider::V2_4::ICameraProvider>& interface,
421 hardware::hidl_bitfield<hardware::camera::provider::V2_5::DeviceState>
422 currentDeviceState);
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700423
424 const sp<hardware::camera::provider::V2_4::ICameraProvider> startProviderInterface();
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800425
426 const std::string& getType() const;
427
428 status_t addDevice(const std::string& name,
429 hardware::camera::common::V1_0::CameraDeviceStatus initialStatus =
430 hardware::camera::common::V1_0::CameraDeviceStatus::PRESENT,
431 /*out*/ std::string *parsedId = nullptr);
432
433 status_t dump(int fd, const Vector<String16>& args) const;
434
435 // ICameraProviderCallbacks interface - these lock the parent mInterfaceMutex
Shuzhen Wang43858162020-01-10 13:42:15 -0800436 hardware::Return<void> cameraDeviceStatusChange(
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800437 const hardware::hidl_string& cameraDeviceName,
438 hardware::camera::common::V1_0::CameraDeviceStatus newStatus) override;
Shuzhen Wang43858162020-01-10 13:42:15 -0800439 hardware::Return<void> torchModeStatusChange(
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800440 const hardware::hidl_string& cameraDeviceName,
441 hardware::camera::common::V1_0::TorchModeStatus newStatus) override;
Shuzhen Wang43858162020-01-10 13:42:15 -0800442 hardware::Return<void> physicalCameraDeviceStatusChange(
443 const hardware::hidl_string& cameraDeviceName,
444 const hardware::hidl_string& physicalCameraDeviceName,
445 hardware::camera::common::V1_0::CameraDeviceStatus newStatus) override;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800446
Shuzhen Wang394ad702020-07-23 13:01:54 -0700447 status_t cameraDeviceStatusChangeLocked(
448 std::string* id, const hardware::hidl_string& cameraDeviceName,
449 hardware::camera::common::V1_0::CameraDeviceStatus newStatus);
450 status_t physicalCameraDeviceStatusChangeLocked(
451 std::string* id, std::string* physicalId,
452 const hardware::hidl_string& cameraDeviceName,
453 const hardware::hidl_string& physicalCameraDeviceName,
454 hardware::camera::common::V1_0::CameraDeviceStatus newStatus);
455
Eino-Ville Talvala8d942f92017-03-13 10:09:51 -0700456 // hidl_death_recipient interface - this locks the parent mInterfaceMutex
457 virtual void serviceDied(uint64_t cookie, const wp<hidl::base::V1_0::IBase>& who) override;
458
Peter Kalauskas1b3c9072018-11-07 12:41:53 -0800459 /**
460 * Setup vendor tags for this provider
461 */
462 status_t setUpVendorTags();
463
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800464 /**
465 * Notify provider about top-level device physical state changes
Emilian Peev7fe6c422021-09-08 13:43:20 -0700466 *
467 * Note that 'mInterfaceMutex' should not be held when calling this method.
468 * It is possible for camera providers to add/remove devices and try to
469 * acquire it.
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800470 */
471 status_t notifyDeviceStateChange(
472 hardware::hidl_bitfield<hardware::camera::provider::V2_5::DeviceState>
473 newDeviceState);
Jayant Chowdharycbe770a2020-02-14 11:14:46 -0800474
475 std::vector<std::unordered_set<std::string>> getConcurrentCameraIdCombinations();
476
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800477 /**
Emilian Peevb50402e2021-09-24 17:41:57 -0700478 * Notify 'DeviceInfo' instanced about top-level device physical state changes
479 *
480 * Note that 'mInterfaceMutex' should be held when calling this method.
481 */
482 void notifyDeviceInfoStateChangeLocked(
483 hardware::hidl_bitfield<hardware::camera::provider::V2_5::DeviceState>
484 newDeviceState);
485
486 /**
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800487 * Query the camera provider for concurrent stream configuration support
488 */
489 status_t isConcurrentSessionConfigurationSupported(
490 const hardware::hidl_vec<
Shuzhen Wang83bff122020-11-20 15:51:39 -0800491 hardware::camera::provider::V2_7::CameraIdAndStreamCombination>
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800492 &halCameraIdsAndStreamCombinations,
493 bool *isSupported);
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800494
Valentin Iftime29e2e152021-08-13 15:17:33 +0200495 /**
496 * Remove all devices associated with this provider and notify listeners
497 * with NOT_PRESENT state.
498 */
499 void removeAllDevices();
500
501 /**
502 * Provider is an external lazy HAL
503 */
504 bool isExternalLazyHAL() const;
505
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800506 // Basic device information, common to all camera devices
507 struct DeviceInfo {
508 const std::string mName; // Full instance name
509 const std::string mId; // ID section of full name
510 const hardware::hidl_version mVersion;
Emilian Peev71c73a22017-03-21 16:35:51 +0000511 const metadata_vendor_id_t mProviderTagid;
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700512 bool mIsLogicalCamera;
513 std::vector<std::string> mPhysicalIds;
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700514 hardware::CameraInfo mInfo;
515 sp<IBase> mSavedInterface;
Jayant Chowdhary5216b212019-07-17 09:26:23 -0700516 SystemCameraKind mSystemCameraKind = SystemCameraKind::PUBLIC;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800517
518 const hardware::camera::common::V1_0::CameraResourceCost mResourceCost;
519
520 hardware::camera::common::V1_0::CameraDeviceStatus mStatus;
521
Shuzhen Wang79680432020-03-05 11:53:46 -0800522 wp<ProviderInfo> mParentProvider;
Rucha Katakwar38284522021-11-10 11:25:21 -0800523 // Torch strength default, maximum levels if the torch strength control
524 // feature is supported.
525 int32_t mTorchStrengthLevel;
526 int32_t mTorchMaximumStrengthLevel;
527 int32_t mTorchDefaultStrengthLevel;
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700528
Valentin Iftime29e2e152021-08-13 15:17:33 +0200529 // Wait for lazy HALs to confirm device availability
530 static const nsecs_t kDeviceAvailableTimeout = 2000e6; // 2000 ms
531 Mutex mDeviceAvailableLock;
532 Condition mDeviceAvailableSignal;
533 bool mIsDeviceAvailable = true;
534
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800535 bool hasFlashUnit() const { return mHasFlashUnit; }
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -0800536 bool supportNativeZoomRatio() const { return mSupportNativeZoomRatio; }
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800537 virtual status_t setTorchMode(bool enabled) = 0;
Rucha Katakwar38284522021-11-10 11:25:21 -0800538 virtual status_t turnOnTorchWithStrengthLevel(int32_t torchStrength) = 0;
539 virtual status_t getTorchStrengthLevel(int32_t *torchStrength) = 0;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800540 virtual status_t getCameraInfo(hardware::CameraInfo *info) const = 0;
Emilian Peevf53f66e2017-04-11 14:29:43 +0100541 virtual bool isAPI1Compatible() const = 0;
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700542 virtual status_t dumpState(int fd) = 0;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700543 virtual status_t getCameraCharacteristics(bool overrideForPerfClass,
544 CameraMetadata *characteristics) const {
545 (void) overrideForPerfClass;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800546 (void) characteristics;
547 return INVALID_OPERATION;
548 }
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700549 virtual status_t getPhysicalCameraCharacteristics(const std::string& physicalCameraId,
550 CameraMetadata *characteristics) const {
551 (void) physicalCameraId;
552 (void) characteristics;
553 return INVALID_OPERATION;
554 }
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800555
Emilian Peev35ae8262018-11-08 13:11:32 +0000556 virtual status_t isSessionConfigurationSupported(
Emilian Peev2295df72021-11-12 18:14:10 -0800557 const hardware::camera::device::V3_8::StreamConfiguration &/*configuration*/,
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700558 bool * /*status*/) {
Emilian Peev35ae8262018-11-08 13:11:32 +0000559 return INVALID_OPERATION;
560 }
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700561 virtual status_t filterSmallJpegSizes() = 0;
Emilian Peevb50402e2021-09-24 17:41:57 -0700562 virtual void notifyDeviceStateChange(
563 hardware::hidl_bitfield<hardware::camera::provider::V2_5::DeviceState>
564 /*newState*/) {}
Emilian Peev35ae8262018-11-08 13:11:32 +0000565
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700566 template<class InterfaceT>
567 sp<InterfaceT> startDeviceInterface();
568
Emilian Peev71c73a22017-03-21 16:35:51 +0000569 DeviceInfo(const std::string& name, const metadata_vendor_id_t tagId,
570 const std::string &id, const hardware::hidl_version& version,
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700571 const std::vector<std::string>& publicCameraIds,
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700572 const hardware::camera::common::V1_0::CameraResourceCost& resourceCost,
573 sp<ProviderInfo> parentProvider) :
Emilian Peev71c73a22017-03-21 16:35:51 +0000574 mName(name), mId(id), mVersion(version), mProviderTagid(tagId),
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700575 mIsLogicalCamera(false), mResourceCost(resourceCost),
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800576 mStatus(hardware::camera::common::V1_0::CameraDeviceStatus::PRESENT),
Rucha Katakwar3c6714d2021-12-15 13:56:55 -0800577 mParentProvider(parentProvider), mTorchStrengthLevel(0),
578 mTorchMaximumStrengthLevel(0), mTorchDefaultStrengthLevel(0),
579 mHasFlashUnit(false), mSupportNativeZoomRatio(false),
580 mPublicCameraIds(publicCameraIds) {}
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800581 virtual ~DeviceInfo();
582 protected:
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -0800583 bool mHasFlashUnit; // const after constructor
584 bool mSupportNativeZoomRatio; // const after constructor
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700585 const std::vector<std::string>& mPublicCameraIds;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800586
587 template<class InterfaceT>
588 static status_t setTorchMode(InterfaceT& interface, bool enabled);
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700589
590 template<class InterfaceT>
591 status_t setTorchModeForDevice(bool enabled) {
592 // Don't save the ICameraProvider interface here because we assume that this was
593 // called from CameraProviderManager::setTorchMode(), which does save it.
594 const sp<InterfaceT> interface = startDeviceInterface<InterfaceT>();
595 return DeviceInfo::setTorchMode(interface, enabled);
596 }
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800597 };
598 std::vector<std::unique_ptr<DeviceInfo>> mDevices;
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -0800599 std::unordered_set<std::string> mUniqueCameraIds;
Yin-Chia Yehe8e9e192017-03-16 15:23:51 -0700600 int mUniqueDeviceCount;
Shuzhen Wange8aceb52018-05-21 12:00:56 -0700601 std::vector<std::string> mUniqueAPI1CompatibleCameraIds;
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700602 // The initial public camera IDs published by the camera provider.
603 // Currently logical multi-camera is not supported for hot-plug camera.
604 // And we use this list to keep track of initial public camera IDs
605 // advertised by the provider, and to distinguish against "hidden"
606 // physical camera IDs.
607 std::vector<std::string> mProviderPublicCameraIds;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800608
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800609 // HALv3-specific camera fields, including the actual device interface
610 struct DeviceInfo3 : public DeviceInfo {
611 typedef hardware::camera::device::V3_2::ICameraDevice InterfaceT;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800612
613 virtual status_t setTorchMode(bool enabled) override;
Rucha Katakwar38284522021-11-10 11:25:21 -0800614 virtual status_t turnOnTorchWithStrengthLevel(int32_t torchStrength) override;
615 virtual status_t getTorchStrengthLevel(int32_t *torchStrength) override;
616
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800617 virtual status_t getCameraInfo(hardware::CameraInfo *info) const override;
Emilian Peevf53f66e2017-04-11 14:29:43 +0100618 virtual bool isAPI1Compatible() const override;
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700619 virtual status_t dumpState(int fd) override;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800620 virtual status_t getCameraCharacteristics(
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700621 bool overrideForPerfClass,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800622 CameraMetadata *characteristics) const override;
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700623 virtual status_t getPhysicalCameraCharacteristics(const std::string& physicalCameraId,
624 CameraMetadata *characteristics) const override;
Emilian Peev35ae8262018-11-08 13:11:32 +0000625 virtual status_t isSessionConfigurationSupported(
Emilian Peev2295df72021-11-12 18:14:10 -0800626 const hardware::camera::device::V3_8::StreamConfiguration &configuration,
Emilian Peev35ae8262018-11-08 13:11:32 +0000627 bool *status /*out*/)
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700628 override;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700629 virtual status_t filterSmallJpegSizes() override;
Emilian Peevb50402e2021-09-24 17:41:57 -0700630 virtual void notifyDeviceStateChange(
631 hardware::hidl_bitfield<hardware::camera::provider::V2_5::DeviceState>
632 newState) override;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800633
Emilian Peev71c73a22017-03-21 16:35:51 +0000634 DeviceInfo3(const std::string& name, const metadata_vendor_id_t tagId,
635 const std::string &id, uint16_t minorVersion,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800636 const hardware::camera::common::V1_0::CameraResourceCost& resourceCost,
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700637 sp<ProviderInfo> parentProvider,
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700638 const std::vector<std::string>& publicCameraIds, sp<InterfaceT> interface);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800639 virtual ~DeviceInfo3();
640 private:
641 CameraMetadata mCameraCharacteristics;
Emilian Peevb50402e2021-09-24 17:41:57 -0700642 // Map device states to sensor orientations
643 std::unordered_map<int64_t, int32_t> mDeviceStateOrientationMap;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700644 // A copy of mCameraCharacteristics without performance class
645 // override
646 std::unique_ptr<CameraMetadata> mCameraCharNoPCOverride;
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700647 std::unordered_map<std::string, CameraMetadata> mPhysicalCameraCharacteristics;
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700648 void queryPhysicalCameraIds();
Jayant Chowdhary5216b212019-07-17 09:26:23 -0700649 SystemCameraKind getSystemCameraKind();
Shuzhen Wang268a1362018-10-16 16:32:59 -0700650 status_t fixupMonochromeTags();
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800651 status_t addDynamicDepthTags(bool maxResolution = false);
652 status_t deriveHeicTags(bool maxResolution = false);
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800653 status_t addRotateCropTags();
Shuzhen Wang9bf8a6f2020-05-01 09:49:04 -0700654 status_t addPreCorrectionActiveArraySize();
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800655
Emilian Peev4c6d2b52019-01-04 17:13:56 +0000656 static void getSupportedSizes(const CameraMetadata& ch, uint32_t tag,
657 android_pixel_format_t format,
658 std::vector<std::tuple<size_t, size_t>> *sizes /*out*/);
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700659 static void getSupportedDurations( const CameraMetadata& ch, uint32_t tag,
Emilian Peev4c6d2b52019-01-04 17:13:56 +0000660 android_pixel_format_t format,
661 const std::vector<std::tuple<size_t, size_t>>& sizes,
662 std::vector<int64_t> *durations/*out*/);
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700663 static void getSupportedDynamicDepthDurations(
664 const std::vector<int64_t>& depthDurations,
Emilian Peev4c6d2b52019-01-04 17:13:56 +0000665 const std::vector<int64_t>& blobDurations,
666 std::vector<int64_t> *dynamicDepthDurations /*out*/);
667 static void getSupportedDynamicDepthSizes(
668 const std::vector<std::tuple<size_t, size_t>>& blobSizes,
669 const std::vector<std::tuple<size_t, size_t>>& depthSizes,
670 std::vector<std::tuple<size_t, size_t>> *dynamicDepthSizes /*out*/,
671 std::vector<std::tuple<size_t, size_t>> *internalDepthSizes /*out*/);
Shuzhen Wang268a1362018-10-16 16:32:59 -0700672 status_t removeAvailableKeys(CameraMetadata& c, const std::vector<uint32_t>& keys,
673 uint32_t keyTag);
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800674 status_t fillHeicStreamCombinations(std::vector<int32_t>* outputs,
675 std::vector<int64_t>* durations,
676 std::vector<int64_t>* stallDurations,
677 const camera_metadata_entry& halStreamConfigs,
678 const camera_metadata_entry& halStreamDurations);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800679 };
680
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800681 private:
682 std::string mType;
683 uint32_t mId;
684
Eino-Ville Talvala8d942f92017-03-13 10:09:51 -0700685 std::mutex mLock;
686
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800687 CameraProviderManager *mManager;
688
Shuzhen Wang394ad702020-07-23 13:01:54 -0700689 struct CameraStatusInfoT {
690 bool isPhysicalCameraStatus = false;
691 hardware::hidl_string cameraId;
692 hardware::hidl_string physicalCameraId;
693 hardware::camera::common::V1_0::CameraDeviceStatus status;
694 CameraStatusInfoT(bool isForPhysicalCamera, const hardware::hidl_string& id,
695 const hardware::hidl_string& physicalId,
696 hardware::camera::common::V1_0::CameraDeviceStatus s) :
697 isPhysicalCameraStatus(isForPhysicalCamera), cameraId(id),
698 physicalCameraId(physicalId), status(s) {}
699 };
700
701 // Lock to synchronize between initialize() and camera status callbacks
702 std::mutex mInitLock;
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -0800703 bool mInitialized = false;
Shuzhen Wang394ad702020-07-23 13:01:54 -0700704 std::vector<CameraStatusInfoT> mCachedStatus;
705 // End of scope for mInitLock
706
707 std::future<void> mInitialStatusCallbackFuture;
708 void notifyInitialStatusChange(sp<StatusListener> listener,
709 std::unique_ptr<std::vector<CameraStatusInfoT>> cachedStatus);
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -0800710
Jayant Chowdharycbe770a2020-02-14 11:14:46 -0800711 std::vector<std::unordered_set<std::string>> mConcurrentCameraIdCombinations;
712
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800713 // Templated method to instantiate the right kind of DeviceInfo and call the
714 // right CameraProvider getCameraDeviceInterface_* method.
715 template<class DeviceInfoT>
716 std::unique_ptr<DeviceInfo> initializeDeviceInfo(const std::string &name,
Emilian Peev71c73a22017-03-21 16:35:51 +0000717 const metadata_vendor_id_t tagId, const std::string &id,
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700718 uint16_t minorVersion);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800719
720 // Helper for initializeDeviceInfo to use the right CameraProvider get method.
721 template<class InterfaceT>
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700722 sp<InterfaceT> startDeviceInterface(const std::string &name);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800723
724 // Parse provider instance name for type and id
725 static status_t parseProviderName(const std::string& name,
726 std::string *type, uint32_t *id);
727
728 // Parse device instance name for device version, type, and id.
729 static status_t parseDeviceName(const std::string& name,
730 uint16_t *major, uint16_t *minor, std::string *type, std::string *id);
Emilian Peev71c73a22017-03-21 16:35:51 +0000731
732 // Generate vendor tag id
733 static metadata_vendor_id_t generateVendorTagId(const std::string &name);
Guennadi Liakhovetski6034bf52017-12-07 10:28:29 +0100734
735 void removeDevice(std::string id);
Jayant Chowdharycbe770a2020-02-14 11:14:46 -0800736
737 // Expects to have mLock locked
738 status_t reCacheConcurrentStreamingCameraIdsLocked();
739 // Expects to have mLock locked
Jayant Chowdharycad23c22020-03-10 15:04:59 -0700740 status_t getConcurrentCameraIdsInternalLocked(
Jayant Chowdharycbe770a2020-02-14 11:14:46 -0800741 sp<hardware::camera::provider::V2_6::ICameraProvider> &interface2_6);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800742 };
743
Emilian Peev7fe6c422021-09-08 13:43:20 -0700744 /**
745 * Save the ICameraProvider while it is being used by a camera or torch client
746 */
747 void saveRef(DeviceMode usageType, const std::string &cameraId,
748 sp<hardware::camera::provider::V2_4::ICameraProvider> provider);
749
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800750 // Utility to find a DeviceInfo by ID; pointer is only valid while mInterfaceMutex is held
751 // and the calling code doesn't mutate the list of providers or their lists of devices.
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800752 // Finds the first device of the given ID that falls within the requested version range
753 // minVersion <= deviceVersion < maxVersion
754 // No guarantees on the order of traversal
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800755 ProviderInfo::DeviceInfo* findDeviceInfoLocked(const std::string& id,
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800756 hardware::hidl_version minVersion = hardware::hidl_version{0,0},
757 hardware::hidl_version maxVersion = hardware::hidl_version{1000,0}) const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800758
Valentin Iftime29e2e152021-08-13 15:17:33 +0200759 // Map external providers to USB devices in order to handle USB hotplug
760 // events for lazy HALs
761 std::pair<std::vector<std::string>, sp<ProviderInfo>>
762 mExternalUsbDevicesForProvider;
763 sp<ProviderInfo> startExternalLazyProvider() const;
764
Emilian Peevc93cac22020-08-17 16:00:10 -0700765 status_t addProviderLocked(const std::string& newProvider, bool preexisting = false);
766
767 status_t tryToInitializeProviderLocked(const std::string& providerName,
768 const sp<ProviderInfo>& providerInfo);
Eino-Ville Talvala8d942f92017-03-13 10:09:51 -0700769
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800770 bool isLogicalCameraLocked(const std::string& id, std::vector<std::string>* physicalCameraIds);
771
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800772 status_t removeProvider(const std::string& provider);
Eino-Ville Talvala8d942f92017-03-13 10:09:51 -0700773 sp<StatusListener> getStatusListener() const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800774
775 bool isValidDeviceLocked(const std::string &id, uint16_t majorVersion) const;
776
Emilian Peevc93cac22020-08-17 16:00:10 -0700777 size_t mProviderInstanceId = 0;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800778 std::vector<sp<ProviderInfo>> mProviders;
779
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700780 void addProviderToMap(
781 const std::string &cameraId,
782 sp<hardware::camera::provider::V2_4::ICameraProvider> provider,
783 bool isTorchUsage);
784 void removeCameraIdFromMap(
785 std::unordered_map<std::string, sp<hardware::camera::provider::V2_4::ICameraProvider>> &map,
786 const std::string &cameraId);
787
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800788 static const char* deviceStatusToString(
789 const hardware::camera::common::V1_0::CameraDeviceStatus&);
790 static const char* torchStatusToString(
791 const hardware::camera::common::V1_0::TorchModeStatus&);
792
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700793 status_t getCameraCharacteristicsLocked(const std::string &id, bool overrideForPerfClass,
Shuzhen Wange8aceb52018-05-21 12:00:56 -0700794 CameraMetadata* characteristics) const;
795 void filterLogicalCameraIdsLocked(std::vector<std::string>& deviceIds) const;
Jayant Chowdhary847947d2019-08-30 18:02:59 -0700796
Jayant Chowdhary33e8ef82019-09-27 09:20:42 -0700797 status_t getSystemCameraKindLocked(const std::string& id, SystemCameraKind *kind) const;
798 std::pair<bool, ProviderInfo::DeviceInfo *> isHiddenPhysicalCameraInternal(const std::string& cameraId) const;
Jayant Chowdhary847947d2019-08-30 18:02:59 -0700799
800 void collectDeviceIdsLocked(const std::vector<std::string> deviceIds,
801 std::vector<std::string>& normalDeviceIds,
802 std::vector<std::string>& systemCameraDeviceIds) const;
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800803
804 status_t convertToHALStreamCombinationAndCameraIdsLocked(
805 const std::vector<hardware::camera2::utils::CameraIdAndSessionConfiguration>
806 &cameraIdsAndSessionConfigs,
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700807 const std::set<std::string>& perfClassPrimaryCameraIds,
808 int targetSdkVersion,
Shuzhen Wang83bff122020-11-20 15:51:39 -0800809 hardware::hidl_vec<hardware::camera::provider::V2_7::CameraIdAndStreamCombination>
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800810 *halCameraIdsAndStreamCombinations,
811 bool *earlyExit);
Valentin Iftime29e2e152021-08-13 15:17:33 +0200812
813 status_t usbDeviceDetached(const std::string &usbDeviceId);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800814};
815
816} // namespace android
817
818#endif