Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 1 | /* |
| 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 Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 21 | #include <unordered_map> |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 22 | #include <unordered_set> |
Shuzhen Wang | d4abdf7 | 2021-05-28 11:22:50 -0700 | [diff] [blame] | 23 | #include <set> |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 24 | #include <string> |
| 25 | #include <mutex> |
| 26 | |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 27 | #include <camera/camera2/ConcurrentCamera.h> |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 28 | #include <camera/CameraParameters2.h> |
| 29 | #include <camera/CameraMetadata.h> |
| 30 | #include <camera/CameraBase.h> |
Valentin Iftime | 29e2e15 | 2021-08-13 15:17:33 +0200 | [diff] [blame] | 31 | #include <utils/Condition.h> |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 32 | #include <utils/Errors.h> |
Valentin Iftime | 29e2e15 | 2021-08-13 15:17:33 +0200 | [diff] [blame] | 33 | #include <android/hardware/ICameraService.h> |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 34 | #include <utils/IPCTransport.h> |
Shuzhen Wang | a79a64d | 2022-04-24 19:56:30 -0700 | [diff] [blame] | 35 | #include <utils/SessionConfigurationUtils.h> |
Jayant Chowdhary | a04055f | 2022-01-03 02:07:49 +0000 | [diff] [blame] | 36 | #include <aidl/android/hardware/camera/provider/ICameraProvider.h> |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 37 | #include <android/hardware/camera/common/1.0/types.h> |
Eino-Ville Talvala | 63f3611 | 2018-12-06 14:57:03 -0800 | [diff] [blame] | 38 | #include <android/hardware/camera/provider/2.5/ICameraProvider.h> |
Shuzhen Wang | 4385816 | 2020-01-10 13:42:15 -0800 | [diff] [blame] | 39 | #include <android/hardware/camera/provider/2.6/ICameraProviderCallback.h> |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 40 | #include <android/hardware/camera/provider/2.6/ICameraProvider.h> |
Shuzhen Wang | 83bff12 | 2020-11-20 15:51:39 -0800 | [diff] [blame] | 41 | #include <android/hardware/camera/provider/2.7/ICameraProvider.h> |
| 42 | #include <android/hardware/camera/device/3.7/types.h> |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 43 | #include <android/hidl/manager/1.0/IServiceNotification.h> |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 44 | #include <binder/IServiceManager.h> |
Yin-Chia Yeh | 067428c | 2017-01-13 15:19:24 -0800 | [diff] [blame] | 45 | #include <camera/VendorTagDescriptor.h> |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 46 | |
| 47 | namespace android { |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 48 | |
| 49 | using hardware::camera2::utils::CameraIdAndSessionConfiguration; |
| 50 | |
| 51 | enum class CameraDeviceStatus : uint32_t { |
| 52 | NOT_PRESENT = 0, |
| 53 | PRESENT = 1, |
| 54 | ENUMERATING = 2 |
| 55 | }; |
| 56 | |
| 57 | enum class TorchModeStatus : uint32_t { |
| 58 | NOT_AVAILABLE = 0, |
| 59 | AVAILABLE_OFF = 1, |
| 60 | AVAILABLE_ON = 2 |
| 61 | }; |
| 62 | |
| 63 | struct CameraResourceCost { |
| 64 | uint32_t resourceCost; |
| 65 | std::vector<std::string> conflictingDevices; |
Yin-Chia Yeh | 067428c | 2017-01-13 15:19:24 -0800 | [diff] [blame] | 66 | }; |
| 67 | |
Jayant Chowdhary | 5216b21 | 2019-07-17 09:26:23 -0700 | [diff] [blame] | 68 | enum 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 Wang | 83bff12 | 2020-11-20 15:51:39 -0800 | [diff] [blame] | 88 | #define CAMERA_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION(1, 0) |
Kwangkyu Park | 91f4a9b | 2023-03-17 17:28:39 +0900 | [diff] [blame] | 89 | #define CAMERA_DEVICE_API_VERSION_1_2 HARDWARE_DEVICE_API_VERSION(1, 2) |
Shuzhen Wang | 83bff12 | 2020-11-20 15:51:39 -0800 | [diff] [blame] | 90 | #define CAMERA_DEVICE_API_VERSION_3_0 HARDWARE_DEVICE_API_VERSION(3, 0) |
| 91 | #define CAMERA_DEVICE_API_VERSION_3_1 HARDWARE_DEVICE_API_VERSION(3, 1) |
| 92 | #define CAMERA_DEVICE_API_VERSION_3_2 HARDWARE_DEVICE_API_VERSION(3, 2) |
| 93 | #define CAMERA_DEVICE_API_VERSION_3_3 HARDWARE_DEVICE_API_VERSION(3, 3) |
| 94 | #define CAMERA_DEVICE_API_VERSION_3_4 HARDWARE_DEVICE_API_VERSION(3, 4) |
| 95 | #define CAMERA_DEVICE_API_VERSION_3_5 HARDWARE_DEVICE_API_VERSION(3, 5) |
| 96 | #define CAMERA_DEVICE_API_VERSION_3_6 HARDWARE_DEVICE_API_VERSION(3, 6) |
| 97 | #define CAMERA_DEVICE_API_VERSION_3_7 HARDWARE_DEVICE_API_VERSION(3, 7) |
| 98 | |
Yin-Chia Yeh | 067428c | 2017-01-13 15:19:24 -0800 | [diff] [blame] | 99 | /** |
Jayant Chowdhary | a04055f | 2022-01-03 02:07:49 +0000 | [diff] [blame] | 100 | * The vendor tag descriptor class that takes HIDL/AIDL vendor tag information as |
| 101 | * input. Not part of VendorTagDescriptor class because that class is used |
| 102 | * in AIDL generated sources which don't have access to AIDL / HIDL headers. |
| 103 | */ |
| 104 | class IdlVendorTagDescriptor : public VendorTagDescriptor { |
| 105 | public: |
| 106 | /** |
| 107 | * Create a VendorTagDescriptor object from the HIDL/AIDL VendorTagSection |
| 108 | * vector. |
| 109 | * |
| 110 | * Returns OK on success, or a negative error code. |
| 111 | */ |
| 112 | template <class VendorTagSectionVectorType, class VendorTagSectionType> |
| 113 | static status_t createDescriptorFromIdl( |
| 114 | const VendorTagSectionVectorType& vts, |
| 115 | /*out*/ |
| 116 | sp<VendorTagDescriptor>& descriptor); |
| 117 | }; |
| 118 | |
| 119 | /** |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 120 | * A manager for all camera providers available on an Android device. |
| 121 | * |
| 122 | * Responsible for enumerating providers and the individual camera devices |
| 123 | * they export, both at startup and as providers and devices are added/removed. |
| 124 | * |
| 125 | * Provides methods for requesting information about individual devices and for |
| 126 | * opening them for active use. |
| 127 | * |
| 128 | */ |
Jayant Chowdhary | a04055f | 2022-01-03 02:07:49 +0000 | [diff] [blame] | 129 | class CameraProviderManager : virtual public hidl::manager::V1_0::IServiceNotification, |
| 130 | public virtual IServiceManager::LocalRegistrationCallback { |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 131 | public: |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 132 | // needs to be made friend strict since HidlProviderInfo needs to inherit |
| 133 | // from CameraProviderManager::ProviderInfo which isn't a public member. |
| 134 | friend struct HidlProviderInfo; |
Jayant Chowdhary | a04055f | 2022-01-03 02:07:49 +0000 | [diff] [blame] | 135 | friend struct AidlProviderInfo; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 136 | ~CameraProviderManager(); |
| 137 | |
| 138 | // Tiny proxy for the static methods in a HIDL interface that communicate with the hardware |
| 139 | // service manager, to be replacable in unit tests with a fake. |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 140 | struct HidlServiceInteractionProxy { |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 141 | virtual bool registerForNotifications( |
| 142 | const std::string &serviceName, |
| 143 | const sp<hidl::manager::V1_0::IServiceNotification> |
| 144 | ¬ification) = 0; |
Eino-Ville Talvala | ec96060 | 2019-10-15 11:46:16 -0700 | [diff] [blame] | 145 | // Will not wait for service to start if it's not already running |
| 146 | virtual sp<hardware::camera::provider::V2_4::ICameraProvider> tryGetService( |
| 147 | const std::string &serviceName) = 0; |
| 148 | // Will block for service if it exists but isn't running |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 149 | virtual sp<hardware::camera::provider::V2_4::ICameraProvider> getService( |
| 150 | const std::string &serviceName) = 0; |
Yin-Chia Yeh | 177b0c1 | 2019-06-25 10:53:03 -0700 | [diff] [blame] | 151 | virtual hardware::hidl_vec<hardware::hidl_string> listServices() = 0; |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 152 | virtual ~HidlServiceInteractionProxy() {} |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 153 | }; |
| 154 | |
| 155 | // Standard use case - call into the normal generated static methods which invoke |
| 156 | // the real hardware service manager |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 157 | struct HidlServiceInteractionProxyImpl : public HidlServiceInteractionProxy { |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 158 | virtual bool registerForNotifications( |
| 159 | const std::string &serviceName, |
| 160 | const sp<hidl::manager::V1_0::IServiceNotification> |
| 161 | ¬ification) override { |
| 162 | return hardware::camera::provider::V2_4::ICameraProvider::registerForNotifications( |
| 163 | serviceName, notification); |
| 164 | } |
Eino-Ville Talvala | ec96060 | 2019-10-15 11:46:16 -0700 | [diff] [blame] | 165 | virtual sp<hardware::camera::provider::V2_4::ICameraProvider> tryGetService( |
| 166 | const std::string &serviceName) override { |
| 167 | return hardware::camera::provider::V2_4::ICameraProvider::tryGetService(serviceName); |
| 168 | } |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 169 | virtual sp<hardware::camera::provider::V2_4::ICameraProvider> getService( |
| 170 | const std::string &serviceName) override { |
| 171 | return hardware::camera::provider::V2_4::ICameraProvider::getService(serviceName); |
| 172 | } |
Yin-Chia Yeh | 177b0c1 | 2019-06-25 10:53:03 -0700 | [diff] [blame] | 173 | |
| 174 | virtual hardware::hidl_vec<hardware::hidl_string> listServices() override; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 175 | }; |
| 176 | |
Vadim Caen | 7eccd7c | 2023-10-03 16:26:33 +0200 | [diff] [blame] | 177 | // Proxy to inject fake services in test. |
| 178 | class AidlServiceInteractionProxy { |
| 179 | public: |
| 180 | // Returns the Aidl service with the given serviceName |
| 181 | virtual std::shared_ptr<aidl::android::hardware::camera::provider::ICameraProvider> |
| 182 | getAidlService(const std::string& serviceName) = 0; |
| 183 | |
| 184 | virtual ~AidlServiceInteractionProxy() = default; |
| 185 | }; |
| 186 | |
| 187 | // Standard use case - call into the normal static methods which invoke |
| 188 | // the real service manager |
| 189 | class AidlServiceInteractionProxyImpl : public AidlServiceInteractionProxy { |
| 190 | public: |
| 191 | virtual std::shared_ptr<aidl::android::hardware::camera::provider::ICameraProvider> |
| 192 | getAidlService(const std::string& serviceName) override; |
| 193 | }; |
| 194 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 195 | /** |
| 196 | * Listener interface for device/torch status changes |
| 197 | */ |
| 198 | struct StatusListener : virtual public RefBase { |
| 199 | ~StatusListener() {} |
| 200 | |
Austin Borger | 0fb3ad9 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 201 | virtual void onDeviceStatusChanged(const std::string &cameraId, |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 202 | CameraDeviceStatus newStatus) = 0; |
Austin Borger | 0fb3ad9 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 203 | virtual void onDeviceStatusChanged(const std::string &cameraId, |
| 204 | const std::string &physicalCameraId, |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 205 | CameraDeviceStatus newStatus) = 0; |
Austin Borger | 0fb3ad9 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 206 | virtual void onTorchStatusChanged(const std::string &cameraId, |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 207 | TorchModeStatus newStatus, |
Jayant Chowdhary | 46ef0f5 | 2021-10-05 14:36:13 -0700 | [diff] [blame] | 208 | SystemCameraKind kind) = 0; |
Austin Borger | 0fb3ad9 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 209 | virtual void onTorchStatusChanged(const std::string &cameraId, |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 210 | TorchModeStatus newStatus) = 0; |
Emilian Peev | aee727d | 2017-05-04 16:35:48 +0100 | [diff] [blame] | 211 | virtual void onNewProviderRegistered() = 0; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 212 | }; |
| 213 | |
| 214 | /** |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 215 | * Represents the mode a camera device is currently in |
| 216 | */ |
| 217 | enum class DeviceMode { |
| 218 | TORCH, |
| 219 | CAMERA |
| 220 | }; |
| 221 | |
| 222 | /** |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 223 | * Initialize the manager and give it a status listener; optionally accepts a service |
| 224 | * interaction proxy. |
| 225 | * |
| 226 | * The default proxy communicates via the hardware service manager; alternate proxies can be |
| 227 | * used for testing. The lifetime of the proxy must exceed the lifetime of the manager. |
| 228 | */ |
| 229 | status_t initialize(wp<StatusListener> listener, |
Vadim Caen | 7eccd7c | 2023-10-03 16:26:33 +0200 | [diff] [blame] | 230 | HidlServiceInteractionProxy* hidlProxy = &sHidlServiceInteractionProxy, |
| 231 | AidlServiceInteractionProxy* aidlProxy = &sAidlServiceInteractionProxy); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 232 | |
Jayant Chowdhary | 22441f3 | 2021-12-26 18:35:41 -0800 | [diff] [blame] | 233 | status_t getCameraIdIPCTransport(const std::string &id, |
| 234 | IPCTransport *providerTransport) const; |
| 235 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 236 | /** |
Jayant Chowdhary | 847947d | 2019-08-30 18:02:59 -0700 | [diff] [blame] | 237 | * Retrieve the total number of available cameras. |
| 238 | * This value may change dynamically as cameras are added or removed. |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 239 | */ |
Jayant Chowdhary | 847947d | 2019-08-30 18:02:59 -0700 | [diff] [blame] | 240 | std::pair<int, int> getCameraCount() const; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 241 | |
Shuzhen Wang | 3d316f3 | 2022-10-25 20:33:34 +0000 | [diff] [blame] | 242 | /** |
| 243 | * Upon the function return, if unavailablePhysicalIds is not nullptr, it |
| 244 | * will contain all of the unavailable physical camera Ids represented in |
| 245 | * the form of: |
| 246 | * {[logicalCamera, {physicalCamera1, physicalCamera2, ...}], ...}. |
| 247 | */ |
| 248 | std::vector<std::string> getCameraDeviceIds(std::unordered_map< |
| 249 | std::string, std::set<std::string>>* unavailablePhysicalIds = nullptr) const; |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 250 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 251 | /** |
Emilian Peev | f53f66e | 2017-04-11 14:29:43 +0100 | [diff] [blame] | 252 | * Retrieve the number of API1 compatible cameras; these are internal and |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 253 | * backwards-compatible. This is the set of cameras that will be |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 254 | * accessible via the old camera API. |
| 255 | * The return value may change dynamically due to external camera hotplug. |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 256 | */ |
Emilian Peev | f53f66e | 2017-04-11 14:29:43 +0100 | [diff] [blame] | 257 | std::vector<std::string> getAPI1CompatibleCameraDeviceIds() const; |
Yin-Chia Yeh | dc3134e | 2017-03-23 15:26:59 -0700 | [diff] [blame] | 258 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 259 | /** |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 260 | * Return true if a device with a given ID has a flash unit. Returns false |
| 261 | * for devices that are unknown. |
| 262 | */ |
| 263 | bool hasFlashUnit(const std::string &id) const; |
| 264 | |
| 265 | /** |
Shuzhen Wang | dbdf72b | 2019-11-13 11:22:12 -0800 | [diff] [blame] | 266 | * Return true if the camera device has native zoom ratio support. |
| 267 | */ |
| 268 | bool supportNativeZoomRatio(const std::string &id) const; |
| 269 | |
| 270 | /** |
Emilian Peev | 1523014 | 2023-04-27 20:22:54 +0000 | [diff] [blame] | 271 | * Return true if the camera device has no composite Jpeg/R support. |
Emilian Peev | e579d8b | 2023-02-28 14:16:08 -0800 | [diff] [blame] | 272 | */ |
Emilian Peev | 1523014 | 2023-04-27 20:22:54 +0000 | [diff] [blame] | 273 | bool isCompositeJpegRDisabled(const std::string &id) const; |
Emilian Peev | e579d8b | 2023-02-28 14:16:08 -0800 | [diff] [blame] | 274 | |
| 275 | /** |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 276 | * Return the resource cost of this camera device |
| 277 | */ |
| 278 | status_t getResourceCost(const std::string &id, |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 279 | CameraResourceCost* cost) const; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 280 | |
| 281 | /** |
| 282 | * Return the old camera API camera info |
| 283 | */ |
| 284 | status_t getCameraInfo(const std::string &id, |
Austin Borger | 3560b7e | 2022-10-27 12:20:29 -0700 | [diff] [blame] | 285 | bool overrideToPortrait, int *portraitRotation, hardware::CameraInfo* info) const; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 286 | |
| 287 | /** |
| 288 | * Return API2 camera characteristics - returns NAME_NOT_FOUND if a device ID does |
| 289 | * not have a v3 or newer HAL version. |
| 290 | */ |
| 291 | status_t getCameraCharacteristics(const std::string &id, |
Austin Borger | 3560b7e | 2022-10-27 12:20:29 -0700 | [diff] [blame] | 292 | bool overrideForPerfClass, CameraMetadata* characteristics, |
| 293 | bool overrideToPortrait) const; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 294 | |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 295 | status_t isConcurrentSessionConfigurationSupported( |
| 296 | const std::vector<hardware::camera2::utils::CameraIdAndSessionConfiguration> |
| 297 | &cameraIdsAndSessionConfigs, |
Shuzhen Wang | d4abdf7 | 2021-05-28 11:22:50 -0700 | [diff] [blame] | 298 | const std::set<std::string>& perfClassPrimaryCameraIds, |
| 299 | int targetSdkVersion, bool *isSupported); |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 300 | |
Jayant Chowdhary | cad23c2 | 2020-03-10 15:04:59 -0700 | [diff] [blame] | 301 | std::vector<std::unordered_set<std::string>> getConcurrentCameraIds() const; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 302 | /** |
Emilian Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 303 | * Check for device support of specific stream combination. |
| 304 | */ |
| 305 | status_t isSessionConfigurationSupported(const std::string& id, |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 306 | const SessionConfiguration &configuration, |
Shuzhen Wang | a79a64d | 2022-04-24 19:56:30 -0700 | [diff] [blame] | 307 | bool overrideForPerfClass, camera3::metadataGetter getMetadata, |
Emilian Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 308 | bool *status /*out*/) const; |
| 309 | |
| 310 | /** |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 311 | * Return the highest supported device interface version for this ID |
| 312 | */ |
| 313 | status_t getHighestSupportedVersion(const std::string &id, |
Jayant Chowdhary | ffc5d68 | 2022-05-12 18:34:34 +0000 | [diff] [blame] | 314 | hardware::hidl_version *v, IPCTransport *transport); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 315 | |
| 316 | /** |
Yin-Chia Yeh | dc3134e | 2017-03-23 15:26:59 -0700 | [diff] [blame] | 317 | * Check if a given camera device support setTorchMode API. |
| 318 | */ |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 319 | bool supportSetTorchMode(const std::string &id) const; |
Yin-Chia Yeh | dc3134e | 2017-03-23 15:26:59 -0700 | [diff] [blame] | 320 | |
| 321 | /** |
Rucha Katakwar | 3828452 | 2021-11-10 11:25:21 -0800 | [diff] [blame] | 322 | * Check if torch strength update should be skipped or not. |
| 323 | */ |
| 324 | bool shouldSkipTorchStrengthUpdate(const std::string &id, int32_t torchStrength) const; |
| 325 | |
| 326 | /** |
| 327 | * Return the default torch strength level if the torch strength control |
| 328 | * feature is supported. |
| 329 | */ |
| 330 | int32_t getTorchDefaultStrengthLevel(const std::string &id) const; |
| 331 | |
| 332 | /** |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 333 | * Turn on or off the flashlight on a given camera device. |
Yin-Chia Yeh | dc3134e | 2017-03-23 15:26:59 -0700 | [diff] [blame] | 334 | * May fail if the device does not support this API, is in active use, or if the device |
| 335 | * doesn't exist, etc. |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 336 | */ |
| 337 | status_t setTorchMode(const std::string &id, bool enabled); |
| 338 | |
| 339 | /** |
Rucha Katakwar | 3828452 | 2021-11-10 11:25:21 -0800 | [diff] [blame] | 340 | * Change the brightness level of the flash unit associated with the cameraId and |
| 341 | * set it to the value in torchStrength. |
| 342 | * If the torch is OFF and torchStrength > 0, the torch will be turned ON with the |
| 343 | * specified strength level. If the torch is ON, only the brightness level will be |
| 344 | * changed. |
| 345 | * |
| 346 | * This operation will fail if the device does not have flash unit, has flash unit |
| 347 | * but does not support this API, torchStrength is invalid or if the device doesn't |
| 348 | * exist etc. |
| 349 | */ |
| 350 | status_t turnOnTorchWithStrengthLevel(const std::string &id, int32_t torchStrength); |
| 351 | |
| 352 | /** |
| 353 | * Return the torch strength level of this camera device. |
| 354 | */ |
| 355 | status_t getTorchStrengthLevel(const std::string &id, int32_t* torchStrength); |
| 356 | |
| 357 | /** |
Yin-Chia Yeh | 067428c | 2017-01-13 15:19:24 -0800 | [diff] [blame] | 358 | * Setup vendor tags for all registered providers |
| 359 | */ |
| 360 | status_t setUpVendorTags(); |
| 361 | |
| 362 | /** |
Eino-Ville Talvala | 63f3611 | 2018-12-06 14:57:03 -0800 | [diff] [blame] | 363 | * Inform registered providers about a device state change, such as folding or unfolding |
| 364 | */ |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 365 | status_t notifyDeviceStateChange(int64_t newState); |
Eino-Ville Talvala | 63f3611 | 2018-12-06 14:57:03 -0800 | [diff] [blame] | 366 | |
Jayant Chowdhary | a04055f | 2022-01-03 02:07:49 +0000 | [diff] [blame] | 367 | status_t openAidlSession(const std::string &id, |
| 368 | const std::shared_ptr< |
| 369 | aidl::android::hardware::camera::device::ICameraDeviceCallback>& callback, |
| 370 | /*out*/ |
| 371 | std::shared_ptr<aidl::android::hardware::camera::device::ICameraDeviceSession> *session); |
| 372 | |
Jayant Chowdhary | 35642f2 | 2022-01-08 00:39:39 +0000 | [diff] [blame] | 373 | status_t openAidlInjectionSession(const std::string &id, |
| 374 | const std::shared_ptr< |
| 375 | aidl::android::hardware::camera::device::ICameraDeviceCallback>& callback, |
| 376 | /*out*/ |
| 377 | std::shared_ptr<aidl::android::hardware::camera::device::ICameraInjectionSession> *session); |
Jayant Chowdhary | a04055f | 2022-01-03 02:07:49 +0000 | [diff] [blame] | 378 | |
Eino-Ville Talvala | 63f3611 | 2018-12-06 14:57:03 -0800 | [diff] [blame] | 379 | /** |
Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 380 | * Open an active session to a camera device. |
| 381 | * |
| 382 | * This fully powers on the camera device hardware, and returns a handle to a |
| 383 | * session to be used for hardware configuration and operation. |
| 384 | */ |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 385 | status_t openHidlSession(const std::string &id, |
Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 386 | const sp<hardware::camera::device::V3_2::ICameraDeviceCallback>& callback, |
| 387 | /*out*/ |
| 388 | sp<hardware::camera::device::V3_2::ICameraDeviceSession> *session); |
| 389 | |
Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 390 | /** |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 391 | * Notify that the camera or torch is no longer being used by a camera client |
| 392 | */ |
| 393 | void removeRef(DeviceMode usageType, const std::string &cameraId); |
| 394 | |
| 395 | /** |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 396 | * IServiceNotification::onRegistration |
| 397 | * Invoked by the hardware service manager when a new camera provider is registered |
| 398 | */ |
| 399 | virtual hardware::Return<void> onRegistration(const hardware::hidl_string& fqName, |
| 400 | const hardware::hidl_string& name, |
| 401 | bool preexisting) override; |
| 402 | |
Jayant Chowdhary | a04055f | 2022-01-03 02:07:49 +0000 | [diff] [blame] | 403 | // LocalRegistrationCallback::onServiceRegistration |
| 404 | virtual void onServiceRegistration(const String16& name, const sp<IBinder> &binder) override; |
| 405 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 406 | /** |
| 407 | * Dump out information about available providers and devices |
| 408 | */ |
| 409 | status_t dump(int fd, const Vector<String16>& args); |
| 410 | |
Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 411 | /** |
| 412 | * Conversion methods between HAL Status and status_t and strings |
| 413 | */ |
| 414 | static status_t mapToStatusT(const hardware::camera::common::V1_0::Status& s); |
| 415 | static const char* statusToString(const hardware::camera::common::V1_0::Status& s); |
| 416 | |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 417 | /* |
| 418 | * Return provider type for a specific device. |
| 419 | */ |
Jayant Chowdhary | ffc5d68 | 2022-05-12 18:34:34 +0000 | [diff] [blame] | 420 | metadata_vendor_id_t getProviderTagIdLocked(const std::string& id) const; |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 421 | |
Shuzhen Wang | e8aceb5 | 2018-05-21 12:00:56 -0700 | [diff] [blame] | 422 | /* |
Shuzhen Wang | 03d8cc1 | 2018-09-12 14:17:09 -0700 | [diff] [blame] | 423 | * Check if a camera is a logical camera. And if yes, return |
Shuzhen Wang | e8aceb5 | 2018-05-21 12:00:56 -0700 | [diff] [blame] | 424 | * the physical camera ids. |
| 425 | */ |
Shuzhen Wang | 03d8cc1 | 2018-09-12 14:17:09 -0700 | [diff] [blame] | 426 | bool isLogicalCamera(const std::string& id, std::vector<std::string>* physicalCameraIds); |
Shuzhen Wang | e8aceb5 | 2018-05-21 12:00:56 -0700 | [diff] [blame] | 427 | |
Jayant Chowdhary | 33e8ef8 | 2019-09-27 09:20:42 -0700 | [diff] [blame] | 428 | status_t getSystemCameraKind(const std::string& id, SystemCameraKind *kind) const; |
| 429 | bool isHiddenPhysicalCamera(const std::string& cameraId) const; |
Emilian Peev | 538c90e | 2018-12-17 18:03:19 +0000 | [diff] [blame] | 430 | |
Shuzhen Wang | d4abdf7 | 2021-05-28 11:22:50 -0700 | [diff] [blame] | 431 | status_t filterSmallJpegSizes(const std::string& cameraId); |
Shuzhen Wang | 89db299 | 2021-05-20 13:09:48 -0700 | [diff] [blame] | 432 | |
Valentin Iftime | 29e2e15 | 2021-08-13 15:17:33 +0200 | [diff] [blame] | 433 | status_t notifyUsbDeviceEvent(int32_t eventId, const std::string &usbDeviceId); |
| 434 | |
Emilian Peev | 434248e | 2022-10-06 14:58:54 -0700 | [diff] [blame] | 435 | static bool isConcurrentDynamicRangeCaptureSupported(const CameraMetadata& deviceInfo, |
| 436 | int64_t profile, int64_t concurrentProfile); |
| 437 | |
Emilian Peev | 538c90e | 2018-12-17 18:03:19 +0000 | [diff] [blame] | 438 | static const float kDepthARTolerance; |
Emilian Peev | 434248e | 2022-10-06 14:58:54 -0700 | [diff] [blame] | 439 | static const bool kFrameworkJpegRDisabled; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 440 | private: |
| 441 | // All private members, unless otherwise noted, expect mInterfaceMutex to be locked before use |
| 442 | mutable std::mutex mInterfaceMutex; |
| 443 | |
| 444 | wp<StatusListener> mListener; |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 445 | HidlServiceInteractionProxy* mHidlServiceProxy; |
Vadim Caen | 7eccd7c | 2023-10-03 16:26:33 +0200 | [diff] [blame] | 446 | AidlServiceInteractionProxy* mAidlServiceProxy; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 447 | |
Eino-Ville Talvala | 63f3611 | 2018-12-06 14:57:03 -0800 | [diff] [blame] | 448 | // Current overall Android device physical status |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 449 | int64_t mDeviceState; |
Eino-Ville Talvala | 63f3611 | 2018-12-06 14:57:03 -0800 | [diff] [blame] | 450 | |
Shuzhen Wang | 6ba8eb2 | 2018-07-08 13:10:44 -0700 | [diff] [blame] | 451 | // mProviderLifecycleLock is locked during onRegistration and removeProvider |
| 452 | mutable std::mutex mProviderLifecycleLock; |
| 453 | |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 454 | static HidlServiceInteractionProxyImpl sHidlServiceInteractionProxy; |
Vadim Caen | 7eccd7c | 2023-10-03 16:26:33 +0200 | [diff] [blame] | 455 | static AidlServiceInteractionProxyImpl sAidlServiceInteractionProxy; |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 456 | |
| 457 | struct HalCameraProvider { |
| 458 | // Empty parent struct for storing either aidl / hidl camera provider reference |
| 459 | HalCameraProvider(const char *descriptor) : mDescriptor(descriptor) { }; |
| 460 | virtual ~HalCameraProvider() {}; |
| 461 | std::string mDescriptor; |
| 462 | }; |
| 463 | |
| 464 | struct HidlHalCameraProvider : public HalCameraProvider { |
| 465 | HidlHalCameraProvider( |
| 466 | const sp<hardware::camera::provider::V2_4::ICameraProvider> &provider, |
| 467 | const char *descriptor) : |
| 468 | HalCameraProvider(descriptor), mCameraProvider(provider) { }; |
| 469 | private: |
| 470 | sp<hardware::camera::provider::V2_4::ICameraProvider> mCameraProvider; |
| 471 | }; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 472 | |
Jayant Chowdhary | a04055f | 2022-01-03 02:07:49 +0000 | [diff] [blame] | 473 | struct AidlHalCameraProvider : public HalCameraProvider { |
| 474 | AidlHalCameraProvider( |
| 475 | const std::shared_ptr< |
| 476 | aidl::android::hardware::camera::provider::ICameraProvider> &provider, |
| 477 | const char *descriptor) : |
| 478 | HalCameraProvider(descriptor), mCameraProvider(provider) { }; |
| 479 | private: |
| 480 | std::shared_ptr<aidl::android::hardware::camera::provider::ICameraProvider> mCameraProvider; |
| 481 | }; |
| 482 | |
| 483 | |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 484 | // Mapping from CameraDevice IDs to CameraProviders. This map is used to keep the |
| 485 | // ICameraProvider alive while it is in use by the camera with the given ID for camera |
| 486 | // capabilities |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 487 | std::unordered_map<std::string, std::shared_ptr<HalCameraProvider>> |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 488 | mCameraProviderByCameraId; |
| 489 | |
| 490 | // Mapping from CameraDevice IDs to CameraProviders. This map is used to keep the |
| 491 | // ICameraProvider alive while it is in use by the camera with the given ID for torch |
| 492 | // capabilities |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 493 | std::unordered_map<std::string, std::shared_ptr<HalCameraProvider>> |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 494 | mTorchProviderByCameraId; |
| 495 | |
| 496 | // Lock for accessing mCameraProviderByCameraId and mTorchProviderByCameraId |
| 497 | std::mutex mProviderInterfaceMapLock; |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 498 | struct ProviderInfo : public virtual RefBase { |
| 499 | friend struct HidlProviderInfo; |
Jayant Chowdhary | a04055f | 2022-01-03 02:07:49 +0000 | [diff] [blame] | 500 | friend struct AidlProviderInfo; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 501 | const std::string mProviderName; |
Emilian Peev | c93cac2 | 2020-08-17 16:00:10 -0700 | [diff] [blame] | 502 | const std::string mProviderInstance; |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 503 | const metadata_vendor_id_t mProviderTagid; |
Jayant Chowdhary | a04055f | 2022-01-03 02:07:49 +0000 | [diff] [blame] | 504 | int32_t mMinorVersion; |
Peter Kalauskas | 1b3c907 | 2018-11-07 12:41:53 -0800 | [diff] [blame] | 505 | sp<VendorTagDescriptor> mVendorTagDescriptor; |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 506 | bool mSetTorchModeSupported; |
| 507 | bool mIsRemote; |
| 508 | |
Emilian Peev | c93cac2 | 2020-08-17 16:00:10 -0700 | [diff] [blame] | 509 | ProviderInfo(const std::string &providerName, const std::string &providerInstance, |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 510 | CameraProviderManager *manager); |
| 511 | ~ProviderInfo(); |
| 512 | |
Jayant Chowdhary | d65d944 | 2023-07-11 01:18:06 +0000 | [diff] [blame] | 513 | virtual IPCTransport getIPCTransport() const = 0; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 514 | |
| 515 | const std::string& getType() const; |
| 516 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 517 | status_t dump(int fd, const Vector<String16>& args) const; |
| 518 | |
Jayant Chowdhary | a04055f | 2022-01-03 02:07:49 +0000 | [diff] [blame] | 519 | void initializeProviderInfoCommon(const std::vector<std::string> &devices); |
Peter Kalauskas | 1b3c907 | 2018-11-07 12:41:53 -0800 | [diff] [blame] | 520 | /** |
| 521 | * Setup vendor tags for this provider |
| 522 | */ |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 523 | virtual status_t setUpVendorTags() = 0; |
Peter Kalauskas | 1b3c907 | 2018-11-07 12:41:53 -0800 | [diff] [blame] | 524 | |
Eino-Ville Talvala | 63f3611 | 2018-12-06 14:57:03 -0800 | [diff] [blame] | 525 | /** |
| 526 | * Notify provider about top-level device physical state changes |
Emilian Peev | 7fe6c42 | 2021-09-08 13:43:20 -0700 | [diff] [blame] | 527 | * |
| 528 | * Note that 'mInterfaceMutex' should not be held when calling this method. |
| 529 | * It is possible for camera providers to add/remove devices and try to |
| 530 | * acquire it. |
Eino-Ville Talvala | 63f3611 | 2018-12-06 14:57:03 -0800 | [diff] [blame] | 531 | */ |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 532 | virtual status_t notifyDeviceStateChange(int64_t newDeviceState) = 0; |
| 533 | |
| 534 | virtual bool successfullyStartedProviderInterface() = 0; |
Jayant Chowdhary | cbe770a | 2020-02-14 11:14:46 -0800 | [diff] [blame] | 535 | |
Jayant Chowdhary | a04055f | 2022-01-03 02:07:49 +0000 | [diff] [blame] | 536 | virtual int64_t getDeviceState() = 0; |
| 537 | |
Jayant Chowdhary | cbe770a | 2020-02-14 11:14:46 -0800 | [diff] [blame] | 538 | std::vector<std::unordered_set<std::string>> getConcurrentCameraIdCombinations(); |
| 539 | |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 540 | /** |
Emilian Peev | b50402e | 2021-09-24 17:41:57 -0700 | [diff] [blame] | 541 | * Notify 'DeviceInfo' instanced about top-level device physical state changes |
| 542 | * |
| 543 | * Note that 'mInterfaceMutex' should be held when calling this method. |
| 544 | */ |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 545 | void notifyDeviceInfoStateChangeLocked(int64_t newDeviceState); |
Emilian Peev | b50402e | 2021-09-24 17:41:57 -0700 | [diff] [blame] | 546 | |
| 547 | /** |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 548 | * Query the camera provider for concurrent stream configuration support |
| 549 | */ |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 550 | virtual status_t isConcurrentSessionConfigurationSupported( |
| 551 | const std::vector<CameraIdAndSessionConfiguration> &cameraIdsAndSessionConfigs, |
| 552 | const std::set<std::string>& perfClassPrimaryCameraIds, |
| 553 | int targetSdkVersion, bool *isSupported) = 0; |
| 554 | |
Valentin Iftime | 29e2e15 | 2021-08-13 15:17:33 +0200 | [diff] [blame] | 555 | /** |
| 556 | * Remove all devices associated with this provider and notify listeners |
| 557 | * with NOT_PRESENT state. |
| 558 | */ |
| 559 | void removeAllDevices(); |
| 560 | |
| 561 | /** |
| 562 | * Provider is an external lazy HAL |
| 563 | */ |
| 564 | bool isExternalLazyHAL() const; |
| 565 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 566 | // Basic device information, common to all camera devices |
| 567 | struct DeviceInfo { |
| 568 | const std::string mName; // Full instance name |
| 569 | const std::string mId; // ID section of full name |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 570 | //Both hidl and aidl DeviceInfos. Aidl deviceInfos get {3, 8} to |
| 571 | //start off. |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 572 | const hardware::hidl_version mVersion; |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 573 | const metadata_vendor_id_t mProviderTagid; |
Shuzhen Wang | 03d8cc1 | 2018-09-12 14:17:09 -0700 | [diff] [blame] | 574 | bool mIsLogicalCamera; |
| 575 | std::vector<std::string> mPhysicalIds; |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 576 | hardware::CameraInfo mInfo; |
Jayant Chowdhary | 5216b21 | 2019-07-17 09:26:23 -0700 | [diff] [blame] | 577 | SystemCameraKind mSystemCameraKind = SystemCameraKind::PUBLIC; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 578 | |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 579 | const CameraResourceCost mResourceCost; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 580 | |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 581 | CameraDeviceStatus mStatus; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 582 | |
Shuzhen Wang | 7968043 | 2020-03-05 11:53:46 -0800 | [diff] [blame] | 583 | wp<ProviderInfo> mParentProvider; |
Rucha Katakwar | 3828452 | 2021-11-10 11:25:21 -0800 | [diff] [blame] | 584 | // Torch strength default, maximum levels if the torch strength control |
| 585 | // feature is supported. |
| 586 | int32_t mTorchStrengthLevel; |
| 587 | int32_t mTorchMaximumStrengthLevel; |
| 588 | int32_t mTorchDefaultStrengthLevel; |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 589 | |
Valentin Iftime | 29e2e15 | 2021-08-13 15:17:33 +0200 | [diff] [blame] | 590 | // Wait for lazy HALs to confirm device availability |
| 591 | static const nsecs_t kDeviceAvailableTimeout = 2000e6; // 2000 ms |
| 592 | Mutex mDeviceAvailableLock; |
| 593 | Condition mDeviceAvailableSignal; |
| 594 | bool mIsDeviceAvailable = true; |
| 595 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 596 | bool hasFlashUnit() const { return mHasFlashUnit; } |
Shuzhen Wang | dbdf72b | 2019-11-13 11:22:12 -0800 | [diff] [blame] | 597 | bool supportNativeZoomRatio() const { return mSupportNativeZoomRatio; } |
Emilian Peev | 1523014 | 2023-04-27 20:22:54 +0000 | [diff] [blame] | 598 | bool isCompositeJpegRDisabled() const { return mCompositeJpegRDisabled; } |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 599 | virtual status_t setTorchMode(bool enabled) = 0; |
Rucha Katakwar | 3828452 | 2021-11-10 11:25:21 -0800 | [diff] [blame] | 600 | virtual status_t turnOnTorchWithStrengthLevel(int32_t torchStrength) = 0; |
| 601 | virtual status_t getTorchStrengthLevel(int32_t *torchStrength) = 0; |
Austin Borger | 3560b7e | 2022-10-27 12:20:29 -0700 | [diff] [blame] | 602 | virtual status_t getCameraInfo(bool overrideToPortrait, |
| 603 | int *portraitRotation, |
| 604 | hardware::CameraInfo *info) const = 0; |
Emilian Peev | f53f66e | 2017-04-11 14:29:43 +0100 | [diff] [blame] | 605 | virtual bool isAPI1Compatible() const = 0; |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 606 | virtual status_t dumpState(int fd) = 0; |
Jing Mike | c7f9b13 | 2023-03-12 11:12:04 +0800 | [diff] [blame] | 607 | virtual status_t getCameraCharacteristics( |
| 608 | [[maybe_unused]] bool overrideForPerfClass, |
| 609 | [[maybe_unused]] CameraMetadata *characteristics, |
| 610 | [[maybe_unused]] bool overrideToPortrait) { |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 611 | return INVALID_OPERATION; |
| 612 | } |
Jing Mike | c7f9b13 | 2023-03-12 11:12:04 +0800 | [diff] [blame] | 613 | virtual status_t getPhysicalCameraCharacteristics( |
| 614 | [[maybe_unused]] const std::string& physicalCameraId, |
| 615 | [[maybe_unused]] CameraMetadata *characteristics) const { |
Shuzhen Wang | f9d2c02 | 2018-08-21 12:07:35 -0700 | [diff] [blame] | 616 | return INVALID_OPERATION; |
| 617 | } |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 618 | |
Emilian Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 619 | virtual status_t isSessionConfigurationSupported( |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 620 | const SessionConfiguration &/*configuration*/, |
| 621 | bool /*overrideForPerfClass*/, |
Shuzhen Wang | a79a64d | 2022-04-24 19:56:30 -0700 | [diff] [blame] | 622 | camera3::metadataGetter /*getMetadata*/, |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 623 | bool * /*status*/) { |
Emilian Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 624 | return INVALID_OPERATION; |
| 625 | } |
Shuzhen Wang | d4abdf7 | 2021-05-28 11:22:50 -0700 | [diff] [blame] | 626 | virtual status_t filterSmallJpegSizes() = 0; |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 627 | virtual void notifyDeviceStateChange(int64_t /*newState*/) {} |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 628 | |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 629 | DeviceInfo(const std::string& name, const metadata_vendor_id_t tagId, |
| 630 | const std::string &id, const hardware::hidl_version& version, |
Shuzhen Wang | f9d2c02 | 2018-08-21 12:07:35 -0700 | [diff] [blame] | 631 | const std::vector<std::string>& publicCameraIds, |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 632 | const CameraResourceCost& resourceCost, |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 633 | sp<ProviderInfo> parentProvider) : |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 634 | mName(name), mId(id), mVersion(version), mProviderTagid(tagId), |
Shuzhen Wang | 03d8cc1 | 2018-09-12 14:17:09 -0700 | [diff] [blame] | 635 | mIsLogicalCamera(false), mResourceCost(resourceCost), |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 636 | mStatus(CameraDeviceStatus::PRESENT), |
Rucha Katakwar | 3c6714d | 2021-12-15 13:56:55 -0800 | [diff] [blame] | 637 | mParentProvider(parentProvider), mTorchStrengthLevel(0), |
| 638 | mTorchMaximumStrengthLevel(0), mTorchDefaultStrengthLevel(0), |
| 639 | mHasFlashUnit(false), mSupportNativeZoomRatio(false), |
Emilian Peev | 1523014 | 2023-04-27 20:22:54 +0000 | [diff] [blame] | 640 | mPublicCameraIds(publicCameraIds), mCompositeJpegRDisabled(false) {} |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 641 | virtual ~DeviceInfo() {} |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 642 | protected: |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 643 | |
Shuzhen Wang | dbdf72b | 2019-11-13 11:22:12 -0800 | [diff] [blame] | 644 | bool mHasFlashUnit; // const after constructor |
| 645 | bool mSupportNativeZoomRatio; // const after constructor |
Shuzhen Wang | f9d2c02 | 2018-08-21 12:07:35 -0700 | [diff] [blame] | 646 | const std::vector<std::string>& mPublicCameraIds; |
Emilian Peev | 1523014 | 2023-04-27 20:22:54 +0000 | [diff] [blame] | 647 | bool mCompositeJpegRDisabled; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 648 | }; |
| 649 | std::vector<std::unique_ptr<DeviceInfo>> mDevices; |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 650 | std::unordered_set<std::string> mUniqueCameraIds; |
Shuzhen Wang | 3d316f3 | 2022-10-25 20:33:34 +0000 | [diff] [blame] | 651 | std::unordered_map<std::string, std::set<std::string>> mUnavailablePhysicalCameras; |
Yin-Chia Yeh | e8e9e19 | 2017-03-16 15:23:51 -0700 | [diff] [blame] | 652 | int mUniqueDeviceCount; |
Shuzhen Wang | e8aceb5 | 2018-05-21 12:00:56 -0700 | [diff] [blame] | 653 | std::vector<std::string> mUniqueAPI1CompatibleCameraIds; |
Shuzhen Wang | f9d2c02 | 2018-08-21 12:07:35 -0700 | [diff] [blame] | 654 | // The initial public camera IDs published by the camera provider. |
| 655 | // Currently logical multi-camera is not supported for hot-plug camera. |
| 656 | // And we use this list to keep track of initial public camera IDs |
| 657 | // advertised by the provider, and to distinguish against "hidden" |
| 658 | // physical camera IDs. |
| 659 | std::vector<std::string> mProviderPublicCameraIds; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 660 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 661 | // HALv3-specific camera fields, including the actual device interface |
| 662 | struct DeviceInfo3 : public DeviceInfo { |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 663 | |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 664 | virtual status_t setTorchMode(bool enabled) = 0; |
| 665 | virtual status_t turnOnTorchWithStrengthLevel(int32_t torchStrength) = 0; |
| 666 | virtual status_t getTorchStrengthLevel(int32_t *torchStrength) = 0; |
Austin Borger | 3560b7e | 2022-10-27 12:20:29 -0700 | [diff] [blame] | 667 | virtual status_t getCameraInfo(bool overrideToPortrait, |
| 668 | int *portraitRotation, |
| 669 | hardware::CameraInfo *info) const override; |
Emilian Peev | f53f66e | 2017-04-11 14:29:43 +0100 | [diff] [blame] | 670 | virtual bool isAPI1Compatible() const override; |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 671 | virtual status_t dumpState(int fd) = 0; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 672 | virtual status_t getCameraCharacteristics( |
Shuzhen Wang | d4abdf7 | 2021-05-28 11:22:50 -0700 | [diff] [blame] | 673 | bool overrideForPerfClass, |
Austin Borger | 3560b7e | 2022-10-27 12:20:29 -0700 | [diff] [blame] | 674 | CameraMetadata *characteristics, |
| 675 | bool overrideToPortrait) override; |
Shuzhen Wang | f9d2c02 | 2018-08-21 12:07:35 -0700 | [diff] [blame] | 676 | virtual status_t getPhysicalCameraCharacteristics(const std::string& physicalCameraId, |
| 677 | CameraMetadata *characteristics) const override; |
Emilian Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 678 | virtual status_t isSessionConfigurationSupported( |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 679 | const SessionConfiguration &configuration, bool /*overrideForPerfClass*/, |
Shuzhen Wang | a79a64d | 2022-04-24 19:56:30 -0700 | [diff] [blame] | 680 | camera3::metadataGetter /*getMetadata*/, |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 681 | bool *status /*out*/) = 0; |
Shuzhen Wang | d4abdf7 | 2021-05-28 11:22:50 -0700 | [diff] [blame] | 682 | virtual status_t filterSmallJpegSizes() override; |
Emilian Peev | b50402e | 2021-09-24 17:41:57 -0700 | [diff] [blame] | 683 | virtual void notifyDeviceStateChange( |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 684 | int64_t newState) override; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 685 | |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 686 | DeviceInfo3(const std::string& name, const metadata_vendor_id_t tagId, |
| 687 | const std::string &id, uint16_t minorVersion, |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 688 | const CameraResourceCost& resourceCost, |
Peter Kalauskas | a29c135 | 2018-10-10 12:05:42 -0700 | [diff] [blame] | 689 | sp<ProviderInfo> parentProvider, |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 690 | const std::vector<std::string>& publicCameraIds); |
| 691 | virtual ~DeviceInfo3() {}; |
| 692 | protected: |
| 693 | // Modified by derived transport specific (hidl / aidl) class |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 694 | CameraMetadata mCameraCharacteristics; |
Emilian Peev | b50402e | 2021-09-24 17:41:57 -0700 | [diff] [blame] | 695 | // Map device states to sensor orientations |
| 696 | std::unordered_map<int64_t, int32_t> mDeviceStateOrientationMap; |
Shuzhen Wang | d4abdf7 | 2021-05-28 11:22:50 -0700 | [diff] [blame] | 697 | // A copy of mCameraCharacteristics without performance class |
| 698 | // override |
| 699 | std::unique_ptr<CameraMetadata> mCameraCharNoPCOverride; |
Shuzhen Wang | a79a64d | 2022-04-24 19:56:30 -0700 | [diff] [blame] | 700 | // Only contains characteristics for hidden physical cameras, |
| 701 | // not for public physical cameras. |
Shuzhen Wang | f9d2c02 | 2018-08-21 12:07:35 -0700 | [diff] [blame] | 702 | std::unordered_map<std::string, CameraMetadata> mPhysicalCameraCharacteristics; |
Shuzhen Wang | 03d8cc1 | 2018-09-12 14:17:09 -0700 | [diff] [blame] | 703 | void queryPhysicalCameraIds(); |
Jayant Chowdhary | 5216b21 | 2019-07-17 09:26:23 -0700 | [diff] [blame] | 704 | SystemCameraKind getSystemCameraKind(); |
Shuzhen Wang | 268a136 | 2018-10-16 16:32:59 -0700 | [diff] [blame] | 705 | status_t fixupMonochromeTags(); |
Rucha Katakwar | 31fbf3a | 2022-05-02 13:23:56 -0700 | [diff] [blame] | 706 | status_t fixupTorchStrengthTags(); |
Rucha Katakwar | e4d3e1f | 2023-11-06 13:46:45 -0800 | [diff] [blame] | 707 | status_t fixupManualFlashStrengthControlTags(CameraMetadata& ch); |
Jayant Chowdhary | 13f9b2f | 2020-12-02 22:46:15 -0800 | [diff] [blame] | 708 | status_t addDynamicDepthTags(bool maxResolution = false); |
| 709 | status_t deriveHeicTags(bool maxResolution = false); |
Emilian Peev | 434248e | 2022-10-06 14:58:54 -0700 | [diff] [blame] | 710 | status_t deriveJpegRTags(bool maxResolution = false); |
Eino-Ville Talvala | f2e3709 | 2020-01-07 15:32:32 -0800 | [diff] [blame] | 711 | status_t addRotateCropTags(); |
Bharatt Kukreja | d33fe9f | 2022-11-23 21:52:52 +0000 | [diff] [blame] | 712 | status_t addAutoframingTags(); |
Shuzhen Wang | 9bf8a6f | 2020-05-01 09:49:04 -0700 | [diff] [blame] | 713 | status_t addPreCorrectionActiveArraySize(); |
Jayant Chowdhary | ffc5d68 | 2022-05-12 18:34:34 +0000 | [diff] [blame] | 714 | status_t addReadoutTimestampTag(bool readoutTimestampSupported = true); |
Eino-Ville Talvala | f2e3709 | 2020-01-07 15:32:32 -0800 | [diff] [blame] | 715 | |
Emilian Peev | 4c6d2b5 | 2019-01-04 17:13:56 +0000 | [diff] [blame] | 716 | static void getSupportedSizes(const CameraMetadata& ch, uint32_t tag, |
| 717 | android_pixel_format_t format, |
| 718 | std::vector<std::tuple<size_t, size_t>> *sizes /*out*/); |
Shuzhen Wang | d4abdf7 | 2021-05-28 11:22:50 -0700 | [diff] [blame] | 719 | static void getSupportedDurations( const CameraMetadata& ch, uint32_t tag, |
Emilian Peev | 4c6d2b5 | 2019-01-04 17:13:56 +0000 | [diff] [blame] | 720 | android_pixel_format_t format, |
| 721 | const std::vector<std::tuple<size_t, size_t>>& sizes, |
| 722 | std::vector<int64_t> *durations/*out*/); |
Shuzhen Wang | d4abdf7 | 2021-05-28 11:22:50 -0700 | [diff] [blame] | 723 | static void getSupportedDynamicDepthDurations( |
| 724 | const std::vector<int64_t>& depthDurations, |
Emilian Peev | 4c6d2b5 | 2019-01-04 17:13:56 +0000 | [diff] [blame] | 725 | const std::vector<int64_t>& blobDurations, |
| 726 | std::vector<int64_t> *dynamicDepthDurations /*out*/); |
| 727 | static void getSupportedDynamicDepthSizes( |
| 728 | const std::vector<std::tuple<size_t, size_t>>& blobSizes, |
| 729 | const std::vector<std::tuple<size_t, size_t>>& depthSizes, |
| 730 | std::vector<std::tuple<size_t, size_t>> *dynamicDepthSizes /*out*/, |
| 731 | std::vector<std::tuple<size_t, size_t>> *internalDepthSizes /*out*/); |
Shuzhen Wang | 268a136 | 2018-10-16 16:32:59 -0700 | [diff] [blame] | 732 | status_t removeAvailableKeys(CameraMetadata& c, const std::vector<uint32_t>& keys, |
| 733 | uint32_t keyTag); |
Shuzhen Wang | 68ac7ad | 2019-01-30 14:03:28 -0800 | [diff] [blame] | 734 | status_t fillHeicStreamCombinations(std::vector<int32_t>* outputs, |
| 735 | std::vector<int64_t>* durations, |
| 736 | std::vector<int64_t>* stallDurations, |
| 737 | const camera_metadata_entry& halStreamConfigs, |
| 738 | const camera_metadata_entry& halStreamDurations); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 739 | }; |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 740 | protected: |
Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 741 | std::string mType; |
| 742 | uint32_t mId; |
| 743 | |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 744 | std::mutex mLock; |
| 745 | |
Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 746 | CameraProviderManager *mManager; |
| 747 | |
Shuzhen Wang | 394ad70 | 2020-07-23 13:01:54 -0700 | [diff] [blame] | 748 | struct CameraStatusInfoT { |
| 749 | bool isPhysicalCameraStatus = false; |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 750 | std::string cameraId; |
| 751 | std::string physicalCameraId; |
| 752 | CameraDeviceStatus status; |
| 753 | CameraStatusInfoT(bool isForPhysicalCamera, const std::string& id, |
| 754 | const std::string& physicalId, |
| 755 | CameraDeviceStatus s) : |
Shuzhen Wang | 394ad70 | 2020-07-23 13:01:54 -0700 | [diff] [blame] | 756 | isPhysicalCameraStatus(isForPhysicalCamera), cameraId(id), |
| 757 | physicalCameraId(physicalId), status(s) {} |
| 758 | }; |
| 759 | |
| 760 | // Lock to synchronize between initialize() and camera status callbacks |
| 761 | std::mutex mInitLock; |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 762 | bool mInitialized = false; |
Shuzhen Wang | 394ad70 | 2020-07-23 13:01:54 -0700 | [diff] [blame] | 763 | std::vector<CameraStatusInfoT> mCachedStatus; |
| 764 | // End of scope for mInitLock |
| 765 | |
Jayant Chowdhary | a04055f | 2022-01-03 02:07:49 +0000 | [diff] [blame] | 766 | std::unique_ptr<ProviderInfo::DeviceInfo> |
| 767 | virtual initializeDeviceInfo( |
| 768 | const std::string &name, const metadata_vendor_id_t tagId, |
| 769 | const std::string &id, uint16_t minorVersion) = 0; |
| 770 | |
| 771 | virtual status_t reCacheConcurrentStreamingCameraIdsLocked() = 0; |
| 772 | |
Jayant Chowdhary | cbe770a | 2020-02-14 11:14:46 -0800 | [diff] [blame] | 773 | std::vector<std::unordered_set<std::string>> mConcurrentCameraIdCombinations; |
| 774 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 775 | // Parse provider instance name for type and id |
| 776 | static status_t parseProviderName(const std::string& name, |
| 777 | std::string *type, uint32_t *id); |
| 778 | |
| 779 | // Parse device instance name for device version, type, and id. |
| 780 | static status_t parseDeviceName(const std::string& name, |
| 781 | uint16_t *major, uint16_t *minor, std::string *type, std::string *id); |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 782 | |
| 783 | // Generate vendor tag id |
| 784 | static metadata_vendor_id_t generateVendorTagId(const std::string &name); |
Guennadi Liakhovetski | 6034bf5 | 2017-12-07 10:28:29 +0100 | [diff] [blame] | 785 | |
Jayant Chowdhary | a04055f | 2022-01-03 02:07:49 +0000 | [diff] [blame] | 786 | status_t addDevice( |
| 787 | const std::string& name, CameraDeviceStatus initialStatus, |
| 788 | /*out*/ std::string* parsedId); |
| 789 | |
| 790 | void cameraDeviceStatusChangeInternal(const std::string& cameraDeviceName, |
| 791 | CameraDeviceStatus newStatus); |
| 792 | |
| 793 | status_t cameraDeviceStatusChangeLocked( |
| 794 | std::string* id, const std::string& cameraDeviceName, |
| 795 | CameraDeviceStatus newStatus); |
| 796 | |
| 797 | void physicalCameraDeviceStatusChangeInternal(const std::string& cameraDeviceName, |
| 798 | const std::string& physicalCameraDeviceName, |
| 799 | CameraDeviceStatus newStatus); |
| 800 | |
| 801 | status_t physicalCameraDeviceStatusChangeLocked( |
| 802 | std::string* id, std::string* physicalId, |
| 803 | const std::string& cameraDeviceName, |
| 804 | const std::string& physicalCameraDeviceName, |
| 805 | CameraDeviceStatus newStatus); |
| 806 | |
| 807 | void torchModeStatusChangeInternal(const std::string& cameraDeviceName, |
| 808 | TorchModeStatus newStatus); |
| 809 | |
Austin Borger | 0fb3ad9 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 810 | void removeDevice(const std::string &id); |
Jayant Chowdhary | cbe770a | 2020-02-14 11:14:46 -0800 | [diff] [blame] | 811 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 812 | }; |
| 813 | |
Jayant Chowdhary | a04055f | 2022-01-03 02:07:49 +0000 | [diff] [blame] | 814 | template <class ProviderInfoType, class HalCameraProviderType> |
| 815 | status_t setTorchModeT(sp<ProviderInfo> &parentProvider, |
| 816 | std::shared_ptr<HalCameraProvider> *halCameraProvider); |
| 817 | |
| 818 | // Try to get hidl provider services declared. Expects mInterfaceMutex to be |
| 819 | // locked. Also registers for hidl provider service notifications. |
| 820 | status_t tryToInitAndAddHidlProvidersLocked(HidlServiceInteractionProxy *hidlProxy); |
| 821 | |
| 822 | // Try to get aidl provider services declared. Expects mInterfaceMutex to be |
| 823 | // locked. Also registers for aidl provider service notifications. |
| 824 | status_t tryToAddAidlProvidersLocked(); |
| 825 | |
Emilian Peev | 7fe6c42 | 2021-09-08 13:43:20 -0700 | [diff] [blame] | 826 | /** |
| 827 | * Save the ICameraProvider while it is being used by a camera or torch client |
| 828 | */ |
| 829 | void saveRef(DeviceMode usageType, const std::string &cameraId, |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 830 | std::shared_ptr<HalCameraProvider> provider); |
Emilian Peev | 7fe6c42 | 2021-09-08 13:43:20 -0700 | [diff] [blame] | 831 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 832 | // Utility to find a DeviceInfo by ID; pointer is only valid while mInterfaceMutex is held |
| 833 | // and the calling code doesn't mutate the list of providers or their lists of devices. |
Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 834 | // No guarantees on the order of traversal |
Jayant Chowdhary | ffc5d68 | 2022-05-12 18:34:34 +0000 | [diff] [blame] | 835 | ProviderInfo::DeviceInfo* findDeviceInfoLocked(const std::string& id) const; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 836 | |
Emilian Peev | 1523014 | 2023-04-27 20:22:54 +0000 | [diff] [blame] | 837 | bool isCompositeJpegRDisabledLocked(const std::string &id) const; |
Emilian Peev | e579d8b | 2023-02-28 14:16:08 -0800 | [diff] [blame] | 838 | |
Valentin Iftime | 29e2e15 | 2021-08-13 15:17:33 +0200 | [diff] [blame] | 839 | // Map external providers to USB devices in order to handle USB hotplug |
| 840 | // events for lazy HALs |
| 841 | std::pair<std::vector<std::string>, sp<ProviderInfo>> |
| 842 | mExternalUsbDevicesForProvider; |
| 843 | sp<ProviderInfo> startExternalLazyProvider() const; |
| 844 | |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 845 | status_t addHidlProviderLocked(const std::string& newProvider, bool preexisting = false); |
Emilian Peev | c93cac2 | 2020-08-17 16:00:10 -0700 | [diff] [blame] | 846 | |
Jayant Chowdhary | a04055f | 2022-01-03 02:07:49 +0000 | [diff] [blame] | 847 | status_t addAidlProviderLocked(const std::string& newProvider); |
| 848 | |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 849 | status_t tryToInitializeHidlProviderLocked(const std::string& providerName, |
Emilian Peev | c93cac2 | 2020-08-17 16:00:10 -0700 | [diff] [blame] | 850 | const sp<ProviderInfo>& providerInfo); |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 851 | |
Jayant Chowdhary | a04055f | 2022-01-03 02:07:49 +0000 | [diff] [blame] | 852 | status_t tryToInitializeAidlProviderLocked(const std::string& providerName, |
| 853 | const sp<ProviderInfo>& providerInfo); |
| 854 | |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 855 | bool isLogicalCameraLocked(const std::string& id, std::vector<std::string>* physicalCameraIds); |
| 856 | |
Jayant Chowdhary | e8c4b23 | 2022-02-04 18:18:04 +0000 | [diff] [blame] | 857 | // No method corresponding to the same provider / member belonging to the |
| 858 | // same provider should be used after this method is called since it'll lead |
| 859 | // to invalid memory access (especially since this is called by ProviderInfo methods on hal |
| 860 | // service death). |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 861 | status_t removeProvider(const std::string& provider); |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 862 | sp<StatusListener> getStatusListener() const; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 863 | |
Jayant Chowdhary | ffc5d68 | 2022-05-12 18:34:34 +0000 | [diff] [blame] | 864 | bool isValidDeviceLocked(const std::string &id, uint16_t majorVersion, |
| 865 | IPCTransport transport) const; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 866 | |
Emilian Peev | c93cac2 | 2020-08-17 16:00:10 -0700 | [diff] [blame] | 867 | size_t mProviderInstanceId = 0; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 868 | std::vector<sp<ProviderInfo>> mProviders; |
Jayant Chowdhary | a04055f | 2022-01-03 02:07:49 +0000 | [diff] [blame] | 869 | // Provider names of AIDL providers with retrieved binders. |
| 870 | std::set<std::string> mAidlProviderWithBinders; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 871 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 872 | static const char* deviceStatusToString( |
| 873 | const hardware::camera::common::V1_0::CameraDeviceStatus&); |
| 874 | static const char* torchStatusToString( |
| 875 | const hardware::camera::common::V1_0::TorchModeStatus&); |
| 876 | |
Shuzhen Wang | d4abdf7 | 2021-05-28 11:22:50 -0700 | [diff] [blame] | 877 | status_t getCameraCharacteristicsLocked(const std::string &id, bool overrideForPerfClass, |
Austin Borger | 3560b7e | 2022-10-27 12:20:29 -0700 | [diff] [blame] | 878 | CameraMetadata* characteristics, bool overrideToPortrait) const; |
Shuzhen Wang | e8aceb5 | 2018-05-21 12:00:56 -0700 | [diff] [blame] | 879 | void filterLogicalCameraIdsLocked(std::vector<std::string>& deviceIds) const; |
Jayant Chowdhary | 847947d | 2019-08-30 18:02:59 -0700 | [diff] [blame] | 880 | |
Jayant Chowdhary | 33e8ef8 | 2019-09-27 09:20:42 -0700 | [diff] [blame] | 881 | status_t getSystemCameraKindLocked(const std::string& id, SystemCameraKind *kind) const; |
Jayant Chowdhary | 0bd3852 | 2021-11-05 17:49:27 -0700 | [diff] [blame] | 882 | std::pair<bool, ProviderInfo::DeviceInfo *> isHiddenPhysicalCameraInternal( |
| 883 | const std::string& cameraId) const; |
Jayant Chowdhary | 847947d | 2019-08-30 18:02:59 -0700 | [diff] [blame] | 884 | |
| 885 | void collectDeviceIdsLocked(const std::vector<std::string> deviceIds, |
| 886 | std::vector<std::string>& normalDeviceIds, |
| 887 | std::vector<std::string>& systemCameraDeviceIds) const; |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 888 | |
Valentin Iftime | 29e2e15 | 2021-08-13 15:17:33 +0200 | [diff] [blame] | 889 | status_t usbDeviceDetached(const std::string &usbDeviceId); |
Jayant Chowdhary | a04055f | 2022-01-03 02:07:49 +0000 | [diff] [blame] | 890 | ndk::ScopedAStatus onAidlRegistration(const std::string& in_name, |
| 891 | const ::ndk::SpAIBinder& in_binder); |
Vadim Caen | 7eccd7c | 2023-10-03 16:26:33 +0200 | [diff] [blame] | 892 | |
| 893 | static bool isVirtualCameraHalEnabled(); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 894 | }; |
| 895 | |
| 896 | } // namespace android |
| 897 | |
| 898 | #endif |