blob: a2ec576d18547d0d615c0c69660922ed8246e345 [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>
26
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -080027#include <camera/camera2/ConcurrentCamera.h>
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080028#include <camera/CameraParameters2.h>
29#include <camera/CameraMetadata.h>
30#include <camera/CameraBase.h>
Valentin Iftime29e2e152021-08-13 15:17:33 +020031#include <utils/Condition.h>
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080032#include <utils/Errors.h>
Valentin Iftime29e2e152021-08-13 15:17:33 +020033#include <android/hardware/ICameraService.h>
Jayant Chowdhary0bd38522021-11-05 17:49:27 -070034#include <utils/IPCTransport.h>
Shuzhen Wanga79a64d2022-04-24 19:56:30 -070035#include <utils/SessionConfigurationUtils.h>
Jayant Chowdharya04055f2022-01-03 02:07:49 +000036#include <aidl/android/hardware/camera/provider/ICameraProvider.h>
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080037#include <android/hardware/camera/common/1.0/types.h>
Eino-Ville Talvala63f36112018-12-06 14:57:03 -080038#include <android/hardware/camera/provider/2.5/ICameraProvider.h>
Shuzhen Wang43858162020-01-10 13:42:15 -080039#include <android/hardware/camera/provider/2.6/ICameraProviderCallback.h>
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -080040#include <android/hardware/camera/provider/2.6/ICameraProvider.h>
Shuzhen Wang83bff122020-11-20 15:51:39 -080041#include <android/hardware/camera/provider/2.7/ICameraProvider.h>
42#include <android/hardware/camera/device/3.7/types.h>
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080043#include <android/hidl/manager/1.0/IServiceNotification.h>
Jayant Chowdhary0bd38522021-11-05 17:49:27 -070044#include <binder/IServiceManager.h>
Yin-Chia Yeh067428c2017-01-13 15:19:24 -080045#include <camera/VendorTagDescriptor.h>
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080046
47namespace android {
Jayant Chowdhary0bd38522021-11-05 17:49:27 -070048
49using hardware::camera2::utils::CameraIdAndSessionConfiguration;
50
51enum class CameraDeviceStatus : uint32_t {
52 NOT_PRESENT = 0,
53 PRESENT = 1,
54 ENUMERATING = 2
55};
56
57enum class TorchModeStatus : uint32_t {
58 NOT_AVAILABLE = 0,
59 AVAILABLE_OFF = 1,
60 AVAILABLE_ON = 2
61};
62
63struct CameraResourceCost {
64 uint32_t resourceCost;
65 std::vector<std::string> conflictingDevices;
Yin-Chia Yeh067428c2017-01-13 15:19:24 -080066};
67
Jayant Chowdhary5216b212019-07-17 09:26:23 -070068enum SystemCameraKind {
69 /**
70 * These camera devices are visible to all apps and system components alike
71 */
72 PUBLIC = 0,
73
74 /**
75 * These camera devices are visible only to processes having the
76 * android.permission.SYSTEM_CAMERA permission. They are not exposed to 3P
77 * apps.
78 */
79 SYSTEM_ONLY_CAMERA,
80
81 /**
82 * These camera devices are visible only to HAL clients (that try to connect
83 * on a hwbinder thread).
84 */
85 HIDDEN_SECURE_CAMERA
86};
87
Shuzhen Wang83bff122020-11-20 15:51:39 -080088#define CAMERA_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION(1, 0)
89#define CAMERA_DEVICE_API_VERSION_3_0 HARDWARE_DEVICE_API_VERSION(3, 0)
90#define CAMERA_DEVICE_API_VERSION_3_1 HARDWARE_DEVICE_API_VERSION(3, 1)
91#define CAMERA_DEVICE_API_VERSION_3_2 HARDWARE_DEVICE_API_VERSION(3, 2)
92#define CAMERA_DEVICE_API_VERSION_3_3 HARDWARE_DEVICE_API_VERSION(3, 3)
93#define CAMERA_DEVICE_API_VERSION_3_4 HARDWARE_DEVICE_API_VERSION(3, 4)
94#define CAMERA_DEVICE_API_VERSION_3_5 HARDWARE_DEVICE_API_VERSION(3, 5)
95#define CAMERA_DEVICE_API_VERSION_3_6 HARDWARE_DEVICE_API_VERSION(3, 6)
96#define CAMERA_DEVICE_API_VERSION_3_7 HARDWARE_DEVICE_API_VERSION(3, 7)
97
Yin-Chia Yeh067428c2017-01-13 15:19:24 -080098/**
Jayant Chowdharya04055f2022-01-03 02:07:49 +000099 * The vendor tag descriptor class that takes HIDL/AIDL vendor tag information as
100 * input. Not part of VendorTagDescriptor class because that class is used
101 * in AIDL generated sources which don't have access to AIDL / HIDL headers.
102 */
103class IdlVendorTagDescriptor : public VendorTagDescriptor {
104public:
105 /**
106 * Create a VendorTagDescriptor object from the HIDL/AIDL VendorTagSection
107 * vector.
108 *
109 * Returns OK on success, or a negative error code.
110 */
111 template <class VendorTagSectionVectorType, class VendorTagSectionType>
112 static status_t createDescriptorFromIdl(
113 const VendorTagSectionVectorType& vts,
114 /*out*/
115 sp<VendorTagDescriptor>& descriptor);
116};
117
118/**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800119 * A manager for all camera providers available on an Android device.
120 *
121 * Responsible for enumerating providers and the individual camera devices
122 * they export, both at startup and as providers and devices are added/removed.
123 *
124 * Provides methods for requesting information about individual devices and for
125 * opening them for active use.
126 *
127 */
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000128class CameraProviderManager : virtual public hidl::manager::V1_0::IServiceNotification,
129 public virtual IServiceManager::LocalRegistrationCallback {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800130public:
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700131 // needs to be made friend strict since HidlProviderInfo needs to inherit
132 // from CameraProviderManager::ProviderInfo which isn't a public member.
133 friend struct HidlProviderInfo;
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000134 friend struct AidlProviderInfo;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800135 ~CameraProviderManager();
136
137 // Tiny proxy for the static methods in a HIDL interface that communicate with the hardware
138 // service manager, to be replacable in unit tests with a fake.
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700139 struct HidlServiceInteractionProxy {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800140 virtual bool registerForNotifications(
141 const std::string &serviceName,
142 const sp<hidl::manager::V1_0::IServiceNotification>
143 &notification) = 0;
Eino-Ville Talvalaec960602019-10-15 11:46:16 -0700144 // Will not wait for service to start if it's not already running
145 virtual sp<hardware::camera::provider::V2_4::ICameraProvider> tryGetService(
146 const std::string &serviceName) = 0;
147 // Will block for service if it exists but isn't running
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800148 virtual sp<hardware::camera::provider::V2_4::ICameraProvider> getService(
149 const std::string &serviceName) = 0;
Yin-Chia Yeh177b0c12019-06-25 10:53:03 -0700150 virtual hardware::hidl_vec<hardware::hidl_string> listServices() = 0;
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700151 virtual ~HidlServiceInteractionProxy() {}
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800152 };
153
154 // Standard use case - call into the normal generated static methods which invoke
155 // the real hardware service manager
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700156 struct HidlServiceInteractionProxyImpl : public HidlServiceInteractionProxy {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800157 virtual bool registerForNotifications(
158 const std::string &serviceName,
159 const sp<hidl::manager::V1_0::IServiceNotification>
160 &notification) override {
161 return hardware::camera::provider::V2_4::ICameraProvider::registerForNotifications(
162 serviceName, notification);
163 }
Eino-Ville Talvalaec960602019-10-15 11:46:16 -0700164 virtual sp<hardware::camera::provider::V2_4::ICameraProvider> tryGetService(
165 const std::string &serviceName) override {
166 return hardware::camera::provider::V2_4::ICameraProvider::tryGetService(serviceName);
167 }
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800168 virtual sp<hardware::camera::provider::V2_4::ICameraProvider> getService(
169 const std::string &serviceName) override {
170 return hardware::camera::provider::V2_4::ICameraProvider::getService(serviceName);
171 }
Yin-Chia Yeh177b0c12019-06-25 10:53:03 -0700172
173 virtual hardware::hidl_vec<hardware::hidl_string> listServices() override;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800174 };
175
176 /**
177 * Listener interface for device/torch status changes
178 */
179 struct StatusListener : virtual public RefBase {
180 ~StatusListener() {}
181
Austin Borger0fb3ad92023-06-01 16:51:35 -0700182 virtual void onDeviceStatusChanged(const std::string &cameraId,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700183 CameraDeviceStatus newStatus) = 0;
Austin Borger0fb3ad92023-06-01 16:51:35 -0700184 virtual void onDeviceStatusChanged(const std::string &cameraId,
185 const std::string &physicalCameraId,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700186 CameraDeviceStatus newStatus) = 0;
Austin Borger0fb3ad92023-06-01 16:51:35 -0700187 virtual void onTorchStatusChanged(const std::string &cameraId,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700188 TorchModeStatus newStatus,
Jayant Chowdhary46ef0f52021-10-05 14:36:13 -0700189 SystemCameraKind kind) = 0;
Austin Borger0fb3ad92023-06-01 16:51:35 -0700190 virtual void onTorchStatusChanged(const std::string &cameraId,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700191 TorchModeStatus newStatus) = 0;
Emilian Peevaee727d2017-05-04 16:35:48 +0100192 virtual void onNewProviderRegistered() = 0;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800193 };
194
195 /**
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700196 * Represents the mode a camera device is currently in
197 */
198 enum class DeviceMode {
199 TORCH,
200 CAMERA
201 };
202
203 /**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800204 * Initialize the manager and give it a status listener; optionally accepts a service
205 * interaction proxy.
206 *
207 * The default proxy communicates via the hardware service manager; alternate proxies can be
208 * used for testing. The lifetime of the proxy must exceed the lifetime of the manager.
209 */
210 status_t initialize(wp<StatusListener> listener,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700211 HidlServiceInteractionProxy *hidlProxy = &sHidlServiceInteractionProxy);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800212
Jayant Chowdhary22441f32021-12-26 18:35:41 -0800213 status_t getCameraIdIPCTransport(const std::string &id,
214 IPCTransport *providerTransport) const;
215
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800216 /**
Jayant Chowdhary847947d2019-08-30 18:02:59 -0700217 * Retrieve the total number of available cameras.
218 * This value may change dynamically as cameras are added or removed.
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800219 */
Jayant Chowdhary847947d2019-08-30 18:02:59 -0700220 std::pair<int, int> getCameraCount() const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800221
Shuzhen Wang3d316f32022-10-25 20:33:34 +0000222 /**
223 * Upon the function return, if unavailablePhysicalIds is not nullptr, it
224 * will contain all of the unavailable physical camera Ids represented in
225 * the form of:
226 * {[logicalCamera, {physicalCamera1, physicalCamera2, ...}], ...}.
227 */
228 std::vector<std::string> getCameraDeviceIds(std::unordered_map<
229 std::string, std::set<std::string>>* unavailablePhysicalIds = nullptr) const;
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -0800230
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800231 /**
Emilian Peevf53f66e2017-04-11 14:29:43 +0100232 * Retrieve the number of API1 compatible cameras; these are internal and
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800233 * backwards-compatible. This is the set of cameras that will be
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -0800234 * accessible via the old camera API.
235 * The return value may change dynamically due to external camera hotplug.
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800236 */
Emilian Peevf53f66e2017-04-11 14:29:43 +0100237 std::vector<std::string> getAPI1CompatibleCameraDeviceIds() const;
Yin-Chia Yehdc3134e2017-03-23 15:26:59 -0700238
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800239 /**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800240 * Return true if a device with a given ID has a flash unit. Returns false
241 * for devices that are unknown.
242 */
243 bool hasFlashUnit(const std::string &id) const;
244
245 /**
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -0800246 * Return true if the camera device has native zoom ratio support.
247 */
248 bool supportNativeZoomRatio(const std::string &id) const;
249
250 /**
Emilian Peev15230142023-04-27 20:22:54 +0000251 * Return true if the camera device has no composite Jpeg/R support.
Emilian Peeve579d8b2023-02-28 14:16:08 -0800252 */
Emilian Peev15230142023-04-27 20:22:54 +0000253 bool isCompositeJpegRDisabled(const std::string &id) const;
Emilian Peeve579d8b2023-02-28 14:16:08 -0800254
255 /**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800256 * Return the resource cost of this camera device
257 */
258 status_t getResourceCost(const std::string &id,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700259 CameraResourceCost* cost) const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800260
261 /**
262 * Return the old camera API camera info
263 */
264 status_t getCameraInfo(const std::string &id,
Austin Borger3560b7e2022-10-27 12:20:29 -0700265 bool overrideToPortrait, int *portraitRotation, hardware::CameraInfo* info) const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800266
267 /**
268 * Return API2 camera characteristics - returns NAME_NOT_FOUND if a device ID does
269 * not have a v3 or newer HAL version.
270 */
271 status_t getCameraCharacteristics(const std::string &id,
Austin Borger3560b7e2022-10-27 12:20:29 -0700272 bool overrideForPerfClass, CameraMetadata* characteristics,
273 bool overrideToPortrait) const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800274
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800275 status_t isConcurrentSessionConfigurationSupported(
276 const std::vector<hardware::camera2::utils::CameraIdAndSessionConfiguration>
277 &cameraIdsAndSessionConfigs,
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700278 const std::set<std::string>& perfClassPrimaryCameraIds,
279 int targetSdkVersion, bool *isSupported);
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800280
Jayant Chowdharycad23c22020-03-10 15:04:59 -0700281 std::vector<std::unordered_set<std::string>> getConcurrentCameraIds() const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800282 /**
Emilian Peev35ae8262018-11-08 13:11:32 +0000283 * Check for device support of specific stream combination.
284 */
285 status_t isSessionConfigurationSupported(const std::string& id,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700286 const SessionConfiguration &configuration,
Shuzhen Wanga79a64d2022-04-24 19:56:30 -0700287 bool overrideForPerfClass, camera3::metadataGetter getMetadata,
Emilian Peev35ae8262018-11-08 13:11:32 +0000288 bool *status /*out*/) const;
289
290 /**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800291 * Return the highest supported device interface version for this ID
292 */
293 status_t getHighestSupportedVersion(const std::string &id,
Jayant Chowdharyffc5d682022-05-12 18:34:34 +0000294 hardware::hidl_version *v, IPCTransport *transport);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800295
296 /**
Yin-Chia Yehdc3134e2017-03-23 15:26:59 -0700297 * Check if a given camera device support setTorchMode API.
298 */
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700299 bool supportSetTorchMode(const std::string &id) const;
Yin-Chia Yehdc3134e2017-03-23 15:26:59 -0700300
301 /**
Rucha Katakwar38284522021-11-10 11:25:21 -0800302 * Check if torch strength update should be skipped or not.
303 */
304 bool shouldSkipTorchStrengthUpdate(const std::string &id, int32_t torchStrength) const;
305
306 /**
307 * Return the default torch strength level if the torch strength control
308 * feature is supported.
309 */
310 int32_t getTorchDefaultStrengthLevel(const std::string &id) const;
311
312 /**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800313 * Turn on or off the flashlight on a given camera device.
Yin-Chia Yehdc3134e2017-03-23 15:26:59 -0700314 * May fail if the device does not support this API, is in active use, or if the device
315 * doesn't exist, etc.
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800316 */
317 status_t setTorchMode(const std::string &id, bool enabled);
318
319 /**
Rucha Katakwar38284522021-11-10 11:25:21 -0800320 * Change the brightness level of the flash unit associated with the cameraId and
321 * set it to the value in torchStrength.
322 * If the torch is OFF and torchStrength > 0, the torch will be turned ON with the
323 * specified strength level. If the torch is ON, only the brightness level will be
324 * changed.
325 *
326 * This operation will fail if the device does not have flash unit, has flash unit
327 * but does not support this API, torchStrength is invalid or if the device doesn't
328 * exist etc.
329 */
330 status_t turnOnTorchWithStrengthLevel(const std::string &id, int32_t torchStrength);
331
332 /**
333 * Return the torch strength level of this camera device.
334 */
335 status_t getTorchStrengthLevel(const std::string &id, int32_t* torchStrength);
336
337 /**
Yin-Chia Yeh067428c2017-01-13 15:19:24 -0800338 * Setup vendor tags for all registered providers
339 */
340 status_t setUpVendorTags();
341
342 /**
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800343 * Inform registered providers about a device state change, such as folding or unfolding
344 */
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700345 status_t notifyDeviceStateChange(int64_t newState);
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800346
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000347 status_t openAidlSession(const std::string &id,
348 const std::shared_ptr<
349 aidl::android::hardware::camera::device::ICameraDeviceCallback>& callback,
350 /*out*/
351 std::shared_ptr<aidl::android::hardware::camera::device::ICameraDeviceSession> *session);
352
Jayant Chowdhary35642f22022-01-08 00:39:39 +0000353 status_t openAidlInjectionSession(const std::string &id,
354 const std::shared_ptr<
355 aidl::android::hardware::camera::device::ICameraDeviceCallback>& callback,
356 /*out*/
357 std::shared_ptr<aidl::android::hardware::camera::device::ICameraInjectionSession> *session);
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000358
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800359 /**
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800360 * Open an active session to a camera device.
361 *
362 * This fully powers on the camera device hardware, and returns a handle to a
363 * session to be used for hardware configuration and operation.
364 */
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700365 status_t openHidlSession(const std::string &id,
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800366 const sp<hardware::camera::device::V3_2::ICameraDeviceCallback>& callback,
367 /*out*/
368 sp<hardware::camera::device::V3_2::ICameraDeviceSession> *session);
369
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800370 /**
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700371 * Notify that the camera or torch is no longer being used by a camera client
372 */
373 void removeRef(DeviceMode usageType, const std::string &cameraId);
374
375 /**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800376 * IServiceNotification::onRegistration
377 * Invoked by the hardware service manager when a new camera provider is registered
378 */
379 virtual hardware::Return<void> onRegistration(const hardware::hidl_string& fqName,
380 const hardware::hidl_string& name,
381 bool preexisting) override;
382
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000383 // LocalRegistrationCallback::onServiceRegistration
384 virtual void onServiceRegistration(const String16& name, const sp<IBinder> &binder) override;
385
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800386 /**
387 * Dump out information about available providers and devices
388 */
389 status_t dump(int fd, const Vector<String16>& args);
390
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800391 /**
392 * Conversion methods between HAL Status and status_t and strings
393 */
394 static status_t mapToStatusT(const hardware::camera::common::V1_0::Status& s);
395 static const char* statusToString(const hardware::camera::common::V1_0::Status& s);
396
Emilian Peev71c73a22017-03-21 16:35:51 +0000397 /*
398 * Return provider type for a specific device.
399 */
Jayant Chowdharyffc5d682022-05-12 18:34:34 +0000400 metadata_vendor_id_t getProviderTagIdLocked(const std::string& id) const;
Emilian Peev71c73a22017-03-21 16:35:51 +0000401
Shuzhen Wange8aceb52018-05-21 12:00:56 -0700402 /*
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700403 * Check if a camera is a logical camera. And if yes, return
Shuzhen Wange8aceb52018-05-21 12:00:56 -0700404 * the physical camera ids.
405 */
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700406 bool isLogicalCamera(const std::string& id, std::vector<std::string>* physicalCameraIds);
Shuzhen Wange8aceb52018-05-21 12:00:56 -0700407
Jayant Chowdhary33e8ef82019-09-27 09:20:42 -0700408 status_t getSystemCameraKind(const std::string& id, SystemCameraKind *kind) const;
409 bool isHiddenPhysicalCamera(const std::string& cameraId) const;
Emilian Peev538c90e2018-12-17 18:03:19 +0000410
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700411 status_t filterSmallJpegSizes(const std::string& cameraId);
Shuzhen Wang89db2992021-05-20 13:09:48 -0700412
Valentin Iftime29e2e152021-08-13 15:17:33 +0200413 status_t notifyUsbDeviceEvent(int32_t eventId, const std::string &usbDeviceId);
414
Emilian Peev434248e2022-10-06 14:58:54 -0700415 static bool isConcurrentDynamicRangeCaptureSupported(const CameraMetadata& deviceInfo,
416 int64_t profile, int64_t concurrentProfile);
417
Emilian Peev538c90e2018-12-17 18:03:19 +0000418 static const float kDepthARTolerance;
Emilian Peev434248e2022-10-06 14:58:54 -0700419 static const bool kFrameworkJpegRDisabled;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800420private:
421 // All private members, unless otherwise noted, expect mInterfaceMutex to be locked before use
422 mutable std::mutex mInterfaceMutex;
423
424 wp<StatusListener> mListener;
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700425 HidlServiceInteractionProxy* mHidlServiceProxy;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800426
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800427 // Current overall Android device physical status
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700428 int64_t mDeviceState;
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800429
Shuzhen Wang6ba8eb22018-07-08 13:10:44 -0700430 // mProviderLifecycleLock is locked during onRegistration and removeProvider
431 mutable std::mutex mProviderLifecycleLock;
432
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700433 static HidlServiceInteractionProxyImpl sHidlServiceInteractionProxy;
434
435 struct HalCameraProvider {
436 // Empty parent struct for storing either aidl / hidl camera provider reference
437 HalCameraProvider(const char *descriptor) : mDescriptor(descriptor) { };
438 virtual ~HalCameraProvider() {};
439 std::string mDescriptor;
440 };
441
442 struct HidlHalCameraProvider : public HalCameraProvider {
443 HidlHalCameraProvider(
444 const sp<hardware::camera::provider::V2_4::ICameraProvider> &provider,
445 const char *descriptor) :
446 HalCameraProvider(descriptor), mCameraProvider(provider) { };
447 private:
448 sp<hardware::camera::provider::V2_4::ICameraProvider> mCameraProvider;
449 };
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800450
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000451 struct AidlHalCameraProvider : public HalCameraProvider {
452 AidlHalCameraProvider(
453 const std::shared_ptr<
454 aidl::android::hardware::camera::provider::ICameraProvider> &provider,
455 const char *descriptor) :
456 HalCameraProvider(descriptor), mCameraProvider(provider) { };
457 private:
458 std::shared_ptr<aidl::android::hardware::camera::provider::ICameraProvider> mCameraProvider;
459 };
460
461
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700462 // Mapping from CameraDevice IDs to CameraProviders. This map is used to keep the
463 // ICameraProvider alive while it is in use by the camera with the given ID for camera
464 // capabilities
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700465 std::unordered_map<std::string, std::shared_ptr<HalCameraProvider>>
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700466 mCameraProviderByCameraId;
467
468 // Mapping from CameraDevice IDs to CameraProviders. This map is used to keep the
469 // ICameraProvider alive while it is in use by the camera with the given ID for torch
470 // capabilities
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700471 std::unordered_map<std::string, std::shared_ptr<HalCameraProvider>>
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700472 mTorchProviderByCameraId;
473
474 // Lock for accessing mCameraProviderByCameraId and mTorchProviderByCameraId
475 std::mutex mProviderInterfaceMapLock;
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700476 struct ProviderInfo : public virtual RefBase {
477 friend struct HidlProviderInfo;
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000478 friend struct AidlProviderInfo;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800479 const std::string mProviderName;
Emilian Peevc93cac22020-08-17 16:00:10 -0700480 const std::string mProviderInstance;
Emilian Peev71c73a22017-03-21 16:35:51 +0000481 const metadata_vendor_id_t mProviderTagid;
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000482 int32_t mMinorVersion;
Peter Kalauskas1b3c9072018-11-07 12:41:53 -0800483 sp<VendorTagDescriptor> mVendorTagDescriptor;
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700484 bool mSetTorchModeSupported;
485 bool mIsRemote;
486
Emilian Peevc93cac22020-08-17 16:00:10 -0700487 ProviderInfo(const std::string &providerName, const std::string &providerInstance,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800488 CameraProviderManager *manager);
489 ~ProviderInfo();
490
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700491 virtual IPCTransport getIPCTransport() = 0;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800492
493 const std::string& getType() const;
494
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800495 status_t dump(int fd, const Vector<String16>& args) const;
496
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000497 void initializeProviderInfoCommon(const std::vector<std::string> &devices);
Peter Kalauskas1b3c9072018-11-07 12:41:53 -0800498 /**
499 * Setup vendor tags for this provider
500 */
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700501 virtual status_t setUpVendorTags() = 0;
Peter Kalauskas1b3c9072018-11-07 12:41:53 -0800502
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800503 /**
504 * Notify provider about top-level device physical state changes
Emilian Peev7fe6c422021-09-08 13:43:20 -0700505 *
506 * Note that 'mInterfaceMutex' should not be held when calling this method.
507 * It is possible for camera providers to add/remove devices and try to
508 * acquire it.
Eino-Ville Talvala63f36112018-12-06 14:57:03 -0800509 */
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700510 virtual status_t notifyDeviceStateChange(int64_t newDeviceState) = 0;
511
512 virtual bool successfullyStartedProviderInterface() = 0;
Jayant Chowdharycbe770a2020-02-14 11:14:46 -0800513
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000514 virtual int64_t getDeviceState() = 0;
515
Jayant Chowdharycbe770a2020-02-14 11:14:46 -0800516 std::vector<std::unordered_set<std::string>> getConcurrentCameraIdCombinations();
517
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800518 /**
Emilian Peevb50402e2021-09-24 17:41:57 -0700519 * Notify 'DeviceInfo' instanced about top-level device physical state changes
520 *
521 * Note that 'mInterfaceMutex' should be held when calling this method.
522 */
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700523 void notifyDeviceInfoStateChangeLocked(int64_t newDeviceState);
Emilian Peevb50402e2021-09-24 17:41:57 -0700524
525 /**
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800526 * Query the camera provider for concurrent stream configuration support
527 */
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700528 virtual status_t isConcurrentSessionConfigurationSupported(
529 const std::vector<CameraIdAndSessionConfiguration> &cameraIdsAndSessionConfigs,
530 const std::set<std::string>& perfClassPrimaryCameraIds,
531 int targetSdkVersion, bool *isSupported) = 0;
532
Valentin Iftime29e2e152021-08-13 15:17:33 +0200533 /**
534 * Remove all devices associated with this provider and notify listeners
535 * with NOT_PRESENT state.
536 */
537 void removeAllDevices();
538
539 /**
540 * Provider is an external lazy HAL
541 */
542 bool isExternalLazyHAL() const;
543
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800544 // Basic device information, common to all camera devices
545 struct DeviceInfo {
546 const std::string mName; // Full instance name
547 const std::string mId; // ID section of full name
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700548 //Both hidl and aidl DeviceInfos. Aidl deviceInfos get {3, 8} to
549 //start off.
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800550 const hardware::hidl_version mVersion;
Emilian Peev71c73a22017-03-21 16:35:51 +0000551 const metadata_vendor_id_t mProviderTagid;
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700552 bool mIsLogicalCamera;
553 std::vector<std::string> mPhysicalIds;
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700554 hardware::CameraInfo mInfo;
Jayant Chowdhary5216b212019-07-17 09:26:23 -0700555 SystemCameraKind mSystemCameraKind = SystemCameraKind::PUBLIC;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800556
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700557 const CameraResourceCost mResourceCost;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800558
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700559 CameraDeviceStatus mStatus;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800560
Shuzhen Wang79680432020-03-05 11:53:46 -0800561 wp<ProviderInfo> mParentProvider;
Rucha Katakwar38284522021-11-10 11:25:21 -0800562 // Torch strength default, maximum levels if the torch strength control
563 // feature is supported.
564 int32_t mTorchStrengthLevel;
565 int32_t mTorchMaximumStrengthLevel;
566 int32_t mTorchDefaultStrengthLevel;
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700567
Valentin Iftime29e2e152021-08-13 15:17:33 +0200568 // Wait for lazy HALs to confirm device availability
569 static const nsecs_t kDeviceAvailableTimeout = 2000e6; // 2000 ms
570 Mutex mDeviceAvailableLock;
571 Condition mDeviceAvailableSignal;
572 bool mIsDeviceAvailable = true;
573
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800574 bool hasFlashUnit() const { return mHasFlashUnit; }
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -0800575 bool supportNativeZoomRatio() const { return mSupportNativeZoomRatio; }
Emilian Peev15230142023-04-27 20:22:54 +0000576 bool isCompositeJpegRDisabled() const { return mCompositeJpegRDisabled; }
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800577 virtual status_t setTorchMode(bool enabled) = 0;
Rucha Katakwar38284522021-11-10 11:25:21 -0800578 virtual status_t turnOnTorchWithStrengthLevel(int32_t torchStrength) = 0;
579 virtual status_t getTorchStrengthLevel(int32_t *torchStrength) = 0;
Austin Borger3560b7e2022-10-27 12:20:29 -0700580 virtual status_t getCameraInfo(bool overrideToPortrait,
581 int *portraitRotation,
582 hardware::CameraInfo *info) const = 0;
Emilian Peevf53f66e2017-04-11 14:29:43 +0100583 virtual bool isAPI1Compatible() const = 0;
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700584 virtual status_t dumpState(int fd) = 0;
Jing Mikec7f9b132023-03-12 11:12:04 +0800585 virtual status_t getCameraCharacteristics(
586 [[maybe_unused]] bool overrideForPerfClass,
587 [[maybe_unused]] CameraMetadata *characteristics,
588 [[maybe_unused]] bool overrideToPortrait) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800589 return INVALID_OPERATION;
590 }
Jing Mikec7f9b132023-03-12 11:12:04 +0800591 virtual status_t getPhysicalCameraCharacteristics(
592 [[maybe_unused]] const std::string& physicalCameraId,
593 [[maybe_unused]] CameraMetadata *characteristics) const {
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700594 return INVALID_OPERATION;
595 }
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800596
Emilian Peev35ae8262018-11-08 13:11:32 +0000597 virtual status_t isSessionConfigurationSupported(
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700598 const SessionConfiguration &/*configuration*/,
599 bool /*overrideForPerfClass*/,
Shuzhen Wanga79a64d2022-04-24 19:56:30 -0700600 camera3::metadataGetter /*getMetadata*/,
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700601 bool * /*status*/) {
Emilian Peev35ae8262018-11-08 13:11:32 +0000602 return INVALID_OPERATION;
603 }
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700604 virtual status_t filterSmallJpegSizes() = 0;
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700605 virtual void notifyDeviceStateChange(int64_t /*newState*/) {}
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700606
Emilian Peev71c73a22017-03-21 16:35:51 +0000607 DeviceInfo(const std::string& name, const metadata_vendor_id_t tagId,
608 const std::string &id, const hardware::hidl_version& version,
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700609 const std::vector<std::string>& publicCameraIds,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700610 const CameraResourceCost& resourceCost,
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700611 sp<ProviderInfo> parentProvider) :
Emilian Peev71c73a22017-03-21 16:35:51 +0000612 mName(name), mId(id), mVersion(version), mProviderTagid(tagId),
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700613 mIsLogicalCamera(false), mResourceCost(resourceCost),
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700614 mStatus(CameraDeviceStatus::PRESENT),
Rucha Katakwar3c6714d2021-12-15 13:56:55 -0800615 mParentProvider(parentProvider), mTorchStrengthLevel(0),
616 mTorchMaximumStrengthLevel(0), mTorchDefaultStrengthLevel(0),
617 mHasFlashUnit(false), mSupportNativeZoomRatio(false),
Emilian Peev15230142023-04-27 20:22:54 +0000618 mPublicCameraIds(publicCameraIds), mCompositeJpegRDisabled(false) {}
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700619 virtual ~DeviceInfo() {}
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800620 protected:
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700621
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -0800622 bool mHasFlashUnit; // const after constructor
623 bool mSupportNativeZoomRatio; // const after constructor
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700624 const std::vector<std::string>& mPublicCameraIds;
Emilian Peev15230142023-04-27 20:22:54 +0000625 bool mCompositeJpegRDisabled;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800626 };
627 std::vector<std::unique_ptr<DeviceInfo>> mDevices;
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -0800628 std::unordered_set<std::string> mUniqueCameraIds;
Shuzhen Wang3d316f32022-10-25 20:33:34 +0000629 std::unordered_map<std::string, std::set<std::string>> mUnavailablePhysicalCameras;
Yin-Chia Yehe8e9e192017-03-16 15:23:51 -0700630 int mUniqueDeviceCount;
Shuzhen Wange8aceb52018-05-21 12:00:56 -0700631 std::vector<std::string> mUniqueAPI1CompatibleCameraIds;
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700632 // The initial public camera IDs published by the camera provider.
633 // Currently logical multi-camera is not supported for hot-plug camera.
634 // And we use this list to keep track of initial public camera IDs
635 // advertised by the provider, and to distinguish against "hidden"
636 // physical camera IDs.
637 std::vector<std::string> mProviderPublicCameraIds;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800638
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800639 // HALv3-specific camera fields, including the actual device interface
640 struct DeviceInfo3 : public DeviceInfo {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800641
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700642 virtual status_t setTorchMode(bool enabled) = 0;
643 virtual status_t turnOnTorchWithStrengthLevel(int32_t torchStrength) = 0;
644 virtual status_t getTorchStrengthLevel(int32_t *torchStrength) = 0;
Austin Borger3560b7e2022-10-27 12:20:29 -0700645 virtual status_t getCameraInfo(bool overrideToPortrait,
646 int *portraitRotation,
647 hardware::CameraInfo *info) const override;
Emilian Peevf53f66e2017-04-11 14:29:43 +0100648 virtual bool isAPI1Compatible() const override;
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700649 virtual status_t dumpState(int fd) = 0;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800650 virtual status_t getCameraCharacteristics(
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700651 bool overrideForPerfClass,
Austin Borger3560b7e2022-10-27 12:20:29 -0700652 CameraMetadata *characteristics,
653 bool overrideToPortrait) override;
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700654 virtual status_t getPhysicalCameraCharacteristics(const std::string& physicalCameraId,
655 CameraMetadata *characteristics) const override;
Emilian Peev35ae8262018-11-08 13:11:32 +0000656 virtual status_t isSessionConfigurationSupported(
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700657 const SessionConfiguration &configuration, bool /*overrideForPerfClass*/,
Shuzhen Wanga79a64d2022-04-24 19:56:30 -0700658 camera3::metadataGetter /*getMetadata*/,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700659 bool *status /*out*/) = 0;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700660 virtual status_t filterSmallJpegSizes() override;
Emilian Peevb50402e2021-09-24 17:41:57 -0700661 virtual void notifyDeviceStateChange(
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700662 int64_t newState) override;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800663
Emilian Peev71c73a22017-03-21 16:35:51 +0000664 DeviceInfo3(const std::string& name, const metadata_vendor_id_t tagId,
665 const std::string &id, uint16_t minorVersion,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700666 const CameraResourceCost& resourceCost,
Peter Kalauskasa29c1352018-10-10 12:05:42 -0700667 sp<ProviderInfo> parentProvider,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700668 const std::vector<std::string>& publicCameraIds);
669 virtual ~DeviceInfo3() {};
670 protected:
671 // Modified by derived transport specific (hidl / aidl) class
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800672 CameraMetadata mCameraCharacteristics;
Emilian Peevb50402e2021-09-24 17:41:57 -0700673 // Map device states to sensor orientations
674 std::unordered_map<int64_t, int32_t> mDeviceStateOrientationMap;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700675 // A copy of mCameraCharacteristics without performance class
676 // override
677 std::unique_ptr<CameraMetadata> mCameraCharNoPCOverride;
Shuzhen Wanga79a64d2022-04-24 19:56:30 -0700678 // Only contains characteristics for hidden physical cameras,
679 // not for public physical cameras.
Shuzhen Wangf9d2c022018-08-21 12:07:35 -0700680 std::unordered_map<std::string, CameraMetadata> mPhysicalCameraCharacteristics;
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700681 void queryPhysicalCameraIds();
Jayant Chowdhary5216b212019-07-17 09:26:23 -0700682 SystemCameraKind getSystemCameraKind();
Shuzhen Wang268a1362018-10-16 16:32:59 -0700683 status_t fixupMonochromeTags();
Rucha Katakwar31fbf3a2022-05-02 13:23:56 -0700684 status_t fixupTorchStrengthTags();
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800685 status_t addDynamicDepthTags(bool maxResolution = false);
686 status_t deriveHeicTags(bool maxResolution = false);
Emilian Peev434248e2022-10-06 14:58:54 -0700687 status_t deriveJpegRTags(bool maxResolution = false);
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800688 status_t addRotateCropTags();
Bharatt Kukrejad33fe9f2022-11-23 21:52:52 +0000689 status_t addAutoframingTags();
Shuzhen Wang9bf8a6f2020-05-01 09:49:04 -0700690 status_t addPreCorrectionActiveArraySize();
Jayant Chowdharyffc5d682022-05-12 18:34:34 +0000691 status_t addReadoutTimestampTag(bool readoutTimestampSupported = true);
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800692
Emilian Peev4c6d2b52019-01-04 17:13:56 +0000693 static void getSupportedSizes(const CameraMetadata& ch, uint32_t tag,
694 android_pixel_format_t format,
695 std::vector<std::tuple<size_t, size_t>> *sizes /*out*/);
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700696 static void getSupportedDurations( const CameraMetadata& ch, uint32_t tag,
Emilian Peev4c6d2b52019-01-04 17:13:56 +0000697 android_pixel_format_t format,
698 const std::vector<std::tuple<size_t, size_t>>& sizes,
699 std::vector<int64_t> *durations/*out*/);
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700700 static void getSupportedDynamicDepthDurations(
701 const std::vector<int64_t>& depthDurations,
Emilian Peev4c6d2b52019-01-04 17:13:56 +0000702 const std::vector<int64_t>& blobDurations,
703 std::vector<int64_t> *dynamicDepthDurations /*out*/);
704 static void getSupportedDynamicDepthSizes(
705 const std::vector<std::tuple<size_t, size_t>>& blobSizes,
706 const std::vector<std::tuple<size_t, size_t>>& depthSizes,
707 std::vector<std::tuple<size_t, size_t>> *dynamicDepthSizes /*out*/,
708 std::vector<std::tuple<size_t, size_t>> *internalDepthSizes /*out*/);
Shuzhen Wang268a1362018-10-16 16:32:59 -0700709 status_t removeAvailableKeys(CameraMetadata& c, const std::vector<uint32_t>& keys,
710 uint32_t keyTag);
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800711 status_t fillHeicStreamCombinations(std::vector<int32_t>* outputs,
712 std::vector<int64_t>* durations,
713 std::vector<int64_t>* stallDurations,
714 const camera_metadata_entry& halStreamConfigs,
715 const camera_metadata_entry& halStreamDurations);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800716 };
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700717 protected:
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800718 std::string mType;
719 uint32_t mId;
720
Eino-Ville Talvala8d942f92017-03-13 10:09:51 -0700721 std::mutex mLock;
722
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800723 CameraProviderManager *mManager;
724
Shuzhen Wang394ad702020-07-23 13:01:54 -0700725 struct CameraStatusInfoT {
726 bool isPhysicalCameraStatus = false;
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700727 std::string cameraId;
728 std::string physicalCameraId;
729 CameraDeviceStatus status;
730 CameraStatusInfoT(bool isForPhysicalCamera, const std::string& id,
731 const std::string& physicalId,
732 CameraDeviceStatus s) :
Shuzhen Wang394ad702020-07-23 13:01:54 -0700733 isPhysicalCameraStatus(isForPhysicalCamera), cameraId(id),
734 physicalCameraId(physicalId), status(s) {}
735 };
736
737 // Lock to synchronize between initialize() and camera status callbacks
738 std::mutex mInitLock;
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -0800739 bool mInitialized = false;
Shuzhen Wang394ad702020-07-23 13:01:54 -0700740 std::vector<CameraStatusInfoT> mCachedStatus;
741 // End of scope for mInitLock
742
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000743 std::unique_ptr<ProviderInfo::DeviceInfo>
744 virtual initializeDeviceInfo(
745 const std::string &name, const metadata_vendor_id_t tagId,
746 const std::string &id, uint16_t minorVersion) = 0;
747
748 virtual status_t reCacheConcurrentStreamingCameraIdsLocked() = 0;
749
Jayant Chowdharycbe770a2020-02-14 11:14:46 -0800750 std::vector<std::unordered_set<std::string>> mConcurrentCameraIdCombinations;
751
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800752 // Parse provider instance name for type and id
753 static status_t parseProviderName(const std::string& name,
754 std::string *type, uint32_t *id);
755
756 // Parse device instance name for device version, type, and id.
757 static status_t parseDeviceName(const std::string& name,
758 uint16_t *major, uint16_t *minor, std::string *type, std::string *id);
Emilian Peev71c73a22017-03-21 16:35:51 +0000759
760 // Generate vendor tag id
761 static metadata_vendor_id_t generateVendorTagId(const std::string &name);
Guennadi Liakhovetski6034bf52017-12-07 10:28:29 +0100762
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000763 status_t addDevice(
764 const std::string& name, CameraDeviceStatus initialStatus,
765 /*out*/ std::string* parsedId);
766
767 void cameraDeviceStatusChangeInternal(const std::string& cameraDeviceName,
768 CameraDeviceStatus newStatus);
769
770 status_t cameraDeviceStatusChangeLocked(
771 std::string* id, const std::string& cameraDeviceName,
772 CameraDeviceStatus newStatus);
773
774 void physicalCameraDeviceStatusChangeInternal(const std::string& cameraDeviceName,
775 const std::string& physicalCameraDeviceName,
776 CameraDeviceStatus newStatus);
777
778 status_t physicalCameraDeviceStatusChangeLocked(
779 std::string* id, std::string* physicalId,
780 const std::string& cameraDeviceName,
781 const std::string& physicalCameraDeviceName,
782 CameraDeviceStatus newStatus);
783
784 void torchModeStatusChangeInternal(const std::string& cameraDeviceName,
785 TorchModeStatus newStatus);
786
Austin Borger0fb3ad92023-06-01 16:51:35 -0700787 void removeDevice(const std::string &id);
Jayant Chowdharycbe770a2020-02-14 11:14:46 -0800788
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800789 };
790
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000791 template <class ProviderInfoType, class HalCameraProviderType>
792 status_t setTorchModeT(sp<ProviderInfo> &parentProvider,
793 std::shared_ptr<HalCameraProvider> *halCameraProvider);
794
795 // Try to get hidl provider services declared. Expects mInterfaceMutex to be
796 // locked. Also registers for hidl provider service notifications.
797 status_t tryToInitAndAddHidlProvidersLocked(HidlServiceInteractionProxy *hidlProxy);
798
799 // Try to get aidl provider services declared. Expects mInterfaceMutex to be
800 // locked. Also registers for aidl provider service notifications.
801 status_t tryToAddAidlProvidersLocked();
802
Emilian Peev7fe6c422021-09-08 13:43:20 -0700803 /**
804 * Save the ICameraProvider while it is being used by a camera or torch client
805 */
806 void saveRef(DeviceMode usageType, const std::string &cameraId,
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700807 std::shared_ptr<HalCameraProvider> provider);
Emilian Peev7fe6c422021-09-08 13:43:20 -0700808
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800809 // Utility to find a DeviceInfo by ID; pointer is only valid while mInterfaceMutex is held
810 // and the calling code doesn't mutate the list of providers or their lists of devices.
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800811 // No guarantees on the order of traversal
Jayant Chowdharyffc5d682022-05-12 18:34:34 +0000812 ProviderInfo::DeviceInfo* findDeviceInfoLocked(const std::string& id) const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800813
Emilian Peev15230142023-04-27 20:22:54 +0000814 bool isCompositeJpegRDisabledLocked(const std::string &id) const;
Emilian Peeve579d8b2023-02-28 14:16:08 -0800815
Valentin Iftime29e2e152021-08-13 15:17:33 +0200816 // Map external providers to USB devices in order to handle USB hotplug
817 // events for lazy HALs
818 std::pair<std::vector<std::string>, sp<ProviderInfo>>
819 mExternalUsbDevicesForProvider;
820 sp<ProviderInfo> startExternalLazyProvider() const;
821
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700822 status_t addHidlProviderLocked(const std::string& newProvider, bool preexisting = false);
Emilian Peevc93cac22020-08-17 16:00:10 -0700823
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000824 status_t addAidlProviderLocked(const std::string& newProvider);
825
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700826 status_t tryToInitializeHidlProviderLocked(const std::string& providerName,
Emilian Peevc93cac22020-08-17 16:00:10 -0700827 const sp<ProviderInfo>& providerInfo);
Eino-Ville Talvala8d942f92017-03-13 10:09:51 -0700828
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000829 status_t tryToInitializeAidlProviderLocked(const std::string& providerName,
830 const sp<ProviderInfo>& providerInfo);
831
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800832 bool isLogicalCameraLocked(const std::string& id, std::vector<std::string>* physicalCameraIds);
833
Jayant Chowdharye8c4b232022-02-04 18:18:04 +0000834 // No method corresponding to the same provider / member belonging to the
835 // same provider should be used after this method is called since it'll lead
836 // to invalid memory access (especially since this is called by ProviderInfo methods on hal
837 // service death).
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800838 status_t removeProvider(const std::string& provider);
Eino-Ville Talvala8d942f92017-03-13 10:09:51 -0700839 sp<StatusListener> getStatusListener() const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800840
Jayant Chowdharyffc5d682022-05-12 18:34:34 +0000841 bool isValidDeviceLocked(const std::string &id, uint16_t majorVersion,
842 IPCTransport transport) const;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800843
Emilian Peevc93cac22020-08-17 16:00:10 -0700844 size_t mProviderInstanceId = 0;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800845 std::vector<sp<ProviderInfo>> mProviders;
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000846 // Provider names of AIDL providers with retrieved binders.
847 std::set<std::string> mAidlProviderWithBinders;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800848
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800849 static const char* deviceStatusToString(
850 const hardware::camera::common::V1_0::CameraDeviceStatus&);
851 static const char* torchStatusToString(
852 const hardware::camera::common::V1_0::TorchModeStatus&);
853
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700854 status_t getCameraCharacteristicsLocked(const std::string &id, bool overrideForPerfClass,
Austin Borger3560b7e2022-10-27 12:20:29 -0700855 CameraMetadata* characteristics, bool overrideToPortrait) const;
Shuzhen Wange8aceb52018-05-21 12:00:56 -0700856 void filterLogicalCameraIdsLocked(std::vector<std::string>& deviceIds) const;
Jayant Chowdhary847947d2019-08-30 18:02:59 -0700857
Jayant Chowdhary33e8ef82019-09-27 09:20:42 -0700858 status_t getSystemCameraKindLocked(const std::string& id, SystemCameraKind *kind) const;
Jayant Chowdhary0bd38522021-11-05 17:49:27 -0700859 std::pair<bool, ProviderInfo::DeviceInfo *> isHiddenPhysicalCameraInternal(
860 const std::string& cameraId) const;
Jayant Chowdhary847947d2019-08-30 18:02:59 -0700861
862 void collectDeviceIdsLocked(const std::vector<std::string> deviceIds,
863 std::vector<std::string>& normalDeviceIds,
864 std::vector<std::string>& systemCameraDeviceIds) const;
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800865
Valentin Iftime29e2e152021-08-13 15:17:33 +0200866 status_t usbDeviceDetached(const std::string &usbDeviceId);
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000867 ndk::ScopedAStatus onAidlRegistration(const std::string& in_name,
868 const ::ndk::SpAIBinder& in_binder);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800869};
870
871} // namespace android
872
873#endif