blob: 8ab2eff68ffac26abb120430fcdadaf3726bb19c [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>
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080041#include <android/hidl/manager/1.0/IServiceNotification.h>
Yin-Chia Yeh067428c2017-01-13 15:19:24 -080042#include <camera/VendorTagDescriptor.h>
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080043
44namespace android {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080045/**
Yin-Chia Yeh067428c2017-01-13 15:19:24 -080046 * The vendor tag descriptor class that takes HIDL vendor tag information as
47 * input. Not part of VendorTagDescriptor class because that class is used
48 * in AIDL generated sources which don't have access to HIDL headers.
49 */
50class HidlVendorTagDescriptor : public VendorTagDescriptor {
51public:
52 /**
53 * Create a VendorTagDescriptor object from the HIDL VendorTagSection
54 * vector.
55 *
56 * Returns OK on success, or a negative error code.
57 */
58 static status_t createDescriptorFromHidl(
59 const hardware::hidl_vec<hardware::camera::common::V1_0::VendorTagSection>& vts,
60 /*out*/
61 sp<VendorTagDescriptor>& descriptor);
62};
63
Jayant Chowdhary5216b212019-07-17 09:26:23 -070064enum SystemCameraKind {
65 /**
66 * These camera devices are visible to all apps and system components alike
67 */
68 PUBLIC = 0,
69
70 /**
71 * These camera devices are visible only to processes having the
72 * android.permission.SYSTEM_CAMERA permission. They are not exposed to 3P
73 * apps.
74 */
75 SYSTEM_ONLY_CAMERA,
76
77 /**
78 * These camera devices are visible only to HAL clients (that try to connect
79 * on a hwbinder thread).
80 */
81 HIDDEN_SECURE_CAMERA
82};
83
Shuzhen Wang83bff122020-11-20 15:51:39 -080084#define CAMERA_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION(1, 0)
85#define CAMERA_DEVICE_API_VERSION_3_0 HARDWARE_DEVICE_API_VERSION(3, 0)
86#define CAMERA_DEVICE_API_VERSION_3_1 HARDWARE_DEVICE_API_VERSION(3, 1)
87#define CAMERA_DEVICE_API_VERSION_3_2 HARDWARE_DEVICE_API_VERSION(3, 2)
88#define CAMERA_DEVICE_API_VERSION_3_3 HARDWARE_DEVICE_API_VERSION(3, 3)
89#define CAMERA_DEVICE_API_VERSION_3_4 HARDWARE_DEVICE_API_VERSION(3, 4)
90#define CAMERA_DEVICE_API_VERSION_3_5 HARDWARE_DEVICE_API_VERSION(3, 5)
91#define CAMERA_DEVICE_API_VERSION_3_6 HARDWARE_DEVICE_API_VERSION(3, 6)
92#define CAMERA_DEVICE_API_VERSION_3_7 HARDWARE_DEVICE_API_VERSION(3, 7)
Shuzhen Wang90708ea2021-11-04 11:40:49 -070093#define CAMERA_DEVICE_API_VERSION_3_8 HARDWARE_DEVICE_API_VERSION(3, 8)
Shuzhen Wang83bff122020-11-20 15:51:39 -080094
Yin-Chia Yeh067428c2017-01-13 15:19:24 -080095/**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080096 * A manager for all camera providers available on an Android device.
97 *
98 * Responsible for enumerating providers and the individual camera devices
99 * they export, both at startup and as providers and devices are added/removed.
100 *
101 * Provides methods for requesting information about individual devices and for
102 * opening them for active use.
103 *
104 */
105class CameraProviderManager : virtual public hidl::manager::V1_0::IServiceNotification {
106public:
107
108 ~CameraProviderManager();
109
110 // Tiny proxy for the static methods in a HIDL interface that communicate with the hardware
111 // service manager, to be replacable in unit tests with a fake.
112 struct ServiceInteractionProxy {
113 virtual bool registerForNotifications(
114 const std::string &serviceName,
115 const sp<hidl::manager::V1_0::IServiceNotification>
116 &notification) = 0;
Eino-Ville Talvalaec960602019-10-15 11:46:16 -0700117 // Will not wait for service to start if it's not already running
118 virtual sp<hardware::camera::provider::V2_4::ICameraProvider> tryGetService(
119 const std::string &serviceName) = 0;
120 // Will block for service if it exists but isn't running
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800121 virtual sp<hardware::camera::provider::V2_4::ICameraProvider> getService(
122 const std::string &serviceName) = 0;
Yin-Chia Yeh177b0c12019-06-25 10:53:03 -0700123 virtual hardware::hidl_vec<hardware::hidl_string> listServices() = 0;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800124 virtual ~ServiceInteractionProxy() {}
125 };
126
127 // Standard use case - call into the normal generated static methods which invoke
128 // the real hardware service manager
129 struct HardwareServiceInteractionProxy : public ServiceInteractionProxy {
130 virtual bool registerForNotifications(
131 const std::string &serviceName,
132 const sp<hidl::manager::V1_0::IServiceNotification>
133 &notification) override {
134 return hardware::camera::provider::V2_4::ICameraProvider::registerForNotifications(
135 serviceName, notification);
136 }
Eino-Ville Talvalaec960602019-10-15 11:46:16 -0700137 virtual sp<hardware::camera::provider::V2_4::ICameraProvider> tryGetService(
138 const std::string &serviceName) override {
139 return hardware::camera::provider::V2_4::ICameraProvider::tryGetService(serviceName);
140 }
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800141 virtual sp<hardware::camera::provider::V2_4::ICameraProvider> getService(
142 const std::string &serviceName) override {
143 return hardware::camera::provider::V2_4::ICameraProvider::getService(serviceName);
144 }
Yin-Chia Yeh177b0c12019-06-25 10:53:03 -0700145
146 virtual hardware::hidl_vec<hardware::hidl_string> listServices() override;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800147 };
148
149 /**
150 * Listener interface for device/torch status changes
151 */
152 struct StatusListener : virtual public RefBase {
153 ~StatusListener() {}
154
155 virtual void onDeviceStatusChanged(const String8 &cameraId,
156 hardware::camera::common::V1_0::CameraDeviceStatus newStatus) = 0;
Shuzhen Wang43858162020-01-10 13:42:15 -0800157 virtual void onDeviceStatusChanged(const String8 &cameraId,
158 const String8 &physicalCameraId,
159 hardware::camera::common::V1_0::CameraDeviceStatus newStatus) = 0;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800160 virtual void onTorchStatusChanged(const String8 &cameraId,
Jayant Chowdhary46ef0f52021-10-05 14:36:13 -0700161 hardware::camera::common::V1_0::TorchModeStatus newStatus,
162 SystemCameraKind kind) = 0;
163 virtual void onTorchStatusChanged(const String8 &cameraId,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800164 hardware::camera::common::V1_0::TorchModeStatus newStatus) = 0;
Emilian Peevaee727d2017-05-04 16:35:48 +0100165 virtual void onNewProviderRegistered() = 0;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800166 };
167
168 /**
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700169 * Represents the mode a camera device is currently in
170 */
171 enum class DeviceMode {
172 TORCH,
173 CAMERA
174 };
175
176 /**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800177 * Initialize the manager and give it a status listener; optionally accepts a service
178 * interaction proxy.
179 *
180 * The default proxy communicates via the hardware service manager; alternate proxies can be
181 * used for testing. The lifetime of the proxy must exceed the lifetime of the manager.
182 */
183 status_t initialize(wp<StatusListener> listener,
184 ServiceInteractionProxy *proxy = &sHardwareServiceInteractionProxy);
185
186 /**
Jayant Chowdhary847947d2019-08-30 18:02:59 -0700187 * Retrieve the total number of available cameras.
188 * This value may change dynamically as cameras are added or removed.
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800189 */
Jayant Chowdhary847947d2019-08-30 18:02:59 -0700190 std::pair<int, int> getCameraCount() const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800191
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -0800192 std::vector<std::string> getCameraDeviceIds() const;
193
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800194 /**
Emilian Peevf53f66e2017-04-11 14:29:43 +0100195 * Retrieve the number of API1 compatible cameras; these are internal and
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800196 * backwards-compatible. This is the set of cameras that will be
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -0800197 * accessible via the old camera API.
198 * The return value may change dynamically due to external camera hotplug.
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800199 */
Emilian Peevf53f66e2017-04-11 14:29:43 +0100200 std::vector<std::string> getAPI1CompatibleCameraDeviceIds() const;
Yin-Chia Yehdc3134e2017-03-23 15:26:59 -0700201
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800202 /**
203 * Return true if a device with a given ID and major version exists
204 */
205 bool isValidDevice(const std::string &id, uint16_t majorVersion) const;
206
207 /**
208 * Return true if a device with a given ID has a flash unit. Returns false
209 * for devices that are unknown.
210 */
211 bool hasFlashUnit(const std::string &id) const;
212
213 /**
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -0800214 * Return true if the camera device has native zoom ratio support.
215 */
216 bool supportNativeZoomRatio(const std::string &id) const;
217
218 /**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800219 * Return the resource cost of this camera device
220 */
221 status_t getResourceCost(const std::string &id,
222 hardware::camera::common::V1_0::CameraResourceCost* cost) const;
223
224 /**
225 * Return the old camera API camera info
226 */
227 status_t getCameraInfo(const std::string &id,
228 hardware::CameraInfo* info) const;
229
230 /**
231 * Return API2 camera characteristics - returns NAME_NOT_FOUND if a device ID does
232 * not have a v3 or newer HAL version.
233 */
234 status_t getCameraCharacteristics(const std::string &id,
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700235 bool overrideForPerfClass, CameraMetadata* characteristics) const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800236
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800237 status_t isConcurrentSessionConfigurationSupported(
238 const std::vector<hardware::camera2::utils::CameraIdAndSessionConfiguration>
239 &cameraIdsAndSessionConfigs,
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700240 const std::set<std::string>& perfClassPrimaryCameraIds,
241 int targetSdkVersion, bool *isSupported);
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800242
Jayant Chowdharycad23c22020-03-10 15:04:59 -0700243 std::vector<std::unordered_set<std::string>> getConcurrentCameraIds() const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800244 /**
Emilian Peev35ae8262018-11-08 13:11:32 +0000245 * Check for device support of specific stream combination.
246 */
247 status_t isSessionConfigurationSupported(const std::string& id,
Shuzhen Wang83bff122020-11-20 15:51:39 -0800248 const hardware::camera::device::V3_7::StreamConfiguration &configuration,
Emilian Peev35ae8262018-11-08 13:11:32 +0000249 bool *status /*out*/) const;
250
251 /**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800252 * Return the highest supported device interface version for this ID
253 */
254 status_t getHighestSupportedVersion(const std::string &id,
255 hardware::hidl_version *v);
256
257 /**
Yin-Chia Yehdc3134e2017-03-23 15:26:59 -0700258 * Check if a given camera device support setTorchMode API.
259 */
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700260 bool supportSetTorchMode(const std::string &id) const;
Yin-Chia Yehdc3134e2017-03-23 15:26:59 -0700261
262 /**
Rucha Katakwar38284522021-11-10 11:25:21 -0800263 * Check if torch strength update should be skipped or not.
264 */
265 bool shouldSkipTorchStrengthUpdate(const std::string &id, int32_t torchStrength) const;
266
267 /**
268 * Return the default torch strength level if the torch strength control
269 * feature is supported.
270 */
271 int32_t getTorchDefaultStrengthLevel(const std::string &id) const;
272
273 /**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800274 * Turn on or off the flashlight on a given camera device.
Yin-Chia Yehdc3134e2017-03-23 15:26:59 -0700275 * May fail if the device does not support this API, is in active use, or if the device
276 * doesn't exist, etc.
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800277 */
278 status_t setTorchMode(const std::string &id, bool enabled);
279
280 /**
Rucha Katakwar38284522021-11-10 11:25:21 -0800281 * Change the brightness level of the flash unit associated with the cameraId and
282 * set it to the value in torchStrength.
283 * If the torch is OFF and torchStrength > 0, the torch will be turned ON with the
284 * specified strength level. If the torch is ON, only the brightness level will be
285 * changed.
286 *
287 * This operation will fail if the device does not have flash unit, has flash unit
288 * but does not support this API, torchStrength is invalid or if the device doesn't
289 * exist etc.
290 */
291 status_t turnOnTorchWithStrengthLevel(const std::string &id, int32_t torchStrength);
292
293 /**
294 * Return the torch strength level of this camera device.
295 */
296 status_t getTorchStrengthLevel(const std::string &id, int32_t* torchStrength);
297
298 /**
Yin-Chia Yeh067428c2017-01-13 15:19:24 -0800299 * Setup vendor tags for all registered providers
300 */
301 status_t setUpVendorTags();
302
303 /**
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800304 * Inform registered providers about a device state change, such as folding or unfolding
305 */
306 status_t notifyDeviceStateChange(
307 android::hardware::hidl_bitfield<hardware::camera::provider::V2_5::DeviceState> newState);
308
309 /**
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800310 * Open an active session to a camera device.
311 *
312 * This fully powers on the camera device hardware, and returns a handle to a
313 * session to be used for hardware configuration and operation.
314 */
315 status_t openSession(const std::string &id,
316 const sp<hardware::camera::device::V3_2::ICameraDeviceCallback>& callback,
317 /*out*/
318 sp<hardware::camera::device::V3_2::ICameraDeviceSession> *session);
319
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800320 /**
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700321 * Notify that the camera or torch is no longer being used by a camera client
322 */
323 void removeRef(DeviceMode usageType, const std::string &cameraId);
324
325 /**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800326 * IServiceNotification::onRegistration
327 * Invoked by the hardware service manager when a new camera provider is registered
328 */
329 virtual hardware::Return<void> onRegistration(const hardware::hidl_string& fqName,
330 const hardware::hidl_string& name,
331 bool preexisting) override;
332
333 /**
334 * Dump out information about available providers and devices
335 */
336 status_t dump(int fd, const Vector<String16>& args);
337
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800338 /**
339 * Conversion methods between HAL Status and status_t and strings
340 */
341 static status_t mapToStatusT(const hardware::camera::common::V1_0::Status& s);
342 static const char* statusToString(const hardware::camera::common::V1_0::Status& s);
343
Emilian Peev71c73a22017-03-21 16:35:51 +0000344 /*
345 * Return provider type for a specific device.
346 */
347 metadata_vendor_id_t getProviderTagIdLocked(const std::string& id,
348 hardware::hidl_version minVersion = hardware::hidl_version{0,0},
349 hardware::hidl_version maxVersion = hardware::hidl_version{1000,0}) const;
350
Shuzhen Wange8aceb52018-05-21 12:00:56 -0700351 /*
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700352 * Check if a camera is a logical camera. And if yes, return
Shuzhen Wange8aceb52018-05-21 12:00:56 -0700353 * the physical camera ids.
354 */
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700355 bool isLogicalCamera(const std::string& id, std::vector<std::string>* physicalCameraIds);
Shuzhen Wange8aceb52018-05-21 12:00:56 -0700356
Jayant Chowdhary33e8ef82019-09-27 09:20:42 -0700357 status_t getSystemCameraKind(const std::string& id, SystemCameraKind *kind) const;
358 bool isHiddenPhysicalCamera(const std::string& cameraId) const;
Emilian Peev538c90e2018-12-17 18:03:19 +0000359
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700360 status_t filterSmallJpegSizes(const std::string& cameraId);
Shuzhen Wang89db2992021-05-20 13:09:48 -0700361
Valentin Iftime29e2e152021-08-13 15:17:33 +0200362 status_t notifyUsbDeviceEvent(int32_t eventId, const std::string &usbDeviceId);
363
Emilian Peev538c90e2018-12-17 18:03:19 +0000364 static const float kDepthARTolerance;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800365private:
366 // All private members, unless otherwise noted, expect mInterfaceMutex to be locked before use
367 mutable std::mutex mInterfaceMutex;
368
369 wp<StatusListener> mListener;
370 ServiceInteractionProxy* mServiceProxy;
371
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800372 // Current overall Android device physical status
373 android::hardware::hidl_bitfield<hardware::camera::provider::V2_5::DeviceState> mDeviceState;
374
Shuzhen Wang6ba8eb22018-07-08 13:10:44 -0700375 // mProviderLifecycleLock is locked during onRegistration and removeProvider
376 mutable std::mutex mProviderLifecycleLock;
377
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800378 static HardwareServiceInteractionProxy sHardwareServiceInteractionProxy;
379
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700380 // Mapping from CameraDevice IDs to CameraProviders. This map is used to keep the
381 // ICameraProvider alive while it is in use by the camera with the given ID for camera
382 // capabilities
383 std::unordered_map<std::string, sp<hardware::camera::provider::V2_4::ICameraProvider>>
384 mCameraProviderByCameraId;
385
386 // Mapping from CameraDevice IDs to CameraProviders. This map is used to keep the
387 // ICameraProvider alive while it is in use by the camera with the given ID for torch
388 // capabilities
389 std::unordered_map<std::string, sp<hardware::camera::provider::V2_4::ICameraProvider>>
390 mTorchProviderByCameraId;
391
392 // Lock for accessing mCameraProviderByCameraId and mTorchProviderByCameraId
393 std::mutex mProviderInterfaceMapLock;
394
Eino-Ville Talvala8d942f92017-03-13 10:09:51 -0700395 struct ProviderInfo :
Shuzhen Wang43858162020-01-10 13:42:15 -0800396 virtual public hardware::camera::provider::V2_6::ICameraProviderCallback,
Eino-Ville Talvala8d942f92017-03-13 10:09:51 -0700397 virtual public hardware::hidl_death_recipient
398 {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800399 const std::string mProviderName;
Emilian Peevc93cac22020-08-17 16:00:10 -0700400 const std::string mProviderInstance;
Emilian Peev71c73a22017-03-21 16:35:51 +0000401 const metadata_vendor_id_t mProviderTagid;
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800402 int mMinorVersion;
Peter Kalauskas1b3c9072018-11-07 12:41:53 -0800403 sp<VendorTagDescriptor> mVendorTagDescriptor;
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700404 bool mSetTorchModeSupported;
405 bool mIsRemote;
406
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800407 // Current overall Android device physical status
408 hardware::hidl_bitfield<hardware::camera::provider::V2_5::DeviceState> mDeviceState;
409
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700410 // This pointer is used to keep a reference to the ICameraProvider that was last accessed.
411 wp<hardware::camera::provider::V2_4::ICameraProvider> mActiveInterface;
412
413 sp<hardware::camera::provider::V2_4::ICameraProvider> mSavedInterface;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800414
Emilian Peevc93cac22020-08-17 16:00:10 -0700415 ProviderInfo(const std::string &providerName, const std::string &providerInstance,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800416 CameraProviderManager *manager);
417 ~ProviderInfo();
418
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800419 status_t initialize(sp<hardware::camera::provider::V2_4::ICameraProvider>& interface,
420 hardware::hidl_bitfield<hardware::camera::provider::V2_5::DeviceState>
421 currentDeviceState);
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700422
423 const sp<hardware::camera::provider::V2_4::ICameraProvider> startProviderInterface();
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800424
425 const std::string& getType() const;
426
427 status_t addDevice(const std::string& name,
428 hardware::camera::common::V1_0::CameraDeviceStatus initialStatus =
429 hardware::camera::common::V1_0::CameraDeviceStatus::PRESENT,
430 /*out*/ std::string *parsedId = nullptr);
431
432 status_t dump(int fd, const Vector<String16>& args) const;
433
434 // ICameraProviderCallbacks interface - these lock the parent mInterfaceMutex
Shuzhen Wang43858162020-01-10 13:42:15 -0800435 hardware::Return<void> cameraDeviceStatusChange(
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800436 const hardware::hidl_string& cameraDeviceName,
437 hardware::camera::common::V1_0::CameraDeviceStatus newStatus) override;
Shuzhen Wang43858162020-01-10 13:42:15 -0800438 hardware::Return<void> torchModeStatusChange(
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800439 const hardware::hidl_string& cameraDeviceName,
440 hardware::camera::common::V1_0::TorchModeStatus newStatus) override;
Shuzhen Wang43858162020-01-10 13:42:15 -0800441 hardware::Return<void> physicalCameraDeviceStatusChange(
442 const hardware::hidl_string& cameraDeviceName,
443 const hardware::hidl_string& physicalCameraDeviceName,
444 hardware::camera::common::V1_0::CameraDeviceStatus newStatus) override;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800445
Shuzhen Wang394ad702020-07-23 13:01:54 -0700446 status_t cameraDeviceStatusChangeLocked(
447 std::string* id, const hardware::hidl_string& cameraDeviceName,
448 hardware::camera::common::V1_0::CameraDeviceStatus newStatus);
449 status_t physicalCameraDeviceStatusChangeLocked(
450 std::string* id, std::string* physicalId,
451 const hardware::hidl_string& cameraDeviceName,
452 const hardware::hidl_string& physicalCameraDeviceName,
453 hardware::camera::common::V1_0::CameraDeviceStatus newStatus);
454
Eino-Ville Talvala8d942f92017-03-13 10:09:51 -0700455 // hidl_death_recipient interface - this locks the parent mInterfaceMutex
456 virtual void serviceDied(uint64_t cookie, const wp<hidl::base::V1_0::IBase>& who) override;
457
Peter Kalauskas1b3c9072018-11-07 12:41:53 -0800458 /**
459 * Setup vendor tags for this provider
460 */
461 status_t setUpVendorTags();
462
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800463 /**
464 * Notify provider about top-level device physical state changes
Emilian Peev7fe6c422021-09-08 13:43:20 -0700465 *
466 * Note that 'mInterfaceMutex' should not be held when calling this method.
467 * It is possible for camera providers to add/remove devices and try to
468 * acquire it.
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800469 */
470 status_t notifyDeviceStateChange(
471 hardware::hidl_bitfield<hardware::camera::provider::V2_5::DeviceState>
472 newDeviceState);
Jayant Chowdharycbe770a2020-02-14 11:14:46 -0800473
474 std::vector<std::unordered_set<std::string>> getConcurrentCameraIdCombinations();
475
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800476 /**
Emilian Peevb50402e2021-09-24 17:41:57 -0700477 * Notify 'DeviceInfo' instanced about top-level device physical state changes
478 *
479 * Note that 'mInterfaceMutex' should be held when calling this method.
480 */
481 void notifyDeviceInfoStateChangeLocked(
482 hardware::hidl_bitfield<hardware::camera::provider::V2_5::DeviceState>
483 newDeviceState);
484
485 /**
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800486 * Query the camera provider for concurrent stream configuration support
487 */
488 status_t isConcurrentSessionConfigurationSupported(
489 const hardware::hidl_vec<
Shuzhen Wang83bff122020-11-20 15:51:39 -0800490 hardware::camera::provider::V2_7::CameraIdAndStreamCombination>
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800491 &halCameraIdsAndStreamCombinations,
492 bool *isSupported);
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800493
Valentin Iftime29e2e152021-08-13 15:17:33 +0200494 /**
495 * Remove all devices associated with this provider and notify listeners
496 * with NOT_PRESENT state.
497 */
498 void removeAllDevices();
499
500 /**
501 * Provider is an external lazy HAL
502 */
503 bool isExternalLazyHAL() const;
504
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800505 // Basic device information, common to all camera devices
506 struct DeviceInfo {
507 const std::string mName; // Full instance name
508 const std::string mId; // ID section of full name
509 const hardware::hidl_version mVersion;
Emilian Peev71c73a22017-03-21 16:35:51 +0000510 const metadata_vendor_id_t mProviderTagid;
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700511 bool mIsLogicalCamera;
512 std::vector<std::string> mPhysicalIds;
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700513 hardware::CameraInfo mInfo;
514 sp<IBase> mSavedInterface;
Jayant Chowdhary5216b212019-07-17 09:26:23 -0700515 SystemCameraKind mSystemCameraKind = SystemCameraKind::PUBLIC;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800516
517 const hardware::camera::common::V1_0::CameraResourceCost mResourceCost;
518
519 hardware::camera::common::V1_0::CameraDeviceStatus mStatus;
520
Shuzhen Wang79680432020-03-05 11:53:46 -0800521 wp<ProviderInfo> mParentProvider;
Rucha Katakwar38284522021-11-10 11:25:21 -0800522 // Torch strength default, maximum levels if the torch strength control
523 // feature is supported.
524 int32_t mTorchStrengthLevel;
525 int32_t mTorchMaximumStrengthLevel;
526 int32_t mTorchDefaultStrengthLevel;
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700527
Valentin Iftime29e2e152021-08-13 15:17:33 +0200528 // Wait for lazy HALs to confirm device availability
529 static const nsecs_t kDeviceAvailableTimeout = 2000e6; // 2000 ms
530 Mutex mDeviceAvailableLock;
531 Condition mDeviceAvailableSignal;
532 bool mIsDeviceAvailable = true;
533
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800534 bool hasFlashUnit() const { return mHasFlashUnit; }
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -0800535 bool supportNativeZoomRatio() const { return mSupportNativeZoomRatio; }
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800536 virtual status_t setTorchMode(bool enabled) = 0;
Rucha Katakwar38284522021-11-10 11:25:21 -0800537 virtual status_t turnOnTorchWithStrengthLevel(int32_t torchStrength) = 0;
538 virtual status_t getTorchStrengthLevel(int32_t *torchStrength) = 0;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800539 virtual status_t getCameraInfo(hardware::CameraInfo *info) const = 0;
Emilian Peevf53f66e2017-04-11 14:29:43 +0100540 virtual bool isAPI1Compatible() const = 0;
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700541 virtual status_t dumpState(int fd) = 0;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700542 virtual status_t getCameraCharacteristics(bool overrideForPerfClass,
543 CameraMetadata *characteristics) const {
544 (void) overrideForPerfClass;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800545 (void) characteristics;
546 return INVALID_OPERATION;
547 }
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700548 virtual status_t getPhysicalCameraCharacteristics(const std::string& physicalCameraId,
549 CameraMetadata *characteristics) const {
550 (void) physicalCameraId;
551 (void) characteristics;
552 return INVALID_OPERATION;
553 }
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800554
Emilian Peev35ae8262018-11-08 13:11:32 +0000555 virtual status_t isSessionConfigurationSupported(
Shuzhen Wang83bff122020-11-20 15:51:39 -0800556 const hardware::camera::device::V3_7::StreamConfiguration &/*configuration*/,
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700557 bool * /*status*/) {
Emilian Peev35ae8262018-11-08 13:11:32 +0000558 return INVALID_OPERATION;
559 }
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700560 virtual status_t filterSmallJpegSizes() = 0;
Emilian Peevb50402e2021-09-24 17:41:57 -0700561 virtual void notifyDeviceStateChange(
562 hardware::hidl_bitfield<hardware::camera::provider::V2_5::DeviceState>
563 /*newState*/) {}
Emilian Peev35ae8262018-11-08 13:11:32 +0000564
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700565 template<class InterfaceT>
566 sp<InterfaceT> startDeviceInterface();
567
Emilian Peev71c73a22017-03-21 16:35:51 +0000568 DeviceInfo(const std::string& name, const metadata_vendor_id_t tagId,
569 const std::string &id, const hardware::hidl_version& version,
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700570 const std::vector<std::string>& publicCameraIds,
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700571 const hardware::camera::common::V1_0::CameraResourceCost& resourceCost,
572 sp<ProviderInfo> parentProvider) :
Emilian Peev71c73a22017-03-21 16:35:51 +0000573 mName(name), mId(id), mVersion(version), mProviderTagid(tagId),
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700574 mIsLogicalCamera(false), mResourceCost(resourceCost),
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800575 mStatus(hardware::camera::common::V1_0::CameraDeviceStatus::PRESENT),
Rucha Katakwar3c6714d2021-12-15 13:56:55 -0800576 mParentProvider(parentProvider), mTorchStrengthLevel(0),
577 mTorchMaximumStrengthLevel(0), mTorchDefaultStrengthLevel(0),
578 mHasFlashUnit(false), mSupportNativeZoomRatio(false),
579 mPublicCameraIds(publicCameraIds) {}
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800580 virtual ~DeviceInfo();
581 protected:
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -0800582 bool mHasFlashUnit; // const after constructor
583 bool mSupportNativeZoomRatio; // const after constructor
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700584 const std::vector<std::string>& mPublicCameraIds;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800585
586 template<class InterfaceT>
587 static status_t setTorchMode(InterfaceT& interface, bool enabled);
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700588
589 template<class InterfaceT>
590 status_t setTorchModeForDevice(bool enabled) {
591 // Don't save the ICameraProvider interface here because we assume that this was
592 // called from CameraProviderManager::setTorchMode(), which does save it.
593 const sp<InterfaceT> interface = startDeviceInterface<InterfaceT>();
594 return DeviceInfo::setTorchMode(interface, enabled);
595 }
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800596 };
597 std::vector<std::unique_ptr<DeviceInfo>> mDevices;
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -0800598 std::unordered_set<std::string> mUniqueCameraIds;
Yin-Chia Yehe8e9e192017-03-16 15:23:51 -0700599 int mUniqueDeviceCount;
Shuzhen Wange8aceb52018-05-21 12:00:56 -0700600 std::vector<std::string> mUniqueAPI1CompatibleCameraIds;
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700601 // The initial public camera IDs published by the camera provider.
602 // Currently logical multi-camera is not supported for hot-plug camera.
603 // And we use this list to keep track of initial public camera IDs
604 // advertised by the provider, and to distinguish against "hidden"
605 // physical camera IDs.
606 std::vector<std::string> mProviderPublicCameraIds;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800607
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800608 // HALv3-specific camera fields, including the actual device interface
609 struct DeviceInfo3 : public DeviceInfo {
610 typedef hardware::camera::device::V3_2::ICameraDevice InterfaceT;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800611
612 virtual status_t setTorchMode(bool enabled) override;
Rucha Katakwar38284522021-11-10 11:25:21 -0800613 virtual status_t turnOnTorchWithStrengthLevel(int32_t torchStrength) override;
614 virtual status_t getTorchStrengthLevel(int32_t *torchStrength) override;
615
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800616 virtual status_t getCameraInfo(hardware::CameraInfo *info) const override;
Emilian Peevf53f66e2017-04-11 14:29:43 +0100617 virtual bool isAPI1Compatible() const override;
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700618 virtual status_t dumpState(int fd) override;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800619 virtual status_t getCameraCharacteristics(
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700620 bool overrideForPerfClass,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800621 CameraMetadata *characteristics) const override;
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700622 virtual status_t getPhysicalCameraCharacteristics(const std::string& physicalCameraId,
623 CameraMetadata *characteristics) const override;
Emilian Peev35ae8262018-11-08 13:11:32 +0000624 virtual status_t isSessionConfigurationSupported(
Shuzhen Wang83bff122020-11-20 15:51:39 -0800625 const hardware::camera::device::V3_7::StreamConfiguration &configuration,
Emilian Peev35ae8262018-11-08 13:11:32 +0000626 bool *status /*out*/)
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700627 override;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700628 virtual status_t filterSmallJpegSizes() override;
Emilian Peevb50402e2021-09-24 17:41:57 -0700629 virtual void notifyDeviceStateChange(
630 hardware::hidl_bitfield<hardware::camera::provider::V2_5::DeviceState>
631 newState) override;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800632
Emilian Peev71c73a22017-03-21 16:35:51 +0000633 DeviceInfo3(const std::string& name, const metadata_vendor_id_t tagId,
634 const std::string &id, uint16_t minorVersion,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800635 const hardware::camera::common::V1_0::CameraResourceCost& resourceCost,
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700636 sp<ProviderInfo> parentProvider,
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700637 const std::vector<std::string>& publicCameraIds, sp<InterfaceT> interface);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800638 virtual ~DeviceInfo3();
639 private:
640 CameraMetadata mCameraCharacteristics;
Emilian Peevb50402e2021-09-24 17:41:57 -0700641 // Map device states to sensor orientations
642 std::unordered_map<int64_t, int32_t> mDeviceStateOrientationMap;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700643 // A copy of mCameraCharacteristics without performance class
644 // override
645 std::unique_ptr<CameraMetadata> mCameraCharNoPCOverride;
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700646 std::unordered_map<std::string, CameraMetadata> mPhysicalCameraCharacteristics;
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700647 void queryPhysicalCameraIds();
Jayant Chowdhary5216b212019-07-17 09:26:23 -0700648 SystemCameraKind getSystemCameraKind();
Shuzhen Wang268a1362018-10-16 16:32:59 -0700649 status_t fixupMonochromeTags();
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800650 status_t addDynamicDepthTags(bool maxResolution = false);
651 status_t deriveHeicTags(bool maxResolution = false);
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800652 status_t addRotateCropTags();
Shuzhen Wang9bf8a6f2020-05-01 09:49:04 -0700653 status_t addPreCorrectionActiveArraySize();
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800654
Emilian Peev4c6d2b52019-01-04 17:13:56 +0000655 static void getSupportedSizes(const CameraMetadata& ch, uint32_t tag,
656 android_pixel_format_t format,
657 std::vector<std::tuple<size_t, size_t>> *sizes /*out*/);
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700658 static void getSupportedDurations( const CameraMetadata& ch, uint32_t tag,
Emilian Peev4c6d2b52019-01-04 17:13:56 +0000659 android_pixel_format_t format,
660 const std::vector<std::tuple<size_t, size_t>>& sizes,
661 std::vector<int64_t> *durations/*out*/);
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700662 static void getSupportedDynamicDepthDurations(
663 const std::vector<int64_t>& depthDurations,
Emilian Peev4c6d2b52019-01-04 17:13:56 +0000664 const std::vector<int64_t>& blobDurations,
665 std::vector<int64_t> *dynamicDepthDurations /*out*/);
666 static void getSupportedDynamicDepthSizes(
667 const std::vector<std::tuple<size_t, size_t>>& blobSizes,
668 const std::vector<std::tuple<size_t, size_t>>& depthSizes,
669 std::vector<std::tuple<size_t, size_t>> *dynamicDepthSizes /*out*/,
670 std::vector<std::tuple<size_t, size_t>> *internalDepthSizes /*out*/);
Shuzhen Wang268a1362018-10-16 16:32:59 -0700671 status_t removeAvailableKeys(CameraMetadata& c, const std::vector<uint32_t>& keys,
672 uint32_t keyTag);
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800673 status_t fillHeicStreamCombinations(std::vector<int32_t>* outputs,
674 std::vector<int64_t>* durations,
675 std::vector<int64_t>* stallDurations,
676 const camera_metadata_entry& halStreamConfigs,
677 const camera_metadata_entry& halStreamDurations);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800678 };
679
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800680 private:
681 std::string mType;
682 uint32_t mId;
683
Eino-Ville Talvala8d942f92017-03-13 10:09:51 -0700684 std::mutex mLock;
685
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800686 CameraProviderManager *mManager;
687
Shuzhen Wang394ad702020-07-23 13:01:54 -0700688 struct CameraStatusInfoT {
689 bool isPhysicalCameraStatus = false;
690 hardware::hidl_string cameraId;
691 hardware::hidl_string physicalCameraId;
692 hardware::camera::common::V1_0::CameraDeviceStatus status;
693 CameraStatusInfoT(bool isForPhysicalCamera, const hardware::hidl_string& id,
694 const hardware::hidl_string& physicalId,
695 hardware::camera::common::V1_0::CameraDeviceStatus s) :
696 isPhysicalCameraStatus(isForPhysicalCamera), cameraId(id),
697 physicalCameraId(physicalId), status(s) {}
698 };
699
700 // Lock to synchronize between initialize() and camera status callbacks
701 std::mutex mInitLock;
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -0800702 bool mInitialized = false;
Shuzhen Wang394ad702020-07-23 13:01:54 -0700703 std::vector<CameraStatusInfoT> mCachedStatus;
704 // End of scope for mInitLock
705
706 std::future<void> mInitialStatusCallbackFuture;
707 void notifyInitialStatusChange(sp<StatusListener> listener,
708 std::unique_ptr<std::vector<CameraStatusInfoT>> cachedStatus);
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -0800709
Jayant Chowdharycbe770a2020-02-14 11:14:46 -0800710 std::vector<std::unordered_set<std::string>> mConcurrentCameraIdCombinations;
711
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800712 // Templated method to instantiate the right kind of DeviceInfo and call the
713 // right CameraProvider getCameraDeviceInterface_* method.
714 template<class DeviceInfoT>
715 std::unique_ptr<DeviceInfo> initializeDeviceInfo(const std::string &name,
Emilian Peev71c73a22017-03-21 16:35:51 +0000716 const metadata_vendor_id_t tagId, const std::string &id,
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700717 uint16_t minorVersion);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800718
719 // Helper for initializeDeviceInfo to use the right CameraProvider get method.
720 template<class InterfaceT>
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700721 sp<InterfaceT> startDeviceInterface(const std::string &name);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800722
723 // Parse provider instance name for type and id
724 static status_t parseProviderName(const std::string& name,
725 std::string *type, uint32_t *id);
726
727 // Parse device instance name for device version, type, and id.
728 static status_t parseDeviceName(const std::string& name,
729 uint16_t *major, uint16_t *minor, std::string *type, std::string *id);
Emilian Peev71c73a22017-03-21 16:35:51 +0000730
731 // Generate vendor tag id
732 static metadata_vendor_id_t generateVendorTagId(const std::string &name);
Guennadi Liakhovetski6034bf52017-12-07 10:28:29 +0100733
734 void removeDevice(std::string id);
Jayant Chowdharycbe770a2020-02-14 11:14:46 -0800735
736 // Expects to have mLock locked
737 status_t reCacheConcurrentStreamingCameraIdsLocked();
738 // Expects to have mLock locked
Jayant Chowdharycad23c22020-03-10 15:04:59 -0700739 status_t getConcurrentCameraIdsInternalLocked(
Jayant Chowdharycbe770a2020-02-14 11:14:46 -0800740 sp<hardware::camera::provider::V2_6::ICameraProvider> &interface2_6);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800741 };
742
Emilian Peev7fe6c422021-09-08 13:43:20 -0700743 /**
744 * Save the ICameraProvider while it is being used by a camera or torch client
745 */
746 void saveRef(DeviceMode usageType, const std::string &cameraId,
747 sp<hardware::camera::provider::V2_4::ICameraProvider> provider);
748
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800749 // Utility to find a DeviceInfo by ID; pointer is only valid while mInterfaceMutex is held
750 // and the calling code doesn't mutate the list of providers or their lists of devices.
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800751 // Finds the first device of the given ID that falls within the requested version range
752 // minVersion <= deviceVersion < maxVersion
753 // No guarantees on the order of traversal
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800754 ProviderInfo::DeviceInfo* findDeviceInfoLocked(const std::string& id,
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800755 hardware::hidl_version minVersion = hardware::hidl_version{0,0},
756 hardware::hidl_version maxVersion = hardware::hidl_version{1000,0}) const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800757
Valentin Iftime29e2e152021-08-13 15:17:33 +0200758 // Map external providers to USB devices in order to handle USB hotplug
759 // events for lazy HALs
760 std::pair<std::vector<std::string>, sp<ProviderInfo>>
761 mExternalUsbDevicesForProvider;
762 sp<ProviderInfo> startExternalLazyProvider() const;
763
Emilian Peevc93cac22020-08-17 16:00:10 -0700764 status_t addProviderLocked(const std::string& newProvider, bool preexisting = false);
765
766 status_t tryToInitializeProviderLocked(const std::string& providerName,
767 const sp<ProviderInfo>& providerInfo);
Eino-Ville Talvala8d942f92017-03-13 10:09:51 -0700768
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800769 bool isLogicalCameraLocked(const std::string& id, std::vector<std::string>* physicalCameraIds);
770
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800771 status_t removeProvider(const std::string& provider);
Eino-Ville Talvala8d942f92017-03-13 10:09:51 -0700772 sp<StatusListener> getStatusListener() const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800773
774 bool isValidDeviceLocked(const std::string &id, uint16_t majorVersion) const;
775
Emilian Peevc93cac22020-08-17 16:00:10 -0700776 size_t mProviderInstanceId = 0;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800777 std::vector<sp<ProviderInfo>> mProviders;
778
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700779 void addProviderToMap(
780 const std::string &cameraId,
781 sp<hardware::camera::provider::V2_4::ICameraProvider> provider,
782 bool isTorchUsage);
783 void removeCameraIdFromMap(
784 std::unordered_map<std::string, sp<hardware::camera::provider::V2_4::ICameraProvider>> &map,
785 const std::string &cameraId);
786
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800787 static const char* deviceStatusToString(
788 const hardware::camera::common::V1_0::CameraDeviceStatus&);
789 static const char* torchStatusToString(
790 const hardware::camera::common::V1_0::TorchModeStatus&);
791
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700792 status_t getCameraCharacteristicsLocked(const std::string &id, bool overrideForPerfClass,
Shuzhen Wange8aceb52018-05-21 12:00:56 -0700793 CameraMetadata* characteristics) const;
794 void filterLogicalCameraIdsLocked(std::vector<std::string>& deviceIds) const;
Jayant Chowdhary847947d2019-08-30 18:02:59 -0700795
Jayant Chowdhary33e8ef82019-09-27 09:20:42 -0700796 status_t getSystemCameraKindLocked(const std::string& id, SystemCameraKind *kind) const;
797 std::pair<bool, ProviderInfo::DeviceInfo *> isHiddenPhysicalCameraInternal(const std::string& cameraId) const;
Jayant Chowdhary847947d2019-08-30 18:02:59 -0700798
799 void collectDeviceIdsLocked(const std::vector<std::string> deviceIds,
800 std::vector<std::string>& normalDeviceIds,
801 std::vector<std::string>& systemCameraDeviceIds) const;
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800802
803 status_t convertToHALStreamCombinationAndCameraIdsLocked(
804 const std::vector<hardware::camera2::utils::CameraIdAndSessionConfiguration>
805 &cameraIdsAndSessionConfigs,
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700806 const std::set<std::string>& perfClassPrimaryCameraIds,
807 int targetSdkVersion,
Shuzhen Wang83bff122020-11-20 15:51:39 -0800808 hardware::hidl_vec<hardware::camera::provider::V2_7::CameraIdAndStreamCombination>
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800809 *halCameraIdsAndStreamCombinations,
810 bool *earlyExit);
Valentin Iftime29e2e152021-08-13 15:17:33 +0200811
812 status_t usbDeviceDetached(const std::string &usbDeviceId);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800813};
814
815} // namespace android
816
817#endif